:root {
  --bg: #f4f7fb;
  --surface: #ffffff;
  --surface-2: #f8fafc;
  --text: #101828;
  --muted: #667085;
  --line: #e5e7eb;
  --primary: #2563eb;
  --primary-2: #1d4ed8;
  --danger: #dc2626;
  --ok: #16a34a;
  --warn: #d97706;
  --purple: #7c3aed;
  --shadow: 0 18px 45px rgba(15, 23, 42, .10);
  --soft-shadow: 0 8px 24px rgba(15, 23, 42, .07);
  --radius: 22px;
}
* { box-sizing: border-box; }
html, body { margin: 0; min-height: 100%; color: var(--text); font-family: Inter, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Arial, sans-serif; }
body { background: radial-gradient(circle at top left, rgba(37,99,235,.16), transparent 38%), linear-gradient(180deg, #f8fbff, var(--bg)); padding-bottom: env(safe-area-inset-bottom); }
button, input, select, textarea { font: inherit; }
button { cursor: pointer; }
.hidden { display: none !important; }
.app-shell { display: grid; grid-template-columns: 280px minmax(0, 1fr); min-height: 100vh; }
.side-nav { position: sticky; top: 0; height: 100vh; padding: 24px 18px; background: rgba(255,255,255,.80); backdrop-filter: blur(16px); border-right: 1px solid var(--line); }
.brand-block, .brand-line { display: flex; align-items: center; gap: 12px; }
.brand-block { margin-bottom: 28px; }
.logo-dot, .logo-mark { display: inline-flex; align-items: center; justify-content: center; width: 44px; height: 44px; border-radius: 15px; background: linear-gradient(135deg, var(--primary), var(--purple)); color: #fff; font-weight: 950; box-shadow: var(--soft-shadow); flex: 0 0 auto; }
.logo-mark { width: 60px; height: 60px; border-radius: 22px; font-size: 22px; margin-bottom: 14px; }
.brand-name { font-size: 21px; font-weight: 950; letter-spacing: -.04em; }
.brand-caption { font-size: 12px; color: var(--muted); margin-top: 3px; }
.desktop-nav { display: grid; gap: 8px; }
.nav { border: 0; background: transparent; border-radius: 16px; padding: 13px 14px; display: flex; align-items: center; gap: 11px; color: #475467; font-weight: 850; text-align: left; }
.nav.active, .nav:hover { background: #eff6ff; color: var(--primary-2); }
.side-card { margin-top: 24px; padding: 16px; border: 1px solid var(--line); border-radius: 20px; background: linear-gradient(180deg, #fff, #f8fafc); }
.side-card strong { display: block; margin-bottom: 6px; }
.side-card small { color: var(--muted); line-height: 1.45; }
.main-frame { min-width: 0; padding: 24px 28px 96px; }
.app-topbar { display: flex; align-items: center; justify-content: space-between; gap: 14px; margin-bottom: 14px; }
.brand-line { font-size: 28px; font-weight: 950; letter-spacing: -.04em; }
.mobile-logo { display: none; }
.subtle, .muted { color: var(--muted); font-size: 13px; }
.top-actions, .actions, .section-head, .sheet-head, .card-row, .kv-row { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.primary, .ghost, .danger, .small { border: 0; border-radius: 15px; min-height: 44px; padding: 0 16px; font-weight: 900; }
.primary { background: var(--primary); color: #fff; }
.primary:hover { background: var(--primary-2); }
.ghost { background: #fff; color: var(--text); border: 1px solid var(--line); }
.danger { background: var(--danger); color: #fff; }
.ghost-danger { border-color: rgba(220,38,38,.25); color: var(--danger); background: #fff; }
.small { min-height: 36px; padding: 0 12px; border-radius: 12px; }
.wide { width: 100%; }
.content { display: block; }
.view { display: none; }
.view.active { display: block; }
.section-hero { display: flex; justify-content: space-between; align-items: flex-start; gap: 18px; margin: 12px 0 18px; }
.section-hero h1, .section-head h2 { margin: 0; font-size: 30px; letter-spacing: -.05em; }
.section-hero p, .section-head p { margin: 6px 0 0; color: var(--muted); }
.search-box { display: flex; gap: 10px; align-items: center; background: var(--surface); border: 1px solid var(--line); border-radius: 18px; padding: 10px 12px; box-shadow: var(--soft-shadow); min-width: 340px; }
.search-box input, label input, label select, textarea { width: 100%; border: 1px solid var(--line); background: #fff; border-radius: 16px; min-height: 46px; padding: 10px 13px; color: var(--text); outline: none; }
.search-box input { border: 0; min-height: 28px; padding: 0; background: transparent; }
.search-box input:focus, label input:focus, label select:focus, textarea:focus { border-color: var(--primary-2); box-shadow: 0 0 0 4px rgba(37,99,235,.10); }
.stats-grid { display: grid; grid-template-columns: repeat(6, minmax(0, 1fr)); gap: 14px; margin-bottom: 18px; }
.stat-card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; box-shadow: var(--soft-shadow); position: relative; overflow: hidden; min-height: 106px; }
.stat-card:after { content: ""; position: absolute; right: -24px; top: -30px; width: 85px; height: 85px; border-radius: 50%; background: rgba(37,99,235,.08); }
.stat-card span { display: block; color: var(--muted); font-size: 12px; margin-bottom: 8px; font-weight: 800; }
.stat-card b { display: block; font-size: 30px; line-height: 1; letter-spacing: -.04em; }
.stat-card small { display: block; color: var(--muted); margin-top: 8px; }
.work-grid { display: grid; grid-template-columns: minmax(0, 1fr) 360px; gap: 18px; align-items: start; }
.queue-panel, .panel, .rail-card, .request-card, .loading-card, .empty-card, .diag-card, .user-card { background: rgba(255,255,255,.88); border: 1px solid var(--line); border-radius: 28px; box-shadow: var(--shadow); }
.queue-panel { overflow: hidden; }
.panel-head { padding: 18px; border-bottom: 1px solid var(--line); }
.panel-head strong { display: block; font-size: 18px; }
.panel-head span { display: block; margin-top: 3px; color: var(--muted); font-size: 13px; }
.tabs { display: flex; gap: 8px; overflow-x: auto; scrollbar-width: none; padding: 14px 18px; }
.tabs::-webkit-scrollbar { display: none; }
.tab { white-space: nowrap; border: 1px solid var(--line); background: #fff; color: var(--muted); padding: 11px 14px; border-radius: 999px; font-weight: 900; }
.tab.active { background: var(--primary); color: #fff; border-color: var(--primary); }
.request-list, .stack { display: grid; gap: 12px; }
.request-list { padding: 0 18px 18px; }
.loading-card, .empty-card, .panel, .diag-card, .user-card { padding: 16px; }
.request-card { padding: 16px; cursor: pointer; transition: transform .15s ease, box-shadow .15s ease, border-color .15s ease; }
.request-card:hover { transform: translateY(-2px); border-color: #bfdbfe; }
.card-title { font-size: 18px; font-weight: 950; letter-spacing: -.025em; }
.badge { display: inline-flex; align-items: center; border-radius: 999px; padding: 6px 9px; background: #eef2ff; color: #4338ca; font-size: 11px; font-weight: 950; text-transform: uppercase; letter-spacing: .04em; }
.badge.ok { color: #15803d; background: #dcfce7; }
.badge.danger { color: #b91c1c; background: #fee2e2; }
.badge.warn { color: #c2410c; background: #fff7ed; }
.amount-grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 8px; margin-top: 13px; }
.amount-box { background: #f8fbff; border: 1px solid #eef2f7; border-radius: 16px; padding: 10px; }
.amount-box span { display: block; color: var(--muted); font-size: 11px; font-weight: 850; }
.amount-box b { display: block; margin-top: 4px; font-size: 15px; }
.risk-bar { margin-top: 12px; height: 8px; background: #eef2f7; border-radius: 999px; overflow: hidden; }
.risk-bar span { display: block; height: 100%; background: linear-gradient(90deg, #22c55e, #f59e0b, #ef4444); }
.message { margin-top: 12px; color: var(--muted); font-size: 14px; }
.message.error, .error-text { color: var(--danger); }
.message.ok { color: var(--ok); }
.banner { border-radius: 18px; padding: 12px 14px; margin-bottom: 12px; display: flex; justify-content: space-between; align-items: center; gap: 12px; }
.banner.warning { background: #fff7ed; color: #9a3412; border: 1px solid #fed7aa; }
.banner.info { background: #eff6ff; color: #1d4ed8; border: 1px solid #bfdbfe; }
.right-rail { display: grid; gap: 14px; }
.rail-card { padding: 18px; }
.rail-card h3 { margin: 0 0 8px; }
.rail-card p, .rail-card li { color: var(--muted); line-height: 1.5; }
.rail-card ul { margin: 10px 0 0; padding-left: 20px; }
.rail-card.accent { background: linear-gradient(135deg, #eff6ff, #f5f3ff); }
.section-head { margin: 8px 0 18px; align-items: flex-start; }
.form-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; }
.form-grid.one { grid-template-columns: 1fr; }
label { color: var(--muted); font-size: 13px; font-weight: 800; }
label input, label select { margin-top: 6px; }
.profile-info { margin-bottom: 16px; }
.profile-panel { max-width: 720px; }
.kv-row { align-items: flex-start; border-bottom: 1px solid var(--line); padding: 10px 0; }
.kv-row b { color: var(--muted); font-size: 13px; }
.kv-row span { font-weight: 750; text-align: right; overflow-wrap: anywhere; }
.detail-grid { background: #fff; border: 1px solid var(--line); border-radius: 22px; padding: 6px 14px; margin-bottom: 12px; }
.detail-amounts { display: grid; grid-template-columns: repeat(3,1fr); gap: 10px; margin-bottom: 12px; }
.detail-amount { background: var(--surface-2); border: 1px solid #eef2f7; border-radius: 18px; padding: 12px; }
.detail-amount small { color: var(--muted); font-weight: 850; }
.detail-amount strong { display: block; font-size: 18px; margin-top: 5px; }
textarea { resize: vertical; min-height: 92px; }
pre { white-space: pre-wrap; overflow: auto; background: #f8fafc; border-radius: 14px; padding: 12px; }
.timeline { display: grid; gap: 10px; }
.timeline-item { border-left: 3px solid #dbeafe; padding: 2px 0 8px 12px; }
.timeline-item b { display: block; }
.sheet-backdrop { position: fixed; inset: 0; background: rgba(15, 23, 42, .48); z-index: 20; display: flex; align-items: center; justify-content: center; padding: 20px; }
.sheet-card { width: min(760px, 100%); max-height: 92vh; overflow: auto; background: #fff; border-radius: 28px; box-shadow: var(--shadow); }
.sheet-head { position: sticky; top: 0; background: rgba(255,255,255,.95); backdrop-filter: blur(10px); padding: 18px; border-bottom: 1px solid var(--line); z-index: 2; }
.sheet-head h2 { margin: 0; }
.sheet-body { padding: 18px; display: grid; gap: 12px; }
.toast { position: fixed; left: 50%; bottom: 100px; transform: translateX(-50%); z-index: 40; background: #111827; color: #fff; border-radius: 999px; padding: 12px 16px; box-shadow: var(--shadow); }
.bottom-nav { display: none; }
.login-page { min-height: 100vh; display: grid; place-items: center; padding: 22px; background: radial-gradient(circle at 15% 15%, rgba(37,99,235,.35), transparent 35%), linear-gradient(135deg, #0f172a, #1e3a8a); }
.login-shell { width: min(1040px, 100%); display: grid; grid-template-columns: 1.05fr 420px; gap: 22px; align-items: center; }
.login-copy { color: #fff; padding: 24px; }
.brand-block.light .brand-caption { color: #cbd5e1; }
.login-copy h1 { font-size: clamp(34px, 5vw, 58px); line-height: .98; letter-spacing: -.06em; margin: 42px 0 16px; }
.login-copy p { color: #cbd5e1; font-size: 17px; line-height: 1.6; max-width: 620px; }
.login-points { display: flex; flex-wrap: wrap; gap: 10px; margin-top: 22px; }
.login-points span { border: 1px solid rgba(255,255,255,.22); background: rgba(255,255,255,.10); border-radius: 999px; padding: 9px 12px; }
.login-card { background: #fff; border-radius: 30px; padding: 26px; box-shadow: var(--shadow); }
.login-card h2 { margin: 0; font-size: 30px; letter-spacing: -.04em; }
.login-card form { display: grid; gap: 12px; margin-top: 16px; }
.check-row { display: flex; align-items: center; gap: 8px; color: var(--muted); }
.check-row input { width: auto; min-height: auto; margin: 0; }
.hint { color: var(--muted); font-size: 13px; line-height: 1.5; margin-top: 14px; }
@media (max-width: 1180px) {
  .app-shell { grid-template-columns: 1fr; }
  .side-nav { display: none; }
  .main-frame { padding: 16px 14px 100px; }
  .mobile-logo { display: inline-flex; }
  .work-grid { grid-template-columns: 1fr; }
  .right-rail { display: none; }
  .stats-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .section-hero, .app-topbar { align-items: flex-start; flex-direction: column; }
  .search-box { min-width: 0; width: 100%; }
  .bottom-nav { position: fixed; left: 12px; right: 12px; bottom: calc(12px + env(safe-area-inset-bottom)); z-index: 30; display: grid; grid-template-columns: repeat(4, 1fr); gap: 6px; padding: 8px; background: rgba(255,255,255,.94); border: 1px solid var(--line); border-radius: 22px; box-shadow: var(--shadow); backdrop-filter: blur(16px); }
  .bottom-nav .nav { justify-content: center; padding: 10px 6px; font-size: 11px; flex-direction: column; gap: 3px; }
  .bottom-nav .nav em { font-style: normal; }
}
@media (max-width: 720px) {
  .brand-line { font-size: 24px; }
  .section-hero h1, .section-head h2 { font-size: 25px; }
  .queue-panel, .panel, .rail-card, .request-card, .loading-card, .empty-card, .diag-card, .user-card { border-radius: 22px; }
  .amount-grid, .detail-amounts { grid-template-columns: repeat(2, minmax(0,1fr)); }
  .amount-box:last-child, .detail-amount:last-child { grid-column: 1 / -1; }
  .form-grid { grid-template-columns: 1fr; }
  .sheet-backdrop { align-items: flex-end; padding: 0; }
  .sheet-card { border-radius: 28px 28px 0 0; width: 100%; max-height: 88vh; }
  .login-shell { grid-template-columns: 1fr; }
  .login-copy { padding: 0 4px; }
  .login-copy h1 { margin-top: 26px; }
}

/* Clean mobile-first PWA refinements */
.side-card { display: none; }
.brand-caption { opacity: .72; }
.work-grid { grid-template-columns: minmax(0, 1fr); }
.right-rail { display: none !important; }
.section-hero.compact { margin: 6px 0 14px; }
.section-hero.compact .search-box { width: min(640px, 100%); min-width: 0; }
.panel-head span, .stat-card small { display: none; }
.stat-card { min-height: 82px; padding: 14px; }
.stat-card b { margin-top: 6px; font-size: 28px; }
.banner.warning { box-shadow: 0 8px 24px rgba(154,52,18,.10); }
.banner-text { min-width: 0; line-height: 1.35; }
.banner-text span { font-weight: 500; }
.banner-actions { display: inline-flex; align-items: center; gap: 8px; flex: 0 0 auto; }
.icon-btn { width: 36px; height: 36px; border: 0; border-radius: 12px; display: inline-grid; place-items: center; background: rgba(15,23,42,.08); color: var(--text); font-size: 22px; line-height: 1; font-weight: 900; }
.icon-btn:hover { background: rgba(15,23,42,.14); }

@media (max-width: 1180px) {
  .side-nav, .desktop-nav, .side-card { display: none !important; }
  .app-shell { display: block; }
  .main-frame { padding-top: 14px; }
  .app-topbar { flex-direction: row; align-items: center; margin-bottom: 10px; }
  .brand-line { font-size: 23px; }
  #signedInAs { font-size: 12px; }
  .top-actions .ghost { min-height: 40px; padding: 0 13px; }
  .content { padding-bottom: 8px; }
  .section-hero.compact { margin-top: 4px; }
  .stats-grid { gap: 10px; margin-bottom: 12px; }
  .stat-card { border-radius: 18px; min-height: 74px; padding: 12px; }
  .stat-card span { font-size: 11px; margin-bottom: 6px; }
  .stat-card b { font-size: 25px; }
  .queue-panel { border-radius: 22px; }
  .panel-head { padding: 14px; }
  .tabs { padding: 12px 14px; }
  .request-list { padding: 0 14px 14px; }
  .bottom-nav { display: grid !important; }
}

@media (max-width: 720px) {
  body { background: #f4f7fb; }
  .main-frame { padding: 12px 12px 92px; }
  .mobile-logo { width: 38px; height: 38px; border-radius: 14px; }
  .brand-line { font-size: 21px; }
  .app-topbar { gap: 10px; }
  .top-actions { gap: 8px; }
  .top-actions .ghost { min-height: 38px; border-radius: 14px; padding: 0 12px; }
  .banner { border-radius: 18px; padding: 11px; align-items: flex-start; }
  .banner.warning { margin-bottom: 10px; }
  .banner-text b { display: block; }
  .banner-text span { display: block; margin-top: 2px; }
  .banner-actions { gap: 6px; }
  .banner-actions .small { min-height: 36px; padding: 0 11px; }
  .section-hero.compact .search-box { border-radius: 18px; box-shadow: none; }
  .stats-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .stat-card:after { display: none; }
  .card-title { font-size: 16px; }
  .amount-grid { grid-template-columns: repeat(3, minmax(0,1fr)); gap: 6px; }
  .amount-box { padding: 8px; border-radius: 14px; }
  .amount-box:last-child { grid-column: auto; }
  .amount-box b { font-size: 13px; }
  .bottom-nav { left: 10px; right: 10px; bottom: calc(10px + env(safe-area-inset-bottom)); border-radius: 20px; }
}

/* v5 final mobile cleanup: remove duplicate top navigation and keep one navigation surface. */
.side-nav,
.desktop-nav,
.side-card {
  display: none !important;
}

.app-shell {
  display: block !important;
  min-height: 100vh;
}

.main-frame {
  width: min(1280px, 100%);
  margin: 0 auto;
}

.desktop-tabs {
  display: flex;
  gap: 8px;
  align-items: center;
  margin: 0 0 14px;
  overflow: auto;
  padding-bottom: 2px;
}

.desktop-tabs .nav {
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 10px 14px;
  white-space: nowrap;
  box-shadow: 0 4px 12px rgba(15,23,42,.04);
}

.desktop-tabs .nav.active,
.desktop-tabs .nav:hover {
  background: var(--primary);
  border-color: var(--primary);
  color: #fff;
}

.banner-actions .icon-btn {
  appearance: none;
  -webkit-appearance: none;
  cursor: pointer;
  touch-action: manipulation;
}

@media (max-width: 900px) {
  .desktop-tabs {
    display: none !important;
  }

  .main-frame {
    width: 100%;
    margin: 0;
  }

  .app-topbar {
    position: sticky;
    top: 0;
    z-index: 16;
    background: rgba(244,247,251,.94);
    backdrop-filter: blur(14px);
    -webkit-backdrop-filter: blur(14px);
    padding: 10px 0;
  }

  .brand-line span:not(.logo-dot) {
    white-space: nowrap;
  }

  .bottom-nav {
    display: grid !important;
  }
}

@media (max-width: 720px) {
  .main-frame {
    padding: 10px 10px 94px;
  }

  .app-topbar {
    margin-bottom: 8px;
  }

  .brand-line {
    font-size: 20px;
  }

  #signedInAs {
    display: none;
  }

  .banner.warning {
    display: flex;
    justify-content: space-between;
    gap: 10px;
  }

  .banner.warning.hidden {
    display: none !important;
  }

  .banner-text {
    font-size: 14px;
  }

  .banner-text span {
    display: none;
  }

  .banner-actions .small {
    display: none;
  }

  .icon-btn {
    width: 34px;
    height: 34px;
    min-width: 34px;
  }
}
