/* Monochrome console theme: neutral greys only, hairline borders, quiet
   surfaces, and one content column that stays centred on wide screens. */

:root {
  --background: oklch(1 0 0);
  --foreground: oklch(0.145 0.004 106);
  --card: oklch(1 0 0);
  --card-foreground: oklch(0.145 0.004 106);
  --popover: oklch(1 0 0);
  --popover-foreground: oklch(0.145 0.004 106);
  --primary: oklch(0.205 0.005 106);
  --primary-foreground: oklch(0.985 0.002 106);
  --secondary: oklch(0.96 0.004 106);
  --secondary-foreground: oklch(0.205 0.005 106);
  --muted: oklch(0.966 0.004 106);
  --muted-foreground: oklch(0.54 0.008 106);
  --accent: oklch(0.94 0.005 106);
  --accent-foreground: oklch(0.205 0.005 106);
  --destructive: oklch(0.52 0.16 27);
  --border: oklch(0.925 0.005 106);
  --input: oklch(0.925 0.005 106);
  --ring: oklch(0.708 0.008 106);
  --chart-1: oklch(0.87 0.005 106);
  --chart-2: oklch(0.556 0.008 106);
  --chart-3: oklch(0.439 0.008 106);
  --chart-4: oklch(0.371 0.008 106);
  --chart-5: oklch(0.269 0.006 106);
  --sidebar: oklch(0.972 0.004 106);
  --sidebar-foreground: oklch(0.145 0.004 106);
  --sidebar-accent: oklch(0.94 0.005 106);
  --sidebar-accent-foreground: oklch(0.205 0.005 106);
  --sidebar-border: oklch(0.925 0.005 106);
  --radius: 0.75rem;
  --content-width: 1200px;
  --font-sans: "Geist", ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", "PingFang SC", "Microsoft YaHei", sans-serif;
  --font-mono: ui-monospace, SFMono-Regular, "JetBrains Mono", Menlo, Consolas, "Liberation Mono", monospace;
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

body {
  margin: 0;
  font-family: var(--font-sans);
  font-size: 14px;
  line-height: 1.55;
  color: var(--foreground);
  background: var(--background);
  font-synthesis: none;
  -webkit-text-size-adjust: 100%;
}

button,
input,
select,
textarea {
  font: inherit;
  color: inherit;
}

button {
  cursor: pointer;
}

h1,
h2,
p {
  margin-top: 0;
}

h1 {
  font-size: 22px;
  font-weight: 600;
  letter-spacing: -0.01em;
  margin-bottom: 4px;
}

h2 {
  font-size: 15px;
  font-weight: 600;
  margin-bottom: 14px;
}

small,
.muted {
  color: var(--muted-foreground);
}

.hidden {
  display: none !important;
}

code,
pre {
  font-family: var(--font-mono);
}

/* ---------- layout ---------- */

.app {
  display: grid;
  grid-template-columns: 224px minmax(0, 1fr);
  min-height: 100vh;
}

.sidebar {
  position: sticky;
  top: 0;
  height: 100vh;
  display: flex;
  flex-direction: column;
  padding: 16px 12px;
  background: var(--sidebar);
  border-right: 1px solid var(--sidebar-border);
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 4px 8px 22px;
  font-size: 15px;
  font-weight: 600;
  letter-spacing: -0.01em;
}

.brand-mark {
  display: grid;
  place-items: center;
  width: 28px;
  height: 28px;
  border-radius: 8px;
  background: var(--primary);
  color: var(--primary-foreground);
  font-size: 13px;
  font-weight: 700;
}

.sidebar nav {
  display: grid;
  gap: 2px;
}

.nav,
.ghost {
  border: 0;
  background: transparent;
  color: var(--muted-foreground);
  text-align: left;
  padding: 8px 10px;
  border-radius: 8px;
  font-size: 14px;
}

.nav:hover {
  background: var(--sidebar-accent);
  color: var(--sidebar-accent-foreground);
}

.nav.active {
  background: var(--sidebar-accent);
  color: var(--sidebar-accent-foreground);
  font-weight: 500;
}

.logout {
  margin-top: auto;
  width: 100%;
}

.main {
  min-width: 0;
  padding: 32px 28px 72px;
}

.content {
  width: 100%;
  max-width: var(--content-width);
  margin-inline: auto;
}

.page-head,
.panel-head,
.pager,
.actions,
.inline {
  display: flex;
  align-items: center;
  gap: 12px;
}

.page-head {
  justify-content: space-between;
  margin-bottom: 22px;
}

.page-head p {
  color: var(--muted-foreground);
  margin: 0;
  font-size: 13px;
}

.panel-head {
  justify-content: space-between;
}

.panel {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 18px 20px;
  margin-bottom: 18px;
  min-width: 0;
}

.grid {
  display: grid;
  gap: 18px;
}

.grid.two {
  grid-template-columns: repeat(2, minmax(0, 1fr));
}

.cards {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
  gap: 12px;
  margin-bottom: 18px;
}

.card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 15px 17px;
}

