:root {
  color-scheme: light;
  --bg: #f5f7fa;
  --surface: #ffffff;
  --surface-2: #eef2f6;
  --surface-3: #e4eaf0;
  --text: #17202a;
  --muted: #5b6775;
  --border: #d7dee7;
  --accent: #1769aa;
  --accent-strong: #0f4f87;
  --green: #1f7a4d;
  --yellow: #9a6a00;
  --red: #b42318;
  --gray: #687385;
  --teal: #047481;
  --shadow: 0 16px 40px rgba(23, 32, 42, 0.08);
  --radius: 8px;
  --sidebar-width: 248px;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

[data-theme="dark"] {
  color-scheme: dark;
  --bg: #101418;
  --surface: #171d23;
  --surface-2: #202832;
  --surface-3: #2a3440;
  --text: #eef3f8;
  --muted: #a6b2bf;
  --border: #33404d;
  --accent: #6bb6ff;
  --accent-strong: #a8d4ff;
  --green: #5fc98f;
  --yellow: #e1b84d;
  --red: #ff8177;
  --gray: #9aa7b7;
  --teal: #5bd2dc;
  --shadow: 0 18px 44px rgba(0, 0, 0, 0.32);
}

* {
  box-sizing: border-box;
}

html,
body {
  min-height: 100%;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-size: 14px;
  line-height: 1.45;
  overflow-x: hidden;
}

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

button {
  cursor: pointer;
}

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

:focus-visible {
  outline: 3px solid color-mix(in srgb, var(--accent) 62%, transparent);
  outline-offset: 2px;
}

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

.auth-shell {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 28px;
}

.auth-panel {
  width: min(460px, 100%);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 28px;
}

.auth-panel h1 {
  margin: 0 0 6px;
  font-size: 24px;
  letter-spacing: 0;
}

.auth-panel .subtle {
  margin: 0 0 22px;
  color: var(--muted);
}

.setup-qr {
  display: grid;
  grid-template-columns: 132px 1fr;
  gap: 18px;
  align-items: center;
  padding: 14px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface-2);
  margin-bottom: 18px;
}

.setup-qr img {
  width: 132px;
  height: 132px;
  background: #fff;
  border-radius: 4px;
}

.totp-assist {
  display: grid;
  gap: 10px;
  margin-bottom: 18px;
}

.manual-key {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 8px 10px;
  align-items: center;
  padding: 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
}

