/* tm — light theme */
:root {
  --bg: #f6f7f9;
  --surface: #ffffff;
  --text: #1d2330;
  --muted: #667085;
  --border: #d9dde3;
  --accent: #2563eb;
  --accent-text: #ffffff;
  --danger: #c0262d;
  --archived: #f08c00; /* "A" badge background */
  --ok-bg: #e7f6ec;
  --ok-text: #17663a;
  --err-bg: #fdecec;
  --err-text: #a1181e;
  --radius: 6px;
  --font: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  --mono: ui-monospace, "SFMono-Regular", Menlo, Consolas, monospace;
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font: 15px/1.5 var(--font);
}
a { color: var(--accent); }
h1 { font-size: 1.5rem; margin: 0 0 1rem; }
h2 { font-size: 1.1rem; margin: 0; }
code { font-family: var(--mono); }

/* Top bar */
.topbar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: .5rem 1rem;
  padding: .5rem 1rem;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}
.topbar .brand { font-weight: 700; text-decoration: none; color: var(--text); }
.spacer { flex: 1; }

/* Page containers */
.page { padding: 1.5rem 1rem; }
.page.narrow { max-width: 380px; margin: 3rem auto; }
.page.medium { max-width: 560px; margin: 0 auto; }

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1rem;
  margin-bottom: 1rem;
}
.stack { display: flex; flex-direction: column; gap: .75rem; }
.stack > form { margin: 0; }
form.inline { display: inline; margin: 0; }

/* Forms */
label { display: flex; flex-direction: column; gap: .25rem; font-weight: 500; }
input, select, textarea {
  font: inherit;
  padding: .45rem .6rem;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--text);
}
input:focus, select:focus, textarea:focus, button:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 1px;
}
button, .button {
  font: inherit;
  display: inline-block;
  padding: .45rem .9rem;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--text);
  cursor: pointer;
  text-decoration: none;
  line-height: 1.3;
}
button:hover, .button:hover { border-color: var(--muted); }
button.primary, .button.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-text); }
button.danger { color: var(--danger); border-color: var(--danger); }
button.link {
  border: 0; padding: 0; background: none;
  color: var(--accent); text-decoration: underline;
}
button:disabled { opacity: .5; cursor: not-allowed; }

/* Messages */
.msg { padding: .6rem .8rem; border-radius: var(--radius); margin: 0 0 1rem; }
.msg-error { background: var(--err-bg); color: var(--err-text); }
.msg-info { background: var(--ok-bg); color: var(--ok-text); }

/* Archived badge */
.badge-a {
  display: inline-block;
  margin-left: .35em;
  padding: 0 .35em;
  border-radius: 3px;
  background: var(--archived);
  color: #fff;
  font-size: .8em;
  font-weight: 700;
  line-height: 1.4;
  vertical-align: middle;
}

/* 2FA */
.qr { image-rendering: pixelated; align-self: flex-start; border: 1px solid var(--border); }
.secret { font-size: 1.05rem; letter-spacing: .03em; user-select: all; }

/* Tabs */
.tabs { display: flex; gap: .25rem; margin-bottom: -1px; position: relative; }
.tabs a {
  padding: .45rem 1rem;
  border: 1px solid transparent;
  border-bottom: 0;
  border-radius: var(--radius) var(--radius) 0 0;
  text-decoration: none;
  color: var(--muted);
}
.tabs a[aria-current="page"] {
  background: var(--surface);
  border-color: var(--border);
  color: var(--text);
  font-weight: 600;
}

/* Lists (projects, tasks) */
.projects { max-width: 900px; margin: 0 auto; }
ul.list { list-style: none; margin: 0; padding: 0; border-top-left-radius: 0; }
.list-row {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: .5rem 1rem;
  padding: .7rem 1rem;
  border-bottom: 1px solid var(--border);
}
.list-row:last-child { border-bottom: 0; }
.list-row.empty { color: var(--muted); }
.list-row .name { font-weight: 600; color: var(--text); text-decoration: none; }
.list-row .name:hover { text-decoration: underline; }
.meta { color: var(--muted); font-size: .85rem; }
.grow { flex: 1; min-width: 12rem; }
.actions { display: flex; flex-wrap: wrap; gap: .4rem; }
.row-form { display: flex; flex-wrap: wrap; gap: .5rem; align-items: center; }
.row-form input[name="name"] { flex: 1; min-width: 12rem; }

/* ---------- Main screen ---------- */
/* The main screen fills the window: the top bar takes what it needs (it
   may wrap), the workspace gets the rest, and each pane scrolls itself. */
