/* ---------------------------------------------------------------------------
   Operator console for a multi-client MSP CRM.
   Light, dense "instrument panel" — calm slate sidebar, bright work surface,
   brand accent driven by CSS variables (white-label). Money & IDs are mono.
--------------------------------------------------------------------------- */
:root {
  --brand: #1693a6;
  --accent: #7db72f;
  --ink: #0f1c22;
  --ink-2: #46555c;
  --ink-3: #7b8a91;
  --line: #e4e9eb;
  --line-2: #eef2f3;
  --surface: #ffffff;
  --canvas: #f5f7f8;
  --rail: #0f1c22;
  --rail-ink: #b9c6cb;
  --rail-line: #21333b;
  --won: #2f9e44;
  --lost: #e03131;
  --warn: #e8893b;
  --radius: 9px;
  --mono: ui-monospace, "SF Mono", "JetBrains Mono", Menlo, Consolas, monospace;
  --sans: "Inter", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, system-ui, sans-serif;
  --shadow: 0 1px 2px rgba(15,28,34,.06), 0 4px 16px rgba(15,28,34,.06);
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  font-family: var(--sans); color: var(--ink); background: var(--canvas);
  -webkit-font-smoothing: antialiased; font-size: 14px; line-height: 1.45;
}
button { font-family: inherit; cursor: pointer; }
a { color: var(--brand); }
.eyebrow { font-size: 10.5px; letter-spacing: .14em; text-transform: uppercase; color: var(--ink-3); font-weight: 600; }
.mono { font-family: var(--mono); font-variant-numeric: tabular-nums; }
.num { font-family: var(--mono); font-variant-numeric: tabular-nums; }

/* ---------- Login ---------- */
.login-wrap { min-height: 100vh; display: grid; place-items: center; background:
  radial-gradient(1200px 600px at 70% -10%, rgba(22,147,166,.10), transparent),
  var(--canvas); }
.login-card { background: var(--surface); width: 360px; padding: 34px 30px; border-radius: 14px;
  box-shadow: var(--shadow); border: 1px solid var(--line); }
.login-card h1 { margin: 0 0 2px; font-size: 21px; letter-spacing: -.01em; }
.login-card .sub { color: var(--ink-3); margin: 0 0 22px; font-size: 13px; }
.brandmark { display: inline-flex; align-items: baseline; font-weight: 800; font-size: 19px; letter-spacing: -.02em; }
.brandmark .b1 { color: var(--brand); } .brandmark .b2 { color: var(--accent); }

/* ---------- Shell ---------- */
.shell { display: grid; grid-template-columns: 244px 1fr; min-height: 100vh; }
.rail { background: var(--rail); color: var(--rail-ink); display: flex; flex-direction: column;
  position: sticky; top: 0; height: 100vh; }
