/* =========================
   Base Theme
   ========================= */

:root {
  /* Brand palette */
  --brand-primary: #ed462f;
  --brand-secondary: #a9210f;
  --brand-accent: #f59e0b;
  --brand-lime: #f97316;
  --brand-orange: #ed462f;

  --ink: #17212f;
  --muted: #6b7280;
  --bg: #f8f5f2;
  --card: #ffffff;
  --line: #e8ddd6;
  --radius: 18px;
  --radius-lg: 22px;
  --shadow-soft: 0 18px 46px rgba(23, 33, 47, 0.08);
  --shadow-lift: 0 24px 64px rgba(23, 33, 47, 0.14);
  --grad-primary: linear-gradient(135deg, #ed462f 0%, #a9210f 100%);
}

* { box-sizing: border-box; }

body.app-body {
  min-height: 100vh;
  background:
    radial-gradient(900px 420px at 5% -10%, rgba(237,70,47,0.14), transparent 60%),
    radial-gradient(820px 380px at 95% 10%, rgba(169,33,15,0.08), transparent 55%),
    radial-gradient(780px 360px at 50% 100%, rgba(245,158,11,0.06), transparent 58%),
    var(--bg);
  color: var(--ink);
  font-family: "Manrope", system-ui, -apple-system, "Segoe UI", sans-serif;
}

h1, h2, h3, h4, .display-6 {
  font-family: "Fraunces", "Manrope", system-ui, sans-serif;
  letter-spacing: -0.01em;
}

p { color: var(--muted); }
a { color: inherit; }
a:hover { color: var(--brand-primary); }
ul { padding-left: 1.2rem; }
.app-hero ul li { margin-bottom: 6px; }

.app-shell { min-height: 100vh; display: flex; flex-direction: column; }
.app-main { flex: 1; width: 100%; }
.app-container { max-width: 1280px; margin: 0 auto; padding-left: 16px; padding-right: 16px; width: 100%; }
.app-container-full { width: 100%; padding-left: 0; padding-right: 0; }

.page-header {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 16px;
}
.page-title { font-size: 1.6rem; margin: 0; }
.page-subtitle { color: var(--muted); margin: 0; }
.toolbar { display: flex; gap: 8px; flex-wrap: wrap; }

/* =========================
   Topbar
   ========================= */

.app-topbar {
  background: #101829;
  backdrop-filter: blur(12px);
  border-bottom: 1px solid rgba(255,255,255,0.06);
  box-shadow: 0 14px 34px rgba(16, 24, 41, 0.32);
}
.app-topbar .app-container,
.admin-topbar .app-container {
  max-width: 1280px;
}

.app-brand { text-decoration: none; }
.app-brand-text { font-family: "Manrope", system-ui, sans-serif; font-size: 0.98rem; font-weight: 800; letter-spacing: 0.01em; color: #ffffff; }
.app-brand-sub { font-size: 0.78rem; color: rgba(226, 232, 240, 0.7); margin-left: 6px; }

.app-mark,
.app-mark-lg {
  display: grid;
  place-items: center;
  color: #fff;
  background: var(--brand-primary);
  box-shadow: 0 10px 30px rgba(0,0,0,0.12);
}
.app-mark { width: 34px; height: 34px; border-radius: 12px; }
.app-mark-lg { width: 46px; height: 46px; border-radius: 16px; }

.app-nav-link {
  color: rgba(248,250,252,0.92);
  font-size: 0.9rem;
  font-weight: 700;
  letter-spacing: 0.01em;
  border-radius: 999px;
  padding: 8px 12px;
  background: rgba(255,255,255,0.05);
  border: 1px solid rgba(255,255,255,0.08);
}
.app-nav-link:hover {
  background: rgba(255,255,255,0.1);
  color: #fff;
}
.app-nav-link.is-active {
  background: rgba(255,255,255,0.94);
  color: var(--brand-primary);
  box-shadow: inset 0 0 0 1px rgba(255,255,255,0.18), 0 10px 22px rgba(16,24,41,0.24);
}
.app-nav-toggle {
  border-radius: 12px;
  border-color: rgba(255,255,255,0.16);
  color: #fff;
  background: rgba(255,255,255,0.05);
}
.topbar-admin-btn {
  border-radius: 12px;
  font-weight: 700;
  border-color: rgba(255,255,255,0.16);
  color: #fff;
  background: rgba(255,255,255,0.05);
}
.topbar-admin-btn:hover {
  border-color: rgba(255,255,255,0.24);
  background: rgba(255,255,255,0.12);
  color: #fff;
}
.topbar-user-btn {
  border-radius: 12px;
  border: 1px solid rgba(255,255,255,0.14);
  color: #fff;
  background: rgba(255,255,255,0.05);
  min-width: 38px;
}
.topbar-user-btn:hover,
.topbar-user-btn:focus {
  border-color: rgba(255,255,255,0.24);
  background: rgba(255,255,255,0.12);
  color: #fff;
}
.topbar-user-btn:focus-visible {
  outline: 0;
  box-shadow: 0 0 0 3px rgba(237,70,47,0.18);
}

.admin-topbar .admin-user .btn {
  min-height: 36px;
  border-radius: 999px;
  padding: 0 12px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 0.78rem;
  font-weight: 700;
  white-space: nowrap;
  border: 1px solid rgba(255,255,255,0.16);
  color: #fff;
  background: rgba(255,255,255,0.05);
}

.admin-topbar .admin-user .btn:hover,
.admin-topbar .admin-user .btn:focus {
  color: #fff;
  border-color: rgba(255,255,255,0.24);
  background: rgba(255,255,255,0.1);
  box-shadow: none;
}

.admin-topbar .admin-user .btn.btn-primary {
  border-color: transparent;
  background: #ed462f;
  box-shadow: 0 10px 22px rgba(237,70,47,0.18);
}

.admin-topbar .admin-user .btn.btn-primary:hover,
.admin-topbar .admin-user .btn.btn-primary:focus {
  background: #d43f2a;
}

/* =========================
   Buttons + Forms
   ========================= */

.btn-primary {
  background: var(--brand-primary);
  border: none;
  font-weight: 700;
  box-shadow: 0 10px 20px rgba(237,70,47,0.2);
}
.btn-primary:hover { filter: brightness(0.98); }
.btn-outline-primary {
  color: var(--brand-primary);
  border-color: rgba(237,70,47,0.45);
}
.btn-outline-primary:hover {
  background: rgba(237,70,47,0.08);
  border-color: rgba(237,70,47,0.7);
}
.btn-outline-secondary {
  border-color: rgba(100,116,139,0.35);
  color: #334155;
}
.btn-outline-secondary:hover {
  background: rgba(100,116,139,0.08);
}

.btn-ui {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 42px;
  padding: 0 16px;
  border-radius: 12px;
  border: 1px solid transparent;
  font-size: 0.88rem;
  font-weight: 700;
  line-height: 1;
  letter-spacing: 0.01em;
  transition: transform 0.16s ease, background-color 0.16s ease, border-color 0.16s ease, color 0.16s ease, box-shadow 0.16s ease;
}

.btn-ui:hover {
  transform: translateY(-1px);
}

.btn-ui:disabled,
.btn-ui.disabled {
  opacity: 0.72;
  pointer-events: none;
  transform: none;
}

.btn-ui--primary {
  color: #fff;
  background: var(--brand-primary);
  box-shadow: 0 10px 20px rgba(237,70,47,0.18);
}

.btn-ui--primary:hover,
.btn-ui--primary:focus {
  color: #fff;
  filter: brightness(1.02);
}

.btn-ui--neutral {
  color: var(--ink);
  background: #fff;
  border-color: rgba(100,116,139,0.22);
  box-shadow: 0 8px 18px rgba(15,23,42,0.05);
}

.btn-ui--neutral:hover,
.btn-ui--neutral:focus {
  color: var(--ink);
  background: #f8fafc;
  border-color: rgba(100,116,139,0.3);
}

.btn-ui--ghost {
  color: var(--brand-primary);
  background: rgba(237,70,47,0.08);
  border-color: rgba(237,70,47,0.16);
}

.btn-ui--ghost:hover,
.btn-ui--ghost:focus {
  color: var(--brand-primary);
  background: rgba(237,70,47,0.12);
  border-color: rgba(237,70,47,0.24);
}

.btn-ui--danger {
  color: #fff;
  background: #dc2626;
  box-shadow: 0 10px 20px rgba(220,38,38,0.18);
}

.btn-ui--danger:hover,
.btn-ui--danger:focus {
  color: #fff;
  filter: brightness(1.02);
}

.btn-ui--sm {
  min-height: 36px;
  padding: 0 12px;
  font-size: 0.8rem;
  border-radius: 10px;
}
.alert { border-radius: 14px; }
.modal-content {
  border-radius: 18px;
  border: 1px solid var(--line);
  background: rgba(255, 250, 246, 0.98);
  box-shadow: var(--shadow-lift);
}
.modal-header {
  border-bottom: 1px solid var(--line);
  background: rgba(255, 246, 240, 0.88);
}
.modal-footer {
  border-top: 1px solid var(--line);
  background: rgba(255, 248, 242, 0.7);
}

.swal2-popup.app-swal-toast {
  border-radius: 16px;
  border: 1px solid var(--line);
  background: rgba(255, 250, 246, 0.98);
  box-shadow: var(--shadow-lift);
}

.swal2-popup.app-swal-toast .swal2-title,
.swal2-title.app-swal-toast__title {
  color: var(--ink);
  font-size: 0.92rem;
  font-weight: 800;
}

.form-control,
.form-select {
  border-radius: 14px;
  border: 1px solid var(--line);
  background: #fff;
}
.form-control:focus,
.form-select:focus {
  border-color: rgba(237,70,47,0.6);
  box-shadow: 0 0 0 3px rgba(237,70,47,0.15);
}

/* =========================
   Cards + Helpers
   ========================= */

.app-card {
  background: rgba(255,255,255,0.95);
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-soft);
}

.app-soft {
  background: rgba(237,70,47,0.06);
  border: 1px dashed rgba(237,70,47,0.25);
  border-radius: 16px;
}

.app-hero {
  position: relative;
  padding: 22px;
  border-radius: 22px;
  background: rgba(237,70,47,0.07);
  border: 1px solid rgba(237,70,47,0.16);
  overflow: hidden;
}
.app-hero::after {
  content: "";
  position: absolute;
  width: 220px;
  height: 220px;
  right: -60px;
  top: -80px;
  background: radial-gradient(circle, rgba(245,158,11,0.28), transparent 70%);
}
.app-hero h1 { font-size: 2rem; margin-bottom: 6px; }
.app-hero p { color: var(--muted); margin: 0; }

.stat-card {
  border-radius: 16px;
  background: #fff;
  border: 1px solid var(--line);
  padding: 14px 16px;
  box-shadow: 0 12px 30px rgba(15,23,42,0.06);
}
.stat-value { font-size: 1.35rem; font-weight: 700; }
.stat-label { font-size: 0.85rem; color: var(--muted); }

/* =========================
   Dashboard Cards
   ========================= */

.course-card {
  position: relative;
  overflow: hidden;
  animation: fadeUp 0.45s ease;
}
.course-card::after {
  content: "";
  position: absolute;
  inset: auto -40% -50% auto;
  width: 200px;
  height: 200px;
  background: radial-gradient(circle, rgba(237,70,47,0.12), transparent 70%);
}
.course-thumb {
  width: 128px;
  height: 84px;
  border-radius: 14px;
  overflow: hidden;
  background: #eef2f7;
  border: 1px solid var(--line);
}
.course-thumb img { width: 100%; height: 100%; object-fit: cover; }
.course-meta { color: var(--muted); font-size: 0.9rem; }
.course-progress {
  height: 8px;
  border-radius: 999px;
  background: #e2e8f0;
  overflow: hidden;
}
.course-progress .progress-bar {
  background: var(--brand-primary);
  border-radius: 999px;
}
.progress-pill {
  background: rgba(237,70,47,0.12);
  color: var(--brand-primary);
  padding: 2px 10px;
  border-radius: 999px;
  font-size: 0.8rem;
  font-weight: 700;
}

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

.app-hero { animation: fadeUp 0.5s ease; }

/* =========================
   Tables
   ========================= */

.table.app-table > :not(caption) > * > * {
  padding: 14px 14px;
  border-bottom: 1px solid var(--line);
}
.table.app-table thead th {
  color: #0f172a;
  font-weight: 700;
  background: #fff8f5;
}
.dataTables_wrapper .dataTables_filter input {
  border-radius: 12px;
  border: 1px solid var(--line);
  padding: 6px 10px;
}
.dataTables_wrapper .dataTables_length select {
  border-radius: 12px;
  border: 1px solid var(--line);
  padding: 6px 10px;
}

.form-section {
  border: 1px solid var(--line);
  border-radius: 18px;
  padding: 16px;
  background: #fff;
}
.form-section + .form-section { margin-top: 16px; }
.section-title { font-weight: 700; margin-bottom: 8px; }
.input-hint { font-size: 0.85rem; color: var(--muted); }
.chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 6px 10px;
  border-radius: 999px;
  background: rgba(237,70,47,0.1);
  color: var(--brand-primary);
  font-size: 0.8rem;
  font-weight: 700;
}
.badge-soft {
  background: rgba(237,70,47,0.12);
  color: var(--brand-primary);
  border-radius: 10px;
  padding: 4px 8px;
  font-size: 0.8rem;
}

