:root {
  --md-sys-color-primary: #6750a4;
  --md-sys-color-on-primary: #ffffff;
  --md-sys-color-primary-container: #eaddff;
  --md-sys-color-on-primary-container: #21005d;
  --md-sys-color-secondary: #625b71;
  --md-sys-color-on-secondary: #ffffff;
  --md-sys-color-secondary-container: #e8def8;
  --md-sys-color-on-secondary-container: #1d192b;
  --md-sys-color-tertiary: #7d5260;
  --md-sys-color-tertiary-container: #ffd8e4;
  --md-sys-color-on-tertiary-container: #31111d;
  --md-sys-color-error: #b3261e;
  --md-sys-color-on-error: #ffffff;
  --md-sys-color-error-container: #f9dedc;
  --md-sys-color-on-error-container: #410e0b;
  --md-sys-color-background: #fef7ff;
  --md-sys-color-surface: #fef7ff;
  --md-sys-color-on-surface: #1d1b20;
  --md-sys-color-on-surface-variant: #49454f;
  --md-sys-color-surface-container-lowest: #ffffff;
  --md-sys-color-surface-container-low: #f7f2fa;
  --md-sys-color-surface-container: #f3edf7;
  --md-sys-color-surface-container-high: #ece6f0;
  --md-sys-color-surface-container-highest: #e6e0e9;
  --md-sys-color-outline: #79747e;
  --md-sys-color-outline-variant: #cac4d0;
  --md-sys-color-success: #146c2e;
  --md-sys-color-success-container: #c4eed0;
  --md-sys-color-inverse-surface: #322f35;
  --md-sys-color-inverse-on-surface: #f5eff7;
  --md-space: 8px;
  --md-sidebar: 280px;
  --md-radius-card: 12px;
  --md-radius-full: 999px;
  --md-topbar: 64px;
  color-scheme: light;
  font-family: "Roboto Flex", "Roboto", sans-serif;
}

[data-theme="dark"] {
  --md-sys-color-primary: #d0bcff;
  --md-sys-color-on-primary: #381e72;
  --md-sys-color-primary-container: #4f378b;
  --md-sys-color-on-primary-container: #eaddff;
  --md-sys-color-secondary: #ccc2dc;
  --md-sys-color-on-secondary: #332d41;
  --md-sys-color-secondary-container: #4a4458;
  --md-sys-color-on-secondary-container: #e8def8;
  --md-sys-color-tertiary: #efb8c8;
  --md-sys-color-tertiary-container: #633b48;
  --md-sys-color-on-tertiary-container: #ffd8e4;
  --md-sys-color-error: #f2b8b5;
  --md-sys-color-on-error: #601410;
  --md-sys-color-error-container: #8c1d18;
  --md-sys-color-on-error-container: #f9dedc;
  --md-sys-color-background: #141218;
  --md-sys-color-surface: #141218;
  --md-sys-color-on-surface: #e6e0e9;
  --md-sys-color-on-surface-variant: #cac4d0;
  --md-sys-color-surface-container-lowest: #0f0d13;
  --md-sys-color-surface-container-low: #1d1b20;
  --md-sys-color-surface-container: #211f26;
  --md-sys-color-surface-container-high: #2b2930;
  --md-sys-color-surface-container-highest: #36343b;
  --md-sys-color-outline: #938f99;
  --md-sys-color-outline-variant: #49454f;
  --md-sys-color-success: #86d993;
  --md-sys-color-success-container: #0f3d1d;
  --md-sys-color-inverse-surface: #e6e0e9;
  --md-sys-color-inverse-on-surface: #322f35;
  color-scheme: dark;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--md-sys-color-background);
  color: var(--md-sys-color-on-surface);
  font-size: 16px;
  line-height: 1.5;
}

a { color: var(--md-sys-color-primary); }
a:focus-visible, button:focus-visible, input:focus-visible, select:focus-visible, textarea:focus-visible {
  outline: 2px solid var(--md-sys-color-primary);
  outline-offset: 2px;
}

.material-symbols-outlined {
  font-variation-settings: "FILL" 0, "wght" 500, "GRAD" 0, "opsz" 24;
  font-size: 22px;
  vertical-align: middle;
}

.app-shell { min-height: 100vh; display: flex; }

.sidebar {
  width: var(--md-sidebar);
  background: var(--md-sys-color-surface-container-low);
  border-right: 1px solid var(--md-sys-color-outline-variant);
  padding: 16px 12px;
  display: flex;
  flex-direction: column;
  position: sticky;
  top: 0;
  height: 100vh;
}

.brand {
  display: flex;
  gap: 12px;
  align-items: center;
  padding: 8px 12px 20px;
  text-decoration: none;
  color: inherit;
}
.brand strong { display: block; font-size: 15px; font-weight: 600; letter-spacing: -0.01em; }
.brand span { color: var(--md-sys-color-on-surface-variant); font-size: 12px; }
.brand-mark {
  width: 40px;
  height: 40px;
  border-radius: 12px;
  display: grid;
  place-items: center;
  background: var(--md-sys-color-primary-container);
  color: var(--md-sys-color-on-primary-container);
}

