/* UX Mate admin — design system.
   Keeps the class names the existing tabs already use (.btn, .section, .stat-card, .table-wrap,
   .filter-tab, .badge, .ai-bar …) so every feature picks up the new look, and adds the shell. */

:root {
  color-scheme: light dark;
  --bg: #f5f4fa; --bg-2: #ecebf4; --surface: #ffffff; --surface-2: #f3f1fa;
  --line: rgb(20 22 40 / .1); --line-2: rgb(20 22 40 / .2);
  --text: #1a1c2c; --muted: #5d627a;
  --brand: #6a47e6; --brand-2: #5836cf; --brand-ink: #5836cf; --brand-soft: rgb(106 71 230 / .1);
  --ok: #0c8a57; --warn: #b86e00; --bad: #c62828; --reward: #b86e00;
  --shadow: 0 18px 40px -26px rgb(20 22 40 / .35);
  --radius: 16px; --side: 264px;
  --font: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', system-ui, sans-serif;
  --mono: ui-monospace, 'SF Mono', Menlo, Consolas, monospace;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0b0c14; --bg-2: #10121c; --surface: #151826; --surface-2: #1d2133;
    --line: rgb(255 255 255 / .09); --line-2: rgb(255 255 255 / .2);
    --text: #eef0f8; --muted: #a3abc2;
    --brand: #8b6cff; --brand-2: #7655f0; --brand-ink: #b9a8ff; --brand-soft: rgb(139 108 255 / .16);
    --ok: #3ddc97; --warn: #ffb938; --bad: #ff7a7a; --reward: #ffb938;
    --shadow: 0 18px 40px -26px rgb(0 0 0 / .8);
  }
}

*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html { -webkit-text-size-adjust: 100%; }
body { font: 400 15.5px/1.55 var(--font); background: var(--bg); color: var(--text); min-height: 100vh; -webkit-font-smoothing: antialiased; }
a { color: var(--brand-ink); text-decoration: none; }
a:hover { text-decoration: underline; }
:focus-visible { outline: 3px solid var(--brand); outline-offset: 2px; border-radius: 6px; }
h1, h2, h3 { letter-spacing: -.01em; line-height: 1.25; }

