:root {
  --bg:        #0d0f0e;
  --bg-soft:   #14181a;
  --bg-card:   #171b1d;
  --border:    #262c2e;
  --fg:        #d6d3c8;
  --fg-dim:    #8b9088;
  --fg-faint:  #5a615c;
  --green:     #8a9a7b;
  --amber:     #cbb07a;
  --blue:      #7a94a8;
  --red:       #b07a7a;
  --focus:     #a6b892;
  /* muted note-color palette */
  --tag-red:    #b07a7a;
  --tag-amber:  #cbb07a;
  --tag-green:  #8a9a7b;
  --tag-blue:   #7a94a8;
  --tag-purple: #9a8aa8;
  --tag-gray:   #808a86;
  --mono: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, "Liberation Mono", monospace;
  --safe-t: env(safe-area-inset-top, 0px);
  --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-l: env(safe-area-inset-left, 0px);
  --safe-r: env(safe-area-inset-right, 0px);
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
  background: var(--bg);
  color: var(--fg);
  font-family: var(--mono);
  font-size: 15px;
  line-height: 1.5;
  -webkit-text-size-adjust: 100%;
  /* App-like feel: no pinch/double-tap zoom, no tap highlight, no rubber-band. */
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
  overscroll-behavior: none;
}

body {
  padding: var(--safe-t) var(--safe-r) var(--safe-b) var(--safe-l);
}

#app { min-height: 100dvh; }

.hidden { display: none !important; }

.view {
  max-width: 780px;
  width: 100%;
  margin: 0 auto;
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  padding-left: max(8px, var(--safe-l));
  padding-right: max(8px, var(--safe-r));
}

