:root {
  color-scheme: light;
  --bg: #f5f7fb;
  --panel: #ffffff;
  --panel-soft: #f8fafc;
  --text: #172033;
  --muted: #667085;
  --line: #d9e0ea;
  --line-strong: #c4ccd9;
  --accent: #0f766e;
  --accent-dark: #115e59;
  --accent-soft: #dff7f2;
  --good-bg: #dcfce7;
  --good-text: #166534;
  --warn-bg: #fee2e2;
  --warn-text: #991b1b;
  --code-bg: #0d1321;
}

* { box-sizing: border-box; }

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

button, input, select { font: inherit; }

.sidebar {
  position: fixed;
  inset: 0 auto 0 0;
  display: flex;
  flex-direction: column;
  width: 272px;
  padding: 22px 16px;
  border-right: 1px solid var(--line);
  background: #fff;
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 0 8px 22px;
}

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

.brand strong, .brand span { display: block; }
.brand span { color: var(--muted); font-size: 12px; }

.app-switcher {
  display: grid;
  gap: 8px;
  margin: 0 0 18px;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel-soft);
}

.app-switcher span, label {
  color: var(--muted);
  font-size: 13px;
  font-weight: 650;
}

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

nav a {
  border-radius: 6px;
  color: var(--muted);
  padding: 10px 12px;
  text-decoration: none;
  font-weight: 650;
}

nav a.active, nav a:hover {
  background: var(--accent-soft);
  color: var(--accent-dark);
}

.sidebar-footer {
  display: grid;
  gap: 12px;
  margin-top: auto;
  padding: 16px 8px 0;
  color: var(--muted);
  font-size: 12px;
}

.shell {
  min-height: 100vh;
  margin-left: 272px;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 24px;
  min-height: 112px;
  padding: 26px 34px;
  border-bottom: 1px solid var(--line);
  background: var(--panel);
}

.context-bar {
  display: grid;
  grid-template-columns: 1.4fr 1fr 0.8fr 1fr;
  gap: 12px;
  padding: 14px 34px;
  border-bottom: 1px solid var(--line);
  background: #fbfcfe;
}

.context-bar div {
  min-width: 0;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
}

.context-bar span {
  display: block;
  color: var(--muted);
  font-size: 12px;
}

.context-bar strong {
  display: block;
  margin-top: 4px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.topbar h1, .login-panel h1 {
  margin: 0;
  font-size: 28px;
  line-height: 1.15;
  letter-spacing: 0;
}

.subtitle { margin: 8px 0 0; color: var(--muted); }

.eyebrow {
  margin: 0 0 6px;
  color: var(--accent);
  font-size: 12px;
  font-weight: 700;
  text-transform: uppercase;
}

.topbar-actions, .table-tools, .modal-actions {
  display: flex;
  align-items: center;
  gap: 10px;
}

button {
  min-height: 38px;
  border: 1px solid var(--accent);
  border-radius: 6px;
  background: var(--accent);
  color: #fff;
  cursor: pointer;
  padding: 0 14px;
  font-weight: 650;
}

button:hover { background: var(--accent-dark); border-color: var(--accent-dark); }

button.ghost {
  background: #fff;
  border-color: var(--line-strong);
  color: var(--text);
}

button.full { width: 100%; }

.page {
  width: min(1440px, 100%);
  margin: 0 auto;
  padding: 24px 34px 42px;
}

.page-view[hidden] { display: none; }

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

.metric, .panel, .login-panel, dialog {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
}

.metric {
  min-height: 126px;
  padding: 18px;
}

.metric span, .summary-tile span, .storage-grid span, .app-db {
  display: block;
  color: var(--muted);
  font-size: 13px;
}

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

.metric small {
  display: block;
  margin-top: 10px;
  color: var(--muted);
  line-height: 1.35;
}

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

.panel { padding: 18px; }

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

.panel h2 { margin: 0; font-size: 18px; }
.panel p { margin: 6px 0 0; color: var(--muted); font-size: 13px; }

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

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

.app-card {
  display: grid;
  gap: 10px;
  min-height: 156px;
  border-color: var(--line);
  background: #fff;
  color: var(--text);
  padding: 16px;
  text-align: left;
}

.compact-card { min-height: 138px; }

.app-card:hover, .app-card.selected {
  border-color: var(--accent);
  background: #fbfffe;
}

.app-card-top, .app-meta, .selected-title {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.app-meta {
  align-items: flex-start;
  flex-direction: column;
  color: var(--muted);
  font-size: 13px;
}

.app-health {
  color: var(--accent-dark);
  font-size: 12px;
  font-weight: 800;
  text-transform: uppercase;
}

.selected-title { margin-bottom: 14px; }

dl { margin: 0; }
dt { color: var(--muted); font-size: 13px; }
dd { margin: 4px 0 12px; overflow-wrap: anywhere; }

input, select {
  min-height: 38px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #fff;
  color: var(--text);
  padding: 0 11px;
}

input:focus, select:focus {
  border-color: var(--accent);
  outline: 2px solid var(--accent-soft);
}

.credential-summary {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 12px;
  margin-bottom: 14px;
}

.summary-tile {
  min-width: 0;
  padding: 13px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel-soft);
}

.summary-tile strong {
  display: block;
  margin-top: 6px;
  overflow-wrap: anywhere;
}

.env-block {
  min-height: 112px;
  margin: 0;
  overflow: auto;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--code-bg);
  color: #d7fbe8;
  padding: 16px;
  white-space: pre-wrap;
}

