:root {
  color-scheme: light;

  --ink: #14130c;
  --paper: #f3ead8;
  --surface: #ffffff;
  --surface-2: #faf6ec;
  --surface-3: #efe7d6;
  --field: #ffffff;
  --summary-bar: #fbe7a6;
  --summary-bar-hover: #f7d978;
  --text: #14130c;
  --text-soft: #2f2c20;
  --muted: #6f6a57;

  --accent: #c6e034;
  --accent-hover: #d6f04a;
  --accent-text: #14130c;
  --accent-2: #6c5cff;
  --accent-2-text: #ffffff;
  --danger: #ff4d4d;
  --danger-text: #ffffff;
  --ok: #1fb46b;

  --radius: 0px;

  --s1: 4px;
  --s2: 8px;
  --s3: 12px;
  --s4: 16px;
  --s5: 22px;

  --bd: 2px;
  --bd-thick: 3px;
  --shadow: 5px 5px 0 var(--ink);
  --shadow-sm: 3px 3px 0 var(--ink);
  --shadow-xs: 2px 2px 0 var(--ink);

  font-family: "Inter", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  font-feature-settings: "cv05", "ss01";
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background-color: var(--paper);
  background-image: url("/bg.png");
  background-size: cover;
  background-position: center;
  background-repeat: no-repeat;
  background-attachment: fixed;
  color: var(--text);
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  font-size: 14px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

.hidden { display: none !important; }

.view {
  width: 100%;
  max-width: 1100px;
  display: flex;
  justify-content: center;
}

h1, h2, h3, h4 { margin: 0; font-weight: 800; letter-spacing: -0.01em; color: var(--text); }
h1 { font-size: 1.2rem; text-transform: uppercase; letter-spacing: 0.01em; }
h3 { font-size: 0.95rem; text-transform: uppercase; letter-spacing: 0.02em; }
p { margin: 0; }

.muted { color: var(--muted); }
.hint { color: var(--muted); font-size: 0.76rem; line-height: 1.45; }
code {
  font-family: "Inter", monospace;
  font-weight: 700;
  background: var(--accent);
  padding: 0.05em 0.4em;
  border: var(--bd) solid var(--ink);
  font-size: 0.82em;
  color: var(--ink);
}

.error {
  color: var(--danger);
  font-weight: 700;
  font-size: 0.82rem;
  margin-top: var(--s3);
}

/* ---------- Banner ---------- */
.banner-panel {
  width: 100%;
  height: 76px;
  flex-shrink: 0;
  border: var(--bd-thick) solid var(--ink);
  box-shadow: var(--shadow-sm);
  overflow: hidden;
  background-color: var(--accent);
  background-image: url("/userhunt.png");
  background-size: cover;
  background-position: center;
  background-repeat: no-repeat;
}

.banner-panel--login {
  height: 92px;
  margin-bottom: var(--s5);
}

.sidebar .banner-panel { margin-bottom: var(--s4); }

/* ---------- Form primitives ---------- */
input, select, textarea, button { font: inherit; }

.field { display: flex; flex-direction: column; gap: var(--s2); }
.field-label {
  font-size: 0.74rem;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--ink);
}

input, select, textarea {
  width: 100%;
  background: var(--field);
  color: var(--text);
  border: var(--bd) solid var(--ink);
  border-radius: var(--radius);
  padding: 0.55rem 0.7rem;
  font-size: 0.85rem;
  font-weight: 500;
  transition: box-shadow 0.12s, transform 0.12s;
}

input::placeholder, textarea::placeholder { color: #a39d89; font-weight: 500; }

input:focus, select:focus, textarea:focus {
  outline: none;
  box-shadow: var(--shadow-xs);
}

select {
  appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 24 24' fill='none' stroke='%2314130c' stroke-width='3' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M6 9l6 6 6-6'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 0.6rem center;
  padding-right: 1.9rem;
  cursor: pointer;
}

textarea {
  min-height: 3.75rem;
  resize: vertical;
  field-sizing: content;
  line-height: 1.5;
}

button {
  border: var(--bd) solid var(--ink);
  border-radius: var(--radius);
  padding: 0.55rem 0.95rem;
  font-size: 0.82rem;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: 0.02em;
  cursor: pointer;
  background: var(--surface);
  color: var(--ink);
  box-shadow: var(--shadow-xs);
  transition: transform 0.08s, box-shadow 0.08s;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--s2);
  white-space: nowrap;
}
button:hover:not(:disabled) { transform: translate(-1px, -1px); box-shadow: var(--shadow-sm); }
button:active:not(:disabled) { transform: translate(2px, 2px); box-shadow: 0 0 0 var(--ink); }
button:disabled { opacity: 0.5; cursor: not-allowed; box-shadow: none; }
button:focus-visible { outline: 3px solid var(--accent-2); outline-offset: 2px; }

