/* ===== AIA Partner Portal ===== */
:root {
  --accent: #4f46e5;
  --accent-soft: #eef2ff;
  --ink: #0f172a;
  --ink-2: #334155;
  --muted: #64748b;
  --line: #e2e8f0;
  --bg: #f6f7fb;
  --card: #ffffff;
  --ok: #059669;
  --bad: #dc2626;
  --radius: 14px;
  --shadow: 0 1px 2px rgba(15, 23, 42, .05), 0 4px 16px rgba(15, 23, 42, .06);
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  background: var(--bg);
  color: var(--ink);
  font-size: 15px;
  -webkit-font-smoothing: antialiased;
}

/* ===== layout ===== */
.layout { display: flex; min-height: 100vh; }
.content { flex: 1; min-width: 0; position: relative; }
#main { padding: 28px 32px 48px; max-width: 1500px; }

/* ===== sidebar ===== */
.sidebar {
  width: 232px; flex-shrink: 0;
  background: linear-gradient(180deg, #111c34 0%, #0f172a 100%);
  color: #cbd5e1;
  display: flex; flex-direction: column;
  position: sticky; top: 0; height: 100vh;
}
.brand { display: flex; align-items: center; gap: 10px; padding: 22px 20px 18px; }
.brand-mark {
  width: 38px; height: 38px; border-radius: 10px; flex-shrink: 0;
  background: linear-gradient(135deg, #6366f1, #8b5cf6);
  color: #fff; font-weight: 800; font-size: 13px; letter-spacing: .5px;
  display: flex; align-items: center; justify-content: center;
  box-shadow: 0 4px 12px rgba(99, 102, 241, .4);
}
.brand-mark.lg { width: 54px; height: 54px; font-size: 18px; border-radius: 14px; margin: 0 auto; }
.brand-name { font-weight: 700; color: #f1f5f9; font-size: 15px; letter-spacing: .2px; }

.nav { padding: 8px 12px; flex: 1; }
.nav-link {
  display: flex; align-items: center; gap: 12px;
  padding: 10px 12px; margin: 2px 0;
  color: #94a3b8; text-decoration: none;
  border-radius: 9px; font-weight: 500; font-size: 14px;
  transition: background .15s, color .15s;
}
.nav-link svg { width: 18px; height: 18px; fill: currentColor; opacity: .9; }
.nav-link:hover { background: rgba(148, 163, 184, .12); color: #e2e8f0; }
.nav-link.active { background: var(--accent); color: #fff; box-shadow: 0 4px 12px rgba(79, 70, 229, .35); }

.sidebar-foot {
  display: flex; align-items: center; gap: 10px;
  padding: 14px 16px; border-top: 1px solid rgba(148, 163, 184, .15);
}
.avatar {
  width: 34px; height: 34px; border-radius: 50%; flex-shrink: 0;
  background: rgba(99, 102, 241, .3); color: #c7d2fe;
  display: flex; align-items: center; justify-content: center; font-weight: 700;
}
.who { flex: 1; min-width: 0; }
.who-name { color: #e2e8f0; font-size: 13px; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.who-role { font-size: 11px; color: #64748b; text-transform: uppercase; letter-spacing: .6px; }
.logout-form { margin: 0; }
.logout {
  background: none; border: none; cursor: pointer; padding: 6px;
  border-radius: 8px; color: #64748b; display: flex;
}
.logout svg { width: 18px; height: 18px; fill: currentColor; }
.logout:hover { background: rgba(148, 163, 184, .12); color: #e2e8f0; }

/* ===== page header ===== */
.page-head {
  display: flex; align-items: flex-end; justify-content: space-between;
  gap: 18px; flex-wrap: wrap; margin-bottom: 22px;
}
.page-head h1 { margin: 0; font-size: 24px; font-weight: 750; letter-spacing: -.3px; }
.page-sub { margin: 4px 0 0; color: var(--muted); font-size: 13.5px; }
.section { margin-bottom: 34px; }
.section-title {
  font-size: 13px; font-weight: 700; text-transform: uppercase;
  letter-spacing: 1.2px; color: var(--muted); margin: 0 0 4px;
}
.section-sub { margin: 0 0 14px; color: var(--muted); font-size: 13px; }
.section-title + .kpi-row, .section-title + .card { margin-top: 14px; }

/* ===== KPI tiles ===== */
.kpi-row {
  display: grid; gap: 16px; margin-bottom: 18px;
  grid-template-columns: repeat(auto-fit, minmax(210px, 1fr));
}
.kpi-tile {
  background: var(--card); border-radius: var(--radius);
  padding: 18px 20px; box-shadow: var(--shadow);
  border-top: 3px solid var(--accent);
  min-height: 92px;
}
.kpi-tile.skeleton { display: flex; align-items: center; justify-content: center; border-top-color: var(--line); }
.kpi-label {
  font-size: 12px; font-weight: 600; text-transform: uppercase;
  letter-spacing: .8px; color: var(--muted);
}
.kpi-value { font-size: 30px; font-weight: 800; letter-spacing: -.5px; margin-top: 6px; color: var(--ink); }

/* ===== cards ===== */
.card {
  background: var(--card); border-radius: var(--radius);
  box-shadow: var(--shadow); margin-bottom: 22px;
}
.chart-card { padding: 18px 20px; min-height: 360px; }
.chart-wrap { position: relative; height: 320px; }
.table-card { padding: 0; overflow: hidden; }
.card-head {
  display: flex; align-items: center; justify-content: space-between;
  padding: 16px 20px; border-bottom: 1px solid var(--line);
}
.card-head h3 { margin: 0; font-size: 15.5px; font-weight: 700; }

/* ===== tables ===== */
.table-scroll { overflow: auto; max-height: 540px; }
table.data { width: 100%; border-collapse: collapse; font-size: 13.5px; }
table.data th {
  text-align: left; padding: 11px 14px; white-space: nowrap;
  font-size: 11.5px; text-transform: uppercase; letter-spacing: .7px;
  color: var(--muted); background: #fafbfd;
  border-bottom: 1px solid var(--line);
  position: sticky; top: 0;
}
table.sortable th { cursor: pointer; user-select: none; }
table.sortable th:hover { color: var(--accent); }
table.sortable th.sorted-asc::after { content: " ▲"; font-size: 9px; }
table.sortable th.sorted-desc::after { content: " ▼"; font-size: 9px; }
table.data td { padding: 10px 14px; border-bottom: 1px solid #eef1f6; white-space: nowrap; }
table.data tbody tr:hover { background: #f8faff; }
.table-foot { padding: 12px 20px; color: var(--muted); font-size: 12.5px; }
.empty { padding: 42px; text-align: center; color: var(--muted); }

.pill {
  display: inline-block; padding: 3px 10px; border-radius: 99px;
  font-size: 11.5px; font-weight: 600; background: var(--accent-soft); color: var(--accent);
}
.pill-admin { background: #fdf4ff; color: #a21caf; }
.pill-ok { background: #ecfdf5; color: var(--ok); }
.pill-off { background: #fef2f2; color: var(--bad); }
.row-actions { display: flex; gap: 8px; }

/* ===== forms & buttons ===== */
.btn {
  display: inline-flex; align-items: center; gap: 6px;
  font-size: 13.5px; font-weight: 600;
  padding: 9px 16px; border-radius: 9px; border: none;
  cursor: pointer; text-decoration: none; line-height: 1.2;
  transition: filter .15s, background .15s;
}
.btn-primary { background: var(--accent); color: #fff; box-shadow: 0 2px 8px rgba(79, 70, 229, .3); }
.btn-primary:hover { filter: brightness(1.08); }
.btn-outline { background: #fff; color: var(--ink-2); border: 1px solid var(--line); }
.btn-outline:hover { border-color: var(--accent); color: var(--accent); }
.btn-sm { padding: 5px 11px; font-size: 12px; }
.btn-block { width: 100%; justify-content: center; margin-top: 18px; }

.range-picker { display: flex; align-items: flex-end; gap: 10px; flex-wrap: wrap; }
.range-picker label { display: flex; flex-direction: column; gap: 4px; font-size: 12px; font-weight: 600; color: var(--muted); }
.range-picker input[type="date"] {
  padding: 8px 10px; border: 1px solid var(--line); border-radius: 9px;
  font-size: 13.5px; background: #fff; color: var(--ink);
}

.admin-create { display: flex; gap: 14px; align-items: flex-end; flex-wrap: wrap; padding: 18px 20px; }
.admin-create label { display: flex; flex-direction: column; gap: 5px; font-size: 12px; font-weight: 600; color: var(--muted); }
.admin-create input, .admin-create select {
  padding: 9px 11px; border: 1px solid var(--line); border-radius: 9px;
  font-size: 14px; min-width: 180px; background: #fff;
}

input:focus, select:focus { outline: 2px solid var(--accent); outline-offset: 0; border-color: transparent; }

/* ===== alerts / credentials ===== */
.alert {
  background: #fef2f2; color: #991b1b; border: 1px solid #fecaca;
  border-radius: 10px; padding: 13px 16px; margin-bottom: 18px; font-size: 14px;
}
.alert.success { background: #ecfdf5; color: #065f46; border-color: #a7f3d0; }
.cred { display: flex; gap: 26px; margin-top: 8px; flex-wrap: wrap; }
.cred code {
  background: #fff; padding: 3px 9px; border-radius: 6px;
  border: 1px solid #a7f3d0; font-size: 14px; user-select: all;
}

/* ===== loading ===== */
.loading-box {
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 12px; min-height: 220px; color: var(--muted); font-size: 13.5px;
}
.spinner {
  width: 34px; height: 34px; border-radius: 50%;
  border: 3px solid var(--line); border-top-color: var(--accent);
  animation: spin .7s linear infinite;
}
.spinner.sm { width: 22px; height: 22px; border-width: 2.5px; }
@keyframes spin { to { transform: rotate(360deg); } }

.page-loading {
  position: absolute; top: 0; left: 0; right: 0; height: 3px;
  pointer-events: none; opacity: 0; transition: opacity .15s; z-index: 10;
  overflow: hidden;
}
.page-loading.htmx-request { opacity: 1; }
.page-loading .bar {
  height: 100%; width: 40%;
  background: linear-gradient(90deg, var(--accent), #8b5cf6);
}
.page-loading.htmx-request .bar {
  animation: slide 1s ease-in-out infinite;
}
@keyframes slide { 0% { margin-left: -40%; } 100% { margin-left: 100%; } }

/* ===== login ===== */
.login-body {
  min-height: 100vh; display: flex; flex-direction: column;
  align-items: center; justify-content: center; gap: 22px;
  background: radial-gradient(1100px 500px at 50% -10%, #e0e7ff 0%, var(--bg) 55%);
}
.login-card {
  background: var(--card); border-radius: 18px;
  box-shadow: 0 8px 40px rgba(15, 23, 42, .12);
  padding: 38px 40px; width: 400px; max-width: calc(100vw - 32px);
}
.login-brand { text-align: center; margin-bottom: 22px; }
.login-brand h1 { margin: 14px 0 0; font-size: 21px; letter-spacing: -.3px; }
.login-sub { color: var(--muted); font-size: 13.5px; margin: 6px 0 0; }
.login-card label { display: block; font-size: 12.5px; font-weight: 600; color: var(--ink-2); margin: 14px 0 5px; }
.login-card input {
  width: 100%; padding: 11px 13px; font-size: 15px;
  border: 1px solid var(--line); border-radius: 10px; background: #fff;
}
.cf-turnstile { margin-top: 18px; }
.login-foot { color: var(--muted); font-size: 12px; }

/* ===== tablet / mobile: sidebar becomes a top nav ===== */
@media (max-width: 1024px) {
  .layout { flex-direction: column; }

  .sidebar {
    width: 100%; height: auto;
    flex-direction: row; flex-wrap: wrap; align-items: center;
    position: sticky; top: 0; z-index: 50;
    padding: 6px 8px;
    box-shadow: 0 2px 10px rgba(15, 23, 42, .18);
  }

  .brand { padding: 8px 10px; order: 1; }

  /* user + logout pushed to the far right of the top row */
  .sidebar-foot {
    order: 2; margin-left: auto; padding: 6px 8px;
    border-top: none; gap: 8px;
  }

  /* nav links wrap to a full-width second row, horizontally scrollable */
  .nav {
    order: 3; flex: 1 1 100%;
    display: flex; gap: 4px; padding: 4px 2px 2px;
    overflow-x: auto; -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
  }
  .nav::-webkit-scrollbar { display: none; }
  .nav-link {
    flex: 0 0 auto; margin: 0; padding: 9px 14px;
    white-space: nowrap;
  }

  #main { padding: 18px 16px 40px; }
  .sidebar { height: auto !important; }
}

/* phones: tighten spacing, allow brand to sit alongside a wrapping nav */
@media (max-width: 560px) {
  .brand-name { font-size: 14px; }
  .who { display: none; }            /* keep avatar + logout, drop the name block */
  .nav-link { padding: 8px 12px; font-size: 13.5px; }
  .page-head { gap: 12px; }
  .range-picker { width: 100%; }
}