/* ---------- Login ---------- */
.login-wrap { display: grid; place-items: center; min-height: 100vh; padding: 24px; background: radial-gradient(900px 500px at 80% -10%, var(--brand-soft), transparent 60%), var(--bg); }
.login-card { width: min(100%, 420px); background: var(--surface); border: 1px solid var(--line); border-radius: 24px; padding: 40px 34px; box-shadow: var(--shadow); text-align: center; }
.login-card .logo { width: 52px; height: 52px; margin: 0 auto 18px; border-radius: 16px; display: grid; place-items: center; font: 800 20px/1 var(--font); color: #fff; background: linear-gradient(135deg, var(--brand), var(--brand-2)); }
.login-card h1 { font-size: 24px; margin-bottom: 6px; }
.login-card p { color: var(--muted); font-size: 15px; margin-bottom: 26px; }
.login-card .or { margin: 22px 0 14px; color: var(--muted); font-size: 13px; }
.login-card details { text-align: left; margin-top: 6px; }
.login-card summary { cursor: pointer; color: var(--muted); font-size: 14px; text-align: center; list-style: none; }
.login-card summary::-webkit-details-marker { display: none; }
.login-card form { margin-top: 16px; }
.error-msg { background: color-mix(in srgb, var(--bad) 12%, transparent); border: 1px solid var(--bad); border-radius: 10px; padding: 10px 14px; color: var(--bad); font-size: 14px; margin-bottom: 18px; text-align: left; }
.g-btn { display: flex; align-items: center; justify-content: center; gap: 12px; width: 100%; min-height: 52px; border-radius: 14px; border: 1.5px solid var(--line-2); background: var(--surface-2); color: var(--text); font: 600 16px/1 var(--font); cursor: pointer; transition: border-color .2s, transform .2s; }
.g-btn:hover { border-color: var(--brand); transform: translateY(-1px); }
.g-btn:disabled { opacity: .6; cursor: wait; }

/* ---------- Shell ---------- */
.shell { display: grid; grid-template-columns: var(--side) minmax(0, 1fr); min-height: 100vh; }
.sidebar { position: sticky; top: 0; height: 100vh; overflow-y: auto; padding: 22px 16px; background: var(--surface); border-right: 1px solid var(--line); display: flex; flex-direction: column; gap: 6px; }
.brand { display: flex; align-items: center; gap: 12px; padding: 6px 10px 22px; font: 700 18px/1 var(--font); color: var(--text); }
.brand:hover { text-decoration: none; }
.brand i { width: 36px; height: 36px; border-radius: 11px; display: grid; place-items: center; font: 800 14px/1 var(--font); font-style: normal; color: #fff; background: linear-gradient(135deg, var(--brand), var(--brand-2)); }
.brand small { display: block; font: 500 12px/1.2 var(--font); color: var(--muted); margin-top: 3px; }
.nav-group { margin-top: 16px; padding: 0 10px 6px; font: 700 11px/1 var(--font); letter-spacing: .12em; text-transform: uppercase; color: var(--muted); }
.nav a { display: flex; align-items: center; gap: 12px; padding: 11px 12px; border-radius: 12px; color: var(--text); font-weight: 500; font-size: 15.5px; transition: background .15s; }
.nav a:hover { background: var(--surface-2); text-decoration: none; }
.nav a.active { background: var(--brand-soft); color: var(--brand-ink); font-weight: 700; }
.nav a .ico { width: 22px; text-align: center; font-size: 17px; }
.nav a .count { margin-left: auto; font-size: 12px; font-weight: 700; padding: 2px 8px; border-radius: 99px; background: var(--surface-2); color: var(--muted); }
.side-foot { margin-top: auto; padding: 14px 10px 0; border-top: 1px solid var(--line); font-size: 13.5px; color: var(--muted); display: grid; gap: 10px; }
.side-foot b { color: var(--text); display: block; word-break: break-all; font-weight: 600; }
.side-foot .linkbtn { background: none; border: 0; padding: 0; font: inherit; color: var(--brand-ink); cursor: pointer; text-align: left; }
.main { min-width: 0; }
.page { max-width: 1180px; margin: 0 auto; padding: 32px clamp(16px, 3vw, 40px) 64px; }
.page-head { display: flex; flex-wrap: wrap; align-items: flex-end; justify-content: space-between; gap: 14px; margin-bottom: 26px; }
.page-head h1 { font-size: clamp(24px, 3vw, 32px); }
.page-head p { color: var(--muted); margin-top: 4px; }
.mobilebar { display: none; }
@media (max-width: 900px) {
  .shell { display: block; }
  .mobilebar { display: flex; align-items: center; justify-content: space-between; padding: 12px 16px; background: var(--surface); border-bottom: 1px solid var(--line); position: sticky; top: 0; z-index: 30; }
  .mobilebar button { background: var(--surface-2); border: 1px solid var(--line); border-radius: 10px; padding: 8px 14px; color: var(--text); font: 600 14px var(--font); cursor: pointer; }
  .sidebar { position: fixed; inset: 0 auto 0 0; width: min(86vw, 320px); z-index: 40; transform: translateX(-102%); transition: transform .25s; box-shadow: var(--shadow); }
  body.nav-open .sidebar { transform: none; }
  body.nav-open::after { content: ''; position: fixed; inset: 0; background: rgb(0 0 0 / .5); z-index: 35; }
}

/* ---------- Controls ---------- */
label { display: block; font-size: 14px; font-weight: 600; margin-bottom: 6px; }
input[type=text], input[type=password], input[type=email], input[type=number], input[type=url], input[type=datetime-local], textarea, select {
  width: 100%; padding: 11px 14px; border: 1.5px solid var(--line-2); border-radius: 12px; font: inherit; font-size: 15px; color: var(--text); background: var(--surface-2); margin-bottom: 16px; transition: border-color .2s, box-shadow .2s;
}
input:focus, textarea:focus, select:focus { outline: none; border-color: var(--brand); box-shadow: 0 0 0 3px var(--brand-soft); }
textarea { resize: vertical; min-height: 120px; }
textarea.code { font-family: var(--mono); font-size: 14px; line-height: 1.6; min-height: 260px; }
input[type=checkbox] { width: 18px; height: 18px; accent-color: var(--brand); }
.check { display: flex; align-items: center; gap: 10px; margin-bottom: 16px; font-weight: 500; }
.check input { margin: 0; }
.field-row { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 0 18px; }
.hint { font-size: 13px; color: var(--muted); margin: -10px 0 16px; }

.btn { display: inline-flex; align-items: center; justify-content: center; gap: 8px; min-height: 44px; padding: 10px 20px; border-radius: 12px; font: 600 15px/1.2 var(--font); border: 1.5px solid transparent; cursor: pointer; text-decoration: none; transition: transform .15s, box-shadow .2s, background .2s, border-color .2s; }
.btn:hover { text-decoration: none; transform: translateY(-1px); }
.btn:active { transform: none; }
.btn-primary { background: linear-gradient(180deg, var(--brand), var(--brand-2)); color: #fff; box-shadow: 0 8px 20px -10px var(--brand); }
.btn-dark { background: var(--text); color: var(--bg); }
.btn-danger { background: color-mix(in srgb, var(--bad) 14%, transparent); border-color: var(--bad); color: var(--bad); min-height: 36px; padding: 6px 14px; font-size: 13.5px; }
.btn-ghost { background: transparent; color: var(--text); border-color: var(--line-2); min-height: 36px; padding: 6px 14px; font-size: 13.5px; }
.btn-ghost:hover { border-color: var(--brand); background: var(--brand-soft); }
.btn-sm { min-height: 36px; padding: 6px 14px; font-size: 13.5px; }

/* ---------- Cards, tables, badges ---------- */
.stats, .kpis { display: grid; grid-template-columns: repeat(auto-fit, minmax(190px, 1fr)); gap: 16px; margin-bottom: 26px; }
.stat-card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 20px 22px; }
.stat-card .num { font: 700 32px/1.1 var(--font); color: var(--brand-ink); }
.stat-card .lbl { font-size: 14px; color: var(--muted); margin-top: 6px; }
.stat-card .sub { font-size: 13px; color: var(--ok); margin-top: 4px; }

.section { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); margin-bottom: 26px; overflow: hidden; }
.section-header { padding: 18px 24px; border-bottom: 1px solid var(--line); display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; }
.section-header h2 { font-size: 18px; }
.compose { padding: 24px; }
.compose h3 { font-size: 16px; margin: 6px 0 14px; }

.filter-tabs { display: flex; gap: 6px; flex-wrap: wrap; }
.filter-tab { padding: 8px 16px; border-radius: 99px; font-size: 14px; font-weight: 600; color: var(--muted); border: 1px solid transparent; }
.filter-tab:hover { background: var(--surface-2); text-decoration: none; color: var(--text); }
.filter-tab.active { background: var(--brand-soft); color: var(--brand-ink); border-color: color-mix(in srgb, var(--brand) 40%, transparent); }

.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: 14.5px; }
th { text-align: left; padding: 12px 18px; border-bottom: 1px solid var(--line); color: var(--muted); font-weight: 600; font-size: 13px; text-transform: uppercase; letter-spacing: .05em; white-space: nowrap; }
td { padding: 14px 18px; border-bottom: 1px solid var(--line); vertical-align: middle; }
tr:last-child td { border-bottom: none; }
tbody tr:hover td { background: var(--surface-2); }
.badge { display: inline-block; padding: 4px 11px; border-radius: 99px; font-size: 12px; font-weight: 700; }
.badge-active { background: color-mix(in srgb, var(--ok) 16%, transparent); color: var(--ok); }
.badge-unsub, .badge-draft { background: var(--surface-2); color: var(--muted); }
.badge-warn { background: color-mix(in srgb, var(--warn) 18%, transparent); color: var(--warn); }
.badge-bad { background: color-mix(in srgb, var(--bad) 16%, transparent); color: var(--bad); }
.empty { text-align: center; padding: 52px 20px; color: var(--muted); }
.muted { color: var(--muted); font-size: 14px; }
.mono { font-family: var(--mono); font-size: 13.5px; }
.actions { display: flex; gap: 8px; flex-wrap: wrap; }
.actions form { display: inline; }

