/* 
 * Stylesheet for EMS Report Generator
 * ศูนย์กู้ชีพพันท้ายนรสิงห์ - สมุทรสาคร
 */

:root {
  --primary: #c9182b;
  --primary-dark: #9e1020;
  --primary-light: #ffebed;
  --secondary: #0a3d62;
  --secondary-dark: #07253b;
  --accent: #2e86de;
  --success: #10b981;
  --success-dark: #059669;
  --warning: #f59e0b;
  --danger: #ef4444;
  --bg-app: #f1f5f9;
  --card-bg: #ffffff;
  --text-main: #1e293b;
  --text-muted: #64748b;
  --border: #e2e8f0;
  --radius-sm: 6px;
  --radius-md: 10px;
  --radius-lg: 14px;
  --shadow-sm: 0 1px 3px rgba(0,0,0,0.05);
  --shadow-md: 0 4px 6px -1px rgba(0,0,0,0.07), 0 2px 4px -2px rgba(0,0,0,0.07);
  --shadow-lg: 0 10px 25px -5px rgba(0,0,0,0.1), 0 8px 10px -6px rgba(0,0,0,0.1);
  --font-thai: 'Sarabun', -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  --font-display: 'Prompt', var(--font-thai);
  --font-doc: 'Angsana New', 'AngsanaUPC', 'TH Sarabun New', 'TH Sarabun PSK', 'Sarabun', sans-serif;
}

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

