:root {
  color-scheme: dark;
  --bg: #050505;
  --surface-1: #0d0d0d;
  --surface-2: #151515;
  --surface-3: #1f1f1f;
  --surface-4: #262626;
  --border: #2a2a2a;
  --border-strong: #3a3a3a;
  --text: #f5f5f5;
  --text-muted: #a3a3a3;
  --text-subtle: #737373;
  --text-inverse: #050505;
  --action: #ffffff;
  --action-text: #050505;
  --focus: #f5f5f5;
  --shadow: 0 24px 80px rgba(0, 0, 0, 0.42);
  --radius: 8px;
  --radius-sm: 6px;
  --space-1: 4px;
  --space-2: 8px;
  --space-3: 12px;
  --space-4: 16px;
  --space-5: 20px;
  --space-6: 24px;
  --space-8: 32px;
  --space-10: 40px;
  --sidebar-width: 268px;
  --content-max: 1440px;
}

* {
  box-sizing: border-box;
}

html {
  background: var(--bg);
  min-width: 320px;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  font-size: 15px;
  line-height: 1.5;
  overflow-x: hidden;
}

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

a:hover {
  color: var(--text-muted);
}

:focus-visible {
  outline: 2px solid var(--focus);
  outline-offset: 3px;
}

h1,
h2,
h3,
p {
  margin-top: 0;
}

h1,
.page-title {
  font-size: clamp(2rem, 4vw, 3.5rem);
  line-height: 0.95;
  letter-spacing: 0;
  margin-bottom: var(--space-3);
}

h2 {
  font-size: 1.35rem;
  line-height: 1.2;
}

h3 {
  font-size: 1rem;
  color: var(--text);
  margin-bottom: var(--space-3);
}

code,
pre,
.mono {
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", monospace;
}

code {
  display: inline-block;
  max-width: 100%;
  padding: 2px 6px;
  border-radius: var(--radius-sm);
  background: #000000;
  color: var(--text);
  overflow-wrap: anywhere;
}

pre {
  max-width: 100%;
  padding: var(--space-4);
  overflow: auto;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: #000000;
}

.skip-link {
  position: absolute;
  left: var(--space-4);
  top: -80px;
  z-index: 100;
  padding: var(--space-2) var(--space-3);
  border-radius: var(--radius-sm);
  background: var(--action);
  color: var(--action-text);
}

.skip-link:focus {
  top: var(--space-4);
}

.app-shell {
  min-height: 100vh;
}

.app-topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  justify-content: space-between;
  min-height: 56px;
  padding: var(--space-3) var(--space-6);
  border-bottom: 1px solid var(--border);
  background: rgba(13, 13, 13, 0.96);
  backdrop-filter: blur(12px);
}

.brand {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  min-width: 0;
  font-weight: 760;
}

.brand-mark {
  display: grid;
  width: 34px;
  height: 34px;
  place-items: center;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius);
  background: var(--text);
  color: var(--text-inverse);
  font-size: 0.8rem;
  letter-spacing: 0;
}

.brand-name {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.topbar-meta {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  min-width: 0;
  color: var(--text-muted);
  font-size: 0.9rem;
}

.topbar-logout {
  min-height: 34px;
  padding: 7px 10px;
}

.app-body {
  display: grid;
  grid-template-columns: var(--sidebar-width) minmax(0, 1fr);
  min-height: calc(100vh - 56px);
}

.app-body--public {
  display: block;
}

.app-sidebar {
  position: sticky;
  top: 56px;
  align-self: start;
  height: calc(100vh - 56px);
  padding: var(--space-5);
  overflow-y: auto;
  border-right: 1px solid var(--border);
  background: var(--surface-1);
}

.nav-group + .nav-group {
  margin-top: var(--space-6);
}

.nav-heading {
  margin-bottom: var(--space-2);
  color: var(--text-subtle);
  font-size: 0.72rem;
  font-weight: 760;
  letter-spacing: 0;
  text-transform: uppercase;
}

.nav-link {
  display: flex;
  align-items: center;
  min-height: 38px;
  margin: 2px 0;
  padding: 8px 10px;
  border: 1px solid transparent;
  border-radius: var(--radius-sm);
  color: var(--text-muted);
}

.nav-link:hover {
  border-color: var(--border);
  background: var(--surface-2);
  color: var(--text);
}

.nav-link.is-active {
  border-color: var(--border-strong);
  background: var(--text);
  color: var(--text-inverse);
}

.sidebar-footer {
  margin-top: var(--space-8);
  padding-top: var(--space-5);
  border-top: 1px solid var(--border);
}

.app-main {
  min-width: 0;
  padding: clamp(24px, 4vw, 56px);
}

.content-frame {
  width: min(100%, var(--content-max));
}

.page-header {
  display: flex;
  align-items: end;
  justify-content: space-between;
  gap: var(--space-5);
  margin-bottom: var(--space-6);
}

.page-header > *,
.panel,
.panel-header > *,
.panel-body,
.list-row,
.empty-state {
  min-width: 0;
}

.page-kicker,
.page-subtitle,
.muted {
  color: var(--text-muted);
}

.page-kicker {
  margin-bottom: var(--space-2);
  font-size: 0.78rem;
  font-weight: 760;
  text-transform: uppercase;
}

.page-subtitle {
  max-width: 760px;
  margin-bottom: 0;
  overflow-wrap: anywhere;
}

.page-actions,
.actions {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-2);
  align-items: center;
}

