:root {
  color-scheme: dark;
  --bg: #0d1020;
  --sidebar: #121629;
  --panel: rgba(28, 33, 61, 0.88);
  --panel-strong: #1d2341;
  --border: rgba(143, 157, 220, 0.18);
  --text: #f4f6ff;
  --muted: #98a1c3;
  --primary: #7468ff;
  --primary-2: #4d90ff;
  --success: #55d6a1;
  --warning: #f7c76c;
  --danger: #ff7d8e;
  font-family: Inter, "Noto Sans TC", "Microsoft JhengHei", system-ui, sans-serif;
}

* { box-sizing: border-box; }
html, body { margin: 0; min-height: 100%; background: var(--bg); color: var(--text); }
body { min-height: 100vh; background-image: radial-gradient(circle at 85% 10%, rgba(101, 74, 255, .16), transparent 32%), radial-gradient(circle at 20% 90%, rgba(50, 134, 255, .1), transparent 35%); }
button, input { font: inherit; }
button, .button-link { cursor: pointer; }
.hidden { display: none !important; }
.muted { color: var(--muted); }
.eyebrow { margin: 0 0 8px; color: #8490c9; font-size: 12px; font-weight: 800; letter-spacing: .14em; }

.login-shell { min-height: 100vh; display: grid; place-items: center; padding: 24px; }
.login-card { width: min(420px, 100%); padding: 38px; border: 1px solid var(--border); border-radius: 24px; background: rgba(20, 24, 46, .94); box-shadow: 0 30px 80px rgba(0,0,0,.36); }
.login-card h1 { margin: 10px 0 8px; font-size: 30px; }
.brand-mark { width: 54px; height: 54px; display: grid; place-items: center; border-radius: 16px; background: linear-gradient(135deg, var(--primary), var(--primary-2)); color: white; font-size: 25px; font-weight: 900; box-shadow: 0 10px 30px rgba(93, 93, 255, .35); }
.brand-mark.small { width: 42px; height: 42px; border-radius: 13px; font-size: 20px; }
form { display: grid; gap: 16px; margin-top: 28px; }
label { display: grid; gap: 8px; color: #cbd1ec; font-size: 14px; font-weight: 700; }
input { width: 100%; border: 1px solid var(--border); border-radius: 12px; padding: 12px 14px; color: var(--text); background: #11162b; outline: none; }
input:focus { border-color: var(--primary); box-shadow: 0 0 0 3px rgba(116, 104, 255, .16); }
.form-error, .form-message { min-height: 20px; margin: 0; color: var(--danger); font-size: 13px; }
.form-message.success { color: var(--success); }

.primary, .secondary, .config-list button, .button-link { min-height: 40px; display: inline-flex; align-items: center; justify-content: center; gap: 8px; border-radius: 11px; padding: 9px 15px; font-weight: 800; text-decoration: none; transition: .18s ease; }
.primary { border: 0; color: white; background: linear-gradient(135deg, var(--primary), #536eff); box-shadow: 0 8px 24px rgba(91, 91, 245, .24); }
.primary:hover { transform: translateY(-1px); filter: brightness(1.08); }
.secondary, .config-list button { border: 1px solid var(--border); color: #d7dcf5; background: rgba(19, 24, 47, .82); }
.secondary:hover, .config-list button:hover { border-color: #756aff; color: white; }
.full { width: 100%; }

.app-shell { min-height: 100vh; display: grid; grid-template-columns: 260px 1fr; }
.sidebar { position: sticky; top: 0; height: 100vh; display: flex; flex-direction: column; padding: 26px 18px; border-right: 1px solid var(--border); background: rgba(16, 20, 39, .96); backdrop-filter: blur(16px); }
.brand { display: flex; align-items: center; gap: 13px; padding: 0 10px 28px; }
.brand strong { display: block; font-size: 18px; }
.brand span { display: block; margin-top: 3px; color: var(--muted); font-size: 12px; }
nav { display: grid; gap: 8px; }
.nav-item { width: 100%; display: flex; align-items: center; gap: 13px; border: 0; border-radius: 12px; padding: 13px 15px; color: var(--muted); background: transparent; text-align: left; font-weight: 800; }
.nav-item span { width: 24px; color: #8792ce; font-size: 19px; text-align: center; }
.nav-item:hover, .nav-item.active { color: white; background: linear-gradient(90deg, rgba(106, 96, 255, .24), rgba(81, 108, 255, .1)); }
.nav-item.active span { color: #7ea8ff; }
.sidebar-foot { margin-top: auto; }

main { min-width: 0; padding: 34px clamp(24px, 4vw, 62px) 60px; }
.topbar { display: flex; align-items: center; justify-content: space-between; gap: 20px; margin-bottom: 28px; }
.topbar h1 { margin: 0; font-size: clamp(28px, 3vw, 40px); letter-spacing: -.03em; }
.top-actions { display: flex; align-items: center; gap: 12px; font-size: 12px; }
.view { display: none; }
.view.active { display: block; animation: fade .2s ease; }
@keyframes fade { from { opacity: 0; transform: translateY(4px); } to { opacity: 1; transform: none; } }

.notice { display: flex; align-items: center; justify-content: space-between; gap: 18px; margin-bottom: 24px; padding: 16px 18px; border: 1px solid rgba(247, 199, 108, .3); border-radius: 14px; background: rgba(247, 199, 108, .09); }
.notice strong, .notice span { display: block; }
.notice span { margin-top: 3px; color: #d3c7a5; font-size: 13px; }
.stats-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 18px; }
.stat-card { position: relative; min-height: 156px; display: grid; grid-template-columns: auto 1fr auto; align-items: center; gap: 20px; padding: 24px; border: 1px solid var(--border); border-radius: 20px; overflow: hidden; background: var(--panel); }
.stat-card::after { content: ""; position: absolute; right: -50px; bottom: -80px; width: 190px; height: 190px; border-radius: 50%; background: rgba(117, 104, 255, .12); }
.stat-icon { width: 58px; height: 58px; display: grid; place-items: center; border-radius: 18px; background: rgba(113, 103, 255, .16); color: #9c95ff; font-size: 28px; }
.stat-card.blue .stat-icon { color: #76b0ff; background: rgba(70, 141, 255, .15); }
.stat-card span { color: #b9c0df; font-size: 14px; font-weight: 700; }
.stat-card strong { display: block; margin: 4px 0; font-size: 38px; }
.stat-card small { color: var(--muted); }
.status-pill { position: relative; z-index: 1; align-self: start; padding: 7px 10px; border: 1px solid var(--border); border-radius: 999px; font-size: 11px !important; }
.status-pill.ok { color: var(--success); border-color: rgba(85,214,161,.3); background: rgba(85,214,161,.09); }
.status-pill.error { color: var(--danger); border-color: rgba(255,125,142,.3); background: rgba(255,125,142,.09); }

.panel-grid, .settings-grid { display: grid; grid-template-columns: 1.15fr .85fr; gap: 18px; margin-top: 18px; }
.panel { padding: 26px; border: 1px solid var(--border); border-radius: 20px; background: var(--panel); }
.panel h2 { margin: 0 0 8px; font-size: 22px; }
.panel p:not(.eyebrow) { color: var(--muted); line-height: 1.7; }
.hero-panel { background: linear-gradient(135deg, rgba(42, 48, 91, .95), rgba(52, 36, 98, .83)); }
.hero-panel .primary { margin-top: 18px; }
.section-head { display: flex; align-items: end; justify-content: space-between; gap: 20px; margin-bottom: 18px; }
.section-head h2 { margin: 0 0 7px; font-size: 24px; }
.section-head p { margin: 0; color: var(--muted); }

.table-wrap { overflow: hidden; border: 1px solid var(--border); border-radius: 18px; background: var(--panel); }
table { width: 100%; border-collapse: collapse; }
th { padding: 15px 18px; color: #939dc7; background: rgba(10, 14, 30, .35); font-size: 12px; letter-spacing: .05em; text-align: left; }
td { padding: 17px 18px; border-top: 1px solid var(--border); color: #d7dcf3; font-size: 14px; }
td strong { color: white; }
td small { display: block; margin-top: 4px; color: var(--muted); }
td code { color: #83b2ff; font-family: ui-monospace, Consolas, monospace; font-size: 14px; }
.row-actions { display: flex; gap: 8px; }
.row-actions button { border: 1px solid var(--border); border-radius: 9px; padding: 7px 10px; color: #cfd5f0; background: rgba(13, 17, 35, .8); }
.empty { padding: 48px 20px; color: var(--muted); text-align: center; }

.config-list { margin: 20px 0 0; }
.config-list > div { display: grid; grid-template-columns: 130px minmax(0, 1fr); gap: 16px; padding: 15px 0; border-top: 1px solid var(--border); }
.config-list dt { color: var(--muted); font-size: 13px; }
.config-list dd { min-width: 0; display: flex; align-items: center; justify-content: space-between; gap: 12px; margin: 0; }
.config-list code { color: #87b5ff; font-family: ui-monospace, Consolas, monospace; overflow-wrap: anywhere; }
.config-list button { min-height: 32px; flex: 0 0 auto; padding: 6px 10px; font-size: 12px; }
.config-list.compact { margin-top: 12px; }
.config-list.compact > div { grid-template-columns: 100px minmax(0, 1fr); padding: 10px 0; }
.config-list.compact dd { display: block; color: #a9c7ff; font-family: ui-monospace, Consolas, monospace; font-size: 13px; }
.truncate { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.button-row { display: flex; flex-wrap: wrap; gap: 10px; margin-top: 22px; }
.settings-grid form { margin-top: 18px; }

.toast { position: fixed; right: 24px; bottom: 24px; z-index: 20; max-width: 380px; padding: 13px 17px; border: 1px solid var(--border); border-radius: 12px; color: white; background: #242b4d; box-shadow: 0 15px 40px rgba(0,0,0,.34); opacity: 0; transform: translateY(12px); pointer-events: none; transition: .2s ease; }
.toast.show { opacity: 1; transform: none; }
.toast.error { border-color: rgba(255,125,142,.4); background: #452436; }

@media (max-width: 900px) {
  .app-shell { grid-template-columns: 82px 1fr; }
  .sidebar { padding-inline: 11px; }
  .brand { justify-content: center; padding-inline: 0; }
  .brand > div:last-child, .nav-item:not(#logoutButton) { font-size: 0; }
  .nav-item { justify-content: center; padding-inline: 8px; }
  .nav-item span { font-size: 20px; }
  .stats-grid, .panel-grid, .settings-grid { grid-template-columns: 1fr; }
}

@media (max-width: 640px) {
  .app-shell { display: block; }
  .sidebar { position: fixed; z-index: 10; right: 0; bottom: 0; left: 0; top: auto; width: auto; height: 68px; flex-direction: row; align-items: center; padding: 8px; border: 1px solid var(--border); }
  .brand, .sidebar-foot { display: none; }
  nav { width: 100%; grid-template-columns: repeat(4, 1fr); }
  .nav-item { padding: 10px 4px; }
  main { padding: 24px 16px 92px; }
  .topbar, .section-head { align-items: flex-start; flex-direction: column; }
  .top-actions { width: 100%; justify-content: space-between; }
  .stat-card { grid-template-columns: auto 1fr; }
  .status-pill { position: absolute; top: 16px; right: 16px; }
  .table-wrap { overflow-x: auto; }
  table { min-width: 760px; }
  .config-list > div { grid-template-columns: 1fr; }
}
