/* ════════════════════════════════════════════════════════════════
   Calm calendar (Phase 1)
   Loaded last so it can settle the older layered calendar rules.
   Principles: one row of controls, two layers in a day (posts are
   solid, plans are outlined), gaps are invitations, not alarms.
   ════════════════════════════════════════════════════════════════ */

[hidden] { display: none !important; }

/* ── Toolbar: turn the page, pick a zoom, add ───────────────────── */
#calendarView .calm-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: nowrap;
  gap: var(--s3);
  padding: var(--s2) 0 var(--s4);
  margin: 0;
  position: static;
}
#calendarView .calm-toolbar .cal-toolbar-nav {
  display: flex;
  align-items: center;
  gap: 2px;
  min-width: 0;
  width: auto;
  padding: 0;
}
#calendarView .calm-toolbar .cal-month-label {
  margin: 0 var(--s2);
  font-family: var(--font-display);
  font-size: 26px;
  font-weight: 400;
  letter-spacing: -.01em;
  line-height: 1.1;
  color: var(--ink);
  white-space: nowrap;
  min-width: 0;
}
.cal-nav-btn {
  width: 32px;
  height: 32px;
  display: inline-grid;
  place-items: center;
  border: 0;
  border-radius: 50%;
  background: transparent;
  color: var(--muted);
  font-size: 22px;
  line-height: 1;
  cursor: pointer;
  transition: background .15s, color .15s;
}
.cal-nav-btn:hover { background: var(--surface3); color: var(--ink); }
.cal-nav-btn:focus-visible { outline: 2px solid var(--brand); outline-offset: 1px; }
#calendarView .cal-today-btn { margin-left: var(--s2); font-size: 12px; }

#calendarView .calm-toolbar .cal-toolbar-right {
  display: flex;
  align-items: center;
  flex-wrap: nowrap;
  gap: var(--s2);
  width: auto;
  position: relative;
}

/* Segmented Month / Week */
#calendarView .calm-toolbar .cal-view-toggle {
  display: inline-flex;
  gap: 0;
  margin: 0;
  padding: 2px;
  border: 1px solid var(--border);
  border-radius: calc(var(--r) + 2px);
  background: var(--surface2);
}
.seg-btn {
  appearance: none;
  border: 0;
  background: transparent;
  color: var(--muted);
  font: 500 12px/1 inherit;
  font-family: inherit;
  padding: 7px 12px;
  border-radius: var(--r);
  cursor: pointer;
  transition: background .15s, color .15s;
}
.seg-btn:hover { color: var(--ink); }
.seg-btn.active { background: var(--surface); color: var(--ink); box-shadow: var(--shadow-sm); }
.seg-btn:focus-visible { outline: 2px solid var(--brand); outline-offset: 1px; }

#calendarView .cal-add-btn { min-height: 32px; padding-inline: 14px; }

/* Bell only appears when something needs you */
#calendarView .cal-alert-bell { width: 32px; height: 32px; border-radius: 50%; }

/* "Filtered · Clear" — so an emptier calendar never looks like lost posts */
.cal-filter-chip {
  appearance: none;
  border: 1px solid var(--border2);
  background: var(--surface);
  color: var(--muted);
  font: 500 12px/1 inherit;
  font-family: inherit;
  padding: 7px 10px;
  border-radius: 999px;
  cursor: pointer;
  white-space: nowrap;
}
.cal-filter-chip span { color: var(--brand); }
.cal-filter-chip:hover { border-color: var(--brand-glow); }