body {
  font-family: var(--font-thai);
  background-color: var(--bg-app);
  color: var(--text-main);
  line-height: 1.5;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

/* ==============================================================
   Top Navigation Bar
   ============================================================== */
.app-navbar {
  background: linear-gradient(135deg, var(--secondary-dark) 0%, #1a2a3a 100%);
  color: #ffffff;
  padding: 12px 24px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  box-shadow: 0 2px 8px rgba(0,0,0,0.15);
  position: sticky;
  top: 0;
  z-index: 100;
  flex-wrap: wrap;
  gap: 12px;
}

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

.brand-badge {
  background: var(--primary);
  color: #fff;
  padding: 6px 12px;
  border-radius: var(--radius-md);
  font-family: var(--font-display);
  font-weight: 700;
  font-size: 16px;
  box-shadow: 0 2px 6px rgba(201, 24, 43, 0.4);
}

.brand-text h1 {
  font-family: var(--font-display);
  font-size: 18px;
  font-weight: 700;
  letter-spacing: 0.3px;
}

.brand-text p {
  font-size: 12px;
  color: #94a3b8;
}

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

/* Button Styles */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 8px 16px;
  font-family: var(--font-thai);
  font-size: 14px;
  font-weight: 600;
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: all 0.2s ease;
  border: 1px solid transparent;
  text-decoration: none;
}

.btn-primary {
  background: linear-gradient(135deg, #10b981 0%, #059669 100%);
  color: white;
  box-shadow: 0 2px 4px rgba(16, 185, 129, 0.3);
}

.btn-primary:hover {
  background: linear-gradient(135deg, #059669 0%, #047857 100%);
  transform: translateY(-1px);
  box-shadow: 0 4px 8px rgba(16, 185, 129, 0.4);
}

.btn-secondary {
  background: #334155;
  color: #f8fafc;
}

.btn-secondary:hover {
  background: #475569;
}

.btn-outline {
  background: transparent;
  color: #e2e8f0;
  border-color: #475569;
}

.btn-outline:hover {
  background: rgba(255, 255, 255, 0.1);
  color: white;
}

.btn-sm {
  padding: 4px 10px;
  font-size: 12px;
  font-weight: 600;
  border-radius: var(--radius-sm);
  cursor: pointer;
  border: 1px solid var(--border);
  background: #f8fafc;
  color: var(--text-main);
  transition: all 0.15s;
}

.btn-sm:hover {
  background: #e2e8f0;
}

.btn-danger {
  background: #fee2e2;
  color: #b91c1c;
  border-color: #fecaca;
}

.btn-danger:hover {
  background: #fecaca;
}

.btn-link {
  background: none;
  border: none;
  color: var(--accent);
  cursor: pointer;
  font-family: var(--font-thai);
  font-size: 13px;
  text-decoration: underline;
  padding: 0;
}

.btn-link:hover {
  color: var(--secondary);
}

.btn-icon-sm {
  width: 28px;
  height: 28px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: #fff;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  cursor: pointer;
  font-weight: bold;
}

.btn-icon-sm:hover {
  background: #f1f5f9;
}

/* ==============================================================
   Main App Layout
   ============================================================== */
.app-layout {
  display: flex;
  flex: 1;
  overflow: hidden;
  height: calc(100vh - 65px);
}

/* Left Panel: Form Input */
.form-container {
  width: 480px;
  background: var(--card-bg);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  box-shadow: 2px 0 8px rgba(0,0,0,0.03);
  flex-shrink: 0;
}

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

.form-header h2 {
  font-size: 16px;
  font-weight: 700;
  font-family: var(--font-display);
  color: var(--secondary-dark);
}

.badge-status {
  font-size: 11px;
  background: #dcfce7;
  color: #15803d;
  padding: 3px 8px;
  border-radius: 12px;
  font-weight: 600;
}

.form-scrollable {
  padding: 16px 20px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 16px;
}

/* Form Sections */
.form-section {
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 14px;
  background: #ffffff;
  transition: border-color 0.2s;
}

.form-section:focus-within {
  border-color: #93c5fd;
  box-shadow: 0 0 0 3px rgba(147, 197, 253, 0.15);
}

.form-section legend {
  font-weight: 700;
  font-size: 13.5px;
  color: var(--secondary);
  padding: 0 6px;
}

.section-title-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 8px;
}

.team-quick-actions {
  display: flex;
  gap: 8px;
}

.form-row {
  display: flex;
  gap: 10px;
}

.flex-1 { flex: 1; }
.flex-2 { flex: 2; }
.flex-3 { flex: 3; }

.form-grid-2 {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

.form-grid-5 {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 6px;
}

.form-group {
  display: flex;
  flex-direction: column;
  gap: 4px;
  margin-bottom: 8px;
}

.form-group:last-child {
  margin-bottom: 0;
}

.form-group label {
  font-size: 12px;
  font-weight: 600;
  color: var(--text-muted);
}

.form-group input[type="text"],
.form-group input[type="url"],
.form-group select,
.form-group textarea {
  width: 100%;
  padding: 7px 10px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  font-family: var(--font-thai);
  font-size: 13.5px;
  color: var(--text-main);
  background: #ffffff;
  transition: all 0.15s;
}

.form-group input:focus,
.form-group select:focus,
.form-group textarea:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 2px rgba(46, 134, 222, 0.2);
}

.input-with-btn {
  display: flex;
  gap: 6px;
}

.input-with-btn input {
  flex: 1;
}

.quick-tags {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
  margin-top: 6px;
}

.tag {
  font-size: 11px;
  background: #f1f5f9;
  color: #475569;
  padding: 2px 7px;
  border-radius: 4px;
  cursor: pointer;
  border: 1px solid #e2e8f0;
  transition: all 0.15s;
}

.tag:hover {
  background: #e0f2fe;
  color: #0369a1;
  border-color: #bae6fd;
}

/* Upload Dropzone */
.upload-dropzone {
  border: 2px dashed #cbd5e1;
  border-radius: var(--radius-md);
  padding: 16px;
  text-align: center;
  background: #f8fafc;
  cursor: pointer;
  transition: all 0.2s;
}

.upload-dropzone:hover,
.upload-dropzone.dragover {
  border-color: var(--accent);
  background: #eff6ff;
}

.dropzone-icon {
  font-size: 24px;
  margin-bottom: 4px;
}

.dropzone-content p {
  font-size: 13px;
  color: var(--text-main);
}

.dropzone-content span {
  font-size: 11px;
  color: var(--text-muted);
}

.photos-control-bar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-top: 10px;
  padding: 6px 8px;
  background: #f8fafc;
  border-radius: var(--radius-sm);
}

.layout-selector {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 12px;
}

.layout-selector select {
  padding: 3px 6px;
  font-size: 12px;
  border-radius: 4px;
  border: 1px solid var(--border);
}

.thumbnails-list {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 8px;
  margin-top: 10px;
}

.thumb-item {
  position: relative;
  aspect-ratio: 1;
  border-radius: var(--radius-sm);
  overflow: hidden;
  border: 1px solid var(--border);
}

.thumb-item img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.thumb-remove {
  position: absolute;
  top: 2px;
  right: 2px;
  background: rgba(220, 38, 38, 0.85);
  color: white;
  border: none;
  width: 18px;
  height: 18px;
  border-radius: 50%;
  font-size: 11px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
}

/* ==============================================================
   Right Panel: Document Preview & A4 Rendering
   ============================================================== */
.preview-container {
  flex: 1;
  display: flex;
  flex-direction: column;
  background: #e2e8f0;
  overflow: hidden;
}

.preview-toolbar {
  padding: 10px 20px;
  background: #ffffff;
  border-bottom: 1px solid var(--border);
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.toolbar-left {
  display: flex;
  align-items: center;
  gap: 12px;
}

.preview-title {
  font-size: 13.5px;
  font-weight: 700;
  color: var(--secondary);
}

.edit-hint-pill {
  font-size: 11.5px;
  background: #ecfdf5;
  color: #065f46;
  border: 1px solid #a7f3d0;
  padding: 3px 9px;
  border-radius: 12px;
  font-weight: 500;
  display: inline-flex;
  align-items: center;
  gap: 4px;
}

.zoom-controls {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 12px;
  font-weight: 600;
  color: var(--text-muted);
}

.sheet-viewport {
  flex: 1;
  overflow: auto;
  padding: 30px;
  display: flex;
  justify-content: center;
  align-items: flex-start;
}

/* A4 Sheet Dimensions (Standard Proportion 210mm x 297mm) */
.a4-sheet {
  width: 794px;
  height: 1123px;
  position: relative;
  background: #ffffff;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.15), 0 1px 3px rgba(0, 0, 0, 0.08);
  transform-origin: top center;
  flex-shrink: 0;
  overflow: hidden;
  user-select: none;
  image-rendering: -webkit-optimize-contrast;
  image-rendering: crisp-edges;
  text-rendering: optimizeLegibility;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

/* Clean Background Template (Contains logos, headers, cartoons, corner art) */
.sheet-background {
  position: absolute;
  inset: 0;
  background-image: url('assets/template_clean.png');
  background-repeat: no-repeat;
  background-position: center top;
  background-size: 100% 100%;
  pointer-events: none;
  z-index: 1;
}

/* Document Header Center (Editable Titles + Date) */
.sheet-header-center {
  position: absolute;
  left: 134px;
  top: 66px;
  width: 526px;
  height: 214px;
  background: #ffffff;
  z-index: 4;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  padding: 4px 10px;
  box-sizing: border-box;
}

.header-title-1 {
  font-family: var(--font-doc);
  font-size: 26px;
  font-weight: 700;
  color: #0a3d62;
  letter-spacing: 0.2px;
  line-height: 1.22;
  margin-bottom: 1px;
  width: 100%;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.header-title-2 {
  font-family: var(--font-doc);
  font-size: 22.5px;
  font-weight: 700;
  color: #0a3d62;
  line-height: 1.22;
  margin-bottom: 1px;
  width: 100%;
}

.header-title-3 {
  font-family: var(--font-doc);
  font-size: 18.5px;
  font-weight: 400;
  color: #1e293b;
  line-height: 1.22;
  margin-bottom: 6px;
  width: 100%;
}

.sheet-date {
  font-family: var(--font-doc);
  font-size: 21px;
  font-weight: 700;
  color: #000000;
  line-height: 1.22;
  width: 100%;
}

.header-title-1[contenteditable="true"],
.header-title-2[contenteditable="true"],
.header-title-3[contenteditable="true"],
.sheet-date[contenteditable="true"],
.sheet-bubble-motto[contenteditable="true"] {
  outline: none;
  cursor: text;
  border-radius: 4px;
  padding: 1px 4px;
  transition: background 0.15s, box-shadow 0.15s;
}

.header-title-1[contenteditable="true"]:hover,
.header-title-2[contenteditable="true"]:hover,
.header-title-3[contenteditable="true"]:hover,
.sheet-date[contenteditable="true"]:hover,
.sheet-bubble-motto[contenteditable="true"]:hover {
  background: rgba(2, 132, 199, 0.06);
}

.header-title-1[contenteditable="true"]:focus,
.header-title-2[contenteditable="true"]:focus,
.header-title-3[contenteditable="true"]:focus,
.sheet-date[contenteditable="true"]:focus,
.sheet-bubble-motto[contenteditable="true"]:focus {
  background: rgba(2, 132, 199, 0.1);
  box-shadow: 0 0 0 1px rgba(2, 132, 199, 0.4);
}

/* Logos (Customizable Left & Right) */
.sheet-logo-container {
  position: absolute;
  top: 57px;
  width: 127px;
  height: 127px;
  border-radius: 50%;
  overflow: hidden;
  z-index: 10;
  cursor: pointer;
  background: #ffffff;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.1);
  transition: transform 0.15s ease, box-shadow 0.15s ease;
}

.sheet-logo-container:hover {
  transform: scale(1.02);
  box-shadow: 0 4px 12px rgba(2, 132, 199, 0.25);
}

.sheet-logo-container.logo-left {
  left: 21px;
}

.sheet-logo-container.logo-right {
  right: 21px;
}

.sheet-logo-container img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

.logo-change-overlay {
  position: absolute;
  inset: 0;
  background: rgba(10, 61, 98, 0.78);
  color: #ffffff;
  font-family: var(--font-doc);
  font-size: 15px;
  font-weight: 700;
  display: flex;
  align-items: center;
  justify-content: center;
  opacity: 0;
  transition: opacity 0.2s ease;
  pointer-events: none;
  text-align: center;
}

.sheet-logo-container:hover .logo-change-overlay {
  opacity: 1;
}

/* Cartoon Speech Bubble Motto */
.sheet-bubble-motto {
  position: absolute;
  left: 48px;
  top: 736px;
  width: 140px;
  text-align: center;
  font-family: var(--font-doc);
  font-size: 16.5px;
  font-weight: 700;
  line-height: 1.25;
  color: #1e293b;
  z-index: 6;
  background: transparent;
  word-break: break-word;
}

/* Incident Photos Container (Middle Blank Area) */
.sheet-photos-area {
  position: absolute;
  top: 295px;
  left: 60px;
  right: 60px;
  height: 460px;
  z-index: 2;
  display: flex;
  flex-direction: column;
}

.photos-placeholder {
  width: 100%;
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
}

.placeholder-box {
  width: 95%;
  height: 90%;
  border: 2px dashed #e2e8f0;
  border-radius: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  color: #94a3b8;
  font-size: 16px;
  background: rgba(255, 255, 255, 0.6);
}

.photos-grid {
  width: 100%;
  height: 100%;
  display: grid;
  gap: 8px;
}

/* Photo Grid Layouts */
.photos-grid.layout-single {
  grid-template-columns: 1fr;
}

.photos-grid.layout-cols2 {
  grid-template-columns: 1fr 1fr;
}

.photos-grid.layout-cols3 {
  grid-template-columns: 1fr 1fr;
  grid-template-rows: 1fr 1fr;
}
.photos-grid.layout-cols3 .photo-card:first-child {
  grid-column: span 2;
}

.photos-grid.layout-grid2x2 {
  grid-template-columns: 1fr 1fr;
  grid-template-rows: 1fr 1fr;
}

.photo-card {
  width: 100%;
  height: 100%;
  border-radius: 6px;
  overflow: hidden;
  background: #f8fafc;
  border: 1px solid #cbd5e1;
  box-shadow: 0 1px 3px rgba(0,0,0,0.05);
  position: relative;
  user-select: none;
  touch-action: none;
}

.photo-card img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
  pointer-events: none;
}

/* Photo Drag Resizing Handles */
.photo-resize-handle {
  position: absolute;
  width: 24px;
  height: 24px;
  background: #0284c7;
  color: #ffffff;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 13px;
  font-weight: 700;
  z-index: 25;
  opacity: 0.82;
  transition: opacity 0.15s, background 0.15s, transform 0.15s;
  box-shadow: 0 1px 4px rgba(0,0,0,0.3);
  touch-action: none;
  user-select: none;
}

.photo-resize-handle.br {
  right: 0;
  bottom: 0;
  border-top-left-radius: 6px;
  cursor: nwse-resize;
}

.photo-resize-handle.bl {
  left: 0;
  bottom: 0;
  border-top-right-radius: 6px;
  cursor: nesw-resize;
}

.photo-resize-handle:hover {
  opacity: 1;
  background: #0369a1;
  transform: scale(1.15);
}

.photo-card.resizing {
  box-shadow: 0 0 0 2px #0284c7 !important;
}

.photos-grid.layout-custom {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  align-items: center;
  align-content: center;
  gap: 8px;
  height: 100%;
  overflow: hidden;
}

/* Photo sizing actions in left sidebar */
.photo-size-actions {
  display: flex;
  align-items: center;
  gap: 4px;
}

.photo-drag-hint {
  font-size: 11.5px;
  color: #0369a1;
  background: #e0f2fe;
  padding: 6px 10px;
  border-radius: 6px;
  margin-top: 8px;
  line-height: 1.45;
  border: 1px solid #bae6fd;
}

/* Sidebar Logo Upload Card */
.highlight-header-section {
  border-color: #f59e0b !important;
  background: #fffbeb !important;
}

.highlight-header-section legend {
  color: #b45309 !important;
  font-weight: 700 !important;
}

.logo-upload-card {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.logo-upload-card label {
  font-size: 12px;
  font-weight: 600;
  color: #78350f;
}

.logo-preview-box {
  display: flex;
  align-items: center;
  gap: 8px;
}

.logo-preview-box img {
  width: 44px;
  height: 44px;
  border-radius: 50%;
  object-fit: cover;
  border: 2px solid #e2e8f0;
  background: #ffffff;
  flex-shrink: 0;
}

.logo-btn-group {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.logo-btn-group .btn-link {
  font-size: 11px;
  text-decoration: underline;
  cursor: pointer;
  background: none;
  border: none;
  padding: 0;
  color: #64748b;
  text-align: left;
}

.logo-btn-group .btn-link:hover {
  color: #dc2626;
}

/* Body dragging state */
body.is-resizing-photo {
  cursor: nwse-resize !important;
  user-select: none !important;
}

/* Hide handles on export canvas */
.exporting-canvas .photo-resize-handle,
.exporting-canvas .logo-change-overlay,
.exporting-canvas .edit-hint-pill {
  display: none !important;
  opacity: 0 !important;
  visibility: hidden !important;
}

/* Bottom Report Text Box - Perfectly fitted inside the blue rectangle */
.sheet-report-box {
  position: absolute;
  left: 192px;
  top: 752px;
  width: 568px;
  height: 308px;
  border: none;
  background: transparent;
  padding: 6px 14px 10px 14px;
  z-index: 5;
  box-sizing: border-box;
  overflow: hidden;
}

.box-siren-icon {
  display: none !important;
}

.box-content {
  display: flex;
  flex-direction: column;
  gap: 2px;
  font-family: var(--font-doc);
  color: #000000;
  font-size: var(--box-font-size, 19.5px);
  line-height: 1.38;
}

.box-line.is-bold {
  font-weight: 700 !important;
}

.box-line.is-normal {
  font-weight: 400 !important;
}

/* Formatting toolbar in Section Dotted Lines */
.formatting-toolbar {
  background: #ffffff;
  border: 1px solid #bae6fd;
  border-radius: 8px;
  padding: 10px 12px;
  margin-bottom: 12px;
  box-shadow: 0 1px 3px rgba(2, 132, 199, 0.08);
}

.format-toolbar-row {
  display: flex;
  gap: 12px;
  flex-wrap: wrap;
}

.format-item {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.format-item label {
  font-size: 12px;
  color: #0369a1;
}

.font-size-controls {
  display: flex;
  align-items: center;
  gap: 6px;
}

.font-size-controls input[type="range"] {
  flex: 1;
  min-width: 80px;
  cursor: pointer;
  accent-color: #0284c7;
}

.font-size-badge {
  background: #0284c7;
  color: #ffffff;
  font-size: 11.5px;
  font-weight: 700;
  padding: 3px 7px;
  border-radius: 10px;
  min-width: 48px;
  text-align: center;
}

.bold-actions-group {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
}

.line-edit-group {
  margin-bottom: 8px;
}

.line-edit-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 3px;
}

.line-edit-header label {
  margin-bottom: 0;
  font-size: 12.5px;
}

.btn-bold-toggle {
  display: inline-flex;
  align-items: center;
  gap: 3px;
  padding: 2px 7px;
  font-size: 11.5px;
  font-family: var(--font-thai);
  font-weight: 600;
  border: 1px solid #cbd5e1;
  border-radius: 4px;
  background: #ffffff;
  color: #475569;
  cursor: pointer;
  transition: all 0.15s ease;
}

.btn-bold-toggle:hover {
  background: #f1f5f9;
  border-color: #94a3b8;
  color: #1e293b;
}

.btn-bold-toggle.active {
  background: #0284c7;
  border-color: #0284c7;
  color: #ffffff;
  box-shadow: 0 1px 3px rgba(2, 132, 199, 0.3);
}

.font-mono-th.is-bold {
  font-weight: 700 !important;
}

.box-line {
  white-space: normal;
  word-break: break-word;
}

/* In-place Editable Dotted Lines */
.box-line[contenteditable="true"] {
  outline: none;
  cursor: text;
  border-radius: 3px;
  padding: 1px 3px;
  margin-left: -3px;
  transition: background 0.15s, box-shadow 0.15s;
}

.box-line[contenteditable="true"]:hover {
  background: rgba(2, 132, 199, 0.05);
}

.box-line[contenteditable="true"]:focus {
  background: rgba(2, 132, 199, 0.09);
  box-shadow: 0 0 0 1px rgba(2, 132, 199, 0.35);
}

.line-1, .line-2, .line-3, .line-4 {
  letter-spacing: -0.2px;
}

.line-4 {
  max-width: 480px;
}

.line-team-title {
  font-weight: 700;
  margin-top: 3px;
  max-width: 350px;
}

.line-member {
  padding-left: 2px;
  max-width: 350px;
}

/* Highlight section in left form */
.highlight-section {
  border-color: #38bdf8 !important;
  background: #f0f9ff !important;
}

.highlight-section legend {
  color: #0284c7 !important;
  font-weight: 700 !important;
}

.section-desc {
  font-size: 12px;
  color: #0369a1;
  margin-bottom: 10px;
  line-height: 1.45;
}

.font-mono-th {
  font-family: var(--font-doc), monospace, sans-serif !important;
  font-size: 14.5px !important;
  letter-spacing: -0.2px;
}

/* ==============================================================
   Modals & Overlays
   ============================================================== */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, 0.65);
  backdrop-filter: blur(4px);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
  padding: 16px;
}

.nav-badge {
  background: var(--primary);
  color: #ffffff;
  font-size: 11px;
  font-weight: 700;
  padding: 2px 7px;
  border-radius: 10px;
  margin-left: 6px;
  min-width: 18px;
  text-align: center;
  display: inline-block;
}

.modal-large {
  max-width: 880px;
  width: 95%;
  max-height: 90vh;
  display: flex;
  flex-direction: column;
}

.modal-title-with-badge {
  display: flex;
  align-items: center;
  gap: 10px;
}

.badge-count {
  font-size: 12px;
  background: #e0f2fe;
  color: #0369a1;
  font-weight: 600;
  padding: 3px 8px;
  border-radius: 12px;
}

.history-modal-body {
  overflow-y: auto;
  padding: 16px 20px;
  max-height: calc(88vh - 120px);
}

.history-toolbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  margin-bottom: 14px;
}

.search-box {
  display: flex;
  align-items: center;
  position: relative;
  flex: 1;
}

.search-box .search-icon {
  position: absolute;
  left: 10px;
  font-size: 14px;
  color: var(--text-muted);
}

.search-box input {
  width: 100%;
  padding: 8px 10px 8px 32px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  font-size: 13px;
  font-family: var(--font-thai);
}

.history-empty {
  text-align: center;
  padding: 40px 20px;
  color: var(--text-muted);
}

.history-empty .empty-icon {
  font-size: 48px;
  margin-bottom: 12px;
}

.history-empty h4 {
  font-size: 16px;
  font-weight: 700;
  color: var(--text-main);
  margin-bottom: 6px;
}

.history-empty p {
  font-size: 13.5px;
  max-width: 500px;
  margin: 0 auto;
  line-height: 1.5;
}

.history-items-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(380px, 1fr));
  gap: 14px;
}

