/* =========================================================
   Tokens
   ========================================================= */
:root{
  --ink:        #0B1220;
  --ink-2:      #121B2E;
  --ink-3:      #1B2740;
  --canvas:     #F4F5F7;
  --panel:      #FFFFFF;
  --line:       #E4E6EB;
  --text:       #171B24;
  --text-dim:   #5B6472;
  --text-faint: #8B93A1;

  --amber:      #E8912A;
  --amber-soft: #FBEBD6;
  --teal:       #1F9E8C;
  --teal-soft:  #DDF2EE;
  --red:        #D64545;
  --red-soft:   #FBE2E2;
  --blue:       #3E6FE0;
  --blue-soft:  #E4EAFC;

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

  --font-display: 'Space Grotesk', sans-serif;
  --font-body: 'Inter', sans-serif;
  --font-mono: 'IBM Plex Mono', monospace;

  --shadow-1: 0 1px 2px rgba(11,18,32,0.06), 0 1px 1px rgba(11,18,32,0.04);
  --shadow-2: 0 8px 24px rgba(11,18,32,0.12);
}

*{ box-sizing: border-box; }
html,body{ height:100%; }
body{
  margin:0;
  font-family: var(--font-body);
  background: var(--canvas);
  color: var(--text);
  -webkit-font-smoothing: antialiased;
}
button{ font-family: inherit; }
input, select, textarea{ font-family: inherit; font-size: 14px; }
::selection{ background: var(--amber-soft); }

/* =========================================================
   Shell
   ========================================================= */
.app-shell{ display:flex; min-height:100vh; }

