/* Dark-first palette (matches the manifest's theme_color), with a light
 * override. Vanilla CSS, no preprocessor -- consistent with the rest of
 * the frontend having no build step. */
:root {
  --bg: #12141c;
  --bg-elevated: #1b1e29;
  --bg-input: #232734;
  --text: #e8e9ee;
  --text-muted: #9298a8;
  --border: #2c303e;
  --accent: #f4c542;
  --accent-text: #12141c;
  --danger: #e5637a;
  --today-ring: #6ea8fe;
  --radius: 10px;
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
}

@media (prefers-color-scheme: light) {
  :root {
    --bg: #f6f6f8;
    --bg-elevated: #ffffff;
    --bg-input: #ffffff;
    --text: #1b1e29;
    --text-muted: #5b6072;
    --border: #dfe1e8;
    --accent: #c9891a;
    --accent-text: #ffffff;
    --danger: #b23a52;
    --today-ring: #2d6cdf;
  }
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  -webkit-tap-highlight-color: transparent;
}

body {
  min-height: 100vh;
  min-height: 100dvh;
}

#app {
  min-height: 100vh;
  min-height: 100dvh;
}

a { color: inherit; }

/* Only safe to use standalone on an element with no padding of its own --
 * anything that also sets its own `padding` shorthand (topnav, the login
 * screen, the day panel) must instead bake env() into that same rule via
 * calc(), further down. A separate class here loses the cascade to a
 * same-specificity shorthand `padding` rule declared later in the file --
 * exactly the bug that left the topnav rendering under the iOS Dynamic
 * Island despite this class being applied to it. */
.safe-top { padding-top: env(safe-area-inset-top); }
.safe-bottom { padding-bottom: env(safe-area-inset-bottom); }

.hidden { display: none !important; }

.loading, .error {
  padding: 1.5rem;
  color: var(--text-muted);
}
.error { color: var(--danger); }

button {
  font-family: inherit;
  font-size: 1rem;
  cursor: pointer;
  border-radius: var(--radius);
  border: none;
  padding: 0.6rem 1rem;
}
button:disabled { opacity: 0.5; cursor: default; }

.btn-primary {
  background: var(--accent);
  color: var(--accent-text);
  font-weight: 600;
}
.btn-ghost {
  background: transparent;
  color: var(--text);
  border: 1px solid var(--border);
}
.btn-icon {
  background: transparent;
  color: var(--text-muted);
  border: none;
  padding: 0.25rem 0.5rem;
  font-size: 0.85rem;
}

input[type="text"], input[type="password"], textarea {
  width: 100%;
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text);
  padding: 0.65rem 0.8rem;
  font-family: inherit;
  font-size: 1rem;
}
textarea { resize: vertical; font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; }

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

.login-screen {
  min-height: 100vh;
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 1.5rem;
  padding: 1.5rem;
  padding-top: calc(1.5rem + env(safe-area-inset-top));
  padding-bottom: calc(1.5rem + env(safe-area-inset-bottom));
}
.login-screen h1 { margin: 0; letter-spacing: 0.02em; }
.setup-intro {
  margin: -0.75rem 0 0;
  max-width: 320px;
  text-align: center;
  color: var(--text-muted);
  font-size: 0.9rem;
}
.login-form {
  display: flex;
  flex-direction: column;
  gap: 1rem;
  width: 100%;
  max-width: 320px;
}
.login-form label {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
  font-size: 0.85rem;
  color: var(--text-muted);
}

/* ---------------- App shell / nav ---------------- */

.app-shell {
  display: flex;
  flex-direction: column;
  min-height: 100vh;
  min-height: 100dvh;
}
.topnav {
  display: flex;
  align-items: center;
  gap: 1rem;
  padding: 0.75rem 1rem;
  padding-top: calc(0.75rem + env(safe-area-inset-top));
  border-bottom: 1px solid var(--border);
  background: var(--bg-elevated);
  position: sticky;
  top: 0;
  z-index: 5;
}
.brand { font-weight: 700; flex-shrink: 0; }
.nav-links {
  display: flex;
  gap: 0.25rem;
  flex: 1;
  /* min-width: 0 is the actual fix -- a flex: 1 child otherwise refuses
   * to shrink below its content's intrinsic width (min-width: auto is
   * the flexbox default), so on a narrow iOS viewport the nav links
   * push the logout button straight off the right edge of the screen
   * instead of yielding space to it. Letting this box scroll
   * horizontally on its own, rather than overflowing into siblings, is
   * the other half of the fix. */
  min-width: 0;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}
