/* Northstar Notes. Built on the Altech UI kit: tokens first, change the look here. */

:root {
  --fs: 15px;
  --gap: 12px;
  --pad: 16px;
  --radius: 10px;
  --bar: 52px;
  --side: 260px;

  /* Dark (default) */
  --bg: #0a1213;
  --surface: #0f1819;
  --surface-2: #152122;
  --hover: rgba(233, 247, 233, 0.05);
  --text: #e8eee8;
  --muted: #93a39a;
  --line: rgba(233, 247, 233, 0.09);
  --accent: #b6f19b;
  --accent-2: #7fe0b4;
  --on-accent: #0a1212;
  --tint: rgba(182, 241, 155, 0.08);
  --danger: #ffb4ad;
  --danger-bg: rgba(255, 120, 110, 0.1);
  --shadow: 0 12px 32px rgba(0, 0, 0, 0.35);
  color-scheme: dark;
}

:root[data-text="small"] { --fs: 14px; }
:root[data-text="large"] { --fs: 17px; }
:root[data-density="compact"] { --gap: 8px; --pad: 12px; --bar: 46px; }

:root[data-theme="light"] {
  --bg: #f5f7f5;
  --surface: #ffffff;
  --surface-2: #eef3ef;
  --hover: rgba(20, 40, 30, 0.05);
  --text: #18211c;
  --muted: #5d6b63;
  --line: #dde5df;
  --accent: #2f8a4a;
  --accent-2: #1f7a6a;
  --on-accent: #ffffff;
  --tint: rgba(47, 138, 74, 0.08);
  --danger: #b42318;
  --danger-bg: rgba(180, 35, 24, 0.07);
  --shadow: 0 12px 32px rgba(20, 30, 25, 0.12);
  color-scheme: light;
}

@media (prefers-color-scheme: light) {
  :root[data-theme="auto"] {
    --bg: #f5f7f5;
    --surface: #ffffff;
    --surface-2: #eef3ef;
    --hover: rgba(20, 40, 30, 0.05);
    --text: #18211c;
    --muted: #5d6b63;
    --line: #dde5df;
    --accent: #2f8a4a;
    --accent-2: #1f7a6a;
    --on-accent: #ffffff;
    --tint: rgba(47, 138, 74, 0.08);
    --danger: #b42318;
    --danger-bg: rgba(180, 35, 24, 0.07);
    --shadow: 0 12px 32px rgba(20, 30, 25, 0.12);
    color-scheme: light;
  }
}

/* ---- Base ---- */

* { box-sizing: border-box; }

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

body {
  background: var(--bg);
  color: var(--text);
  font: var(--fs)/1.55 system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  display: grid;
  grid-template-rows: var(--bar) minmax(0, 1fr);
  overflow: hidden;
}

button, input, textarea, select { font: inherit; color: inherit; }
button { cursor: pointer; }
[hidden] { display: none !important; }

:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

.muted { color: var(--muted); }

/* ---- Buttons ---- */

.icon-btn,
.tool,
.button {
  border: 1px solid var(--line);
  background: var(--surface);
  border-radius: 8px;
  min-height: 34px;
  padding: 0 10px;
  white-space: nowrap;
}

.icon-btn { min-width: 34px; display: inline-grid; place-items: center; }
.icon-btn:hover, .tool:hover, .button:hover { background: var(--hover); }
.icon-btn.info { border-radius: 50%; padding: 0; font: italic 700 15px Georgia, serif; }

.button--primary { background: var(--accent); color: var(--on-accent); border-color: transparent; font-weight: 600; }
.button--primary:hover { background: var(--accent-2); }
.button--danger { color: var(--danger); background: var(--danger-bg); border-color: transparent; }

/* ---- Top bar: menu | brand | contextual tools | save | settings | info ---- */

.topbar {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 0 var(--pad);
  background: var(--surface);
  border-bottom: 1px solid var(--line);
  min-width: 0;
}

.brand { display: flex; align-items: center; gap: 8px; color: inherit; text-decoration: none; font-weight: 700; }

.brand-mark {
  display: grid;
  place-items: center;
  width: 28px;
  height: 28px;
  border-radius: 8px;
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  color: var(--on-accent);
  font-size: 14px;
  font-weight: 800;
}

.ctx-tools {
  flex: 1;
  display: flex;
  gap: 6px;
  justify-content: center;
  min-width: 0;
  overflow-x: auto;
  scrollbar-width: none;
}

.ctx-tools::-webkit-scrollbar { display: none; }

