/* ── Reset & Variables ── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
:root {
  --primary: #c0392b;
  --primary-dark: #a93226;
  --primary-light: #fef5f5;
  --surface: #ffffff;
  --bg: #f4f6fa;
  --border: #e2e8f0;
  --text: #1e293b;
  --text-muted: #64748b;
  --success: #059669;
  --warning: #d97706;
  --danger: #dc2626;
  --shadow: rgba(0,0,0,0.08);
  --shadow-lg: rgba(0,0,0,0.15);
  --radius: 12px;
  --radius-sm: 7px;
  --font: 'Segoe UI', 'Inter', Arial, sans-serif;
}
body { font-family: var(--font); background: var(--bg); color: var(--text); min-height: 100vh; }
button { cursor: pointer; border: none; background: none; font-family: inherit; }
input, textarea { font-family: inherit; }

/* ── App Header ── */
.app-header {
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  position: sticky; top: 0; z-index: 50;
  box-shadow: 0 2px 12px var(--shadow);
}
.app-header-inner {
  max-width: 1100px; margin: 0 auto;
  padding: 0.9rem 1.5rem;
  display: flex; align-items: center; justify-content: space-between;
}
.app-logo { display: flex; align-items: center; gap: 0.85rem; }
.logo-icon { font-size: 2rem; }
.logo-title { font-size: 1.15rem; font-weight: 800; color: var(--text); }
.logo-sub { font-size: 0.75rem; color: var(--text-muted); }

/* ── Buttons ── */
.btn {
  padding: 0.6rem 1.4rem;
  border-radius: var(--radius-sm);
  font-size: 0.9rem; font-weight: 700;
  border: 2px solid transparent;
  transition: all 0.15s;
}
.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-dark); }
.btn-generate {
  width: 100%; padding: 0.9rem;
  font-size: 1rem; font-weight: 800;
  background: var(--primary); color: #fff;
  border-radius: var(--radius); border: none;
  margin-top: 0.5rem; transition: all 0.15s;
  display: flex; align-items: center; justify-content: center; gap: 0.5rem;
}
.btn-generate:hover:not(:disabled) { background: var(--primary-dark); transform: translateY(-1px); box-shadow: 0 4px 16px rgba(192,57,43,0.3); }
.btn-generate:disabled { opacity: 0.6; cursor: not-allowed; transform: none; box-shadow: none; }

/* ── Main ── */
.app-main { max-width: 1100px; margin: 0 auto; padding: 2rem 1.5rem; }

/* ── Packages Section ── */
.packages-section { background: var(--surface); border-radius: var(--radius); border: 1px solid var(--border); overflow: hidden; }
.section-header { padding: 1.25rem 1.5rem; border-bottom: 1px solid var(--border); display: flex; align-items: center; justify-content: space-between; }
.section-title { font-size: 1.15rem; font-weight: 800; }
.section-sub { font-size: 0.82rem; color: var(--text-muted); margin-top: 2px; }

