/* Decoder — clean, minimal, neutral. Light + dark via [data-theme]. */

:root {
  --bg: #fbfbfa;
  --surface: #ffffff;
  --surface-2: #f4f4f2;
  --border: #e4e4e1;
  --border-strong: #d2d2ce;
  --text: #1b1b19;
  --text-soft: #5c5c57;
  --text-faint: #8a8a83;
  --accent: #2f6f4f;
  --accent-soft: #e4f0e9;
  --accent-text: #245c41;
  --danger: #b3261e;
  --danger-soft: #fbe9e7;
  --mark-bg: #ffe08a;
  --mark-text: #4a3b00;
  --radius: 10px;
  --radius-sm: 6px;
  --mono: ui-monospace, "SF Mono", "JetBrains Mono", "Cascadia Code", Menlo, Consolas, monospace;
  --sans: ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  --shadow: 0 1px 2px rgba(0,0,0,.04), 0 4px 16px rgba(0,0,0,.04);
}

[data-theme="dark"] {
  --bg: #14140f;
  --surface: #1c1c17;
  --surface-2: #24241e;
  --border: #2f2f28;
  --border-strong: #3d3d34;
  --text: #ededea;
  --text-soft: #b4b4ac;
  --text-faint: #80807a;
  --accent: #6dbf95;
  --accent-soft: #1f3b2d;
  --accent-text: #9bd9b8;
  --danger: #f08a82;
  --danger-soft: #3a1f1c;
  --mark-bg: #b88a1f;
  --mark-text: #1b1503;
  --shadow: 0 1px 2px rgba(0,0,0,.3), 0 4px 16px rgba(0,0,0,.25);
}

* { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  font-family: var(--sans);
  background: var(--bg);
  color: var(--text);
  line-height: 1.55;
  font-size: 16px;
  -webkit-font-smoothing: antialiased;
}

.mono { font-family: var(--mono); }

a { color: var(--accent-text); }

.skip-link {
  position: absolute;
  left: -999px;
  top: 0;
  background: var(--accent);
  color: #fff;
  padding: 8px 14px;
  border-radius: 0 0 var(--radius-sm) 0;
  z-index: 100;
}
.skip-link:focus { left: 0; }