body:has(> .main-screen) { height: 100dvh; display: flex; flex-direction: column; }
.main-screen {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-height: 0;
}
.main-screen > .msg { margin: .5rem 1rem 0; }
.topbar .search-title { color: var(--muted); font-weight: 500; }
/* The dropdown and search box are wide but give way first, so the top bar
   stays on one line on desktop widths. */
.topbar select#project-select { flex: 0 1 20rem; min-width: 9rem; }
.topbar > * { white-space: nowrap; }
@media (min-width: 761px) {
  .topbar { flex-wrap: nowrap; }
}

/* Search box with the scope dropdown inside it, as one control. */
.search-group {
  display: flex;
  align-items: stretch;
  flex: 0 1 26rem;
  min-width: 13rem;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
}
.search-group:focus-within { outline: 2px solid var(--accent); outline-offset: 1px; }
.search-group input, .search-group select { border: 0; border-radius: 0; background: transparent; }
.search-group input { flex: 1; min-width: 0; border-radius: var(--radius) 0 0 var(--radius); }
.search-group select {
  border-left: 1px solid var(--border);
  color: var(--muted);
  font-size: .9em;
  border-radius: 0 var(--radius) var(--radius) 0;
}
.search-group input:focus, .search-group select:focus { outline: none; }
.topbar .user { color: var(--muted); }

.workspace {
  flex: 1;
  min-height: 0;
  display: grid;
  grid-template-columns: var(--left-width, 320px) 6px minmax(0, 1fr);
}
.pane-left, .pane-right { overflow: auto; min-width: 0; }
.pane-left { background: var(--surface); padding: .75rem 0 0; display: flex; flex-direction: column; }
.pane-left .project-name { font-size: 1rem; padding: 0 1rem; margin-bottom: .5rem; }
.pane-left .tabs { padding: 0 .5rem; border-bottom: 1px solid var(--border); margin-bottom: 0; }
.pane-left .tabs a[aria-current="page"] { border-bottom: 1px solid var(--surface); margin-bottom: -1px; }
.tabs .count { color: var(--muted); font-weight: 400; font-size: .85em; }
/* Right pane: white, like a page. The title line above it stays light gray
   and spans the full width; the padding lives on the header and body. */
.pane-right { background: var(--surface); }
.empty { color: var(--muted); padding: .75rem 1rem; margin: 0; }