.primary { background: var(--accent); color: var(--accent-text); }
.primary:hover:not(:disabled) { background: var(--accent-hover); }

.ghost { background: var(--surface); color: var(--ink); }
.ghost:hover:not(:disabled) { background: var(--surface-3); }

.danger { background: var(--danger); color: var(--danger-text); }
.danger:hover:not(:disabled) { background: #ff6464; }

.small { padding: 0.36rem 0.65rem; font-size: 0.72rem; box-shadow: var(--shadow-xs); }
.block { width: 100%; }

.row { display: flex; gap: var(--s2); align-items: center; }
.row.spread { justify-content: space-between; }

/* ---------- Login ---------- */
.login-card {
  background: var(--surface);
  border: var(--bd-thick) solid var(--ink);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 28px;
  width: min(400px, 100%);
}

.login-hint { font-size: 0.84rem; margin-bottom: var(--s4); }
.login-card .field { margin-bottom: var(--s4); }

/* ---------- App shell ---------- */
.view--app { max-width: 1100px; }

.app-modal {
  background: var(--surface);
  border: var(--bd-thick) solid var(--ink);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  display: flex;
  width: 100%;
  height: 88vh;
  max-height: 880px;
  overflow: hidden;
}

/* ---------- Sidebar ---------- */
.sidebar {
  width: 224px;
  background: var(--surface-2);
  border-right: var(--bd-thick) solid var(--ink);
  display: flex;
  flex-direction: column;
  padding: 16px 14px;
  flex-shrink: 0;
}

.tabs { display: flex; flex-direction: column; gap: var(--s2); flex: 1; }

.tab {
  background: var(--surface);
  color: var(--ink);
  justify-content: flex-start;
  gap: 10px;
  font-size: 0.78rem;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: 0.03em;
  padding: 0.6rem 0.7rem;
}
.tab svg {
  width: 18px;
  height: 18px;
  fill: none;
  stroke: currentColor;
  stroke-width: 2.2;
  stroke-linecap: round;
  stroke-linejoin: round;
  flex-shrink: 0;
}
.tab:hover { background: var(--surface-3); }
.tab.active {
  background: var(--accent);
  color: var(--accent-text);
  box-shadow: var(--shadow-sm);
  transform: translate(-1px, -1px);
}

.sidebar-bottom { margin-top: auto; padding-top: var(--s4); }

/* ---------- Content ---------- */
.content-wrapper {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  position: relative;
  min-width: 0;
}

.topbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 14px 20px;
  border-bottom: var(--bd-thick) solid var(--ink);
  background: var(--accent);
}
.topbar-title h1 { line-height: 1.2; }
.topbar-sub, .topbar-title p { font-size: 0.76rem; margin-top: 3px; color: var(--ink); font-weight: 600; }

.panels {
  flex: 1;
  overflow-y: auto;
  padding: 22px;
  background: var(--surface-2);
}

.panel { max-width: 740px; margin: 0 auto; }

/* ---------- Status toast ---------- */
.status {
  position: absolute;
  top: 16px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 50;
  padding: 0.55rem 1.1rem;
  border: var(--bd-thick) solid var(--ink);
  background: var(--ok);
  color: #ffffff;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: 0.03em;
  font-size: 0.78rem;
  box-shadow: var(--shadow-sm);
  animation: slideDown 0.18s ease-out;
}
.status.error { background: var(--danger); }

@keyframes slideDown {
  from { transform: translate(-50%, -12px); opacity: 0; }
  to { transform: translate(-50%, 0); opacity: 1; }
}

/* ---------- Cards ---------- */
.card {
  background: var(--surface);
  border: var(--bd) solid var(--ink);
  border-radius: var(--radius);
  box-shadow: var(--shadow-sm);
  padding: 18px;
  margin-bottom: 18px;
}
.card--flush { background: transparent; border: none; box-shadow: none; padding: 0; }
.card-head { margin-bottom: var(--s4); }
.card-head h3 + p { margin-top: 4px; }
.card-head p { font-size: 0.8rem; }

