/* ===========================================================
   ระบบจัดการหอพัก — Design tokens & styles
   =========================================================== */
:root {
  --bg: #f4f3ef;
  --surface: #ffffff;
  --surface-2: #faf9f6;
  --ink: #1b2430;
  --ink-2: #3d4754;
  --muted: #6b7380;
  --line: #e6e3dc;
  --line-2: #efede8;

  --brand: #0f766e;
  --brand-600: #0c625b;
  --brand-soft: #e2f1ee;

  --side: #14202a;
  --side-ink: #c9d3dc;
  --side-muted: #7d8b98;

  --ok: #15803d;      --ok-soft: #e5f4e9;
  --info: #2c5cc5;    --info-soft: #e8eefb;
  --warn: #b45309;    --warn-soft: #fcf0dc;
  --bad: #c42b2b;     --bad-soft: #fce9e8;

  --radius: 14px;
  --radius-sm: 9px;
  --shadow: 0 1px 2px rgba(20, 32, 42, .05), 0 2px 10px rgba(20, 32, 42, .04);
  --shadow-lg: 0 20px 60px rgba(20, 32, 42, .22);
  --font: "IBM Plex Sans Thai", "Noto Sans Thai", "Sarabun", "Leelawadee UI", system-ui, -apple-system, "Segoe UI", sans-serif;
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  font-family: var(--font);
  background: var(--bg);
  color: var(--ink);
  font-size: 15px;
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
}
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
.ic { width: 18px; height: 18px; flex: none; }
.muted { color: var(--muted); }
.num { font-variant-numeric: tabular-nums; }
.right { text-align: right; }
.spacer { flex: 1; }
.nowrap { white-space: nowrap; }

/* ---------- Layout ---------- */
.app { display: grid; grid-template-columns: 236px 1fr; min-height: 100vh; }

