:root {
  --bg: #f2f4ef;
  --surface: #fbfcf8;
  --fg: #18241f;
  --muted: #5a6a62;
  --border: #cdd6d0;
  --accent: #a33d2d;
  --accent-on: #fffaf5;
  --success: #2d6a4f;
  --warning: #996515;
  --danger: #a12e35;
  --sidebar: #1a2923;
  --sidebar-fg: #e9eee9;
  --font-display: 'Onest', sans-serif;
  --font-body: 'Onest', sans-serif;
  --radius: 9px;
  --space-section: 32px;
  --shadow: 0 16px 44px rgba(21, 35, 28, .12);
}

* { box-sizing: border-box; }
html { color-scheme: light; }
body { margin: 0; min-width: 320px; background: var(--bg); color: var(--fg); font-family: var(--font-body); font-size: 15px; line-height: 1.45; }
button, input, select, textarea { font: inherit; }
button, select { cursor: pointer; }
button:disabled { cursor: not-allowed; opacity: .5; }
a { color: inherit; }
.hidden { display: none !important; }
:focus-visible { outline: 3px solid rgba(163, 61, 45, .28); outline-offset: 2px; }

.auth-screen { min-height: 100vh; display: grid; grid-template-columns: minmax(0, 1.2fr) minmax(380px, .8fr); }
.auth-story { min-width: 0; display: flex; flex-direction: column; padding: 40px 56px; background: var(--sidebar); color: var(--sidebar-fg); overflow: hidden; }
.auth-brand, .brand { display: inline-flex; align-items: center; gap: 11px; font-size: 19px; font-weight: 700; text-decoration: none; }
.brand-mark { width: 34px; height: 34px; display: grid; place-items: center; border: 1px solid currentColor; border-radius: 50%; font-size: 15px; }
.auth-copy { margin-block: auto; max-width: 690px; }
.eyebrow, .form-heading p { margin: 0 0 12px; color: #d6a795; font-size: 12px; font-weight: 700; letter-spacing: .12em; text-transform: uppercase; }
.auth-copy h1 { margin: 0; max-width: 720px; font-size: clamp(40px, 6vw, 78px); line-height: .99; letter-spacing: -.055em; }
.auth-copy > p:last-child { max-width: 590px; margin: 28px 0 0; color: #b7c3bc; font-size: 17px; }
.trace-demo { display: grid; grid-template-columns: repeat(3, minmax(120px, 1fr)); align-items: center; gap: 16px; margin-top: 48px; padding-top: 24px; border-top: 1px solid #3a4a43; }
.trace-demo div { min-width: 0; }
.trace-demo span { display: block; margin-bottom: 3px; color: #92a39a; font-size: 12px; }
.trace-demo strong { display: block; overflow-wrap: anywhere; color: #f3f5f1; font-size: 14px; }
.trace-demo i { display: none; }
.auth-panel { display: grid; place-items: center; padding: 32px; background: var(--surface); }
.auth-form { width: min(100%, 420px); display: grid; gap: 18px; }
.form-heading { margin-bottom: 8px; }
.form-heading h2 { margin: 0 0 8px; font-size: 28px; line-height: 1.18; letter-spacing: -.025em; }
.form-heading span { color: var(--muted); }
label { display: grid; gap: 7px; color: #33453c; font-size: 14px; font-weight: 600; }
input, select, textarea { width: 100%; min-width: 0; border: 1px solid var(--border); border-radius: var(--radius); background: var(--surface); color: var(--fg); }
input, select { height: 44px; padding: 0 12px; }
textarea { min-height: 104px; padding: 10px 12px; resize: vertical; }
input:hover, select:hover, textarea:hover { border-color: #9baaa2; }
input:focus, select:focus, textarea:focus { border-color: var(--accent); outline: 3px solid rgba(163, 61, 45, .12); }
label small { color: var(--muted); font-weight: 400; }
.password-wrap { position: relative; }
.password-wrap input { padding-right: 94px; }
.password-toggle { position: absolute; inset: 0 2px 0 auto; min-width: 84px; min-height: 44px; border: 0; background: transparent; color: var(--accent); font-size: 13px; font-weight: 700; }
.btn { min-height: 44px; border: 1px solid transparent; border-radius: var(--radius); padding: 0 16px; display: inline-flex; align-items: center; justify-content: center; gap: 8px; font-weight: 700; transition: background-color 160ms ease, color 160ms ease, border-color 160ms ease, transform 120ms ease; }
.btn:active { transform: translateY(1px); }
.btn.primary { background: var(--accent); color: var(--accent-on); }
.btn.primary:hover { background: #883023; }
.btn.secondary { border-color: var(--border); background: var(--surface); color: var(--fg); }
.btn.secondary:hover { border-color: #8e9e95; background: #f4f6f2; }
.btn.danger { border-color: #dfb4b6; background: #fff8f7; color: var(--danger); }
.btn.small { min-height: 40px; padding-inline: 12px; font-size: 14px; }
.form-error { min-height: 20px; margin: -5px 0 0; color: var(--danger); font-size: 14px; }

.app-shell { min-height: 100vh; display: grid; grid-template-columns: 248px minmax(0, 1fr); grid-template-rows: 64px minmax(0, 1fr); }
.sidebar { position: sticky; top: 0; z-index: 20; grid-row: 1 / 3; height: 100vh; display: flex; flex-direction: column; background: var(--sidebar); color: var(--sidebar-fg); }
.sidebar .brand { height: 64px; padding: 0 24px; border-bottom: 1px solid #34443d; }
.main-nav { padding: 16px 12px; display: grid; gap: 3px; overflow-y: auto; }
.nav-link { min-height: 42px; display: grid; grid-template-columns: 20px minmax(0, 1fr); align-items: center; gap: 10px; padding: 0 12px; border: 0; border-radius: 7px; background: transparent; color: #bdc9c2; text-align: left; text-decoration: none; font-weight: 500; }
.nav-link span:first-child { color: #758a7f; font-size: 11px; font-variant-numeric: tabular-nums; }
.nav-link:hover { background: #24372f; color: #fff; }
.nav-link.active { background: #f1f4ef; color: var(--fg); }
.nav-link.active span:first-child { color: var(--accent); }
.sidebar-foot { margin-top: auto; padding: 12px; border-top: 1px solid #34443d; }
.profile-button { width: 100%; min-height: 52px; display: grid; grid-template-columns: 34px minmax(0, 1fr); align-items: center; gap: 10px; border: 0; border-radius: 7px; padding: 6px 8px; background: transparent; color: var(--sidebar-fg); text-align: left; }
.profile-button:hover { background: #24372f; }
.profile-button strong, .profile-button small { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.profile-button small { color: #94a59c; }
.avatar { width: 34px; height: 34px; display: grid; place-items: center; border-radius: 50%; background: #dfb09d; color: #422118; font-weight: 700; }
.topbar { position: sticky; top: 0; z-index: 15; display: flex; align-items: center; gap: 20px; min-width: 0; padding: 0 32px; border-bottom: 1px solid var(--border); background: rgba(242, 244, 239, .94); backdrop-filter: blur(10px); }
.menu-button { display: none; min-height: 44px; border: 1px solid var(--border); border-radius: var(--radius); background: var(--surface); }
.account-filter { min-width: 260px; display: grid; grid-template-columns: auto minmax(150px, 1fr); align-items: center; gap: 10px; font-weight: 500; }
.account-filter span { color: var(--muted); font-size: 13px; }
.account-filter select { height: 40px; background: var(--surface); }
.system-state { margin-left: auto; display: flex; gap: 14px; color: var(--muted); font-size: 12px; white-space: nowrap; }
.system-state span::before { content: ''; display: inline-block; width: 7px; height: 7px; margin-right: 6px; border-radius: 50%; background: #aa6d58; }
.system-state .ready::before { background: var(--success); }
.workspace { min-width: 0; padding: 28px 32px 40px; }
.page-head { min-height: 48px; display: flex; align-items: flex-start; justify-content: space-between; gap: 20px; margin-bottom: 24px; }
.page-head h1 { margin: 0; font-size: 28px; line-height: 1.2; letter-spacing: -.03em; }
.page-head p { margin: 6px 0 0; color: var(--muted); }
.actions { display: flex; flex-wrap: wrap; gap: 8px; }
.metric-grid { display: grid; grid-template-columns: repeat(6, minmax(120px, 1fr)); border: 1px solid var(--border); border-radius: var(--radius); background: var(--surface); overflow: hidden; }
.metric { min-width: 0; padding: 18px; border-right: 1px solid var(--border); }
.metric:last-child { border-right: 0; }
.metric-grid.four { grid-template-columns: repeat(4, minmax(120px, 1fr)); }
.metric span { display: block; color: var(--muted); font-size: 13px; }
.metric strong { display: block; margin-top: 5px; font-size: 26px; line-height: 1; font-variant-numeric: tabular-nums; }
.content-grid { display: grid; grid-template-columns: minmax(0, 1.6fr) minmax(280px, .8fr); gap: 24px; margin-top: 24px; }
.section { min-width: 0; border-top: 1px solid var(--border); padding-top: 18px; }
.section-head { display: flex; align-items: center; justify-content: space-between; gap: 16px; margin-bottom: 14px; }
.section-head h2 { margin: 0; font-size: 19px; }
.section-head p { margin: 3px 0 0; color: var(--muted); font-size: 13px; }
.event-list { display: grid; }
.event { min-width: 0; display: grid; grid-template-columns: 12px minmax(0, 1fr) auto; gap: 12px; padding: 13px 0; border-bottom: 1px solid var(--border); }
.event-dot { width: 8px; height: 8px; margin-top: 6px; border-radius: 50%; background: #789086; }
.event-dot.success { background: var(--success); }
.event-dot.warning { background: var(--warning); }
.event-dot.error { background: var(--danger); }
.event strong, .event span { overflow-wrap: anywhere; }
.event p { margin: 3px 0 0; color: var(--muted); font-size: 13px; }
.event time { color: var(--muted); font-size: 12px; font-variant-numeric: tabular-nums; }
.onboarding { display: grid; gap: 10px; }
.onboarding-row { display: grid; grid-template-columns: 26px minmax(0, 1fr); gap: 10px; padding: 10px 0; }
.onboarding-row b { width: 24px; height: 24px; display: grid; place-items: center; border: 1px solid var(--border); border-radius: 50%; color: var(--accent); font-size: 12px; }
.onboarding-row strong { display: block; }
.onboarding-row span { color: var(--muted); font-size: 13px; }
.empty { padding: 44px 20px; border: 1px dashed #aab8b0; border-radius: var(--radius); text-align: center; color: var(--muted); }
.empty strong { display: block; margin-bottom: 5px; color: var(--fg); font-size: 17px; }
.table-wrap { min-width: 0; overflow-x: auto; border: 1px solid var(--border); border-radius: var(--radius); background: var(--surface); }
table { width: 100%; border-collapse: collapse; font-size: 14px; }
th, td { padding: 11px 13px; border-bottom: 1px solid var(--border); text-align: left; vertical-align: top; }
th { background: #e8ece7; color: #415248; font-size: 12px; font-weight: 700; letter-spacing: .02em; white-space: nowrap; }
tr:last-child td { border-bottom: 0; }
td { overflow-wrap: anywhere; }
.status { display: inline-flex; min-height: 24px; align-items: center; padding: 2px 8px; border-radius: 999px; background: #e7ece8; color: #405148; font-size: 12px; font-weight: 700; white-space: nowrap; }
.status.success { background: #e0eee6; color: #245b42; }
.status.warning { background: #f4ead5; color: #795110; }
.status.error { background: #f7e2e3; color: #8c2830; }
.status.accent { background: #f0dfd9; color: #7e2e22; }
.form-panel { max-width: 900px; display: grid; gap: 18px; border: 1px solid var(--border); border-radius: var(--radius); padding: 20px; background: var(--surface); }
.form-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 18px 20px; }
.form-grid .full { grid-column: 1 / -1; }
.inline-check { min-height: 44px; display: flex; align-items: center; gap: 9px; }
.inline-check input { width: 18px; height: 18px; }
.rule-list, .account-list, .knowledge-list { display: grid; gap: 10px; }
.row-card { min-width: 0; display: grid; grid-template-columns: minmax(0, 1fr) auto; align-items: center; gap: 16px; padding: 15px 16px; border: 1px solid var(--border); border-radius: var(--radius); background: var(--surface); }
.row-card h3 { margin: 0; font-size: 16px; }
.row-card p { margin: 4px 0 0; color: var(--muted); font-size: 13px; overflow-wrap: anywhere; }
.row-meta { display: flex; align-items: center; flex-wrap: wrap; justify-content: flex-end; gap: 8px; }
.switch { position: relative; width: 46px; height: 28px; display: inline-flex; }
.switch input { position: absolute; opacity: 0; width: 1px; height: 1px; }
.switch span { width: 46px; height: 28px; border-radius: 999px; background: #aeb8b2; transition: background-color 160ms ease; }
.switch span::after { content: ''; position: absolute; top: 4px; left: 4px; width: 20px; height: 20px; border-radius: 50%; background: #fff; box-shadow: 0 1px 3px rgba(0,0,0,.2); transition: transform 160ms ease; }
.switch input:checked + span { background: var(--success); }
.switch input:checked + span::after { transform: translateX(18px); }
.switch input:focus-visible + span { outline: 3px solid rgba(163, 61, 45, .28); outline-offset: 2px; }
.trace { display: flex; align-items: center; flex-wrap: wrap; gap: 6px; color: var(--muted); font-size: 13px; }
.trace b { color: var(--fg); font-weight: 600; }
.trace i { width: 18px; height: 1px; background: var(--border); }
.note { padding: 13px 15px; border-left: 3px solid var(--warning); background: #f5eee0; color: #64491d; font-size: 13px; }
.note.spaced { margin-top: 16px; }
.short-field { max-width: 240px; }
.toast { position: fixed; z-index: 100; right: 20px; bottom: 20px; max-width: min(420px, calc(100vw - 40px)); padding: 12px 16px; border-radius: var(--radius); background: #17241e; color: #fff; box-shadow: var(--shadow); opacity: 0; transform: translateY(10px); pointer-events: none; transition: opacity 180ms ease, transform 180ms ease; }
.toast.show { opacity: 1; transform: none; }
.toast.error { background: #7f2730; }
.modal { width: min(620px, calc(100% - 32px)); max-height: calc(100vh - 32px); border: 0; border-radius: 12px; padding: 0; background: var(--surface); color: var(--fg); box-shadow: var(--shadow); }
.modal::backdrop { background: rgba(18, 31, 25, .58); }
.modal-body { padding: 24px; }
.modal-head { display: flex; justify-content: space-between; gap: 16px; margin-bottom: 20px; }
.modal-head h2 { margin: 0; font-size: 22px; }
.modal-head p { margin: 5px 0 0; color: var(--muted); }
.modal-close { min-width: 44px; height: 44px; border: 1px solid var(--border); border-radius: var(--radius); background: var(--surface); }

@media (max-width: 1180px) {
  .metric-grid { grid-template-columns: repeat(3, 1fr); }
  .metric-grid.four { grid-template-columns: repeat(2, 1fr); }
  .metric:nth-child(3) { border-right: 0; }
  .metric:nth-child(-n+3) { border-bottom: 1px solid var(--border); }
  .content-grid { grid-template-columns: 1fr; }
}
@media (max-width: 900px) {
  .auth-screen { grid-template-columns: 1fr; }
  .auth-story { min-height: 360px; padding: 28px 32px; }
  .auth-copy { margin-top: 62px; }
  .auth-copy h1 { font-size: clamp(38px, 10vw, 60px); }
  .trace-demo { margin-top: 40px; }
  .auth-panel { padding: 36px 24px; }
  .app-shell { grid-template-columns: 1fr; grid-template-rows: 60px minmax(0, 1fr); }
  .sidebar { position: fixed; left: 0; transform: translateX(-100%); width: 248px; transition: transform 180ms ease; box-shadow: var(--shadow); }
  .sidebar.open { transform: none; }
  .topbar { padding: 0 20px; }
  .menu-button { display: inline-flex; align-items: center; padding: 0 12px; }
  .account-filter { min-width: 0; flex: 1; display: block; }
  .account-filter span { display: none; }
  .system-state { display: none; }
  .workspace { padding: 24px 20px 36px; }
}
@media (max-width: 620px) {
  .auth-story { min-height: 330px; padding: 24px 20px; }
  .auth-copy { margin-top: 52px; }
  .auth-copy > p:last-child { font-size: 15px; margin-top: 18px; }
  .trace-demo { grid-template-columns: 1fr; gap: 8px; margin-top: 28px; padding-top: 16px; }
  .trace-demo div:nth-of-type(n+2), .trace-demo i { display: none; }
  .auth-panel { padding: 32px 20px; }
  .workspace { padding-inline: 16px; }
  .page-head { display: grid; }
  .page-head h1 { font-size: 25px; }
  .actions { width: 100%; }
  .actions .btn { flex: 1; }
  .metric-grid { grid-template-columns: repeat(2, 1fr); }
  .metric-grid.four { grid-template-columns: repeat(2, 1fr); }
  .metric:nth-child(n) { border-right: 1px solid var(--border); border-bottom: 1px solid var(--border); }
  .metric:nth-child(2n) { border-right: 0; }
  .metric:nth-last-child(-n+2) { border-bottom: 0; }
  .form-grid { grid-template-columns: 1fr; }
  .form-grid .full { grid-column: auto; }
  .row-card { grid-template-columns: 1fr; }
  .row-meta { justify-content: flex-start; }
  th, td { padding: 10px; }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { scroll-behavior: auto !important; transition-duration: .01ms !important; animation-duration: .01ms !important; }
}
