:root {
  --bg-base: #f5f5f4;
  --bg-surface: #ffffff;
  --bg-subtle: #efefed;
  --bg-strong: #111110;
  --text-primary: #111110;
  --text-secondary: #6b6b68;
  --text-muted: #a8a8a4;
  --accent-primary: #111110;
  --accent-inverse: #ffffff;
  --status-ok: #2d7d4f;
  --status-warn: #b45309;
  --status-danger: #b91c1c;
  --status-neutral: #6b6b68;
  --status-ok-bg: #ecfdf5;
  --status-warn-bg: #fffbeb;
  --status-danger-bg: #fef2f2;
  --border: #e4e4e1;
  --border-strong: #c9c9c5;
  --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.05);
  --shadow-md: 0 2px 6px rgba(0, 0, 0, 0.07);
  --radius: 3px;
  --content-max: 1480px;
  --sidebar-width: 220px;
  --topbar-height: 48px;
}

* {
  box-sizing: border-box;
}

html {
  scroll-behavior: smooth;
  overflow-x: hidden;
}

body {
  margin: 0;
  min-width: 320px;
  background: var(--bg-base);
  color: var(--text-primary);
  font-family: 'Poppins', sans-serif;
  font-size: 13px;
  line-height: 1.5;
  overflow-x: hidden;
  position: relative;
}

button,
input,
textarea,
select {
  font: inherit;
}

button {
  cursor: pointer;
}

button:disabled {
  cursor: not-allowed;
  opacity: 0.6;
}

button,
a {
  transition: all 0.15s ease;
}

a {
  color: inherit;
}

h1,
h2,
h3,
h4,
h5,
h6,
p {
  margin: 0;
}

small {
  font-size: 11px;
}

code,
pre {
  font-family: 'Consolas', 'Courier New', monospace;
}

.app-shell {
  width: calc(100% - 32px);
  margin: 16px auto;
  display: block;
  min-height: calc(100vh - 32px);
  padding-bottom: 92px;
  position: relative;
}

.sidebar {
  position: fixed;
  top: 16px;
  left: 16px;
  width: var(--sidebar-width);
  height: calc(100vh - 32px);
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-sm);
  padding: 16px 12px;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  gap: 16px;
  z-index: 100;
  overflow-y: auto;
}

.sidebar::-webkit-scrollbar {
  width: 4px;
}

.sidebar::-webkit-scrollbar-track {
  background: transparent;
}

.sidebar::-webkit-scrollbar-thumb {
  background: var(--border-strong);
  border-radius: 4px;
}

.sidebar__top {
  display: grid;
  gap: 14px;
}

.brand-block {
  display: grid;
  grid-template-columns: 38px minmax(0, 1fr);
  gap: 10px;
  align-items: start;
}

.brand-mark {
  width: 38px;
  height: 38px;
  display: grid;
  place-items: center;
  border-radius: var(--radius);
  background: var(--accent-primary);
  color: var(--accent-inverse);
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0.08em;
}

.brand-copy-block h1 {
  margin-top: 3px;
  font-size: 18px;
  line-height: 1.2;
  font-weight: 600;
}

.brand-copy,
.topbar-copy,
.sidebar-meta__text,
.muted,
.section-lead {
  color: var(--text-secondary);
}

.brand-copy,
.sidebar-meta__text,
.topbar-copy,
.section-lead {
  margin-top: 6px;
  font-size: 12px;
  line-height: 1.6;
}

.eyebrow {
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--text-muted);
}

.sidebar-meta,
.sidebar-user-card {
  background: var(--bg-subtle);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 10px;
}

.sidebar-user-card strong {
  display: block;
  margin-top: 4px;
  font-size: 13px;
  font-weight: 600;
  color: var(--text-primary);
}

.sidebar-user-card .muted {
  display: block;
  margin-top: 6px;
  font-size: 11px;
}

.nav-group {
  display: grid;
  gap: 6px;
}

.tab-btn {
  width: 100%;
  min-height: 38px;
  padding: 6px 10px;
  border: 1px solid transparent;
  border-radius: var(--radius);
  background: transparent;
  color: var(--text-secondary);
  display: flex;
  align-items: center;
  gap: 8px;
  text-align: left;
}