/* ---- buttons ---- */
.btn {
  font-family: var(--mono);
  font-size: 14px;
  background: var(--bg-soft);
  color: var(--fg);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 9px 14px;
  cursor: pointer;
  transition: border-color .12s, background .12s, color .12s;
}
.btn:hover { border-color: var(--fg-dim); }
.btn:active { transform: translateY(1px); }
.btn:disabled { opacity: .4; cursor: not-allowed; }
.btn.primary { color: var(--green); border-color: var(--green); }
.btn.primary:hover { background: rgba(138,154,123,.12); }
.btn.danger { color: var(--red); border-color: transparent; }
.btn.danger:hover { border-color: var(--red); }
.btn.ghost {
  background: transparent;
  border-color: transparent;
  color: var(--fg-dim);
  padding: 7px 10px;
}
.btn.ghost:hover { color: var(--fg); background: var(--bg-soft); }
.btn.icon {
  background: transparent;
  border-color: transparent;
  color: var(--fg-dim);
  padding: 7px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  line-height: 0;
}
.btn.icon:hover { color: var(--green); background: var(--bg-soft); }
.btn.icon.spin svg { animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
.linkbtn {
  background: none;
  border: none;
  color: var(--fg-dim);
  font-family: var(--mono);
  cursor: pointer;
  padding: 0;
}
.linkbtn:hover { color: var(--green); }

/* ---- auth ---- */
.auth-wrap {
  margin: auto;
  width: 100%;
  max-width: 420px;
  padding: 32px 20px;
}
.brand { text-align: center; margin-bottom: 36px; }
.brand-mark {
  font-size: 40px;
  font-weight: 700;
  letter-spacing: 1px;
  color: var(--green);
}
.brand-mark.small { font-size: 18px; color: var(--fg-dim); font-weight: 600; }
.brand-tag { display: block; color: var(--fg-dim); margin-top: 6px; font-size: 14px; }
.auth-panel { display: flex; flex-direction: column; gap: 14px; }
.or { text-align: center; color: var(--fg-faint); font-size: 13px; }
.field { display: flex; flex-direction: column; gap: 6px; }
.field .label { color: var(--fg-dim); font-size: 13px; }
input, select, textarea {
  font-family: var(--mono);
  font-size: 15px;
  background: var(--bg-soft);
  color: var(--fg);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 10px 12px;
  width: 100%;
}
input:focus, select:focus, textarea:focus {
  outline: none;
  border-color: var(--focus);
}
.warn { color: var(--amber); font-weight: 600; }
.muted { color: var(--fg-dim); font-size: 13px; margin: 4px 0; }
.error { color: var(--red); font-size: 13px; }
.keybox {
  background: var(--bg-card);
  border: 1px solid var(--amber);
  border-radius: 6px;
  padding: 14px;
  word-break: break-all;
}
.keybox code { color: var(--amber); font-size: 14px; }
.check { display: flex; align-items: center; gap: 8px; color: var(--fg-dim); font-size: 13px; }
.check input { width: auto; }

/* ---- topbar / toolbar ---- */
.topbar {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 14px 16px;
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  background: var(--bg);
  z-index: 5;
}
.spacer { flex: 1; }
.toolbar {
  display: flex;
  gap: 8px;
  align-items: center;
  padding: 14px 16px;
}
.search { flex: 1; }

/* ---- note list ---- */
.note-list { list-style: none; margin: 0; padding: 0 10px; flex: 1; }
.note-item {
  display: flex;
  align-items: baseline;
  gap: 10px;
  padding: 12px 10px;
  border-bottom: 1px solid var(--border);
  cursor: pointer;
  user-select: none;
  -webkit-user-select: none;
}
.note-item:hover { background: var(--bg-soft); }
.note-item.selected { background: var(--bg-soft); box-shadow: inset 3px 0 0 var(--green); }
.note-item.selected .title { color: var(--green); }

/* ---- board / folders (Kanban-ish) ---- */
.board { flex: 1; padding: 2px 8px; overflow-y: auto; user-select: none; -webkit-user-select: none; }
.folder-section { margin-bottom: 2px; }
.folder-head {
  display: flex; align-items: center; gap: 8px;
  margin: 10px 2px 4px; padding: 9px 10px; cursor: pointer; user-select: none;
  background: var(--bg-soft); border: 1px solid var(--border); border-radius: 6px;
  color: var(--fg); font-size: 14px;
}
.folder-head:hover { border-color: var(--fg-faint); }
.fold-toggle { width: 12px; color: var(--fg-dim); }
.fold-name { color: var(--fg); font-weight: 600; letter-spacing: .3px; }
.fold-count {
  color: var(--fg-dim); font-size: 11px;
  background: var(--bg-card); border-radius: 10px; padding: 1px 7px;
}
/* All cards share the same small left indent (foldered and unfiled alike). */
.folder-body { margin: 0 0 6px 12px; }
.folder-section.unfiled { margin-left: 12px; }

/* discreet archived sub-section (inside a folder, or general at the bottom) */
.arch-section { margin: 2px 0 4px; }
.arch-head {
  display: flex; align-items: center; gap: 6px;
  padding: 4px 8px; cursor: pointer; user-select: none;
  color: var(--fg-faint); font-size: 11px; letter-spacing: .3px;
}
.arch-head:hover { color: var(--fg-dim); }
.arch-head .fold-toggle { width: 10px; }
.arch-head .fold-count { background: none; padding: 0; }
.arch-body { opacity: .65; }
.arch-body .note-item { padding-top: 8px; padding-bottom: 8px; }
.fold-menu-btn {
  margin-left: auto; background: none; border: none; color: var(--fg-faint);
  cursor: pointer; font-size: 16px; line-height: 1; padding: 0 6px;
}
.fold-menu-btn:hover { color: var(--fg); }
.color-dot { width: 8px; height: 8px; border-radius: 50%; flex: 0 0 auto; align-self: center; }
.due-clock { flex: 0 0 auto; align-self: center; display: inline-flex; }
.card-menu-btn {
  margin-left: 6px; flex: 0 0 auto; background: none; border: none;
  color: var(--fg-faint); cursor: pointer; font-size: 16px; line-height: 1; padding: 0 4px; opacity: 0;
}
.note-item:hover .card-menu-btn { opacity: 1; }
@media (hover: none) { .card-menu-btn { opacity: 1; } }
/* The original card stays in place as a dim placeholder so the layout doesn't jump. */
.card.dragging { opacity: .15; }
/* Trello-like ghost: a real clone of the card, tilted, lifted, following the finger. */
.drag-ghost {
  position: fixed; left: 0; top: 0; pointer-events: none; z-index: 60;
  margin: 0; border-bottom: none;
  background: var(--bg-card); border: 1px solid var(--border); border-radius: 6px;
  box-shadow: 0 12px 28px rgba(0,0,0,.5);
  transform: rotate(3deg) scale(1.02);
}
body.dragging-cursor, body.dragging-cursor * { cursor: grabbing !important; }

/* Soft, layout-stable highlight of the group under the pointer. */
.drop-into { background: var(--bg-soft); border-radius: 6px; }
/* Dashed slot — only shown in EMPTY groups, filling their reserved min-height. */
.drop-placeholder {
  height: 0; opacity: 0; overflow: hidden; pointer-events: none;
  margin: 0; border-radius: 6px;
  background: var(--bg-soft);
  border: 1px dashed var(--fg-faint);
  animation: ph-in 120ms ease forwards;
}
@keyframes ph-in { to { height: 36px; opacity: 1; margin: 2px 0; } }
/* Collapsed folders / archives can't hold a slot — tint their header instead. */
.drop-hint { background: var(--bg-soft); }
.folder-head.drop-hint { border-color: var(--fg-dim); }
/* Empty groups keep a small reserved area at all times — so they stay droppable
   AND nothing shifts at drag-lift (a drag-gated min-height moved the whole board). */
.folder-body,
.folder-section.unfiled { min-height: 44px; }
.board-actions { padding: 8px 16px 14px; }

/* ---- popover menu ---- */
.popmenu {
  position: fixed; z-index: 50; background: var(--bg-card); border: 1px solid var(--border);
  border-radius: 8px; padding: 6px; min-width: 180px; max-width: 260px;
  display: flex; flex-direction: column; gap: 2px; box-shadow: 0 8px 24px rgba(0,0,0,.45);
}
.popmenu .menu-label { font-size: 11px; color: var(--fg-faint); padding: 6px 8px 2px; }
.popmenu .menu-item {
  text-align: left; background: none; border: none; color: var(--fg);
  font-family: var(--mono); font-size: 13px; padding: 7px 8px; border-radius: 5px; cursor: pointer;
}
.popmenu .menu-item:hover { background: var(--bg-soft); }
.popmenu .menu-item.danger { color: var(--red); }
.popmenu .color-row { display: flex; gap: 6px; padding: 4px 8px 6px; flex-wrap: wrap; }
.popmenu .swatch {
  width: 20px; height: 20px; border-radius: 50%; border: 1px solid var(--border);
  cursor: pointer; padding: 0;
}
.popmenu .swatch.on { box-shadow: 0 0 0 2px var(--fg-dim); }
.popmenu .swatch.none { background: transparent; color: var(--fg-faint); font-size: 12px; line-height: 18px; }
.note-item .sel { flex: 0 0 auto; }
.note-item .title { flex: 1; color: var(--fg); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.note-item .meta { color: var(--fg-faint); font-size: 12px; flex: 0 0 auto; }
.note-item .date { color: var(--blue); font-size: 12px; flex: 0 0 auto; opacity: .8; }
.note-item.archived .title { color: var(--fg-dim); }
.empty { color: var(--fg-dim); padding: 40px 20px; text-align: center; }
kbd {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 1px 6px;
  font-size: 12px;
}

/* ---- statusline ---- */
.statusline {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 10px 14px;
  border-top: 1px solid var(--border);
  color: var(--fg-dim);
  font-size: 12px;
  position: sticky;
  bottom: 0;
  background: var(--bg);
  flex-wrap: wrap;
}
.stat { white-space: nowrap; }
.cursor {
  margin-left: auto;
  color: var(--green);
  animation: blink 1.1s steps(1) infinite;
}
@keyframes blink { 50% { opacity: 0; } }

/* ---- editor ---- */
.editor-date {
  border: none;
  background: transparent;
  color: var(--fg-faint);
  font-family: var(--mono);
  font-size: 12px;
  width: auto;
  /* Don't let the flex column stretch it full-width; keep it left-justified
     (native date inputs otherwise center their text on mobile). */
  align-self: flex-start;
  text-align: left;
  padding: 12px 18px 0;
  color-scheme: dark;
  cursor: pointer;
}
.editor-date:focus { color: var(--fg-dim); }
.editor-date::-webkit-calendar-picker-indicator { opacity: .5; cursor: pointer; }
/* Created (left) + due control (right after it) share one sober row. */
.editor-date-row { display: flex; align-items: center; gap: 4px; padding: 12px 18px 0; }
.editor-date-row .editor-date { padding: 0; }
.editor-due { display: inline-flex; align-items: center; gap: 3px; color: var(--fg-faint); }
.editor-due .due-glyph { flex: 0 0 auto; opacity: .7; }
.editor-due .editor-date { color: var(--fg-faint); }
.editor-due-clear {
  background: none; border: none; color: var(--fg-faint); cursor: pointer;
  font-size: 13px; line-height: 1; padding: 0 2px;
}
.editor-due-clear:hover { color: var(--fg-dim); }
.editor-title {
  border: none;
  border-bottom: 1px solid var(--border);
  border-radius: 0;
  background: transparent;
  font-size: 18px;
  color: var(--green);
  padding: 8px 18px 16px;
}
.editor-body {
  flex: 1;
  border: none;
  border-radius: 0;
  background: transparent;
  resize: none;
  padding: 16px 18px;
  /* Trailing space so the last lines can scroll up to a comfortable height
     (scroll-past-end, like a code editor). */
  padding-bottom: 45vh;
  line-height: 1.6;
  min-height: 40dvh;
}

/* ---- drawer / modal ---- */
.drawer {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,.5);
  z-index: 20;
  display: flex;
  justify-content: flex-end;
}
.drawer-inner {
  background: var(--bg-card);
  border-left: 1px solid var(--border);
  width: min(360px, 90vw);
  height: 100%;
  padding: 16px;
  overflow-y: auto;
  padding-bottom: calc(16px + var(--safe-b));
}
.drawer-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 12px;
  color: var(--fg-dim);
}
.rev-list, .synth-list { list-style: none; margin: 0; padding: 0; }
.rev-item {
  padding: 10px 6px;
  border-bottom: 1px solid var(--border);
  display: flex;
  gap: 10px;
  align-items: center;
  justify-content: space-between;
}
.rev-item .when { color: var(--fg); font-size: 13px; }