/* ── Courses Table ── */
.courses-table { width: 100%; border-collapse: collapse; font-size: 0.88rem; }
.courses-table th { padding: 0.75rem 1.25rem; text-align: left; font-size: 0.75rem; font-weight: 700; text-transform: uppercase; letter-spacing: 0.06em; color: var(--text-muted); background: var(--bg); border-bottom: 1px solid var(--border); }
.courses-table td { padding: 0.9rem 1.25rem; border-bottom: 1px solid var(--border); vertical-align: middle; }
.courses-table tr:last-child td { border-bottom: none; }
.courses-table tr:hover td { background: color-mix(in srgb, var(--primary) 3%, var(--surface)); }
.course-title-cell { font-weight: 700; }
.theme-badge {
  display: inline-block; padding: 0.2rem 0.6rem;
  border-radius: 999px; font-size: 0.72rem; font-weight: 700;
  background: color-mix(in srgb, var(--primary) 12%, var(--surface));
  color: var(--primary); border: 1px solid color-mix(in srgb, var(--primary) 25%, transparent);
}
.action-btns { display: flex; gap: 0.4rem; align-items: center; }
.btn-action {
  padding: 0.35rem 0.85rem; border-radius: var(--radius-sm);
  font-size: 0.78rem; font-weight: 700;
  border: 1.5px solid var(--border); color: var(--text-muted);
  background: var(--surface); transition: all 0.15s;
}
.btn-action:hover { border-color: var(--primary); color: var(--primary); }
.btn-action.btn-dl { background: var(--primary); color: #fff; border-color: var(--primary); }
.btn-action.btn-dl:hover { background: var(--primary-dark); }

/* ── Empty State ── */
.empty-state { text-align: center; padding: 4rem 2rem; }
.empty-icon { font-size: 3rem; margin-bottom: 0.75rem; }
.empty-text { font-size: 1rem; color: var(--text-muted); margin-bottom: 1.25rem; }

/* ── Modal ── */
.modal-overlay {
  position: fixed; inset: 0;
  background: rgba(0,0,0,0.5); backdrop-filter: blur(3px);
  z-index: 200; display: none; align-items: center; justify-content: center;
  padding: 1rem;
}
.modal-overlay.open { display: flex; }
.modal {
  background: var(--surface); border-radius: var(--radius);
  width: 100%; max-width: 620px;
  max-height: 90vh; overflow-y: auto;
  box-shadow: 0 20px 60px rgba(0,0,0,0.3);
  animation: modalIn 0.2s ease;
}
@keyframes modalIn { from{transform:scale(0.95);opacity:0} to{transform:scale(1);opacity:1} }
.modal-header {
  display: flex; align-items: flex-start; justify-content: space-between;
  padding: 1.5rem 1.5rem 1rem;
  border-bottom: 1px solid var(--border);
}
.modal-title { font-size: 1.25rem; font-weight: 800; }
.modal-sub { font-size: 0.82rem; color: var(--text-muted); margin-top: 2px; }
.modal-close {
  width: 32px; height: 32px; border-radius: 50%;
  background: var(--bg); color: var(--text-muted);
  font-size: 1rem; display: flex; align-items: center; justify-content: center;
  flex-shrink: 0; transition: all 0.15s;
}
.modal-close:hover { background: var(--danger); color: #fff; }

/* Mode Tabs */
.mode-tabs { display: flex; padding: 1rem 1.5rem 0; gap: 0.4rem; }
.mode-tab {
  flex: 1; padding: 0.6rem 1rem; border-radius: var(--radius-sm);
  font-size: 0.85rem; font-weight: 600;
  border: 1.5px solid var(--border); color: var(--text-muted);
  background: var(--bg); transition: all 0.15s;
}
.mode-tab.active { background: var(--primary); color: #fff; border-color: var(--primary); }

/* Forms */
#form-single, #form-bulk, #form-add-ml { padding: 1.25rem 1.5rem 1.5rem; display: flex; flex-direction: column; gap: 1.1rem; }
.form-group { display: flex; flex-direction: column; gap: 0.35rem; }
.form-label { font-size: 0.85rem; font-weight: 700; color: var(--text); }
.required { color: var(--danger); }
.optional { color: var(--text-muted); font-weight: 400; }
.form-input {
  padding: 0.7rem 0.9rem; border-radius: var(--radius-sm);
  border: 1.5px solid var(--border); background: var(--bg);
  font-size: 0.9rem; color: var(--text);
  transition: border-color 0.15s;
}
.form-input:focus { outline: none; border-color: var(--primary); background: var(--surface); }
.form-textarea { resize: vertical; }
.char-count { font-size: 0.72rem; color: var(--text-muted); text-align: right; }

/* Checkbox row */
.checkbox-row { display: flex; align-items: center; gap: 0.5rem; font-size: 0.85rem; font-weight: 600; color: var(--text); cursor: pointer; }
.checkbox-row input[type="checkbox"] { width: 16px; height: 16px; accent-color: var(--primary); cursor: pointer; }

/* Toggle group */
.toggle-group { display: flex; gap: 0; border: 1.5px solid var(--border); border-radius: var(--radius-sm); overflow: hidden; }
.toggle-btn { flex: 1; padding: 0.6rem; font-size: 0.85rem; font-weight: 600; color: var(--text-muted); background: var(--bg); border-right: 1px solid var(--border); transition: all 0.15s; }
.toggle-btn:last-child { border-right: none; }
.toggle-btn.active { background: var(--primary); color: #fff; }

/* Module count */
.module-count-row { display: flex; align-items: center; gap: 0.85rem; }
.count-btn {
  width: 32px; height: 32px; border-radius: 50%;
  background: var(--bg); border: 1.5px solid var(--border);
  font-size: 1.1rem; color: var(--text);
  display: flex; align-items: center; justify-content: center;
  transition: all 0.15s;
}
.count-btn:hover { border-color: var(--primary); color: var(--primary); }
#module-count-display { font-size: 1.25rem; font-weight: 800; min-width: 28px; text-align: center; }
.count-hint { font-size: 0.78rem; color: var(--text-muted); }

/* Upload zone */
.upload-zone {
  border: 2px dashed var(--border); border-radius: var(--radius);
  padding: 1.5rem; text-align: center; background: var(--bg);
  cursor: pointer; transition: all 0.15s;
}
.upload-zone.drag-over { border-color: var(--primary); background: var(--primary-light); }
.upload-icon { font-size: 2rem; margin-bottom: 0.4rem; }
.upload-text { font-size: 0.9rem; font-weight: 600; margin-bottom: 0.25rem; }
.upload-browse {
  color: var(--primary); font-weight: 700; text-decoration: underline;
  cursor: pointer; font-size: 0.9rem;
}
.upload-hint { font-size: 0.75rem; color: var(--text-muted); margin-top: 0.35rem; }
.file-list { margin-top: 0.75rem; display: flex; flex-direction: column; gap: 0.3rem; }
.file-chip {
  display: flex; align-items: center; justify-content: space-between;
  background: color-mix(in srgb, var(--primary) 8%, var(--surface));
  border: 1px solid color-mix(in srgb, var(--primary) 25%, transparent);
  padding: 0.35rem 0.75rem; border-radius: var(--radius-sm);
  font-size: 0.8rem; color: var(--text);
}
.file-chip-remove { cursor: pointer; color: var(--danger); font-weight: 700; padding: 0 0.2rem; }

/* Spinner */
.spinner {
  width: 16px; height: 16px; border-radius: 50%;
  border: 2px solid rgba(255,255,255,0.3);
  border-top-color: #fff;
  animation: spin 0.7s linear infinite; display: inline-block;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* Bulk info */
.bulk-info { display: flex; gap: 1rem; align-items: flex-start; padding: 1rem; background: color-mix(in srgb, var(--primary) 6%, var(--surface)); border: 1px solid color-mix(in srgb, var(--primary) 20%, transparent); border-radius: var(--radius); }
.bulk-info-icon { font-size: 1.8rem; flex-shrink: 0; }
.bulk-info-title { font-weight: 700; margin-bottom: 0.2rem; }
.bulk-info-desc { font-size: 0.85rem; color: var(--text-muted); }

/* Excel columns hint */
.excel-columns-hint { background: var(--bg); border: 1px solid var(--border); border-radius: var(--radius); padding: 1rem; font-size: 0.82rem; }
.hint-title { font-weight: 700; margin-bottom: 0.5rem; }
.hint-table { display: flex; flex-direction: column; gap: 0.3rem; }
.hint-row { display: flex; align-items: center; gap: 0.75rem; }
.hint-col { font-family: monospace; background: var(--surface); padding: 0.15rem 0.5rem; border-radius: 4px; border: 1px solid var(--border); min-width: 120px; font-size: 0.78rem; }
.required-col { border-color: var(--danger); color: var(--danger); }

/* Toast */
.toast {
  position: fixed; bottom: 1.5rem; left: 50%; transform: translateX(-50%);
  background: var(--text); color: #fff;
  padding: 0.7rem 1.5rem; border-radius: 999px;
  font-size: 0.88rem; font-weight: 600;
  opacity: 0; pointer-events: none; transition: opacity 0.25s;
  z-index: 999; max-width: 380px; text-align: center;
}
.toast.show { opacity: 1; }
.toast.success { background: var(--success); }
.toast.error { background: var(--danger); }

/* Responsive */
@media (max-width: 640px) {
  .app-header-inner { flex-direction: column; gap: 0.75rem; align-items: flex-start; }
  .modal { max-height: 95vh; }
  .courses-table { font-size: 0.8rem; }
  .courses-table th, .courses-table td { padding: 0.65rem 0.75rem; }
}
