/* Theme tokens and layout for Kith. */

/* Star colours run fresh -> due -> overdue -> lost; graph.js reads them from here. */
:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #0b1020;
  --panel: #121a33;
  --text: #e8ecf8;
  --muted: #8a93b2;
  --border: rgba(255, 255, 255, 0.10);
  --hover: rgba(255, 255, 255, 0.05);
  --line: rgba(180, 195, 255, 0.20);
  --accent: #ffd56b;
  --star-fresh: #ffd56b;
  --star-due: #f4f1ea;
  --star-overdue: #7fa6ff;
  --star-lost: #4f587a;
}

:root[data-theme="light"] {
  color-scheme: light;
  --bg: #f7f4ec;
  --panel: #fffdf7;
  --text: #1d2030;
  --muted: #6b6f80;
  --border: rgba(0, 0, 0, 0.10);
  --hover: rgba(0, 0, 0, 0.04);
  --line: rgba(30, 40, 80, 0.22);
  --accent: #b7791f;
  --star-fresh: #d29a00;
  --star-due: #343a52;
  --star-overdue: #2f66d0;
  --star-lost: #b4b8c6;
}

:root {
  --font-body: 'Nunito', system-ui, sans-serif;
  --font-display: 'Fraunces', Georgia, serif;
  --sidebar-w: 260px;
  --ease: cubic-bezier(0.22, 0.8, 0.24, 1);
}

* { box-sizing: border-box; }

html, body { height: 100%; margin: 0; }

body {
  display: flex;
  flex-direction: column;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-body);
  font-size: 15px;
}

/* ── Top bar ── */
.topbar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 14px 20px;
  border-bottom: 1px solid var(--border);
}
.brand { display: flex; align-items: baseline; gap: 12px; }
.brand h1 { margin: 0; font-family: var(--font-display); font-weight: 500; font-size: 30px; line-height: 1; }
.tagline { font-family: var(--font-display); font-style: italic; font-weight: 300; color: var(--muted); font-size: 16px; }
.actions { display: flex; align-items: center; gap: 8px; }

.search, .btn {
  font: inherit;
  color: var(--text);
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 7px 14px;
}
.btn { cursor: pointer; white-space: nowrap; transition: border-color 0.2s; }
.btn:hover:not(:disabled) { border-color: var(--accent); }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }
.btn-ghost { background: transparent; }
.search { width: 100%; outline: none; transition: border-color 0.2s; }
.search:focus { border-color: var(--accent); }

/* ── Main layout: sidebar | sky ── */
.layout { flex: 1; min-height: 0; display: flex; }

.sidebar {
  width: var(--sidebar-w);
  flex: none;
  display: flex;
  flex-direction: column;
  gap: 18px;
  padding: 16px 12px 16px 16px;
  overflow-y: auto;
  border-right: 1px solid var(--border);
}
.side-section h3 {
  margin: 0 0 6px 10px;
  font-family: var(--font-display);
  font-style: italic;
  font-weight: 300;
  font-size: 16px;
  color: var(--muted);
}
.side-section h3 .count { font-family: var(--font-body); font-style: normal; font-size: 13px; opacity: 0.7; }

.tag-list, .people-list { display: flex; flex-direction: column; gap: 1px; margin: 0; padding: 0; list-style: none; }

