:root {
  --navy: #1e3a5f;
  --navy-2: #16304f;
  --blue: #2b5c8a;
  --blue-soft: #e8f0f7;
  --ink: #1c2430;
  --muted: #5c6b7a;
  --paper: #f4f6f8;
  --surface: #ffffff;
  --line: #d7dee6;
  --line-strong: #c3ced8;
  --ok: #1f6b4a;
  --ok-soft: #e7f4ee;
  --danger: #b42318;
  --danger-soft: #fdecec;
  --shadow: 0 1px 2px rgba(28, 36, 48, .06), 0 8px 24px rgba(28, 36, 48, .04);
}

* { box-sizing: border-box; }
html, body { margin: 0; min-height: 100%; }
body.app-body {
  font-family: "Source Sans 3", "Segoe UI", sans-serif;
  background: var(--paper);
  color: var(--ink);
}
html.app-locked, body.app-locked {
  height: 100%;
  overflow: hidden;
}

.wrap { width: min(1180px, calc(100% - 32px)); margin: 0 auto; }
.nav {
  display: flex; align-items: center; justify-content: space-between;
  gap: 12px; padding: 18px 0;
  border-bottom: 3px solid var(--navy);
}
.brand { display: flex; gap: 12px; align-items: center; color: inherit; text-decoration: none; }
.brand-text b {
  display: block; font-size: 16px; letter-spacing: .02em;
  color: var(--navy); font-weight: 700;
}
.brand-text small {
  color: var(--muted); font-size: 12px;
}
.nav-links { display: flex; gap: 8px; align-items: center; flex-shrink: 0; }

.btn, .ghost, .btn-google, .danger {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  border: 1px solid transparent; border-radius: 4px; padding: 9px 14px; cursor: pointer;
  text-decoration: none; font-weight: 600; font-size: 14px;
  background: var(--navy); color: #fff;
}
.btn:hover { background: var(--navy-2); }
.btn-login { padding: 6px 12px; font-size: 13px; }
.btn-sm { padding: 6px 10px; font-size: 13px; }
.ghost {
  background: var(--surface); color: var(--navy);
  border-color: var(--line-strong);
}
.ghost:hover { background: var(--blue-soft); }
.danger {
  background: var(--surface); color: var(--danger);
  border-color: #e8b4b0;
}
.danger:hover { background: var(--danger-soft); }

.hero {
  padding: 28px 0 8px;
  border-bottom: 1px solid var(--line);
  margin-bottom: 8px;
}
.eyebrow {
  display: inline-flex; gap: 8px; align-items: center;
  color: var(--blue); letter-spacing: .12em; text-transform: uppercase;
  font-size: 11px; font-weight: 700;
}
.live {
  width: 8px; height: 8px; border-radius: 50%; background: var(--ok);
}
.hero h1 {
  font-family: "Source Serif 4", "Georgia", serif;
  font-size: clamp(28px, 4vw, 40px);
  line-height: 1.15; margin: 8px 0 0; color: var(--navy);
  font-weight: 600;
}

.kpis { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 12px; margin: 20px 0; }
.summary-kpis { grid-template-columns: repeat(auto-fill, minmax(180px, 1fr)); }
.kpi {
  background: var(--surface); border: 1px solid var(--line);
  border-left: 4px solid var(--navy); border-radius: 4px;
  padding: 14px 16px; min-width: 0; box-shadow: var(--shadow);
}
.kpi span {
  color: var(--muted); font-size: 12px; letter-spacing: .06em;
  text-transform: uppercase; font-weight: 700;
}
.kpi strong {
  display: block; font-family: "Source Serif 4", Georgia, serif;
  font-size: clamp(22px, 3vw, 32px); margin: 8px 0 6px; color: var(--navy);
  word-break: break-word; font-weight: 600;
}
.kpi em { font-style: normal; color: var(--ok); font-size: 13px; font-weight: 700; }
.ring {
  height: 4px; border-radius: 99px; background: #e6edf3; overflow: hidden; margin-top: 10px;
}
.ring b { display: block; height: 100%; width: var(--p); background: var(--navy); }