.nav-link {
  display: flex;
  align-items: center;
  gap: 12px;
  min-height: 48px;
  padding: 0 16px;
  margin-bottom: 4px;
  border-radius: var(--md-radius-full);
  color: var(--md-sys-color-on-surface-variant);
  text-decoration: none;
  font-size: 14px;
  font-weight: 500;
}
.nav-link:hover { background: var(--md-sys-color-surface-container-high); color: inherit; }
.nav-link.is-active {
  background: var(--md-sys-color-secondary-container);
  color: var(--md-sys-color-on-secondary-container);
}
.nav-spacer { flex: 1; }

.workspace { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.topbar {
  height: var(--md-topbar);
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 0 24px;
  background: var(--md-sys-color-surface);
  position: sticky;
  top: 0;
  z-index: 20;
}
.topbar h1 { font-size: 22px; line-height: 28px; font-weight: 500; margin: 0; letter-spacing: -0.01em; }
.icon-btn, .md-btn {
  border: 0;
  background: transparent;
  color: inherit;
  min-height: 40px;
  border-radius: var(--md-radius-full);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 0 16px;
  font: inherit;
  font-size: 14px;
  font-weight: 500;
  text-decoration: none;
  cursor: pointer;
}
.icon-btn { width: 40px; padding: 0; }
.icon-btn:hover, .md-btn-text:hover { background: var(--md-sys-color-surface-container-high); }
.md-btn-filled { background: var(--md-sys-color-primary); color: var(--md-sys-color-on-primary); }
.md-btn-filled:hover { filter: brightness(1.05); color: var(--md-sys-color-on-primary); }
.md-btn-tonal { background: var(--md-sys-color-secondary-container); color: var(--md-sys-color-on-secondary-container); }
.md-btn-outlined { box-shadow: inset 0 0 0 1px var(--md-sys-color-outline); }
.md-btn-danger { background: var(--md-sys-color-error); color: var(--md-sys-color-on-error); }
.md-btn:disabled { opacity: 0.5; cursor: not-allowed; }
.menu-btn { display: none; }

.page { padding: 8px 24px 32px; }
.page-intro { color: var(--md-sys-color-on-surface-variant); margin: 0 0 16px; max-width: 72ch; }

.md-card {
  background: var(--md-sys-color-surface-container-lowest);
  border: 1px solid var(--md-sys-color-outline-variant);
  border-radius: var(--md-radius-card);
  padding: 16px;
}
.md-card + .md-card, .stack > * + * { margin-top: 16px; }
.card-title { font-size: 16px; font-weight: 500; margin: 0 0 12px; }

.kpi-grid, .split, .form-grid { display: grid; gap: 16px; }
.kpi-grid { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.split { grid-template-columns: 1.2fr 0.8fr; align-items: start; }
.form-grid { grid-template-columns: 1fr 1fr; }
.kpi {
  background: var(--md-sys-color-surface-container-low);
  border-radius: var(--md-radius-card);
  padding: 16px;
}
.kpi span { display: block; color: var(--md-sys-color-on-surface-variant); font-size: 13px; }
.kpi strong { display: block; font-size: 28px; font-weight: 500; letter-spacing: -0.02em; margin-top: 4px; }

.table-wrap { overflow-x: auto; }
.table-wrap > .table { margin-bottom: 0; }
table.data { width: 100%; border-collapse: collapse; font-size: 14px; }
table.data th, table.data td { text-align: left; padding: 12px; border-bottom: 1px solid var(--md-sys-color-outline-variant); vertical-align: top; }
table.data th { font-size: 12px; font-weight: 500; color: var(--md-sys-color-on-surface-variant); }
table.data tr:hover td { background: var(--md-sys-color-surface-container-low); }
.mono { font-family: "Roboto Mono", ui-monospace, monospace; font-size: 12px; }

.md-chip {
  display: inline-flex;
  align-items: center;
  min-height: 24px;
  padding: 0 8px;
  border-radius: 8px;
  font-size: 12px;
  font-weight: 500;
  background: var(--md-sys-color-surface-container-high);
}
.md-chip-success { background: var(--md-sys-color-success-container); color: var(--md-sys-color-success); }
.md-chip-warning { background: #ffddb8; color: #633f00; }
.md-chip-danger { background: var(--md-sys-color-error-container); color: var(--md-sys-color-on-error-container); }
[data-theme="dark"] .md-chip-warning { background: #5c4300; color: #ffddb8; }

.field { display: flex; flex-direction: column; gap: 6px; margin-bottom: 16px; }
.field label { font-size: 13px; font-weight: 500; color: var(--md-sys-color-on-surface-variant); }
.field input, .field select, .field textarea, .inline-fields input, .inline-fields select {
  width: 100%;
  min-height: 48px;
  border-radius: 4px 4px 0 0;
  border: 0;
  border-bottom: 1px solid var(--md-sys-color-outline);
  background: var(--md-sys-color-surface-container-highest);
  color: inherit;
  padding: 12px 16px;
  font: inherit;
}
.field textarea { min-height: 96px; border-radius: 12px; }
.field input:focus, .field select:focus, .field textarea:focus { border-bottom-color: var(--md-sys-color-primary); background: var(--md-sys-color-surface-container-high); }
.check { display: flex; gap: 8px; align-items: center; min-height: 40px; }
.filters { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 16px; }
.filters .field { margin: 0; min-width: 160px; flex: 1; }

.actions { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.alert {
  border-radius: 12px;
  padding: 12px 16px;
  margin-bottom: 16px;
  background: var(--md-sys-color-error-container);
  color: var(--md-sys-color-on-error-container);
}
.note {
  background: var(--md-sys-color-tertiary-container);
  color: var(--md-sys-color-on-tertiary-container);
  border-radius: 12px;
  padding: 12px 16px;
}
.empty { text-align: center; padding: 32px 16px; color: var(--md-sys-color-on-surface-variant); }
.empty .material-symbols-outlined { font-size: 40px; display: block; margin-bottom: 8px; }

.pager { display: flex; gap: 8px; align-items: center; justify-content: flex-end; margin-top: 12px; }
.toast-stack { position: fixed; right: 16px; bottom: 16px; z-index: 50; display: flex; flex-direction: column; gap: 8px; }
.toast {
  min-width: 240px;
  max-width: 360px;
  background: var(--md-sys-color-inverse-surface);
  color: var(--md-sys-color-inverse-on-surface);
  border-radius: 8px;
  padding: 12px 16px;
  box-shadow: 0 2px 8px rgba(0,0,0,.2);
}
.backdrop { display: none; }

.update-flow { max-width: 420px; margin: 0 auto; text-align: center; }
.update-flow h2 { font-size: 16px; font-weight: 500; margin: 0 0 16px; }
.flow-step { padding: 8px 12px 4px; }
.flow-step .material-symbols-outlined { font-size: 28px; color: var(--md-sys-color-on-surface-variant); }
.flow-step strong { display: block; margin-top: 4px; }
.flow-step p { margin: 4px 0 0; color: var(--md-sys-color-on-surface-variant); font-size: 14px; }
.flow-arrow { color: var(--md-sys-color-outline); }
.flow-done {
  margin-top: 8px;
  border: 1px solid var(--md-sys-color-outline-variant);
  border-radius: 16px;
  padding: 16px;
  background: var(--md-sys-color-surface-container-low);
}
.flow-done .material-symbols-outlined { color: var(--md-sys-color-success); font-variation-settings: "FILL" 1, "wght" 500, "GRAD" 0, "opsz" 24; }

.dropzone {
  border: 1px dashed var(--md-sys-color-outline);
  border-radius: 12px;
  padding: 24px;
  text-align: center;
  background: var(--md-sys-color-surface-container-low);
}
.dropzone.is-hot { border-color: var(--md-sys-color-primary); background: var(--md-sys-color-primary-container); }
.timeline { display: flex; flex-direction: column; gap: 0; }
.timeline-item { display: grid; grid-template-columns: 16px 1fr; gap: 12px; }
.timeline-rail { width: 2px; background: var(--md-sys-color-outline-variant); margin: 0 auto; position: relative; }
.timeline-rail::before {
  content: "";
  width: 10px; height: 10px; border-radius: 50%;
  background: var(--md-sys-color-primary);
  position: absolute; left: -4px; top: 18px;
}
.bars { display: flex; flex-direction: column; gap: 8px; }
.bar-row { display: grid; grid-template-columns: 110px 1fr 40px; gap: 8px; align-items: center; font-size: 13px; }
.bar { height: 8px; border-radius: 99px; background: var(--md-sys-color-surface-container-high); overflow: hidden; }
.bar span { display: block; height: 100%; background: var(--md-sys-color-primary); }

.auth-wrap { min-height: 100vh; display: grid; place-items: center; padding: 24px; }
.auth-card { width: min(440px, 100%); background: var(--md-sys-color-surface-container-lowest); border: 1px solid var(--md-sys-color-outline-variant); border-radius: 28px; padding: 32px 24px; }
.secret {
  font-family: ui-monospace, monospace;
  background: var(--md-sys-color-surface-container);
  padding: 12px;
  border-radius: 8px;
  word-break: break-all;
}

.sidebar-overlay { display: none; }

@media (max-width: 1100px) {
  .kpi-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .split, .form-grid { grid-template-columns: 1fr; }
}

@media (max-width: 599px) {
  .menu-btn { display: inline-flex; }
  .sidebar {
    position: fixed;
    z-index: 40;
    transform: translateX(-105%);
    transition: transform 200ms cubic-bezier(0.2, 0, 0, 1);
  }
  .sidebar.is-open { transform: none; }
  .sidebar-overlay { display: block; position: fixed; inset: 0; background: rgba(0,0,0,.32); z-index: 30; }
  .sidebar-overlay[hidden] { display: none; }
  .topbar, .page { padding-left: 16px; padding-right: 16px; }
  .kpi-grid { grid-template-columns: 1fr; }
  .topbar h1 { font-size: 18px; }
}