.tag-chip, .person-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  width: 100%;
  font: inherit;
  font-size: 14px;
  text-align: left;
  color: var(--text);
  background: transparent;
  border: 1px solid transparent;
  border-radius: 10px;
  padding: 5px 10px;
  cursor: pointer;
  transition: background 0.2s, border-color 0.2s;
}
.tag-chip:hover, .person-row:hover { background: var(--hover); }
.tag-chip.active, .person-row.active { background: var(--panel); border-color: var(--border); }
.tag-name { display: inline-flex; align-items: center; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.count { color: var(--muted); font-size: 12px; white-space: nowrap; }
.people-list .empty { color: var(--muted); padding: 5px 10px; font-size: 14px; }
.people-list .group-label { padding-top: 6px; }
.people-list .group-label:first-child { padding-top: 0; }
.group-toggle {
  display: flex;
  align-items: center;
  gap: 6px;
  width: 100%;
  font: inherit;
  font-size: 12px;
  color: var(--muted);
  background: none;
  border: none;
  padding: 4px 10px;
  cursor: pointer;
  text-align: left;
}
.group-toggle:hover { color: var(--text); }
.chev {
  width: 6px;
  height: 6px;
  border-right: 1.5px solid currentColor;
  border-bottom: 1.5px solid currentColor;
  transform: rotate(-45deg);
  transition: transform 0.25s var(--ease);
  margin-right: 4px;
}
.group-toggle.open .chev { transform: rotate(45deg); }

.mini {
  font: inherit;
  font-style: normal;
  font-size: 12px;
  color: var(--muted);
  background: none;
  border: none;
  padding: 0 0 0 6px;
  cursor: pointer;
  text-decoration: underline;
  text-underline-offset: 3px;
  text-decoration-color: var(--border);
}
.mini:hover { color: var(--text); }
.mini[hidden] { display: none; }

/* Thin, rounded scrollbars in the theme colours. */
.sidebar, .panel {
  scrollbar-width: thin;
  scrollbar-color: var(--border) transparent;
}
.sidebar::-webkit-scrollbar, .panel::-webkit-scrollbar { width: 8px; }
.sidebar::-webkit-scrollbar-track, .panel::-webkit-scrollbar-track { background: transparent; }
.sidebar::-webkit-scrollbar-thumb, .panel::-webkit-scrollbar-thumb {
  background: var(--border);
  border-radius: 999px;
  border: 2px solid transparent;
  background-clip: padding-box;
}
.sidebar:hover, .panel:hover { scrollbar-color: var(--muted) transparent; }
.sidebar:hover::-webkit-scrollbar-thumb, .panel:hover::-webkit-scrollbar-thumb { background-color: var(--muted); }

/* ── Sky ── */
.stage { position: relative; flex: 1; min-width: 0; min-height: 0; display: flex; overflow: hidden; }
.sky-wrap { position: relative; flex: 1; min-width: 0; min-height: 0; }
#sky { position: absolute; inset: 0; width: 100%; height: 100%; display: block; cursor: grab; }
#sky:active { cursor: grabbing; }

.bg-star { fill: var(--text); }
:root[data-theme="light"] .bg-star { display: none; }

.ring { fill: none; stroke: var(--line); stroke-dasharray: 2 6; }
.ring-label { fill: var(--muted); font-family: var(--font-display); font-style: italic; font-size: 13px; }

.nebula circle { opacity: 0.45; }
:root[data-theme="light"] .nebula circle { opacity: 0.3; }

.link { stroke: var(--line); stroke-width: 1; transition: opacity 0.5s var(--ease); }
.link.dim { opacity: 0.1; }
.link.log { stroke-dasharray: 3 4; stroke-width: 1.2; opacity: 0.85; }
.link.log.dim { opacity: 0.08; }

.node { cursor: pointer; transition: opacity 0.5s var(--ease); }
.node .halo { opacity: 0.2; transition: opacity 0.3s; }
.node:hover .halo { opacity: 0.45; }
:root[data-theme="light"] .node .halo { opacity: 0.12; }
.node .label {
  fill: var(--text);
  font-family: var(--font-display);
  pointer-events: none;
  opacity: 0;
  transition: opacity 0.35s var(--ease);
  paint-order: stroke;
  stroke: var(--bg);
}
#sky.zoomed .node .label,
.node:hover .label,
.node.selected .label,
.node.neighbour .label,
.node.tagged .label,
.node.me .label { opacity: 1; }
.node.crowded:not(:hover) .label { opacity: 0; }
.node.selected .core { stroke: var(--text); stroke-width: 1.5px; }
.node.dim { opacity: 0.15; }

.node.me { cursor: pointer; }
.node.me .core { fill: var(--text); }
.node.me .halo { fill: var(--accent); opacity: 0.18; }
.node.me .label { font-style: italic; }

/* ── Person panel (slides over the sky) ── */
.panel {
  position: absolute;
  top: 0;
  right: 0;
  bottom: 0;
  width: 340px;
  max-width: 100%;
  overflow-y: auto;
  background: color-mix(in srgb, var(--panel) 90%, transparent);
  backdrop-filter: blur(8px);
  border-left: 1px solid var(--border);
  transform: translateX(105%);
  opacity: 0;
  pointer-events: none;
  transition: transform 0.55s var(--ease), opacity 0.4s var(--ease);
}
.panel.open { transform: none; opacity: 1; pointer-events: auto; }
.panel { display: flex; flex-direction: column; }
.panel-inner { flex: 1 0 auto; padding: 20px 22px 28px; }
.panel h2 { margin: 0 0 4px; font-family: var(--font-display); font-weight: 500; font-size: 24px; line-height: 1.15; }
.panel .close { float: right; font-size: 13px; padding: 4px 12px; }
.panel .when { display: block; color: var(--muted); margin-bottom: 4px; }
.cadence-row { display: flex; align-items: center; flex-wrap: wrap; gap: 6px; margin-bottom: 14px; }
.cadence-num, .cadence-unit {
  font: inherit;
  color: var(--text);
  background: transparent;
  border: none;
  border-bottom: 1px dashed var(--muted);
  padding: 0 2px;
}
.cadence-num { width: 3.2em; text-align: center; -moz-appearance: textfield; }
.cadence-num::-webkit-inner-spin-button, .cadence-num::-webkit-outer-spin-button { -webkit-appearance: none; margin: 0; }
.cadence-num:focus, .cadence-unit:focus { outline: none; border-bottom-color: var(--accent); }
.cadence-unit { cursor: pointer; }
/* With the hint showing, the row gives up its bottom gap so the hint sits just below it. */
.cadence-row:has(+ .hint:not([hidden])) { margin-bottom: 8px; }
.panel .hint { color: var(--star-overdue); font-size: 13px; line-height: 1.4; margin: 0 0 14px; }
.panel .hint[hidden] { display: none; }

/* ── About dialog ── */
.about {
  width: min(560px, calc(100% - 32px));
  max-height: calc(100% - 64px);
  overflow-y: auto;
  padding: 26px 30px 30px;
  color: var(--text);
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 18px;
  line-height: 1.6;
  opacity: 0;
  transform: translateY(10px);
  transition: opacity 0.35s var(--ease), transform 0.35s var(--ease), overlay 0.35s allow-discrete, display 0.35s allow-discrete;
}
.about[open] { opacity: 1; transform: none; }
@starting-style { .about[open] { opacity: 0; transform: translateY(10px); } }
.about::backdrop { background: rgba(5, 8, 20, 0.55); backdrop-filter: blur(3px); }
.about h2 { margin: 0 0 14px; font-family: var(--font-display); font-weight: 500; font-size: 28px; }
.about .close { float: right; font-size: 13px; padding: 4px 12px; }
.about p { margin: 0 0 14px; }
.about .lede { font-family: var(--font-display); font-weight: 300; font-size: 18px; line-height: 1.5; }
.about a { color: var(--text); text-decoration-color: var(--accent); text-underline-offset: 3px; }
@media (max-width: 700px) { .about { padding: 20px 20px 24px; } }
.panel h3 { margin: 18px 0 4px; font-family: var(--font-display); font-style: italic; font-weight: 300; font-size: 16px; color: var(--muted); }
.panel p { margin: 0; line-height: 1.55; }
.panel ul { margin: 0; padding: 0; list-style: none; }
.panel li { padding: 3px 0; }
.panel .linkish { background: none; border: none; padding: 0; font: inherit; color: var(--text); cursor: pointer; text-decoration: underline; text-decoration-color: var(--border); text-underline-offset: 3px; }
.panel .linkish:hover { text-decoration-color: var(--accent); }
.panel .rel { color: var(--muted); }
.panel .notes { white-space: pre-wrap; }

/* Pencil button, pinned to the panel's bottom-right corner. */
.edit-btn {
  position: sticky;
  bottom: 16px;
  align-self: flex-end;
  flex: none;
  display: grid;
  place-items: center;
  width: 40px;
  height: 40px;
  margin: 0 18px 16px 0;
  color: var(--text);
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 50%;
  cursor: pointer;
  box-shadow: 0 4px 14px rgba(0, 0, 0, 0.18);
  transition: border-color 0.2s, transform 0.2s var(--ease);
}
.edit-btn:hover { border-color: var(--accent); transform: translateY(-1px); }
.edit-btn[hidden] { display: none; }

/* ── Person editor ── */
.editor h2 { margin-bottom: 14px; }
.field { position: relative; display: flex; flex-direction: column; gap: 4px; margin-bottom: 12px; }
.form-hint { color: var(--muted); font-size: 13px; line-height: 1.45; margin: -2px 0 0; }
.edit-chip.new em, .conn-list em { font-style: normal; font-size: 11px; color: var(--muted); margin-left: 4px; }

/* Suggestion dropdown under a name field or the chat note. */
.suggest {
  position: absolute;
  top: 100%;
  left: 0;
  right: 0;
  z-index: 5;
  margin: 4px 0 0;
  padding: 4px;
  list-style: none;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 10px;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.25);
}
.suggest[hidden] { display: none; }
.suggest li { padding: 6px 10px; border-radius: 8px; cursor: pointer; font-size: 14px; }
.suggest li.active, .suggest li:hover { background: var(--hover); }
.suggest li.new { color: var(--muted); font-style: italic; }

