:root {
  color-scheme: dark;
  --bg: #071017;
  --panel: rgba(16, 28, 37, 0.88);
  --panel-strong: #101c25;
  --panel-soft: #14232d;
  --border: rgba(148, 175, 188, 0.16);
  --border-strong: rgba(148, 175, 188, 0.28);
  --text: #eef7f7;
  --muted: #86a0ad;
  --aqua: #68f5d0;
  --aqua-dark: #183f39;
  --blue: #6a9cff;
  --amber: #f3c56b;
  --red: #ff7d78;
  --green: #6be0a8;
  --radius: 18px;
  font-family: Inter, ui-sans-serif, -apple-system, BlinkMacSystemFont, "Segoe UI", "Microsoft YaHei", sans-serif;
}

* { box-sizing: border-box; }
body { margin: 0; min-width: 320px; min-height: 100vh; background: var(--bg); color: var(--text); font-size: 16px; }
button, input, textarea, select { font: inherit; }
button { color: inherit; }
.hidden { display: none !important; }

.ambient { position: fixed; pointer-events: none; filter: blur(100px); opacity: .12; border-radius: 999px; }
.ambient-a { width: 420px; height: 420px; background: var(--aqua); top: -180px; right: 10%; }
.ambient-b { width: 380px; height: 380px; background: #2168ff; bottom: -220px; left: 8%; }

.login-gate { min-height: 100vh; display: grid; place-items: center; padding: 24px; }
.login-card { width: min(430px, 100%); padding: 42px; border: 1px solid var(--border-strong); border-radius: 26px; background: rgba(11, 21, 28, .94); box-shadow: 0 30px 90px rgba(0,0,0,.38); backdrop-filter: blur(18px); }
.brand-mark { width: 54px; height: 54px; display: grid; place-items: center; border-radius: 16px; background: var(--aqua); color: #06241f; font-size: 25px; font-weight: 900; margin-bottom: 26px; box-shadow: 0 0 38px rgba(104,245,208,.18); }
.brand-mark.small { width: 39px; height: 39px; border-radius: 12px; font-size: 18px; margin: 0; }
.login-card h1 { margin: 6px 0 10px; font-size: 28px; letter-spacing: -.03em; }
.muted, .helper { color: var(--muted); line-height: 1.7; }
.login-card .muted { margin-bottom: 28px; }
.form-error { min-height: 22px; color: var(--red); margin: 12px 0 0; font-size: 14px; }

.shell { min-height: 100vh; display: grid; grid-template-columns: 248px minmax(0, 1fr); }
.sidebar { position: sticky; top: 0; height: 100vh; padding: 28px 18px; border-right: 1px solid var(--border); background: rgba(8, 17, 23, .86); backdrop-filter: blur(18px); display: flex; flex-direction: column; overflow-y: auto; z-index: 20; }
.brand { display: flex; gap: 12px; align-items: center; padding: 0 8px 30px; }
.brand strong { display: block; font-size: 17px; letter-spacing: .02em; }
.brand span { display: block; margin-top: 2px; color: var(--muted); font-size: 12px; }
.project-switcher { margin: -13px 5px 17px; padding: 11px; border: 1px solid var(--border); border-radius: 12px; background: rgba(255,255,255,.025); }
.project-switcher label { display: block; margin-bottom: 7px; color: var(--muted); font-size: 11px; letter-spacing: .08em; }
.project-switcher div { display: grid; grid-template-columns: minmax(0,1fr) 34px; gap: 7px; }
.project-switcher select { min-height: 35px; padding: 6px 8px; font-size: 12px; }
.project-switcher button { border: 1px solid var(--border-strong); border-radius: 9px; color: var(--aqua); background: #0a151c; cursor: pointer; font-size: 18px; }
nav { display: grid; gap: 5px; }
nav p { color: #58717d; font-size: 11px; letter-spacing: .14em; margin: 25px 12px 8px; }
.nav-item { width: 100%; min-height: 45px; border: 0; border-radius: 11px; background: transparent; color: #98adb7; text-align: left; padding: 0 13px; cursor: pointer; transition: .18s ease; }
.nav-item span { display: inline-block; width: 29px; color: #506873; font-size: 11px; }
.nav-item:hover { background: rgba(255,255,255,.04); color: var(--text); }
.nav-item.active { color: var(--aqua); background: rgba(104,245,208,.08); box-shadow: inset 2px 0 var(--aqua); }
.nav-item.active span { color: var(--aqua); }
.sidebar-footer { margin-top: auto; padding: 15px 9px 0; border-top: 1px solid var(--border); display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.mode-badge { padding: 7px 9px; border-radius: 8px; color: var(--amber); background: rgba(243,197,107,.08); border: 1px solid rgba(243,197,107,.18); font-size: 12px; }
.mode-badge.real { color: var(--red); background: rgba(255,125,120,.08); border-color: rgba(255,125,120,.2); }

.workspace { width: 100%; max-width: 1580px; padding: 30px 38px 60px; overflow: hidden; }
.topbar { display: flex; align-items: center; justify-content: space-between; margin-bottom: 30px; }
.topbar h1 { margin: 3px 0 0; font-size: clamp(25px, 3vw, 34px); letter-spacing: -.04em; }
.eyebrow { margin: 0; color: var(--aqua); font-size: 11px; font-weight: 700; letter-spacing: .17em; }
.top-actions { display: flex; align-items: center; gap: 10px; }
.status-pill { display: flex; align-items: center; gap: 8px; min-height: 38px; padding: 0 13px; border: 1px solid var(--border); border-radius: 999px; color: var(--muted); font-size: 13px; background: rgba(12,23,30,.75); }
.status-pill i { width: 7px; height: 7px; border-radius: 50%; background: var(--amber); box-shadow: 0 0 10px currentColor; }
.status-pill.connected i { background: var(--green); }
.icon-button, .mobile-menu { width: 39px; height: 39px; border: 1px solid var(--border); border-radius: 11px; background: rgba(12,23,30,.75); cursor: pointer; }
.icon-button:hover, .mobile-menu:hover { border-color: var(--border-strong); background: var(--panel-soft); }
.mobile-menu { display: none; margin-right: 12px; }

.view { display: none; animation: enter .22s ease; }
.view.active { display: block; }
@keyframes enter { from { opacity: 0; transform: translateY(4px); } to { opacity: 1; transform: none; } }
.metric-grid { display: grid; grid-template-columns: 1.25fr repeat(3, 1fr); gap: 14px; margin-bottom: 14px; }
.metric-card, .panel { border: 1px solid var(--border); background: var(--panel); box-shadow: 0 15px 45px rgba(0,0,0,.12); }
.metric-card { min-height: 157px; border-radius: var(--radius); padding: 22px; display: flex; flex-direction: column; justify-content: space-between; }
.metric-card.featured { background: linear-gradient(135deg, rgba(25,69,61,.78), rgba(14,35,35,.9)); border-color: rgba(104,245,208,.25); }
.metric-top { display: flex; align-items: center; justify-content: space-between; color: #adc0c7; font-size: 13px; }
.metric-top b { font-size: 10px; letter-spacing: .12em; color: var(--aqua); }
.metric-top .amber { color: var(--amber); } .metric-top .green { color: var(--green); } .metric-top .red { color: var(--red); }
.metric-card > strong { font-size: clamp(28px, 3.2vw, 43px); letter-spacing: -.05em; font-variant-numeric: tabular-nums; }
.metric-card small { color: var(--muted); font-size: 12px; }

.two-column { display: grid; grid-template-columns: minmax(0, 1.7fr) minmax(310px, .8fr); gap: 14px; margin-bottom: 14px; }
.panel { border-radius: var(--radius); padding: 23px; margin-bottom: 14px; }
.panel-heading { display: flex; justify-content: space-between; align-items: flex-start; gap: 16px; margin-bottom: 22px; }
.panel-heading h2, .note-panel h2 { margin: 5px 0 0; font-size: 18px; letter-spacing: -.02em; }
.live-chip, .config-chip { padding: 6px 9px; border-radius: 999px; border: 1px solid rgba(104,245,208,.18); color: var(--aqua); background: rgba(104,245,208,.07); font-size: 11px; }
.config-chip.off { color: var(--muted); border-color: var(--border); background: transparent; }
.flow-line { display: flex; align-items: center; justify-content: space-between; gap: 10px; padding: 18px 4px 8px; }
.flow-node { min-width: 130px; }
.flow-node b { width: 26px; height: 26px; display: grid; place-items: center; border-radius: 8px; color: var(--aqua); background: rgba(104,245,208,.09); font-size: 11px; margin-bottom: 13px; }
.flow-node strong, .flow-node span { display: block; }
.flow-node strong { font-size: 14px; margin-bottom: 5px; }
.flow-node span { color: var(--muted); font-size: 12px; line-height: 1.45; }
.flow-arrow { color: #3d5964; margin-top: 4px; }
.readiness-list { display: grid; gap: 13px; }
.readiness-item { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding-bottom: 13px; border-bottom: 1px solid var(--border); }
.readiness-item:last-child { border: 0; padding: 0; }
.readiness-item div { display: flex; gap: 10px; align-items: center; }
.readiness-item i { width: 8px; height: 8px; border-radius: 50%; background: var(--red); }
.readiness-item.ready i { background: var(--green); }
.readiness-item strong { font-size: 13px; }
.readiness-item span { color: var(--muted); font-size: 12px; }

.table-wrap { overflow-x: auto; scrollbar-color: #28414b transparent; }
table { width: 100%; border-collapse: collapse; min-width: 760px; }
th { color: #68828e; font-size: 11px; font-weight: 600; letter-spacing: .08em; text-align: left; padding: 0 12px 12px; border-bottom: 1px solid var(--border); }
td { padding: 16px 12px; border-bottom: 1px solid rgba(148,175,188,.09); color: #b8cad1; font-size: 13px; }
tr:last-child td { border-bottom: 0; }
td strong { color: var(--text); font-weight: 600; }
.status-tag { display: inline-flex; padding: 5px 8px; border-radius: 7px; background: rgba(134,160,173,.09); color: #a8bac2; font-size: 11px; white-space: nowrap; }
.status-tag.success { color: var(--green); background: rgba(107,224,168,.08); }
.status-tag.pending, .status-tag.processing { color: var(--amber); background: rgba(243,197,107,.08); }
.status-tag.failed { color: var(--red); background: rgba(255,125,120,.08); }
.status-tag.manual_review { color: #ffb86b; background: rgba(255,184,107,.10); }
.status-tag.partial { color: #ffb86b; background: rgba(255,184,107,.10); }
.empty-table { text-align: center; color: var(--muted); padding: 42px 20px; }

.settings-grid { display: grid; grid-template-columns: minmax(0, 1.35fr) minmax(320px, .65fr); gap: 14px; }
.narrow-panel { max-width: 850px; }
.stack-form { display: grid; gap: 18px; }
label { display: grid; gap: 8px; color: #a9bcc4; font-size: 13px; }
input, textarea, select { width: 100%; min-height: 44px; padding: 10px 13px; color: var(--text); background: #0a151c; border: 1px solid var(--border-strong); border-radius: 10px; outline: none; transition: .15s; }
textarea { resize: vertical; line-height: 1.6; }
input:focus, textarea:focus, select:focus { border-color: rgba(104,245,208,.6); box-shadow: 0 0 0 3px rgba(104,245,208,.08); }
input:disabled { color: #78909a; background: #0d181f; }
.form-row { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
.form-actions { display: flex; justify-content: flex-end; gap: 10px; }
button.primary, button.secondary { min-height: 42px; padding: 0 16px; border-radius: 10px; cursor: pointer; font-weight: 650; font-size: 13px; }
button.primary { border: 1px solid var(--aqua); background: var(--aqua); color: #08241f; }
button.primary:hover { filter: brightness(1.06); box-shadow: 0 9px 28px rgba(104,245,208,.12); }
button.secondary { border: 1px solid var(--border-strong); background: #15232c; color: #c6d5da; }
button:disabled { opacity: .55; cursor: not-allowed; }
.full { width: 100%; }
.align-end { justify-self: end; }
.text-button { padding: 0; border: 0; background: none; color: var(--muted); cursor: pointer; font-size: 12px; }
.text-button:hover { color: var(--aqua); }
.helper { margin: -8px 0 20px; font-size: 13px; }
.note-panel { background: linear-gradient(145deg, rgba(17,44,42,.8), rgba(13,26,34,.9)); }
.note-panel > p:not(.eyebrow) { color: #9db3bb; line-height: 1.75; font-size: 14px; }
.code-note { display: grid; gap: 7px; margin-top: 16px; }
.code-note span { color: #6f8b96; font-size: 11px; }
.code-note code { padding: 11px 13px; border-radius: 9px; background: rgba(5,13,17,.5); color: var(--aqua); font-size: 12px; white-space: pre-wrap; }
.section-label { display: flex; align-items: center; justify-content: space-between; margin-top: 4px; }
.section-label strong { font-size: 14px; }
.section-label span { color: var(--muted); font-size: 12px; }
.divider { height: 1px; background: var(--border); margin: 4px 0; }
.switch-row { grid-template-columns: 1fr auto; align-items: center; padding: 15px; border: 1px solid var(--border); border-radius: 12px; background: rgba(9,20,26,.55); }
.switch-row div { display: grid; gap: 5px; }
.switch-row strong { color: var(--text); font-size: 14px; }
.switch-row span { color: var(--muted); font-size: 12px; }
.switch-row input { appearance: none; width: 42px; min-height: 24px; height: 24px; padding: 0; border-radius: 999px; background: #22353f; cursor: pointer; position: relative; }
.switch-row input::after { content: ""; position: absolute; width: 18px; height: 18px; top: 2px; left: 3px; border-radius: 50%; background: #8fa5ae; transition: .18s; }
.switch-row input:checked { background: rgba(104,245,208,.25); border-color: var(--aqua); }
.switch-row input:checked::after { transform: translateX(17px); background: var(--aqua); }
.danger-zone input:checked { background: rgba(255,125,120,.2); border-color: var(--red); }
.danger-zone input:checked::after { background: var(--red); }
.copy-field { display: grid; grid-template-columns: 1fr auto; gap: 8px; }

.bot-preview { min-height: 360px; }
.message-bubble { margin-top: 32px; padding: 18px; border-radius: 5px 16px 16px 16px; background: #172932; color: #d9e7ea; white-space: pre-wrap; line-height: 1.7; font-size: 14px; box-shadow: 0 12px 30px rgba(0,0,0,.16); }
.message-bubble.empty { color: #6f8792; font-style: italic; }
.toast { position: fixed; right: 24px; bottom: 24px; max-width: min(390px, calc(100% - 48px)); padding: 13px 16px; border-radius: 11px; background: #1a2a33; border: 1px solid var(--border-strong); box-shadow: 0 18px 45px rgba(0,0,0,.3); color: var(--text); opacity: 0; transform: translateY(15px); pointer-events: none; transition: .2s; z-index: 100; }
.toast.show { opacity: 1; transform: none; }
.toast.error { border-color: rgba(255,125,120,.35); color: #ffd0ce; }

@media (max-width: 1100px) {
  .metric-grid { grid-template-columns: 1fr 1fr; }
  .two-column, .settings-grid { grid-template-columns: 1fr; }
}

@media (max-width: 760px) {
  .shell { display: block; }
  .sidebar { position: fixed; left: -260px; width: 248px; transition: left .2s; box-shadow: 25px 0 60px rgba(0,0,0,.4); }
  .sidebar.open { left: 0; }
  .workspace { padding: 22px 17px 45px; }
  .mobile-menu { display: inline-grid; place-items: center; }
  .topbar { justify-content: flex-start; }
  .top-actions { margin-left: auto; }
  .status-pill { max-width: 126px; }
  .status-pill span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  .metric-grid { grid-template-columns: 1fr 1fr; gap: 10px; }
  .metric-card { min-height: 135px; padding: 17px; }
  .metric-card.featured { grid-column: 1 / -1; }
  .flow-line { align-items: stretch; flex-direction: column; }
  .flow-arrow { transform: rotate(90deg); align-self: flex-start; margin-left: 9px; }
  .form-row { grid-template-columns: 1fr; }
  .split-mobile { flex-direction: column; }
  .login-card { padding: 30px 24px; }
}

@media (max-width: 430px) {
  .metric-grid { grid-template-columns: 1fr; }
  .metric-card.featured { grid-column: auto; }
  .panel { padding: 19px 16px; }
  .topbar h1 { font-size: 24px; }
}