.panel {
  margin-bottom: var(--space-5);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface-2);
}

.panel-header {
  display: flex;
  align-items: start;
  justify-content: space-between;
  gap: var(--space-4);
  padding: var(--space-5) var(--space-5) 0;
}

.panel-body {
  padding: var(--space-5);
}

.panel-title {
  margin-bottom: var(--space-1);
}

.panel-subtitle {
  margin-bottom: 0;
  color: var(--text-muted);
  overflow-wrap: anywhere;
}

.metric-grid,
.dashboard-grid,
.detail-grid {
  display: grid;
  gap: var(--space-4);
}

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

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

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

.metric {
  min-width: 0;
  padding: var(--space-4);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface-1);
}

.metric-label,
.detail-label {
  margin-bottom: var(--space-1);
  color: var(--text-subtle);
  font-size: 0.78rem;
  font-weight: 760;
  text-transform: uppercase;
}

.metric-value,
.detail-value {
  overflow-wrap: anywhere;
  font-size: 1.05rem;
  font-weight: 700;
}

.button,
button,
input[type="submit"] {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 40px;
  max-width: 100%;
  padding: 9px 14px;
  border: 1px solid var(--action);
  border-radius: var(--radius-sm);
  background: var(--action);
  color: var(--action-text);
  cursor: pointer;
  font: inherit;
  font-weight: 720;
  line-height: 1.2;
  text-align: center;
  white-space: normal;
}

.button:hover,
button:hover,
input[type="submit"]:hover {
  background: var(--text-muted);
  border-color: var(--text-muted);
  color: var(--text-inverse);
}

.button--secondary {
  background: transparent;
  color: var(--text);
  border-color: var(--border-strong);
}

.button--secondary:hover {
  background: var(--surface-3);
  color: var(--text);
}

.button--ghost {
  min-height: auto;
  padding: 0;
  border-color: transparent;
  background: transparent;
  color: var(--text);
}

.button--danger,
.danger {
  border-color: var(--text);
  background: var(--text);
  color: var(--text-inverse);
  box-shadow: inset 0 0 0 2px var(--text-inverse);
}

.button_to {
  display: inline;
}

.button_to .button,
.button_to input[type="submit"] {
  width: auto;
}

.badge {
  display: inline-flex;
  align-items: center;
  min-height: 24px;
  max-width: 100%;
  padding: 3px 8px;
  border: 1px solid var(--border-strong);
  border-radius: 999px;
  background: var(--surface-1);
  color: var(--text-muted);
  font-size: 0.78rem;
  font-weight: 760;
  line-height: 1.2;
  text-transform: uppercase;
}

.badge--strong {
  background: var(--text);
  color: var(--text-inverse);
}

.badge--danger {
  border-color: var(--text);
  color: var(--text);
}

.badge--muted {
  color: var(--text-muted);
}

.table-wrap {
  width: 100%;
  overflow-x: auto;
  border: 1px solid var(--border);
  border-radius: var(--radius);
}

.table-wrap table,
.data-table {
  width: 100%;
  border-collapse: collapse;
}

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

th {
  color: var(--text);
  font-size: 0.78rem;
  font-weight: 760;
  text-transform: uppercase;
}

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

.table-actions {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-2);
}

.mobile-list {
  display: none;
}

.list-row {
  padding: var(--space-4);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface-1);
}

.list-row + .list-row {
  margin-top: var(--space-3);
}

.list-row-title {
  margin-bottom: var(--space-2);
  font-weight: 760;
}

.list-row-meta {
  display: grid;
  gap: var(--space-2);
  color: var(--text-muted);
}

.form {
  display: grid;
  gap: var(--space-5);
}

.form-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: var(--space-4);
}

.field {
  min-width: 0;
}

label,
.field-label {
  display: block;
  margin-bottom: 7px;
  color: var(--text);
  font-weight: 680;
}

input:not([type="checkbox"]):not([type="radio"]):not([type="submit"]),
select,
textarea {
  width: 100%;
  min-height: 42px;
  padding: 10px 12px;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  background: #000000;
  color: var(--text);
  font: inherit;
}

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

input[type="checkbox"] {
  width: 18px;
  height: 18px;
  accent-color: var(--text);
}