/* ⋯ menu */
.calendar-more { position: relative; }
.cal-more-btn {
  position: relative;
  width: 32px;
  height: 32px;
  display: grid;
  place-items: center;
  border: 1px solid var(--border);
  border-radius: 50%;
  background: var(--surface);
  color: var(--ink);
  font-size: 18px;
  line-height: 1;
  cursor: pointer;
  list-style: none;
}
.cal-more-btn::-webkit-details-marker { display: none; }
.calendar-more[open] > .cal-more-btn,
.cal-more-btn:hover { border-color: var(--border2); background: var(--surface2); }
.cal-more-btn:focus-visible { outline: 2px solid var(--brand); outline-offset: 2px; }
.cal-more-dot {
  position: absolute;
  top: 3px;
  right: 3px;
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--brand);
  box-shadow: 0 0 0 2px var(--surface);
}
#calendarView .calendar-more-menu {
  right: 0;
  left: auto;
  width: 280px;
  padding: 6px;
  border-radius: calc(var(--r) + 3px);
  box-shadow: var(--shadow-float);
}
.more-section { padding: 10px; }
.more-section + .more-section { border-top: 1px solid var(--border); }
.more-heading {
  font: 600 10px/1 'DM Mono', monospace;
  letter-spacing: .08em;
  text-transform: uppercase;
  color: var(--subtle);
  margin-bottom: 10px;
}
.calendar-more-menu .seg-row {
  display: flex;
  padding: 2px;
  margin-bottom: 12px;
  border: 1px solid var(--border);
  border-radius: calc(var(--r) + 2px);
  background: var(--surface2);
}
.calendar-more-menu .seg-row .seg-btn { flex: 1; }
#calendarView .calendar-more-menu .input { height: 32px; font-size: 12px; margin-bottom: 10px; }
.calendar-more-menu .label { font-size: 11px; color: var(--muted); margin-bottom: 4px; }
.more-section:has(.more-item) { padding: 4px; }
.more-item {
  display: flex;
  align-items: center;
  width: 100%;
  padding: 9px 10px;
  border: 0;
  border-radius: var(--r);
  background: transparent;
  color: var(--text);
  font: 13px/1.2 inherit;
  font-family: inherit;
  text-align: left;
  text-decoration: none;
  cursor: pointer;
}
.more-item:hover, .more-item:focus-visible { background: var(--surface2); color: var(--ink); outline: none; }
.more-item.active::after { content: '✓'; margin-left: auto; color: var(--brand); }
.more-link {
  appearance: none;
  border: 0;
  background: none;
  padding: 0;
  color: var(--muted);
  font: 12px/1 inherit;
  font-family: inherit;
  text-decoration: underline;
  text-underline-offset: 3px;
  cursor: pointer;
}
.more-link:hover { color: var(--ink); }

/* Status line only renders when something needs attention */
#calendarView .calendar-state { margin: -4px 0 var(--s3); font-size: 12px; color: var(--muted); }

/* ── Day cells ──────────────────────────────────────────────────── */
#calendarView .cal-day {
  gap: 3px;
  padding: 8px;
  border-color: var(--border);
  background: var(--surface);
}
#calendarView .cal-day.has-posts { border-color: var(--border); }
#calendarView .cal-day.has-gap { border-color: var(--border); background: var(--surface); }
#calendarView .cal-day:hover { border-color: var(--border2); background: var(--surface); }
#calendarView .cal-day.other-month { opacity: .4; }

/* Today: a filled date, not a tinted box */
#calendarView .cal-day.today { border-color: var(--border2); background: var(--surface); box-shadow: inset 0 2px 0 var(--brand); }
#calendarView .cal-day.today .day-num {
  display: inline-grid;
  place-items: center;
  min-width: 20px;
  height: 20px;
  padding: 0 5px;
  border-radius: 10px;
  background: var(--brand);
  color: #fff;
  font-weight: 700;
}

/* The + appears when you reach for a day (always visible on touch) */
#calendarView .day-add-note-btn { opacity: 0; transition: opacity .15s; }
#calendarView .cal-day:hover .day-add-note-btn,
#calendarView .cal-day:focus-within .day-add-note-btn,
#calendarView .cal-week-day:hover .day-add-note-btn,
#calendarView .cal-week-day:focus-within .day-add-note-btn { opacity: 1; }
@media (hover: none) { #calendarView .day-add-note-btn { opacity: 1; } }

/* Layer 1 — Posts: solid, platform icon first */
#calendarView .day-post-pill {
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: var(--r);
  font-size: 11px;
  padding: 4px 6px;
}
#calendarView .day-post-pill:hover,
#calendarView .day-post-pill:focus-visible { border-color: var(--border2); background: var(--surface3); }
#calendarView .day-post-pill.is-published { opacity: .7; }

