:root {
  color-scheme: dark;
  --bg: #0d0f14;
  --surface: #151923;
  --surface-soft: #202737;
  --sidebar: #11151d;
  --input: #0f131b;
  --ink: #f3f7fb;
  --muted: #96a3b7;
  --line: #2a3344;
  --accent: #4fd1b7;
  --accent-strong: #35b99e;
  --warning: #f2b84b;
  --danger: #ff6b6b;
  --blue: #7ab8ff;
  --shadow: 0 18px 42px rgba(0, 0, 0, 0.22);
}

[data-theme="light"] {
  color-scheme: light;
  --bg: #f6f7f4;
  --surface: #ffffff;
  --surface-soft: #eef4ef;
  --sidebar: #fbfcfa;
  --input: #ffffff;
  --ink: #19201d;
  --muted: #64706b;
  --line: #d8ded9;
  --accent: #1f8a70;
  --accent-strong: #176b57;
  --warning: #b7791f;
  --danger: #b83232;
  --blue: #2f6f9f;
  --shadow: 0 14px 38px rgba(31, 42, 36, 0.1);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  background: var(--bg);
  color: var(--ink);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  letter-spacing: 0;
  overflow-x: hidden;
}

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

.app-shell {
  display: grid;
  grid-template-columns: 248px minmax(0, 1fr);
  min-height: 100vh;
}

.sidebar {
  min-width: 0;
  border-right: 1px solid var(--line);
  background: var(--sidebar);
  padding: 22px 16px;
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 28px;
  min-width: 0;
}

.brand-mark {
  display: grid;
  place-items: center;
  width: 42px;
  height: 42px;
  border-radius: 8px;
  background: var(--ink);
  color: var(--bg);
  font-weight: 800;
  overflow: hidden;
  flex: 0 0 auto;
}

.brand-avatar {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

.brand strong,
.brand span {
  display: block;
  max-width: 160px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.brand span {
  color: var(--muted);
  font-size: 13px;
}

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

.nav-item,
.ghost-btn,
.primary-btn,
.icon-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 38px;
  border: 1px solid transparent;
  border-radius: 8px;
  cursor: pointer;
  transition: background 140ms ease, border-color 140ms ease, color 140ms ease;
}

.nav-item {
  justify-content: flex-start;
  width: 100%;
  padding: 9px 10px;
  color: var(--muted);
  background: transparent;
}

.nav-item:hover,
.nav-item.is-active {
  background: var(--surface-soft);
  color: var(--ink);
}

.nav-item.is-active {
  border-color: var(--accent);
}

.nav-item svg,
.top-actions svg,
.table-action svg,
.danger-btn svg {
  width: 17px;
  height: 17px;
}

.main {
  min-width: 0;
  padding: 22px clamp(16px, 4vw, 36px) 36px;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 18px;
}

.eyebrow {
  margin: 0 0 4px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0;
  text-transform: uppercase;
}

h1 {
  margin: 0;
  font-size: 28px;
  line-height: 1.15;
}

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

.primary-btn {
  padding: 0 14px;
  background: var(--accent);
  color: #07110f;
  border-color: var(--accent);
  font-weight: 700;
}

.primary-btn:hover {
  background: var(--accent-strong);
  border-color: var(--accent-strong);
}

.ghost-btn,
.icon-btn {
  padding: 0 12px;
  background: var(--surface);
  color: var(--ink);
  border-color: var(--line);
}

.ghost-btn:hover,
.icon-btn:hover {
  background: var(--surface-soft);
}

.danger-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 38px;
  border: 1px solid rgba(255, 107, 107, 0.35);
  border-radius: 8px;
  background: rgba(255, 107, 107, 0.12);
  color: var(--danger);
  padding: 0 12px;
  cursor: pointer;
  font-weight: 700;
}

.danger-btn:hover {
  background: rgba(255, 107, 107, 0.18);
}

.icon-btn {
  width: 38px;
  padding: 0;
}

.notice {
  border: 1px solid var(--line);
  background: var(--surface);
  border-left: 4px solid var(--accent);
  border-radius: 8px;
  padding: 12px 14px;
  margin-bottom: 16px;
  color: var(--muted);
}

.notice.error {
  border-left-color: var(--danger);
}

.notice.warning {
  border-left-color: var(--warning);
}

.toast-root {
  position: fixed;
  top: 18px;
  right: 18px;
  z-index: 50;
  display: flex;
  flex-direction: column;
  gap: 10px;
  width: min(360px, calc(100vw - 28px));
  pointer-events: none;
}

