:root {
  color-scheme: light;
  --bg: #f4f6f8;
  --panel: #ffffff;
  --text: #162019;
  --muted: #6e7872;
  --line: #dfe5e1;
  --accent: #087f5b;
  --accent-dark: #056347;
  --accent-soft: #e7f6f0;
  --danger: #c92a2a;
  --warning: #d97706;
  --shadow: 0 14px 40px rgba(25, 40, 31, .08);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* { box-sizing: border-box; }
body { margin: 0; color: var(--text); background: var(--bg); }
button, input, select, textarea { font: inherit; }
button { cursor: pointer; }
[hidden] { display: none !important; }

.login-shell { min-height: 100vh; display: grid; place-items: center; padding: 24px; background: radial-gradient(circle at 20% 0%, #dff7ed, transparent 40%), #f5f7f6; }
.login-card { width: min(440px, 100%); background: var(--panel); border: 1px solid var(--line); border-radius: 22px; padding: 38px; box-shadow: var(--shadow); }
.login-card h1 { margin: 18px 0 8px; font-size: 28px; }
.login-card p { color: var(--muted); line-height: 1.6; }
.brand-mark { width: 58px; height: 58px; display: grid; place-items: center; border-radius: 16px; background: var(--accent); color: white; font-weight: 800; letter-spacing: -.04em; }
.brand-mark.small { width: 34px; height: 34px; border-radius: 10px; font-size: 13px; }

.app-shell { min-height: 100vh; display: grid; grid-template-columns: 240px minmax(0, 1fr); }
.sidebar { position: sticky; top: 0; height: 100vh; padding: 22px 16px; background: #10271f; color: white; display: flex; flex-direction: column; }
.brand { display: flex; align-items: center; gap: 10px; padding: 4px 8px 26px; font-weight: 700; }
.sidebar nav { display: grid; gap: 5px; }
.nav-item { width: 100%; border: 0; border-radius: 10px; padding: 11px 12px; text-align: left; color: #bed0c8; background: transparent; }
.nav-item:hover, .nav-item.active { color: white; background: rgba(255,255,255,.1); }
.nav-item.danger { margin-top: auto; color: #ffc9c9; }

.content { min-width: 0; padding: 28px 36px 60px; }
.topbar { display: flex; justify-content: space-between; align-items: center; margin-bottom: 24px; }
.topbar h2 { margin: 3px 0 0; font-size: 28px; }
.topbar-actions, .button-row, .copy-row { display: flex; gap: 10px; align-items: center; }
.eyebrow { margin: 0; color: var(--accent); font-size: 11px; font-weight: 800; letter-spacing: .12em; }
.status-pill { padding: 7px 11px; border-radius: 999px; background: var(--accent-soft); color: var(--accent-dark); font-size: 13px; }
.status-pill.busy { background: #fff3bf; color: #8a5d00; }
.status-pill.error { background: #ffe3e3; color: var(--danger); }

.view { display: none; }
.view.active { display: block; }
.stats-grid { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 16px; margin-bottom: 18px; }
.stat-card, .panel { background: var(--panel); border: 1px solid var(--line); border-radius: 16px; box-shadow: 0 5px 20px rgba(25, 40, 31, .04); }
.stat-card { padding: 20px; }
.stat-card span { color: var(--muted); font-size: 13px; }
.stat-card strong { display: block; margin-top: 8px; font-size: 30px; }
.panel { padding: 22px; }
.panel h3 { margin: 4px 0 0; }
.panel-heading { display: flex; justify-content: space-between; align-items: center; gap: 14px; margin-bottom: 18px; }
.two-column { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 18px; }
.split-layout { display: grid; grid-template-columns: minmax(320px, .72fr) minmax(420px, 1.28fr); gap: 18px; align-items: start; }
.sticky-panel { position: sticky; top: 20px; }

label { display: grid; gap: 7px; margin: 0 0 14px; color: #39443e; font-size: 13px; font-weight: 650; }
.check-label { display: flex; align-items: center; gap: 8px; }
.check-label input { width: auto; flex: 0 0 auto; }
input, select, textarea { width: 100%; border: 1px solid #ccd5d0; border-radius: 9px; padding: 10px 11px; color: var(--text); background: white; outline: none; }
input:focus, select:focus, textarea:focus { border-color: var(--accent); box-shadow: 0 0 0 3px rgba(8,127,91,.12); }
textarea { resize: vertical; font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 12px; line-height: 1.55; }
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
fieldset { border: 1px solid var(--line); border-radius: 10px; padding: 12px; margin: 0 0 15px; }
legend { color: var(--muted); font-size: 12px; padding: 0 5px; }
.check-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; }
.check-grid label { display: flex; align-items: center; gap: 7px; margin: 0; font-weight: 500; }
.check-grid input { width: auto; }
.ordered-checks { display: grid; gap: 7px; max-height: 420px; overflow: auto; }
.ordered-check-row { display: flex; align-items: center; justify-content: space-between; gap: 10px; padding: 7px 8px; border: 1px solid var(--line); border-radius: 8px; background: #fafcfb; }
.ordered-check-row label { display: flex; align-items: center; gap: 8px; min-width: 0; margin: 0; font-weight: 500; overflow-wrap: anywhere; }
.ordered-check-row input { width: auto; flex: 0 0 auto; }
.order-actions { display: flex; gap: 4px; flex: 0 0 auto; }
.order-actions button { width: 30px; padding: 4px 0; }

button { border: 1px solid transparent; border-radius: 9px; padding: 9px 13px; font-weight: 700; }
button.primary { color: white; background: var(--accent); }
button.primary:hover { background: var(--accent-dark); }
button.secondary { border-color: var(--line); color: #344039; background: white; }
button.danger-button { color: var(--danger); background: #fff5f5; border-color: #ffc9c9; }
.compact-input { width: min(190px, 45%); }
.copy-row input { flex: 1; }
.copy-row button { flex: 0 0 auto; }

.item-list { display: grid; gap: 9px; }
.list-item { display: flex; justify-content: space-between; align-items: flex-start; gap: 12px; border: 1px solid var(--line); border-radius: 11px; padding: 13px; }
.list-item-main { min-width: 0; }
.list-item h4 { margin: 0 0 5px; font-size: 14px; overflow-wrap: anywhere; }
.list-item p { margin: 0; color: var(--muted); font-size: 12px; overflow-wrap: anywhere; }
.list-actions { display: flex; gap: 6px; flex: 0 0 auto; }
.list-actions button { padding: 6px 9px; font-size: 12px; }
.rule-code { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; }
.rule-index { color: #97a19b; margin-right: 8px; }
.muted, .hint { color: var(--muted); line-height: 1.55; }
.hint { font-size: 12px; }
.empty { padding: 35px 10px; text-align: center; color: var(--muted); }
.validation-ok { padding: 12px; border-radius: 10px; background: var(--accent-soft); color: var(--accent-dark); }
.validation-errors, .validation-warnings { padding: 12px 12px 12px 30px; border-radius: 10px; font-size: 13px; }
.validation-errors { color: #a51111; background: #fff0f0; }
.validation-warnings { color: #8a5d00; background: #fff8db; }
.error-text { color: var(--danger) !important; }
.toast { position: fixed; z-index: 20; right: 28px; bottom: 28px; max-width: 420px; padding: 12px 15px; border-radius: 10px; color: white; background: #183c30; box-shadow: var(--shadow); }
.toast.error { background: var(--danger); }
code { padding: 2px 5px; border-radius: 5px; background: #eef2ef; }

@media (max-width: 980px) {
  .app-shell { grid-template-columns: 1fr; }
  .sidebar { position: static; height: auto; }
  .sidebar nav { grid-template-columns: repeat(3, 1fr); }
  .nav-item.danger { margin-top: 8px; }
  .split-layout, .two-column { grid-template-columns: 1fr; }
  .sticky-panel { position: static; }
}
@media (max-width: 680px) {
  .content { padding: 20px 14px 40px; }
  .sidebar nav { grid-template-columns: 1fr 1fr; }
  .stats-grid { grid-template-columns: 1fr 1fr; }
  .form-grid, .check-grid { grid-template-columns: 1fr; }
  .topbar { align-items: flex-start; gap: 12px; }
}
