/* =========================================================================
   Nieva TMS — Design System
   Refined utilitarian. Dark ink on warm off-white. Sharp accents.
   ========================================================================= */

:root {
  --ink: #0f172a;
  --ink-soft: #1e293b;
  --muted: #64748b;
  --muted-2: #94a3b8;
  --line: #e2e8f0;
  --line-soft: #eef2f6;
  --paper: #fbfaf6;
  --surface: #ffffff;
  --surface-2: #f7f5ee;
  --accent: #c2410c;
  --accent-2: #9a3412;
  --accent-soft: #fff1e8;
  --green: #15803d;
  --green-soft: #dcfce7;
  --amber: #b45309;
  --amber-soft: #fef3c7;
  --red: #b91c1c;
  --red-soft: #fee2e2;
  --blue: #1d4ed8;
  --blue-soft: #dbeafe;
  --grey-soft: #e2e8f0;

  --f-sans: 'Manrope', -apple-system, BlinkMacSystemFont, sans-serif;
  --f-mono: 'JetBrains Mono', ui-monospace, 'SF Mono', Menlo, monospace;

  --side-w: 240px;
  --radius: 10px;
  --radius-sm: 6px;
  --shadow-sm: 0 1px 2px rgba(15, 23, 42, 0.04), 0 1px 3px rgba(15, 23, 42, 0.04);
  --shadow-md: 0 4px 12px rgba(15, 23, 42, 0.06);
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  font-family: var(--f-sans);
  background: var(--paper);
  color: var(--ink);
  font-size: 14px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}
a { color: var(--accent); text-decoration: none; }
a:hover { color: var(--accent-2); }
hr { border: none; border-top: 1px solid var(--line); margin: 18px 0; }