.tab-btn:hover {
  background: var(--bg-subtle);
  color: var(--text-primary);
}

.tab-btn.active {
  background: var(--accent-primary);
  border-color: var(--accent-primary);
  color: var(--accent-inverse);
}

.tab-btn__icon {
  width: 18px;
  min-width: 18px;
  text-align: center;
  font-size: 12px;
  line-height: 1;
}

.tab-btn__text,
.tab-btn__label {
  display: block;
  font-size: 12px;
  font-weight: 500;
  line-height: 1.2;
}

.sidebar-footer {
  display: grid;
  gap: 10px;
}

button,
.button-link {
  min-height: 34px;
  padding: 7px 12px;
  border-radius: var(--radius);
  border: 1px solid var(--accent-primary);
  background: var(--accent-primary);
  color: var(--accent-inverse);
  font-size: 12px;
  font-weight: 500;
  box-shadow: none;
}

button:hover,
.button-link:hover {
  opacity: 0.92;
}

.secondary,
button.secondary {
  background: var(--bg-surface);
  color: var(--text-primary);
  border-color: var(--border-strong);
}

.secondary:hover,
button.secondary:hover {
  background: var(--bg-subtle);
}

.danger,
button.danger {
  background: var(--status-danger);
  border-color: var(--status-danger);
  color: #fff;
}

.success,
button.success {
  background: var(--status-ok);
  border-color: var(--status-ok);
  color: #fff;
}

.button-block {
  width: 100%;
}

.main-shell {
  min-width: 0;
  max-width: 100%;
  overflow-x: hidden;
  margin-left: calc(var(--sidebar-width) + 16px);
}

.topbar {
  min-height: var(--topbar-height);
  padding: 12px 16px;
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-sm);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
}

.topbar__intro {
  display: grid;
  gap: 10px;
}

.topbar__context-pill {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  width: fit-content;
  min-height: 28px;
  padding: 4px 10px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--bg-surface);
  color: var(--text-secondary);
  font-size: 11px;
  font-weight: 500;
}

.topbar__context-dot,
.status-chip__dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--status-ok);
}

.topbar h2 {
  margin-top: 4px;
  font-size: clamp(22px, 2vw, 28px);
  line-height: 1.15;
  font-weight: 600;
  color: var(--text-primary);
}

.topbar-actions {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 8px;
  flex-wrap: wrap;
}

.status-chip {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  min-height: 34px;
  padding: 6px 10px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--bg-surface);
  color: var(--text-primary);
  font-size: 12px;
}

.content {
  margin-top: 16px;
  display: grid;
  gap: 16px;
  min-width: 0;
}

.tab-panel {
  display: none;
}

.tab-panel.active {
  display: block;
}

.panel-group,
.grid-2,
.grid-3,
.grid-4,
.stats-grid,
.metrics-grid,
.kpi-strip,
.info-grid,
.section-grid,
.docs-grid,
.dashboard-grid,
.hero-metrics,
.summary-grid,
.stack-form,
.form-grid,
.filters-grid,
.login-hero__grid,
.meta-list {
  display: grid;
  gap: 12px;
  min-width: 0;
}

.grid-2,
.section-grid,
.docs-grid,
.split-layout {
  grid-template-columns: repeat(2, minmax(0, 1fr));
}

.grid-3,
.metrics-grid,
.kpi-strip,
.summary-grid {
  grid-template-columns: repeat(3, minmax(0, 1fr));
}

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

.card,
.metric-tile,
.stat-tile,
.info-tile,
.data-tile,
.surface-note,
.summary-tile,
.overview-stat,
.info-band,
.helper-band,
.notice-band,
.hero-card {
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-sm);
  color: var(--text-primary);
  min-width: 0;
  max-width: 100%;
}

.card,
.hero-card {
  padding: 18px;
}

.metric-tile,
.stat-tile,
.info-tile,
.data-tile,
.surface-note,
.summary-tile,
.overview-stat,
.info-band,
.helper-band,
.notice-band {
  padding: 14px;
}

