:root {
  --bg: #f4f6f9;
  --surface: #ffffff;
  --surface-muted: #f8fafc;
  --text: #172033;
  --text-soft: #64748b;
  --border: #e2e8f0;
  --primary: #2563eb;
  --primary-dark: #1d4ed8;
  --primary-soft: #eff6ff;
  --danger: #dc2626;
  --danger-soft: #fef2f2;
  --success: #15803d;
  --success-soft: #f0fdf4;
  --warning: #b45309;
  --warning-soft: #fffbeb;
  --sidebar: #111827;
  --sidebar-soft: #1f2937;
  --radius: 12px;
  --shadow: 0 1px 2px rgba(15, 23, 42, .04), 0 8px 24px rgba(15, 23, 42, .05);
  --focus: 0 0 0 3px rgba(37, 99, 235, .2);
  color-scheme: light;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", sans-serif;
}

* { box-sizing: border-box; }
html { min-width: 320px; background: var(--bg); }
body { margin: 0; color: var(--text); background: var(--bg); font-size: 14px; line-height: 1.55; }
button, input, select, textarea { font: inherit; }
button { cursor: pointer; }
button:disabled { cursor: not-allowed; opacity: .55; }
a { color: var(--primary); }
h1, h2, h3, p { margin-top: 0; }
[hidden] { display: none !important; }