.app-shell {
  display: grid;
  grid-template-columns: var(--side-w) 1fr;
  min-height: 100vh;
}
.sidebar {
  background: var(--ink);
  color: #cbd5e1;
  display: flex;
  flex-direction: column;
  position: sticky;
  top: 0;
  height: 100vh;
}
.brand {
  display: flex; align-items: center; gap: 12px;
  padding: 22px 22px 18px;
  border-bottom: 1px solid rgba(255,255,255,0.08);
}
.brand-mark {
  font-weight: 800; font-size: 22px;
  width: 38px; height: 38px;
  border-radius: 8px;
  background: var(--accent);
  color: #fff;
  display: grid; place-items: center;
  position: relative;
  letter-spacing: -0.02em;
}
.brand-dot {
  position: absolute;
  width: 6px; height: 6px;
  background: #fde68a;
  border-radius: 50%;
  bottom: 6px; right: 6px;
}
.brand-name { font-weight: 700; color: #f8fafc; font-size: 15px; letter-spacing: -0.01em; }
.brand-sub { font-size: 11px; color: #64748b; letter-spacing: 0.06em; text-transform: uppercase; }

.nav {
  flex: 1;
  padding: 14px 12px;
  display: flex; flex-direction: column; gap: 2px;
  overflow-y: auto;
}
.nav-item {
  display: flex; align-items: center; gap: 11px;
  padding: 9px 12px;
  border-radius: var(--radius-sm);
  color: #94a3b8;
  font-size: 13.5px; font-weight: 500;
  transition: background 0.12s, color 0.12s;
}
.nav-item svg { width: 18px; height: 18px; flex-shrink: 0; }
.nav-item:hover { background: rgba(255,255,255,0.04); color: #e2e8f0; }
.nav-item.is-active {
  background: rgba(194, 65, 12, 0.16);
  color: #fed7aa;
  position: relative;
}
.nav-item.is-active::before {
  content: '';
  position: absolute;
  left: -12px; top: 6px; bottom: 6px;
  width: 3px; background: var(--accent);
  border-radius: 0 2px 2px 0;
}

.sidebar-footer {
  padding: 14px;
  border-top: 1px solid rgba(255,255,255,0.08);
}
.user-chip { display: flex; align-items: center; gap: 10px; padding: 8px; border-radius: var(--radius-sm); }
.avatar {
  width: 32px; height: 32px; border-radius: 50%;
  background: var(--accent); color: #fff;
  display: grid; place-items: center;
  font-weight: 700; font-size: 13px;
}
.user-name { font-size: 13px; color: #e2e8f0; font-weight: 600; line-height: 1.2; }
.user-role { font-size: 11px; color: #64748b; }
.logout-link {
  display: block; margin-top: 8px; padding: 6px 10px;
  font-size: 12px; color: #94a3b8; border-radius: var(--radius-sm);
}
.logout-link:hover { background: rgba(255,255,255,0.04); color: #fff; }

.main { background: var(--paper); min-height: 100vh; }
.topbar {
  display: flex; justify-content: space-between; align-items: flex-end;
  gap: 16px;
  padding: 26px 32px 18px;
  border-bottom: 1px solid var(--line);
  background: var(--paper);
}
.page-title { margin: 0; font-size: 24px; font-weight: 700; letter-spacing: -0.02em; color: var(--ink); }
.page-subtitle { margin: 4px 0 0; color: var(--muted); font-size: 13.5px; }
.topbar-actions { display: flex; gap: 8px; align-items: center; }
.content { padding: 24px 32px 60px; }

.flash {
  margin: 14px 32px 0;
  padding: 12px 16px;
  border-radius: var(--radius-sm);
  font-size: 13.5px;
  border: 1px solid;
}
.flash-success { background: var(--green-soft); color: var(--green); border-color: #bbf7d0; }
.flash-error   { background: var(--red-soft);   color: var(--red);   border-color: #fecaca; }

.card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow-sm);
}
.card-pad { padding: 20px; }
.card-head {
  padding: 14px 18px;
  border-bottom: 1px solid var(--line);
  display: flex; justify-content: space-between; align-items: center;
}
.card-title { font-size: 14px; font-weight: 700; }
.card-sub { font-size: 12px; color: var(--muted); }

.stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 16px;
  margin-bottom: 22px;
}
.stat {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 18px;
  position: relative;
  overflow: hidden;
}
.stat-label {
  font-size: 11px; text-transform: uppercase; letter-spacing: 0.08em;
  color: var(--muted); font-weight: 600;
}
.stat-value { margin-top: 6px; font-size: 28px; font-weight: 700; letter-spacing: -0.02em; }
.stat-meta { font-size: 12px; color: var(--muted); margin-top: 4px; }
.stat-accent::before {
  content: ''; position: absolute; left: 0; top: 0; bottom: 0;
  width: 3px; background: var(--accent);
}

.table-wrap { overflow-x: auto; }
table.data { width: 100%; border-collapse: collapse; font-size: 13px; }
table.data thead th {
  text-align: left;
  font-size: 11px; text-transform: uppercase; letter-spacing: 0.06em;
  font-weight: 600; color: var(--muted);
  padding: 10px 14px;
  background: var(--surface-2);
  border-bottom: 1px solid var(--line);
  white-space: nowrap;
}
table.data tbody td {
  padding: 12px 14px;
  border-bottom: 1px solid var(--line-soft);
  vertical-align: middle;
}
table.data tbody tr:hover { background: var(--surface-2); }
table.data tbody tr:last-child td { border-bottom: none; }
.num { font-variant-numeric: tabular-nums; text-align: right; }
.mono { font-family: var(--f-mono); }

.badge {
  display: inline-flex; align-items: center;
  padding: 3px 9px; border-radius: 999px;
  font-size: 11px; font-weight: 600;
  letter-spacing: 0.02em; text-transform: uppercase;
  white-space: nowrap;
}
.badge-green { background: var(--green-soft); color: var(--green); }
.badge-amber { background: var(--amber-soft); color: var(--amber); }
.badge-red   { background: var(--red-soft);   color: var(--red); }
.badge-blue  { background: var(--blue-soft);  color: var(--blue); }
.badge-grey  { background: var(--grey-soft);  color: var(--ink-soft); }
.badge-info  { background: #f1f5f9;           color: var(--ink-soft); }

.btn {
  display: inline-flex; align-items: center; gap: 7px;
  padding: 8px 14px;
  border-radius: var(--radius-sm);
  font-family: var(--f-sans);
  font-size: 13px; font-weight: 600;
  border: 1px solid transparent;
  cursor: pointer; text-decoration: none;
  transition: all 0.12s;
  white-space: nowrap;
}
.btn-primary { background: var(--ink); color: #fff; }
.btn-primary:hover { background: var(--ink-soft); color: #fff; }
.btn-accent  { background: var(--accent); color: #fff; }
.btn-accent:hover  { background: var(--accent-2); color: #fff; }
.btn-ghost   { background: var(--surface); border-color: var(--line); color: var(--ink); }
.btn-ghost:hover   { background: var(--surface-2); }
.btn-danger  { background: var(--red); color: #fff; }
.btn-danger:hover  { background: #991b1b; color: #fff; }
.btn-sm { padding: 5px 10px; font-size: 12px; }
.btn svg { width: 16px; height: 16px; }
.btn-link {
  background: none; border: none;
  color: var(--accent);
  font-size: 12.5px; font-weight: 600;
  padding: 4px 8px; cursor: pointer;
}
.btn-link:hover { text-decoration: underline; }

.form-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 16px;
}
.form-grid .full { grid-column: 1 / -1; }
.field { display: flex; flex-direction: column; gap: 5px; }
.field label { font-size: 12px; font-weight: 600; color: var(--ink-soft); }
.field .hint { font-size: 11.5px; color: var(--muted); }
.input, .select, .textarea {
  width: 100%;
  padding: 9px 12px;
  font-family: var(--f-sans);
  font-size: 13.5px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  color: var(--ink);
  transition: border-color 0.12s, box-shadow 0.12s;
}
.input:focus, .select:focus, .textarea:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(194, 65, 12, 0.12);
}
.textarea { resize: vertical; min-height: 70px; }
.checkbox { display: inline-flex; align-items: center; gap: 8px; font-size: 13px; }
.checkbox input { width: 16px; height: 16px; accent-color: var(--accent); }

.toolbar {
  display: flex; flex-wrap: wrap; gap: 10px; align-items: center;
  margin-bottom: 14px;
  padding: 12px 14px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
}
.toolbar .input, .toolbar .select { width: auto; min-width: 160px; }

.empty { text-align: center; padding: 50px 20px; color: var(--muted); }
.empty h3 { color: var(--ink-soft); margin: 0 0 6px; font-size: 15px; }
.empty p { margin: 0; font-size: 13px; }

/* Plotter */
.plotter {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  overflow: hidden;
}
.plotter-head {
  display: grid;
  grid-template-columns: 200px repeat(7, 1fr);
  background: var(--surface-2);
  border-bottom: 1px solid var(--line);
  position: sticky; top: 0; z-index: 5;
}
.plotter-head > div {
  padding: 10px 12px;
  font-size: 11px; font-weight: 700;
  text-transform: uppercase; letter-spacing: 0.05em;
  color: var(--muted);
  border-right: 1px solid var(--line);
}
.plotter-head > div:last-child { border-right: none; }
.plotter-head .day-label { color: var(--ink); }
.plotter-head .is-today { background: var(--accent-soft); color: var(--accent-2); }
.plotter-row {
  display: grid;
  grid-template-columns: 200px repeat(7, 1fr);
  border-bottom: 1px solid var(--line-soft);
  min-height: 56px;
}
.plotter-row:last-child { border-bottom: none; }
.plotter-veh {
  padding: 10px 12px;
  background: var(--surface-2);
  border-right: 1px solid var(--line);
  display: flex; flex-direction: column; justify-content: center;
}
.plotter-veh .v-code { font-weight: 700; font-size: 13px; }
.plotter-veh .v-meta { font-size: 11px; color: var(--muted); margin-top: 2px; }
.plotter-cell {
  border-right: 1px solid var(--line-soft);
  padding: 4px;
  display: flex; flex-direction: column; gap: 3px;
  position: relative;
  min-height: 56px;
}
.plotter-cell:last-child { border-right: none; }
.plotter-cell.is-today { background: rgba(194, 65, 12, 0.04); }
.trip-chip {
  display: block;
  padding: 4px 7px;
  background: var(--blue-soft); color: var(--blue);
  border-radius: 4px;
  font-size: 11px; font-weight: 600;
  cursor: pointer;
  border-left: 3px solid var(--blue);
  text-decoration: none;
}
.trip-chip:hover { filter: brightness(0.95); }
.trip-chip.is-completed   { background: var(--green-soft); color: var(--green); border-left-color: var(--green); }
.trip-chip.is-cancelled   { background: var(--grey-soft); color: var(--muted); border-left-color: var(--muted); text-decoration: line-through; }
.trip-chip.is-in_progress { background: var(--amber-soft); color: var(--amber); border-left-color: var(--amber); }
.trip-chip.is-dispatched  { background: #e0e7ff; color: #4338ca; border-left-color: #4338ca; }
.trip-chip .chip-client { font-weight: 700; display: block; line-height: 1.2; }
.trip-chip .chip-meta   { font-size: 10px; opacity: 0.85; }

/* Modal */
.modal-backdrop {
  position: fixed; inset: 0;
  background: rgba(15, 23, 42, 0.5);
  display: none;
  align-items: center; justify-content: center;
  z-index: 100;
  padding: 20px;
}
.modal-backdrop.is-open { display: flex; }
.modal {
  background: var(--surface);
  border-radius: var(--radius);
  width: 100%; max-width: 700px;
  max-height: 90vh; overflow-y: auto;
  box-shadow: 0 20px 60px rgba(15, 23, 42, 0.2);
}
.modal-head {
  padding: 16px 22px;
  border-bottom: 1px solid var(--line);
  display: flex; justify-content: space-between; align-items: center;
}
.modal-head h2 { margin: 0; font-size: 16px; font-weight: 700; }
.modal-body { padding: 22px; }
.modal-foot {
  padding: 14px 22px;
  border-top: 1px solid var(--line);
  display: flex; justify-content: flex-end; gap: 8px;
  background: var(--surface-2);
}
.modal-close {
  background: none; border: none; cursor: pointer;
  font-size: 22px; color: var(--muted);
  width: 32px; height: 32px; border-radius: var(--radius-sm);
}
.modal-close:hover { background: var(--surface-2); color: var(--ink); }

/* Login */
.login-shell {
  min-height: 100vh;
  display: grid; place-items: center;
  background:
    radial-gradient(circle at 20% 20%, rgba(194,65,12,0.08), transparent 50%),
    radial-gradient(circle at 80% 80%, rgba(15,23,42,0.06), transparent 50%),
    var(--paper);
  padding: 20px;
}
.login-card {
  width: 100%; max-width: 400px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 36px 32px;
  box-shadow: var(--shadow-md);
}
.login-brand {
  display: flex; flex-direction: column; align-items: center;
  margin-bottom: 24px;
}
.login-brand .brand-mark { width: 52px; height: 52px; font-size: 26px; margin-bottom: 14px; }
.login-brand h1 { margin: 0; font-size: 18px; font-weight: 700; letter-spacing: -0.01em; }
.login-brand p  { margin: 4px 0 0; font-size: 12px; color: var(--muted); letter-spacing: 0.04em; text-transform: uppercase; }

.row-2col { display: grid; grid-template-columns: 2fr 1fr; gap: 18px; }
.row-2col-equal { display: grid; grid-template-columns: 1fr 1fr; gap: 18px; }
.muted { color: var(--muted); }
.small { font-size: 12px; }
.right { text-align: right; }
.tag {
  display: inline-block;
  padding: 2px 7px;
  background: var(--surface-2);
  border: 1px solid var(--line);
  border-radius: 4px;
  font-size: 11px;
  font-family: var(--f-mono);
  color: var(--ink-soft);
}

/* Invoice (printable) */
.invoice-doc {
  background: white;
  padding: 40px;
  max-width: 850px;
  margin: 0 auto;
  border: 1px solid var(--line);
  border-radius: var(--radius);
}
.invoice-head {
  display: flex; justify-content: space-between; align-items: flex-start;
  border-bottom: 2px solid var(--ink);
  padding-bottom: 18px;
  margin-bottom: 28px;
}
.invoice-head .biz-name { font-size: 20px; font-weight: 700; letter-spacing: -0.01em; }
.invoice-head .biz-meta { font-size: 12px; color: var(--muted); margin-top: 4px; }
.invoice-head .inv-meta { text-align: right; }
.invoice-head .inv-meta .inv-no { font-family: var(--f-mono); font-size: 16px; font-weight: 600; }
.invoice-head .inv-meta .inv-label { font-size: 10px; text-transform: uppercase; letter-spacing: 0.08em; color: var(--muted); margin-top: 8px; }

.invoice-bill { display: grid; grid-template-columns: 1fr 1fr; gap: 30px; margin-bottom: 28px; }
.invoice-bill .section-label { font-size: 10px; text-transform: uppercase; letter-spacing: 0.08em; color: var(--muted); margin-bottom: 6px; font-weight: 600; }
.invoice-bill .bill-name { font-weight: 700; font-size: 14px; }

.invoice-totals { margin-top: 16px; margin-left: auto; width: 320px; }
.invoice-totals .tot-row {
  display: flex; justify-content: space-between;
  padding: 6px 0;
  font-size: 13px;
}
.invoice-totals .tot-row.grand {
  border-top: 2px solid var(--ink);
  padding-top: 10px;
  margin-top: 6px;
  font-weight: 700;
  font-size: 16px;
}

.section-title {
  font-size: 11px; text-transform: uppercase; letter-spacing: 0.08em;
  font-weight: 700; color: var(--ink-soft);
  margin: 24px 0 10px;
}

@media (max-width: 920px) {
  .app-shell { grid-template-columns: 1fr; }
  .sidebar { position: relative; height: auto; flex-direction: row; flex-wrap: wrap; padding: 8px; }
  .sidebar .brand { padding: 10px; border: none; }
  .sidebar .nav { flex-direction: row; flex-wrap: wrap; padding: 4px; }
  .sidebar-footer { display: none; }
  .topbar, .content { padding-left: 16px; padding-right: 16px; }
  .form-grid { grid-template-columns: 1fr; }
  .row-2col, .row-2col-equal { grid-template-columns: 1fr; }
  .plotter-head, .plotter-row { grid-template-columns: 140px repeat(7, minmax(80px, 1fr)); overflow-x: auto; }
  .invoice-bill { grid-template-columns: 1fr; }
}

@media print {
  .sidebar, .topbar, .toolbar, .btn, .no-print, .flash { display: none !important; }
  .app-shell { grid-template-columns: 1fr; }
  .main { background: #fff; }
  .content { padding: 0; }
  .card { border: none; box-shadow: none; }
  .invoice-doc { border: none; padding: 0; }
}
