/* ระบบติดตามปันผล — สไตล์ */
:root {
  --bg: #f4f6f8;
  --surface: #ffffff;
  --surface-2: #fafbfc;
  --border: #e3e7ec;
  --border-strong: #cfd6de;
  --text: #16181d;
  --muted: #697586;
  --accent: #14746f;
  --accent-soft: #e2f2f0;
  --good: #1f9254;
  --warn: #c4820a;
  --bad: #c73e3e;
  --shadow: 0 1px 2px rgba(16, 24, 40, .05), 0 6px 18px rgba(16, 24, 40, .06);
  --radius: 12px;
  --grid: #eef1f4;
}
:root[data-theme="dark"] {
  --bg: #0e1116;
  --surface: #161a21;
  --surface-2: #1b2029;
  --border: #262d38;
  --border-strong: #38414f;
  --text: #e7eaee;
  --muted: #98a2b3;
  --accent: #37b5ac;
  --accent-soft: #10312f;
  --good: #45c07c;
  --warn: #e0a93c;
  --bad: #e26a6a;
  --shadow: 0 1px 2px rgba(0, 0, 0, .35), 0 8px 24px rgba(0, 0, 0, .35);
  --grid: #232a34;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { margin: 0; padding: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Sukhumvit Set", "Noto Sans Thai",
    "Thonburi", "Segoe UI", Roboto, sans-serif;
  font-size: 14px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}
h1, h2, h3, h4 { margin: 0; font-weight: 650; letter-spacing: -.01em; }
button, input, select, textarea { font: inherit; color: inherit; }
.muted { color: var(--muted); }
.spacer { flex: 1; }
.num { font-variant-numeric: tabular-nums; }