/* Layer 2 — Plans: outlined in their note colour, nothing filled */
#calendarView .day-note-pill,
#calendarView button.day-note-pill {
  display: flex;
  align-items: flex-start;
  gap: 6px;
  background: transparent;
  border: 1px solid color-mix(in srgb, var(--note-color, var(--muted)) 45%, transparent) !important;
  border-left: 2px solid var(--note-color, var(--muted)) !important;
  border-radius: var(--r);
  color: var(--text);
  font-size: 11px;
  padding: 3px 6px;
}
#calendarView button.day-note-pill:hover,
#calendarView button.day-note-pill:focus-visible { background: var(--note-tint, var(--surface2)); outline: none; filter: none; }
#calendarView .day-note-pill .note-copy { overflow: hidden; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; min-width: 0; }
.note-check {
  flex: 0 0 10px;
  width: 10px;
  height: 10px;
  margin-top: 2px;
  border: 1.5px solid var(--note-color, var(--muted));
  border-radius: 50%;
}
.note-check.is-checked { background: var(--note-color, var(--muted)); box-shadow: inset 0 0 0 1.5px var(--surface); }
#calendarView .day-note-pill.is-done { opacity: .6; }

/* Shelf items placed on a date but not yet in Buffer: a dashed outline */
#calendarView .content-calendar-pill {
  background: transparent;
  border: 1px dashed var(--border2);
  border-radius: var(--r);
}

#calendarView .more-indicator {
  margin-top: 0;
  font: 500 10px/1.4 'DM Mono', monospace;
  color: var(--muted);
}

/* Gaps: an empty, dashed slot that invites a post */
.day-gap-slot {
  margin-top: auto;
  padding: 4px 6px;
  border: 1px dashed var(--border2);
  border-radius: var(--r);
  color: var(--subtle);
  font-size: 10.5px;
  line-height: 1.3;
  text-align: center;
  transition: border-color .15s, color .15s, background .15s;
}
.cal-day:hover .day-gap-slot,
.cal-week-day:hover .day-gap-slot,
.calendar-agenda-day:hover .day-gap-slot { border-color: var(--brand-glow); color: var(--brand); background: var(--brand-dim); }

/* Week view: cards stay consistent with month cells */
#calendarView .cal-week-day .day-gap-slot { margin-top: var(--s2); }

/* ── Agenda (phones and List view) ─────────────────────────────── */
.calendar-agenda-day { border-radius: calc(var(--r) + 3px); padding: 14px 16px; }
.calendar-agenda-day .day-gap-slot { margin-top: var(--s2); padding: 8px; font-size: 12px; }
.calendar-agenda-day.is-empty {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--s3);
  padding: 10px 16px;
  background: transparent;
  border-style: dashed;
}
.calendar-agenda-day.is-empty .calendar-agenda-heading { margin: 0; flex: 1; }
.calendar-agenda-day.is-empty .calendar-agenda-heading strong { color: var(--muted); font-weight: 500; }
.calendar-agenda-day.is-empty .calendar-agenda-empty { order: 2; margin: 0; font-size: 12px; color: var(--subtle); white-space: nowrap; }
.calendar-agenda-day.is-empty .calendar-agenda-heading .btn { order: 3; }

