/* Google Material Design (MD3) Pure Monochrome Black & White System */
:root,
html[data-theme="light"] {
  --bg: #ffffff;
  --surface: #ffffff;
  --surface-container: #f4f4f4;
  --surface-hover: #ebebeb;
  --ink: #0a0a0a;
  --ink-muted: #5f6368;
  --outline: #e0e0e0;
  --outline-strong: #0a0a0a;
  --primary: #0a0a0a;
  --on-primary: #ffffff;
  --primary-hover: #262626;
  --tonal: #efefef;
  --on-tonal: #0a0a0a;
  --shadow: 0 1px 2px rgba(0, 0, 0, 0.06), 0 1px 3px rgba(0, 0, 0, 0.04);
  --shadow-lg: 0 12px 32px rgba(0, 0, 0, 0.16);
  --backdrop: rgba(0, 0, 0, 0.45);
}

html[data-theme="dark"] {
  --bg: #000000;
  --surface: #0e0e0e;
  --surface-container: #1a1a1a;
  --surface-hover: #252525;
  --ink: #ffffff;
  --ink-muted: #9aa0a6;
  --outline: #2b2b2b;
  --outline-strong: #ffffff;
  --primary: #ffffff;
  --on-primary: #000000;
  --primary-hover: #e5e5e5;
  --tonal: #1f1f1f;
  --on-tonal: #ffffff;
  --shadow: 0 1px 2px rgba(0, 0, 0, 0.45);
  --shadow-lg: 0 16px 40px rgba(0, 0, 0, 0.72);
  --backdrop: rgba(0, 0, 0, 0.72);
}

*, *::before, *::after { box-sizing: border-box; }
[hidden] { display: none !important; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: "Roboto", "Google Sans", "Segoe UI", "PingFang SC", "Microsoft YaHei", sans-serif;
  font-size: 14px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  transition: background-color 0.2s ease, color 0.2s ease;
}

button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
button:disabled { opacity: 0.38; cursor: not-allowed; }
button:focus-visible, a:focus-visible, input:focus-visible, select:focus-visible, textarea:focus-visible {
  outline: 2px solid var(--outline-strong);
  outline-offset: 2px;
}

.app { max-width: 1200px; margin: 0 auto; padding: 0 24px; min-height: 100vh; display: flex; flex-direction: column; }
main { flex: 1; padding: 24px 0 40px; }

/* Top App Bar */
.appbar {
  height: 68px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  border-bottom: 1px solid var(--outline);
}
.brand { display: inline-flex; align-items: center; gap: 12px; color: inherit; text-decoration: none; }
.brand-mark {
  width: 36px; height: 36px; border-radius: 10px;
  background: var(--primary); color: var(--on-primary);
  display: grid; place-items: center;
  font-weight: 700; font-size: 17px; letter-spacing: -0.5px;
}
.brand-text { display: flex; flex-direction: column; line-height: 1.2; }
.brand-text strong { font-size: 15px; font-weight: 600; letter-spacing: 0.2px; }
.brand-text small { font-size: 11px; color: var(--ink-muted); }
.appbar-actions { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }

/* MD3 Typography & Helpers */
.overline { display: block; font-size: 11px; font-weight: 600; letter-spacing: 1.2px; color: var(--ink-muted); margin-bottom: 4px; }
h1 { margin: 0; font-size: 26px; font-weight: 500; letter-spacing: -0.4px; }
h2 { margin: 0; font-size: 16px; font-weight: 500; letter-spacing: -0.1px; }
.subtext { margin: 6px 0 0; font-size: 13px; color: var(--ink-muted); }
.helper { margin: 10px 0 0; font-size: 12px; color: var(--ink-muted); }
.mono, code { font-family: ui-monospace, "Cascadia Code", Consolas, monospace; font-size: 12px; }

/* MD3 Cards */
.md-card {
  background: var(--surface);
  border: 1px solid var(--outline);
  border-radius: 16px;
  padding: 24px;
  box-shadow: var(--shadow);
}

