/* =====================================================================
   PTU PDF Editor — UI theme based on the "Cyborg Creator UI 36" prompt
   dark cards #0C1124 / radius 24, accents gold #E8B64C, green #3DDC84,
   purple #8B7CFF, pink #FF5C8A, Inter (Latin/digits) + Kanit (Thai),
   Lucide SVG icons, 200–600ms ease-out/spring motion, reduced-motion aware.
   ===================================================================== */

/* ---------- fonts (bundled, offline) ---------- */
@font-face { font-family: "InterUI"; font-style: normal; font-weight: 400; font-display: swap; src: url("../fonts/ui/inter-latin-400-normal.woff2") format("woff2"); unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+2000-206F, U+2074, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD; }
@font-face { font-family: "InterUI"; font-style: normal; font-weight: 500; font-display: swap; src: url("../fonts/ui/inter-latin-500-normal.woff2") format("woff2"); unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+2000-206F, U+2074, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD; }
@font-face { font-family: "InterUI"; font-style: normal; font-weight: 600; font-display: swap; src: url("../fonts/ui/inter-latin-600-normal.woff2") format("woff2"); unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+2000-206F, U+2074, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD; }
@font-face { font-family: "InterUI"; font-style: normal; font-weight: 700; font-display: swap; src: url("../fonts/ui/inter-latin-700-normal.woff2") format("woff2"); unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+2000-206F, U+2074, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD; }
@font-face { font-family: "KanitUI"; font-style: normal; font-weight: 400; font-display: swap; src: url("../fonts/ui/kanit-thai-400-normal.woff2") format("woff2"); unicode-range: U+02D7, U+0303, U+0331, U+0E01-0E5B, U+200C-200D, U+25CC; }
@font-face { font-family: "KanitUI"; font-style: normal; font-weight: 500; font-display: swap; src: url("../fonts/ui/kanit-thai-500-normal.woff2") format("woff2"); unicode-range: U+02D7, U+0303, U+0331, U+0E01-0E5B, U+200C-200D, U+25CC; }
@font-face { font-family: "KanitUI"; font-style: normal; font-weight: 600; font-display: swap; src: url("../fonts/ui/kanit-thai-600-normal.woff2") format("woff2"); unicode-range: U+02D7, U+0303, U+0331, U+0E01-0E5B, U+200C-200D, U+25CC; }

