*,
::before,
::after {
  box-sizing: border-box;
}

:root {
  color-scheme: light;
  --canvas:        #eeede9;
  --surface:       #ffffff;
  --surface-soft:  #eeede9;
  --surface-muted: #e5e3dc;
  --ink:           #1b1b18;
  --ink-2:         #3d3c38;
  --muted:         #6d6c66;
  --faint:         #a4a39c;
  --line:          #dad8d0;
  --line-soft:     #e7e5de;
  --accent:        #1b1b18;
  --accent-2:      #2a6b64;
  --danger:        #be3a30;
  --warn:          #b45309;
  --ok:            #15803d;
  --r:             12px;
  --r-sm:          8px;
  --shadow-xs:     0 1px 2px rgba(27,27,24,.05);
  --shadow-sm:     0 1px 4px rgba(27,27,24,.07), 0 4px 14px rgba(27,27,24,.09);
  --shadow:        0 2px 8px rgba(27,27,24,.07), 0 10px 28px rgba(27,27,24,.11);
  --shadow-lg:     0 4px 16px rgba(27,27,24,.08), 0 24px 56px rgba(27,27,24,.14);
  --t:             150ms ease;
}

/* ── Reset ─────────────────────────────────────────────── */

html {
  -webkit-text-size-adjust: 100%;
}

