:root {
  --bg: #f4f7fb; --panel: #ffffff; --border: #dce7f5;
  --text: #0f172a; --muted: #64748b; --accent: #2781f6;
  --good: #16a34a; --warn: #d97706; --bad: #dc2626;
}
* { box-sizing: border-box; margin: 0; }
body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  background: var(--bg); color: var(--text); line-height: 1.45;
}
.hidden { display: none !important; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.error { color: var(--bad); font-size: 14px; margin-top: 8px; }

/* Login */
#login { display: flex; min-height: 100vh; align-items: center; justify-content: center; }
.login-card {
  background: var(--panel); border: 1px solid var(--border); border-radius: 16px;
  padding: 36px; width: 380px; box-shadow: 0 12px 32px rgba(15,23,42,.06);
}
.login-card h1 { font-size: 22px; margin-bottom: 8px; }
.login-card p { margin-bottom: 16px; font-size: 14px; }
.login-card input {
  width: 100%; padding: 10px 12px; border: 1px solid var(--border);
  border-radius: 8px; font-size: 14px; margin-bottom: 12px;
}
button {
  background: var(--accent); color: #fff; border: none; border-radius: 8px;
  padding: 10px 16px; font-size: 14px; cursor: pointer; font-weight: 600;
}
button.ghost { background: transparent; color: var(--muted); border: 1px solid var(--border); }

/* App layout */
#app { max-width: 1080px; margin: 0 auto; padding: 24px 16px 60px; }
header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 20px; }
header h1 { font-size: 20px; }
.header-right { display: flex; gap: 10px; align-items: center; }
select { padding: 8px 10px; border: 1px solid var(--border); border-radius: 8px; font-size: 14px; background: #fff; }

.cards { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 12px; margin-bottom: 20px; }
.card {
  background: var(--panel); border: 1px solid var(--border); border-radius: 12px;
  padding: 14px 16px;
}
.card .value { font-size: 24px; font-weight: 700; }
.card .label { font-size: 12px; color: var(--muted); margin-top: 2px; }

.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
@media (max-width: 860px) { .grid2 { grid-template-columns: 1fr; } }

.panel {
  background: var(--panel); border: 1px solid var(--border); border-radius: 12px;
  padding: 18px; margin-bottom: 16px; overflow-x: auto;
}
.panel h2 { font-size: 15px; margin-bottom: 4px; }
.panel .small { margin-bottom: 10px; }

table { width: 100%; border-collapse: collapse; font-size: 14px; }
th { text-align: left; color: var(--muted); font-size: 12px; font-weight: 600;
     padding: 6px 8px; border-bottom: 1px solid var(--border); }
td { padding: 8px; border-bottom: 1px solid #eef3fa; vertical-align: top; }
tr.clickable { cursor: pointer; }
tr.clickable:hover td { background: #f0f6ff; }
.pill { display: inline-block; padding: 1px 8px; border-radius: 999px; font-size: 12px;
        background: #eef3fa; color: var(--muted); }
.pill.warn { background: #fef3c7; color: var(--warn); }
.pill.bad { background: #fee2e2; color: var(--bad); }
.empty { color: var(--muted); font-size: 14px; padding: 12px 8px; }

/* Contact search */
.search-panel { position: relative; padding: 6px; border: 2px solid var(--accent); }
#contact-search { width: 100%; border: none; outline: none; font-size: 17px;
  padding: 14px 16px; background: transparent; }
#contact-search::placeholder { color: var(--muted); }
.search-results { position: absolute; left: 8px; right: 8px; top: 100%; z-index: 30;
  background: #fff; border: 1px solid var(--border); border-radius: 10px;
  box-shadow: 0 12px 32px rgba(15,23,42,.12); overflow: hidden; }
.search-results .hit { padding: 10px 14px; cursor: pointer; display: flex;
  justify-content: space-between; gap: 10px; font-size: 14px; }
.search-results .hit:hover { background: #f0f6ff; }

/* Contact 360 drawer */
#drawer-backdrop { position: fixed; inset: 0; background: rgba(15,23,42,.35); z-index: 40; }
#drawer { position: fixed; top: 0; right: 0; bottom: 0; width: min(560px, 94vw);
  background: var(--bg); z-index: 50; overflow-y: auto; padding: 20px 18px 40px;
  box-shadow: -16px 0 40px rgba(15,23,42,.25); }
.drawer-head { display: flex; justify-content: space-between; align-items: start; margin-bottom: 12px; }
.drawer-head h2 { font-size: 19px; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip { background: #eef3fa; color: var(--muted); border-radius: 999px;
  padding: 2px 10px; font-size: 12px; }
.contact-link { color: var(--accent); cursor: pointer; text-decoration: none; }
.contact-link:hover { text-decoration: underline; }
.mini-hm .cell { border-radius: 1px; }

/* Tabs */
.tabs { display: flex; gap: 4px; background: #eef3fa; border-radius: 8px; padding: 3px; }
.tab { background: transparent; color: var(--muted); font-weight: 600; padding: 7px 14px; }
.tab.active { background: #fff; color: var(--text); box-shadow: 0 1px 3px rgba(15,23,42,.08); }
h3.sub { font-size: 13px; color: var(--muted); margin: 14px 0 6px; }

/* Pipeline */
.pipeline { display: grid; grid-auto-flow: column; grid-auto-columns: minmax(180px, 1fr);
            gap: 10px; overflow-x: auto; padding-bottom: 6px; }
.stage-col { background: #f8fafd; border: 1px solid var(--border); border-radius: 10px; padding: 10px; }
.stage-col h4 { font-size: 12px; color: var(--muted); margin-bottom: 8px; }
.deal-card { background: #fff; border: 1px solid var(--border); border-radius: 8px;
             padding: 8px 10px; margin-bottom: 8px; font-size: 13px; }
.deal-card .val { color: var(--muted); font-size: 12px; }
.deal-card .actions { display: flex; gap: 4px; margin-top: 6px; flex-wrap: wrap; }
.deal-card .actions button { padding: 2px 8px; font-size: 11px; border-radius: 6px; }
.deal-card .actions .win { background: var(--good); }
.deal-card .actions .lose { background: var(--bad); }
.deal-form { display: flex; gap: 8px; flex-wrap: wrap; }
.deal-form input { padding: 8px 10px; border: 1px solid var(--border); border-radius: 8px; font-size: 13px; }
.export-links { display: flex; gap: 14px; flex-wrap: wrap; }
.export-links a { color: var(--accent); font-size: 14px; font-weight: 600; text-decoration: none; }

/* Heatmap */
.hm { display: grid; grid-template-columns: 36px repeat(24, 1fr); gap: 2px; font-size: 10px; }
.hm .lbl { color: var(--muted); align-self: center; }
.hm .cell { aspect-ratio: 1; border-radius: 2px; background: #eef3fa; }
.hm-hours { display: grid; grid-template-columns: 36px repeat(24, 1fr); gap: 2px;
            font-size: 9px; color: var(--muted); margin-top: 4px; }

/* Volume chart */
#volume svg { width: 100%; height: 160px; display: block; }
.legend { display: flex; gap: 16px; font-size: 12px; color: var(--muted); margin-top: 6px; }
.legend span::before { content: ""; display: inline-block; width: 10px; height: 10px;
                       border-radius: 2px; margin-right: 5px; vertical-align: -1px; }
.legend .recv::before { background: var(--accent); }
.legend .sent::before { background: var(--good); }