.tool { font-size: 0.9em; animation: fade 0.15s ease; }
.tool.is-on { border-color: var(--accent); color: var(--accent); background: var(--tint); }
.tool--danger { color: var(--danger); }
.tool-sep { width: 1px; align-self: stretch; margin: 6px 2px; background: var(--line); flex: none; }

@keyframes fade { from { opacity: 0; transform: translateY(-2px); } }

.save { display: inline-flex; align-items: center; gap: 6px; color: var(--muted); font-size: 0.85em; }
.save-dot { width: 8px; height: 8px; border-radius: 50%; background: var(--accent); }
.save[data-state="saving"] .save-dot, .save[data-state="loading"] .save-dot { background: #e7c66b; }
.save[data-state="error"] { color: var(--danger); }
.save[data-state="error"] .save-dot { background: var(--danger); }

/* ---- Layout: sidebar + document, full screen ---- */

.layout { display: grid; grid-template-columns: auto minmax(0, 1fr); min-height: 0; }

.sidebar {
  width: var(--side);
  display: flex;
  flex-direction: column;
  gap: var(--gap);
  padding: var(--gap);
  background: var(--surface);
  border-right: 1px solid var(--line);
  min-height: 0;
}

:root[data-side="closed"] .sidebar { display: none; }

.side-head { display: flex; gap: 6px; }

.side-head input {
  flex: 1;
  min-width: 0;
  min-height: 34px;
  padding: 0 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--bg);
}

.nav-list { display: grid; gap: 2px; align-content: start; overflow-y: auto; min-height: 0; }

.nav-item {
  display: flex;
  align-items: center;
  gap: 8px;
  width: 100%;
  min-height: 34px;
  padding: 4px 8px;
  border: 0;
  border-radius: 8px;
  background: transparent;
  text-align: left;
}

.nav-item:hover { background: var(--hover); }

/* Page tree: each level indents a little. */
.nav-row { display: flex; align-items: center; gap: 2px; padding-left: calc(var(--depth, 0) * 14px); min-width: 0; }
.nav-row .nav-item { flex: 1; min-width: 0; padding-left: 4px; }

.nav-toggle {
  flex: none;
  width: 20px;
  height: 28px;
  padding: 0;
  border: 0;
  border-radius: 6px;
  background: transparent;
  color: var(--muted);
  font-size: 0.8em;
}

button.nav-toggle:hover { background: var(--hover); color: var(--text); }

.nav-add {
  flex: none;
  width: 26px;
  height: 26px;
  padding: 0;
  border: 0;
  border-radius: 6px;
  background: transparent;
  color: var(--muted);
  opacity: 0;
}