.manual-key span {
  grid-column: 1 / -1;
  color: var(--muted);
  font-size: 12px;
  font-weight: 750;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.manual-key code {
  min-width: 0;
  word-break: break-word;
  color: var(--text);
}

.totp-diagnostics {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  color: var(--muted);
  font-size: 12px;
}

.totp-diagnostics span {
  padding: 4px 8px;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: var(--surface);
}

.layout {
  min-height: 100vh;
  display: grid;
  grid-template-columns: var(--sidebar-width) 1fr;
  min-width: 0;
  max-width: 100%;
}

.sidebar {
  background: var(--surface);
  border-right: 1px solid var(--border);
  padding: 18px 14px;
  position: sticky;
  top: 0;
  height: 100vh;
  overflow-y: auto;
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 8px 18px;
  font-weight: 750;
  font-size: 16px;
}

.brand-mark {
  display: inline-grid;
  place-items: center;
  width: 32px;
  height: 32px;
  border-radius: 7px;
  background: var(--accent);
  color: #fff;
  font-weight: 800;
}

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

.nav button {
  width: 100%;
  display: flex;
  align-items: center;
  gap: 10px;
  border: 0;
  border-radius: 7px;
  background: transparent;
  color: var(--muted);
  padding: 10px;
  text-align: left;
}

.nav button:hover,
.nav button.active {
  background: var(--surface-2);
  color: var(--text);
}

.nav-icon {
  width: 22px;
  color: var(--accent);
  text-align: center;
  font-weight: 800;
}

.main {
  min-width: 0;
  max-width: 100%;
}

.topbar {
  height: 64px;
  background: color-mix(in srgb, var(--surface) 94%, transparent);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 0 24px;
  position: sticky;
  top: 0;
  z-index: 10;
  backdrop-filter: blur(10px);
}

.topbar-title {
  min-width: 0;
}

.topbar-title h1 {
  margin: 0;
  font-size: 18px;
  letter-spacing: 0;
}

.topbar-title p {
  margin: 2px 0 0;
  color: var(--muted);
  font-size: 12px;
}

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

.user-chip {
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 6px 10px;
  color: var(--muted);
  background: var(--surface);
  white-space: nowrap;
}

.content {
  padding: 24px;
  display: grid;
  gap: 18px;
  min-width: 0;
  max-width: 100%;
}

.content > * {
  min-width: 0;
  max-width: 100%;
}

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

.metric-card,
.panel,
.table-panel {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  min-width: 0;
  max-width: 100%;
}

.metric-card {
  padding: 16px;
  min-height: 104px;
}

.metric-label {
  color: var(--muted);
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.metric-value {
  margin-top: 8px;
  font-size: 30px;
  font-weight: 780;
  line-height: 1.1;
}

.metric-note {
  margin-top: 6px;
  color: var(--muted);
  font-size: 12px;
}

.panel {
  padding: 18px;
}

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

.panel-header h2 {
  margin: 0;
  font-size: 16px;
  letter-spacing: 0;
}

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

.toolbar {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  align-items: center;
  justify-content: space-between;
  padding: 14px;
  border-bottom: 1px solid var(--border);
}

.toolbar-group {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  align-items: center;
  min-width: 0;
}

.input,
.select,
.textarea {
  width: 100%;
  border: 1px solid var(--border);
  border-radius: 7px;
  background: var(--surface);
  color: var(--text);
  padding: 10px 11px;
}

.input.compact,
.select.compact {
  width: auto;
  min-width: 180px;
}

.textarea {
  min-height: 96px;
  resize: vertical;
}

.field {
  display: grid;
  gap: 7px;
  margin-bottom: 14px;
}

.field label {
  font-weight: 650;
}

.field-hint {
  color: var(--muted);
  font-size: 12px;
}

.compact-text {
  display: inline-block;
  max-width: min(48vw, 420px);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  vertical-align: bottom;
}

.button {
  border: 1px solid var(--border);
  border-radius: 7px;
  background: var(--surface);
  color: var(--text);
  padding: 9px 12px;
  min-height: 38px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  white-space: nowrap;
}

.button:hover {
  background: var(--surface-2);
}

.button.primary {
  background: var(--accent);
  color: #fff;
  border-color: var(--accent);
}

.button.primary:hover {
  background: var(--accent-strong);
}

.button.danger {
  color: var(--red);
  border-color: color-mix(in srgb, var(--red) 38%, var(--border));
}

.button.ghost {
  border-color: transparent;
  background: transparent;
}

.table-wrap {
  overflow-x: auto;
  max-width: 100%;
  min-width: 0;
}

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

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

th {
  color: var(--muted);
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  background: var(--surface);
  position: sticky;
  top: 0;
}

tr:hover td {
  background: color-mix(in srgb, var(--surface-2) 70%, transparent);
}

.row-actions {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  min-width: 0;
}

.status-badge {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  min-height: 26px;
  border-radius: 999px;
  padding: 3px 9px;
  font-size: 12px;
  font-weight: 700;
  border: 1px solid currentColor;
  white-space: nowrap;
}

.status-dot {
  width: 8px;
  height: 8px;
  border-radius: 999px;
  background: currentColor;
}

.status-running,
.status-online,
.status-healthy,
.status-success {
  color: var(--green);
}

.status-warning,
.status-restarting,
.status-launching,
.status-starting {
  color: var(--yellow);
}

.status-stopped,
.status-exited,
.status-errored,
.status-unhealthy,
.status-failure,
.status-denied {
  color: var(--red);
}

.status-unknown,
.status-none,
.status-inactive {
  color: var(--gray);
}

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

.kv {
  padding: 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface-2);
  min-width: 0;
}

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

.kv strong {
  word-break: break-word;
}

.list {
  display: grid;
  gap: 10px;
  margin: 0;
  padding: 0;
  list-style: none;
}

.list-item {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  padding: 11px 0;
  border-bottom: 1px solid var(--border);
}

.list-item:last-child {
  border-bottom: 0;
}

.mono,
.log-output,
code,
pre {
  font-family: "SFMono-Regular", Consolas, "Liberation Mono", monospace;
}

.log-output {
  min-height: 430px;
  max-height: 68vh;
  overflow: auto;
  background: #0e141b;
  color: #dce7f1;
  border-radius: var(--radius);
  border: 1px solid #263342;
  padding: 14px;
  white-space: pre-wrap;
  tab-size: 2;
  line-height: 1.5;
}

.diagnostic-list {
  display: grid;
  gap: 12px;
}

.finding {
  border: 1px solid var(--border);
  border-left: 4px solid var(--gray);
  border-radius: var(--radius);
  padding: 14px;
  background: var(--surface);
}

.finding.high {
  border-left-color: var(--red);
}

.finding.medium {
  border-left-color: var(--yellow);
}

.finding h3 {
  margin: 0 0 8px;
  font-size: 15px;
}

.finding p {
  margin: 6px 0;
}

.advanced {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 12px;
}

.advanced summary {
  cursor: pointer;
  font-weight: 700;
}

.raw-json {
  overflow: auto;
  max-height: 420px;
  padding: 12px;
  background: var(--surface-2);
  border-radius: 6px;
  white-space: pre;
}

.empty,
.error-state,
.loading-panel {
  display: grid;
  place-items: center;
  gap: 10px;
  min-height: 180px;
  color: var(--muted);
  text-align: center;
  padding: 24px;
}

.spinner {
  width: 28px;
  height: 28px;
  border: 3px solid var(--surface-3);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.9s linear infinite;
}

@keyframes spin {
  to {
    transform: rotate(360deg);
  }
}

.toast-region {
  position: fixed;
  right: 18px;
  bottom: 18px;
  display: grid;
  gap: 10px;
  z-index: 100;
}

.toast {
  width: min(420px, calc(100vw - 36px));
  background: var(--surface);
  color: var(--text);
  border: 1px solid var(--border);
  border-left: 4px solid var(--accent);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 12px 14px;
}

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

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

.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.44);
  display: grid;
  place-items: center;
  padding: 18px;
  z-index: 80;
}

