/* Admin panel — reuses the tokens defined in styles.css.
   Admins are grown-ups, so this stays on the pine-green accent. */

.admin-topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 14px 22px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}
.admin-topbar .wordmark { font-size: 20px; }
.admin-topbar .crumb {
  font-family: var(--font-ui); font-weight: 700; color: var(--muted);
  font-size: 14px; margin-left: 6px;
}
.topbar-right { display: flex; align-items: center; gap: 16px; }
.topbar-right a, .topbar-right button {
  font-family: var(--font-ui); font-weight: 700; font-size: 14px;
  color: var(--muted); text-decoration: none;
  border: none; background: none; cursor: pointer;
}
.topbar-right a:hover { color: var(--accent-ink); }
.topbar-right button:hover { color: var(--danger); }

.admin-main {
  max-width: 960px; margin: 0 auto; padding: 28px 22px 60px;
}

.panel {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 22px;
  margin-bottom: 26px;
}
.panel h2 {
  font-family: var(--font-ui); font-weight: 800; font-size: 17px;
  margin: 0 0 16px;
}

/* Add-user form */
.form-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 14px 18px;
  align-items: start;   /* `end` made short fields sink to the tall Models box */
}
/* A field that needs the whole row (the model picker). */
.form-grid .field-wide { grid-column: 1 / -1; }
/* Keep the create button aligned with the inputs, not the labels. */
.form-grid .field > .btn-primary.inline { margin-top: 22px; }
.form-grid .field { margin: 0; }
.form-grid label {
  display: block; font-family: var(--font-ui); font-weight: 700;
  font-size: 13px; margin-bottom: 6px;
}
.form-grid input[type="text"],
.form-grid input[type="password"],
.form-grid select {
  width: 100%; padding: 9px 11px;
  border: 1px solid var(--border); border-radius: var(--radius-sm);
  font-size: 14px; font-family: var(--font-body); color: var(--ink);
  background: var(--surface);
}
.form-grid input:focus, .form-grid select:focus,
.provider-box:focus-within {
  outline: none; border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}

.provider-box {
  border: 1px solid var(--border); border-radius: var(--radius-sm);
  padding: 10px 12px; display: flex; gap: 28px; flex-wrap: wrap;
  align-items: flex-start;
}
.check {
  display: inline-flex; align-items: center; gap: 6px;
  font-size: 14px; font-family: var(--font-ui); font-weight: 600;
  cursor: pointer; user-select: none;
}
.check input { accent-color: var(--accent); width: 16px; height: 16px; }
.check .hint { color: var(--warm); font-size: 12px; font-weight: 700; }

.btn-primary.inline { width: auto; padding: 10px 20px; }
.form-msg { margin-top: 12px; font-size: 14px; font-weight: 600; min-height: 20px; }
.form-msg.ok { color: var(--accent-ink); }
.form-msg.err { color: var(--danger); }

/* Users table */
.table-wrap { overflow-x: auto; }
table.users { width: 100%; border-collapse: collapse; font-size: 14px; }
table.users th {
  text-align: left; font-family: var(--font-ui); font-weight: 800;
  font-size: 12px; text-transform: uppercase; letter-spacing: 0.03em;
  color: var(--muted); padding: 0 10px 10px; white-space: nowrap;
}
table.users td {
  padding: 12px 10px; border-top: 1px solid var(--border); vertical-align: middle;
}
table.users tr.inactive { opacity: 0.55; }
.uname { font-family: var(--font-ui); font-weight: 800; }
.uname .you {
  font-size: 11px; font-weight: 800; color: var(--accent-ink);
  background: var(--accent-soft); border-radius: 999px;
  padding: 1px 7px; margin-left: 6px;
}
table.users select {
  padding: 6px 8px; border: 1px solid var(--border);
  border-radius: var(--radius-sm); font-family: var(--font-body);
  font-size: 13px; background: var(--surface); color: var(--ink);
}
.row-providers { display: flex; gap: 10px; }
.row-providers .check { font-size: 13px; }

