/* ============================================================
   Tokens
   ============================================================ */
:root {
  --paper: #F4F5F1;
  --surface: #FFFFFF;
  --ink: #1E2321;
  --ink-soft: #5B6560;
  --ink-faint: #8A928C;
  --line: #DDE2DA;
  --line-strong: #C3CAC0;

  --brand: #2F5D50;
  --brand-dark: #234840;
  --brand-tint: #E4ECE7;

  --warning: #9C6510;
  --warning-tint: #FBEBD3;
  --warning-line: #E9C989;

  --alert: #B3311C;
  --alert-tint: #F6E4E0;
  --alert-line: #E7B4A8;

  --font-ui: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  --font-display: 'Space Grotesk', var(--font-ui);

  --radius-s: 6px;
  --radius-m: 10px;
  --shadow-panel: -8px 0 24px rgba(30, 35, 33, 0.08);
}

* { box-sizing: border-box; }
.is-hidden { display: none !important; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--paper);
  color: var(--ink);
  font-family: var(--font-ui);
  font-size: 14px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

button, input, select, textarea { font-family: inherit; font-size: inherit; color: inherit; }

h1, h2, h3 { margin: 0; font-weight: 600; }

.num { text-align: right; font-variant-numeric: tabular-nums; }

/* ============================================================
   Shell / rail
   ============================================================ */
.shell {
  display: grid;
  grid-template-columns: 240px 1fr;
  min-height: 100vh;
}

.rail {
  background: var(--brand-dark);
  color: #EFF3F0;
  padding: 22px 16px;
  display: flex;
  flex-direction: column;
  gap: 26px;
  position: sticky;
  top: 0;
  height: 100vh;
}