.card:hover,
.metric-tile:hover,
.stat-tile:hover,
.info-tile:hover,
.data-tile:hover,
.surface-note:hover,
.summary-tile:hover,
.overview-stat:hover,
.hero-card:hover {
  border-color: var(--border-strong);
  box-shadow: var(--shadow-md);
}

.hero-card {
  background: var(--bg-strong);
  border-color: var(--bg-strong);
  color: var(--accent-inverse);
}

.hero-card p,
.hero-card .muted,
.hero-card small,
.hero-card .metric-tile__label,
.hero-card .overview-stat__label,
.hero-card .summary-tile__label {
  color: rgba(255, 255, 255, 0.72);
}

.hero-card__layout {
  display: grid;
  grid-template-columns: minmax(0, 1.5fr) minmax(220px, 0.85fr);
  gap: 12px;
  align-items: stretch;
}

.hero-card h3 {
  margin-top: 8px;
  font-size: clamp(22px, 2.2vw, 30px);
  line-height: 1.15;
  font-weight: 600;
}

.hero-card__actions,
.actions,
.badge-row,
.inline-metrics {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

.hero-card__actions {
  margin-top: 14px;
}

.metric-tile__label,
.stat-tile__label,
.info-tile__kicker,
.summary-tile__label,
.overview-stat__label {
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--text-muted);
}

.metric-tile strong,
.stat-tile strong,
.summary-tile strong,
.overview-stat strong,
.big-number,
.metric-value {
  display: block;
  margin-top: 8px;
  font-size: clamp(22px, 2vw, 30px);
  line-height: 1.1;
  font-weight: 600;
  color: var(--text-primary);
  word-break: break-all;
}

.hero-card .metric-tile {
  background: rgba(255, 255, 255, 0.08) !important;
  border-color: rgba(255, 255, 255, 0.14) !important;
  color: #fff !important;
  box-shadow: none;
}

.hero-card .metric-tile strong,
.hero-card .metric-tile small,
.hero-card .metric-tile span {
  color: #fff !important;
}

.surface-note--soft,
.info-band,
.helper-band,
.notice-band,
.pagination-shell {
  background: var(--bg-subtle);
}

.notice-band.warning {
  background: var(--status-warn-bg);
}

.section-header,
.card-header,
.table-header,
.split-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
}

.section-header + .section-grid,
.card-header + .table-wrap,
.table-header + .table-wrap,
.section-header + .muted,
.card-header + .muted {
  margin-top: 12px;
}

.section-header h3,
.card-header h3,
.table-header h3,
.login-card__header h2 {
  margin-top: 4px;
  font-size: 18px;
  line-height: 1.25;
  font-weight: 600;
  color: var(--text-primary);
}

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

.filters-grid {
  grid-template-columns: repeat(4, minmax(0, 1fr));
  align-items: end;
}

.form-field,
.input-group {
  display: grid;
  gap: 6px;
}

label {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  color: var(--text-primary);
  font-size: 12px;
  font-weight: 500;
}

input,
textarea,
select {
  width: 100%;
  padding: 8px 10px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--bg-surface);
  color: var(--text-primary);
  outline: none;
}

textarea {
  min-height: 124px;
  resize: vertical;
}

input::placeholder,
textarea::placeholder {
  color: var(--text-muted);
}

input:focus,
textarea:focus,
select:focus {
  border-color: var(--accent-primary);
  box-shadow: 0 0 0 2px rgba(17, 17, 16, 0.08);
}

.checkbox-inline {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

.checkbox-inline input[type='checkbox'] {
  width: 14px;
  height: 14px;
  margin: 0;
  box-shadow: none;
}

.table-wrap,
.modal-scroll {
  width: 100%;
  max-width: 100%;
  overflow-x: auto;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--bg-surface);
  -webkit-overflow-scrolling: touch;
}

.table-wrap table,
.modal-scroll table,
table {
  width: 100%;
  min-width: max-content;
  border-collapse: collapse;
}

th,
td {
  padding: 12px 10px;
  text-align: left;
  vertical-align: top;
  border-bottom: 1px solid var(--border);
  color: var(--text-primary);
  font-size: 12px;
}

