:root {
  color-scheme: light;
  --bg: #f7faff;
  --surface: rgba(255, 255, 255, .84);
  --surface-solid: #fff;
  --ink: #102039;
  --ink-soft: #4d607d;
  --muted: #74839c;
  --blue: #176bff;
  --blue-strong: #095cf1;
  --blue-pale: #eaf2ff;
  --line: #d3def0;
  --line-strong: #a8c3f1;
  --success: #169a62;
  --danger: #ca3f53;
  --shadow: 0 22px 60px rgba(54, 92, 148, .13), 0 4px 14px rgba(54, 92, 148, .06);
  --soft-shadow: 0 10px 30px rgba(54, 92, 148, .09);
}

html[data-theme="dark"] {
  color-scheme: dark;
  --bg: #0d1522;
  --surface: rgba(20, 31, 49, .88);
  --surface-solid: #162238;
  --ink: #edf4ff;
  --ink-soft: #b2c2d9;
  --muted: #8292aa;
  --blue: #66a0ff;
  --blue-strong: #8cb7ff;
  --blue-pale: #172d4f;
  --line: #2a3b55;
  --line-strong: #48688f;
  --success: #54d49a;
  --danger: #ff8193;
  --shadow: 0 22px 60px rgba(0, 0, 0, .28), 0 4px 14px rgba(0, 0, 0, .16);
  --soft-shadow: 0 10px 30px rgba(0, 0, 0, .2);
}

