:root {
  color-scheme: dark;
  --bg: #090d14;
  --sidebar: #080c13;
  --surface: #0f1520;
  --surface-2: #131b28;
  --surface-3: #182231;
  --input: #0b111b;
  --line: #202b3a;
  --line-strong: #314054;
  --text: #f3f5f8;
  --muted: #8c98aa;
  --muted-2: #657184;
  --accent: #f4511e;
  --accent-hover: #ff6734;
  --accent-soft: rgba(244, 81, 30, 0.12);
  --blue: #5794f2;
  --green: #24c28a;
  --yellow: #f3a712;
  --red: #ef4e5d;
  --cyan: #25b9cb;
  --shadow: 0 24px 70px rgba(0, 0, 0, 0.35);
  --sidebar-width: 252px;
  --topbar-height: 58px;
  font-family: Inter, ui-sans-serif, -apple-system, BlinkMacSystemFont, "Segoe UI", "Microsoft YaHei", sans-serif;
  font-synthesis: none;
}

:root[data-theme="light"] {
  color-scheme: light;
  --bg: #f4f6f8;
  --sidebar: #ffffff;
  --surface: #ffffff;
  --surface-2: #f7f9fb;
  --surface-3: #edf1f5;
  --input: #ffffff;
  --line: #dfe5eb;
  --line-strong: #cbd4de;
  --text: #17202b;
  --muted: #657184;
  --muted-2: #8a95a3;
  --accent-soft: rgba(244, 81, 30, 0.09);
  --shadow: 0 24px 70px rgba(40, 53, 69, 0.16);
}

* { box-sizing: border-box; }

html, body { min-height: 100%; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-size: 14px;
  line-height: 1.45;
  letter-spacing: 0;
}

button, input, textarea, select { font: inherit; letter-spacing: 0; }
button, select { cursor: pointer; }
button:disabled { cursor: not-allowed; opacity: 0.48; }
a { color: inherit; }
.hidden { display: none !important; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0, 0, 0, 0); }
svg { width: 17px; height: 17px; stroke-width: 1.8; }

.boot-screen {
  min-height: 100vh;
  display: grid;
  place-content: center;
  justify-items: center;
  gap: 14px;
  background: var(--bg);
  color: var(--muted);
}

.brand-mark {
  display: grid;
  flex: 0 0 auto;
  place-items: center;
  width: 34px;
  height: 34px;
  border-radius: 50%;
  background: var(--accent);
  color: #fff;
  font-size: 11px;
  font-weight: 850;
  box-shadow: 0 0 0 1px rgba(255,255,255,.08), 0 8px 24px rgba(244,81,30,.22);
}

.brand-mark-lg { width: 48px; height: 48px; font-size: 14px; }

.auth-shell {
  min-height: 100vh;
  display: grid;
  grid-template-columns: minmax(420px, 1fr) minmax(500px, 1fr);
  background: var(--bg);
}

.auth-context {
  position: relative;
  display: flex;
  min-height: 100vh;
  flex-direction: column;
  justify-content: space-between;
  padding: 30px clamp(30px, 5vw, 82px) 42px;
  overflow: hidden;
  border-right: 1px solid var(--line);
  background: var(--surface-2);
}

.auth-context::after {
  content: "";
  position: absolute;
  right: -1px;
  bottom: 17%;
  width: 42%;
  height: 1px;
  background: var(--accent);
  opacity: .38;
}

.auth-brand, .sidebar-brand {
  display: flex;
  align-items: center;
  gap: 12px;
}

.auth-brand > span:last-child, .sidebar-brand > span:nth-child(2) { display: grid; }
.auth-brand b, .sidebar-brand b { color: var(--accent); font-size: 10px; letter-spacing: 2px; }
.auth-brand strong, .sidebar-brand strong { margin-top: 1px; font-size: 15px; }