/* ---------- top bar ---------- */
.topbar {
  position: sticky; top: 0; z-index: 40;
  display: flex; align-items: center; gap: 20px;
  padding: 10px 20px;
  background: color-mix(in srgb, var(--surface) 88%, transparent);
  backdrop-filter: saturate(1.4) blur(10px);
  border-bottom: 1px solid var(--border);
  flex-wrap: wrap;
}
.brand { display: flex; align-items: center; gap: 10px; }
.brand-mark {
  width: 34px; height: 34px; border-radius: 9px;
  display: grid; place-items: center;
  background: linear-gradient(140deg, var(--accent), #1b9c8f);
  color: #fff; font-weight: 700; font-size: 18px;
}
.brand h1 { font-size: 15px; }
.brand p { margin: 0; font-size: 11.5px; color: var(--muted); }

.tabs { display: flex; gap: 2px; background: var(--surface-2); padding: 3px; border-radius: 10px; border: 1px solid var(--border); }
.tabs button {
  border: 0; background: transparent; color: var(--muted);
  padding: 6px 13px; border-radius: 7px; cursor: pointer; font-weight: 550; font-size: 13px;
}
.tabs button:hover { color: var(--text); }
.tabs button.on { background: var(--surface); color: var(--text); box-shadow: 0 1px 2px rgba(0,0,0,.08); }

.topbar-right { display: flex; align-items: center; gap: 8px; margin-inline-start: auto; }
.year-pick { padding: 6px 10px; border-radius: 8px; border: 1px solid var(--border-strong); background: var(--surface); }

.btn {
  border: 1px solid var(--border-strong); background: var(--surface); color: var(--text);
  padding: 7px 14px; border-radius: 9px; cursor: pointer; font-weight: 550; font-size: 13px;
  white-space: nowrap; transition: .12s;
}
.btn:hover { border-color: var(--accent); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.primary:hover { filter: brightness(1.08); }
.btn.ghost { background: transparent; }
.btn.danger { color: var(--bad); border-color: color-mix(in srgb, var(--bad) 40%, var(--border)); }
.btn.sm { padding: 4px 9px; font-size: 12px; border-radius: 7px; }
.icon-btn {
  border: 1px solid transparent; background: transparent; cursor: pointer;
  width: 30px; height: 30px; border-radius: 8px; display: grid; place-items: center; color: var(--muted);
}
.icon-btn:hover { background: var(--surface-2); color: var(--text); }

/* ---------- layout ---------- */
main { padding: 18px 20px 60px; max-width: 1500px; margin: 0 auto; }
.card {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); box-shadow: var(--shadow); padding: 16px;
}
.card > header { display: flex; align-items: center; gap: 10px; margin-bottom: 12px; flex-wrap: wrap; }
.card > header h3 { font-size: 14px; }
.card > header .muted { font-size: 12px; }
.row { display: grid; gap: 14px; margin-bottom: 14px; }
.row.c2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.row.c3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.row.c4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.row.wide-left { grid-template-columns: minmax(0, 2fr) minmax(0, 1fr); }
.row.wide-right { grid-template-columns: minmax(0, 1fr) minmax(0, 2fr); }
@media (max-width: 1100px) {
  .row.c4 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .row.c3, .row.wide-left, .row.wide-right, .row.c2 { grid-template-columns: minmax(0, 1fr); }
}

/* ---------- filter bar ---------- */
.filters { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; margin-bottom: 14px; }
.filters select, .filters input {
  padding: 7px 10px; border-radius: 9px; border: 1px solid var(--border-strong);
  background: var(--surface); min-width: 0;
}
.filters input[type="search"] { min-width: 200px; }
.chip-group { display: flex; gap: 4px; background: var(--surface); border: 1px solid var(--border); border-radius: 10px; padding: 3px; }
.chip-group button {
  border: 0; background: transparent; color: var(--muted); cursor: pointer;
  padding: 5px 11px; border-radius: 7px; font-size: 12.5px; font-weight: 550;
}
.chip-group button.on { background: var(--accent-soft); color: var(--accent); }

/* ---------- KPI ---------- */
.kpi { position: relative; overflow: hidden; }
.kpi .label { font-size: 12px; color: var(--muted); display: flex; align-items: center; gap: 6px; }
.kpi .value { font-size: 25px; font-weight: 700; letter-spacing: -.02em; margin-top: 4px; font-variant-numeric: tabular-nums; }
.kpi .sub { font-size: 12px; color: var(--muted); margin-top: 3px; }
.kpi .spark { position: absolute; right: 0; bottom: 0; opacity: .5; pointer-events: none; }
.kpi-on { outline: 2px solid var(--accent); outline-offset: -1px; }
.delta { font-weight: 600; font-variant-numeric: tabular-nums; }
.delta.up { color: var(--good); }
.delta.down { color: var(--bad); }
.delta.flat { color: var(--muted); }
.dot { width: 9px; height: 9px; border-radius: 3px; display: inline-block; flex: none; }

/* ---------- tables ---------- */
.tbl-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: 13px; }
th, td { padding: 8px 10px; text-align: right; border-bottom: 1px solid var(--border); white-space: nowrap; }
th { font-weight: 600; color: var(--muted); font-size: 12px; position: sticky; top: 0; background: var(--surface); z-index: 1; }
th:first-child, td:first-child { text-align: left; }
td.txt, th.txt { text-align: left; white-space: normal; }
tbody tr:hover { background: var(--surface-2); }
tfoot td { font-weight: 700; border-top: 2px solid var(--border-strong); border-bottom: 0; }
.tag {
  display: inline-flex; align-items: center; gap: 5px; padding: 2px 8px;
  border-radius: 999px; font-size: 11.5px; font-weight: 600; border: 1px solid transparent;
}
.tag.ok { background: color-mix(in srgb, var(--good) 14%, transparent); color: var(--good); }
.tag.wait { background: color-mix(in srgb, var(--warn) 16%, transparent); color: var(--warn); }
.tag.na { background: var(--surface-2); color: var(--muted); }
.bar-cell { position: relative; }
.bar-cell .fill {
  position: absolute; inset: 5px auto 5px 6px; z-index: 0; border-radius: 3px;
  background: color-mix(in srgb, var(--accent) 22%, transparent);
}
.bar-cell span { position: relative; z-index: 1; }

/* ---------- progress ---------- */
.progress { height: 9px; background: var(--surface-2); border: 1px solid var(--border); border-radius: 999px; overflow: hidden; display: flex; }
.progress i { display: block; height: 100%; }
.legend { display: flex; gap: 14px; flex-wrap: wrap; font-size: 12px; color: var(--muted); }
.legend span { display: inline-flex; align-items: center; gap: 6px; }