.sidebar {
  background: var(--side);
  color: var(--side-ink);
  padding: 20px 14px;
  position: sticky; top: 0;
  height: 100vh;
  display: flex; flex-direction: column; gap: 24px;
}
.brand { display: flex; align-items: center; gap: 11px; padding: 2px 8px; }
.brand-mark {
  width: 38px; height: 38px; border-radius: 11px;
  background: var(--brand); color: #fff;
  display: grid; place-items: center;
}
.brand-mark .ic { width: 21px; height: 21px; }
.brand-name { font-weight: 600; color: #fff; font-size: 15px; line-height: 1.25; }
.brand-sub { font-size: 12px; color: var(--side-muted); }

.nav { display: flex; flex-direction: column; gap: 2px; }
.nav a {
  display: flex; align-items: center; gap: 12px;
  padding: 10px 12px; border-radius: 10px;
  color: var(--side-ink); text-decoration: none; font-size: 14.5px;
  transition: background .15s, color .15s;
}
.nav a:hover { background: rgba(255, 255, 255, .06); color: #fff; }
.nav a.active { background: rgba(45, 212, 191, .14); color: #fff; box-shadow: inset 3px 0 0 #2dd4bf; }
.nav .ic { width: 19px; height: 19px; }
.nav-badge {
  margin-left: auto; background: var(--bad); color: #fff;
  font-size: 11px; line-height: 18px; padding: 0 7px; border-radius: 99px; font-weight: 600;
}
.side-foot { margin-top: auto; font-size: 12px; color: var(--side-muted); padding: 0 8px; line-height: 1.6; }

.main { min-width: 0; display: flex; flex-direction: column; }
.topbar {
  display: flex; align-items: flex-end; justify-content: space-between; gap: 16px;
  padding: 26px 32px 4px;
}
.topbar h1 { margin: 0; font-size: 25px; font-weight: 600; letter-spacing: -.01em; line-height: 1.3; }
.topbar .sub { color: var(--muted); font-size: 14px; }
.today {
  font-size: 13px; color: var(--ink-2);
  background: var(--surface); border: 1px solid var(--line);
  padding: 6px 13px; border-radius: 99px; white-space: nowrap;
}
#view { padding: 18px 32px 56px; display: flex; flex-direction: column; gap: 20px; }

/* ---------- Cards ---------- */
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); min-width: 0; }
.card-head {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 15px 20px; border-bottom: 1px solid var(--line-2);
}
.card-head h2 { margin: 0; font-size: 16px; font-weight: 600; }
.card-head .hint { font-size: 13px; color: var(--muted); }
.card-body { padding: 18px 20px; }
.card-body.flush { padding: 0; }

.grid-2 { display: grid; grid-template-columns: minmax(0, 1.45fr) minmax(0, 1fr); gap: 20px; align-items: start; }
.stack { display: flex; flex-direction: column; gap: 20px; min-width: 0; }

/* ---------- KPI ---------- */
.kpis { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 16px; }
.kpi { padding: 18px 20px; display: flex; flex-direction: column; gap: 4px; }
.kpi-label { font-size: 13.5px; color: var(--muted); display: flex; align-items: center; gap: 8px; }
.kpi-label .ic { width: 16px; height: 16px; }
.kpi-value { font-size: 28px; font-weight: 600; letter-spacing: -.02em; line-height: 1.25; font-variant-numeric: tabular-nums; }
.kpi-foot { font-size: 13px; color: var(--muted); }
.kpi.tone-bad .kpi-value { color: var(--bad); }
.meter-bar { height: 6px; background: var(--line-2); border-radius: 99px; overflow: hidden; margin-top: 8px; }
.meter-bar > span { display: block; height: 100%; background: var(--brand); border-radius: 99px; }

/* ---------- Buttons ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 7px;
  height: 38px; padding: 0 15px; border-radius: var(--radius-sm);
  border: 1px solid var(--line); background: var(--surface);
  font-size: 14px; font-weight: 500; white-space: nowrap;
  transition: background .15s, border-color .15s, box-shadow .15s;
}
.btn:hover { background: var(--surface-2); border-color: #d6d2c8; }
a.btn { text-decoration: none; color: inherit; }
.btn:focus-visible, .icon-btn:focus-visible, .chip:focus-visible, .tile:focus-visible, .room-card:focus-visible, .nav a:focus-visible {
  outline: 2px solid var(--brand); outline-offset: 2px;
}
.btn.primary { background: var(--brand); border-color: var(--brand); color: #fff; }
.btn.primary:hover { background: var(--brand-600); border-color: var(--brand-600); }
.btn.danger { background: var(--bad); border-color: var(--bad); color: #fff; }
.btn.danger:hover { filter: brightness(.94); }
.btn.ghost { background: transparent; border-color: transparent; }
.btn.ghost:hover { background: var(--line-2); }
.btn.sm { height: 32px; padding: 0 11px; font-size: 13px; border-radius: 8px; }
.btn.text-bad { color: var(--bad); }
.btn[disabled] { opacity: .5; pointer-events: none; }
.icon-btn {
  width: 34px; height: 34px; display: inline-grid; place-items: center;
  border: 0; background: transparent; border-radius: 8px; color: var(--muted);
}
.icon-btn:hover { background: var(--line-2); color: var(--ink); }

/* ---------- Toolbar & chips ---------- */
.toolbar { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.chips { display: inline-flex; gap: 4px; background: var(--surface); border: 1px solid var(--line); padding: 4px; border-radius: 11px; flex-wrap: wrap; }
.chip {
  border: 0; background: transparent; padding: 5px 12px; border-radius: 8px;
  font-size: 13.5px; color: var(--ink-2); display: inline-flex; align-items: center; gap: 6px;
}
.chip:hover { background: var(--line-2); }
.chip.on { background: var(--ink); color: #fff; }
.chip .count { font-size: 12px; opacity: .7; font-variant-numeric: tabular-nums; }
.search {
  display: flex; align-items: center; gap: 8px;
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius-sm);
  padding: 0 12px; height: 38px; min-width: 220px; color: var(--muted);
}
.search input { border: 0; outline: 0; background: transparent; flex: 1; min-width: 0; color: var(--ink); }
.search:focus-within { border-color: var(--brand); box-shadow: 0 0 0 3px var(--brand-soft); }
.select {
  height: 38px; border-radius: var(--radius-sm); border: 1px solid var(--line);
  background: var(--surface); padding: 0 12px;
}
.check { display: inline-flex; align-items: center; gap: 8px; font-size: 14px; color: var(--ink-2); }

/* ---------- Status badges ---------- */
.badge {
  display: inline-flex; align-items: center; gap: 5px;
  font-size: 12px; font-weight: 500; line-height: 20px;
  padding: 0 9px; border-radius: 99px; white-space: nowrap;
}
.badge::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: currentColor; }
.s-vacant   { --c: var(--ok);   --cs: var(--ok-soft); }
.s-occupied { --c: var(--info); --cs: var(--info-soft); }
.s-blocked  { --c: var(--warn); --cs: var(--warn-soft); }
.s-paid     { --c: var(--ok);   --cs: var(--ok-soft); }
.s-unpaid   { --c: var(--warn); --cs: var(--warn-soft); }
.s-overdue  { --c: var(--bad);  --cs: var(--bad-soft); }
.s-pending  { --c: var(--warn); --cs: var(--warn-soft); }
.s-progress { --c: var(--info); --cs: var(--info-soft); }
.s-done     { --c: var(--ok);   --cs: var(--ok-soft); }
.s-high     { --c: var(--bad);  --cs: var(--bad-soft); }
.s-normal   { --c: var(--info); --cs: var(--info-soft); }
.s-low      { --c: var(--muted); --cs: var(--line-2); }
.badge { color: var(--c); background: var(--cs); }

.legend { display: flex; gap: 14px; flex-wrap: wrap; font-size: 13px; color: var(--muted); }
.legend span { display: inline-flex; align-items: center; gap: 6px; }
.legend i { width: 10px; height: 10px; border-radius: 3px; background: var(--c); }

/* ---------- Floor map (dashboard) ---------- */
.floors { display: flex; flex-direction: column; gap: 14px; }
.floor { display: grid; grid-template-columns: 54px 1fr; gap: 10px; align-items: center; }
.floor-label { font-size: 13px; color: var(--muted); font-weight: 500; }
.tiles { display: grid; grid-template-columns: repeat(auto-fill, minmax(58px, 1fr)); gap: 8px; }
.tile {
  position: relative; border: 1px solid transparent; border-radius: 10px;
  background: var(--cs); color: var(--c);
  padding: 8px 4px 7px; text-align: center; line-height: 1.2;
  transition: transform .12s, box-shadow .12s;
}
.tile:hover { transform: translateY(-1px); box-shadow: 0 4px 12px rgba(20, 32, 42, .1); border-color: var(--c); }
.tile b { display: block; font-size: 14.5px; font-weight: 600; font-variant-numeric: tabular-nums; }
.tile small { display: block; font-size: 11px; color: var(--ink-2); opacity: .8; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.dot-alert {
  position: absolute; top: -4px; right: -4px; width: 11px; height: 11px;
  border-radius: 50%; background: var(--bad); border: 2px solid var(--surface);
}

/* ---------- Room cards ---------- */
.floor-block + .floor-block { margin-top: 26px; }
.floor-title { display: flex; align-items: baseline; gap: 10px; margin: 0 0 12px; font-size: 15px; font-weight: 600; }
.floor-title span { font-size: 13px; font-weight: 400; color: var(--muted); }
.room-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(178px, 1fr)); gap: 12px; }
.room-card {
  position: relative; text-align: left;
  background: var(--surface); border: 1px solid var(--line); border-radius: 12px;
  padding: 14px 15px 13px; display: flex; flex-direction: column; gap: 4px;
  box-shadow: var(--shadow); transition: border-color .15s, transform .12s, box-shadow .15s;
  border-top: 3px solid var(--c);
}
.room-card:hover { transform: translateY(-1px); box-shadow: 0 6px 18px rgba(20, 32, 42, .09); }
.rc-top { display: flex; justify-content: space-between; align-items: center; gap: 8px; }
.rc-num { font-size: 20px; font-weight: 600; font-variant-numeric: tabular-nums; letter-spacing: -.01em; }
.rc-tenant { font-size: 14px; color: var(--ink-2); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; min-height: 22px; }
.rc-tenant.empty { color: var(--muted); }
.rc-meta { font-size: 12.5px; color: var(--muted); }
.rc-foot { display: flex; align-items: baseline; justify-content: space-between; gap: 8px; margin-top: 2px; }
.rc-rent { font-size: 14px; font-weight: 600; font-variant-numeric: tabular-nums; }
.rc-rent small { font-weight: 400; color: var(--muted); font-size: 12px; }
.rc-flag { font-size: 12px; color: var(--bad); font-weight: 600; white-space: nowrap; }