.toast {
  position: relative;
  display: grid;
  grid-template-columns: 34px minmax(0, 1fr) auto;
  gap: 10px;
  align-items: flex-start;
  min-height: 64px;
  overflow: hidden;
  border: 1px solid var(--line);
  border-left: 4px solid var(--accent);
  border-radius: 8px;
  background: color-mix(in srgb, var(--surface) 94%, transparent);
  box-shadow: var(--shadow);
  color: var(--ink);
  padding: 12px;
  pointer-events: auto;
  animation: toast-slide-in 220ms cubic-bezier(0.2, 0.9, 0.2, 1) both;
}

.toast.error {
  border-left-color: var(--danger);
}

.toast.warning {
  border-left-color: var(--warning);
}

.toast.is-leaving {
  animation: toast-slide-out 180ms ease-in forwards;
}

.toast-icon {
  display: grid;
  place-items: center;
  width: 30px;
  height: 30px;
  border-radius: 8px;
  background: var(--surface-soft);
  color: var(--accent);
}

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

.toast.warning .toast-icon {
  color: var(--warning);
}

.toast-body {
  min-width: 0;
}

.toast-title {
  margin: 0;
  font-size: 13px;
  font-weight: 800;
}

.toast-message {
  margin: 3px 0 0;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.35;
  overflow-wrap: anywhere;
}

.toast-close {
  display: grid;
  place-items: center;
  width: 28px;
  height: 28px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--input);
  color: var(--muted);
  cursor: pointer;
}

.toast-close:hover {
  background: var(--surface-soft);
  color: var(--ink);
}

.toast-bar {
  position: absolute;
  right: 0;
  bottom: 0;
  left: 0;
  height: 2px;
  background: var(--accent);
  transform-origin: left center;
  animation: toast-progress 7000ms linear forwards;
}

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

.toast.warning .toast-bar {
  background: var(--warning);
}

@keyframes toast-slide-in {
  from {
    opacity: 0;
    transform: translateX(calc(100% + 24px));
  }
  to {
    opacity: 1;
    transform: translateX(0);
  }
}

@keyframes toast-slide-out {
  to {
    opacity: 0;
    transform: translateX(calc(100% + 24px));
  }
}

@keyframes toast-progress {
  from {
    transform: scaleX(1);
  }
  to {
    transform: scaleX(0);
  }
}

.content-grid {
  display: grid;
  gap: 14px;
}

.panel {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
  padding: 16px;
}

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

.panel-title {
  margin: 0;
  font-size: 16px;
}

.panel-subtitle {
  margin: 3px 0 0;
  color: var(--muted);
  font-size: 13px;
}

.metrics {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 12px;
}

.metric {
  min-height: 96px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 14px;
}

.metric span {
  color: var(--muted);
  font-size: 13px;
}

.metric strong {
  display: block;
  margin-top: 10px;
  font-size: 30px;
  line-height: 1;
}

.split {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(320px, 0.8fr);
  gap: 14px;
}

.toolbar {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
  margin-bottom: 12px;
}

.input,
.select,
.textarea {
  min-height: 38px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--input);
  color: var(--ink);
  padding: 0 11px;
}

.input {
  min-width: 260px;
}

.textarea {
  min-height: 88px;
  padding: 10px 11px;
  resize: vertical;
}

.input[type="color"] {
  width: 48px;
  min-width: 48px;
  padding: 4px;
}

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

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

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

th {
  background: var(--surface-soft);
  color: var(--muted);
  font-weight: 700;
}

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

tr.is-selected td {
  background: rgba(90, 169, 255, 0.08);
}

.table-action {
  width: 32px;
  height: 32px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--input);
  color: var(--ink);
  cursor: pointer;
}

.table-action:hover {
  background: var(--surface-soft);
}

.badge {
  display: inline-flex;
  align-items: center;
  min-height: 24px;
  border-radius: 999px;
  padding: 0 9px;
  background: rgba(79, 209, 183, 0.15);
  color: var(--accent-strong);
  font-size: 12px;
  font-weight: 700;
}

.badge.warn {
  background: rgba(242, 184, 75, 0.16);
  color: var(--warning);
}

.badge.danger {
  background: rgba(255, 107, 107, 0.15);
  color: var(--danger);
}

.badge.blue {
  background: rgba(122, 184, 255, 0.16);
  color: var(--blue);
}

