/* The SRE Toolbox — self-contained styles. No external fonts or assets. */

:root {
  --font-sans: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  --font-mono: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, "Liberation Mono", monospace;

  --radius: 12px;
  --radius-sm: 8px;
  --maxw: 1180px;
  --transition: 160ms cubic-bezier(0.4, 0, 0.2, 1);
}

/* ---- Light theme (default palette) ---- */
:root[data-theme="light"] {
  --bg: #f6f7f9;
  --bg-elev: #ffffff;
  --bg-inset: #f0f2f5;
  --border: #e2e5ea;
  --border-strong: #cdd2da;
  --text: #1a1f2b;
  --text-muted: #5b6472;
  --accent: #2563eb;
  --accent-weak: #dbe6fe;
  --good: #15803d;
  --good-bg: #dcfce7;
  --warn: #b45309;
  --warn-bg: #fef3c7;
  --bad: #b91c1c;
  --bad-bg: #fee2e2;
  --shadow: 0 1px 2px rgba(16, 24, 40, 0.06), 0 6px 20px rgba(16, 24, 40, 0.06);
}

/* ---- Dark theme ---- */
:root[data-theme="dark"] {
  --bg: #0e1117;
  --bg-elev: #161b22;
  --bg-inset: #0b0e14;
  --border: #262c36;
  --border-strong: #333b47;
  --text: #e6edf3;
  --text-muted: #9aa4b2;
  --accent: #4c8dff;
  --accent-weak: #17233b;
  --good: #4ade80;
  --good-bg: #0f2a1a;
  --warn: #fbbf24;
  --warn-bg: #2a220c;
  --bad: #f87171;
  --bad-bg: #2a1212;
  --shadow: 0 1px 2px rgba(0, 0, 0, 0.4), 0 8px 24px rgba(0, 0, 0, 0.3);
}

* {
  box-sizing: border-box;
}

html {
  color-scheme: light dark;
}

body {
  margin: 0;
  font-family: var(--font-sans);
  background: var(--bg);
  color: var(--text);
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

a {
  color: var(--accent);
  text-decoration: none;
}
a:hover {
  text-decoration: underline;
}

/* ---- Top bar ---- */
.topbar {
  position: sticky;
  top: 0;
  z-index: 10;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  padding: 0.85rem clamp(1rem, 3vw, 2rem);
  background: color-mix(in srgb, var(--bg-elev) 88%, transparent);
  backdrop-filter: saturate(160%) blur(10px);
  border-bottom: 1px solid var(--border);
}

.brand {
  display: flex;
  align-items: center;
  gap: 0.75rem;
}
.brand-mark {
  font-size: 1.6rem;
  line-height: 1;
}
.brand-text {
  display: flex;
  flex-direction: column;
}
.brand-title {
  font-weight: 700;
  font-size: 1.05rem;
  letter-spacing: -0.01em;
}
.brand-sub {
  font-size: 0.75rem;
  color: var(--text-muted);
}

.theme-toggle {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  padding: 0.45rem 0.8rem;
  font: inherit;
  font-size: 0.85rem;
  color: var(--text);
  background: var(--bg-inset);
  border: 1px solid var(--border);
  border-radius: 999px;
  cursor: pointer;
  transition: border-color var(--transition), background var(--transition);
}
.theme-toggle:hover {
  border-color: var(--border-strong);
}
.theme-icon {
  font-size: 0.95rem;
}

/* ---- Layout ---- */
.layout {
  display: grid;
  grid-template-columns: 280px 1fr;
  gap: 0;
  max-width: var(--maxw);
  margin: 0 auto;
  min-height: calc(100vh - 61px);
}

.sidebar {
  border-right: 1px solid var(--border);
  padding: 1.25rem 1rem;
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
}

.nav-item {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0.65rem 0.75rem;
  border-radius: var(--radius-sm);
  color: var(--text);
  border: 1px solid transparent;
  transition: background var(--transition), border-color var(--transition);
}
.nav-item:hover {
  background: var(--bg-inset);
  text-decoration: none;
}
.nav-item.active {
  background: var(--accent-weak);
  border-color: color-mix(in srgb, var(--accent) 35%, transparent);
}
.nav-emoji {
  font-size: 1.15rem;
  width: 1.5rem;
  text-align: center;
}
.nav-body {
  display: flex;
  flex-direction: column;
  min-width: 0;
}
.nav-title {
  font-weight: 600;
  font-size: 0.92rem;
}
.nav-desc {
  font-size: 0.72rem;
  color: var(--text-muted);
}
.nav-item.active .nav-title {
  color: var(--accent);
}
.sidebar-note {
  margin-top: auto;
  padding: 0.75rem;
  font-size: 0.72rem;
  color: var(--text-muted);
  border-top: 1px solid var(--border);
}

/* ---- Workspace ---- */
.workspace {
  padding: clamp(1.25rem, 3vw, 2.25rem);
  min-width: 0;
}

.tool-panel[hidden] {
  display: none;
}
.tool-panel {
  animation: fade 220ms ease;
}
@keyframes fade {
  from {
    opacity: 0;
    transform: translateY(4px);
  }
  to {
    opacity: 1;
    transform: none;
  }
}

h1 {
  font-size: clamp(1.4rem, 2.6vw, 1.9rem);
  letter-spacing: -0.02em;
  margin: 0 0 0.35rem;
}
h4 {
  font-size: 0.95rem;
  margin: 1.5rem 0 0.6rem;
  color: var(--text);
}
.lede {
  color: var(--text-muted);
  margin: 0 0 1.5rem;
  max-width: 62ch;
}
.muted {
  color: var(--text-muted);
}

/* ---- Controls ---- */
.controls {
  display: flex;
  flex-wrap: wrap;
  gap: 1rem;
  margin-bottom: 1.25rem;
}
.field {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
  flex: 1 1 180px;
}
.field.grow {
  flex: 3 1 320px;
}
.field > span {
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--text-muted);
}
.field .opt {
  font-weight: 400;
  font-size: 0.72rem;
  color: var(--text-muted);
  opacity: 0.8;
}

