:root {
  --bg: #07111f;
  --surface: #101d31;
  --surface-2: #17263d;
  --line: #263a56;
  --text: #eef6ff;
  --soft: #a9b8cf;
  --muted: #73849d;
  --accent: #10b981;
  --accent-2: #38bdf8;
  --danger: #fb7185;
  --warn: #f59e0b;
  --radius: 14px;
}
* { box-sizing: border-box; }
html { width: 100%; min-height: 100%; overflow-x: hidden; }
[hidden] { display: none !important; }
body { width: 100%; min-height: 100vh; margin: 0; font-family: Inter, ui-sans-serif, system-ui, "Segoe UI", Arial, sans-serif; color: var(--text); background: var(--bg); line-height: 1.45; overflow-x: hidden; }
button, input, select, textarea { font: inherit; }
button { cursor: pointer; }
input, select, textarea {
  width: 100%;
  border: 1px solid var(--line);
  background: #0b1424;
  color: var(--text);
  border-radius: 10px;
  padding: 10px 11px;
}
textarea { min-height: 96px; resize: vertical; }
h1, h2, h3 { margin: 0; line-height: 1.08; letter-spacing: -0.03em; }
h1 { font-size: clamp(2rem, 4vw, 3rem); }
h2 { font-size: 1.25rem; }
.login-shell { min-height: 100vh; display: grid; place-items: center; padding: 24px; }
.login-card, .panel, .data-table, .modal-card, .drawer-panel {
  border: 1px solid var(--line);
  background: linear-gradient(145deg, var(--surface), rgba(16, 29, 49, 0.8));
  border-radius: var(--radius);
  box-shadow: 0 24px 70px rgba(0,0,0,0.28);
}
.login-card { width: min(440px, 100%); padding: 28px; }
.login-card h1 { margin: 28px 0 10px; }
.login-card p, small, .soft { color: var(--soft); }
.brand-row { display: flex; align-items: center; gap: 12px; }
.brand-row strong, .brand-row small { display: block; }
.brand-mark { width: 42px; height: 42px; border-radius: 12px; display: grid; place-items: center; background: linear-gradient(135deg, var(--accent), var(--accent-2)); color: #05111d; font-weight: 1000; }
.app-shell { display: grid; grid-template-columns: 260px 1fr; min-height: 100vh; }
.sidebar { position: sticky; top: 0; height: 100vh; border-right: 1px solid var(--line); padding: 22px; background: rgba(7,17,31,0.94); }
.nav-list { display: grid; gap: 8px; margin-top: 28px; }
.nav-item { border: 1px solid transparent; background: transparent; color: var(--soft); border-radius: 12px; padding: 12px; text-align: left; font-weight: 900; }
.nav-item:hover, .nav-item.active { background: rgba(255,255,255,0.06); border-color: rgba(255,255,255,0.08); color: var(--text); }
.sidebar-card { margin-top: 28px; padding: 16px; border: 1px solid var(--line); border-radius: var(--radius); background: rgba(255,255,255,0.04); display: grid; gap: 6px; }
.sidebar-card span, .eyebrow { color: var(--accent); text-transform: uppercase; letter-spacing: .08em; font-size: 11px; font-weight: 1000; margin: 0; }
.workspace { min-width: 0; padding: 26px; }
.topbar, .table-toolbar, .panel-head { display: flex; align-items: center; justify-content: space-between; gap: 16px; margin-bottom: 18px; }
.top-actions, .toolbar-actions, .row-actions, .bulk-bar { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.top-actions input { width: min(330px, 36vw); }
.btn { border: 0; border-radius: 11px; padding: 10px 14px; font-weight: 900; display: inline-flex; align-items: center; justify-content: center; gap: 8px; }
.btn.primary { background: linear-gradient(135deg, var(--accent), #059669); color: #04121d; }
.btn.danger { background: rgba(251,113,133,0.14); color: #fecdd3; border: 1px solid rgba(251,113,133,0.38); }
.btn.ghost, .row-actions button, .template-card button, .service-card button, .agent-card button { border: 1px solid var(--line); color: var(--text); background: rgba(255,255,255,0.04); }
.view { display: none; }
.view.active { display: block; }
.metrics-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 14px; margin-bottom: 18px; }
.metric-card { border: 1px solid var(--line); border-radius: var(--radius); padding: 18px; background: var(--surface); color: var(--text); text-align: left; cursor: pointer; transition: transform .15s ease, border-color .15s ease, background .15s ease; }
.metric-card:hover, .metric-card:focus-visible { transform: translateY(-2px); border-color: rgba(34,211,238,0.45); background: rgba(23, 38, 62, 0.95); outline: 0; }
.metric-card span { color: var(--muted); text-transform: uppercase; letter-spacing: .08em; font-size: 12px; font-weight: 900; }
.metric-card b { display: block; font-size: 28px; margin-top: 6px; }
.metric-card small { color: var(--soft); }
.dashboard-grid, .settings-grid { display: grid; grid-template-columns: 1.2fr .8fr; gap: 18px; }
.panel { padding: 20px; }
.stack { display: grid; gap: 10px; }
.stage-bars { display: grid; grid-template-columns: repeat(6, minmax(150px, 1fr)); gap: 10px; overflow-x: auto; padding-bottom: 4px; }
.pipeline-stage { min-width: 150px; border: 1px solid rgba(255,255,255,0.08); border-radius: 12px; background: rgba(255,255,255,0.035); overflow: hidden; }
.stage-head { width: 100%; border: 0; border-bottom: 1px solid rgba(255,255,255,0.08); background: rgba(255,255,255,0.04); color: var(--text); padding: 12px; text-align: left; display: grid; gap: 5px; cursor: pointer; }
.stage-head:hover, .stage-head:focus-visible { background: rgba(34,211,238,0.08); outline: 0; }
.stage-head span { color: var(--soft); font-weight: 1000; }
.stage-head b { font-size: 24px; line-height: 1; }
.stage-head small { color: var(--accent-2); font-weight: 900; }
.stage-list { display: grid; gap: 8px; padding: 10px; min-height: 134px; align-content: start; }
.stage-lead { border: 1px solid rgba(255,255,255,0.08); background: rgba(5, 17, 29, 0.72); color: var(--text); border-radius: 10px; padding: 10px; text-align: left; cursor: pointer; }
.stage-lead:hover, .stage-lead:focus-visible { border-color: rgba(16,185,129,0.45); outline: 0; }
.stage-lead strong, .stage-lead small { display: block; }
.stage-lead small, .stage-empty { color: var(--soft); }
.stage-empty { padding: 10px; font-size: 13px; }
.action-card, .template-card, .message-card, .service-card, .agent-card { border: 1px solid rgba(255,255,255,0.08); background: rgba(255,255,255,0.04); border-radius: 12px; padding: 13px; }
.data-table { overflow: hidden; }
.table-row { display: grid; grid-template-columns: 42px minmax(250px, 1.5fr) 140px 110px 150px 160px; gap: 12px; align-items: center; padding: 13px 15px; border-bottom: 1px solid rgba(255,255,255,0.08); }
.table-row:last-child { border-bottom: 0; }
.table-head { background: rgba(255,255,255,0.05); color: var(--muted); text-transform: uppercase; letter-spacing: .08em; font-size: 12px; font-weight: 1000; }
.person-cell { border: 0; background: transparent; color: var(--text); text-align: left; padding: 0; }
.person-cell strong, .person-cell small { display: block; }
.status-chip { width: fit-content; border-radius: 999px; padding: 6px 9px; background: rgba(16,185,129,0.12); color: #67e8b9; font-size: 12px; font-weight: 900; }
.status-chip.warn { color: #fbbf24; background: rgba(245,158,11,0.13); }
.status-chip.danger { color: #fda4af; background: rgba(251,113,133,0.12); }
.row-actions button, .template-card button, .service-card button, .agent-card button { border-radius: 9px; padding: 7px 9px; font-size: 12px; font-weight: 900; }
.bulk-bar { border: 1px solid rgba(56,189,248,0.2); background: rgba(56,189,248,0.08); border-radius: 13px; padding: 12px; margin-bottom: 14px; }
.bulk-bar[hidden] { display: none; }
.bulk-bar strong { margin-right: auto; }
.template-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 14px; }
.template-card { display: grid; gap: 10px; }
.template-top { display: flex; justify-content: space-between; gap: 12px; align-items: flex-start; }
.service-card { display: grid; gap: 10px; }
.agent-grid { display: grid; grid-template-columns: minmax(0, 1fr); gap: 14px; }
.agent-card { display: grid; gap: 14px; }
.agent-top { display: grid; grid-template-columns: 48px 1fr auto; gap: 12px; align-items: center; }
.agent-avatar { width: 48px; height: 48px; border-radius: 14px; display: grid; place-items: center; background: linear-gradient(135deg, var(--accent), var(--accent-2)); color: #05111d; font-size: 22px; font-weight: 1000; }
.agent-lists { display: grid; grid-template-columns: repeat(3, 1fr); gap: 12px; }
.agent-lists section { border: 1px solid rgba(255,255,255,0.08); border-radius: 12px; padding: 12px; background: rgba(5, 17, 29, 0.45); }
.agent-lists strong { display: block; margin-bottom: 8px; }
.agent-lists ul { margin: 0; padding-left: 18px; color: var(--soft); }
.agent-lists li + li { margin-top: 6px; }
.detail-list { display: grid; gap: 8px; margin-top: 12px; }
.detail-line { display: flex; justify-content: space-between; gap: 12px; border: 1px solid rgba(255,255,255,0.08); border-radius: 10px; padding: 10px; background: rgba(255,255,255,0.035); }
.detail-line span { color: var(--muted); font-size: 12px; font-weight: 900; text-transform: uppercase; letter-spacing: .08em; }
.detail-line b { text-align: right; }
.drawer { position: fixed; inset: 0; display: none; justify-content: flex-end; background: rgba(0,0,0,0.5); z-index: 20; }
.drawer.open { display: flex; }
.drawer-panel { width: min(560px, 100%); height: 100%; overflow-y: auto; padding: 24px; border-radius: 0; position: relative; }
.icon-btn { width: 34px; height: 34px; border-radius: 10px; border: 1px solid var(--line); background: rgba(255,255,255,0.05); color: var(--text); font-weight: 900; }
.drawer .close { position: absolute; right: 18px; top: 18px; }
.drawer-title { padding-right: 44px; margin-bottom: 18px; }
.drawer-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; margin: 16px 0; }
.info-box { border: 1px solid var(--line); border-radius: 12px; padding: 12px; background: rgba(255,255,255,0.04); }
.info-box span { display: block; color: var(--muted); font-size: 12px; text-transform: uppercase; letter-spacing: .08em; font-weight: 900; }
.modal { width: min(760px, calc(100% - 28px)); border: 0; padding: 0; background: transparent; color: var(--text); }
.modal::backdrop { background: rgba(0,0,0,0.6); }
.modal-card { padding: 24px; }
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
label { display: grid; gap: 7px; color: var(--soft); font-size: 13px; font-weight: 800; }
label.full { grid-column: 1 / -1; }
.inline-check {
  display: flex;
  align-items: center;
  gap: 8px;
  width: fit-content;
  margin: 2px 0 4px;
}
.inline-check input {
  width: 16px;
  height: 16px;
  accent-color: var(--accent);
}
.form-error { color: var(--danger); margin-top: 10px; min-height: 20px; }
@media (max-width: 980px) {
  .app-shell { grid-template-columns: 1fr; }
  .sidebar { position: relative; height: auto; border-right: 0; border-bottom: 1px solid var(--line); }
  .nav-list { grid-template-columns: repeat(3, 1fr); }
  .metrics-grid, .dashboard-grid, .settings-grid, .template-grid, .agent-lists { grid-template-columns: 1fr; }
  .topbar { align-items: flex-start; flex-direction: column; }
  .top-actions, .top-actions input { width: 100%; }
}
@media (max-width: 680px) {
  body { min-height: 100svh; }
  h1 { font-size: 1.65rem; }
  h2 { font-size: 1.05rem; }
  input, select, textarea { min-height: 42px; font-size: 16px; }
  .login-shell { min-height: 100svh; padding: 14px; align-items: start; }
  .login-card { margin-top: 7svh; padding: 20px; border-radius: 14px; }
  .app-shell { width: 100%; min-height: 100svh; display: block; }
  .sidebar {
    position: sticky;
    top: 0;
    z-index: 12;
    height: auto;
    padding: 10px 12px 8px;
    border-bottom: 1px solid var(--line);
    background: rgba(7,17,31,0.98);
    backdrop-filter: blur(12px);
  }
  .brand-mark { width: 34px; height: 34px; border-radius: 10px; }
  .brand-row { gap: 9px; }
  .brand-row small { font-size: 11px; }
  .sidebar-card { display: none; }
  .nav-list {
    display: flex;
    gap: 6px;
    margin-top: 10px;
    overflow-x: auto;
    padding-bottom: 3px;
    scrollbar-width: none;
  }
  .nav-list::-webkit-scrollbar { display: none; }
  .nav-item {
    flex: 0 0 auto;
    min-height: 38px;
    padding: 8px 10px;
    border-radius: 999px;
    font-size: 12px;
    white-space: nowrap;
  }
  .workspace { width: 100%; max-width: 100vw; padding: 12px; overflow-x: hidden; }
  .topbar { gap: 10px; margin-bottom: 12px; }
  .topbar, .table-toolbar { align-items: stretch; flex-direction: column; }
  .top-actions, .toolbar-actions { display: grid; grid-template-columns: 1fr 1fr; width: 100%; gap: 8px; }
  .top-actions input { grid-column: 1 / -1; width: 100%; }
  .top-actions .btn, .toolbar-actions .btn { width: 100%; min-height: 42px; }
  .metrics-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; margin-bottom: 12px; }
  .metric-card { min-height: 106px; padding: 13px; border-radius: 12px; }
  .metric-card span { font-size: 10px; }
  .metric-card b { font-size: 22px; }
  .dashboard-grid, .settings-grid, .template-grid, .agent-lists { grid-template-columns: 1fr; gap: 12px; }
  .panel { padding: 14px; border-radius: 12px; }
  .panel-head { align-items: flex-start; margin-bottom: 12px; }
  .stage-bars { grid-template-columns: 1fr; gap: 8px; overflow-x: hidden; padding-bottom: 0; }
  .pipeline-stage { min-width: 0; border-radius: 11px; }
  .stage-head { grid-template-columns: 1fr auto auto; align-items: center; gap: 8px; padding: 10px 12px; }
  .stage-head b { font-size: 18px; }
  .stage-list { min-height: 0; padding: 8px; }
  .bulk-bar {
    display: grid;
    grid-template-columns: 1fr 1fr;
    align-items: stretch;
    gap: 8px;
    padding: 10px;
  }
  .bulk-bar strong { grid-column: 1 / -1; margin-right: 0; }
  .bulk-bar select, .bulk-bar .btn { width: 100%; min-height: 40px; }
  .data-table { border: 0; background: transparent; box-shadow: none; overflow: visible; }
  .table-row {
    grid-template-columns: 28px minmax(0, 1fr);
    gap: 8px 10px;
    align-items: start;
    margin-bottom: 10px;
    padding: 12px;
    border: 1px solid rgba(255,255,255,0.08);
    border-radius: 12px;
    background: rgba(255,255,255,0.04);
  }
  .table-head { display: none; }
  .table-row input[type="checkbox"] { width: 18px; height: 18px; margin-top: 4px; }
  .table-row > span, .table-row .row-actions { grid-column: 2; min-width: 0; }
  .table-row > span:nth-child(3)::before { content: "Status: "; color: var(--muted); font-weight: 900; }
  .table-row > span:nth-child(4)::before { content: "Value: "; color: var(--muted); font-weight: 900; }
  .table-row > span:nth-child(5)::before { content: "Next: "; color: var(--muted); font-weight: 900; }
  .person-cell { min-width: 0; }
  .person-cell strong, .person-cell small { overflow-wrap: anywhere; }
  .status-chip { white-space: normal; }
  .row-actions { width: 100%; display: grid; grid-template-columns: 1fr 1fr; }
  .row-actions button { min-height: 38px; }
  .template-top, .agent-top { grid-template-columns: 42px 1fr; display: grid; align-items: start; }
  .template-top button, .agent-top .status-chip { grid-column: 1 / -1; }
  .agent-avatar { width: 42px; height: 42px; border-radius: 12px; }
  .agent-card, .template-card, .service-card, .action-card { border-radius: 12px; }
  .agent-lists section { min-width: 0; }
  .detail-line { display: grid; gap: 4px; }
  .detail-line b { text-align: left; overflow-wrap: anywhere; }
  .drawer-panel {
    width: 100%;
    height: 100svh;
    padding: 18px 14px 28px;
  }
  .drawer-grid, .form-grid { grid-template-columns: 1fr; }
  .modal {
    width: 100vw;
    max-width: 100vw;
    height: 100svh;
    max-height: 100svh;
    margin: 0;
  }
  .modal-card {
    min-height: 100svh;
    padding: 18px 14px 28px;
    border-radius: 0;
    overflow-y: auto;
  }
  label.full { grid-column: auto; }
}
