/* ==========================================================================
   Neopsy Record System - Medical Aesthetics & A5 Sheet Layout
   ========================================================================== */

:root {
  --primary: #1e56a0;
  --primary-dark: #163172;
  --primary-light: #e6eef8;
  --accent: #00a8cc;
  --success: #28a745;
  --warning: #f39c12;
  --danger: #e74c3c;
  --bg-main: #f4f7fb;
  --card-bg: #ffffff;
  --text-main: #2c3e50;
  --text-muted: #7f8c8d;
  --border-color: #dcdfe6;
  --shadow-sm: 0 2px 6px rgba(0, 0, 0, 0.05);
  --shadow-md: 0 4px 14px rgba(0, 0, 0, 0.08);
  --shadow-lg: 0 10px 25px rgba(0, 0, 0, 0.12);
  --radius: 8px;
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Noto Sans TC", "Microsoft JhengHei", sans-serif;
  background-color: var(--bg-main);
  color: var(--text-main);
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

/* ─── 登入畫面 ───────────────────────────────────────────────────────── */
.login-container {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  background: linear-gradient(135deg, #163172 0%, #1e56a0 50%, #00a8cc 100%);
}

.login-card {
  background: #ffffff;
  width: 100%;
  max-width: 440px;
  padding: 40px 35px;
  border-radius: 16px;
  box-shadow: 0 20px 40px rgba(0, 0, 0, 0.2);
  animation: fadeIn 0.4s ease;
}

.login-header {
  text-align: center;
  margin-bottom: 30px;
}

.login-badge {
  display: inline-block;
  background: var(--primary-light);
  color: var(--primary);
  font-size: 12px;
  font-weight: 700;
  padding: 4px 12px;
  border-radius: 20px;
  margin-bottom: 12px;
  letter-spacing: 0.5px;
}

.login-title {
  font-size: 22px;
  font-weight: 700;
  color: var(--primary-dark);
  margin-bottom: 6px;
}

.login-subtitle {
  font-size: 13px;
  color: var(--text-muted);
}

.form-group {
  margin-bottom: 20px;
}

.form-label {
  display: block;
  font-size: 13px;
  font-weight: 600;
  margin-bottom: 6px;
  color: #34495e;
}

.form-input {
  width: 100%;
  padding: 12px 14px;
  border: 1px solid var(--border-color);
  border-radius: var(--radius);
  font-size: 14px;
  transition: all 0.2s;
  outline: none;
}

.form-input:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(30, 86, 160, 0.15);
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 10px 20px;
  font-size: 14px;
  font-weight: 600;
  border-radius: var(--radius);
  border: none;
  cursor: pointer;
  transition: all 0.2s;
  gap: 8px;
  text-decoration: none;
}

.btn-primary {
  background: var(--primary);
  color: #ffffff;
}

.btn-primary:hover {
  background: var(--primary-dark);
  box-shadow: 0 4px 12px rgba(22, 49, 114, 0.25);
}

.btn-block {
  width: 100%;
  padding: 13px;
  font-size: 15px;
}

.btn-outline {
  background: transparent;
  border: 1px solid var(--border-color);
  color: var(--text-main);
}

.btn-outline:hover {
  background: #f0f3f8;
  border-color: #c0c4cc;
}

.btn-success {
  background: #27ae60;
  color: #ffffff;
}

.btn-success:hover {
  background: #219150;
}

.btn-sm {
  padding: 6px 12px;
  font-size: 12px;
}

.login-hints {
  margin-top: 25px;
  padding: 14px;
  background: #f8fafc;
  border: 1px dashed var(--border-color);
  border-radius: var(--radius);
  font-size: 12px;
  color: var(--text-muted);
}

.login-hints strong {
  color: var(--primary-dark);
}

/* ─── 主應用導覽列 ───────────────────────────────────────────────────── */
.navbar {
  background: #ffffff;
  border-bottom: 1px solid var(--border-color);
  padding: 0 25px;
  height: 64px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  position: sticky;
  top: 0;
  z-index: 100;
  box-shadow: var(--shadow-sm);
}

.nav-brand {
  display: flex;
  align-items: center;
  gap: 12px;
}

.brand-icon {
  width: 36px;
  height: 36px;
  background: linear-gradient(135deg, var(--primary) 0%, var(--accent) 100%);
  color: #ffffff;
  border-radius: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 800;
  font-size: 18px;
}

.brand-name {
  font-size: 16px;
  font-weight: 700;
  color: var(--primary-dark);
}

.brand-tag {
  background: var(--primary-light);
  color: var(--primary);
  font-size: 11px;
  font-weight: 700;
  padding: 2px 8px;
  border-radius: 12px;
}

.nav-status {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 12px;
  color: var(--text-muted);
  background: #f8fafc;
  padding: 6px 12px;
  border-radius: 20px;
  border: 1px solid #eef2f7;
}

.status-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--success);
  box-shadow: 0 0 6px var(--success);
}