.rail-brand { display: flex; align-items: center; gap: 10px; padding: 0 6px; }
.rail-brand-mark { font-size: 20px; }
.rail-brand-title { font-weight: 600; font-size: 14.5px; letter-spacing: 0.1px; }
.rail-brand-sub { font-size: 12px; color: #B9C9C2; margin-top: 1px; }

.rail-nav { display: flex; flex-direction: column; gap: 2px; }

.rail-link {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 9px 10px;
  border: none;
  background: transparent;
  color: #D6E0DB;
  border-radius: var(--radius-s);
  text-align: left;
  cursor: pointer;
  font-weight: 500;
}
.rail-link-icon { width: 16px; text-align: center; opacity: 0.85; }
.rail-link:hover { background: rgba(255,255,255,0.06); color: #fff; }
.rail-link.is-active { background: rgba(255,255,255,0.12); color: #fff; }

.rail-cta { margin-top: auto; width: 100%; }
.rail-session { margin-top: auto; font-size: 12px; overflow-wrap: anywhere; }
.rail-session .rail-link { width: 100%; font-size: 12px; }
#sync-status { display: block; color: #B9C9C2; padding: 6px 10px; }
.login-screen { min-height: 100vh; display: grid; place-items: center; padding: 24px; }
.login-card { background: var(--surface); border: 1px solid var(--line); border-radius: 14px; padding: 32px; width: 420px; max-width: 100%; box-shadow: 0 12px 35px #23484010; }
.login-mark { font-size: 36px; }
.login-card .field:first-of-type { margin-top: 24px; }
.login-card .btn { width: 100%; }

/* ============================================================
   Content / views
   ============================================================ */
.content { padding: 28px 28px 56px; max-width: none; min-width: 0; }

.view.is-hidden { display: none; }

.view-header {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 20px;
  margin-bottom: 26px;
  flex-wrap: wrap;
}

.view-header h1 { font-size: 22px; }
.view-sub { margin: 4px 0 0; color: var(--ink-soft); font-size: 13.5px; }

.section-label {
  font-size: 13.5px;
  font-weight: 600;
  color: var(--ink);
  border-left: 3px solid var(--brand);
  padding-left: 10px;
  margin: 0 0 14px;
}

/* ============================================================
   Buttons / inputs
   ============================================================ */
.btn {
  border: 1px solid transparent;
  border-radius: var(--radius-s);
  padding: 8px 14px;
  font-weight: 600;
  font-size: 13.5px;
  cursor: pointer;
  white-space: nowrap;
}
.btn-primary { background: var(--brand); color: #fff; }
.btn-primary:hover { background: var(--brand-dark); }
.btn-ghost { background: transparent; border-color: var(--line-strong); color: var(--ink); }
.btn-ghost:hover { background: var(--surface); }
.btn-danger { background: transparent; border-color: var(--alert-line); color: var(--alert); }
.btn-danger:hover { background: var(--alert-tint); }

.icon-btn {
  border: none;
  background: transparent;
  color: var(--ink-soft);
  font-size: 15px;
  cursor: pointer;
  padding: 4px 8px;
  border-radius: var(--radius-s);
}
.icon-btn:hover { background: var(--paper); color: var(--ink); }

.input, .select {
  border: 1px solid var(--line-strong);
  background: var(--surface);
  border-radius: var(--radius-s);
  padding: 8px 10px;
  color: var(--ink);
}
.input:focus, .select:focus, .btn:focus, .rail-link:focus {
  outline: 2px solid var(--brand);
  outline-offset: 1px;
}
.textarea { resize: vertical; font-family: inherit; }

.check-pill {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 7px 12px;
  border: 1px solid var(--line-strong);
  border-radius: 999px;
  background: var(--surface);
  font-size: 13px;
  cursor: pointer;
  user-select: none;
}
.check-pill-standalone { margin: 2px 0 10px; }

/* ============================================================
   Dashboard: stat row
   ============================================================ */
.stat-row {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  border: 1px solid var(--line);
  border-radius: var(--radius-m);
  background: var(--surface);
  overflow: hidden;
  margin-bottom: 30px;
}
.stat {
  padding: 18px 20px;
  border-right: 1px solid var(--line);
}
.stat:last-child { border-right: none; }
.stat-value {
  font-family: var(--font-display);
  font-weight: 700;
  font-size: 28px;
  line-height: 1.1;
}
.stat-label { margin-top: 6px; color: var(--ink-soft); font-size: 12.5px; }

@media (max-width: 900px) {
  .stat-row { grid-template-columns: repeat(2, 1fr); }
  .stat:nth-child(2) { border-right: none; }
}

/* ============================================================
   Attention boards
   ============================================================ */
.board-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 20px;
  margin-bottom: 34px;
}
@media (max-width: 820px) { .board-grid { grid-template-columns: 1fr; } }

.board-title {
  font-size: 13.5px;
  font-weight: 600;
  padding-left: 10px;
  border-left: 3px solid var(--line-strong);
  margin: 0 0 12px;
}
.board-title-alert { border-left-color: var(--alert); color: var(--alert); }
.board-title-warning { border-left-color: var(--warning); color: var(--warning); }

.board-list { display: flex; flex-direction: column; gap: 8px; }

.board-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-left: 3px solid var(--line-strong);
  border-radius: var(--radius-s);
  padding: 10px 12px;
  cursor: pointer;
}
.board-item:hover { border-color: var(--line-strong); }
.board-item.alert { border-left-color: var(--alert); background: var(--alert-tint); }
.board-item.warning { border-left-color: var(--warning); background: var(--warning-tint); }
.board-item-name { font-weight: 600; }
.board-item-sub { font-size: 12px; color: var(--ink-soft); margin-top: 2px; }
.board-item-tag {
  font-family: var(--font-display);
  font-weight: 700;
  font-size: 13px;
  white-space: nowrap;
}
.board-item.alert .board-item-tag { color: var(--alert); }
.board-item.warning .board-item-tag { color: var(--warning); }

.board-empty {
  color: var(--ink-faint);
  font-size: 13px;
  padding: 14px 4px;
}

/* ============================================================
   Tables
   ============================================================ */
.table-wrap {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius-m);
  overflow: auto;
}

.table { width: 100%; border-collapse: collapse; min-width: 720px; }
.table th, .table td {
  padding: 9px 10px;
  text-align: left;
  border-bottom: 1px solid var(--line);
  white-space: nowrap;
}
.table th {
  font-size: 12px;
  color: var(--ink-soft);
  font-weight: 600;
  background: var(--paper);
  position: sticky;
  top: 0;
}
.table th.sortable { cursor: pointer; user-select: none; }
.table th.sortable:hover { color: var(--ink); }
.table th.sort-active { color: var(--brand); }
.table tbody tr:last-child td { border-bottom: none; }
.table tbody tr:hover { background: #FAFAF8; }
.table td.name-cell { cursor: pointer; font-weight: 600; color: var(--brand-dark); }
.table td.name-cell:hover { text-decoration: underline; }
.table td.notes-cell { color: var(--ink-soft); white-space: normal; overflow-wrap: anywhere; line-height: 1.4; }

#incidents-table { table-layout: fixed; min-width: 1080px; }
#incidents-table th:nth-child(1) { width: 110px; }
#incidents-table th:nth-child(2) { width: 90px; }
#incidents-table th:nth-child(3) { width: 145px; }
#incidents-table th:nth-child(4) { width: 140px; }
#incidents-table th:nth-child(5) { width: 170px; }
#incidents-table th:nth-child(6) { width: 80px; }
#incidents-table th:nth-child(7) { width: 140px; }
#incidents-table th:nth-child(8) { width: 75px; }
#incidents-table th:nth-child(10) { width: 56px; }
#incidents-table td.name-cell { white-space: normal; overflow-wrap: anywhere; }
#incidents-table th:last-child,
#incidents-table td:last-child { position: sticky; right: 0; background: var(--surface); }
#incidents-table th:last-child { background: var(--paper); }
#incidents-table tbody tr:hover td:last-child { background: #FAFAF8; }

.row-flash { animation: flash 1.4s ease-out; }
@keyframes flash {
  0% { background: var(--brand-tint); }
  100% { background: transparent; }
}

/* status dot */
.status-cell { display: flex; align-items: center; gap: 7px; }
.status-dot { width: 8px; height: 8px; border-radius: 50%; flex: none; }
.status-dot.first_warning { background: var(--warning); }
.status-dot.blocked { background: var(--alert); }

.inline-status-select {
  width: 100%;
  min-width: 0;
  padding: 5px 26px 5px 8px;
  font-size: 12.5px;
}

.inline-warning-date {
  width: 100%;
  min-width: 0;
  border: 1px solid var(--line-strong);
  border-radius: var(--radius-s);
  background: var(--surface);
  color: var(--ink);
  padding: 5px 7px;
  font: inherit;
  font-size: 12.5px;
}
.inline-warning-date:focus {
  outline: 2px solid color-mix(in srgb, var(--brand) 30%, transparent);
  outline-offset: 1px;
}
.inline-warning-date:disabled { cursor: wait; opacity: .55; }

/* blocking badge */
.badge {
  display: inline-flex;
  align-items: center;
  padding: 3px 9px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 600;
  white-space: nowrap;
}
.badge-alert { background: var(--alert-tint); color: var(--alert); }
.badge-warning { background: var(--warning-tint); color: var(--warning); }
.badge-neutral { background: var(--paper); color: var(--ink-soft); }
.badge-brand { background: var(--brand-tint); color: var(--brand-dark); }

.resolved-tick { color: var(--brand); font-weight: 700; }
.resolved-dash { color: var(--ink-faint); }
.resolved-cell { text-align: center !important; }
.inline-resolved-toggle { width: 16px; height: 16px; accent-color: var(--brand); cursor: pointer; }
.inline-resolved-toggle:disabled { cursor: wait; opacity: .55; }

.row-actions { display: flex; gap: 4px; justify-content: flex-end; }

/* ============================================================
   Toolbar
   ============================================================ */
.toolbar {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 16px;
}
.toolbar .input { width: 190px; }

/* ============================================================
   Empty states
   ============================================================ */
.empty-state { padding: 44px 20px; text-align: center; color: var(--ink-soft); }
.empty-state.is-hidden { display: none; }

/* ============================================================
   Settings
   ============================================================ */
.panel-block { margin-bottom: 34px; max-width: 640px; }
.inline-form { display: flex; align-items: center; gap: 10px; margin-top: 14px; flex-wrap: wrap; }
.input-amount { width: 110px; }
.rule-text { color: var(--ink-soft); }
.hint { color: var(--ink-faint); font-size: 12.5px; }

.branch-name-input, .branch-price-input {
  border: 1px solid transparent;
  background: transparent;
  border-radius: var(--radius-s);
  padding: 5px 7px;
  width: 100%;
}
.branch-name-input:hover, .branch-price-input:hover,
.branch-name-input:focus, .branch-price-input:focus {
  border-color: var(--line-strong);
  background: var(--paper);
}
.branch-price-input { width: 90px; text-align: right; }

/* ============================================================
   Slide-over panels
   ============================================================ */
.scrim {
  position: fixed;
  inset: 0;
  background: rgba(20, 24, 22, 0.28);
  display: flex;
  justify-content: flex-end;
  z-index: 50;
}
.scrim.is-hidden { display: none; }

.panel {
  width: 420px;
  max-width: 92vw;
  height: 100%;
  background: var(--paper);
  box-shadow: var(--shadow-panel);
  display: flex;
  flex-direction: column;
  animation: slide-in 0.18s ease-out;
}
@keyframes slide-in {
  from { transform: translateX(24px); opacity: 0.6; }
  to { transform: translateX(0); opacity: 1; }
}

.panel-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 18px 22px;
  border-bottom: 1px solid var(--line);
  background: var(--surface);
}
.panel-header h2 { font-size: 16px; }

.panel-body { padding: 20px 22px; overflow-y: auto; flex: 1; }

.field { display: block; margin-bottom: 14px; }
.field-label { display: block; font-size: 12.5px; color: var(--ink-soft); margin-bottom: 5px; font-weight: 500; }
.field .input, .field .select, .field .textarea { width: 100%; }
.field-row { display: flex; gap: 12px; }
.field-row .field { flex: 1; }
.field-amount .amount-display {
  font-family: var(--font-display);
  font-weight: 700;
  font-size: 17px;
  padding: 8px 0;
  color: var(--brand-dark);
}

.name-hint { min-height: 18px; font-size: 12.5px; margin-top: 6px; }
.name-hint.is-repeat { color: var(--warning); font-weight: 600; }
.name-hint.is-new { color: var(--ink-faint); }

.panel-error {
  background: var(--alert-tint);
  color: var(--alert);
  padding: 9px 12px;
  border-radius: var(--radius-s);
  font-size: 13px;
  margin-bottom: 12px;
}
.panel-error.is-hidden { display: none; }

.panel-actions {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding-top: 6px;
  border-top: 1px solid var(--line);
  margin-top: 8px;
  padding-top: 16px;
}
.panel-actions-right { display: flex; gap: 8px; }

/* history panel content */
.history-summary {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
  margin-bottom: 20px;
}
.history-stat {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius-s);
  padding: 12px;
}
.history-stat-value { font-family: var(--font-display); font-weight: 700; font-size: 19px; }
.history-stat-label { font-size: 12px; color: var(--ink-soft); margin-top: 3px; }

.history-entry {
  border-left: 3px solid var(--line-strong);
  padding: 4px 0 4px 14px;
  margin-bottom: 16px;
  position: relative;
}
.history-entry.first_warning { border-left-color: var(--warning); }
.history-entry.blocked { border-left-color: var(--alert); }
.history-entry.resolved { border-left-color: var(--brand); }
.history-entry-top { display: flex; justify-content: space-between; gap: 10px; font-weight: 600; }
.history-entry-date { color: var(--ink-soft); font-weight: 500; font-size: 12.5px; margin-top: 2px; }
.account-form { max-width: 520px; }
.account-list { margin: 18px 0 28px; display: grid; gap: 10px; max-width: 850px; }
.account-row { display: flex; justify-content: space-between; align-items: center; flex-wrap: wrap; gap: 14px; padding: 14px; border: 1px solid var(--line); border-radius: 8px; }
.account-details { min-width: 0; overflow-wrap: anywhere; }
.account-details small { display: block; color: var(--ink-soft); margin-top: 3px; }
.account-row.is-inactive { opacity: .65; }
.history-entry-notes { color: var(--ink-soft); font-size: 13px; margin-top: 4px; }

/* ============================================================
   Confirm dialog
   ============================================================ */
.confirm-box {
  background: var(--surface);
  border-radius: var(--radius-m);
  padding: 20px;
  width: 320px;
  margin: auto;
  box-shadow: 0 12px 32px rgba(0,0,0,0.18);
}
#confirm-scrim { align-items: center; justify-content: center; }
#confirm-message { margin: 0 0 16px; }

/* ============================================================
   Toast
   ============================================================ */
.toast {
  position: fixed;
  bottom: 22px;
  left: 50%;
  transform: translateX(-50%);
  background: var(--ink);
  color: #fff;
  padding: 10px 18px;
  border-radius: var(--radius-s);
  font-size: 13.5px;
  z-index: 100;
  box-shadow: 0 8px 24px rgba(0,0,0,0.2);
}
.toast.is-hidden { display: none; }
.toast.is-error { background: var(--alert); }

/* ============================================================
   Responsive
   ============================================================ */
@media (max-width: 760px) {
  .shell { grid-template-columns: 1fr; }
  .rail { position: static; height: auto; flex-direction: row; align-items: center; padding: 12px 16px; }
  .rail-nav { flex-direction: row; }
  .rail-cta { margin-top: 0; }
  .rail { flex-wrap: wrap; gap: 10px; }
  .rail-session { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; margin-top: 0; }
  .rail-session .rail-link { width: auto; }
  .content { padding: 20px; }
  .panel { width: 100%; }
  .history-summary { grid-template-columns: 1fr 1fr; }
}