.grid { display: grid; grid-template-columns: minmax(0, 1.4fr) minmax(0, .8fr); gap: 12px; margin-bottom: 12px; }
.card {
  background: var(--surface); border: 1px solid var(--line); border-radius: 4px;
  padding: 16px; min-width: 0; box-shadow: var(--shadow);
}
.card h2 {
  margin: 0 0 12px; font-size: 16px; color: var(--navy);
  font-weight: 700; border-bottom: 1px solid var(--line); padding-bottom: 8px;
}
.chart-box { position: relative; height: 260px; width: 100%; }
.footer {
  padding: 24px 0 28px; color: var(--muted); font-size: 13px;
  display: flex; justify-content: space-between; gap: 12px; flex-wrap: wrap;
  border-top: 1px solid var(--line); margin-top: 12px;
}

.auth-shell {
  min-height: 100vh; display: grid; place-items: center; padding: 24px;
  background: var(--paper);
}
.auth-card {
  width: min(420px, 100%); background: var(--surface); border: 1px solid var(--line);
  border-top: 4px solid var(--navy); border-radius: 4px; padding: 32px 28px;
  text-align: center; box-shadow: var(--shadow);
}
.auth-card h1 {
  font-family: "Source Serif 4", Georgia, serif;
  margin: 12px 0 8px; color: var(--navy); font-size: 28px; font-weight: 600;
}
.btn-google {
  width: 100%; margin-top: 18px; background: var(--surface); color: var(--ink);
  border-color: var(--line-strong);
}
.btn-google:hover { background: var(--blue-soft); }
.btn-google svg { width: 18px; height: 18px; }
.err { color: var(--danger); font-size: 14px; margin-top: 12px; }

