/* ============================================================================
   App shell — sidebar layout shared by the user center (/account.html) and the
   admin console (/admin.html). Sits on top of landing.css (tokens + buttons).
   Green-grid brand system; light mode. Mirrors mature SaaS dashboards
   (sidebar + content, current user pinned bottom-left).
   ============================================================================ */

.app-body {
  margin: 0;
  min-height: 100vh;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--font);
}

.shell {
  display: grid;
  grid-template-columns: 248px minmax(0, 1fr);
  min-height: 100vh;
}

/* ── Sidebar ─────────────────────────────────────────────────────────────── */
.shell__side {
  display: flex;
  flex-direction: column;
  gap: 6px;
  border-right: 1px solid var(--line);
  background: #fff;
  padding: 16px 14px;
  position: sticky;
  top: 0;
  height: 100vh;
}

.shell__brand {
  display: flex;
  align-items: center;
  gap: 9px;
  font-weight: 800;
  font-size: 16px;
  padding: 6px 8px 14px;
  color: var(--ink);
}
.shell__brand .mk {
  width: 26px; height: 26px;
  border-radius: 7px;
  background: var(--green);
  color: #fff;
  display: grid; place-items: center;
  font-size: 12px; font-weight: 800;
}

.nav-group { margin-top: 10px; }
.nav-group__label {
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--faint);
  padding: 4px 8px;
}

.nav-item {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  border: 0;
  background: transparent;
  border-radius: 9px;
  padding: 9px 10px;
  font: inherit;
  font-size: 14px;
  color: var(--muted);
  cursor: pointer;
  text-align: left;
}
.nav-item[hidden] { display: none; }
.nav-item:hover { background: var(--green-soft); color: var(--green-strong); }
.nav-item.is-active { background: var(--green-soft); color: var(--green-strong); font-weight: 700; }
.nav-item .ic { width: 18px; height: 18px; flex-shrink: 0; opacity: 0.85; }