.nav-row:hover .nav-add,
.nav-row.is-active .nav-add,
.nav-add:focus-visible { opacity: 1; }
.nav-add:hover { background: var(--hover); color: var(--text); }
.nav-item.is-active { background: var(--tint); color: var(--accent); font-weight: 600; }
.nav-icon { width: 20px; flex: none; text-align: center; }
.nav-title { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.nav-empty { padding: 8px; color: var(--muted); font-size: 0.9em; }

.scrim { position: fixed; inset: var(--bar) 0 0 0; background: rgba(0, 0, 0, 0.45); z-index: 5; }

/* ---- Document ---- */

.doc {
  overflow-y: auto;
  padding: calc(var(--pad) * 1.5) clamp(16px, 5vw, 72px) 96px;
  min-width: 0;
}

.page-head { display: flex; align-items: flex-start; gap: 10px; }

.page-icon {
  flex: none;
  width: 44px;
  height: 44px;
  border: 0;
  border-radius: 10px;
  background: transparent;
  font-size: 1.7em;
  line-height: 1;
}

.page-icon:hover { background: var(--hover); }

.page-title {
  flex: 1;
  min-width: 0;
  border: 0;
  padding: 4px 0;
  background: transparent;
  font-size: 1.75em;
  font-weight: 700;
  line-height: 1.25;
  letter-spacing: -0.01em;
  resize: none;
  overflow: hidden;
}

.page-title:focus, .block-text:focus { outline: none; }

.page-meta {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 6px 10px;
  margin: 4px 0 18px 54px;
  color: var(--muted);
  font-size: 0.85em;
}

.tag { padding: 1px 8px; border-radius: 999px; background: var(--tint); color: var(--accent); }

.blocks { display: grid; gap: 2px; }

/* Path to the current page */
.crumbs { display: flex; flex-wrap: wrap; align-items: center; gap: 2px 4px; margin-bottom: 8px; font-size: 0.85em; color: var(--muted); }
.crumb { border: 0; border-radius: 6px; padding: 2px 6px; background: transparent; color: inherit; max-width: 220px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.crumb:hover { background: var(--hover); color: var(--text); }

/* A link to a sub-page, shown as a line on the parent page */
.page-link {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  min-height: 34px;
  padding: 4px 0;
  border: 0;
  background: transparent;
  text-align: left;
}

.page-link:focus { outline: none; }
.page-link-icon { width: 20px; text-align: center; }
.page-link-title { font-weight: 600; text-decoration: underline; text-decoration-color: var(--line); text-underline-offset: 4px; }
.page-link:hover .page-link-title { text-decoration-color: var(--accent); }

.block {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  padding: 2px 8px;
  border-radius: 8px;
}

.block:hover { background: var(--hover); }
.block:focus-within { background: var(--surface-2); }

.block-text {
  flex: 1;
  min-width: 0;
  border: 0;
  padding: 4px 0;
  background: transparent;
  line-height: 1.55;
  resize: none;
  overflow: hidden;
}

.block-text::placeholder, .page-title::placeholder { color: var(--muted); opacity: 0.7; }

.block--heading { margin-top: 12px; }
.block--heading .block-text { font-size: 1.3em; font-weight: 700; line-height: 1.3; }

.block--callout { padding: 6px 12px; background: var(--tint); border-left: 3px solid var(--accent); }
.block--callout:hover, .block--callout:focus-within { background: var(--tint); }

.block-check { flex: none; width: 18px; height: 18px; margin: 6px 0 0; accent-color: var(--accent); cursor: pointer; }
.block--todo.is-done .block-text { color: var(--muted); text-decoration: line-through; }

.add-block {
  margin-top: 6px;
  padding: 6px 8px;
  border: 0;
  border-radius: 8px;
  background: transparent;
  color: var(--muted);
}

.add-block:hover { background: var(--hover); color: var(--text); }

.empty { display: grid; gap: 12px; justify-items: start; color: var(--muted); }

/* ---- Database tables ---- */

.db { display: grid; gap: 6px; justify-items: start; }
.db-scroll { justify-self: stretch; }

.db-scroll {
  overflow-x: auto;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--bg);
}

.db-table { border-collapse: separate; border-spacing: 0; width: 100%; min-width: max-content; }

.db-table th,
.db-table td {
  min-width: 150px;
  padding: 0;
  border-bottom: 1px solid var(--line);
  border-right: 1px solid var(--line);
  text-align: left;
  vertical-align: middle;
}

.db-table .col-end { min-width: 44px; width: 44px; border-right: 0; }
.db-table tbody tr:last-child td { border-bottom: 0; }
.db-table thead th { background: var(--surface); color: var(--muted); font-size: 0.9em; }
.db-table tbody tr:hover td { background: var(--hover); }

/* Name column stays put when the table scrolls sideways. */
.db-table .col-name { position: sticky; left: 0; z-index: 1; min-width: 220px; background: var(--bg); }
.db-table thead .col-name { z-index: 2; background: var(--surface); }
.db-table tbody tr:hover .col-name { background: var(--surface-2); }

.th-btn {
  display: flex;
  align-items: center;
  gap: 6px;
  width: 100%;
  min-height: 36px;
  padding: 6px 10px;
  border: 0;
  background: transparent;
  color: inherit;
  font-weight: 600;
  text-align: left;
  white-space: nowrap;
}

button.th-btn:hover { background: var(--hover); color: var(--text); }
.th-type { width: 18px; flex: none; text-align: center; color: var(--muted); font-size: 0.85em; }

.cell-input {
  width: 100%;
  min-height: 38px;
  padding: 6px 10px;
  border: 0;
  background: transparent;
}

.cell-input:focus { outline: 2px solid var(--accent); outline-offset: -2px; background: var(--surface-2); }
.cell-name { font-weight: 600; }
.cell-check { width: 18px; height: 18px; margin: 10px; accent-color: var(--accent); cursor: pointer; }

.cell-pills {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 4px;
  width: 100%;
  min-height: 38px;
  padding: 6px 10px;
  border: 0;
  background: transparent;
  text-align: left;
}

.cell-empty { color: var(--muted); }
.name-cell { display: flex; align-items: center; }

.open-btn {
  flex: none;
  margin-right: 6px;
  padding: 2px 8px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--surface);
  color: var(--muted);
  font-size: 0.8em;
  opacity: 0;
}

.db-table tr:hover .open-btn,
.db-table tr:focus-within .open-btn,
.open-btn:focus-visible { opacity: 1; }

@media (hover: none) { .open-btn { opacity: 1; } }

