/* pen v0.1 — vox terminal-layer aesthetic (slate + terminal-green accents, JetBrains Mono). */

:root {
  --bg:          #0e1513;
  --bg-elev:     #131c19;
  --bg-hover:    #1b2622;
  --ink:         #d3dcd7;
  --ink-soft:    #7d8b85;
  --rule:        #23302b;
  --accent:      #7ad39a;      /* terminal green */
  --amber:       #d9a75a;
  --red:         #d97a7a;
  --sb-height:   1.9rem;
  --sidebar-w:   14rem;
  --topbar-h:   2.4rem;
  --mono: ui-monospace, "JetBrains Mono", SFMono-Regular, "SF Mono", Menlo, Consolas, "Liberation Mono", monospace;
}

*, *::before, *::after { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--mono);
  font-size: 14px;
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
}

button, input, textarea, select {
  font-family: inherit;
  font-size: inherit;
  color: inherit;
  background: transparent;
  border: 0;
  padding: 0;
  margin: 0;
  outline: none;
}

button { cursor: pointer; }

/* ---------- app grid ---------- */

.app {
  display: grid;
  grid-template-columns: var(--sidebar-w) 1fr;
  grid-template-rows: 1fr var(--sb-height);
  grid-template-areas:
    "sidebar main"
    "status  status";
  height: 100dvh;
  overflow: hidden;
}

.sidebar   { grid-area: sidebar; }
.main      { grid-area: main; }
.statusbar { grid-area: status; }

/* ---------- sidebar ---------- */

.sidebar {
  background: var(--bg-elev);
  border-right: 1px solid var(--rule);
  display: flex;
  flex-direction: column;
  min-width: 0;
  overflow: hidden;
  position: relative;
}

/* Full-height invisible hitbox for drag; the visible affordance is the pill pseudo-element. */
.sidebar-handle {
  position: absolute;
  top: 0;
  right: 0;
  width: 10px;
  height: 100%;
  cursor: col-resize;
  z-index: 20;
  background: transparent;
}

.sidebar-handle::before {
  content: "";
  position: absolute;
  top: 50%;
  right: 2px;
  transform: translateY(-50%);
  width: 4px;
  height: 32px;
  border-radius: 4px;
  background: var(--rule);
  transition: background 120ms ease, height 120ms ease;
}

.sidebar-handle:hover::before {
  background: var(--accent);
  height: 44px;
}

.sidebar-handle.dragging::before {
  background: var(--accent);
  height: 60px;
}

.sidebar-head {
  padding: 0.75rem 0.9rem 0.5rem;
  border-bottom: 1px solid var(--rule);
}

.brand {
  color: var(--accent);
  font-weight: 600;
  letter-spacing: 0.02em;
}

.brand-name { color: var(--ink); }

.brand-ver {
  color: var(--ink-soft);
  font-weight: 400;
  font-size: 0.82em;
}

.sidebar-actions {
  display: flex;
  gap: 0.4rem;
  padding: 0.5rem 0.6rem;
  border-bottom: 1px solid var(--rule);
}

.sb-btn {
  color: var(--ink-soft);
  padding: 0.25rem 0.5rem;
  border-radius: 3px;
  transition: color 120ms, background 120ms;
  white-space: nowrap;
}

.sb-btn:hover { color: var(--ink); background: var(--bg-hover); }
.sb-btn:active { color: var(--accent); }

.note-list {
  flex: 1;
  overflow-y: auto;
  padding: 0.4rem 0.3rem;
  scrollbar-width: thin;
  scrollbar-color: var(--rule) transparent;
}

.note-item {
  display: block;
  width: 100%;
  text-align: left;
  padding: 0.4rem 0.6rem;
  color: var(--ink-soft);
  border-left: 2px solid transparent;
  border-radius: 2px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  cursor: pointer;
  transition: color 120ms, background 120ms, border-color 120ms;
}

.note-item:hover { color: var(--ink); background: var(--bg-hover); }

.note-item.active {
  color: var(--ink);
  background: var(--bg-hover);
  border-left-color: var(--accent);
}

.note-item .note-item-meta {
  display: block;
  font-size: 0.78em;
  color: var(--ink-soft);
  margin-top: 1px;
}

.note-item.active .note-item-meta { color: var(--ink-soft); }

/* ---------- main writing area ---------- */

.main {
  display: flex;
  flex-direction: column;
  background: var(--bg);
  min-width: 0;
  overflow: hidden;
}

.topbar {
  height: var(--topbar-h);
  border-bottom: 1px solid var(--rule);
  display: flex;
  align-items: center;
  padding: 0 1rem;
  flex-shrink: 0;
}

.note-title {
  width: 100%;
  color: var(--ink);
  font-weight: 500;
}

.note-title::placeholder { color: var(--ink-soft); }

.sheet {
  flex: 1;
  overflow: hidden;
  display: flex;
  justify-content: center;
  padding: 2rem 1.5rem 1.5rem;
}

.editor {
  width: 100%;
  max-width: 78ch;
  height: 100%;
  resize: none;
  color: var(--ink);
  background: transparent;
  line-height: 1.75;
  scrollbar-width: thin;
  scrollbar-color: var(--rule) transparent;
  caret-color: var(--accent);
}

