:root {
  --bg: #131210;
  --surface: #1c1a16;
  --surface-2: #221f1a;
  --border: #3b331f;
  --border-soft: #2c2820;
  --text: #f1ecdf;
  --muted: #a59c85;
  --accent: #d4af37;
  --accent-strong: #e8c34e;
  --accent-soft: rgba(212, 175, 55, .14);
  --on-accent: #1a1508;
  --green: #4ade80;
  --green-soft: rgba(74, 222, 128, .13);
  --amber: #fbbf24;
  --amber-soft: rgba(251, 191, 36, .13);
  --red: #f87171;
  --red-soft: rgba(248, 113, 113, .13);
  --blue: #93c5fd;
  --blue-soft: rgba(147, 197, 253, .12);
  --sidebar: #0b0a08;
  --radius: 12px;
  --shadow: 0 1px 2px rgba(0, 0, 0, .4);
}
* { box-sizing: border-box; }
body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Inter, Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 14px;
  -webkit-font-smoothing: antialiased;
}
a { color: inherit; text-decoration: none; }

.layout { display: flex; min-height: 100vh; }
.sidebar {
  width: 216px; flex-shrink: 0; background: var(--sidebar); color: #cfc7b2;
  display: flex; flex-direction: column; padding: 20px 12px; position: sticky;
  top: 0; height: 100vh; border-right: 1px solid #262115;
}
.brand { font-size: 17px; font-weight: 700; color: #fff; padding: 0 10px; letter-spacing: -.2px; display: inline-flex; flex-direction: column; align-items: center; gap: 1px; }
.brand-crown { width: 22px; height: 15px; display: block; color: var(--accent); }
.org { font-size: 12px; color: #8a8168; padding: 4px 10px 18px; border-bottom: 1px solid #262115; margin-bottom: 14px; text-align: center; }
.trial-pill { display: block; margin: 0 0 12px; padding: 7px 10px; border-radius: 8px;
  background: var(--accent-soft); color: var(--accent-strong); font-size: 12px; font-weight: 600;
  text-align: center; border: 1px solid rgba(212, 175, 55, .3); }
.trial-pill:hover { background: rgba(212, 175, 55, .25); color: #fff; }
.trial-pill.expired { background: var(--red-soft); color: var(--red); border-color: rgba(248, 113, 113, .3); }
.trial-pill.plan { background: var(--green-soft); color: var(--green); border-color: rgba(74, 222, 128, .25); }
.sidebar nav { display: flex; flex-direction: column; gap: 2px; }
.sidebar nav a {
  padding: 8px 10px; border-radius: 8px; font-weight: 500; color: #b3aa8f;
  display: flex; align-items: center; gap: 9px; font-size: 13.5px;
}
.sidebar nav a:hover { background: #1a1712; color: #fff; }
.sidebar nav a.active { background: var(--accent-soft); color: var(--accent-strong); border: 1px solid rgba(212, 175, 55, .35); padding: 7px 9px; }
.sidebar-foot { margin-top: auto; padding: 10px; font-size: 12.5px; color: #8a8168; }
.sidebar-foot a:hover { color: var(--accent-strong); }

.content { flex: 1; padding: 28px 32px; max-width: 1280px; min-width: 0; }
.page-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 20px; gap: 12px; flex-wrap: wrap; }
h1 { font-size: 21px; margin: 0; letter-spacing: -.3px; color: #fff; }
.sub { color: var(--muted); font-size: 13px; margin-top: 3px; }
h2 { font-size: 14px; margin: 0 0 12px; color: var(--accent-strong); }

.card {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 18px; box-shadow: var(--shadow);
}
.grid { display: grid; gap: 14px; }
.stats-grid { grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); }
.stat .label { font-size: 12px; color: var(--muted); font-weight: 500; }
.stat .value { font-size: 24px; font-weight: 700; margin-top: 4px; letter-spacing: -.5px; color: #fff; }
.stat .delta { font-size: 12px; margin-top: 3px; color: var(--muted); }
.delta.up { color: var(--green); }
.two-col { grid-template-columns: 1.4fr 1fr; align-items: start; }
@media (max-width: 980px) { .two-col { grid-template-columns: 1fr; } }

.btn {
  display: inline-flex; align-items: center; gap: 6px; background: var(--accent);
  color: var(--on-accent); border: none; border-radius: 8px; padding: 8px 14px;
  font-size: 13px; font-weight: 700; cursor: pointer; font-family: inherit;
}
.btn:hover { background: var(--accent-strong); }
.btn.secondary { background: var(--surface-2); color: var(--text); border: 1px solid var(--border); font-weight: 600; }
.btn.secondary:hover { background: #2a261e; border-color: var(--accent); }
.btn.small { padding: 5px 10px; font-size: 12px; }
.btn.ghost { background: transparent; color: var(--accent-strong); }

.badge { display: inline-block; padding: 2px 8px; border-radius: 99px; font-size: 11px; font-weight: 600; }
.badge.hot { background: var(--red-soft); color: var(--red); }
.badge.warm { background: var(--amber-soft); color: var(--amber); }
.badge.cool { background: var(--blue-soft); color: var(--blue); }
.badge.stage { background: var(--accent-soft); color: var(--accent-strong); }
.badge.won, .badge.accepted { background: var(--green-soft); color: var(--green); }
.badge.lost, .badge.rejected { background: var(--red-soft); color: var(--red); }
.badge.sent, .badge.viewed { background: var(--amber-soft); color: var(--amber); }
.badge.draft { background: #2a261e; color: var(--muted); }
.badge.ai { background: rgba(196, 181, 253, .13); color: #c4b5fd; }
.badge.high { background: var(--red-soft); color: var(--red); }
.badge.medium { background: var(--amber-soft); color: var(--amber); }
.badge.low { background: #2a261e; color: var(--muted); }

table { width: 100%; border-collapse: collapse; }
th { text-align: left; font-size: 11.5px; text-transform: uppercase; letter-spacing: .4px; color: var(--muted); padding: 8px 10px; border-bottom: 1px solid var(--border-soft); }
td { padding: 10px; border-bottom: 1px solid var(--border-soft); font-size: 13.5px; }
tr:last-child td { border-bottom: none; }
tr.rowlink:hover { background: var(--surface-2); cursor: pointer; }

/* funnel + source bars */
.bar-row { display: flex; align-items: center; gap: 10px; margin-bottom: 8px; font-size: 12.5px; }
.bar-row .lbl { width: 128px; color: var(--muted); flex-shrink: 0; }
.bar-track { flex: 1; background: #262218; border-radius: 5px; height: 18px; overflow: hidden; }
.bar-fill { height: 100%; background: var(--accent); border-radius: 5px; min-width: 2px; }
.bar-row .num { width: 30px; text-align: right; font-weight: 600; }

/* attention queue */
.attn { display: flex; flex-direction: column; gap: 10px; }
.attn-item { border: 1px solid var(--border-soft); border-radius: 10px; padding: 12px 14px; background: var(--surface-2); }
.attn-item:hover { border-color: var(--accent); }
.attn-item .top { display: flex; justify-content: space-between; align-items: center; gap: 8px; }
.attn-item .action { font-weight: 600; font-size: 13.5px; color: #fff; }
.attn-item .reason { color: var(--muted); font-size: 12.5px; margin-top: 4px; line-height: 1.45; }

/* pipeline board */
.board { display: flex; gap: 12px; overflow-x: auto; padding-bottom: 14px; align-items: flex-start; }
.col { width: 250px; flex-shrink: 0; background: #181613; border: 1px solid var(--border-soft); border-radius: var(--radius); padding: 10px; }
.col-head { display: flex; justify-content: space-between; align-items: baseline; padding: 2px 6px 10px; }
.col-head .name { font-weight: 600; font-size: 12.5px; color: var(--accent-strong); }
.col-head .meta { font-size: 11.5px; color: var(--muted); }
.col-cards { min-height: 40px; display: flex; flex-direction: column; gap: 8px; }
.lead-card {
  background: var(--surface); border: 1px solid var(--border); border-radius: 10px;
  padding: 11px 12px; cursor: grab; box-shadow: var(--shadow);
}
.lead-card:hover { border-color: var(--accent); }
.lead-card:active { cursor: grabbing; }
.lead-card .who { font-weight: 600; font-size: 13px; display: flex; justify-content: space-between; align-items: center; gap: 6px; color: #fff; }
.lead-card .svc { color: var(--muted); font-size: 12px; margin-top: 2px; }
.lead-card .meta { display: flex; justify-content: space-between; margin-top: 8px; font-size: 11.5px; color: var(--muted); }
.lead-card .val { font-weight: 700; color: var(--accent-strong); }
.sortable-ghost { opacity: .4; }
.lead-card .next-action { margin-top: 8px; padding-top: 8px; border-top: 1px solid var(--border-soft);
  font-size: 11.5px; color: var(--muted); display: flex; gap: 6px; align-items: center; line-height: 1.35; }

/* inbox */
.inbox-wrap { display: grid; grid-template-columns: 300px 1fr; gap: 14px; align-items: start; }
@media (max-width: 900px) { .inbox-wrap { grid-template-columns: 1fr; } }
.convo-list { padding: 6px; max-height: 78vh; overflow-y: auto; }
.convo { padding: 10px 12px; border-radius: 9px; display: block; }
.convo:hover { background: var(--surface-2); }
.convo.active { background: var(--accent-soft); border: 1px solid rgba(212, 175, 55, .3); padding: 9px 11px; }
.convo .name { font-weight: 600; font-size: 13px; display: flex; justify-content: space-between; color: #fff; }
.convo .name .time { font-weight: 400; color: var(--muted); font-size: 11.5px; }
.convo .snip { color: var(--muted); font-size: 12.5px; margin-top: 3px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.thread { display: flex; flex-direction: column; gap: 8px; padding: 6px 2px; max-height: 56vh; overflow-y: auto; }
.msg { max-width: 72%; padding: 9px 13px; border-radius: 14px; font-size: 13.5px; line-height: 1.45; }
.msg.in { background: var(--surface-2); border: 1px solid var(--border-soft); align-self: flex-start; border-bottom-left-radius: 4px; }
.msg.out { background: var(--accent); color: var(--on-accent); align-self: flex-end; border-bottom-right-radius: 4px; font-weight: 500; }
.msg.sys { background: transparent; color: var(--muted); align-self: center; font-size: 12px; }
.msg .tag { display: block; font-size: 10.5px; opacity: .75; margin-top: 4px; }

.composer { display: flex; gap: 8px; margin-top: 12px; }
.composer input[type=text] { flex: 1; }

/* forms */
input, select, textarea {
  font-family: inherit; font-size: 13.5px; padding: 8px 10px;
  border: 1px solid var(--border); border-radius: 8px; background: var(--surface-2);
  color: var(--text); width: 100%;
}
input:focus, select:focus, textarea:focus { outline: 2px solid var(--accent-soft); border-color: var(--accent); }
input::placeholder, textarea::placeholder { color: #766e58; }
label { font-size: 12px; font-weight: 600; color: var(--muted); display: block; margin-bottom: 4px; }
.field { margin-bottom: 12px; }
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.form-grid .full { grid-column: 1 / -1; }

/* timeline */
.timeline { display: flex; flex-direction: column; gap: 0; }
.tl-item { display: flex; gap: 12px; padding: 10px 0; border-bottom: 1px solid var(--border-soft); }
.tl-item:last-child { border-bottom: none; }
.tl-icon { width: 30px; height: 30px; border-radius: 8px; background: var(--surface-2); border: 1px solid var(--border-soft); display: flex; align-items: center; justify-content: center; flex-shrink: 0; font-size: 14px; }
.tl-body { flex: 1; min-width: 0; }
.tl-body .txt { font-size: 13.5px; line-height: 1.45; }
.tl-body .when { font-size: 11.5px; color: var(--muted); margin-top: 2px; }

/* AI panel */
.ai-panel { border: 1px solid rgba(212, 175, 55, .4); background: linear-gradient(180deg, rgba(212, 175, 55, .07), var(--surface)); }
.ai-panel h2 { color: var(--accent-strong); }

/* modal */
dialog { border: 1px solid var(--border); background: var(--surface); color: var(--text); border-radius: 14px; padding: 22px; width: 480px; max-width: 92vw; box-shadow: 0 20px 50px rgba(0,0,0,.6); }
dialog::backdrop { background: rgba(0, 0, 0, .65); }
dialog h2 { color: var(--accent-strong); }

/* estimate builder rows */
.item-row { display: grid; grid-template-columns: 1fr 110px 64px 96px 30px; gap: 8px; margin-bottom: 8px; align-items: center; }

/* widget page */
.widget-page { min-height: 100vh; display: flex; align-items: center; justify-content: center; background: #0b0a08; padding: 20px; }
.widget-card { background: var(--surface); border: 1px solid var(--border); border-radius: 16px; padding: 28px; width: 420px; max-width: 100%; color: var(--text); }
.widget-card h1 { color: #fff; }

code { background: var(--surface-2); border: 1px solid var(--border-soft); border-radius: 5px; padding: 1px 5px; font-size: 12px; color: var(--accent-strong); }

/* ---- phones & small tablets: sidebar becomes a top bar ---- */
@media (max-width: 820px) {
  .layout { flex-direction: column; }
  .sidebar {
    width: 100%; height: auto; position: static; padding: 12px 12px 8px;
    border-right: none; border-bottom: 1px solid #262115;
  }
  .brand { flex-direction: row; gap: 6px; padding: 0 4px; font-size: 16px; }
  .brand-crown { width: 20px; height: 14px; }
  .org { border-bottom: none; padding: 2px 4px 8px; text-align: left; }
  .trial-pill { margin: 0 0 8px; font-size: 11.5px; padding: 6px 8px; }
  .sidebar nav { flex-direction: row; overflow-x: auto; gap: 4px; padding-bottom: 4px; -webkit-overflow-scrolling: touch; }
  .sidebar nav a { white-space: nowrap; padding: 7px 10px; font-size: 13px; flex-shrink: 0; }
  .sidebar-foot { margin-top: 4px; padding: 4px; font-size: 12px; display: flex; flex-wrap: wrap; gap: 4px 14px; align-items: center; }
  .sidebar-foot br { display: none; }
  .sidebar-foot > div { border: none !important; margin: 0 !important; padding: 0 !important; margin-left: auto !important; }
  .content { padding: 16px 14px 32px; }
  h1 { font-size: 19px; }
  .card { overflow-x: auto; }
  .form-grid { grid-template-columns: 1fr; }
  .item-row { grid-template-columns: 1fr 1fr; }
  .item-row input:first-child { grid-column: 1 / -1; }
  .msg { max-width: 88%; }
  .stat .value { font-size: 22px; }
  .page-head .btn, .page-head form { width: 100%; }
  .page-head .btn { justify-content: center; }
}
