/* Lost & Found — shared styles */
:root {
  color-scheme: light;
  --bg: #f4f5f7;
  --surface: #ffffff;
  --surface-2: #f9f9f7;
  --border: rgba(11, 11, 11, 0.10);
  --grid: #e1e0d9;
  --text: #0b0b0b;
  --text-2: #52514e;
  --muted: #898781;
  --brand: #2a78d6;
  --brand-2: #1c5cab;
  --brand-soft: #e6f0fc;
  --s1: #2a78d6; --s2: #eb6834; --s3: #1baf7a; --s4: #eda100;
  --s5: #e87ba4; --s6: #008300; --s7: #4a3aa7; --s8: #e34948;
  --good: #0ca30c; --good-soft: #e3f5e3; --good-text: #006300;
  --warn: #fab219; --warn-soft: #fff3d6; --warn-text: #7a4d00;
  --crit: #d03b3b; --crit-soft: #fde3e3;
  --radius: 14px;
  --shadow: 0 1px 2px rgba(0,0,0,.04), 0 4px 16px rgba(0,0,0,.05);
  --font: "IBM Plex Sans Thai", "Sarabun", system-ui, -apple-system, "Segoe UI", sans-serif;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --bg: #0d0d0d; --surface: #1a1a19; --surface-2: #222220;
    --border: rgba(255,255,255,.10); --grid: #2c2c2a;
    --text: #ffffff; --text-2: #c3c2b7; --muted: #898781;
    --brand: #3987e5; --brand-2: #6da7ec; --brand-soft: #16304d;
    --s1: #3987e5; --s2: #d95926; --s3: #199e70; --s4: #c98500;
    --s5: #d55181; --s6: #008300; --s7: #9085e9; --s8: #e66767;
    --good-soft: #143814; --good-text: #6fdc6f;
    --warn-soft: #3d2e0a; --warn-text: #ffd27a;
    --crit-soft: #401515;
    --shadow: 0 1px 2px rgba(0,0,0,.4), 0 4px 16px rgba(0,0,0,.35);
  }
}
:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #0d0d0d; --surface: #1a1a19; --surface-2: #222220;
  --border: rgba(255,255,255,.10); --grid: #2c2c2a;
  --text: #ffffff; --text-2: #c3c2b7; --muted: #898781;
  --brand: #3987e5; --brand-2: #6da7ec; --brand-soft: #16304d;
  --s1: #3987e5; --s2: #d95926; --s3: #199e70; --s4: #c98500;
  --s5: #d55181; --s6: #008300; --s7: #9085e9; --s8: #e66767;
  --good-soft: #143814; --good-text: #6fdc6f;
  --warn-soft: #3d2e0a; --warn-text: #ffd27a;
  --crit-soft: #401515;
  --shadow: 0 1px 2px rgba(0,0,0,.4), 0 4px 16px rgba(0,0,0,.35);
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body { margin: 0; background: var(--bg); color: var(--text); font-family: var(--font); font-size: 15px; line-height: 1.5; }
a { color: var(--brand); text-decoration: none; }
button, input, select { font: inherit; color: inherit; }
img { max-width: 100%; }
.container { max-width: 1280px; margin: 0 auto; padding: 0 16px; }