/* ── Chat list in the person panel ── */
.log-list .log { padding: 10px 0; border-top: 1px solid var(--border); }
.log-list .log:first-child { border-top: none; padding-top: 4px; }
.log-head { display: flex; align-items: baseline; gap: 8px; flex-wrap: wrap; font-size: 14px; }
.log-date { font-weight: 600; }
.log-head .mini { margin-left: auto; }
.log-note { margin: 4px 0 0; white-space: pre-wrap; line-height: 1.5; }
.mention {
  font: inherit;
  color: var(--text);
  background: var(--hover);
  border: none;
  border-radius: 6px;
  padding: 0 4px;
  cursor: pointer;
}
.mention:hover { background: var(--border); }
.panel h3 .mini { font-family: var(--font-body); font-style: normal; }
.field > span { font-family: var(--font-display); font-style: italic; font-weight: 300; font-size: 15px; color: var(--muted); }
.field input, .field select, .field textarea, .conn-add input, .conn-add select, .name-dialog input {
  font: inherit;
  color: var(--text);
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 7px 10px;
  min-width: 0;
  outline: none;
  transition: border-color 0.2s;
}
.field input:focus, .field select:focus, .field textarea:focus, .conn-add input:focus,
.conn-add select:focus, .name-dialog input:focus { border-color: var(--accent); }
.field textarea { resize: vertical; line-height: 1.5; }
.inline { display: flex; gap: 6px; align-items: center; flex-wrap: wrap; }
.inline .short { width: 4.5em; }
.suggest-wrap { position: relative; display: flex; flex: 1 1 120px; min-width: 0; }
.suggest-wrap input { flex: 1; min-width: 0; }
.field-error { color: var(--star-overdue); font-size: 13px; margin: -6px 0 12px; }
.field-error[hidden] { display: none; }

