/* ============================================================
   KHTN HTML Authoring Suite — Main Stylesheet
   ============================================================ */

/* ── CSS Variables (Blue theme default) ─────────────────── */
:root {
  --primary: #2563eb;
  --primary-dark: #1d4ed8;
  --primary-light: #dbeafe;
  --secondary: #7c3aed;
  --accent: #06b6d4;
  --success: #10b981;
  --warning: #f59e0b;
  --danger: #ef4444;
  --bg: #f0f4f8;
  --surface: #ffffff;
  --surface2: #f8fafc;
  --border: #e2e8f0;
  --text: #1e293b;
  --text-muted: #64748b;
  --shadow: 0 4px 20px rgba(37,99,235,0.10);
  --shadow-lg: 0 10px 40px rgba(37,99,235,0.16);
  --radius: 14px;
  --radius-sm: 8px;
  --transition: 0.22s cubic-bezier(.4,0,.2,1);
  --sidebar-w: 260px;
  --header-h: 64px;
}

/* ── Dark Theme ──────────────────────────────────────────── */
[data-theme="dark"] {
  --primary: #60a5fa;
  --primary-dark: #3b82f6;
  --primary-light: #1e3a5f;
  --bg: #0f172a;
  --surface: #1e293b;
  --surface2: #0f172a;
  --border: #334155;
  --text: #f1f5f9;
  --text-muted: #94a3b8;
  --shadow: 0 4px 20px rgba(0,0,0,0.40);
}

/* ── Science Theme ───────────────────────────────────────── */
[data-theme="science"] {
  --primary: #059669;
  --primary-dark: #047857;
  --primary-light: #d1fae5;
  --secondary: #0891b2;
  --bg: #f0fdf4;
  --surface: #ffffff;
  --border: #bbf7d0;
}

/* ── Space Theme ─────────────────────────────────────────── */
[data-theme="space"] {
  --primary: #8b5cf6;
  --primary-dark: #7c3aed;
  --primary-light: #1e1b4b;
  --bg: #0d0d1a;
  --surface: #1a1a2e;
  --surface2: #16213e;
  --border: #312e81;
  --text: #e2e8f0;
  --text-muted: #a5b4fc;
  --shadow: 0 4px 20px rgba(139,92,246,0.30);
}

/* ── Nature Theme ─────────────────────────────────────────── */
[data-theme="nature"] {
  --primary: #16a34a;
  --primary-dark: #15803d;
  --primary-light: #dcfce7;
  --secondary: #ca8a04;
  --bg: #fafaf5;
  --surface: #ffffff;
  --border: #d9f99d;
}

/* ── Reset & Base ────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

html { scroll-behavior: smooth; font-size: 15px; }

body {
  font-family: 'Segoe UI', 'Be Vietnam Pro', system-ui, sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  transition: background var(--transition), color var(--transition);
  overflow-x: hidden;
}

/* ── Layout ──────────────────────────────────────────────── */
.app-layout {
  display: flex;
  min-height: 100vh;
}

/* ── Sidebar ─────────────────────────────────────────────── */
.sidebar {
  width: var(--sidebar-w);
  background: var(--surface);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  position: fixed;
  top: 0; left: 0;
  height: 100vh;
  z-index: 100;
  transition: transform var(--transition), background var(--transition);
  overflow-y: auto;
}

.sidebar-logo {
  padding: 20px 18px 14px;
  border-bottom: 1px solid var(--border);
  display: flex; align-items: center; gap: 10px;
}

.sidebar-logo .logo-icon {
  width: 40px; height: 40px;
  background: linear-gradient(135deg, var(--primary), var(--secondary));
  border-radius: 10px;
  display: flex; align-items: center; justify-content: center;
  font-size: 20px; color: #fff;
  flex-shrink: 0;
}

.sidebar-logo h2 {
  font-size: 13px; font-weight: 700;
  color: var(--primary);
  line-height: 1.3;
}
.sidebar-logo small { color: var(--text-muted); font-size: 10px; }

.sidebar-nav { padding: 10px 0; flex: 1; }

.nav-section-label {
  font-size: 10px; font-weight: 700;
  text-transform: uppercase; letter-spacing: 1px;
  color: var(--text-muted);
  padding: 14px 18px 4px;
}

.nav-item {
  display: flex; align-items: center; gap: 10px;
  padding: 10px 18px;
  color: var(--text-muted);
  text-decoration: none;
  cursor: pointer;
  border-radius: 0;
  transition: all var(--transition);
  font-size: 13.5px; font-weight: 500;
  border-left: 3px solid transparent;
  position: relative;
}

.nav-item:hover {
  background: var(--primary-light);
  color: var(--primary);
  border-left-color: var(--primary);
}