th {
  position: sticky;
  top: 0;
  z-index: 1;
  background: var(--bg-surface);
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--text-muted);
}

tbody tr:hover {
  background: var(--bg-subtle);
}

.pill {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  min-height: 24px;
  padding: 3px 8px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--bg-subtle);
  color: var(--text-secondary);
  font-size: 11px;
  font-weight: 500;
}

.pill--success {
  background: #ecf8f0;
  color: #2f6b45;
  border-color: #cfe7d6;
}

.pill--warning {
  background: #fff4e8;
  color: #a85a18;
  border-color: #f2d7bf;
}

pre {
  margin: 0;
  padding: 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: #fafaf9;
  color: var(--text-primary);
  white-space: pre-wrap;
  word-break: break-all;
  overflow-x: auto;
  min-width: 0;
  max-width: 100%;
}

.docs-grid .card {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.docs-page {
  gap: 20px;
}

.docs-hero {
  overflow: hidden;
}

.docs-summary {
  display: grid;
  gap: 16px;
}

.docs-inline-metrics {
  align-items: stretch;
}

.docs-card {
  position: relative;
  overflow: hidden;
}

.docs-card--highlight {
  border-color: rgba(22, 163, 74, 0.24);
  box-shadow: 0 20px 45px rgba(22, 163, 74, 0.08);
}

.docs-grid pre {
  flex: 1 1 auto;
}

.chart-surface {
  width: 100%;
  height: 420px;
  min-height: 320px;
}

.inline-filter-form {
  display: flex;
  align-items: end;
  justify-content: flex-end;
  gap: 8px;
  flex-wrap: wrap;
}

.form-field--compact {
  min-width: 220px;
}

.table-header--filters {
  align-items: flex-start;
}

.log-date-cell {
  display: grid;
  gap: 2px;
  min-width: 92px;
}

.log-date-cell strong {
  font-size: 12px;
  font-weight: 600;
  line-height: 1.2;
}

.log-date-cell small {
  color: var(--text-secondary);
  font-size: 11px;
  line-height: 1.2;
}

.log-message-cell {
  max-width: 320px;
  white-space: normal;
  word-break: break-word;
  line-height: 1.45;
}

.login-body {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 16px;
}

.login-shell {
  width: 100%;
  max-width: 1020px;
  display: grid;
  grid-template-columns: minmax(0, 1.15fr) minmax(0, 400px);
  gap: 16px;
  align-items: stretch;
}

.login-hero {
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-sm);
  padding: 24px;
  display: grid;
  align-content: space-between;
  gap: 18px;
}

.login-hero h1 {
  margin-top: 8px;
  font-size: clamp(24px, 3vw, 34px);
  line-height: 1.2;
  font-weight: 600;
}

.login-hero p {
  margin-top: 8px;
  color: var(--text-secondary);
}

.login-card {
  width: 100%;
}

.login-card--enhanced {
  display: flex;
  flex-direction: column;
  justify-content: center;
}

.login-card__header .muted {
  margin-top: 8px;
}

.message {
  margin-top: 12px;
  min-height: 42px;
  display: flex;
  align-items: center;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--bg-subtle);
  color: var(--text-primary);
}

.modal-overlay {
  position: fixed;
  inset: 0;
  z-index: 9999;
  display: none;
  align-items: center;
  justify-content: center;
  padding: 16px;
  background: rgba(17, 17, 16, 0.38);
}

.modal-overlay.open {
  display: flex;
}

.modal-card {
  width: 100%;
  max-width: 1100px;
  max-height: min(92vh, 860px);
  overflow: hidden;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--bg-surface);
  color: var(--text-primary);
  box-shadow: var(--shadow-md);
  padding: 16px;
  display: flex;
  flex-direction: column;
}

