:root {
  --green: #149a45;
  --green-dark: #0f7a36;
  --green-deep: #0b3d1e;
  --green-soft: #e9f7ee;
  --bg: #f3f5f7;
  --surface: #ffffff;
  --line: #e6eaee;
  --line-strong: #d5dbe1;
  --text: #1c2430;
  --muted: #5c6773;
  --dim: #8b949e;
  --red: #c81e1e;
  --red-soft: #fdecec;
  --yellow: #c2410c;
  --yellow-soft: #fff4e5;
  --blue: #1d4ed8;
  --blue-soft: #e8eefc;
  --font: 'Inter', ui-sans-serif, system-ui, sans-serif;
  --mono: ui-monospace, 'SFMono-Regular', Menlo, Consolas, monospace;
  --topbar-h: 56px;
  --sidebar-w: 236px;
  --shadow: 0 1px 2px rgba(16, 24, 40, .05), 0 0 0 1px rgba(16, 24, 40, .03);
  --shadow-md: 0 8px 24px rgba(16, 24, 40, .08);
  --radius: 10px;
  --radius-sm: 7px;
}

*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html, body { height: 100%; }
html { overflow-x: hidden; }
body {
  font-family: var(--font); background: var(--bg); color: var(--text);
  -webkit-font-smoothing: antialiased; letter-spacing: -.01em;
  overflow-x: hidden;
}
button, input, select, textarea { font-family: inherit; }