.nav-item.active {
  background: var(--primary-light);
  color: var(--primary);
  border-left-color: var(--primary);
  font-weight: 600;
}

.nav-item .nav-icon {
  width: 22px; text-align: center;
  font-size: 15px; flex-shrink: 0;
}

.nav-badge {
  margin-left: auto;
  background: var(--primary);
  color: #fff;
  font-size: 10px; font-weight: 700;
  padding: 1px 7px; border-radius: 20px;
}

.sidebar-footer {
  padding: 14px 18px;
  border-top: 1px solid var(--border);
  font-size: 11px; color: var(--text-muted);
  text-align: center;
}

/* ── Main Content ─────────────────────────────────────────── */
.main-content {
  margin-left: var(--sidebar-w);
  flex: 1;
  display: flex;
  flex-direction: column;
  min-height: 100vh;
}

/* ── Header ──────────────────────────────────────────────── */
.top-header {
  height: var(--header-h);
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  display: flex; align-items: center;
  padding: 0 24px;
  gap: 14px;
  position: sticky; top: 0; z-index: 90;
  box-shadow: var(--shadow);
}

.header-title {
  font-size: 17px; font-weight: 700;
  color: var(--text); flex: 1;
}

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

/* ── Page Content ─────────────────────────────────────────── */
.page-content {
  padding: 26px 28px;
  flex: 1;
}

/* ── Cards ───────────────────────────────────────────────── */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 22px;
  box-shadow: var(--shadow);
  transition: box-shadow var(--transition), border-color var(--transition);
}

.card:hover { box-shadow: var(--shadow-lg); }

.card-header {
  display: flex; align-items: center;
  justify-content: space-between;
  margin-bottom: 18px;
  padding-bottom: 14px;
  border-bottom: 1px solid var(--border);
}

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

/* ── Buttons ─────────────────────────────────────────────── */
.btn {
  display: inline-flex; align-items: center; gap: 7px;
  padding: 9px 18px; border-radius: var(--radius-sm);
  font-size: 13.5px; font-weight: 600; cursor: pointer;
  border: none; transition: all var(--transition);
  text-decoration: none; white-space: nowrap;
}

.btn-primary {
  background: var(--primary); color: #fff;
}
.btn-primary:hover { background: var(--primary-dark); transform: translateY(-1px); box-shadow: 0 4px 14px rgba(37,99,235,0.35); }

.btn-secondary {
  background: var(--surface2); color: var(--text);
  border: 1px solid var(--border);
}
.btn-secondary:hover { background: var(--primary-light); color: var(--primary); }

.btn-success { background: var(--success); color: #fff; }
.btn-success:hover { opacity: 0.88; }

.btn-danger { background: var(--danger); color: #fff; }
.btn-danger:hover { opacity: 0.88; }

.btn-warning { background: var(--warning); color: #fff; }

.btn-outline {
  background: transparent; color: var(--primary);
  border: 2px solid var(--primary);
}
.btn-outline:hover { background: var(--primary); color: #fff; }

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

.btn-icon {
  width: 36px; height: 36px; padding: 0;
  display: inline-flex; align-items: center; justify-content: center;
  border-radius: var(--radius-sm);
}

/* ── Form Controls ───────────────────────────────────────── */
.form-group { margin-bottom: 16px; }

.form-label {
  display: block;
  font-size: 12.5px; font-weight: 600;
  color: var(--text-muted);
  margin-bottom: 6px;
  text-transform: uppercase; letter-spacing: 0.5px;
}

.form-control {
  width: 100%;
  padding: 9px 13px;
  border: 2px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface);
  color: var(--text);
  font-size: 14px;
  transition: border-color var(--transition), box-shadow var(--transition);
  outline: none;
  font-family: inherit;
}

.form-control:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(37,99,235,0.12);
}

.form-control::placeholder { color: var(--text-muted); opacity: 0.7; }

textarea.form-control { resize: vertical; min-height: 90px; }

select.form-control { cursor: pointer; }

/* ── Grid ─────────────────────────────────────────────────── */
.grid { display: grid; }
.grid-2 { grid-template-columns: repeat(2, 1fr); gap: 18px; }
.grid-3 { grid-template-columns: repeat(3, 1fr); gap: 18px; }
.grid-4 { grid-template-columns: repeat(4, 1fr); gap: 16px; }

/* ── Stat Cards ──────────────────────────────────────────── */
.stat-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
  display: flex; align-items: center; gap: 16px;
  box-shadow: var(--shadow);
  transition: transform var(--transition);
}
.stat-card:hover { transform: translateY(-2px); }

.stat-icon {
  width: 54px; height: 54px;
  border-radius: 12px;
  display: flex; align-items: center; justify-content: center;
  font-size: 22px;
  flex-shrink: 0;
}

.stat-info h3 { font-size: 24px; font-weight: 800; color: var(--text); }
.stat-info p { font-size: 12px; color: var(--text-muted); font-weight: 500; }

/* ── Feature Cards (Dashboard) ───────────────────────────── */
.feature-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(230px, 1fr));
  gap: 16px;
  margin-top: 6px;
}