/* ---------- entries ---------- */
.thumbs { display: inline-flex; gap: 4px; vertical-align: middle; margin-inline-start: 6px; }
.thumbs img {
  width: 30px; height: 30px; object-fit: cover; border-radius: 6px;
  border: 1px solid var(--border); cursor: zoom-in; background: var(--surface-2);
}
.sub-cell { font-size: 11px; color: var(--muted); font-weight: 400; }
.check-row { flex-direction: row; align-items: flex-start; gap: 8px; font-weight: 400; }
.check-row input { margin-top: 3px; flex: none; }
.people-pick { border: 1px solid var(--border); border-radius: 11px; padding: 12px; background: var(--surface-2); }
.people-pick-head { display: flex; justify-content: space-between; gap: 10px; font-size: 12.5px; margin-bottom: 8px; }
.people-row { display: flex; gap: 8px; flex-wrap: wrap; }
.people-row label {
  flex-direction: row; align-items: center; gap: 7px; cursor: pointer; font-weight: 550;
  border: 1px solid var(--border-strong); background: var(--surface); border-radius: 999px;
  padding: 6px 13px 6px 10px; color: var(--text);
}
.people-row label.on { border-color: currentColor; }
.people-row input { flex: none; margin: 0; }
.chip-people { display: inline-flex; gap: 3px; }
.chip-people i {
  width: 18px; height: 18px; border-radius: 999px; display: grid; place-items: center;
  font-size: 10px; font-style: normal; font-weight: 700; color: #fff;
}
.split-hint {
  margin: -4px 0 0; font-size: 12.5px; background: var(--accent-soft); color: var(--accent);
  border-radius: 9px; padding: 7px 10px;
}
.empty { text-align: center; padding: 44px 20px; color: var(--muted); }
.empty h3 { color: var(--text); margin-bottom: 6px; }

