:root {
  /* Obsidian dark theme values */
  --bg: #1e1e1e;
  --panel: rgba(38, 38, 38, 0.92);
  --panel-solid: #262626;
  --line: #363636;
  --line-strong: #4a4a4a;
  --text: #dadada;
  --muted: #999999;
  --accent: #8a5cf5;
  --money: #e0ac00;
  --danger: #fb464c;
  --ok: #44cf6e;
  --radius: 8px;
  --font: ui-sans-serif, -apple-system, BlinkMacSystemFont, system-ui, "Segoe UI", Roboto, Inter, sans-serif;
  --mono: ui-monospace, SFMono-Regular, Menlo, monospace;
  color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  background: var(--bg);
  color: var(--text);
  font: 14px/1.45 var(--font);
  -webkit-font-smoothing: antialiased;
  overflow: hidden;
  overscroll-behavior: none;
}
[hidden] { display: none !important; }
button { font: inherit; color: inherit; }
.srOnly { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

/* ---------- brand ---------- */
.brand { display: flex; align-items: center; gap: 9px; font-weight: 650; letter-spacing: -0.01em; white-space: nowrap; }
.brandDot {
  width: 10px; height: 10px; border-radius: 50%;
  background: var(--accent);
  box-shadow: 0 0 0 4px rgba(138, 92, 245, 0.18);
}

/* ---------- login ---------- */
.login { height: 100%; display: grid; place-items: center; padding: 16px; }
.loginBox { width: min(320px, 100%); display: grid; gap: 12px; }
.loginBox .brand { font-size: 18px; margin-bottom: 8px; justify-content: center; }
input, textarea, select {
  width: 100%;
  background: rgba(255, 255, 255, 0.04);
  border: 1px solid var(--line-strong);
  border-radius: 10px;
  color: var(--text);
  font: inherit;
  padding: 11px 12px;
}
input:focus, textarea:focus, select:focus { outline: none; border-color: var(--accent); background: rgba(255, 255, 255, 0.06); }
button[type="submit"] {
  border: 0; border-radius: 10px; padding: 11px 14px;
  background: var(--accent); color: #fff; font-weight: 600; cursor: pointer;
}
button[type="submit"]:hover { filter: brightness(1.08); }
.error { color: var(--danger); margin: 0; min-height: 1.2em; font-size: 13px; }

/* ---------- graph ---------- */
.app, .graph { position: fixed; inset: 0; }
.graph { touch-action: none; }

/* ---------- top bar ---------- */
.bar {
  position: fixed; top: 0; left: 0; right: 0;
  display: flex; align-items: center; gap: 10px; flex-wrap: wrap;
  padding: max(12px, env(safe-area-inset-top)) 16px 12px;
  pointer-events: none;
  background: linear-gradient(var(--bg) 0%, rgba(30, 30, 30, 0.75) 60%, transparent);
}
.bar > * { pointer-events: auto; }
.bar .brand { margin-right: 6px; }

.seg {
  display: inline-flex; align-items: center; gap: 2px; padding: 3px;
  background: var(--panel); border: 1px solid var(--line); border-radius: 999px;
  backdrop-filter: blur(12px); -webkit-backdrop-filter: blur(12px);
}
.seg button {
  border: 0; background: none; cursor: pointer;
  padding: 6px 12px; border-radius: 999px; color: var(--muted); white-space: nowrap;
}
.seg button b { font-weight: 600; font-variant-numeric: tabular-nums; margin-left: 4px; opacity: 0.7; }
.seg button:hover { color: var(--text); }
.seg button[aria-selected="true"], .seg button[aria-checked="true"] { background: rgba(255, 255, 255, 0.09); color: var(--text); }
.seg button[aria-selected="true"] b { color: var(--accent); opacity: 1; }
.segLabel { color: var(--muted); font-size: 12px; padding: 0 6px 0 10px; }

.tools { display: flex; gap: 8px; margin-left: auto; }
.search { position: relative; }
.search input { width: 200px; padding: 8px 12px; border-radius: 999px; background: var(--panel); border-color: var(--line); backdrop-filter: blur(12px); }
.searchResults {
  position: absolute; right: 0; top: calc(100% + 6px); width: 260px; margin: 0; padding: 4px; list-style: none;
  background: var(--panel-solid); border: 1px solid var(--line-strong); border-radius: var(--radius);
  box-shadow: 0 12px 40px rgba(0, 0, 0, 0.5);
}
.searchResults button {
  width: 100%; display: flex; align-items: center; gap: 8px; text-align: left;
  border: 0; background: none; padding: 8px 10px; border-radius: 8px; cursor: pointer;
}
.searchResults button:hover { background: rgba(255, 255, 255, 0.06); }
.searchResults i, .legend i, .facts i { width: 8px; height: 8px; border-radius: 50%; flex: none; display: inline-block; }
.searchResults small { margin-left: auto; color: var(--muted); font-size: 11px; }

.iconBtn {
  width: 36px; height: 36px; display: grid; place-items: center; flex: none;
  border: 1px solid var(--line); border-radius: 50%; background: var(--panel); cursor: pointer;
  backdrop-filter: blur(12px);
}
.iconBtn:hover { border-color: var(--line-strong); background: rgba(255, 255, 255, 0.08); }
#addBtn { color: var(--accent); }

/* ---------- legend / status ---------- */
.legend {
  position: fixed; left: 16px; bottom: max(16px, env(safe-area-inset-bottom));
  display: flex; flex-wrap: wrap; gap: 6px 14px; margin: 0; padding: 0; list-style: none;
  max-width: calc(100% - 64px); color: var(--muted); font-size: 12px; pointer-events: none;
}
.legend li { display: flex; align-items: center; gap: 6px; }
.legend i.ring { background: none; border: 1.5px dashed var(--muted); width: 9px; height: 9px; }
.live {
  position: fixed; right: 18px; bottom: max(20px, env(safe-area-inset-bottom));
  width: 8px; height: 8px; border-radius: 50%; background: var(--muted); opacity: 0.6;
}
.live.on { background: var(--ok); opacity: 1; box-shadow: 0 0 10px rgba(79, 209, 161, 0.7); }
.empty {
  position: fixed; left: 50%; top: 50%; transform: translate(-50%, -50%); margin: 0;
  color: var(--muted); text-align: center; padding: 0 24px; width: min(360px, 100%);
}
.empty b { color: var(--accent); }

/* ---------- card ---------- */
.card {
  position: fixed; top: 76px; right: 16px; bottom: 16px; width: 360px;
  display: flex; flex-direction: column; gap: 12px; overflow-y: auto;
  padding: 22px 20px 20px;
  background: var(--panel); border: 1px solid var(--line); border-radius: 16px;
  backdrop-filter: blur(18px); -webkit-backdrop-filter: blur(18px);
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.45);
  animation: cardIn 0.22s ease-out;
}
@keyframes cardIn { from { opacity: 0; transform: translateX(12px); } }
.cardGrip { display: none; }
.cardClose { position: absolute; top: 14px; right: 14px; width: 30px; height: 30px; }
.cardKind { margin: 0; font-size: 11px; letter-spacing: 0.08em; text-transform: uppercase; color: var(--muted); }
.cardKind[data-kind="customer"] { color: var(--ok); }
.cardKind[data-kind="prospect"] { color: var(--money); }
.cardKind[data-kind="former"] { color: var(--muted); }
.card h2 { margin: -6px 40px 0 0; font-size: 22px; line-height: 1.2; letter-spacing: -0.02em; font-weight: 650; }
.sectorField { position: relative; margin-top: -6px; }
.sectorField i { position: absolute; left: 12px; top: 50%; width: 9px; height: 9px; margin-top: -4.5px; border-radius: 50%; }
.sectorField input { padding-left: 30px; }
.facts { display: flex; flex-wrap: wrap; gap: 6px; margin: 0; padding: 0; list-style: none; }
.facts li {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 4px 10px; border: 1px solid var(--line); border-radius: 999px; font-size: 12.5px;
}
.facts li.money { color: var(--money); }
.facts li.muted { color: var(--muted); }