/* MD3 Buttons */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  height: 40px; padding: 0 20px; border-radius: 20px;
  border: 1px solid transparent; font-size: 13px; font-weight: 500;
  background: transparent; transition: background-color 0.15s ease, border-color 0.15s ease, opacity 0.15s ease;
  white-space: nowrap;
}
.btn.compact { height: 34px; padding: 0 14px; font-size: 12px; }
.btn.full { width: 100%; height: 44px; margin-top: 14px; }
.btn.filled { background: var(--primary); color: var(--on-primary); }
.btn.filled:hover:not(:disabled) { background: var(--primary-hover); }
.btn.tonal { background: var(--tonal); color: var(--on-tonal); }
.btn.tonal:hover:not(:disabled) { background: var(--surface-hover); }
.btn.outlined { border-color: var(--outline); color: var(--ink); background: transparent; }
.btn.outlined:hover:not(:disabled) { background: var(--surface-container); border-color: var(--outline-strong); }
.btn.text { color: var(--ink); padding: 0 12px; }
.btn.text:hover:not(:disabled) { background: var(--surface-container); }
.btn-row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }

/* Chips & Status Pills */
.chip {
  display: inline-flex; align-items: center; gap: 7px;
  height: 32px; padding: 0 12px; border-radius: 16px;
  background: var(--surface-container); color: var(--ink);
  font-size: 12px; font-weight: 500; border: 1px solid var(--outline);
}
.status-chip .dot { width: 7px; height: 7px; border-radius: 50%; background: var(--ink); }
.status-chip.down .dot { background: transparent; border: 1.5px solid var(--ink-muted); }

/* Login View */
.loading-state { text-align: center; padding: 96px 0; color: var(--ink-muted); }
.login-wrap { display: grid; place-items: center; min-height: calc(100vh - 200px); }
.login-card { width: min(440px, 100%); padding: 32px; }
.card-head { margin-bottom: 24px; }
.form-error { margin: 10px 0 0; min-height: 18px; font-size: 12px; font-weight: 500; color: var(--ink); text-decoration: underline; text-underline-offset: 3px; }
.form-error:empty { text-decoration: none; }

/* Fields & Inputs (MD3 Outlined) */
.field { margin-bottom: 16px; }
.field label { display: block; font-size: 12px; font-weight: 500; color: var(--ink-muted); margin-bottom: 6px; }
.opt { font-weight: 400; opacity: 0.75; }
input, select, textarea {
  width: 100%; height: 42px; padding: 0 14px;
  border: 1px solid var(--outline); border-radius: 8px;
  background: var(--bg); color: var(--ink);
  transition: border-color 0.15s ease;
}
input:hover, select:hover, textarea:hover { border-color: var(--ink-muted); }
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--outline-strong); box-shadow: inset 0 0 0 1px var(--outline-strong); }
input::placeholder { color: var(--ink-muted); opacity: 0.75; }
.input-with-action { position: relative; display: flex; align-items: center; }
.input-with-action input { padding-right: 68px; }
.input-with-action button { position: absolute; right: 4px; }
.field-grid { display: grid; grid-template-columns: 1.35fr 1fr; gap: 12px; }
.joined { display: flex; }
.joined input { border-radius: 8px 0 0 8px; min-width: 0; }
.joined select { width: 82px; border-radius: 0 8px 8px 0; border-left: 0; padding: 0 10px; }

/* Console Header & MD3 Segmented Switcher */
.console-top {
  display: flex; align-items: flex-end; justify-content: space-between;
  gap: 16px; flex-wrap: wrap; margin-bottom: 20px;
}
.segmented {
  display: inline-grid; grid-template-columns: repeat(2, minmax(0, 1fr));
  padding: 4px; gap: 4px; border-radius: 24px;
  background: var(--surface-container); border: 1px solid var(--outline);
}
.seg-btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  height: 38px; padding: 0 18px; border-radius: 20px; border: 0;
  background: transparent; color: var(--ink-muted); font-size: 13px; font-weight: 500;
  transition: background-color 0.15s ease, color 0.15s ease;
}
.seg-btn:hover { color: var(--ink); }
.seg-btn.active { background: var(--primary); color: var(--on-primary); }
.seg-btn code { font-size: 11px; opacity: 0.8; }