.auth-screen {
  min-height: 100vh; display: grid; grid-template-columns: minmax(280px, 42%) 1fr;
  background: var(--bg);
}
.auth-aside {
  background: linear-gradient(165deg, #0d3a1c 0%, #149a45 72%, #1db954 100%);
  color: #fff; padding: 48px 40px; display: flex; flex-direction: column; justify-content: space-between;
}
.auth-aside-mark {
  width: 44px; height: 44px; border-radius: 12px; background: rgba(255,255,255,.14);
  display: grid; place-items: center; font-weight: 700; letter-spacing: .04em; margin-bottom: 28px;
}
.auth-aside h2 { font-size: 28px; font-weight: 650; letter-spacing: -.03em; line-height: 1.2; max-width: 16ch; }
.auth-aside p { margin-top: 12px; font-size: 15px; line-height: 1.55; color: rgba(255,255,255,.78); max-width: 32ch; }
.auth-aside-foot { font-size: 12px; letter-spacing: .08em; text-transform: uppercase; color: rgba(255,255,255,.55); font-weight: 600; }
.auth-main { display: flex; align-items: center; justify-content: center; padding: 40px 24px; }
.auth-card {
  background: var(--surface); border: 1px solid var(--line); border-radius: 16px;
  box-shadow: var(--shadow-md); padding: 36px 32px; width: 100%; max-width: 400px;
}
.auth-logo { margin-bottom: 8px; }
.auth-logo .brand { font-size: 13px; font-weight: 650; letter-spacing: .12em; text-transform: uppercase; color: var(--green); }
.auth-title { font-size: 26px; font-weight: 650; letter-spacing: -.03em; margin: 8px 0 6px; }
.auth-sub { font-size: 14px; color: var(--muted); margin-bottom: 24px; line-height: 1.45; }
.form-group { margin-bottom: 14px; }
.form-group label { display: block; font-size: 12px; font-weight: 650; color: var(--muted); margin-bottom: 6px; letter-spacing: .04em; text-transform: uppercase; }
.form-group input, .filter-input, select.filter-input {
  width: 100%; background: #fff; border: 1px solid var(--line-strong); border-radius: var(--radius-sm);
  padding: 10px 12px; color: var(--text); font-size: 14px; outline: none; transition: border-color .15s, box-shadow .15s;
}
.form-group input:focus, .filter-input:focus, select.filter-input:focus {
  border-color: var(--green); box-shadow: 0 0 0 3px rgba(20, 154, 69, .16);
}
.btn { width: 100%; padding: 11px 14px; border-radius: var(--radius-sm); border: none; font-size: 14px; font-weight: 650; cursor: pointer; }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn-accent { background: var(--green); color: #fff; }
.btn-accent:hover:not(:disabled) { background: var(--green-dark); }
.auth-error { background: var(--red-soft); border: 1px solid #f3c1c1; border-radius: var(--radius-sm); padding: 10px 12px; font-size: 13px; color: var(--red); margin-bottom: 14px; display: none; }
.auth-error.show { display: block; }

.shell { min-height: 100vh; }
.topbar {
  position: fixed; top: 0; left: 0; right: 0; height: var(--topbar-h); z-index: 40;
  background: #fff; border-bottom: 1px solid var(--line);
  display: flex; align-items: center; justify-content: space-between;
  padding-left: max(16px, env(safe-area-inset-left));
  padding-right: max(18px, env(safe-area-inset-right));
}
.topbar-left { display: flex; align-items: center; gap: 10px; min-width: 0; }
.nav-toggle {
  display: none; width: 40px; height: 40px; padding: 10px 9px;
  border: 1px solid var(--line); border-radius: var(--radius-sm);
  background: #fff; cursor: pointer; flex-direction: column; justify-content: space-between;
}
.nav-toggle span { display: block; height: 2px; width: 100%; background: var(--text); border-radius: 2px; }
.nav-scrim { display: none; position: fixed; inset: 0; z-index: 28; background: rgba(28, 36, 48, .4); }
.topbar-brand {
  display: flex; align-items: center; gap: 10px;
  font-size: 15px; font-weight: 650; letter-spacing: -.01em; color: var(--text);
  min-width: 0;
}
.brand-mark {
  width: 28px; height: 28px; border-radius: 8px; background: var(--green);
  color: #fff; display: grid; place-items: center; font-size: 11px; font-weight: 700; letter-spacing: .04em;
}
.topbar-right { display: flex; align-items: center; gap: 10px; }
.topbar-user { font-size: 13px; color: var(--muted); font-weight: 500; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 28ch; }
.user-avatar {
  width: 32px; height: 32px; border-radius: 50%; background: var(--green-soft);
  display: flex; align-items: center; justify-content: center;
  font-size: 12px; font-weight: 700; color: var(--green-dark); flex-shrink: 0;
}
.sign-out {
  font-size: 13px; font-weight: 600; color: var(--muted); cursor: pointer;
  border: 1px solid var(--line); border-radius: var(--radius-sm); padding: 6px 11px; background: #fff;
  font-family: inherit; line-height: 1; flex-shrink: 0;
}
.sign-out:hover { color: var(--red); border-color: #f3c1c1; background: var(--red-soft); }

.sidebar {
  position: fixed; top: var(--topbar-h); left: 0; bottom: 0; width: var(--sidebar-w);
  background: #fbfcfd; border-right: 1px solid var(--line);
  overflow-y: auto; padding: 14px 10px 24px; z-index: 30;
}
.sidebar-nav { display: flex; flex-direction: column; gap: 14px; }
.sidebar-section-label {
  font-size: 11px; font-weight: 700; letter-spacing: .1em; text-transform: uppercase;
  color: var(--dim); padding: 0 10px 6px;
}
.nav-item {
  display: flex; align-items: center; gap: 10px;
  padding: 8px 10px; border-radius: 8px; cursor: pointer;
  font-size: 14px; font-weight: 500; color: #3d4752;
  transition: background .12s, color .12s;
}
.nav-item:hover { background: #eef3f0; color: var(--text); }
.nav-item.active { background: var(--green-soft); color: var(--green-dark); font-weight: 650; }
.nav-ico { width: 18px; height: 18px; display: grid; place-items: center; flex-shrink: 0; opacity: .85; }
.nav-ico svg { width: 18px; height: 18px; display: block; }
.nav-item.active .nav-ico { opacity: 1; }
.tenant-pick { padding: 0 10px 10px; }
.tenant-pick .filter-input { width: 100%; }

.main {
  margin-left: var(--sidebar-w); margin-top: var(--topbar-h);
  padding: 28px 32px 48px; min-height: calc(100vh - var(--topbar-h));
  max-width: 1240px; min-width: 0;
}

.page-header { margin-bottom: 22px; }
.page-kicker {
  font-size: 11px; font-weight: 700; letter-spacing: .12em; text-transform: uppercase;
  color: var(--green); margin-bottom: 6px;
}
.page-title { font-size: clamp(22px, 3vw, 26px); font-weight: 650; letter-spacing: -.03em; color: var(--text); }
.page-sub { font-size: 14px; color: var(--muted); margin-top: 4px; line-height: 1.45; }

.stats-row { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 12px; margin-bottom: 16px; }
.stats-row-wide { grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); }
.panel-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; margin-bottom: 14px; }
.panel-grid .card { margin-top: 0; }
.stat-card { background: var(--surface); border-radius: var(--radius); box-shadow: var(--shadow); padding: 16px 18px; }
.stat-label { font-size: 11px; color: var(--muted); margin-bottom: 8px; font-weight: 650; text-transform: uppercase; letter-spacing: .08em; }
.stat-val { font-size: 28px; font-weight: 650; letter-spacing: -.03em; color: var(--text); }
.stat-val.green { color: var(--green); }
.stat-val.red { color: var(--red); }
.stat-val.dim { color: var(--dim); font-weight: 550; }

.farm-hero {
  display: flex; align-items: flex-end; justify-content: space-between; gap: 20px;
  margin-bottom: 22px; padding-bottom: 22px; border-bottom: 1px solid var(--line);
}
.farm-hero-title { font-size: clamp(28px, 3.4vw, 36px); font-weight: 650; letter-spacing: -.04em; line-height: 1.1; }
.farm-hero-sub { font-size: 15px; color: var(--muted); margin-top: 8px; line-height: 1.45; }
.farm-hero-sub strong { color: var(--text); font-weight: 650; }
.farm-hero-actions { display: flex; gap: 8px; flex-shrink: 0; }
.farm-hero-actions .btn-sm { width: auto; }

.cycle-rail {
  display: flex; align-items: stretch; gap: 0;
  background: var(--surface); border-radius: 14px; box-shadow: var(--shadow);
  padding: 8px; margin-bottom: 16px; overflow-x: auto;
}
.cycle-node {
  flex: 1 1 0; min-width: 132px; border: 0; background: transparent;
  display: flex; flex-direction: column; align-items: flex-start; gap: 6px;
  padding: 14px 14px 16px; border-radius: 10px; cursor: pointer; text-align: left;
  font-family: inherit; color: inherit;
}
.cycle-node:hover { background: #f6faf7; }
.cycle-n {
  font-size: 10px; font-weight: 700; letter-spacing: .14em; text-transform: uppercase; color: var(--green);
}
.cycle-t { font-size: 14px; font-weight: 650; letter-spacing: -.02em; }
.cycle-s { font-size: 12px; color: var(--dim); line-height: 1.35; }
.cycle-ico {
  width: 36px; height: 36px; border-radius: 10px; background: var(--green-soft); color: var(--green-dark);
  display: grid; place-items: center; margin-bottom: 4px;
}
.cycle-ico svg { width: 18px; height: 18px; display: block; }
.cycle-join {
  width: 12px; flex-shrink: 0; align-self: center; height: 1px;
  background: linear-gradient(90deg, var(--line) 0%, var(--green) 100%); opacity: .7;
}

.kpi-row { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 12px; margin-bottom: 16px; }
.kpi {
  background: var(--surface); border: 0; border-radius: var(--radius); box-shadow: var(--shadow);
  padding: 16px 18px; text-align: left; cursor: pointer; font-family: inherit; color: inherit;
  box-shadow: var(--shadow), inset 3px 0 0 var(--line);
}
.kpi:hover { transform: translateY(-1px); }
.kpi-ok { box-shadow: var(--shadow), inset 3px 0 0 var(--green); }
.kpi-risk { box-shadow: var(--shadow), inset 3px 0 0 var(--red); }
.kpi-warn { box-shadow: var(--shadow), inset 3px 0 0 #eab308; }
.kpi-mute { box-shadow: var(--shadow), inset 3px 0 0 var(--line-strong); }
.kpi-label { font-size: 11px; font-weight: 700; letter-spacing: .08em; text-transform: uppercase; color: var(--muted); }
.kpi-val { font-size: 28px; font-weight: 650; letter-spacing: -.03em; margin: 6px 0 4px; }
.kpi-risk .kpi-val { color: var(--red); }
.kpi-ok .kpi-val { color: var(--green-dark); }
.kpi-hint { font-size: 12px; color: var(--dim); line-height: 1.35; }

.next-row {
  width: 100%; display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 14px 16px; border: 0; border-bottom: 1px solid var(--line); background: transparent;
  text-align: left; cursor: pointer; font-family: inherit; color: inherit;
}
.next-row:last-child { border-bottom: none; }
.next-row:hover { background: #f8fbf9; }
.next-go { font-size: 12px; font-weight: 650; color: var(--green); flex-shrink: 0; }
.empty-hero { text-align: center; padding: 28px 18px; }
.empty-hero h3 { font-size: 16px; font-weight: 650; margin-bottom: 8px; }
.empty-hero p { font-size: 14px; color: var(--muted); max-width: 36ch; margin: 0 auto 16px; line-height: 1.5; }

.card { background: var(--surface); border-radius: var(--radius); box-shadow: var(--shadow); overflow: hidden; max-width: 100%; }
.card + .card { margin-top: 14px; }
.card-header {
  padding: 14px 16px; border-bottom: 1px solid var(--line);
  display: flex; align-items: center; justify-content: space-between; gap: 10px; min-width: 0;
}
.card-title { font-size: 14px; font-weight: 650; color: var(--text); min-width: 0; }
.card-link { font-size: 13px; font-weight: 650; color: var(--green); cursor: pointer; }
table { width: 100%; border-collapse: collapse; }
th {
  font-size: 11px; font-weight: 700; text-transform: uppercase; letter-spacing: .06em;
  color: var(--dim); padding: 10px 16px; text-align: left; border-bottom: 1px solid var(--line); background: #fafbfc;
}
td { font-size: 14px; padding: 11px 16px; border-bottom: 1px solid var(--line); vertical-align: middle; }
tr:last-child td { border-bottom: none; }
tr:hover td { background: #f8fbf9; }
code { font-size: 12px; font-family: var(--mono); color: var(--muted); }

.badge { display: inline-flex; align-items: center; padding: 3px 9px; border-radius: 999px; font-size: 12px; font-weight: 650; }
.badge-green { background: var(--green-soft); color: var(--green-dark); }
.badge-red { background: var(--red-soft); color: var(--red); }
.badge-yellow { background: var(--yellow-soft); color: var(--yellow); }
.badge-gray { background: #eef1f4; color: var(--muted); }
.badge-blue { background: var(--blue-soft); color: var(--blue); }

.chip { display: inline-flex; align-items: center; padding: 4px 10px; border-radius: 999px; background: var(--green-soft); color: var(--green-dark); font-size: 12px; font-weight: 600; }
.chip-row { display: flex; flex-wrap: wrap; gap: 6px; padding: 14px 16px; }
.kv-row, .ops-row {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 12px 16px; border-bottom: 1px solid var(--line);
}
.kv-row:last-child, .ops-row:last-child { border-bottom: none; }
.feature-name { font-size: 14px; font-weight: 650; }
.feature-desc { font-size: 12px; color: var(--dim); margin-top: 2px; line-height: 1.4; }
.stack-body { padding: 4px 0; }

.desk-table { overflow-x: auto; -webkit-overflow-scrolling: touch; max-width: 100%; }
.desk-table table { min-width: 640px; }
.mob-list { display: none; }
.mob-item {
  display: flex; align-items: flex-start; gap: 12px; width: 100%; text-align: left;
  background: transparent; border: 0; border-bottom: 1px solid var(--line);
  padding: 14px 16px; color: inherit; font-family: inherit;
}
.mob-item:last-child { border-bottom: none; }
.mob-item-main { flex: 1; min-width: 0; }
.mob-item-tags { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 8px; }
.client-who-name { font-size: 14px; font-weight: 650; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.client-who-id { font-size: 12px; color: var(--dim); margin-top: 2px; font-family: var(--mono); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.main.chat-mode { padding: 0; max-width: none; min-height: calc(100vh - var(--topbar-h)); }
.chat-stage {
  height: calc(100vh - var(--topbar-h));
  display: flex; flex-direction: column; background: #f7f8f9;
}
.chat-top {
  flex-shrink: 0; height: 52px; padding: 0 24px;
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  background: #fff; border-bottom: 1px solid var(--line);
}
.chat-top-id { display: flex; align-items: center; gap: 10px; min-width: 0; }
.chat-top-name { font-size: 14px; font-weight: 650; letter-spacing: -.02em; }
.chat-top-place { font-size: 12px; color: var(--dim); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.chat-live { width: 7px; height: 7px; border-radius: 50%; background: var(--green); box-shadow: 0 0 0 3px rgba(20,154,69,.16); flex-shrink: 0; }
.chat-thread {
  flex: 1; overflow-y: auto; padding: 28px 24px 12px;
}
.chat-col { max-width: 720px; margin: 0 auto; display: flex; flex-direction: column; gap: 22px; min-height: 100%; }
.chat-empty {
  margin: auto; text-align: center; padding: 48px 16px 32px;
}
.chat-empty-mark {
  width: 44px; height: 44px; border-radius: 14px; margin: 0 auto 18px;
  background: var(--green); color: #fff; display: grid; place-items: center;
  font-size: 12px; font-weight: 700; letter-spacing: .08em;
}
.chat-empty h2 { font-size: 22px; font-weight: 650; letter-spacing: -.03em; margin-bottom: 8px; }
.chat-empty p { font-size: 14px; color: var(--muted); margin-bottom: 22px; }
.chat-hints { display: flex; flex-wrap: wrap; justify-content: center; gap: 8px; }
.chat-hints button {
  background: #fff; border: 1px solid var(--line); border-radius: 999px;
  padding: 8px 14px; font-size: 13px; font-weight: 550; color: var(--text); cursor: pointer;
}
.chat-hints button:hover { border-color: var(--green); color: var(--green-dark); }
.msg { display: flex; gap: 12px; align-items: flex-start; max-width: 100%; }
.msg.user { flex-direction: row-reverse; }
.msg-ava {
  width: 28px; height: 28px; border-radius: 9px; flex-shrink: 0; margin-top: 2px;
  display: grid; place-items: center; font-size: 9px; font-weight: 700; letter-spacing: .04em;
}
.msg.assistant .msg-ava { background: var(--green); color: #fff; }
.msg.user .msg-ava { background: var(--green-soft); color: var(--green-dark); }
.msg-body { min-width: 0; max-width: min(640px, 100%); }
.msg-bubble { font-size: 15px; line-height: 1.65; color: var(--text); letter-spacing: -.01em; }
.msg.user .msg-bubble {
  background: #fff; border: 1px solid var(--line); border-radius: 16px 16px 6px 16px;
  padding: 12px 16px; box-shadow: var(--shadow);
}
.msg.assistant .msg-bubble { padding: 4px 2px 0; }
.chat-typing { display: flex; gap: 5px; padding: 10px 2px; }
.chat-typing span {
  width: 6px; height: 6px; border-radius: 50%; background: var(--dim);
  animation: chat-dot 1.1s ease-in-out infinite;
}
.chat-typing span:nth-child(2) { animation-delay: .15s; }
.chat-typing span:nth-child(3) { animation-delay: .3s; }
@keyframes chat-dot { 0%, 80%, 100% { opacity: .25; transform: translateY(0); } 40% { opacity: 1; transform: translateY(-3px); } }
.chat-stream-status {
  font-size: 12px; color: var(--dim); margin-bottom: 6px; letter-spacing: -.01em;
}
.chat-dock {
  flex-shrink: 0; padding: 8px 24px 22px;
  background: linear-gradient(180deg, rgba(247,248,249,0) 0%, #f7f8f9 28%);
}
.chat-composer {
  max-width: 720px; margin: 0 auto;
  display: flex; align-items: flex-end; gap: 6px;
  background: #fff; border: 1px solid var(--line-strong); border-radius: 16px;
  padding: 8px; box-shadow: var(--shadow-md);
}
.chat-idle {
  display: flex; align-items: flex-end; gap: 6px; flex: 1; min-width: 0;
}
.chat-tool {
  width: 40px; height: 40px; border: 0; border-radius: 12px; flex-shrink: 0;
  background: transparent; color: var(--muted); cursor: pointer; display: grid; place-items: center;
}
.chat-tool svg { width: 18px; height: 18px; display: block; }
.chat-tool:hover { background: var(--green-soft); color: var(--green-dark); }
.chat-pending { max-width: 720px; margin: 0 auto 8px; }
.pending-chip {
  display: flex; align-items: center; justify-content: space-between; gap: 10px;
  background: #fff; border: 1px solid var(--line); border-radius: 12px;
  padding: 8px 8px 8px 14px; box-shadow: var(--shadow);
}
.pending-name { font-size: 13px; font-weight: 650; }
.pending-meta { font-size: 12px; color: var(--dim); margin-top: 2px; }
.chat-dock-note {
  max-width: 720px; margin: 8px auto 0; font-size: 12px; color: var(--dim); line-height: 1.4; padding: 0 4px;
}
.chat-composer:focus-within:not(.is-voice) { border-color: var(--green); box-shadow: 0 0 0 3px rgba(20,154,69,.14), var(--shadow-md); }
.chat-textarea {
  flex: 1; border: 0; background: transparent; resize: none; outline: none;
  min-height: 40px; max-height: 140px; padding: 10px 0; font-size: 15px; line-height: 1.45; color: var(--text);
}
.chat-send {
  width: 40px; height: 40px; border: 0; border-radius: 12px; flex-shrink: 0;
  background: var(--green); color: #fff; cursor: pointer; display: grid; place-items: center;
}
.chat-send svg { width: 18px; height: 18px; }
.chat-send:hover { background: var(--green-dark); }
.chat-send:disabled { opacity: .35; cursor: default; }
.chat-composer.is-voice {
  align-items: center;
  background: #1c2430;
  border-color: #1c2430;
  border-radius: 28px;
  padding: 8px 8px 8px 8px;
  box-shadow: 0 10px 28px rgba(16, 24, 40, .22);
}
.chat-composer.is-voice .chat-idle { display: none; }
.chat-voice {
  display: none; flex: 1; align-items: center; gap: 10px; min-width: 0; padding: 2px 2px;
}
.chat-composer.is-voice .chat-voice { display: flex; }
.voice-btn {
  width: 40px; height: 40px; border: 0; border-radius: 50%; flex-shrink: 0;
  cursor: pointer; display: grid; place-items: center;
}
.voice-btn svg { width: 16px; height: 16px; display: block; }
.voice-cancel { background: rgba(255,255,255,.12); color: #fff; }
.voice-cancel:hover { background: rgba(255,255,255,.2); }
.voice-stop { background: #fff; color: #1c2430; }
.voice-stop:hover { background: #e8eaed; }
.voice-wave {
  flex: 1; height: 36px; display: flex; align-items: center; justify-content: center;
  gap: 2.5px; min-width: 0; overflow: hidden;
}
.voice-bar {
  width: 3px; height: 4px; border-radius: 99px; background: #fff; opacity: .92;
  transition: height .08s ease-out;
}
.voice-time {
  color: #fff; font-size: 14px; font-weight: 550; letter-spacing: .02em;
  font-variant-numeric: tabular-nums; min-width: 42px; text-align: right;
}

.page-loader {
  min-height: calc(100vh - var(--topbar-h) - 56px);
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 22px;
}
.loader { width: 88px; height: 88px; position: relative; filter: drop-shadow(0 10px 24px rgba(20, 154, 69, .18)); }
.loader-ring {
  position: absolute; inset: 0; border-radius: 50%;
  border: 2.5px solid rgba(20, 154, 69, .12); border-top-color: var(--green); border-right-color: rgba(20, 154, 69, .45);
  animation: loader-spin 1.05s cubic-bezier(.55, .15, .45, .85) infinite;
}
.loader-ring-inner { inset: 12px; border-top-color: var(--green-dark); border-right-color: transparent; animation-duration: 1.7s; animation-direction: reverse; }
.loader-core {
  position: absolute; inset: 22px; border-radius: 50%; background: #fff; color: var(--green-dark);
  display: grid; place-items: center; font-size: 13px; font-weight: 700; letter-spacing: .1em;
  box-shadow: inset 0 0 0 1px rgba(20, 154, 69, .12);
}
.loader-label { font-size: 11px; font-weight: 700; letter-spacing: .16em; text-transform: uppercase; color: var(--muted); }
.empty { text-align: center; padding: 28px 16px; color: var(--dim); font-size: 14px; }
.loading { text-align: center; padding: 48px 16px; color: var(--muted); font-size: 14px; }

.action-btn, .btn-sm {
  background: #fff; border: 1px solid var(--line-strong); border-radius: var(--radius-sm);
  color: var(--muted); padding: 7px 12px; font-size: 13px; font-weight: 600; cursor: pointer; white-space: nowrap;
}
.action-btn:hover, .btn-sm:hover { border-color: var(--green); color: var(--green-dark); }
.btn-sm-accent { background: var(--green); border-color: var(--green); color: #fff; }
.btn-sm-accent:hover { background: var(--green-dark); color: #fff; border-color: var(--green-dark); }
.header-actions { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.stat-card.clickable, .row-link { cursor: pointer; }
.prose { font-size: 14px; line-height: 1.6; color: var(--text); padding: 14px 16px; white-space: pre-wrap; }
.step-list { padding: 4px 0; }
.step-item { padding: 14px 16px; border-bottom: 1px solid var(--line); }
.step-item:last-child { border-bottom: none; }
.step-n { font-size: 11px; font-weight: 700; letter-spacing: .08em; text-transform: uppercase; color: var(--green); }
.msg-meta { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 8px; }
.msg-chip {
  font-size: 11px; font-weight: 650; letter-spacing: .04em; text-transform: uppercase;
  padding: 3px 8px; border-radius: 999px; background: #eef1f4; color: var(--muted);
}
.msg-chip.src { background: var(--green-soft); color: var(--green-dark); }
.msg-chip.global { background: var(--blue-soft); color: var(--blue); }
a.msg-chip.cite {
  text-decoration: none; background: var(--blue-soft); color: var(--blue);
}
a.msg-chip.cite:hover { text-decoration: underline; }
.msg-chip.miss { background: var(--yellow-soft); color: var(--yellow); }
.toast-host {
  position: fixed; top: 16px; right: 16px; z-index: 90; display: flex; flex-direction: column; gap: 8px;
  pointer-events: none; max-width: min(360px, calc(100vw - 24px));
}
.toast {
  pointer-events: auto; background: #fff; border-radius: var(--radius); box-shadow: var(--shadow-md);
  padding: 12px 36px 12px 14px; position: relative;
}
.toast-ok { box-shadow: var(--shadow-md), inset 3px 0 0 var(--green); }
.toast-err { box-shadow: var(--shadow-md), inset 3px 0 0 var(--red); }
.toast-title { font-size: 13px; font-weight: 650; }
.toast-body { font-size: 12px; color: var(--muted); margin-top: 3px; }
.toast-close {
  position: absolute; top: 8px; right: 8px; border: 0; background: transparent; color: var(--dim); cursor: pointer; font-size: 16px;
}
.dialog-host { position: relative; z-index: 80; }
.dialog-backdrop {
  position: fixed; inset: 0; z-index: 80; background: rgba(28, 36, 48, .36);
  display: grid; place-items: center; padding: 24px;
}
.dialog {
  width: min(480px, 100%); background: var(--surface); border-radius: var(--radius);
  box-shadow: var(--shadow-md); overflow: hidden;
}
.dialog-header {
  padding: 14px 16px; border-bottom: 1px solid var(--line);
  display: flex; align-items: center; justify-content: space-between; gap: 10px;
}
.dialog-kicker { font-size: 11px; font-weight: 700; letter-spacing: .12em; text-transform: uppercase; color: var(--green); }
.dialog-title { font-size: 15px; font-weight: 650; }
.dialog-x {
  width: 28px; height: 28px; border: 1px solid var(--line); border-radius: var(--radius-sm);
  background: #fff; color: var(--muted); cursor: pointer; font-size: 18px; line-height: 1;
}
.dialog-content { padding: 16px 16px 4px; }
.dialog-body { font-size: 14px; color: var(--muted); line-height: 1.45; margin: 0; }
.dialog-fields { margin-top: 12px; display: grid; gap: 12px; }
.dialog-fields textarea.filter-input { min-height: 96px; resize: vertical; }
.dialog-actions {
  display: flex; justify-content: flex-end; gap: 8px;
  margin-top: 16px; padding: 14px 16px; border-top: 1px solid var(--line);
}

@keyframes loader-spin { to { transform: rotate(360deg); } }

@media (max-width: 1080px) {
  .nav-toggle { display: flex; }
  .nav-scrim { display: block; opacity: 0; pointer-events: none; transition: opacity .18s; }
  .shell.nav-open .nav-scrim { opacity: 1; pointer-events: auto; }
  .sidebar { transform: translateX(-110%); transition: transform .2s ease; }
  .shell.nav-open .sidebar { transform: none; box-shadow: 16px 0 40px rgba(16, 24, 40, .18); }
  .main { margin-left: 0; padding: 22px 20px 40px; }
  .main.chat-mode { padding: 0; }
  .auth-screen { grid-template-columns: 1fr; }
  .auth-aside { display: none; }
  .panel-grid { grid-template-columns: 1fr; }
  .stats-row { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .kpi-row { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .farm-hero { flex-direction: column; align-items: flex-start; }
  .farm-hero-actions { width: 100%; }
  .farm-hero-actions .btn-sm { flex: 1; text-align: center; }
}
@media (max-width: 880px) {
  .desk-table { display: none !important; }
  .mob-list { display: block; }
}
@media (max-width: 720px) {
  .topbar-user { display: none; }
  .topbar-brand-text { display: none; }
  .main { padding: 16px 14px 36px; padding-bottom: max(36px, env(safe-area-inset-bottom)); }
  .stats-row, .stats-row-wide, .kpi-row { grid-template-columns: 1fr 1fr; gap: 8px; }
  .stat-val { font-size: 22px; }
  .main.chat-mode { padding: 0; }
  .chat-top, .chat-thread, .chat-dock { padding-left: 14px; padding-right: 14px; }
  .chat-stage { height: calc(100vh - var(--topbar-h)); }
}