.detail-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
}

.kv {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 10px;
  min-height: 72px;
}

.kv span {
  display: block;
  color: var(--muted);
  font-size: 12px;
  margin-bottom: 5px;
}

.kv strong {
  word-break: break-word;
  font-size: 14px;
}

.json-box {
  max-height: 420px;
  overflow: auto;
  margin: 0;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #090c10;
  color: #d8e7ef;
  padding: 12px;
  font: 12px/1.55 "Cascadia Code", Consolas, monospace;
}

.empty {
  padding: 28px;
  color: var(--muted);
  text-align: center;
  border: 1px dashed var(--line);
  border-radius: 8px;
  background: var(--input);
}

.login-screen {
  max-width: 680px;
}

.seed-box {
  white-space: pre-wrap;
  word-break: break-word;
  margin: 12px 0 0;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #090c10;
  color: #d8e7ef;
  padding: 12px;
  font: 12px/1.55 "Cascadia Code", Consolas, monospace;
}

.form-grid {
  display: grid;
  grid-template-columns: minmax(190px, 1fr) 140px minmax(170px, 1fr) auto;
  gap: 8px;
  align-items: center;
}

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

.form-row {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
}

.form-field {
  display: grid;
  gap: 5px;
}

.form-field label,
.check-row {
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
}

.check-row {
  display: flex;
  align-items: center;
  gap: 8px;
  min-height: 38px;
}

.check-row input {
  display: grid;
  flex: 0 0 auto;
  place-items: center;
  width: 18px;
  height: 18px;
  margin: 0;
  appearance: none;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--input);
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.02);
  cursor: pointer;
  transition: background 140ms ease, border-color 140ms ease, box-shadow 140ms ease;
}

.check-row input::before {
  content: "";
  width: 5px;
  height: 9px;
  margin-top: -2px;
  border: solid #07110f;
  border-width: 0 2px 2px 0;
  opacity: 0;
  transform: rotate(45deg) scale(0.7);
  transition: opacity 120ms ease, transform 120ms ease;
}

.check-row input:checked {
  border-color: var(--accent);
  background: var(--accent);
  box-shadow: 0 0 0 3px rgba(79, 209, 183, 0.12);
}

.check-row input:checked::before {
  opacity: 1;
  transform: rotate(45deg) scale(1);
}

.check-row input:focus-visible {
  outline: 2px solid var(--blue);
  outline-offset: 2px;
}

.check-row input:disabled {
  cursor: not-allowed;
  opacity: 0.55;
}

.section-grid {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(320px, 0.7fr);
  gap: 14px;
}

.compact-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 10px;
}

.action-row,
.mini-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

.action-row {
  justify-content: flex-end;
}

.danger-zone {
  border-color: rgba(255, 107, 107, 0.35);
  background: rgba(255, 107, 107, 0.08);
}

.mono {
  font-family: "Cascadia Code", Consolas, monospace;
  font-size: 12px;
}

.truncate {
  max-width: 260px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.color-dot {
  display: inline-block;
  width: 12px;
  height: 12px;
  margin-right: 6px;
  border-radius: 999px;
  border: 1px solid var(--line);
  vertical-align: -1px;
}

.pill-strip {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

.is-hidden {
  display: none !important;
}

@media (max-width: 960px) {
  .app-shell {
    grid-template-columns: 1fr;
    grid-template-rows: auto 1fr;
    align-content: start;
  }

  .sidebar {
    position: sticky;
    top: 0;
    z-index: 5;
    align-self: start;
    max-width: 100vw;
    border-right: 0;
    border-bottom: 1px solid var(--line);
    padding: 12px;
  }

  .brand {
    margin-bottom: 10px;
  }

  .nav {
    width: 100%;
    max-width: 100%;
    min-width: 0;
    grid-auto-flow: column;
    grid-auto-columns: max-content;
    overflow-x: auto;
    padding-bottom: 2px;
  }

  .nav-item {
    flex: 0 0 auto;
    width: auto;
    white-space: nowrap;
  }

  .metrics,
  .split,
  .detail-grid,
  .section-grid,
  .compact-grid,
  .form-row {
    grid-template-columns: 1fr;
  }

  .topbar {
    align-items: flex-start;
    flex-direction: column;
  }

  .top-actions {
    justify-content: flex-start;
  }

  .input {
    min-width: min(100%, 260px);
  }

  .form-grid {
    grid-template-columns: 1fr;
  }
}