/* ---------- top bar ---------- */
.topbar { position: sticky; top: 0; z-index: 50; background: var(--surface); border-bottom: 1px solid var(--border); }
.topbar .container { display: flex; align-items: center; gap: 14px; height: 60px; }
.brand { display: flex; align-items: center; gap: 10px; font-weight: 700; font-size: 17px; color: var(--text); }
.brand .logo { width: 34px; height: 34px; border-radius: 10px; background: linear-gradient(135deg, var(--brand), var(--s3)); display: grid; place-items: center; color: #fff; font-size: 18px; }
.brand small { display: block; font-weight: 400; font-size: 12px; color: var(--muted); line-height: 1.1; }
.topbar nav { margin-left: auto; display: flex; gap: 6px; align-items: center; overflow-x: auto; flex: none; max-width: 80%; }
.navlink { padding: 8px 12px; border-radius: 10px; color: var(--text-2); font-weight: 500; }
.navlink:hover, .navlink.active { background: var(--brand-soft); color: var(--brand); }
.iconbtn { border: 1px solid var(--border); background: var(--surface); border-radius: 10px; width: 36px; height: 36px; display: grid; place-items: center; cursor: pointer; color: var(--text-2); }
.iconbtn:hover { background: var(--surface-2); }

/* ---------- generic ---------- */
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); }
.card-h { display: flex; align-items: baseline; justify-content: space-between; gap: 10px; padding: 16px 18px 0; }
.card-h h3 { margin: 0; font-size: 15px; font-weight: 600; }
.card-h .sub { font-size: 12px; color: var(--muted); }
.card-b { padding: 14px 18px 18px; }
.btn { display: inline-flex; align-items: center; gap: 8px; border: 1px solid var(--border); background: var(--surface); padding: 9px 14px; border-radius: 10px; cursor: pointer; font-weight: 500; white-space: nowrap; }
.btn:hover { background: var(--surface-2); }
.btn.primary { background: var(--brand); border-color: var(--brand); color: #fff; }
.btn.primary:hover { background: var(--brand-2); }
.btn.sm { padding: 6px 10px; font-size: 13px; border-radius: 8px; }
.btn[disabled] { opacity: .6; cursor: progress; }
.chip { display: inline-flex; align-items: center; gap: 6px; padding: 3px 10px; border-radius: 999px; font-size: 12.5px; font-weight: 600; line-height: 1.6; }
.chip.waiting { background: var(--warn-soft); color: var(--warn-text); }
.chip.returned { background: var(--good-soft); color: var(--good-text); }
.chip.other { background: var(--surface-2); color: var(--text-2); }
.chip.cat { background: var(--brand-soft); color: var(--brand); font-weight: 500; }
.chip .dot { width: 8px; height: 8px; border-radius: 50%; background: currentColor; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.grid { display: grid; gap: 14px; }
.hidden { display: none !important; }
.tabular { font-variant-numeric: tabular-nums; }

/* ---------- filter bar ---------- */
.filters { display: flex; flex-wrap: wrap; gap: 10px; align-items: end; }
.field { display: flex; flex-direction: column; gap: 4px; min-width: 0; }
.field label { font-size: 12px; color: var(--muted); font-weight: 500; }
.field input, .field select { border: 1px solid var(--border); background: var(--surface); border-radius: 10px; padding: 9px 12px; min-width: 140px; }
.field input:focus, .field select:focus { outline: 2px solid var(--brand); outline-offset: 0; border-color: transparent; }
.search { position: relative; flex: 1 1 260px; }
.search input { width: 100%; padding-left: 38px; }
.search svg { position: absolute; left: 12px; top: 50%; transform: translateY(-50%); color: var(--muted); pointer-events: none; }
.presets { display: flex; gap: 6px; flex-wrap: wrap; }
.presets button { border: 1px solid var(--border); background: var(--surface); padding: 6px 10px; border-radius: 999px; font-size: 13px; cursor: pointer; color: var(--text-2); }
.presets button.active { background: var(--brand); color: #fff; border-color: var(--brand); }

/* ---------- KPI tiles ---------- */
.kpis { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 12px; }
.kpi { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 14px 16px; box-shadow: var(--shadow); position: relative; overflow: hidden; }
.kpi .lbl { font-size: 12.5px; color: var(--text-2); display: flex; align-items: center; gap: 6px; }
.kpi .val { font-size: 28px; font-weight: 700; line-height: 1.2; margin-top: 4px; }
.kpi .val small { font-size: 13px; font-weight: 500; color: var(--muted); margin-left: 4px; }
.kpi .delta { font-size: 12px; color: var(--muted); margin-top: 2px; }
.kpi .delta.up { color: var(--good-text); } .kpi .delta.down { color: var(--crit); }
.kpi::before { content: ""; position: absolute; left: 0; top: 0; bottom: 0; width: 4px; background: var(--accent, var(--brand)); }

/* ---------- charts ---------- */
.charts { display: grid; grid-template-columns: repeat(12, 1fr); gap: 14px; }
.charts > .card { grid-column: span 12; }
@media (min-width: 760px) { .charts > .card.half { grid-column: span 6; } .charts > .card.third { grid-column: span 4; } .charts > .card.two-thirds { grid-column: span 8; } }
.chart-wrap { position: relative; height: 260px; }
.chart-wrap.tall { height: 320px; }
.chart-wrap.short { height: 200px; }
.legend { display: flex; flex-wrap: wrap; gap: 10px 16px; font-size: 12.5px; color: var(--text-2); margin-bottom: 8px; }
.legend span { display: inline-flex; align-items: center; gap: 6px; }
.legend i { width: 10px; height: 10px; border-radius: 3px; display: inline-block; }
.heat { display: grid; grid-template-columns: 52px repeat(15, 1fr); gap: 3px; font-size: 11px; }
.heat .h { color: var(--muted); text-align: center; }
.heat .r { color: var(--muted); }
.heat .c { aspect-ratio: 1; border-radius: 4px; background: var(--surface-2); position: relative; }
.heat .c:hover { outline: 2px solid var(--brand); }
.rank { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 8px; }
.rank li { display: grid; grid-template-columns: 1fr auto; gap: 8px; align-items: center; font-size: 13.5px; }
.rank .bar { grid-column: 1 / -1; height: 6px; border-radius: 4px; background: var(--surface-2); overflow: hidden; }
.rank .bar i { display: block; height: 100%; background: var(--brand); border-radius: 4px; }
.rank .n { font-weight: 600; }

/* ---------- item cards ---------- */
.items { display: grid; grid-template-columns: repeat(auto-fill, minmax(230px, 1fr)); gap: 14px; }
.item { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); overflow: hidden; box-shadow: var(--shadow); cursor: pointer; display: flex; flex-direction: column; transition: transform .12s, box-shadow .12s; }
.item:hover { transform: translateY(-2px); box-shadow: 0 8px 24px rgba(0,0,0,.10); }
.item .ph { aspect-ratio: 4/3; background: var(--surface-2); display: grid; place-items: center; color: var(--muted); font-size: 40px; overflow: hidden; position: relative; }
.item .ph img { width: 100%; height: 100%; object-fit: cover; }
.item .ph .chip { position: absolute; top: 10px; left: 10px; }
.item .ph .id { position: absolute; right: 10px; top: 10px; background: rgba(0,0,0,.55); color: #fff; font-size: 11px; padding: 2px 8px; border-radius: 999px; }
.item .bd { padding: 12px 14px 14px; display: flex; flex-direction: column; gap: 5px; }
.item .ttl { font-weight: 600; font-size: 14.5px; line-height: 1.35; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.item .meta { font-size: 12.5px; color: var(--text-2); display: flex; align-items: center; gap: 6px; }
.item .meta svg { flex: none; color: var(--muted); }
.list-h { display: flex; align-items: center; justify-content: space-between; gap: 10px; flex-wrap: wrap; margin: 6px 0 12px; }
.pager { display: flex; align-items: center; justify-content: center; gap: 8px; margin: 18px 0; }
.empty { text-align: center; padding: 50px 20px; color: var(--muted); }
.empty .big { font-size: 44px; }

/* ---------- table ---------- */
.tbl { width: 100%; border-collapse: collapse; font-size: 13.5px; }
.tbl th, .tbl td { padding: 9px 10px; border-bottom: 1px solid var(--grid); text-align: left; vertical-align: top; }
.tbl th { color: var(--muted); font-weight: 600; font-size: 12px; position: sticky; top: 0; background: var(--surface); }
.tbl tr:hover td { background: var(--surface-2); }
.tbl-wrap { overflow: auto; max-height: 480px; }

/* ---------- modal ---------- */
.modal { position: fixed; inset: 0; background: rgba(0,0,0,.5); display: none; align-items: center; justify-content: center; padding: 16px; z-index: 100; }
.modal.open { display: flex; }
.modal .box { background: var(--surface); border-radius: 18px; width: min(860px, 100%); max-height: 92vh; overflow: auto; box-shadow: 0 20px 60px rgba(0,0,0,.35); }
.modal .box-h { display: flex; align-items: center; gap: 10px; padding: 16px 20px; border-bottom: 1px solid var(--border); position: sticky; top: 0; background: var(--surface); z-index: 1; }
.modal .box-h h2 { margin: 0; font-size: 17px; flex: 1; }
.modal .box-b { padding: 18px 20px 22px; display: grid; gap: 16px; grid-template-columns: 1fr; }
@media (min-width: 720px) { .modal .box-b { grid-template-columns: 300px 1fr; } }
.modal .photo { background: var(--surface-2); border-radius: 12px; overflow: hidden; aspect-ratio: 1; display: grid; place-items: center; color: var(--muted); font-size: 50px; }
.modal .photo img { width: 100%; height: 100%; object-fit: cover; }
.dl { display: grid; grid-template-columns: 130px 1fr; gap: 6px 12px; margin: 0; font-size: 14px; }
.dl dt { color: var(--muted); }
.dl dd { margin: 0; }
.section-t { font-size: 12px; color: var(--muted); text-transform: uppercase; letter-spacing: .06em; margin: 10px 0 4px; font-weight: 600; }

/* ---------- misc ---------- */
.notice { padding: 10px 14px; border-radius: 10px; background: var(--brand-soft); color: var(--brand); font-size: 13.5px; }
.notice.err { background: var(--crit-soft); color: var(--crit); }
.syncbar { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; font-size: 13px; color: var(--muted); }
.spin { display: inline-block; width: 14px; height: 14px; border: 2px solid var(--border); border-top-color: var(--brand); border-radius: 50%; animation: sp .8s linear infinite; }
@keyframes sp { to { transform: rotate(360deg); } }
.skeleton { background: linear-gradient(90deg, var(--surface-2), var(--border), var(--surface-2)); background-size: 200% 100%; animation: sk 1.2s infinite; border-radius: 8px; }
@keyframes sk { to { background-position: -200% 0; } }
footer { text-align: center; color: var(--muted); font-size: 12.5px; padding: 30px 16px; }
.hero { padding: 34px 0 20px; }
.hero h1 { margin: 0 0 6px; font-size: 26px; }
.hero p { margin: 0; color: var(--text-2); }
.login { max-width: 400px; margin: 60px auto; }
.login input { width: 100%; }
@media (max-width: 600px) {
  .kpi .val { font-size: 24px; }
  .topbar .brand span.t { display: none; }
  .navlink { padding: 6px 9px; font-size: 13.5px; white-space: nowrap; }
  .filters .field { flex: 1 1 calc(50% - 5px); }
  .filters .field.search { flex-basis: 100%; }
  .filters .field input, .filters .field select { min-width: 0; width: 100%; }
  .filters .btn { flex: 1 1 100%; justify-content: center; }
  .hero { padding: 22px 0 14px; } .hero h1 { font-size: 22px; }
  .items { grid-template-columns: repeat(2, 1fr); gap: 10px; }
  .item .bd { padding: 10px 11px 12px; } .item .ttl { font-size: 13.5px; }
}