.modal {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,.55);
  z-index: 30;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
}
.modal-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 8px;
  width: min(520px, 100%);
  max-height: 85dvh;
  overflow-y: auto;
  padding: 18px;
}
.synth-list { margin: 10px 0; max-height: 40dvh; overflow-y: auto; }
.synth-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 4px;
  border-bottom: 1px solid var(--border);
}
.synth-item input { width: auto; }

/* ---- settings ---- */
.settings-body { padding: 16px; display: flex; flex-direction: column; gap: 24px; }
.setting { display: flex; flex-direction: column; gap: 8px; }
.setting-label { color: var(--green); font-size: 14px; }
.keyrow, .btnrow { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.btnrow.end { justify-content: flex-end; margin-top: 8px; }
.confirm-card { width: min(400px, 100%); }
.masked {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 8px 10px;
  color: var(--amber);
  word-break: break-all;
  flex: 1;
  min-width: 160px;
}
.plan-status {
  color: var(--amber);
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 1px;
}
.plan-status.pro { color: var(--green); }

/* ---- toast ---- */
.toast {
  position: fixed;
  left: 50%;
  bottom: calc(20px + var(--safe-b));
  transform: translateX(-50%);
  background: var(--bg-card);
  border: 1px solid var(--border);
  color: var(--fg);
  padding: 10px 16px;
  border-radius: 8px;
  z-index: 40;
  font-size: 13px;
  max-width: 90vw;
}
.toast.err { border-color: var(--red); color: var(--red); }
.toast.ok { border-color: var(--green); }

/* ---- brand as a home link ---- */
.brand-link { cursor: pointer; }
.brand-link:hover { color: var(--fg); }

/* ---- AI workspace ---- */
.ai-body {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 22px;
  padding: 16px;
  padding-bottom: calc(20px + var(--safe-b));
  overflow-y: auto;
}
.ai-synth { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; }
.ai-section { display: flex; flex-direction: column; gap: 8px; }
.ai-chat { flex: 1; }
.chat-log {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.chat-msg {
  padding: 8px 12px;
  border-radius: 8px;
  max-width: 85%;
  white-space: pre-wrap;
  word-break: break-word;
  font-size: 14px;
  border: 1px solid var(--border);
}
.chat-msg.user { align-self: flex-end; background: var(--bg-soft); }
.chat-msg.assistant { align-self: flex-start; background: var(--bg-card); color: var(--fg); }
.chat-msg.pending { opacity: .6; }
.chat-input { display: flex; gap: 8px; margin-top: 10px; }
.chat-input input { flex: 1; }
.synth-since { font-size: 11px; color: var(--fg-faint); }

/* ---- shortcuts modal ---- */
.shortcut-list { list-style: none; margin: 8px 0 0; padding: 0; display: flex; flex-direction: column; gap: 10px; }
.shortcut-list li { display: flex; align-items: center; gap: 12px; font-size: 13px; color: var(--fg-dim); }
.shortcut-list .keys { display: inline-flex; gap: 4px; flex: 0 0 96px; }

@media (max-width: 520px) {
  body { font-size: 15px; }
  .brand-mark { font-size: 34px; }
}
