/* ============================================================================
   Phoenix · Modal + Toast + Command Palette + Print
   ============================================================================ */

/* ── Modal overlay ─────────────────────────────────────────────────── */
.phx-modal-overlay {
  position: fixed; inset: 0;
  background: oklch(0.20 0.020 260 / 0.40);
  backdrop-filter: blur(2px);
  -webkit-backdrop-filter: blur(2px);
  z-index: 200;
  display: grid; place-items: center;
  padding: var(--space-5);
  animation: phx-fade 150ms var(--ease-out);
}
.phx-modal-overlay.closing { animation: phx-fade-out 150ms var(--ease-out) forwards; }

@keyframes phx-fade { from { opacity: 0; } to { opacity: 1; } }
@keyframes phx-fade-out { to { opacity: 0; } }

.phx-modal {
  background: var(--surface-1);
  border-radius: var(--radius-xl);
  box-shadow: var(--shadow-xl);
  width: 100%;
  max-height: calc(100vh - var(--space-10));
  display: flex; flex-direction: column;
  overflow: hidden;
  animation: phx-slide-up 200ms var(--ease-out);
}
.phx-modal-sm { max-width: 420px; }
.phx-modal-md { max-width: 600px; }
.phx-modal-lg { max-width: 880px; }

@keyframes phx-slide-up {
  from { transform: translateY(8px); opacity: 0; }
  to   { transform: translateY(0); opacity: 1; }
}

.phx-modal-head {
  display: flex; align-items: center; justify-content: space-between;
  padding: var(--space-5) var(--space-6);
  border-bottom: 1px solid var(--border-subtle);
}
.phx-modal-title {
  margin: 0;
  font-size: var(--text-md);
  font-weight: var(--weight-semibold);
  letter-spacing: var(--tracking-tight);
  color: var(--fg-primary);
}
.phx-modal-close {
  width: 28px; height: 28px;
  display: grid; place-items: center;
  background: transparent;
  border: 0;
  border-radius: var(--radius-sm);
  color: var(--fg-tertiary);
  cursor: pointer;
  transition: all var(--duration-fast) var(--ease-out);
}
.phx-modal-close:hover { background: var(--gray-100); color: var(--fg-primary); }

.phx-modal-body {
  padding: var(--space-6);
  overflow-y: auto;
  flex: 1;
}
.phx-modal-foot {
  padding: var(--space-4) var(--space-6);
  border-top: 1px solid var(--border-subtle);
  background: var(--bg-subtle);
  display: flex;
  justify-content: flex-end;
  gap: var(--space-2);
}

/* ── Toast ─────────────────────────────────────────────────────────── */
#phx-toast-root {
  position: fixed;
  bottom: var(--space-5);
  right: var(--space-5);
  z-index: 300;
  display: flex; flex-direction: column;
  gap: var(--space-2);
  pointer-events: none;
}
.phx-toast {
  pointer-events: auto;
  background: var(--surface-1);
  border: 1px solid var(--border-default);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-lg);
  padding: var(--space-3) var(--space-4);
  display: flex; align-items: center;
  gap: var(--space-3);
  min-width: 280px; max-width: 460px;
  font-size: var(--text-sm);
  color: var(--fg-primary);
  transform: translateX(20px);
  opacity: 0;
  transition: transform 200ms var(--ease-out), opacity 200ms var(--ease-out);
}
.phx-toast.shown { transform: translateX(0); opacity: 1; }
.phx-toast-icon {
  width: 20px; height: 20px;
  border-radius: var(--radius-full);
  display: grid; place-items: center;
  font-size: 11px; font-weight: var(--weight-semibold);
  color: #fff;
  flex-shrink: 0;
}
.phx-toast-info  .phx-toast-icon { background: var(--brand-500); }
.phx-toast-success .phx-toast-icon { background: var(--success-500); }
.phx-toast-warn .phx-toast-icon { background: var(--warn-500); }
.phx-toast-danger .phx-toast-icon { background: var(--danger-500); }
.phx-toast-message { flex: 1; line-height: var(--leading-snug); }
.phx-toast-action {
  border: 0; background: transparent;
  color: var(--brand-700);
  font-weight: var(--weight-semibold);
  font-size: var(--text-xs);
  cursor: pointer;
  padding: 4px 8px;
  border-radius: var(--radius-sm);
}
.phx-toast-action:hover { background: var(--brand-50); }
.phx-toast-close {
  background: transparent; border: 0;
  font-size: var(--text-md); color: var(--fg-tertiary);
  cursor: pointer; line-height: 1;
  padding: 0 4px;
}