.card .label {
  color: var(--muted-foreground);
  font-size: 12px;
}

.card .value {
  font-size: 22px;
  font-weight: 600;
  letter-spacing: -0.01em;
  margin-top: 6px;
  font-variant-numeric: tabular-nums;
}

/* ---------- controls ---------- */

.primary,
.secondary,
.danger {
  border-radius: 8px;
  padding: 8px 14px;
  font-size: 13px;
  font-weight: 500;
  border: 1px solid transparent;
  transition: background-color 0.15s ease, border-color 0.15s ease, color 0.15s ease;
}

.primary {
  background: var(--primary);
  color: var(--primary-foreground);
}

.primary:hover {
  background: oklch(0.28 0.005 106);
}

.secondary {
  background: var(--card);
  border-color: var(--border);
  color: var(--foreground);
}

.secondary:hover {
  background: var(--accent);
}

.secondary:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

.danger {
  background: var(--card);
  border-color: color-mix(in oklab, var(--destructive) 30%, var(--border));
  color: var(--destructive);
}

.danger:hover {
  background: color-mix(in oklab, var(--destructive) 8%, var(--card));
}

.text-btn {
  border: 0;
  background: none;
  color: oklch(0.42 0.008 106);
  padding: 4px 8px;
  border-radius: 6px;
  font-size: 13px;
}

.text-btn:hover {
  background: var(--accent);
  color: var(--foreground);
}

.full {
  width: 100%;
}

.stack {
  display: grid;
  gap: 14px;
}

.stack label,
label {
  display: grid;
  gap: 6px;
  font-size: 13px;
  font-weight: 500;
}

input,
select,
textarea {
  width: 100%;
  border: 1px solid var(--input);
  border-radius: 8px;
  background: var(--card);
  padding: 8px 10px;
  font-size: 13px;
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}

input:focus,
select:focus,
textarea:focus {
  outline: none;
  border-color: var(--ring);
  box-shadow: 0 0 0 3px color-mix(in oklab, var(--ring) 25%, transparent);
}

textarea {
  resize: vertical;
}

.check {
  display: flex;
  align-items: center;
  gap: 8px;
}

.check input {
  width: auto;
}

input[type="checkbox"] {
  accent-color: var(--primary);
}

.actions {
  margin: 14px 0;
}

.filters {
  display: grid;
  grid-template-columns: 1.1fr 1.4fr 1fr 1fr 1fr auto;
  gap: 10px;
}

.field {
  display: grid;
  gap: 7px;
  font-size: 13px;
  font-weight: 500;
}

.field-label {
  color: var(--muted-foreground);
  font-size: 13px;
  font-weight: 500;
}

.models-toolbar {
  display: flex;
  gap: 8px;
  align-items: center;
}

.models-toolbar input {
  flex: 1;
}

.models-toolbar .text-btn {
  white-space: nowrap;
}

.models-list {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(230px, 1fr));
  gap: 6px 14px;
  max-height: 216px;
  overflow: auto;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--card);
  padding: 10px;
}

.models-list .check {
  font-weight: 400;
  font-size: 12px;
}

.models-list code {
  font-size: 12px;
  word-break: break-all;
}

/* ---------- tables ---------- */

.table-wrap {
  overflow: auto;
}

table {
  border-collapse: collapse;
  width: 100%;
  font-size: 13px;
}

th,
td {
  text-align: left;
  padding: 10px 12px;
  border-bottom: 1px solid var(--border);
  vertical-align: top;
}

th {
  color: var(--muted-foreground);
  font-weight: 500;
  white-space: nowrap;
}

tbody tr:last-child td {
  border-bottom: 0;
}

tbody tr:hover td {
  background: color-mix(in oklab, var(--muted) 55%, transparent);
}