.feature-card {
  background: var(--surface);
  border: 1.5px solid var(--border);
  border-radius: var(--radius);
  padding: 22px 18px;
  cursor: pointer;
  transition: all var(--transition);
  display: flex; flex-direction: column;
  gap: 10px;
  text-decoration: none; color: inherit;
  position: relative; overflow: hidden;
}

.feature-card::before {
  content: '';
  position: absolute; top: 0; left: 0;
  width: 4px; height: 100%;
  background: var(--primary);
  transform: scaleY(0);
  transition: transform var(--transition);
  transform-origin: bottom;
}

.feature-card:hover {
  border-color: var(--primary);
  transform: translateY(-3px);
  box-shadow: var(--shadow-lg);
}
.feature-card:hover::before { transform: scaleY(1); }

.feature-card .fc-icon {
  width: 48px; height: 48px;
  border-radius: 12px;
  display: flex; align-items: center; justify-content: center;
  font-size: 22px;
}

.feature-card h4 { font-size: 14px; font-weight: 700; }
.feature-card p { font-size: 12px; color: var(--text-muted); line-height: 1.5; }

/* ── Tabs ─────────────────────────────────────────────────── */
.tabs {
  display: flex; border-bottom: 2px solid var(--border);
  margin-bottom: 20px; gap: 2px;
}

.tab-btn {
  padding: 10px 18px; cursor: pointer;
  font-size: 13.5px; font-weight: 600;
  color: var(--text-muted); background: none; border: none;
  border-bottom: 2px solid transparent;
  margin-bottom: -2px; transition: all var(--transition);
  display: flex; align-items: center; gap: 6px;
}

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

.tab-panel { display: none; }
.tab-panel.active { display: block; }

/* ── Modal ───────────────────────────────────────────────── */
.modal-overlay {
  position: fixed; inset: 0;
  background: rgba(0,0,0,0.55);
  backdrop-filter: blur(4px);
  z-index: 1000;
  display: flex; align-items: center; justify-content: center;
  padding: 20px;
  opacity: 0; pointer-events: none;
  transition: opacity var(--transition);
}

.modal-overlay.open {
  opacity: 1; pointer-events: all;
}

.modal {
  background: var(--surface);
  border-radius: var(--radius);
  padding: 28px;
  width: 100%; max-width: 640px;
  max-height: 90vh; overflow-y: auto;
  box-shadow: var(--shadow-lg);
  transform: scale(0.95);
  transition: transform var(--transition);
}

.modal-overlay.open .modal { transform: scale(1); }

.modal-header {
  display: flex; align-items: center; justify-content: space-between;
  margin-bottom: 20px;
}

.modal-title { font-size: 17px; font-weight: 800; color: var(--text); }

/* ── Toast / Alert ───────────────────────────────────────── */
.toast-container {
  position: fixed; top: 20px; right: 20px; z-index: 9999;
  display: flex; flex-direction: column; gap: 10px;
  pointer-events: none;
}

.toast {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 12px 18px;
  font-size: 13.5px; font-weight: 600;
  box-shadow: var(--shadow-lg);
  display: flex; align-items: center; gap: 10px;
  animation: toastIn 0.3s ease;
  pointer-events: all;
  min-width: 240px;
}

.toast.success { border-left: 4px solid var(--success); }
.toast.error { border-left: 4px solid var(--danger); }
.toast.info { border-left: 4px solid var(--primary); }
.toast.warning { border-left: 4px solid var(--warning); }

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

