/* chkr design v3 — restrained neutral UI, light and dark. */
:root {
  --bg: #fafafa;
  --surface: #ffffff;
  --surface-2: #f4f4f5;
  --line: #e4e4e7;
  --line-strong: #d4d4d8;
  --ink: #18181b;
  --ink-2: #3f3f46;
  --muted: #71717a;
  --accent: #2563eb;
  --accent-soft: #eff4ff;
  --focus: #2563eb40;
  --primary: #18181b;
  --primary-ink: #ffffff;
  --ok: #15803d;      --ok-bg: #ecfdf3;
  --warn: #b45309;    --warn-bg: #fffbeb;
  --fail: #b91c1c;    --fail-bg: #fef2f2;
  --info: #1d4ed8;    --info-bg: #eff6ff;
  --na: #a1a1aa;
  --shadow: 0 1px 2px #0000000a, 0 1px 3px #0000000d;
  --radius: 12px;
  --radius-sm: 8px;
  --mono: ui-monospace, SFMono-Regular, "JetBrains Mono", Menlo, Consolas, monospace;
  --sans: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #111113;
    --surface: #18181b;
    --surface-2: #202024;
    --line: #2a2a2f;
    --line-strong: #3a3a40;
    --ink: #f4f4f5;
    --ink-2: #d4d4d8;
    --muted: #a1a1aa;
    --accent: #6b9bff;
    --accent-soft: #1b2440;
    --focus: #6b9bff55;
    --primary: #f4f4f5;
    --primary-ink: #18181b;
    --ok: #4ade80;      --ok-bg: #12291c;
    --warn: #fbbf24;    --warn-bg: #2d2412;
    --fail: #f87171;    --fail-bg: #2f1616;
    --info: #93b4ff;    --info-bg: #18213a;
    --na: #71717a;
    --shadow: 0 1px 2px #00000040;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html { -webkit-text-size-adjust: 100%; scroll-padding-top: 72px; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font: 14px/1.5 var(--sans);
  -webkit-font-smoothing: antialiased;
}
a { color: inherit; }
h1, h2, h3 { margin: 0; font-weight: 600; letter-spacing: -0.01em; }
h1 { font-size: 22px; line-height: 1.3; }
h2 { font-size: 15px; }
h3 { font-size: 15px; }
p { margin: 0; }
.muted { color: var(--muted); font-weight: 400; }
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
button:disabled { cursor: default; opacity: .5; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
kbd {
  font: 11px var(--mono);
  padding: 1px 5px;
  border: 1px solid var(--line);
  border-bottom-width: 2px;
  border-radius: 4px;
  background: var(--surface);
  color: var(--muted);
}

/* App bar */
.appbar {
  position: sticky; top: 0; z-index: 10;
  background: color-mix(in srgb, var(--bg) 85%, transparent);
  backdrop-filter: saturate(180%) blur(10px);
  -webkit-backdrop-filter: saturate(180%) blur(10px);
  border-bottom: 1px solid var(--line);
}
.appbar-inner {
  max-width: 1180px; margin: 0 auto; padding: 0 24px;
  height: 56px; display: flex; align-items: center; gap: 28px;
}
.brand {
  display: inline-flex; align-items: center; gap: 9px;
  font-weight: 650; font-size: 16px; text-decoration: none; letter-spacing: -0.02em;
}
.brand-mark {
  width: 22px; height: 22px; border-radius: 6px; background: var(--primary); position: relative;
}
.brand-mark::after {
  content: ""; position: absolute; inset: 6px;
  border: 2px solid var(--primary-ink); border-radius: 50%; border-right-color: transparent;
}
.appnav { display: flex; gap: 4px; flex: 1; min-width: 0; overflow-x: auto; scrollbar-width: none; }
.appnav::-webkit-scrollbar { display: none; }
.appnav a {
  padding: 6px 10px; border-radius: var(--radius-sm); text-decoration: none;
  color: var(--muted); white-space: nowrap; font-size: 13.5px;
}
.appnav a:hover { color: var(--ink); background: var(--surface-2); }
.appnav a.active { color: var(--ink); font-weight: 550; }
.count {
  display: inline-block; min-width: 18px; padding: 0 5px; margin-left: 2px;
  border-radius: 9px; background: var(--surface-2); font-size: 11px; text-align: center; color: var(--muted);
}
.service-state {
  display: inline-flex; align-items: center; gap: 7px;
  font-size: 12.5px; color: var(--muted); white-space: nowrap;
}
.service-state i { width: 7px; height: 7px; border-radius: 50%; background: var(--ok); box-shadow: 0 0 0 3px var(--ok-bg); }

/* Page */
.page { max-width: 1180px; margin: 0 auto; padding: 28px 24px 40px; }
.page-head { margin-bottom: 20px; }
.page-head p { margin-top: 4px; }
.page-head.with-action { display: flex; justify-content: space-between; align-items: flex-end; gap: 16px; }

.panel {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}
.panel-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 12px; }