.grid { display: grid; gap: var(--s4) var(--s4); }
.field--full { grid-column: 1 / -1; }
.field--full .row select { flex: 1; }
.field--log { margin-top: var(--s5); }

/* ---------- Checkbox ---------- */
.checkbox-label {
  display: flex;
  flex-direction: row;
  align-items: flex-start;
  gap: var(--s3);
  cursor: pointer;
}
.checkbox-text {
  font-size: 0.82rem;
  font-weight: 700;
  color: var(--text);
  display: flex;
  flex-direction: column;
  gap: 3px;
}
.checkbox-text .hint { font-weight: 500; }
.checkbox-label input[type="checkbox"],
.checkbox-inline input[type="checkbox"] {
  width: 18px;
  height: 18px;
  margin: 1px 0 0;
  flex-shrink: 0;
  cursor: pointer;
  accent-color: var(--accent);
}

/* ---------- Scenarios ---------- */
.section-intro { margin-bottom: 18px; }
.placeholders {
  font-size: 0.76rem;
  color: var(--muted);
  margin: var(--s3) 0;
  line-height: 2;
}
.placeholders code { margin-right: 4px; }

.scenarios { display: flex; flex-direction: column; gap: 14px; }

/* ----- Collapsible scenario card ----- */
.scenario {
  border: var(--bd) solid var(--ink);
  border-radius: var(--radius);
  background: var(--surface);
  box-shadow: var(--shadow-sm);
}

.scenario-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: var(--s3);
  padding: 0.7rem 0.95rem;
  background: var(--surface);
  cursor: pointer;
  list-style: none;
  -webkit-user-select: none;
  user-select: none;
  transition: background 0.12s;
}
.scenario-head::-webkit-details-marker { display: none; }
.scenario-head:hover { background: var(--surface-3); }
.scenario-head:focus-visible { outline: 3px solid var(--accent-2); outline-offset: -3px; }
.scenario[open] > .scenario-head { border-bottom: var(--bd) solid var(--ink); background: var(--summary-bar); }

.scenario-title { display: inline-flex; align-items: center; gap: 10px; min-width: 0; }
.scenario-title strong { font-size: 0.86rem; font-weight: 800; text-transform: uppercase; letter-spacing: 0.02em; }
.scenario-title::before {
  content: "";
  width: 8px;
  height: 8px;
  border-right: 3px solid var(--ink);
  border-bottom: 3px solid var(--ink);
  transform: rotate(-45deg);
  transition: transform 0.18s;
  flex-shrink: 0;
}
.scenario[open] > .scenario-head .scenario-title::before { transform: rotate(45deg); }

.scenario-status {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  font-weight: 800;
  font-size: 0.66rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  padding: 3px 9px;
  border: var(--bd) solid var(--ink);
  background: var(--surface-3);
  color: var(--ink);
  flex-shrink: 0;
}
.scenario-status::before {
  content: "✕";
  font-size: 0.78rem;
  line-height: 1;
  font-weight: 900;
}
.scenario-status.is-active {
  background: var(--accent);
  color: var(--ink);
}
.scenario-status.is-active::before { content: "✓"; }

.scenario-body { padding: 0; }

.scenario-section { padding: 0.95rem; }
.scenario-section + .scenario-section { border-top: var(--bd) solid var(--ink); }
.scenario-section textarea { margin-top: 0; }

/* ----- Section sub-accordions (default message / rules) ----- */
.scenario-section > summary {
  cursor: pointer;
  font-weight: 800;
  font-size: 0.78rem;
  text-transform: uppercase;
  letter-spacing: 0.03em;
  list-style: none;
  display: flex;
  align-items: center;
  gap: var(--s2);
  color: var(--ink);
  padding: 0.55rem 0.7rem;
  border: var(--bd) solid var(--ink);
  background: var(--summary-bar);
  box-shadow: var(--shadow-xs);
  transition: background 0.12s, transform 0.08s, box-shadow 0.08s;
  -webkit-user-select: none;
  user-select: none;
}
.scenario-section > summary:hover { background: var(--summary-bar-hover); transform: translate(-1px, -1px); box-shadow: var(--shadow-sm); }
.scenario-section > summary:focus-visible { outline: 3px solid var(--accent-2); outline-offset: 2px; }
.scenario-section > summary::-webkit-details-marker { display: none; }

/* Shared chevron mark */
.scenario-section > summary::before,
.summary-row > span:first-child::before {
  content: "";
  width: 7px;
  height: 7px;
  border-right: 3px solid var(--ink);
  border-bottom: 3px solid var(--ink);
  transform: rotate(-45deg);
  transition: transform 0.18s;
  flex-shrink: 0;
}
.scenario-section[open] > summary::before,
.scenario-section[open] > summary.summary-row > span:first-child::before { transform: rotate(45deg); }