.shell__user {
  margin-top: auto;
  display: flex;
  align-items: center;
  gap: 10px;
  border-top: 1px solid var(--line);
  padding: 12px 8px 4px;
}
.shell__user .avatar {
  width: 32px; height: 32px;
  border-radius: 50%;
  background: var(--green);
  color: #fff;
  display: grid; place-items: center;
  font-weight: 700; font-size: 13px;
  flex-shrink: 0;
}
.shell__user .who { min-width: 0; }
.shell__user .who strong { display: block; font-size: 13px; color: var(--ink); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.shell__user .who span { display: block; font-size: 11px; color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* ── Main content ────────────────────────────────────────────────────────── */
.shell__main { min-width: 0; display: flex; flex-direction: column; }

.topbar {
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 16px 28px;
  border-bottom: 1px solid var(--line);
  background: rgba(247, 249, 247, 0.9);
  backdrop-filter: blur(8px);
  position: sticky; top: 0; z-index: 10;
}
.topbar h1 { font-size: 20px; letter-spacing: -0.3px; }
.topbar .spacer { flex: 1; }
.topbar a.topbar-link { color: var(--muted); font-size: 14px; font-weight: 600; }
.topbar a.topbar-link:hover { color: var(--green); }

.content { padding: 28px; max-width: 1080px; width: 100%; }
.view[hidden] { display: none; }
.view__head { margin-bottom: 20px; }
.view__head h2 { font-size: 22px; letter-spacing: -0.3px; margin-bottom: 4px; }
.view__head p { color: var(--muted); font-size: 14px; }

/* ── Cards / grid ────────────────────────────────────────────────────────── */
.cards { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 16px; }
.cards--one { grid-template-columns: 1fr; }
.cards--stat { grid-template-columns: repeat(4, minmax(0, 1fr)); }

.card {
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 20px 22px;
}
.card h3 { font-size: 15px; margin-bottom: 14px; }
.card--pad-lg { padding: 24px; }

.kv { display: grid; gap: 12px; }
.kv__row { display: grid; grid-template-columns: 130px 1fr; gap: 12px; align-items: baseline; }
.kv__row dt { color: var(--muted); font-size: 13px; }
.kv__row dd { font-size: 14px; color: var(--ink); overflow-wrap: anywhere; }

.stat { background: #fff; border: 1px solid var(--line); border-radius: 14px; padding: 18px 20px; }
.stat .label { color: var(--muted); font-size: 13px; font-weight: 600; }
.stat .value { display: block; margin-top: 6px; font-size: 30px; line-height: 1; font-weight: 800; color: var(--green-strong); }
.stat .sub { display: block; margin-top: 6px; font-size: 12px; color: var(--faint); }

.big-number { font-size: 34px; font-weight: 800; color: var(--ink); line-height: 1; }
.muted { color: var(--muted); }
.pill {
  display: inline-flex; align-items: center; gap: 6px;
  border-radius: 999px; padding: 3px 10px;
  font-size: 12px; font-weight: 700;
}
.pill--green { background: var(--green-soft); color: var(--green-strong); }
.pill--amber { background: rgba(200, 137, 31, 0.12); color: #8a5a10; }
.pill--red { background: rgba(192, 57, 43, 0.10); color: var(--red); }
.pill--gray { background: #eef1ee; color: var(--muted); }

/* "coming soon" skeleton overlay for not-yet-wired B-phase cards */
.card--soon { position: relative; }
.card--soon .soon-tag {
  position: absolute; top: 14px; right: 16px;
  font-size: 11px; font-weight: 700;
  background: rgba(200, 137, 31, 0.12); color: #8a5a10;
  border-radius: 999px; padding: 3px 9px;
}
.card--soon .soon-body { opacity: 0.55; pointer-events: none; }

/* ── Tables ──────────────────────────────────────────────────────────────── */
.table-wrap { overflow-x: auto; border: 1px solid var(--line); border-radius: 12px; }
table.data { width: 100%; border-collapse: collapse; min-width: 560px; }
table.data th, table.data td { text-align: left; padding: 11px 14px; font-size: 13px; border-bottom: 1px solid var(--line); }
table.data th { background: #f7f9f7; color: var(--muted); font-weight: 700; white-space: nowrap; }
table.data tr:last-child td { border-bottom: 0; }
table.data td.num { text-align: right; font-variant-numeric: tabular-nums; }
.table-empty { padding: 22px; text-align: center; color: var(--faint); font-size: 13px; }

/* ── Forms inside cards ──────────────────────────────────────────────────── */
.form-row { display: grid; gap: 7px; margin-bottom: 14px; }
.form-row > span { font-size: 13px; font-weight: 700; color: var(--ink); }
.form-row input, .form-row select {
  width: 100%; min-height: 42px;
  border: 1px solid rgba(27, 42, 34, 0.16);
  border-radius: 10px; background: #fff;
  padding: 9px 12px; font: inherit; outline: none;
}
.form-row input:focus, .form-row select:focus {
  border-color: rgba(58, 107, 82, 0.5);
  box-shadow: 0 0 0 3px rgba(58, 107, 82, 0.14);
}
.toggle-row { display: grid; grid-template-columns: auto 1fr; gap: 12px; align-items: start; cursor: pointer; }
.toggle-row input { width: 18px; height: 18px; margin-top: 2px; accent-color: var(--green); }
.toggle-row strong { display: block; font-size: 14px; }
.toggle-row em { display: block; font-size: 12px; color: var(--muted); font-style: normal; }

/* ── Notice / feedback ───────────────────────────────────────────────────── */
.notice {
  border-radius: 10px; padding: 11px 13px; font-size: 14px;
  background: var(--green-soft); color: var(--green-strong);
}
.notice[data-tone="error"] { background: rgba(192, 57, 43, 0.10); color: var(--red); }
.notice[data-tone="success"] { background: rgba(58, 107, 82, 0.12); color: var(--green); }
.notice[hidden] { display: none; }

.mini-btn {
  min-height: 30px; border: 1px solid rgba(27, 42, 34, 0.16);
  border-radius: 7px; background: #fff; color: var(--ink);
  font: inherit; font-size: 12px; font-weight: 600; padding: 4px 10px; cursor: pointer;
}
.mini-btn:hover { border-color: var(--green); color: var(--green); }
.mini-btn--danger:hover { border-color: var(--red); color: var(--red); }
.mini-btn:disabled { opacity: 0.5; cursor: not-allowed; }
.row-actions { display: flex; flex-wrap: wrap; gap: 6px; }

/* ── Loading skeletons ───────────────────────────────────────────────────── */
.skel { background: linear-gradient(90deg, #eef1ee 25%, #f6f8f6 37%, #eef1ee 63%); background-size: 400% 100%; animation: skel 1.4s ease infinite; border-radius: 6px; height: 14px; }
@keyframes skel { 0% { background-position: 100% 0; } 100% { background-position: 0 0; } }

/* ── Responsive ──────────────────────────────────────────────────────────── */
@media (max-width: 900px) {
  .shell { grid-template-columns: 1fr; }
  .shell__side {
    position: static; height: auto; flex-direction: row; flex-wrap: wrap;
    align-items: center; gap: 4px; overflow-x: auto;
  }
  .shell__brand { padding: 6px 8px; }
  .nav-group { margin-top: 0; display: flex; align-items: center; gap: 4px; }
  .nav-group__label { display: none; }
  .shell__user { margin-top: 0; border-top: 0; border-left: 1px solid var(--line); }
  .cards, .cards--stat { grid-template-columns: 1fr; }
  .content { padding: 18px; }
}
@media (max-width: 560px) {
  .cards--stat { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .kv__row { grid-template-columns: 1fr; gap: 2px; }
}

/* ── Model config (v3): CC Switch-style provider cards + edit modal ────────── */
.mp-cardlist { display: flex; flex-direction: column; gap: 10px; }
.mp-card {
  background: var(--card); border: 1px solid var(--line); border-radius: var(--radius-sm);
  padding: 13px 15px; display: flex; align-items: center; gap: 12px;
}
.mp-card.is-off { opacity: 0.66; }
.mp-avatar {
  width: 38px; height: 38px; border-radius: 9px; flex: none; display: grid; place-items: center;
  color: #fff; font-weight: 800; font-size: 12px;
}
.mp-meta { min-width: 0; flex: 1; }
.mp-meta__name { font-weight: 700; display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.mp-meta__url { color: var(--accent); font-size: 12px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.mp-meta__conn { font-size: 11px; margin-top: 3px; display: inline-flex; align-items: center; gap: 5px; color: var(--muted); }
.mp-meta__conn .cdot { width: 7px; height: 7px; border-radius: 50%; background: var(--faint); }
.mp-meta__conn.ok { color: #1a7a54; } .mp-meta__conn.ok .cdot { background: #22a06b; }
.mp-meta__conn.err { color: var(--red); } .mp-meta__conn.err .cdot { background: var(--red); }
.mp-meta__conn.testing { color: var(--amber); } .mp-meta__conn.testing .cdot { background: var(--amber); }
.mp-tag {
  font-size: 11px; padding: 2px 8px; border-radius: 999px; border: 1px solid var(--line);
  color: var(--muted); background: var(--surface-muted); font-weight: 600;
}
.mp-tag--oauth { color: #6d28d9; background: #f5f0ff; border-color: #e6dbff; }
.mp-tag--managed { color: var(--green-strong); background: var(--green-soft); border-color: var(--green); }
.mp-tag--gw { color: var(--accent); background: #eef2ff; border-color: #dbe4ff; }
.mp-actions { display: flex; align-items: center; gap: 4px; flex: none; }
.mp-switch { display: inline-flex; align-items: center; cursor: pointer; margin-right: 4px; }
.mp-switch input { display: none; }
.mp-switch .track {
  width: 38px; height: 21px; border-radius: 999px; background: #cbd5e1; position: relative; transition: background .15s;
}
.mp-switch .track::after {
  content: ""; position: absolute; top: 2px; left: 2px; width: 17px; height: 17px; border-radius: 50%;
  background: #fff; transition: left .15s; box-shadow: 0 1px 2px rgba(0,0,0,.2);
}
.mp-switch input:checked + .track { background: var(--green); }
.mp-switch input:checked + .track::after { left: 19px; }
.mp-iconbtn {
  width: 32px; height: 32px; border-radius: 8px; border: 1px solid transparent; background: transparent;
  cursor: pointer; display: grid; place-items: center; color: var(--faint); font-size: 15px;
}
.mp-iconbtn:hover { background: var(--surface-muted); color: var(--text); }
.mp-iconbtn:disabled { opacity: .35; cursor: not-allowed; }

.mp-overlay {
  position: fixed; inset: 0; background: rgba(15,23,42,.45); z-index: 40;
  display: flex; align-items: flex-start; justify-content: center; padding: 40px 16px; overflow: auto;
}
.mp-overlay[hidden] { display: none; }
.mp-modal { background: #fff; border-radius: var(--radius); width: 100%; max-width: 620px; box-shadow: var(--shadow); }
.mp-modal__head { display: flex; align-items: center; justify-content: space-between; padding: 16px 20px; border-bottom: 1px solid var(--line); }
.mp-modal__head h3 { margin: 0; font-size: 16px; }
.mp-modal__body { padding: 18px 20px; max-height: 68vh; overflow: auto; }
.mp-modal__foot { padding: 14px 20px; border-top: 1px solid var(--line); display: flex; justify-content: flex-end; gap: 10px; }
.mp-field { margin-bottom: 14px; }
.mp-field label { display: block; font-size: 12px; color: var(--muted); margin-bottom: 5px; }
.mp-field input, .mp-field select {
  width: 100%; padding: 9px 11px; border: 1px solid var(--line); border-radius: var(--radius-sm); font-size: 13px; font-family: var(--font);
}
.mp-oauthnote { background: #f5f0ff; border: 1px solid #e6dbff; color: #5b21b6; border-radius: var(--radius-sm); padding: 12px 14px; font-size: 13px; }
.mp-mlist { border: 1px solid var(--line); border-radius: var(--radius-sm); overflow: hidden; margin-top: 4px; }
.mp-mline { display: flex; align-items: center; gap: 8px; padding: 9px 12px; border-top: 1px solid var(--line); flex-wrap: wrap; }
.mp-mline:first-child { border-top: none; }
.mp-mline__id { font-weight: 600; font-size: 13px; }
.mp-mline__meta { font-size: 11px; color: var(--muted); }
.mp-mline__capacity { display: flex; flex: 1 1 100%; gap: 12px; order: 2; }
.mp-mline__capacity label { flex: 1; min-width: 0; font-size: 11px; color: var(--muted); }
.mp-mline__capacity input { display: block; width: 100%; min-width: 0; box-sizing: border-box; margin-top: 4px; }
.mp-capacity-help { font-size: 12px; line-height: 1.6; }
.mp-mline__sp { flex: 1; }
.mp-model-actions { display: flex; border-top: 1px solid var(--line); }
.mp-discovermodels, .mp-addmodel { min-height: 38px; border: 0; background: transparent; color: var(--green-strong); font-weight: 600; cursor: pointer; font: inherit; font-size: 13px; text-align: left; }
.mp-discovermodels { flex: 1; padding: 9px 12px; border-right: 1px solid var(--line); }
.mp-discovermodels:hover, .mp-addmodel:hover { background: var(--surface-muted); }
.mp-discovermodels:disabled { color: var(--muted); cursor: wait; }
.mp-addmodel { flex: 1; padding: 9px 12px; }
.mp-pill { font-size: 11px; padding: 2px 8px; border-radius: 999px; background: var(--surface-muted); color: var(--muted); cursor: pointer; border: 1px solid var(--line); }
.mp-pill.is-pro { background: #fff4e5; color: var(--amber); border-color: #eddcb6; }
