:root {
  --bg: #f3efe7;
  --card: #fffdf8;
  --text: #202020;
  --muted: #5a5a5a;
  --line: #d8cfc0;
  --accent: #1e5f4e;
  --accent-strong: #15483b;
}

/* Dark theme for the admin console: the page defines its own color variables
   (light values above), so re-map them here when the toggle sets data-theme. */
body[data-theme="dark"] {
  --bg: #0f1a24;
  --card: #15232f;
  --text: #dfe9f1;
  --muted: #94a8b8;
  --line: #2c3f4f;
  --accent: #2ea9d2;
  --accent-strong: #1a90b8;
  background: radial-gradient(circle at 0% 0%, #182a38 0%, #0f1a24 55%, #0a131b 100%);
}

body[data-theme="dark"] .usage-bar-track {
  background: #26394a;
}

body[data-theme="dark"] .usage-history-track {
  background: #1e2f3d;
}

body[data-theme="dark"] pre {
  background: #0a141d;
  color: #c7e8d8;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  background: radial-gradient(circle at 0% 0%, #f6f2eb 0%, var(--bg) 55%, #ebe3d6 100%);
  color: var(--text);
  font-family: "Space Grotesk", sans-serif;
}

body.admin-locked .admin-shell > header,
body.admin-locked .admin-shell > section:not(.auth-card) {
  display: none;
}

.admin-shell {
  max-width: 1160px;
  margin: 0 auto;
  padding: 28px 18px 56px;
  display: grid;
  gap: 16px;
}

/* The `hidden` attribute must always win over display rules on the shell
   elements (e.g. `.admin-shell { display: grid }`), otherwise the login screen
   stays visible after a successful sign-in. */
.admin-shell[hidden],
.auth-shell[hidden] {
  display: none !important;
}

.card {
  border: 1px solid var(--line);
  border-radius: 14px;
  background: var(--card);
  padding: 16px;
  box-shadow: 0 8px 28px rgba(32, 32, 32, 0.07);
  /* Allow the card to shrink inside its grid column so long content wraps
     instead of spilling out of the panel. */
  min-width: 0;
  overflow-wrap: break-word;
}

.admin-header h1 {
  margin: 6px 0;
  font-size: 2rem;
}

.admin-header-row {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 14px;
}

.theme-toggle-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 40px;
  height: 40px;
  padding: 0;
  flex-shrink: 0;
}

.theme-toggle-btn .header-icon {
  width: 20px;
  height: 20px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.8;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.kicker {
  margin: 0;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  font-size: 0.75rem;
  color: var(--muted);
}

.subtle {
  margin: 0;
  color: var(--muted);
}

.auth-card .row {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  margin-top: 8px;
}

input,
select,
button {
  font-family: "IBM Plex Mono", monospace;
}

input,
select {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 9px 10px;
  background: #fff;
}

button {
  border: 1px solid var(--accent-strong);
  border-radius: 8px;
  padding: 9px 12px;
  background: var(--accent);
  color: #fff;
  cursor: pointer;
}

button:hover {
  background: var(--accent-strong);
}

.status {
  margin: 10px 0 0;
  color: var(--muted);
}

.grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 16px;
}

.kv {
  margin: 0;
  display: grid;
  grid-template-columns: 1fr;
  gap: 8px;
  min-width: 0;
}

.kv div {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  border-bottom: 1px dashed var(--line);
  padding-bottom: 6px;
  min-width: 0;
}

.kv dt {
  color: var(--muted);
  font-size: 0.92rem;
  flex-shrink: 0;
}

.kv dd {
  margin: 0;
  font-family: "IBM Plex Mono", monospace;
  font-size: 0.9rem;
  text-align: right;
  /* Long values (paths, timestamps, kind lists) must wrap or truncate instead
     of pushing the label/row out of the panel. */
  min-width: 0;
  overflow-wrap: anywhere;
  word-break: break-word;
}

.action-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 12px;
}

.inline-action {
  display: grid;
  gap: 8px;
}

.override-grid {
  margin-top: 14px;
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 10px;
}

.override-grid .bbox-label {
  grid-column: span 3;
  font-size: 0.85rem;
  color: var(--muted);
}

.override-grid button {
  grid-column: span 3;
}

h3 {
  margin: 18px 0 8px;
  font-size: 1rem;
}

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.92rem;
}

th,
td {
  border-bottom: 1px solid var(--line);
  text-align: left;
  padding: 8px 4px;
  vertical-align: top;
  /* Long emails, user IDs, and timestamps must wrap/truncate within their
     column instead of overflowing the panel. */
  min-width: 0;
  overflow-wrap: anywhere;
  word-break: break-word;
}

th {
  color: var(--muted);
  font-weight: 600;
}

pre {
  margin: 0;
  max-height: 320px;
  overflow: auto;
  background: #1f1f1f;
  color: #d8f6e3;
  border-radius: 10px;
  padding: 12px;
  font-size: 0.83rem;
}

@media (max-width: 980px) {
  .grid,
  .action-grid,
  .override-grid {
    grid-template-columns: 1fr;
  }

  .override-grid button {
    grid-column: auto;
  }
}

.kpi-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 14px;
  margin-bottom: 18px;
}

.kpi-card {
  padding: 14px 16px;
  min-width: 0;
}

.kpi-label {
  margin: 0;
  font-size: 0.78rem;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--muted);
}

.kpi-value {
  margin: 6px 0 2px;
  font-size: 1.9rem;
  font-weight: 700;
  font-family: "IBM Plex Mono", monospace;
  color: var(--text);
  overflow-wrap: anywhere;
  word-break: break-word;
}

.kpi-sub {
  margin: 0;
  font-size: 0.8rem;
  color: var(--muted);
  overflow-wrap: anywhere;
  word-break: break-word;
}

.session-row {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 14px;
}

.session-row .row {
  margin-left: auto;
}

.usage-bar-row {
  margin-bottom: 12px;
}

.usage-bar-meta {
  display: flex;
  justify-content: space-between;
  font-size: 0.85rem;
  margin-bottom: 4px;
}

.usage-bar-track {
  height: 10px;
  border-radius: 6px;
  background: #e4e0d6;
  overflow: hidden;
}

.usage-bar-fill {
  height: 100%;
  border-radius: 6px;
  background: #177ca2;
  transition: width 0.4s ease;
}

.usage-bar-fill.is-reached {
  background: #c0392b;
}

.role-admin {
  font-weight: 700;
  color: #1e5f4e;
}

#accountsBody td {
  vertical-align: middle;
}

/* Keep the action button on one line so it doesn't wrap awkwardly. */
#accountsBody td:last-child {
  white-space: nowrap;
}

#accountsBody button {
  font-size: 0.78rem;
  padding: 4px 10px;
}

.usage-history-row {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 6px;
  font-size: 0.8rem;
}

.usage-history-day {
  width: 34px;
  font-family: "IBM Plex Mono", monospace;
  color: var(--muted);
}

.usage-history-track {
  flex: 1;
  height: 8px;
  border-radius: 4px;
  background: #e9e4da;
  overflow: hidden;
  display: flex;
}

.usage-history-bar {
  height: 100%;
}

.usage-history-bar.is-rest {
  background: #177ca2;
}

.usage-history-bar.is-vector {
  background: #d44d1f;
}

.usage-history-counts {
  width: 70px;
  text-align: right;
  font-family: "IBM Plex Mono", monospace;
  color: var(--muted);
  font-size: 0.72rem;
}
