/* ============================================================
   EditorHQ Desk — Writer studio v2 ("The Writing Sheet") + Content calendar
   Paper & Ink system (tokens.css). Fits the desk window shell:
   .win--wide / .win--cal get wider desktop footprints; everything
   else reuses desk window chrome. Mobile: single column.
   Writer v2: the sheet is the hero — format/category chrome recedes
   into one quiet top row; fields sit in a hairline strip on the page;
   save state is a fixed status chip; empty state is a format grid.
   ============================================================ */

/* ---- wider windows for these two apps ---- */
@media (min-width: 1024px) {
  .win--wide { width: min(1180px, calc(100vw - 96px)); height: min(720px, calc(100vh - var(--topbar-h) - var(--dock-h) - 48px)); }
  .win--cal  { width: min(1080px, calc(100vw - 96px)); height: min(700px, calc(100vh - var(--topbar-h) - var(--dock-h) - 48px)); }
}

/* the writer rests a touch deeper so emerging from its launcher reads */
#win-writer:not(.open) { scale: 0.965; }

/* ============================================================
   WRITER
   ============================================================ */
.writer { display: grid; grid-template-columns: 280px 1fr; width: 100%; min-height: 100%; height: 100%; }

/* ---- sidebar: search, filters, list ---- */
.wr-side { display: flex; flex-direction: column; min-height: 0; border-right: 1px solid var(--hairline-soft); background: var(--paper-sink); }
.wr-search { position: relative; padding: var(--s3) var(--s3) var(--s2); }
.wr-search > svg { position: absolute; left: calc(var(--s3) + 10px); top: calc(var(--s3) + 9px); width: 15px; height: 15px; color: var(--ink-mute); pointer-events: none; }
.wr-search .input { height: 34px; font-size: var(--text-sm); padding-left: 33px; }

.wr-filters { display: flex; flex-wrap: wrap; gap: 4px; padding: 0 var(--s3) var(--s2); }
.wr-fchip {
  appearance: none; border: 1px solid var(--hairline); background: var(--paper-raise);
  border-radius: 999px; padding: 3px 9px; font: inherit; font-size: var(--text-2xs);
  color: var(--ink-soft); cursor: pointer; transition: color var(--t-fast), border-color var(--t-fast), background var(--t-fast);
}
.wr-fchip:hover { border-color: var(--hairline-strong); color: var(--ink); }
.wr-fchip.active { background: var(--ink); border-color: var(--ink); color: var(--paper-raise); }