input,
textarea {
  font: inherit;
  color: var(--text);
  background: var(--bg-elev);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  padding: 0.6rem 0.7rem;
  width: 100%;
  transition: border-color var(--transition), box-shadow var(--transition);
}
textarea {
  font-family: var(--font-mono);
  font-size: 0.85rem;
  resize: vertical;
}
input:focus,
textarea:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-weak);
}

/* ---- Chips / sample buttons ---- */
.chips {
  display: flex;
  flex-wrap: wrap;
  gap: 0.45rem;
  margin-bottom: 1.25rem;
}
.chip {
  font: inherit;
  font-size: 0.8rem;
  font-family: var(--font-mono);
  color: var(--text-muted);
  background: var(--bg-inset);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 0.3rem 0.7rem;
  cursor: pointer;
  transition: all var(--transition);
}
.chip:hover {
  color: var(--accent);
  border-color: var(--accent);
}

/* ---- Output blocks ---- */
.output {
  margin-top: 0.5rem;
}

.result-callout {
  display: flex;
  flex-direction: column;
  gap: 0.15rem;
  padding: 1.1rem 1.25rem;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  background: var(--bg-elev);
  margin-bottom: 1rem;
  box-shadow: var(--shadow);
}
.result-callout.good {
  border-color: color-mix(in srgb, var(--good) 40%, transparent);
  background: var(--good-bg);
}
.result-callout.warn {
  border-color: color-mix(in srgb, var(--warn) 40%, transparent);
  background: var(--warn-bg);
}
.result-callout.bad {
  border-color: color-mix(in srgb, var(--bad) 40%, transparent);
  background: var(--bad-bg);
}
.big-metric {
  font-size: 2rem;
  font-weight: 700;
  font-family: var(--font-mono);
  letter-spacing: -0.02em;
  line-height: 1.1;
}
.result-callout.good .big-metric {
  color: var(--good);
}
.result-callout.warn .big-metric {
  color: var(--warn);
}
.result-callout.bad .big-metric {
  color: var(--bad);
}
.big-metric-label {
  font-size: 0.85rem;
  color: var(--text-muted);
}
.result-callout.bad .big-metric-label {
  color: var(--bad);
  font-weight: 600;
}