/* ---------- top bar ---------- */
.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: blur(8px);
  border-bottom: 1px solid var(--border);
}
.topbar-inner {
  max-width: 1040px;
  margin: 0 auto;
  padding: 12px 20px;
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.brand { display: flex; align-items: center; gap: 9px; font-weight: 700; }
.brand-mark {
  font-family: var(--mono);
  color: var(--accent);
  font-size: 18px;
  letter-spacing: -1px;
}
.brand-name { font-size: 17px; letter-spacing: -0.2px; }
.topbar-actions { display: flex; align-items: center; gap: 8px; }

/* ---------- buttons ---------- */
.btn {
  font: inherit;
  font-weight: 500;
  border: 1px solid var(--border-strong);
  background: var(--surface);
  color: var(--text);
  padding: 9px 15px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  transition: background .12s, border-color .12s, opacity .12s, transform .04s;
}
.btn:hover { background: var(--surface-2); }
.btn:active { transform: translateY(1px); }
.btn:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.btn:disabled { opacity: .55; cursor: progress; }

.btn-primary {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
}
.btn-primary:hover { background: color-mix(in srgb, var(--accent) 88%, #000); }
[data-theme="dark"] .btn-primary { color: #0c1a12; }

.btn-ghost { background: transparent; border-color: transparent; }
.btn-ghost:hover { background: var(--surface-2); }

.btn-icon { padding: 9px; }
.theme-icon { width: 16px; height: 16px; display: inline-block; }
.theme-icon::before { content: "🌙"; font-size: 15px; line-height: 1; }
[data-theme="dark"] .theme-icon::before { content: "☀️"; }

.dot { width: 8px; height: 8px; border-radius: 50%; display: inline-block; }
.dot-off { background: var(--text-faint); }
.dot-on { background: var(--accent); }

/* ---------- layout ---------- */
.container { max-width: 1040px; margin: 0 auto; padding: 32px 20px 64px; }

.intro { margin-bottom: 28px; }
.intro h1 { font-size: clamp(28px, 5vw, 40px); margin: 0 0 10px; letter-spacing: -0.8px; }
.lede { color: var(--text-soft); max-width: 64ch; margin: 0; font-size: 17px; }

/* ---------- tabs ---------- */
.tabs {
  display: inline-flex;
  gap: 4px;
  padding: 4px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  margin-bottom: 24px;
}
.tab {
  font: inherit;
  font-weight: 500;
  border: 0;
  background: transparent;
  color: var(--text-soft);
  padding: 8px 18px;
  border-radius: var(--radius-sm);
  cursor: pointer;
}
.tab:hover { color: var(--text); }
.tab.is-active { background: var(--surface); color: var(--text); box-shadow: var(--shadow); }
.tab:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

/* ---------- cards / grid ---------- */
.grid { display: grid; grid-template-columns: 1fr 1fr; gap: 20px; align-items: start; }
@media (max-width: 800px) { .grid { grid-template-columns: 1fr; } }

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 22px;
  box-shadow: var(--shadow);
}
.card-title {
  font-size: 15px;
  font-weight: 600;
  margin: 0 0 4px;
  display: flex;
  align-items: center;
  gap: 8px;
}
.card-hint { color: var(--text-soft); font-size: 14px; margin: 0 0 14px; }
.card-hint.warn { color: var(--danger); }

.badge {
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.4px;
  padding: 2px 7px;
  border-radius: 100px;
}
.badge-offline { background: var(--accent-soft); color: var(--accent-text); }

.divider {
  display: flex;
  align-items: center;
  gap: 12px;
  color: var(--text-faint);
  font-size: 13px;
  margin: 22px 0;
}
.divider::before, .divider::after {
  content: "";
  flex: 1;
  height: 1px;
  background: var(--border);
}

/* ---------- fields ---------- */
.field { margin-bottom: 16px; }
.field label, .label {
  display: block;
  font-size: 13px;
  font-weight: 600;
  color: var(--text-soft);
  margin-bottom: 6px;
}
.label { display: inline-block; }

.input {
  width: 100%;
  font: inherit;
  background: var(--surface);
  color: var(--text);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  padding: 10px 12px;
  resize: vertical;
}
.input:focus { outline: 2px solid var(--accent); outline-offset: -1px; border-color: var(--accent); }
textarea.input { line-height: 1.5; }

.rx-input-row { display: flex; align-items: center; gap: 4px; }
.rx-slash { color: var(--text-faint); font-family: var(--mono); font-size: 18px; }
.input-flags { width: 70px; flex: 0 0 auto; }
.rx-input-row .input:not(.input-flags) { flex: 1; }

.error-text {
  color: var(--danger);
  font-size: 13px;
  margin: 6px 0 0;
  font-family: var(--mono);
}

.checkbox-row { display: flex; align-items: center; gap: 8px; font-size: 14px; color: var(--text-soft); margin-bottom: 8px; }
.checkbox-row input { width: 16px; height: 16px; }

/* ---------- regex tester ---------- */
.result-head { display: flex; align-items: baseline; justify-content: space-between; }
.match-count { font-size: 13px; color: var(--text-faint); }

.highlight {
  margin: 0;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 12px;
  min-height: 48px;
  white-space: pre-wrap;
  word-break: break-word;
  font-family: var(--mono);
  font-size: 14px;
  line-height: 1.6;
}
.highlight mark {
  background: var(--mark-bg);
  color: var(--mark-text);
  border-radius: 3px;
  padding: 1px 1px;
}
.highlight .empty { color: var(--text-faint); }

.groups { margin-top: 14px; }
.groups-title { font-size: 13px; font-weight: 600; color: var(--text-soft); margin-bottom: 6px; }
.group-row {
  display: flex;
  gap: 10px;
  font-family: var(--mono);
  font-size: 13px;
  padding: 4px 0;
  border-bottom: 1px solid var(--border);
}
.group-row:last-child { border-bottom: 0; }
.group-idx { color: var(--accent-text); flex: 0 0 auto; min-width: 64px; }
.group-val { word-break: break-all; }
.group-val .nullval { color: var(--text-faint); }

/* ---------- cron breakdown ---------- */
.cron-breakdown {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 8px;
  margin-bottom: 16px;
}
.cron-cell {
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 10px 8px;
  text-align: center;
}
.cron-cell .cc-field { font-family: var(--mono); font-size: 15px; font-weight: 600; color: var(--accent-text); }
.cron-cell .cc-name { font-size: 11px; color: var(--text-faint); text-transform: uppercase; letter-spacing: 0.4px; margin-top: 2px; }
.cron-cell .cc-desc { font-size: 12px; color: var(--text-soft); margin-top: 6px; line-height: 1.4; }
.cron-cell.is-error { border-color: var(--danger); }
.cron-cell.is-error .cc-field { color: var(--danger); }
@media (max-width: 560px) { .cron-breakdown { grid-template-columns: 1fr 1fr; } }

.cron-plain {
  margin: 0;
  background: var(--accent-soft);
  color: var(--accent-text);
  border-radius: var(--radius-sm);
  padding: 12px 14px;
  font-size: 15px;
}

/* ---------- examples / chips ---------- */
.examples { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; margin-top: 16px; }
.chip {
  font: inherit;
  font-size: 12px;
  border: 1px solid var(--border-strong);
  background: var(--surface);
  color: var(--text-soft);
  padding: 4px 10px;
  border-radius: 100px;
  cursor: pointer;
}
.chip:hover { background: var(--surface-2); color: var(--text); }
.chip:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

/* ---------- AI output ---------- */
.ai-out { margin-top: 18px; }
.ai-out:empty { margin-top: 0; }

.ai-card {
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 16px;
}
.ai-card.is-error { border-color: var(--danger); background: var(--danger-soft); }
.ai-card.is-error .ai-body { color: var(--danger); }

.ai-result {
  position: relative;
  display: flex;
  align-items: center;
  gap: 8px;
  background: var(--surface);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  padding: 10px 12px;
  margin-bottom: 12px;
}
.ai-result code { font-family: var(--mono); font-size: 14px; word-break: break-all; flex: 1; }
.copy-btn {
  font: inherit;
  font-size: 12px;
  border: 1px solid var(--border-strong);
  background: var(--surface);
  color: var(--text-soft);
  padding: 4px 10px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  flex: 0 0 auto;
}
.copy-btn:hover { background: var(--surface-2); }

.ai-body { font-size: 15px; color: var(--text); }
.ai-body p { margin: 0 0 10px; }
.ai-body p:last-child { margin-bottom: 0; }
.ai-body ul { margin: 0 0 10px; padding-left: 20px; }
.ai-body li { margin-bottom: 5px; }
.ai-body code {
  font-family: var(--mono);
  font-size: .92em;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 1px 5px;
}
.ai-body strong { font-weight: 600; }

.loading { display: inline-flex; align-items: center; gap: 9px; color: var(--text-soft); font-size: 14px; }
.spinner {
  width: 15px; height: 15px;
  border: 2px solid var(--border-strong);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin .7s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------- footer ---------- */
.footer {
  border-top: 1px solid var(--border);
  max-width: 1040px;
  margin: 0 auto;
  padding: 28px 20px 48px;
  color: var(--text-faint);
  font-size: 13px;
}
.footer p { margin: 0 0 6px; max-width: 70ch; }
.footer code { font-family: var(--mono); font-size: 12px; }

/* ---------- dialog ---------- */
.dialog-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,.45);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  z-index: 50;
}
/* [hidden] must win over the display:flex above, or the invisible backdrop
   keeps covering the page and swallows every click. */
.dialog-backdrop[hidden] { display: none; }
.dialog {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 26px;
  width: 100%;
  max-width: 460px;
  box-shadow: 0 20px 60px rgba(0,0,0,.3);
}
.dialog h2 { margin: 0 0 10px; font-size: 19px; }
.dialog-text { color: var(--text-soft); font-size: 14px; margin: 0 0 16px; }
.dialog-text.small { font-size: 13px; }
.dialog-text code { font-family: var(--mono); font-size: 12px; }
.dialog-actions { display: flex; align-items: center; justify-content: space-between; margin-top: 20px; }
.dialog-actions-right { display: flex; gap: 8px; }

@media (prefers-reduced-motion: reduce) {
  * { animation-duration: .001ms !important; transition-duration: .001ms !important; }
}