.tag-editor {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  align-items: center;
  padding: 6px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 10px;
}
.tag-editor:focus-within { border-color: var(--accent); }
.tag-chips { display: contents; }
.edit-chip {
  display: inline-flex;
  align-items: center;
  gap: 2px;
  font-size: 13px;
  padding: 1px 4px 1px 10px;
  border: 1px solid var(--border);
  border-radius: 999px;
}
.edit-chip button { font: inherit; color: var(--muted); background: none; border: none; cursor: pointer; padding: 0 4px; }
.edit-chip button:hover { color: var(--text); }
/* The typing field inside a chip box takes the box's border, not its own. */
.tag-editor input { flex: 1 1 90px; border: none; background: transparent; padding: 3px 4px; }

.conn-list li { display: flex; align-items: baseline; gap: 4px; }
.conn-list .mini { margin-left: auto; }

.editor-actions { display: flex; gap: 8px; align-items: center; margin-top: 18px; }
.editor-actions .spacer { flex: 1; }
.btn-primary { background: var(--text); color: var(--bg); border-color: var(--text); }
.btn-primary:hover:not(:disabled) { border-color: var(--accent); }
.btn-danger { background: transparent; color: #d9705a; }

/* ── Empty sky ── */
.empty-sky {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 6px;
  text-align: center;
  pointer-events: none;
}
.empty-sky > * { pointer-events: auto; margin: 0; }
.empty-sky[hidden] { display: none; }
.empty-sky p:first-child { font-family: var(--font-display); font-size: 22px; }
.empty-sky .muted { color: var(--muted); margin-bottom: 10px; }

/* ── Name dialog ── */
.name-dialog { width: min(420px, calc(100% - 32px)); }
.name-dialog input { width: 100%; font-size: 17px; }

/* ── Toast ── */
.toast {
  position: fixed;
  left: 50%;
  bottom: 56px;
  transform: translate(-50%, 12px);
  padding: 8px 16px;
  font-size: 14px;
  color: var(--bg);
  background: var(--text);
  border-radius: 999px;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.3s var(--ease), transform 0.3s var(--ease);
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }

/* Tags inside the panel are compact chips. */
.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chips .tag-chip { width: auto; border-color: var(--border); border-radius: 999px; padding: 2px 10px; font-size: 13px; color: var(--muted); }
.chips .tag-chip:hover { color: var(--text); }

.dot { display: inline-block; flex: none; width: 9px; height: 9px; border-radius: 50%; margin-right: 8px; }

/* ── Legend ── */
.legend {
  display: flex;
  flex-wrap: wrap;
  gap: 8px 20px;
  padding: 10px 20px;
  border-top: 1px solid var(--border);
  color: var(--muted);
  font-size: 13px;
}
.legend .dot { margin-right: 6px; vertical-align: middle; display: inline-block; }

/* ── Phone width: sidebar folds into a search box and a scrolling tag row; panel is a bottom sheet ── */
@media (max-width: 700px) {
  .topbar { padding: 12px 16px; gap: 8px; }
  .actions { width: 100%; flex-wrap: wrap; gap: 6px; }
  .actions .btn { font-size: 13px; padding: 5px 11px; }
  .wide-only { display: none; }
  .panel.tall { height: 88%; }
  .layout { flex-direction: column; }
  .sidebar {
    width: 100%;
    gap: 10px;
    padding: 10px 16px;
    overflow: visible;
    border-right: none;
    border-bottom: 1px solid var(--border);
  }
  .side-section h3, .people-section, .reach-section { display: none; }
  .tag-list { flex-direction: row; gap: 6px; overflow-x: auto; scrollbar-width: none; }
  .tag-list .tag-chip {
    width: auto;
    flex: none;
    border-color: var(--border);
    border-radius: 999px;
    padding: 3px 10px;
    font-size: 13px;
  }
  .panel {
    top: auto;
    left: 0;
    width: 100%;
    height: 55%;
    border-left: none;
    border-top: 1px solid var(--border);
    border-radius: 16px 16px 0 0;
    transform: translateY(105%);
  }
  .legend { padding: 10px 16px; }
  .legend-note { display: none; }
}

@media (prefers-reduced-motion: reduce) {
  * { transition-duration: 0.01ms !important; }
}

/* ── Sync status ── */
.sync-wrap { position: relative; }
.sync-btn { display: inline-flex; align-items: center; gap: 8px; }
.sync-dot { width: 8px; height: 8px; border-radius: 50%; background: var(--muted); transition: background 0.3s; }
.sync-btn[data-status="synced"] .sync-dot { background: #7cbf5a; }
.sync-btn[data-status="syncing"] .sync-dot { background: var(--accent); animation: pulse 1s ease-in-out infinite; }
.sync-btn[data-status="reconnect"] .sync-dot,
.sync-btn[data-status="offline"] .sync-dot,
.sync-btn[data-status="paused"] .sync-dot { background: var(--star-overdue); }
@keyframes pulse { 50% { opacity: 0.3; } }
.sync-menu {
  position: absolute;
  top: calc(100% + 6px);
  right: 0;
  z-index: 20;
  display: flex;
  flex-direction: column;
  min-width: 170px;
  padding: 4px;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 12px;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.25);
}
.sync-menu[hidden] { display: none; }
#sheet-link { text-decoration: none; }
#sheet-link[hidden] { display: none; }
.sync-menu a, .sync-menu button {
  font: inherit;
  font-size: 14px;
  text-align: left;
  color: var(--text);
  background: none;
  border: none;
  border-radius: 8px;
  padding: 7px 10px;
  text-decoration: none;
  cursor: pointer;
}
.sync-menu a:hover, .sync-menu button:hover { background: var(--hover); }
.ask-message { margin: 0 0 6px; line-height: 1.55; }

/* ── Welcome screen over a faint preview ── */
body.previewing .topbar, body.previewing .layout, body.previewing .legend {
  filter: blur(2.5px);
  opacity: 0.4;
  pointer-events: none;
  user-select: none;
}
.welcome {
  position: fixed;
  inset: 0;
  z-index: 40;
  display: grid;
  place-items: center;
  padding: 16px;
  background: color-mix(in srgb, var(--bg) 35%, transparent);
}
.welcome[hidden] { display: none; }
.welcome-card {
  width: min(440px, 100%);
  padding: 34px 32px 28px;
  text-align: center;
  background: color-mix(in srgb, var(--panel) 88%, transparent);
  backdrop-filter: blur(6px);
  border: 1px solid var(--border);
  border-radius: 20px;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.3);
  line-height: 1.55;
}
.welcome-card h1 { margin: 0; font-family: var(--font-display); font-weight: 500; font-size: 40px; line-height: 1.1; }
.welcome-card .tagline { display: block; margin: 4px 0 18px; font-size: 18px; }
.welcome-card p { margin: 0 0 20px; }
.welcome-signin { font-size: 16px; padding: 10px 24px; }
.welcome-offline { display: block; margin: 12px auto 0; padding: 0; }
.welcome-offline[hidden] { display: none; }
.welcome-card .fine { margin: 20px 0 0; font-size: 13px; color: var(--muted); }
