/* Empowered Insurance Agent Portal -- matches the real Replit portal's dark
   theme tokens exactly (converted from client/src/index.css .dark block +
   the literal hex values used in login.tsx). */
:root {
  --background: #080c16;
  --foreground: #f1f5f9;
  --border: #212631;
  --card: #0f141f;
  --card-border: #1a2030;
  --sidebar: #070a13;
  --sidebar-border: #151b28;
  --primary: #3366ff;
  --primary-2: #0099ff;
  --muted: #272b34;
  --muted-foreground: #9ea3ae;
  --accent: #23272f;
  --destructive: #ef4343;
  --green: #22c55e;
  --yellow: #eab308;
  --radius: 10px;
  /* Chart palette -- reuses the app's own semantic tokens above wherever
     possible (chart-1..5 ARE primary/green/yellow/destructive/primary-2)
     so charts stay visually in-sync with the rest of the UI by
     construction; chart-6 is the one net-new token, tuned to the same
     saturation/brightness family as the rest for a dark background. */
  --chart-1: var(--primary);
  --chart-2: var(--green);
  --chart-3: var(--yellow);
  --chart-4: var(--destructive);
  --chart-5: var(--primary-2);
  --chart-6: #8b5cf6;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--background);
  color: var(--foreground);
  font-family: -apple-system, BlinkMacSystemFont, "Inter", "Segoe UI", Helvetica, Arial, sans-serif;
  font-size: 14px;
  line-height: 1.5;
}

a { color: inherit; text-decoration: none; }

.app-shell { display: flex; min-height: 100vh; }

/* Sidebar */
.sidebar {
  width: 232px;
  flex-shrink: 0;
  background: var(--sidebar);
  border-right: 1px solid var(--sidebar-border);
  padding: 22px 16px;
  display: flex;
  flex-direction: column;
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 4px 8px 22px 8px;
}

.brand-mark {
  width: 36px;
  height: 36px;
  border-radius: 8px;
  background: linear-gradient(135deg, var(--primary), var(--primary-2));
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 800;
  font-size: 15px;
  color: white;
  letter-spacing: -0.5px;
  box-shadow: 0 0 20px rgba(51,102,255,0.35);
}

.brand-text {
  font-size: 12.5px;
  font-weight: 800;
  letter-spacing: 0.06em;
  color: var(--foreground);
  line-height: 1.3;
}
.brand-text small { display: block; font-size: 9px; font-weight: 600; color: var(--muted-foreground); letter-spacing: 0.12em; }

.nav-section-label {
  font-size: 10.5px;
  font-weight: 700;
  letter-spacing: 0.1em;
  color: var(--muted-foreground);
  padding: 14px 10px 6px 10px;
  text-transform: uppercase;
}

.nav-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 9px 10px;
  border-radius: 8px;
  color: var(--muted-foreground);
  font-weight: 600;
  font-size: 13.5px;
  margin-bottom: 2px;
}
.nav-item:hover { background: var(--accent); color: var(--foreground); }
.nav-item.active { background: var(--primary); color: white; }

/* Admin sidebar dropdown groups (Company / Commissions / Users / Operations) --
   plain <details>/<summary>, no JS, consistent with the rest of the app. */
.nav-group { margin-bottom: 2px; }
.nav-group-label {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 9px 10px;
  border-radius: 8px;
  color: var(--muted-foreground);
  font-weight: 700;
  font-size: 10.5px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  cursor: pointer;
  list-style: none;
}
.nav-group-label::-webkit-details-marker { display: none; }
.nav-group-label:hover { background: var(--accent); color: var(--foreground); }
.nav-group-label::after {
  content: "";
  width: 6px;
  height: 6px;
  flex-shrink: 0;
  border-right: 1.5px solid currentColor;
  border-bottom: 1.5px solid currentColor;
  opacity: 0.65;
  transform: rotate(45deg);
  transition: transform 0.15s ease;
}
.nav-group[open] > .nav-group-label::after { transform: rotate(-135deg); }
.nav-group-body { padding-left: 8px; margin: 1px 0 4px 0; }
.nav-group-body .nav-item { font-size: 13px; }

