/* 婚禮工作台 · 應用殼層與頁面（app/app.css）
   元件（.card .tabs .ledger .dialog .toast .empty .field .btn 等）由 shared/paper.css 提供，這裡只放版面與頁面專屬樣式。
   只用 paper.css 的 token；不寫顏色或字體字面值。 */

/* ---------- Shell ---------- */
.app {
  min-height: 100vh;
  display: block;
}

/* Navigation is the functional layer: a recessed chrome tone, flat, so content cards read as the front layer. */
.site-head {
  background-color: var(--chrome);
  border-bottom: 1px solid var(--desk-line);
  box-shadow: var(--shadow-band);
  padding: var(--s-3) var(--s-4);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--s-3);
  position: relative;
  z-index: 2;
}

.brand {
  display: inline-flex;
  align-items: center;
  gap: var(--s-3);
  min-height: var(--tap);
  color: var(--ink);
  text-decoration: none;
}

.brand:hover {
  color: var(--ink);
}

.site-nav {
  display: flex;
  gap: var(--s-1);
  overflow-x: auto;
}

.site-nav a {
  display: inline-flex;
  align-items: center;
  gap: var(--s-2);
  min-height: var(--tap);
  padding: 0 var(--s-3);
  border-radius: var(--r);
  color: var(--ink-2);
  text-decoration: none;
  white-space: nowrap;
}

.site-nav a:hover {
  color: var(--ink);
  background: var(--desk);
}

/* Current page: a raised paper tab on the chrome, with the accent kept to the icon. */
.site-nav a[aria-current="page"] {
  color: var(--ink);
  background: var(--paper);
  box-shadow: var(--shadow-paper);
  font-weight: 600;
}

.site-nav a[aria-current="page"] .i {
  color: var(--accent);
}

.avatar {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: var(--paper-2);
  border: 1px solid var(--line-strong);
  font-family: var(--f-serif);
  font-size: var(--fs-sm);
  color: var(--ink-2);
  flex: none;
}

.site-foot {
  display: none;
}

.site-foot-text {
  display: grid;
  gap: 2px;
  min-width: 0;
}

