/* Cuupy Staff & Accounts — tokens follow Web-App/design-system.md */
:root {
  --green: #2d6a4f;
  --green-soft: #e7f1ec;
  --green-ink: #1f4a37;
  --ink: #1a1a1a;
  --ink2: #6b7280;
  --border: #e5e7eb;
  --border-strong: #d1d5db;
  --input-bg: #f9fafb;
  --bg: #fafaf7;
  --white: #ffffff;
  --error: #ef4444;
  --error-soft: #fef2f2;
  --error-ink: #b91c1c;
  --amber: #b45309;
  --amber-soft: #fef3c7;
  --blue: #1d4ed8;
  --blue-soft: #dbeafe;
  --orange: #c2410c;
  --orange-soft: #ffedd5;
  --radius: 8px;
  --radius-card: 12px;
  --shadow: 0 1px 2px rgba(0, 0, 0, 0.04), 0 1px 8px rgba(0, 0, 0, 0.04);
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  font-family: "Noto Sans Thai", "Inter", -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  background: var(--bg);
  color: var(--ink);
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  font-size: 16px;
}
input, textarea, select, button { font-family: inherit; font-size: inherit; }
::selection { background: rgba(45, 106, 79, 0.18); }
input[type="number"]::-webkit-outer-spin-button,
input[type="number"]::-webkit-inner-spin-button { -webkit-appearance: none; margin: 0; }
input[type="number"] { -moz-appearance: textfield; }
.num { font-variant-numeric: tabular-nums; }
.muted { color: var(--ink2); }
.small { font-size: 14px; }
.tiny { font-size: 12.5px; }
.bold { font-weight: 700; }
.right { text-align: right; }
.row { display: flex; align-items: center; gap: 8px; }
.row.wrap { flex-wrap: wrap; }
.row.between { justify-content: space-between; }
.stack { display: flex; flex-direction: column; gap: 12px; }
.stack.tight { gap: 6px; }
.grow { flex: 1; min-width: 0; }
.ellipsis { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.hide-mobile { display: none; }

@keyframes sa-fadein { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }
@keyframes sa-scalein { from { opacity: 0; transform: scale(.96); } to { opacity: 1; transform: none; } }
@keyframes sa-slideup { from { transform: translateY(24px); opacity: 0; } to { transform: none; opacity: 1; } }
@keyframes sa-fade { from { opacity: 0; } to { opacity: 1; } }
@keyframes sa-spin { to { transform: rotate(360deg); } }

/* ---------- App shell ---------- */
.app { min-height: 100vh; }
.header {
  position: sticky; top: 0; z-index: 20;
  display: flex; align-items: center; gap: 10px;
  padding: 10px 16px; background: var(--white); border-bottom: 1px solid var(--border);
}
.brand { display: flex; align-items: center; gap: 8px; font-weight: 700; color: var(--green); white-space: nowrap; }
.brand small { font-weight: 500; color: var(--green-ink); }
.loc-select {
  height: 38px; padding: 0 30px 0 12px; border: 1.5px solid var(--border-strong); border-radius: 999px;
  background: var(--white) url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 24 24' fill='none' stroke='%236b7280' stroke-width='2.5'%3E%3Cpath d='m6 9 6 6 6-6'/%3E%3C/svg%3E") no-repeat right 10px center;
  -webkit-appearance: none; appearance: none; font-weight: 600; color: var(--ink); max-width: 52vw;
}
.main { max-width: 1100px; margin: 0 auto; padding: 16px; animation: sa-fadein .2s ease; }
.page-title { font-size: 22px; font-weight: 700; margin: 4px 0 14px; }

/* Menu: a slide-in drawer on phones (opened by the coffee button), a fixed side
   bar from 900px. */
.brand-btn { border: 0; background: none; padding: 4px; margin: -4px; cursor: pointer; position: relative;
  font: inherit; color: inherit; border-radius: 8px; }
.brand-btn .dot {
  position: absolute; top: -4px; left: 16px; min-width: 18px; height: 18px; padding: 0 5px;
  border-radius: 999px; background: var(--error); color: #fff; font-size: 11px; line-height: 18px; text-align: center;
}
.nav {
  position: fixed; top: 0; bottom: 0; left: 0; z-index: 45; width: min(280px, 82vw);
  display: flex; flex-direction: column; justify-content: flex-start; overflow-y: auto;
  background: var(--white); border-right: 1px solid var(--border);
  padding: calc(16px + env(safe-area-inset-top)) 10px calc(16px + env(safe-area-inset-bottom));
  transform: translateX(-100%); transition: transform .2s ease; box-shadow: none;
}
.nav.open { transform: none; box-shadow: 0 10px 40px rgba(0, 0, 0, .25); }
.nav-backdrop { position: fixed; inset: 0; z-index: 44; background: rgba(0, 0, 0, .4); animation: sa-fade .15s; }
.nav-head { display: flex; align-items: center; gap: 8px; font-weight: 700; color: var(--green); padding: 2px 12px 8px; }
.nav-head small { font-weight: 500; color: var(--green-ink); }
.nav button {
  flex: 0 0 auto; border: 0; background: none; color: var(--ink2); cursor: pointer; position: relative;
  display: flex; align-items: center; gap: 12px; font-size: 16px; font-weight: 600;
  padding: 12px 12px; border-radius: 8px; text-align: left;
}
.nav button.active { color: var(--green); background: var(--green-soft); }
.nav button svg { width: 22px; height: 22px; }
.nav .dot {
  margin-left: auto; min-width: 20px; height: 20px; padding: 0 6px;
  border-radius: 999px; background: var(--error); color: #fff; font-size: 12px; line-height: 20px; text-align: center;
}
.nav-section { display: block; font-size: 12.5px; font-weight: 700; color: var(--ink2); letter-spacing: .3px;
  padding: 14px 12px 4px; }
.nav-section.nav-gap { border-top: 1px solid var(--border); margin: 12px 8px 4px; padding: 0; }

@media (min-width: 900px) {
  .hide-mobile { display: block; }
  .hide-desktop { display: none !important; }
  .app { padding-left: 210px; }
  .brand-btn { cursor: default; }
  .brand-btn .dot, .nav-backdrop, .nav-head { display: none; }
  .nav {
    z-index: 30; width: 210px; transform: none; transition: none; box-shadow: none;
    padding: 72px 10px 10px;
  }
  .nav.open { box-shadow: none; }
  .nav-head + .nav-section { padding-top: 0; }
  .nav button { font-size: 15.5px; padding: 10px 12px; gap: 10px; }
  .header { padding-left: 24px; }
  .main { padding: 24px; }
}

/* ---------- Primitives ---------- */
.card {
  background: var(--white); border: 1px solid var(--border); border-radius: var(--radius-card);
  padding: 16px; box-shadow: var(--shadow);
}
.card.flat { box-shadow: none; }
.card-title { font-size: 17px; font-weight: 700; margin: 0 0 8px; display: flex; align-items: center; gap: 8px; }
.card-title::before { content: ""; width: 4px; height: 18px; border-radius: 2px; background: var(--green); }

.btn {
  height: 44px; padding: 0 18px; border-radius: var(--radius); font-weight: 600; font-size: 16px;
  border: 1.5px solid transparent; cursor: pointer; display: inline-flex; align-items: center;
  justify-content: center; gap: 6px; white-space: nowrap; transition: background .15s, box-shadow .15s, transform .1s;
}
.btn:active:not(:disabled) { transform: scale(.97); }
.btn:disabled { cursor: not-allowed; opacity: .55; }
.btn.sm { height: 36px; padding: 0 12px; font-size: 14.5px; }
.btn.block { width: 100%; }
.btn-primary { background: var(--green); color: #fff; }
.btn-primary:hover:not(:disabled) { background: var(--green-ink); box-shadow: 0 4px 12px rgba(45, 106, 79, .3); }
.btn-primary:disabled { background: #9ca3af; opacity: 1; }
.btn-ghost { background: var(--white); color: var(--ink); border-color: var(--border-strong); }
.btn-ghost:hover:not(:disabled) { background: #f3f4f6; }
.btn-danger { background: var(--white); color: var(--error-ink); border-color: #fecaca; }
.btn-danger:hover:not(:disabled) { background: var(--error-soft); }
.btn-add { background: transparent; color: var(--green); border: 1.5px dashed var(--green); }
.btn-add:hover:not(:disabled) { background: var(--green-soft); }
.btn-link { background: none; border: 0; color: var(--green); font-weight: 600; cursor: pointer; padding: 4px; }
.icon-btn { width: 36px; height: 36px; border-radius: 8px; border: 1px solid var(--border); background: var(--white);
  display: inline-flex; align-items: center; justify-content: center; cursor: pointer; color: var(--ink2); }
.icon-btn:hover { background: #f3f4f6; }

.field { display: flex; flex-direction: column; gap: 5px; min-width: 0; }
.field-label { font-size: 14.5px; font-weight: 600; display: flex; justify-content: space-between; gap: 8px; }
.field-label .req { color: var(--error); margin-left: 3px; }
.field-label .hint { font-weight: 400; color: var(--ink2); font-size: 13px; }
.field-error { color: var(--error-ink); font-size: 13.5px; }
.input, .select, .textarea {
  width: 100%; height: 44px; padding: 0 12px; border: 1.5px solid var(--border); border-radius: var(--radius);
  background: var(--input-bg); color: var(--ink); font-size: 16px; outline: none; transition: border .15s, box-shadow .15s;
}
.textarea { height: auto; min-height: 80px; padding: 10px 12px; resize: vertical; }
.input:focus, .select:focus, .textarea:focus { border-color: var(--green); box-shadow: 0 0 0 4px rgba(45, 106, 79, .1); background: #fff; }
.input.error { border-color: var(--error); }
.select { -webkit-appearance: none; appearance: none; padding-right: 32px;
  background: var(--input-bg) url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 24 24' fill='none' stroke='%236b7280' stroke-width='2.5'%3E%3Cpath d='m6 9 6 6 6-6'/%3E%3C/svg%3E") no-repeat right 12px center; }
.input-unit { position: relative; }
.input-unit .unit { position: absolute; right: 12px; top: 50%; transform: translateY(-50%); color: var(--ink2); font-size: 14px; pointer-events: none; }
.input-unit .input { padding-right: 44px; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.grid3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 12px; }
@media (max-width: 520px) { .grid3 { grid-template-columns: 1fr 1fr; } }

.pills { display: inline-flex; background: #f1f2f0; border-radius: 999px; padding: 3px; gap: 2px; flex-wrap: wrap; }
.pills.full { display: flex; }
.pills.full button { flex: 1; }
.pills button { border: 0; background: transparent; color: var(--ink2); font-weight: 600; font-size: 14.5px;
  height: 34px; padding: 0 14px; border-radius: 999px; cursor: pointer; white-space: nowrap; }
.pills button.on { background: var(--white); color: var(--green); box-shadow: 0 1px 3px rgba(0, 0, 0, .1); }

.badge { display: inline-flex; align-items: center; gap: 4px; height: 24px; padding: 0 9px; border-radius: 999px;
  font-size: 12.5px; font-weight: 600; white-space: nowrap; background: #f3f4f6; color: var(--ink2); }
.badge.green { background: var(--green-soft); color: var(--green-ink); }
.badge.amber { background: var(--amber-soft); color: var(--amber); }
.badge.red { background: var(--error-soft); color: var(--error-ink); }
.badge.blue { background: var(--blue-soft); color: var(--blue); }
.badge.orange { background: var(--orange-soft); color: var(--orange); }

.banner { display: flex; gap: 10px; align-items: flex-start; padding: 12px 14px; border-radius: 10px; font-size: 15px;
  border: 1px solid #bcd9c8; background: var(--green-soft); color: var(--green-ink); }
.banner.amber { background: var(--amber-soft); border-color: #fde68a; color: var(--amber); }
.banner.red { background: var(--error-soft); border-color: #fecaca; color: var(--error-ink); }
.banner button { margin-left: auto; }

.empty { text-align: center; color: var(--ink2); padding: 32px 12px; }
.spinner { width: 22px; height: 22px; border: 3px solid var(--green-soft); border-top-color: var(--green);
  border-radius: 50%; animation: sa-spin .8s linear infinite; margin: 24px auto; }

.list { display: flex; flex-direction: column; }
.list-item { display: flex; align-items: center; gap: 10px; padding: 12px 2px; border-bottom: 1px solid var(--border); }
.list-item:last-child { border-bottom: 0; }
.list-item.click { cursor: pointer; }
.list-item.click:hover { background: #fafafa; }

.money-neg { color: var(--error-ink); }
.money-pos { color: var(--green-ink); }

/* ---------- Sheets / modals ---------- */
.overlay { position: fixed; inset: 0; background: rgba(0, 0, 0, .45); z-index: 50; display: flex;
  align-items: flex-end; justify-content: center; animation: sa-fade .15s; }
.sheet { background: var(--white); width: 100%; max-width: 560px; max-height: 92vh; overflow: auto;
  border-radius: 16px 16px 0 0; padding: 16px 16px calc(16px + env(safe-area-inset-bottom)); animation: sa-slideup .2s ease; }
.sheet-head { display: flex; align-items: center; gap: 8px; margin-bottom: 12px; }
.sheet-head h3 { margin: 0; font-size: 18px; flex: 1; }
.sheet-actions { display: flex; gap: 10px; margin-top: 16px; }
.sheet-actions .btn { flex: 1; }
@media (min-width: 640px) {
  .overlay { align-items: center; }
  .sheet { border-radius: 14px; animation: sa-scalein .18s ease; }
}

.toast-wrap { position: fixed; left: 50%; bottom: calc(16px + env(safe-area-inset-bottom)); transform: translateX(-50%); z-index: 60;
  display: flex; flex-direction: column; gap: 8px; width: min(92vw, 420px); }
.toast { background: var(--ink); color: #fff; padding: 10px 14px; border-radius: 10px; font-size: 15px;
  box-shadow: 0 6px 20px rgba(0, 0, 0, .2); animation: sa-slideup .2s; }
.toast.error { background: var(--error-ink); }
@media (min-width: 900px) { .toast-wrap { bottom: 24px; } }

/* ---------- Weekly Review strip ---------- */
.week-nav { display: flex; align-items: center; gap: 8px; }
.week-nav .label { flex: 1; text-align: center; font-weight: 700; font-size: 17px; }
.strip { display: grid; grid-template-columns: minmax(64px, 1fr) repeat(7, minmax(34px, 1fr)); gap: 4px; align-items: stretch; }
.strip .hd { text-align: center; font-size: 12px; color: var(--ink2); font-weight: 600; padding-bottom: 2px; }
.strip .hd.today { color: var(--green); }
.strip .who { font-weight: 600; font-size: 14px; display: flex; flex-direction: column; justify-content: center; min-width: 0; }
.strip .who small { font-weight: 400; color: var(--ink2); font-size: 11.5px; }
.cell { min-height: 44px; border-radius: 8px; border: 1.5px solid transparent; background: #f1f2f0; cursor: pointer;
  display: flex; flex-direction: column; align-items: center; justify-content: center; font-size: 11px; font-weight: 700;
  color: var(--ink2); position: relative; padding: 2px; line-height: 1.15; text-align: center; }
.cell.off { background: #f4f4f2; color: #c4c4c0; }
.cell.work { background: #d8eadf; color: var(--green-ink); }
.cell.leave { background: #fde2c4; color: var(--orange); }
.cell.half { background: linear-gradient(135deg, #fde2c4 50%, #d8eadf 50%); color: var(--orange); }
.cell.absence { background: #fecaca; color: var(--error-ink); }
.cell.closed { background: repeating-linear-gradient(45deg, #e5e7eb, #e5e7eb 4px, #f9fafb 4px, #f9fafb 8px); color: var(--ink2); }
.cell.standdown { background: #e0e7ff; color: #4338ca; }
.cell.pending { border-color: #eab308; border-style: dashed; }
.cell.paid { opacity: .55; }
.cell.extra::after { content: attr(data-extra); position: absolute; top: -6px; right: -4px; background: var(--blue);
  color: #fff; border-radius: 999px; font-size: 10px; padding: 0 4px; line-height: 15px; }
.cell.ghost { background: transparent; cursor: default; }

/* Weekly Review (ตรวจก่อนจ่าย): text 15% larger than the rest of the app. */
.review .page-title { font-size: 25.5px; }
.review .week-nav .label { font-size: 19.5px; }
.review .strip .hd { font-size: 14px; }
.review .strip .who { font-size: 16px; }
.review .strip .who small { font-size: 13px; }
.review .cell { font-size: 12.5px; }
.review .cell.extra::after { font-size: 11.5px; line-height: 17px; }
.review .legend { font-size: 14.5px; }
.review .pay-card .net { font-size: 25.5px; }
.review .pay-lines { font-size: 16.5px; }
.review .banner { font-size: 17px; }
.review .btn { font-size: 18.5px; }
.review .btn.sm { font-size: 16.5px; }
.review .small { font-size: 16px; }
.review .tiny { font-size: 14.5px; }
.review .badge { font-size: 14.5px; height: 27px; }
.legend { display: flex; flex-wrap: wrap; gap: 10px; font-size: 12.5px; color: var(--ink2); }
.legend span { display: inline-flex; align-items: center; gap: 5px; }
.legend i { width: 14px; height: 14px; border-radius: 4px; display: inline-block; }

.pay-card .net { font-size: 22px; font-weight: 700; }
.pay-lines { display: flex; flex-direction: column; gap: 2px; font-size: 14.5px; margin: 8px 0; }
.pay-lines .l { display: flex; justify-content: space-between; gap: 12px; }

/* ---------- Ledger ---------- */
.ledger-cols { display: grid; gap: 16px; }
@media (min-width: 900px) { .ledger-cols { grid-template-columns: 1fr 1fr; } }
.entry { display: grid; grid-template-columns: 52px 1fr auto; gap: 8px; align-items: center; padding: 9px 0;
  border-bottom: 1px solid var(--border); font-size: 15px; }
.entry:last-child { border-bottom: 0; }
.entry .d { color: var(--ink2); font-size: 13px; }
.entry .g { font-size: 12.5px; color: var(--ink2); }

/* ---------- Dashboard ---------- */
.tiles { display: grid; grid-template-columns: repeat(2, 1fr); gap: 10px; }
@media (min-width: 900px) { .tiles { grid-template-columns: repeat(4, 1fr); } }
.tile { background: var(--white); border: 1px solid var(--border); border-radius: 12px; padding: 12px 14px; }
.tile .k { font-size: 13px; color: var(--ink2); font-weight: 600; }
.tile .v { font-size: 21px; font-weight: 700; margin-top: 2px; }
.bar-track { height: 8px; background: #f1f2f0; border-radius: 999px; overflow: hidden; }
.bar-fill { height: 100%; border-radius: 999px; }
.donut-wrap { display: flex; flex-wrap: wrap; gap: 16px; align-items: center; }
.donut { width: 168px; height: 168px; flex: none; margin: 0 auto; }
.donut path, .donut circle { cursor: pointer; transition: opacity .15s; }
.donut-legend { flex: 1 1 220px; min-width: 0; display: flex; flex-direction: column; }
.donut-row { display: flex; align-items: center; gap: 8px; padding: 5px 6px; border-radius: 6px; font-size: 14.5px; }
.donut-row.on { background: #f3f4f1; }
.donut-row i { width: 12px; height: 12px; border-radius: 3px; flex: none; }
.donut-row .grow { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.donut-row.sub { padding-left: 26px; color: var(--ink2); }
table.t { width: 100%; border-collapse: collapse; font-size: 15px; }
table.t td, table.t th { padding: 8px 4px; border-bottom: 1px solid var(--border); text-align: left; }
table.t th { font-size: 13px; color: var(--ink2); font-weight: 600; }
table.t td.n, table.t th.n { text-align: right; font-variant-numeric: tabular-nums; }

/* ---------- Payslip ---------- */
.slip { max-width: 440px; margin: 0 auto; background: #fff; border: 1px solid var(--border); border-radius: 14px; padding: 20px; }
.slip h2 { margin: 0; font-size: 19px; }
.slip .ln { display: flex; justify-content: space-between; gap: 12px; padding: 6px 0; border-bottom: 1px dashed var(--border); font-size: 15px; }
.slip .ln .sub { display: block; color: var(--ink2); font-size: 12.5px; }
.slip .net { display: flex; justify-content: space-between; font-size: 21px; font-weight: 700; padding-top: 12px; }
@media print {
  @page { size: A5; margin: 10mm; }
  body { background: #fff; }
  .no-print, .nav, .header, .toast-wrap { display: none !important; }
  .app { padding: 0 !important; }
  .overlay { position: static; background: none; display: block; }
  .sheet { max-height: none; box-shadow: none; padding: 0; }
  .slip { border: 0; }
}

/* ---------- Login ---------- */
.login { min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: 16px; }
.login .card { width: 100%; max-width: 380px; padding: 24px; }

/* ---------- Public Leave Form ---------- */
.lf { max-width: 520px; margin: 0 auto; padding: 16px 16px 40px; }
.lf h1 { font-size: 22px; margin: 6px 0 2px; }
.lf .names { display: grid; grid-template-columns: repeat(auto-fill, minmax(110px, 1fr)); gap: 8px; }
.lf .name-btn { height: 56px; border-radius: 12px; border: 2px solid var(--border); background: #fff; font-size: 18px;
  font-weight: 700; cursor: pointer; color: var(--ink); }
.lf .name-btn.on { border-color: var(--green); background: var(--green-soft); color: var(--green-ink); }
.lf .summary { background: #fff; border: 3px solid var(--green); border-radius: 16px; padding: 18px; font-size: 17px; }
.lf .summary .big { font-size: 26px; font-weight: 800; color: var(--green-ink); }
.lf .summary .ref { font-size: 30px; font-weight: 800; letter-spacing: 2px; }
.lf .summary .shot { background: var(--amber-soft); color: var(--amber); border-radius: 10px; padding: 10px 12px;
  font-weight: 700; font-size: 17px; }
.lf .kv { display: flex; justify-content: space-between; gap: 10px; padding: 5px 0; border-bottom: 1px solid var(--border); }