/* Option pills. Soft colours that read on light and dark. */
.pill { padding: 1px 8px; border-radius: 999px; background: var(--pill, rgba(140, 150, 145, 0.28)); font-size: 0.85em; white-space: nowrap; }
.pill[data-color="gray"] { --pill: rgba(140, 150, 145, 0.28); }
.pill[data-color="brown"] { --pill: rgba(160, 110, 70, 0.32); }
.pill[data-color="orange"] { --pill: rgba(230, 140, 50, 0.32); }
.pill[data-color="yellow"] { --pill: rgba(220, 185, 50, 0.34); }
.pill[data-color="green"] { --pill: rgba(80, 185, 105, 0.32); }
.pill[data-color="blue"] { --pill: rgba(70, 140, 230, 0.32); }
.pill[data-color="purple"] { --pill: rgba(150, 110, 220, 0.34); }
.pill[data-color="pink"] { --pill: rgba(225, 100, 170, 0.32); }
.pill[data-color="red"] { --pill: rgba(230, 80, 70, 0.32); }

/* Properties at the top of a row's own page */
.row-props {
  display: grid;
  grid-template-columns: minmax(110px, 180px) minmax(0, 1fr);
  gap: 2px 8px;
  margin-bottom: 16px;
  padding-bottom: 12px;
  border-bottom: 1px solid var(--line);
}

.row-prop-name {
  display: flex;
  align-items: center;
  gap: 6px;
  min-height: 38px;
  padding: 0 8px;
  border: 0;
  border-radius: 6px;
  background: transparent;
  color: var(--muted);
  text-align: left;
}

.row-prop-name:hover { background: var(--hover); color: var(--text); }
.row-prop-value { min-width: 0; border-radius: 6px; }
.row-prop-value:hover { background: var(--hover); }

/* Views: tabs, board */
.db-body { display: grid; gap: 6px; justify-items: start; width: 100%; min-width: 0; }

.view-bar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 4px;
  justify-self: stretch;
  padding-bottom: 6px;
  border-bottom: 1px solid var(--line);
}

.view-tab {
  min-height: 30px;
  padding: 2px 10px;
  border: 0;
  border-radius: 6px;
  background: transparent;
  color: var(--muted);
  white-space: nowrap;
}

.view-tab:hover { background: var(--hover); color: var(--text); }
.view-tab.is-on { background: var(--surface-2); color: var(--text); font-weight: 600; }

.view-summary {
  margin-left: auto;
  min-height: 30px;
  padding: 2px 8px;
  border: 0;
  border-radius: 6px;
  background: transparent;
  color: var(--accent);
  font-size: 0.85em;
}

.view-summary:hover { background: var(--hover); }

.board { display: flex; align-items: flex-start; gap: var(--gap); width: 100%; overflow-x: auto; padding-bottom: 8px; }

.lane {
  flex: 0 0 270px;
  min-width: 0;
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  gap: 8px;
  padding: 8px;
  border-radius: var(--radius);
  background: var(--surface);
}

.lane.is-over { outline: 2px dashed var(--accent); outline-offset: -2px; }
.lane-head { display: flex; align-items: center; justify-content: space-between; padding: 2px 4px; }
.lane-count { color: var(--muted); font-size: 0.85em; }
.lane-add { justify-self: start; margin-top: 0; }

.card {
  min-width: 0;
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  gap: 6px;
  padding: 8px 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--bg);
}

.card.is-dragging { opacity: 0.5; }
.card:focus-within { border-color: var(--accent); }
.card-top { display: flex; align-items: center; gap: 4px; }
.card-drag { padding: 0 2px; color: var(--muted); cursor: grab; user-select: none; letter-spacing: -2px; }
.card-title { flex: 1; min-width: 0; padding: 2px 0; border: 0; background: transparent; font-weight: 600; }
.card-title:focus { outline: none; }
.card-props { display: flex; flex-wrap: wrap; gap: 4px; }
.card-meta { color: var(--muted); font-size: 0.8em; }
.card-foot { display: flex; align-items: center; justify-content: space-between; gap: 6px; }
.card-status { width: auto; min-height: 28px; padding: 2px 4px; border-radius: 6px; }
.card .open-btn { opacity: 1; margin: 0; }

@media (hover: none) { .card-drag { display: none; } }

.filter-row { display: grid; gap: 6px; padding: 8px; border: 1px solid var(--line); border-radius: 8px; }
.field .filter-row .opt-row select { flex: 1; min-width: 0; width: auto; }
.field .opt-row #v-sort, .field .opt-row #v-dir { flex: 1; min-width: 0; width: auto; }