.auth-title { position: relative; z-index: 1; max-width: 680px; }
.eyebrow, .section-kicker, .panel-kicker { font-size: 10px; font-weight: 750; letter-spacing: 1.6px; color: var(--accent); }
.auth-title h1 { margin: 15px 0 0; max-width: 10ch; font-size: clamp(46px, 6vw, 84px); line-height: .98; font-weight: 800; }
.auth-title p { margin: 18px 0 0; color: var(--muted); font-size: 18px; }

.auth-status { display: grid; grid-template-columns: repeat(3, 1fr); gap: 1px; margin: 0; border: 1px solid var(--line); background: var(--line); }
.auth-status div { min-width: 0; padding: 14px 16px; background: var(--surface); }
.auth-status dt { margin-bottom: 5px; color: var(--muted-2); font: 10px/1.2 ui-monospace, SFMono-Regular, Consolas, monospace; }
.auth-status dd { display: flex; align-items: center; gap: 7px; margin: 0; overflow: hidden; color: var(--text); white-space: nowrap; text-overflow: ellipsis; }

.signal { display: inline-block; width: 7px; height: 7px; border-radius: 50%; background: var(--muted-2); }
.signal-ok { background: var(--green); box-shadow: 0 0 0 3px rgba(36,194,138,.12); }
.signal-error { background: var(--red); box-shadow: 0 0 0 3px rgba(239,78,93,.12); }

.auth-panel-wrap { display: grid; place-items: center; padding: 28px; background: var(--bg); }
.auth-panel { width: min(440px, 100%); padding: 26px; border: 1px solid var(--line-strong); border-radius: 8px; background: var(--surface); box-shadow: var(--shadow); }
.auth-panel-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 16px; margin-bottom: 30px; padding-bottom: 18px; border-bottom: 1px solid var(--line); }
.auth-panel-head h2, .modal-head h2 { margin: 4px 0 0; font-size: 21px; }
.auth-foot { display: flex; align-items: center; justify-content: center; gap: 7px; margin-top: 20px; padding-top: 18px; border-top: 1px solid var(--line); color: var(--muted); font-size: 12px; }
.auth-foot svg { width: 14px; }

.field { display: grid; gap: 7px; margin-bottom: 17px; color: var(--muted); font-size: 12px; }
.input-shell, .search-shell { position: relative; display: flex; align-items: center; min-width: 0; border: 1px solid var(--line); border-radius: 6px; background: var(--input); color: var(--muted); }
.input-shell:focus-within, .search-shell:focus-within { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.input-shell > svg, .search-shell > svg { position: absolute; left: 12px; width: 16px; pointer-events: none; }
.input-shell input, .search-shell input { width: 100%; height: 42px; padding: 0 42px 0 38px; border: 0; outline: 0; background: transparent; color: var(--text); }
.input-action { position: absolute; right: 5px; }
.form-error { min-height: 19px; margin: -3px 0 12px; color: var(--red); font-size: 12px; }

.btn, .icon-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border: 1px solid transparent;
  border-radius: 6px;
  transition: border-color .16s ease, background .16s ease, color .16s ease, opacity .16s ease;
}