.nav-links a {
  text-decoration: none;
  padding: 0.4rem 0.75rem;
  border-radius: var(--radius);
  color: var(--text-muted);
  font-size: 0.95rem;
  flex-shrink: 0;
  white-space: nowrap;
}
.nav-links a:hover { background: var(--bg-input); color: var(--text); }
#logout-btn { flex-shrink: 0; }

.view-container {
  flex: 1;
  padding: 1rem;
  max-width: 720px;
  width: 100%;
  margin: 0 auto;
}

/* ---------------- Entry editor (Today view + day panel) ---------------- */

.entry-date {
  margin: 0 0 1rem;
  font-size: 1.15rem;
}

.quick-form { display: flex; gap: 0.5rem; }
.quick-form input { flex: 1; }

.quick-display {
  display: flex;
  align-items: flex-start;
  gap: 0.6rem;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 0.8rem 1rem;
}
.quick-dot {
  width: 0.55rem;
  height: 0.55rem;
  border-radius: 50%;
  background: var(--accent);
  margin-top: 0.4rem;
  flex-shrink: 0;
}
.quick-text { flex: 1; margin: 0; white-space: pre-wrap; word-break: break-word; }

.notes-block { margin-top: 1.25rem; }
.notes-heading {
  margin: 0 0 0.5rem;
  font-size: 0.85rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--text-muted);
}
.note-links {
  list-style: none;
  margin: 0 0 0.75rem;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
}
.note-link {
  display: block;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 0.6rem 0.9rem;
  text-decoration: none;
  color: var(--text);
}
.note-link:hover { border-color: var(--accent); }

.tabs { display: flex; gap: 0.4rem; }
.tab-btn {
  background: transparent;
  border: 1px solid var(--border);
  color: var(--text-muted);
  padding: 0.35rem 0.75rem;
  font-size: 0.85rem;
}
.tab-btn.active { color: var(--text); border-color: var(--accent); }
.editor-actions { display: flex; justify-content: flex-end; gap: 0.5rem; }

.markdown-body { line-height: 1.55; word-wrap: break-word; }
.markdown-body h1, .markdown-body h2, .markdown-body h3 { margin: 0.6em 0 0.3em; }
.markdown-body p { margin: 0.5em 0; }
.markdown-body ul, .markdown-body ol { padding-left: 1.4em; }
.markdown-body blockquote {
  margin: 0.5em 0;
  padding: 0.2em 0.9em;
  border-left: 3px solid var(--accent);
  color: var(--text-muted);
}
.markdown-body pre {
  background: var(--bg-input);
  border-radius: var(--radius);
  padding: 0.75em;
  overflow-x: auto;
}
.markdown-body code {
  background: var(--bg-input);
  border-radius: 4px;
  padding: 0.1em 0.35em;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}
.markdown-body pre code { background: none; padding: 0; }
.markdown-body img { max-width: 100%; }

/* ---------------- Month view (day list) ---------------- */

.cal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 0.75rem;
}
.cal-header h2 { margin: 0; font-size: 1.1rem; }

.day-list {
  display: flex;
  flex-direction: column;
}
.week-group {
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
}
.week-group + .week-group {
  margin-top: 0.9rem;
  padding-top: 0.9rem;
  border-top: 1px solid var(--border);
}
.day-row {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0.65rem 0.9rem;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  background: var(--bg-elevated);
  cursor: pointer;
}
.day-row:hover { border-color: var(--accent); }
.day-row.is-today { box-shadow: inset 0 0 0 2px var(--today-ring); }
.day-row.selected { border-color: var(--accent); background: var(--bg-input); }

.day-row-date {
  flex-shrink: 0;
  width: 3.6rem;
  color: var(--text-muted);
  font-variant-numeric: tabular-nums;
  font-size: 0.9rem;
}
.day-row.is-today .day-row-date { color: var(--text); font-weight: 600; }

