/* Colors are the app's own (lib/theme/tokens.dart): Kinsman navy for the
   header, Kinsman blue (primary) for actions, and the app's light and dark
   surface ramps for the page. */
:root {
  --brand-navy: #182330;
  --brand-blue: #2196f3;
  --on-brand: #ffffff;
  --on-brand-muted: #adbace;

  --text: #223144;
  --muted: #758390;
  --border: #d8e2ec;
  --background: #f4f9fe;
  --surface: #ffffff;
  --surface-alt: #ebf2f9;
  --selected: #e1effc;
  --accent: #1976d2;
  --accent-text: #ffffff;
  --warning-background: #fff4dc;
  --warning-text: #7a4b00;
  --error: #b3261e;
  --success: #1e7b34;
  --prod: #b3261e;
  --shadow: 0 8px 28px rgba(18, 30, 44, 0.18);
}

@media (prefers-color-scheme: dark) {
  :root {
    --text: #ffffff;
    --muted: #adbace;
    --border: #2e3946;
    --background: #141a21;
    --surface: #1d252e;
    --surface-alt: #181f27;
    --selected: #1c3550;
    --accent: #64b5f6;
    --accent-text: #0e1319;
    --warning-background: #3a2e12;
    --warning-text: #ffd27a;
    --error: #ff8a80;
    --success: #7ad48c;
    --shadow: 0 8px 28px rgba(0, 0, 0, 0.5);
  }
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

body {
  margin: 0;
  font: 14px/1.45 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  color: var(--text);
  background: var(--background);
}

/* Header ------------------------------------------------------------------ */

.top { position: sticky; top: 0; z-index: 5; }
header {
  display: flex; align-items: center; gap: 16px; flex-wrap: wrap;
  padding: 12px 24px;
  background: var(--brand-navy); color: var(--on-brand);
  border-bottom: 3px solid var(--brand-blue);
}
.brand { display: flex; align-items: center; gap: 14px; }
.brand img { display: block; height: 18px; width: auto; }
.brand h1 {
  margin: 0; padding-left: 14px; border-left: 1px solid rgba(255, 255, 255, 0.25);
  font-size: 17px; font-weight: 600; line-height: 28px;
}
.spacer { flex: 1; }
.signed-in-as { color: var(--on-brand-muted); }

.environment-switch { display: inline-flex; border: 1px solid rgba(255, 255, 255, 0.3); border-radius: 6px; overflow: hidden; }
.environment-switch button {
  border: none; border-radius: 0; padding: 4px 14px; font-size: 13px;
  background: transparent; color: var(--on-brand-muted);
}
.environment-switch button + button { border-left: 1px solid rgba(255, 255, 255, 0.3); }
.environment-switch button[aria-pressed="true"] { background: var(--brand-blue); color: #fff; }
.environment-switch button[data-environment="prod"][aria-pressed="true"] { background: var(--prod); }

button.on-brand { background: transparent; color: var(--on-brand); border-color: rgba(255, 255, 255, 0.4); }

.prod-banner {
  padding: 10px 24px; text-align: center;
  background: var(--prod); color: #fff; font-weight: 500;
}

/* Controls ---------------------------------------------------------------- */

.muted { color: var(--muted); }
.hint { display: block; margin-top: 4px; font-size: 12px; color: var(--muted); font-weight: normal; }
.pending { margin: 8px 0 0; font-size: 13px; color: var(--muted); font-style: italic; }
.hidden-label { position: absolute; left: -9999px; }

button {
  font: inherit; font-weight: 600;
  padding: 8px 16px; border-radius: 6px; border: 1px solid var(--accent);
  background: var(--accent); color: var(--accent-text); cursor: pointer;
}
button.quiet { background: var(--surface); color: var(--accent); border-color: var(--border); }
button.small { padding: 5px 12px; font-size: 13px; }
button.link { background: none; border: none; padding: 2px 4px; color: var(--accent); font-size: 13px; }
button:disabled { opacity: 0.45; cursor: default; }

input, textarea, select {
  font: inherit; color: var(--text); background: var(--surface);
  padding: 7px 9px; border: 1px solid var(--border); border-radius: 6px;
  width: 100%;
}
input[type="checkbox"], input[type="radio"] { width: auto; accent-color: var(--accent); }
input:disabled, textarea:disabled { background: var(--surface-alt); color: var(--muted); cursor: not-allowed; }
textarea { resize: vertical; }
:focus-visible { outline: 2px solid var(--brand-blue); outline-offset: 1px; }

.message { max-width: 520px; margin: 80px auto; padding: 0 16px; text-align: center; }

/* Results ----------------------------------------------------------------- */

.dashboard { max-width: 1400px; margin: 0 auto; padding: 20px 24px 40px; }

.toolbar { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; }
.toolbar input[type="search"] { width: min(420px, 100%); }

.active-filters { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; margin: 10px 0; min-height: 4px; }
.chips { display: contents; list-style: none; }
.chips li {
  display: inline-flex; align-items: center; gap: 4px;
  padding: 3px 4px 3px 10px; border-radius: 14px;
  background: var(--selected); color: var(--text); font-size: 13px;
}
.chips li button { background: none; border: none; padding: 0 6px; color: var(--muted); font-size: 16px; line-height: 1; }
.chips li span { cursor: pointer; }

.table-wrap {
  overflow-x: auto;
  background: var(--surface); border: 1px solid var(--border); border-radius: 8px;
}
table.accounts { width: 100%; border-collapse: collapse; font-size: 13px; }
.accounts th, .accounts td { padding: 9px 12px; text-align: left; white-space: nowrap; }
.accounts thead th {
  position: sticky; top: 0;
  background: var(--surface-alt); color: var(--muted); font-weight: 600;
  border-bottom: 1px solid var(--border);
}
.accounts tbody tr { border-bottom: 1px solid var(--border); cursor: pointer; }
.accounts tbody tr:last-child { border-bottom: none; }
.accounts tbody tr:hover { background: var(--surface-alt); }
.accounts tbody tr.selected { background: var(--selected); }
.accounts td.account { white-space: normal; min-width: 220px; }
.accounts .email { font-weight: 600; overflow-wrap: anywhere; }
.accounts .name { color: var(--muted); }
.accounts .empty-cell { color: var(--muted); }
.accounts .empty-row td { padding: 32px; text-align: center; color: var(--muted); cursor: default; }

.column { display: inline-flex; align-items: center; gap: 2px; }
.column .sort {
  background: none; border: none; padding: 2px 4px; margin-left: -4px;
  color: inherit; font-weight: 600; display: inline-flex; align-items: center; gap: 4px;
}
.column .sort .arrow { width: 10px; color: var(--accent); }
.column .filter {
  background: none; border: none; padding: 3px; border-radius: 4px;
  color: var(--muted); display: inline-flex;
}
.column .filter:hover { background: var(--border); }
.column .filter.active { color: var(--accent-text); background: var(--accent); }
.column .filter svg { width: 14px; height: 14px; }
.column .tag { font-weight: normal; font-size: 11px; color: var(--muted); }

.badge {
  display: inline-block; padding: 1px 8px; border-radius: 10px;
  font-size: 12px; font-weight: 600;
}
.badge.pro { background: var(--brand-blue); color: #fff; }
.badge.standard { background: var(--surface-alt); color: var(--muted); border: 1px solid var(--border); }
.badge.disabled { background: var(--warning-background); color: var(--warning-text); }

.pager { display: flex; align-items: center; justify-content: flex-end; gap: 8px; margin-top: 10px; }
.pager span { margin-right: 4px; }

/* Column filter popover ---------------------------------------------------- */

.popover {
  position: absolute; z-index: 20; width: 320px;
  padding: 14px; border-radius: 8px;
  background: var(--surface); border: 1px solid var(--border); box-shadow: var(--shadow);
}
.popover h4 { margin: 0 0 10px; font-size: 13px; }
.popover .options { display: flex; flex-direction: column; gap: 6px; }
.popover .options label { display: flex; align-items: center; gap: 8px; font-size: 13px; }
.popover .range { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin: 8px 0 0 24px; }
.popover .options .range label { display: block; font-size: 12px; color: var(--muted); }
.popover .range input { margin-top: 2px; padding: 5px 6px; font-size: 13px; }
.popover .actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 14px; }
.popover .note { margin: 10px 0 0; font-size: 12px; color: var(--muted); }

/* Account drawer ----------------------------------------------------------- */

.drawer {
  position: fixed; right: 0; bottom: 0; z-index: 10;
  width: min(560px, 100vw); overflow-y: auto;
  padding: 24px;
  background: var(--surface); border-left: 1px solid var(--border); box-shadow: var(--shadow);
  animation: slide-in 160ms ease-out;
}
/* On a wide screen the table makes room for the drawer instead of sitting under it. */
@media (min-width: 1200px) {
  body.drawer-open .dashboard { max-width: none; margin: 0; padding-right: calc(min(560px, 100vw) + 24px); }
}
@keyframes slide-in { from { transform: translateX(40px); opacity: 0; } }
@media (prefers-reduced-motion: reduce) { .drawer { animation: none; } }
.drawer .close {
  position: absolute; top: 14px; right: 14px;
  width: 32px; height: 32px; padding: 0; border-radius: 16px;
  background: var(--surface-alt); color: var(--text); border: none; font-size: 20px; line-height: 1;
}
.drawer .empty { margin: 40px 0; text-align: center; }

.account-header h2 { margin: 0 40px 0 0; font-size: 20px; }
.account-header p { margin: 4px 0 0; overflow-wrap: anywhere; }
.drawer h3 { margin: 24px 0 8px; font-size: 14px; }

.flags { list-style: none; margin: 8px 0 0; padding: 0; display: flex; flex-direction: column; gap: 6px; }
.flags li { padding: 8px 10px; border-radius: 6px; background: var(--warning-background); color: var(--warning-text); }

.switch-row { display: flex; gap: 10px; align-items: flex-start; }
.switch-row input { margin-top: 3px; }

.grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 16px; margin-top: 16px; }
.grid label, .save label { display: block; font-weight: 600; }
.grid input, .save input { margin-top: 4px; font-weight: normal; }

.edited { border-color: var(--accent); box-shadow: 0 0 0 1px var(--accent); }

.read-only { margin: 24px 0 0; padding: 10px 12px; border-radius: 6px; background: var(--warning-background); color: var(--warning-text); }

.save { margin-top: 24px; padding-top: 16px; border-top: 1px solid var(--border); }
.save-row { display: flex; align-items: center; gap: 12px; margin-top: 10px; flex-wrap: wrap; }
.save-status-error { color: var(--error); }
.save-status-ok { color: var(--success); }

.history { width: 100%; border-collapse: collapse; font-size: 13px; }
.history th, .history td { text-align: left; padding: 6px 8px; border-bottom: 1px solid var(--border); vertical-align: top; }
.history th { font-weight: 600; color: var(--muted); }
.history td { overflow-wrap: anywhere; }
@media (max-width: 760px) {
  header { padding: 10px 16px; }
  .dashboard { padding: 16px; }
  .history thead { display: none; }
  .history tr { display: block; padding: 8px 0; border-bottom: 1px solid var(--border); }
  .history td { display: block; border: none; padding: 2px 0; }
}

/* Loading ----------------------------------------------------------------- */

.spinner {
  display: inline-block; flex: none; vertical-align: -3px;
  width: 16px; height: 16px; border-radius: 50%;
  border: 2px solid var(--border); border-top-color: var(--accent);
  animation: spin 0.8s linear infinite;
}
.spinner.small { width: 14px; height: 14px; }
.spinner.large { width: 32px; height: 32px; border-width: 3px; }
@keyframes spin { to { transform: rotate(360deg); } }
@media (prefers-reduced-motion: reduce) { .spinner { animation-duration: 2s; } }

button.busy { display: inline-flex; align-items: center; gap: 8px; }
button.busy:disabled { opacity: 0.75; }
button.busy .spinner { border-color: currentColor; border-top-color: transparent; opacity: 0.9; }

#search-status { display: inline-flex; align-items: center; gap: 6px; }
#search-status .spinner { margin-right: 0; }

.loading-page { display: flex; flex-direction: column; align-items: center; gap: 12px; }
.loading-page p { margin: 0; }

.table-wrap { position: relative; min-height: 120px; }
.table-loading {
  display: none; position: absolute; inset: 0; z-index: 2;
  align-items: flex-start; justify-content: center; padding-top: 72px;
  background: color-mix(in srgb, var(--surface) 60%, transparent);
}
.table-wrap.busy .table-loading { display: flex; }
.table-wrap.busy tbody { pointer-events: none; }

.drawer-loading { display: flex; flex-direction: column; align-items: center; gap: 12px; margin: 60px 0; }
.drawer-loading p { margin: 0; }