.btn { min-height: 36px; gap: 8px; padding: 0 13px; font-weight: 650; }
.btn-block { width: 100%; min-height: 42px; }
.btn-primary { border-color: var(--accent); background: var(--accent); color: #fff; }
.btn-primary:hover:not(:disabled) { border-color: var(--accent-hover); background: var(--accent-hover); }
.btn-secondary { border-color: var(--line); background: var(--surface-2); color: var(--text); }
.btn-secondary:hover:not(:disabled) { border-color: var(--line-strong); background: var(--surface-3); }
.btn-danger { border-color: rgba(239,78,93,.36); background: rgba(239,78,93,.1); color: var(--red); }
.btn-danger:hover { border-color: var(--red); }
.icon-btn { width: 34px; height: 34px; padding: 0; border-color: transparent; background: transparent; color: var(--muted); }
.icon-btn:hover:not(:disabled) { border-color: var(--line); background: var(--surface-2); color: var(--text); }

.theme-control { display: grid; grid-template-columns: repeat(3, 1fr); gap: 2px; padding: 3px; border: 1px solid var(--line); border-radius: 6px; background: var(--input); }
.theme-control button { display: grid; height: 28px; place-items: center; padding: 0 9px; border: 0; border-radius: 4px; background: transparent; color: var(--muted); }
.theme-control button.active { background: var(--surface-3); color: var(--text); }
.theme-control svg { width: 14px; height: 14px; }
.theme-control.compact button { width: 30px; padding: 0; }

.app-shell { min-height: 100vh; }
.sidebar {
  position: fixed;
  z-index: 50;
  inset: 0 auto 0 0;
  display: flex;
  width: var(--sidebar-width);
  flex-direction: column;
  border-right: 1px solid var(--line);
  background: var(--sidebar);
}

.sidebar-brand { min-height: 68px; padding: 0 17px; border-bottom: 1px solid var(--line); }
.sidebar-close { display: none; margin-left: auto; }
.sidebar-nav { flex: 1; padding: 17px 10px; overflow-y: auto; }
.nav-section { display: block; margin: 16px 9px 7px; color: var(--muted-2); font-size: 10px; }
.nav-section:first-child { margin-top: 0; }
.nav-item { display: flex; width: 100%; min-height: 38px; align-items: center; gap: 11px; margin: 2px 0; padding: 0 11px; border: 1px solid transparent; border-radius: 6px; background: transparent; color: var(--muted); text-align: left; }
.nav-item:hover { background: var(--surface-2); color: var(--text); }
.nav-item.active { border-color: rgba(244,81,30,.12); background: var(--accent-soft); color: var(--text); box-shadow: inset 2px 0 var(--accent); }
.nav-item.active svg { color: var(--accent); }
.nav-count { margin-left: auto; min-width: 20px; padding: 1px 6px; border-radius: 10px; background: var(--surface-3); color: var(--muted); font-size: 10px; text-align: center; }

.sidebar-footer { padding: 11px; border-top: 1px solid var(--line); }
.profile-button { display: flex; width: 100%; align-items: center; gap: 10px; padding: 8px; border: 0; border-radius: 6px; background: transparent; color: var(--text); text-align: left; }
.profile-button:hover { background: var(--surface-2); }
.profile-button > span:nth-child(2) { display: grid; min-width: 0; }
.profile-button strong { overflow: hidden; font-size: 13px; white-space: nowrap; text-overflow: ellipsis; }
.profile-button small { margin-top: 2px; color: var(--muted); font: 9px/1.2 ui-monospace, SFMono-Regular, Consolas, monospace; }
.profile-avatar { display: grid; width: 34px; height: 34px; place-items: center; border-radius: 50%; background: var(--accent); color: #fff; font-weight: 750; }
.sidebar-settings { display: flex; align-items: center; gap: 6px; margin-top: 7px; }
.sidebar-settings .theme-control { flex: 1; }
.sidebar-scrim { display: none; }

.app-main { min-height: 100vh; padding-left: var(--sidebar-width); }
.topbar { position: sticky; z-index: 30; top: 0; display: flex; min-height: var(--topbar-height); align-items: center; gap: 14px; padding: 0 22px; border-bottom: 1px solid var(--line); background: color-mix(in srgb, var(--bg) 92%, transparent); backdrop-filter: blur(14px); }
.topbar-title { display: flex; align-items: center; gap: 10px; font-size: 15px; font-weight: 700; }
.session-badge { padding: 3px 7px; border: 1px solid var(--line); border-radius: 4px; color: var(--muted); font: 9px/1.2 ui-monospace, SFMono-Regular, Consolas, monospace; }
.topbar-actions { display: flex; align-items: center; gap: 8px; margin-left: auto; }
.connection-badge { display: flex; align-items: center; gap: 7px; color: var(--muted); font-size: 12px; }
.mobile-menu { display: none; }

.content { width: 100%; max-width: 1680px; margin: 0 auto; padding: 25px 26px 42px; }
.page { display: none; }
.page.active { display: block; }
.page-header { display: flex; min-height: 53px; align-items: flex-start; justify-content: space-between; gap: 18px; margin-bottom: 18px; }
.page-header h1 { margin: 4px 0 0; font-size: 25px; line-height: 1.15; }

.metric-strip { display: grid; grid-template-columns: 1.15fr .8fr .8fr 1.25fr; margin-bottom: 14px; border: 1px solid var(--line); border-radius: 8px; background: var(--surface); overflow: hidden; }
.metric { display: grid; min-width: 0; padding: 14px 16px; border-right: 1px solid var(--line); }
.metric:last-child { border-right: 0; }
.metric span { color: var(--muted); font-size: 11px; }
.metric strong { margin-top: 4px; overflow: hidden; font-size: 22px; line-height: 1.1; white-space: nowrap; text-overflow: ellipsis; }
.metric:first-child strong { color: var(--accent); }
.metric small { margin-top: 7px; color: var(--muted-2); font: 9px/1.2 ui-monospace, SFMono-Regular, Consolas, monospace; }
.metric-code { font-family: ui-monospace, SFMono-Regular, Consolas, monospace; font-size: 17px !important; }

.work-grid { display: grid; grid-template-columns: minmax(0, 1.08fr) minmax(360px, .92fr); gap: 14px; margin-bottom: 14px; }
.panel { min-width: 0; border: 1px solid var(--line); border-radius: 8px; background: var(--surface); overflow: hidden; }
.panel-head { display: flex; min-height: 61px; align-items: center; justify-content: space-between; gap: 16px; padding: 11px 14px; border-bottom: 1px solid var(--line); }
.panel-head h2 { margin: 2px 0 0; font-size: 14px; }
.panel-actions { display: flex; gap: 2px; }
.panel-body { padding: 13px; }
.counter { padding: 4px 8px; border: 1px solid var(--line); border-radius: 4px; color: var(--muted); font: 10px/1.2 ui-monospace, SFMono-Regular, Consolas, monospace; }

#linksInput { width: 100%; height: 206px; min-height: 138px; resize: vertical; padding: 12px 13px; border: 1px solid var(--line); border-radius: 6px; outline: 0; background: var(--input); color: var(--text); font: 12px/1.65 ui-monospace, SFMono-Regular, Consolas, monospace; }
#linksInput:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.input-toolbar { display: flex; align-items: center; gap: 7px; margin-top: 10px; }
.toolbar-spacer { flex: 1; }

.log-output { height: 278px; padding: 12px 14px; overflow: auto; background: var(--input); color: #aab5c4; font: 11px/1.72 ui-monospace, SFMono-Regular, Consolas, monospace; }
:root[data-theme="light"] .log-output { color: #566273; }
.log-line { display: grid; grid-template-columns: 68px 52px minmax(0,1fr); gap: 8px; padding: 2px 0; }
.log-time { color: var(--muted-2); }
.log-level { font-weight: 700; text-transform: uppercase; }
.log-line.info .log-level { color: var(--blue); }
.log-line.warning .log-level { color: var(--yellow); }
.log-line.error .log-level { color: var(--red); }
.log-empty { display: grid; height: 100%; place-items: center; color: var(--muted-2); }

.results-panel { margin-top: 0; }
.results-head { min-height: 67px; }
.result-tools { display: flex; align-items: center; gap: 8px; }
.search-shell { width: min(290px, 30vw); }
.search-shell input { height: 34px; padding-left: 36px; padding-right: 10px; font-size: 12px; }
select { height: 36px; padding: 0 34px 0 10px; border: 1px solid var(--line); border-radius: 6px; outline: 0; background: var(--input); color: var(--text); }
select:focus { border-color: var(--accent); }
.table-scroll { overflow-x: auto; }
.data-table { width: 100%; min-width: 820px; border-collapse: collapse; table-layout: auto; }
.data-table th { height: 39px; padding: 0 12px; border-bottom: 1px solid var(--line); background: var(--surface-2); color: var(--muted); font-size: 10px; font-weight: 600; text-align: left; white-space: nowrap; }
.data-table td { height: 47px; max-width: 320px; padding: 8px 12px; border-bottom: 1px solid var(--line); overflow: hidden; font-size: 12px; white-space: nowrap; text-overflow: ellipsis; }
.data-table tbody tr:last-child td { border-bottom: 0; }
.data-table tbody tr:hover { background: color-mix(in srgb, var(--surface-3) 55%, transparent); }
.data-table .number { text-align: right; font-variant-numeric: tabular-nums; }
.data-table .actions-column { width: 80px; text-align: right; }
.reddit-link { display: inline-flex; max-width: 240px; align-items: center; gap: 6px; overflow: hidden; color: var(--accent); text-decoration: none; white-space: nowrap; text-overflow: ellipsis; }
.reddit-link span { overflow: hidden; text-overflow: ellipsis; }
.reddit-link:hover { text-decoration: underline; }
.title-cell { max-width: 340px; }
.time-cell { color: var(--muted); font-variant-numeric: tabular-nums; }
.badge { display: inline-flex; align-items: center; gap: 5px; min-height: 22px; padding: 2px 7px; border: 1px solid var(--line); border-radius: 4px; background: var(--surface-2); color: var(--muted); font-size: 10px; }
.badge.available, .badge.completed, .badge.enabled { border-color: rgba(36,194,138,.25); background: rgba(36,194,138,.09); color: var(--green); }
.badge.running, .badge.queued, .badge.cancelling { border-color: rgba(87,148,242,.25); background: rgba(87,148,242,.09); color: var(--blue); }
.badge.removed, .badge.filtered, .badge.self_deleted, .badge.cancelled, .badge.disabled { border-color: rgba(243,167,18,.25); background: rgba(243,167,18,.09); color: var(--yellow); }
.badge.error, .badge.failed, .badge.unavailable { border-color: rgba(239,78,93,.25); background: rgba(239,78,93,.09); color: var(--red); }
.empty-row td { height: 176px; text-align: center; color: var(--muted-2); }
.empty-row td > span, .empty-row td > svg { display: inline-block; vertical-align: middle; }
.empty-row svg { margin-right: 8px; }
.table-foot { display: flex; min-height: 43px; align-items: center; justify-content: space-between; padding: 0 13px; border-top: 1px solid var(--line); color: var(--muted); font-size: 11px; }

.history-panel, .members-panel { min-height: 220px; }
.row-actions { display: flex; justify-content: flex-end; gap: 2px; }
.row-actions .icon-btn { width: 30px; height: 30px; }

.modal { width: min(500px, calc(100vw - 28px)); padding: 0; border: 1px solid var(--line-strong); border-radius: 8px; background: var(--surface); color: var(--text); box-shadow: var(--shadow); }
.modal::backdrop { background: rgba(0,0,0,.66); backdrop-filter: blur(3px); }
.modal-head { display: flex; align-items: center; justify-content: space-between; padding: 16px 18px; border-bottom: 1px solid var(--line); }
.modal-body { padding: 18px; }
.modal-foot { display: flex; justify-content: flex-end; gap: 8px; padding: 13px 18px; border-top: 1px solid var(--line); background: var(--surface-2); }
.field-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.switch-field { display: flex; align-items: center; justify-content: space-between; align-self: end; height: 42px; margin-bottom: 17px; padding: 0 10px; border: 1px solid var(--line); border-radius: 6px; color: var(--muted); font-size: 12px; }
.switch-field input { position: absolute; opacity: 0; pointer-events: none; }
.switch { position: relative; width: 34px; height: 19px; border-radius: 10px; background: var(--muted-2); transition: background .16s; }
.switch::after { content: ""; position: absolute; top: 3px; left: 3px; width: 13px; height: 13px; border-radius: 50%; background: #fff; transition: transform .16s; }
.switch-field input:checked + .switch { background: var(--accent); }
.switch-field input:checked + .switch::after { transform: translateX(15px); }

.toast-region { position: fixed; z-index: 100; right: 18px; bottom: 18px; display: grid; width: min(360px, calc(100vw - 36px)); gap: 8px; pointer-events: none; }
.toast { display: flex; align-items: center; gap: 10px; padding: 11px 12px; border: 1px solid var(--line-strong); border-left: 3px solid var(--blue); border-radius: 6px; background: var(--surface); box-shadow: var(--shadow); color: var(--text); animation: toast-in .18s ease-out; }
.toast.success { border-left-color: var(--green); }
.toast.error { border-left-color: var(--red); }
.toast.warning { border-left-color: var(--yellow); }
@keyframes toast-in { from { transform: translateY(8px); opacity: 0; } }

@media (max-width: 980px) {
  .auth-shell { grid-template-columns: 1fr; }
  .auth-context { min-height: 38vh; padding: 24px 28px 26px; border-right: 0; border-bottom: 1px solid var(--line); }
  .auth-title h1 { margin-top: 10px; font-size: 46px; }
  .auth-title p { margin-top: 10px; font-size: 15px; }
  .auth-status { margin-top: 34px; }
  .auth-panel-wrap { min-height: 62vh; }
  .work-grid { grid-template-columns: 1fr; }
  #linksInput { height: 170px; }
  .log-output { height: 230px; }
}

@media (max-width: 760px) {
  :root { --topbar-height: 54px; }
  .sidebar { transform: translateX(-102%); transition: transform .2s ease; box-shadow: var(--shadow); }
  .sidebar.open { transform: translateX(0); }
  .sidebar-close, .mobile-menu { display: inline-flex; }
  .sidebar-scrim { position: fixed; z-index: 45; inset: 0; display: block; visibility: hidden; background: rgba(0,0,0,.58); opacity: 0; transition: opacity .2s; }
  .sidebar-scrim.open { visibility: visible; opacity: 1; }
  .app-main { padding-left: 0; }
  .topbar { padding: 0 12px; }
  .connection-badge, .topbar-actions .btn span { display: none; }
  .topbar-actions .btn { width: 34px; padding: 0; }
  .content { padding: 18px 13px 32px; }
  .page-header { align-items: center; }
  .page-header h1 { font-size: 21px; }
  .page-header .btn span { display: none; }
  .page-header .btn { width: 36px; padding: 0; }
  .metric-strip { grid-template-columns: 1fr 1fr; }
  .metric:nth-child(2) { border-right: 0; }
  .metric:nth-child(-n+2) { border-bottom: 1px solid var(--line); }
  .metric strong { font-size: 19px; }
  .metric-code { font-size: 14px !important; }
  .results-head { align-items: flex-start; flex-direction: column; }
  .result-tools { width: 100%; }
  .search-shell { width: 100%; }
  .result-tools select { max-width: 124px; }
  .log-line { grid-template-columns: 59px 46px minmax(0,1fr); gap: 6px; }
}

@media (max-width: 520px) {
  .auth-context { min-height: auto; padding: 20px 18px 22px; }
  .auth-title { margin-top: 54px; }
  .auth-title h1 { font-size: 39px; }
  .auth-status { grid-template-columns: 1fr; }
  .auth-status div { display: flex; align-items: center; justify-content: space-between; padding: 10px 12px; }
  .auth-status dt { margin: 0; }
  .auth-panel-wrap { min-height: auto; padding: 18px 12px 28px; }
  .auth-panel { padding: 20px 16px; }
  .metric { padding: 12px; }
  .field-grid { grid-template-columns: 1fr; gap: 0; }
  .panel-head { padding-inline: 11px; }
  .panel-body { padding: 10px; }
  #linksInput { height: 155px; }
  .log-output { height: 210px; padding: 10px; }
  .toast-region { right: 12px; bottom: 12px; width: calc(100vw - 24px); }
}

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