  @import url('https://fonts.googleapis.com/css2?family=DM+Serif+Display&family=DM+Sans:wght@300;400;500;600&display=swap');
  
  :root {
    --dark:    #0f1a0e;
    --mid:     #1e3a1e;
    --panel:   #162614;
    --border:  #2a4a29;
    --gold:    #c9a227;
    --gold2:   #e8c84a;
    --green:   #7aab72;
    --pale:    #96aa90;
    --white:   #f5f2ea;
    --muted:   #6a8068;
    --red:     #c0392b;
    --orange:  #e67e22;
    --blue:    #2980b9;
    --radius:  10px;
  }

  * { box-sizing: border-box; margin: 0; padding: 0; }

  body {
    font-family: 'DM Sans', system-ui, sans-serif;
    background: var(--dark);
    color: var(--white);
    height: 100vh;
    display: flex;
    overflow: hidden;
    font-size: 13px;
  }
  /* Global readability: bump tiny fonts */
  table { font-size: 12px !important; }
  th, td { font-size: inherit; }
  .kpi-label { font-size: 11px !important; }
  .kpi-value { font-size: 22px !important; }
  .kpi-sub { font-size: 10px !important; }
  .card-title { font-size: 14px !important; }

  /* ── SIDEBAR ──────────────────────────────────────── */
  #sidebar {
    width: 220px;
    min-width: 220px;
    background: var(--panel);
    border-right: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    padding: 0;
    overflow: hidden;
  }

  .logo {
    padding: 16px 18px 14px;
    border-bottom: 1px solid var(--border);
    display: flex;
    align-items: center;
    gap: 11px;
  }
  .logo-img { width: 54px; height: 54px; object-fit: contain; flex-shrink: 0; filter: invert(1) sepia(1) saturate(5) hue-rotate(5deg); }
  .logo-title {
    font-family: 'DM Serif Display', serif;
    font-size: 20px;
    color: var(--gold);
    letter-spacing: 0.5px;
  }
  .logo-sub {
    font-size: 10px;
    color: var(--muted);
    letter-spacing: 1.5px;
    text-transform: uppercase;
    margin-top: 3px;
  }

  .nav {
    flex: 1;
    overflow-y: auto;
    padding: 10px 0;
  }
  .nav-section {
    font-size: 9px;
    letter-spacing: 2px;
    text-transform: uppercase;
    color: var(--muted);
    padding: 12px 18px 5px;
  }
  .nav-item {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 9px 18px;
    cursor: pointer;
    font-size: 13px;
    color: var(--pale);
    border-left: 3px solid transparent;
    transition: all .15s;
    user-select: none;
  }
  .nav-item:hover { background: rgba(201,162,39,.07); color: var(--white); }
  .nav-item.active {
    background: rgba(201,162,39,.12);
    color: var(--gold);
    border-left-color: var(--gold);
    font-weight: 600;
  }
  .nav-icon { font-size: 15px; width: 20px; text-align: center; }

  .sidebar-footer {
    flex-shrink: 0;
    padding: 14px 18px;
    border-top: 1px solid var(--border);
    font-size: 11px;
    color: var(--muted);
  }

  /* ── MAIN AREA ───────────────────────────────────── */
  #main {
    flex: 1;
    display: flex;
    flex-direction: column;
    overflow: hidden;
  }

  .topbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 14px 24px;
    border-bottom: 1px solid var(--border);
    background: var(--panel);
  }
  .topbar-title {
    font-family: 'DM Serif Display', serif;
    font-size: 20px;
    color: var(--white);
  }
  .topbar-sub { font-size: 12px; color: var(--muted); margin-top: 2px; }
  .topbar-actions { display: flex; gap: 10px; align-items: center; }

  .btn {
    padding: 7px 16px;
    border-radius: 6px;
    border: none;
    cursor: pointer;
    font-size: 13px;
    font-family: 'DM Sans', sans-serif;
    font-weight: 500;
    transition: all .15s;
  }
  .btn-primary { background: var(--gold); color: var(--dark); }
  .btn-primary:hover { background: var(--gold2); }
  .btn-ghost { background: transparent; color: var(--pale); border: 1px solid var(--border); }
  .btn-ghost:hover { border-color: var(--gold); color: var(--gold); }
  .btn-danger { background: var(--red); color: white; }
  .btn-sm { padding: 5px 11px; font-size: 12px; }

  .content {
    flex: 1;
    overflow-y: auto;
    padding: 24px;
    min-height: 0;   /* critical: allows flex child to shrink & scroll */
  }

  /* ── CARDS & GRID ────────────────────────────────── */
  .kpi-grid {
    display: grid;
    grid-template-columns: repeat(5, 1fr);
    gap: 14px;
    margin-bottom: 24px;
  }
  .kpi-card {
    background: var(--panel);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 16px;
    position: relative;
    overflow: hidden;
  }
  .kpi-card::before {
    content: '';
    position: absolute;
    top: 0; left: 0; right: 0;
    height: 2px;
    background: var(--gold);
    opacity: .6;
  }
  .kpi-label { font-size: 10px; letter-spacing: 1.5px; text-transform: uppercase; color: var(--muted); margin-bottom: 8px; }
  .kpi-value { font-family: 'DM Serif Display', serif; font-size: 28px; color: var(--gold); line-height: 1; }
  .kpi-sub { font-size: 11px; color: var(--muted); margin-top: 5px; }
  .kpi-badge {
    display: inline-block;
    padding: 2px 8px;
    border-radius: 99px;
    font-size: 10px;
    font-weight: 600;
    margin-top: 6px;
  }
  .badge-green { background: rgba(122,171,114,.2); color: var(--green); }
  .badge-gold  { background: rgba(201,162,39,.2);  color: var(--gold); }
  .badge-red   { background: rgba(192,57,43,.2);   color: #e74c3c; }
  .badge-blue  { background: rgba(41,128,185,.2);  color: #5dade2; }
  .badge-orange { background: rgba(230,126,34,.2); color: var(--orange); }

  .card {
    background: var(--panel);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    overflow: hidden;
    margin-bottom: 20px;
  }
  .card-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 14px 18px;
    border-bottom: 1px solid var(--border);
    background: rgba(0,0,0,.15);
  }
  .card-title { font-weight: 600; font-size: 14px; display: flex; align-items: center; gap: 8px; }
  .card-body { padding: 18px; }

  /* ── TABLE ───────────────────────────────────────── */
  .tbl-wrap { overflow-x: auto; }
  table { width: 100%; border-collapse: collapse; font-size: 12px; }
  th {
    padding: 6px 10px;
    text-align: left;
    font-size: 9px;
    letter-spacing: .8px;
    text-transform: uppercase;
    color: var(--muted);
    border-bottom: 1px solid var(--border);
    background: rgba(0,0,0,.2);
    white-space: nowrap;
  }
  td {
    padding: 5px 10px;
    border-bottom: 1px solid rgba(42,74,41,.3);
    color: var(--white);
    vertical-align: middle;
  }
  tr:hover td { background: rgba(201,162,39,.04); }
  tr:last-child td { border-bottom: none; }
  /* Expandable row detail */
  .row-detail { display:none;padding:8px 12px 10px;background:rgba(0,0,0,.12);border-bottom:1px solid var(--border); }
  .row-detail.open { display:block; }
  .row-toggle { cursor:pointer; }
  .row-toggle:hover td:first-child { color:var(--gold) !important; }

  .status-pill {
    display: inline-block;
    padding: 2px 9px;
    border-radius: 99px;
    font-size: 11px;
    font-weight: 600;
    white-space: nowrap;
  }
  .s-delivered { background: rgba(122,171,114,.2); color: var(--green); }
  .s-transit   { background: rgba(41,128,185,.2);  color: #5dade2; }
  .s-hub       { background: rgba(201,162,39,.2);  color: var(--gold); }
  .s-pending   { background: rgba(150,170,144,.15); color: var(--muted); }
  .s-closed    { background: rgba(122,171,114,.15); color: var(--muted); }
  .s-open      { background: rgba(192,57,43,.2);   color: #e74c3c; }
  .s-yes       { color: var(--green); font-weight: 600; }
  .s-no        { color: #e74c3c; }
  .s-pass      { color: var(--green); }
  .s-fail      { color: #e74c3c; }

  .action-btn {
    padding: 3px 10px;
    border-radius: 4px;
    border: 1px solid var(--border);
    background: transparent;
    color: var(--pale);
    cursor: pointer;
    font-size: 11px;
    transition: all .15s;
    margin-right: 4px;
  }
  .action-btn:hover { border-color: var(--gold); color: var(--gold); }
  .action-btn.danger:hover { border-color: var(--red); color: var(--red); }

  /* ── FORMS ───────────────────────────────────────── */
  .modal-overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,.82);
    z-index: 100;
    align-items: center;
    justify-content: center;
  }
  .modal-overlay.open { display: flex; }
  .modal {
    background: var(--panel);
    border: 1px solid var(--border);
    border-radius: 12px;
    width: 680px;
    max-width: 95vw;
    max-height: 90vh;
    display: flex;
    flex-direction: column;
    box-shadow: 0 24px 80px rgba(0,0,0,.6);
  }
  .modal-header {
    padding: 18px 22px;
    border-bottom: 1px solid var(--border);
    display: flex;
    justify-content: space-between;
    align-items: center;
  }
  .modal-title { font-family: 'DM Serif Display', serif; font-size: 18px; color: var(--gold); }
  .modal-close { background: none; border: none; color: var(--muted); font-size: 20px; cursor: pointer; }
  .modal-close:hover { color: var(--white); }
  .modal-body { padding: 22px; overflow-y: auto; flex: 1; }
  .modal-footer { padding: 14px 22px; border-top: 1px solid var(--border); display: flex; justify-content: flex-end; gap: 10px; }

  .form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
  .form-grid.cols3 { grid-template-columns: 1fr 1fr 1fr; }
  .form-group { display: flex; flex-direction: column; gap: 6px; }
  .form-group.full { grid-column: 1 / -1; }
  label { font-size: 11px; color: var(--muted); letter-spacing: .5px; text-transform: uppercase; }
  input, select, textarea {
    background: rgba(0,0,0,.3);
    border: 1px solid var(--border);
    border-radius: 6px;
    color: var(--white);
    padding: 8px 11px;
    font-size: 13px;
    font-family: 'DM Sans', sans-serif;
    transition: border .15s;
    width: 100%;
  }
  input:focus, select:focus, textarea:focus {
    outline: none;
    border-color: var(--gold);
  }
  select option { background: var(--mid); }
  textarea { resize: vertical; min-height: 70px; }

  /* ── SEARCH BAR ──────────────────────────────────── */
  .search-row {
    display: flex;
    gap: 10px;
    margin-bottom: 16px;
    align-items: center;
  }
  .search-box {
    flex: 1;
    position: relative;
  }
  .search-box input {
    padding-left: 34px;
  }
  .search-icon {
    position: absolute;
    left: 11px;
    top: 50%;
    transform: translateY(-50%);
    color: var(--muted);
    font-size: 14px;
  }

  /* ── CHAIN STEPS ────────────────────────────────── */
  .chain-steps {
    display: flex;
    gap: 0;
    margin-bottom: 20px;
    overflow-x: auto;
    padding-bottom: 4px;
  }
  .chain-step {
    display: flex;
    align-items: center;
    gap: 0;
    flex-shrink: 0;
  }
  .chain-node {
    display: flex;
    flex-direction: column;
    align-items: center;
    padding: 10px 14px;
    background: var(--mid);
    border: 1px solid var(--border);
    border-radius: 8px;
    min-width: 110px;
    cursor: pointer;
    transition: all .15s;
    text-align: center;
  }
  .chain-node:hover, .chain-node.active { border-color: var(--gold); background: rgba(201,162,39,.1); }
  .chain-node .step-num { font-size: 10px; color: var(--gold); font-weight: 700; letter-spacing: 1px; }
  .chain-node .step-icon { font-size: 20px; margin: 4px 0; }
  .chain-node .step-name { font-size: 11px; color: var(--pale); }
  .chain-arrow { color: var(--muted); font-size: 16px; padding: 0 4px; align-self: center; }

  /* ── ESG SCORE ───────────────────────────────────── */
  .score-ring {
    width: 80px; height: 80px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-family: 'DM Serif Display', serif;
    font-size: 22px;
    border: 3px solid var(--gold);
  }

  /* ── TRUST SCORE BAR ──────────────────────────────── */
  .trust-bar {
    height: 6px;
    background: var(--border);
    border-radius: 99px;
    overflow: hidden;
    margin-top: 4px;
  }
  .trust-fill {
    height: 100%;
    border-radius: 99px;
    background: linear-gradient(90deg, #c0392b 0%, #e67e22 50%, #27ae60 100%);
    transition: width .4s;
  }

  /* ── EMPTY STATE ─────────────────────────────────── */
  .empty-state {
    text-align: center;
    padding: 50px 20px;
    color: var(--muted);
  }
  .empty-state .empty-icon { font-size: 40px; margin-bottom: 12px; }
  .empty-state .empty-text { font-size: 14px; }

  /* ── TOAST ───────────────────────────────────────── */
  .toast {
    position: fixed;
    bottom: 24px;
    right: 24px;
    background: var(--mid);
    border: 1px solid var(--gold);
    border-radius: 8px;
    padding: 12px 18px;
    font-size: 13px;
    color: var(--gold);
    z-index: 999;
    transform: translateY(20px);
    opacity: 0;
    transition: all .25s;
    pointer-events: none;
  }
  .toast.show { transform: translateY(0); opacity: 1; }

  /* ── DELIVERY DETAIL ─────────────────────────────── */
  .detail-section {
    margin-bottom: 16px;
  }
  .detail-section-title {
    font-size: 10px;
    letter-spacing: 1.5px;
    text-transform: uppercase;
    color: var(--gold);
    margin-bottom: 10px;
    padding-bottom: 6px;
    border-bottom: 1px solid var(--border);
  }
  .detail-grid {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 12px;
  }
  .detail-item label { font-size: 10px; color: var(--muted); display: block; margin-bottom: 3px; }
  .detail-item .val { font-size: 13px; color: var(--white); }

  .page { display: none; }
  .page.active { display: block; }

  /* ── SCROLLBAR ───────────────────────────────────── */
  ::-webkit-scrollbar { width: 5px; height: 5px; }
  ::-webkit-scrollbar-track { background: transparent; }
  ::-webkit-scrollbar-thumb { background: var(--border); border-radius: 99px; }
  ::-webkit-scrollbar-thumb:hover { background: var(--muted); }
  @keyframes pulse { 0%,100%{opacity:1;transform:scale(1)} 50%{opacity:.6;transform:scale(1.15)} }
  /* Leaflet map overrides for dark theme */
  .leaflet-container { background: #111318; font-family: 'DM Sans', sans-serif; }
  .leaflet-popup-content-wrapper { background: var(--panel); color: var(--pale); border: 1px solid var(--border); border-radius: 8px; }
  .leaflet-popup-tip { background: var(--panel); }
  .leaflet-popup-content { font-size: 12px; line-height: 1.5; }
  .leaflet-control-layers { background: var(--panel) !important; color: var(--pale) !important; border: 1px solid var(--border) !important; border-radius: 8px !important; }
  .leaflet-control-layers-base label, .leaflet-control-layers-overlays label { color: var(--pale); }
  .leaflet-control-zoom a { background: var(--panel) !important; color: var(--gold) !important; border-color: var(--border) !important; }
  .leaflet-control-zoom a:hover { background: var(--mid) !important; }
  .sf-map-container { width: 100%; height: calc(100vh - 280px); min-height: 400px; border-radius: 10px; border: 1px solid var(--border); overflow: hidden; }

/* ── Inline styles (second block) ── */
        .addr-wrap { position:relative; }
        .addr-dropdown {
          position:absolute; top:100%; left:0; right:0; z-index:200;
          background:var(--mid); border:1px solid var(--gold); border-radius:6px;
          max-height:180px; overflow-y:auto; display:none;
        }
        .addr-dropdown.open { display:block; }
        .addr-option {
          padding:8px 12px; cursor:pointer; font-size:12px; border-bottom:1px solid var(--border);
          color:var(--white); line-height:1.4;
        }
        .addr-option:hover { background:rgba(201,162,39,.15); color:var(--gold); }
        .form-section-label {
          grid-column:1/-1; font-size:10px; letter-spacing:2px; text-transform:uppercase;
          color:var(--gold); padding:10px 12px 6px; border-bottom:2px solid rgba(201,162,39,.3);
          margin-top:12px; background:rgba(201,162,39,.04); border-radius:6px 6px 0 0;
          font-weight:700;
        }
        .readonly-field {
          background:rgba(122,171,114,.08) !important;
          color:var(--muted) !important;
          font-size:12px;
        }
        .perf-badge {
          display:inline-block; padding:2px 8px; border-radius:4px; font-size:11px; font-weight:600;
          background:rgba(201,162,39,.15); color:var(--gold);
        }

/* ── AUTH SCREENS ─────────────────────────────────────────────────────────── */
.auth-card {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 40px 36px 32px;
  width: 100%;
  max-width: 380px;
  box-shadow: 0 20px 60px rgba(0,0,0,.5);
}
.auth-logo {
  display: flex;
  align-items: center;
  gap: 12px;
  font-family: 'DM Serif Display', serif;
  font-size: 24px;
  color: var(--gold);
  margin-bottom: 4px;
}
.auth-subtitle {
  font-size: 12px;
  color: var(--muted);
  letter-spacing: 1px;
  text-transform: uppercase;
  margin-bottom: 28px;
}
.auth-card input[type="email"],
.auth-card input[type="password"] {
  display: block;
  width: 100%;
  background: var(--mid);
  border: 1px solid var(--border);
  border-radius: 6px;
  color: var(--white);
  font-size: 14px;
  padding: 11px 14px;
  margin-bottom: 12px;
  outline: none;
  font-family: inherit;
  transition: border-color .15s;
}
.auth-card input:focus {
  border-color: var(--gold);
}
.auth-card button[type="submit"] {
  display: block;
  width: 100%;
  background: var(--gold);
  color: #0f1a0e;
  border: none;
  border-radius: 6px;
  font-size: 14px;
  font-weight: 600;
  padding: 12px;
  cursor: pointer;
  margin-top: 4px;
  font-family: inherit;
  transition: background .15s, opacity .15s;
}
.auth-card button[type="submit"]:hover { background: var(--gold2); }
.auth-card button[type="submit"]:disabled { opacity: .55; cursor: not-allowed; }
.auth-error {
  color: var(--red);
  font-size: 12px;
  margin-top: 10px;
  min-height: 16px;
  line-height: 1.4;
}

@media (max-width: 480px) {
  .auth-card { padding: 28px 20px 24px; }
}
