:root {
  --brand-orange: #ef7d06;
  --brand-orange-hover: #d96d00;
  --brand-orange-soft: rgba(239, 125, 6, 0.12);
  --sidebar-bg: #0f172a;
  --sidebar-surface: #18233c;
  --sidebar-text: #cbd5e1;
  --bg: #f4f6fa;
  --surface: #ffffff;
  --border: #e2e8f0;
  --text: #0f172a;
  --muted: #64748b;
  --success: #16a34a;
  --success-soft: #dcfce7;
  --warning: #d97706;
  --warning-soft: #fef3c7;
  --danger: #dc2626;
  --danger-soft: #fee2e2;
  --info: #2563eb;
  --info-soft: #dbeafe;
  --radius: 12px;
  --shadow: 0 1px 3px rgba(15, 23, 42, 0.06), 0 4px 14px rgba(15, 23, 42, 0.04);
  --surface-alt: #f8fafc;
}

[data-theme="dark"] {
  --bg: #0b1120;
  --surface: #111827;
  --surface-alt: #1e293b;
  --border: #1f2937;
  --text: #f1f5f9;
  --muted: #94a3b8;
  --shadow: 0 2px 8px rgba(0, 0, 0, 0.4);
}

[data-theme="dark"] th,
[data-theme="dark"] .modal-footer,
[data-theme="dark"] tr.clickable:hover td {
  background: var(--surface-alt);
}

[data-theme="dark"] .timeline-item {
  background: var(--surface-alt);
}

[data-theme="dark"] .timeline-item.internal {
  background: #271b3f;
}

[data-theme="dark"] .timeline-item.status {
  background: #172033;
}

[data-theme="dark"] .form-field label {
  color: #cbd5e1;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  font-family: 'Segoe UI', system-ui, -apple-system, BlinkMacSystemFont, Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.45;
  -webkit-font-smoothing: antialiased;
}

.tabular {
  font-variant-numeric: tabular-nums;
}

/* Login */
.login-screen {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px;
  background: radial-gradient(circle at top right, rgba(239, 125, 6, 0.16), transparent 45%),
              linear-gradient(135deg, #0b1220 0%, #16223a 100%);
}

.login-card {
  width: 100%;
  max-width: 440px;
  background: var(--surface);
  border-radius: 18px;
  padding: 34px 32px;
  box-shadow: 0 24px 60px rgba(0, 0, 0, 0.35);
}

.brand-lockup {
  display: flex;
  align-items: center;
  gap: 12px;
}

.brand-lockup h1 {
  margin: 0;
  font-size: 1.3rem;
  font-weight: 800;
  letter-spacing: -0.02em;
}

.brand-lockup small {
  display: block;
  font-size: 0.78rem;
  color: var(--muted);
  font-weight: 500;
}

.demo-accounts {
  margin-top: 20px;
  padding-top: 16px;
  border-top: 1px solid var(--border);
}

.demo-accounts-title {
  font-size: 0.78rem;
  font-weight: 600;
  color: var(--muted);
  margin-bottom: 8px;
}

.demo-buttons {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
}

/* App shell */
.shell {
  display: flex;
  min-height: 100vh;
}

.sidebar {
  width: 256px;
  background: var(--sidebar-bg);
  color: var(--sidebar-text);
  display: flex;
  flex-direction: column;
  padding: 20px 14px;
  position: sticky;
  top: 0;
  height: 100vh;
  flex-shrink: 0;
}

.sidebar .brand-lockup h1 {
  color: #fff;
  font-size: 1.15rem;
}

.sidebar .brand-lockup small {
  color: #94a3b8;
}

.nav-list {
  margin-top: 26px;
  display: flex;
  flex-direction: column;
  gap: 4px;
  flex: 1;
}

.nav-item {
  display: flex;
  align-items: center;
  gap: 11px;
  padding: 10px 12px;
  border-radius: 10px;
  border: none;
  background: transparent;
  color: var(--sidebar-text);
  font-size: 0.92rem;
  font-weight: 500;
  cursor: pointer;
  text-align: left;
  transition: background 0.15s, color 0.15s;
}

.nav-item:hover {
  background: var(--sidebar-surface);
  color: #fff;
}

.nav-item.active {
  background: var(--brand-orange);
  color: #fff;
  font-weight: 600;
}

.sidebar-footer {
  margin-top: 16px;
  padding-top: 16px;
  border-top: 1px solid rgba(255, 255, 255, 0.08);
}

.user-pill {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 10px 12px;
  border-radius: 10px;
  background: var(--sidebar-surface);
}

.user-pill-name {
  font-size: 0.85rem;
  font-weight: 600;
  color: #fff;
}

.user-pill-role {
  font-size: 0.74rem;
  color: #94a3b8;
}

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

.topbar {
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  padding: 14px 28px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  position: sticky;
  top: 0;
  z-index: 20;
}

.topbar-title {
  margin: 0;
  font-size: 1.25rem;
  font-weight: 700;
}

.topbar-sub {
  font-size: 0.83rem;
  color: var(--muted);
}

.content {
  padding: 24px 28px 40px;
  max-width: 1400px;
  width: 100%;
  margin: 0 auto;
}

/* Grids & Cards */
.kpi-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(210px, 1fr));
  gap: 16px;
  margin-bottom: 22px;
}