.feedback { padding: 14px 18px; border-radius: 12px; font-size: 15px; margin-bottom: 22px; background: color-mix(in srgb, var(--ok) 13%, transparent); border: 1px solid var(--ok); color: var(--ok); }
.feedback.err { background: color-mix(in srgb, var(--bad) 12%, transparent); border-color: var(--bad); color: var(--bad); }

/* ---------- Existing tab widgets ---------- */
.ai-bar { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; background: var(--brand-soft); border: 1px solid color-mix(in srgb, var(--brand) 30%, transparent); border-radius: 14px; padding: 14px; margin-bottom: 18px; }
.ai-bar .ai-label { font-size: 12px; font-weight: 700; color: var(--brand-ink); text-transform: uppercase; letter-spacing: .08em; margin-right: 4px; }
.ai-btn { background: var(--surface); border: 1px solid var(--line-2); color: var(--text); border-radius: 10px; padding: 8px 14px; font-size: 14px; font-weight: 600; cursor: pointer; }
.ai-btn:hover { background: var(--brand); color: #fff; border-color: var(--brand); }
.ai-btn:disabled { opacity: .5; cursor: wait; }
.ai-note { font-size: 13px; color: var(--muted); width: 100%; }
.ai-prompt-row { display: flex; gap: 8px; width: 100%; }
.ai-prompt-row input { margin: 0; }
#editor { background: var(--surface); min-height: 320px; color: var(--text); }
.ql-toolbar.ql-snow, .ql-container.ql-snow { border-color: var(--line-2) !important; }
.ql-toolbar.ql-snow { border-radius: 12px 12px 0 0; background: var(--surface-2); }
.ql-container.ql-snow { border-radius: 0 0 12px 12px; font-size: 16px; }
.ql-snow .ql-stroke { stroke: var(--muted) !important; } .ql-snow .ql-fill { fill: var(--muted) !important; } .ql-snow .ql-picker { color: var(--muted) !important; }
.compose-actions { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; margin-top: 20px; }
.schedule-inline { display: flex; gap: 8px; align-items: center; }
.schedule-inline input { margin: 0; width: auto; }
.chart-title { font-size: 12px; font-weight: 700; color: var(--muted); text-transform: uppercase; letter-spacing: .08em; margin-bottom: 8px; }
.apexcharts-tooltip { border: 1px solid var(--line-2) !important; }
@media (max-width: 720px) { .chart-2col { grid-template-columns: 1fr !important; } }
.modal-back { position: fixed; inset: 0; background: rgb(0 0 0 / .55); display: none; align-items: center; justify-content: center; padding: 20px; z-index: 60; }
.modal-back.open { display: flex; }
.modal { background: var(--surface); color: var(--text); border-radius: 18px; max-width: 700px; width: 100%; max-height: 90vh; overflow: auto; }
.modal-head { padding: 14px 20px; border-bottom: 1px solid var(--line); display: flex; justify-content: space-between; align-items: center; }
.modal-body iframe { width: 100%; border: 0; height: 70vh; background: #fff; }

/* ---------- Course CMS ---------- */
.lesson-list { list-style: none; }
.lesson-list li { display: grid; grid-template-columns: 70px minmax(0, 1fr) auto; gap: 14px; align-items: center; padding: 14px 24px; border-bottom: 1px solid var(--line); margin: 0; }
.lesson-list li:last-child { border-bottom: 0; }
.lesson-list input[type=number] { margin: 0; padding: 8px 10px; text-align: center; }
.lesson-list .t { font-weight: 600; }
.lesson-list .m { font-size: 13px; color: var(--muted); }
.q-card { border: 1px solid var(--line); border-radius: 14px; padding: 18px 20px; margin-bottom: 14px; background: var(--surface-2); }
.q-card h4 { font-size: 15px; margin-bottom: 10px; }
.q-card ol { margin: 8px 0 0 20px; color: var(--muted); font-size: 14.5px; }
.q-card li.ok { color: var(--ok); font-weight: 600; }
.crumbs { font-size: 14px; color: var(--muted); margin-bottom: 14px; }
.two-col { display: grid; grid-template-columns: minmax(0, 1.5fr) minmax(0, 1fr); gap: 26px; align-items: start; }
@media (max-width: 1000px) { .two-col { grid-template-columns: 1fr; } }
