/* Layout: a sales binder — sticky header, index-tabbed media panel beside a notice board; phones stack notices first */
:root{
  --bg:#eef1f4; --surface:#ffffff; --surface-2:#e2e7ec; --ink:#14212b; --muted:#566571; --line:#d2d9e0;
  --accent:#1d4ed8; --accent-ink:#ffffff; --accent-soft:#e1e8fb;
  --tag:#ffd23f; --tag-ink:#2b2200;
  --urgent:#b42318; --urgent-soft:#fcebe8; --info:#0b6b66; --info-soft:#dff1ef;
  --paper:#ffffff; --stage:#12181d; --stage-2:#1c242b; --stage-line:#2b353d; --stage-ink:#e8eef2; --stage-muted:#9aa8b2;
  --scrim:rgba(10,16,22,.62);
  --shadow:0 1px 2px rgba(20,33,43,.06),0 6px 18px rgba(20,33,43,.08);
  --f-display:"Bai Jamjuree","IBM Plex Sans Thai Looped","Leelawadee UI",Tahoma,system-ui,sans-serif;
  --f-body:"IBM Plex Sans Thai Looped","Noto Sans Thai","Leelawadee UI",Tahoma,system-ui,sans-serif;
  --f-mono:"IBM Plex Mono",ui-monospace,"Cascadia Mono",Consolas,monospace;
  color-scheme:light;
}
@media (prefers-color-scheme: dark){
  :root{
    --bg:#0e1419; --surface:#161f26; --surface-2:#1f2a33; --ink:#e6edf2; --muted:#94a3ae; --line:#2b3842;
    --accent:#7ea4ff; --accent-ink:#0a1430; --accent-soft:#1c2a4c;
    --urgent:#ff8b7b; --urgent-soft:#341c19; --info:#62d3c8; --info-soft:#12302e;
    --scrim:rgba(0,0,0,.72); --shadow:0 1px 2px rgba(0,0,0,.3),0 8px 22px rgba(0,0,0,.3);
    color-scheme:dark;
  }
}
*,*::before,*::after{box-sizing:border-box}
[hidden]{display:none!important}
html{-webkit-text-size-adjust:100%}
html.locked,html.locked body{overflow:hidden}
body{margin:0;background:var(--bg);color:var(--ink);font-family:var(--f-body);font-size:15px;line-height:1.6;-webkit-font-smoothing:antialiased;padding-bottom:env(safe-area-inset-bottom,0px)}
img{max-width:100%}
h1,h2,h3{font-family:var(--f-display);margin:0;line-height:1.3;text-wrap:balance}
a{color:var(--accent)}
button,input,select,textarea{font:inherit;color:inherit}
:focus-visible{outline:2px solid var(--accent);outline-offset:2px}
.sr-only{position:absolute;width:1px;height:1px;overflow:hidden;clip:rect(0 0 0 0);white-space:nowrap}
.wrap{max-width:1240px;margin-inline:auto;padding-inline:clamp(16px,3vw,32px)}
svg{flex:none}