.credential-list, .status-list, .audit-list, .detail-list {
  display: grid;
  gap: 10px;
}

.credential-row, .status-row, .audit-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 12px 0;
  border-bottom: 1px solid var(--line);
}

.credential-row span, .audit-row span {
  display: block;
  color: var(--muted);
  font-size: 12px;
}

.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }

th, td {
  padding: 12px 10px;
  text-align: left;
  border-bottom: 1px solid var(--line);
  white-space: nowrap;
}

th {
  color: var(--muted);
  font-size: 12px;
  text-transform: uppercase;
}

tr.has-dummy td:first-child { border-left: 3px solid #92400e; }
tr.selected-row { background: #f0fdfa; }
.collection-name { font-weight: 650; }

.bar {
  display: inline-block;
  width: 160px;
  height: 8px;
  overflow: hidden;
  border-radius: 999px;
  background: #e7ebf1;
}

.bar span {
  display: block;
  height: 100%;
  min-width: 3px;
  border-radius: inherit;
  background: var(--accent);
}

.table-open-btn {
  min-height: 30px;
  margin-right: 10px;
  padding: 0 10px;
}

.table-records-panel { margin-top: 16px; }

.secret-cell {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  max-width: 360px;
}

.secret-mask {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.icon-btn {
  min-height: 26px;
  border-color: var(--line-strong);
  background: #fff;
  color: var(--text);
  padding: 0 8px;
  font-size: 12px;
}

.error-panel {
  margin-bottom: 16px;
  border-color: #fecaca;
  background: #fff7f7;
}

.badge {
  display: inline-flex;
  align-items: center;
  min-height: 24px;
  border-radius: 999px;
  padding: 0 9px;
  font-size: 12px;
  font-weight: 700;
}

.badge.good { background: var(--good-bg); color: var(--good-text); }
.badge.warn { background: var(--warn-bg); color: var(--warn-text); }

dialog {
  width: min(460px, calc(100% - 32px));
  padding: 0;
}

dialog::backdrop { background: rgb(15 23 42 / 0.42); }

.modal-card {
  display: grid;
  gap: 16px;
  padding: 24px;
}

.modal-actions { justify-content: flex-end; }

.login-page {
  display: grid;
  place-items: center;
  padding: 24px;
}

.login-shell { width: min(420px, 100%); }
.login-panel { padding: 28px; }
.login-form { display: grid; gap: 14px; margin-top: 24px; }

label {
  display: grid;
  gap: 7px;
}

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

.form-error {
  min-height: 20px;
  margin: 0;
  color: var(--warn-text);
  font-size: 13px;
}

@media (max-width: 1180px) {
  .app-grid, .app-grid.compact { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .split-grid { grid-template-columns: 1fr; }
}

@media (max-width: 860px) {
  .sidebar {
    position: static;
    width: auto;
    border-right: 0;
    border-bottom: 1px solid var(--line);
  }

  nav { grid-template-columns: repeat(3, 1fr); }
  .shell { margin-left: 0; }
  .topbar, .topbar-actions, .panel-heading, .table-tools { align-items: flex-start; flex-direction: column; }
  .context-bar { grid-template-columns: 1fr; padding-left: 18px; padding-right: 18px; }
  .metrics-grid, .credential-summary, .app-grid, .app-grid.compact { grid-template-columns: 1fr; }
  .page, .topbar { padding-left: 18px; padding-right: 18px; }
}