/* ── Phones ─────────────────────────────────────────────────────── */
@media (max-width: 768px) {
  #calendarView .calm-toolbar {
    position: sticky;
    top: 0;
    z-index: 15;
    margin: 0 -16px;
    padding: 10px 16px;
    background: var(--bg);
    border-bottom: 1px solid var(--border);
  }
  #calendarView .calm-toolbar .cal-toolbar-right { display: flex; width: auto; }
  #calendarView .calm-toolbar .cal-view-toggle { display: none; }
  #calendarView .calm-toolbar .cal-month-label { font-size: 19px; margin: 0 2px; }
  #calendarView .cal-today-btn { margin-left: 0; padding-inline: 8px; }
  #calendarView .cal-add-btn { width: 36px; min-height: 36px; padding: 0; justify-content: center; font-size: 18px; border-radius: 50%; }
  #calendarView .cal-add-label { display: none; }
  #calendarView .cal-nav-btn { width: 30px; height: 30px; }
  #calendarView .cal-more-btn, #calendarView .cal-alert-bell { width: 36px; height: 36px; }
  #calendarView .cal-filter-chip { display: none !important; } /* the dot on ⋯ carries it on phones */
  #calendarView .calendar-more { position: static; }
  #calendarView .calendar-more-menu {
    position: fixed;
    left: 12px;
    right: 12px;
    top: auto;
    bottom: calc(72px + env(safe-area-inset-bottom, 0px));
    width: auto;
    max-height: 70vh;
    overflow: auto;
  }
  .more-item { padding: 12px 10px; font-size: 14px; }
  .seg-btn { padding: 10px 12px; font-size: 13px; }
}

@media (prefers-reduced-motion: reduce) {
  .cal-nav-btn, .seg-btn, #calendarView .day-add-note-btn, .day-gap-slot { transition: none; }
}

/* Toolbar type, set explicitly (the font shorthand can't inherit a family) */
.seg-btn, .cal-filter-chip, .more-item, .more-link { font-family: inherit; }
.seg-btn { font-size: 12px; font-weight: 500; line-height: 1; }
.cal-filter-chip { font-size: 12px; font-weight: 500; line-height: 1; }
.more-item { font-size: 13px; line-height: 1.2; }
.more-link { font-size: 12px; line-height: 1; }

/* Agenda cards keep the icon and the text on one line */
.calendar-agenda-day .day-post-pill,
.calendar-agenda-day .day-note-pill,
.calendar-agenda-day button.day-note-pill { display: flex !important; align-items: flex-start; gap: 8px; width: 100%; margin: 8px 0 0; font-size: 13px; padding: 8px 10px; }
.calendar-agenda-day .platform-logo { width: 18px; height: 18px; flex-basis: 18px; }
.calendar-agenda-day .day-post-copy { -webkit-line-clamp: 3; }
.calendar-agenda-day .note-check { margin-top: 3px; }

/* ── Shelf: one place for past posts and ideas ─────────────────── */
.shelf-tabs {
  display: inline-flex;
  gap: 0;
  margin: 0 0 var(--s4);
  padding: 2px;
  border: 1px solid var(--border);
  border-radius: calc(var(--r) + 2px);
  background: var(--surface2);
}
.shelf-tabs:has([data-shelf-tab="ideasView"][hidden]) { display: none; }
.shelf-tab {
  appearance: none;
  border: 0;
  background: transparent;
  color: var(--muted);
  font-family: inherit;
  font-size: 13px;
  font-weight: 500;
  padding: 8px 16px;
  border-radius: var(--r);
  cursor: pointer;
}
.shelf-tab:hover { color: var(--ink); }
.shelf-tab.active { background: var(--surface); color: var(--ink); box-shadow: var(--shadow-sm); }
.shelf-tab:focus-visible { outline: 2px solid var(--brand); outline-offset: 1px; }
#libraryView > .shelf-tabs, #ideasView > .shelf-tabs { margin-left: 32px; }
@media (max-width: 768px) {
  #libraryView > .shelf-tabs, #ideasView > .shelf-tabs { margin: 8px 16px 12px; display: flex; }
  #libraryView > .shelf-tabs:has([data-shelf-tab="ideasView"][hidden]),
  #ideasView > .shelf-tabs:has([data-shelf-tab="ideasView"][hidden]) { display: none; }
  .shelf-tab { flex: 1; padding: 10px; }
}

/* Phones: the Shelf earns a spot in the tab bar; list view is the only view, so its menu item goes */
@media (max-width: 768px) {
  .mobile-tabs .mob-tab[data-shelf-nav]:not([hidden]) { display: flex !important; }
  #calendarView .calendar-more-menu #calendarViewAgendaBtn { display: none; }
  #calendarView .calendar-more-menu .input { height: 42px; font-size: 15px; line-height: 1.2; padding-top: 0; padding-bottom: 0; }
}