.kpi-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 18px 20px;
  box-shadow: var(--shadow);
}

.kpi-label {
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.03em;
}

.kpi-value {
  margin-top: 8px;
  font-size: 1.65rem;
  font-weight: 800;
  letter-spacing: -0.02em;
}

.kpi-meta {
  margin-top: 6px;
  font-size: 0.8rem;
  color: var(--muted);
}

.two-col {
  display: grid;
  grid-template-columns: 1.6fr 1fr;
  gap: 18px;
}

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  overflow: hidden;
}

.card-header {
  padding: 16px 20px;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
}

.card-title {
  margin: 0;
  font-size: 1rem;
  font-weight: 700;
}

.card-body {
  padding: 18px 20px;
}

/* Toolbar & Filters */
.toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
  margin-bottom: 18px;
}

.filters {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}

/* Tables */
.table-wrap {
  width: 100%;
  overflow-x: auto;
}

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.9rem;
}

th {
  text-align: left;
  padding: 11px 14px;
  font-size: 0.76rem;
  font-weight: 700;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.04em;
  background: #f8fafc;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}

td {
  padding: 12px 14px;
  border-bottom: 1px solid var(--border);
  vertical-align: middle;
}

tr:last-child td {
  border-bottom: none;
}

tr.clickable:hover td {
  background: #f8fafc;
  cursor: pointer;
}

/* Badges */
.badge {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 3px 9px;
  border-radius: 999px;
  font-size: 0.76rem;
  font-weight: 700;
  white-space: nowrap;
}

.badge-orange { background: var(--brand-orange-soft); color: #b45309; }
.badge-success { background: var(--success-soft); color: #15803d; }
.badge-warning { background: var(--warning-soft); color: #b45309; }
.badge-danger { background: var(--danger-soft); color: #b91c1c; }
.badge-info { background: var(--info-soft); color: #1d4ed8; }
.badge-muted { background: #e2e8f0; color: #475569; }

/* Buttons & Inputs */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  padding: 9px 15px;
  border-radius: 9px;
  border: 1px solid transparent;
  font-size: 0.88rem;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s, transform 0.05s;
  white-space: nowrap;
}

.btn:active {
  transform: translateY(1px);
}

.btn-primary {
  background: var(--brand-orange);
  color: #fff;
}

.btn-primary:hover {
  background: var(--brand-orange-hover);
}

.btn-secondary {
  background: var(--surface);
  border-color: var(--border);
  color: var(--text);
}

.btn-secondary:hover {
  background: #f8fafc;
}

.btn-danger {
  background: var(--danger-soft);
  color: var(--danger);
}

.btn-danger:hover {
  background: #fecaca;
}

.btn-sm {
  padding: 6px 10px;
  font-size: 0.8rem;
}

.input, .select, .textarea {
  width: 100%;
  padding: 9px 12px;
  border: 1px solid var(--border);
  border-radius: 9px;
  font-size: 0.9rem;
  font-family: inherit;
  color: var(--text);
  background: var(--surface);
}

.input:focus, .select:focus, .textarea:focus {
  outline: none;
  border-color: var(--brand-orange);
  box-shadow: 0 0 0 3px var(--brand-orange-soft);
}

.filters .input, .filters .select {
  width: auto;
  min-width: 170px;
}

.form-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 14px;
}

.form-field {
  display: flex;
  flex-direction: column;
  gap: 5px;
}

.form-field.full {
  grid-column: 1 / -1;
}

.form-field label {
  font-size: 0.82rem;
  font-weight: 600;
  color: #334155;
}

/* Modal */
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, 0.55);
  display: grid;
  place-items: center;
  padding: 20px;
  z-index: 60;
}

.modal {
  width: 100%;
  max-width: 720px;
  max-height: 90vh;
  background: var(--surface);
  border-radius: 16px;
  box-shadow: 0 24px 60px rgba(15, 23, 42, 0.35);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.modal.modal-lg {
  max-width: 920px;
}

.modal-header {
  padding: 16px 22px;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.modal-header h3 {
  margin: 0;
  font-size: 1.08rem;
}

.modal-body {
  padding: 20px 22px;
  overflow-y: auto;
}

.modal-footer {
  padding: 14px 22px;
  border-top: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 10px;
  background: #f8fafc;
}

/* Timeline */
.timeline {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.timeline-item {
  border: 1px solid var(--border);
  border-left: 4px solid var(--brand-orange);
  border-radius: 10px;
  padding: 11px 14px;
  background: #fff;
}

.timeline-item.internal {
  border-left-color: #7c3aed;
  background: #faf5ff;
}

.timeline-item.status {
  border-left-color: #64748b;
  background: #f8fafc;
}

.timeline-meta {
  display: flex;
  justify-content: space-between;
  gap: 8px;
  font-size: 0.78rem;
  color: var(--muted);
  margin-bottom: 5px;
}

/* Toast */
.toast-root {
  position: fixed;
  right: 20px;
  bottom: 20px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  z-index: 90;
}

.toast {
  background: #0f172a;
  color: #fff;
  padding: 12px 16px;
  border-radius: 10px;
  font-size: 0.88rem;
  font-weight: 500;
  box-shadow: 0 12px 28px rgba(0, 0, 0, 0.25);
  border-left: 4px solid var(--brand-orange);
}

.toast.error {
  border-left-color: var(--danger);
}

.empty-state {
  padding: 36px 20px;
  text-align: center;
  color: var(--muted);
}

.mobile-menu-btn {
  display: none;
}

/* Print layout */
.print-only {
  display: none;
}

.print-sheet {
  background: #ffffff;
  color: #0f172a;
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 28px 32px;
  box-shadow: var(--shadow);
  font-size: 0.95rem;
  line-height: 1.5;
}

.print-sheet h2 {
  margin: 10px 0 8px;
  font-size: 1.2rem;
}

.print-sheet h3 {
  margin: 16px 0 8px;
  font-size: 1rem;
}

@media print {
  #app, #modal-root, #toast-root {
    display: none !important;
  }
  .print-only {
    display: block !important;
    padding: 20px;
    color: #000;
    font-size: 12pt;
  }
}

.sidebar-backdrop {
  display: none;
}

@media (max-width: 960px) {
  .two-col {
    grid-template-columns: 1fr;
  }
  .sidebar {
    position: fixed;
    left: -270px;
    z-index: 50;
    transition: left 0.2s ease;
  }
  .sidebar.open {
    left: 0;
  }
  .sidebar-backdrop.open {
    display: block;
    position: fixed;
    inset: 0;
    background: rgba(15, 23, 42, 0.5);
    z-index: 45;
  }
  .mobile-menu-btn {
    display: inline-flex;
  }
  .form-grid {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 640px) {
  .topbar {
    padding: 12px 14px;
  }
  .topbar-sub,
  .topbar-site {
    display: none;
  }
  .topbar-title {
    font-size: 1.08rem;
  }
  .content {
    padding: 14px 12px 28px;
  }
  .kpi-grid {
    grid-template-columns: repeat(2, 1fr);
    gap: 10px;
  }
  .kpi-card {
    padding: 13px 14px;
  }
  .kpi-value {
    font-size: 1.28rem;
  }
  .filters {
    width: 100%;
  }
  .filters .input,
  .filters .select {
    width: 100%;
    min-width: 0;
  }
  .modal-backdrop {
    padding: 10px;
  }
  .modal {
    max-height: 94vh;
  }
  .modal-header,
  .modal-body,
  .modal-footer {
    padding: 13px 14px;
  }
  .modal-footer {
    flex-wrap: wrap;
    justify-content: stretch;
  }
  .modal-footer .btn {
    flex: 1 1 auto;
  }
  .qt-item-row {
    grid-template-columns: 1fr !important;
  }
}