body {
  margin: 0;
  background: var(--canvas);
  color: var(--ink);
  font-family:
    Inter, ui-sans-serif, system-ui, -apple-system,
    BlinkMacSystemFont, "Segoe UI", sans-serif;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

button,
input {
  font: inherit;
}

button {
  cursor: pointer;
  border: 0;
  background: none;
  padding: 0;
}

svg {
  display: block;
}

/* ── Utility ────────────────────────────────────────────── */

.hidden {
  display: none !important;
}

.min-h-screen {
  min-height: 100vh;
}

.space-y-5 > * + * {
  margin-top: 20px;
}

/* ── Brand mark ─────────────────────────────────────────── */

.brand-mark {
  position: relative;
  width: 36px;
  height: 36px;
  flex: 0 0 36px;
}

.brand-mark::before,
.brand-mark::after,
.brand-mark span {
  position: absolute;
  display: block;
  width: 24px;
  height: 24px;
  border-radius: 7px;
  content: "";
}

.brand-mark::before {
  left: 0;
  top: 10px;
  background: #cac8c0;
}

.brand-mark::after {
  left: 5px;
  top: 5px;
  background: #aeada5;
}

.brand-mark span {
  left: 10px;
  top: 0;
  background: var(--accent);
  box-shadow: 0 6px 16px rgba(27,27,24,.22);
}

.brand-row {
  display: flex;
  align-items: center;
  gap: 11px;
  min-width: 0;
}

.brand-title {
  margin: 0;
  font-size: 21px;
  font-weight: 760;
  line-height: 1;
  letter-spacing: -.3px;
}

.brand-logo {
  display: block;
  width: min(220px, 100%);
  height: auto;
  max-height: 36px;
  object-fit: contain;
}

/* ── Sidebar ────────────────────────────────────────────── */

.sidebar {
  position: sticky;
  top: 0;
  z-index: 10;
  display: flex;
  flex-direction: column;
  gap: 14px;
  width: 100%;
  padding: 16px;
  border-bottom: 1px solid var(--line-soft);
  background: rgba(238,237,233,.96);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
}

/* ── Sidebar search ─────────────────────────────────────── */

.sidebar-search {
  display: flex;
  align-items: center;
  gap: 9px;
  min-height: 44px;
  padding: 0 12px;
  border: 1.5px solid var(--line-soft);
  border-radius: var(--r-sm);
  background: var(--surface-soft);
  transition: border-color var(--t), box-shadow var(--t), background var(--t);
}

.sidebar-search:focus-within {
  border-color: var(--line);
  background: var(--surface);
  box-shadow: 0 0 0 3px rgba(27,27,24,.07);
}

.sidebar-search input {
  flex: 1 1 0;
  min-width: 0;
  border: 0;
  outline: 0;
  background: transparent;
  color: var(--ink);
  font-size: 15px;
}

.sidebar-search input::placeholder {
  color: var(--faint);
}

.sidebar-search kbd {
  display: none;
  flex-shrink: 0;
  padding: 3px 8px;
  border: 1px solid var(--line);
  border-radius: 5px;
  background: rgba(255,255,255,.85);
  color: var(--muted);
  font: 600 12px/1.5 ui-monospace, SFMono-Regular, Menlo, monospace;
  user-select: none;
  pointer-events: none;
}

.icon-muted {
  width: 19px;
  height: 19px;
  flex: 0 0 19px;
  fill: none;
  stroke: var(--faint);
  stroke-linecap: round;
  stroke-linejoin: round;
  stroke-width: 2;
}

/* ── Nav list ───────────────────────────────────────────── */

.nav-list {
  display: flex;
  gap: 3px;
  overflow-x: auto;
  padding-bottom: 2px;
  scrollbar-width: none;
}

.nav-list::-webkit-scrollbar {
  display: none;
}

.nav-button {
  display: inline-flex;
  flex: 0 0 auto;
  align-items: center;
  gap: 10px;
  min-height: 46px;
  padding: 0 13px;
  border-radius: var(--r-sm);
  background: transparent;
  color: var(--muted);
  text-decoration: none;
  white-space: nowrap;
  font-size: 15px;
  font-weight: 600;
  -webkit-tap-highlight-color: transparent;
  transition: background var(--t), color var(--t), box-shadow var(--t);
}

.nav-button svg {
  width: 20px;
  height: 20px;
  flex: 0 0 20px;
  fill: none;
  stroke: currentColor;
  stroke-linecap: round;
  stroke-linejoin: round;
  stroke-width: 1.9;
}

.nav-button:hover {
  background: rgba(255,255,255,.65);
  color: var(--ink-2);
}

.nav-button:active:not(.active) {
  background: rgba(255,255,255,.4);
}

.nav-button.active {
  background: var(--surface);
  color: var(--ink);
  font-weight: 650;
  box-shadow: var(--shadow-sm);
}

/* ── Sidebar footer ─────────────────────────────────────── */

.sidebar-footer {
  display: none;
  padding-top: 10px;
  border-top: 1px solid var(--line-soft);
}

/* ── Content shell ──────────────────────────────────────── */

.content-shell {
  width: 100%;
  max-width: 1480px;
  margin: 0 auto;
  padding: 22px 18px 48px;
}

/* ── Page header ────────────────────────────────────────── */

.page-header {
  display: flex;
  flex-direction: column;
  gap: 14px;
  margin-bottom: 24px;
}

.eyebrow,
.section-label,
.metric-label {
  margin: 0;
  color: var(--muted);
  font-size: 11px;
  font-weight: 700;
  line-height: 1.3;
  letter-spacing: .06em;
  text-transform: uppercase;
}

.page-title {
  margin: 5px 0 0;
  font-size: clamp(28px, 7vw, 48px);
  font-weight: 780;
  line-height: .97;
  letter-spacing: -.025em;
}

.header-actions {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
}

/* ── Buttons ────────────────────────────────────────────── */

.primary-button,
.secondary-button,
.ghost-button,
.table-action,
.login-form button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  min-height: 40px;
  padding: 0 16px;
  border-radius: var(--r-sm);
  font-size: 14px;
  font-weight: 660;
  line-height: 1;
  text-decoration: none;
  white-space: nowrap;
  -webkit-tap-highlight-color: transparent;
  user-select: none;
  transition:
    background var(--t),
    border-color var(--t),
    box-shadow var(--t),
    transform var(--t),
    opacity var(--t);
}

.primary-button {
  border: 1.5px solid var(--accent);
  background: var(--accent);
  color: #fff;
  box-shadow: 0 1px 3px rgba(27,27,24,.18), 0 1px 1px rgba(27,27,24,.12);
}

.primary-button:hover {
  background: #2e2e2b;
  border-color: #2e2e2b;
  box-shadow: 0 2px 8px rgba(27,27,24,.22), 0 1px 2px rgba(27,27,24,.14);
}

.primary-button:active {
  background: #111110;
  border-color: #111110;
  transform: translateY(1px);
  box-shadow: 0 1px 2px rgba(27,27,24,.14);
}