/* Shelf tabs only make sense when both halves exist */
.shelf-tabs:has([data-shelf-tab="libraryView"][hidden]) { display: none !important; }

/* A gentle nudge on the Shelf entry when Ideas is switched on in Settings */
@keyframes shelf-nudge {
  0%, 100% { box-shadow: 0 0 0 0 transparent; }
  30% { box-shadow: 0 0 0 3px var(--brand-glow); }
}
.shelf-nudge { animation: shelf-nudge 1.2s ease-in-out 2; border-radius: var(--r); }
@media (prefers-reduced-motion: reduce) { .shelf-nudge { animation: none; outline: 2px solid var(--brand-glow); } }

/* ════════════════════════════════════════════════════════════════
   Phase 2: delight — Today strip, fill cards, quick add, drag, holidays
   ════════════════════════════════════════════════════════════════ */

/* ── Today strip ───────────────────────────────────────────────── */
.today-strip {
  display: grid;
  grid-template-columns: minmax(220px, 1fr) minmax(300px, 1.3fr);
  gap: var(--s5);
  align-items: start;
  margin: 0 0 var(--s4);
  padding: 16px 18px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-left: 3px solid var(--brand);
  border-radius: calc(var(--r) + 2px);
}
.today-strip:not(:has(.today-right)) { grid-template-columns: 1fr; }
.today-kicker {
  font: 600 10px/1 'DM Mono', monospace;
  letter-spacing: .1em;
  text-transform: uppercase;
  color: var(--brand);
}
.today-date { margin: 6px 0 8px; font-family: var(--font-display); font-size: 20px; color: var(--ink); line-height: 1.15; }
.today-going { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; font-size: 13px; color: var(--text); }
.today-icons { display: inline-flex; gap: 3px; }
.today-muted { color: var(--muted); font-size: 13px; }
.today-todos { list-style: none; margin: 10px 0 0; padding: 0; display: grid; gap: 6px; font-size: 13px; }
.today-todos label { display: flex; gap: 8px; align-items: flex-start; cursor: pointer; }
.today-todos input { margin-top: 2px; accent-color: var(--brand); }
.today-todos input:checked + span { text-decoration: line-through; color: var(--muted); }
.today-calm { display: grid; gap: 6px; align-content: center; height: 100%; font-size: 13px; color: var(--muted); }
.today-calm strong { color: var(--ink); font-weight: 600; }

/* ── Fill card (Today strip and open-slot popover) ─────────────── */
.fill-card { display: grid; gap: 10px; }
.fill-head { display: flex; align-items: center; gap: 8px; font-size: 13px; color: var(--text); }
.fill-head strong { color: var(--ink); }
.fill-quote {
  margin: 0;
  padding: 10px 12px;
  border: 1px dashed var(--border2);
  border-radius: var(--r);
  background: var(--surface2);
  font-size: 13px;
  line-height: 1.45;
  color: var(--text);
}
.fill-empty { margin: 0; font-size: 13px; color: var(--muted); }
.fill-actions { display: flex; flex-wrap: wrap; gap: 6px; }
.fill-card.is-compact + .fill-card { padding-top: 12px; border-top: 1px solid var(--border); }

.fill-pop {
  position: absolute;
  z-index: 60;
  display: grid;
  gap: 12px;
  padding: 14px;
  background: var(--surface);
  border: 1px solid var(--border2);
  border-radius: calc(var(--r) + 3px);
  box-shadow: var(--shadow-float);
}
.fill-pop-title { display: flex; justify-content: space-between; align-items: center; font-family: var(--font-display); font-size: 16px; color: var(--ink); }
.fill-pop-close { border: 0; background: none; font-size: 20px; line-height: 1; color: var(--muted); cursor: pointer; padding: 0 4px; }
.fill-pop-close:hover { color: var(--ink); }

/* Open slots are buttons now */
button.day-gap-slot {
  appearance: none;
  width: 100%;
  background: transparent;
  font-family: inherit;
  cursor: pointer;
}
button.day-gap-slot:focus-visible { outline: 2px solid var(--brand); outline-offset: 1px; }