.stepper {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
}
.step {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 8px 12px;
  border-radius: 12px;
  border: 1px solid var(--line);
  background: #fff;
  font-size: 0.9rem;
  color: var(--muted);
}
.step.is-active {
  border-color: rgba(237,70,47,0.45);
  background: rgba(237,70,47,0.08);
  color: var(--brand-primary);
  font-weight: 700;
}

/* =========================
   Builder
   ========================= */

.builder-fluid { width: 100%; }
.builder-fluid .container-fluid-inner { max-width: 1600px; margin: 0 auto; }
.builder-fluid.px-0 { padding-left: 0; padding-right: 0; }
@media (max-width: 575px) {
  .builder-fluid .container-fluid-inner { padding-left: 12px; padding-right: 12px; }
}

.builder-fluid.editor-expanded .builder-tree-column { display: none; }
.builder-fluid.editor-expanded .editor-column { flex: 0 0 100%; max-width: 100%; }
.builder-fluid .builder-tree-column,
.builder-fluid .editor-column { transition: all 0.18s ease; }

.builder-tree {
  border: 1px solid var(--line);
  border-radius: 16px;
  padding: 10px;
  background: rgba(255,255,255,0.7);
  max-height: 70vh;
  overflow: auto;
}
.builder-toolbar {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}
.builder-search {
  min-width: 200px;
  max-width: 260px;
  flex: 1 1 auto;
}
.builder-hint {
  color: var(--muted);
  font-size: 0.85rem;
}
.sticky-actions {
  position: sticky;
  bottom: 12px;
  background: #fff;
  padding: 10px;
  border-radius: 14px;
  border: 1px solid var(--line);
  box-shadow: 0 12px 30px rgba(15,23,42,0.08);
}
.builder-list { list-style: none; padding-left: 14px; margin: 0; }
.builder-item { margin: 6px 0; }
.builder-row {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 10px;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: #fff;
}
.builder-handle {
  cursor: grab;
  width: 26px;
  height: 26px;
  border-radius: 10px;
  display: grid;
  place-items: center;
  border: 1px solid var(--line);
  color: var(--muted);
  flex: 0 0 auto;
}
.builder-title {
  display: flex;
  align-items: center;
  gap: 6px;
  flex: 1 1 auto;
  min-width: 0;
}
.builder-title .text-truncate { max-width: 220px; }
.builder-item.is-selected > .builder-row {
  border-color: rgba(237,70,47,0.55);
  background: linear-gradient(135deg, rgba(237,70,47,0.12), rgba(245,158,11,0.08));
}