/* Live Monitoring Metrics */
.metrics {
  display: grid; grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 14px; margin-bottom: 20px;
}
.metric { padding: 18px 20px; display: flex; flex-direction: column; gap: 4px; }
.metric-label { font-size: 12px; color: var(--ink-muted); font-weight: 500; }
.metric strong { font-size: 28px; font-weight: 500; letter-spacing: -0.8px; line-height: 1.15; }
.metric-sub { font-size: 11px; color: var(--ink-muted); }

/* Workspace Grid */
.grid-two { display: grid; grid-template-columns: 420px 1fr; gap: 16px; margin-bottom: 16px; }
.section-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 18px; }
.title-inline { display: flex; align-items: center; gap: 10px; }

/* Filter Chips (Presets) */
.preset-row { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.chip-btn {
  height: 36px; border-radius: 8px; border: 1px solid var(--outline);
  background: var(--bg); color: var(--ink); font-size: 12px; font-weight: 500;
  transition: background-color 0.15s ease, color 0.15s ease, border-color 0.15s ease;
}
.chip-btn:hover { background: var(--surface-container); }
.chip-btn.active { background: var(--primary); color: var(--on-primary); border-color: var(--primary); }

/* Result Panel */
.result-card { display: flex; flex-direction: column; }
.empty-box {
  flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center;
  text-align: center; padding: 40px 20px;
  border: 1px dashed var(--outline); border-radius: 12px; color: var(--ink-muted);
}
.empty-box strong { color: var(--ink); font-weight: 500; margin-bottom: 4px; }
.empty-box p { margin: 0; font-size: 12px; }
.result-body { display: flex; flex-direction: column; flex: 1; gap: 12px; }
.result-body .helper { margin: 0; }
#result {
  flex: 1; min-height: 240px; height: auto; padding: 14px;
  font-family: ui-monospace, "Cascadia Code", Consolas, monospace;
  font-size: 12px; line-height: 1.9; resize: vertical;
  background: var(--surface-container); white-space: pre;
}

/* History & Table */
.toolbar { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; margin-bottom: 16px; }
.toolbar input { max-width: 260px; }
.toolbar select { max-width: 140px; }
.toolbar-note { margin-left: auto; font-size: 12px; color: var(--ink-muted); }

.table-wrap { overflow-x: auto; border: 1px solid var(--outline); border-radius: 12px; }
table { width: 100%; border-collapse: collapse; font-size: 13px; white-space: nowrap; }
th {
  text-align: left; font-size: 11px; font-weight: 600; color: var(--ink-muted);
  background: var(--surface-container); padding: 12px 14px; border-bottom: 1px solid var(--outline);
}
td { padding: 14px; border-bottom: 1px solid var(--outline); vertical-align: middle; }
tbody tr:last-child td { border-bottom: 0; }
tbody tr:hover { background: var(--surface-container); }
th.right, td.right { text-align: right; }
.note-line { display: block; font-size: 12px; color: var(--ink-muted); margin-top: 2px; max-width: 240px; overflow: hidden; text-overflow: ellipsis; }
.table-empty { text-align: center; padding: 40px 16px; color: var(--ink-muted); }

/* Monochrome Status Badges */
.badge {
  display: inline-flex; align-items: center; gap: 6px;
  height: 24px; padding: 0 10px; border-radius: 12px;
  font-size: 11px; font-weight: 500; border: 1px solid var(--outline);
}
.badge::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: currentColor; }
.badge.active, .badge.online { background: var(--primary); color: var(--on-primary); border-color: var(--primary); }
.badge.unused { background: var(--surface-container); color: var(--ink); }
.badge.expired, .badge.offline { background: transparent; color: var(--ink-muted); }
.badge.revoked { background: transparent; color: var(--ink-muted); text-decoration: line-through; }
.badge.revoked::before { background: transparent; border: 1px solid var(--ink-muted); }