.editor::placeholder { color: var(--ink-soft); }
.editor::selection { background: rgba(122, 211, 154, 0.25); }

/* ---------- status bar ---------- */

.statusbar {
  background: var(--bg-elev);
  border-top: 1px solid var(--rule);
  display: flex;
  align-items: center;
  gap: 1rem;
  padding: 0 0.75rem;
  font-size: 0.82rem;
  overflow: hidden;
  color: var(--ink-soft);
}

.sb-left, .sb-right { display: flex; gap: 0.6rem; align-items: center; flex-shrink: 0; }
.sb-right { margin-left: auto; }

.chip { color: var(--ink-soft); white-space: nowrap; }

.chip-btn {
  padding: 0.1rem 0.4rem;
  border-radius: 3px;
  transition: color 100ms, background 100ms;
  cursor: pointer;
}
.chip-btn:hover  { color: var(--ink); background: var(--bg-hover); }
.chip-btn:active { color: var(--accent); }

#chipSave[data-state="dirty"]  { color: var(--amber); }
#chipSave[data-state="saved"]  { color: var(--accent); }
#chipSave[data-state="error"]  { color: var(--red); }

/* ---------- popovers (anchored to status-bar chips) ---------- */

.popover {
  position: fixed;
  bottom: calc(var(--sb-height) + 0.35rem);
  background: var(--bg-elev);
  border: 1px solid var(--rule);
  border-radius: 4px;
  padding: 0.35rem;
  font-size: 0.82rem;
  color: var(--ink);
  z-index: 50;
  min-width: 12rem;
  box-shadow: 0 6px 16px rgba(0,0,0,0.35);
}

.pop-title {
  color: var(--ink-soft);
  font-size: 0.72rem;
  letter-spacing: 0.08em;
  padding: 0.15rem 0.5rem 0.35rem;
  border-bottom: 1px solid var(--rule);
  margin-bottom: 0.35rem;
}

.pop-item {
  display: block;
  width: 100%;
  text-align: left;
  padding: 0.35rem 0.55rem;
  color: var(--ink-soft);
  border-radius: 3px;
  cursor: pointer;
  transition: color 100ms, background 100ms;
  white-space: nowrap;
}
.pop-item:hover  { color: var(--ink); background: var(--bg-hover); }
.pop-item:active { color: var(--accent); }

.pop-row {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  padding: 0.3rem 0.55rem;
}

.pop-label { color: var(--ink); flex: 1; }
.pop-actions { display: flex; gap: 0.3rem; }

.pop-state {
  color: var(--ink-soft);
  font-size: 0.78em;
  white-space: nowrap;
}
.pop-state-on    { color: var(--accent); }
.pop-state-off   { color: var(--ink-soft); }
.pop-state-error { color: var(--red); }

.pop-action {
  color: var(--ink-soft);
  padding: 0.1rem 0.4rem;
  border-radius: 3px;
  transition: color 100ms, background 100ms;
  cursor: pointer;
}
.pop-action:hover  { color: var(--ink); background: var(--bg-hover); }
.pop-action:disabled { color: var(--rule); cursor: not-allowed; }

.pop-sep {
  height: 1px;
  background: var(--rule);
  margin: 0.3rem 0.2rem;
}

.pop-item-shortcut {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 1rem;
}

.pop-kbd {
  color: var(--ink-soft);
  font-size: 0.78em;
  letter-spacing: 0.02em;
}

.pop-note {
  color: var(--ink-soft);
  font-size: 0.75rem;
  padding: 0.4rem 0.55rem 0.2rem;
  border-top: 1px solid var(--rule);
  margin-top: 0.3rem;
  line-height: 1.45;
  white-space: normal;
  max-width: 20rem;
}

.sb-toolbar {
  display: flex;
  align-items: center;
  gap: 0.15rem;
  padding: 0 0.5rem;
  overflow-x: auto;
  scrollbar-width: none;
  flex: 1;
  min-width: 0;
  justify-content: center;
}

.sb-toolbar::-webkit-scrollbar { display: none; }

.tb-btn {
  color: var(--ink-soft);
  padding: 0.1rem 0.45rem;
  min-width: 1.8rem;
  border-radius: 3px;
  transition: color 100ms, background 100ms;
  white-space: nowrap;
}

.tb-btn:hover  { color: var(--ink); background: var(--bg-hover); }
.tb-btn:active { color: var(--accent); }

.tb-sep {
  color: var(--rule);
  padding: 0 0.15rem;
  user-select: none;
}

/* ---------- responsive ---------- */

@media (max-width: 720px) {
  :root { --sidebar-w: 100%; }
  .app {
    grid-template-columns: 1fr;
    grid-template-rows: auto 1fr var(--sb-height);
    grid-template-areas: "sidebar" "main" "status";
  }
  .sidebar { max-height: 40vh; border-right: 0; border-bottom: 1px solid var(--rule); }
  .sheet { padding: 1rem; }
  .sb-toolbar { justify-content: flex-start; }
}
