/* Global Styles & Variables */
:root {
  /* Safe initial values (Dark Mode Default) */
  --bg-color: #1a1a1a;
  --text-color: #ffffff;
  --accent-color: #3b82f6;
  --accent-hover: #2563eb;
  --danger-color: #ef4444;
  --card-bg: #2d2d2d;
  --border-color: #404040;
  --header-gradient: linear-gradient(45deg, #60a5fa, #a78bfa);
}

/* Light Mode Overrides */
body.light-mode {
  --bg-color: #f3f4f6;
  --text-color: #111827;
  --accent-color: #2563eb;
  --accent-hover: #1d4ed8;
  --card-bg: #ffffff;
  --border-color: #d1d5db;
  --header-gradient: linear-gradient(45deg, #2563eb, #7c3aed);
}

body {
  font-family:
    "HYGraphic",
    "HY그래픽",
    "HYGraphicM",
    "Pretendard",
    -apple-system,
    sans-serif;
  margin: 0;
  padding: 0;
  background-color: var(--bg-color);
  color: var(--text-color);
  transition:
    background-color 0.3s,
    color 0.3s;
}

/* UI Container (Screen Only) */
.ui-container {
  max-width: 800px;
  margin: 0 auto;
  padding: 20px;
  text-align: center;
}

header {
  position: relative;
  margin-bottom: 2rem;
}

.logo-area {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 1rem;
  margin-bottom: 0.5rem;
}

.app-logo {
  width: 60px;
  height: 60px;
  object-fit: contain;
  border-radius: 12px;
  box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
}

header h1 {
  font-size: 2rem;
  margin: 0;
  /* Removing margin-bottom as parent handles gap */
  background: var(--header-gradient);
  -webkit-background-clip: text;
  background-clip: text;
  -webkit-text-fill-color: transparent;
}

header p {
  color: #9ca3af;
  margin-bottom: 1rem;
}

.support-info {
  font-size: 0.85rem;
  color: #60a5fa;
  background: rgba(59, 130, 246, 0.1);
  padding: 0.6rem 1rem;
  border-radius: 8px;
  margin: 0.5rem auto 1.5rem auto;
  display: inline-block;
  max-width: 90%;
  line-height: 1.5;
  border: 1px dashed rgba(59, 130, 246, 0.3);
}

body.light-mode .support-info {
  color: #2563eb;
  background: rgba(37, 99, 235, 0.05);
  border-color: rgba(37, 99, 235, 0.2);
}

/* Theme Toggle Button */
.theme-toggle {
  position: absolute;
  top: 0;
  right: 0;
  background: transparent;
  font-size: 1.5rem;
  padding: 0.5rem;
  color: var(--text-color);
  border: none;
  cursor: pointer;
}

.theme-toggle:hover {
  transform: rotate(15deg);
}

/* Actions Bar */
.actions {
  margin-bottom: 3rem;
  display: flex;
  justify-content: center;
  align-items: center;
  gap: 1rem;
  flex-wrap: wrap;
}

.config-bar {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  background: var(--card-bg);
  padding: 0.5rem 1rem;
  border-radius: 8px;
}

.desc-toggle-label {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  font-size: 0.9rem;
  cursor: pointer;
  padding: 0.5rem;
  border-radius: 4px;
  background: rgba(255, 255, 255, 0.05);
}

.desc-toggle-label input {
  width: 1.2rem;
  height: 1.2rem;
}

/* Buttons */
button {
  cursor: pointer;
  border: none;
  padding: 0.75rem 1.5rem;
  border-radius: 8px;
  font-size: 1rem;
  font-weight: 600;
  transition: all 0.2s;
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.btn-secondary {
  background: #4b5563;
  color: white;
}

.btn-secondary:hover {
  background: #374151;
}

.btn-danger {
  background: var(--danger-color);
  color: white;
}

/* Inputs */
input[type="date"] {
  padding: 0.4rem;
  border-radius: 4px;
  border: 1px solid var(--border-color);
  background: #404040;
  color: white;
}

/* Bulk Upload Zone */
.bulk-upload-area {
  margin: 20px auto 30px auto;
  max-width: 600px;
  border: 3px dashed var(--border-color);
  border-radius: 12px;
  padding: 2rem;
  cursor: pointer;
  transition: all 0.2s;
  background: rgba(255, 255, 255, 0.05);
}

.bulk-upload-area:hover,
.bulk-upload-area.drag-over {
  border-color: var(--accent-color);
  background: rgba(59, 130, 246, 0.1);
  transform: scale(1.02);
}

.drop-content {
  pointer-events: none;
  /* Let clicks pass to parent */
}

.drop-content .icon-large {
  font-size: 3rem;
  display: block;
  margin-bottom: 1rem;
}

.drop-content h3 {
  margin: 0.5rem 0;
  color: var(--accent-color);
}

.drop-content p {
  color: #9ca3af;
  margin: 0.2rem 0;
}

.drop-content .sub-text {
  font-size: 0.9rem;
  opacity: 0.8;
}

/* =========================================
   Print Preview & Slot Layout
   ========================================= */
.print-page {
  background: white;
  color: black;
  width: 210mm;
  min-height: 297mm;
  margin: 0 auto;
  padding: 10mm;
  box-sizing: border-box;
  box-shadow: 0 0 20px rgba(0, 0, 0, 0.5);
  position: relative;
  transform-origin: top center;
}

/* Header Section */
.doc-header {
  margin-bottom: 5mm;
  text-align: center;
}

/* Main Titile - "물품검수사진" */
.main-title {
  margin: 0 0 5mm 0;
  text-align: center;
  /* border-bottom removed */
  display: inline-block;
  padding-bottom: 2px;
}

.editable-title {
  font-family: "HYGraphic", "HY그래픽", "HYGraphicM", "Batang", serif;
  /* Changed to HYGraphic */
  font-size: 24pt;
  font-weight: bold;
  border: none;
  text-align: center;
  width: 300px;
  background: transparent;
}

.info-table {
  width: 100%;
  border-collapse: collapse;
  margin-top: 5px;
}

.info-table td {
  border: 1px solid black;
  padding: 5px;
}

.info-table .label {
  background-color: #e5e7eb;
  width: 80px;
  text-align: center;
  font-weight: bold;
  white-space: nowrap;
  text-align-last: justify;
}

.info-table .input-cell input {
  width: 100%;
  border: none;
  font-size: 1rem;
  outline: none;
  font-family: inherit;
}

/* Grid */
.photo-grid {
  display: grid;
  /* Default (Layout 6) */
  grid-template-columns: 1fr 1fr;
  grid-template-rows: repeat(3, 1fr);
  height: 190mm;
  border: 1px solid black;
}

/* Dynamic Layouts */
.photo-grid.layout-1 {
  grid-template-columns: 1fr;
  grid-template-rows: 1fr;
}

.photo-grid.layout-2 {
  grid-template-columns: 1fr;
  grid-template-rows: 1fr 1fr;
}

.photo-grid.layout-4 {
  grid-template-columns: 1fr 1fr;
  grid-template-rows: 1fr 1fr;
}

.grid-slot {
  border: 1px solid black;
  position: relative;
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  overflow: hidden;
  padding: 2mm;
  transition:
    background-color 0.2s,
    border-color 0.2s;
}

.grid-slot.empty {
  background-color: #f9fafb;
  /* Light gray on print prev */
}

/* Drag Over State */
.grid-slot.drag-over {
  background-color: #e0f2fe !important;
  border: 3px dashed var(--accent-color) !important;
}

/* Upload Button inside Slot */
.slot-upload-btn {
  background: white;
  border: 2px dashed #9ca3af;
  color: #4b5563;
  width: 80%;
  height: 60%;
  justify-content: center;
  flex-direction: column;
  font-size: 1.2rem;
  cursor: pointer;
}

.slot-upload-btn:hover {
  border-color: var(--accent-color);
  color: var(--accent-color);
  background: #f0f9ff;
}

/* Slot Content */
.grid-slot img {
  max-width: 100%;
  max-height: 70%; /* Reduced to make room for description */
  object-fit: contain;
  display: block;
  margin-bottom: 2mm;
}

.slot-description-container {
  width: 100%;
  flex-grow: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  margin-bottom: 5mm; /* Space for date */
}

.slot-description-editor {
  width: 100%;
  height: 50px;
  min-height: 50px;
  max-height: 80px;
  resize: vertical;
  background: var(--card-bg);
  color: var(--text-color);
  border: 1px solid var(--border-color);
  border-radius: 4px;
  padding: 5px;
  font-size: 0.85rem;
  font-family: inherit;
  margin-bottom: 5px;
}

.slot-description-view {
  font-size: 10pt;
  line-height: 1.4;
  overflow-y: auto;
  text-align: left;
  padding: 0 5px;
}

.slot-description-view p {
  margin: 0 0 0.5em 0;
}

.slot-description-view ul, .slot-description-view ol {
  margin: 0;
  padding-left: 1.2em;
}

/* Hide editor on print */
@media print {
  .slot-description-editor {
    display: none !important;
  }
}

/* Toggle logic */
body.hide-descriptions .slot-description-container {
  display: none !important;
}

body.hide-descriptions .grid-slot img {
  max-height: 90%;
}

/* Individual No-Description Toggle */
.grid-slot.no-description .slot-description-container {
  display: none !important;
}

.grid-slot.no-description img {
  max-height: 90% !important;
}

/* Scrollbar styling for description view */
.slot-description-view::-webkit-scrollbar {
  width: 4px;
}

.slot-description-view::-webkit-scrollbar-thumb {
  background: var(--border-color);
  border-radius: 2px;
}

.slot-description-view::-webkit-scrollbar-track {
  background: transparent;
}

/* Fix for marked.js rendering */
.slot-description-view h1, .slot-description-view h2, .slot-description-view h3 {
  font-size: 1.1em;
  margin: 0.5em 0 0.2em 0;
}

.slot-description-view blockquote {
  border-left: 3px solid var(--accent-color);
  margin: 0;
  padding-left: 10px;
  color: #6b7280;
}

body.light-mode .slot-description-view blockquote {
  color: #4b5563;
}

.slot-date-input {
  position: absolute;
  bottom: 2mm;
  right: 2mm;
  font-size: 10pt;
  padding: 2px;
  background: rgba(255, 255, 255, 0.9);
  border: none;
  text-align: right;
  width: 120px;
  color: black;
  /* Always black for print */
  font-family: inherit;
}

/* Photo Hover Actions */
.photo-actions {
  position: absolute;
  top: 5px;
  right: 5px;
  display: flex;
  gap: 5px;
  opacity: 0;
  transition: opacity 0.2s;
  background: rgba(0, 0, 0, 0.6);
  border-radius: 4px;
  padding: 4px;
  z-index: 10;
}

.grid-slot:hover .photo-actions {
  opacity: 1;
}

.action-btn {
  background: transparent;
  border: 1px solid rgba(255, 255, 255, 0.3);
  color: white;
  font-size: 1.2rem;
  cursor: pointer;
  padding: 4px 8px;
  border-radius: 4px;
}

.action-btn:hover {
  background: rgba(255, 255, 255, 0.2);
  color: var(--accent-color);
}

/* Mobile Scaling for Preview */
@media screen and (max-width: 850px) {
  .print-page {
    transform: scale(0.45);
    margin-bottom: -150mm;
  }

  .photo-actions {
    opacity: 1;
    background: rgba(0, 0, 0, 0.4);
  }
}

@media screen and (max-width: 450px) {
  .print-page {
    transform: scale(0.32);
    margin-bottom: -200mm;
  }
}

/* Print Styles */
@media print {
  @page {
    size: A4;
    /* Top 20, Right 20, Bottom 5, Left 20 */
    margin: 20mm 20mm 5mm 20mm;
  }

  body {
    margin: 0;
    background: white;
    -webkit-print-color-adjust: exact;
    print-color-adjust: exact;
  }

  .ui-container,
  .no-print,
  .photo-actions,
  .slot-upload-btn {
    display: none !important;
  }

  .print-page {
    margin: 0;
    width: 100%;
    height: auto;
    /* Changed from 100vh */
    min-height: 0;
    /* Override screen style */
    box-shadow: none;
    border: none;
    transform: none !important;
    page-break-after: always;
    break-after: page;
  }

  /* Don't break after the last page to avoid empty sheet */
  .print-page:last-child {
    page-break-after: auto;
    break-after: auto;
  }

  .info-table .label {
    background-color: #e5e7eb !important;
  }

  .grid-slot.empty::after {
    content: "";
  }

  input {
    background: transparent !important;
  }

  .slot-date-input {
    display: none !important;
  }
}

/* =========================================
   Modal Styles
   ========================================= */
.modal-overlay {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(0, 0, 0, 0.7);
  display: flex;
  justify-content: center;
  align-items: center;
  z-index: 1000;
  backdrop-filter: blur(4px);
  opacity: 1;
  transition: opacity 0.3s;
}

.modal-overlay.hidden {
  opacity: 0;
  pointer-events: none;
}

.modal-content {
  background: var(--card-bg);
  color: var(--text-color);
  width: 90%;
  max-width: 600px;
  max-height: 85vh;
  padding: 2rem;
  border-radius: 12px;
  box-shadow: 0 10px 25px rgba(0, 0, 0, 0.5);
  overflow-y: auto;
  position: relative;
  border: 1px solid var(--border-color);
}

.close-modal {
  position: absolute;
  top: 1rem;
  right: 1rem;
  background: transparent;
  border: none;
  font-size: 2rem;
  color: var(--text-color);
  cursor: pointer;
  line-height: 1;
}

.modal-content h2 {
  margin-top: 0;
  margin-bottom: 1.5rem;
  color: var(--accent-color);
  border-bottom: 1px solid var(--border-color);
  padding-bottom: 0.5rem;
}

.help-section {
  margin-bottom: 1.5rem;
}

.help-section h3 {
  margin-bottom: 0.5rem;
  font-size: 1.1rem;
  color: var(--text-color);
}

.help-section ul {
  margin: 0;
  padding-left: 1.2rem;
  color: #d1d5db;
}

body.light-mode .help-section ul {
  color: #4b5563;
}

.help-section li {
  margin-bottom: 0.3rem;
  line-height: 1.5;
}

.help-tip {
  background: rgba(59, 130, 246, 0.1);
  border-left: 4px solid var(--accent-color);
  padding: 1rem;
  border-radius: 0 4px 4px 0;
  margin-top: 2rem;
  font-size: 0.95rem;
}
