/* Magpie Admin console. Dense, desktop-first, mobile-usable.
   Palette echoes the Magpie brand (Nunito Sans, indigo/teal accents). */

:root {
  --bg: #f5f7fa;
  --surface: #ffffff;
  --surface-2: #f0f3f8;
  --ink: #141824;
  --ink-2: #56606f;
  --ink-3: #8a93a4;
  --line: #e2e7ef;
  --line-2: #ccd4e0;
  --primary: #4a5bd6;
  --primary-ink: #ffffff;
  --primary-soft: #eef0fd;
  --accent: #2a94b3;
  --danger: #c8412f;
  --danger-soft: #fdecea;

  --p-low: #56606f;
  --p-medium: #2a7ab3;
  --p-high: #b5761a;
  --p-urgent: #c8412f;

  --s-open: #2a7ab3;
  --s-progress: #7d54c9;
  --s-resolved: #2f9e6b;
  --s-neutral: #56606f;

  --radius: 8px;
  --radius-s: 6px;
  --shadow: 0 1px 2px rgba(20, 24, 36, 0.06), 0 2px 8px rgba(20, 24, 36, 0.05);
  --font: "Nunito Sans", system-ui, -apple-system, Segoe UI, Roboto, sans-serif;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--font);
  font-size: 14px;
  line-height: 1.45;
}

h1, h2 { margin: 0; font-weight: 800; }
button { font-family: inherit; }
[hidden] { display: none !important; }

.muted { color: var(--ink-2); }
.small { font-size: 12px; }