.rail-brand { padding: 18px 18px 12px; }
.rail-brand .brandmark { font-size: 17px; }
.rail-brand .brandmark .b1 { color: #fff; } .rail-brand .brandmark .b2 { color: var(--accent); }

/* Workspace switcher — the signature control */
.ws { margin: 4px 12px 10px; }
.ws-btn { width: 100%; text-align: left; background: var(--rail-line); border: 1px solid transparent;
  color: #fff; border-radius: 8px; padding: 9px 11px; display: flex; align-items: center; gap: 9px; }
.ws-btn:hover { border-color: #36505b; }
.ws-dot { width: 7px; height: 7px; border-radius: 50%; background: var(--accent); box-shadow: 0 0 0 3px rgba(125,183,47,.18); flex: none; }
.ws-meta { min-width: 0; }
.ws-meta .lbl { font-size: 9.5px; letter-spacing: .12em; text-transform: uppercase; color: var(--rail-ink); opacity: .7; }
.ws-meta .nm { font-size: 13.5px; font-weight: 650; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; color: #fff; }
.ws-caret { margin-left: auto; color: var(--rail-ink); opacity: .6; }
.ws-pop { position: absolute; z-index: 40; margin: 4px 12px; left: 0; right: 0; background: #16262d;
  border: 1px solid var(--rail-line); border-radius: 8px; padding: 5px; box-shadow: 0 12px 30px rgba(0,0,0,.4); }
.ws-pop .item { padding: 8px 10px; border-radius: 6px; color: var(--rail-ink); display: flex; align-items: center; gap: 8px; font-size: 13px; }
.ws-pop .item:hover { background: var(--rail-line); color: #fff; }
.ws-pop .item.active { color: #fff; }
.ws-pop .add { color: var(--accent); border-top: 1px solid var(--rail-line); margin-top: 4px; padding-top: 9px; }

.nav { padding: 6px 10px; flex: 1; overflow: auto; }
.nav a { display: flex; align-items: center; gap: 10px; padding: 8px 11px; border-radius: 7px;
  color: var(--rail-ink); text-decoration: none; font-size: 13.5px; font-weight: 500; margin-bottom: 1px; }
.nav a:hover { background: var(--rail-line); color: #fff; }
.nav a.active { background: linear-gradient(90deg, rgba(22,147,166,.22), rgba(22,147,166,.06)); color: #fff;
  box-shadow: inset 2px 0 0 var(--brand); }
.nav a .ic { width: 17px; text-align: center; opacity: .85; }
.nav .sec { font-size: 9.5px; letter-spacing: .13em; text-transform: uppercase; color: var(--ink-3);
  padding: 14px 11px 5px; opacity: .8; }
.rail-user { border-top: 1px solid var(--rail-line); padding: 12px 16px; display: flex; align-items: center; gap: 10px; }
.avatar { width: 28px; height: 28px; border-radius: 50%; background: var(--brand); color: #fff; display: grid; place-items: center; font-size: 12px; font-weight: 700; }
.rail-user .nm { font-size: 12.5px; color: #fff; font-weight: 600; }
.rail-user .ro { font-size: 10.5px; color: var(--rail-ink); }
.rail-user button { margin-left: auto; background: none; border: none; color: var(--rail-ink); font-size: 16px; }
.rail-user button:hover { color: #fff; }

/* ---------- Main ---------- */
.main { display: flex; flex-direction: column; min-width: 0; }
.topbar { display: flex; align-items: center; gap: 14px; padding: 16px 26px; border-bottom: 1px solid var(--line);
  background: var(--surface); position: sticky; top: 0; z-index: 20; }
.topbar h2 { margin: 0; font-size: 18px; letter-spacing: -.01em; }
.topbar .spacer { flex: 1; }
.content { padding: 22px 26px 60px; overflow: auto; }

.btn { background: var(--brand); color: #fff; border: none; border-radius: 8px; padding: 8px 14px; font-weight: 600; font-size: 13px; }
.btn:hover { filter: brightness(1.07); }
.btn.ghost { background: var(--surface); color: var(--ink); border: 1px solid var(--line); }
.btn.ghost:hover { border-color: var(--ink-3); filter: none; }
.btn.sm { padding: 5px 10px; font-size: 12px; }
.btn.danger { background: var(--lost); }

/* Cards / KPIs */
.kpis { display: grid; grid-template-columns: repeat(4, 1fr); gap: 14px; margin-bottom: 22px; }
.kpi { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px 17px; box-shadow: var(--shadow); }
.kpi .v { font-size: 26px; font-weight: 700; letter-spacing: -.02em; font-family: var(--mono); font-variant-numeric: tabular-nums; }
.kpi .l { color: var(--ink-3); margin-top: 2px; }
.kpi .v small { font-size: 14px; color: var(--ink-3); font-weight: 600; }

.panel { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); margin-bottom: 18px; }
.panel-head { padding: 14px 17px; border-bottom: 1px solid var(--line-2); display: flex; align-items: center; gap: 10px; }
.panel-head h3 { margin: 0; font-size: 14px; }
.panel-body { padding: 14px 17px; }

/* Funnel bars */
.funnel-row { display: grid; grid-template-columns: 130px 1fr 120px; align-items: center; gap: 12px; padding: 7px 0; }
.funnel-row .nm { font-size: 13px; }
.bar { height: 22px; background: var(--line-2); border-radius: 6px; overflow: hidden; }
.bar > span { display: block; height: 100%; background: linear-gradient(90deg, var(--brand), #2fb3c6); border-radius: 6px; }
.funnel-row .amt { text-align: right; font-family: var(--mono); font-variant-numeric: tabular-nums; color: var(--ink-2); font-size: 13px; }

/* Tables */
table { width: 100%; border-collapse: collapse; }
thead th { text-align: left; font-size: 10.5px; letter-spacing: .08em; text-transform: uppercase; color: var(--ink-3);
  padding: 10px 14px; border-bottom: 1px solid var(--line); font-weight: 600; }
tbody td { padding: 11px 14px; border-bottom: 1px solid var(--line-2); font-size: 13.5px; }
tbody tr:hover { background: #fafcfc; cursor: pointer; }
tbody tr:last-child td { border-bottom: none; }

.pill { display: inline-flex; align-items: center; gap: 5px; font-size: 11px; font-weight: 600; padding: 2px 8px; border-radius: 20px; }
.pill.lead { background: #eef2f3; color: var(--ink-2); }
.pill.mql { background: rgba(125,183,47,.16); color: #5a8a1f; }
.pill.sql { background: rgba(22,147,166,.14); color: var(--brand); }
.pill.customer { background: rgba(47,158,68,.14); color: var(--won); }
.score { font-family: var(--mono); font-weight: 700; }
.score.hot { color: var(--won); }
.score.warm { color: var(--warn); }
.score.cold { color: var(--ink-3); }

/* Kanban */
.kanban { display: grid; grid-auto-flow: column; grid-auto-columns: 268px; gap: 14px; overflow-x: auto; padding-bottom: 10px; align-items: start; }
.col { background: #eef2f3; border-radius: 10px; padding: 10px; min-height: 120px; }
.col.won { background: rgba(47,158,68,.08); } .col.lost { background: rgba(224,49,49,.07); }
.col-head { display: flex; align-items: center; justify-content: space-between; padding: 2px 4px 9px; }
.col-head .nm { font-size: 12px; font-weight: 700; letter-spacing: .02em; }
.col-head .meta { font-family: var(--mono); font-size: 11px; color: var(--ink-3); }
.col.drag-over { outline: 2px dashed var(--brand); outline-offset: -2px; }
.deal { background: var(--surface); border: 1px solid var(--line); border-radius: 8px; padding: 10px 11px; margin-bottom: 8px;
  box-shadow: 0 1px 2px rgba(15,28,34,.05); cursor: grab; }
.deal:active { cursor: grabbing; }
.deal .dn { font-weight: 600; font-size: 13px; }
.deal .dc { color: var(--ink-3); font-size: 12px; margin-top: 1px; }
.deal .df { display: flex; align-items: center; justify-content: space-between; margin-top: 8px; }
.deal .amt { font-family: var(--mono); font-weight: 700; font-size: 13px; }
.deal .mrr { font-size: 10.5px; color: var(--accent); font-weight: 700; background: rgba(125,183,47,.12); padding: 1px 6px; border-radius: 5px; }

/* Detail drawer */
.drawer-bg { position: fixed; inset: 0; background: rgba(15,28,34,.34); z-index: 50; }
.drawer { position: fixed; top: 0; right: 0; height: 100vh; width: 460px; max-width: 92vw; background: var(--surface);
  z-index: 51; box-shadow: -10px 0 40px rgba(0,0,0,.18); display: flex; flex-direction: column; }
.drawer-head { padding: 20px 22px 16px; border-bottom: 1px solid var(--line); }
.drawer-head h3 { margin: 0; font-size: 18px; }
.drawer-head .sub { color: var(--ink-3); font-size: 13px; margin-top: 2px; }
.drawer-body { overflow: auto; padding: 18px 22px; flex: 1; }
.kv { display: grid; grid-template-columns: 92px 1fr; gap: 6px 10px; margin-bottom: 16px; font-size: 13px; }
.kv .k { color: var(--ink-3); }
.timeline { border-left: 2px solid var(--line); padding-left: 16px; margin-left: 4px; }
.tl-item { position: relative; padding: 0 0 16px; }
.tl-item::before { content: ""; position: absolute; left: -22px; top: 3px; width: 9px; height: 9px; border-radius: 50%; background: var(--brand); box-shadow: 0 0 0 3px var(--surface); }
.tl-item.automation::before { background: var(--accent); }
.tl-item .ty { font-size: 10px; text-transform: uppercase; letter-spacing: .08em; color: var(--ink-3); font-weight: 600; }
.tl-item .su { font-weight: 600; font-size: 13.5px; }
.tl-item .bo { color: var(--ink-2); font-size: 13px; }
.tl-item .dt { font-size: 11px; color: var(--ink-3); font-family: var(--mono); }

/* Automation run log */
.run { border: 1px solid var(--line); border-radius: 8px; margin-bottom: 10px; overflow: hidden; }
.run-head { padding: 9px 12px; background: #fafcfc; display: flex; align-items: center; gap: 10px; font-size: 13px; border-bottom: 1px solid var(--line-2); }
.run-head .when { margin-left: auto; font-family: var(--mono); font-size: 11px; color: var(--ink-3); }
.step { display: grid; grid-template-columns: 22px 120px 1fr 86px; gap: 10px; align-items: center; padding: 7px 12px; font-size: 12.5px; border-top: 1px solid var(--line-2); }
.step:first-child { border-top: none; }
.step .si { font-family: var(--mono); color: var(--ink-3); }
.step .ac { font-weight: 600; }
.step .de { color: var(--ink-2); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.tag { font-size: 10.5px; font-weight: 700; padding: 2px 8px; border-radius: 20px; text-align: center; text-transform: uppercase; letter-spacing: .04em; }
.tag.sent { background: rgba(47,158,68,.15); color: var(--won); }
.tag.simulated { background: rgba(22,147,166,.14); color: var(--brand); }
.tag.skipped { background: #eef2f3; color: var(--ink-3); }
.tag.error { background: rgba(224,49,49,.14); color: var(--lost); }

/* Toggles */
.toggle { width: 38px; height: 22px; border-radius: 20px; background: var(--line); position: relative; border: none; flex: none; transition: background .15s; }
.toggle.on { background: var(--accent); }
.toggle::after { content: ""; position: absolute; top: 2px; left: 2px; width: 18px; height: 18px; border-radius: 50%; background: #fff; transition: left .15s; box-shadow: 0 1px 2px rgba(0,0,0,.2); }
.toggle.on::after { left: 18px; }

.template-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 14px; }
.tpl { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 15px 16px; box-shadow: var(--shadow); }
.tpl .cat { color: var(--brand); }
.tpl h4 { margin: 4px 0 6px; font-size: 14px; }
.tpl p { margin: 0; color: var(--ink-2); font-size: 12.5px; }
.tpl .ch { float: right; font-size: 10px; text-transform: uppercase; letter-spacing: .06em; color: var(--ink-3); border: 1px solid var(--line); padding: 1px 7px; border-radius: 20px; }

/* Forms */
label { display: block; font-size: 12px; color: var(--ink-2); margin: 12px 0 4px; font-weight: 600; }
input, select, textarea { width: 100%; padding: 9px 11px; border: 1px solid var(--line); border-radius: 8px; font-family: inherit; font-size: 13.5px; background: var(--surface); color: var(--ink); }
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--brand); box-shadow: 0 0 0 3px rgba(22,147,166,.12); }
.field-row { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }

/* Modal */
.modal-bg { position: fixed; inset: 0; background: rgba(15,28,34,.4); z-index: 60; display: grid; place-items: center; padding: 20px; }
.modal { background: var(--surface); border-radius: 14px; width: 440px; max-width: 100%; box-shadow: 0 24px 60px rgba(0,0,0,.3); max-height: 90vh; overflow: auto; }
.modal-head { padding: 18px 22px 4px; }
.modal-head h3 { margin: 0; font-size: 17px; }
.modal-body { padding: 6px 22px 20px; }
.modal-foot { padding: 14px 22px; border-top: 1px solid var(--line-2); display: flex; gap: 10px; justify-content: flex-end; }

.empty { text-align: center; color: var(--ink-3); padding: 40px 20px; }
.empty .big { font-size: 15px; color: var(--ink-2); margin-bottom: 4px; font-weight: 600; }

.toast { position: fixed; bottom: 22px; left: 50%; transform: translateX(-50%); background: var(--ink); color: #fff;
  padding: 11px 18px; border-radius: 9px; font-size: 13px; z-index: 80; box-shadow: 0 8px 24px rgba(0,0,0,.3); }

.banner { background: rgba(232,137,59,.12); border: 1px solid rgba(232,137,59,.4); color: #9a5a1e;
  padding: 8px 14px; border-radius: 8px; font-size: 12.5px; margin-bottom: 16px; display: flex; align-items: center; gap: 10px; }

@media (max-width: 820px) {
  .shell { grid-template-columns: 1fr; }
  .rail { position: static; height: auto; flex-direction: row; flex-wrap: wrap; }
  .nav { display: flex; flex-wrap: wrap; }
  .kpis { grid-template-columns: repeat(2, 1fr); }
  .template-grid { grid-template-columns: 1fr; }
}
@media (prefers-reduced-motion: reduce) { * { transition: none !important; } }

/* --- Workspace switcher: truncate long names ------------------------------ */
.ws-btn { max-width: 100%; }
.ws-btn .ws-meta { min-width: 0; flex: 1; overflow: hidden; }
.ws-btn .nm {
  display: block;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.ws-pop .item {
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

