/* Day to Day — a quiet, paper-like journal. Reading and writing come first; chrome stays out of the way. */

:root {
  --bg: #f6f2ea;           /* page / editor paper */
  --side: #fbf9f4;         /* sidebar */
  --surface: #ffffff;
  --text: #2a2622;
  --muted: #8b8478;
  --line: #e8e2d6;
  --hover: #f1ece2;
  --accent: #2e7d73;
  --accent-soft: #e0efec;
  --accent-text: #ffffff;
  --danger: #b4412f;
  --notice-bg: #fbf0d4;
  --notice-text: #6a5314;
  --shadow: 0 8px 28px rgb(40 30 10 / .16);

  --serif: "Iowan Old Style", "Palatino Linotype", Palatino, Charter, Georgia, "Noto Serif", serif;
  --sans: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", sans-serif;
  --radius: 12px;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #171614; --side: #1d1c1a; --surface: #25241f; --text: #ece7dd; --muted: #9a9488;
    --line: #34322d; --hover: #2a2926; --accent: #6fc5b9; --accent-soft: #223a36; --accent-text: #0c1a18;
    --danger: #ef8272; --notice-bg: #35301c; --notice-text: #e8d9a8; --shadow: 0 8px 28px rgb(0 0 0 / .5);
  }
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html { -webkit-text-size-adjust: 100%; }
html, body { height: 100%; margin: 0; }
body {
  height: 100dvh; overscroll-behavior: none;
  background: var(--bg); color: var(--text);
  font: 16px/1.5 var(--sans);
  padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left);
  -webkit-font-smoothing: antialiased;
}
h1, h2, p { margin: 0; }
button, input, textarea { font: inherit; color: inherit; touch-action: manipulation; -webkit-tap-highlight-color: transparent; }
button { cursor: pointer; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.danger { color: var(--danger); }
svg { width: 20px; height: 20px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }

/* ---------- buttons & fields ---------- */
button.primary {
  background: var(--accent); color: var(--accent-text); border: 0; border-radius: 10px;
  padding: .62rem 1rem; font-weight: 600; transition: filter .15s;
}
button.primary:hover { filter: brightness(1.07); }
button.primary:disabled { opacity: .6; cursor: wait; }
.icon-btn {
  display: grid; place-items: center; width: 2.25rem; height: 2.25rem; flex: none;
  background: none; border: 0; border-radius: 10px; color: var(--muted);
}
.icon-btn:hover { background: var(--hover); color: var(--text); }
.icon-btn.danger:hover { color: var(--danger); }
button.link { background: none; border: 0; color: var(--accent); padding: .2rem; font-size: .9rem; }
button.link:hover { text-decoration: underline; }

input, textarea, select {
  width: 100%; background: var(--surface); border: 1px solid var(--line); border-radius: 10px;
  padding: .6rem .8rem; transition: border-color .15s, box-shadow .15s;
}
input:focus, textarea:focus, select:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
input::placeholder, textarea::placeholder { color: var(--muted); opacity: .8; }

.seg, .tabs { display: grid; grid-auto-flow: column; grid-auto-columns: 1fr; background: var(--hover); border-radius: 10px; padding: 3px; }
.seg button, .tabs button {
  background: none; border: 0; padding: .42rem .8rem; border-radius: 8px; color: var(--muted); font-weight: 500; white-space: nowrap;
}
.seg button[aria-selected="true"], .tabs button[aria-selected="true"] {
  background: var(--surface); color: var(--text); box-shadow: 0 1px 2px rgb(0 0 0 / .12); font-weight: 600;
}

button.secondary {
  background: none; border: 1px solid var(--line); border-radius: 10px; padding: .62rem 1rem; font-weight: 500;
}
button.secondary:hover { background: var(--hover); }
button.primary.danger-btn { background: var(--danger); color: #fff; }

.dialog {
  width: min(420px, calc(100vw - 2rem)); padding: 1.6rem; border: 1px solid var(--line); border-radius: 18px;
  background: var(--surface); color: var(--text); box-shadow: var(--shadow);
}
.dialog::backdrop { background: rgb(20 15 5 / .45); }
.dialog form { display: grid; gap: 1rem; }
.dialog h2 { font: 700 1.3rem/1.2 var(--serif); }
.dialog .lead { color: var(--muted); }
.dialog label { display: grid; gap: .3rem; font-size: .85rem; font-weight: 500; color: var(--muted); }
.dialog-actions { display: flex; justify-content: flex-end; gap: .6rem; }

/* ---------- sign in ---------- */
.auth { min-height: 100%; display: grid; place-items: center; padding: 1.2rem; }
.card {
  width: min(400px, 100%); background: var(--surface); border: 1px solid var(--line);
  border-radius: 18px; padding: 2rem 1.8rem; display: grid; gap: 1rem; box-shadow: var(--shadow);
}
.card .logo { border-radius: 13px; }
.card h1 { font: 700 1.7rem/1.15 var(--serif); }
.card .lead { color: var(--muted); margin-top: -.5rem; }
.card label { display: grid; gap: .3rem; font-size: .85rem; font-weight: 500; color: var(--muted); }
.card .primary { padding: .75rem; }
.card button.link { justify-self: center; }
.error { color: var(--danger); font-size: .92rem; }
.info { color: var(--accent); font-size: .92rem; }
.sso { display: grid; gap: .5rem; }
.sso button {
  background: var(--surface); border: 1px solid var(--line); border-radius: 10px; padding: .65rem; font-weight: 600;
}
.sso button:hover { background: var(--hover); }
.or { display: flex; align-items: center; gap: .8rem; color: var(--muted); font-size: .8rem; }
.or::before, .or::after { content: ""; flex: 1; height: 1px; background: var(--line); }

/* ---------- app shell ---------- */
.app { height: 100%; }
.layout { height: 100%; display: grid; grid-template-columns: minmax(300px, 380px) 1fr; }

/* sidebar */
.browser {
  position: relative; display: flex; flex-direction: column; min-height: 0; min-width: 0;
  background: var(--side); border-right: 1px solid var(--line);
}
.brand-row { display: flex; align-items: center; justify-content: space-between; padding: 1rem 1rem .5rem 1.2rem; }
.brand { display: flex; align-items: center; gap: .6rem; font: 700 1.25rem/1 var(--serif); letter-spacing: -.01em; }
.brand img { border-radius: 8px; }

.menu {
  position: absolute; top: 3.6rem; right: .8rem; z-index: 10; min-width: 15rem; padding: .4rem;
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow);
  display: grid;
}
.menu button, .menu a { display: block; color: inherit; text-decoration: none; background: none; border: 0; text-align: left; padding: .6rem .75rem; border-radius: 8px; }
.menu button:hover, .menu a:hover { background: var(--hover); }
.menu hr { border: 0; border-top: 1px solid var(--line); margin: .3rem 0; }
.menu-user { padding: .5rem .75rem; color: var(--muted); font-size: .85rem; overflow-wrap: anywhere; }

.notice {
  display: flex; align-items: center; justify-content: space-between; gap: .6rem;
  margin: .2rem 1rem .4rem; padding: .5rem .75rem; border-radius: 10px;
  background: var(--notice-bg); color: var(--notice-text); font-size: .85rem;
}
.notice .link { color: inherit; font-weight: 600; text-decoration: underline; white-space: nowrap; }

.controls { display: grid; gap: .7rem; padding: .4rem 1rem .8rem; }
.quick { display: flex; gap: .5rem; align-items: center; }
.quick .primary { white-space: nowrap; }
.quick input { flex: 1; min-width: 0; color: var(--muted); padding: .55rem .7rem; }
.quick-label { display: none; }

.scroller {
  flex: 1; min-height: 0; overflow-y: auto; overflow-x: hidden; padding: 0 .6rem 1.5rem;
  scrollbar-width: thin; scrollbar-color: var(--line) transparent;
}
#search { position: sticky; top: 0; z-index: 1; margin: 0 .4rem .5rem; width: calc(100% - .8rem); }

/* list */
.month-label {
  margin: 1.1rem .6rem .25rem; font-size: .72rem; font-weight: 600; letter-spacing: .09em;
  text-transform: uppercase; color: var(--muted);
}
.entry {
  display: grid; grid-template-columns: 2.8rem minmax(0, 1fr); gap: .8rem; width: 100%; text-align: left;
  padding: .7rem .6rem; margin: 0; background: none; border: 0; border-radius: 10px; position: relative;
}
.entry:hover { background: var(--hover); }
.entry[aria-current="true"] { background: var(--accent-soft); }
.entry[aria-current="true"]::before {
  content: ""; position: absolute; left: 0; top: .7rem; bottom: .7rem; width: 3px; border-radius: 3px; background: var(--accent);
}
.entry .d { text-align: center; line-height: 1; padding-top: .1rem; }
.entry .d b { display: block; font: 600 1.5rem/1 var(--serif); }
.entry .d span { display: block; margin-top: .3rem; font-size: .68rem; letter-spacing: .06em; text-transform: uppercase; color: var(--muted); }
.entry .t { font: 600 1rem/1.35 var(--serif); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.entry .s {
  margin-top: .15rem; color: var(--muted); font-size: .88rem; line-height: 1.45;
  display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden;
}
.list-empty { text-align: center; padding: 3rem 1rem; color: var(--muted); }

/* calendar */
.cal-head { display: flex; justify-content: space-between; align-items: center; margin: .2rem .2rem .6rem; }
.cal-head strong { font: 600 1.2rem var(--serif); }
.cal-grid { display: grid; grid-template-columns: repeat(7, 1fr); gap: 4px; padding: 0 .2rem; }
.cal-grid .dow { text-align: center; font-size: .7rem; font-weight: 600; letter-spacing: .06em; text-transform: uppercase; color: var(--muted); padding: .3rem 0; }
.cal-grid button.day {
  aspect-ratio: 1; display: grid; place-items: center; position: relative; padding: 0;
  background: none; border: 1px solid transparent; border-radius: 12px; font-variant-numeric: tabular-nums;
}
.cal-grid button.day:hover:not(:disabled) { background: var(--hover); }
.cal-grid button.day:disabled { color: var(--muted); opacity: .4; cursor: default; }
.cal-grid button.day.has::after {
  content: ""; position: absolute; bottom: 22%; width: 5px; height: 5px; border-radius: 50%; background: var(--accent);
}
.cal-grid button.day.today { border-color: var(--accent); font-weight: 700; }
.cal-grid button.day.sel { background: var(--accent); color: var(--accent-text); border-color: var(--accent); }
.cal-grid button.day.sel::after { background: var(--accent-text); }

/* ---------- editor ---------- */
.editor {
  display: flex; flex-direction: column; min-height: 0; min-width: 0;
  padding: 1.1rem max(1.5rem, calc((100% - 42rem) / 2)) 0;
}
.editor-head { display: flex; align-items: center; gap: .5rem; margin-bottom: 1.2rem; }
.editor-head .when { margin-right: auto; }
.eyebrow { display: block; font-size: .72rem; font-weight: 600; letter-spacing: .09em; text-transform: uppercase; color: var(--accent); }
.editor-head h2 { font: 600 1.1rem/1.3 var(--serif); }
.status { font-size: .82rem; color: var(--muted); }
.back { display: none; }

#note-title {
  background: none; border: 0; border-radius: 0; padding: 0 0 .4rem; box-shadow: none;
  font: 700 2rem/1.25 var(--serif); letter-spacing: -.01em;
}
#note-text {
  flex: 1; min-height: 0; resize: none; background: none; border: 0; border-radius: 0; box-shadow: none;
  padding: .5rem 0 4rem; font: 1.15rem/1.8 var(--serif);
}
#note-title:focus, #note-text:focus { box-shadow: none; }