/* Option picker and property drawer */
.choose-list { display: grid; gap: 2px; }
.choose-item { display: flex; align-items: center; gap: 10px; min-height: 38px; padding: 4px 8px; border-radius: 8px; cursor: pointer; }
.choose-item:hover { background: var(--hover); }
.choose-item input { width: 18px; height: 18px; accent-color: var(--accent); }
.opt-list { display: grid; gap: 6px; }
.opt-row { display: flex; align-items: center; gap: 6px; }
.field .opt-row input { flex: 1; min-width: 0; }
.field .opt-row select { width: auto; flex: none; }

/* ---- Drawers (info, settings, page details) ---- */

.drawer {
  position: fixed;
  top: var(--bar);
  right: 0;
  bottom: 0;
  z-index: 10;
  width: min(360px, 100vw);
  display: flex;
  flex-direction: column;
  background: var(--surface);
  border-left: 1px solid var(--line);
  box-shadow: var(--shadow);
}

.drawer-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: var(--pad);
  border-bottom: 1px solid var(--line);
}

.drawer-body { display: grid; gap: 14px; align-content: start; padding: var(--pad); overflow-y: auto; }
.drawer-body p, .drawer-body ul { margin: 0; }
.drawer-body ul { padding-left: 18px; display: grid; gap: 8px; }
.drawer-body kbd { padding: 0 5px; border: 1px solid var(--line); border-radius: 4px; font-size: 0.9em; }

.field { display: grid; gap: 6px; font-weight: 600; font-size: 0.9em; }

.field input, .field textarea, .field select {
  width: 100%;
  min-height: 38px;
  padding: 8px 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--bg);
  font-weight: 400;
  font-size: var(--fs);
}

.field textarea { resize: vertical; }
.field small { color: var(--muted); font-weight: 400; }
.drawer-actions { display: flex; flex-wrap: wrap; gap: 8px; }

/* ---- Toast ---- */

.toast {
  position: fixed;
  left: 50%;
  bottom: 72px;
  transform: translateX(-50%);
  z-index: 20;
  max-width: calc(100vw - 32px);
  padding: 10px 14px;
  border-radius: 10px;
  background: var(--danger-bg);
  border: 1px solid var(--danger);
  color: var(--danger);
  box-shadow: var(--shadow);
}

/* ---- Phone ---- */

@media (max-width: 720px) {
  .brand-name, .save-label { display: none; }
  .topbar { padding: 0 10px; }
  .save { margin-left: auto; padding: 0 6px; }

  .sidebar,
  :root[data-side="closed"] .sidebar {
    display: flex;
    position: fixed;
    top: var(--bar);
    bottom: 0;
    left: 0;
    z-index: 6;
    width: min(300px, 85vw);
    transform: translateX(-105%);
    transition: transform 0.2s ease;
    box-shadow: var(--shadow);
  }

  body.side-open .sidebar { transform: none; }

  /* Tools sit at the bottom, above the keyboard, where thumbs reach. */
  .ctx-tools {
    position: fixed;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 4;
    justify-content: flex-start;
    padding: 8px 10px calc(8px + env(safe-area-inset-bottom));
    background: var(--surface);
    border-top: 1px solid var(--line);
  }

  .ctx-tools:empty { display: none; }
  .ctx-tools { gap: 4px; }
  .tool { min-height: 40px; padding: 0 9px; }

  .doc { padding: 16px 12px 96px; }
  .page-title { font-size: 1.5em; }
  .page-icon { width: 38px; height: 38px; font-size: 1.5em; }
  .page-meta { margin-left: 0; }
  .db-table .col-name { min-width: 150px; max-width: 170px; }
  .db-table th, .db-table td { min-width: 120px; }
  .row-props { grid-template-columns: minmax(96px, 120px) minmax(0, 1fr); }
  .lane { flex-basis: 78vw; }
  .view-summary { margin-left: 0; }
  .block { padding: 2px 6px; }
}

@media (prefers-reduced-motion: reduce) {
  * { animation: none !important; transition: none !important; }
}

/* ---- Login page ---- */

.login-shell { display: grid; place-items: center; min-height: 100vh; padding: 16px; }
body.login { display: block; overflow: auto; }

.login-card {
  width: 100%;
  max-width: 380px;
  display: grid;
  gap: 16px;
  padding: 28px 24px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 14px;
  box-shadow: var(--shadow);
}

.login-card .brand { font-size: 1.15em; }
.login-card label { display: grid; gap: 6px; font-weight: 600; }

.login-card input {
  min-height: 44px;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--bg);
  font-size: 1rem;
}

.login-card .button { min-height: 44px; }

.login-error {
  margin: 0;
  padding: 8px 12px;
  border-radius: 8px;
  background: var(--danger-bg);
  color: var(--danger);
}