.workspace {
  display: grid; grid-template-columns: minmax(0, 5fr) minmax(0, 6fr); gap: 20px; align-items: start;
}
.input-panel, .result-panel { padding: 20px; }
.result-panel { min-height: 100%; }

/* Segmented control */
.segmented {
  display: flex; gap: 2px; padding: 3px; margin-bottom: 18px;
  background: var(--surface-2); border-radius: 10px; overflow-x: auto; scrollbar-width: none;
}
.segmented::-webkit-scrollbar { display: none; }
.segmented button {
  flex: 1 0 auto; border: 0; background: transparent; padding: 6px 12px;
  border-radius: 7px; color: var(--muted); font-size: 13px; white-space: nowrap;
}
.segmented button:hover { color: var(--ink); }
.segmented button.selected {
  background: var(--surface); color: var(--ink); font-weight: 550;
  box-shadow: 0 1px 2px #0000001a, 0 0 0 1px var(--line);
}

/* Form */
.field-head { display: flex; justify-content: space-between; align-items: baseline; margin-bottom: 6px; }
.field-head label { font-weight: 550; font-size: 13px; }
.link-button { border: 0; background: none; padding: 0; color: var(--muted); font-size: 12.5px; }
.link-button:hover { color: var(--ink); text-decoration: underline; }
.editor {
  border: 1px solid var(--line-strong); border-radius: 10px; background: var(--surface);
  transition: border-color .15s, box-shadow .15s; overflow: hidden;
}
.editor:focus-within, .editor.dragover { border-color: var(--accent); box-shadow: 0 0 0 3px var(--focus); }
.editor.dragover { background: var(--accent-soft); }
.editor textarea {
  display: block; width: 100%; min-height: 132px; resize: vertical;
  border: 0; outline: 0; background: transparent; padding: 12px 14px;
  font: 13px/1.6 var(--mono);
}
.editor textarea::placeholder { color: var(--na); }
.editor-bar {
  display: flex; justify-content: space-between; align-items: center; gap: 10px;
  padding: 7px 8px 7px 14px; border-top: 1px solid var(--line); background: var(--surface-2);
  font-size: 12px; color: var(--muted);
}
.editor-bar > span { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.file-button {
  flex: none; padding: 4px 10px; border-radius: 6px; border: 1px solid var(--line-strong);
  background: var(--surface); color: var(--ink-2); cursor: pointer; font-size: 12px;
}
.file-button:hover { border-color: var(--muted); }
.file-button input { position: absolute; width: 1px; height: 1px; opacity: 0; pointer-events: none; }
.file-button:focus-within { outline: 2px solid var(--accent); outline-offset: 2px; }
.hint { font-size: 12.5px; color: var(--muted); margin-top: 8px; }
.form-actions { display: flex; align-items: center; gap: 14px; margin-top: 16px; flex-wrap: wrap; }
.kbd-hint { font-size: 12px; color: var(--muted); }

.primary-button {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  height: 38px; padding: 0 20px; border: 0; border-radius: var(--radius-sm);
  background: var(--primary); color: var(--primary-ink); font-weight: 550;
  transition: opacity .15s;
}
.primary-button:hover:not(:disabled) { opacity: .88; }
.primary-button.wide { width: 100%; margin-top: 18px; }
.subtle-button {
  display: inline-flex; align-items: center; gap: 6px; height: 32px; padding: 0 12px;
  border: 1px solid var(--line-strong); border-radius: var(--radius-sm);
  background: var(--surface); color: var(--ink-2); font-size: 13px; text-decoration: none; white-space: nowrap;
}
.subtle-button:hover:not(:disabled) { background: var(--surface-2); color: var(--ink); }
.subtle-button.danger:hover:not(:disabled) { color: var(--fail); border-color: color-mix(in srgb, var(--fail) 40%, var(--line)); }
.subtle-button.icon { width: 32px; justify-content: center; padding: 0; }

.form-error, .notice {
  margin-top: 12px; padding: 10px 12px; border-radius: var(--radius-sm); font-size: 13px;
}
.form-error { background: var(--fail-bg); color: var(--fail); }
.notice { background: var(--warn-bg); color: var(--warn); }

input[type="search"], input:not([type]), input[type="password"], select {
  height: 36px; padding: 0 12px; border: 1px solid var(--line-strong); border-radius: var(--radius-sm);
  background: var(--surface); outline: 0; transition: border-color .15s, box-shadow .15s; min-width: 0;
}
input:focus, select:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--focus); }
select {
  appearance: none; padding-right: 30px; cursor: pointer;
  background-image: linear-gradient(45deg, transparent 50%, var(--muted) 50%), linear-gradient(135deg, var(--muted) 50%, transparent 50%);
  background-position: calc(100% - 15px) 15px, calc(100% - 10px) 15px;
  background-size: 5px 5px; background-repeat: no-repeat;
}

