/* ParkingHome — warm friendly admin */

:root {
  --accent: #2563eb;
  --accent-soft: color-mix(in oklab, var(--accent) 12%, transparent);
  --accent-strong: color-mix(in oklab, var(--accent) 80%, #000);
  --accent-ink: #fff;

  /* warm neutrals */
  --bg: #faf6ef;
  --bg-2: #f4ede0;
  --surface: #ffffff;
  --surface-2: #fbf7f0;
  --ink: #1f1812;
  --ink-2: #4a3f35;
  --ink-3: #8a7c6c;
  --line: #ece2d1;
  --line-2: #ddd0b9;

  --ok: #16804a;
  --ok-soft: #def3e4;
  --warn: #b76a05;
  --warn-soft: #fbebcf;
  --danger: #b3261e;
  --danger-soft: #fbdedb;
  --info-soft: color-mix(in oklab, var(--accent) 12%, #fff);

  --radius: 14px;
  --radius-sm: 10px;
  --radius-lg: 18px;

  --shadow-1: 0 1px 0 rgba(60,40,20,.04), 0 1px 2px rgba(60,40,20,.05);
  --shadow-2: 0 1px 0 rgba(60,40,20,.04), 0 6px 22px -8px rgba(60,40,20,.18);
  --shadow-3: 0 30px 80px -20px rgba(20,12,4,.35);

  --pad-card: 18px;
  --gap: 16px;
  --row-h: 44px;

  --font-thai: 'IBM Plex Sans Thai', 'Sarabun', system-ui, sans-serif;
  --font-num: 'Inter', 'IBM Plex Sans Thai', system-ui, sans-serif;
  --font-mono: 'IBM Plex Mono', ui-monospace, monospace;
  --fs: 15px;
}

[data-theme="dark"] {
  --bg: #16110b;
  --bg-2: #1d1812;
  --surface: #221c14;
  --surface-2: #2a2319;
  --ink: #f4ecdd;
  --ink-2: #d8cdba;
  --ink-3: #9f917c;
  --line: #352c20;
  --line-2: #463a2a;
  --ok-soft: #1b3826;
  --warn-soft: #3a2b10;
  --danger-soft: #3a1814;
  --info-soft: color-mix(in oklab, var(--accent) 22%, #1d1812);
  --shadow-2: 0 1px 0 rgba(0,0,0,.4), 0 6px 22px -8px rgba(0,0,0,.6);
}

[data-warmth="neutral"] {
  --bg: #f6f6f5;
  --bg-2: #ececea;
  --surface: #ffffff;
  --surface-2: #f9f9f8;
  --line: #e6e4e0;
  --line-2: #d4d1cb;
  --ink: #15171a;
  --ink-2: #3a3d44;
  --ink-3: #80848d;
}
[data-density="compact"] {
  --pad-card: 12px;
  --gap: 10px;
  --row-h: 36px;
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  font-family: var(--font-thai);
  font-size: calc(var(--fs) * var(--font-scale, 1));
  color: var(--ink);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}
button { font-family: inherit; font-size: inherit; color: inherit; }
input, select, textarea { font-family: inherit; font-size: inherit; color: inherit; }
.num, .mono { font-family: var(--font-num); font-variant-numeric: tabular-nums; }

/* ====== App shell ====== */
.app {
  display: grid;
  grid-template-columns: 248px 1fr;
  min-height: 100vh;
  background: var(--bg);
}
@media (max-width: 880px) {
  .app { grid-template-columns: 1fr; }
}

/* Sidebar */
.sidebar {
  background: var(--surface);
  border-right: 1px solid var(--line);
  display: flex; flex-direction: column;
  position: sticky; top: 0; height: 100vh;
  padding: 18px 14px;
  gap: 4px;
}
.brand {
  display: flex; align-items: center; gap: 12px;
  padding: 6px 8px 16px 8px;
  border-bottom: 1px dashed var(--line);
  margin-bottom: 10px;
}
.brand .logo {
  width: 40px; height: 40px; border-radius: 12px;
  background: var(--accent); color: var(--accent-ink);
  display: grid; place-items: center;
  font-weight: 700; font-family: var(--font-num);
  letter-spacing: -0.02em;
  box-shadow: 0 6px 16px -6px var(--accent);
}
.brand .name { font-weight: 600; font-size: 1.05rem; line-height: 1.1; }
.brand .sub { font-size: 0.78rem; color: var(--ink-3); }

.nav-section {
  font-size: 0.72rem; text-transform: uppercase; letter-spacing: 0.08em;
  color: var(--ink-3); padding: 12px 10px 6px;
}
.nav-item {
  display: flex; align-items: center; gap: 12px;
  padding: 10px 12px; border-radius: 10px;
  color: var(--ink-2); cursor: pointer;
  text-decoration: none;
  border: 1px solid transparent;
  user-select: none;
}
.nav-item:hover { background: var(--bg-2); color: var(--ink); }
.nav-item.active {
  background: var(--info-soft);
  color: var(--accent-strong);
  border-color: color-mix(in oklab, var(--accent) 25%, transparent);
  font-weight: 600;
}
.nav-item .badge {
  margin-left: auto;
  background: var(--danger-soft); color: var(--danger);
  font-size: 0.7rem; padding: 2px 8px; border-radius: 999px;
  font-weight: 600;
}

@media (max-width: 880px) {
  .sidebar {
    position: fixed; top: 0; left: 0; right: 0; height: auto;
    flex-direction: row; flex-wrap: wrap; padding: 8px;
    z-index: 50; border-bottom: 1px solid var(--line); border-right: none;
  }
  .brand { border: none; padding: 4px 8px; margin: 0 8px 0 0; }
  .nav-section { display: none; }
  .nav-item { padding: 6px 10px; font-size: 0.85rem; }
  .nav-item .label { display: none; }
  .nav-item.active .label { display: inline; }
}

/* Main */
.main {
  min-width: 0;
  display: flex; flex-direction: column;
}
.topbar {
  position: sticky; top: 0; z-index: 20;
  background: color-mix(in oklab, var(--bg) 85%, transparent);
  backdrop-filter: blur(8px);
  border-bottom: 1px solid var(--line);
  padding: 14px 28px;
  display: flex; align-items: center; gap: 16px;
}
.topbar h1 {
  margin: 0; font-size: 1.25rem; font-weight: 600;
}
.topbar .sub { color: var(--ink-3); font-size: 0.9rem; }
.topbar .spacer { flex: 1; }
.topbar .search {
  position: relative;
  width: 320px; max-width: 36vw;
}
.topbar .search input {
  width: 100%; padding: 9px 12px 9px 36px;
  border: 1px solid var(--line); border-radius: 10px;
  background: var(--surface);
}
.topbar .search svg {
  position: absolute; left: 11px; top: 50%; transform: translateY(-50%);
  color: var(--ink-3);
}
.topbar .iconbtn {
  width: 38px; height: 38px; border-radius: 10px;
  display: grid; place-items: center;
  background: var(--surface); border: 1px solid var(--line); cursor: pointer;
  color: var(--ink-2);
}
.topbar .iconbtn:hover { background: var(--bg-2); }

.content { padding: 24px 28px 60px; min-width: 0; }
@media (max-width: 600px) { .content { padding: 18px 14px 60px; } .topbar { padding: 12px 14px; } }

/* ===== Buttons ===== */
.btn {
  display: inline-flex; align-items: center; gap: 8px;
  padding: 9px 14px; border-radius: 10px;
  background: var(--surface); border: 1px solid var(--line);
  cursor: pointer; font-weight: 500; color: var(--ink);
  transition: background .12s, transform .06s;
}
.btn:hover { background: var(--bg-2); }
.btn:active { transform: translateY(1px); }
.btn.primary {
  background: var(--accent); color: var(--accent-ink); border-color: transparent;
  box-shadow: 0 4px 12px -4px var(--accent);
}
.btn.primary:hover { background: var(--accent-strong); }
.btn.ghost { background: transparent; border-color: transparent; }
.btn.ghost:hover { background: var(--bg-2); }
.btn.danger { color: var(--danger); border-color: color-mix(in oklab, var(--danger) 30%, var(--line)); }
.btn.sm { padding: 6px 10px; font-size: 0.85rem; border-radius: 8px; }
.btn.lg { padding: 12px 18px; font-size: 1.02rem; }
.btn[disabled] { opacity: 0.5; cursor: not-allowed; }

/* ===== Cards ===== */
.card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: var(--pad-card);
  box-shadow: var(--shadow-1);
}
.card-head {
  display: flex; align-items: center; gap: 10px;
  margin-bottom: 12px;
}
.card-head h2, .card-head h3 { margin: 0; }
.card-head h3 { font-size: 1rem; font-weight: 600; }
.card-head .spacer { flex: 1; }

/* KPI */
.kpi {
  padding: 18px 18px 16px;
  display: flex; flex-direction: column; gap: 6px;
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
  position: relative; overflow: hidden;
}
.kpi .label { color: var(--ink-3); font-size: 0.85rem; }
.kpi .val { font-size: 1.7rem; font-weight: 600; font-family: var(--font-num); letter-spacing: -0.02em; }
.kpi .sub { color: var(--ink-3); font-size: 0.82rem; }
.kpi .trend { display: inline-flex; align-items: center; gap: 4px; font-size: 0.85rem; font-weight: 600; }
.kpi .trend.up { color: var(--ok); }
.kpi .trend.down { color: var(--danger); }
.kpi .deco {
  position: absolute; right: -10px; top: -10px;
  width: 80px; height: 80px; border-radius: 50%;
  background: var(--info-soft); opacity: 0.5;
}

/* tag pill */
.pill {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 3px 10px; font-size: 0.78rem; border-radius: 999px;
  background: var(--bg-2); color: var(--ink-2); font-weight: 500;
  border: 1px solid transparent;
}
.pill.ok { background: var(--ok-soft); color: var(--ok); }
.pill.warn { background: var(--warn-soft); color: var(--warn); }
.pill.danger { background: var(--danger-soft); color: var(--danger); }
.pill.info { background: var(--info-soft); color: var(--accent-strong); }
.pill .dot { width: 6px; height: 6px; border-radius: 50%; background: currentColor; }

/* Tabs */
.tabs {
  display: inline-flex; gap: 2px;
  background: var(--bg-2); padding: 4px; border-radius: 12px;
  border: 1px solid var(--line);
}
.tab {
  padding: 7px 14px; border-radius: 9px; cursor: pointer;
  color: var(--ink-2); font-weight: 500; font-size: 0.92rem;
  background: transparent; border: none;
}
.tab.active { background: var(--surface); color: var(--ink); box-shadow: var(--shadow-1); }

/* Inputs */
.field { display: flex; flex-direction: column; gap: 6px; }
.field label { font-size: 0.85rem; color: var(--ink-2); font-weight: 500; }
.input, .select, .textarea {
  padding: 9px 12px; border: 1px solid var(--line); border-radius: 10px;
  background: var(--surface); width: 100%;
  transition: border-color .12s, box-shadow .12s;
}
.input:focus, .select:focus, .textarea:focus {
  outline: none; border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}
.textarea { min-height: 80px; resize: vertical; }

/* Tables */
.table-wrap { overflow: auto; border-radius: var(--radius); border: 1px solid var(--line); background: var(--surface); }
table.table { width: 100%; border-collapse: collapse; }
.table th, .table td {
  text-align: left; padding: 11px 14px; border-bottom: 1px solid var(--line);
  font-size: 0.92rem; vertical-align: middle;
}
.table th { color: var(--ink-3); font-weight: 500; font-size: 0.78rem; text-transform: uppercase; letter-spacing: 0.04em; background: var(--surface-2); }
.table tbody tr:hover { background: var(--bg-2); }
.table tbody tr:last-child td { border-bottom: none; }
.table td.num { text-align: right; font-family: var(--font-num); font-variant-numeric: tabular-nums; }
.table th.num { text-align: right; }

/* Modal */
.modal-backdrop {
  position: fixed; inset: 0;
  background: rgba(20,12,4,.45);
  display: grid; place-items: center;
  z-index: 100; padding: 20px;
  animation: fadein .15s ease;
}
.modal {
  background: var(--surface); border-radius: 16px;
  width: 100%; max-width: 560px;
  box-shadow: var(--shadow-3);
  border: 1px solid var(--line);
  max-height: 90vh; display: flex; flex-direction: column;
  animation: pop .18s ease;
}
.modal.lg { max-width: 780px; }
.modal.xl { max-width: 980px; }
.modal-head {
  padding: 18px 22px; border-bottom: 1px solid var(--line);
  display: flex; align-items: center; gap: 10px;
}
.modal-head h3 { margin: 0; font-size: 1.1rem; }
.modal-head .spacer { flex: 1; }
.modal-body { padding: 22px; overflow: auto; }
.modal-foot { padding: 16px 22px; border-top: 1px solid var(--line); display: flex; gap: 10px; justify-content: flex-end; }
@keyframes fadein { from { opacity: 0; } to { opacity: 1; } }
@keyframes pop { from { transform: translateY(8px) scale(0.98); opacity: 0; } to { transform: none; opacity: 1; } }

/* ===== Floor plan ===== */
.floor {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(86px, 1fr));
  gap: 10px;
}
.room-cell {
  position: relative;
  background: var(--surface); border: 1px solid var(--line);
  border-radius: 12px; padding: 12px 10px;
  cursor: pointer; transition: transform .08s, box-shadow .12s, border-color .12s;
  display: flex; flex-direction: column; gap: 4px;
  min-height: 88px;
}
.room-cell:hover { transform: translateY(-1px); box-shadow: var(--shadow-2); border-color: var(--line-2); }
.room-cell .no {
  font-family: var(--font-num); font-weight: 600; font-size: 1.05rem; letter-spacing: -0.02em;
}
.room-cell .who {
  font-size: 0.78rem; color: var(--ink-3); overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.room-cell .status-dot { position: absolute; top: 10px; right: 10px; width: 8px; height: 8px; border-radius: 50%; }
.room-cell[data-status="vacant"] .status-dot { background: #c8c1b3; }
.room-cell[data-status="occupied"] .status-dot { background: var(--ok); }
.room-cell[data-status="overdue"] .status-dot { background: var(--danger); }
.room-cell[data-status="daily"] .status-dot { background: var(--accent); }
.room-cell[data-status="cleaning"] .status-dot { background: var(--warn); }
.room-cell[data-status="occupied"] { background: color-mix(in oklab, var(--ok-soft) 50%, var(--surface)); border-color: color-mix(in oklab, var(--ok) 25%, var(--line)); }
.room-cell[data-status="overdue"] { background: color-mix(in oklab, var(--danger-soft) 50%, var(--surface)); border-color: color-mix(in oklab, var(--danger) 25%, var(--line)); }
.room-cell[data-status="daily"] { background: color-mix(in oklab, var(--info-soft) 60%, var(--surface)); border-color: color-mix(in oklab, var(--accent) 25%, var(--line)); }
.room-cell[data-status="cleaning"] { background: color-mix(in oklab, var(--warn-soft) 40%, var(--surface)); border-color: color-mix(in oklab, var(--warn) 25%, var(--line)); }
.room-cell .floor-tag { font-size: 0.66rem; color: var(--ink-3); }

/* Parking map */
.lot {
  background: var(--surface-2);
  border: 1px solid var(--line);
  border-radius: 16px;
  padding: 22px;
  display: grid;
  gap: 26px;
}
.lot-row {
  display: grid;
  grid-template-columns: 70px 1fr;
  gap: 16px;
  align-items: stretch;
}
.lot-row .lot-label {
  display: grid; place-items: center;
  background: var(--surface); border: 1px dashed var(--line-2); border-radius: 12px;
  font-weight: 600; color: var(--ink-3); font-family: var(--font-num);
}
.lot-row .spots {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(72px, 1fr));
  gap: 8px;
}
.spot {
  position: relative;
  background: var(--surface); border: 1px solid var(--line);
  border-radius: 8px; padding: 10px 8px;
  cursor: pointer; min-height: 72px;
  display: flex; flex-direction: column; justify-content: space-between;
  transition: transform .08s, box-shadow .1s, border-color .1s;
}
.spot:hover { transform: translateY(-1px); box-shadow: var(--shadow-2); }
.spot .no { font-family: var(--font-num); font-size: 0.86rem; font-weight: 600; }
.spot .plate { font-size: 0.72rem; color: var(--ink-3); font-family: var(--font-mono); }
.spot[data-status="occupied"] { background: color-mix(in oklab, var(--ok-soft) 60%, var(--surface)); border-color: color-mix(in oklab, var(--ok) 25%, var(--line)); }
.spot[data-status="daily"] { background: color-mix(in oklab, var(--info-soft) 70%, var(--surface)); border-color: color-mix(in oklab, var(--accent) 25%, var(--line)); }
.spot[data-status="overdue"] { background: color-mix(in oklab, var(--danger-soft) 60%, var(--surface)); border-color: color-mix(in oklab, var(--danger) 25%, var(--line)); }
.spot[data-status="reserved"] { background: color-mix(in oklab, var(--warn-soft) 50%, var(--surface)); border-color: color-mix(in oklab, var(--warn) 25%, var(--line)); }

/* Legend */
.legend { display: flex; gap: 14px; flex-wrap: wrap; align-items: center; font-size: 0.85rem; color: var(--ink-2); }
.legend .item { display: inline-flex; align-items: center; gap: 6px; }
.legend .swatch { width: 12px; height: 12px; border-radius: 4px; border: 1px solid var(--line); }

/* Chart */
.bars { display: grid; grid-template-columns: repeat(12, 1fr); gap: 8px; align-items: end; height: 200px; padding-top: 10px; }
.bar { background: var(--info-soft); border-radius: 6px 6px 0 0; position: relative; min-height: 6px; }
.bar.alt { background: color-mix(in oklab, var(--accent) 22%, var(--info-soft)); }
.bar .top { position: absolute; top: -22px; left: 0; right: 0; text-align: center; font-size: 0.7rem; color: var(--ink-3); font-family: var(--font-num); }
.bar-row { display: contents; }
.bars + .axis { display: grid; grid-template-columns: repeat(12, 1fr); gap: 8px; padding-top: 8px; font-size: 0.72rem; color: var(--ink-3); text-align: center; }

/* Grid helpers */
.grid { display: grid; gap: var(--gap); }
.cols-2 { grid-template-columns: repeat(auto-fit, minmax(280px, 1fr)); }
.cols-3 { grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); }
.cols-4 { grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); }
.row { display: flex; align-items: center; gap: 10px; }