.nav-actions {
  display: flex;
  align-items: center;
  gap: 12px;
}

.user-capsule {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 13px;
  font-weight: 600;
  color: var(--primary-dark);
  background: var(--primary-light);
  padding: 6px 14px;
  border-radius: 20px;
}

.role-badge {
  background: var(--primary);
  color: #fff;
  font-size: 10px;
  padding: 1px 6px;
  border-radius: 10px;
}

/* ─── 標籤列 ─────────────────────────────────────────────────────────── */
.nav-tabs {
  background: #ffffff;
  border-bottom: 1px solid var(--border-color);
  display: flex;
  padding: 0 25px;
  gap: 20px;
}

.nav-tab {
  padding: 14px 4px;
  font-size: 14px;
  font-weight: 600;
  color: var(--text-muted);
  cursor: pointer;
  border-bottom: 3px solid transparent;
  display: flex;
  align-items: center;
  gap: 6px;
  transition: all 0.2s;
}

.nav-tab:hover {
  color: var(--primary);
}

.nav-tab.active {
  color: var(--primary);
  border-bottom-color: var(--primary);
}

/* ─── 主版面容器 ─────────────────────────────────────────────────────── */
.main-content {
  max-width: 1400px;
  margin: 25px auto;
  padding: 0 20px;
}

/* ─── 卡片容器 ───────────────────────────────────────────────────────── */
.card {
  background: var(--card-bg);
  border-radius: var(--radius);
  border: 1px solid var(--border-color);
  box-shadow: var(--shadow-sm);
  margin-bottom: 25px;
  overflow: hidden;
}

.card-header {
  padding: 16px 20px;
  border-bottom: 1px solid var(--border-color);
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: #fafbfc;
}

.card-title {
  font-size: 15px;
  font-weight: 700;
  color: var(--primary-dark);
  display: flex;
  align-items: center;
  gap: 8px;
}

.card-body {
  padding: 20px;
}

/* ─── 查詢欄位網格 ───────────────────────────────────────────────────── */
.filter-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 15px;
  align-items: flex-end;
}

.quick-pills {
  display: flex;
  gap: 6px;
  margin-top: 6px;
}

.pill-btn {
  background: #edf2f7;
  border: 1px solid #e2e8f0;
  border-radius: 12px;
  padding: 3px 10px;
  font-size: 11px;
  font-weight: 600;
  color: #4a5568;
  cursor: pointer;
}

.pill-btn:hover, .pill-btn.active {
  background: var(--primary);
  border-color: var(--primary);
  color: #fff;
}

/* ─── 紀錄勾選清單 ───────────────────────────────────────────────────── */
.list-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 20px;
  background: #f1f5f9;
  border-radius: var(--radius);
  margin-bottom: 15px;
}

.selection-info {
  font-size: 14px;
  font-weight: 700;
  color: var(--primary-dark);
}

.list-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}

.list-table th {
  background: #fafbfc;
  padding: 12px 14px;
  font-weight: 700;
  text-align: left;
  border-bottom: 1px solid var(--border-color);
  color: #4b5563;
}