.task-list { list-style: none; margin: 0; padding: 0; flex: 1; overflow: auto; }
.task-list a {
  display: block;
  padding: .45rem 1rem;
  border-bottom: 1px solid var(--border);
  border-left: 3px solid transparent;
  color: var(--text);
  text-decoration: none;
}
.task-list a:hover { background: var(--bg); }
.task-list a[aria-current="true"] { background: #eef3ff; border-left-color: var(--accent); }
.task-list .task-name { font-weight: 500; overflow-wrap: anywhere; }

.splitter {
  cursor: col-resize;
  background: var(--border);
  border-left: 2px solid var(--bg);
  border-right: 2px solid var(--bg);
  touch-action: none;
}
.splitter:hover, .splitter:focus-visible { background: var(--accent); outline: none; }
.resizing, .resizing * { cursor: col-resize !important; user-select: none !important; }

.task-header {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: .5rem 1rem;
  padding: .75rem 1.5rem;
  background: var(--bg);
  border-bottom: 1px solid var(--border);
  /* The name and buttons stay visible while the body scrolls. */
  position: sticky;
  top: 0;
  z-index: 1;
}
/* First line: name on the left; dates and buttons on the right. */
.task-title { flex: 1; min-width: 12rem; margin: 0; font-size: 1.4rem; overflow-wrap: anywhere; }
.task-header .dates { white-space: nowrap; }
.pane-right > .task-body { padding: 1rem 1.5rem 2rem; box-sizing: content-box; }
.pane-right > .empty { padding: 1rem 1.5rem; }

/* Task body: the user's HTML. Keep it readable and contained. */
/* Same text width as in the editor (60rem box minus its 1.5rem side padding). */
.task-body { max-width: 57rem; line-height: 1.6; overflow-wrap: anywhere; }
.task-body img { max-width: 100%; height: auto; }
.task-body pre { background: var(--bg); padding: .75rem; border-radius: var(--radius); overflow-x: auto; }
.task-body code { background: var(--bg); padding: .1em .3em; border-radius: 3px; font-size: .92em; }
.task-body pre code { background: none; padding: 0; }
.task-body blockquote { margin: 0; padding-left: 1rem; border-left: 3px solid var(--border); color: var(--muted); }
.task-body table { border-collapse: collapse; }
.task-body th, .task-body td { border: 1px solid var(--border); padding: .3rem .6rem; }

/* Popovers (New Project / New Task) — native, no JavaScript */
.popover {
  margin: 4rem auto auto;
  width: min(420px, calc(100vw - 2rem));
  box-shadow: 0 10px 30px rgba(0, 0, 0, .15);
}
.popover::backdrop { background: rgba(0, 0, 0, .25); }

/* Phones and narrow windows: stack the panes, hide the separator. */
@media (max-width: 760px) {
  body:has(> .main-screen) { height: auto; display: block; }
  .workspace { display: block; }
  .splitter { display: none; }
  .pane-left { max-height: 45vh; border-bottom: 1px solid var(--border); }
  .task-header { padding: .75rem 1rem; }
  .pane-right > .task-body { padding: 1rem; }
  .pane-right { min-height: 60vh; }
  .search-group { flex: 1 1 100%; }
  .topbar select#project-select { flex: 1 1 auto; }
}

/* ---------- Editor (full screen) ---------- */
body:has(> .editor-screen) { height: 100dvh; display: flex; flex-direction: column; }
.editor-screen { flex: 1; min-height: 0; display: flex; flex-direction: column; }
.editor-screen > .msg { margin: .5rem 1rem 0; }
.editor { flex: 1; min-height: 0; display: flex; flex-direction: column; }

.editor-bar {
  display: flex;
  align-items: center;
  gap: .75rem;
  padding: .5rem 1rem;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}
.editor-project { color: var(--muted); white-space: nowrap; max-width: 30%; overflow: hidden; text-overflow: ellipsis; }
.editor-name { flex: 1; min-width: 8rem; font-size: 1.2rem; font-weight: 600; border-color: transparent; }
.editor-name:hover { border-color: var(--border); }
#editor-status { white-space: nowrap; }
#editor-status.error { color: var(--danger); white-space: normal; }

.toolbar {
  display: flex;
  flex-wrap: wrap;
  gap: .25rem .75rem;
  padding: .4rem 1rem;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
}
.tb-group { display: inline-flex; gap: .2rem; }
.toolbar button {
  padding: .25rem .55rem;
  min-width: 2rem;
  font-size: .9rem;
  border-color: transparent;
  background: transparent;
}
.toolbar button:hover { border-color: var(--border); background: var(--bg); }
.toolbar button.active, .toolbar button[aria-pressed="true"] { background: #e3ebff; border-color: #b9cbff; }
.toolbar button code { background: none; padding: 0; }
.toolbar.source-mode button:not([data-cmd="source"]) { opacity: .35; pointer-events: none; }

.editor-scroll { flex: 1; min-height: 0; overflow: auto; background: var(--surface); }
.editor-area {
  min-height: 100%;
  max-width: 60rem;
  margin: 0 auto;
  padding: 1.25rem 1.5rem 4rem;
  outline: none;
}
.editor-area:empty::before { content: attr(data-placeholder); color: var(--muted); }
.editor-area.drop-target { background: #f0f5ff; box-shadow: inset 0 0 0 2px var(--accent); }
.editor-area img { cursor: default; }
.editor-area .uploading { color: var(--muted); font-style: italic; }
.editor-source {
  display: block;
  width: 100%;
  min-height: 100%;
  border: 0;
  border-radius: 0;
  padding: 1rem 1.5rem;
  font: .9rem/1.5 var(--mono);
  resize: none;
}
.editor-source[hidden], .editor-area[hidden] { display: none; }

@media (max-width: 760px) {
  .editor-bar { flex-wrap: wrap; }
  .editor-project { display: none; }
  .editor-name { flex-basis: 100%; order: -1; }
  .editor-area { padding: 1rem; }
}

/* ---------- Search results ---------- */
.search-summary { margin: 0; padding: .4rem 1rem .6rem; color: var(--muted); font-size: .85rem; border-bottom: 1px solid var(--border); }
.task-list.results a { display: flex; flex-direction: column; gap: .1rem; }
.result-project { color: var(--muted); font-size: .8rem; }
.excerpt {
  color: var(--muted);
  font-size: .82rem;
  line-height: 1.4;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}
.excerpt mark, .task-name mark { background: #fff1a8; color: inherit; padding: 0 .05em; border-radius: 2px; }