.switch { display: flex; align-items: center; gap: 12px; cursor: pointer; padding: 10px 0; border-top: 1px solid var(--line); border-bottom: 1px solid var(--line); font-weight: 550; }
.switch input { position: absolute; opacity: 0; width: 1px; height: 1px; }
.switchTrack { width: 40px; height: 24px; border-radius: 999px; background: rgba(255, 255, 255, 0.12); position: relative; transition: background 0.2s; flex: none; }
.switchTrack::after { content: ""; position: absolute; top: 3px; left: 3px; width: 18px; height: 18px; border-radius: 50%; background: #fff; transition: transform 0.2s; }
.switch input:checked + .switchTrack { background: var(--ok); }
.switch input:checked + .switchTrack::after { transform: translateX(16px); }
.switch input:focus-visible + .switchTrack { outline: 2px solid var(--accent); outline-offset: 2px; }

.fieldLabel { display: flex; justify-content: space-between; color: var(--muted); font-size: 12px; }
.saveState { color: var(--muted); font-style: italic; }
.card textarea { resize: vertical; min-height: 140px; line-height: 1.5; }
.accounts { display: flex; flex-wrap: wrap; gap: 6px; }
.accounts .fieldLabel { width: 100%; }
.accounts code { font: 11.5px var(--mono); color: var(--muted); background: rgba(255, 255, 255, 0.04); padding: 3px 7px; border-radius: 6px; }
.linkBtn { border: 0; background: none; color: var(--muted); cursor: pointer; padding: 6px 0; text-align: left; }
.linkBtn:hover { color: var(--text); }
.linkBtn.danger { color: var(--danger); opacity: 0.8; margin-top: auto; }

/* ---------- dialog ---------- */
.dialog {
  width: min(420px, calc(100% - 32px)); padding: 0;
  background: var(--panel-solid); color: var(--text);
  border: 1px solid var(--line-strong); border-radius: 16px;
  box-shadow: 0 30px 80px rgba(0, 0, 0, 0.6);
}
.dialog::backdrop { background: rgba(0, 0, 0, 0.55); backdrop-filter: blur(3px); }
.dialog form { display: grid; gap: 12px; padding: 22px; }
.dialog h2 { margin: 0 0 4px; font-size: 18px; }
.dialog label { display: grid; gap: 6px; color: var(--muted); font-size: 12px; }
.dialog .row { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.dialog .check { display: flex; align-items: center; gap: 8px; font-size: 13px; color: var(--text); }
.dialog .check input { width: auto; }
.dialogActions { display: flex; justify-content: flex-end; align-items: center; gap: 16px; }

/* ---------- mobile ---------- */
@media (max-width: 760px) {
  .bar { gap: 8px; padding-left: 12px; padding-right: 12px; }
  .brandText { display: none; }
  .bar .brand { order: 0; margin: 0; }
  .tools { order: 1; margin-left: auto; }
  .search input { width: 150px; }
  .seg { order: 2; }
  .seg--view { flex: 1 1 100%; justify-content: space-between; }
  .seg--view button { flex: 1; padding: 7px 4px; font-size: 13px; }
  .seg--quiet { flex: 1 1 100%; justify-content: space-between; }
  .seg--quiet button { flex: 1; padding: 6px 4px; font-size: 13px; }
  .segLabel { display: none; }
  .searchResults { width: min(280px, calc(100vw - 24px)); }

  .card {
    top: auto; left: 0; right: 0; bottom: 0; width: auto; max-height: 62vh;
    border-radius: 18px 18px 0 0; border-bottom: 0;
    padding: 12px 16px max(18px, env(safe-area-inset-bottom));
    animation-name: sheetIn;
  }
  @keyframes sheetIn { from { transform: translateY(24px); opacity: 0; } }
  .cardGrip { display: block; width: 38px; height: 4px; border-radius: 4px; background: var(--line-strong); margin: 0 auto 4px; flex: none; }
  .card textarea { min-height: 96px; }
  body.hasCard .legend, body.hasCard .live { display: none; }
}

@media (prefers-reduced-motion: reduce) {
  .card { animation: none; }
}
