/* Дневник — light/dark driven by the shell's `appearance`, never by the
   browser's own prefers-color-scheme once inside Manaurum (the two
   disagree: a user in a dark OS with a light browser profile would
   otherwise get a light app inside a dark desktop). The inline script in
   index.html stamps data-appearance on <html>; everything here paints
   through var(). */

:root[data-appearance='light'] {
  --bg: #f7f8fb;
  --surface: #ffffff;
  --surface-2: #f1f3f8;
  --fg: #16181d;
  --fg-soft: #565d6d;
  --fg-faint: #8a91a1;
  --line: #e3e6ee;
  --line-soft: #edeff5;
  --accent: #0058bc;
  --accent-soft: rgba(0, 88, 188, 0.09);
  --ok: #17803d;
  --warn: #a55a00;
}

:root[data-appearance='dark'] {
  --bg: #0f1218;
  --surface: #161a22;
  --surface-2: #1c212b;
  --fg: #e8ebf2;
  --fg-soft: #a3abbb;
  --fg-faint: #767f92;
  --line: #262c39;
  --line-soft: #1f2531;
  --accent: #6ea8ff;
  --accent-soft: rgba(110, 168, 255, 0.14);
  --ok: #4ade80;
  --warn: #fbbf24;
}

* { box-sizing: border-box; }

/* `hidden` is display:none only in the *browser's* stylesheet, so any
   author rule with a display wins over it and the element stays visible.
   That silently breaks every empty state. */
[hidden] { display: none !important; }

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

body {
  background: var(--bg);
  color: var(--fg);
  font: 15px/1.55 -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
  overflow: hidden;
}

.app { display: flex; height: 100%; }

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

.sidebar {
  width: 248px;
  flex: 0 0 248px;
  display: flex;
  flex-direction: column;
  background: var(--surface-2);
  border-right: 1px solid var(--line);
  padding: 14px 10px 10px;
  overflow: hidden;
}

.sidebar-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.09em;
  text-transform: uppercase;
  color: var(--fg-faint);
  padding: 0 8px 10px;
}

/* Two-class selector on purpose: `.icon-btn` below sets
   `display: inline-flex` and, at equal specificity, the later rule wins —
   a bare `.sidebar-close { display: none }` loses and the close button
   shows up on desktop where there is nothing to close. */
.sidebar .sidebar-close { display: none; }

.day-list {
  list-style: none;
  margin: 0;
  padding: 0;
  overflow-y: auto;
  flex: 1;
}

.day-list li { margin-bottom: 2px; }

.day-list button {
  width: 100%;
  text-align: left;
  border: none;
  background: transparent;
  color: inherit;
  font: inherit;
  padding: 9px 10px;
  border-radius: 10px;
  cursor: pointer;
  display: block;
}

.day-list button:hover { background: var(--line-soft); }

.day-list button[aria-current='true'] {
  background: var(--accent-soft);
}

.day-list .d-date {
  display: block;
  font-size: 12.5px;
  font-weight: 600;
  margin-bottom: 2px;
}

.day-list button[aria-current='true'] .d-date { color: var(--accent); }

.day-list .d-snippet {
  display: block;
  font-size: 12px;
  color: var(--fg-soft);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.sidebar-empty {
  color: var(--fg-faint);
  font-size: 12.5px;
  padding: 4px 10px;
  margin: 0;
}

.scrim { display: none; }

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

.page {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-width: 0;
  background: var(--surface);
}

.daybar {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 12px 16px;
  border-bottom: 1px solid var(--line-soft);
  flex-shrink: 0;
}

.daybar-title {
  flex: 1;
  min-width: 0;
  text-align: center;
}

.daybar-title h1 {
  margin: 0;
  font-size: 19px;
  font-weight: 700;
  letter-spacing: -0.015em;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* The native date input sits invisibly over its label so the whole
   "сегодня / вчера" line is the click target for picking a date. */
.day-picker {
  position: relative;
  display: inline-flex;
  align-items: center;
  gap: 4px;
  margin-top: 1px;
  font-size: 12px;
  color: var(--fg-faint);
  cursor: pointer;
}

.day-picker::after {
  content: '▾';
  font-size: 10px;
}

.day-picker input[type='date'] {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  opacity: 0;
  cursor: pointer;
  border: none;
  padding: 0;
}

.icon-btn {
  width: 32px;
  height: 32px;
  flex: 0 0 32px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border: none;
  border-radius: 9px;
  background: transparent;
  color: var(--fg-soft);
  cursor: pointer;
  padding: 0;
}

.icon-btn:hover { background: var(--surface-2); color: var(--fg); }

.icon-btn svg {
  width: 19px;
  height: 19px;
  fill: none;
  stroke: currentColor;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.icon-btn:disabled {
  opacity: 0.28;
  cursor: default;
  background: transparent;
}

.daybar .sidebar-open { display: none; }

.today-btn {
  border: 1px solid var(--line);
  background: transparent;
  color: var(--fg-soft);
  font: inherit;
  font-size: 12.5px;
  font-weight: 600;
  padding: 6px 12px;
  border-radius: 9px;
  cursor: pointer;
  flex-shrink: 0;
}

.today-btn:hover { background: var(--surface-2); color: var(--fg); }
.today-btn:disabled { opacity: 0.4; cursor: default; background: transparent; }

/* ----------------------------------------------------------- editor */

.editor-wrap {
  flex: 1;
  overflow-y: auto;
  display: flex;
  justify-content: center;
  padding: 26px 20px 40px;
}

#editor {
  width: 100%;
  max-width: 680px;
  min-height: 100%;
  border: none;
  outline: none;
  resize: none;
  background: transparent;
  color: var(--fg);
  font-family: 'Georgia', 'Times New Roman', serif;
  font-size: 17px;
  line-height: 1.75;
}

#editor::placeholder { color: var(--fg-faint); }

#editor:disabled { opacity: 0.5; }

.statusbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  height: 38px;
  flex-shrink: 0;
  padding: 0 18px;
  border-top: 1px solid var(--line-soft);
  font-size: 12px;
  color: var(--fg-faint);
}

.status[data-state='saved'] { color: var(--ok); }
.status[data-state='unsaved'] { color: var(--warn); }
.status[data-state='error'] { color: #dc2626; }

:root[data-appearance='dark'] .status[data-state='error'] { color: #f87171; }

/* ----------------------------------------------------------- mobile */

:root[data-device='mobile'] .sidebar {
  position: fixed;
  z-index: 30;
  top: 0;
  bottom: 0;
  left: 0;
  width: 82%;
  max-width: 320px;
  flex-basis: auto;
  transform: translateX(-102%);
  transition: transform 0.18s ease;
  box-shadow: 0 0 40px rgba(0, 0, 0, 0.25);
}

:root[data-device='mobile'] .sidebar[data-open='true'] { transform: none; }
:root[data-device='mobile'] .sidebar .sidebar-close { display: inline-flex; }
:root[data-device='mobile'] .daybar .sidebar-open { display: inline-flex; }

:root[data-device='mobile'] .scrim[data-open='true'] {
  display: block;
  position: fixed;
  inset: 0;
  z-index: 25;
  background: rgba(0, 0, 0, 0.35);
}

:root[data-device='mobile'] .daybar { padding: 10px 10px; gap: 2px; }
:root[data-device='mobile'] .daybar-title h1 { font-size: 16px; }
:root[data-device='mobile'] .today-btn { padding: 6px 9px; font-size: 12px; }
:root[data-device='mobile'] .editor-wrap { padding: 18px 16px 32px; }
:root[data-device='mobile'] #editor { font-size: 16px; }