/* =========================
   Choice Cards
   ========================= */

.app-choice {
  width: 100%;
  text-align: left;
  border: 1px solid var(--line);
  border-radius: 16px;
  padding: 14px 14px;
  background: #fff;
  transition: transform 0.08s ease, border-color 0.08s ease, box-shadow 0.08s ease;
}
.app-choice:hover {
  transform: translateY(-1px);
  border-color: rgba(237,70,47,0.35);
  box-shadow: 0 14px 28px rgba(16,24,40,0.08);
}
.app-choice.is-active {
  border-color: rgba(237,70,47,0.55);
  background: rgba(237,70,47,0.07);
}
.app-choice-ico {
  width: 44px;
  height: 44px;
  border-radius: 16px;
  display: grid;
  place-items: center;
  color: #fff;
  background: var(--brand-primary);
  box-shadow: 0 14px 34px rgba(0,0,0,0.12);
}

/* =========================
   Tawk Launcher
   ========================= */

.app-tawk-wrap {
  position: fixed;
  right: 18px;
  bottom: calc(18px + env(safe-area-inset-bottom));
  z-index: 1085;
}

.app-tawk-wrap.is-study-mobile {
  bottom: calc(100px + env(safe-area-inset-bottom));
}

.app-tawk-launcher {
  border: 0;
  min-height: 52px;
  min-width: 52px;
  width: 52px;
  padding: 0;
  border-radius: 16px;
  color: #fff;
  background: var(--brand-primary);
  box-shadow: 0 14px 28px rgba(237,70,47,0.28);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0;
  font-weight: 800;
  font-size: 0.86rem;
  letter-spacing: 0.01em;
  position: relative;
  overflow: hidden;
  transition: transform 0.16s ease, box-shadow 0.16s ease, filter 0.16s ease, background 0.16s ease;
}