/* ---------- modal ---------- */
.modal-back {
  position: fixed; inset: 0; z-index: 90; background: rgba(12, 16, 22, .5);
  display: grid; place-items: center; padding: 20px; overflow: auto;
}
.modal {
  background: var(--surface); border: 1px solid var(--border); border-radius: 16px;
  width: min(680px, 100%); box-shadow: 0 24px 60px rgba(0,0,0,.3); max-height: 92vh; display: flex; flex-direction: column;
}
.modal-head { display: flex; align-items: center; padding: 14px 18px; border-bottom: 1px solid var(--border); }
.modal-head h2 { font-size: 15px; flex: 1; }
.modal-body { padding: 16px 18px; overflow: auto; display: flex; flex-direction: column; gap: 12px; }
.modal-foot { display: flex; gap: 8px; align-items: center; padding-top: 6px; border-top: 1px solid var(--border); margin-top: 4px; padding-block-start: 12px; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
@media (max-width: 560px) { .grid2 { grid-template-columns: 1fr; } }
label { display: flex; flex-direction: column; gap: 5px; font-size: 12.5px; color: var(--muted); font-weight: 550; }
label input, label select, label textarea {
  padding: 8px 10px; border-radius: 9px; border: 1px solid var(--border-strong);
  background: var(--surface); color: var(--text); font-weight: 400;
}
label input:focus, label select:focus, label textarea:focus { outline: 2px solid color-mix(in srgb, var(--accent) 40%, transparent); outline-offset: 1px; border-color: var(--accent); }
.form-error { color: var(--bad); font-size: 13px; margin: 0; }

.slip-box { border: 1px solid var(--border); border-radius: 11px; padding: 12px; background: var(--surface-2); }
.slip-box-head { display: flex; justify-content: space-between; gap: 10px; font-size: 12.5px; margin-bottom: 8px; flex-wrap: wrap; }
.dropzone {
  border: 1.5px dashed var(--border-strong); border-radius: 10px; padding: 14px;
  display: grid; place-items: center; transition: .15s;
}
.dropzone.over { border-color: var(--accent); background: var(--accent-soft); }
.slip-preview { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 10px; }
.slip-preview figure { margin: 0; position: relative; }
.slip-preview img { width: 74px; height: 74px; object-fit: cover; border-radius: 8px; border: 1px solid var(--border); cursor: zoom-in; }
.slip-preview button {
  position: absolute; top: -6px; right: -6px; width: 20px; height: 20px; border-radius: 999px;
  border: 1px solid var(--border-strong); background: var(--surface); cursor: pointer; line-height: 1; font-size: 11px;
}

/* ---------- lightbox ---------- */
.lightbox { position: fixed; inset: 0; z-index: 100; background: rgba(8, 10, 14, .92); display: grid; place-items: center; }
.lightbox img { max-width: 88vw; max-height: 82vh; border-radius: 10px; box-shadow: 0 10px 50px rgba(0,0,0,.6); }
.lightbox .lb-close { position: absolute; top: 16px; right: 18px; color: #fff; font-size: 18px; }
.lb-nav { position: absolute; top: 50%; transform: translateY(-50%); background: rgba(255,255,255,.1); color: #fff; border: 0; font-size: 34px; width: 46px; height: 74px; cursor: pointer; border-radius: 10px; }
.lb-prev { left: 14px; } .lb-next { right: 14px; }
.lb-caption { position: absolute; bottom: 18px; color: #e7eaee; font-size: 13px; text-align: center; }

/* ---------- toast ---------- */
.toast {
  position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%);
  background: #16181d; color: #fff; padding: 10px 18px; border-radius: 10px;
  z-index: 200; box-shadow: 0 8px 30px rgba(0,0,0,.3); font-size: 13px;
}
.toast.bad { background: var(--bad); }

/* ---------- charts ---------- */
.chart { width: 100%; display: block; overflow: visible; }
.chart text { fill: var(--muted); font-size: 11px; font-family: inherit; }
.chart .grid-line { stroke: var(--grid); stroke-width: 1; }
.chart .axis { stroke: var(--border-strong); stroke-width: 1; }
.chart .hover-band { fill: transparent; }
.chart .hover-band:hover { fill: color-mix(in srgb, var(--accent) 8%, transparent); }
.chart .val-label { fill: var(--text); font-size: 10.5px; font-weight: 600; }
.chart-tip {
  position: absolute; pointer-events: none; z-index: 50;
  background: var(--surface); border: 1px solid var(--border-strong); border-radius: 9px;
  box-shadow: var(--shadow); padding: 8px 10px; font-size: 12px; min-width: 150px;
}
.chart-tip .t-row { display: flex; justify-content: space-between; gap: 14px; }
.chart-tip .t-head { font-weight: 650; margin-bottom: 4px; }
.chart-host { position: relative; }

/* heatmap */
.heat { display: grid; gap: 3px; font-size: 11px; }
.heat .cell { border-radius: 5px; padding: 6px 4px; text-align: center; font-variant-numeric: tabular-nums; }
.heat .head { color: var(--muted); font-weight: 600; text-align: center; padding: 4px 2px; }
.heat .rowhead { color: var(--muted); font-weight: 600; text-align: left; padding: 6px 4px; white-space: nowrap; }

/* slips gallery */
.gallery { display: grid; grid-template-columns: repeat(auto-fill, minmax(130px, 1fr)); gap: 10px; }
.gallery figure { margin: 0; background: var(--surface-2); border: 1px solid var(--border); border-radius: 10px; overflow: hidden; }
.gallery img { width: 100%; height: 118px; object-fit: cover; display: block; cursor: zoom-in; }
.gallery figcaption { padding: 6px 8px; font-size: 11.5px; color: var(--muted); }
.gallery figcaption b { color: var(--text); display: block; font-variant-numeric: tabular-nums; }

/* settings */
.set-list { display: flex; flex-direction: column; gap: 8px; }
.set-row { display: flex; gap: 8px; align-items: center; }
.set-row input[type="text"], .set-row input[type="number"] { flex: 1; padding: 7px 10px; border-radius: 9px; border: 1px solid var(--border-strong); background: var(--surface); }
.set-row input[type="color"] { width: 38px; height: 34px; padding: 2px; border-radius: 8px; border: 1px solid var(--border-strong); background: var(--surface); }
.hint { font-size: 12px; color: var(--muted); background: var(--surface-2); border: 1px solid var(--border); border-radius: 10px; padding: 10px 12px; }
.note-list { margin: 0; padding-left: 18px; font-size: 12.5px; color: var(--muted); }
.note-list li { margin: 3px 0; }

@media print {
  .topbar, .filters, .btn, .icon-btn { display: none !important; }
  body { background: #fff; }
  .card { box-shadow: none; break-inside: avoid; }
}

/* ---------- บัญชีผู้ใช้ ---------- */
.user-menu { position: relative; }
.user-pop {
  position: absolute; right: 0; top: calc(100% + 6px); z-index: 60;
  background: var(--surface); border: 1px solid var(--border); border-radius: 11px;
  box-shadow: var(--shadow); padding: 8px; min-width: 190px;
  display: flex; flex-direction: column; gap: 4px;
}
.user-pop .btn { justify-content: flex-start; text-align: left; }
.user-pop-head { padding: 4px 8px 8px; border-bottom: 1px solid var(--border); margin-bottom: 4px; font-size: 13px; }
.user-pop-head b { display: block; }
.user-pop-head span { font-size: 11.5px; }
body.readonly #addBtn { display: none; }
