/* ==========================================================================
   Balsan design system
   Light, dense, operational. Bootstrap stays for the grid and a few
   utilities; everything with a visual identity is defined here.
   ========================================================================== */

:root {
  --bg:        #f6f7f9;
  --panel:     #ffffff;
  --line:      #e4e7ec;
  --line-soft: #f1f3f6;
  --line-xsoft:#f7f9fb;

  --ink:       #10151c;
  --ink-2:     #3d4756;
  --muted:     #6b7686;
  --muted-2:   #8592a3;
  --off:       #98a2b3;

  --accent:      #0b6bcb;
  --accent-ink:  #084e97;
  --accent-soft: #e8f1fd;

  --ok:      #15803d;  --ok-soft:   #e7f6ec;  --ok-rail:   #22a559;
  --warn:    #b45309;  --warn-soft: #fdf3e3;  --warn-rail: #e0a012;
  --bad:     #b91c1c;  --bad-soft:  #fdeceb;  --bad-rail:  #dc2626;

  --r-sm: 6px;
  --r:    8px;
  --r-lg: 10px;

  --sans: "IBM Plex Sans", system-ui, -apple-system, "Segoe UI", sans-serif;
  --mono: "IBM Plex Mono", ui-monospace, SFMono-Regular, Menlo, monospace;

  /* Bootstrap overrides so its components inherit the palette */
  --bs-primary: #0b6bcb;
  --bs-primary-rgb: 11, 107, 203;
  --bs-body-bg: #f6f7f9;
  --bs-body-color: #10151c;
  --bs-border-color: #e4e7ec;
  --bs-body-font-family: var(--sans);
  --bs-border-radius: 8px;
  --bs-link-color: #0b6bcb;
  --bs-link-hover-color: #084e97;
}

body {
  background: var(--bg);
  color: var(--ink);
  font-family: var(--sans);
  font-size: 14px;
  -webkit-font-smoothing: antialiased;
}

.mono, .num { font-family: var(--mono); font-variant-numeric: tabular-nums; }
.t-muted  { color: var(--muted); }
.t-muted2 { color: var(--muted-2); }
.t-xs { font-size: 12px; }
.t-sm { font-size: 13px; }

/* ---------------------------------------------------------------- app bar */

.appbar {
  background: var(--panel);
  border-bottom: 1px solid var(--line);
  position: sticky; top: 0; z-index: 30;
}
.appbar-inner {
  max-width: 1440px; margin: 0 auto;
  display: flex; align-items: center; gap: 18px;
  padding: 0 20px; min-height: 52px;
}
.appbar-brand {
  font-weight: 600; letter-spacing: .14em; font-size: 11px;
  color: var(--muted-2); text-decoration: none; text-transform: uppercase;
}
.appbar-brand:hover { color: var(--ink); text-decoration: none; }
.appnav { display: flex; gap: 2px; align-items: center; flex-wrap: wrap; }
.appnav a {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 6px 11px; border-radius: var(--r-sm);
  color: var(--muted); font-size: 13.5px; text-decoration: none; white-space: nowrap;
}
.appnav a:hover { background: var(--line-soft); color: var(--ink); text-decoration: none; }
.appnav a.is-active { background: var(--accent-soft); color: var(--accent); font-weight: 600; }
.appbar-user { margin-left: auto; display: flex; align-items: center; gap: 10px; }
.appbar-burger { display: none; }
.appnav-head, .appnav-foot { display: none; }
.appnav-overlay { display: none; }

/* ------------------------------------------------------------------ page */

.page { max-width: 1440px; margin: 0 auto; padding: 16px 20px 48px; }
.page-head { display: flex; align-items: flex-start; gap: 12px; margin-bottom: 14px; flex-wrap: wrap; }
.page-title { font-size: 22px; font-weight: 600; letter-spacing: -.015em; margin: 0; }
.page-sub { color: var(--muted); font-size: 13px; margin-top: 3px; }
.page-actions { margin-left: auto; display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }

/* ---------------------------------------------------------------- panels */

