/* Daybook — a paper-planner calendar: warm paper, deep ink, one vermilion accent. */
:root {
  --paper: #f5f0e6;
  --paper-2: #efe8da;
  --card: #fbf8f2;
  --ink: #1c1a17;
  --ink-2: #4a453d;
  --muted: #8a8276;
  --rule: #ddd4c3;
  --rule-soft: #e8e1d3;
  --accent: #d9412b;
  --accent-soft: #f6d9d1;

  /* event colors: [fill, text] */
  --c-ink: #2b2925;       --c-ink-bg: #e4e0d8;
  --c-vermilion: #c2381f; --c-vermilion-bg: #f7dcd3;
  --c-moss: #4d6b2f;      --c-moss-bg: #e0e8cf;
  --c-ocean: #23577a;     --c-ocean-bg: #d5e3ec;
  --c-ochre: #a26a0e;     --c-ochre-bg: #f3e3c0;
  --c-plum: #74345f;      --c-plum-bg: #ecd8e4;

  --display: 'Fraunces', Georgia, serif;
  --body: 'IBM Plex Sans', system-ui, sans-serif;
  --mono: 'IBM Plex Mono', ui-monospace, monospace;
  --radius: 6px;
}

* { box-sizing: border-box; margin: 0; padding: 0; }
[hidden] { display: none !important; }
html, body { height: 100%; }
body {
  font: 14px/1.45 var(--body);
  color: var(--ink);
  background-color: var(--paper);
  /* subtle paper grain */
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='160' height='160'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='.9' numOctaves='2' stitchTiles='stitch'/%3E%3CfeColorMatrix values='0 0 0 0 0.35 0 0 0 0 0.3 0 0 0 0 0.2 0 0 0 .07 0'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)'/%3E%3C/svg%3E");
  -webkit-font-smoothing: antialiased;
}
button { font: inherit; color: inherit; background: none; border: 0; cursor: pointer; }
input, textarea { font: inherit; color: inherit; }
svg { width: 18px; height: 18px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; flex: none; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

.muted { color: var(--muted); }
.error { color: var(--accent); font-size: 13px; min-height: 1.2em; }

/* ── Buttons ─────────────────────────────────────────────────────────────── */
.btn { display: inline-flex; align-items: center; gap: 8px; height: 36px; padding: 0 14px; border-radius: var(--radius); font-weight: 500; white-space: nowrap; transition: background .15s, transform .1s; }
.btn:active { transform: translateY(1px); }
.btn-primary { background: var(--ink); color: var(--paper); }
.btn-primary:hover { background: #000; }
.btn-primary:disabled { opacity: .6; cursor: wait; }
.btn-ghost { border: 1px solid var(--rule); background: var(--card); }
.btn-ghost:hover { border-color: var(--ink-2); }
.btn-danger { color: var(--accent); padding: 0 6px; }
.btn-danger:hover { text-decoration: underline; }
.icon-btn { display: inline-grid; place-items: center; width: 34px; height: 34px; border-radius: var(--radius); color: var(--ink-2); }
.icon-btn:hover { background: var(--paper-2); color: var(--ink); }

/* ── Brand ───────────────────────────────────────────────────────────────── */
.brand { display: flex; align-items: center; gap: 9px; font: 600 19px var(--display); letter-spacing: -.01em; }
.brand-dot { width: 12px; height: 12px; border-radius: 50%; background: var(--accent); box-shadow: 0 0 0 3px var(--paper), 0 0 0 4px var(--ink); }

/* ── Auth ────────────────────────────────────────────────────────────────── */
.auth { min-height: 100%; display: grid; place-items: center; padding: 24px; }
.auth-card { width: min(400px, 100%); background: var(--card); border: 1px solid var(--rule); border-radius: 10px; padding: 36px 32px 30px; box-shadow: 0 1px 0 #fff inset, 0 30px 60px -30px rgba(60, 40, 10, .35); display: grid; gap: 14px; animation: rise .5s ease both; }
.auth-card h1 { font: 400 36px/1.05 var(--display); letter-spacing: -.02em; margin-top: 18px; }
.auth-card .btn { justify-content: center; height: 42px; margin-top: 4px; }

/* ── Fields ──────────────────────────────────────────────────────────────── */
.field { display: grid; gap: 5px; }
.field > span, .swatches legend { font: 500 11px var(--mono); text-transform: uppercase; letter-spacing: .08em; color: var(--muted); }
.field input, .field textarea { width: 100%; padding: 9px 11px; border: 1px solid var(--rule); border-radius: var(--radius); background: #fff; }
.field input:focus, .field textarea:focus { outline: none; border-color: var(--ink); }
.field textarea { resize: vertical; }

/* ── Top bar ─────────────────────────────────────────────────────────────── */
.app { height: 100%; display: flex; flex-direction: column; }
.topbar { display: flex; align-items: center; gap: 24px; padding: 14px 24px; border-bottom: 1px solid var(--ink); }
.nav { display: flex; align-items: center; gap: 10px; flex: 1; min-width: 0; }
.arrows { display: flex; }
.period { font: 400 26px/1 var(--display); letter-spacing: -.02em; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; margin-left: 6px; }
.period em { font-style: italic; }
.actions { display: flex; align-items: center; gap: 10px; }
.seg { display: flex; border: 1px solid var(--ink); border-radius: var(--radius); overflow: hidden; }
.seg button { height: 34px; padding: 0 14px; font-weight: 500; color: var(--ink-2); }
.seg button + button { border-left: 1px solid var(--ink); }
.seg button[aria-selected="true"] { background: var(--ink); color: var(--paper); }
.seg button:not([aria-selected="true"]):hover { background: var(--paper-2); }

.view { flex: 1; min-height: 0; display: flex; flex-direction: column; }

/* ── Event colors ────────────────────────────────────────────────────────── */
.c-ink { --fg: var(--c-ink); --bg: var(--c-ink-bg); }
.c-vermilion { --fg: var(--c-vermilion); --bg: var(--c-vermilion-bg); }
.c-moss { --fg: var(--c-moss); --bg: var(--c-moss-bg); }
.c-ocean { --fg: var(--c-ocean); --bg: var(--c-ocean-bg); }
.c-ochre { --fg: var(--c-ochre); --bg: var(--c-ochre-bg); }
.c-plum { --fg: var(--c-plum); --bg: var(--c-plum-bg); }

/* ── Month ───────────────────────────────────────────────────────────────── */
.month { flex: 1; display: flex; flex-direction: column; min-height: 0; padding: 0 24px 20px; }
.month-head { display: grid; grid-template-columns: repeat(7, 1fr); }
.month-head div { padding: 12px 10px 8px; font: 500 11px var(--mono); text-transform: uppercase; letter-spacing: .1em; color: var(--muted); }
.month-grid { flex: 1; display: grid; grid-template-columns: repeat(7, 1fr); grid-template-rows: repeat(6, minmax(96px, 1fr)); border-top: 1px solid var(--rule); border-left: 1px solid var(--rule); }
.cell { border-right: 1px solid var(--rule); border-bottom: 1px solid var(--rule); padding: 6px 6px 4px; min-width: 0; min-height: 0; overflow: hidden; display: flex; flex-direction: column; gap: 4px; cursor: pointer; background: rgba(251, 248, 242, .55); animation: fade .4s ease both; animation-delay: calc(var(--i) * 6ms); }
.cell:hover { background: var(--card); }
.cell.is-weekend { background: rgba(239, 232, 218, .5); }
.cell.is-out { background: transparent; }
.cell.is-out .num { color: #b7ae9f; }
.num { align-self: flex-start; min-width: 28px; height: 28px; padding: 0 6px; border-radius: 14px; font: 400 17px/28px var(--display); text-align: center; }
.num:hover { background: var(--paper-2); }
.cell.is-today .num { background: var(--accent); color: #fff; font-weight: 600; }
.chips { display: grid; gap: 2px; min-width: 0; }
.chip { display: flex; align-items: center; gap: 6px; min-width: 0; padding: 1px 6px; border-radius: 4px; font-size: 12.5px; text-align: left; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.chip::before { content: ''; flex: none; width: 7px; height: 7px; border-radius: 50%; background: var(--fg); }
.chip .t { font: 12px var(--mono); color: var(--muted); }
.chip:hover { background: var(--bg); }
.chip.is-allday { background: var(--bg); color: var(--fg); font-weight: 500; }
.chip.is-allday::before { display: none; }
.more { align-self: flex-start; padding: 0 6px; font: 500 11.5px var(--mono); color: var(--ink-2); }
.more:hover { color: var(--accent); }

/* ── Time grid (day + week) ──────────────────────────────────────────────── */
.tg { --gutter: 64px; flex: 1; min-height: 0; display: flex; flex-direction: column; padding: 0 24px; }
.tg-head, .tg-allday, .tg-body { display: grid; grid-template-columns: var(--gutter) repeat(var(--days), minmax(0, 1fr)); }
.tg-head { border-bottom: 1px solid var(--rule); }
.tg-day { display: flex; align-items: baseline; justify-content: center; gap: 8px; padding: 12px 4px 10px; animation: rise .45s ease both; animation-delay: calc(var(--i) * 35ms); }
.tg-day:hover .dn { color: var(--accent); }
.tg-day .wd { font: 500 11px var(--mono); text-transform: uppercase; letter-spacing: .1em; color: var(--muted); }
.tg-day .dn { font: 400 28px/1 var(--display); letter-spacing: -.02em; }
.tg-day.is-today .dn { color: var(--accent); font-style: italic; font-weight: 600; }
.tg-day.is-today .wd { color: var(--accent); }
.tg-single .tg-day { justify-content: flex-start; padding-left: 12px; }

.tg-allday { border-bottom: 1px solid var(--ink); min-height: 30px; }
.tg-label { font: 500 10px var(--mono); text-transform: uppercase; letter-spacing: .08em; color: var(--muted); align-self: center; text-align: right; padding-right: 10px; }
.tg-bars { grid-column: 2 / -1; display: grid; grid-template-columns: repeat(var(--days), minmax(0, 1fr)); grid-auto-flow: row dense; gap: 2px 0; padding: 4px 0; align-content: start; }
.bar { margin: 0 3px; padding: 2px 8px; border-radius: 4px; background: var(--bg); color: var(--fg); font-weight: 500; font-size: 12.5px; text-align: left; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; border-left: 3px solid var(--fg); }
.bar:hover { filter: brightness(.96); }

.tg-scroll { flex: 1; min-height: 0; overflow-y: auto; overflow-x: hidden; scrollbar-width: thin; }
.tg-hours { position: relative; }
.tg-hours span { position: absolute; right: 10px; transform: translateY(-50%); font: 11px var(--mono); color: var(--muted); white-space: nowrap; }
.tg-col { position: relative; border-left: 1px solid var(--rule-soft); touch-action: pan-y; cursor: crosshair;
  background-image: linear-gradient(to bottom, var(--rule) 1px, transparent 1px), linear-gradient(to bottom, transparent 25px, var(--rule-soft) 26px, transparent 27px);
  background-size: 100% 52px; }
.tg-col.is-today { background-color: rgba(246, 217, 209, .22); }
.tg-col:last-child { border-right: 1px solid var(--rule-soft); }

.ev { position: absolute; z-index: 1; display: flex; flex-direction: column; align-items: flex-start; gap: 1px; padding: 4px 7px; overflow: hidden; border-radius: 5px; background: var(--bg); color: var(--fg); border-left: 3px solid var(--fg); text-align: left; font-size: 12.5px; line-height: 1.3; cursor: pointer; box-shadow: 0 0 0 1px var(--card); animation: fade .3s ease both; }
.ev:hover { z-index: 2; box-shadow: 0 0 0 1px var(--card), 0 6px 16px -6px rgba(40, 25, 5, .35); }
.ev strong { font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 100%; }
.ev .t, .ev .loc { font: 11px var(--mono); opacity: .85; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 100%; }
.ev.is-short { flex-direction: row; align-items: center; gap: 6px; padding-top: 1px; padding-bottom: 1px; }
.ev.is-short .loc { display: none; }
.ghost { position: absolute; left: 2px; right: 2px; z-index: 3; border-radius: 5px; background: rgba(28, 26, 23, .1); border: 1.5px dashed var(--ink-2); pointer-events: none; }
.now-line { position: absolute; left: -5px; right: 0; z-index: 4; height: 2px; background: var(--accent); pointer-events: none; }
.now-line::before { content: ''; position: absolute; left: 0; top: -4px; width: 10px; height: 10px; border-radius: 50%; background: var(--accent); }

/* ── Dialog ──────────────────────────────────────────────────────────────── */
.dialog { margin: auto; width: min(480px, calc(100% - 24px)); border: 1px solid var(--ink); border-radius: 10px; padding: 0; background: var(--card); color: var(--ink); box-shadow: 0 40px 80px -30px rgba(40, 25, 5, .5); }
.dialog[open] { animation: rise .25s ease both; }
.dialog::backdrop { background: rgba(28, 26, 23, .35); backdrop-filter: blur(2px); }
.dialog { overflow-x: hidden; }
.dialog form { display: grid; grid-template-columns: minmax(0, 1fr); gap: 14px; padding: 18px 22px 20px; }
.dialog .field, .when > * { min-width: 0; }
.dialog-head { display: flex; align-items: center; justify-content: space-between; }
.dialog-head h3 { font: 500 11px var(--mono); text-transform: uppercase; letter-spacing: .1em; color: var(--muted); }
.title-input { width: 100%; border: 0; border-bottom: 1px solid var(--rule); padding: 4px 0 8px; background: transparent; font: 400 26px/1.15 var(--display); letter-spacing: -.01em; }
.title-input:focus { outline: none; border-color: var(--ink); }
.title-input::placeholder { color: #bcb3a4; font-style: italic; }
.toggle { display: inline-flex; align-items: center; gap: 8px; font-weight: 500; cursor: pointer; justify-self: start; }
.toggle input { accent-color: var(--ink); width: 16px; height: 16px; }
.when { display: grid; grid-template-columns: minmax(0, 1fr); gap: 12px; }
.pair { display: flex; gap: 6px; }
.pair input[type="date"] { flex: 1.6; min-width: 0; }
.pair input[type="time"] { flex: 1; min-width: 0; }
.is-allday .pair input[type="time"] { display: none; }
.swatches { border: 0; display: grid; gap: 7px; }
#ev-colors { display: flex; gap: 10px; }
.swatch { position: relative; cursor: pointer; }
.swatch input { position: absolute; opacity: 0; }
.swatch span { display: block; width: 26px; height: 26px; border-radius: 50%; background: var(--fg); box-shadow: 0 0 0 2px var(--card), 0 0 0 3px transparent; transition: box-shadow .15s, transform .15s; }
.swatch:hover span { transform: scale(1.08); }
.swatch input:checked + span { box-shadow: 0 0 0 2px var(--card), 0 0 0 4px var(--ink); }
.swatch input:focus-visible + span { outline: 2px solid var(--accent); outline-offset: 4px; }
.dialog-foot { display: flex; align-items: center; gap: 8px; margin-top: 4px; }
.spacer { flex: 1; }

/* ── Motion ──────────────────────────────────────────────────────────────── */
@keyframes rise { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }
@keyframes fade { from { opacity: 0; } to { opacity: 1; } }
@media (prefers-reduced-motion: reduce) { * { animation: none !important; transition: none !important; } }

/* ── Small screens ───────────────────────────────────────────────────────── */
@media (max-width: 860px) {
  .topbar { flex-wrap: wrap; gap: 10px 12px; padding: 12px 14px; }
  .topbar > .brand { display: none; }
  .nav { order: 2; flex-basis: 100%; }
  .actions { order: 1; flex: 1; justify-content: space-between; }
  .period { font-size: 22px; }
  .btn-primary span { display: none; }
  .btn-primary { padding: 0 10px; }
  .month { padding: 0 8px 10px; }
  .tg { --gutter: 46px; padding: 0 6px; }
  /* week: horizontally scrollable, ~3 days visible */
  .tg:not(.tg-single) { overflow-x: auto; }
  .tg:not(.tg-single) > * { min-width: calc(var(--gutter) + var(--days) * 104px); }
  .tg:not(.tg-single) .tg-scroll { overflow-y: auto; }
  .tg-day { flex-direction: column; align-items: center; gap: 2px; }
}
@media (max-width: 600px) {
  .month-grid { grid-template-rows: repeat(6, minmax(64px, 1fr)); }
  .month-head div { padding: 8px 4px; text-align: center; font-size: 10px; letter-spacing: .04em; }
  .num { font-size: 15px; min-width: 24px; height: 24px; line-height: 24px; padding: 0 4px; align-self: center; }
  .cell { padding: 3px 2px; }
  /* chips become dots */
  .chips { display: flex; flex-wrap: wrap; justify-content: center; gap: 3px; }
  .chip, .chip.is-allday { width: 7px; height: 7px; padding: 0; border-radius: 50%; background: var(--fg); font-size: 0; }
  .chip::before, .chip .t { display: none; }
  .more { font-size: 0; width: 7px; height: 7px; padding: 0; border-radius: 50%; border: 1px solid var(--ink-2); }
  .when { grid-template-columns: 1fr; }
}

/* ── Repeat + scope (dialog) ─────────────────────────────────────────────── */
.repeat { display: grid; gap: 10px; }
.field select { width: 100%; padding: 9px 11px; border: 1px solid var(--rule); border-radius: var(--radius); background: #fff; font: inherit; color: inherit; }
.field select:focus { outline: none; border-color: var(--ink); }
.field i { text-transform: none; letter-spacing: 0; font-style: italic; }
.repeat-more { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1.4fr); gap: 12px; }
.repeat-more .pair { align-items: center; }
.repeat-more input[type="number"] { width: 72px; flex: none; }
.repeat-more em { font-style: normal; color: var(--ink-2); }
.repeat-summary { font: italic 15px var(--display); color: var(--ink-2); min-height: 0; }
.repeat-summary:empty { display: none; }
.scope { display: grid; gap: 10px; padding: 14px; border: 1px solid var(--ink); border-radius: var(--radius); background: var(--paper); animation: rise .2s ease both; }
.scope p { font: 400 17px/1.3 var(--display); }
.scope-btns { display: flex; flex-wrap: wrap; gap: 8px; }
.btn-link { color: var(--muted); padding: 0 6px; }
.btn-link:hover { color: var(--ink); }

/* repeat marker on events */
.rep { display: inline-block; width: 11px; height: 11px; margin-right: 3px; vertical-align: -1px; stroke-width: 2.2; opacity: .8; }
@media (max-width: 600px) { .chip .rep { display: none; } }

/* Request log under the sign-in form */
.auth { align-content: center; gap: 16px; }
.netlog { width: min(640px, 100%); font-size: 13px; color: var(--ink-2); }
.netlog summary { cursor: pointer; font: 500 11px var(--mono); text-transform: uppercase; letter-spacing: .08em; color: var(--muted); }
.netlog .toggle { margin: 10px 0; }
.netlog-entry { font: 12px/1.5 var(--mono); white-space: pre-wrap; word-break: break-all; background: var(--card); border: 1px solid var(--rule); border-left: 3px solid var(--moss, #4f6b2a); border-radius: 6px; padding: 10px 12px; margin: 0 0 8px; }
.netlog-entry.is-bad { border-left-color: var(--accent); }