/* header */
.top{position:sticky;top:0;z-index:20;background:var(--bg);background:color-mix(in srgb,var(--bg) 90%,transparent);-webkit-backdrop-filter:blur(10px);backdrop-filter:blur(10px);border-bottom:1px solid var(--line);padding-top:env(safe-area-inset-top,0px)}
.top-in{display:flex;flex-wrap:wrap;align-items:center;gap:12px 20px;padding-block:14px}
.brand{display:flex;flex-direction:column;margin-right:auto;min-width:0;color:inherit;text-decoration:none}
.eyebrow{font-family:var(--f-mono);font-size:11px;letter-spacing:.16em;text-transform:uppercase;color:var(--muted)}
.brand-name{font-family:var(--f-display);font-size:25px;font-weight:700;line-height:1.25;letter-spacing:-.005em}
.search{position:relative;flex:1 1 260px;max-width:400px}
.search svg{position:absolute;left:12px;top:50%;translate:0 -50%;width:18px;height:18px;color:var(--muted);pointer-events:none}
.search input{width:100%;height:42px;border-radius:10px;border:1px solid var(--line);background:var(--surface);padding:0 12px 0 38px}
.search input::placeholder{color:var(--muted)}
.admin-bar{display:flex;flex-wrap:wrap;align-items:center;gap:8px}
.btn{display:inline-flex;align-items:center;justify-content:center;gap:8px;height:40px;padding:0 14px;border-radius:10px;border:1px solid var(--line);background:var(--surface);cursor:pointer;font-weight:500;white-space:nowrap;text-decoration:none;color:var(--ink);transition:border-color .15s,filter .15s}
.btn:hover{border-color:var(--muted)}
.btn svg{width:18px;height:18px}
.btn.primary{background:var(--accent);color:var(--accent-ink);border-color:transparent}
.btn.primary:hover{filter:brightness(1.08)}
.btn.danger{color:var(--urgent);border-color:currentColor;background:transparent}
.btn.danger.solid{background:var(--urgent);color:var(--surface);border-color:transparent}
.btn[disabled]{opacity:.55;cursor:not-allowed}
.switch{display:inline-flex;align-items:center;gap:8px;font-size:13px;color:var(--muted);cursor:pointer;padding-left:4px}
.switch input{appearance:none;-webkit-appearance:none;margin:0;width:34px;height:20px;border-radius:999px;background:var(--line);position:relative;cursor:pointer;transition:background .15s}
.switch input::after{content:"";position:absolute;top:2px;left:2px;width:16px;height:16px;border-radius:50%;background:var(--surface);box-shadow:0 1px 2px rgba(0,0,0,.25);transition:translate .15s}
.switch input:checked{background:var(--accent)}
.switch input:checked::after{translate:14px 0}
.banner{margin:20px 0 0;padding:12px 16px;border:1px dashed var(--line);border-radius:12px;background:var(--surface);color:var(--muted)}
.banner.warn{border-style:solid;border-color:color-mix(in srgb,var(--urgent) 40%,var(--line));background:var(--urgent-soft);color:var(--ink)}

/* layout */
.layout{display:grid;grid-template-columns:minmax(0,1fr) minmax(280px,340px);grid-template-areas:"lib board";gap:28px;padding-block:24px 40px;align-items:start}
.library{grid-area:lib;min-width:0}
.board{grid-area:board;min-width:0}
.sec-head{display:flex;flex-wrap:wrap;align-items:center;gap:8px 12px;margin-bottom:12px;min-height:34px}
.sec-head h2{font-size:20px;font-weight:600;display:inline-flex;align-items:center;gap:8px}
.sec-head h2 svg{width:20px;height:20px;color:var(--accent)}
.count{font-family:var(--f-mono);font-size:12px;color:var(--muted);font-variant-numeric:tabular-nums}
.seg{margin-left:auto;display:inline-flex;border:1px solid var(--line);border-radius:9px;padding:2px;background:var(--surface)}
.seg button{border:0;background:transparent;padding:3px 12px;border-radius:7px;font-size:13px;cursor:pointer;color:var(--muted)}
.seg button[aria-pressed="true"]{background:var(--accent-soft);color:var(--ink);font-weight:600}
.foot{display:flex;flex-wrap:wrap;align-items:center;gap:8px 20px;padding-block:0 40px;font-size:13px;color:var(--muted)}
.foot a{color:var(--muted)}
.inline{display:inline}

/* index tabs over the panel, like a binder divider */
.tabs-wrap{overflow-x:auto;scrollbar-width:thin;margin-bottom:-1px;position:relative;z-index:1}
.tabs{display:flex;gap:4px;padding-inline:8px;width:max-content;min-width:100%}
.tab{display:inline-flex;align-items:baseline;gap:7px;border:1px solid var(--line);border-bottom-color:transparent;background:var(--surface-2);color:var(--muted);padding:7px 14px 6px;border-radius:10px 10px 0 0;font-size:14px;cursor:pointer;white-space:nowrap}
.tab .n{font-family:var(--f-mono);font-size:11px;font-variant-numeric:tabular-nums}
.tab:hover{color:var(--ink)}
.tab[aria-selected="true"]{background:var(--surface);color:var(--ink);font-weight:600;border-bottom-color:var(--surface)}
.panel{background:var(--surface);border:1px solid var(--line);border-radius:0 12px 12px 12px;padding:16px}
.grid{display:grid;grid-template-columns:repeat(auto-fill,minmax(200px,1fr));gap:16px}

