/* DB 稽核查詢 UI */
:root {
  color-scheme: light;
  --bg: #f4f4f2;
  --surface: #fcfcfb;
  --surface-2: #f0efec;
  --border: rgba(11, 11, 11, 0.10);
  --text: #0b0b0b;
  --text-2: #52514e;
  --muted: #6f6e69;
  --link: #1f62b3;
  --accent: #2a78d6;
  --accent-text: #ffffff;
  --grid: #e1e0d9;
  --axis: #c3c2b7;
  --series-1: #2a78d6;
  --series-1-hover: #5b97e0;
  --good: #0ca30c;
  --warning: #fab219;
  --critical: #d03b3b;
  --critical-text: #b42f2f;
  --critical-bg: rgba(208, 59, 59, 0.10);
  --warning-bg: rgba(250, 178, 25, 0.16);
  --env-uat: #2a78d6;
  --env-prod: #1baf7a;
  --radius: 10px;
  --shadow: 0 1px 2px rgba(0, 0, 0, 0.04);
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang TC", "Noto Sans TC", "Microsoft JhengHei", sans-serif;
  --mono: ui-monospace, SFMono-Regular, Menlo, Consolas, "Liberation Mono", monospace;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --bg: #121211;
    --surface: #1a1a19;
    --surface-2: #232321;
    --border: rgba(255, 255, 255, 0.10);
    --text: #f0efec;
    --text-2: #c3c2b7;
    --muted: #9a998f;
    --link: #79aef0;
    --accent: #3987e5;
    --grid: #2c2c2a;
    --axis: #383835;
    --series-1: #3987e5;
    --series-1-hover: #6aa5ec;
    --critical-text: #f08a8a;
    --critical-bg: rgba(208, 59, 59, 0.18);
    --warning-bg: rgba(250, 178, 25, 0.14);
    --env-uat: #3987e5;
    --env-prod: #199e70;
  }
}
:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #121211;
  --surface: #1a1a19;
  --surface-2: #232321;
  --border: rgba(255, 255, 255, 0.10);
  --text: #f0efec;
  --text-2: #c3c2b7;
  --muted: #9a998f;
  --link: #79aef0;
  --accent: #3987e5;
  --grid: #2c2c2a;
  --axis: #383835;
  --series-1: #3987e5;
  --series-1-hover: #6aa5ec;
  --critical-text: #f08a8a;
  --critical-bg: rgba(208, 59, 59, 0.18);
  --warning-bg: rgba(250, 178, 25, 0.14);
  --env-uat: #3987e5;
  --env-prod: #199e70;
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font: 14px/1.5 var(--font);
  -webkit-font-smoothing: antialiased;
}
a { color: var(--link); text-decoration: none; }
a:hover { text-decoration: underline; }
h1 { font-size: 20px; margin: 0 0 4px; }
h2 { font-size: 15px; margin: 0; font-weight: 600; }
code, pre, .mono { font-family: var(--mono); font-size: 12.5px; }
.muted { color: var(--muted); }
.small { font-size: 12px; }
.nowrap { white-space: nowrap; }
.num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }

/* 版面 */
.container { max-width: 1440px; margin: 0 auto; padding: 16px; display: flex; flex-direction: column; gap: 16px; }
.topbar { background: var(--surface); border-bottom: 1px solid var(--border); position: sticky; top: 0; z-index: 10; }
.topbar-inner { max-width: 1440px; margin: 0 auto; padding: 0 16px; height: 52px; display: flex; align-items: center; gap: 24px; }
.brand { font-weight: 700; color: var(--text); font-size: 15px; }
.brand:hover { text-decoration: none; }
.nav { display: flex; gap: 4px; flex: 1; }
.nav a { color: var(--text-2); padding: 6px 10px; border-radius: 6px; }
.nav a:hover { background: var(--surface-2); text-decoration: none; }
.nav a.active { color: var(--text); background: var(--surface-2); font-weight: 600; }
.logout { display: flex; align-items: center; gap: 8px; margin: 0; }

.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 16px; box-shadow: var(--shadow); min-width: 0; }
.card-head { display: flex; align-items: baseline; justify-content: space-between; gap: 12px; margin-bottom: 12px; flex-wrap: wrap; }

/* 表單 */
.filters { display: flex; flex-direction: column; gap: 12px; }
.filter-row { display: flex; flex-wrap: wrap; gap: 12px; align-items: flex-end; }
.field { display: flex; flex-direction: column; gap: 4px; min-width: 150px; }
.field > span { font-size: 12px; color: var(--text-2); }
.field-wide { flex: 1; min-width: 220px; }
input, select {
  font: inherit; color: var(--text); background: var(--surface);
  border: 1px solid var(--axis); border-radius: 6px; padding: 6px 8px; height: 34px; min-width: 0;
}
input:focus, select:focus, button:focus-visible, a:focus-visible, summary:focus-visible, [tabindex]:focus-visible {
  outline: 2px solid var(--accent); outline-offset: 1px;
}
.check { display: flex; align-items: center; gap: 6px; height: 34px; color: var(--text-2); }
.check input { height: auto; }
.chips { display: flex; gap: 6px; flex-wrap: wrap; }
.chip {
  font: inherit; font-size: 13px; color: var(--text-2); background: var(--surface-2);
  border: 1px solid var(--border); border-radius: 999px; padding: 0 12px; height: 34px; cursor: pointer;
}
.chip:hover { color: var(--text); border-color: var(--axis); }
.filter-actions { display: flex; gap: 8px; }
.btn {
  font: inherit; display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  height: 34px; padding: 0 14px; border-radius: 6px; border: 1px solid transparent; cursor: pointer; white-space: nowrap;
}
.btn:hover { text-decoration: none; }
.btn-primary { background: var(--accent); color: var(--accent-text); font-weight: 600; }
.btn-primary:hover { filter: brightness(1.08); }
.btn-ghost { background: transparent; color: var(--text-2); border-color: var(--border); }
.btn-ghost:hover { background: var(--surface-2); color: var(--text); }
.btn-block { width: 100%; }