.bulk-delete-modal {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.bulk-delete-modal__header,
.bulk-delete-modal__footer {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 10px;
  flex-wrap: wrap;
}

.bulk-delete-modal__body {
  display: flex;
  flex-direction: column;
  gap: 12px;
  min-height: 0;
}

.bulk-delete-modal__list {
  flex: 1 1 auto;
  min-height: 0;
}

.bulk-delete-modal__list--compact {
  max-height: 150px;
}

.json-hme-input {
  max-height: 300px;
  min-height: 220px;
  font-family: 'Consolas', 'Courier New', monospace;
}

.mobile-nav {
  position: fixed;
  left: 8px;
  right: 8px;
  bottom: 8px;
  z-index: 9500;
  display: none;
  grid-template-columns: repeat(6, minmax(0, 1fr));
  gap: 6px;
  padding: 6px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: rgba(255, 255, 255, 0.96);
  box-shadow: var(--shadow-md);
}

.mobile-nav .tab-btn {
  min-height: 52px;
  justify-content: center;
  flex-direction: column;
  gap: 4px;
  text-align: center;
  padding: 6px 4px;
}

.mobile-nav .tab-btn__label {
  width: 100%;
  font-size: 10px;
  font-weight: 500;
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

@media (max-width: 1279px) {
  .grid-4,
  .stats-grid,
  .info-grid,
  .filters-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .hero-card__layout,
  .login-shell,
  .split-layout {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 920px) {
  .app-shell {
    width: calc(100% - 20px);
    max-width: 100%;
    margin: 10px auto;
    padding-bottom: 88px;
    overflow-x: hidden;
  }

  .sidebar {
    position: static;
    top: auto;
    left: auto;
    right: auto;
    width: auto;
    height: auto;
    min-height: auto;
    overflow-y: visible;
  }

  .main-shell {
    margin-left: 0;
    max-width: 100%;
  }

  .desktop-nav,
  .sidebar-footer {
    display: none;
  }

  .mobile-nav {
    display: grid;
    width: auto;
    max-width: calc(100vw - 16px);
  }

  .grid-2,
  .grid-3,
  .grid-4,
  .stats-grid,
  .metrics-grid,
  .kpi-strip,
  .info-grid,
  .section-grid,
  .docs-grid,
  .dashboard-grid,
  .hero-metrics,
  .summary-grid,
  .form-grid,
  .filters-grid,
  .split-layout,
  .login-hero__grid {
    grid-template-columns: 1fr;
  }

  .topbar,
  .topbar-actions,
  .section-header,
  .card-header,
  .table-header,
  .split-header,
  .surface-note,
  .bulk-delete-modal__footer {
    align-items: stretch;
  }

  .topbar,
  .topbar-actions,
  .section-header,
  .card-header,
  .table-header,
  .split-header,
  .surface-note,
  .bulk-delete-modal__footer {
    flex-direction: column;
  }

  .inline-filter-form,
  .table-header--filters {
    width: 100%;
  }

  .inline-filter-form {
    justify-content: stretch;
    flex-direction: column;
  }

  .form-field--compact,
  .chart-surface,
  .log-message-cell {
    min-width: 0;
    max-width: 100%;
  }

  .actions,
  .hero-card__actions {
    width: 100%;
  }

  .actions > button,
  .actions > .secondary,
  .hero-card__actions > button,
  .hero-card__actions > .secondary {
    flex: 1 1 auto;
  }

  .inline-filter-form,
  .table-header--filters {
    width: 100%;
  }

  .inline-filter-form {
    justify-content: stretch;
    flex-direction: column;
  }

  .form-field--compact,
  .chart-surface,
  .log-message-cell {
    min-width: 0;
    max-width: 100%;
  }
}

@media (max-width: 640px) {
  .app-shell {
    width: 100%;
    margin: 8px auto;
    padding: 0 10px;
    box-sizing: border-box;
  }

  .sidebar,
  .topbar,
  .hero-card,
  .card,
  .login-hero,
  .modal-card {
    padding: 14px;
    max-width: 100%;
  }

  .brand-block {
    grid-template-columns: 34px minmax(0, 1fr);
  }

  .brand-mark {
    width: 34px;
    height: 34px;
  }

  th,
  td {
    padding: 10px 8px;
  }

  .chart-surface {
    height: 320px;
    min-height: 260px;
  }
}