* { box-sizing: border-box; }
html { min-width: 320px; background: var(--bg); scroll-behavior: smooth; }
body { min-height: 100dvh; margin: 0; overflow-x: hidden; color: var(--ink); background: radial-gradient(circle at 50% 28%, color-mix(in srgb, var(--blue-pale) 56%, transparent), transparent 42%), var(--bg); font-family: Inter, ui-sans-serif, -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Microsoft YaHei", sans-serif; }
button, input { font: inherit; }
button, a { -webkit-tap-highlight-color: transparent; }
button { cursor: pointer; }
button:focus-visible, a:focus-visible, input:focus-visible { outline: 3px solid color-mix(in srgb, var(--blue) 26%, transparent); outline-offset: 2px; }
[hidden] { display: none !important; }

.topbar { min-height: 72px; display: flex; align-items: center; justify-content: space-between; gap: 24px; padding: 0 clamp(24px, 3vw, 44px); border-bottom: 1px solid var(--line); background: color-mix(in srgb, var(--surface-solid) 82%, transparent); backdrop-filter: blur(18px); }
.brand { color: var(--blue-strong); font-size: 23px; font-weight: 800; letter-spacing: -.06em; text-decoration: none; }
.top-actions { display: flex; align-items: center; gap: clamp(14px, 2vw, 28px); }
.user-email { max-width: 240px; overflow: hidden; color: var(--ink-soft); font-size: 14px; text-overflow: ellipsis; white-space: nowrap; }
.admin-badge { padding: 5px 9px; border-radius: 999px; color: var(--blue); background: var(--blue-pale); font-size: 11px; font-weight: 750; }
.text-button { padding: 6px 0; border: 0; color: var(--blue); background: transparent; font-size: 14px; font-weight: 650; }
.theme-toggle { position: relative; width: 66px; height: 34px; display: grid; grid-template-columns: 1fr 1fr; align-items: center; padding: 0 9px; border: 1px solid var(--line); border-radius: 999px; color: var(--muted); background: var(--blue-pale); }
.theme-toggle span { z-index: 1; font-size: 17px; line-height: 1; }
.theme-toggle i { position: absolute; left: 3px; top: 3px; width: 26px; height: 26px; border-radius: 50%; background: var(--surface-solid); box-shadow: 0 3px 10px rgba(43, 75, 124, .18); transition: transform .22s ease; }
html[data-theme="dark"] .theme-toggle i { transform: translateX(32px); }

body[data-view="boot"] .auth-screen, body[data-view="boot"] .app-screen, body[data-view="boot"] .app-only { visibility: hidden; }
body[data-view="auth"] .app-screen, body[data-view="auth"] .app-only { display: none; }
body[data-view="app"] .auth-screen { display: none; }

.auth-screen { min-height: calc(100dvh - 72px); display: grid; place-items: center; padding: 54px 20px 80px; }
.auth-card { width: min(590px, 100%); display: grid; gap: 22px; padding: 42px 54px 44px; border: 1px solid var(--line); border-radius: 24px; background: var(--surface); box-shadow: var(--shadow); backdrop-filter: blur(24px); }
.coordinate { display: flex; align-items: center; gap: 18px; margin: 0; color: var(--ink-soft); font-size: 13px; letter-spacing: .01em; }
.coordinate span + span { padding-left: 18px; border-left: 1px solid var(--line); }
.auth-card h1 { margin: 0; font-size: clamp(30px, 4vw, 40px); letter-spacing: -.055em; }
.auth-tabs { display: grid; grid-template-columns: 1fr 1fr; border-bottom: 1px solid var(--line); }
.auth-tabs button { min-height: 48px; border: 0; border-bottom: 3px solid transparent; color: var(--muted); background: transparent; font-size: 16px; font-weight: 700; }
.auth-tabs button.is-active { border-color: var(--blue); color: var(--blue); }
.auth-form { display: grid; gap: 18px; }
.auth-note { margin: 0; color: var(--muted); font-size: 13px; line-height: 1.6; }
.auth-form label, .modal-card > label { display: grid; gap: 8px; color: var(--ink); font-size: 12px; font-weight: 650; }
input, textarea { width: 100%; border: 1px solid var(--line); border-radius: 11px; color: var(--ink); background: var(--surface-solid); font: inherit; font-size: 15px; transition: border-color .18s ease, box-shadow .18s ease; }
input { min-height: 50px; padding: 0 15px; }
textarea { min-height: 112px; padding: 13px 15px; line-height: 1.65; resize: vertical; }
input:focus, textarea:focus { border-color: var(--blue); box-shadow: 0 0 0 3px color-mix(in srgb, var(--blue) 12%, transparent); outline: 0; }
.remember { display: flex !important; grid-template-columns: auto 1fr; align-items: center; gap: 9px !important; color: var(--ink-soft) !important; font-size: 13px !important; font-weight: 500 !important; }
.remember input { width: 18px; min-height: 18px; height: 18px; padding: 0; accent-color: var(--blue); }
.code-row { display: grid; grid-template-columns: 1fr auto; gap: 12px; align-items: end; }
.code-button { min-height: 50px; }

.primary, .outline { min-height: 48px; display: inline-flex; align-items: center; justify-content: center; gap: 10px; padding: 0 22px; border-radius: 10px; font-size: 15px; font-weight: 750; transition: transform .18s ease, box-shadow .18s ease, background .18s ease; }
.primary { border: 1px solid var(--blue); color: #fff; background: linear-gradient(135deg, var(--blue-strong), #3e7fff); box-shadow: 0 12px 24px rgba(23, 107, 255, .22); }
.primary:hover { transform: translateY(-1px); box-shadow: 0 16px 30px rgba(23, 107, 255, .27); }
.outline { border: 1px solid var(--blue); color: var(--blue); background: color-mix(in srgb, var(--surface-solid) 90%, transparent); }
.outline:hover { background: var(--blue-pale); transform: translateY(-1px); }
.full { width: 100%; }
.form-status, .analysis-status { min-height: 20px; margin: 0; color: var(--muted); font-size: 13px; line-height: 1.5; }
.form-status[data-kind="error"], .analysis-status[data-kind="error"] { color: var(--danger); }
.form-status[data-kind="success"], .analysis-status[data-kind="success"] { color: var(--success); }

.app-screen { width: min(1440px, 100%); display: grid; gap: 24px; margin: 0 auto; padding: 32px clamp(20px, 3vw, 42px) 60px; }
.app-screen, .action-layout, .action-panel, .cli-panel, .section-panel { min-width: 0; }
.action-layout { display: grid; grid-template-columns: minmax(0, 2.1fr) minmax(300px, .95fr); gap: 20px; }
.action-panel, .cli-panel, .section-panel { border: 1px solid var(--line); border-radius: 18px; background: var(--surface); box-shadow: var(--soft-shadow); backdrop-filter: blur(18px); }
.action-panel { min-height: 318px; display: flex; flex-direction: column; justify-content: center; padding: clamp(32px, 5vw, 58px); background-image: radial-gradient(circle at 76% 32%, color-mix(in srgb, var(--blue-pale) 65%, transparent), transparent 38%); }
.action-panel h1 { margin: 0; font-size: clamp(46px, 5vw, 68px); line-height: 1; letter-spacing: -.07em; }
.action-panel > p:not(.analysis-status) { margin: 20px 0 0; color: var(--ink-soft); font-size: 16px; }
.action-buttons { display: flex; flex-wrap: wrap; gap: 18px; margin-top: 42px; }
.start-button { min-width: 300px; min-height: 72px; justify-content: space-between; padding: 0 34px; font-size: 24px; }
.start-button svg { width: 28px; fill: none; stroke: currentColor; stroke-linecap: round; stroke-linejoin: round; stroke-width: 2; }
.action-buttons .outline { min-width: 180px; min-height: 62px; font-size: 17px; }
.analysis-status { margin-top: 16px; }
.cli-panel { min-height: 318px; display: flex; flex-direction: column; padding: 40px; }
.cli-panel h2 { margin: 0; font-size: 23px; letter-spacing: -.035em; }
.cli-state { display: flex; align-items: center; gap: 14px; margin: 34px 0 42px; color: var(--ink-soft); font-size: 18px; }
.cli-state i { width: 44px; height: 44px; display: grid; place-items: center; flex: 0 0 auto; border-radius: 50%; background: var(--blue-pale); }
.cli-state i::after { content: "!"; color: var(--blue); font-weight: 800; }
.cli-state[data-state="bound"] { color: var(--success); }
.cli-state[data-state="bound"] i { background: color-mix(in srgb, var(--success) 14%, transparent); }
.cli-state[data-state="bound"] i::after { content: "✓"; color: var(--success); }
.cli-state[data-state="pending"] i::after { content: "…"; }
.cli-state[data-state="error"] { color: var(--danger); }
.cli-panel small { margin-top: auto; padding-top: 18px; color: var(--muted); font-size: 11px; line-height: 1.6; }
.section-panel { padding: 26px 30px; }
.section-heading { display: flex; align-items: flex-end; justify-content: space-between; gap: 20px; margin-bottom: 20px; }
.section-heading h2 { margin: 0; font-size: 22px; letter-spacing: -.035em; }
.section-heading p, .section-heading > span { margin: 6px 0 0; color: var(--muted); font-size: 12px; }
.rule-list { display: grid; gap: 9px; }
.rule-row { min-height: 64px; display: grid; grid-template-columns: 1fr .7fr 1fr auto; align-items: center; gap: 20px; padding: 0 18px; border: 1px solid var(--line); border-radius: 11px; background: color-mix(in srgb, var(--surface-solid) 80%, transparent); }
.rule-row strong { font-size: 14px; }
.rule-row span { color: var(--ink-soft); font-size: 14px; }
.rule-row small { color: var(--muted); font-size: 12px; }
.rule-actions { display: flex; align-items: center; gap: 5px; }
.icon-button { width: 38px; height: 38px; border: 0; border-radius: 9px; color: var(--blue); background: transparent; font-size: 17px; }
.icon-button:hover { background: var(--blue-pale); }
.icon-button.danger { color: var(--danger); }
.empty-rule { margin: 0; padding: 26px 0; color: var(--muted); font-size: 13px; text-align: center; }
.source-form { display: grid; gap: 9px; }
.source-form > label { color: var(--ink); font-size: 12px; font-weight: 650; }
.source-input-row { display: grid; grid-template-columns: minmax(0, 1fr) auto auto; gap: 12px; }
.source-input-row .primary, .source-input-row .outline { min-width: 132px; }
.source-tip { display: flex; align-items: flex-start; gap: 9px; margin: 10px 0 0; color: var(--muted); font-size: 12px; line-height: 1.6; }
.source-tip i { width: 19px; height: 19px; display: grid; place-items: center; flex: 0 0 auto; border-radius: 50%; color: var(--blue); background: var(--blue-pale); font-size: 11px; font-style: normal; font-weight: 800; }
.default-badge { margin: 0 !important; padding: 8px 12px; border: 1px solid color-mix(in srgb, var(--success) 36%, var(--line)); border-radius: 999px; color: var(--success) !important; background: color-mix(in srgb, var(--success) 8%, transparent); font-weight: 700; white-space: nowrap; }
.settings-form { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 20px; }
.settings-form > label { display: grid; align-content: start; gap: 8px; color: var(--ink); font-size: 12px; font-weight: 650; }
.settings-form > label small, .fixed-setting small { color: var(--muted); font-size: 11px; font-weight: 400; line-height: 1.55; }
.settings-wide { grid-column: 1 / -1; }
.fixed-setting { min-height: 108px; display: grid; align-content: center; gap: 6px; padding: 15px; border: 1px solid var(--line); border-radius: 11px; background: color-mix(in srgb, var(--blue-pale) 48%, transparent); }
.fixed-setting > span { color: var(--ink); font-size: 12px; font-weight: 650; }
.fixed-setting > strong { color: var(--blue); font-size: 22px; letter-spacing: -.02em; }
.settings-footer { grid-column: 1 / -1; display: flex; align-items: center; justify-content: flex-end; gap: 18px; }
.settings-footer .form-status { flex: 1; text-align: right; }
.progress-panel { overflow: hidden; }
.delivery-state { display: inline-flex; align-items: center; gap: 9px; margin: 0 !important; padding: 9px 13px; border: 1px solid var(--line); border-radius: 999px; color: var(--ink-soft) !important; background: color-mix(in srgb, var(--surface-solid) 82%, transparent); font-size: 13px !important; }
.delivery-state i { width: 8px; height: 8px; border-radius: 50%; background: var(--muted); }
.delivery-state[data-status="pending"] { border-color: color-mix(in srgb, var(--blue) 42%, var(--line)); color: var(--blue) !important; }
.delivery-state[data-status="pending"] i { background: var(--blue); box-shadow: 0 0 0 5px color-mix(in srgb, var(--blue) 12%, transparent); animation: status-pulse 1.45s ease-in-out infinite; }
.delivery-state[data-status="done"] { border-color: color-mix(in srgb, var(--success) 42%, var(--line)); color: var(--success) !important; }
.delivery-state[data-status="done"] i { background: var(--success); }
.delivery-state[data-status="failed"] { border-color: color-mix(in srgb, var(--danger) 42%, var(--line)); color: var(--danger) !important; }
.delivery-state[data-status="failed"] i { background: var(--danger); }
.progress-summary { display: grid; grid-template-columns: minmax(220px, .75fr) minmax(0, 1.6fr); align-items: center; gap: clamp(28px, 5vw, 70px); min-height: 184px; padding: clamp(25px, 4vw, 42px); border: 1px solid var(--line); border-radius: 14px; background: linear-gradient(135deg, color-mix(in srgb, var(--blue-pale) 45%, transparent), color-mix(in srgb, var(--surface-solid) 78%, transparent)); }
.progress-copy { display: grid; gap: 12px; }
.progress-copy > strong { font-size: clamp(32px, 4vw, 48px); line-height: 1; letter-spacing: -.055em; }
.progress-copy > span { max-width: 390px; color: var(--ink-soft); font-size: 13px; line-height: 1.7; }
.progress-summary[data-status="pending"] .progress-copy > strong { color: var(--blue); }
.progress-summary[data-status="done"] .progress-copy > strong { color: var(--success); }
.progress-summary[data-status="failed"] .progress-copy > strong { color: var(--danger); }
.progress-steps { position: relative; display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; margin: 0; padding: 0; list-style: none; }
.progress-steps::before { content: ""; position: absolute; z-index: 0; top: 20px; left: 16.66%; right: 16.66%; height: 2px; background: var(--line); }
.progress-steps li { position: relative; z-index: 1; display: grid; justify-items: center; gap: 11px; min-width: 0; color: var(--muted); text-align: center; }
.progress-steps li > i { width: 42px; height: 42px; display: grid; place-items: center; border: 2px solid var(--line); border-radius: 50%; background: var(--surface-solid); font-size: 13px; font-style: normal; font-weight: 800; }
.progress-steps li > span { display: grid; gap: 4px; }
.progress-steps li strong { color: inherit; font-size: 14px; }
.progress-steps li small { color: var(--muted); font-size: 11px; }
.progress-summary[data-status="pending"] [data-step="read"] > i,
.progress-summary[data-status="pending"] [data-step="make"] > i { border-color: var(--blue); color: #fff; background: var(--blue); }
.progress-summary[data-status="pending"] [data-step="read"],
.progress-summary[data-status="pending"] [data-step="make"] { color: var(--blue); }
.progress-summary[data-status="pending"] [data-step="make"] > i { animation: status-pulse 1.45s ease-in-out infinite; }
.progress-summary[data-status="done"] .progress-steps::before { background: var(--success); }
.progress-summary[data-status="done"] .progress-steps li { color: var(--success); }
.progress-summary[data-status="done"] .progress-steps li > i { border-color: var(--success); color: #fff; background: var(--success); }
.progress-summary[data-status="done"] .progress-steps li > i { font-size: 0; }
.progress-summary[data-status="done"] .progress-steps li > i::after { content: "✓"; font-size: 16px; }
.progress-summary[data-status="failed"] .progress-steps li { color: var(--danger); }
.progress-summary[data-status="failed"] .progress-steps li > i { border-color: var(--danger); color: var(--danger); }
@keyframes status-pulse { 50% { box-shadow: 0 0 0 7px color-mix(in srgb, currentColor 10%, transparent); } }

.modal { width: min(610px, calc(100% - 30px)); padding: 0; border: 0; border-radius: 20px; color: var(--ink); background: transparent; box-shadow: var(--shadow); }
.modal::backdrop { background: rgba(8, 18, 34, .34); backdrop-filter: blur(5px); }
.modal-card { display: grid; gap: 18px; margin: 0; padding: 28px; border: 1px solid var(--line); border-radius: 20px; background: var(--surface-solid); }
.modal-card header { display: flex; align-items: flex-start; justify-content: space-between; gap: 20px; }
.modal-card header p { margin: 0 0 5px; color: var(--blue); font-size: 11px; font-weight: 700; letter-spacing: .08em; text-transform: uppercase; }
.modal-card h2 { margin: 0; font-size: 27px; letter-spacing: -.045em; }
.close-button { width: 38px; height: 38px; border: 0; border-radius: 50%; color: var(--muted); background: var(--blue-pale); font-size: 24px; }
.modal-card label small { color: var(--muted); font-size: 11px; font-weight: 400; line-height: 1.5; }
.modal-card footer { display: flex; justify-content: flex-end; align-items: center; gap: 20px; padding-top: 4px; }
.rule-expression { display: grid; grid-template-columns: auto auto 1fr; align-items: center; gap: 10px; color: var(--ink-soft); font-size: 13px; }
.rule-expression > span { min-height: 44px; display: grid; place-items: center; padding: 0 14px; border: 1px solid var(--line); border-radius: 10px; background: var(--blue-pale); }
.binding-card > p { margin: 0; color: var(--ink-soft); font-size: 13px; line-height: 1.7; }
.binding-qr { display: grid; justify-items: center; gap: 8px; padding: 14px; border: 1px solid var(--line); border-radius: 12px; background: #fff; }
.binding-qr img { width: 190px; height: 190px; display: block; }
.binding-qr small { color: #627089; font-size: 11px; }
.authorization-link { min-height: 50px; display: grid; place-items: center; border: 1px solid var(--blue); border-radius: 10px; color: var(--blue); font-size: 14px; font-weight: 700; text-decoration: none; }

@media (max-width: 900px) {
  .action-layout { grid-template-columns: 1fr; }
  .cli-panel { min-height: 250px; }
  .action-panel { min-height: 340px; }
}
@media (max-width: 620px) {
  .topbar { min-height: 64px; padding: 0 16px; }
  .brand { font-size: 20px; }
  .user-email, #manageRulesTop { display: none; }
  .admin-badge { display: none; }
  .theme-toggle { width: 58px; }
  html[data-theme="dark"] .theme-toggle i { transform: translateX(24px); }
  .auth-screen { min-height: calc(100dvh - 64px); align-items: start; padding: 28px 14px 50px; }
  .auth-card { gap: 18px; padding: 28px 22px; border-radius: 18px; }
  .code-row { grid-template-columns: 1fr; }
  .app-screen { padding: 18px 14px 42px; }
  .action-panel, .cli-panel, .section-panel { padding: 24px 20px; }
  .action-panel h1 { font-size: 45px; }
  .action-panel > p:not(.analysis-status) { font-size: 14px; line-height: 1.6; }
  .action-buttons { display: grid; margin-top: 30px; }
  .start-button, .action-buttons .outline { width: 100%; min-width: 0; }
  .rule-row { grid-template-columns: 1fr auto; gap: 6px 12px; padding: 13px 14px; }
  .rule-row span, .rule-row small { grid-column: 1; }
  .rule-actions { grid-column: 2; grid-row: 1 / span 3; }
  .section-heading { align-items: flex-start; flex-direction: column; }
  .rule-expression { grid-template-columns: 1fr 1fr; }
  .rule-expression input { grid-column: 1 / -1; }
  .source-input-row { grid-template-columns: 1fr; }
  .source-input-row .primary, .source-input-row .outline { width: 100%; }
  .settings-form { grid-template-columns: 1fr; }
  .settings-wide, .settings-footer { grid-column: 1; }
  .settings-footer { align-items: stretch; flex-direction: column; }
  .settings-footer .form-status { text-align: left; }
  .settings-footer .primary { width: 100%; }
  .progress-summary { grid-template-columns: 1fr; }
  .progress-steps li strong { font-size: 13px; }
  .progress-steps li small { font-size: 10px; }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { scroll-behavior: auto !important; transition-duration: .01ms !important; animation-duration: .01ms !important; }
}