.empty { align-items: center; justify-content: center; gap: 1rem; color: var(--muted); text-align: center; padding-bottom: 6rem; }
.empty img { border-radius: 18px; opacity: .55; }

.toast {
  position: fixed; left: 50%; bottom: calc(1.5rem + env(safe-area-inset-bottom)); transform: translateX(-50%);
  background: var(--text); color: var(--bg); padding: .65rem 1.1rem; border-radius: 10px; z-index: 20;
  max-width: 90vw; box-shadow: var(--shadow); font-size: .92rem;
}

.fab { display: none; }

/* ---------- PIN lock screen ---------- */
.lock {
  position: fixed; inset: 0; z-index: 50; display: grid; place-items: center; background: var(--bg);
  padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left);
  overflow-y: auto;
}
.lock-card { width: min(320px, calc(100vw - 2rem)); display: grid; justify-items: center; gap: 1rem; padding: 1.5rem 0; text-align: center; }
.lock-card .logo { border-radius: 13px; }
.lock-card h1 { font: 700 1.45rem/1.2 var(--serif); }
.lock-card .lead { color: var(--muted); margin-top: -.5rem; }
.dots { display: flex; gap: .8rem; height: 1rem; align-items: center; }
.dot { width: .85rem; height: .85rem; border-radius: 50%; border: 2px solid var(--muted); transition: background .1s, border-color .1s; }
.dot.filled { background: var(--accent); border-color: var(--accent); }
.shake { animation: shake .35s; }
@keyframes shake { 20%, 60% { transform: translateX(-8px); } 40%, 80% { transform: translateX(8px); } }
.keypad { display: grid; grid-template-columns: repeat(3, 1fr); gap: .7rem; width: 100%; }
.key {
  aspect-ratio: 1.25; border-radius: 16px; border: 1px solid var(--line); background: var(--surface);
  font: 600 1.5rem var(--sans); color: var(--text);
}
.key:hover { background: var(--hover); }
.key:active { background: var(--accent-soft); }
.key-alt { font-size: 1.2rem; color: var(--muted); background: none; }
.lock .error { min-height: 1.3rem; }

