/*
 * Calendar, Writing and Notes
 * ---------------------------
 * A shared editorial system with app-specific layouts. Feature behavior stays
 * in workspace-apps.js; this file owns presentation only.
 */

/* ---------- Shared editorial shell ---------- */
.app-modal:has(.workspace-app:not([hidden])) .modal-panel {
  display: flex;
  flex-direction: column;
  min-height: 0;
  overflow: hidden;
  padding-bottom: 0;
  background: #f8f8f5;
  color: #242421;
  text-align: left;
}
.app-modal:has(.workspace-app:not([hidden])) .modal-close { flex: 0 0 auto; }
.workspace-app {
  --workspace-ink: #242421;
  --workspace-muted: #8e8e87;
  --workspace-line: #deded8;
  --workspace-soft: #f1f1ed;
  flex: 1 1 auto;
  min-height: 0;
  overflow: auto;
  padding: 9px 4px calc(34px + env(safe-area-inset-bottom));
  color: var(--workspace-ink);
  overscroll-behavior: contain;
  -webkit-overflow-scrolling: touch;
}
.workspace-app button,.workspace-app input,.workspace-app textarea,.workspace-app select { color: inherit; font-family: var(--font-family); }
.workspace-app button { touch-action: manipulation; }
.workspace-head {
  position: relative;
  display: flex;
  min-height: 76px;
  align-items: flex-end;
  justify-content: space-between;
  gap: 14px;
  padding: 8px 2px 15px;
  border-bottom: 1px solid var(--workspace-line);
}
.workspace-head::after {
  position: absolute;
  top: 8px;
  right: 3px;
  color: #b0b0aa;
  font: 500 9px/1 ui-monospace, monospace;
  letter-spacing: .12em;
}
.planner-app .workspace-head::after { content: "01 / CALENDAR"; }
.writing-app .workspace-head::after { content: "02 / MANUSCRIPT"; }
.notes-app .workspace-head::after { content: "03 / NOTEBOOK"; }
.workspace-head small { display: block; margin-bottom: 5px; color: var(--workspace-muted); font-size: 8px; letter-spacing: .18em; }
.workspace-head strong { font: 600 25px/1 var(--display-font); letter-spacing: -.025em; }
.workspace-head > button,.workspace-wide {
  min-height: 40px;
  padding: 0 14px;
  border: 1px solid #cfcfc9;
  border-radius: 8px;
  background: transparent;
  font-size: 10px;
}
.workspace-card { margin-top: 18px; padding: 0; border: 0; border-radius: 0; background: transparent; box-shadow: none; }
.workspace-card > header { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding-bottom: 11px; border-bottom: 1px solid var(--workspace-line); }
.workspace-card > header small,.workspace-card > header strong { display: block; }
.workspace-card > header small { margin-bottom: 4px; color: var(--workspace-muted); font-size: 8px; letter-spacing: .13em; }
.workspace-card > header strong { font-size: 13px; font-weight: 600; }
.workspace-card > header button { min-height: 40px; padding: 0 12px; border: 1px solid #d2d2cc; border-radius: 8px; background: #fff; font-size: 9px; }
.workspace-two,.workspace-actions { display: grid; grid-template-columns: repeat(2,minmax(0,1fr)); gap: 7px; }
.workspace-actions { margin-top: 11px; }
.workspace-actions:has(> :nth-child(3)) { grid-template-columns: repeat(3,minmax(0,1fr)); }
.workspace-actions button,.workspace-primary,.workspace-wide { border: 1px solid #d5d5cf; background: transparent; }
.workspace-actions button { min-height: 40px; border-radius: 7px; font-size: 9px; }
.workspace-primary { border-color: var(--workspace-ink)!important; background: var(--workspace-ink)!important; color: #fff!important; }
.workspace-wide { width: 100%; margin-top: 11px; }
.workspace-toggle { display: flex; align-items: center; gap: 8px; color: #666660; font-size: 9px; white-space: nowrap; }
.workspace-toggle input { position: absolute; opacity: 0; }
.workspace-toggle i { position: relative; width: 37px; height: 22px; flex: 0 0 auto; border-radius: 12px; background: #d8d8d2; transition: .2s; }
.workspace-toggle i::after { content: ""; position: absolute; top: 3px; left: 3px; width: 16px; height: 16px; border-radius: 50%; background: #fff; box-shadow: 0 1px 3px rgba(0,0,0,.15); transition: .2s; }
.workspace-toggle input:checked + i { background: var(--workspace-ink); }
.workspace-toggle input:checked + i::after { transform: translateX(15px); }
.backup-empty { margin: 14px 0; color: #aaa; font-size: 9px; text-align: center; }

/* ---------- Calendar: open grid + timeline ---------- */
.planner-month-head { display: grid; grid-template-columns: 42px minmax(0,1fr) 42px; align-items: center; margin: 17px 0 12px; }
.planner-month-head strong { text-align: center; font: 500 22px/1.1 Georgia,"Songti SC",serif; letter-spacing: -.02em; }
.planner-month-head button { width: 40px; height: 40px; border: 0; border-radius: 0; background: transparent; color: #666; font-size: 25px; }
.planner-month-head button:first-child { border-right: 1px solid var(--workspace-line); }
.planner-month-head button:last-child { border-left: 1px solid var(--workspace-line); }
.planner-weekdays,.planner-calendar { display: grid; grid-template-columns: repeat(7,minmax(0,1fr)); }
.planner-weekdays { padding: 0 2px 8px; color: #9c9c95; font-size: 8px; letter-spacing: .08em; text-align: center; }
.planner-calendar { overflow: hidden; border-top: 1px solid var(--workspace-ink); border-bottom: 1px solid var(--workspace-line); background: transparent; }
.planner-calendar button { position: relative; min-width: 0; min-height: 47px; padding: 9px 2px 8px; border: 0; border-bottom: 1px solid #e7e7e2; background: transparent; font: 500 11px/1 var(--font-family); }
.planner-calendar button:nth-last-child(-n+7) { border-bottom: 0; }
.planner-calendar button.outside { color: #c3c3bd; }
.planner-calendar button span { display: grid; width: 26px; height: 26px; margin: 0 auto; place-items: center; border-radius: 50%; }
.planner-calendar button.today span { border: 1px solid #777771; background: transparent; color: var(--workspace-ink); }
.planner-calendar button.selected span,.planner-calendar button.selected.today span { border-color: var(--workspace-ink); background: var(--workspace-ink); color: #fff; }
.planner-calendar button i { position: absolute; left: 50%; bottom: 5px; width: 3px; height: 3px; border-radius: 50%; background: #4d4d48; transform: translateX(-50%); }
.planner-calendar button.selected i { background: #fff; }
.planner-day { margin-top: 21px; }
#plannerEvents { display: grid; }
.planner-event { position: relative; display: grid; grid-template-columns: 47px minmax(0,1fr) 40px; gap: 12px; align-items: start; min-height: 58px; padding: 14px 0 11px; border-bottom: 1px solid #e4e4df; }
.planner-event::before { content: ""; position: absolute; top: 21px; left: 47px; width: 5px; height: 5px; border-radius: 50%; background: var(--workspace-ink); transform: translateX(-50%); }
.planner-event time { padding-top: 1px; color: #777771; font: 500 9px/1.4 ui-monospace, monospace; }
.planner-event span { padding-left: 1px; }
.planner-event strong,.planner-event small { display: block; }
.planner-event strong { font-size: 12px; font-weight: 600; }
.planner-event small { margin-top: 5px; color: #777771; font-size: 9px; line-height: 1.55; }
.planner-event button { width: 40px; height: 40px; border: 0; background: transparent; color: #aaa; font-size: 17px; }

/* ---------- Full-screen workspace sheet ---------- */
.workspace-sheet { position: absolute; inset: 0; z-index: 25; display: flex; flex-direction: column; gap: 13px; padding: 22px 22px max(25px,env(safe-area-inset-bottom)); overflow: auto; background: #fafaf7; }
.workspace-sheet[hidden] { display: none; }
.workspace-sheet header { display: flex; align-items: center; justify-content: space-between; margin-bottom: 7px; padding-bottom: 14px; border-bottom: 1px solid var(--workspace-line); }
.workspace-sheet header strong { font: 600 21px/1 var(--display-font); }
.workspace-sheet header button { width: 40px; height: 40px; border: 1px solid #d8d8d2; border-radius: 50%; background: transparent; }
.workspace-sheet input,.workspace-sheet textarea,.workspace-sheet select { box-sizing: border-box; width: 100%; min-width: 0; padding: 12px 2px; border: 0; border-bottom: 1px solid #d5d5cf; border-radius: 0; outline: 0; background: transparent; font-size: 12px; }
.workspace-sheet input:focus,.workspace-sheet textarea:focus,.workspace-sheet select:focus { border-bottom-color: var(--workspace-ink); }
.workspace-sheet textarea { min-height: 96px; resize: vertical; line-height: 1.7; }
.workspace-sheet label { color: #777771; font-size: 9px; }
.workspace-sheet label select { margin-top: 5px; }
.workspace-sheet .workspace-primary { min-height: 45px; margin-top: 5px; border-radius: 7px; }

/* ---------- Writing: manuscript desk ---------- */
.writing-project-bar { display: flex; align-items: center; justify-content: space-between; gap: 14px; padding: 15px 2px 12px; }
.writing-project-picker { display: grid; grid-template-columns: minmax(0,1fr) auto; gap: 6px; min-width: 0; flex: 1 1 auto; }
.writing-project-picker button { min-height: 40px; padding: 0 10px; border: 0; border-bottom: 1px solid #cecec8; border-radius: 0; background: transparent; color: #777; font-size: 9px; }
.writing-project-bar select,.writing-chapter-bar select { min-width: 0; height: 40px; padding: 0 28px 0 2px; border: 0; border-bottom: 1px solid #cecec8; border-radius: 0; background: transparent; font-size: 10px; }
.workspace-tabs { display: flex; gap: 20px; padding: 0; overflow-x: auto; border-top: 1px solid var(--workspace-line); border-bottom: 1px solid var(--workspace-line); scrollbar-width: none; }
.workspace-tabs::-webkit-scrollbar { display: none; }
.workspace-tabs button { position: relative; flex: 0 0 auto; min-width: 0; height: 42px; padding: 0; border: 0; border-radius: 0; background: transparent; color: #888881; font-size: 9px; }
.workspace-tabs button.active { color: var(--workspace-ink); font-weight: 600; }
.workspace-tabs button.active::after { content: ""; position: absolute; right: 0; bottom: -1px; left: 0; height: 2px; background: var(--workspace-ink); }
.writing-pane { display: none; padding-top: 15px; }
.writing-pane.active { display: block; }
.writing-chapter-bar { display: grid; grid-template-columns: minmax(0,1fr) auto; gap: 8px; }
.writing-chapter-bar button { min-height: 40px; padding: 0 12px; border: 1px solid #d2d2cc; border-radius: 7px; background: transparent; font-size: 9px; }
.writing-title { box-sizing: border-box; width: 100%; margin-top: 13px; padding: 13px 1px 11px; border: 0; border-bottom: 1px solid var(--workspace-line); outline: 0; background: transparent; font: 500 20px/1.25 Georgia,"Songti SC",var(--display-font); }
.writing-symbol-strip { display: flex; gap: 0; min-height: 39px; padding: 5px 0; overflow-x: auto; border-bottom: 1px solid #ecece7; scrollbar-width: none; }
.writing-symbol-strip::-webkit-scrollbar { display: none; }
.writing-symbol-strip button { flex: 0 0 auto; min-width: 38px; height: 34px; padding: 0 9px; border: 0; border-right: 1px solid #e3e3de; border-radius: 0; background: transparent; font-size: 12px; }
.writing-editor,#writingOutline,#writingSymbols { box-sizing: border-box; width: 100%; padding: 18px 3px; resize: vertical; border: 0; outline: 0; background: transparent; color: #292926; font: 14px/2 ui-sans-serif,-apple-system,"PingFang SC",sans-serif; }
.writing-editor { min-height: 335px; }
#writingOutline,#writingSymbols { min-height: 330px; }
.writing-footer { display: flex; align-items: center; justify-content: space-between; gap: 10px; padding-top: 11px; border-top: 1px solid var(--workspace-line); }
.writing-footer > span { flex: 0 0 auto; color: #8d8d86; font-size: 9px; }
.writing-footer > div { display: flex; gap: 3px; justify-content: flex-end; }
.writing-footer button { min-height: 40px; padding: 0 9px; border: 0; border-radius: 0; background: transparent; color: #62625d; font-size: 9px; }
.writing-footer .workspace-primary { min-width: 72px; border-radius: 7px; }
.writing-ai-result,#notesStudyResult { margin: 15px 0 0; padding: 14px 15px; border: 0; border-left: 2px solid var(--workspace-ink); background: #f0f0ec; color: #555550; font: 10px/1.7 ui-sans-serif,sans-serif; white-space: pre-wrap; overflow-wrap: anywhere; }
.writing-card-list { display: grid; gap: 0; counter-reset: writing-character; }
.writing-character-card { position: relative; padding: 15px 2px 15px 40px; border: 0; border-bottom: 1px solid var(--workspace-line); border-radius: 0; background: transparent; counter-increment: writing-character; }
.writing-character-card::before { content: counter(writing-character,decimal-leading-zero); position: absolute; top: 18px; left: 2px; color: #999993; font: 500 11px/1 Georgia,serif; }
.writing-character-card input,.writing-character-card textarea { box-sizing: border-box; width: 100%; border: 0; border-bottom: 1px solid #e5e5e0; outline: 0; background: transparent; font-size: 11px; }
.writing-character-card input { padding: 6px 0 9px; font-weight: 600; }
.writing-character-card textarea { min-height: 85px; padding: 10px 0; resize: vertical; line-height: 1.7; }
.writing-character-card button { min-height: 38px; padding: 0; border: 0; background: transparent; color: #98605a; font-size: 9px; }
.writing-version-list { display: grid; padding-left: 15px; border-left: 1px solid #cdcdc7; }
.writing-version-list article { position: relative; display: grid; grid-template-columns: minmax(0,1fr) auto; gap: 9px; align-items: center; padding: 13px 0 13px 14px; border: 0; border-bottom: 1px solid #e4e4df; border-radius: 0; background: transparent; }
.writing-version-list article::before { content: ""; position: absolute; top: 19px; left: -18px; width: 5px; height: 5px; border-radius: 50%; background: #555550; }
.writing-version-list strong,.writing-version-list small { display: block; }
.writing-version-list strong { font-size: 11px; }
.writing-version-list small { margin-top: 4px; color: #999993; font-size: 8px; }
.writing-version-list button { min-height: 38px; padding: 0 10px; border: 1px solid #d5d5cf; border-radius: 6px; background: transparent; font-size: 9px; }

/* ---------- Notes: horizontal index on phones, sidebar on wide screens ---------- */
.notes-layout { display: flex; flex-direction: column; min-height: 480px; margin-top: 13px; overflow: visible; border: 0; border-radius: 0; background: transparent; }
.notes-layout aside { flex: 0 0 auto; min-width: 0; padding: 0 0 12px; overflow: visible; border: 0; border-bottom: 1px solid var(--workspace-line); background: transparent; }
.notes-layout aside input { box-sizing: border-box; width: 100%; height: 42px; padding: 0 14px; border: 1px solid #d7d7d1; border-radius: 21px; outline: 0; background: #fff; font-size: 10px; }
.notes-layout aside input:focus { border-color: #999993; }
#notesList { display: flex; gap: 6px; margin-top: 10px; overflow-x: auto; padding-bottom: 2px; scrollbar-width: none; scroll-snap-type: x proximity; }
#notesList::-webkit-scrollbar { display: none; }
#notesList button { flex: 0 0 126px; min-width: 0; min-height: 64px; padding: 11px; border: 1px solid #dfdfda; border-radius: 7px; background: transparent; text-align: left; scroll-snap-align: start; }
#notesList button.active { border-color: var(--workspace-ink); background: var(--workspace-ink); color: #fff; box-shadow: none; }
#notesList strong,#notesList small { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
#notesList strong { font-size: 10px; }
#notesList small { margin-top: 5px; color: #999993; font-size: 8px; }
#notesList button.active small { color: #bfbfba; }
.notes-layout main { display: flex; flex: 1 1 auto; flex-direction: column; min-width: 0; padding: 19px 2px 0; }
.notes-title { box-sizing: border-box; width: 100%; padding: 4px 1px 13px; border: 0; border-bottom: 1px solid var(--workspace-line); outline: 0; background: transparent; font: 500 20px/1.25 Georgia,"Songti SC",var(--display-font); }
#notesBody { box-sizing: border-box; flex: 1 1 auto; width: 100%; min-height: 315px; padding: 17px 2px; resize: vertical; border: 0; outline: 0; background: transparent; color: #30302d; font: 14px/1.95 ui-sans-serif,-apple-system,"PingFang SC",sans-serif; }
.notes-layout main footer { display: grid; grid-template-columns: 1fr; gap: 8px; padding-top: 10px; border-top: 1px solid var(--workspace-line); }
.notes-layout main footer > span { color: #999993; font-size: 8px; }
.notes-layout main footer > div { display: grid; grid-template-columns: repeat(3,minmax(0,1fr)); gap: 5px; }
.notes-layout main footer button { min-height: 40px; padding: 0 6px; border: 1px solid #d5d5cf; border-radius: 7px; background: transparent; font-size: 9px; }
.notes-layout main footer button.recording { border-color: var(--workspace-ink); background: var(--workspace-ink); color: #fff; }
.notes-audio { padding-bottom: 9px; }
.notes-audio audio { width: 100%; height: 36px; }
.notes-audio > a { display: inline-flex; min-height: 34px; margin-top: 4px; align-items: center; color: #666660; font-size: 8px; text-decoration: underline; text-underline-offset: 3px; }
.notes-study { margin: 22px 0 14px; padding-top: 15px; border-top: 1px solid var(--workspace-ink); }
.notes-study > header { border-bottom-color: var(--workspace-line); }
.notes-study .workspace-actions button { min-height: 43px; background: transparent; }
.notes-app[data-notes-ready="false"] .notes-layout,.notes-app[data-notes-ready="false"] .notes-study { opacity: .55; pointer-events: none; }

/* ---------- Responsive ---------- */
@media (min-width: 600px) {
  .workspace-app { padding-right: 12px; padding-left: 12px; }
  .notes-layout { display: grid; grid-template-columns: 150px minmax(0,1fr); min-height: 520px; overflow: hidden; border-top: 1px solid var(--workspace-line); border-bottom: 1px solid var(--workspace-line); }
  .notes-layout aside { padding: 14px 12px; overflow: auto; border-right: 1px solid var(--workspace-line); border-bottom: 0; }
  #notesList { display: grid; gap: 3px; overflow: visible; }
  #notesList button { width: 100%; min-height: 60px; }
  .notes-layout main { padding: 18px 20px 0; }
}
@media (max-width: 350px) {
  .workspace-head { min-height: 70px; }
  .workspace-head strong { font-size: 22px; }
  .writing-project-bar { align-items: stretch; flex-direction: column; }
  .writing-project-bar .workspace-toggle { justify-content: flex-end; }
  .workspace-tabs { gap: 17px; }
  .writing-footer { align-items: flex-start; flex-direction: column; }
  .writing-footer > div { display: grid; grid-template-columns: repeat(3,minmax(0,1fr)); width: 100%; }
  .workspace-actions:has(> :nth-child(3)) { grid-template-columns: repeat(3,minmax(0,1fr)); }
  .planner-calendar button { min-height: 43px; }
}
@media (max-height: 700px) {
  .workspace-head { min-height: 62px; }
  .writing-editor { min-height: 235px; }
  .notes-layout { min-height: 370px; }
  #notesBody { min-height: 220px; }
}
