/* === Page-wide defaults === */
/* Lives here rather than as an inline <style> in index.html so the
   Content-Security-Policy can forbid inline styles cleanly. */

body {
  font-family: 'Noto Sans TC', system-ui, sans-serif;
  background-color: #F8F9FA;
  color: #1A1A2E;
  margin: 0;
}

/* === The Paper — 公文即介面 === */
/* The document sheet IS the interface: one centered sheet, floating on
   a desk-colored backdrop, from idle through done. */

.doc-preview {
  font-family: 'Noto Serif TC', 'PMingLiU', serif;
  background-color: #FFFFFF;
  color: #111111;
  width: 680px;
  box-sizing: border-box;
  padding: 40px 48px;
  line-height: 2.0;
  font-size: 17px;
  border-radius: 2px;
  box-shadow: 0 1px 2px rgba(0, 0, 0, .08), 0 14px 36px rgba(30, 40, 60, .16);
  position: relative;
}

/* Desk: the scroll container behind the paper. A saturated navy/periwinkle
   wash (not a flat gray) is what makes the glass panels visibly frost —
   blurring a uniform color looks identical to a solid panel. */
.desk-wrap {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  background-color: #DDE3EF;
  background-image:
    radial-gradient(820px 460px at 12% -8%, rgba(30, 58, 110, 0.22), transparent 68%),
    radial-gradient(760px 520px at 92% 8%, rgba(99, 130, 200, 0.20), transparent 66%),
    radial-gradient(1000px 620px at 78% 108%, rgba(30, 58, 110, 0.20), transparent 70%),
    linear-gradient(160deg, #E7ECF6 0%, #D6DEEF 50%, #E3E8F4 100%);
}

.desk {
  flex: 1;
  overflow-y: auto;
  overflow-x: auto;
  padding: 0 16px 130px;
}

/* Sticky glass region holding the describe bar + its under-bar chips, so
   the paper scrolls UP BEHIND it — the moment the glass reads as glass. */
.desk-bar {
  position: sticky;
  top: 0;
  z-index: 30;
  padding: 16px 0 12px;
  /* faint top fade so paper doesn't collide hard with the bar's edge */
  background: linear-gradient(to bottom, rgba(225, 230, 242, 0.55), rgba(225, 230, 242, 0));
  /* The transparent fade region must NOT swallow clicks on cards scrolled
     under it — only the bar + its chips are interactive. Without this the
     sticky band (z-30, full width) blocks clicks on anything beneath it. */
  pointer-events: none;
}

.desk-bar > * {
  pointer-events: auto;
}

/* Liquid-glass panels: .pvbar, .pvdock, .note-card, .glass-top each carry
   the treatment (translucent white + backdrop blur + bright inner edge).
   The paper itself stays solid: it's paper. */

.desk-inner {
  display: flex;
  gap: 34px;
  width: max-content;
  margin: 0 auto;
  align-items: flex-start;
}

.paper-col { width: 680px; }
.notes-col { width: 290px; padding-top: 10px; }

.paper-dimmed { opacity: 0.55; transition: opacity 0.2s; }

/* Margin annotation cards — the AI's red-pen notes beside the paper */
.note-card {
  position: relative;
  background: rgba(255, 255, 255, 0.6);
  backdrop-filter: blur(16px) saturate(150%);
  -webkit-backdrop-filter: blur(16px) saturate(150%);
  border: 1px solid rgba(255, 255, 255, 0.7);
  border-left: 3px solid #1E3A6E;
  border-radius: 10px;
  padding: 14px 16px;
  margin-bottom: 14px;
  box-shadow:
    0 4px 14px rgba(22, 41, 79, 0.08),
    inset 0 1px 0 rgba(255, 255, 255, 0.7);
  animation: fade-up 0.25s ease-out;
}

.note-card::before {
  content: '';
  position: absolute;
  left: -37px;
  top: 18px;
  width: 34px;
  border-top: 1px solid #C3CCDD;
}

.note-card::after {
  content: '';
  position: absolute;
  left: -42px;
  top: 14.5px;
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: #1E3A6E;
}

.note-card.warn { border-left-color: #F4D88C; background: rgba(255, 251, 235, 0.72); }
.note-card.warn::after { background: #F59E0B; }
.note-card.error { border-left-color: #F0C4C0; background: rgba(254, 242, 242, 0.75); }
.note-card.error::after { background: #DC2626; }

/* Swipe-out exit: dismissed/answered cards slide off to the right + fade.
   The card stays mounted ~300ms (matches CARD_EXIT_MS in app.js) so the
   transition can run, then React unmounts it. */
.note-card.card-exit {
  transition: transform 0.3s cubic-bezier(0.4, 0, 0.6, 1), opacity 0.3s ease;
  transform: translateX(118%);
  opacity: 0;
  pointer-events: none;
}

/* Done-stage review deck: top card shown, peek layers behind it hint at
   how many confirmations remain. Only rendered when 2+ cards pending. */
.review-deck {
  position: relative;
  margin-bottom: 14px;
  padding-bottom: 16px;
}

.review-deck > .note-card {
  position: relative;
  z-index: 2;
  margin-bottom: 0;
}

.deck-peek {
  position: absolute;
  left: 0;
  right: 0;
  top: 0;
  bottom: 16px;
  border-radius: 10px;
  background: rgba(255, 251, 235, 0.6);
  border: 1px solid rgba(244, 216, 140, 0.5);
  border-left: 3px solid #F4D88C;
  box-shadow: 0 4px 12px rgba(22, 41, 79, 0.07);
}

.deck-peek-1 { transform: translate(6px, 8px); z-index: 1; }
.deck-peek-2 { transform: translate(12px, 16px); z-index: 0; }

/* Converse-stage question deck: same stacking, default (non-warn) peek tone.
   min-height dampens the layout shift when a shorter card is revealed —
   question heights vary, but only the top card is ever really rendered. */
.q-deck { min-height: 170px; }

.q-deck .deck-peek {
  background: rgba(255, 255, 255, 0.55);
  border: 1px solid rgba(255, 255, 255, 0.7);
  border-left: 3px solid #1E3A6E;
}

@keyframes fade-up {
  from { opacity: 0; transform: translateY(6px); }
  to { opacity: 1; transform: translateY(0); }
}

/* Describe bar — the pill input above the paper */
.pvbar {
  width: 760px;
  max-width: calc(100vw - 32px);
  margin: 0 auto;
  background: rgba(255, 255, 255, 0.42);
  backdrop-filter: blur(26px) saturate(180%);
  -webkit-backdrop-filter: blur(26px) saturate(180%);
  border: 1px solid rgba(255, 255, 255, 0.85);
  border-radius: 99px;
  padding: 6px 6px 6px 20px;
  display: flex;
  align-items: center;
  gap: 10px;
  box-shadow:
    0 6px 22px rgba(22, 41, 79, 0.14),
    inset 0 1px 0 rgba(255, 255, 255, 0.9);
  box-sizing: border-box;
}

.pvbar input {
  flex: 1;
  border: none;
  outline: none;
  font-size: 15px;
  font-family: inherit;
  color: #1F2937;
  background: transparent;
  min-width: 0;
}

.pvbar input::placeholder { color: #9CA3AF; }
.pvbar input:disabled { color: #9CA3AF; }

.pvbar-under {
  width: 760px;
  max-width: calc(100vw - 32px);
  margin: 10px auto 0;
  box-sizing: border-box;
}

/* Centered glass strip for under-bar chips/status. Gives the content a
   solid backing so the document scrolling beneath the sticky bar doesn't
   bleed through and clash with it. */
.under-strip {
  display: inline-flex;
  align-items: center;
  flex-wrap: wrap;
  justify-content: center;
  gap: 6px;
  max-width: 100%;
  padding: 5px 12px;
  border-radius: 99px;
  background: rgba(255, 255, 255, 0.6);
  backdrop-filter: blur(18px) saturate(160%);
  -webkit-backdrop-filter: blur(18px) saturate(160%);
  border: 1px solid rgba(255, 255, 255, 0.8);
  box-shadow: 0 2px 12px rgba(22, 41, 79, 0.1);
}

/* Action dock — fixed bottom, always one line. Floats over the paper
   when scrolling, so the glass blur really shows here. */
.pvdock {
  position: fixed;
  bottom: 18px;
  left: 50%;
  transform: translateX(-50%);
  width: max-content;
  white-space: nowrap;
  background: rgba(255, 255, 255, 0.45);
  backdrop-filter: blur(28px) saturate(190%);
  -webkit-backdrop-filter: blur(28px) saturate(190%);
  border: 1px solid rgba(255, 255, 255, 0.85);
  border-radius: 16px;
  box-shadow:
    0 10px 34px rgba(22, 41, 79, 0.22),
    inset 0 1px 0 rgba(255, 255, 255, 0.9);
  padding: 10px 14px;
  display: flex;
  align-items: center;
  gap: 10px;
  z-index: 40;
}

/* 複製欄位 dropdown — solid panel (NOT glass: a small text list needs
   contrast, not blur), vertical. The transparent .pb-2 bridge (in the
   markup) keeps the button→menu gap inside the hover region so the menu
   doesn't close while the cursor crosses to it. */
.copy-menu {
  background: #FFFFFF;
  border: 1px solid #E5E7EB;
  box-shadow: 0 10px 28px rgba(22, 41, 79, 0.16);
}

.copy-menu-item {
  display: block;
  width: 100%;
  text-align: left;
  padding: 7px 14px;
  font-size: 14px;
  border-radius: 7px;
  white-space: nowrap;
  color: #4B5563;
  border: 1px solid transparent; /* reserve space so hover border doesn't shift */
  transition: all 0.12s;
}

/* Same navy hover as the refine chips (border + text + light tint) */
.copy-menu-item:hover {
  background: #EFF3F9;
  border-color: #9DB1D4;
  color: #1E3A6E;
}

/* Glass top bar */
.glass-top {
  background: rgba(255, 255, 255, 0.6);
  backdrop-filter: blur(22px) saturate(160%);
  -webkit-backdrop-filter: blur(22px) saturate(160%);
  border-bottom: 1px solid rgba(255, 255, 255, 0.65);
  box-shadow: 0 1px 12px rgba(22, 41, 79, 0.08);
}

.pvdock-hint { font-size: 12px; color: #6B7280; }

/* Paper slots — empty fields waiting to be filled (native inputs: IME-safe) */
.pslot {
  font-family: inherit;
  font-size: inherit;
  line-height: inherit;
  color: #111111;
  background: #F7FAFF;
  border: none;
  border-bottom: 1.5px dashed #B6C6E4;
  border-radius: 2px;
  padding: 0 4px;
  outline: none;
  width: 100%;
  box-sizing: border-box;
  resize: none;
  overflow: hidden;
  display: block;
}

.pslot::placeholder { color: #7E97C4; }

.pslot:focus {
  border-bottom: 1.5px solid #1E3A6E;
  background: #F1F5FB;
}

.pslot-inline { display: inline-block; width: auto; min-width: 12em; }

/* 文別 chips on the paper */
.ptype-chip {
  font-family: 'Noto Sans TC', sans-serif;
  font-size: 13px;
  padding: 3px 12px;
  border: 1px solid #D1D5DB;
  border-radius: 99px;
  background: #FFFFFF;
  color: #4B5563;
  cursor: pointer;
  transition: all 0.15s;
}

.ptype-chip:hover { border-color: #9DB1D4; color: #1E3A6E; }

.ptype-chip.sel {
  border-color: #1E3A6E;
  background: #EFF3F9;
  color: #1E3A6E;
  font-weight: 500;
}

/* Sans-serif meta strip on the paper (category/direction/speed controls) */
.pmeta-strip {
  font-family: 'Noto Sans TC', sans-serif;
  font-size: 13px;
  color: #6B7280;
  display: flex;
  flex-wrap: wrap;
  gap: 8px 16px;
  align-items: center;
  line-height: 1.6;
}

.pmeta-strip select,
.pmeta-strip input {
  font-family: inherit;
  font-size: 13px;
  color: #374151;
  border: 1px solid #E5E7EB;
  border-radius: 6px;
  padding: 2px 6px;
  background: #FFFFFF;
  outline: none;
}

.pmeta-strip select:focus,
.pmeta-strip input:focus { border-color: #9DB1D4; }

/* Streaming caret + skeleton lines during generation */
.pvcaret {
  display: inline-block;
  width: 2px;
  height: 1.1em;
  background: #1E3A6E;
  vertical-align: -0.15em;
  margin-left: 1px;
  animation: caret-blink 0.9s steps(1) infinite;
}

@keyframes caret-blink { 50% { opacity: 0; } }

.skel-line {
  height: 0.9em;
  background: #E8EDF4;
  border-radius: 4px;
  margin: 0.7em 0;
  animation: skel-pulse 1.4s ease-in-out infinite;
}

@keyframes skel-pulse {
  0%, 100% { opacity: 0.55; }
  50% { opacity: 1; }
}

.doc-preview .doc-org-name {
  font-family: 'Noto Serif TC', serif;
  font-size: 21px;
  font-weight: 700;
  color: #1A3A5C;
  text-align: center;
  letter-spacing: 0.35em;
  text-indent: 0.35em; /* re-center: letter-spacing adds trailing space */
  margin-bottom: 0.25rem;
}

.doc-preview .doc-type-label {
  font-family: 'Noto Serif TC', serif;
  font-size: 17px;
  font-weight: 700;
  text-align: center;
  letter-spacing: 0.6em;
  text-indent: 0.6em;
  margin-bottom: 1rem;
}

.doc-preview .doc-header-line {
  border-top: 2px solid #9CA3AF;
  margin: 0.75rem 0;
}

.doc-preview .doc-header-double {
  border-top: 3px double #9CA3AF;
  margin: 0.75rem 0;
}

.doc-preview .doc-meta-row {
  display: flex;
  justify-content: space-between;
  font-size: 14px;
  margin: 0.3rem 0;
}

.doc-preview .doc-meta-label {
  color: #6B7280;
  min-width: 5em;
}

.doc-preview .doc-meta-value {
  flex: 1;
}

.doc-preview .doc-section-label {
  font-weight: 700;
  letter-spacing: 0.5em;
  margin-top: 1.25rem;
  margin-bottom: 0.25rem;
}

.doc-preview .doc-subject {
  margin-top: 1.25rem;
}

.doc-preview .doc-subject .doc-section-label {
  display: inline;
  margin-right: 0.5rem;
}

.doc-preview .doc-subject-text {
  display: inline;
}

.doc-preview .doc-explanation-item {
  text-indent: 0;
  padding-left: 2em;
  margin: 0.3rem 0;
}

.doc-preview .doc-action {
  margin-top: 1rem;
}

.doc-preview .doc-action .doc-section-label {
  display: inline;
  margin-right: 0.5rem;
}

.doc-preview .doc-action-text {
  display: inline;
}

.doc-preview .doc-signature {
  text-align: right;
  margin-top: 2rem;
  padding-right: 2rem;
}

.doc-preview .doc-signature-org {
  font-weight: 700;
  color: #1A3A5C;
}

.doc-preview .doc-footer {
  font-size: 13px;
  color: #6B7280;
  margin-top: 0.5rem;
}

.doc-preview .doc-placeholder {
  color: #C0392B;
  background-color: rgba(192, 57, 43, 0.08);
  padding: 0 0.2em;
  border-radius: 2px;
}

/* --- 簽/報告: Closing section (敬陳/校長) --- */

.doc-preview .doc-closing {
  text-align: center;
  margin-top: 2.5rem;
  margin-bottom: 1rem;
}

.doc-preview .doc-closing-text {
  font-size: 16px;
  margin-bottom: 0.25rem;
}

.doc-preview .doc-closing-title {
  font-size: 16px;
  font-weight: 700;
}

/* --- 簽/報告: Approval chain footer --- */

.doc-preview .doc-approval-chain {
  display: flex;
  justify-content: space-between;
  gap: 1rem;
}

/* === Editable Fields (click-to-edit in preview) === */

.doc-preview .editable-field {
  cursor: pointer;
  border-bottom: 1px dashed transparent;
  transition: border-color 0.15s, background-color 0.15s;
  border-radius: 2px;
  padding: 0 2px;
}

.doc-preview .editable-field:hover {
  border-bottom-color: #9CA3AF;
  background-color: rgba(156, 163, 175, 0.08);
}

.doc-preview .editable-field-input {
  font-family: 'Noto Serif TC', serif;
  font-size: inherit;
  line-height: inherit;
  color: #1A1A2E;
  background-color: #F9FAFB;
  border: 1px solid #D1D5DB;
  border-radius: 3px;
  padding: 2px 4px;
  width: 100%;
  box-sizing: border-box;
  outline: none;
  resize: none;
  overflow: hidden;
}

.doc-preview .editable-field-input:focus {
  border-color: #6B7280;
  box-shadow: 0 0 0 2px rgba(107, 114, 128, 0.2);
}

/* Keep inline display for subject and action fields */
.doc-preview .doc-subject .editable-field,
.doc-preview .doc-action .editable-field {
  display: inline;
}

.doc-preview .doc-subject .editable-field-input,
.doc-preview .doc-action .editable-field-input {
  display: inline-block;
  width: calc(100% - 5em);
}

/* Hide edit affordance in print */
@media print {
  .doc-preview .editable-field {
    border-bottom: none !important;
    cursor: default;
  }
}

/* === Animations === */

@keyframes pulse-dots {
  0%, 80%, 100% { opacity: 0.3; }
  40% { opacity: 1; }
}

.loading-dot {
  animation: pulse-dots 1.4s infinite both;
}

.loading-dot:nth-child(2) { animation-delay: 0.2s; }
.loading-dot:nth-child(3) { animation-delay: 0.4s; }

@keyframes fade-in {
  from { opacity: 0; transform: translateY(4px); }
  to { opacity: 1; transform: translateY(0); }
}

.fade-in {
  animation: fade-in 200ms ease-out;
}

/* === Print Styles === */
/* Hide the app chrome via .no-print tags (the old `#root > * { display:none }`
   approach killed the paper's ancestors too — descendants of a display:none
   element can never be made visible again). */

@media print {
  body { background: white !important; }

  .no-print { display: none !important; }

  .desk {
    background: white !important;
    padding: 0 !important;
    overflow: visible !important;
  }

  .desk-inner {
    display: block !important;
    width: auto !important;
  }

  .paper-col { width: auto !important; }

  .doc-preview {
    background: white !important;
    border: none !important;
    box-shadow: none !important;
    width: auto !important;
    padding: 2cm 2.5cm;
    font-size: 14pt;
    line-height: 2;
  }

  .pslot {
    background: transparent !important;
    border-bottom-color: transparent !important;
  }
}