.day-row-quick {
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.day-row-quick.empty { color: var(--text-muted); font-style: italic; }

.day-row-notecount {
  flex-shrink: 0;
  min-width: 1.4rem;
  height: 1.4rem;
  padding: 0 0.4rem;
  border-radius: 999px;
  background: var(--bg-input);
  border: 1px solid var(--border);
  color: var(--text-muted);
  font-size: 0.75rem;
  display: flex;
  align-items: center;
  justify-content: center;
}

.day-row-check {
  flex-shrink: 0;
  width: 1.1rem;
  height: 1.1rem;
  border-radius: 4px;
  border: 1px solid var(--border);
}
.day-row.selected .day-row-check { background: var(--accent); border-color: var(--accent); }

.cal-toolbar {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  margin-top: 1rem;
  flex-wrap: wrap;
}
.select-count { color: var(--text-muted); font-size: 0.9rem; }

/* ---------------- Year view (plain month list) ---------------- */

.month-list {
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
}
.month-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  padding: 0.85rem 1rem;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  background: var(--bg-elevated);
  cursor: pointer;
}
.month-row:hover { border-color: var(--accent); }
.month-row-name { font-weight: 600; }
.month-row-summary { color: var(--text-muted); font-size: 0.9rem; }

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

.note-view { display: flex; flex-direction: column; gap: 0.85rem; }
.note-header {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}
.note-title-input {
  flex: 1;
  font-size: 1.2rem;
  font-weight: 600;
  border: none;
  background: transparent;
  padding: 0.3rem 0;
}
.note-title-input:focus { outline: none; border-bottom: 1px solid var(--accent); }
.note-meta {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  flex-wrap: wrap;
  color: var(--text-muted);
  font-size: 0.9rem;
}
.note-meta a { color: var(--accent); text-decoration: none; }
.note-meta input[type="date"] {
  width: auto;
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text);
  padding: 0.35rem 0.5rem;
}
.note-content-textarea { min-height: 40vh; }
.muted { color: var(--text-muted); }

.note-organize {
  display: flex;
  gap: 0.75rem;
  flex-wrap: wrap;
}
.note-organize-field {
  display: flex;
  flex-direction: column;
  gap: 0.3rem;
  font-size: 0.8rem;
  color: var(--text-muted);
  flex: 1;
  min-width: 180px;
}

/* ---------------- Notes fuzzy-search view ---------------- */

.notes-search-view { display: flex; flex-direction: column; gap: 1rem; }
.notes-results { display: flex; flex-direction: column; gap: 0.4rem; }
.note-result {
  display: flex;
  align-items: baseline;
  gap: 0.5rem;
  flex-wrap: wrap;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 0.65rem 0.9rem;
  text-decoration: none;
  color: var(--text);
}
.note-result:hover { border-color: var(--accent); }
.note-result-title { font-weight: 600; }
.note-result-folder {
  color: var(--text-muted);
  font-size: 0.8rem;
  padding: 0.1em 0.5em;
  border: 1px solid var(--border);
  border-radius: 999px;
}
.note-result-date { color: var(--text-muted); font-size: 0.8rem; font-variant-numeric: tabular-nums; }
.note-tag {
  color: var(--accent);
  font-size: 0.8rem;
}
.note-tag::before { content: "#"; }
.note-result-preview {
  flex-basis: 100%;
  color: var(--text-muted);
  font-size: 0.85rem;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* ---------------- Day overlay panel ---------------- */

.day-overlay {
  position: fixed;
  inset: 0;
  z-index: 10;
  display: flex;
  align-items: flex-end;
}
.day-overlay-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(0, 0, 0, 0.5);
}
.day-panel {
  position: relative;
  background: var(--bg);
  width: 100%;
  max-height: 88vh;
  overflow-y: auto;
  border-radius: 16px 16px 0 0;
  padding: 1.25rem;
  padding-bottom: calc(1.25rem + env(safe-area-inset-bottom));
  margin: 0 auto;
  max-width: 720px;
}
.close-panel {
  position: absolute;
  top: 0.75rem;
  right: 0.75rem;
  font-size: 1rem;
}

@media (min-width: 720px) {
  .day-overlay { align-items: center; justify-content: center; }
  .day-panel { border-radius: 16px; max-width: 560px; max-height: 80vh; }
}