.app-frame {
  position: relative; z-index: 1;
  display: grid; grid-template-columns: 240px minmax(0, 1fr);
  height: 100%; background: var(--paper);
}
.side {
  display: flex; flex-direction: column;
  position: sticky; top: 0; height: 100vh;
  padding: 20px 14px;
  border-right: 1px solid var(--line);
  background: var(--surface);
  overflow: auto;
}
.side .brand { padding: 4px 8px 16px; border-bottom: 3px solid var(--navy); margin-bottom: 12px; }
.side-nav { flex: 1; }
.side a {
  display: flex; gap: 10px; align-items: center; color: var(--ink);
  text-decoration: none; padding: 9px 12px; border-radius: 4px; margin-top: 2px;
}
.side a.active, .side a:hover { background: var(--blue-soft); color: var(--navy); }
.side a.active { background: var(--navy); color: #fff; }
.side-foot { margin-top: auto; padding-top: 16px; }
.side-foot .ghost { width: 100%; }
.main {
  min-width: 0; height: 100vh; overflow: auto;
  padding: 22px 24px 40px;
}
.page-title {
  font-family: "Source Serif 4", Georgia, serif;
  font-size: clamp(22px, 3vw, 30px); margin: 4px 0 0; color: var(--navy); font-weight: 600;
}
.topbar {
  display: flex; justify-content: space-between; align-items: center;
  margin-bottom: 18px; gap: 12px; padding-bottom: 14px;
  border-bottom: 1px solid var(--line);
}
.userchip { display: flex; align-items: center; gap: 10px; min-width: 0; }
.userchip small { color: var(--muted); }
.userchip img, .avatar {
  width: 36px; height: 36px; border-radius: 50%; object-fit: cover;
  background: var(--blue-soft); color: var(--navy);
  display: grid; place-items: center; font-size: 12px; font-weight: 700;
  border: 1px solid var(--line);
}
.flash {
  background: var(--ok-soft); border: 1px solid #b7d7c8; color: var(--ok);
  padding: 10px 14px; border-radius: 4px; margin-bottom: 14px;
}
.flash-error { background: var(--danger-soft); border-color: #e8b4b0; color: var(--danger); }
.toolbar { display: flex; justify-content: flex-start; gap: 8px; flex-wrap: wrap; margin-bottom: 14px; }
.kpi-link { text-decoration: none; color: inherit; }
.kpi-link:hover { border-color: var(--navy); }
.card-head { display: flex; justify-content: space-between; align-items: center; gap: 8px; margin-bottom: 8px; }
.card-head h2 { margin: 0; border: 0; padding: 0; }
.metric-head { color: var(--muted); font-size: 12px; }
.metric-head li { border-bottom: 1px solid var(--line); font-weight: 700; }
.row-switch {
  display: grid; grid-template-columns: auto 1fr auto; gap: 8px; align-items: center;
  background: var(--surface); border: 1px solid var(--line); border-radius: 4px;
  padding: 10px 12px; margin-bottom: 14px;
}
.row-switch-label { text-align: center; }
.row-switch-label span { display: block; color: var(--muted); font-size: 12px; }
.row-switch-label strong { color: var(--navy); }
.detail-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); gap: 10px; }
.detail-set { border: 1px solid var(--line); border-radius: 4px; padding: 10px; background: #f7fafc; }
.detail-set h3 { margin: 0 0 8px; font-size: 14px; color: var(--navy); }
.hero-lead, .monitor-lead { color: var(--muted); max-width: 72ch; margin: 10px 0 0; font-size: 15px; line-height: 1.5; }
.monitor-lead { margin: 0 0 16px; }
.card-link { display: block; color: inherit; text-decoration: none; }
.card-link:hover { border-color: var(--navy); }
.member-metrics { display: flex; flex-wrap: wrap; gap: 6px; list-style: none; margin: 6px 0 0; padding: 0; }
.member-metrics li { font-size: 12px; color: var(--muted); background: #f7fafc; border: 1px solid var(--line); border-radius: 4px; padding: 2px 6px; }
.metric-stack li { grid-template-columns: 1fr auto; }
.row-switch-label label { display: grid; gap: 4px; }
.row-switch-label select { min-width: min(100%, 280px); }
#confirm-modal { z-index: 50; }
.ghost[aria-disabled="true"] { opacity: .45; pointer-events: none; }

.table-wrap {
  overflow: auto; border-radius: 4px; border: 1px solid var(--line);
  max-width: 100%; background: var(--surface); box-shadow: var(--shadow);
}
.report-wrap { background: var(--surface); }
table { width: 100%; border-collapse: collapse; font-size: 13px; }
th, td { padding: 9px 11px; border-bottom: 1px solid var(--line); text-align: left; white-space: nowrap; }
th { color: var(--navy); font-weight: 700; background: #eef3f8; }
.accounts-table tbody tr:hover { background: #f7fafc; }
.report-table { min-width: 980px; }
.report-table thead tr:first-child th {
  text-align: center; color: #fff; background: var(--navy);
  border-bottom: 1px solid var(--navy-2);
}
.report-table thead tr:nth-child(2) th {
  text-align: center; font-size: 11px; background: #dbe6f0; color: var(--navy);
}
.report-table td { text-align: center; }
.report-table tbody tr:nth-child(even) td { background: #f7fafc; }
.report-table .sticky-col:nth-child(1),
.report-table .sticky-0 { text-align: left; }
.sticky-col, .sticky-head { position: sticky; z-index: 2; }
.sticky-0, .sticky-head:nth-child(1) { left: 0; min-width: 70px; }
.sticky-1, .sticky-head:nth-child(2) { left: 70px; min-width: 128px; }
.report-table thead .sticky-head:nth-child(1),
.report-table thead .sticky-0 { background: var(--navy); color: #fff; }
.report-table thead tr:nth-child(2) .sticky-0,
.report-table thead tr:nth-child(2) .sticky-1 { background: #dbe6f0; }
.report-table tbody .sticky-col { background: var(--surface); }
.report-table tbody tr:nth-child(even) .sticky-col { background: #f7fafc; }
.kind-editor tbody td:nth-child(n+3):nth-child(-n+6) { background: #f3f7fb; }
.kind-editor tbody td:nth-child(n+7):nth-child(-n+10) { background: #eef6f2; }
.kind-editor tbody td:nth-child(n+11):nth-child(-n+14) { background: #f6f3f8; }
.kind-sosmed tbody td:nth-child(n+3):nth-child(-n+5) { background: #f3f7fb; }
.kind-sosmed tbody td:nth-child(n+6):nth-child(-n+8) { background: #eef6f2; }
.is-total td { font-weight: 700; color: var(--navy); background: #e8eef5 !important; }
.col-action { position: sticky; right: 0; background: var(--surface); z-index: 2; }

input, select {
  background: var(--surface); border: 1px solid var(--line-strong); color: var(--ink);
  border-radius: 4px; padding: 8px 10px; font: inherit; width: 100%;
}
input:focus, select:focus {
  outline: 2px solid var(--blue-soft); border-color: var(--blue);
}
input[readonly] { background: #f0f3f6; color: var(--muted); }
.row-actions { display: flex; gap: 8px; justify-content: flex-end; }
.accounts-table td:last-child { text-align: right; }

.modal-backdrop {
  position: fixed; inset: 0; z-index: 40;
  display: grid; place-items: center;
  background: rgba(28, 36, 48, .35);
  padding: 16px;
}
.modal-backdrop[hidden] { display: none; }
.modal {
  width: min(820px, 100%);
  max-height: min(88vh, 920px);
  overflow: auto;
  background: var(--surface);
  border: 1px solid var(--line);
  border-top: 4px solid var(--navy);
  border-radius: 4px;
  padding: 20px;
  box-shadow: var(--shadow);
}
.modal-sm { width: min(420px, 100%); }
.modal-head { display: flex; justify-content: space-between; align-items: center; gap: 12px; margin-bottom: 14px; }
.modal-head h2 { margin: 0; font-size: 20px; color: var(--navy); font-family: "Source Serif 4", Georgia, serif; }
.modal-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 12px; }
.modal-set {
  margin: 0; border: 1px solid var(--line); border-radius: 4px; padding: 12px;
  background: #f8fafc;
}
.modal-set legend { padding: 0 6px; color: var(--navy); font-weight: 700; }
.modal-set label, .modal label {
  display: grid; gap: 6px; margin: 8px 0; font-size: 12px; color: var(--muted); font-weight: 600;
}
.modal-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 16px; }
.modal-email { margin: 0 0 10px; color: var(--ink); }

.day-banner {
  display: flex; justify-content: space-between; gap: 16px; align-items: center;
  background: var(--surface); border: 1px solid var(--line); border-left: 4px solid var(--navy);
  border-radius: 4px; padding: 16px 18px; margin: 0 0 16px; box-shadow: var(--shadow);
}
.day-banner h2 { margin: 4px 0; color: var(--navy); font-family: "Source Serif 4", Georgia, serif; font-size: 26px; }
.day-banner p { margin: 0; color: var(--muted); }
.day-progress { min-width: 140px; text-align: right; }
.day-progress strong { display: block; font-size: 28px; color: var(--navy); }
.day-progress span { color: var(--muted); font-size: 12px; }
.target-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; margin-bottom: 12px; }
.compare { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 10px; margin-bottom: 12px; }
.compare div { background: #f7fafc; border: 1px solid var(--line); border-radius: 4px; padding: 10px; }
.compare span, .compare small { display: block; color: var(--muted); font-size: 12px; }
.compare strong { display: block; font-size: 24px; color: var(--navy); margin: 4px 0; }
.metric-list { list-style: none; margin: 0; padding: 0; }
.metric-list li {
  display: grid; grid-template-columns: 1.1fr 1fr 1fr auto; gap: 8px;
  padding: 8px 0; border-bottom: 1px solid var(--line); font-size: 13px;
}
.metric-list li:last-child { border-bottom: 0; }
.hint { color: var(--muted); margin: 0 0 12px; font-size: 14px; }
.member-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(180px, 1fr)); gap: 10px; }
.member-card {
  display: grid; gap: 4px; text-align: left; cursor: pointer;
  background: var(--surface); border: 1px solid var(--line); border-radius: 4px;
  padding: 12px; color: inherit; font: inherit; text-decoration: none;
}
.member-card:hover { border-color: var(--navy); background: var(--blue-soft); }
.member-static { cursor: default; }
.member-static:hover { border-color: var(--line); background: var(--surface); }
.member-role { color: var(--blue); font-size: 11px; letter-spacing: .08em; text-transform: uppercase; font-weight: 700; }
.member-card strong { font-size: 18px; color: var(--navy); }
.member-card em { font-style: normal; color: var(--muted); font-size: 13px; }
.member-card small { color: var(--ok); font-weight: 700; }

@media (max-width: 980px) {
  .wrap { width: min(1180px, calc(100% - 20px)); }
  .kpis { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .grid, .target-grid, .compare { grid-template-columns: minmax(0, 1fr); }
  .chart-box { height: 220px; }
  .day-banner { flex-direction: column; align-items: flex-start; }
  .day-progress { text-align: left; width: 100%; min-width: 0; }
  .metric-list li { grid-template-columns: 1fr 1fr; gap: 4px 8px; }
  .metric-list li b { grid-column: 1 / -1; }
  .card-head { flex-wrap: wrap; align-items: flex-start; }
  .row-switch { grid-template-columns: 1fr; }
  .row-switch-label { text-align: left; }
  html.app-locked, body.app-locked { height: auto; overflow: auto; }
  .app-frame { grid-template-columns: minmax(0, 1fr); height: auto; }
  .side {
    position: sticky; top: 0; z-index: 12; height: auto;
    flex-direction: row; flex-wrap: wrap; align-items: center; gap: 6px;
    border-right: 0; border-bottom: 1px solid var(--line);
    padding: 10px 12px;
  }
  .side .brand { border-bottom: 0; margin-bottom: 0; padding: 0 8px 0 0; }
  .side-nav { display: flex; flex-wrap: wrap; gap: 4px; flex: 1; }
  .side a { margin-top: 0; padding: 8px 10px; font-size: 13px; }
  .side-foot { margin-top: 0; padding-top: 0; width: auto; }
  .side-foot .ghost { width: auto; padding: 8px 12px; }
  .main { height: auto; overflow: visible; padding: 16px 14px 32px; }
  .userchip div { display: none; }
  .modal { padding: 16px; }
}
@media (max-width: 640px) {
  .wrap { width: calc(100% - 16px); }
  .nav { flex-wrap: wrap; align-items: flex-start; padding: 12px 0; gap: 10px; }
  .nav-links { width: 100%; justify-content: flex-end; }
  .kpis, .member-grid, .detail-grid, .modal-grid { grid-template-columns: minmax(0, 1fr); }
  .kpi, .card, .day-banner { padding: 12px; }
  .kpi strong, .day-banner h2 { font-size: 22px; }
  .hero { padding: 16px 0 8px; }
  .hero h1 { font-size: 26px; }
  .hero-lead, .monitor-lead { font-size: 14px; }
  .toolbar { position: sticky; top: 0; z-index: 8; background: var(--paper); padding: 8px 0; }
  .compare div { padding: 8px; }
  .footer { flex-direction: column; gap: 6px; }
}
