/* ===== VARIABLES ===== */
:root {
  --grad:    linear-gradient(135deg, #6a11cb 0%, #2575fc 100%);
  --primary: #2575fc;
  --bg:      #f0f2f5;
  --surface: #ffffff;
  --border:  #dee2e6;
  --text:    #212529;
  --muted:   #6c757d;
  --radius:  12px;
  --shadow:  0 2px 16px rgba(0,0,0,0.08);
  --trans:   all 0.2s ease;
}

/* ===== BASE ===== */
*, *::before, *::after { box-sizing: border-box; }
html, body {
  margin: 0;
  padding: 0;
  width: 100%;
  overflow-x: hidden;
}
body {
  font-family: 'Sarabun', sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  transition: background 0.3s, color 0.3s;
}

/* ===== SHELL ===== */
.app-shell {
  display: flex;
  flex-direction: column;
  min-height: 100vh;
  width: 100%;
  overflow-x: hidden;
}

/* ===== HEADER ===== */
.top-bar {
  background: var(--grad);
  padding: 0.7rem 1.25rem;
  position: sticky;
  top: 0;
  left: 0;
  width: 100%;
  z-index: 200;
  box-shadow: 0 2px 12px rgba(0,0,0,0.2);
}
.top-bar-inner {
  max-width: 1400px;
  margin: 0 auto;
  display: flex;
  align-items: center;
  justify-content: space-between;
  width: 100%;
}
.app-title {
  font-size: 1.2rem;
  font-weight: 700;
  color: #fff;
  margin: 0;
  display: flex;
  align-items: center;
  gap: 0.45rem;
}
.dark-toggle {
  background: rgba(255,255,255,0.15);
  border: 1px solid rgba(255,255,255,0.3);
  color: #fff;
  border-radius: 50%;
  width: 38px;
  height: 38px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  font-size: 0.95rem;
  line-height: 1;
  padding: 0;
  flex-shrink: 0;
  transition: var(--trans);
}
.dark-toggle:hover { background: rgba(255,255,255,0.28); }

/* ===== WORKSPACE ===== */
.workspace {
  flex: 1;
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  gap: 1rem;
  max-width: 1400px;
  margin: 0 auto;
  width: 100%;
  padding: 1rem;
}
@media (min-width: 992px) {
  .workspace {
    grid-template-columns: minmax(0, 5fr) minmax(0, 7fr);
    gap: 1.5rem;
    padding: 1.5rem;
    align-items: start;
  }
}

/* ===== PANELS ===== */
.panel {
  background: var(--surface);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 1.25rem;
  display: flex;
  flex-direction: column;
  gap: 1rem;
  min-width: 0;
}

/* ===== DROP ZONE ===== */
.dropzone {
  border: 2px dashed var(--border);
  border-radius: 10px;
  padding: 2rem 1rem;
  text-align: center;
  cursor: pointer;
  background: #f8f9fa;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.3rem;
  transition: var(--trans);
}
.dropzone:hover, .dropzone.dragover {
  border-color: var(--primary);
  background: #eef4ff;
  transform: scale(1.01);
}
.dropzone-icon  { width: 2.5rem; height: 2.5rem; fill: var(--muted); }
.dropzone-title { font-weight: 600; margin: 0; font-size: 0.95rem; }
.dropzone-hint  { color: var(--muted); margin: 0; font-size: 0.85rem; }
.dropzone-types { color: var(--muted); font-size: 0.75rem; letter-spacing: 0.02em; }

/* ===== FILE LIST ===== */
.list-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  width: 100%;
}
.badge-count { font-size: 0.8rem; color: var(--muted); font-weight: 500; }
.file-list-ul {
  max-height: 280px;
  overflow-y: auto;
  border-radius: 8px;
  border: 1px solid var(--border);
  margin: 0;
  padding: 0;
  width: 100%;
}
.file-item {
  background: var(--surface) !important;
  border-color: var(--border) !important;
  cursor: grab;
  user-select: none;
  touch-action: none;
  min-width: 0;
  width: 100%;
  transition: background 0.15s;
}
.file-item:hover { background: #f8f9fa !important; }
.file-item.dragging { opacity: 0.5; background: #e9ecef !important; border: 2px dashed var(--primary) !important; }
.file-item.over    { border-top: 2px solid var(--primary) !important; }
.file-thumb { width: 36px; height: 36px; object-fit: cover; border-radius: 4px; background: #eee; flex-shrink: 0; }

/* ===== CONTROLS ===== */
.ctrl-row { display: flex; flex-wrap: wrap; gap: 0.75rem; }
.ctrl-group { flex: 1 1 150px; display: flex; flex-direction: column; gap: 0.3rem; }
.ctrl-label {
  font-size: 0.78rem;
  font-weight: 700;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  margin: 0;
}

/* ===== ACTION BUTTONS ===== */
.action-row { 
  display: grid; 
  grid-template-columns: 1fr 1fr;
  gap: 0.75rem; 
  width: 100%;
}
.btn-action {
  display: flex;
  align-items: center;
  justify-content: center;
  flex-direction: row;
  gap: 0.35rem;
  padding: 0.7rem 0.4rem;
  border: none;
  border-radius: 8px;
  font-size: 0.875rem;
  font-weight: 600;
  cursor: pointer;
  width: 100%;
  min-width: 0;
  white-space: normal;
  text-align: center;
  transition: filter 0.2s, opacity 0.2s;
}
.btn-action:disabled { opacity: 0.45; cursor: not-allowed; }
.btn-action:not(:disabled):hover { filter: brightness(1.1); }
.btn-action-grey { background: #9ea7b0; color: #fff; }
.btn-action-blue { background: #5a97f2; color: #fff; }

/* ===== PROGRESS ===== */
.prog-wrap { display: flex; flex-direction: column; gap: 0.35rem; }
.prog-meta  { display: flex; justify-content: space-between; }
.prog-meta small { color: var(--muted); font-size: 0.78rem; }
.prog-track { height: 6px; background: #e9ecef; border-radius: 10px; overflow: hidden; }
.prog-fill  { height: 100%; background: var(--grad); border-radius: 10px; transition: width 0.3s ease; will-change: width; }

/* ===== RESULTS ===== */
#result-area { display: flex; flex-direction: column; gap: 0.5rem; }
.preview-container { max-height: 420px; overflow-y: auto; border: 1px solid var(--border); border-radius: 8px; padding: 0.75rem; background: #f8f9fa; }
.preview-image { max-width: 100%; height: auto; display: block; margin: 0 auto; border-radius: 4px; box-shadow: 0 2px 8px rgba(0,0,0,0.1); }
.preview-pdf   { width: 100%; height: 450px; border: none; }

/* ===== MODAL ===== */
.modal-content { border-radius: var(--radius); border: none; box-shadow: 0 10px 40px rgba(0,0,0,0.15); }
.modal-header  { background: var(--grad); color: #fff; border-radius: var(--radius) var(--radius) 0 0; border: none; }
.modal-title   { font-weight: 600; font-size: 1rem; }

/* ===== DARK MODE ===== */
body.dark-mode {
  --bg:      #0f1117;
  --surface: #1a1d27;
  --border:  #2d3142;
  --text:    #e2e8f0;
  --muted:   #8892a4;
  --shadow:  0 2px 16px rgba(0,0,0,0.35);
  --grad:    linear-gradient(135deg, #3a0ca3 0%, #4361ee 100%);
}
body.dark-mode .dropzone            { background: #1e2130; }
body.dark-mode .dropzone:hover,
body.dark-mode .dropzone.dragover   { background: #252840; border-color: #4dabf7; }
body.dark-mode .file-item           { background: #1e2130 !important; color: var(--text); border-color: var(--border) !important; }
body.dark-mode .file-item:hover     { background: #252840 !important; }
body.dark-mode .file-item.dragging  { background: #2d3142 !important; }
body.dark-mode .preview-container   { background: #1a1d27; }
body.dark-mode .prog-track          { background: #2d3142; }
body.dark-mode .form-select,
body.dark-mode .form-control        { background: #1e2130; color: var(--text); border-color: var(--border); }
body.dark-mode .form-select:focus,
body.dark-mode .form-control:focus  { background: #252840; color: #fff; border-color: #4dabf7; box-shadow: 0 0 0 0.2rem rgba(77,171,247,0.15); }
body.dark-mode .modal-content       { background: #1a1d27; color: var(--text); }
body.dark-mode .modal-body,
body.dark-mode .modal-footer        { background: #1a1d27; border-color: var(--border); }
body.dark-mode .btn-secondary       { background: #2d3142; color: var(--text); border-color: var(--border); }
body.dark-mode .list-group-item     { background: #1e2130; border-color: var(--border); color: var(--text); }
body.dark-mode .text-muted,
body.dark-mode .form-text           { color: var(--muted) !important; }

/* ===== RESPONSIVE: MOBILE ===== */
@media (max-width: 575px) {
  .workspace   { padding: 0.75rem; gap: 0.75rem; }
  .panel       { padding: 0.875rem; gap: 0.75rem; }
  .dropzone    { padding: 1.25rem 0.75rem; }
  .dropzone-icon { width: 2rem; height: 2rem; }
  .file-list-ul { max-height: 180px; }
  .preview-pdf { height: 300px; }
  
  .action-row  { gap: 0.5rem; }
  .btn-action  { font-size: 0.82rem; padding: 0.65rem 0.3rem; gap: 0.25rem; }
}

/* ===== REDUCED MOTION ===== */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition-duration: 0.01ms !important; }
}

/* ===== PRINT ===== */
@media print {
  .top-bar, .action-row, .file-panel { display: none !important; }
  .workspace { grid-template-columns: 1fr !important; }
  .panel { box-shadow: none !important; }
}