/* media card */
.card{position:relative;min-width:0}
.card-open{display:flex;flex-direction:column;width:100%;height:100%;text-align:left;border:1px solid var(--line);border-radius:10px;background:var(--surface);padding:0;cursor:pointer;overflow:hidden;transition:border-color .15s,box-shadow .15s,transform .15s}
.card-open:hover{border-color:var(--accent);box-shadow:var(--shadow);transform:translateY(-2px)}
.thumb{position:relative;aspect-ratio:4/3;max-width:100%;background:var(--surface-2);overflow:hidden;border-bottom:1px solid var(--line)}
.thumb img{display:block;width:100%;height:100%;object-fit:cover;object-position:top center}
.thumb.is-image img{object-position:center}
.thumb .ph{position:absolute;inset:0;display:grid;place-items:center;color:var(--muted)}
.thumb .ph svg{width:40px;height:40px;opacity:.7}
.chip-kind{position:absolute;left:8px;top:8px;font-size:11.5px;font-weight:600;letter-spacing:.04em;padding:1px 8px;border-radius:6px;background:var(--ink);color:var(--bg)}
.chip-new{position:absolute;right:8px;top:8px;font-size:12px;font-weight:600;padding:1px 8px;border-radius:6px;background:var(--tag);color:var(--tag-ink)}
.c-body{display:flex;flex-direction:column;gap:3px;padding:10px 12px 12px;min-width:0;flex:1}
.c-body h3{font-size:15px;font-weight:600;display:-webkit-box;-webkit-line-clamp:2;-webkit-box-orient:vertical;overflow:hidden}
.c-meta{margin:0;display:flex;flex-wrap:wrap;align-items:center;gap:2px 8px;font-size:12.5px;color:var(--muted)}
.c-facts{margin:0;margin-top:auto;padding-right:36px;font-family:var(--f-mono);font-size:11.5px;color:var(--muted);font-variant-numeric:tabular-nums}
.pin{display:inline-flex;align-items:center;gap:3px;color:var(--accent);font-weight:600}
.pin svg{width:13px;height:13px}
.icon-btn{width:32px;height:32px;display:inline-grid;place-items:center;border-radius:8px;border:1px solid var(--line);background:var(--surface);cursor:pointer;color:var(--muted);padding:0}
.icon-btn:hover{color:var(--ink);border-color:var(--muted)}
.icon-btn svg{width:16px;height:16px}
.card-edit{position:absolute;right:8px;bottom:8px}

/* notices */
.notices{list-style:none;margin:0;padding:0;display:flex;flex-direction:column;gap:10px}
.notice{display:flex;flex-direction:column;gap:5px;background:var(--surface);border:1px solid var(--line);border-radius:12px;padding:12px 14px}
.notice.lvl-urgent{background:var(--urgent-soft);border-color:color-mix(in srgb,var(--urgent) 40%,var(--line))}
.notice.expired{opacity:.6}
.n-top{display:flex;flex-wrap:wrap;align-items:center;gap:6px 8px;font-size:12px;color:var(--muted);min-height:24px}
.pill{font-size:11.5px;font-weight:600;line-height:1.6;padding:0 8px;border-radius:999px;border:1px solid currentColor}
.pill.urgent{color:var(--urgent)} .pill.normal{color:var(--accent)} .pill.info{color:var(--info)} .pill.expired{color:var(--muted)}
.tag-new{background:var(--tag);color:var(--tag-ink);font-weight:600;padding:0 7px;border-radius:5px;line-height:1.6}
.n-time{margin-left:auto;font-family:var(--f-mono);font-size:11.5px;font-variant-numeric:tabular-nums}
.n-top .icon-btn{width:26px;height:26px}
.n-top .icon-btn svg{width:14px;height:14px}
.notice h3{font-size:16px;font-weight:600}
.n-body{margin:0;font-size:14px;white-space:pre-wrap;overflow-wrap:anywhere}
.n-body.clamp{display:-webkit-box;-webkit-line-clamp:3;-webkit-box-orient:vertical;overflow:hidden}
.n-until{font-size:12px;color:var(--muted)}
.linkbtn{align-self:flex-start;border:0;background:none;padding:0;color:var(--accent);cursor:pointer;font-size:13px;font-weight:600}
.foot .linkbtn{color:var(--muted);font-weight:400;text-decoration:underline}
.more{margin-top:10px}