.checkbox-row {
  display: flex;
  align-items: start;
  gap: var(--space-3);
  min-height: 44px;
  padding: var(--space-3);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface-1);
}

.checkbox-row label {
  margin-bottom: 0;
}

.form-actions {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-2);
  align-items: center;
}

.form-errors {
  padding: var(--space-4);
  border: 1px solid var(--text);
  border-radius: var(--radius);
  background: var(--surface-1);
}

.form-errors-title {
  margin-bottom: var(--space-2);
  font-weight: 760;
}

.section-nav {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-2);
  margin-bottom: var(--space-5);
}

.section-nav a {
  padding: 8px 10px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text-muted);
}

.section-nav a:hover,
.section-nav a.is-active {
  border-color: var(--text);
  background: var(--text);
  color: var(--text-inverse);
}

.flash-stack {
  display: grid;
  gap: var(--space-3);
  margin-bottom: var(--space-5);
}

.flash {
  padding: var(--space-3) var(--space-4);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius);
  background: var(--surface-2);
  color: var(--text);
}

.flash--alert {
  border-color: var(--text);
}

.empty-state {
  padding: var(--space-5);
  border: 1px dashed var(--border-strong);
  border-radius: var(--radius);
  color: var(--text-muted);
  text-align: center;
}

.danger-zone {
  padding: var(--space-5);
  border: 1px solid var(--text);
  border-radius: var(--radius);
  background: #000000;
}

.danger-zone-title {
  margin-bottom: var(--space-2);
}

.action-zone {
  display: grid;
  gap: var(--space-4);
}

.stack {
  display: grid;
  gap: var(--space-4);
}

.mt-5 {
  margin-top: var(--space-5);
}

.mb-5 {
  margin-bottom: var(--space-5);
}

.inline-form {
  display: inline-block;
}

.address {
  max-width: 100%;
  overflow-wrap: anywhere;
}

.login-shell {
  display: grid;
  min-height: calc(100vh - 56px);
  place-items: center;
  padding: var(--space-6);
}

.login-panel {
  width: min(100%, 440px);
}

.login-brand {
  margin-bottom: var(--space-5);
  text-align: center;
}

.login-brand .brand-mark {
  margin: 0 auto var(--space-3);
}

@media (max-width: 1023px) {
  .metric-grid,
  .dashboard-grid,
  .detail-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}

@media (max-width: 767px) {
  .app-topbar {
    position: sticky;
    align-items: start;
    gap: var(--space-3);
    padding: var(--space-3) var(--space-4);
  }

  .brand {
    flex: 1 1 auto;
    padding-right: 76px;
  }

  .topbar-meta {
    position: absolute;
    top: var(--space-3);
    right: var(--space-4);
    flex: 0 0 auto;
    justify-content: end;
    max-width: none;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }

  .app-body {
    display: block;
    width: 100%;
    max-width: 100%;
    overflow-x: hidden;
  }

  .app-sidebar {
    position: static;
    top: auto;
    z-index: 15;
    width: 100%;
    max-width: 100vw;
    height: auto;
    padding: var(--space-2) var(--space-4);
    overflow-x: auto;
    overflow-y: hidden;
    border-right: 0;
    border-bottom: 1px solid var(--border);
  }

  .app-sidebar nav {
    display: flex;
    gap: var(--space-2);
    width: max-content;
  }

  .nav-group,
  .nav-group + .nav-group {
    display: flex;
    gap: var(--space-2);
    margin-top: 0;
  }

  .nav-heading {
    display: none;
  }

  .nav-link {
    min-height: 34px;
    margin: 0;
    white-space: nowrap;
  }

  .sidebar-footer {
    display: none;
  }

  .app-main {
    width: 100%;
    max-width: 100%;
    overflow-x: hidden;
    padding: var(--space-5) var(--space-4) var(--space-8);
  }

  .content-frame {
    width: calc(100vw - 32px);
    max-width: calc(100vw - 32px);
  }

  .page-header {
    display: grid;
    align-items: start;
  }

  .metric-grid,
  .dashboard-grid,
  .detail-grid,
  .form-grid {
    grid-template-columns: 1fr;
  }

  .desktop-table {
    display: none;
  }

  .mobile-list {
    display: block;
  }

  .table-wrap {
    max-width: 100%;
  }

  .panel-header {
    display: grid;
  }

  .button,
  button,
  input[type="submit"] {
    width: 100%;
  }

  .button_to,
  .button_to .button,
  .button_to input[type="submit"],
  .actions .button,
  .page-actions .button {
    width: 100%;
  }

  .topbar-meta .button_to,
  .topbar-meta .button_to .button,
  .topbar-meta .button_to input[type="submit"] {
    width: auto;
  }

  .topbar-meta > span {
    display: none;
  }
}