.switch { display: inline-grid; place-items: center; }
.switch input { width: 18px; height: 18px; accent-color: var(--accent); cursor: pointer; }
.switch input:disabled { cursor: not-allowed; opacity: 0.5; }

.row-actions { display: flex; gap: 6px; white-space: nowrap; }
.btn-sm {
  border: 1px solid var(--border); background: var(--surface);
  border-radius: var(--radius-sm); padding: 6px 10px;
  font-family: var(--font-ui); font-weight: 700; font-size: 13px; color: var(--ink);
  cursor: pointer;
}
.btn-sm:hover { border-color: var(--accent); color: var(--accent-ink); }
.btn-sm.save { background: var(--accent); color: #fff; border-color: var(--accent); }
.btn-sm.save:hover { background: var(--accent-ink); }
.btn-sm.danger:hover { border-color: var(--danger); color: var(--danger); }
.btn-sm:disabled { opacity: 0.4; cursor: not-allowed; }

.loading { color: var(--muted); padding: 20px 0; }

@media (max-width: 640px) {
  .admin-main { padding: 18px 14px 50px; }
}
@media (prefers-reduced-motion: reduce) {
  * { animation: none !important; transition: none !important; }
}

/* ---- Activity counts (in users table) ---- */
.counts { font-size: 12px; color: var(--muted); margin-top: 4px; }
.flag-badge {
  display: inline-block; margin-left: 6px;
  font-family: var(--font-ui); font-weight: 800; font-size: 11px;
  color: var(--danger); background: #f8e7e3;
  border-radius: 999px; padding: 1px 8px;
}

/* ---- Guardian activity page ---- */
.activity-layout {
  display: grid;
  grid-template-columns: 300px 1fr;
  gap: 22px;
  align-items: start;
}
.who-head { margin-bottom: 18px; }
.who-head .name { font-family: var(--font-ui); font-weight: 800; font-size: 20px; }
.who-head .role-badge { color: var(--accent-ink); }
.who-head.kid .role-badge { color: #6c5ce7; }

.convo-index { padding: 0; }
.convo-index .panel { padding: 10px; }
.convo-pick {
  display: block; width: 100%; text-align: left;
  border: none; background: transparent; cursor: pointer;
  padding: 11px 12px; border-radius: var(--radius-sm);
  font-family: var(--font-body); font-size: 14px; color: var(--ink);
}
.convo-pick:hover { background: var(--surface-2); }
.convo-pick.active { background: var(--accent-soft); color: var(--accent-ink); }
.convo-pick .title {
  font-weight: 700; display: block;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.convo-pick .meta { font-size: 12px; color: var(--muted); margin-top: 2px; }
.convo-pick .flag-badge { margin-left: 0; margin-top: 4px; }

.transcript { min-height: 200px; }
.transcript .msg { display: flex; margin-bottom: 16px; }
.transcript .msg.user { justify-content: flex-end; }
.transcript .bubble {
  padding: 10px 14px; border-radius: var(--radius);
  max-width: 78%; white-space: pre-wrap; word-wrap: break-word; font-size: 14px;
}
.transcript .msg.user .bubble { background: var(--accent-soft); border-bottom-right-radius: 4px; }
.transcript .msg.assistant .bubble {
  background: var(--surface); border: 1px solid var(--border); border-bottom-left-radius: 4px;
}
.transcript .msg.flagged .bubble {
  border: 1px solid var(--danger); background: #fdf3f1;
}
.transcript .who {
  font-family: var(--font-ui); font-weight: 800; font-size: 11px;
  color: var(--muted); margin-bottom: 3px;
}
.transcript .flag-note {
  font-size: 11px; font-weight: 700; color: var(--danger); margin-top: 5px;
}
.transcript .ts { font-size: 11px; color: var(--muted); font-weight: 600; }
.empty-transcript { color: var(--muted); padding: 40px 0; text-align: center; }

@media (max-width: 720px) {
  .activity-layout { grid-template-columns: 1fr; }
}

/* ---- Access-limit editor (expandable row) ---- */
.limits-row td { background: var(--surface-2); }
.limits-editor {
  display: flex; flex-wrap: wrap; align-items: flex-end; gap: 16px;
}
.lim-field { display: flex; flex-direction: column; gap: 5px; }
.lim-field label {
  font-family: var(--font-ui); font-weight: 700; font-size: 12px; color: var(--muted);
}
.lim-field input {
  width: 130px; padding: 8px 10px;
  border: 1px solid var(--border); border-radius: var(--radius-sm);
  font-family: var(--font-body); font-size: 14px; color: var(--ink);
  background: var(--surface);
}
.lim-field input:focus {
  outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft);
}
.lim-tz { font-size: 12px; color: var(--muted); font-weight: 700; }
.lim-hint { font-size: 12px; color: var(--muted); margin-top: 10px; }

/* Guardian search snippet under a conversation in the index */
.convo-pick .snippet { font-style: italic; opacity: .85; white-space: normal; }

/* Deleted-by-kid markers in the guardian view */
.convo-pick.deleted .title { text-decoration: line-through; opacity: .7; }
.pick-badges { display: inline-flex; gap: 6px; flex-wrap: wrap; margin-top: 2px; }
.del-badge {
  display: inline-block; font-size: 11px; font-weight: 800; padding: 2px 7px;
  border-radius: 999px; background: #efe7f8; color: #6C5CE7;
}
.deleted-note {
  margin-bottom: 12px; padding: 9px 12px; border-radius: 10px;
  background: #efe7f8; color: #4a3b8a; font-weight: 700; font-size: 14px;
}

/* ===== Usage dashboard (Phase 9) ===== */
.usage-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 16px; flex-wrap: wrap; }
.usage-head h1 { margin: 0; font-size: 24px; }
.range-tabs { display: inline-flex; gap: 4px; background: var(--surface); border: 1px solid var(--border); border-radius: 999px; padding: 3px; }
.range-tabs button {
  border: none; background: transparent; cursor: pointer; padding: 6px 14px;
  border-radius: 999px; font-family: var(--font-ui); font-weight: 700; font-size: 13px; color: var(--muted);
}
.range-tabs button.active { background: var(--accent); color: #fff; }

.stat-cards { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 12px; margin-bottom: 16px; }
.stat-card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 16px 18px; }
.stat-card.danger { border-color: #f0c0ba; background: #fdf3f1; }
.stat-value { font-size: 30px; font-weight: 800; color: var(--ink); line-height: 1.1; }
.stat-card.danger .stat-value { color: #c0392b; }
.stat-label { font-size: 13px; color: var(--muted); font-weight: 700; margin-top: 4px; }

.chart-panel { margin-bottom: 16px; }
.panel-title { font-weight: 800; font-size: 15px; margin-bottom: 10px; display: flex; align-items: center; gap: 8px; }
.panel-title .sub { font-weight: 600; font-size: 12px; color: var(--muted); }
.legend { margin-left: auto; font-weight: 600; font-size: 12px; color: var(--muted); display: inline-flex; align-items: center; gap: 6px; }
.legend .key { display: inline-block; width: 11px; height: 11px; border-radius: 3px; vertical-align: middle; }
.legend .key.msgs { background: var(--accent); }
.legend .key.flags { background: #c0392b; }
.chart svg { display: block; }

.usage-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
@media (max-width: 720px) { .usage-grid { grid-template-columns: 1fr; } }

.mix-row, .user-row { display: grid; grid-template-columns: 120px 1fr auto; align-items: center; gap: 10px; padding: 7px 0; }
.mix-label { font-weight: 700; font-size: 14px; }
.mix-track { background: var(--bg); border-radius: 999px; height: 12px; overflow: hidden; }
.mix-fill { height: 100%; background: var(--accent); border-radius: 999px; }
.mix-val { font-size: 13px; color: var(--muted); font-weight: 700; white-space: nowrap; }
.user-row { grid-template-columns: 1fr 90px auto; }
.user-name { font-weight: 700; font-size: 14px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.user-name .role { font-weight: 600; font-size: 11px; color: var(--muted); margin-left: 4px; }
.user-flags { color: #c0392b; font-size: 11px; font-weight: 800; margin-left: 6px; }
.muted { color: var(--muted); font-size: 14px; }
.usage-note { color: var(--muted); font-size: 12px; margin-top: 14px; }

/* ===== Model catalog (Phase 10) ===== */
.add-model-form {
  display: grid; grid-template-columns: 160px 1fr 1fr auto; gap: 12px; align-items: end;
}
@media (max-width: 760px) { .add-model-form { grid-template-columns: 1fr; } }
.add-model-form .field { display: flex; flex-direction: column; gap: 5px; }
.add-model-form label { font-size: 12px; font-weight: 800; color: var(--muted); }
.add-model-form input, .add-model-form select {
  padding: 9px 10px; border: 1px solid var(--border); border-radius: var(--radius);
  font-family: var(--font-ui); font-size: 14px; background: var(--surface); color: var(--ink);
}
.inline-input {
  width: 100%; min-width: 110px; padding: 6px 8px; font-size: 13px;
  border: 1px solid var(--border); border-radius: 7px; background: var(--surface); color: var(--ink);
  font-family: var(--font-ui);
}
.inline-input.mono { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 12px; }
.row-disabled { opacity: .55; }
.muted-cell { color: var(--muted); font-size: 13px; white-space: nowrap; }
.prov { font-weight: 800; }
.btn-sm.danger { color: #c0392b; border-color: #f0c0ba; }
.btn-sm.danger:hover { background: #fdecea; }
code { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 12px;
  background: var(--bg); padding: 1px 5px; border-radius: 5px; }

/* Model checkboxes grouped by provider, in the users table + add form */
.model-group { margin-bottom: 6px; }
.model-group:last-child { margin-bottom: 0; }
.model-group-head {
  font-size: 10px; font-weight: 800; text-transform: uppercase; letter-spacing: .05em;
  color: var(--muted); margin-bottom: 2px;
}
.row-models { min-width: 190px; }

/* Banner used on the models page */
.banner { display: none; margin-bottom: 12px; padding: 10px 12px; border-radius: 10px; font-weight: 700; font-size: 14px; }
.banner.show { display: block; }
.banner.ok { background: #e8f6f0; color: #1d6f56; }
.banner.err { background: #fdecea; color: #a5311f; }

/* ===== Model picker layout (fixes cramped/wrapping columns) ===== */
/* The users table now carries a model list per row, so it needs more room. */
.admin-main.wide { max-width: min(1640px, 96vw); }

/* Users table: stack the provider groups vertically and never break a model
   name mid-word (side-by-side groups in a narrow cell caused that). */
.row-models {
  display: flex; flex-direction: column; gap: 8px;
  min-width: 220px;
}
.row-models .model-group { margin: 0; }
.row-models .check {
  font-size: 13px; white-space: nowrap; line-height: 1.5;
}
.row-models .check input { flex: none; }

/* Model names can be long (claude-haiku-4-5-20251001) — keep them on one line
   and let the table scroll rather than shredding the words. */
.provider-box .check { white-space: nowrap; }
.provider-box .model-group { min-width: 0; }
.users td, .users th { vertical-align: middle; }
.users .row-models { padding: 2px 0; }

/* ===== Status badges + action buttons (Bills-style admin) ===== */
.role-tag {
  display: inline-block; margin-left: 6px; padding: 1px 7px; border-radius: 999px;
  font-size: 10px; font-weight: 800; text-transform: uppercase; letter-spacing: .04em;
  vertical-align: middle;
}
.admin-tag { background: var(--accent-soft); color: var(--accent-ink); }
.off-tag { background: #f1e0dc; color: #a5311f; }
.row-actions { display: flex; gap: 6px; flex-wrap: wrap; white-space: nowrap; align-items: center; }
.row-actions .btn-sm { flex: none; }
/* Account link in the admin topbar, styled like the other topbar links. */
.admin-topbar .link-btn {
  border: none; background: transparent; color: var(--muted);
  font-family: var(--font-ui); font-weight: 700; font-size: 14px; cursor: pointer;
}
.admin-topbar .link-btn:hover { color: var(--accent-ink); }
