:root {
  --bg: #ffffff;
  --panel: #ffffff;
  --text: #1f2933;
  --muted: #6b7682;
  --line: #e3e7ec;
  --accent: #155eef;
  --error: #c0262d;
  --shadow: 0 6px 24px rgba(16, 24, 40, .12);
  font: 14px/1.4 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  color: var(--text);
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; background: var(--bg); }
[hidden] { display: none !important; }
.muted { color: var(--muted); }
.small { font-size: 12px; }
.error { color: var(--error); min-height: 1.2em; }
button, .btn { font: inherit; cursor: pointer; border: 1px solid var(--line); background: #fff; border-radius: 6px; padding: 6px 10px; color: var(--text); text-decoration: none; display: inline-block; }
button.primary, .login-card button { background: var(--accent); border-color: var(--accent); color: #fff; }
button.link { border: 0; background: none; color: var(--accent); padding: 2px 4px; }
input, select { font: inherit; padding: 4px 6px; border: 1px solid var(--line); border-radius: 6px; background: #fff; color: var(--text); }

/* login */
.login { display: grid; place-items: center; min-height: 100%; padding: 16px; background: #f5f7fa; }
.login-card { width: min(380px, 100%); background: var(--panel); padding: 24px; border-radius: 12px; box-shadow: var(--shadow); display: grid; gap: 12px; }
.login-card h1 { margin: 0; font-size: 20px; }
.login-card label { display: grid; gap: 4px; }
.login-card button { padding: 9px; }
.chooser-list { list-style: none; padding: 0; margin: 0; display: grid; gap: 8px; }
.chooser-list button { width: 100%; text-align: left; }

/* layout */
.app { position: relative; display: grid; grid-template-columns: 260px 1fr; grid-template-rows: auto 1fr; height: 100%; }
.bar { grid-column: 1 / -1; display: flex; flex-wrap: wrap; align-items: center; gap: 8px 16px; padding: 8px 12px; border-bottom: 1px solid var(--line); }
.bar .title { white-space: nowrap; }
.filters { display: flex; flex-wrap: wrap; gap: 8px 12px; align-items: center; flex: 1; }
.filters label { display: flex; gap: 6px; align-items: center; color: var(--muted); }
.side { border-right: 1px solid var(--line); padding: 12px; overflow: auto; display: flex; flex-direction: column; gap: 12px; }
.map { position: relative; min-height: 0; }

.legend-head { display: flex; justify-content: space-between; align-items: center; font-weight: 600; margin-bottom: 6px; }
#legend { list-style: none; margin: 0; padding: 0; display: grid; gap: 2px; }
#legend li { display: flex; align-items: center; gap: 8px; padding: 4px 6px; border-radius: 6px; cursor: pointer; user-select: none; }
#legend li:hover { background: #f2f4f7; }
#legend li.off { opacity: .4; }
#legend .dot { width: 12px; height: 12px; border-radius: 50%; flex: none; }
#legend .n { margin-left: auto; font-variant-numeric: tabular-nums; color: var(--muted); }
.hollow { display: inline-block; width: 10px; height: 10px; border: 2px solid var(--muted); border-radius: 50%; vertical-align: -1px; }

/* panels */
.panel { position: absolute; z-index: 5; background: var(--panel); box-shadow: var(--shadow); border-radius: 10px; display: flex; flex-direction: column; overflow: hidden; }
.panel-head { display: flex; justify-content: space-between; align-items: center; gap: 8px; padding: 10px 12px; border-bottom: 1px solid var(--line); }
.panel .close { border: 0; font-size: 20px; line-height: 1; padding: 0 4px; }
.card { right: 12px; top: 64px; width: min(420px, calc(100% - 24px)); max-height: calc(100% - 76px); }
#card-body { overflow: auto; padding: 12px; display: grid; gap: 14px; }
#list { left: 272px; bottom: 12px; width: min(680px, calc(100% - 284px)); max-height: 45%; }
#list-note { margin: 6px 12px 0; }
.table-wrap { overflow: auto; }
#list-table { width: 100%; border-collapse: collapse; }
#list-table th, #list-table td { text-align: left; padding: 6px 12px; border-bottom: 1px solid var(--line); vertical-align: top; }
#list-table th { position: sticky; top: 0; background: #f8f9fb; font-weight: 600; }
#list-table tbody tr { cursor: pointer; }
#list-table tbody tr:hover { background: #f2f6ff; }

.chip { display: inline-flex; align-items: center; gap: 6px; padding: 2px 8px; border-radius: 999px; background: #f2f4f7; font-size: 12px; white-space: nowrap; }
.chip .dot { width: 8px; height: 8px; border-radius: 50%; }
.kv { display: grid; grid-template-columns: auto 1fr; gap: 4px 12px; }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; }
.section h3 { font-size: 12px; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); margin: 0 0 6px; }
.people, .timeline { list-style: none; margin: 0; padding: 0; display: grid; gap: 8px; }
.people li { border: 1px solid var(--line); border-radius: 8px; padding: 8px; }
.people .row { display: flex; justify-content: space-between; gap: 8px; }
.timeline li { display: grid; grid-template-columns: 88px 1fr; gap: 8px; }
.timeline li.muted { display: block; }
.timeline .when { color: var(--muted); font-variant-numeric: tabular-nums; }
.actions { display: flex; flex-wrap: wrap; gap: 8px; }
.note { background: #fff8e6; border: 1px solid #f5dfa3; border-radius: 8px; padding: 6px 8px; font-size: 12px; }
.maplibregl-popup-content { font: 12px/1.4 system-ui, sans-serif; padding: 8px 10px; }

/* phone: map fills the screen; side legend collapses to a strip; panels become bottom sheets */
@media (max-width: 760px) {
  .app { grid-template-columns: 1fr; grid-template-rows: auto auto 1fr; }
  .side { border-right: 0; border-bottom: 1px solid var(--line); padding: 8px 12px; flex-direction: row; overflow-x: auto; align-items: flex-start; }
  .side .legend p { display: none; }
  #legend { grid-auto-flow: column; }
  #legend li .label { display: none; }
  .legend-head { display: none; }
  #list-btn { white-space: nowrap; order: -1; }
  .card, #list { left: 0; right: 0; bottom: 0; top: auto; width: 100%; max-height: 70%; border-radius: 14px 14px 0 0; }
}
.map-error { margin: 24px; max-width: 520px; color: var(--muted); }

/* v0.2: banner, modal, deals, mapping */
.app { grid-template-rows: auto auto 1fr; }
.banner { grid-column: 1 / -1; background: #eef4ff; border-bottom: 1px solid #c9dafc; padding: 8px 12px; font-size: 13px; }
.banner:empty { display: none; }
.side, .map { grid-row: 3; }
.modal-wrap { position: absolute; inset: 0; background: rgba(16, 24, 40, .35); z-index: 20; display: grid; place-items: center; padding: 16px; }
.modal { background: var(--panel); border-radius: 12px; box-shadow: var(--shadow); width: min(640px, 100%); max-height: 90%; display: flex; flex-direction: column; }
.modal-body { padding: 14px; overflow: auto; display: grid; gap: 12px; }
.modal-body label { display: grid; gap: 4px; }
.warn { background: #fff4e5; border: 1px solid #f5c27a; border-radius: 8px; padding: 8px 10px; font-size: 13px; }
.ok { background: #ecfdf3; border: 1px solid #a6e9c1; border-radius: 8px; padding: 8px 10px; font-size: 13px; }
.counts { display: grid; grid-template-columns: repeat(auto-fit, minmax(120px, 1fr)); gap: 8px; }
.counts div { background: #f5f7fa; border-radius: 8px; padding: 8px; }
.counts strong { display: block; font-size: 18px; }
.deals { list-style: none; margin: 0; padding: 0; display: grid; gap: 6px; }
.deals li { border: 1px solid var(--line); border-radius: 8px; padding: 6px 8px; font-size: 13px; }
.deals .closed { opacity: .65; }
.mapping-pipe { border: 1px solid var(--line); border-radius: 8px; padding: 8px 10px; }
.mapping-pipe h4 { margin: 0 0 6px; display: flex; justify-content: space-between; align-items: center; gap: 8px; }
.mapping-pipe .row { display: grid; grid-template-columns: 1fr 190px 60px; gap: 8px; align-items: center; padding: 3px 0; font-size: 13px; }
.mapping-pipe.off .row { opacity: .4; }
.tag-name { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; background: #f2f4f7; padding: 2px 6px; border-radius: 4px; }
@media (max-width: 760px) { .app { grid-template-rows: auto auto auto 1fr; } .side, .map { grid-row: auto; } .mapping-pipe .row { grid-template-columns: 1fr 140px; } .mapping-pipe .row .muted { display: none; } }
.mapping-pipe h4 label { display: flex; gap: 6px; align-items: center; font-weight: 400; white-space: nowrap; }
