/* ============ Defincho Brand UI ============ */
:root {
  --bg: #0f1226;
  --bg2: #171a35;
  --card: #ffffff;
  --ink: #1a1d33;
  --ink2: #5b6080;
  --line: #e7e9f4;
  --brand: #5b5bd6;
  --brand2: #7c3aed;
  --brand-soft: #eeeefc;
  --accent: #14b8a6;
  --amber: #f59e0b;
  --red: #ef4444;
  --green: #22c55e;
  --grad: linear-gradient(135deg, #5b5bd6 0%, #7c3aed 55%, #a855f7 100%);
  --shadow: 0 10px 30px rgba(35, 31, 90, .10);
  --radius: 16px;
  font-size: 16px;
}
* { box-sizing: border-box; margin: 0; padding: 0; }
html, body { height: 100%; }
body {
  font-family: 'Inter', 'Segoe UI', system-ui, -apple-system, sans-serif;
  background: #f3f4fb;
  color: var(--ink);
  -webkit-font-smoothing: antialiased;
}
a { color: var(--brand); text-decoration: none; }
button { font-family: inherit; }

/* ---- Login screen ---- */
.login-wrap {
  min-height: 100vh; display: flex; align-items: center; justify-content: center;
  background: radial-gradient(1200px 700px at 10% -10%, #2d2a6e 0%, transparent 60%),
              radial-gradient(1000px 600px at 110% 110%, #4c1d95 0%, transparent 55%), var(--bg);
  padding: 24px;
}
.login-card {
  width: 100%; max-width: 430px; background: var(--card); border-radius: 24px;
  padding: 38px 34px; box-shadow: 0 30px 80px rgba(0,0,0,.35); animation: pop .5s cubic-bezier(.2,.9,.3,1.2);
}
@keyframes pop { from { transform: translateY(24px) scale(.97); opacity: 0 } to { transform: none; opacity: 1 } }
.logo-row { display: flex; align-items: center; gap: 14px; margin-bottom: 8px; }
.logo-badge {
  width: 54px; height: 54px; border-radius: 16px; background: var(--grad); color: #fff;
  display: flex; align-items: center; justify-content: center; font-weight: 800; font-size: 26px;
  box-shadow: 0 8px 20px rgba(124, 58, 237, .4);
}
.logo-name { font-size: 26px; font-weight: 800; letter-spacing: .5px; }
.logo-name span { background: var(--grad); -webkit-background-clip: text; background-clip: text; color: transparent; }
.login-sub { color: var(--ink2); margin: 6px 0 26px; font-size: 14.5px; }
.field { margin-bottom: 16px; }
.field label { display: block; font-size: 13px; font-weight: 600; color: var(--ink2); margin-bottom: 7px; }
.field input, .field select, .field textarea {
  width: 100%; padding: 13px 15px; border: 1.5px solid var(--line); border-radius: 12px;
  font-size: 15px; font-family: inherit; transition: border .15s, box-shadow .15s; background: #fafbff; color: var(--ink);
}
.field input:focus, .field select:focus, .field textarea:focus {
  outline: none; border-color: var(--brand); box-shadow: 0 0 0 4px rgba(91, 91, 214, .13); background: #fff;
}
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  padding: 13px 22px; border: none; border-radius: 12px; font-size: 15px; font-weight: 700;
  cursor: pointer; transition: transform .12s, box-shadow .15s, opacity .15s; user-select: none;
}
.btn:active { transform: scale(.97); }
.btn-primary { background: var(--grad); color: #fff; box-shadow: 0 8px 20px rgba(124, 58, 237, .35); width: 100%; }
.btn-primary:hover { box-shadow: 0 10px 26px rgba(124, 58, 237, .5); }
.btn-ghost { background: var(--brand-soft); color: var(--brand); }
.btn-danger { background: #fee2e2; color: var(--red); }
.btn-sm { padding: 8px 14px; font-size: 13px; border-radius: 10px; }
.err { background: #fee2e2; color: #b91c1c; padding: 11px 14px; border-radius: 10px; font-size: 13.5px; margin-bottom: 14px; display: none; }
.hint { font-size: 12.5px; color: var(--ink2); margin-top: 18px; text-align: center; line-height: 1.7; }
.hint code { background: var(--brand-soft); color: var(--brand); padding: 2px 7px; border-radius: 6px; font-size: 12px; }

/* ---- App shell ---- */
.shell { display: flex; min-height: 100vh; }
.sidebar {
  width: 258px; background: var(--bg); color: #cfd2ee; position: fixed; inset: 0 auto 0 0;
  display: flex; flex-direction: column; z-index: 50; transition: transform .25s ease;
}
.sidebar .logo-row { padding: 22px 20px 14px; }
.sidebar .logo-name { color: #fff; font-size: 21px; }
.nav { flex: 1; overflow-y: auto; padding: 8px 12px 20px; }
.nav-label { font-size: 10.5px; text-transform: uppercase; letter-spacing: 1.4px; color: #7b7fae; margin: 16px 10px 6px; font-weight: 700; }
.nav-item {
  display: flex; align-items: center; gap: 11px; padding: 10.5px 12px; border-radius: 11px;
  color: #cfd2ee; font-size: 14px; font-weight: 500; cursor: pointer; margin-bottom: 2px; transition: background .13s; border: none; width: 100%; background: none; text-align: left;
}
.nav-item:hover { background: rgba(255,255,255,.07); color: #fff; }
.nav-item.active { background: var(--grad); color: #fff; font-weight: 700; box-shadow: 0 6px 16px rgba(124,58,237,.35); }
.nav-item .ico { font-size: 17px; width: 22px; text-align: center; }
.nav-item .pill { margin-left: auto; background: var(--red); color: #fff; font-size: 10.5px; font-weight: 800; padding: 2px 7px; border-radius: 99px; }
.side-foot { padding: 14px 18px; border-top: 1px solid rgba(255,255,255,.08); font-size: 12.5px; color: #8f93c0; }

.main { flex: 1; margin-left: 258px; min-width: 0; }
.topbar {
  position: sticky; top: 0; z-index: 40; background: rgba(243,244,251,.85); backdrop-filter: blur(10px);
  display: flex; align-items: center; gap: 12px; padding: 14px 26px; border-bottom: 1px solid var(--line);
}
.burger { display: none; background: #fff; border: 1px solid var(--line); border-radius: 10px; width: 40px; height: 40px; font-size: 18px; cursor: pointer; }
.top-title { font-size: 18px; font-weight: 800; }
.top-spacer { flex: 1; }
.bell { position: relative; background: #fff; border: 1px solid var(--line); width: 40px; height: 40px; border-radius: 12px; font-size: 17px; cursor: pointer; }
.bell .dot { position: absolute; top: -5px; right: -5px; background: var(--red); color: #fff; font-size: 10px; font-weight: 800; min-width: 18px; height: 18px; border-radius: 99px; display: flex; align-items: center; justify-content: center; padding: 0 4px; }
.avatar { width: 40px; height: 40px; border-radius: 12px; background: var(--grad); color: #fff; display: flex; align-items: center; justify-content: center; font-weight: 800; font-size: 15px; }
.who { line-height: 1.15; }
.who b { font-size: 13.5px; display: block; }
.who small { color: var(--ink2); font-size: 11.5px; }

.content { padding: 26px; max-width: 1200px; }
.view { display: none; animation: fadein .3s ease; }
.view.active { display: block; }
@keyframes fadein { from { opacity: 0; transform: translateY(8px) } to { opacity: 1; transform: none } }

/* ---- Cards / grids ---- */
.grid { display: grid; gap: 16px; }
.g4 { grid-template-columns: repeat(4, 1fr); }
.g3 { grid-template-columns: repeat(3, 1fr); }
.g2 { grid-template-columns: repeat(2, 1fr); }
.card { background: var(--card); border-radius: var(--radius); padding: 20px; box-shadow: var(--shadow); border: 1px solid #f0f1fa; }
.card h3 { font-size: 15px; margin-bottom: 12px; display: flex; align-items: center; gap: 8px; }
.stat { display: flex; flex-direction: column; gap: 4px; }
.stat .k { font-size: 12.5px; color: var(--ink2); font-weight: 600; }
.stat .v { font-size: 26px; font-weight: 800; letter-spacing: -.5px; }
.stat .sub { font-size: 12px; color: var(--ink2); }
.stat-ico { width: 42px; height: 42px; border-radius: 12px; display: flex; align-items: center; justify-content: center; font-size: 20px; margin-bottom: 10px; }
.hero {
  background: var(--grad); border-radius: 20px; color: #fff; padding: 26px 28px; margin-bottom: 20px;
  position: relative; overflow: hidden; box-shadow: 0 16px 40px rgba(124,58,237,.35);
}
.hero::after { content: ''; position: absolute; right: -60px; top: -60px; width: 220px; height: 220px; border-radius: 50%; background: rgba(255,255,255,.12); }
.hero::before { content: ''; position: absolute; right: 60px; bottom: -80px; width: 160px; height: 160px; border-radius: 50%; background: rgba(255,255,255,.09); }
.hero h1 { font-size: 24px; margin-bottom: 6px; }
.hero p { opacity: .92; font-size: 14px; }

.quick { display: grid; grid-template-columns: repeat(5, 1fr); gap: 12px; margin: 18px 0 22px; }
.quick button {
  background: #fff; border: 1px solid #f0f1fa; border-radius: 14px; padding: 14px 8px; cursor: pointer;
  display: flex; flex-direction: column; align-items: center; gap: 7px; font-size: 12px; font-weight: 700; color: var(--ink);
  box-shadow: var(--shadow); transition: transform .13s, box-shadow .15s;
}
.quick button:hover { transform: translateY(-3px); box-shadow: 0 14px 30px rgba(35,31,90,.16); }
.quick .qi { font-size: 22px; }

/* ---- Tables ---- */
.tbl { width: 100%; border-collapse: collapse; font-size: 13.5px; }
.tbl th { text-align: left; font-size: 11px; text-transform: uppercase; letter-spacing: .8px; color: var(--ink2); padding: 9px 10px; border-bottom: 2px solid var(--line); white-space: nowrap; }
.tbl td { padding: 11px 10px; border-bottom: 1px solid var(--line); vertical-align: middle; }
.tbl tr:last-child td { border-bottom: none; }
.tbl tr:hover td { background: #fafaff; }
.tbl-wrap { overflow-x: auto; }

.badge { display: inline-flex; align-items: center; gap: 5px; font-size: 11.5px; font-weight: 700; padding: 4px 10px; border-radius: 99px; }
.b-green { background: #dcfce7; color: #15803d; }
.b-amber { background: #fef3c7; color: #b45309; }
.b-red { background: #fee2e2; color: #b91c1c; }
.b-blue { background: #dbeafe; color: #1d4ed8; }
.b-purple { background: var(--brand-soft); color: var(--brand2); }
.b-gray { background: #eef0f7; color: #556; }

/* ---- Progress bars ---- */
.pbar { height: 9px; background: #edeef8; border-radius: 99px; overflow: hidden; }
.pbar > div { height: 100%; border-radius: 99px; background: var(--grad); transition: width .8s cubic-bezier(.2,.8,.3,1); }
.pbar.green > div { background: linear-gradient(90deg, #10b981, #22c55e); }
.pbar.amber > div { background: linear-gradient(90deg, #f59e0b, #fbbf24); }
.prow { display: flex; align-items: center; gap: 12px; margin-bottom: 12px; }
.prow .pl { width: 110px; font-size: 13px; font-weight: 600; }
.prow .pv { width: 44px; text-align: right; font-size: 13px; font-weight: 800; color: var(--brand); }
.prow .pbar { flex: 1; }

/* ---- Chat ---- */
.chat-box { display: flex; flex-direction: column; height: calc(100vh - 210px); min-height: 420px; }
.chat-scroll { flex: 1; overflow-y: auto; padding: 6px 2px 16px; display: flex; flex-direction: column; gap: 12px; }
.msg { max-width: 78%; padding: 12px 16px; border-radius: 16px; font-size: 14px; line-height: 1.65; white-space: pre-wrap; word-break: break-word; }
.msg.me { align-self: flex-end; background: var(--grad); color: #fff; border-bottom-right-radius: 4px; }
.msg.them { align-self: flex-start; background: #fff; border: 1px solid var(--line); border-bottom-left-radius: 4px; box-shadow: var(--shadow); }
.msg.them b { color: var(--brand2); }
.msg small.t { display: block; opacity: .6; font-size: 10.5px; margin-top: 6px; }
.chat-input { display: flex; gap: 10px; padding-top: 12px; }
.chat-input input { flex: 1; padding: 13px 16px; border: 1.5px solid var(--line); border-radius: 12px; font-size: 14.5px; font-family: inherit; }
.chat-input input:focus { outline: none; border-color: var(--brand); }
.chips { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 10px; }
.chip { background: #fff; border: 1px solid var(--line); border-radius: 99px; padding: 7px 13px; font-size: 12px; font-weight: 600; cursor: pointer; color: var(--ink2); transition: all .13s; }
.chip:hover { border-color: var(--brand); color: var(--brand); }

/* ---- Modal ---- */
.modal-bg { position: fixed; inset: 0; background: rgba(15,18,38,.55); z-index: 100; display: none; align-items: center; justify-content: center; padding: 18px; backdrop-filter: blur(3px); }
.modal-bg.open { display: flex; }
.modal { background: #fff; border-radius: 20px; width: 100%; max-width: 560px; max-height: 90vh; overflow-y: auto; padding: 26px; animation: pop .3s cubic-bezier(.2,.9,.3,1.15); }
.modal h3 { margin-bottom: 18px; font-size: 18px; }
.modal .row2 { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }

/* ---- Accordion / units ---- */
.unit { background: #fff; border-radius: var(--radius); box-shadow: var(--shadow); border: 1px solid #f0f1fa; margin-bottom: 12px; overflow: hidden; }
.unit-head { display: flex; align-items: center; gap: 12px; padding: 16px 20px; cursor: pointer; font-weight: 700; font-size: 15px; }
.unit-head .chev { margin-left: auto; transition: transform .2s; color: var(--ink2); }
.unit.open .chev { transform: rotate(180deg); }
.unit-body { display: none; padding: 0 20px 16px; }
.unit.open .unit-body { display: block; }
.lesson-item { display: flex; align-items: flex-start; gap: 12px; padding: 13px 14px; border: 1px solid var(--line); border-radius: 12px; margin-bottom: 9px; background: #fafbff; }
.lesson-item .li-ico { font-size: 20px; margin-top: 1px; }
.lesson-item .li-main { flex: 1; min-width: 0; }
.lesson-item .li-main b { font-size: 14px; }
.lesson-item .li-main p { font-size: 12.5px; color: var(--ink2); margin-top: 3px; white-space: pre-wrap; }

/* ---- Toast ---- */
#toast { position: fixed; bottom: 24px; left: 50%; transform: translateX(-50%) translateY(80px); background: var(--bg); color: #fff; padding: 13px 22px; border-radius: 12px; font-size: 14px; font-weight: 600; z-index: 200; transition: transform .3s cubic-bezier(.2,.9,.3,1.2); box-shadow: 0 14px 40px rgba(0,0,0,.35); max-width: 90vw; }
#toast.show { transform: translateX(-50%) translateY(0); }

/* ---- Timer ---- */
.timer-pill { position: sticky; top: 74px; z-index: 30; display: inline-flex; align-items: center; gap: 8px; background: var(--bg); color: #fff; font-weight: 800; font-size: 16px; padding: 10px 18px; border-radius: 99px; box-shadow: 0 8px 24px rgba(0,0,0,.3); }
.timer-pill.low { background: var(--red); animation: pulse 1s infinite; }
@keyframes pulse { 50% { opacity: .75 } }
.q-card { background: #fff; border-radius: var(--radius); padding: 20px; box-shadow: var(--shadow); border: 1px solid #f0f1fa; margin-bottom: 14px; }
.q-card .qq { font-weight: 700; font-size: 15px; margin-bottom: 12px; }
.opt { display: flex; align-items: center; gap: 10px; padding: 11px 14px; border: 1.5px solid var(--line); border-radius: 11px; margin-bottom: 8px; cursor: pointer; font-size: 14px; transition: all .13s; background: #fafbff; }
.opt:hover { border-color: #c7c9ea; }
.opt.sel { border-color: var(--brand); background: var(--brand-soft); font-weight: 700; }
.opt.right { border-color: var(--green); background: #dcfce7; }
.opt.wrong { border-color: var(--red); background: #fee2e2; }

/* ---- Badges page ---- */
.badge-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 14px; }
.badge-card { background: #fff; border-radius: 16px; padding: 20px 12px; text-align: center; box-shadow: var(--shadow); border: 1px solid #f0f1fa; }
.badge-card.locked { opacity: .45; filter: grayscale(1); }
.badge-card .be { font-size: 38px; }
.badge-card b { display: block; font-size: 13px; margin-top: 8px; }
.badge-card small { color: var(--ink2); font-size: 11px; }

/* ---- Tabs ---- */
.tabs { display: flex; gap: 6px; background: #eaebf5; border-radius: 12px; padding: 5px; margin-bottom: 18px; flex-wrap: wrap; }
.tab { border: none; background: none; padding: 9px 16px; border-radius: 9px; font-size: 13px; font-weight: 700; color: var(--ink2); cursor: pointer; }
.tab.active { background: #fff; color: var(--brand); box-shadow: 0 3px 10px rgba(35,31,90,.12); }

.search-row { display: flex; gap: 10px; margin-bottom: 16px; flex-wrap: wrap; }
.search-row input, .search-row select { padding: 11px 14px; border: 1.5px solid var(--line); border-radius: 11px; font-size: 14px; font-family: inherit; background: #fff; }
.search-row input { flex: 1; min-width: 180px; }
.search-row input:focus, .search-row select:focus { outline: none; border-color: var(--brand); }

.empty { text-align: center; color: var(--ink2); padding: 40px 16px; font-size: 14px; }
.empty .e-ico { font-size: 40px; display: block; margin-bottom: 10px; }

.overlay { position: fixed; inset: 0; background: rgba(0,0,0,.4); z-index: 45; display: none; }

/* ---- Responsive ---- */
@media (max-width: 1024px) {
  .g4 { grid-template-columns: repeat(2, 1fr); }
  .g3 { grid-template-columns: repeat(2, 1fr); }
  .quick { grid-template-columns: repeat(4, 1fr); }
}
@media (max-width: 768px) {
  .sidebar { transform: translateX(-100%); width: 272px; }
  .sidebar.open { transform: none; box-shadow: 30px 0 80px rgba(0,0,0,.4); }
  .overlay.show { display: block; }
  .main { margin-left: 0; }
  .burger { display: block; }
  .content { padding: 16px; }
  .g2, .g3 { grid-template-columns: 1fr; }
  .g4 { grid-template-columns: repeat(2, 1fr); }
  .quick { grid-template-columns: repeat(3, 1fr); }
  .who { display: none; }
  .hero h1 { font-size: 20px; }
  .modal .row2 { grid-template-columns: 1fr; }
  .msg { max-width: 92%; }
  .chat-box { height: calc(100vh - 190px); }
}
@media (max-width: 420px) { .quick { grid-template-columns: repeat(2, 1fr); } }

/* ---- RTL (Arabic) ---- */
[dir=rtl] body { font-family: 'Cairo', 'Inter', 'Segoe UI', Tahoma, sans-serif; }
[dir=rtl] .sidebar { left: auto; right: 0; }
[dir=rtl] .main { margin-left: 0; margin-right: 258px; }
[dir=rtl] .nav-item { text-align: right; }
[dir=rtl] .nav-item .pill { margin-left: 0; margin-right: auto; }
[dir=rtl] .unit-head .chev { margin-left: 0; margin-right: auto; }
[dir=rtl] .tbl th { text-align: right; }
[dir=rtl] .prow .pv { text-align: left; }
[dir=rtl] .login-card, [dir=rtl] .modal { text-align: right; }
@media (max-width: 768px) {
  [dir=rtl] .main { margin-right: 0; }
  [dir=rtl] .sidebar { transform: translateX(100%); }
  [dir=rtl] .sidebar.open { transform: none; box-shadow: -30px 0 80px rgba(0,0,0,.4); }
}
.lang-btn { font-weight: 800 !important; font-size: 13px !important; }
.login-lang { position: absolute; top: 18px; right: 18px; z-index: 5; background: rgba(255,255,255,.12); color: #fff; border: 1px solid rgba(255,255,255,.25); border-radius: 10px; padding: 8px 14px; font-size: 13px; font-weight: 700; cursor: pointer; }
[dir=rtl] .login-lang { right: auto; left: 18px; }