/* ---------- touch screens ---------- */
@media (pointer: coarse) {
  .icon-btn { width: 2.75rem; height: 2.75rem; }
  .seg button, .tabs button, .menu button, button.link { min-height: 2.75rem; }
  .tabs button { min-height: 2.5rem; }
  input, textarea { font-size: 16px; }   /* stops iOS zooming into focused fields */
}

/* ---------- phones: list and editor are separate screens ---------- */
@media (max-width: 720px) {
  .layout { grid-template-columns: 1fr; }
  .browser { border-right: 0; }
  .layout.editing .browser, .layout:not(.editing) .editor, .empty { display: none; }
  .layout.editing .editor:not(.empty) { display: flex; }
  .back { display: grid; }

  .brand-row { padding: .8rem .8rem .4rem 1rem; }
  .menu { top: 3.4rem; right: .6rem; }
  .quick .primary { display: none; }                        /* the + button replaces it */
  .quick-label { display: block; color: var(--muted); font-size: .88rem; white-space: nowrap; }
  .scroller { padding-bottom: 6rem; }                       /* keep the last entries clear of the + button */

  .editor { padding: .6rem 1.1rem 0; }
  .editor-head { margin-bottom: .6rem; }
  #note-title { font-size: 1.6rem; }
  #note-text { font-size: 1.08rem; }

  .fab {
    display: grid; place-items: center; position: fixed; z-index: 5;
    right: calc(1.1rem + env(safe-area-inset-right)); bottom: calc(1.1rem + env(safe-area-inset-bottom));
    width: 3.6rem; height: 3.6rem; border: 0; border-radius: 50%; font-size: 2rem; line-height: 1;
    background: var(--accent); color: var(--accent-text); box-shadow: 0 6px 18px rgb(0 0 0 / .3);
  }
  .layout.editing + .fab { display: none; }                 /* hide while a note is open */
}

@media (prefers-reduced-motion: reduce) { * { transition: none !important; animation: none !important; } }
