:root {
  --bg: #f4f6fb;
  --surface: #ffffff;
  --text: #0f172a;
  --muted: #64748b;
  --border: #e2e8f0;
  --primary: #2563eb;
  --primary-hover: #1d4ed8;
  --primary-soft: #eff6ff;
  --success: #10b981;
  --success-dark: #059669;
  --success-soft: #ecfdf5;
  --warning: #f59e0b;
  --warning-soft: #fffbeb;
  --danger: #ef4444;
  --danger-soft: #fef2f2;
  --purple: #7c3aed;
  --purple-soft: #f5f3ff;
  --radius: 14px;
  --radius-sm: 9px;
  --shadow: 0 1px 2px rgba(15, 23, 42, 0.04), 0 4px 12px rgba(15, 23, 42, 0.04);
  --shadow-lg: 0 20px 45px rgba(15, 23, 42, 0.16);
}

* { box-sizing: border-box; }
body {
  margin: 0;
  font-family: "Inter", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

/* Auth Screen */
.auth-wrap {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  background:
    radial-gradient(at 15% 20%, rgba(59, 130, 246, 0.35) 0px, transparent 50%),
    radial-gradient(at 85% 80%, rgba(16, 185, 129, 0.22) 0px, transparent 50%),
    linear-gradient(135deg, #0b1120 0%, #172554 100%);
}
.auth-card {
  background: rgba(255, 255, 255, 0.98);
  width: 100%;
  max-width: 430px;
  border-radius: 20px;
  padding: 36px 34px;
  box-shadow: 0 25px 60px rgba(0, 0, 0, 0.35);
  border: 1px solid rgba(255, 255, 255, 0.25);
}
.brand-mark {
  display: flex;
  align-items: center;
  gap: 10px;
  font-weight: 800;
  font-size: 22px;
  letter-spacing: -0.02em;
  color: var(--text);
  margin-bottom: 6px;
}
.brand-badge {
  width: 36px;
  height: 36px;
  border-radius: 10px;
  background: linear-gradient(135deg, #2563eb, #1d4ed8);
  color: #fff;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 4px 12px rgba(37, 99, 235, 0.35);
}
.demo-creds {
  margin-top: 22px;
  padding: 14px;
  background: #f8fafc;
  border: 1px solid var(--border);
  border-radius: 12px;
  font-size: 12px;
  color: var(--muted);
}
.demo-creds .demo-btns {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 8px;
}

/* App Shell */
.shell {
  display: flex;
  min-height: 100vh;
}
.sidebar {
  width: 256px;
  background: linear-gradient(180deg, #0f172a 0%, #0b1120 100%);
  color: #e2e8f0;
  display: flex;
  flex-direction: column;
  padding: 20px 14px;
  flex-shrink: 0;
  border-right: 1px solid rgba(255, 255, 255, 0.06);
  position: sticky;
  top: 0;
  height: 100vh;
  overflow-y: auto;
}
.sidebar .brand {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 18px;
  font-weight: 800;
  letter-spacing: -0.02em;
  color: #fff;
  padding: 4px 8px 18px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.08);
  margin-bottom: 14px;
}
.nav-btn {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  text-align: left;
  background: transparent;
  border: none;
  color: #94a3b8;
  padding: 10px 12px;
  border-radius: 10px;
  font-size: 13.5px;
  font-weight: 600;
  cursor: pointer;
  margin-bottom: 4px;
  transition: all 0.15s ease;
}
.nav-btn svg { width: 17px; height: 17px; flex-shrink: 0; opacity: 0.8; }
.nav-btn:hover { background: rgba(255, 255, 255, 0.07); color: #f8fafc; }
.nav-btn.active {
  background: linear-gradient(135deg, #2563eb, #1d4ed8);
  color: #fff;
  box-shadow: 0 4px 12px rgba(37, 99, 235, 0.35);
}
.nav-btn.active svg { opacity: 1; }

.sidebar-footer {
  margin-top: auto;
  padding-top: 14px;
  border-top: 1px solid rgba(255, 255, 255, 0.08);
  font-size: 13px;
}
.user-chip {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 12px;
}
.avatar {
  width: 34px;
  height: 34px;
  border-radius: 10px;
  background: rgba(59, 130, 246, 0.2);
  color: #93c5fd;
  font-weight: 700;
  font-size: 13px;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}
.sidebar-footer .user-name { font-weight: 600; color: #f8fafc; line-height: 1.2; }
.sidebar-footer .user-role { font-size: 11px; color: #94a3b8; text-transform: uppercase; letter-spacing: 0.05em; }

.panel-switcher {
  display: flex;
  background: rgba(255, 255, 255, 0.06);
  padding: 3px;
  border-radius: 9px;
  gap: 3px;
  margin-bottom: 10px;
}
.panel-switcher button {
  flex: 1;
  border: none;
  background: transparent;
  color: #94a3b8;
  font-size: 11px;
  font-weight: 700;
  padding: 6px 4px;
  border-radius: 7px;
  cursor: pointer;
  transition: all 0.15s ease;
}
.panel-switcher button.active {
  background: #2563eb;
  color: #fff;
  box-shadow: 0 2px 6px rgba(37, 99, 235, 0.35);
}
.logout-btn {
  width: 100%;
  background: rgba(255, 255, 255, 0.06);
  color: #cbd5e1;
  border: 1px solid rgba(255, 255, 255, 0.1);
}
.logout-btn:hover { background: rgba(239, 68, 68, 0.18); color: #fca5a5; border-color: rgba(239, 68, 68, 0.3); }

.main {
  flex: 1;
  padding: 28px 32px;
  max-width: 1400px;
  width: 100%;
  margin: 0 auto;
}

.page-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 12px;
  margin-bottom: 22px;
}
.page-header h1 { margin: 0; font-size: 24px; font-weight: 800; letter-spacing: -0.02em; }
.page-header p { margin: 3px 0 0; color: var(--muted); font-size: 13.5px; }

/* Cards & Grids */
.grid-2 { display: grid; grid-template-columns: repeat(auto-fit, minmax(340px, 1fr)); gap: 18px; }
.grid-4 { display: grid; grid-template-columns: repeat(auto-fit, minmax(195px, 1fr)); gap: 14px; }
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px 22px;
  box-shadow: var(--shadow);
  margin-bottom: 18px;
}
.card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 14px;
}
.card-header h2, .card-header h3 { margin: 0; font-size: 15.5px; font-weight: 700; letter-spacing: -0.01em; }

.stat-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 18px 18px 16px;
  box-shadow: var(--shadow);
  position: relative;
  overflow: hidden;
  transition: transform 0.15s ease, box-shadow 0.15s ease;
}
.stat-card::before {
  content: "";
  position: absolute;
  top: 0; left: 0; right: 0;
  height: 3px;
  background: linear-gradient(90deg, #2563eb, #38bdf8);
  opacity: 0.75;
}
.stat-card:hover { transform: translateY(-1px); box-shadow: 0 8px 20px rgba(15, 23, 42, 0.06); }
.stat-label { font-size: 11.5px; color: var(--muted); text-transform: uppercase; letter-spacing: 0.05em; font-weight: 700; }
.stat-value { font-size: 26px; font-weight: 800; margin-top: 6px; letter-spacing: -0.02em; font-variant-numeric: tabular-nums; }
.stat-sub { font-size: 12px; color: var(--muted); margin-top: 2px; }

/* Buttons */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 9px 15px;
  border-radius: var(--radius-sm);
  font-size: 13.5px;
  font-weight: 600;
  border: 1px solid transparent;
  cursor: pointer;
  transition: all 0.15s ease;
  font-family: inherit;
}
.btn-primary { background: var(--primary); color: #fff; box-shadow: 0 1px 2px rgba(37, 99, 235, 0.25); }
.btn-primary:hover { background: var(--primary-hover); transform: translateY(-0.5px); }
.btn-success { background: var(--success); color: #fff; }
.btn-success:hover { background: var(--success-dark); }
.btn-danger { background: var(--danger); color: #fff; }
.btn-danger:hover { background: #dc2626; }
.btn-outline { background: #fff; color: #334155; border-color: var(--border); }
.btn-outline:hover { background: #f8fafc; border-color: #cbd5e1; color: var(--text); }
.btn-sm { padding: 6px 11px; font-size: 12px; border-radius: 7px; }

/* Badges */
.badge {
  display: inline-flex;
  align-items: center;
  padding: 3px 9px;
  border-radius: 999px;
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.03em;
}
.badge-pending, .badge-unpaid, .badge-partial { background: var(--warning-soft); color: #b45309; border: 1px solid #fde68a; }
.badge-dispatched { background: var(--primary-soft); color: var(--primary); border: 1px solid #bfdbfe; }
.badge-in_progress { background: var(--purple-soft); color: var(--purple); border: 1px solid #ddd6fe; }
.badge-awaiting_approval { background: #fff7ed; color: #c2410c; border: 1px solid #fed7aa; }
.badge-approved, .badge-signed, .badge-paid { background: var(--success-soft); color: #047857; border: 1px solid #a7f3d0; }
.badge-cancelled, .badge-emergency { background: var(--danger-soft); color: #b91c1c; border: 1px solid #fecaca; }
.badge-draft { background: #f1f5f9; color: #475569; border: 1px solid #e2e8f0; }

/* Forms */
.form-group { margin-bottom: 14px; }
.form-group label { display: block; font-size: 12.5px; font-weight: 600; margin-bottom: 5px; color: #334155; }
input[type="text"], input[type="email"], input[type="password"], input[type="number"], input[type="tel"], input[type="date"], select, textarea {
  width: 100%;
  padding: 9px 12px;
  border: 1px solid #cbd5e1;
  border-radius: var(--radius-sm);
  font-size: 13.5px;
  font-family: inherit;
  background: #fff;
  color: var(--text);
  transition: border-color 0.15s, box-shadow 0.15s;
}
input:focus, select:focus, textarea:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.14);
}
textarea { min-height: 76px; resize: vertical; }
.form-row { display: grid; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); gap: 12px; }

/* Tables */
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: 13.5px; font-variant-numeric: tabular-nums; }
th, td { text-align: left; padding: 12px 12px; border-bottom: 1px solid #f1f5f9; }
th { font-size: 11px; text-transform: uppercase; letter-spacing: 0.05em; color: var(--muted); font-weight: 700; background: #f8fafc; border-bottom: 1px solid var(--border); }
tbody tr { transition: background 0.12s; }
tbody tr:hover td { background: #f8fafc; }

/* Signature Canvas */
.sig-box {
  border: 2px dashed #cbd5e1;
  border-radius: 10px;
  background: #fff;
  overflow: hidden;
  touch-action: none;
}
.sig-box canvas { display: block; width: 100%; height: 150px; cursor: crosshair; }
.sig-preview { max-height: 70px; border: 1px solid var(--border); border-radius: 8px; background: #fff; padding: 4px; }

/* Photos */
.photo-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 12px; }
.photo-card { border: 1px solid var(--border); border-radius: 10px; overflow: hidden; background: #fff; }
.photo-card img { width: 100%; height: 110px; object-fit: cover; display: block; }
.photo-card .meta { padding: 7px 9px; font-size: 12px; }

/* Modal */
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, 0.55);
  backdrop-filter: blur(4px);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
  z-index: 100;
  animation: fadeIn 0.15s ease;
}
.modal {
  background: #fff;
  width: 100%;
  max-width: 740px;
  max-height: 90vh;
  overflow-y: auto;
  border-radius: 16px;
  padding: 26px;
  box-shadow: var(--shadow-lg);
  animation: popIn 0.18s ease;
}
.modal-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 16px; padding-bottom: 12px; border-bottom: 1px solid var(--border); }
.modal-header h2 { margin: 0; font-size: 18px; font-weight: 700; }

@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }
@keyframes popIn { from { opacity: 0; transform: translateY(8px) scale(0.98); } to { opacity: 1; transform: none; } }

/* Toast */
#toast-root { position: fixed; bottom: 20px; right: 20px; z-index: 200; display: flex; flex-direction: column; gap: 8px; }
.toast { background: #0f172a; color: #fff; padding: 12px 16px; border-radius: 10px; font-size: 13.5px; font-weight: 500; box-shadow: 0 10px 25px rgba(0, 0, 0, 0.22); }
.toast.error { background: var(--danger); }
.toast.success { background: var(--success-dark); }

/* In-House Notification Banner Stack */
#inapp-notif-bar {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-bottom: 16px;
}
.inapp-notif {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 12px 16px;
  background: linear-gradient(135deg, #eff6ff 0%, #ffffff 100%);
  border: 1px solid #bfdbfe;
  border-left: 4px solid var(--primary);
  border-radius: 12px;
  box-shadow: var(--shadow);
  touch-action: pan-y;
  transition: transform 0.2s ease, opacity 0.2s ease;
  user-select: none;
}
.inapp-notif .n-title { font-weight: 700; font-size: 13.5px; color: var(--text); }
.inapp-notif .n-body { font-size: 13px; color: #334155; }
.inapp-notif .n-hint { font-size: 11px; color: var(--muted); margin-top: 2px; }

/* Legal / Terms Box */
.terms-box {
  background: #f8fafc;
  border: 1px solid #cbd5e1;
  border-radius: 10px;
  padding: 12px 14px;
  font-size: 12.5px;
  color: #334155;
  white-space: pre-line;
  max-height: 170px;
  overflow-y: auto;
  margin-bottom: 12px;
}
.doc-title {
  font-size: 13px;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--primary);
  margin-bottom: 6px;
}

/* Mobile Responsive */
@media (max-width: 768px) {
  .shell { flex-direction: column; }
  .sidebar { position: static; height: auto; width: 100%; flex-direction: row; flex-wrap: wrap; align-items: center; padding: 12px; gap: 6px; }
  .sidebar .brand { border-bottom: none; padding: 4px 8px; margin: 0; }
  .nav-btn { width: auto; padding: 7px 10px; font-size: 13px; margin: 0; }
  .sidebar-footer {
    order: -1;
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
    width: 100%;
    margin-top: 0;
    margin-bottom: 8px;
    padding-top: 0;
    padding-bottom: 10px;
    border-top: none;
    border-bottom: 1px solid rgba(255, 255, 255, 0.1);
  }
  .sidebar-footer .user-chip { margin-bottom: 0; }
  .sidebar-footer .panel-switcher { margin-bottom: 0; min-width: 150px; }
  .sidebar-footer .logout-btn { width: auto; padding: 6px 12px; }
  .main { padding: 16px; }
}

@media print {
  .sidebar, .no-print, #toast-root, .btn { display: none !important; }
  body { background: #fff; }
  .main { padding: 0; max-width: 100%; }
  .card { box-shadow: none; border: 1px solid #cbd5e1; break-inside: avoid; }
}