.sidebar-footer {
  margin-top: auto;
  padding-top: 14px;
  border-top: 1px solid var(--sidebar-border);
  display: flex;
  align-items: center;
  gap: 10px;
  padding-left: 8px;
}
.avatar {
  width: 32px; height: 32px; border-radius: 50%;
  background: var(--primary);
  display: flex; align-items: center; justify-content: center;
  font-weight: 700; font-size: 12px; color: white;
}
.sidebar-footer-name { font-weight: 700; font-size: 13px; }
.sidebar-footer-role { font-size: 11px; color: var(--muted-foreground); }
.logout-link { margin-left: auto; color: var(--muted-foreground); font-size: 12px; }
.logout-link:hover { color: var(--destructive); }

/* Main content */
.main { flex: 1; overflow-y: auto; }
.page-header { padding: 30px 40px 22px 40px; border-bottom: 1px solid var(--border); }
.page-title { font-size: 26px; font-weight: 800; margin: 0 0 4px 0; letter-spacing: -0.02em; }
.page-subtitle { font-size: 13.5px; color: var(--muted-foreground); margin: 0; }
.page-body { padding: 28px 40px 60px 40px; }

/* Cards / KPIs */
.kpi-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(190px, 1fr)); gap: 14px; margin-bottom: 26px; }
.kpi-card {
  background: var(--card);
  border: 1px solid var(--card-border);
  border-radius: var(--radius);
  padding: 16px 18px;
}
.kpi-label { font-size: 10.5px; font-weight: 700; letter-spacing: 0.08em; text-transform: uppercase; color: var(--muted-foreground); margin-bottom: 8px; }
.kpi-value { font-size: 24px; font-weight: 800; letter-spacing: -0.01em; }
.kpi-sub { font-size: 11.5px; color: var(--muted-foreground); margin-top: 4px; }
.green { color: var(--green); }
.yellow { color: var(--yellow); }
.red { color: var(--destructive); }
.blue { color: var(--primary-2); }

.card {
  background: var(--card);
  border: 1px solid var(--card-border);
  border-radius: var(--radius);
  padding: 20px 22px;
  margin-bottom: 20px;
}
.card-title { font-size: 15px; font-weight: 700; margin: 0 0 14px 0; }

table { width: 100%; border-collapse: collapse; font-size: 13px; }
th {
  text-align: left;
  font-size: 10.5px;
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--muted-foreground);
  padding: 8px 10px;
  border-bottom: 1px solid var(--border);
}
th.num, td.num { text-align: right; }
td { padding: 10px; border-bottom: 1px solid var(--border); }
tr:last-child td { border-bottom: none; }
tr.me { background: rgba(51,102,255,0.08); }

.badge {
  display: inline-block; padding: 2px 9px; border-radius: 100px;
  font-size: 10.5px; font-weight: 700; letter-spacing: 0.04em;
}
.badge.active { background: rgba(34,197,94,0.15); color: var(--green); }
.badge.terminated { background: rgba(239,67,67,0.15); color: var(--destructive); }
.badge.rank1 { background: rgba(234,179,8,0.18); color: var(--yellow); }
.badge.generated { background: rgba(34,197,94,0.15); color: var(--green); }
.badge.imported { background: rgba(234,179,8,0.18); color: var(--yellow); }
.badge.reviewed { background: rgba(0,153,255,0.15); color: var(--primary-2); }
.badge.unpublished { background: rgba(239,67,67,0.15); color: var(--destructive); }
.badge.open { background: rgba(234,179,8,0.18); color: var(--yellow); }
.badge.payments_confirmed { background: rgba(34,197,94,0.15); color: var(--green); }
.badge.processed { background: rgba(34,197,94,0.15); color: var(--green); }
.badge.failed { background: rgba(239,67,67,0.15); color: var(--destructive); }
.badge.carina { background: rgba(0,153,255,0.15); color: var(--primary-2); }