/* ── Command palette ─────────────────────────────────────────────── */
.cp-section {
  font-size: var(--text-2xs);
  letter-spacing: var(--tracking-caps);
  text-transform: uppercase;
  color: var(--fg-tertiary);
  font-weight: var(--weight-semibold);
  padding: var(--space-2) var(--space-2);
}
.cp-item {
  display: flex; align-items: center;
  width: 100%;
  padding: var(--space-2) var(--space-3);
  background: transparent;
  border: 0;
  border-radius: var(--radius-sm);
  font-family: inherit;
  font-size: var(--text-sm);
  color: var(--fg-primary);
  cursor: pointer;
  text-align: left;
  gap: var(--space-3);
  transition: background var(--duration-instant) var(--ease-out);
}
.cp-item:hover { background: var(--bg-subtle); }
.cp-item.selected { background: var(--brand-50); }
.cp-section-tag {
  font-size: var(--text-2xs);
  color: var(--fg-tertiary);
  background: var(--gray-100);
  padding: 2px 8px;
  border-radius: var(--radius-xs);
  letter-spacing: var(--tracking-tight);
}
.cp-label { flex: 1; }
.cp-kbd {
  font-family: var(--font-sans);
  font-size: var(--text-2xs);
  background: var(--bg-subtle);
  border: 1px solid var(--border-default);
  border-radius: var(--radius-xs);
  padding: 1px 6px;
  color: var(--fg-secondary);
  font-weight: var(--weight-medium);
}

/* ── Form helpers (모달 내부) ────────────────────────────────────── */
.form-row { display: flex; flex-direction: column; gap: var(--space-2); margin-bottom: var(--space-4); }
.form-row label { font-size: var(--text-xs); color: var(--fg-secondary); font-weight: var(--weight-medium); letter-spacing: var(--tracking-tight); }
.form-row input, .form-row select, .form-row textarea {
  height: 36px; padding: 0 var(--space-3);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-md);
  font-family: inherit; font-size: var(--text-sm);
  background: var(--surface-1); color: var(--fg-primary);
}
.form-row textarea {
  height: auto; min-height: 80px;
  padding: var(--space-2) var(--space-3);
  resize: vertical;
  font-family: inherit;
}
.form-row input:focus-visible, .form-row select:focus-visible, .form-row textarea:focus-visible {
  outline: none; border-color: var(--border-focus); box-shadow: var(--shadow-focus);
}
.form-row .hint { font-size: var(--text-2xs); color: var(--fg-tertiary); }
.form-row-grid { display: grid; grid-template-columns: 1fr 1fr; gap: var(--space-3); }

/* ── Print stylesheet ────────────────────────────────────────────── */
@media print {
  /* 사이드바·topbar·footer 제거, 모달 제거 */
  .sidebar, .topbar, .phx-modal-overlay, #phx-toast-root { display: none !important; }
  .app { display: block; }
  .main { display: block; }
  .page { padding: 0; max-width: none; }
  .page-actions { display: none; }
  .footnote { page-break-inside: avoid; }

  /* 카드들 페이지 분할 회피 */
  .panel, .layer-card, .scen, .kpi-card, .ceiling-card, .pricing-card,
  .contract-card, .policyholder-card, .formula-card, .pricer-hero, .stepper {
    page-break-inside: avoid;
    box-shadow: none !important;
    border: 1px solid #ccc !important;
  }

  /* 색상 보존 (브라우저 print 기본은 색 빠짐) */
  body { -webkit-print-color-adjust: exact; print-color-adjust: exact; }

  /* 페이지 설정 */
  @page { size: A4 landscape; margin: 12mm; }

  /* 그라디언트 배경은 인쇄 시 단색으로 */
  .hero, .final-card, .ceiling-card { background: #f7f9fb !important; color: #161B22 !important; }
  .final-card * { color: #161B22 !important; }
}