.alert { padding: 10px 14px; border-radius: 8px; border: 1px solid var(--border); }
.alert-error { background: var(--critical-bg); color: var(--critical-text); }
.alert-warning { background: var(--warning-bg); }

/* 統計 */
.tiles { display: grid; grid-template-columns: repeat(5, minmax(0, 1fr)); gap: 16px; }
.tile { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 14px 16px; }
.tile-label { font-size: 12px; color: var(--text-2); }
.tile-value { font-size: 26px; font-weight: 600; font-variant-numeric: tabular-nums; margin-top: 2px; }
.tile-value a.tile-link-critical { color: var(--critical-text); }
.duration { font-variant-numeric: tabular-nums; font-weight: 600; }

.grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 16px; }
.span-all { grid-column: 1 / -1; }

table { border-collapse: collapse; width: 100%; }
table.mini td, table.mini th { padding: 5px 6px; border-bottom: 1px solid var(--grid); text-align: left; }
table.mini th { font-size: 12px; color: var(--text-2); font-weight: 500; }
table.mini tr:last-child td { border-bottom: 0; }
table.bars td:first-child { white-space: nowrap; max-width: 170px; overflow: hidden; text-overflow: ellipsis; }
.bar-cell { width: 45%; }
.bar { display: block; height: 10px; min-width: 2px; background: var(--series-1); border-radius: 0 4px 4px 0; }

.env-tag { display: inline-flex; align-items: center; gap: 4px; font-size: 11px; color: var(--text-2); font-weight: 600; letter-spacing: 0.02em; }
.env-tag::before { content: ""; width: 7px; height: 7px; border-radius: 50%; background: var(--axis); }
.env-tag.env-uat::before { background: var(--env-uat); }
.env-tag.env-prod::before { background: var(--env-prod); }

/* 趨勢圖 */
.chart { position: relative; height: 220px; }
.chart svg { display: block; overflow: visible; }
.chart .grid-line { stroke: var(--grid); stroke-width: 1; shape-rendering: crispEdges; }
.chart .baseline { stroke: var(--axis); stroke-width: 1; shape-rendering: crispEdges; }
.chart .tick { fill: var(--muted); font-size: 11px; font-family: var(--font); }
.chart .bar-mark { fill: var(--series-1); pointer-events: none; }
.chart .hit { fill: transparent; cursor: pointer; outline: none; }
.chart .hit:hover + .bar-mark, .chart .hit:focus + .bar-mark { fill: var(--series-1-hover); }
.chart .hit:focus-visible { stroke: var(--accent); stroke-width: 2; }
.tooltip {
  position: absolute; pointer-events: none; z-index: 5; min-width: 120px;
  background: var(--surface); color: var(--text); border: 1px solid var(--border); border-radius: 8px;
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.12); padding: 8px 10px; font-size: 12px; white-space: nowrap;
}
.tooltip strong { display: block; font-size: 15px; font-variant-numeric: tabular-nums; }
.table-view { margin-top: 8px; }
.table-view summary { cursor: pointer; color: var(--text-2); font-size: 12px; }
.table-view table { max-width: 360px; margin-top: 8px; }

/* 紀錄表 */
.table-scroll { overflow-x: auto; }
table.events th, table.events td { padding: 8px 10px; border-bottom: 1px solid var(--grid); text-align: left; vertical-align: top; }
table.events th { font-size: 12px; color: var(--text-2); font-weight: 500; position: sticky; top: 0; background: var(--surface); }
table.events tbody tr:hover { background: var(--surface-2); }
.sql-col { min-width: 360px; width: 100%; }
.sql-col code { overflow-wrap: anywhere; }
details.sql summary { cursor: pointer; list-style: none; }
details.sql summary::-webkit-details-marker { display: none; }
details.sql summary::before { content: "▸ "; color: var(--muted); }
details.sql[open] summary::before { content: "▾ "; }
details.sql pre {
  white-space: pre-wrap; overflow-wrap: anywhere; background: var(--surface-2); border-radius: 6px;
  padding: 10px; margin: 8px 0 4px; max-height: 420px; overflow: auto;
}
.empty { text-align: center; color: var(--muted); padding: 32px !important; }
.pager { display: flex; align-items: center; justify-content: center; gap: 8px; margin-top: 12px; flex-wrap: wrap; }

.status { display: inline-flex; align-items: center; gap: 4px; font-size: 12px; font-weight: 600; padding: 2px 8px; border-radius: 999px; }
.status-good { color: var(--good); background: rgba(12, 163, 12, 0.10); }
.status-critical { color: var(--critical-text); background: var(--critical-bg); }
.status-warning { color: var(--text); background: var(--warning-bg); }
.status-unknown { color: var(--muted); background: var(--surface-2); }
.error-text { min-width: 240px; color: var(--critical-text); word-break: break-word; }
.note { margin: 0; }

/* 登入 */
.login-wrap { min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: 16px; }
.login-card { width: 100%; max-width: 360px; display: flex; flex-direction: column; gap: 14px; padding: 28px; }
.login-card .field { min-width: 0; }

@media (max-width: 960px) {
  .grid { grid-template-columns: minmax(0, 1fr); }
  .tiles { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}
@media (max-width: 600px) {
  .topbar-inner { gap: 12px; }
  .brand { display: none; }
  .field, .field-wide { min-width: 0; flex: 1 1 100%; }
  .chips { gap: 4px; }
  .chip { padding: 0 10px; }
  .tile-value { font-size: 22px; }
}