.empty{grid-column:1/-1;display:flex;flex-direction:column;align-items:center;gap:4px;padding:28px 16px;text-align:center;color:var(--muted);border:1px dashed var(--line);border-radius:12px;list-style:none}
.empty strong{font-family:var(--f-display);font-size:16px;color:var(--ink)}

/* viewer: always a dark stage so pages read like paper on a desk */
.viewer{position:fixed;inset:0;z-index:50;display:flex;flex-direction:column;background:var(--stage);color:var(--stage-ink);padding-top:env(safe-area-inset-top,0px);padding-bottom:env(safe-area-inset-bottom,0px)}
.v-bar{display:flex;flex-wrap:wrap;align-items:center;gap:10px 16px;padding:10px 16px;border-bottom:1px solid var(--stage-line)}
.v-info{flex:1 1 260px;min-width:0}
.v-info h2{font-size:17px;font-weight:600;white-space:nowrap;overflow:hidden;text-overflow:ellipsis}
.v-info p{margin:0;font-size:12.5px;color:var(--stage-muted)}
.v-tools{display:flex;flex-wrap:wrap;align-items:center;gap:6px}
.v-btn{display:inline-flex;align-items:center;justify-content:center;gap:6px;height:36px;min-width:36px;padding:0 10px;border-radius:8px;border:1px solid var(--stage-line);background:var(--stage-2);color:var(--stage-ink);cursor:pointer;text-decoration:none;font-size:14px}
.v-btn:hover{border-color:var(--stage-muted)}
.v-btn svg{width:17px;height:17px}
.v-num{font-family:var(--f-mono);font-size:12.5px;color:var(--stage-muted);font-variant-numeric:tabular-nums;min-width:52px;text-align:center}
.v-sep{width:1px;height:22px;background:var(--stage-line);margin-inline:4px}
.v-desc{margin:0;padding:8px 16px;font-size:13.5px;color:var(--stage-muted);border-bottom:1px solid var(--stage-line);white-space:pre-wrap;max-height:30vh;overflow:auto}
.v-body{flex:1;min-height:0;overflow:auto;position:relative;overscroll-behavior:contain}
.v-pages{display:flex;flex-direction:column;gap:14px;padding:16px;width:max-content;min-width:100%}
.pg{margin-inline:auto;background:var(--paper);box-shadow:0 2px 12px rgba(0,0,0,.45)}
.pg canvas{display:block;width:100%;height:100%}
.v-img-wrap{display:grid;place-items:center;padding:16px;width:max-content;min-width:100%;min-height:100%}
.v-img{display:block;max-width:none;box-shadow:0 2px 12px rgba(0,0,0,.45);background:var(--paper)}
.v-msg{position:absolute;inset:0;display:flex;flex-direction:column;align-items:center;justify-content:center;gap:8px;padding:16px;text-align:center;color:var(--stage-muted)}
.v-msg strong{color:var(--stage-ink);font-family:var(--f-display);font-size:17px}
.spin{width:28px;height:28px;border-radius:50%;border:3px solid var(--stage-line);border-top-color:var(--stage-ink);animation:spin .8s linear infinite}
@keyframes spin{to{transform:rotate(360deg)}}