/* ---- Key/value tables ---- */
.kv {
  width: 100%;
  border-collapse: collapse;
  margin-bottom: 1rem;
}
.kv th,
.kv td {
  text-align: left;
  padding: 0.55rem 0.75rem;
  border-bottom: 1px solid var(--border);
  vertical-align: top;
}
.kv th {
  font-weight: 500;
  color: var(--text-muted);
  width: 45%;
}
.kv td {
  font-family: var(--font-mono);
  font-size: 0.9rem;
}

/* ---- Data table ---- */
.table-scroll {
  overflow-x: auto;
  border: 1px solid var(--border);
  border-radius: var(--radius);
}
.data-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.88rem;
}
.data-table th,
.data-table td {
  padding: 0.6rem 0.85rem;
  text-align: left;
  white-space: nowrap;
}
.data-table thead th {
  background: var(--bg-inset);
  color: var(--text-muted);
  font-weight: 600;
  font-size: 0.78rem;
  text-transform: uppercase;
  letter-spacing: 0.03em;
  border-bottom: 1px solid var(--border);
}
.data-table tbody th {
  font-family: var(--font-mono);
  font-weight: 700;
  color: var(--accent);
}
.data-table tbody td {
  font-family: var(--font-mono);
  color: var(--text);
}
.data-table tbody tr:nth-child(even) {
  background: color-mix(in srgb, var(--bg-inset) 55%, transparent);
}

/* ---- Metric grid ---- */
.metric-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(120px, 1fr));
  gap: 0.75rem;
}
.metric-card {
  padding: 0.9rem 1rem;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--bg-elev);
}
.metric-value {
  font-family: var(--font-mono);
  font-size: 1.3rem;
  font-weight: 700;
  letter-spacing: -0.01em;
}
.metric-label {
  font-size: 0.75rem;
  color: var(--text-muted);
  margin-top: 0.15rem;
}

/* ---- Code output ---- */
.code-out {
  font-family: var(--font-mono);
  font-size: 0.85rem;
  background: var(--bg-inset);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 0.85rem 1rem;
  overflow-x: auto;
  margin: 0 0 0.75rem;
  white-space: pre;
}
.note-inline {
  font-size: 0.82rem;
  color: var(--warn);
  background: var(--warn-bg);
  border: 1px solid color-mix(in srgb, var(--warn) 35%, transparent);
  border-radius: var(--radius-sm);
  padding: 0.5rem 0.75rem;
  margin: 0 0 1rem;
}

.run-list {
  list-style: none;
  padding: 0;
  margin: 0;
  display: grid;
  gap: 0.35rem;
}
.run-list li {
  padding: 0.5rem 0.75rem;
  background: var(--bg-inset);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
}
.run-list code {
  font-family: var(--font-mono);
  font-size: 0.85rem;
}

code {
  font-family: var(--font-mono);
  font-size: 0.9em;
  background: var(--bg-inset);
  padding: 0.1em 0.35em;
  border-radius: 5px;
}

/* ---- Split (humanizer) ---- */
.split {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1.5rem;
}
.split-col h4 {
  margin-top: 0;
}

/* ---- Footer ---- */
.footer {
  max-width: var(--maxw);
  margin: 0 auto;
  padding: 1.25rem clamp(1rem, 3vw, 2rem);
  border-top: 1px solid var(--border);
  display: flex;
  justify-content: space-between;
  gap: 1rem;
  font-size: 0.8rem;
  color: var(--text-muted);
  flex-wrap: wrap;
}

/* ---- Responsive ---- */
@media (max-width: 820px) {
  .layout {
    grid-template-columns: 1fr;
  }
  .sidebar {
    flex-direction: row;
    flex-wrap: wrap;
    border-right: none;
    border-bottom: 1px solid var(--border);
    position: sticky;
    top: 61px;
    background: var(--bg);
    z-index: 5;
  }
  .nav-item {
    flex: 1 1 auto;
  }
  .nav-desc {
    display: none;
  }
  .sidebar-note {
    flex-basis: 100%;
    margin-top: 0.5rem;
  }
  .split {
    grid-template-columns: 1fr;
  }
}

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