.panel { background: var(--panel); border: 1px solid var(--line); border-radius: var(--r-lg); overflow: hidden; }
.panel + .panel { margin-top: 14px; }
.panel-head {
  padding: 9px 16px; font-size: 10.5px; letter-spacing: .09em; text-transform: uppercase;
  color: var(--muted-2); background: #fbfcfd; border-bottom: 1px solid var(--line); font-weight: 600;
  display: flex; align-items: center; gap: 10px;
}
.panel-head .spacer { margin-left: auto; }
.panel-body { padding: 16px; }
.panel-body.tight { padding: 8px 16px; }

/* --------------------------------------------------------------- buttons */

.btn {
  --bs-btn-border-radius: var(--r-sm);
  border-radius: var(--r-sm); font-size: 13px; font-weight: 500;
  display: inline-flex; align-items: center; gap: 6px; line-height: 1.5;
}
.btn-app {
  border: 1px solid var(--line); background: var(--panel); color: var(--ink-2);
  padding: 6px 12px; border-radius: var(--r-sm); font-size: 13px;
  display: inline-flex; align-items: center; gap: 6px; text-decoration: none;
}
.btn-app:hover { background: var(--line-soft); color: var(--ink); text-decoration: none; }
.btn-app.is-primary { background: var(--accent); border-color: var(--accent); color: #fff; font-weight: 500; }
.btn-app.is-primary:hover { background: var(--accent-ink); border-color: var(--accent-ink); color: #fff; }
.btn-app.is-danger { color: var(--bad); border-color: #f2d2d0; }
.btn-app.is-danger:hover { background: var(--bad-soft); color: var(--bad); }
.btn-app.is-lg { padding: 9px 16px; font-size: 14px; font-weight: 600; }
.btn-app.is-disabled { opacity: .45; pointer-events: none; }
.btn-icon {
  width: 30px; height: 30px; padding: 0; justify-content: center;
  border: 1px solid var(--line); background: var(--panel); color: var(--muted);
  border-radius: var(--r-sm); display: inline-flex; align-items: center; text-decoration: none;
}
.btn-icon:hover { background: var(--line-soft); color: var(--ink); }
.btn-icon.is-danger:hover { background: var(--bad-soft); color: var(--bad); border-color: #f2d2d0; }

.seg { display: inline-flex; border: 1px solid var(--line); border-radius: var(--r-sm); overflow: hidden; background: var(--panel); }
.seg a, .seg span {
  padding: 6px 13px; font-size: 13px; color: var(--muted); border-right: 1px solid var(--line);
  text-decoration: none;
}
.seg a:last-child, .seg span:last-child { border-right: 0; }
.seg a:hover { background: var(--line-soft); color: var(--ink); text-decoration: none; }
.seg .is-on { background: var(--ink); color: #fff; font-weight: 600; }

/* ------------------------------------------------------------ tags/status */

.tag {
  display: inline-flex; align-items: center; gap: 4px;
  padding: 2px 7px; border-radius: 4px; font-size: 11.5px; line-height: 1.5;
  background: var(--line-soft); color: #4a5566; white-space: nowrap; text-decoration: none;
}
a.tag:hover { background: #e4e8ee; color: var(--ink); text-decoration: none; }
.tag.is-miss { background: var(--bad-soft); color: var(--bad); font-weight: 600; }
.tag.is-ok   { background: var(--ok-soft);  color: var(--ok); }
.tag.is-warn { background: var(--warn-soft);color: var(--warn); }
.tag.is-accent { background: var(--accent-soft); color: var(--accent); }

.st { font-size: 11px; letter-spacing: .06em; text-transform: uppercase; font-weight: 600; white-space: nowrap; }
.st.is-ok { color: var(--ok); } .st.is-warn { color: var(--warn); }
.st.is-off { color: var(--off); } .st.is-bad { color: var(--bad); }

/* ------------------------------------------------------------------ KPIs */

.kpis { display: flex; background: var(--panel); border: 1px solid var(--line); border-radius: var(--r-lg); overflow: hidden; flex-wrap: wrap; }
.kpi { padding: 10px 20px; border-right: 1px solid var(--line-soft); flex: 0 0 auto; }
.kpi:last-child { border-right: 0; }
.kpi b { display: block; font-size: 20px; font-weight: 600; line-height: 1.15; font-family: var(--mono); font-variant-numeric: tabular-nums; }
.kpi span { font-size: 10.5px; letter-spacing: .08em; text-transform: uppercase; color: var(--muted-2); }
.kpi.is-alert b { color: var(--bad); }

/* ------------------------------------------------------------ data tables */

.dtable { width: 100%; background: var(--panel); border: 1px solid var(--line); border-radius: var(--r-lg); overflow: hidden; }
.dtable-head, .dtable-row { display: grid; gap: 14px; align-items: center; }
.dtable-head {
  padding: 9px 16px; font-size: 10px; letter-spacing: .09em; text-transform: uppercase;
  color: var(--muted-2); background: #fbfcfd; border-bottom: 1px solid var(--line); font-weight: 600;
}
.dtable-row { padding: 10px 16px; border-bottom: 1px solid var(--line-soft); border-left: 3px solid transparent; }
.dtable-row:last-child { border-bottom: 0; }
.dtable-row:hover { background: #fcfdfe; }
.dtable-row.is-ok   { border-left-color: var(--ok-rail); }
.dtable-row.is-warn { border-left-color: var(--warn-rail); }
.dtable-row.is-bad  { border-left-color: var(--bad-rail); background: #fffbfb; }
.dtable-row.is-off  { border-left-color: #d3d8e0; background: #fcfcfd; color: var(--off); }
.dtable-row.is-off .cell-title { text-decoration: line-through; }
.cell-title { font-weight: 600; font-size: 14.5px; }
.cell-sub { color: var(--muted); font-size: 12.5px; margin-top: 2px; }
.cell-actions { display: flex; gap: 5px; justify-content: flex-end; }
.cell-num { text-align: right; font-size: 16px; font-weight: 600; font-family: var(--mono); font-variant-numeric: tabular-nums; }
.cell-time { font-size: 16px; font-weight: 600; line-height: 1.15; font-family: var(--mono); font-variant-numeric: tabular-nums; }
.cell-time small { display: block; font-size: 12px; color: var(--muted-2); font-weight: 400; margin-top: 1px; }

.empty { padding: 40px 20px; text-align: center; color: var(--muted); }
.empty svg { width: 26px; height: 26px; stroke: var(--off); fill: none; stroke-width: 1.5; margin-bottom: 8px; }

/* ------------------------------------------------------------ definition */

.kv { display: grid; grid-template-columns: 190px 1fr; margin: 0; }
.kv dt { padding: 9px 16px; color: var(--muted); font-size: 13px; border-bottom: 1px solid var(--line-xsoft); font-weight: 400; }
.kv dd { padding: 9px 16px; margin: 0; font-size: 14px; border-bottom: 1px solid var(--line-xsoft); }
.kv dt:last-of-type, .kv dd:last-of-type { border-bottom: 0; }

/* ----------------------------------------------------------------- forms */

.form-panel { max-width: 940px; }
.form-panel.is-wide { max-width: 1180px; }
.form-grid { display: grid; grid-template-columns: repeat(12, minmax(0, 1fr)); gap: 12px 14px; }
.field { display: flex; flex-direction: column; gap: 5px; grid-column: span 6; min-width: 0; }
.field.fw-3  { grid-column: span 3; }
.field.fw-4  { grid-column: span 4; }
.field.fw-6  { grid-column: span 6; }
.field.fw-8  { grid-column: span 8; }
.field.fw-12 { grid-column: span 12; }
.field-check.fw-3  { grid-column: span 3; }
.field-check.fw-4  { grid-column: span 4; }
.field-check.fw-6  { grid-column: span 6; }
.field-check.fw-12 { grid-column: span 12; }
.field > label, .field-label {
  font-size: 11px; letter-spacing: .05em; text-transform: uppercase;
  color: var(--muted-2); font-weight: 600; margin: 0;
}
.field .form-control,
.field .form-select,
.field input[type="text"], .field input[type="email"], .field input[type="number"],
.field input[type="date"], .field input[type="datetime-local"], .field textarea, .field select {
  border: 1px solid var(--line); border-radius: var(--r-sm); background: var(--panel);
  padding: 7px 11px; font-size: 14px; color: var(--ink); width: 100%; font-family: var(--sans);
}
.field > input, .field > select, .field > textarea,
.field > .form-control, .field > .form-select, .field > .ts-wrapper,
.field .flatpickr-input, .field input.form-control {
  width: 100%; max-width: 100%; box-sizing: border-box;
}
.field .form-control:focus, .field .form-select:focus, .field input:focus, .field textarea:focus, .field select:focus {
  outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px rgba(11,107,203,.12);
}
.field .form-control::placeholder { color: #b3bcc8; }
.field .invalid-feedback, .field .form-error { display: block; color: var(--bad); font-size: 12px; }
.field ul { list-style: none; padding: 0; margin: 0; }
.field ul li { color: var(--bad); font-size: 12px; }

.input-affix { display: flex; align-items: center; gap: 7px; }
.input-affix > .form-control, .input-affix > input { flex: 1; min-width: 0; }

.field-check {
  grid-column: span 6; display: flex; align-items: center; gap: 9px;
  padding: 8px 11px; border: 1px solid var(--line); border-radius: var(--r-sm);
  background: var(--panel); align-self: end; min-height: 36px;
}
.field-check input { width: 16px; height: 16px; margin: 1px 0 0; accent-color: var(--accent); flex: none; }
.field-check label { font-size: 13.5px; color: var(--ink-2); margin: 0; cursor: pointer; text-transform: none; letter-spacing: 0; font-weight: 500; }

.form-section { border-top: 1px solid var(--line); margin-top: 18px; padding-top: 16px; }
.form-section:first-of-type { border-top: 0; margin-top: 0; padding-top: 0; }
.form-section-title { font-size: 11px; letter-spacing: .09em; text-transform: uppercase; color: var(--muted-2); font-weight: 600; margin-bottom: 12px; }

.form-actions {
  position: sticky; bottom: 0; background: var(--panel); border-top: 1px solid var(--line);
  padding: 12px 16px; display: flex; gap: 8px; align-items: center; margin: 18px -16px -16px;
  border-radius: 0 0 var(--r-lg) var(--r-lg);
}
.form-actions .spacer { margin-left: auto; }

/* repeatable collection rows */
.collection-row { display: flex; gap: 6px; margin-bottom: 6px; }
.collection-row input { flex: 1; }

/* Tom Select inside our fields */
.field .ts-wrapper { width: 100%; }
.field .ts-control {
  border: 1px solid var(--line) !important; border-radius: var(--r-sm) !important;
  padding: 5px 9px !important; font-size: 14px; min-height: 36px; background: var(--panel) !important;
}
.field .ts-wrapper.focus .ts-control { border-color: var(--accent) !important; box-shadow: 0 0 0 3px rgba(11,107,203,.12); }
.field .ts-control > .item {
  background: var(--accent-soft) !important; color: var(--accent) !important;
  border-radius: 999px !important; padding: 1px 9px !important; font-size: 12.5px; border: 0 !important;
}
.field .ts-dropdown { border-radius: var(--r-sm); border-color: var(--line); font-size: 13.5px; }
.field .ts-dropdown .optgroup-header { font-size: 10.5px; letter-spacing: .08em; text-transform: uppercase; color: var(--muted-2); font-weight: 600; }

/* --------------------------------------------------------------- filters */

.filterbar { display: flex; gap: 8px; align-items: flex-end; flex-wrap: wrap; }
.filter-chips { display: flex; gap: 6px; flex-wrap: wrap; align-items: center; }
.fchip {
  border: 1px solid var(--line); border-radius: 999px; padding: 5px 12px;
  font-size: 12.5px; color: var(--ink-2); background: var(--panel); text-decoration: none;
}
.fchip:hover { background: var(--line-soft); color: var(--ink); text-decoration: none; }
.fchip.is-on { background: var(--ink); color: #fff; border-color: var(--ink); font-weight: 500; }
.fchip.is-bad { background: var(--bad-soft); border-color: #f6cfcd; color: var(--bad); font-weight: 600; }

/* --------------------------------------------------------------- daybar */

.daybar { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; margin-bottom: 14px; }
.dayname { font-size: 19px; font-weight: 600; letter-spacing: -.01em; white-space: nowrap; }
.dayname em { font-style: normal; color: var(--accent); }

/* ---------------------------------------------------------- deadline bar */

.dl-ribbon {
  display: flex; gap: 16px; align-items: center; flex-wrap: wrap;
  padding: 10px 16px; background: var(--warn-soft); border: 1px solid #f3e3c6;
  border-radius: var(--r-lg); font-size: 12.5px; color: #7c4a03; margin-top: 14px;
}
.dl-ribbon b { font-weight: 600; }
.dl-ribbon .is-over { color: var(--bad); }

/* ------------------------------------------------------------- send box */

.sendbox-pre {
  padding: 12px 14px; background: #f7f9fb; border: 1px solid var(--line); border-radius: var(--r);
  font-family: var(--mono); font-size: 12px; line-height: 1.65; color: #26303c;
  white-space: pre-wrap; width: 100%; resize: vertical; min-height: 180px;
}
.sendbox-fields { display: flex; flex-wrap: wrap; gap: 6px 14px; }
.sendbox-fields label { display: inline-flex; align-items: center; gap: 5px; font-size: 12.5px; color: var(--ink-2); cursor: pointer; margin: 0; }
.sendbox-fields input { width: 14px; height: 14px; accent-color: var(--accent); margin: 0; }

/* ------------------------------------------------------------ route spine */

.route { display: flex; gap: 12px; }
.route-spine { width: 12px; display: flex; flex-direction: column; align-items: center; padding-top: 5px; }
.route-dot { width: 9px; height: 9px; border-radius: 50%; background: var(--accent); flex: none; }
.route-dot.is-end { background: var(--ink); }
.route-dot.is-mid { background: #fff; border: 2px solid #c8d3e0; width: 8px; height: 8px; }
.route-line { flex: 1; width: 2px; background: #dfe4ea; margin: 3px 0; min-height: 14px; }
.route-stop { padding-bottom: 14px; }
.route-stop:last-child { padding-bottom: 0; }
.route-stop b { font-size: 14.5px; font-weight: 600; display: block; }
.route-stop .when { font-weight: 600; color: var(--accent); font-family: var(--mono); font-size: 12.5px; }
.route-stop span { color: var(--muted); font-size: 12.5px; }

/* ------------------------------------------------------------- utilities */

.icn { width: 15px; height: 15px; stroke: currentColor; fill: none; stroke-width: 1.7; flex: none; }
.icn-sm { width: 13px; height: 13px; }
.stack { display: flex; flex-direction: column; gap: 14px; }
.row-gap { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.split { display: grid; grid-template-columns: 1fr 420px; gap: 16px; align-items: start; }
.sticky-side { position: sticky; top: 68px; }

.alert { border-radius: var(--r); border: 1px solid var(--line); font-size: 13.5px; }

/* ------------------------------------------------------------ responsive */

@media (max-width: 991.98px) {
  .split { grid-template-columns: 1fr; }
  .sticky-side { position: static; }
  .kv { grid-template-columns: 1fr; }
  .kv dt { padding-bottom: 0; border-bottom: 0; font-size: 11px; text-transform: uppercase; letter-spacing: .05em; }
}

@media (max-width: 767.98px) {
  /* ---- mobile navigation drawer ---- */
  .appbar-inner { padding: 0 12px; min-height: 54px; }
  .appbar-email, .appbar-logout { display: none; }

  .appbar-burger {
    display: inline-flex; flex-direction: column; justify-content: center; gap: 4px;
    width: 44px; height: 44px; padding: 0 11px; margin-right: -10px;
    background: none; border: 0; cursor: pointer;
  }
  .appbar-burger span {
    display: block; height: 2px; width: 100%; background: var(--ink); border-radius: 2px;
    transition: transform .18s ease, opacity .18s ease;
  }
  .is-open .appbar-burger span:nth-child(1) { transform: translateY(6px) rotate(45deg); }
  .is-open .appbar-burger span:nth-child(2) { opacity: 0; }
  .is-open .appbar-burger span:nth-child(3) { transform: translateY(-6px) rotate(-45deg); }

  .appnav {
    position: fixed; top: 0; right: 0; bottom: 0; z-index: 60;
    width: min(300px, 86vw);
    flex-direction: column; flex-wrap: nowrap; align-items: stretch; gap: 2px;
    background: var(--panel); border-left: 1px solid var(--line);
    box-shadow: -8px 0 28px rgba(16,21,28,.14);
    padding: 8px 10px 14px; overflow-y: auto;
    transform: translateX(100%); transition: transform .22s ease, visibility .22s;
    visibility: hidden;
  }
  .is-open .appnav { transform: translateX(0); visibility: visible; }

  .appnav a {
    min-height: 46px; padding: 11px 12px; font-size: 15px; border-radius: var(--r);
  }
  .appnav a.is-active { background: var(--accent-soft); }

  .appnav-head {
    display: flex; align-items: center; justify-content: space-between;
    padding: 6px 6px 10px; margin-bottom: 6px; border-bottom: 1px solid var(--line);
  }
  .appnav-foot {
    display: flex; flex-direction: column; gap: 8px; align-items: flex-start;
    margin-top: 10px; padding-top: 12px; border-top: 1px solid var(--line);
  }
  .appnav-foot .btn-app { width: 100%; justify-content: center; }

  .appnav-overlay {
    display: block; position: fixed; inset: 0; z-index: 50;
    background: rgba(16,21,28,.42); opacity: 0; pointer-events: none;
    transition: opacity .22s ease;
  }
  .is-open .appnav-overlay { opacity: 1; pointer-events: auto; }
  body.has-open-menu { overflow: hidden; }

  /* Touch targets: anything tappable gets a 44px hit area on a phone.
     Apple/Google both put the comfortable minimum around there, and this app
     is used one-handed in a vehicle. */
  .btn-app, a.btn-app, button.btn-app { min-height: 44px; padding: 10px 16px; }
  .seg a, .seg span { min-height: 44px; display: inline-flex; align-items: center; }
  .btn-icon { width: 44px; height: 44px; }
  input[type="checkbox"] { width: 22px; height: 22px; }
  .panel-body a:not(.btn-app):not(.btn-icon):not(.tag),
  .kv dd a:not(.btn-app) { display: inline-block; min-height: 40px; padding: 8px 0; }

  .appbar-brand { display: inline-flex; align-items: center; min-height: 44px; }
  .page-head a:not(.btn-app):not(.btn-icon),
  .cell-title a, .kv a:not(.btn-app), .t-xs a { display: inline-block; padding: 8px 0; min-height: 40px; }
  .fchip { min-height: 40px; display: inline-flex; align-items: center; }
  .tag { min-height: 30px; padding: 5px 9px; }
  a.tag { min-height: 36px; }
  .field-check { padding: 12px; }
  .field-check input { width: 22px; height: 22px; }
  .sendbox-fields label { min-height: 36px; }
  .sendbox-fields input { width: 20px; height: 20px; }
  .dtable-row .cell-actions .btn-icon { width: 42px; height: 42px; }

  .page { padding: 12px 12px 90px; }
  .field, .field.fw-3, .field.fw-4, .field.fw-6, .field.fw-8 { grid-column: span 12; }
  .field-check, .field-check.fw-3, .field-check.fw-4, .field-check.fw-6 { grid-column: span 12; }
  .kpi { padding: 9px 14px; }
  .kpi b { font-size: 17px; }
  .dtable-head { display: none; }
  .dtable { background: transparent; border: 0; border-radius: 0; }
  .dtable-row {
    grid-template-columns: 1fr !important; gap: 6px;
    background: var(--panel); border: 1px solid var(--line); border-left-width: 3px;
    border-radius: var(--r-lg); margin-bottom: 8px; padding: 11px 13px;
  }
  .dtable-row:last-child { border-bottom: 1px solid var(--line); }
  .cell-num, .cell-actions { text-align: left; justify-content: flex-start; }
  .cell-time { font-size: 18px; }
  .cell-time small { display: inline; margin-left: 6px; }
  /* touch targets */
  .btn-icon { width: 40px; height: 40px; }
  .btn-app { padding: 9px 14px; }
  .form-actions { margin: 18px -12px -12px; padding: 12px; }
  .form-actions .btn-app { flex: 1; justify-content: center; }
}