/* Rows with a trailing action button keep label+chevron together on the left */
.scenario-section > summary.summary-row { justify-content: space-between; }
.scenario-section > summary.summary-row::before { display: none; }
.summary-row > span:first-child { display: inline-flex; align-items: center; gap: var(--s2); }

/* Body of an opened section sits just below its header bar */
.scenario-section[open] > summary { margin-bottom: var(--s3); }

/* ---------- Voice / language overrides ---------- */
.settings-row {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: var(--s3) var(--s4);
  margin-top: var(--s3);
  background: var(--surface-2);
  padding: 0.65rem 0.8rem;
  border: var(--bd) solid var(--ink);
}
.settings-row label {
  margin: 0;
  flex-direction: row;
  align-items: center;
  gap: var(--s2);
  font-size: 0.74rem;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: 0.03em;
  color: var(--ink);
}
.settings-row select { width: auto; min-width: 9rem; padding: 0.4rem 1.8rem 0.4rem 0.6rem; }
.settings-row .checkbox-inline {
  display: inline-flex;
  flex-direction: row;
  align-items: center;
  gap: 6px;
  cursor: pointer;
  font-weight: 700;
  margin-left: auto;
}

/* ---------- Rules ---------- */
.rules-list { display: flex; flex-direction: column; gap: var(--s3); margin-top: var(--s3); }

.rule-row {
  border: var(--bd) solid var(--ink);
  border-radius: var(--radius);
  padding: 0.85rem;
  background: var(--surface-2);
  box-shadow: var(--shadow-xs);
}
.rule-grid { display: grid; gap: var(--s3); margin-bottom: var(--s3); }
.rule-row label {
  display: flex;
  flex-direction: column;
  gap: var(--s2);
  font-size: 0.72rem;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: 0.03em;
  color: var(--ink);
  margin-bottom: var(--s3);
}
.rule-row label:last-of-type { margin-bottom: 0; }

/* ---------- Cache ---------- */
.cache-add { margin-bottom: var(--s4); }
.cache-add input { flex: 1; }

.cache-list { display: flex; flex-direction: column; gap: var(--s3); margin: var(--s4) 0; }
.cache-item {
  border: var(--bd) solid var(--ink);
  border-radius: var(--radius);
  padding: 0.75rem 0.85rem;
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: var(--s4);
  background: var(--surface);
  box-shadow: var(--shadow-xs);
}
.cache-item strong { display: block; font-size: 0.85rem; font-weight: 700; margin-bottom: 2px; }
.cache-item p { font-size: 0.74rem; color: var(--muted); }

.pager { margin-top: var(--s4); }
.pager .hint { margin: 0; font-weight: 700; }

/* ---------- Scrollbar ---------- */
.panels::-webkit-scrollbar { width: 14px; }
.panels::-webkit-scrollbar-track { background: var(--surface-2); border-left: var(--bd) solid var(--ink); }
.panels::-webkit-scrollbar-thumb {
  background: var(--ink);
  border: 3px solid var(--surface-2);
}

/* ---------- Responsive ---------- */
@media (min-width: 720px) {
  .grid { grid-template-columns: 1fr 1fr; }
  .rule-grid { grid-template-columns: 1fr 1fr 1.6fr; }
}

@media (max-width: 760px) {
  body { padding: 0; align-items: stretch; }
  .view--app { max-width: none; }
  .app-modal {
    flex-direction: column;
    height: 100vh;
    max-height: none;
    border: none;
    box-shadow: none;
  }
  .sidebar {
    width: 100%;
    flex-direction: row;
    align-items: center;
    border-right: none;
    border-bottom: var(--bd-thick) solid var(--ink);
    padding: 10px 12px;
    gap: var(--s3);
  }
  .sidebar .banner-panel {
    width: 120px;
    height: 44px;
    margin: 0;
    flex-shrink: 0;
  }
  .tabs { flex-direction: row; flex: 1; overflow-x: auto; gap: var(--s2); }
  .tab span { display: none; }
  .tab { padding: 0.5rem 0.7rem; }
  .sidebar-bottom { margin: 0; padding: 0; }
  .sidebar-bottom .block { width: auto; }
  .topbar { padding: 12px 16px; }
  .panels { padding: 16px; }
}

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