:root {
  color-scheme: light;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  color: #172033;
  background: #f3f5f9;
  font-synthesis: none;
  text-rendering: optimizeLegibility;
  font-size: 16px;
  line-height: 1.5;
  -webkit-text-size-adjust: 100%;
}

* { box-sizing: border-box; }
body { margin: 0; min-width: 320px; }
button, input, select, textarea { font: inherit; }
button { cursor: pointer; touch-action: manipulation; }
a { color: inherit; }
:focus-visible { outline: 3px solid #3266e3; outline-offset: 3px; }
input[type="checkbox"] { width: 20px; height: 20px; flex: 0 0 20px; margin: 0; accent-color: #3266e3; }

.loading, .auth-screen { min-height: 100vh; min-height: 100dvh; display: grid; place-content: center; text-align: center; padding: 24px; }
.spinner { width: 28px; height: 28px; border: 3px solid #d5dbea; border-top-color: #3266e3; border-radius: 50%; animation: spin .8s linear infinite; margin: auto; }
@keyframes spin { to { transform: rotate(360deg); } }
.auth-card { min-width: 0; max-width: 460px; padding: 32px; border: 1px solid #e1e6ef; border-radius: 16px; background: white; box-shadow: 0 18px 48px #18274612; overflow-wrap: anywhere; }
.auth-card h1 { margin-top: 0; }
.brand-mark-centered { margin: 0 auto 18px; }
.muted { color: #68748a; }
.app-shell { min-height: 100vh; }
.topbar { min-height: 68px; display: flex; align-items: center; justify-content: space-between; gap: 16px; padding: 12px max(24px, calc((100% - 1440px) / 2)); background: #111c31; color: white; }
.brand { display: flex; align-items: center; gap: 12px; font-size: 17px; font-weight: 700; }
.brand-mark { width: 34px; height: 34px; flex: 0 0 34px; border-radius: 10px; background: #3266e3; display: grid; place-items: center; }
.top-actions { display: flex; gap: 12px; align-items: center; }
.chat-label { color: #b7c2d6; font-size: 13px; }
.layout { max-width: 1440px; margin: 26px auto; padding: 0 24px; display: grid; grid-template-columns: 220px minmax(0, 1fr); gap: 24px; }
.sidebar { position: sticky; top: 16px; align-self: start; padding: 10px; border: 1px solid #e2e7ef; border-radius: 14px; background: white; }
.nav-item { display: flex; align-items: center; gap: 8px; width: 100%; min-height: 48px; padding: 10px 12px; margin: 2px 0; border: 0; border-radius: 9px; color: #526078; text-align: left; background: transparent; }
.nav-icon { width: 24px; text-align: center; font-size: 22px; line-height: 1; }
.nav-item:hover, .nav-item.active { background: #edf2ff; color: #2456ce; font-weight: 650; }
.content { min-width: 0; }
.content > section, .content > .card { margin-bottom: 16px; }
.page-heading { display: flex; justify-content: space-between; gap: 16px; align-items: center; margin: 2px 0 20px; }
.page-heading > div { min-width: 0; }
.page-heading > .button { flex-shrink: 0; }
.page-heading h1 { margin: 0; font-size: 24px; letter-spacing: -.03em; }
.page-heading p { margin: 5px 0 0; color: #69758b; font-size: 14px; }
.card { min-width: 0; background: white; border: 1px solid #e2e7ef; border-radius: 14px; padding: 20px; box-shadow: 0 2px 8px #192c4b08; overflow-wrap: anywhere; }
.editor-grid > div > .card + .card { margin-top: 16px; }
.cards { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 14px; }
.metric { font-size: 26px; font-weight: 750; line-height: 1.25; margin-top: 8px; overflow-wrap: anywhere; }
.metric-label { font-size: 13px; color: #68748a; }
.section-title { margin: 0 0 14px; font-size: 16px; }
.button { display: inline-flex; justify-content: center; align-items: center; gap: 6px; min-width: 44px; min-height: 44px; border: 1px solid #d6deeb; border-radius: 8px; background: white; color: #25324a; padding: 10px 14px; font-size: 14px; font-weight: 600; line-height: 1.3; text-align: center; }
.button:hover { background: #f6f8fc; }
.button.primary { border-color: #285ad4; background: #3266e3; color: white; }
.button.primary:hover { background: #2455cd; }
.button.danger { color: #b33636; }
.button.small { padding: 10px; font-size: 14px; }
.button:disabled { opacity: .5; cursor: not-allowed; }
.rule-list { display: grid; gap: 10px; }
.rule-row { display: grid; grid-template-columns: 24px minmax(0, 1fr) minmax(0, .8fr) auto; align-items: center; gap: 12px; padding: 14px; border: 1px solid #e4e9f1; border-radius: 11px; background: white; }
.rule-row > div { min-width: 0; }
.rule-row[data-rule-id] { grid-template-columns: 24px minmax(0, 1fr) minmax(0, .8fr); }
.dragging { opacity: .45; }
.drag-handle { cursor: grab; color: #8a96aa; font-size: 18px; }
.rule-name { font-weight: 700; overflow-wrap: anywhere; }
.rule-sub { margin-top: 4px; color: #68748a; font-size: 13px; overflow-wrap: anywhere; }
.rule-channel { color: #40506a; font-size: 14px; overflow-wrap: anywhere; }
.rule-actions { grid-column: 2 / -1; display: flex; flex-wrap: wrap; align-items: center; gap: 8px; padding-top: 12px; border-top: 1px solid #edf0f5; }
.rule-controls { display: flex; align-items: center; gap: 8px; }
.badge { display: inline-flex; align-items: center; justify-content: center; justify-self: start; border-radius: 99px; padding: 4px 9px; background: #e9f7ef; color: #247748; font-size: 12px; font-weight: 700; }
.badge.off { background: #f0f2f5; color: #6b7482; }
.empty { padding: 35px 20px; text-align: center; color: #66738a; }
.form-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 15px; }
.field { display: grid; gap: 6px; min-width: 0; }
.field.full { grid-column: 1 / -1; }
.field > label:not(.checkline), .field-label { color: #45526a; font-size: 14px; font-weight: 650; }
.field input:not([type="checkbox"]), .field select, .field textarea, .inline-control > select { min-width: 0; width: 100%; min-height: 48px; padding: 11px 12px; border: 1px solid #d7deea; border-radius: 8px; font-size: 16px; color: #1b2740; background: #fff; }
.field textarea { min-height: 76px; resize: vertical; }
.check-grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 8px; }
.check-pill { display: flex; min-width: 0; min-height: 44px; gap: 8px; align-items: center; padding: 10px; border: 1px solid #dfe5ee; border-radius: 8px; color: #46536a; font-size: 14px; cursor: pointer; }
.check-pill:has(input:checked) { border-color: #3266e3; background: #edf2ff; }
.check-pill:has(input:disabled) { opacity: .55; cursor: not-allowed; }
.checkline, .field.checkline { display: flex; min-width: 0; min-height: 44px; align-items: center; gap: 10px; padding: 8px 0; color: #46536a; font-size: 14px; cursor: pointer; }
.editor-grid { display: grid; grid-template-columns: minmax(0, 1.15fr) minmax(0, .85fr); gap: 16px; align-items: start; }
.editor-grid > div { min-width: 0; }
.editor-grid > aside { position: sticky; top: 16px; }
.preview-box { min-width: 0; min-height: 190px; padding: 16px; border-radius: 12px; background: #111c31; color: #f3f6fc; white-space: pre-wrap; overflow-wrap: anywhere; font: 14px/1.6 ui-monospace, SFMono-Regular, Menlo, monospace; }
.preview-label { color: #526078; font-size: 12px; font-weight: 700; letter-spacing: .06em; text-transform: uppercase; margin-bottom: 10px; }
.preview-meta { margin-top: 10px; color: #68748a; font-size: 13px; }
.toolbar { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 18px; }
.block-list { display: grid; gap: 8px; }
.block-row { display: grid; grid-template-columns: 20px minmax(0, 1fr) 44px 44px; align-items: center; gap: 8px; padding: 8px; border: 1px solid #e2e7ef; border-radius: 8px; }
.block-row .checkline { font-size: 14px; }
.settings-preview-input { margin-top: 14px; }
.alert { padding: 12px 14px; border: 1px solid #f1d2cb; border-radius: 9px; background: #fff5f2; color: #963b2b; margin-bottom: 14px; }
.notice { padding: 12px 14px; border: 1px solid #cbd9fa; border-radius: 9px; background: #eff4ff; color: #294d9b; margin-bottom: 14px; font-size: 14px; }
.toast { position: fixed; right: 24px; bottom: 24px; z-index: 20; max-width: min(420px, calc(100% - 48px)); padding: 12px 16px; border-radius: 10px; color: white; background: #182943; box-shadow: 0 8px 24px #17203330; overflow-wrap: anywhere; }
.toast.error { background: #9c302a; }
.hint { color: #68748a; font-size: 13px; line-height: 1.5; }
.divider { height: 1px; border: 0; background: #edf0f5; margin: 20px 0; }
.inline-control { display: grid; gap: 10px; min-width: 0; }
.hidden { display: none !important; }

@media (max-width: 1100px) {
  .layout { grid-template-columns: 180px minmax(0, 1fr); gap: 16px; }
  .editor-grid { grid-template-columns: 1fr; }
  .editor-grid > aside { position: static; }
}
@media (max-width: 900px) {
  .layout { grid-template-columns: 1fr; margin-top: 16px; }
  .sidebar { position: static; display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .nav-item { justify-content: center; }
}
@media (max-width: 640px) {
  html { scroll-padding-top: 16px; scroll-padding-bottom: calc(152px + env(safe-area-inset-bottom)); }
  .topbar { min-height: 64px; padding: 10px 12px; gap: 8px; }
  .brand { gap: 8px; font-size: 15px; }
  .top-actions .chat-label { display: none; }
  .layout { padding: 0 12px; margin-bottom: 0; }
  .content { padding-bottom: calc(84px + env(safe-area-inset-bottom)); }
  .content:has(.editor-actions) { padding-bottom: calc(152px + env(safe-area-inset-bottom)); }
  .sidebar { position: fixed; top: auto; right: 0; bottom: 0; left: 0; z-index: 10; gap: 4px; padding: 6px 8px calc(6px + env(safe-area-inset-bottom)); border-width: 1px 0 0; border-radius: 0; box-shadow: 0 -4px 16px #192c4b08; }
  .nav-item { flex-direction: column; gap: 4px; min-height: 52px; margin: 0; padding: 6px 2px; font-size: 12px; line-height: 16px; }
  .nav-icon { font-size: 20px; }
  .page-heading { flex-direction: column; align-items: stretch; gap: 12px; margin-bottom: 16px; }
  .page-heading h1 { font-size: 22px; }
  .card { padding: 16px; }
  .cards { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
  .cards > .card:last-child:nth-child(odd) { grid-column: 1 / -1; }
  .metric { font-size: 24px; }
  .rule-row, .rule-row[data-rule-id] { grid-template-columns: 20px minmax(0, 1fr); gap: 8px; padding: 12px; }
  .rule-row > .rule-channel, .rule-row > .badge, .rule-row[data-rule-id] > div:nth-child(3) { grid-column: 2; }
  .rule-actions { grid-column: 1 / -1; display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .rule-controls { grid-column: 1 / -1; }
  .rule-controls .badge { margin-right: auto; }
  .rule-actions > .danger { grid-column: 1 / -1; }
  .rule-actions .button { padding: 10px 6px; }
  .form-grid { grid-template-columns: 1fr; }
  .check-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .block-row { grid-template-columns: minmax(0, 1fr) 44px 44px; }
  .block-row > .drag-handle { display: none; }
  .block-row .checkline { gap: 8px; }
  .toolbar > .button { flex: 1 1 140px; }
  .editor-actions { position: fixed; right: 0; bottom: calc(65px + env(safe-area-inset-bottom)); left: 0; z-index: 11; margin: 0; padding: 10px 12px; border-top: 1px solid #e2e7ef; background: white; }
  .preview-box { min-height: 160px; padding: 14px; }
  .toast { right: 12px; bottom: calc(144px + env(safe-area-inset-bottom)); max-width: calc(100% - 24px); }
  .auth-screen { padding: 16px; }
  .auth-card { padding: 24px 20px; }
}
@media (prefers-reduced-motion: reduce) {
  .spinner { animation: none; }
}