.history-card {
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 12px;
  background: #ffffff;
  display: flex;
  gap: 12px;
  transition: all 0.2s;
  box-shadow: 0 1px 3px rgba(0,0,0,0.05);
}

.history-card:hover {
  border-color: var(--accent);
  box-shadow: 0 4px 12px rgba(0,0,0,0.08);
  transform: translateY(-2px);
}

.history-card-thumb {
  width: 90px;
  height: 127px;
  background: #f1f5f9;
  border-radius: 4px;
  overflow: hidden;
  border: 1px solid #cbd5e1;
  flex-shrink: 0;
  cursor: pointer;
}

.history-card-thumb img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

.history-card-info {
  flex: 1;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  min-width: 0;
}

.history-card-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 6px;
  margin-bottom: 4px;
}

.history-card-title {
  font-size: 14px;
  font-weight: 700;
  color: var(--secondary-dark);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.history-card-date {
  font-size: 12px;
  color: var(--text-muted);
  margin-bottom: 4px;
}

.history-card-details {
  font-size: 12px;
  color: var(--text-main);
  line-height: 1.4;
  margin-bottom: 8px;
}

.history-card-details div {
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.history-card-tags {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
  margin-bottom: 8px;
}

.badge-als {
  font-size: 10.5px;
  font-weight: 700;
  background: #fef2f2;
  color: #b91c1c;
  padding: 1px 6px;
  border-radius: 4px;
  border: 1px solid #fecaca;
}

.badge-self {
  font-size: 10.5px;
  font-weight: 600;
  background: #f8fafc;
  color: #64748b;
  padding: 1px 6px;
  border-radius: 4px;
  border: 1px solid #e2e8f0;
}

.badge-drive {
  font-size: 10.5px;
  font-weight: 600;
  background: #ecfdf5;
  color: #047857;
  padding: 1px 6px;
  border-radius: 4px;
  border: 1px solid #a7f3d0;
}

.history-card-actions {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
}

.btn-card-action {
  font-size: 11.5px;
  padding: 4px 8px;
  border-radius: 4px;
  border: 1px solid var(--border);
  background: #ffffff;
  color: var(--text-main);
  cursor: pointer;
  transition: all 0.15s;
  display: inline-flex;
  align-items: center;
  gap: 4px;
  text-decoration: none;
}

.btn-card-action:hover {
  background: #f1f5f9;
  border-color: #94a3b8;
}

.btn-card-action.primary {
  background: #e0f2fe;
  color: #0369a1;
  border-color: #bae6fd;
}
.btn-card-action.primary:hover {
  background: #0284c7;
  color: #ffffff;
}

.btn-card-action.danger {
  color: #dc2626;
  border-color: #fecaca;
}
.btn-card-action.danger:hover {
  background: #dc2626;
  color: #ffffff;
}

.team-quick-presets {
  display: flex;
  gap: 6px;
  margin-bottom: 8px;
}

.btn-outline-primary {
  border: 1px solid #0284c7;
  color: #0284c7;
  background: transparent;
  padding: 3px 8px;
  border-radius: 4px;
  font-size: 11.5px;
  cursor: pointer;
}
.btn-outline-primary:hover {
  background: #0284c7;
  color: #fff;
}

.btn-outline-danger {
  border: 1px solid #ef4444;
  color: #ef4444;
  background: transparent;
  padding: 3px 8px;
  border-radius: 4px;
  font-size: 11.5px;
  cursor: pointer;
}
.btn-outline-danger:hover {
  background: #ef4444;
  color: #fff;
}

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

@keyframes modalPop {
  from { opacity: 0; transform: scale(0.95); }
  to { opacity: 1; transform: scale(1); }
}

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

.modal-header h3 {
  font-size: 16px;
  font-weight: 700;
  font-family: var(--font-display);
  color: var(--secondary-dark);
}

.btn-close {
  background: none;
  border: none;
  font-size: 22px;
  cursor: pointer;
  color: var(--text-muted);
  line-height: 1;
}

.btn-close:hover {
  color: var(--danger);
}

.modal-body {
  padding: 20px;
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.modal-desc {
  font-size: 13.5px;
  color: var(--text-muted);
  line-height: 1.5;
}

.helper-text {
  font-size: 11.5px;
  color: #64748b;
  line-height: 1.4;
}

.required {
  color: var(--danger);
}

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

.justify-center {
  justify-content: center;
}

/* Success Modal */
.modal-success .success-icon {
  font-size: 48px;
  margin-bottom: 8px;
}

.text-center {
  text-align: center;
}

.link-box {
  display: flex;
  gap: 6px;
  margin-top: 12px;
}

.link-box input {
  flex: 1;
  padding: 8px 10px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  font-size: 12px;
  background: #f8fafc;
}

/* Loading Overlay */
.loading-overlay {
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, 0.7);
  backdrop-filter: blur(4px);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 2000;
}

.loading-card {
  background: #ffffff;
  padding: 30px 40px;
  border-radius: var(--radius-lg);
  text-align: center;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
  box-shadow: var(--shadow-lg);
  max-width: 360px;
}

.spinner {
  width: 44px;
  height: 44px;
  border: 4px solid #e2e8f0;
  border-top-color: var(--primary);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

/* Toast */
.toast {
  position: fixed;
  bottom: 24px;
  right: 24px;
  background: #1e293b;
  color: #ffffff;
  padding: 12px 20px;
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-lg);
  font-size: 13.5px;
  font-weight: 500;
  display: none;
  z-index: 3000;
  animation: toastIn 0.25s ease-out;
}

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

/* ==============================================================
   Print Styles (Exact 1-Page A4)
   ============================================================== */
@media print {
  @page {
    size: A4 portrait;
    margin: 0;
  }
  
  html, body {
    margin: 0;
    padding: 0;
    width: 210mm;
    height: 297mm;
    background: #ffffff !important;
    overflow: hidden !important;
  }
  
  .no-print {
    display: none !important;
  }

  .app-layout {
    display: block;
    height: auto;
  }

  .preview-container {
    background: none;
    padding: 0;
    overflow: visible;
  }

  .sheet-viewport {
    padding: 0;
    overflow: visible;
  }

  .a4-sheet {
    box-shadow: none !important;
    width: 210mm !important;
    height: 297mm !important;
    transform: none !important;
    page-break-after: avoid;
    page-break-inside: avoid;
  }
}

/* ==============================================================
   Mobile / Responsive Layout
   ============================================================== */
@media (max-width: 1024px) {
  .app-layout {
    flex-direction: column;
    height: auto;
    overflow: visible;
  }

  .form-container {
    width: 100%;
    border-right: none;
    border-bottom: 1px solid var(--border);
  }

  .sheet-viewport {
    padding: 16px 8px;
  }
}