.wr-list { flex: 1; overflow-y: auto; padding: 0 var(--s2) var(--s2); }
.wr-item {
  position: relative; display: flex; align-items: flex-start; gap: 10px;
  width: 100%; text-align: left; appearance: none; border: 1px solid transparent; background: transparent;
  border-radius: var(--r-md); padding: var(--s2) var(--s3); cursor: pointer; margin-bottom: 2px;
  transition: background var(--t-fast), border-color var(--t-fast); font: inherit; color: inherit;
}
.wr-item:hover { background: var(--amber-wash); }
.wr-item.active { background: var(--paper-raise); border-color: rgba(184, 92, 26, 0.35); box-shadow: var(--sh-sub); }
.wr-item-glyph {
  flex: none; width: 26px; height: 26px; margin-top: 1px; border-radius: 8px;
  display: grid; place-items: center;
  background: var(--paper-raise); border: 1px solid var(--hairline-soft);
}
.wr-item-glyph svg { width: 14px; height: 14px; }
.wr-item-main { flex: 1; min-width: 0; display: grid; gap: 2px; }
.wr-item-top { display: flex; align-items: baseline; gap: 6px; min-width: 0; }
.wr-item-title {
  flex: 1; min-width: 0; font-weight: 600; font-size: var(--text-sm); line-height: 1.35;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.wr-item-sub {
  display: flex; align-items: center; gap: 5px; min-width: 0;
  font-size: var(--text-2xs); color: var(--ink-mute); white-space: nowrap;
}
.wr-item-date { flex: none; margin-top: 3px; font-family: var(--ff-mono); font-size: var(--text-2xs); color: var(--ink-mute); }
.wr-badge {
  display: inline-block; padding: 1px 7px; border-radius: 999px; font-size: var(--text-2xs);
  border: 1px solid var(--hairline); background: var(--paper-raise); color: var(--ink-soft);
}
.wr-badge--scheduled { border-color: rgba(59, 91, 146, 0.35); background: var(--blue-wash); color: var(--blue); }
.wr-badge--published { border-color: rgba(30, 127, 79, 0.35); background: var(--green-wash); color: var(--green); }
.wr-empty-side { padding: var(--s5) var(--s3); text-align: center; color: var(--ink-mute); font-size: var(--text-sm); }
.wr-count { padding: var(--s2) var(--s3); border-top: 1px solid var(--hairline-soft); font-size: var(--text-2xs); color: var(--ink-mute); font-family: var(--ff-mono); }

/* ---- main area ---- */
.wr-main { position: relative; min-width: 0; min-height: 0; display: flex; flex-direction: column; }

/* empty state — format launch grid */
.wr-empty {
  flex: 1; min-height: 0; overflow-y: auto;
  display: flex; flex-direction: column; align-items: center; justify-content: safe center;
  text-align: center; padding: var(--s6);
}
.we-mark {
  width: 64px; height: 64px; border-radius: 18px; display: grid; place-items: center;
  background: var(--paper-raise); border: 1px solid var(--hairline-soft); box-shadow: var(--sh-sub);
  font-family: var(--ff-bn); font-size: 22px; font-weight: 700; color: var(--amber);
  transform: rotate(-4deg); margin-bottom: var(--s3);
}
.we-t { font-weight: 700; font-size: var(--text-xl); color: var(--ink-deep); }
.we-d { color: var(--ink-soft); font-size: var(--text-sm); line-height: 1.5; margin-top: 2px; }
.we-actions {
  display: grid; grid-template-columns: repeat(auto-fill, minmax(160px, 1fr)); gap: var(--s2);
  width: min(780px, 100%); margin: var(--s5) auto 0;
}
.we-card {
  display: grid; gap: 2px; justify-items: start; text-align: left;
  appearance: none; font: inherit; cursor: pointer;
  background: var(--paper-raise); border: 1px solid var(--hairline-soft); border-radius: var(--r-md);
  padding: var(--s3) var(--s3) var(--s2);
  transition: border-color var(--t-fast), box-shadow var(--t-fast), transform var(--t-fast);
  opacity: 0; animation: weIn 260ms cubic-bezier(0.22, 1, 0.36, 1) forwards;
  animation-delay: calc(var(--i) * 30ms);
}
@keyframes weIn { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }
@media (hover: hover) and (pointer: fine) {
  .we-card:hover { border-color: var(--hairline-strong); box-shadow: var(--sh-sub); transform: translateY(-1px); }
}
.we-card:active { transform: translateY(1px); }
.we-ic {
  width: 30px; height: 30px; border-radius: 9px; display: grid; place-items: center;
  background: var(--paper); border: 1px solid var(--hairline-soft); margin-bottom: var(--s2);
}
.we-ic svg { width: 15px; height: 15px; }
.we-label { font-weight: 600; font-size: var(--text-sm); color: var(--ink-deep); }
.we-hint { font-size: var(--text-2xs); color: var(--ink-mute); line-height: 1.4; }

/* ---- top row: format segmented control + category/pub ---- */
.wr-page { flex: 1; min-height: 0; display: flex; flex-direction: column; width: 100%; }
.wr-top {
  display: flex; align-items: center; gap: var(--s3); flex-wrap: wrap;
  padding: var(--s2) var(--s4); border-bottom: 1px solid var(--hairline-soft);
  background: var(--paper-sink);
}
.wr-modes {
  position: relative; display: flex; gap: 2px;
  background: var(--paper-deep); border: 1px solid var(--hairline-soft); border-radius: var(--r-sm); padding: 2px;
}
.wr-thumb {
  position: absolute; top: 2px; bottom: 2px; left: 0; width: 0; border-radius: 5px;
  background: var(--paper-raise); box-shadow: 0 1px 2px rgba(42, 38, 32, 0.14);
  transition: left 200ms cubic-bezier(0.25, 1, 0.5, 1), width 200ms cubic-bezier(0.25, 1, 0.5, 1), opacity var(--t-fast);
  pointer-events: none;
}
.wr-mode {
  position: relative; z-index: 1;
  appearance: none; border: 0; background: transparent; font: inherit; font-size: var(--text-xs);
  font-weight: 600; color: var(--ink-soft); padding: 5px 10px; border-radius: 5px; cursor: pointer;
  display: inline-flex; align-items: center; gap: 5px; transition: color var(--t-fast); white-space: nowrap;
}
.wr-mode svg { width: 14px; height: 14px; }
.wr-mode:hover { color: var(--ink); }
.wr-mode.active { color: var(--amber-deep); }
.wr-meta { display: flex; gap: var(--s2); margin-left: auto; }
.select--slim { height: 30px; font-size: var(--text-xs); padding: 0 24px 0 8px; }

/* ---- the sheet — a piece of paper on the desk ---- */
.wr-sheetwrap { flex: 1; min-height: 0; display: flex; flex-direction: column; background: var(--paper); }
.wr-sheet { flex: 1; min-height: 0; overflow-y: auto; padding: var(--s5) var(--s6) var(--s8); }
.wr-paper {
  max-width: 760px; margin: 0 auto;
  background: var(--paper-raise);
  border: 1px solid var(--hairline-soft);
  border-radius: var(--r-md);
  box-shadow: 0 1px 2px rgba(26, 24, 20, 0.05), 0 10px 28px -14px rgba(26, 24, 20, 0.2);
  padding: var(--s6) var(--s8) var(--s5);
}
.wr-page.page-in .wr-paper { animation: wrPageIn 220ms cubic-bezier(0.22, 1, 0.36, 1); }
@keyframes wrPageIn { from { opacity: 0; transform: translateY(6px); } }

.wr-title {
  width: 100%; border: 0; outline: 0; background: transparent; resize: none;
  font-family: var(--ff-bn); font-size: clamp(1.4rem, 2.4vw, 1.75rem); font-weight: 700; line-height: 1.3;
  color: var(--ink-deep); padding: 0; margin-bottom: var(--s2);
}
.wr-title::placeholder { color: var(--ink-mute); opacity: 0.5; }

/* format fields — one quiet hairline strip on the page */
.wr-fields {
  display: flex; flex-wrap: wrap; gap: var(--s2) var(--s6);
  padding: var(--s2) 0 var(--s3); margin-bottom: var(--s3);
  border-bottom: 1px dashed var(--hairline-soft);
}
.wr-field { flex: 1 1 190px; min-width: 150px; display: grid; gap: 3px; }
.wr-field-label {
  display: flex; align-items: center; gap: 5px;
  font-size: var(--text-2xs); font-weight: 600; letter-spacing: 0.07em; text-transform: uppercase;
  color: var(--ink-mute);
}
.wr-field-label svg { width: 12px; height: 12px; }
.wr-field input, .wr-field select {
  width: 100%; height: 30px; font-size: var(--text-sm); font-family: var(--ff-body);
  color: var(--ink); background: transparent;
  border: 0; border-bottom: 1px solid var(--hairline); border-radius: 0; padding: 2px 0;
  transition: border-color var(--t-fast), box-shadow var(--t-fast);
}
.wr-field input::placeholder { color: var(--ink-mute); opacity: 0.7; }
.wr-field input:hover, .wr-field select:hover { border-bottom-color: var(--ink-soft); }
.wr-field input:focus, .wr-field select:focus {
  outline: none; border-bottom-color: var(--amber); box-shadow: 0 1px 0 var(--amber);
}
.wr-field select {
  appearance: none; -webkit-appearance: none; cursor: pointer; padding-right: 20px;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%239a9384' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='m7 10 5 5 5-5'/%3E%3C/svg%3E");
  background-repeat: no-repeat; background-position: right 2px center; background-size: 14px 14px;
}
.wr-field select option { font-family: var(--ff-body); }

/* body — the hero of the page */
.wr-body {
  display: block; width: 100%; min-height: 360px; resize: none;
  border: 0; outline: 0; background: transparent;
  font-family: var(--ff-bn); font-size: 1.05rem; line-height: 1.9; color: var(--ink); padding: 0;
}
.wr-body::placeholder { color: var(--ink-mute); opacity: 0.5; }

/* fixed status strip — words left, save state right (never scrolls away) */
.wr-status {
  flex: none; display: flex; align-items: center; justify-content: space-between; gap: var(--s3);
  padding: 6px var(--s6); border-top: 1px solid var(--hairline-soft); background: var(--paper-raise);
  font-family: var(--ff-mono); font-size: var(--text-2xs); color: var(--ink-mute);
}
.wr-savechip { display: inline-flex; align-items: center; gap: 6px; transition: color var(--t-fast); }
.wr-save-dot { width: 7px; height: 7px; border-radius: 50%; background: var(--green); flex: none; }
.wr-savechip[data-state="saving"] { color: var(--amber-deep); }
.wr-savechip[data-state="saving"] .wr-save-dot { background: var(--amber); animation: wrPulse 1.1s ease-in-out infinite; }
.wr-savechip[data-state="saved"] .wr-save-dot { animation: wrPop 260ms cubic-bezier(0.22, 1, 0.36, 1); }
@keyframes wrPulse { 50% { opacity: 0.35; } }
@keyframes wrPop { 0% { transform: scale(0.6); } 60% { transform: scale(1.3); } 100% { transform: scale(1); } }

/* footer actions */
.wr-foot {
  display: flex; align-items: center; gap: var(--s2); padding: var(--s2) var(--s4);
  border-top: 1px solid var(--hairline-soft); background: var(--paper-sink);
}
.wr-foot .btn--danger { border-color: transparent; background: transparent; }
.wr-foot .btn--danger:hover { background: var(--red-wash); border-color: rgba(180, 35, 45, 0.25); }
.wr-foot-spacer { flex: 1; }

/* mobile */
@media (max-width: 767px) {
  .writer { grid-template-columns: 1fr; grid-template-rows: minmax(0, 38%) minmax(0, 1fr); }
  .wr-side { border-right: 0; border-bottom: 1px solid var(--hairline-soft); max-height: none; }
  .wr-sheet { padding: var(--s3) var(--s3) var(--s6); }
  .wr-paper { padding: var(--s4) var(--s4) var(--s4); }
  .wr-status { padding: 6px var(--s4); }
  .wr-meta { margin-left: 0; }
  /* keep footer actions clear of the floating dock */
  .wr-foot { padding-bottom: calc(var(--s2) + 68px); }
}

/* ============================================================
   CONTENT CALENDAR
   ============================================================ */
.cal { display: flex; flex-direction: column; height: 100%; min-height: 0; position: relative; }

.cal-bar {
  display: flex; align-items: center; gap: var(--s3); flex-wrap: wrap;
  padding: var(--s2) var(--s4); border-bottom: 1px solid var(--hairline-soft); background: var(--paper-sink);
}
.cal-nav { display: flex; gap: 2px; }
.cal-nav .btn--icon svg { width: 16px; height: 16px; }
.cal-next-rot svg { transform: rotate(180deg); }
.cal-month { font-weight: 700; font-size: var(--text-lg); min-width: 150px; }
.cal-legend { display: inline-flex; align-items: center; gap: 5px; font-size: var(--text-2xs); color: var(--ink-soft); margin-left: auto; }
.lg { width: 10px; height: 10px; border-radius: 3px; display: inline-block; }
.lg--sched { background: var(--blue-wash); border: 1px solid rgba(59, 91, 146, 0.4); }
.lg--pub { background: var(--green-wash); border: 1px solid rgba(30, 127, 79, 0.4); }
.cal-side { display: flex; gap: var(--s2); align-items: center; }

.cal-grid {
  flex: 1; min-height: 0; display: grid;
  grid-template-columns: repeat(7, 1fr);
  grid-auto-rows: minmax(64px, 1fr);
  gap: 1px; background: var(--hairline-soft); border-bottom: 1px solid var(--hairline-soft);
  overflow-y: auto;
}
.cal-dow {
  display: grid; grid-template-columns: repeat(7, 1fr); gap: 1px;
  background: var(--hairline-soft); border-bottom: 1px solid var(--hairline);
}
.cal-dow > div {
  background: var(--paper-sink); padding: 4px 8px;
  font-size: var(--text-2xs); font-weight: 700; letter-spacing: 0.08em; text-transform: uppercase; color: var(--ink-soft);
}
.cal-cell { background: var(--paper-raise); padding: 4px 5px; position: relative; min-height: 0; overflow: hidden; transition: background var(--t-fast); }
.cal-cell.other { background: var(--paper); opacity: 0.55; }
.cal-cell.today::before {
  content: ""; position: absolute; inset: 0; pointer-events: none;
  border: 2px solid var(--amber); border-radius: 2px; opacity: 0.7;
}
.cal-num { font-family: var(--ff-mono); font-size: var(--text-2xs); color: var(--ink-soft); }
.cal-cell.today .cal-num { color: var(--amber-deep); font-weight: 700; }

.cal-pill {
  position: relative; z-index: 2;
  display: flex; align-items: center; gap: 4px; width: 100%; text-align: left;
  appearance: none; border: 0; cursor: grab; font: inherit;
  border-radius: var(--r-sm); padding: 2px 6px; margin-top: 3px;
  background: var(--blue-wash); border: 1px solid rgba(59, 91, 146, 0.28);
  color: var(--ink); font-size: var(--text-2xs); line-height: 1.3;
  overflow: hidden; white-space: nowrap; text-overflow: ellipsis;
}
.cal-pill .fmt { flex: none; width: 13px; height: 13px; opacity: 0.75; }
.cal-pill .pt { overflow: hidden; text-overflow: ellipsis; }
.cal-pill--published { background: var(--green-wash); border-color: rgba(30, 127, 79, 0.3); }
.cal-pill.dragging { opacity: 0.45; }
.cal-cell.drop { background: var(--amber-wash); box-shadow: inset 0 0 0 2px var(--amber); }
.cal-more {
  position: relative; z-index: 2;
  display: block; width: 100%; text-align: left; appearance: none; border: 0; background: none;
  font: inherit; font-size: var(--text-2xs); color: var(--ink-soft); padding: 2px 6px 0; cursor: pointer;
}
.cal-more:hover { color: var(--amber-deep); }

/* full-cell invisible click target (opens day popover) */
.cal-cell-btn { position: absolute; inset: 0; width: 100%; appearance: none; border: 0; background: transparent; cursor: pointer; z-index: 1; }
.cal-cell-btn:focus-visible { outline: 2px solid var(--amber); outline-offset: -2px; }

/* unscheduled tray */
.cal-tray { flex: none; border-top: 1px solid var(--hairline-strong); background: var(--paper-sink); }
.cal-tray-head {
  display: flex; align-items: center; gap: 6px; padding: 6px var(--s4);
  font-size: var(--text-xs); font-weight: 700; color: var(--ink-soft);
}
.cal-tray-head svg { width: 14px; height: 14px; }
.cal-tray-hint { margin-left: auto; font-weight: 400; font-style: italic; color: var(--ink-mute); font-size: var(--text-2xs); }
.cal-tray-items { display: flex; gap: var(--s2); overflow-x: auto; padding: 0 var(--s4) var(--s3); min-height: 44px; align-items: stretch; }
.cal-tray-item {
  flex: 0 0 auto; max-width: 220px; cursor: grab;
  border: 1px solid var(--hairline); border-radius: var(--r-md); background: var(--paper-raise);
  padding: 5px 10px; font: inherit; text-align: left;
  transition: border-color var(--t-fast), box-shadow var(--t-fast);
}
.cal-tray-item:hover { border-color: var(--hairline-strong); box-shadow: var(--sh-sub); }
.cal-tray-item .tt { font-size: var(--text-xs); font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 200px; }
.cal-tray-item .ss { font-size: var(--text-2xs); color: var(--ink-mute); margin-top: 1px; }
.cal-tray-item.dragging { opacity: 0.45; }
.cal-tray-empty { color: var(--ink-mute); font-size: var(--text-xs); font-style: italic; padding: 8px 0; }

/* day popover */
.cal-day-pop {
  position: absolute; z-index: 8; width: 280px; max-height: 340px; overflow-y: auto;
  background: var(--paper-raise); border: 1px solid var(--hairline-strong); border-radius: var(--r-lg);
  box-shadow: var(--sh-win); padding: var(--s3);
}
.cal-day-pop .dp-date { font-weight: 700; font-size: var(--text-sm); margin-bottom: var(--s2); }
.cal-day-pop .dp-item { display: flex; align-items: center; gap: 6px; padding: 5px 2px; border-bottom: 1px dashed var(--hairline-soft); font-size: var(--text-xs); }
.cal-day-pop .dp-item:last-of-type { border-bottom: 0; }
.cal-day-pop .dp-t { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.cal-day-pop .dp-x { flex: none; }
.cal-day-pop .dp-empty { color: var(--ink-mute); font-size: var(--text-xs); font-style: italic; padding: var(--s2) 0; }
.cal-day-pop .dp-actions { display: flex; gap: var(--s2); margin-top: var(--s2); flex-wrap: wrap; }

/* mobile */
@media (max-width: 767px) {
  .cal-grid { grid-auto-rows: minmax(52px, 1fr); }
  .cal-legend { display: none; }
  .cal-month { font-size: var(--text-md); min-width: 0; }
  .cal-tray-items { min-height: 40px; }
  .cal-day-pop { position: fixed; left: 8px; right: 8px; width: auto; bottom: 64px; top: auto; max-height: 46vh; }
}

/* ---- slug composer: /{category}/{user-set}/ ---- */
.wr-slugwrap { display: flex; align-items: center; gap: 6px; min-width: 0; }
.wr-slugpre {
  font-family: var(--font-mono, 'JetBrains Mono', ui-monospace, monospace);
  font-size: 12px; color: var(--ink-soft, #5c6470);
  background: rgba(127,127,127,.12);
  padding: 7px 9px; border-radius: 8px; white-space: nowrap; user-select: none;
}
.wr-slugwrap input { flex: 1 1 auto; min-width: 0; }