.app-tawk-launcher:hover,
.app-tawk-launcher:focus-visible {
  color: #fff;
  transform: translateY(-1px);
  filter: brightness(1.01);
}

.app-tawk-launcher.is-open {
  background: #2f7a44;
  box-shadow: 0 14px 28px rgba(22, 163, 74, 0.28);
}

.app-tawk-launcher.is-loading {
  opacity: 0.88;
}

.app-tawk-launcher.is-loading .app-tawk-launcher__pulse {
  animation: tawk-pulse 1.4s ease-in-out infinite;
}

.app-tawk-launcher__pulse {
  width: 7px;
  height: 7px;
  border-radius: 999px;
  background: var(--brand-accent);
  box-shadow: 0 0 0 0 rgba(254, 204, 0, 0.7);
}

.app-tawk-launcher__icon {
  width: 30px;
  height: 30px;
  border-radius: 999px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: rgba(255,255,255,0.18);
  border: 1px solid rgba(255,255,255,0.24);
  font-size: 0.84rem;
}

.app-tawk-launcher__label {
  white-space: nowrap;
  display: none;
}

.app-tawk-launcher__badge {
  min-width: 20px;
  height: 20px;
  border-radius: 999px;
  background: #ef4444;
  color: #fff;
  border: 1px solid rgba(255,255,255,0.44);
  padding: 0 5px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 0.7rem;
  font-weight: 800;
  line-height: 1;
  position: absolute;
  top: -4px;
  right: -4px;
}