.site-foot-name {
  font-weight: 500;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.main {
  padding: var(--s-5) var(--s-4) var(--s-8);
  min-width: 0;
  outline: none;
}

.main-inner {
  max-width: 880px;
  margin: 0 auto;
  display: grid;
  gap: var(--s-7);
}

.main-inner.is-wide {
  max-width: none;
}

/* 章節：雙線金框 */
.sec {
  display: grid;
  gap: var(--s-4);
  align-content: start;
  min-width: 0;
}

.sec-head {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  justify-content: space-between;
  gap: var(--s-2) var(--s-4);
  padding-bottom: var(--s-3);
  border-bottom: 3px double var(--gold);
}

.sec-head-actions {
  display: flex;
  flex-wrap: wrap;
  gap: var(--s-2);
}

.sec-no {
  font-family: var(--f-serif);
  font-size: var(--fs-sm);
  color: var(--accent-text);
  letter-spacing: 0.08em;
}

.page-head {
  display: grid;
  gap: var(--s-2);
}

.page-head h1 {
  margin-top: var(--s-1);
}

/* ---------- Paper lists: program (todos), rows (meetings), wedding cards ---------- */
.program,
.rows {
  background-color: var(--paper);
  background-image: var(--tex-fiber);
  border: 1px solid var(--paper-edge);
  border-radius: var(--r);
  box-shadow: var(--shadow-paper);
  padding: 0 var(--s-4);
  margin: 0;
  list-style: none;
}

.program li {
  display: grid;
  grid-template-columns: 44px 64px minmax(0, 1fr) auto;
  align-items: start;
  gap: var(--s-2) var(--s-3);
  padding: var(--s-3) 0;
  border-bottom: 1px solid var(--line);
}

/* The next thing to do is the focus of the page: raised tint row, accent bar, accent time. */
.program li.is-next {
  margin: 0 calc(-1 * var(--s-4));
  padding-left: var(--s-4);
  padding-right: var(--s-4);
  background: var(--paper-2);
  box-shadow: inset 3px 0 0 var(--accent);
}

.program li.is-next .time {
  color: var(--accent-text);
  font-weight: 600;
}

.program li:last-child {
  border-bottom: 0;
}

.todo-toggle {
  width: var(--tap);
  height: var(--tap);
  padding: 0;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border: 0;
  background: none;
  color: var(--ink);
}

.todo-toggle:disabled {
  cursor: progress;
}

.program .box {
  width: 20px;
  height: 20px;
  border: 1.5px solid var(--field-line);
  border-radius: 2px;
  background: var(--card);
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

.program li.done .box {
  background: var(--paper-2);
  border-color: var(--line-strong);
}

.program .box .i {
  width: 14px;
  height: 14px;
  opacity: 0;
}

.program li.done .box .i {
  opacity: 1;
}

.program .time {
  font-family: var(--f-serif);
  font-size: var(--fs-md);
  color: var(--ink);
  white-space: nowrap;
  font-variant-numeric: lining-nums tabular-nums;
  padding-top: var(--s-2);
}

.program .task {
  color: var(--ink);
  font-weight: 500;
  padding-top: var(--s-2);
  overflow-wrap: anywhere;
}

.program li.done .task {
  color: var(--ink-2);
  font-weight: 400;
  text-decoration: line-through;
  text-decoration-color: var(--line-strong);
}

.program .sub {
  display: block;
  font-size: var(--fs-sm);
  font-weight: 400;
  color: var(--ink-2);
}

/* Case names are supporting info here: quiet until hovered, so the task text leads. */
.program .sub a,
.rows .who a,
.ledger tbody th a {
  color: var(--ink-2);
  text-decoration: none;
}

.rows .who a,
.ledger tbody th a {
  color: var(--ink);
}

.program .sub a:hover,
.rows .who a:hover,
.ledger tbody th a:hover {
  color: var(--accent-text);
  text-decoration: underline;
}

.program .sub a {
  display: inline-flex;
  align-items: center;
  min-height: var(--tap);
}

.program .tag {
  align-self: center;
}

.rows li {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: var(--s-2) var(--s-4);
  padding: var(--s-3) 0;
  border-bottom: 1px dotted var(--line-strong);
}

.rows li:last-child {
  border-bottom: 0;
}

.rows .who {
  font-family: var(--f-serif);
  font-weight: 600;
}

.rows .who a {
  display: inline-flex;
  align-items: center;
  min-height: var(--tap);
}

.wedding-grid {
  display: grid;
  gap: var(--s-4);
  grid-template-columns: 1fr;
}

.wedding-card {
  gap: var(--s-2);
}

.wedding-card h3 {
  font-size: var(--fs-lg);
}

/* Tomorrow's (or today's) wedding is lifted above the other cards. */
.wedding-card.is-soon {
  border-top: 3px solid var(--accent);
  box-shadow: var(--shadow-raised);
}

.wedding-card h3 a {
  color: var(--ink);
  text-decoration: none;
}

.wedding-card h3 a:hover {
  color: var(--accent-text);
  text-decoration: underline;
}

.wedding-card .when {
  font-family: var(--f-serif);
  font-size: var(--fs-md);
  color: var(--ink-2);
}

.wedding-card .meta {
  font-size: var(--fs-sm);
  color: var(--ink-2);
  margin: 0;
}

.wedding-card .meta + .meta {
  margin-top: 0;
}

.wedding-card .actions {
  display: flex;
  flex-wrap: wrap;
  gap: var(--s-2);
  align-items: center;
}

/* ---------- Home header and calendar ---------- */
.home-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: var(--s-5);
}

.home-head .lead {
  margin-top: var(--s-2);
}

.home-head h1 {
  margin-top: var(--s-1);
}

.tear-cal {
  flex: none;
  display: grid;
  justify-items: center;
  width: 96px;
  overflow: hidden;
  text-align: center;
  background-color: var(--paper);
  background-image: var(--tex-fiber);
  border: 1px solid var(--paper-edge);
  border-radius: var(--r);
  box-shadow: var(--shadow-paper);
}

.tc-month {
  justify-self: stretch;
  padding: 2px 0;
  background: var(--accent);
  color: var(--on-accent);
  font-family: var(--f-serif);
  font-size: var(--fs-xs);
  letter-spacing: 0.2em;
  border-bottom: 1px dashed var(--pending-line);
}

.tc-day {
  padding-top: var(--s-2);
  font-family: var(--f-serif);
  font-size: var(--fs-2xl);
  line-height: 1;
  color: var(--ink);
}

.tc-week {
  padding: var(--s-2) var(--s-2) var(--s-3);
  font-size: var(--fs-xs);
  color: var(--ink-2);
}

.nowrap {
  white-space: nowrap;
}

.home-grid {
  display: grid;
  gap: var(--s-7);
  align-items: start;
}

.home-wide {
  grid-column: 1 / -1;
}

.home-grid .wedding-grid {
  grid-template-columns: 1fr;
}

/* 01 今日待辦／02 本週婚禮並排（≥700），03、04 全寬 */
@media (min-width: 700px) {
  .home-grid {
    grid-template-columns: minmax(0, 1.35fr) minmax(0, 1fr);
    gap: var(--s-6);
  }
}

/* ---------- Filters (cases list) ---------- */
.filter-bar {
  display: grid;
  gap: var(--s-3);
}

.filter-bar .field {
  max-width: 420px;
}

/* ---------- Case header ---------- */
.case-head {
  position: relative;
  isolation: isolate;
  display: grid;
  gap: var(--s-3);
  padding: var(--s-5) var(--s-6);
  background-color: var(--paper);
  background-image:
    linear-gradient(var(--gold), var(--gold)) left 12px top 12px / 16px 1px no-repeat,
    linear-gradient(var(--gold), var(--gold)) left 12px top 12px / 1px 16px no-repeat,
    linear-gradient(var(--gold), var(--gold)) right 12px top 12px / 16px 1px no-repeat,
    linear-gradient(var(--gold), var(--gold)) right 12px top 12px / 1px 16px no-repeat,
    linear-gradient(var(--gold), var(--gold)) left 12px bottom 12px / 16px 1px no-repeat,
    linear-gradient(var(--gold), var(--gold)) left 12px bottom 12px / 1px 16px no-repeat,
    linear-gradient(var(--gold), var(--gold)) right 12px bottom 12px / 16px 1px no-repeat,
    linear-gradient(var(--gold), var(--gold)) right 12px bottom 12px / 1px 16px no-repeat,
    var(--tex-fiber);
  border: 1px solid var(--paper-edge);
  border-radius: var(--r);
  box-shadow: var(--shadow-raised);
}

.case-head::before {
  content: "";
  position: absolute;
  inset: 6px -8px -8px 8px;
  z-index: -1;
  background-color: var(--paper-2);
  border: 1px solid var(--paper-edge);
  border-radius: var(--r);
  box-shadow: var(--shadow-paper);
  opacity: 0.5;
}

.case-head h1 {
  font-size: var(--fs-xl);
}

.case-title {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: var(--s-2) var(--s-3);
}

.case-title h1 {
  flex: 1 1 auto;
  min-width: 0;
  overflow-wrap: anywhere;
}

.case-meta {
  margin: var(--s-3) 0 0;
  color: var(--ink-2);
  font-size: var(--fs-sm);
  line-height: 1.9;
}

.case-date {
  color: var(--ink);
  font-weight: 500;
}

.countdown {
  margin-left: var(--s-2);
  font-family: var(--f-serif);
  font-size: 24px;
  font-weight: 500;
  line-height: 1;
  color: var(--accent);
  font-variant-numeric: lining-nums tabular-nums;
}

.facts {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  margin: var(--s-4) 0 0;
  border-top: 1px solid var(--line);
}

.facts > div {
  display: grid;
  gap: 2px;
  min-width: 0;
  padding: var(--s-3) 0;
  border-bottom: 1px solid var(--line);
  font-size: var(--fs-sm);
}

.facts > div + div {
  padding-left: var(--s-4);
  border-left: 1px solid var(--line);
}

.facts dt {
  color: var(--ink-2);
  font-size: var(--fs-xs);
}

.facts dd {
  margin: 0;
  font-weight: 500;
  overflow-wrap: anywhere;
}

/* 案件分頁內容 */
.tab-pane[hidden] {
  display: none;
}

.case-pane {
  min-width: 0;
}

.case-frame {
  display: block;
  width: 100%;
  height: 640px;
  border: 1px solid var(--paper-edge);
  border-radius: var(--r);
  background: var(--card);
  box-shadow: var(--shadow-paper);
}

/* ---------- Files ---------- */
.dropzone {
  display: grid;
  gap: var(--s-2);
  justify-items: start;
  padding: var(--s-5);
  border: 1px dashed var(--field-line);
  border-radius: var(--r);
  background: var(--paper-2);
  color: var(--ink-2);
}

.dropzone.is-over {
  border-color: var(--accent);
  background: var(--accent-tint);
  color: var(--ink);
}

.dropzone-actions {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: var(--s-3);
}

.file-name {
  overflow-wrap: anywhere;
}

.file-actions {
  display: flex;
  flex-wrap: wrap;
  gap: var(--s-1);
}

/* 44px tap height: list links */
.ledger a,
.rows a,
.program a,
.wedding-card h3 a {
  display: inline-flex;
  align-items: center;
  min-height: var(--tap);
}

/* ---------- Forms (settings, new case) ---------- */
.form-stack {
  display: grid;
  gap: var(--s-4);
}

.form-row {
  display: grid;
  gap: var(--s-4);
  grid-template-columns: repeat(2, minmax(0, 1fr));
}

.form-actions {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: var(--s-2);
}

.dialog-form {
  display: grid;
  gap: var(--s-4);
}

.dialog h2 {
  margin: 0;
}

/* ---------- AI assistant panel ---------- */
.ai-fab {
  display: none;
}

.ai-panel {
  min-width: 0;
}

.ai-panel[hidden] {
  display: none;
}

.ai-panel .chat-close {
  display: none;
}

/* ---------- Breakpoints ---------- */

/* 手機 ≤699：頂列＋單欄，AI 全螢幕覆蓋 */
@media (max-width: 699px) {
  .site-head {
    position: sticky;
    top: 0;
    flex-wrap: wrap;
    padding: var(--s-2) var(--s-4);
  }

  .site-nav {
    width: 100%;
    order: 3;
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    overflow: visible;
  }

  .site-nav a {
    flex-direction: column;
    justify-content: center;
    gap: 2px;
    padding: var(--s-1) 2px;
    font-size: var(--fs-sm);
    text-align: center;
  }

  .main {
    padding: var(--s-5) var(--s-3) 96px;
  }

  .main-inner {
    gap: var(--s-6);
  }

  .card,
  .case-head {
    padding: var(--s-4);
  }

  .case-head {
    padding: var(--s-5) var(--s-4);
  }

  .case-head::before {
    inset: 5px -4px -6px 5px;
  }

  .sec {
    gap: var(--s-3);
  }

  .ai-fab {
    display: inline-flex;
    position: fixed;
    right: var(--s-4);
    bottom: var(--s-4);
    min-height: var(--tap);
    padding: 0 var(--s-4);
    background: var(--primary);
    color: var(--on-primary);
    border: 0;
    border-radius: 999px;
    box-shadow: var(--shadow-float);
    align-items: center;
    gap: var(--s-2);
    z-index: 5;
    font-size: var(--fs-sm);
    font-weight: 500;
  }

  .ai-panel {
    position: fixed;
    inset: 0;
    z-index: 10;
    display: flex;
    flex-direction: column;
    background: var(--paper);
  }

  .ai-panel .chat-root {
    flex: 1 1 auto;
    min-height: 0;
  }

  .ai-panel .chat-close {
    display: inline-flex;
  }

  .program li {
    grid-template-columns: 44px minmax(0, 1fr) auto;
  }

  .program .time {
    grid-column: 2 / 3;
    padding-top: 0;
  }

  .program li > .task {
    grid-column: 2 / 3;
  }

  .program li > .tag {
    grid-column: 3;
  }

  .program li > .todo-toggle {
    grid-row: span 2;
  }

  .rows li {
    grid-template-columns: 1fr;
  }

  .facts {
    grid-template-columns: 1fr;
  }

  .facts > div + div {
    padding-left: 0;
    border-left: 0;
  }

  .form-row {
    grid-template-columns: 1fr;
  }

  .case-frame {
    height: 560px;
  }
}

/* 平板 700–1359：頂列＋浮動 AI 面板 */
@media (min-width: 700px) and (max-width: 1359px) {
  .site-head {
    position: sticky;
    top: 0;
    padding: var(--s-2) var(--s-5);
  }

  .site-nav {
    flex: 1;
    justify-content: flex-start;
  }

  .main {
    padding: var(--s-6) var(--s-5) 96px;
  }

  .main-inner {
    max-width: 760px;
  }

  .main-inner.is-wide {
    max-width: none;
  }

  .wedding-grid {
    grid-template-columns: 1fr 1fr;
  }

  .ai-fab {
    display: inline-flex;
    position: fixed;
    right: var(--s-5);
    bottom: var(--s-5);
    min-height: var(--tap);
    padding: 0 var(--s-5);
    background: var(--primary);
    color: var(--on-primary);
    border: 0;
    border-radius: 999px;
    box-shadow: var(--shadow-float);
    align-items: center;
    gap: var(--s-2);
    z-index: 5;
    font-size: var(--fs-sm);
    font-weight: 500;
  }

  .ai-panel {
    position: fixed;
    right: var(--s-5);
    bottom: 88px;
    width: min(480px, calc(100vw - 2 * var(--s-5)));
    height: min(820px, calc(100vh - 120px));
    z-index: 10;
    display: flex;
    flex-direction: column;
    border: 1px solid var(--paper-edge);
    border-radius: var(--r);
    box-shadow: var(--shadow-float);
    background: var(--paper);
    overflow: hidden;
  }

  .ai-panel .chat-root {
    flex: 1 1 auto;
    min-height: 0;
  }

  .ai-panel .chat-close {
    display: inline-flex;
  }
}

/* 桌面 ≥1360：三欄 側欄｜主欄｜AI 右欄 */
@media (min-width: 1360px) {
  .app {
    display: grid;
    grid-template-columns: 220px minmax(0, 1fr) clamp(380px, 28vw, 460px);
    grid-template-areas: "side main ai";
    align-items: start;
  }

  .site-head {
    grid-area: side;
    position: sticky;
    top: 0;
    height: 100vh;
    flex-direction: column;
    align-items: stretch;
    justify-content: flex-start;
    gap: var(--s-5);
    padding: var(--s-6) var(--s-4);
    border-bottom: 0;
    border-right: 1px solid var(--desk-line);
    box-shadow: none;
    overflow-y: auto;
  }

  .brand {
    flex-direction: column;
    align-items: flex-start;
    gap: var(--s-2);
  }

  .wordmark {
    font-size: 56px;
  }

  .site-nav {
    flex-direction: column;
    overflow: visible;
  }

  .site-nav a {
    justify-content: flex-start;
  }

  .avatar {
    display: none;
  }

  .site-foot {
    display: flex;
    align-items: center;
    gap: var(--s-2);
    margin-top: auto;
    font-size: var(--fs-xs);
    color: var(--ink-2);
  }

  .main {
    grid-area: main;
    padding: var(--s-7) var(--s-6) var(--s-8);
  }

  .main-inner {
    max-width: 800px;
    margin: 0;
  }

  .main-inner.is-wide {
    max-width: none;
  }

  .wedding-grid {
    grid-template-columns: 1fr 1fr;
  }

  .ai-fab {
    display: none;
  }

  .ai-panel {
    grid-area: ai;
    position: sticky;
    top: 0;
    height: 100vh;
    display: flex;
    flex-direction: column;
    border-left: 1px solid var(--paper-edge);
    box-shadow: var(--shadow-side);
    background: var(--panel);
  }

  .ai-panel[hidden] {
    display: flex;
  }

  .ai-panel .chat-root {
    flex: 1 1 auto;
    min-height: 0;
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    scroll-behavior: auto !important;
    transition-duration: 0.01ms !important;
    animation-duration: 0.01ms !important;
  }
}