/* ---------- Lists ---------- */
.list { list-style: none; margin: 0; padding: 0; }
.list li { display: flex; align-items: center; gap: 12px; padding: 12px 20px; border-top: 1px solid var(--line-2); }
.list li:first-child { border-top: 0; }
.list .li-main { flex: 1; min-width: 0; }
.list .li-title { font-weight: 500; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.list .li-sub { font-size: 13px; color: var(--muted); }
.room-pill {
  flex: none; min-width: 46px; height: 32px; padding: 0 8px; border-radius: 8px;
  display: grid; place-items: center; background: var(--line-2);
  font-weight: 600; font-size: 13.5px; font-variant-numeric: tabular-nums;
}
.empty-state { padding: 34px 20px; text-align: center; color: var(--muted); font-size: 14px; }
.empty-state .ic { width: 28px; height: 28px; display: block; margin: 0 auto 8px; opacity: .6; }

/* ---------- Tables ---------- */
.table-wrap { overflow-x: auto; }
table.table { width: 100%; border-collapse: collapse; font-size: 14px; }
.table th {
  text-align: left; font-weight: 500; font-size: 12.5px; color: var(--muted);
  padding: 10px 14px; border-bottom: 1px solid var(--line); background: var(--surface-2); white-space: nowrap;
}
.table td { padding: 11px 14px; border-bottom: 1px solid var(--line-2); vertical-align: middle; }
.table tr:last-child td { border-bottom: 0; }
.table tbody tr:hover td { background: #fcfbf9; }
.table .right, .table th.right { text-align: right; }
.table .actions { display: flex; gap: 4px; justify-content: flex-end; }
.table .t-strong { font-weight: 500; }
.table .t-sub { font-size: 12.5px; color: var(--muted); }
.table tr.inactive td { color: var(--muted); }
.th-group { text-align: center !important; border-left: 1px solid var(--line); }
.bl { border-left: 1px solid var(--line-2); }

/* Meter inputs */
.meter-input {
  width: 96px; height: 34px; border: 1px solid var(--line); border-radius: 8px;
  padding: 0 10px; text-align: right; background: var(--surface); font-variant-numeric: tabular-nums;
}
.meter-input:focus { outline: 0; border-color: var(--brand); box-shadow: 0 0 0 3px var(--brand-soft); }
.meter-input:disabled { background: var(--line-2); color: var(--muted); }
.meter-row.err .meter-input { border-color: var(--bad); background: var(--bad-soft); }
.ms-input {
  width: 120px; height: 34px; border: 1px solid var(--line); border-radius: 8px;
  padding: 0 10px; text-align: right; background: var(--surface); font-variant-numeric: tabular-nums;
}
.ms-input:focus { outline: 0; border-color: var(--brand); box-shadow: 0 0 0 3px var(--brand-soft); }
.ms-month { height: 34px; font-size: 13.5px; }
.ms-row.err td { background: var(--bad-soft) !important; }
.ms-row.err .ms-input { border-color: var(--bad); }
.ms-row td .ic { width: 14px; height: 14px; vertical-align: -2px; }
.unit-cell { font-variant-numeric: tabular-nums; color: var(--ink-2); }
.unit-cell.neg { color: var(--bad); font-weight: 600; }
.meter-ico { display: inline-flex; align-items: center; gap: 5px; }
.meter-ico .ic { width: 15px; height: 15px; }
.c-water { color: #2563eb; }
.c-elec { color: #d97706; }

/* Summary strip */
.summary { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); }
.summary > div { padding: 14px 20px; border-left: 1px solid var(--line-2); }
.summary > div:first-child { border-left: 0; }
.summary .s-label { font-size: 13px; color: var(--muted); }
.summary .s-value { font-size: 20px; font-weight: 600; font-variant-numeric: tabular-nums; }
.notice {
  display: flex; align-items: center; gap: 12px; flex-wrap: wrap;
  padding: 12px 16px; border-radius: 12px;
  background: var(--brand-soft); color: #0b4f4a; font-size: 14px;
}
.notice.warn { background: var(--warn-soft); color: #7a3d06; }
.notice .ic { width: 18px; height: 18px; }

/* ---------- Kanban (maintenance) ---------- */
.kanban { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 16px; align-items: start; }
.col { background: #ecebe6; border-radius: var(--radius); padding: 12px; display: flex; flex-direction: column; gap: 10px; min-height: 140px; }
.col-head { display: flex; align-items: center; gap: 8px; padding: 2px 4px 4px; font-weight: 600; font-size: 14px; }
.col-head .n { font-weight: 500; color: var(--muted); font-size: 13px; }
.ticket { background: var(--surface); border-radius: 11px; padding: 12px 13px; box-shadow: var(--shadow); display: flex; flex-direction: column; gap: 6px; border: 1px solid var(--line); }
.ticket-top { display: flex; align-items: center; gap: 8px; }
.ticket-title { font-weight: 500; }
.ticket-detail { font-size: 13px; color: var(--ink-2); }
.ticket-foot { display: flex; align-items: center; gap: 4px; font-size: 12.5px; color: var(--muted); }
.ticket-foot .icon-btn { width: 30px; height: 30px; }

/* ---------- Forms ---------- */
.form-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 14px 16px; }
.form-grid.three { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.field { display: flex; flex-direction: column; gap: 6px; min-width: 0; }
.field.full { grid-column: 1 / -1; }
.field > span { font-size: 13.5px; color: var(--ink-2); font-weight: 500; }
.field > span em { color: var(--bad); font-style: normal; }
.field small { font-size: 12.5px; color: var(--muted); }
.field .check { padding: 4px 0; }
.field .check input { width: 18px; height: 18px; flex: none; margin: 0; padding: 0; accent-color: var(--brand); }
.field input:not([type="checkbox"]):not([type="radio"]), .field select, .field textarea {
  height: 40px; border: 1px solid var(--line); border-radius: var(--radius-sm);
  padding: 0 12px; background: var(--surface); width: 100%;
}
.field textarea { height: auto; min-height: 76px; padding: 9px 12px; resize: vertical; }
.field input:focus, .field select:focus, .field textarea:focus { outline: 0; border-color: var(--brand); box-shadow: 0 0 0 3px var(--brand-soft); }
.input-suffix { position: relative; }
.input-suffix input { padding-right: 64px; }
.input-suffix b { position: absolute; right: 12px; top: 50%; transform: translateY(-50%); font-weight: 400; font-size: 13px; color: var(--muted); }
.section-title { margin: 6px 0 0; font-size: 13px; font-weight: 600; color: var(--muted); text-transform: none; letter-spacing: .02em; grid-column: 1 / -1; }
.hint-list { margin: 14px 0 0; padding-left: 18px; color: var(--muted); font-size: 13px; line-height: 1.75; }
.hint-list b { color: var(--ink-2); font-weight: 600; }
.import-issues { margin-top: 14px; padding: 12px 14px; border-radius: 10px; background: var(--bad-soft); font-size: 13px; display: flex; flex-direction: column; gap: 5px; max-height: 220px; overflow-y: auto; }
.import-issues > div { display: flex; gap: 8px; align-items: flex-start; }
.import-issues .ic { width: 15px; height: 15px; color: var(--bad); margin-top: 3px; flex: none; }
.form-actions { display: flex; gap: 10px; justify-content: flex-end; padding-top: 4px; }

/* ---------- Detail (room modal) ---------- */
.facts { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 10px; }
.fact { background: var(--surface-2); border: 1px solid var(--line-2); border-radius: 10px; padding: 10px 12px; }
.fact > span:first-child { display: block; font-size: 12px; color: var(--muted); }
.fact b { font-weight: 600; font-variant-numeric: tabular-nums; }
.block-title { margin: 20px 0 10px; font-size: 14px; font-weight: 600; display: flex; align-items: center; justify-content: space-between; }
.person {
  display: flex; align-items: center; gap: 14px; padding: 14px; border-radius: 12px;
  border: 1px solid var(--line); background: var(--surface);
}
.avatar {
  width: 44px; height: 44px; border-radius: 50%; flex: none;
  display: grid; place-items: center; font-weight: 600; font-size: 17px;
  background: var(--info-soft); color: var(--info);
}
.person .p-main { flex: 1; min-width: 0; }
.person .p-name { font-weight: 600; }
.person .p-sub { font-size: 13px; color: var(--muted); }
.mini-table { width: 100%; border-collapse: collapse; font-size: 13.5px; }
.mini-table td { padding: 8px 2px; border-bottom: 1px solid var(--line-2); }
.mini-table tr:last-child td { border-bottom: 0; }

/* ---------- Modal ---------- */
#modal-root { position: fixed; inset: 0; z-index: 50; display: none; }
#modal-root.open { display: grid; place-items: center; padding: 20px; }
.backdrop { position: absolute; inset: 0; background: rgba(15, 23, 31, .45); animation: fade .15s ease-out; }
.modal {
  position: relative; width: min(560px, 100%); max-height: calc(100vh - 40px);
  background: var(--surface); border-radius: 16px; box-shadow: var(--shadow-lg);
  display: flex; flex-direction: column; animation: pop .18s ease-out;
}
.modal.wide { width: min(760px, 100%); }
.modal form { display: flex; flex-direction: column; min-height: 0; flex: 1; }
.modal-head { display: flex; align-items: center; gap: 12px; padding: 18px 22px 14px; border-bottom: 1px solid var(--line-2); }
.modal-head h2 { margin: 0; font-size: 18px; font-weight: 600; flex: 1; }
.modal-body { padding: 18px 22px; overflow-y: auto; }
.modal-foot { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; padding: 14px 22px; border-top: 1px solid var(--line-2); background: var(--surface-2); border-radius: 0 0 16px 16px; }
@keyframes fade { from { opacity: 0; } }
@keyframes pop { from { opacity: 0; transform: translateY(8px) scale(.98); } }

/* ---------- Toast ---------- */
#toast {
  position: fixed; left: 50%; bottom: 28px; transform: translate(-50%, 20px);
  background: var(--ink); color: #fff; padding: 11px 18px; border-radius: 12px;
  font-size: 14px; box-shadow: var(--shadow-lg); opacity: 0; pointer-events: none;
  transition: opacity .2s, transform .2s; z-index: 60; max-width: calc(100vw - 32px);
}
#toast.show { opacity: 1; transform: translate(-50%, 0); }
#toast.bad { background: var(--bad); }

/* ---------- Invoice ---------- */
.invoice { color: #111; font-size: 14px; }
.inv-head { display: flex; justify-content: space-between; gap: 20px; padding-bottom: 16px; border-bottom: 2px solid #111; }
.inv-dorm { font-size: 19px; font-weight: 700; }
.inv-head .muted { font-size: 13px; }
.inv-title { text-align: right; }
.inv-title h3 { margin: 0 0 4px; font-size: 17px; }
.inv-title div { font-size: 13px; color: #444; }
.inv-to { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 10px; padding: 14px 0; }
.inv-to span { display: block; font-size: 12px; color: #666; }
.inv-to b { font-weight: 600; }
.inv-table { width: 100%; border-collapse: collapse; }
.inv-table th { text-align: left; font-size: 12.5px; font-weight: 600; padding: 8px 6px; border-bottom: 1px solid #bbb; background: #f6f6f4; }
.inv-table td { padding: 9px 6px; border-bottom: 1px solid #e5e5e5; font-variant-numeric: tabular-nums; }
.inv-table .right { text-align: right; }
.inv-total { display: flex; justify-content: space-between; align-items: center; gap: 12px; padding: 14px 6px; border-bottom: 2px solid #111; }
.inv-total .words { font-size: 13px; color: #333; }
.inv-total .amount { font-size: 21px; font-weight: 700; font-variant-numeric: tabular-nums; }
.inv-foot { display: flex; justify-content: space-between; gap: 20px; padding-top: 14px; font-size: 13px; color: #333; align-items: flex-end; }
.stamp { border: 2px solid var(--ok); color: var(--ok); padding: 6px 14px; border-radius: 8px; font-weight: 700; transform: rotate(-4deg); text-align: center; line-height: 1.3; }
.stamp small { display: block; font-weight: 500; font-size: 11.5px; }
.stamp.due { border-color: var(--warn); color: var(--warn); }
.sign { text-align: center; min-width: 180px; }
.sign .line { border-bottom: 1px dotted #555; height: 36px; margin-bottom: 4px; }

#print-area { display: none; }

@media print {
  @page { size: A5 landscape; margin: 12mm; }
  body { background: #fff; }
  body > *:not(#print-area) { display: none !important; }
  #print-area { display: block; }
}

/* ---------- Server mode: sign-in, sync, tenant items ---------- */
.auth-screen { position: fixed; inset: 0; z-index: 70; background: var(--bg); display: grid; place-items: center; padding: 20px; }
.auth-screen[hidden] { display: none; }
.auth-card {
  width: min(400px, 100%); background: var(--surface); border: 1px solid var(--line); border-radius: 18px;
  box-shadow: var(--shadow-lg); padding: 30px 28px; display: flex; flex-direction: column; gap: 14px;
}
.auth-card h1 { margin: 4px 0 0; font-size: 22px; font-weight: 600; }
.auth-card p { margin: 0; }
.auth-mark { width: 48px; height: 48px; border-radius: 14px; }
.auth-error { color: var(--bad); font-size: 13.5px; min-height: 1px; }
.auth-error:empty { display: none; }
.sync { font-size: 12px; color: var(--side-muted); display: flex; align-items: center; gap: 6px; flex-wrap: wrap; margin-bottom: 8px; }
.sync::before { content: ""; width: 7px; height: 7px; border-radius: 50%; background: #34d399; }
.sync.saving::before { background: #fbbf24; }
.sync.error { color: #fca5a5; }
.sync.error::before { background: #f87171; }
.side-link { border: 0; background: none; color: var(--side-ink); font-size: 12.5px; padding: 4px 0; display: inline-flex; align-items: center; gap: 6px; text-decoration: underline; text-underline-offset: 3px; }
.side-link .ic { width: 15px; height: 15px; }
.side-link:hover { color: #fff; }
.tag { display: inline-block; font-size: 11px; font-weight: 600; line-height: 18px; padding: 0 7px; border-radius: 6px; background: var(--brand-soft); color: var(--brand-600); vertical-align: 1px; }
.pin { color: var(--brand); display: inline-flex; vertical-align: -3px; margin-right: 4px; }
.pin .ic { width: 15px; height: 15px; }
.ann-body { white-space: normal; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.slip-grid { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1.1fr); gap: 20px; align-items: start; }
.slip-frame { display: block; background: var(--surface-2); border: 1px solid var(--line); border-radius: 12px; padding: 8px; text-align: center; }
.slip-img { display: block; max-width: 100%; max-height: 60vh; margin: 0 auto; border-radius: 8px; }
.url-list { display: flex; flex-direction: column; gap: 8px; }
.url-row { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.url-row code, .url-list code { font-size: 15px; background: var(--surface-2); border: 1px solid var(--line); padding: 6px 12px; border-radius: 8px; font-family: ui-monospace, Consolas, monospace; }

/* ---------- Responsive ---------- */
@media (max-width: 1180px) {
  .kpis { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .grid-2 { grid-template-columns: minmax(0, 1fr); }
}
@media (max-width: 860px) {
  .app { grid-template-columns: minmax(0, 1fr); }
  .sidebar {
    position: fixed; top: auto; bottom: 0; left: 0; right: 0; height: auto; z-index: 40;
    padding: 6px 6px calc(6px + env(safe-area-inset-bottom)); flex-direction: row;
  }
  .brand, .side-foot { display: none; }
  .nav { flex-direction: row; width: 100%; justify-content: space-between; gap: 0; }
  .nav a { flex-direction: column; gap: 2px; padding: 6px 0; font-size: 10.5px; flex: 1 1 0; min-width: 0; text-align: center; position: relative; white-space: nowrap; }
  .nav a.active { box-shadow: none; }
  .nav-badge { position: absolute; top: 2px; right: 50%; transform: translateX(18px); font-size: 10px; line-height: 15px; padding: 0 5px; }
  .topbar { padding: 18px 16px 0; }
  .topbar h1 { font-size: 21px; }
  #view { padding: 14px 16px 96px; }
  .kanban { grid-template-columns: 1fr; }
  .summary { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .summary > div:nth-child(3) { border-left: 0; }
  .summary > div:nth-child(n+3) { border-top: 1px solid var(--line-2); }
  .facts, .inv-to { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .search { min-width: 0; flex: 1; }
  .today { display: none; }
  .slip-grid { grid-template-columns: 1fr; }
}
@media (max-width: 560px) {
  .kpis { grid-template-columns: 1fr 1fr; gap: 10px; }
  .kpi { padding: 14px; }
  .kpi-value { font-size: 22px; }
  .form-grid, .form-grid.three { grid-template-columns: 1fr; }
  .room-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .floor { grid-template-columns: 1fr; gap: 6px; }
  #modal-root.open { padding: 0; place-items: end stretch; }
  .modal, .modal.wide { width: 100%; max-height: 92vh; border-radius: 16px 16px 0 0; }
  .modal-foot { border-radius: 0; }
}

/* Links inside notices and hint lines */
.notice a, p.muted a { color: var(--brand); font-weight: 500; }

/* ---------- Announcements page ---------- */
.ann-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(320px, 1fr)); gap: 16px; align-items: start; }
.ann-card { padding: 16px 18px 12px; display: flex; flex-direction: column; gap: 6px; }
.ann-card h3 { margin: 0; font-size: 16.5px; font-weight: 600; }
.ann-card p { margin: 0; font-size: 14px; color: var(--ink-2); white-space: pre-line; }
.ann-card footer { display: flex; align-items: center; gap: 4px; margin-top: 6px; padding-top: 8px; border-top: 1px solid var(--line-2); font-size: 12.5px; }
.ann-card.important { border-color: #f3c2c2; box-shadow: inset 3px 0 0 var(--bad), var(--shadow); }
.ann-card.expired { opacity: .62; }
.ann-tags { display: flex; flex-wrap: wrap; gap: 6px; }
.ann-tags:empty { display: none; }
.tag.ann-pin { display: inline-flex; align-items: center; gap: 3px; color: var(--brand-600); background: var(--brand-soft); }
.tag.ann-pin .ic { width: 12px; height: 12px; }
.tag.ann-imp { color: var(--bad); background: var(--bad-soft); }
.chip b { font-weight: 600; margin-left: 2px; }

/* Picture viewer */
body.lb-open { overflow: hidden; }
.lightbox { position: fixed; inset: 0; z-index: 90; background: rgba(10, 14, 18, .96); display: flex; flex-direction: column; animation: lb-in .15s ease-out; }
@keyframes lb-in { from { opacity: 0; } }
.lb-bar {
  display: flex; align-items: center; gap: 12px; color: #fff;
  padding: calc(10px + env(safe-area-inset-top)) 12px 10px 18px; flex: none;
}
.lb-title { font-weight: 600; font-size: 15px; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.lb-hint { color: rgba(255, 255, 255, .6); font-size: 13px; margin-right: auto; white-space: nowrap; }
.lb-close {
  display: inline-flex; align-items: center; gap: 6px; height: 44px; padding: 0 18px 0 14px; flex: none;
  border: 0; border-radius: 999px; background: #fff; color: #111; font: inherit; font-weight: 600; font-size: 15px; cursor: pointer;
}
.lb-close .ic { width: 20px; height: 20px; }
.lb-close:hover { background: #e9edf0; }
.lb-close:focus-visible { outline: 3px solid #7dd3c0; outline-offset: 2px; }
.lb-stage { flex: 1; min-height: 0; display: flex; align-items: center; justify-content: center; padding: 8px 16px calc(16px + env(safe-area-inset-bottom)); overflow: auto; }
.lb-stage img { max-width: 100%; max-height: 100%; object-fit: contain; border-radius: 8px; background: #fff; cursor: zoom-in; box-shadow: 0 10px 40px rgba(0, 0, 0, .5); }
.lightbox.zoomed .lb-stage { align-items: flex-start; justify-content: flex-start; }
.lightbox.zoomed .lb-stage img { max-width: none; max-height: none; cursor: zoom-out; margin: auto; }
@media (max-width: 560px) { .lb-hint { display: none; } .lb-title { margin-right: auto; } }
.slip-frame { cursor: zoom-in; }

/* Settings: internet access */
.remote-box { display: flex; flex-direction: column; gap: 10px; }
.remote-row { display: flex; align-items: center; gap: 14px; padding: 12px 14px; border: 1px solid var(--line); border-radius: 12px; background: var(--surface-2); }
.remote-row .url-row { margin-top: 6px; }
.remote-main { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 2px; }
.remote-main b { font-weight: 600; font-size: 14.5px; }
.remote-ico { width: 38px; height: 38px; border-radius: 10px; display: grid; place-items: center; flex: none; background: var(--line-2); color: var(--muted); }
.remote-ico.on { background: var(--brand-soft); color: var(--brand); }
.remote-ico.warn { background: var(--warn-soft); color: var(--warn); }
@media (max-width: 560px) { .remote-row { flex-wrap: wrap; } }
