:root {
  --bg: #0b0d12;
  --panel: #13161e;
  --panel-2: #1a1e28;
  --line: #262b38;
  --text: #e7e9ee;
  --muted: #8b92a3;
  --accent: #f59e0b;
  --danger: #ef4444;
  --radius: 10px;
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}
* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { margin: 0; height: 100%; background: var(--bg); color: var(--text); font: 14px/1.45 var(--font); overflow: hidden; }
button, input, textarea, select { font: inherit; color: inherit; }
button {
  background: var(--panel-2); border: 1px solid var(--line); border-radius: 8px;
  padding: 7px 12px; cursor: pointer; white-space: nowrap;
}
button:hover { border-color: #3a4152; }
button.primary { background: var(--accent); border-color: var(--accent); color: #111; font-weight: 600; }
button.ghost { background: none; border-color: transparent; color: var(--muted); }
button.danger { color: var(--danger); }
input, textarea, select {
  background: var(--bg); border: 1px solid var(--line); border-radius: 8px; padding: 8px 10px; width: 100%;
}
textarea { resize: vertical; min-height: 70px; }
input:focus, textarea:focus, select:focus { outline: none; border-color: var(--accent); }

#graph { position: fixed; inset: 0; }

#bar {
  position: fixed; top: 0; left: 0; right: 0; z-index: 10;
  display: flex; gap: 8px; align-items: center;
  padding: calc(10px + env(safe-area-inset-top)) 12px 10px;
  background: linear-gradient(var(--bg) 60%, transparent);
}
.brand { font-weight: 700; letter-spacing: .02em; margin-right: 4px; }
.search { position: relative; flex: 1; max-width: 320px; margin-left: auto; }
#results {
  position: absolute; top: 40px; left: 0; right: 0; margin: 0; padding: 4px; list-style: none;
  background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); max-height: 50vh; overflow: auto;
}
#results li { padding: 8px 10px; border-radius: 6px; cursor: pointer; display: flex; gap: 8px; align-items: center; }
#results li:hover, #results li.on { background: var(--panel-2); }
#menu {
  position: absolute; top: calc(52px + env(safe-area-inset-top)); right: 12px; display: flex; flex-direction: column; gap: 2px;
  background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 6px; min-width: 200px;
}
#menu button { background: none; border: none; text-align: left; }
#menu button:hover { background: var(--panel-2); }

#legend {
  position: fixed; left: 12px; bottom: calc(12px + env(safe-area-inset-bottom)); z-index: 5;
  display: flex; gap: 10px; flex-wrap: wrap; color: var(--muted); font-size: 12px; pointer-events: none;
}
.dot { display: inline-block; width: 9px; height: 9px; border-radius: 50%; margin-right: 5px; vertical-align: 0; }
#status {
  position: fixed; right: 12px; bottom: calc(12px + env(safe-area-inset-bottom)); z-index: 5;
  color: var(--muted); font-size: 12px;
}

#panel {
  position: fixed; z-index: 20; top: 62px; right: 12px; bottom: 12px; width: 400px;
  background: var(--panel); border: 1px solid var(--line); border-radius: 14px;
  display: flex; flex-direction: column; box-shadow: 0 10px 40px rgba(0,0,0,.5);
}
.grip { display: none; }
#panel-body { overflow: auto; padding: 16px; flex: 1; }
.p-head { display: flex; gap: 8px; align-items: center; margin-bottom: 12px; }
.p-head .title { font-size: 18px; font-weight: 650; border-color: transparent; background: none; padding: 4px 6px; }
.p-head .title:focus { border-color: var(--line); background: var(--bg); }
.kind-row { display: flex; gap: 8px; align-items: center; margin-bottom: 12px; }
.kind-row select { width: auto; }
.chk { display: flex; gap: 6px; align-items: center; color: var(--muted); margin-left: auto; cursor: pointer; }
.chk input { width: auto; }
.sec { margin-top: 18px; }
.sec h3 { font-size: 11px; text-transform: uppercase; letter-spacing: .08em; color: var(--muted); margin: 0 0 8px; font-weight: 600; }
.row { display: flex; gap: 8px; }
.row > * { min-width: 0; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 8px; }
.chip {
  display: inline-flex; align-items: center; gap: 6px; padding: 4px 6px 4px 10px; border-radius: 999px;
  background: var(--panel-2); border: 1px solid var(--line); font-size: 13px; cursor: pointer;
}
.chip .x { border: none; background: none; padding: 0 4px; color: var(--muted); }
.chip .x:hover { color: var(--danger); }
.note { border-left: 2px solid var(--line); padding: 2px 0 2px 10px; margin: 10px 0; }
.note .meta { display: flex; justify-content: space-between; color: var(--muted); font-size: 12px; }
.note .meta button { padding: 0 4px; font-size: 12px; }
.note .text { white-space: pre-wrap; word-break: break-word; margin-top: 2px; }
.muted { color: var(--muted); }
.saved { color: var(--muted); font-size: 12px; min-height: 18px; }
.foot { display: flex; justify-content: space-between; margin-top: 24px; }
.datenav { display: flex; gap: 6px; align-items: center; flex: 1; }
.datenav input { width: auto; flex: 1; }
.hist-item { padding: 10px; border-radius: 8px; cursor: pointer; border: 1px solid transparent; }
.hist-item:hover { background: var(--panel-2); border-color: var(--line); }
.hist-item .d { font-weight: 600; }
.hist-item .s { color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
label.f { display: block; font-size: 12px; color: var(--muted); margin: 12px 0 4px; }

#signin { position: fixed; inset: 0; z-index: 50; display: grid; place-items: center; background: rgba(11,13,18,.85); }
#signin .card { background: var(--panel); border: 1px solid var(--line); border-radius: 16px; padding: 28px; text-align: center; width: min(340px, 90vw); }
#signin h1 { font-size: 20px; margin: 0 0 18px; }
.err { color: var(--danger); font-size: 13px; min-height: 18px; }

.tooltip-node { font: 12px var(--font); }

@media (max-width: 720px) {
  .brand { display: none; }
  .search { max-width: none; margin-left: 0; }
  #btn-add { padding: 7px 10px; }
  #legend { display: none; }
  #panel {
    top: auto; left: 0; right: 0; bottom: 0; width: auto; max-height: 72vh; height: 72vh;
    border-radius: 16px 16px 0 0; border-bottom: none; padding-bottom: env(safe-area-inset-bottom);
  }
  #panel.min { height: 120px; }
  .grip { display: block; width: 44px; height: 5px; border-radius: 3px; background: var(--line); margin: 8px auto 0; cursor: pointer; }
  input, textarea, select { font-size: 16px; } /* prevents zoom on focus */
}