/* Result */
.empty-result { text-align: center; padding: 48px 16px 40px; color: var(--muted); }
.empty-icon {
  display: inline-block; width: 40px; height: 40px; border-radius: 50%;
  border: 1.5px dashed var(--line-strong); margin-bottom: 14px; position: relative;
}
.empty-icon::after {
  content: ""; position: absolute; inset: 13px; border-radius: 50%; background: var(--line-strong);
}
.empty-result h3 { color: var(--ink); margin-bottom: 6px; }
.empty-result p { font-size: 13px; }
.capabilities { list-style: none; padding: 0; margin: 18px 0 0; display: flex; gap: 6px; justify-content: center; flex-wrap: wrap; }
.capabilities li {
  font-size: 12px; padding: 3px 10px; border-radius: 999px; background: var(--surface-2); color: var(--muted);
}

.result-summary {
  display: flex; align-items: center; gap: 10px; flex-wrap: wrap;
  padding: 2px 0 14px; border-bottom: 1px solid var(--line); margin-bottom: 4px;
}
.result-target { font: 13px var(--mono); overflow-wrap: anywhere; color: var(--ink); }
.badge {
  display: inline-flex; align-items: center; gap: 6px; width: max-content;
  padding: 2px 9px 2px 8px; border-radius: 999px; font-size: 12px; font-weight: 500; white-space: nowrap;
  background: var(--surface-2); color: var(--muted);
}
.badge::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: currentColor; }
.badge.ok { background: var(--ok-bg); color: var(--ok); }
.badge.partial { background: var(--warn-bg); color: var(--warn); }
.badge.error { background: var(--fail-bg); color: var(--fail); }
.badge.queued, .badge.running { background: var(--info-bg); color: var(--info); }
.badge.running::before, .badge.queued::before { animation: blink 1.4s ease-in-out infinite; }

.report-row {
  display: grid; grid-template-columns: 22px minmax(0, 1fr); gap: 8px;
  padding: 9px 0; border-bottom: 1px solid var(--line);
}
.report-row:last-of-type { border-bottom: 0; }
.report-row .mark {
  width: 18px; height: 18px; margin-top: 1px; border-radius: 50%;
  display: grid; place-items: center; font-size: 11px; font-weight: 700;
  background: var(--ok-bg); color: var(--ok);
}
.report-row.FAIL .mark { background: var(--fail-bg); color: var(--fail); }
.report-row.WARN .mark { background: var(--warn-bg); color: var(--warn); }
.report-row.INFO .mark { background: var(--info-bg); color: var(--info); }
.report-row.NA .mark { background: var(--surface-2); color: var(--na); }
.report-row > div {
  display: grid; grid-template-columns: minmax(130px, 2fr) minmax(0, 3fr); gap: 2px 16px; align-items: start;
}
.report-row b { font-size: 13px; font-weight: 500; overflow-wrap: anywhere; }
.report-row p { font: 12.5px/1.55 var(--mono); color: var(--ink-2); white-space: pre-wrap; overflow-wrap: anywhere; }
.report-row p ~ p { grid-column: 2; color: var(--muted); }
.report-note { font-size: 12.5px; color: var(--muted); margin-top: 10px; }
#result-content > .subtle-button { margin-top: 14px; }
.result-meta { font-size: 12px; color: var(--muted); margin-top: 14px; }
#detail-content > .result-meta:first-child { margin: 0 0 8px; }

.progress-view { text-align: center; padding: 44px 16px 36px; }
.spinner {
  width: 28px; height: 28px; margin: 0 auto 16px; border-radius: 50%;
  border: 2.5px solid var(--line); border-top-color: var(--accent);
  animation: spin .9s linear infinite;
}
.progress-view h3 { margin-bottom: 6px; }
.progress-view p { font-size: 13px; color: var(--muted); overflow-wrap: anywhere; margin-top: 4px; }
.progress-view strong {
  display: block; margin: 14px 0 6px; font-size: 28px; font-weight: 600;
  font-variant-numeric: tabular-nums; letter-spacing: -0.02em;
}

/* History / lists */
.history { margin-top: 36px; }
.history-head { display: flex; justify-content: space-between; align-items: center; gap: 12px; margin-bottom: 12px; }
.history-head h2 { font-size: 17px; }
.toolbar { display: flex; gap: 8px; flex-wrap: wrap; }
.history-filters, .filters { display: flex; gap: 8px; align-items: center; margin-bottom: 12px; flex-wrap: wrap; }
.history-filters input, .filters input { flex: 1 1 240px; }
.history-filters .muted { font-size: 12.5px; }
.list { overflow: hidden; }
.empty-history { padding: 36px 16px; text-align: center; color: var(--muted); font-size: 13px; }

