:root {
  --surface-0: #f7f6f3;
  --surface-1: #f1efe8;
  --surface-2: #ffffff;
  --text-primary: #0b0b0b;
  --text-secondary: #52514e;
  --text-muted: #898781;
  --border: rgba(11,11,11,0.10);
  --accent: #2a78d6;
  --accent-text: #185fa5;
  --bg-accent: #e6f1fb;
  --success: #008300;
  --bg-success: #eaf3de;
  --danger: #d03b3b;
  --bg-danger: #fcebeb;
  --warning: #854f0b;
  --bg-warning: #faeeda;
  --radius: 8px;
}
* { box-sizing: border-box; }
body {
  margin: 0; background: var(--surface-0); color: var(--text-primary);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Helvetica, Arial, sans-serif;
  font-size: 15px; line-height: 1.5; -webkit-font-smoothing: antialiased;
}
.shell { max-width: 1040px; margin: 0 auto; padding: 24px 28px 48px; }

.appbar {
  display: flex; align-items: center; justify-content: space-between;
  gap: 20px; padding-bottom: 14px; margin-bottom: 20px;
  border-bottom: 1px solid var(--border);
}
.brand { display: flex; align-items: center; gap: 10px; font-weight: 500; font-size: 15px; }
.brand .dot { width: 22px; height: 22px; border-radius: 6px; background: var(--accent); }
nav { display: flex; gap: 4px; flex-wrap: wrap; }
nav a { font-size: 13px; color: var(--text-secondary); text-decoration: none; padding: 6px 11px; border-radius: var(--radius); }
nav a:hover { background: var(--surface-1); }
nav a.on { background: var(--surface-1); color: var(--text-primary); font-weight: 500; }

.crumb { font-size: 12px; color: var(--text-muted); margin-bottom: 10px; }
.crumb a { color: var(--text-muted); text-decoration: none; }
.crumb a:hover { color: var(--text-secondary); }

.pagehead { display: flex; align-items: flex-start; justify-content: space-between; gap: 16px; margin-bottom: 16px; }
.pagehead h1 { margin: 0; font-size: 21px; font-weight: 500; }
.pagehead .sub { margin: 3px 0 0; font-size: 13px; color: var(--text-muted); }
.headtools { display: flex; align-items: center; gap: 8px; flex: none; }