.sidebar{
  width: 232px;
  flex-shrink:0;
  background: linear-gradient(180deg, var(--ink) 0%, var(--ink-2) 100%);
  color: #C9D0DE;
  display:flex; flex-direction:column;
  position: sticky; top:0; height:100vh;
  z-index: 40;
}
.brand{
  display:flex; align-items:center; gap:9px;
  padding: 22px 20px 18px;
  font-family: var(--font-display);
  letter-spacing: 0.5px;
}
.brand-mark{ color: var(--amber); font-size: 18px; }
.brand-name{ font-weight:700; font-size:15px; color:#F2F4F8; }
.brand-name-dim{ color: var(--text-faint); font-weight:500; }

.nav{ display:flex; flex-direction:column; gap:2px; padding: 6px 10px; flex:1; overflow-y:auto; }
.nav-item{
  display:flex; align-items:center; gap:10px;
  background:none; border:none; color:#AEB6C6;
  text-align:left; padding:9px 11px; border-radius: var(--radius-sm);
  font-size: 13.5px; font-weight:500; cursor:pointer;
  transition: background .12s ease, color .12s ease;
}
.nav-item:hover{ background: rgba(255,255,255,0.06); color:#EDEFF3; }
.nav-item.active{ background: var(--amber); color: #24160A; font-weight:600; }
.nav-item.active .nav-ico{ color:#24160A; }
.nav-item.is-disabled{ opacity:0.35; cursor:default; }
.nav-item.is-disabled:hover{ background:none; color:#AEB6C6; }
.nav-ico{ width:16px; display:inline-block; text-align:center; color: var(--text-faint); font-size:13px; }
.nav-badge{
  margin-left:auto; background: var(--red); color:#fff; font-size:10.5px;
  font-weight:700; padding: 1px 6px; border-radius:20px;
}
.nav-section{
  font-size:10.5px; text-transform:uppercase; letter-spacing:0.6px;
  color: var(--text-faint); padding: 16px 11px 6px;
}
.sidebar-foot{
  padding: 14px 20px 18px; font-size:11.5px; color: var(--text-faint);
  display:flex; align-items:center; gap:7px; border-top:1px solid rgba(255,255,255,0.07);
}
.status-dot{ width:7px; height:7px; border-radius:50%; background: var(--teal); box-shadow: 0 0 0 3px rgba(31,158,140,0.25); }

.sidebar-backdrop{
  display:none; position:fixed; inset:0; background: rgba(11,18,32,0.5); z-index:39;
}
.sidebar-backdrop.show{ display:block; }

.main{ flex:1; min-width:0; display:flex; flex-direction:column; }

.topbar{
  display:flex; align-items:center; gap:14px;
  padding: 14px 22px; background: var(--panel); border-bottom:1px solid var(--line);
  position: sticky; top:0; z-index:30;
}
.menu-toggle{ display:none; background:none; border:none; font-size:18px; cursor:pointer; color:var(--text); }
.search-wrap{ position:relative; flex:1; max-width:520px; }
.search-input{
  width:100%; padding:9px 13px; border:1px solid var(--line); border-radius: var(--radius);
  background: var(--canvas); color: var(--text); outline:none;
}
.search-input:focus{ border-color: var(--amber); background:#fff; }
.search-results{
  position:absolute; top:calc(100% + 6px); left:0; right:0;
  background:#fff; border:1px solid var(--line); border-radius: var(--radius);
  box-shadow: var(--shadow-2); max-height:360px; overflow-y:auto; z-index:50;
}
.search-result{ padding:10px 13px; cursor:pointer; border-bottom:1px solid var(--line); font-size:13.5px; }
.search-result:last-child{ border-bottom:none; }
.search-result:hover{ background: var(--amber-soft); }
.search-result-type{ font-size:10.5px; text-transform:uppercase; color:var(--text-faint); letter-spacing:0.4px; }
.search-empty{ padding:14px; color:var(--text-faint); font-size:13px; }

.btn{
  border:none; border-radius: var(--radius-sm); padding: 9px 15px;
  font-size:13.5px; font-weight:600; cursor:pointer; transition: filter .12s ease, transform .05s ease;
}
.btn:active{ transform: translateY(1px); }
.btn-primary{ background: var(--amber); color:#24160A; }
.btn-primary:hover{ filter:brightness(1.05); }
.btn-ghost{ background:transparent; color: var(--text-dim); border:1px solid var(--line); }
.btn-ghost:hover{ background: var(--canvas); }
.btn-danger{ background: var(--red-soft); color: var(--red); }
.btn-sm{ padding:6px 10px; font-size:12.5px; }

.view-area{ padding: 22px 26px 60px; flex:1; }

.clock-banner{
  background: var(--amber-soft); color:#8A5A16; font-size:12.5px; font-weight:600;
  padding:7px 22px; display:flex; align-items:center; gap:8px; border-bottom:1px solid var(--line);
}
.clock-banner button{ background:none; border:none; text-decoration:underline; color:#8A5A16; font-weight:600; cursor:pointer; font-size:12.5px; padding:0; margin-left:auto; }

.combo-wrap{ position:relative; }
.combo-results{
  position:absolute; top:calc(100% + 4px); left:0; right:0; background:#fff;
  border:1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow-2);
  max-height:220px; overflow-y:auto; z-index:20;
}
.combo-result{ padding:9px 12px; cursor:pointer; font-size:13.5px; border-bottom:1px solid var(--line); }
.combo-result:last-child{ border-bottom:none; }
.combo-result:hover, .combo-result.is-active{ background: var(--amber-soft); }
.combo-result-sub{ font-size:11.5px; color: var(--text-faint); }
.checkbox-row{ display:flex; align-items:center; gap:7px; font-size:12.5px; color: var(--text-dim); margin-top:6px; }
.pending-note{ font-size:11px; color: var(--amber); font-family: var(--font-mono); margin-top:2px; }

/* =========================================================
   Page headers
   ========================================================= */
.page-head{ display:flex; align-items:flex-end; justify-content:space-between; gap:16px; margin-bottom:20px; flex-wrap:wrap; }
.page-title{ font-family: var(--font-display); font-size:22px; font-weight:700; margin:0 0 4px; }
.page-sub{ color: var(--text-dim); font-size:13.5px; margin:0; }

/* =========================================================
   Dashboard — dispatch board
   ========================================================= */
.stat-grid{
  display:grid; grid-template-columns: repeat(auto-fill, minmax(190px, 1fr));
  gap:12px; margin-bottom: 24px;
}
.stat-card{
  background: var(--panel); border:1px solid var(--line); border-radius: var(--radius-lg);
  padding: 16px 17px; box-shadow: var(--shadow-1); position:relative; overflow:hidden;
}
.stat-card::before{
  content:""; position:absolute; left:0; top:0; bottom:0; width:3px; background: var(--accent, var(--amber));
}
.stat-label{ font-size:11.5px; text-transform:uppercase; letter-spacing:0.5px; color: var(--text-faint); margin-bottom:8px; }
.stat-value{ font-family: var(--font-mono); font-size:26px; font-weight:500; line-height:1; color: var(--text); }
.stat-value.alert{ color: var(--red); }
.stat-foot{ font-size:11.5px; color: var(--text-faint); margin-top:6px; }

.board-grid{ display:grid; grid-template-columns: 1.3fr 1fr; gap:16px; }
@media (max-width: 980px){ .board-grid{ grid-template-columns: 1fr; } }

.panel{
  background: var(--panel); border:1px solid var(--line); border-radius: var(--radius-lg);
  padding: 16px 18px; box-shadow: var(--shadow-1);
}
.panel-title{ font-family:var(--font-display); font-weight:700; font-size:14.5px; margin:0 0 12px; display:flex; align-items:center; justify-content:space-between; }
.panel-title .count{ font-family: var(--font-mono); color: var(--text-faint); font-weight:400; font-size:12.5px; }

.mini-row{ display:flex; align-items:center; justify-content:space-between; padding:9px 0; border-bottom:1px solid var(--line); font-size:13px; }
.mini-row:last-child{ border-bottom:none; }
.mini-row-main{ font-weight:600; }
.mini-row-sub{ color: var(--text-faint); font-size:12px; font-family: var(--font-mono); }
.empty-note{ color: var(--text-faint); font-size:13px; padding: 8px 0; }

/* =========================================================
   Tables
   ========================================================= */
.table-wrap{
  background: var(--panel); border:1px solid var(--line); border-radius: var(--radius-lg);
  overflow-x:auto; overflow-y:hidden; -webkit-overflow-scrolling:touch; box-shadow: var(--shadow-1);
}
table{ width:100%; min-width:640px; border-collapse:collapse; font-size:13.5px; }
thead th{
  text-align:left; padding:11px 14px; background: var(--canvas); color: var(--text-dim);
  font-weight:600; font-size:11.5px; text-transform:uppercase; letter-spacing:0.4px;
  border-bottom:1px solid var(--line); white-space:nowrap;
}
tbody td{ padding:11px 14px; border-bottom:1px solid var(--line); vertical-align:middle; }
tbody tr:last-child td{ border-bottom:none; }
tbody tr{ cursor:pointer; transition: background .1s ease; }
tbody tr:hover{ background: #FAFAFB; }
.mono{ font-family: var(--font-mono); }
.overdue-row{ background: var(--red-soft); }
.overdue-row:hover{ background: #F8D3D3; }

/* status pill — plate-like */
.pill{
  display:inline-flex; align-items:center; gap:5px;
  font-family: var(--font-mono); font-size:11px; font-weight:500;
  padding: 3px 9px; border-radius:20px; letter-spacing:0.3px; text-transform:uppercase;
  white-space:nowrap;
}
.pill-available{ background: var(--teal-soft); color: var(--teal); }
.pill-rented{ background: var(--blue-soft); color: var(--blue); }
.pill-reserved{ background: var(--amber-soft); color:#8A5A16; }
.pill-maintenance, .pill-workshop, .pill-waiting_parts{ background:#F1E9FB; color:#7A4FC2; }
.pill-broken, .pill-stolen{ background: var(--red-soft); color: var(--red); }
.pill-sold{ background:#EDEDEF; color:#6B7280; }
.pill-active{ background: var(--teal-soft); color: var(--teal); }
.pill-closed{ background:#EDEDEF; color:#6B7280; }
.pill-late{ background: var(--red-soft); color: var(--red); }
.pill-paid{ background: var(--teal-soft); color: var(--teal); }
.pill-no_rental{ background:#EDEDEF; color:#6B7280; }
.pill-installed{ background: var(--teal-soft); color: var(--teal); }
.pill-spare{ background: var(--blue-soft); color: var(--blue); }
.pill-faulty, .pill-waiting_repair{ background:#F1E9FB; color:#7A4FC2; }
.pill-retired{ background:#EDEDEF; color:#6B7280; }

.empty-state{ text-align:center; padding: 48px 20px; color: var(--text-faint); }
.empty-state h3{ font-family: var(--font-display); color: var(--text); margin: 10px 0 4px; }

/* =========================================================
   Toolbar (filters above tables)
   ========================================================= */
.toolbar{ display:flex; gap:10px; margin-bottom:14px; flex-wrap:wrap; align-items:center; }
.toolbar input[type="text"], .toolbar select{
  padding:8px 11px; border:1px solid var(--line); border-radius: var(--radius-sm);
  background:#fff; color:var(--text); outline:none;
}
.toolbar input[type="text"]:focus, .toolbar select:focus{ border-color: var(--amber); }

/* =========================================================
   Modal
   ========================================================= */
.modal-backdrop{
  position:fixed; inset:0; background: rgba(11,18,32,0.5);
  align-items:flex-start; justify-content:center;
  padding: 5vh 16px; overflow-y:auto; z-index: 100;
  display:none;
}
.modal-backdrop:not([hidden]){ display:flex; }
.modal{
  background:#fff; border-radius: var(--radius-lg); width:100%; max-width:640px;
  box-shadow: var(--shadow-2); overflow:hidden;
}
.modal-head{ display:flex; align-items:center; justify-content:space-between; padding:16px 20px; border-bottom:1px solid var(--line); }
.modal-title{ font-family: var(--font-display); font-weight:700; font-size:16px; margin:0; }
.modal-close{ background:none; border:none; font-size:18px; cursor:pointer; color: var(--text-faint); }
.modal-body{ padding: 18px 20px; max-height:66vh; overflow-y:auto; }
.modal-foot{ padding: 14px 20px; border-top:1px solid var(--line); display:flex; justify-content:flex-end; gap:10px; }

.form-grid{ display:grid; grid-template-columns: 1fr 1fr; gap: 12px 14px; }
.form-grid.single{ grid-template-columns: 1fr; }
.field{ display:flex; flex-direction:column; gap:5px; }
.field.span-2{ grid-column: span 2; }
.field label{ font-size:12px; font-weight:600; color: var(--text-dim); }
.field input, .field select, .field textarea{
  padding:9px 11px; border:1px solid var(--line); border-radius: var(--radius-sm); outline:none; background:#fff;
}
.field input:focus, .field select:focus, .field textarea:focus{ border-color: var(--amber); }
.field textarea{ resize:vertical; min-height:64px; }
@media (max-width:560px){ .form-grid{ grid-template-columns: 1fr; } .field.span-2{ grid-column: span 1; } }

/* tabs inside profile views */
.tabs{ display:flex; gap:4px; border-bottom:1px solid var(--line); margin-bottom:16px; }
.tab{ background:none; border:none; padding:9px 4px; margin-right:18px; font-size:13.5px; font-weight:600; color: var(--text-faint); cursor:pointer; border-bottom:2px solid transparent; }
.tab.active{ color: var(--text); border-color: var(--amber); }

.profile-head{ display:flex; align-items:center; justify-content:space-between; gap:14px; margin-bottom:6px; flex-wrap:wrap; }
.profile-name{ font-family: var(--font-display); font-size:20px; font-weight:700; }
.profile-meta{ color: var(--text-faint); font-size:13px; font-family: var(--font-mono); }
.back-link{ background:none; border:none; color: var(--text-dim); font-size:13px; cursor:pointer; padding:0; margin-bottom:10px; }
.back-link:hover{ color: var(--text); }

.timeline{ list-style:none; margin:0; padding:0; }
.timeline li{ display:flex; gap:12px; padding: 10px 0; border-bottom:1px solid var(--line); font-size:13px; align-items:center; }
.timeline li:last-child{ border-bottom:none; }
.timeline-clickable:hover > div:first-child{ text-decoration:underline; }
.tx-link{ cursor:pointer; color: var(--blue); font-weight:600; }
.tx-link:hover{ text-decoration:underline; }
.split-parent-row{ background: #EDEDF5; }
.split-parent-row:hover{ background: #E2E2EF; }
.split-child-row{ background: #F1E9FB; }
.split-child-row:hover{ background: #E9DEF7; }

.cal-header{ display:flex; align-items:center; justify-content:center; gap:14px; margin-bottom:10px; font-family:var(--font-display); }
.cal-weekdays{ display:grid; grid-template-columns: repeat(7, 1fr); gap:4px; margin-bottom:4px; }
.cal-weekdays div{ text-align:center; font-size:11px; color:var(--text-faint); text-transform:uppercase; font-weight:600; }
.cal-grid{ display:grid; grid-template-columns: repeat(7, 1fr); gap:4px; }
.cal-cell{
  position:relative; aspect-ratio:1; display:flex; align-items:center; justify-content:center;
  border-radius:8px; background:var(--panel); border:1px solid var(--line); font-size:13px; cursor:default;
  transition: background .12s ease;
}
.cal-cell-outside{ opacity:0.35; }
.cal-cell-paid{ background: var(--teal-soft); border-color: var(--teal); font-weight:600; cursor:pointer; }
.cal-dot{ position:absolute; bottom:4px; width:5px; height:5px; border-radius:50%; background:var(--teal); }
.cal-week-highlight{ background: var(--amber-soft) !important; border-color: var(--amber) !important; }
.cal-cell-paid.cal-week-highlight .cal-dot{ background: var(--amber); }
.cal-cell-today{ border-color: var(--blue) !important; box-shadow: inset 0 0 0 1.5px var(--blue); font-weight: 700; }
.cal-cell-freedays{ background: var(--blue-soft); }
.cal-cell-freedays:hover{ filter: brightness(0.95); }
.cal-cell-selected{ box-shadow: inset 0 0 0 2px var(--amber); }
.cal-cell-today{ border-color: var(--blue) !important; box-shadow: inset 0 0 0 1.5px var(--blue); font-weight: 700; }
.cal-cell-freedays{ background: var(--blue-soft); }
.cal-cell-freedays:hover{ filter: brightness(0.95); }
.cal-cell-selected{ box-shadow: inset 0 0 0 2px var(--amber); }
.timeline-dot{ width:7px; height:7px; border-radius:50%; background: var(--amber); margin-top:5px; flex-shrink:0; }
.timeline-date{ color: var(--text-faint); font-family: var(--font-mono); font-size:11.5px; }

.toast-stack{ position:fixed; bottom:18px; right:18px; display:flex; flex-direction:column; gap:8px; z-index:200; }
.toast{ background: var(--ink); color:#fff; padding:11px 16px; border-radius: var(--radius); font-size:13px; box-shadow: var(--shadow-2); animation: toast-in .18s ease; }
.toast.error{ background: var(--red); }
@keyframes toast-in{ from{ opacity:0; transform:translateY(6px);} to{opacity:1; transform:translateY(0);} }

/* button row inside table cells */
.btn-group-row{ display:flex; flex-wrap:nowrap; gap:6px; align-items:center; }
.btn-group-row .btn{ white-space:nowrap; }

/* =========================================================
   Responsive
   ========================================================= */
@media (max-width: 860px){
  .sidebar{ position:fixed; left:-232px; transition: left .18s ease; }
  .sidebar.open{ left:0; }
  .menu-toggle{ display:inline-block; }
  .view-area{ padding: 16px 14px 50px; }
  .topbar{ padding: 12px 14px; flex-wrap: wrap; row-gap: 8px; }
  .search-wrap{ order: 3; flex-basis: 100%; max-width: none; }
  .stat-grid{ grid-template-columns: repeat(auto-fill, minmax(150px,1fr)); }
}