.row-actions { display: inline-flex; gap: 6px; justify-content: flex-end; }
.reveal-row td { background: var(--surface-container); padding: 10px 14px; }
.reveal-row:hover td { background: var(--surface-container); }
.reveal-box {
  display: flex; align-items: center; justify-content: space-between;
  gap: 12px; flex-wrap: wrap;
}
.reveal-meta { display: flex; align-items: center; gap: 10px; min-width: 0; flex: 1; flex-wrap: wrap; }
.reveal-tag {
  font-size: 11px; font-weight: 600; color: var(--ink-muted);
  letter-spacing: 0.4px; white-space: nowrap;
}
.reveal-code {
  padding: 6px 10px; border-radius: 8px;
  background: var(--bg); border: 1px solid var(--outline);
  font-size: 12px; user-select: all; word-break: break-all;
}
.pager { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-top: 16px; flex-wrap: wrap; }
.pager .helper { margin: 0; }
.pager-controls { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; }
.page-numbers { display: inline-flex; align-items: center; gap: 4px; flex-wrap: wrap; }
.page-num {
  min-width: 34px; height: 34px; padding: 0 10px; border-radius: 17px;
  border: 1px solid var(--outline); background: transparent; color: var(--ink);
  font-size: 12px; font-weight: 500;
  display: inline-flex; align-items: center; justify-content: center;
  transition: background-color 0.15s ease, color 0.15s ease, border-color 0.15s ease;
}
.page-num:hover:not(:disabled) { background: var(--surface-container); border-color: var(--outline-strong); }
.page-num.active { background: var(--primary); color: var(--on-primary); border-color: var(--primary); }
.page-ellipsis { padding: 0 4px; color: var(--ink-muted); font-size: 12px; user-select: none; }
.jump-form { display: inline-flex; align-items: center; gap: 6px; font-size: 12px; color: var(--ink-muted); }
.jump-form input { width: 64px; height: 34px; padding: 0 8px; text-align: center; }

/* Footer */
.footer {
  border-top: 1px solid var(--outline); padding: 18px 0;
  display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap;
  font-size: 12px; color: var(--ink-muted);
}
.footer a { color: var(--ink); text-decoration: none; font-weight: 500; }
.footer a:hover { text-decoration: underline; }

/* MD3 Snackbar */
.snackbar {
  position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%);
  max-width: calc(100vw - 32px); padding: 12px 20px; border-radius: 8px;
  background: var(--primary); color: var(--on-primary);
  font-size: 13px; font-weight: 500; box-shadow: var(--shadow-lg); z-index: 20;
}
.snackbar.bad { background: var(--surface); color: var(--ink); border: 1.5px solid var(--outline-strong); }

/* MD3 Dialogs */
.md-dialog {
  width: min(460px, calc(100vw - 32px)); padding: 28px;
  border-radius: 24px; border: 1px solid var(--outline);
  background: var(--surface); color: var(--ink); box-shadow: var(--shadow-lg);
}
.md-dialog.wide-dialog { width: min(760px, calc(100vw - 32px)); }
.md-dialog::backdrop { background: var(--backdrop); }
.code-box {
  display: block; padding: 12px 14px; margin: 16px 0 20px;
  border-radius: 8px; background: var(--surface-container);
  border: 1px solid var(--outline); word-break: break-all;
}
.dialog-actions { display: flex; justify-content: flex-end; gap: 8px; }

@media (max-width: 960px) {
  .metrics { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .grid-two { grid-template-columns: 1fr; }
}
@media (max-width: 640px) {
  .app { padding: 0 16px; }
  .appbar { height: auto; padding: 12px 0; flex-wrap: wrap; }
  .segmented { width: 100%; }
  .toolbar input, .toolbar select { max-width: none; flex: 1 1 140px; }
  .toolbar-note { width: 100%; margin-left: 0; }
  .md-card { padding: 18px; }
}
@media (prefers-reduced-motion: reduce) { * { transition: none !important; } }