.history-row {
  display: grid; grid-template-columns: 30px minmax(0, 1fr) auto 120px 14px; gap: 12px; align-items: center;
  width: 100%; padding: 10px 16px; border: 0; border-bottom: 1px solid var(--line);
  background: transparent; text-align: left; transition: background .1s;
}
.history-row:last-child { border-bottom: 0; }
.history-row:hover { background: var(--surface-2); }
.history-row.selected-row { background: var(--accent-soft); box-shadow: inset 2px 0 var(--accent); }
.row-icon {
  width: 30px; height: 30px; border-radius: var(--radius-sm); display: grid; place-items: center;
  background: var(--surface-2); color: var(--muted); font-size: 14px;
}
.row-title { display: block; font: 13px/1.45 var(--mono); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.row-meta { display: block; font-size: 12px; color: var(--muted); }
.row-date { font-size: 12px; color: var(--muted); text-align: right; white-space: nowrap; }
.history-row > .muted:last-child { font-size: 13px; text-align: right; }
.admin-row { grid-template-columns: 30px minmax(0, 1fr) minmax(0, 170px) auto 80px 14px; }
.admin-actor { font: 12px var(--mono); color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* Admin */
.login { display: grid; place-items: center; padding: 40px 0; }
.login-card { width: 100%; max-width: 380px; padding: 28px; display: flex; flex-direction: column; }
.login-card h1 { font-size: 20px; }
.login-card .muted { margin: 4px 0 18px; font-size: 13px; }
.login-card label { font-size: 13px; font-weight: 550; margin: 10px 0 6px; }
.stats { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 12px; margin-bottom: 16px; }
.stat-card {
  padding: 14px 16px; display: flex; flex-direction: column; gap: 4px;
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow);
}
.stat-card span { font-size: 12.5px; color: var(--muted); }
.stat-card strong { font-size: 24px; font-weight: 600; font-variant-numeric: tabular-nums; letter-spacing: -0.02em; }
.list-panel { padding: 16px; }
.list-panel .list { margin: 0 -16px; border-top: 1px solid var(--line); border-bottom: 1px solid var(--line); }
.list-panel .form-error { margin: 0 0 12px; }
.pagination { display: flex; justify-content: space-between; align-items: center; gap: 12px; padding-top: 14px; font-size: 13px; flex-wrap: wrap; }

dialog {
  width: min(760px, calc(100% - 32px)); max-height: 85vh; padding: 20px;
  border: 1px solid var(--line); border-radius: 14px; background: var(--surface); color: var(--ink);
  box-shadow: 0 24px 64px #0000002e;
}
dialog::backdrop { background: #09090b66; backdrop-filter: blur(2px); }

.footer {
  display: flex; justify-content: space-between; gap: 16px; flex-wrap: wrap;
  margin-top: 40px; padding-top: 16px; border-top: 1px solid var(--line);
  font-size: 12.5px; color: var(--muted);
}
.footer a { color: var(--muted); }
.footer a:hover { color: var(--ink); }

@keyframes spin { to { transform: rotate(360deg); } }
@keyframes blink { 50% { opacity: .35; } }
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: 0s !important; transition: none !important; }
  .spinner { animation: spin 2s linear infinite !important; }
}

/* Responsive */
@media (max-width: 900px) {
  .workspace { grid-template-columns: minmax(0, 1fr); }
  .stats { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .admin-row { grid-template-columns: 30px minmax(0, 1fr) auto 14px; }
  .admin-row .admin-actor, .admin-row .source-label { display: none; }
}
@media (max-width: 480px) {
  .appnav a[href^="https://t.me"] { display: none; }
}
@media (max-width: 640px) {
  .appbar-inner { padding: 0 16px; gap: 14px; }
  .service-state { font-size: 0; gap: 0; }
  .appnav a { padding: 6px 8px; }
  .page { padding: 20px 16px 32px; }
  h1 { font-size: 20px; }
  .input-panel, .result-panel { padding: 16px; }
  .kbd-hint { display: none; }
  .segmented { flex-wrap: wrap; }
  .segmented button { flex: 1 0 30%; }
  .primary-button:not(.wide) { flex: 1; }
  .history-row { grid-template-columns: 30px minmax(0, 1fr) auto; padding: 10px 14px; gap: 10px; }
  .history-row .row-date, .history-row > .muted:last-child { display: none; }
  .report-row > div { grid-template-columns: 1fr; }
  .report-row p ~ p { grid-column: 1; }
  .history-head { flex-wrap: wrap; }
  .page-head.with-action { align-items: flex-start; }
  .list-panel { padding: 12px; }
  .list-panel .list { margin: 0 -12px; }
}