/* Empty state */
.empty {
  text-align: center; padding: 40px 20px; color: var(--ink-3);
}

/* Hide on print */
@media print {
  @page { size: A4 portrait; margin: 0; }
  html, body { width: 210mm; height: 297mm; overflow: hidden; }
  body * { visibility: hidden !important; }
  #print-area, #print-area * { visibility: visible !important; }
  #print-area {
    display: flex !important;
    flex-direction: column;
    position: fixed;
    top: 0; left: 0;
    width: 210mm;
    height: 297mm;
    overflow: hidden;
    background: white;
  }
  .print-copy {
    width: 210mm;
    height: 146mm;
    overflow: hidden;
    flex-shrink: 0;
    box-sizing: border-box;
    padding: 6mm 8mm 4mm;
  }
  .print-copy .doc {
    padding: 0;
    max-width: none;
    background: white;
    box-shadow: none;
    zoom: 0.72;
  }
  .print-copy-sep {
    border: none;
    border-top: 1.5px dashed #bbb;
    height: 5mm;
    flex-shrink: 0;
    display: block !important;
  }
  .copy-label { display: block !important; }

  /* thermal receipt print — centered on page */
  #print-area.thermal-print {
    display: flex !important;
    flex-direction: column;
    align-items: center;
    justify-content: flex-start;
    padding-top: 12mm;
    height: auto !important;
    min-height: 297mm;
  }
  #print-area.thermal-print .doc.thermal {
    max-width: 80mm;
    width: 80mm;
    box-shadow: none;
    padding: 4mm 3mm;
    background: white;
    font-size: 11px;
  }
}