/* ── Badges ──────────────────────────────────────────────── */
.badge {
  display: inline-flex; align-items: center;
  padding: 3px 10px; border-radius: 20px;
  font-size: 11px; font-weight: 700;
}
.badge-primary { background: var(--primary-light); color: var(--primary); }
.badge-success { background: #d1fae5; color: #065f46; }
.badge-warning { background: #fef3c7; color: #92400e; }
.badge-danger { background: #fee2e2; color: #991b1b; }
.badge-gray { background: var(--surface2); color: var(--text-muted); }

/* ── Progress Bar ─────────────────────────────────────────── */
.progress-bar {
  height: 8px; border-radius: 99px;
  background: var(--border);
  overflow: hidden;
}
.progress-fill {
  height: 100%; border-radius: 99px;
  background: linear-gradient(90deg, var(--primary), var(--accent));
  transition: width 0.5s ease;
}

/* ── Quiz Answer Options ──────────────────────────────────── */
.option-list { display: flex; flex-direction: column; gap: 10px; }

.option-item {
  display: flex; align-items: center; gap: 12px;
  padding: 12px 16px;
  border: 2px solid var(--border);
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: all var(--transition);
  background: var(--surface);
}

.option-item:hover {
  border-color: var(--primary);
  background: var(--primary-light);
}

.option-item.correct {
  border-color: var(--success);
  background: #d1fae5;
}

.option-item.wrong {
  border-color: var(--danger);
  background: #fee2e2;
}

.option-key {
  width: 30px; height: 30px;
  border-radius: 50%;
  background: var(--border);
  display: flex; align-items: center; justify-content: center;
  font-weight: 700; font-size: 13px;
  flex-shrink: 0;
}

/* ── Table ────────────────────────────────────────────────── */
.data-table {
  width: 100%; border-collapse: collapse;
  font-size: 13.5px;
}

.data-table th {
  background: var(--surface2);
  padding: 10px 14px;
  text-align: left; font-weight: 700;
  color: var(--text-muted); font-size: 12px;
  text-transform: uppercase; letter-spacing: 0.5px;
  border-bottom: 2px solid var(--border);
}

.data-table td {
  padding: 11px 14px;
  border-bottom: 1px solid var(--border);
  color: var(--text);
}

.data-table tr:last-child td { border-bottom: none; }
.data-table tr:hover td { background: var(--surface2); }

/* ── Drag-Drop Zones ──────────────────────────────────────── */
.drop-zone {
  border: 2px dashed var(--border);
  border-radius: var(--radius);
  padding: 32px;
  text-align: center; color: var(--text-muted);
  cursor: pointer; transition: all var(--transition);
}
.drop-zone:hover, .drop-zone.drag-over {
  border-color: var(--primary);
  background: var(--primary-light);
  color: var(--primary);
}

/* ── Code Block ───────────────────────────────────────────── */
.code-block {
  background: #1e293b; color: #e2e8f0;
  border-radius: var(--radius-sm);
  padding: 16px; font-family: 'Cascadia Code', 'Fira Code', monospace;
  font-size: 12.5px; line-height: 1.6; overflow-x: auto;
}

/* ── Scrollbar ────────────────────────────────────────────── */
::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 99px; }
::-webkit-scrollbar-thumb:hover { background: var(--text-muted); }

/* ── Responsive ───────────────────────────────────────────── */
@media (max-width: 900px) {
  .sidebar { transform: translateX(-100%); }
  .sidebar.open { transform: translateX(0); }
  .main-content { margin-left: 0; }
  .grid-3 { grid-template-columns: repeat(2, 1fr); }
  .grid-4 { grid-template-columns: repeat(2, 1fr); }
}

@media (max-width: 600px) {
  .grid-2, .grid-3, .grid-4 { grid-template-columns: 1fr; }
  .page-content { padding: 16px; }
}

/* ── Utility ──────────────────────────────────────────────── */
.flex { display: flex; }
.flex-col { display: flex; flex-direction: column; }
.items-center { align-items: center; }
.justify-between { justify-content: space-between; }
.gap-2 { gap: 8px; }
.gap-4 { gap: 16px; }
.mt-2 { margin-top: 8px; }
.mt-4 { margin-top: 16px; }
.mb-4 { margin-bottom: 16px; }
.text-center { text-align: center; }
.text-muted { color: var(--text-muted); font-size: 13px; }
.font-bold { font-weight: 700; }
.hidden { display: none !important; }
.w-full { width: 100%; }

/* ── Animation ────────────────────────────────────────────── */
@keyframes fadeIn {
  from { opacity: 0; transform: translateY(10px); }
  to { opacity: 1; transform: translateY(0); }
}
.fade-in { animation: fadeIn 0.3s ease; }

@keyframes pulse {
  0%,100% { opacity: 1; }
  50% { opacity: 0.5; }
}
.pulse { animation: pulse 1.5s infinite; }

/* ── Chemistry Formulas ──────────────────────────────────── */
.chem-formula { font-family: 'Segoe UI', sans-serif; }
.chem-formula sub { font-size: 0.75em; }

/* ── Neon Effect ──────────────────────────────────────────── */
.neon-text {
  text-shadow: 0 0 10px var(--primary), 0 0 20px var(--primary), 0 0 40px var(--primary);
}

/* ── Glass Effect ─────────────────────────────────────────── */
.glass {
  background: rgba(255,255,255,0.15);
  backdrop-filter: blur(12px);
  border: 1px solid rgba(255,255,255,0.2);
}