.app-tawk-launcher__pulse {
  display: none;
}

@keyframes tawk-pulse {
  0% {
    transform: scale(0.85);
    box-shadow: 0 0 0 0 rgba(254, 204, 0, 0.65);
  }
  70% {
    transform: scale(1);
    box-shadow: 0 0 0 9px rgba(254, 204, 0, 0);
  }
  100% {
    transform: scale(0.9);
    box-shadow: 0 0 0 0 rgba(254, 204, 0, 0);
  }
}

@media (max-width: 991px) {
  .app-tawk-wrap {
    right: 12px;
    bottom: calc(14px + env(safe-area-inset-bottom));
  }

  .app-tawk-launcher {
    min-width: 52px;
    width: 52px;
    min-height: 52px;
    padding: 0;
    gap: 0;
    border-radius: 16px;
  }

  .app-tawk-launcher__label,
  .app-tawk-launcher__pulse {
    display: none;
  }

  .app-tawk-launcher__icon {
    width: 30px;
    height: 30px;
  }

  .app-tawk-launcher__badge {
    position: absolute;
    top: -4px;
    right: -4px;
  }
}

/* =========================
   Utilities
   ========================= */

.text-muted { color: var(--muted) !important; }

@media (max-width: 991px) {
  .app-topbar .app-user-meta { display: none !important; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation: none !important;
    transition: none !important;
  }
}