.list-table td {
  padding: 12px 14px;
  border-bottom: 1px solid #f0f2f5;
  vertical-align: middle;
}

.list-table tr:hover {
  background: #f8fafc;
}

/* ─── A5 病歷紙官方標準像素級排版 (A5 橫向 210mm × 148mm) ────────────────────────── */
.a5-container {
  display: flex;
  flex-direction: column;
  gap: 35px;
  align-items: center;
  padding: 20px 0;
}

.a5-sheet-wrapper {
  display: flex;
  flex-direction: column;
  gap: 8px;
  align-items: center;
}

.a5-top-controls {
  width: 210mm;
  display: flex;
  justify-content: space-between;
  align-items: center;
  background: #f8fafc;
  border: 1px solid #cbd5e1;
  border-radius: 6px;
  padding: 7px 14px;
  box-sizing: border-box;
}

.a5-top-controls .page-tag {
  font-size: 13px;
  font-weight: 700;
  color: #334155;
  display: flex;
  align-items: center;
  gap: 8px;
}

.a5-sheet {
  background: #ffffff;
  width: 210mm;
  height: 148mm;
  max-height: 148mm;
  padding: 8mm 12mm 6mm 12mm;
  border: 1px solid #cfd8dc;
  box-shadow: var(--shadow-md);
  font-family: "Microsoft JhengHei", "PingFang TC", "Helvetica Neue", sans-serif;
  color: #000000;
  position: relative;
  box-sizing: border-box;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  overflow: hidden;
  background-color: #fff;
}

/* 1. 頁首三欄式排版 (Logo / 抬頭 / 個案資訊) */
.a5-official-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  border-bottom: 1.5px solid #000;
  padding-bottom: 4px;
  margin-bottom: 4px;
}

.a5-header-logo {
  width: 120px;
  display: flex;
  align-items: center;
}

.a5-header-logo img {
  height: 38px;
  object-fit: contain;
}

.a5-header-center {
  flex: 1;
  text-align: center;
}

.a5-official-title {
  font-size: 14pt;
  font-weight: 800;
  letter-spacing: 0.5px;
  color: #000000;
  line-height: 1.2;
}

.a5-official-sub {
  font-size: 7.8pt;
  font-family: "Times New Roman", "Georgia", serif;
  color: #333333;
  line-height: 1.2;
  margin-top: 2px;
}

.a5-header-meta {
  width: 140px;
  text-align: left;
  font-size: 9.5pt;
  font-weight: 700;
  line-height: 1.4;
  color: #000;
}

.a5-editable-inline {
  border-bottom: 1px dashed #999;
  padding: 0 4px;
  min-width: 50px;
  outline: none;
  font-weight: 700;
}

.a5-editable-inline:focus {
  border-bottom: 2px solid var(--primary);
  background: #fffde7;
}

/* 2. 處遇項目標題行 */
.a5-section-title-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 8.8pt;
  font-weight: 800;
  margin-bottom: 2px;
}

.a5-sec-title {
  font-size: 9pt;
  font-weight: 800;
  color: #000;
}

.a5-tele-label {
  font-size: 8pt;
  font-weight: normal;
  color: #222;
}

/* 3. 處遇清單 (9大項) */
.a5-interventions-list {
  display: flex;
  flex-direction: column;
  gap: 1.5px;
  font-size: 7.5pt;
  line-height: 1.2;
  border-bottom: 1px solid #000;
  padding-bottom: 4px;
  margin-bottom: 4px;
}

.a5-int-item {
  display: flex;
  align-items: center;
  gap: 5px;
  cursor: pointer;
  user-select: none;
}

.a5-int-item input[type="checkbox"] {
  margin: 0;
  cursor: pointer;
  accent-color: #000;
  width: 11px;
  height: 11px;
}

.a5-int-title {
  font-size: 7.6pt;
  font-weight: 600;
  color: #000;
}