th.num,
td.num {
  text-align: right;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

td.num .error {
  display: block;
  text-align: left;
  white-space: normal;
}

td code {
  font-size: 12px;
  color: var(--muted-foreground);
}

.row-actions {
  display: flex;
  gap: 4px;
  flex-wrap: wrap;
}

.badge {
  display: inline-flex;
  align-items: center;
  border-radius: 999px;
  padding: 2px 8px;
  font-size: 11px;
  font-weight: 500;
  background: var(--muted);
  color: var(--muted-foreground);
  border: 1px solid var(--border);
  white-space: nowrap;
}

.badge.ok {
  background: var(--secondary);
  color: var(--foreground);
}

.badge.bad {
  background: color-mix(in oklab, var(--destructive) 10%, var(--card));
  color: var(--destructive);
  border-color: color-mix(in oklab, var(--destructive) 25%, var(--border));
}

/* ---------- overview ---------- */

.usage-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(130px, 1fr));
  gap: 10px;
}

.usage-item {
  padding: 12px 14px;
  background: var(--muted);
  border: 1px solid var(--border);
  border-radius: 10px;
}

.usage-item strong {
  display: block;
  font-size: 18px;
  font-weight: 600;
  margin: 4px 0;
  font-variant-numeric: tabular-nums;
}

.usage-json {
  white-space: pre-wrap;
  word-break: break-word;
  font-size: 12px;
  max-height: 320px;
  overflow: auto;
}

.chart {
  display: flex;
  align-items: flex-end;
  gap: 6px;
  min-height: 200px;
  padding-top: 16px;
  overflow-x: auto;
}

.bar-col {
  flex: 1 0 8px;
  min-width: 8px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: flex-end;
  height: 180px;
  gap: 8px;
}

.bar {
  width: 100%;
  max-width: 22px;
  min-height: 2px;
  border-radius: 4px 4px 0 0;
  background: var(--chart-3);
}

.bar-label {
  font-size: 10px;
  color: var(--muted-foreground);
  writing-mode: vertical-rl;
  max-height: 56px;
}

.pager {
  justify-content: flex-end;
  margin-top: 16px;
}

.pager button {
  padding: 6px 10px;
}

pre {
  background: var(--foreground);
  color: oklch(0.985 0.002 106);
  border-radius: 10px;
  padding: 14px 16px;
  overflow: auto;
  font-size: 12px;
  line-height: 1.6;
}

/* ---------- login, dialogs, toast ---------- */

.login-wrap {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px;
  background: radial-gradient(circle at 50% 0%, oklch(0.97 0.003 106), var(--background) 62%);
}

.login-card {
  width: 100%;
  max-width: 380px;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 32px;
  box-shadow: 0 16px 50px oklch(0.145 0.004 106 / 8%);
}

.login-card .brand-mark {
  margin-bottom: 18px;
}

.login-card label {
  margin: 16px 0;
}

.error {
  color: var(--destructive);
  min-height: 20px;
  font-size: 13px;
}

.toast {
  position: fixed;
  right: 24px;
  bottom: 24px;
  background: var(--foreground);
  color: var(--background);
  padding: 10px 16px;
  border-radius: 10px;
  box-shadow: 0 10px 30px oklch(0.145 0.004 106 / 18%);
  z-index: 30;
  font-size: 13px;
  max-width: min(420px, calc(100% - 48px));
}

.toast.bad {
  background: var(--destructive);
  color: oklch(0.985 0.002 106);
}

dialog {
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 0;
  width: min(560px, calc(100% - 32px));
  box-shadow: 0 24px 70px oklch(0.145 0.004 106 / 18%);
}

dialog::backdrop {
  background: oklch(0.145 0.004 106 / 35%);
}

.dialog-form {
  display: grid;
  gap: 14px;
  padding: 22px;
}

.secret {
  user-select: all;
  word-break: break-all;
  white-space: pre-wrap;
}

#totp-qr {
  background: #fff;
  padding: 6px;
  border: 1px solid var(--border);
  width: 200px;
}

code {
  word-break: break-all;
}

/* ---------- responsive ---------- */

@media (max-width: 1024px) {
  .grid.two {
    grid-template-columns: 1fr;
  }

  .filters {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }
}

@media (max-width: 760px) {
  .app {
    grid-template-columns: 1fr;
  }

  .sidebar {
    position: static;
    height: auto;
    border-right: 0;
    border-bottom: 1px solid var(--sidebar-border);
  }

  .brand {
    padding-bottom: 12px;
  }

  .sidebar nav {
    display: flex;
    overflow-x: auto;
  }

  .logout {
    display: none;
  }

  .main {
    padding: 20px 14px 48px;
  }

  .filters {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .page-head {
    flex-direction: column;
    align-items: flex-start;
    gap: 12px;
  }

  .usage-grid {
    grid-template-columns: 1fr;
  }
}