/* ── Quick add ─────────────────────────────────────────────────── */
.quick-add-pop {
  position: absolute;
  top: calc(100% + 8px);
  right: 40px;
  z-index: 40;
  width: min(420px, calc(100vw - 32px));
  padding: 12px;
  background: var(--surface);
  border: 1px solid var(--border2);
  border-radius: calc(var(--r) + 3px);
  box-shadow: var(--shadow-float);
}
.quick-add-input {
  width: 100%;
  height: 44px;
  padding: 0 12px;
  border: 1px solid var(--border2);
  border-radius: var(--r);
  background: var(--bg);
  color: var(--ink);
  font: 15px/1.2 inherit;
  font-family: inherit;
}
.quick-add-input:focus { outline: 2px solid var(--brand-glow); border-color: var(--brand); }
.quick-add-preview { margin: 8px 2px 10px; min-height: 18px; font-size: 12.5px; color: var(--subtle); }
.quick-add-preview.is-ready { color: var(--ink); }
.quick-add-preview.is-ready::before { content: '→ '; color: var(--brand); }
.quick-add-actions { display: flex; align-items: center; gap: 10px; }
.quick-add-hint { margin-left: auto; font-size: 11px; color: var(--subtle); }
.quick-add-hint kbd { font: 10px/1 'DM Mono', monospace; padding: 2px 4px; border: 1px solid var(--border2); border-radius: 3px; background: var(--surface2); }

@keyframes just-added { 0% { box-shadow: inset 0 0 0 2px var(--brand); } 100% { box-shadow: inset 0 0 0 2px transparent; } }
.just-added { animation: just-added 1.4s ease-out; }

/* ── Drag ─────────────────────────────────────────────────────── */
#calendarView [draggable="true"] { cursor: grab; }
#calendarView [draggable="true"]:active { cursor: grabbing; }
#calendarView .is-dragging { opacity: .45; }
#calendarView.is-dragging-item .cal-day,
#calendarView.is-dragging-item .cal-week-day { transition: background .1s, border-color .1s; }
#calendarView .is-drop-target { border-color: var(--brand) !important; background: var(--brand-dim) !important; }

.toast.toast-action { display: flex; align-items: center; gap: 14px; }
.toast-action-btn {
  appearance: none;
  border: 0;
  background: none;
  padding: 0;
  color: inherit;
  font: 600 13px/1 inherit;
  font-family: inherit;
  text-decoration: underline;
  text-underline-offset: 3px;
  cursor: pointer;
}

/* ── Holidays ─────────────────────────────────────────────────── */
.day-holiday {
  margin-top: -1px;
  font-size: 10px;
  line-height: 1.25;
  color: var(--accent);
  font-style: italic;
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
}
.cal-week-day .day-holiday, .calendar-agenda-day .day-holiday { font-size: 12px; margin: 2px 0 6px; }

@media (max-width: 768px) {
  .today-strip { grid-template-columns: 1fr; gap: var(--s3); }
  .quick-add-pop { position: fixed; left: 12px; right: 12px; top: 64px; width: auto; }
  .quick-add-hint { display: none; }
}
@media (prefers-reduced-motion: reduce) { .just-added { animation: none; } }

/* Week cards: an empty day's summary line stays empty, not "NO LOADED POSTS" */
.cal-week-day-summary:empty { display: none; }

/* Dated Shelf ideas in month cells: title first, a quiet status line under it
   (the badge used to squeeze the title into a sliver beside it) */
#calGrid .content-calendar-pill { flex-direction: column; align-items: stretch; gap: 2px; }
#calGrid .content-calendar-pill .day-post-copy strong { font-weight: 600; }
#calGrid .content-calendar-pill .day-post-copy small { display: none; }
#calGrid .content-calendar-pill .content-status {
  align-self: flex-start;
  padding: 0;
  border: 0;
  background: none;
  font: 500 9.5px/1.3 'DM Mono', monospace;
  letter-spacing: .02em;
  text-transform: none;
  color: var(--muted);
}