.a5-en {
  font-size: 6.8pt;
  color: #444;
  font-family: "Calibri", "Arial", sans-serif;
  margin-left: 2px;
}

.a5-referral-tag {
  font-size: 6.8pt;
  color: #666;
  white-space: nowrap;
  margin-right: 4px;
}

/* 4. 處遇計畫與建議 */
.a5-treatment-header-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 3px;
}

.a5-treatment-note {
  font-size: 7pt;
  color: #888;
}

.a5-char-badge {
  font-size: 7pt;
  padding: 1px 6px;
  border-radius: 10px;
  font-weight: 700;
}

.char-ok { background: #d4edda; color: #155724; }
.char-warn { background: #fff3cd; color: #856404; }
.char-danger { background: #f8d7da; color: #721c24; }

.a5-treatment-content-area {
  flex: 1;
  min-height: 48mm;
  max-height: 52mm;
  font-size: 9.5pt;
  line-height: 1.45;
  text-align: justify;
  outline: none;
  overflow-y: auto;
  white-space: pre-wrap;
  word-break: break-all;
  color: #111;
  padding: 2px 0;
}

.a5-treatment-content-area:focus {
  background: #fffff8;
  outline: 1px dashed var(--primary);
}

/* 5. 頁尾右側簽章與日期 */
.a5-official-footer {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  font-size: 8.8pt;
  line-height: 1.4;
  margin-top: 2px;
}

.a5-footer-item {
  display: flex;
  align-items: center;
  gap: 4px;
}

.a5-bottom-dotted-line {
  border-bottom: 1px dotted #ccc;
  margin-top: 3px;
}

/* ─── Modal 彈窗 ─────────────────────────────────────────────────────── */
.modal-overlay {
  position: fixed;
  top: 0; left: 0; right: 0; bottom: 0;
  background: rgba(0, 0, 0, 0.5);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
  backdrop-filter: blur(2px);
}

.modal-card {
  background: #ffffff;
  border-radius: 12px;
  width: 100%;
  max-width: 520px;
  box-shadow: var(--shadow-lg);
  overflow: hidden;
  animation: fadeIn 0.3s ease;
}

.modal-header {
  padding: 16px 20px;
  border-bottom: 1px solid var(--border-color);
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-size: 16px;
  font-weight: 700;
  color: var(--primary-dark);
}

.modal-body {
  padding: 20px;
}

.modal-footer {
  padding: 14px 20px;
  background: #f8fafc;
  border-top: 1px solid var(--border-color);
  display: flex;
  justify-content: flex-end;
  gap: 10px;
}

/* ─── 列印樣式 (標準 A5 橫向) ────────────────────────────────────────── */
@media print {
  @page {
    size: A5 landscape;
    margin: 0;
  }
  
  html, body {
    background: #ffffff !important;
    padding: 0 !important;
    margin: 0 !important;
    width: 210mm !important;
    height: 148mm !important;
  }

  .no-print, .navbar, .nav-tabs, .card-header, .login-container, .a5-top-controls, .list-toolbar {
    display: none !important;
  }

  .main-content, .card {
    max-width: 100% !important;
    margin: 0 !important;
    padding: 0 !important;
    border: none !important;
    box-shadow: none !important;
  }

  .a5-container, .a5-sheet-wrapper {
    padding: 0 !important;
    margin: 0 !important;
    gap: 0 !important;
    display: block !important;
  }

  .a5-sheet {
    border: none !important;
    box-shadow: none !important;
    width: 210mm !important;
    height: 148mm !important;
    max-height: 148mm !important;
    padding: 8mm 12mm 6mm 12mm !important;
    margin: 0 !important;
    page-break-after: always !important;
    break-after: page !important;
    overflow: hidden !important;
  }

  .a5-editable-inline {
    border-bottom: none !important;
  }

  .a5-treatment-content-area {
    overflow: hidden !important;
  }
}

@keyframes fadeIn {
  from { opacity: 0; transform: translateY(10px); }
  to { opacity: 1; transform: translateY(0); }
}