.visually-hidden { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0, 0, 0, 0); white-space: nowrap; border: 0; }
.skip-link { position: fixed; z-index: 1000; top: 8px; left: 8px; transform: translateY(-150%); padding: 8px 12px; border-radius: 8px; color: #fff; background: var(--primary); }
.skip-link:focus { transform: none; }
:focus-visible { outline: none; box-shadow: var(--focus); }

.login-view { min-height: 100vh; display: grid; place-items: center; padding: 24px; background: radial-gradient(circle at 20% 10%, #dbeafe 0, transparent 28%), radial-gradient(circle at 80% 90%, #e0e7ff 0, transparent 25%), #f8fafc; }
.login-card { width: min(100%, 420px); padding: 42px; border: 1px solid rgba(226, 232, 240, .9); border-radius: 18px; background: rgba(255, 255, 255, .96); box-shadow: 0 24px 60px rgba(15, 23, 42, .1); }
.login-brand, .brand-mark { display: grid; place-items: center; color: #fff; background: linear-gradient(145deg, #2563eb, #4338ca); font-weight: 800; }
.login-brand { width: 48px; height: 48px; margin-bottom: 24px; border-radius: 13px; font-size: 22px; }
.login-card h1 { margin-bottom: 8px; font-size: 28px; letter-spacing: -.02em; }
.login-intro, .login-footnote { color: var(--text-soft); }
.login-footnote { margin: 20px 0 0; text-align: center; font-size: 12px; }
.eyebrow { margin-bottom: 6px; color: var(--primary); font-size: 11px; font-weight: 800; letter-spacing: .13em; text-transform: uppercase; }
.stack-form { display: grid; gap: 10px; margin-top: 28px; }
.stack-form label, .field > label, .toolbar label { font-weight: 650; }
.form-error { margin: 0; color: var(--danger); font-size: 13px; }

input, select, textarea { width: 100%; border: 1px solid #cbd5e1; border-radius: 8px; color: var(--text); background: #fff; transition: border-color .15s, box-shadow .15s; }
input, select { min-height: 42px; padding: 8px 11px; }
textarea { padding: 10px 11px; resize: vertical; }
input:hover, select:hover, textarea:hover { border-color: #94a3b8; }
input:focus, select:focus, textarea:focus { border-color: var(--primary); outline: none; box-shadow: var(--focus); }
input:disabled, select:disabled, textarea:disabled { color: #94a3b8; background: #f1f5f9; }

.button { display: inline-flex; min-height: 38px; align-items: center; justify-content: center; gap: 6px; padding: 8px 14px; border: 1px solid transparent; border-radius: 8px; font-weight: 700; text-decoration: none; transition: background .15s, border-color .15s, transform .05s; }
.button:active:not(:disabled) { transform: translateY(1px); }
.button-primary { color: #fff; background: var(--primary); }
.button-primary:hover { background: var(--primary-dark); }
.button-secondary { color: #334155; border-color: #cbd5e1; background: #fff; }
.button-secondary:hover { border-color: #94a3b8; background: #f8fafc; }
.button-danger { color: #fff; background: var(--danger); }
.button-danger:hover { background: #b91c1c; }
.button-ghost { color: #cbd5e1; border-color: #374151; background: transparent; }
.button-ghost:hover { color: #fff; background: #1f2937; }
.button-block { width: 100%; }
.text-button { padding: 3px 0; border: 0; color: var(--primary); background: transparent; font-weight: 700; }
.text-button:hover { text-decoration: underline; }
.icon-button { display: grid; width: 40px; height: 40px; place-items: center; padding: 0; border: 0; border-radius: 8px; color: inherit; background: transparent; font-size: 24px; }
.icon-button:hover { background: rgba(148, 163, 184, .15); }

.app-view { min-height: 100vh; }
.sidebar { position: fixed; z-index: 30; inset: 0 auto 0 0; display: flex; width: 248px; flex-direction: column; padding: 24px 16px; color: #e5e7eb; background: var(--sidebar); }
.brand { display: flex; align-items: center; gap: 12px; padding: 2px 8px 26px; }
.brand-mark { width: 40px; height: 40px; flex: 0 0 auto; border-radius: 10px; }
.brand strong, .brand small, .admin-summary strong, .admin-summary small { display: block; }
.brand strong { color: #fff; font-size: 16px; }
.brand small { color: #94a3b8; font-size: 11px; }
.nav-list { display: grid; gap: 5px; }
.nav-item { display: flex; width: 100%; align-items: center; gap: 12px; padding: 11px 12px; border: 0; border-radius: 8px; color: #aeb8c8; background: transparent; text-align: left; font-weight: 650; }
.nav-item > span:first-child { width: 20px; color: #94a3b8; font-size: 18px; text-align: center; }
.nav-item:hover { color: #fff; background: var(--sidebar-soft); }
.nav-item.is-active { color: #fff; background: #2563eb; }
.nav-item.is-active > span:first-child { color: #fff; }
.sidebar-footer { margin-top: auto; padding-top: 18px; border-top: 1px solid #293244; }
.admin-summary { display: flex; align-items: center; gap: 10px; margin-bottom: 14px; padding: 0 4px; }
.admin-summary small { color: #8b98aa; font-size: 11px; }
.avatar { display: grid; width: 34px; height: 34px; place-items: center; border-radius: 50%; color: #bfdbfe; background: #1e3a8a; font-weight: 800; }
.workspace { min-height: 100vh; margin-left: 248px; }
.topbar { display: flex; min-height: 116px; align-items: center; justify-content: space-between; gap: 24px; padding: 24px 36px 20px; border-bottom: 1px solid var(--border); background: rgba(255, 255, 255, .9); }
.topbar h1 { margin-bottom: 2px; font-size: 25px; letter-spacing: -.02em; }
.page-description { margin: 0; color: var(--text-soft); }
.content { width: 100%; max-width: 1600px; margin: 0 auto; padding: 28px 36px 52px; }
.page { animation: page-in .16s ease-out; }
@keyframes page-in { from { opacity: .5; transform: translateY(3px); } to { opacity: 1; transform: none; } }
.mobile-header, .sidebar-backdrop { display: none; }

.stat-grid { display: grid; grid-template-columns: repeat(6, minmax(0, 1fr)); gap: 14px; margin-bottom: 22px; }
.stat-card { min-width: 0; padding: 18px; border: 1px solid var(--border); border-radius: var(--radius); background: var(--surface); box-shadow: 0 1px 2px rgba(15, 23, 42, .03); }
.stat-card span, .stat-card small { display: block; color: var(--text-soft); }
.stat-card strong { display: block; margin: 6px 0 2px; font-size: 29px; line-height: 1.1; }
.stat-card small { font-size: 11px; }
.stat-card-recording strong { color: var(--primary); }
.stat-card-danger strong { color: var(--danger); }
.dashboard-grid { display: grid; grid-template-columns: minmax(0, 1.65fr) minmax(280px, .75fr); gap: 18px; }
.panel { border: 1px solid var(--border); border-radius: var(--radius); background: var(--surface); box-shadow: var(--shadow); }
.panel-heading { display: flex; align-items: flex-start; justify-content: space-between; gap: 16px; padding: 20px 22px; border-bottom: 1px solid var(--border); }
.panel-heading h2, .settings-heading h2 { margin-bottom: 2px; font-size: 17px; }
.panel-heading p, .settings-heading p { margin: 0; color: var(--text-soft); font-size: 12px; }
.recording-list { min-height: 214px; }
.recording-item { display: flex; align-items: center; justify-content: space-between; gap: 18px; padding: 16px 22px; border-bottom: 1px solid var(--border); }
.recording-item:last-child { border-bottom: 0; }
.recording-main { display: flex; min-width: 0; align-items: center; gap: 12px; }
.recording-pulse, .recording-dot { border-radius: 50%; background: #94a3b8; }
.recording-pulse { width: 10px; height: 10px; flex: 0 0 auto; background: var(--danger); box-shadow: 0 0 0 5px var(--danger-soft); }
.recording-item strong, .recording-item small { display: block; }
.recording-item small { overflow: hidden; color: var(--text-soft); text-overflow: ellipsis; white-space: nowrap; }
.recording-actions { display: flex; flex: 0 0 auto; gap: 12px; }
.health-summary { display: grid; gap: 14px; padding: 22px; }
.health-row { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.health-row span { color: var(--text-soft); }
.health-row strong { font-size: 16px; }
.health-summary + .button { width: calc(100% - 44px); margin: 0 22px 22px; }

.toolbar { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 16px; }
.toolbar-filters { justify-content: flex-start; align-items: flex-end; }
.toolbar-filters label { display: grid; min-width: 180px; gap: 5px; color: var(--text-soft); font-size: 12px; }
.search-field { display: flex; width: min(100%, 420px); align-items: center; gap: 8px; padding: 0 10px; border: 1px solid #cbd5e1; border-radius: 8px; background: #fff; }
.search-field:focus-within { border-color: var(--primary); box-shadow: var(--focus); }
.search-field input { border: 0; box-shadow: none; }
.search-field input:focus { box-shadow: none; }
.notice { margin-bottom: 16px; padding: 11px 14px; border: 1px solid; border-radius: 9px; font-size: 12px; }
.notice-info { color: #1e40af; border-color: #bfdbfe; background: var(--primary-soft); }
.notice-muted { color: #475569; border-color: var(--border); background: #f8fafc; }
.table-panel { overflow: hidden; }
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; text-align: left; }
th { padding: 11px 16px; color: var(--text-soft); background: var(--surface-muted); font-size: 11px; font-weight: 800; letter-spacing: .03em; text-transform: uppercase; white-space: nowrap; }
td { padding: 15px 16px; border-top: 1px solid var(--border); vertical-align: middle; }
tbody tr:hover { background: #fbfdff; }
.actions-column { text-align: right; }
.cell-title { display: block; max-width: 300px; overflow: hidden; color: var(--text); text-overflow: ellipsis; white-space: nowrap; }
.cell-subtitle { display: block; max-width: 340px; overflow: hidden; margin-top: 2px; color: var(--text-soft); font-size: 11px; text-overflow: ellipsis; white-space: nowrap; }
.cell-actions { display: flex; justify-content: flex-end; flex-wrap: wrap; gap: 6px; }
.mini-button { min-height: 30px; padding: 4px 8px; border: 1px solid #cbd5e1; border-radius: 6px; color: #334155; background: #fff; font-size: 12px; font-weight: 700; }
.mini-button:hover { border-color: #94a3b8; background: #f8fafc; }
.mini-button-danger { color: var(--danger); border-color: #fecaca; }
.mini-button-danger:hover { background: var(--danger-soft); }
.status-badge, .config-badge { display: inline-flex; align-items: center; gap: 6px; padding: 3px 8px; border-radius: 999px; font-size: 11px; font-weight: 800; white-space: nowrap; }
.status-badge::before { width: 6px; height: 6px; border-radius: 50%; background: currentColor; content: ""; }
.status-recording { color: var(--danger); background: var(--danger-soft); }
.status-monitoring, .status-success, .status-done { color: var(--success); background: var(--success-soft); }
.status-disabled { color: #64748b; background: #f1f5f9; }
.status-error, .status-failed { color: var(--danger); background: var(--danger-soft); }
.status-pending { color: var(--warning); background: var(--warning-soft); }
.status-uploading { color: var(--primary); background: var(--primary-soft); }
.mode-badge { color: #475569; font-size: 12px; font-weight: 700; }
.empty-state { padding: 62px 20px; color: var(--text-soft); text-align: center; }
.empty-state > span { display: block; margin-bottom: 8px; color: #94a3b8; font-size: 32px; }
.empty-state h2 { margin-bottom: 4px; color: var(--text); font-size: 17px; }
.empty-state p { margin-bottom: 16px; }
.log-panel { overflow: hidden; }
.log-output { min-height: 440px; max-height: 65vh; overflow: auto; margin: 0; padding: 20px; color: #d1d5db; background: #111827; font: 12px/1.7 ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace; white-space: pre-wrap; overflow-wrap: anywhere; }

.settings-layout { display: grid; gap: 18px; }
.settings-card { padding: 22px; }
.settings-heading { display: flex; align-items: flex-start; justify-content: space-between; gap: 16px; margin-bottom: 20px; padding-bottom: 16px; border-bottom: 1px solid var(--border); }
.config-badge { color: #64748b; background: #f1f5f9; }
.config-badge.is-configured { color: var(--success); background: var(--success-soft); }
.form-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 16px; }
.form-grid-three { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.field { display: grid; align-content: start; gap: 6px; }
.field-full { grid-column: 1 / -1; }
.field-span-two { grid-column: span 2; }
.field-help { margin: 0; color: var(--text-soft); font-size: 11px; }
.label-row { display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.clear-option { display: inline-flex; align-items: center; gap: 6px; margin: 10px 16px 0 0; color: var(--text-soft); font-size: 12px; }
.clear-option input { width: 16px; min-height: 16px; }
.inline-actions { display: flex; align-items: center; gap: 12px; margin-top: 18px; }
.inline-result { color: var(--text-soft); font-size: 12px; }
.inline-result.is-success { color: var(--success); }
.inline-result.is-error { color: var(--danger); }
.settings-submit-bar { position: sticky; z-index: 5; bottom: 14px; display: flex; align-items: center; justify-content: space-between; gap: 18px; padding: 14px 18px; border: 1px solid #bfdbfe; border-radius: 11px; background: rgba(239, 246, 255, .96); box-shadow: 0 10px 30px rgba(15, 23, 42, .12); backdrop-filter: blur(8px); }
.settings-submit-bar p { margin: 0; color: #475569; font-size: 12px; }

.modal { width: min(calc(100% - 32px), 620px); max-height: calc(100vh - 36px); padding: 0; overflow: hidden; border: 0; border-radius: 14px; color: var(--text); background: var(--surface); box-shadow: 0 30px 80px rgba(15, 23, 42, .3); }
.modal-wide { width: min(calc(100% - 32px), 920px); }
.modal::backdrop { background: rgba(15, 23, 42, .58); backdrop-filter: blur(2px); }
.modal > form { display: flex; max-height: calc(100vh - 36px); flex-direction: column; }
.modal-header, .modal-footer { display: flex; align-items: center; justify-content: space-between; gap: 16px; padding: 18px 22px; }
.modal-header { border-bottom: 1px solid var(--border); }
.modal-header h2 { margin: 0; font-size: 20px; }
.modal-header .eyebrow { margin-bottom: 2px; }
.modal-body { overflow-y: auto; padding: 22px; }
.modal-body > p:last-child { margin-bottom: 0; }
.modal-footer { justify-content: flex-end; border-top: 1px solid var(--border); background: var(--surface-muted); }
.form-section + .form-section { margin-top: 24px; padding-top: 22px; border-top: 1px solid var(--border); }
.section-heading { margin-bottom: 16px; }
.section-heading h3 { margin-bottom: 2px; font-size: 15px; }
.section-heading p { margin: 0; color: var(--text-soft); font-size: 12px; }
.switch-field { align-content: center; }
.switch-field > span { font-weight: 650; }
.switch { display: flex; align-items: center; gap: 9px; cursor: pointer; }
.switch input { position: absolute; width: 1px; height: 1px; opacity: 0; }
.switch > span { position: relative; width: 38px; height: 22px; border-radius: 999px; background: #cbd5e1; transition: background .15s; }
.switch > span::after { position: absolute; top: 3px; left: 3px; width: 16px; height: 16px; border-radius: 50%; background: #fff; box-shadow: 0 1px 3px rgba(15, 23, 42, .3); content: ""; transition: transform .15s; }
.switch input:checked + span { background: var(--primary); }
.switch input:checked + span::after { transform: translateX(16px); }
.switch input:focus-visible + span { box-shadow: var(--focus); }
.switch strong { font-size: 12px; }
.token-field { margin-bottom: 14px; }
.token-actions { display: flex; align-items: center; flex-wrap: wrap; gap: 6px; color: var(--text-soft); font-size: 11px; }
.token-actions button { padding: 2px 7px; border: 1px solid #bfdbfe; border-radius: 5px; color: #1d4ed8; background: #eff6ff; font-size: 11px; }
.preview-toolbar { display: flex; align-items: flex-end; gap: 10px; margin-top: 12px; }
.preview-toolbar label { display: grid; gap: 4px; color: var(--text-soft); font-size: 11px; }
.template-preview { margin-top: 12px; padding: 14px; border: 1px solid var(--border); border-radius: 8px; background: var(--surface-muted); }
.template-preview p:last-child { margin-bottom: 0; }
.preview-message { padding: 12px; border-left: 3px solid var(--primary); background: #fff; }
.preview-message strong, .preview-message span { display: block; }
.preview-message span { margin-top: 4px; white-space: pre-wrap; }
.payload-preview { max-height: 200px; overflow: auto; margin: 12px 0 0; padding: 10px; border-radius: 6px; color: #d1d5db; background: #111827; font: 11px/1.55 ui-monospace, monospace; white-space: pre-wrap; overflow-wrap: anywhere; }
.modal-confirm { width: min(calc(100% - 32px), 440px); }
.toast-region { position: fixed; z-index: 100; top: 18px; right: 18px; display: grid; width: min(calc(100% - 36px), 380px); gap: 8px; }
.toast { padding: 12px 14px; border: 1px solid; border-radius: 9px; box-shadow: var(--shadow); animation: toast-in .18s ease-out; }
.toast-success { color: #166534; border-color: #bbf7d0; background: #f0fdf4; }
.toast-error { color: #991b1b; border-color: #fecaca; background: #fef2f2; }
.toast-info { color: #1e40af; border-color: #bfdbfe; background: #eff6ff; }
@keyframes toast-in { from { opacity: 0; transform: translateY(-6px); } }
.noscript { position: fixed; z-index: 1000; inset: 0; display: grid; place-items: center; padding: 24px; color: #fff; background: #111827; font-size: 18px; }
.loading-row td { padding: 42px 16px; color: var(--text-soft); text-align: center; }
.recording-dot.is-active { background: var(--danger); box-shadow: 0 0 0 4px rgba(220, 38, 38, .16); }

@media (max-width: 1180px) {
  .stat-grid { grid-template-columns: repeat(3, minmax(0, 1fr)); }
}

@media (max-width: 900px) {
  .mobile-header { position: fixed; z-index: 25; inset: 0 0 auto; display: flex; height: 58px; align-items: center; justify-content: space-between; padding: 0 14px; color: #fff; background: var(--sidebar); }
  .mobile-brand { font-weight: 750; }
  .mobile-header .recording-dot { width: 9px; height: 9px; }
  .sidebar { z-index: 40; width: min(82vw, 280px); transform: translateX(-105%); box-shadow: 18px 0 50px rgba(15, 23, 42, .3); transition: transform .2s ease; }
  .sidebar.is-open { transform: none; }
  .sidebar-backdrop { position: fixed; z-index: 35; inset: 0; border: 0; background: rgba(15, 23, 42, .55); }
  .sidebar-backdrop.is-open { display: block; }
  .workspace { margin: 58px 0 0; }
  .topbar { min-height: 105px; padding: 20px 22px; }
  .content { padding: 22px 20px 42px; }
  .dashboard-grid { grid-template-columns: 1fr; }
  .form-grid-three { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}

@media (max-width: 680px) {
  .login-card { padding: 30px 24px; }
  .topbar { align-items: flex-start; padding: 18px 16px; }
  .topbar .eyebrow, .page-description { display: none; }
  .topbar h1 { margin-top: 6px; font-size: 21px; }
  .content { padding: 16px 12px 36px; }
  .stat-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; }
  .stat-card { padding: 14px; }
  .stat-card strong { font-size: 25px; }
  .toolbar { align-items: stretch; flex-direction: column; }
  .toolbar .button, .search-field { width: 100%; }
  .toolbar-filters label { width: 100%; }
  .notice { font-size: 11px; }
  .panel-heading { padding: 16px; }
  .recording-item { align-items: flex-start; flex-direction: column; padding: 15px 16px; }
  .recording-actions { width: 100%; justify-content: flex-end; }
  .health-summary { padding: 18px 16px; }
  .health-summary + .button { width: calc(100% - 32px); margin: 0 16px 16px; }
  .table-wrap { overflow: visible; }
  table, tbody, tr, td { display: block; width: 100%; }
  thead { display: none; }
  tbody { padding: 8px; }
  tbody tr { margin-bottom: 10px; padding: 8px 10px; border: 1px solid var(--border); border-radius: 9px; background: #fff; }
  tbody tr:last-child { margin-bottom: 0; }
  td { display: grid; grid-template-columns: 106px minmax(0, 1fr); gap: 8px; padding: 8px 4px; border: 0; }
  td::before { color: var(--text-soft); content: attr(data-label); font-size: 11px; font-weight: 750; }
  td:first-child { display: block; padding-bottom: 12px; border-bottom: 1px solid var(--border); }
  td:first-child::before { display: none; }
  td:last-child { display: block; padding-top: 12px; border-top: 1px solid var(--border); }
  td:last-child::before { display: block; margin-bottom: 7px; }
  .cell-actions { justify-content: flex-start; }
  .loading-row td { display: block; }
  .loading-row td::before { display: none; }
  .form-grid, .form-grid-three { grid-template-columns: 1fr; }
  .field-full, .field-span-two { grid-column: auto; }
  .settings-card { padding: 16px; }
  .settings-heading { align-items: flex-start; }
  .settings-submit-bar { align-items: stretch; flex-direction: column; bottom: 8px; }
  .settings-submit-bar .button { width: 100%; }
  .modal, .modal-wide { width: 100%; max-width: none; height: 100%; max-height: none; border-radius: 0; }
  .modal > form { height: 100%; max-height: none; }
  .modal-header, .modal-footer, .modal-body { padding-left: 16px; padding-right: 16px; }
  .preview-toolbar { align-items: stretch; flex-direction: column; }
  .preview-toolbar .button { width: 100%; }
  .modal-confirm { width: min(calc(100% - 24px), 440px); height: auto; border-radius: 12px; }
  .modal-confirm .modal-body { min-height: auto; }
  .toast-region { top: 68px; right: 12px; width: calc(100% - 24px); }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { scroll-behavior: auto !important; animation-duration: .01ms !important; transition-duration: .01ms !important; }
}