.secondary-button {
  border: 1.5px solid var(--line);
  background: var(--surface);
  color: var(--ink-2);
  box-shadow: var(--shadow-xs);
}

.secondary-button:hover {
  background: var(--surface-soft);
  box-shadow: var(--shadow-sm);
}

.secondary-button:active {
  transform: translateY(1px);
  box-shadow: var(--shadow-xs);
}

.ghost-button {
  border: 1.5px solid var(--line-soft);
  background: transparent;
  color: var(--muted);
  font-size: 13.5px;
}

.ghost-button:hover {
  background: var(--surface-soft);
  border-color: var(--line);
  color: var(--ink-2);
}

.ghost-button:active {
  transform: translateY(1px);
}

.table-action {
  min-height: 30px;
  padding: 0 10px;
  border: 1.5px solid var(--line-soft);
  background: transparent;
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
  letter-spacing: .02em;
}

.table-action:hover {
  border-color: var(--line);
  background: var(--surface-soft);
  color: var(--ink-2);
}

.table-action:active {
  transform: translateY(1px);
}

/* Loading state */
.btn-loading {
  opacity: .6;
  pointer-events: none;
}

/* Focus ring */
button:focus-visible {
  outline: 2.5px solid var(--accent);
  outline-offset: 2px;
}

input:focus-visible {
  outline: none;
}

/* ── Toast notification ─────────────────────────────────── */

.toast {
  position: fixed;
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%) translateY(12px);
  z-index: 200;
  display: flex;
  align-items: flex-start;
  gap: 10px;
  max-width: min(480px, calc(100vw - 32px));
  width: max-content;
  padding: 13px 18px;
  border-radius: var(--r);
  background: var(--ink);
  color: #f5f4f0;
  font-size: 13.5px;
  line-height: 1.5;
  box-shadow: var(--shadow-lg);
  opacity: 0;
  pointer-events: none;
  overflow-wrap: anywhere;
  transition: opacity .22s ease, transform .22s ease;
}

.toast.toast-error {
  background: var(--danger);
}

.toast.toast-ok {
  background: var(--ok);
}

.toast.visible {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
  pointer-events: auto;
}

.message {
  display: none;
}

/* ── Form controls ──────────────────────────────────────── */

.control-input {
  min-height: 40px;
  width: 100%;
  min-width: 0;
  padding: 0 12px;
  border: 1.5px solid var(--line);
  border-radius: var(--r-sm);
  background: var(--surface);
  color: var(--ink);
  font-size: 14px;
  outline: 0;
  transition: border-color var(--t), box-shadow var(--t);
}

.control-input:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(27,27,24,.08);
}

.inline-form {
  display: flex;
  flex-direction: column;
  gap: 8px;
  width: 100%;
}

/* ── Cards / surfaces ───────────────────────────────────── */

.toolbar-card {
  display: flex;
  flex-direction: column;
  gap: 14px;
  justify-content: space-between;
  padding: 18px 20px;
  border: 1px solid var(--line-soft);
  border-radius: var(--r);
  background: var(--surface);
  box-shadow: var(--shadow-xs);
}

.section-copy {
  margin: 5px 0 0;
  color: var(--muted);
  font-size: 14px;
  line-height: 1.5;
}

/* ── Metric grid ────────────────────────────────────────── */

.metric-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: 12px;
}

.metric-card {
  min-width: 0;
  padding: 20px;
  border: 1px solid var(--line-soft);
  border-radius: var(--r);
  background: var(--surface);
  box-shadow: var(--shadow-xs);
}

.metric-value {
  margin-top: 10px;
  color: var(--accent);
  font-size: 38px;
  font-weight: 780;
  line-height: 1;
  letter-spacing: -.025em;
  overflow-wrap: anywhere;
}

/* ── Panel ──────────────────────────────────────────────── */

.panel {
  min-width: 0;
  padding: 20px;
  border: 1px solid var(--line-soft);
  border-radius: var(--r);
  background: var(--surface);
  box-shadow: var(--shadow-xs);
}

.panel-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 14px;
  margin-bottom: 18px;
}

/* ── Health indicators ──────────────────────────────────── */