#print-area { display: none; }
.copy-label { display: none; }

/* Receipt / invoice docs */
.doc {
  background: white; color: #111;
  padding: 36px 40px; max-width: 800px; margin: 0 auto;
  font-family: var(--font-thai);
  border-radius: 4px;
  box-shadow: var(--shadow-2);
  border: 1px solid var(--line);
}
.doc.thermal {
  max-width: 320px; padding: 18px 14px;
  font-size: 0.85rem; border-radius: 0;
}
.doc h2 { margin: 0 0 4px; font-size: 1.4rem; }
.doc .docrow { display: flex; justify-content: space-between; gap: 12px; padding: 6px 0; }
.doc .docrow.bold { font-weight: 600; }
.doc .divider { border-top: 1px dashed #999; margin: 10px 0; }
.doc .small { font-size: 0.85rem; color: #555; }
.doc table { width: 100%; border-collapse: collapse; margin: 12px 0; }
.doc table th, .doc table td { text-align: left; padding: 8px 6px; border-bottom: 1px solid #e9e3d4; font-size: 0.9rem; }
.doc table th { background: #f7f1e2; }
.doc table td.num, .doc table th.num { text-align: right; font-variant-numeric: tabular-nums; }
.doc .total {
  border-top: 2px solid #111; margin-top: 14px; padding-top: 12px;
  display: flex; justify-content: space-between; font-size: 1.15rem; font-weight: 600;
}
.doc .stamp {
  display: inline-block; padding: 4px 10px;
  border: 2px solid var(--accent); color: var(--accent);
  font-weight: 700; transform: rotate(-6deg);
  border-radius: 6px; margin-top: 14px;
}

/* QR */
.qr-box {
  background: white; padding: 12px;
  border-radius: 8px; border: 1px solid var(--line);
  display: inline-grid; place-items: center; gap: 6px;
}
.qr-box .qr {
  display: grid; gap: 1px;
  width: 120px; height: 120px;
  grid-template-columns: repeat(21, 1fr);
  grid-template-rows: repeat(21, 1fr);
}
.qr-box .qr i { background: #111; }
.qr-box .lbl { font-size: 0.7rem; color: #555; }

/* Meter photo */
.meter-photo {
  background: repeating-linear-gradient(45deg, var(--bg-2) 0 8px, var(--surface-2) 8px 16px);
  border: 1px dashed var(--line-2); border-radius: 8px;
  display: grid; place-items: center; color: var(--ink-3);
  height: 90px; font-size: 0.78rem; font-family: var(--font-mono);
  cursor: pointer;
}
.meter-photo:hover { background: var(--info-soft); border-color: var(--accent); color: var(--accent-strong); }
.meter-photo.has-img {
  background: linear-gradient(135deg, #2b2a26 25%, #4a3f2c);
  color: white; border-style: solid;
}

/* Alert list */
.alert-item {
  display: flex; align-items: flex-start; gap: 12px;
  padding: 12px 4px; border-bottom: 1px solid var(--line);
}
.alert-item:last-child { border: none; }
.alert-item .ico {
  width: 32px; height: 32px; border-radius: 8px;
  display: grid; place-items: center; flex-shrink: 0;
}
.alert-item .ico.warn { background: var(--warn-soft); color: var(--warn); }
.alert-item .ico.danger { background: var(--danger-soft); color: var(--danger); }
.alert-item .ico.info { background: var(--info-soft); color: var(--accent-strong); }

/* tweak panel positioning */
.tweaks-panel { font-family: var(--font-thai); }