/* forms */
.sheet-wrap{position:fixed;inset:0;z-index:60;display:grid;place-items:center;padding:calc(16px + env(safe-area-inset-top,0px)) 16px calc(16px + env(safe-area-inset-bottom,0px));background:var(--scrim)}
.sheet{width:100%;max-width:560px;max-height:100%;overflow:auto;background:var(--surface);border:1px solid var(--line);border-radius:14px;box-shadow:var(--shadow)}
.sheet form{display:flex;flex-direction:column;gap:14px;padding:20px}
.sheet h2{font-size:19px;font-weight:600}
.sheet h3{font-size:15px;font-weight:600;margin-top:4px}
.field{display:flex;flex-direction:column;gap:5px;min-width:0}
.field>label{font-size:13px;font-weight:600}
.field input,.field textarea,.field select,.up-main input{width:100%;border:1px solid var(--line);border-radius:9px;background:var(--bg);padding:8px 11px}
.field textarea{min-height:100px;resize:vertical}
.hint{font-size:12px;color:var(--muted);margin:0}
.row{display:flex;flex-wrap:wrap;gap:12px}
.row>.field{flex:1 1 180px}
.check{display:flex;align-items:center;gap:8px;font-size:14px;cursor:pointer}
.check input{width:18px;height:18px;accent-color:var(--accent);margin:0}
.radio-list{display:flex;flex-direction:column;gap:6px}
.actions{display:flex;flex-wrap:wrap;align-items:center;justify-content:flex-end;gap:8px}
.actions .left{margin-right:auto}
.form-err{margin:0;padding:8px 12px;border-radius:9px;background:var(--urgent-soft);color:var(--urgent);font-size:13.5px}
.confirm{display:flex;flex-direction:column;gap:10px;padding:12px 14px;border-radius:10px;background:var(--urgent-soft)}
.confirm .actions{justify-content:flex-start}
.divider{border:0;border-top:1px solid var(--line);margin:4px 0}
.drop{display:flex;flex-direction:column;align-items:center;gap:4px;padding:22px 16px;border:2px dashed var(--line);border-radius:12px;text-align:center;color:var(--muted);cursor:pointer;transition:border-color .15s,background .15s}
.drop svg{width:26px;height:26px;color:var(--accent)}
.drop strong{color:var(--ink)}
.drop.over,.drop:hover{border-color:var(--accent);background:var(--accent-soft)}
.up-list{display:flex;flex-direction:column;gap:8px}
.up-list:empty{display:none}
.up-row{display:grid;grid-template-columns:auto minmax(0,1fr) auto;align-items:center;gap:10px;padding:8px 10px;border:1px solid var(--line);border-radius:10px}
.up-row>svg{width:22px;height:22px;color:var(--muted)}
.up-main{display:flex;flex-direction:column;gap:3px;min-width:0}
.up-main input{padding:5px 9px}
.up-st{font-size:12px;color:var(--muted)}
.up-st.err{color:var(--urgent)} .up-st.ok{color:var(--info);font-weight:600}
.bar{height:4px;border-radius:2px;background:var(--surface-2);overflow:hidden}
.bar>i{display:block;height:100%;width:0;background:var(--accent);transition:width .2s}

/* gate: login / first-run */
.gate{min-height:100vh;min-height:100dvh;display:grid;place-items:center;padding:24px 16px}
.gate-card{width:100%;max-width:380px;display:flex;flex-direction:column;gap:14px;padding:28px 24px;background:var(--surface);border:1px solid var(--line);border-radius:16px;box-shadow:var(--shadow)}
.gate-card h1{font-size:24px;font-weight:700}
.gate-intro{margin:0;color:var(--muted);font-size:14px}
.gate-card .field input{height:44px}
.gate-card .btn{height:44px}

.toast{position:fixed;left:50%;bottom:calc(20px + env(safe-area-inset-bottom,0px));translate:-50% 0;z-index:90;max-width:calc(100% - 32px);padding:10px 16px;border-radius:10px;background:var(--ink);color:var(--bg);font-size:14px;box-shadow:var(--shadow)}

@media (max-width:900px){
  .layout{grid-template-columns:minmax(0,1fr);grid-template-areas:"board" "lib";gap:24px;padding-block:18px 32px}
}
@media (max-width:720px){
  .top{position:static}
  .search{order:3;flex-basis:100%;max-width:none}
  .brand-name{font-size:22px}
  .grid{grid-template-columns:repeat(auto-fill,minmax(150px,1fr));gap:12px}
  .panel{padding:12px}
  .seg{margin-left:0}
  .v-info h2{white-space:normal}
}
@media (prefers-reduced-motion:reduce){*{transition:none!important;animation:none!important}}