.alert { border-radius: 8px; padding: 12px 16px; font-size: 13px; margin-bottom: 20px; }
.alert-error { background: rgba(239,67,67,0.1); border: 1px solid rgba(239,67,67,0.3); color: #ff8080; }
.alert-warn { background: rgba(234,179,8,0.1); border: 1px solid rgba(234,179,8,0.3); color: var(--yellow); }
.alert-success { background: rgba(34,197,94,0.1); border: 1px solid rgba(34,197,94,0.3); color: var(--green); }

/* Wraps a wide table so it scrolls horizontally within its own card
   instead of forcing the whole page to overflow -- use around any
   <table> whose columns won't comfortably fit a narrow viewport.
   max-width/min-width:0 are load-bearing, not decorative: overflow-x:auto
   alone does not stop a div from growing to fit a wide table INSIDE a
   flex/table ancestor (a nested table inside a <td>, here) -- without an
   explicit width ceiling the browser sizes .table-scroll to its content
   first and only then applies overflow, so the wide content still pushes
   every ancestor (and the page itself) wider. */
.table-scroll { overflow-x: auto; -webkit-overflow-scrolling: touch; max-width: 100%; min-width: 0; }

.btn {
  display: inline-flex; align-items: center; gap: 6px;
  background: var(--primary); color: white; border: none;
  padding: 9px 16px; border-radius: 8px; font-weight: 700; font-size: 13px;
  cursor: pointer;
}
.btn.secondary { background: var(--accent); color: var(--foreground); }
.btn-sm { padding: 6px 12px; font-size: 12px; }

.admin-tiles { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 16px; }
.admin-tile {
  background: var(--card); border: 1px solid var(--card-border); border-radius: var(--radius);
  padding: 22px; display: block;
}
.admin-tile:hover { border-color: var(--primary); }
.admin-tile-title { font-weight: 700; font-size: 15px; margin-bottom: 6px; }
.admin-tile-desc { font-size: 12.5px; color: var(--muted-foreground); }

.empty-state { color: var(--muted-foreground); font-size: 13px; padding: 20px 0; }

/* Login page */
.login-shell {
  min-height: 100vh; display: flex; align-items: center; justify-content: center;
  background: radial-gradient(circle at 30% 20%, rgba(51,102,255,0.10), transparent 45%),
              linear-gradient(160deg, #0d1526, #0a0f1e 55%, #07101d);
}
.login-card {
  width: 380px; background: var(--card); border: 1px solid var(--card-border);
  border-radius: 14px; padding: 34px 32px; box-shadow: 0 20px 60px rgba(0,0,0,0.4);
}
.login-brand { display: flex; flex-direction: column; align-items: center; margin-bottom: 26px; }
.login-mark {
  width: 56px; height: 56px; border-radius: 12px; margin-bottom: 14px;
  background: linear-gradient(135deg, var(--primary), var(--primary-2));
  display: flex; align-items: center; justify-content: center;
  font-weight: 800; font-size: 22px; color: white;
  box-shadow: 0 0 30px rgba(51,102,255,0.45);
}
.login-title { font-weight: 800; font-size: 15px; letter-spacing: 0.15em; text-transform: uppercase; }
.login-tagline { font-size: 10.5px; color: var(--muted-foreground); letter-spacing: 0.16em; text-transform: uppercase; margin-top: 4px; }

.field { margin-bottom: 16px; }
.field label { display: block; font-size: 12px; font-weight: 700; color: var(--muted-foreground); margin-bottom: 6px; }
.field input {
  width: 100%; background: var(--background); border: 1px solid var(--border); color: var(--foreground);
  border-radius: 8px; padding: 10px 12px; font-size: 14px;
}
.field input:focus { outline: none; border-color: var(--primary); }

.login-error {
  background: rgba(239,67,67,0.12); border: 1px solid rgba(239,67,67,0.3); color: #ff8080;
  border-radius: 8px; padding: 10px 12px; font-size: 12.5px; margin-bottom: 16px;
}

.login-submit { width: 100%; padding: 11px; font-size: 14px; margin-top: 4px; }

/* Admin CRUD forms (Agents, Milestone Rules, Carriers, Products, Rates) */
.field select, .field textarea {
  width: 100%; background: var(--background); border: 1px solid var(--border); color: var(--foreground);
  border-radius: 8px; padding: 10px 12px; font-size: 14px; font-family: inherit;
}
.field select:focus, .field textarea:focus { outline: none; border-color: var(--primary); }

table input, table select {
  background: var(--background); border: 1px solid var(--border); color: var(--foreground);
  border-radius: 6px; padding: 5px 8px; font-size: 12.5px; font-family: inherit;
}
table input:focus, table select:focus { outline: none; border-color: var(--primary); }
table input[type="date"] { min-width: 128px; }
table input.narrow { width: 60px; }
table input.mid { width: 100px; }

/* Expenses page's per-row inline forms (Add/edit expense entries) -- not
   inside a .field or a <table>, so they need their own rule matching the
   same dark-theme tokens instead of falling back to browser-default white. */
.expense-row input, .expense-row select {
  background: var(--background); border: 1px solid var(--border); color: var(--foreground);
  border-radius: 6px; padding: 6px 8px; font-size: 12.5px; font-family: inherit;
}
.expense-row input:focus, .expense-row select:focus { outline: none; border-color: var(--primary); }
.expense-row input::placeholder { color: var(--muted-foreground); }
/* Native date-picker glyph renders black-on-transparent by default --
   invert so it's visible against the dark input background. */
.expense-row input[type="date"]::-webkit-calendar-picker-indicator { filter: invert(1); }

.form-row { display: flex; align-items: end; gap: 10px; flex-wrap: wrap; }
.section-title { font-size: 13px; font-weight: 700; color: var(--muted-foreground); text-transform: uppercase; letter-spacing: 0.06em; margin: 30px 0 12px 0; }
.section-title:first-child { margin-top: 0; }
.muted { color: var(--muted-foreground); }

/* ----------------------------------------------------------------------
   Mobile layout: the sidebar becomes an off-canvas panel toggled by a
   fixed hamburger button, instead of permanently sharing the flex row
   with .main (232px of a 375px viewport left only ~63px of usable
   content width once .page-body's own padding was subtracted). Desktop
   (>768px) is completely untouched -- every rule below is either scoped
   to the media query or, for the button/backdrop, hidden by default and
   only shown inside it.
   ---------------------------------------------------------------------- */
.mobile-menu-btn {
  display: none;
  position: fixed; top: 12px; left: 12px; z-index: 70;
  width: 40px; height: 40px;
  background: var(--card); border: 1px solid var(--card-border); border-radius: 8px;
  align-items: center; justify-content: center; flex-direction: column; gap: 4px;
  cursor: pointer; padding: 0;
}
.mobile-menu-btn span { display: block; width: 18px; height: 2px; background: var(--foreground); border-radius: 2px; }

.sidebar-backdrop {
  display: none;
  position: fixed; inset: 0; background: rgba(0,0,0,0.55); z-index: 55;
}
.sidebar-backdrop.sidebar-backdrop-visible { display: block; }

@media (max-width: 768px) {
  .mobile-menu-btn { display: flex; }

  .sidebar {
    position: fixed; top: 0; left: 0; height: 100vh; width: 260px; z-index: 60;
    transform: translateX(-100%);
    transition: transform 0.2s ease;
    overflow-y: auto;
  }
  .sidebar.sidebar-open { transform: translateX(0); }

  /* .sidebar is taken out of the flex flow once fixed-positioned, so
     .main (flex:1) already fills the full width on its own -- these two
     just remove the now-pointless reserved space/scroll behavior. */
  .app-shell { display: block; }
  .main { width: 100%; overflow-y: visible; }

  .page-header { padding: 64px 16px 16px 16px; }
  .page-body { padding: 0 16px 32px 16px; }
  .page-title { font-size: 21px; }

  /* Anything using the shared .form-row/.field pattern (upload forms,
     admin CRUD forms, etc.) already wraps via flex-wrap; this just lets
     each field grow to the full row width once wrapped, instead of
     staying pinned to a desktop-sized min-width. */
  .form-row .field { flex: 1 1 100%; min-width: 0; }
}