.modal {
  width: min(520px, 100%);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 20px;
}

.modal h2 {
  margin: 0 0 8px;
  font-size: 18px;
}

.modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  margin-top: 18px;
}

.banner {
  padding: 12px 14px;
  border-radius: var(--radius);
  border: 1px solid color-mix(in srgb, var(--yellow) 42%, var(--border));
  background: color-mix(in srgb, var(--yellow) 10%, var(--surface));
  color: var(--text);
  margin-bottom: 14px;
}

.port-chip-list {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  max-height: 178px;
  overflow: auto;
  padding: 2px;
}

.port-chip {
  display: inline-flex;
  align-items: center;
  min-height: 28px;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: var(--surface-2);
  padding: 4px 9px;
  font-family: "SFMono-Regular", Consolas, "Liberation Mono", monospace;
  font-size: 12px;
  white-space: nowrap;
}

.hidden {
  display: none !important;
}

@media (max-width: 1100px) {
  .metrics-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .panel-grid,
  .kv-grid {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 900px) {
  .table-panel {
    overflow: hidden;
  }

  .table-wrap {
    overflow-x: hidden;
  }

  table {
    display: block;
    min-width: 0;
    width: 100%;
  }

  thead {
    position: absolute;
    width: 1px;
    height: 1px;
    overflow: hidden;
    clip: rect(0 0 0 0);
    white-space: nowrap;
  }

  tbody {
    display: grid;
    gap: 12px;
    padding: 12px;
  }

  tr {
    display: grid;
    gap: 0;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    background: var(--surface);
    overflow: hidden;
  }

  tr:hover td {
    background: transparent;
  }

  td {
    display: grid;
    grid-template-columns: minmax(92px, 34%) minmax(0, 1fr);
    gap: 12px;
    align-items: start;
    padding: 10px 12px;
    border-bottom: 1px solid var(--border);
    min-width: 0;
    word-break: break-word;
  }

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

  td::before {
    content: attr(data-label);
    color: var(--muted);
    font-size: 12px;
    font-weight: 750;
    text-transform: uppercase;
    letter-spacing: 0.04em;
  }

  td[data-label="Actions"] {
    grid-template-columns: 1fr;
    gap: 8px;
  }

  td[data-label="Actions"]::before {
    margin-bottom: 0;
  }

  .row-actions {
    width: 100%;
  }

  .row-actions .button,
  .row-actions .select.compact {
    flex: 1 1 132px;
    min-width: min(100%, 132px);
  }

  .compact-text {
    max-width: 100%;
    white-space: normal;
  }

  .toolbar {
    align-items: stretch;
  }

  .toolbar,
  .toolbar-group {
    width: 100%;
  }

  .input.compact,
  .select.compact {
    width: 100%;
    min-width: 0;
  }

  .toolbar > .button,
  .toolbar-group > .button {
    width: 100%;
  }
}

@media (max-width: 760px) {
  .layout {
    grid-template-columns: 1fr;
  }

  .sidebar {
    position: static;
    height: auto;
    border-right: 0;
    border-bottom: 1px solid var(--border);
  }

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

  .topbar {
    height: auto;
    align-items: flex-start;
    padding: 14px;
    flex-direction: column;
  }

  .content {
    padding: 14px;
  }

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

  .setup-qr {
    grid-template-columns: 1fr;
  }

  .setup-qr img {
    margin: 0 auto;
  }

  .manual-key {
    grid-template-columns: 1fr;
  }

  .manual-key .button {
    width: 100%;
  }
}