/* ---------- theme tokens ---------- */
:root {
  --gold: #E8B64C;
  --gold-2: #F5CD72;
  --green: #3DDC84;
  --purple: #8B7CFF;
  --pink: #FF5C8A;
  --red: #FF5C5C;
  --ease: cubic-bezier(.22, 1, .36, 1);
  --spring: cubic-bezier(.34, 1.56, .64, 1);
  --r-card: 24px;
  --r-md: 14px;
  --r-sm: 10px;
  --font: "InterUI", "KanitUI", "Sarabun", "Leelawadee UI", system-ui, sans-serif;
  font-family: var(--font);
}
:root, [data-theme="dark"] {
  color-scheme: dark;
  --bg: #060914;
  --bg-glow: radial-gradient(1200px 600px at 85% -10%, rgba(139,124,255,.16), transparent 60%), radial-gradient(900px 500px at -10% 110%, rgba(255,92,138,.10), transparent 60%);
  --surface: #0C1124;
  --surface-2: #121A33;
  --surface-3: #1A2443;
  --glass: rgba(12, 17, 36, .78);
  --border: rgba(255, 255, 255, .08);
  --border-2: rgba(255, 255, 255, .14);
  --text: #E9ECF5;
  --muted: #8E97B5;
  --viewer: #070B18;
  --shadow: 0 12px 40px rgba(0, 0, 0, .45);
  --paper-shadow: 0 10px 34px rgba(0, 0, 0, .55), 0 0 0 1px rgba(255,255,255,.04);
  --accent: var(--purple);
  --accent-soft: rgba(139, 124, 255, .16);
  --sel: #8B7CFF;
}
[data-theme="light"] {
  color-scheme: light;
  --bg: #EEF1F8;
  --bg-glow: radial-gradient(1200px 600px at 85% -10%, rgba(139,124,255,.14), transparent 60%), radial-gradient(900px 500px at -10% 110%, rgba(232,182,76,.12), transparent 60%);
  --surface: #FFFFFF;
  --surface-2: #F4F6FB;
  --surface-3: #E8ECF6;
  --glass: rgba(255, 255, 255, .8);
  --border: rgba(12, 17, 36, .09);
  --border-2: rgba(12, 17, 36, .16);
  --text: #0C1124;
  --muted: #5B6482;
  --viewer: #E3E7F1;
  --shadow: 0 12px 34px rgba(25, 33, 71, .14);
  --paper-shadow: 0 8px 26px rgba(25, 33, 71, .16), 0 0 0 1px rgba(12,17,36,.05);
  --accent: #6C5CE7;
  --accent-soft: rgba(108, 92, 231, .12);
  --sel: #6C5CE7;
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body { color: var(--text); background: var(--bg); background-image: var(--bg-glow); font-size: 14px; -webkit-font-smoothing: antialiased; }
button, input, select, textarea { font-family: inherit; font-size: inherit; color: inherit; }
[hidden] { display: none !important; }
#app { display: flex; flex-direction: column; height: 100vh; }
.spacer { flex: 1; }
.muted { color: var(--muted); }
.ic { flex: none; display: block; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
::selection { background: rgba(139, 124, 255, .35); }
::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-thumb { background: var(--surface-3); border-radius: 10px; border: 2px solid transparent; background-clip: padding-box; }
::-webkit-scrollbar-track { background: transparent; }

/* ---------- top bar ---------- */
.topbar { display: flex; align-items: center; gap: 14px; padding: 10px 16px; min-height: 62px; background: var(--glass); backdrop-filter: blur(20px) saturate(160%); -webkit-backdrop-filter: blur(20px) saturate(160%); border-bottom: 1px solid var(--border); position: relative; z-index: 20; }
.brand { display: flex; align-items: center; gap: 10px; white-space: nowrap; }
.brand-logo { width: 36px; height: 36px; border-radius: 11px; display: grid; place-items: center; color: #fff; background: linear-gradient(135deg, var(--purple), var(--pink)); box-shadow: 0 6px 18px rgba(139, 124, 255, .45); }
.brand-text { display: flex; flex-direction: column; line-height: 1.05; }
.brand-text b { font-size: 15.5px; letter-spacing: .2px; }
.brand-text small { font-size: 11px; color: var(--muted); letter-spacing: 1.6px; text-transform: uppercase; }
.file-group { display: flex; gap: 6px; align-items: center; flex-wrap: wrap; }
.doc-name { flex: 1; min-width: 80px; text-align: center; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: var(--muted); font-size: 13px; }
.top-right { display: flex; align-items: center; gap: 10px; }
.secure-badge { display: inline-flex; align-items: center; gap: 6px; padding: 6px 12px; border-radius: 999px; font-size: 12px; white-space: nowrap; color: var(--green); background: rgba(61, 220, 132, .1); border: 1px solid rgba(61, 220, 132, .28); }

/* ---------- buttons ---------- */
.btn { display: inline-flex; align-items: center; gap: 8px; height: 38px; padding: 0 14px; border-radius: 12px; border: 1px solid var(--border); background: var(--surface-2); color: var(--text); cursor: pointer; white-space: nowrap; line-height: 1; font-weight: 500; transition: transform .2s var(--ease), background .2s var(--ease), border-color .2s var(--ease), box-shadow .3s var(--ease); }
.btn:hover { background: var(--surface-3); border-color: var(--border-2); transform: translateY(-1px); }
.btn:active { transform: translateY(0) scale(.97); }
.btn.ghost { background: transparent; border-color: transparent; }
.btn.ghost:hover { background: var(--surface-2); border-color: var(--border); }
.btn.primary { color: #1A1203; border-color: transparent; background: linear-gradient(135deg, var(--gold-2), var(--gold)); box-shadow: 0 6px 20px rgba(232, 182, 76, .32); font-weight: 600; }
.btn.primary:hover { box-shadow: 0 8px 26px rgba(232, 182, 76, .48); background: linear-gradient(135deg, #FFD983, var(--gold)); }
.btn.primary.done { background: var(--green); box-shadow: 0 0 0 6px rgba(61, 220, 132, .18), 0 8px 26px rgba(61, 220, 132, .45); color: #04210F; animation: pop .5s var(--spring); }
.btn.big { height: 48px; padding: 0 24px; font-size: 16px; border-radius: 14px; }
.btn.danger-ghost { color: var(--pink); }
.btn:disabled { opacity: .45; cursor: default; transform: none; }
.caret { opacity: .7; transition: transform .25s var(--ease); }
#btnTools[aria-expanded="true"] .caret { transform: rotate(180deg); }
@keyframes pop { 0% { transform: scale(.92); } 60% { transform: scale(1.06); } 100% { transform: scale(1); } }

/* #10 Day / Night switch */
.theme-toggle { position: relative; width: 58px; height: 30px; border-radius: 999px; border: 1px solid var(--border-2); cursor: pointer; padding: 0; overflow: hidden; background: linear-gradient(180deg, #7CC6FF, #BFE4FF); transition: background .5s var(--ease); }
[data-theme="dark"] .theme-toggle { background: linear-gradient(180deg, #0A1230, #1B2550); }
.theme-knob { position: absolute; top: 3px; left: 3px; width: 22px; height: 22px; border-radius: 50%; display: grid; place-items: center; background: #FFD45C; color: #8A5A00; box-shadow: 0 2px 8px rgba(0,0,0,.25); transition: transform .5s var(--spring), background .4s var(--ease), color .4s; }
[data-theme="dark"] .theme-knob { transform: translateX(28px) rotate(-360deg); background: #E9ECF5; color: #2A3366; }
.theme-knob .ic { position: absolute; transition: opacity .3s var(--ease), transform .4s var(--ease); }
.theme-knob .moon { opacity: 0; transform: scale(.4) rotate(-90deg); }
[data-theme="dark"] .theme-knob .sun { opacity: 0; transform: scale(.4) rotate(90deg); }
[data-theme="dark"] .theme-knob .moon { opacity: 1; transform: none; }
.theme-toggle .star { position: absolute; width: 3px; height: 3px; border-radius: 50%; background: #fff; opacity: 0; transform: scale(0); transition: opacity .4s var(--ease), transform .5s var(--spring); }
.theme-toggle .s1 { left: 9px; top: 8px; } .theme-toggle .s2 { left: 17px; top: 17px; transition-delay: .08s; } .theme-toggle .s3 { left: 26px; top: 9px; transition-delay: .16s; }
[data-theme="dark"] .theme-toggle .star { opacity: .9; transform: scale(1); }

/* ---------- toolbar ---------- */
.toolbar { display: flex; align-items: center; gap: 8px; margin: 10px 12px 0; padding: 6px 10px; min-height: 60px; background: var(--surface); border: 1px solid var(--border); border-radius: 18px; box-shadow: var(--shadow); flex-wrap: wrap; position: relative; z-index: 10; }
.tool-group { display: flex; align-items: center; gap: 2px; }
.tool-group.seg { background: var(--surface-2); padding: 4px; border-radius: 14px; border: 1px solid var(--border); }
.sep { width: 1px; align-self: stretch; background: var(--border); margin: 8px 2px; }
.tool { position: relative; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 3px; min-width: 52px; height: 46px; padding: 3px 6px; border: 0; border-radius: 11px; background: transparent; color: var(--muted); cursor: pointer; transition: color .2s var(--ease), background .25s var(--ease), transform .2s var(--ease); }
.tool span { font-size: 11px; line-height: 1; white-space: nowrap; }
.tool:hover { color: var(--text); background: var(--surface-3); }
.tool:active { transform: scale(.94); }
.tool.active { color: #fff; background: linear-gradient(135deg, var(--purple), #6E5BFF); box-shadow: 0 6px 18px rgba(139, 124, 255, .45); }
[data-theme="light"] .tool.active { background: linear-gradient(135deg, #8B7CFF, #6C5CE7); }
.tool.small { min-width: 34px; width: 34px; height: 34px; padding: 0; border-radius: 10px; }
.tool:disabled { opacity: .35; cursor: default; transform: none; background: transparent; }
#propBold.active { color: #1A1203; background: var(--gold); box-shadow: none; }

.prop { display: flex; align-items: center; gap: 6px; font-size: 12px; color: var(--muted); padding: 0 4px; transition: opacity .25s var(--ease); }
.prop.disabled { opacity: .3; pointer-events: none; }
.prop input[type=color] { width: 28px; height: 28px; padding: 0; border: 2px solid var(--border-2); border-radius: 50%; background: none; cursor: pointer; overflow: hidden; }
.prop input[type=color]::-webkit-color-swatch-wrapper { padding: 0; }
.prop input[type=color]::-webkit-color-swatch { border: 0; border-radius: 50%; }
.prop input[type=number], .pager input { width: 52px; height: 30px; padding: 0 6px; border-radius: 9px; border: 1px solid var(--border); background: var(--surface-2); text-align: center; font-variant-numeric: tabular-nums; }

/* #07 Range slider: gradient fill + floating value bubble */
.range-wrap { position: relative; display: inline-flex; align-items: center; }
input[type=range] { -webkit-appearance: none; appearance: none; width: 74px; height: 6px; border-radius: 6px; background: linear-gradient(90deg, var(--pink), var(--gold)) 0 / var(--fill, 50%) 100% no-repeat, var(--surface-3); cursor: pointer; }
input[type=range]::-webkit-slider-thumb { -webkit-appearance: none; width: 16px; height: 16px; border-radius: 50%; background: #fff; box-shadow: 0 0 0 3px rgba(232, 182, 76, .35), 0 2px 6px rgba(0,0,0,.35); transition: transform .2s var(--spring); }
input[type=range]::-moz-range-thumb { width: 16px; height: 16px; border: 0; border-radius: 50%; background: #fff; box-shadow: 0 0 0 3px rgba(232, 182, 76, .35); }
input[type=range]:active::-webkit-slider-thumb { transform: scale(1.25); }
.range-wrap output { position: absolute; left: 50%; bottom: calc(100% + 6px); transform: translate(-50%, 4px) scale(.85); opacity: 0; padding: 2px 7px; border-radius: 7px; font-size: 11px; font-weight: 600; color: #1A1203; background: var(--gold); pointer-events: none; transition: opacity .2s var(--ease), transform .3s var(--spring); white-space: nowrap; font-variant-numeric: tabular-nums; }
.range-wrap:hover output, .range-wrap.dragging output { opacity: 1; transform: translate(-50%, 0) scale(1); }

/* #35 Search: expands on focus */
.search-box { display: flex; align-items: center; gap: 6px; height: 34px; padding: 0 10px; width: 150px; border-radius: 11px; background: var(--surface-2); border: 1px solid var(--border); color: var(--muted); transition: width .35s var(--ease), border-color .2s, box-shadow .3s var(--ease); cursor: text; }
.search-box.open, .search-box:focus-within { width: 240px; border-color: var(--accent); box-shadow: 0 0 0 4px var(--accent-soft); color: var(--text); }
.search-box input { flex: 1; min-width: 0; height: 100%; border: 0; outline: none; background: transparent; }
.search-box input::-webkit-search-cancel-button { filter: grayscale(1); }
.search-count { font-size: 12px; color: var(--muted); min-width: 38px; text-align: center; font-variant-numeric: tabular-nums; }
.pager { display: flex; align-items: center; gap: 4px; font-variant-numeric: tabular-nums; color: var(--muted); }
.pager-sep { opacity: .6; }
#zoomSelect { height: 34px; padding: 0 8px; border-radius: 10px; border: 1px solid var(--border); background: var(--surface-2); min-width: 108px; cursor: pointer; }

/* ---------- layout ---------- */
.main { flex: 1; display: flex; min-height: 0; gap: 12px; padding: 12px; }
.sidebar { width: 236px; flex: none; background: var(--surface); border: 1px solid var(--border); border-radius: var(--r-card); display: flex; flex-direction: column; min-height: 0; overflow: hidden; box-shadow: var(--shadow); }
.side-head { display: flex; align-items: center; justify-content: space-between; padding: 14px 14px 8px; }
.count-pill { display: inline-block; min-width: 24px; padding: 1px 8px; margin-left: 4px; border-radius: 999px; font-size: 12px; text-align: center; color: var(--gold); background: rgba(232, 182, 76, .12); font-variant-numeric: tabular-nums; }
.chk-all { font-size: 12px; color: var(--muted); display: flex; gap: 6px; align-items: center; cursor: pointer; }
.side-actions { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; padding: 0 12px 8px; }
.btn-s { display: inline-flex; align-items: center; justify-content: center; gap: 6px; height: 32px; border: 1px solid var(--border); background: var(--surface-2); border-radius: 10px; padding: 0 8px; font-size: 12px; cursor: pointer; white-space: nowrap; transition: background .2s var(--ease), transform .15s var(--ease), border-color .2s; }
.btn-s:hover { background: var(--surface-3); border-color: var(--border-2); }
.btn-s:active { transform: scale(.96); }
.btn-s.danger { color: var(--pink); }
.btn-s.accent { grid-column: span 2; color: var(--gold); border-color: rgba(232, 182, 76, .35); background: rgba(232, 182, 76, .08); }
.btn-s.accent:hover { background: rgba(232, 182, 76, .16); }
.side-hint { font-size: 11px; color: var(--muted); padding: 0 14px 8px; line-height: 1.4; }
.thumbs { flex: 1; overflow-y: auto; padding: 6px 12px 20px; border-top: 1px solid var(--border); }
.thumb { position: relative; margin: 10px auto; width: 168px; padding: 8px; border-radius: 16px; border: 1.5px solid transparent; cursor: pointer; text-align: center; transition: background .2s var(--ease), border-color .2s var(--ease), transform .25s var(--ease); animation: rise .35s var(--ease) both; }
.thumb:hover { background: var(--surface-2); }
.thumb.current { border-color: var(--purple); background: var(--accent-soft); box-shadow: 0 0 0 4px rgba(139, 124, 255, .12); }
.thumb.checked { border-color: rgba(232, 182, 76, .7); background: rgba(232, 182, 76, .08); }
.thumb.drag-over-top { box-shadow: 0 -4px 0 0 var(--gold); }
.thumb.drag-over-bottom { box-shadow: 0 4px 0 0 var(--gold); }
.thumb.dragging { opacity: .35; transform: scale(.96); }
.thumb-img { display: flex; justify-content: center; align-items: center; min-height: 80px; }
.thumb-img img { max-width: 140px; max-height: 180px; border-radius: 6px; box-shadow: 0 4px 14px rgba(0,0,0,.35); background: #fff; animation: fadeIn .4s var(--ease) both; }
/* #15 Skeleton while the thumbnail renders */
.thumb-img .ph { width: 118px; height: 154px; border-radius: 8px; background: linear-gradient(100deg, var(--surface-2) 30%, var(--surface-3) 50%, var(--surface-2) 70%) 0 0 / 300% 100%; animation: shimmer 1.3s linear infinite; }
.thumb-foot { display: flex; align-items: center; justify-content: space-between; margin-top: 6px; font-size: 12px; color: var(--muted); font-variant-numeric: tabular-nums; }
.thumb-tools { position: absolute; top: 12px; right: 12px; display: flex; flex-direction: column; gap: 4px; opacity: 0; transform: translateX(4px); transition: opacity .2s var(--ease), transform .25s var(--ease); }
.thumb:hover .thumb-tools { opacity: 1; transform: none; }
.thumb-tools button { width: 26px; height: 26px; display: grid; place-items: center; border: 1px solid var(--border-2); background: var(--surface); color: var(--text); border-radius: 8px; cursor: pointer; padding: 0; box-shadow: 0 2px 8px rgba(0,0,0,.25); transition: background .2s, color .2s, transform .15s; }
.thumb-tools button:hover { background: var(--purple); color: #fff; transform: scale(1.08); }
.thumb-tools button:last-child:hover { background: var(--pink); }
.thumb-badge { position: absolute; top: 12px; left: 12px; color: #1A1203; background: var(--gold); font-size: 10px; font-weight: 600; border-radius: 6px; padding: 1px 6px; animation: pop .4s var(--spring); }
@keyframes shimmer { to { background-position: -300% 0; } }
@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }
@keyframes rise { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }

/* #04 Checkbox with drawn check */
input.cbx { -webkit-appearance: none; appearance: none; width: 18px; height: 18px; margin: 0; border-radius: 6px; border: 1.5px solid var(--border-2); background: var(--surface-2); display: inline-grid; place-items: center; cursor: pointer; transition: background .25s var(--ease), border-color .25s var(--ease), transform .2s var(--spring); }
input.cbx::after { content: ""; width: 5px; height: 9px; border: solid #1A1203; border-width: 0 2.2px 2.2px 0; transform: translateY(-1px) rotate(45deg) scale(0); transition: transform .3s var(--spring); }
input.cbx:checked { background: var(--gold); border-color: var(--gold); transform: scale(1.06); }
input.cbx:checked::after { transform: translateY(-1px) rotate(45deg) scale(1); }
input.cbx:indeterminate { background: var(--gold); border-color: var(--gold); }
input.cbx:indeterminate::after { width: 8px; height: 0; border-width: 0 0 2.2px 0; transform: none; }

/* #01 Toggle switch */
input.switch { -webkit-appearance: none; appearance: none; position: relative; flex: none; width: 38px; height: 22px; margin: 0; border-radius: 999px; background: var(--surface-3); border: 1px solid var(--border-2); cursor: pointer; vertical-align: middle; transition: background .3s var(--ease), box-shadow .3s var(--ease); }
input.switch::after { content: ""; position: absolute; top: 2px; left: 2px; width: 16px; height: 16px; border-radius: 999px; background: #fff; box-shadow: 0 1px 4px rgba(0,0,0,.3); transition: transform .35s var(--spring), width .2s var(--ease); }
input.switch:active::after { width: 21px; }
input.switch:checked { background: var(--green); border-color: transparent; box-shadow: 0 0 12px rgba(61, 220, 132, .45); }
input.switch:checked::after { transform: translateX(16px); }
input.switch:checked:active::after { transform: translateX(11px); }

/* ---------- viewer ---------- */
.viewer { flex: 1; overflow: auto; position: relative; outline: none; background: var(--viewer); border-radius: var(--r-card); border: 1px solid var(--border); }
.viewer.drop-hover { box-shadow: inset 0 0 0 3px var(--gold), 0 0 40px rgba(232, 182, 76, .25); }
.pages { display: flex; flex-direction: column; align-items: center; padding: 26px 26px 70px; gap: 6px; min-width: min-content; }
.page-outer { display: flex; flex-direction: column; align-items: center; animation: rise .4s var(--ease) both; }
.page-wrap { position: relative; background: #fff; box-shadow: var(--paper-shadow); overflow: hidden; border-radius: 3px; }
.page-wrap canvas.page-canvas { position: absolute; left: 0; top: 0; display: block; }
.page-label { font-size: 11.5px; color: var(--muted); margin: 8px 0 14px; font-variant-numeric: tabular-nums; }
.annot-layer { position: absolute; left: 0; top: 0; transform-origin: 0 0; touch-action: none; }
.viewer[data-tool=text] .annot-layer { cursor: text; }
.viewer[data-tool=whiteout] .annot-layer, .viewer[data-tool=redact] .annot-layer,
.viewer[data-tool=highlight] .annot-layer, .viewer[data-tool=pen] .annot-layer { cursor: crosshair; }

.annot { position: absolute; }
.viewer[data-tool=select] .annot { cursor: move; }
.annot.selected { outline: 1.5px dashed var(--sel); outline-offset: 2px; }
.annot-text { white-space: pre; line-height: 1.3; font-family: "Sarabun", sans-serif; min-width: 8px; padding: 0; outline: none; }
.annot-text.editing { outline: 2px solid var(--sel); outline-offset: 2px; cursor: text; background: rgba(255,255,255,.4); border-radius: 2px; }
.annot-text:empty::before { content: "พิมพ์ข้อความ..."; color: #9aa0a6; }
.annot-hl { mix-blend-mode: multiply; }
.annot-img img { width: 100%; height: 100%; display: block; pointer-events: none; user-select: none; }
.annot-ink { overflow: visible; pointer-events: none; }
.annot-ink path.hit { pointer-events: stroke; stroke: transparent; }
.handle { position: absolute; width: 12px; height: 12px; right: -8px; bottom: -8px; background: #fff; border: 2px solid var(--sel); border-radius: 4px; cursor: nwse-resize; z-index: 3; }
.annot-del { position: absolute; top: -28px; right: -8px; width: 24px; height: 24px; display: grid; place-items: center; border-radius: 50%; border: 0; background: var(--pink); color: #fff; cursor: pointer; padding: 0; z-index: 3; box-shadow: 0 3px 10px rgba(255, 92, 138, .5); animation: pop .3s var(--spring); }
.draft-rect { position: absolute; border: 1px dashed var(--sel); pointer-events: none; }

/* ---------- empty state ---------- */
.empty { position: absolute; inset: 0; display: flex; align-items: center; justify-content: center; padding: 20px; }
.empty-card { position: relative; text-align: center; max-width: 560px; padding: 44px 48px 34px; border-radius: 28px; background: var(--surface); border: 1px solid var(--border); box-shadow: var(--shadow); animation: rise .5s var(--ease) both; }
.empty-card::before { content: ""; position: absolute; inset: -1px; border-radius: inherit; padding: 1px; background: linear-gradient(135deg, rgba(139,124,255,.7), rgba(255,92,138,.4), rgba(232,182,76,.6)); -webkit-mask: linear-gradient(#000 0 0) content-box, linear-gradient(#000 0 0); -webkit-mask-composite: xor; mask-composite: exclude; pointer-events: none; }
/* #24 Cloud upload icon */
.empty-icon { position: relative; width: 84px; height: 84px; margin: 0 auto 14px; border-radius: 26px; display: grid; place-items: center; color: var(--purple); background: var(--accent-soft); }
.empty-icon .cloud { position: absolute; }
.empty-icon .arrow { position: absolute; top: 34px; color: var(--gold); animation: lift 1.6s var(--ease) infinite; }
@keyframes lift { 0% { transform: translateY(8px); opacity: 0; } 30% { opacity: 1; } 70% { opacity: 1; } 100% { transform: translateY(-10px); opacity: 0; } }
.empty-card h2 { margin: 6px 0 6px; font-size: 22px; font-weight: 600; }
.empty-card p { margin: 4px 0 18px; }
.empty-feats { display: flex; flex-wrap: wrap; gap: 8px; justify-content: center; margin: 22px 0 8px; }
.empty-feats span { display: inline-flex; align-items: center; gap: 6px; padding: 5px 11px; border-radius: 999px; font-size: 12px; color: var(--muted); background: var(--surface-2); border: 1px solid var(--border); }
.small-note { display: inline-flex; align-items: center; gap: 6px; font-size: 12px; margin-top: 10px !important; color: var(--green); }

/* ---------- status bar ---------- */
.statusbar { display: flex; align-items: center; gap: 8px; padding: 0 18px 10px; font-size: 12px; color: var(--muted); }
/* #29 live dot */
.live-dot { width: 8px; height: 8px; border-radius: 50%; background: var(--green); box-shadow: 0 0 0 0 rgba(61, 220, 132, .6); animation: livePulse 2s ease-out infinite; }
@keyframes livePulse { 0% { box-shadow: 0 0 0 0 rgba(61, 220, 132, .55); } 70% { box-shadow: 0 0 0 8px rgba(61, 220, 132, 0); } 100% { box-shadow: 0 0 0 0 rgba(61, 220, 132, 0); } }

/* ---------- modal ---------- */
.modal { position: fixed; inset: 0; background: rgba(3, 6, 16, .55); backdrop-filter: blur(6px); -webkit-backdrop-filter: blur(6px); display: flex; align-items: center; justify-content: center; z-index: 50; padding: 16px; animation: fadeIn .25s var(--ease) both; }
.modal-card { background: var(--surface); color: var(--text); border: 1px solid var(--border); border-radius: var(--r-card); padding: 22px 24px; width: min(680px, 100%); box-shadow: 0 24px 70px rgba(0,0,0,.5); max-height: 94vh; overflow: auto; animation: modalIn .4s var(--spring) both; }
@keyframes modalIn { from { opacity: 0; transform: translateY(12px) scale(.96); } to { opacity: 1; transform: none; } }
.modal-card.narrow { width: min(480px, 100%); }
.modal-card.wide { width: min(900px, 100%); }
.modal-card h3 { display: flex; align-items: center; gap: 10px; margin: 0 0 6px; font-size: 18px; font-weight: 600; }
.modal-card h3 > .ic { color: var(--gold); }
#signCanvas { width: 100%; aspect-ratio: 3 / 1; border: 1px solid var(--border-2); border-radius: 16px; background: #fff; touch-action: none; cursor: crosshair; background-image: linear-gradient(transparent calc(75% - 1px), #c7cdd6 calc(75% - 1px), #c7cdd6 75%, transparent 75%); }
.modal-row { display: flex; align-items: center; gap: 10px; margin: 12px 0; flex-wrap: wrap; }
.modal-row .range-prop { display: inline-flex; align-items: center; gap: 8px; color: var(--muted); font-size: 13px; }
.modal-actions { display: flex; gap: 8px; margin-top: 18px; align-items: center; }
.ink-swatch { width: 26px; height: 26px; border-radius: 50%; border: 2px solid var(--surface); box-shadow: 0 0 0 1px var(--border-2); cursor: pointer; padding: 0; transition: transform .25s var(--spring), box-shadow .2s; }
.ink-swatch:hover { transform: scale(1.1); }
.ink-swatch.active { box-shadow: 0 0 0 2px var(--gold); transform: scale(1.12); }
.field { display: flex; flex-direction: column; gap: 6px; margin: 12px 0; font-size: 13px; color: var(--muted); }
.field input[type=text], .field input[type=password], .field input[type=number], .field select { height: 40px; padding: 0 12px; border-radius: 12px; border: 1px solid var(--border); background: var(--surface-2); color: var(--text); font-size: 14px; transition: border-color .2s, box-shadow .3s var(--ease); }
.field input:focus, .field select:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 4px var(--accent-soft); }
.field input[type=color] { height: 40px; width: 72px; padding: 3px; border-radius: 12px; border: 1px solid var(--border); background: var(--surface-2); }
.field small { font-size: 12px; }
.check { display: flex; gap: 12px; align-items: flex-start; margin: 12px 0; line-height: 1.5; cursor: pointer; }
.check input { margin-top: 3px; }
/* #22 Error shake */
.field input.invalid { border-color: var(--red) !important; box-shadow: 0 0 0 4px rgba(255, 92, 92, .15) !important; }
.shake { animation: shake .45s var(--ease); }
@keyframes shake { 0%, 100% { transform: translateX(0); } 20% { transform: translateX(-7px); } 40% { transform: translateX(6px); } 60% { transform: translateX(-4px); } 80% { transform: translateX(3px); } }
.field-error { color: var(--red); animation: rise .3s var(--ease) both; }

/* ---------- busy overlay: #13 spinner / #17 progress ring ---------- */
.busy { position: fixed; inset: 0; background: rgba(3, 6, 16, .45); backdrop-filter: blur(4px); -webkit-backdrop-filter: blur(4px); display: flex; align-items: center; justify-content: center; z-index: 60; animation: fadeIn .2s var(--ease) both; }
.busy-card { display: flex; flex-direction: column; align-items: center; gap: 14px; min-width: 260px; max-width: 420px; padding: 26px 30px; border-radius: var(--r-card); background: var(--surface); border: 1px solid var(--border); box-shadow: var(--shadow); text-align: center; animation: modalIn .35s var(--spring) both; }
#busyText { font-size: 14px; line-height: 1.5; }
.ring { position: relative; width: 76px; height: 76px; }
.ring svg { width: 100%; height: 100%; transform: rotate(-90deg); filter: drop-shadow(0 0 8px rgba(139, 124, 255, .45)); }
.ring circle { fill: none; stroke-width: 6; stroke-linecap: round; }
.ring-bg { stroke: var(--surface-3); }
.ring-fg { stroke: url(#ringGrad); transition: stroke-dashoffset .5s var(--ease); }
.ring.indeterminate svg { animation: spin 1s linear infinite; }
.ring-pct { position: absolute; inset: 0; display: grid; place-items: center; font-weight: 600; font-size: 15px; font-variant-numeric: tabular-nums; }
@keyframes spin { to { transform: rotate(270deg); } }
.ring.indeterminate svg { transform-origin: 50% 50%; }
@keyframes spinFull { from { transform: rotate(-90deg); } to { transform: rotate(270deg); } }
.ring.indeterminate svg { animation: spinFull .9s linear infinite; }

/* ---------- #18 Toast ---------- */
.toast { display: none !important; }
.toast-zone { position: fixed; top: 140px; left: 50%; transform: translateX(-50%); z-index: 70; display: flex; flex-direction: column; gap: 8px; align-items: center; pointer-events: none; width: max-content; max-width: min(640px, 92vw); }
.toast-item { position: relative; display: flex; align-items: center; gap: 10px; padding: 12px 16px 14px; border-radius: 16px; background: var(--surface); color: var(--text); border: 1px solid var(--border-2); box-shadow: 0 14px 40px rgba(0,0,0,.45); overflow: hidden; pointer-events: auto; cursor: pointer; animation: toastIn .45s var(--spring) both; line-height: 1.45; }
.toast-item.leaving { animation: toastOut .25s var(--ease) both; }
.toast-item > .ic { color: var(--purple); }
.toast-item.success > .ic { color: var(--green); }
.toast-item.error > .ic { color: var(--pink); }
.toast-item.error { border-color: rgba(255, 92, 138, .45); }
.toast-timer { position: absolute; left: 0; bottom: 0; height: 3px; width: 100%; background: linear-gradient(90deg, var(--purple), var(--gold)); transform-origin: left; animation: timer var(--life, 3s) linear both; }
.toast-item.success .toast-timer { background: var(--green); }
.toast-item.error .toast-timer { background: var(--pink); }
@keyframes toastIn { from { opacity: 0; transform: translateY(-16px) scale(.96); } to { opacity: 1; transform: none; } }
@keyframes toastOut { to { opacity: 0; transform: translateY(-10px) scale(.97); } }
@keyframes timer { from { transform: scaleX(1); } to { transform: scaleX(0); } }

/* ---------- layers added by features ---------- */
.form-layer, .extra-layer { position: absolute; left: 0; top: 0; transform-origin: 0 0; pointer-events: none; }
.form-layer { z-index: 1; }
.annot-layer { z-index: 2; }
.extra-layer { z-index: 3; }
.stamp-layer { position: absolute; left: 0; top: 0; z-index: 4; pointer-events: none; overflow: hidden; }
.viewer[data-tool=select] .annot-layer { pointer-events: none; }
.viewer[data-tool=select] .annot-layer .annot { pointer-events: auto; }
.viewer[data-tool=select] .annot-layer .annot-ink { pointer-events: none; }
.form-field { position: absolute; pointer-events: auto; box-sizing: border-box; border: 1px solid rgba(108, 92, 231, .6); background: rgba(214, 220, 255, .55); font-family: "Sarabun", sans-serif; padding: 0 2px; margin: 0; color: #000; border-radius: 2px; }
.form-field:focus { outline: 2px solid var(--purple); background: rgba(255,255,255,.92); }
textarea.form-field { resize: none; line-height: 1.2; }
input[type=checkbox].form-field, input[type=radio].form-field { appearance: auto; accent-color: #6C5CE7; }
.form-field:disabled { background: rgba(230,230,230,.5); }
.orig-img-box { position: absolute; pointer-events: auto; cursor: move; border: 1.5px dashed transparent; border-radius: 2px; transition: border-color .2s, background .2s; }
.orig-img-box:hover { border-color: var(--purple); background: rgba(139, 124, 255, .08); }
.viewer[data-tool=edittext] .orig-img-box { border-color: rgba(139, 124, 255, .5); }
.edit-line { position: absolute; pointer-events: auto; cursor: text; border: 1px dashed transparent; border-radius: 3px; transition: border-color .2s, background .2s; }
.edit-line:hover { border-color: var(--purple); background: rgba(139, 124, 255, .1); }
.search-hit { position: absolute; background: rgba(232, 182, 76, .45); mix-blend-mode: multiply; border-radius: 2px; }
.search-hit.current { background: rgba(255, 92, 138, .45); outline: 2px solid var(--pink); }
.stamp { position: absolute; white-space: pre; font-family: "Sarabun", sans-serif; transform-origin: center center; line-height: 1.3; }
.annot-field { border: 1.5px dashed #7B61FF; background: rgba(123, 97, 255, .08); display: flex; align-items: center; padding-left: 3px; color: #6C4DFF; overflow: hidden; }
.viewer[data-tool=edittext] .annot-layer, .viewer[data-tool=fieldtext] .annot-layer, .viewer[data-tool=fieldcheck] .annot-layer { cursor: crosshair; }

/* ---------- menu ---------- */
.menu-wrap { position: relative; }
.menu { position: absolute; top: calc(100% + 8px); left: 0; z-index: 40; background: var(--surface); color: var(--text); border: 1px solid var(--border-2); border-radius: 18px; box-shadow: 0 20px 60px rgba(0,0,0,.45); padding: 8px; min-width: 330px; max-height: 80vh; overflow: auto; transform-origin: top left; animation: menuIn .3s var(--spring) both; }
@keyframes menuIn { from { opacity: 0; transform: translateY(-6px) scale(.97); } to { opacity: 1; transform: none; } }
.menu button { display: flex; align-items: center; gap: 10px; width: 100%; text-align: left; border: 0; background: transparent; padding: 9px 10px; border-radius: 11px; cursor: pointer; font-size: 14px; transition: background .15s var(--ease), transform .2s var(--ease); }
.menu button > .ic { color: var(--muted); transition: color .2s; }
.menu button:hover { background: var(--accent-soft); transform: translateX(2px); }
.menu button:hover > .ic { color: var(--purple); }
.menu-title { font-size: 11px; color: var(--muted); padding: 10px 10px 4px; letter-spacing: .4px; }

/* ---------- result / diff / misc modals ---------- */
.result-body { max-height: 60vh; overflow: auto; border: 1px solid var(--border); border-radius: 16px; padding: 12px 14px; background: var(--surface-2); white-space: pre-wrap; font-size: 14px; line-height: 1.6; }
.diff-add { background: rgba(61, 220, 132, .14); color: var(--green); display: block; border-radius: 4px; padding: 0 4px; }
.diff-del { background: rgba(255, 92, 138, .13); color: var(--pink); display: block; border-radius: 4px; padding: 0 4px; }
.diff-page { display: block; font-weight: 600; margin-top: 10px; color: var(--muted); }
.fs { border: 1px solid var(--border); border-radius: 16px; margin: 12px 0; padding: 8px 14px; }
.fs legend { padding: 0 6px; font-weight: 600; }
.fs legend label { display: inline-flex; align-items: center; gap: 8px; cursor: pointer; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 0 14px; }
.grid2 .field { margin: 6px 0; }
.perm-row { display: flex; gap: 16px; flex-wrap: wrap; margin: 10px 0; }
.perm-row label { display: inline-flex; align-items: center; gap: 8px; cursor: pointer; }
.pw-box { margin: 12px 0; border: 1px solid var(--border); border-radius: 16px; padding: 10px 14px; background: var(--surface-2); }
.pw-box summary { display: flex; align-items: center; gap: 8px; cursor: pointer; font-weight: 500; list-style: none; }
.pw-box summary::-webkit-details-marker { display: none; }
.pw-box summary > .ic { color: var(--gold); }

/* #09 Copy */
.copy-btn { overflow: hidden; }
.copy-swap { position: relative; display: inline-grid; }
.copy-swap > span { grid-area: 1 / 1; display: inline-flex; align-items: center; gap: 8px; transition: transform .35s var(--spring), opacity .25s var(--ease); }
.copy-swap .b { transform: translateY(120%); opacity: 0; color: var(--green); }
.copy-btn.copied { border-color: rgba(61, 220, 132, .5); }
.copy-btn.copied .a { transform: translateY(-120%); opacity: 0; }
.copy-btn.copied .b { transform: none; opacity: 1; }

/* ---------- responsive ---------- */
@media (max-width: 1500px) {
  .tool span { display: none; }
  .tool { min-width: 40px; height: 40px; }
  .doc-name { display: none; }
}
@media (max-width: 1100px) {
  .secure-badge span, .file-group .btn span { display: none; }
  .sidebar { width: 196px; }
  .thumb { width: 150px; }
  .search-box { width: 120px; }
  .search-box.open, .search-box:focus-within { width: 180px; }
}

/* ---------- reduced motion ---------- */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .01ms !important; animation-iteration-count: 1 !important; transition-duration: .01ms !important; scroll-behavior: auto !important; }
  .ring.indeterminate svg { animation: none !important; }
}