/* ---------- Buttons + inputs ---------- */
.btn {
  border: 1px solid var(--line-2);
  background: var(--surface);
  color: var(--ink);
  padding: 7px 12px;
  border-radius: var(--radius-s);
  font-weight: 700;
  font-size: 13px;
  cursor: pointer;
  transition: background 0.12s, border-color 0.12s;
}
.btn:hover { background: var(--surface-2); }
.btn:focus-visible { outline: 2px solid var(--primary); outline-offset: 1px; }
.btn.sm { padding: 5px 10px; font-size: 12px; }
.btn-primary { background: var(--primary); border-color: var(--primary); color: var(--primary-ink); }
.btn-primary:hover { background: #3d4dc0; }
.btn-ghost { border-color: transparent; background: transparent; color: var(--ink-2); }
.btn-ghost:hover { background: var(--surface-2); }
.btn-danger { color: var(--danger); border-color: var(--line-2); }
.btn-danger:hover { background: var(--danger-soft); border-color: var(--danger); }
.btn-block { display: block; width: 100%; }
.btn-icon {
  border: none; background: transparent; cursor: pointer;
  color: var(--ink-3); font-size: 13px; padding: 3px 6px; border-radius: 4px;
}
.btn-icon:hover { background: var(--surface-2); color: var(--ink); }

.input {
  border: 1px solid var(--line-2);
  background: var(--surface);
  color: var(--ink);
  padding: 7px 10px;
  border-radius: var(--radius-s);
  font-size: 13px;
  font-family: inherit;
}
.input:focus { outline: 2px solid var(--primary); outline-offset: -1px; border-color: var(--primary); }
.input.sm { padding: 5px 8px; font-size: 12px; }
.input.grow { flex: 1; min-width: 160px; }
select.input { cursor: pointer; }

/* ---------- Sign-in ---------- */
.signin {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px;
  background:
    radial-gradient(1200px 500px at 50% -10%, rgba(74, 91, 214, 0.10), transparent),
    var(--bg);
}
.signin-card {
  width: 100%;
  max-width: 360px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 16px;
  box-shadow: var(--shadow);
  padding: 32px 28px;
  text-align: center;
}
.signin-card h1 { font-size: 22px; margin-top: 14px; }
.signin-card > p { margin: 6px 0 20px; }
.brand-mark {
  width: 48px; height: 48px; margin: 0 auto;
  display: grid; place-items: center;
  border-radius: 14px;
  background: linear-gradient(135deg, #309bbb 0%, #478acc 34%, #7362ec 72%, #8158f3 100%);
  color: #fff; font-weight: 800; font-size: 24px;
}
.brand-mark.small { width: 28px; height: 28px; border-radius: 8px; font-size: 15px; }
.signin-sep { position: relative; margin: 18px 0; color: var(--ink-3); font-size: 12px; }
.signin-sep::before { content: ""; position: absolute; top: 50%; left: 0; right: 0; height: 1px; background: var(--line); }
.signin-sep span { position: relative; background: var(--surface); padding: 0 10px; }
.token-fallback { text-align: left; }
.token-fallback summary { cursor: pointer; font-weight: 700; font-size: 13px; color: var(--ink-2); }
.token-fallback .input { width: 100%; margin: 10px 0 8px; }
.error-text { color: var(--danger); font-size: 13px; margin-top: 14px; }

/* ---------- Topbar ---------- */
.app { min-height: 100vh; display: flex; flex-direction: column; }
.topbar {
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 10px 18px;
  background: var(--surface);
  border-bottom: 1px solid var(--line);
  position: sticky;
  top: 0;
  z-index: 20;
}
.topbar-left { display: flex; align-items: center; gap: 9px; }
.topbar-title { font-weight: 800; font-size: 16px; white-space: nowrap; }
.topbar-search { flex: 1; display: flex; }
.topbar-search .input { width: 100%; max-width: 440px; }
.topbar-right { display: flex; align-items: center; gap: 10px; }
.identity { font-size: 12px; color: var(--ink-2); max-width: 200px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.banner { padding: 10px 18px; font-size: 13px; font-weight: 600; }
.banner-error { background: var(--danger-soft); color: var(--danger); border-bottom: 1px solid #f2c9c3; }

.content { padding: 18px; max-width: 1400px; width: 100%; margin: 0 auto; flex: 1; }

/* ---------- Sections ---------- */
.section {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  margin-bottom: 16px;
  overflow: hidden;
}
.section-head {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  text-align: left;
  padding: 12px 16px;
  background: transparent;
  border: none;
  cursor: pointer;
  color: var(--ink);
}
.section-head.static { cursor: default; }
.section-head:hover:not(.static) { background: var(--surface-2); }
.section-head h2 { font-size: 15px; }
.section-head .chev { color: var(--ink-3); font-size: 12px; transition: transform 0.15s; display: inline-block; }
.section.collapsed .chev { transform: none; }
.section:not(.collapsed) .chev { transform: rotate(90deg); }
.badge {
  margin-left: auto;
  background: var(--surface-2);
  color: var(--ink-2);
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 1px 9px;
  font-size: 12px;
  font-weight: 800;
}
.section-body { padding: 0 16px 16px; border-top: 1px solid var(--line); }
.section.collapsed .section-body { display: none; }
.section[data-section="stats"] .section-body { border-top: 1px solid var(--line); }

/* ---------- KPIs ---------- */
.kpis {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
  gap: 10px;
  padding-top: 16px;
}
.kpi {
  background: var(--surface-2);
  border: 1px solid var(--line);
  border-radius: var(--radius-s);
  padding: 12px 14px;
}
.kpi-label { font-size: 11px; font-weight: 700; color: var(--ink-2); text-transform: uppercase; letter-spacing: 0.04em; }
.kpi-value { font-size: 26px; font-weight: 800; margin-top: 4px; line-height: 1; }

.sparkline-wrap { margin-top: 16px; }
.sparkline-label { font-size: 11px; font-weight: 700; color: var(--ink-2); text-transform: uppercase; letter-spacing: 0.04em; margin-bottom: 6px; }
#sparkline svg { display: block; }
#sparkline rect { fill: var(--primary); }
#sparkline .axis { fill: none; stroke: var(--line-2); stroke-width: 1; }
.spark-bar-label { fill: var(--ink-3); font-size: 9px; }

.signups-trend { display: flex; flex-wrap: wrap; gap: 8px; padding: 16px 0 6px; }
.trend-chip { background: var(--surface-2); border: 1px solid var(--line); border-radius: var(--radius-s); padding: 6px 10px; font-size: 12px; }
.trend-chip b { font-weight: 800; }

/* ---------- Filters ---------- */
.filters { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; padding: 14px 0 12px; }
.filters .grow { flex: 1; }

/* ---------- Tables ---------- */
.table-wrap { overflow-x: auto; border: 1px solid var(--line); border-radius: var(--radius-s); }
table.dense { width: 100%; border-collapse: collapse; font-size: 13px; }
table.dense th, table.dense td { text-align: left; padding: 7px 10px; border-bottom: 1px solid var(--line); vertical-align: top; }
table.dense thead th {
  position: sticky; top: 0;
  background: var(--surface-2);
  font-size: 11px; font-weight: 800; text-transform: uppercase; letter-spacing: 0.03em; color: var(--ink-2);
  white-space: nowrap; z-index: 1;
}
table.dense tbody tr:hover { background: var(--surface-2); }
table.dense tbody tr.detail-row:hover { background: transparent; }
table.dense tbody tr:last-child td { border-bottom: none; }
.col-x { width: 26px; }
.col-act { width: 1%; white-space: nowrap; }
.cell-id { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 12px; color: var(--ink-2); white-space: nowrap; }
.cell-date { white-space: nowrap; color: var(--ink-2); font-size: 12px; }
.cell-title { min-width: 220px; max-width: 420px; }
.cell-title.editable { cursor: text; border-radius: 4px; }
.cell-title.editable:focus { outline: 2px solid var(--primary); background: #fff; }
.cell-note { max-width: 260px; color: var(--ink-2); font-size: 12px; }
.row-actions { display: flex; gap: 4px; white-space: nowrap; }

.inline-select {
  border: 1px solid transparent;
  background: transparent;
  font-size: 12px; font-weight: 700;
  padding: 3px 6px; border-radius: 999px; cursor: pointer;
  font-family: inherit;
}
.inline-select:hover { border-color: var(--line-2); }
.inline-select:focus { outline: 2px solid var(--primary); }

.pill { display: inline-block; padding: 2px 9px; border-radius: 999px; font-size: 11px; font-weight: 800; text-transform: capitalize; }
.type-bug { background: #fdecea; color: #c8412f; }
.type-feature { background: #eaf3fb; color: #2a7ab3; }
.type-idea { background: #f1ecfb; color: #7d54c9; }

.p-low { color: var(--p-low); }
.p-medium { color: var(--p-medium); }
.p-high { color: var(--p-high); }
.p-urgent { color: var(--p-urgent); }

.s-open { color: var(--s-open); }
.s-triaged { color: var(--s-open); }
.s-in_progress { color: var(--s-progress); }
.s-fixed, .s-wontfix, .s-resolved, .s-done { color: var(--s-resolved); }
.s-queued, .s-claimed { color: var(--s-neutral); }

/* ---------- Report detail expand ---------- */
.detail-row td { background: var(--surface-2); padding: 14px 16px; }
.detail-desc { white-space: pre-wrap; margin: 0 0 12px; font-size: 13px; max-width: 900px; }
.detail-meta { color: var(--ink-2); font-size: 12px; margin-bottom: 10px; }
.shots { display: flex; flex-wrap: wrap; gap: 8px; }
.shots a { display: block; border: 1px solid var(--line-2); border-radius: 6px; overflow: hidden; }
.shots img { display: block; height: 96px; width: auto; object-fit: cover; }
.detail-loading { color: var(--ink-3); font-size: 13px; }

.empty { padding: 22px 12px; text-align: center; color: var(--ink-3); font-size: 13px; }

/* ---------- Responsive ---------- */
@media (max-width: 720px) {
  .topbar { flex-wrap: wrap; gap: 10px; }
  .topbar-search { order: 3; flex-basis: 100%; }
  .topbar-search .input { max-width: none; }
  .content { padding: 12px; }
  .identity { max-width: 120px; }
}

@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; }
}