button {
  font-family: inherit; font-size: 13px; color: var(--text-secondary);
  background: var(--surface-2); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 7px 12px; cursor: pointer;
  display: inline-flex; align-items: center; gap: 6px;
}
button:hover { background: var(--surface-1); color: var(--text-primary); }
button:active { transform: scale(0.98); }
button svg { width: 15px; height: 15px; flex: none; }
button.primary { border-color: #9dc2ec; color: var(--accent-text); }
button.primary:hover { background: var(--bg-accent); color: var(--accent-text); }

input[type=text], input[type=search] {
  flex: 1; min-width: 0; font-family: inherit; font-size: 13px; color: var(--text-secondary);
  padding: 7px 11px; border: 1px solid var(--border); border-radius: var(--radius); background: var(--surface-2);
}

.chips { display: flex; gap: 5px; flex-wrap: wrap; margin-bottom: 16px; }
.chip { font-size: 12px; padding: 5px 11px; border-radius: var(--radius); background: var(--surface-1); color: var(--text-secondary); cursor: default; }
.chip:hover { color: var(--text-primary); }
.chip.on { background: var(--bg-accent); color: var(--accent-text); }

.card { background: var(--surface-2); border: 1px solid var(--border); border-radius: 12px; padding: 8px 20px 12px; margin-bottom: 16px; break-inside: avoid; }
.card.pad { padding: 16px 20px; }
.card h2 { margin: 0; font-size: 16px; font-weight: 500; }
.cardhead { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 12px; }

.grp {
  font-size: 12px; color: var(--text-muted); padding: 14px 0 8px;
  border-top: 1px solid var(--border); margin-top: 4px;
}
.grp:first-child { border-top: 0; margin-top: 0; padding-top: 10px; }
.grp.late { color: var(--danger); }

.r { display: flex; align-items: center; gap: 12px; padding: 10px 0; border-top: 1px solid var(--border); }
.grp + .r { border-top: 0; }
.av {
  width: 30px; height: 30px; border-radius: 50%; background: var(--bg-accent); color: var(--accent-text);
  font-size: 11px; font-weight: 500; display: flex; align-items: center; justify-content: center; flex: none;
}
.nm { flex: 1 1 auto; min-width: 96px; font-size: 14px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.nm small { display: block; font-size: 12px; color: var(--text-muted); font-weight: 400; }
.mt { font-size: 12px; color: var(--text-muted); flex: none; }
.dt { font-size: 12px; color: var(--text-secondary); width: 78px; flex: none; }
.ic { width: 18px; height: 18px; flex: none; color: var(--text-muted); }
.ic.done { color: var(--success); }
.ic.next { color: var(--accent); }

.tag { font-size: 11px; padding: 2px 8px; border-radius: var(--radius); background: var(--surface-1); color: var(--text-secondary); flex: none; }
.tag.ok { background: var(--bg-success); color: #3b6d11; }
.tag.warn { background: var(--bg-warning); color: var(--warning); }
.tag.bad { background: var(--bg-danger); color: var(--danger); }
.tag.info { background: var(--bg-accent); color: var(--accent-text); }

.banner { background: var(--bg-accent); border-radius: var(--radius); padding: 13px 16px; margin-bottom: 16px; }
.banner .k { margin: 0; font-size: 12px; color: var(--accent-text); }
.banner .h { margin: 4px 0 0; font-size: 15px; font-weight: 500; color: #0c447c; }
.banner .s { margin: 3px 0 0; font-size: 12px; color: var(--accent-text); }

.acts { display: flex; gap: 6px; flex: none; }
.acts button { padding: 5px 10px; font-size: 12px; }

.foot { margin-top: 26px; font-size: 12px; color: var(--text-muted); }

@media (max-width: 760px) {
  .shell { padding: 20px 18px 40px; }
  .appbar { flex-direction: column; align-items: flex-start; gap: 12px; }
  .r { flex-wrap: wrap; row-gap: 4px; }
  .nm { flex: 1 1 100%; }
  .dt, .mt, .acts { width: auto; }
}

@media print {
  body { background: #fff; }
  .shell { max-width: none; padding: 0; }
  nav, button, .chips { display: none; }
  .card { border-color: #ddd; }
  @page { margin: 14mm; }
}

/* ── dashboard: KPI cards, pipeline funnel, follow-up rows ── */
.kpis { display: grid; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); gap: 12px; margin-bottom: 20px; }
.kpi { background: var(--surface-1); border-radius: var(--radius); padding: 14px 16px; }
.kpi .lbl { font-size: 13px; color: var(--text-secondary); }
.kpi .val { font-size: 26px; font-weight: 500; margin-top: 3px; }
.kpi .val.bad { color: var(--danger); }
.kpi .sub { font-size: 12px; color: var(--text-muted); margin-top: 1px; }
.kpi .sub.up { color: var(--success); }

.frow { display: flex; align-items: center; gap: 12px; margin-bottom: 10px; }
.frow:last-child { margin-bottom: 0; }
.frow .name { width: 82px; flex: none; font-size: 13px; color: var(--text-secondary); }
.track { flex: 1; min-width: 0; height: 22px; background: #f0efec; border-radius: 4px; }
.fill { height: 100%; background: var(--accent); border-radius: 4px; }
.frow .n { width: 26px; flex: none; text-align: right; font-size: 13px; font-weight: 500; }
.frow .conv { width: 160px; flex: none; font-size: 12px; color: var(--text-muted); }

.fu { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 11px 0; border-top: 1px solid var(--border); }
.fu:first-child { border-top: 0; }
.fu .t { display: flex; align-items: center; gap: 9px; font-size: 14px; min-width: 0; }
.fu .t span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.metaline { display: flex; gap: 20px; flex-wrap: wrap; font-size: 12px; color: var(--text-muted); padding-bottom: 16px; margin-bottom: 18px; border-bottom: 1px solid var(--border); }
.empty { padding: 40px 0; text-align: center; color: var(--text-muted); font-size: 14px; }

/* login */
.login-wrap { max-width: 360px; margin: 8vh auto; padding: 0 20px; }
.login-card { background: var(--surface-2); border: 1px solid var(--border); border-radius: 12px; padding: 28px 26px; }
.login-card h1 { font-size: 19px; font-weight: 500; margin: 0 0 4px; }
.login-card p.sub { font-size: 13px; color: var(--text-muted); margin: 0 0 20px; }
.login-card label { display: block; font-size: 13px; color: var(--text-secondary); margin: 12px 0 5px; }
.login-card input { width: 100%; font-family: inherit; font-size: 14px; padding: 9px 11px; border: 1px solid var(--line, var(--border)); border-radius: var(--radius); background: var(--surface-2); }
.login-card button { width: 100%; margin-top: 18px; padding: 10px; font-size: 14px; border-color: #9dc2ec; color: var(--accent-text); }
.login-card .err { color: var(--danger); font-size: 13px; margin-top: 10px; }

/* ── forms ── */
.appform > div { margin-bottom: 4px; }
.appform label { display: block; font-size: 13px; color: var(--text-secondary); margin: 12px 0 5px; font-weight: 500; }
.appform input, .appform select, .appform textarea {
  width: 100%; font-family: inherit; font-size: 14px; padding: 8px 11px;
  border: 1px solid var(--border); border-radius: var(--radius); background: var(--surface-2); color: var(--text-primary);
}
.appform input:focus, .appform select:focus, .appform textarea:focus { outline: none; border-color: var(--accent); }
.appform textarea { min-height: 80px; resize: vertical; }
.appform select[multiple] { min-height: 96px; }
.appform .helptext { display: block; font-size: 12px; color: var(--text-muted); margin-top: 3px; }
.appform ul.errorlist { list-style: none; padding: 0; margin: 5px 0 0; color: var(--danger); font-size: 13px; }
.msgs { margin-bottom: 16px; }
.msg { font-size: 13px; padding: 9px 13px; border-radius: var(--radius); margin-bottom: 8px; }
.msg.success { background: var(--bg-success); color: #3b6d11; }
.msg.error { background: var(--bg-danger); color: var(--danger); }
.rowact { display: flex; gap: 6px; flex: none; }
.rowact button, .rowact a button { padding: 5px 10px; font-size: 12px; }

/* ── workspace tabs (light theme) ── */
.tabbar { display: flex; gap: 2px; flex-wrap: wrap; border-bottom: 1px solid var(--border); margin-bottom: 22px; }
.tabbtn {
  font-family: inherit; font-size: 14px; color: var(--text-secondary);
  background: none; border: 0; border-bottom: 2px solid transparent;
  padding: 10px 14px; margin-bottom: -1px; cursor: pointer; white-space: nowrap;
}
.tabbtn:hover { color: var(--text-primary); }
.tabbtn.on { color: var(--accent-text); border-bottom-color: var(--accent); font-weight: 500; }
.tabpanel { display: none; }
.tabpanel.on { display: block; }
.richtext { line-height: 1.7; }
.richtext h1, .richtext h2, .richtext h3 { font-weight: 500; margin: 1em 0 .4em; }
.richtext ul, .richtext ol { padding-left: 1.4em; }
.richtext p { margin: 0 0 .7em; }
.postingtext { white-space: pre-line; font-size: 14px; line-height: 1.7; color: var(--text-secondary); }
.uploadinline { display: inline-flex; align-items: center; gap: 6px; }
.uploadinline input[type=file] { font-size: 12px; max-width: 190px; }

/* ── assistant chat overlay ── */
#ai-fab {
  position: fixed; right: 22px; bottom: 22px; z-index: 40;
  padding: 11px 18px; font-size: 14px; font-weight: 500;
  color: #fff; background: var(--accent); border: 0; border-radius: 999px;
  box-shadow: 0 3px 12px rgba(11,11,11,.18); cursor: pointer;
}
#ai-fab:hover { background: var(--accent-text); color: #fff; }
#ai-panel {
  position: fixed; right: 22px; bottom: 22px; z-index: 41;
  width: 380px; max-width: calc(100vw - 32px); height: 520px; max-height: calc(100vh - 44px);
  display: flex; flex-direction: column;
  background: var(--surface-2); border: 1px solid var(--border); border-radius: 12px;
  box-shadow: 0 8px 28px rgba(11,11,11,.18); overflow: hidden;
}
.ai-head {
  display: flex; align-items: center; justify-content: space-between;
  padding: 12px 15px; border-bottom: 1px solid var(--border); font-weight: 500; font-size: 14px;
}
.ai-head button { border: 0; background: none; font-size: 20px; line-height: 1; color: var(--text-muted); cursor: pointer; padding: 0 4px; }
.ai-head button:hover { color: var(--text-primary); background: none; }
#ai-log { flex: 1; overflow-y: auto; padding: 14px 15px; display: flex; flex-direction: column; gap: 10px; }
.ai-hint { font-size: 13px; color: var(--text-muted); line-height: 1.6; margin: 0; }
.ai-msg { font-size: 13.5px; line-height: 1.6; padding: 9px 12px; border-radius: 10px; white-space: pre-wrap; max-width: 92%; }
.ai-msg.me { background: var(--bg-accent); color: var(--accent-text); align-self: flex-end; }
.ai-msg.ai { background: var(--surface-1); color: var(--text-primary); align-self: flex-start; }
.ai-msg.pending { color: var(--text-muted); font-style: italic; }
.ai-msg.err { background: var(--bg-danger); color: var(--danger); }
#ai-form { display: flex; gap: 8px; padding: 12px 14px; border-top: 1px solid var(--border); }
#ai-form input {
  flex: 1; min-width: 0; font-family: inherit; font-size: 13.5px; padding: 8px 11px;
  border: 1px solid var(--border); border-radius: var(--radius); background: var(--surface-2);
}
#ai-form input:focus { outline: none; border-color: var(--accent); }
@media print { #ai-fab, #ai-panel { display: none !important; } }

/* assistant replies render markdown — keep spacing tight inside the bubble */
.ai-msg.richtext { white-space: normal; }
.ai-msg.richtext > *:first-child { margin-top: 0; }
.ai-msg.richtext > *:last-child { margin-bottom: 0; }
.ai-msg.richtext p { margin: 0 0 .6em; }
.ai-msg.richtext ul, .ai-msg.richtext ol { margin: .4em 0 .6em; padding-left: 1.25em; }
.ai-msg.richtext li { margin: .15em 0; }
.ai-msg.richtext h1, .ai-msg.richtext h2, .ai-msg.richtext h3 { font-size: 14px; font-weight: 500; margin: .7em 0 .3em; }
.ai-msg.richtext code { background: rgba(11,11,11,.06); padding: 1px 5px; border-radius: 4px; font-size: 12.5px; }
.ai-msg.richtext pre { background: rgba(11,11,11,.06); padding: 9px 11px; border-radius: 6px; overflow-x: auto; margin: .5em 0; }
.ai-msg.richtext pre code { background: none; padding: 0; }
.ai-msg.richtext a { color: var(--accent-text); }