.health-line {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
  margin-top: 8px;
  color: var(--muted);
  font-size: 13px;
}

.health-badge {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 2px 8px;
  border-radius: 99px;
  font-size: 12px;
  font-weight: 700;
}

.health-badge.ok   { background: #ecfaf2; color: var(--ok); }
.health-badge.bad  { background: #fdf2f1; color: var(--danger); }
.health-badge.warn { background: #fffbf0; color: var(--warn); }

.status-ok   { color: var(--ok);     font-weight: 720; }
.status-bad  { color: var(--danger); font-weight: 720; }
.status-warn { color: var(--warn);   font-weight: 720; }

/* ── Chart ──────────────────────────────────────────────── */

.chart {
  display: flex;
  align-items: flex-end;
  gap: 3px;
  height: 210px;
  padding: 12px 12px 0;
  border: 1px solid var(--line-soft);
  border-radius: var(--r-sm);
  background:
    repeating-linear-gradient(
      to bottom,
      var(--line-soft) 0,
      var(--line-soft) 1px,
      transparent 1px,
      transparent 25%
    ),
    var(--surface-soft);
  overflow: hidden;
}

.bar {
  display: flex;
  flex: 1 1 0;
  min-width: 4px;
  flex-direction: column;
  justify-content: flex-end;
  gap: 2px;
  cursor: default;
  transition: opacity var(--t);
}

.bar:hover {
  opacity: .72;
}

.bar .calls,
.bar .errors {
  min-height: 1px;
  border-radius: 3px 3px 0 0;
}

.bar .calls  { background: var(--accent-2); }
.bar .errors { background: var(--danger); }

/* ── Table ──────────────────────────────────────────────── */

.table-shell {
  width: 100%;
  overflow-x: auto;
  border: 1px solid var(--line-soft);
  border-radius: var(--r);
  background: var(--surface);
  box-shadow: var(--shadow-xs);
}

table {
  width: 100%;
  min-width: 700px;
  border-collapse: collapse;
}

th {
  padding: 11px 16px;
  border-bottom: 1px solid var(--line-soft);
  text-align: left;
  background: var(--surface-soft);
  color: var(--muted);
  font-size: 11px;
  font-weight: 700;
  letter-spacing: .06em;
  text-transform: uppercase;
  white-space: nowrap;
}

td {
  padding: 13px 16px;
  border-bottom: 1px solid var(--line-soft);
  text-align: left;
  vertical-align: top;
  max-width: 300px;
  overflow-wrap: anywhere;
  color: var(--ink-2);
  font-size: 13.5px;
  line-height: 1.45;
}

tbody tr {
  transition: background var(--t);
}

tbody tr:hover {
  background: var(--surface-soft);
}

tbody tr:last-child td {
  border-bottom: 0;
}

.empty-cell {
  padding: 40px 16px !important;
  text-align: center !important;
  max-width: none !important;
  color: var(--faint);
  font-size: 14px;
}

/* ── Log detail panel ───────────────────────────────────── */

.log-detail {
  border: 1px solid var(--line-soft);
  border-radius: var(--r);
  overflow: hidden;
  box-shadow: var(--shadow-xs);
}

.log-detail-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 16px;
  border-bottom: 1px solid var(--line-soft);
  background: var(--surface-soft);
}

.log-detail-title {
  font-size: 12px;
  font-weight: 700;
  color: var(--muted);
  letter-spacing: .05em;
  text-transform: uppercase;
}

.log-detail pre {
  margin: 0;
  border-radius: 0;
  border: 0;
  box-shadow: none;
}

/* ── Tabs ───────────────────────────────────────────────── */

.tabs {
  display: inline-flex;
  gap: 3px;
  padding: 4px;
  border: 1px solid var(--line-soft);
  border-radius: var(--r-sm);
  background: var(--surface-muted);
}

.tab-button {
  min-height: 34px;
  padding: 0 14px;
  border-radius: 6px;
  background: transparent;
  color: var(--muted);
  font-size: 13.5px;
  font-weight: 650;
  transition: background var(--t), color var(--t), box-shadow var(--t);
}

.tab-button:hover {
  color: var(--ink-2);
}

.tab-button.active {
  background: var(--surface);
  color: var(--ink);
  box-shadow: var(--shadow-xs);
}

/* ── Code panel ─────────────────────────────────────────── */

pre {
  margin: 0;
  padding: 20px;
  overflow: auto;
  max-height: 65vh;
  border: 1px solid var(--line-soft);
  border-radius: var(--r);
  background: #1e1e1c;
  color: #e6e4de;
  font-family: ui-monospace, "SF Mono", SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 12.5px;
  line-height: 1.65;
  white-space: pre-wrap;
  box-shadow: var(--shadow-xs);
}

/* ── Login ──────────────────────────────────────────────── */

.login-shell {
  width: min(400px, calc(100vw - 32px));
  margin: min(13vh, 90px) auto;
  padding: 28px;
  border: 1px solid var(--line-soft);
  border-radius: var(--r);
  background: var(--surface);
  box-shadow: var(--shadow);
}

.login-brand {
  margin-bottom: 28px;
  justify-content: center;
  overflow: hidden;
}

.login-form {
  display: grid;
  gap: 10px;
}

.login-form label {
  margin-top: 4px;
  color: var(--muted);
  font-size: 11px;
  font-weight: 700;
  letter-spacing: .06em;
  text-transform: uppercase;
}

.login-form input {
  min-height: 44px;
  width: 100%;
  padding: 0 14px;
  border: 1.5px solid var(--line);
  border-radius: var(--r-sm);
  background: var(--surface);
  color: var(--ink);
  font-size: 15px;
  outline: 0;
  transition: border-color var(--t), box-shadow var(--t);
}

.login-form input:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(27,27,24,.08);
}

.login-form button {
  margin-top: 10px;
  height: 46px;
  border: 1.5px solid var(--accent);
  background: var(--accent);
  color: #fff;
  border-radius: var(--r-sm);
  font-size: 15px;
  font-weight: 700;
  box-shadow: 0 1px 4px rgba(27,27,24,.18);
  transition: background var(--t), box-shadow var(--t), transform var(--t);
}

.login-form button:hover {
  background: #2e2e2b;
  border-color: #2e2e2b;
  box-shadow: 0 2px 8px rgba(27,27,24,.22);
}

.login-form button:active {
  transform: translateY(1px);
  box-shadow: 0 1px 2px rgba(27,27,24,.14);
}

.error {
  min-height: 20px;
  color: var(--danger);
  font-size: 13px;
  line-height: 1.45;
}

/* ── Responsive: tablet ─────────────────────────────────── */

@media (min-width: 640px) {
  .toolbar-card {
    flex-direction: row;
    align-items: center;
  }

  .inline-form {
    width: auto;
    flex-direction: row;
    align-items: center;
  }

  .inline-form .control-input {
    min-width: 220px;
  }

  .metric-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}

/* ── Responsive: desktop ────────────────────────────────── */

@media (min-width: 1024px) {
  .lg\:flex {
    display: flex;
  }

  .sidebar {
    position: fixed;
    inset: 0 auto 0 0;
    width: 272px;
    gap: 20px;
    padding: 28px 18px;
    border-right: 1px solid var(--line-soft);
    border-bottom: 0;
    overflow-y: auto;
    background: var(--canvas);
    backdrop-filter: none;
    -webkit-backdrop-filter: none;
    border-right: 0;
  }

  .sidebar-search kbd {
    display: inline-block;
  }

  .nav-list {
    display: grid;
    gap: 3px;
    overflow: visible;
    padding-bottom: 0;
  }

  .nav-button {
    width: 100%;
    justify-content: flex-start;
    min-height: 50px;
    padding: 0 14px;
    gap: 12px;
  }

  .sidebar-footer {
    display: block;
    margin-top: auto;
  }

  .ghost-button {
    width: 100%;
  }

  .content-shell {
    margin-left: 272px;
    padding: 36px 40px 64px;
  }

  .page-header {
    flex-direction: row;
    align-items: flex-start;
    justify-content: space-between;
  }

  .header-actions {
    justify-content: flex-end;
    flex-shrink: 0;
  }

  .metric-grid {
    grid-template-columns: repeat(4, minmax(0, 1fr));
  }
}
