:root {
  --bg: #0B0E17; --surface: #12172A; --surface2: #1A2140; --surface3: #222a4d; --line: #2A3354;
  --text: #F2F3FF; --muted: #9AA3C7; --violet: #8B7CFF; --deep: #5B3DF5; --gold: #FFC94D;
  --ok: #4ADE9B; --warn: #FFB547; --err: #FF6B6B; --radius: 16px;
}
* { box-sizing: border-box; }
html, body { margin: 0; background: var(--bg); color: var(--text); font-family: 'Tajawal', system-ui, Tahoma, sans-serif; font-size: 15px; }
a { color: inherit; text-decoration: none; }
.hidden { display: none !important; }
input, select, textarea {
  width: 100%; padding: 11px 12px; margin-top: 6px; border-radius: 10px; border: 1px solid var(--line);
  background: var(--surface2); color: var(--text); font: inherit; outline: none; transition: border .15s;
}
input:focus, select:focus, textarea:focus { border-color: var(--violet); }
textarea { min-height: 90px; resize: vertical; }
label { display: block; font-size: 13px; color: var(--muted); margin-bottom: 12px; }
.ltr { direction: ltr; text-align: left; }

.btn { border: 0; border-radius: 10px; padding: 10px 16px; font: inherit; font-weight: 700; cursor: pointer; color: var(--text); transition: transform .1s, opacity .15s, background .15s; white-space: nowrap; }
.btn:active { transform: scale(.97); }
.btn:disabled { opacity: .5; cursor: wait; }
.btn.primary { background: linear-gradient(135deg, var(--deep), var(--violet)); color: #fff; box-shadow: 0 6px 20px -8px var(--deep); }
.btn.gold { background: var(--gold); color: #1b1300; }
.btn.ghost { background: var(--surface2); }
.btn.ghost:hover { background: var(--surface3); }
.btn.danger { background: rgba(255,107,107,.12); color: var(--err); }
.btn.sm { padding: 6px 10px; font-size: 13px; }
.btn.icon { padding: 8px 12px; }
.btn.wide { width: 100%; }

.brand { display: flex; align-items: center; gap: 12px; }
.brand b { display: block; font-size: 18px; font-weight: 800; }
.brand small { color: var(--muted); font-size: 12px; }
.logo { width: 42px; height: 42px; border-radius: 13px; display: grid; place-items: center; font-weight: 900; font-size: 22px;
  color: #1b1300; background: linear-gradient(135deg, var(--violet), var(--deep) 55%, var(--gold)); box-shadow: 0 8px 24px -10px var(--violet); }
.brand.big .logo { width: 56px; height: 56px; font-size: 30px; }

.login { min-height: 100vh; display: grid; place-items: center; padding: 20px;
  background: radial-gradient(900px 500px at 80% -10%, rgba(91,61,245,.35), transparent), radial-gradient(700px 400px at 0% 110%, rgba(255,201,77,.12), transparent), var(--bg); }
.login-card { width: min(420px, 100%); background: var(--surface); border: 1px solid var(--line); border-radius: 22px; padding: 30px; box-shadow: 0 30px 80px -30px #000; }
.login-card .brand { margin-bottom: 24px; }

.shell { display: grid; grid-template-columns: 250px 1fr; min-height: 100vh; }
.side { background: var(--surface); border-left: 1px solid var(--line); padding: 20px 14px; display: flex; flex-direction: column; gap: 18px; position: sticky; top: 0; height: 100vh; overflow: auto; }
.side nav { display: flex; flex-direction: column; gap: 3px; flex: 1; }
.side nav a { display: flex; align-items: center; gap: 10px; padding: 10px 12px; border-radius: 10px; color: var(--muted); cursor: pointer; font-weight: 500; }
.side nav a i { font-style: normal; width: 22px; text-align: center; }
.side nav a:hover { background: var(--surface2); color: var(--text); }
.side nav a.on { background: linear-gradient(90deg, rgba(139,124,255,.22), rgba(139,124,255,.06)); color: var(--text); box-shadow: inset -3px 0 0 var(--violet); }
.side .sep { font-size: 11px; color: var(--muted); opacity: .7; margin: 14px 12px 4px; letter-spacing: .5px; }
main { min-width: 0; }
.top { display: flex; align-items: center; gap: 14px; padding: 18px 28px; border-bottom: 1px solid var(--line); position: sticky; top: 0; background: rgba(11,14,23,.85); backdrop-filter: blur(10px); z-index: 5; }
.top h1 { font-size: 21px; margin: 0; flex: 1; }
.top-actions { display: flex; gap: 8px; flex-wrap: wrap; }
#menuBtn { display: none; }
.page { padding: 24px 28px 60px; max-width: 1400px; }

.grid { display: grid; gap: 16px; }
.kpis { grid-template-columns: repeat(auto-fit, minmax(190px, 1fr)); }
.cols-2 { grid-template-columns: 2fr 1fr; }
.cols-even { grid-template-columns: 1fr 1fr; }
.form-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 0 14px; }
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 20px; }
.card h3 { margin: 0 0 14px; font-size: 16px; display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.card h3 small { color: var(--muted); font-weight: 400; font-size: 12px; }
.kpi { position: relative; overflow: hidden; }
.kpi .v { font-size: 30px; font-weight: 800; margin-top: 6px; }
.kpi .l { color: var(--muted); font-size: 13px; }
.kpi .s { color: var(--muted); font-size: 12px; margin-top: 4px; }
.kpi::after { content: ''; position: absolute; inset: auto -30px -40px auto; width: 120px; height: 120px; border-radius: 50%; background: var(--accent, var(--violet)); opacity: .12; }
.kpi.gold { --accent: var(--gold); } .kpi.gold .v { color: var(--gold); }
.kpi.ok { --accent: var(--ok); }

.chart { width: 100%; height: 200px; }
.bars { display: flex; flex-direction: column; gap: 12px; }
.bar-row .meta { display: flex; justify-content: space-between; font-size: 14px; margin-bottom: 6px; }
.bar-track { height: 10px; background: var(--surface2); border-radius: 99px; overflow: hidden; }
.bar-fill { height: 100%; border-radius: 99px; background: linear-gradient(90deg, var(--deep), var(--violet)); }
.bar-fill.gold { background: linear-gradient(90deg, #d79b16, var(--gold)); }

.toolbar { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; margin-bottom: 16px; }
.toolbar input, .toolbar select { width: auto; min-width: 200px; margin: 0; }
.table-wrap { overflow-x: auto; border-radius: var(--radius); border: 1px solid var(--line); background: var(--surface); }
table { width: 100%; border-collapse: collapse; font-size: 14px; }
th, td { padding: 12px 14px; text-align: right; border-bottom: 1px solid var(--line); vertical-align: middle; }
th { color: var(--muted); font-weight: 500; font-size: 13px; background: var(--surface2); position: sticky; top: 0; }
tr:last-child td { border-bottom: 0; }
tbody tr:hover { background: rgba(139,124,255,.05); }
td.actions { white-space: nowrap; text-align: left; }
td .thumb { width: 52px; height: 32px; object-fit: contain; background: var(--surface2); border-radius: 6px; }
.mono { font-family: ui-monospace, Consolas, monospace; direction: ltr; unicode-bidi: embed; letter-spacing: .5px; }
.trunc { max-width: 260px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; direction: ltr; color: var(--muted); }
.empty { text-align: center; color: var(--muted); padding: 40px; }

.pill { display: inline-flex; align-items: center; gap: 6px; padding: 3px 10px; border-radius: 99px; font-size: 12px; font-weight: 700; background: var(--surface2); color: var(--muted); }
.pill.ok { background: rgba(74,222,155,.12); color: var(--ok); }
.pill.warn { background: rgba(255,181,71,.12); color: var(--warn); }
.pill.err { background: rgba(255,107,107,.12); color: var(--err); }
.pill.violet { background: rgba(139,124,255,.15); color: var(--violet); }
.pill.gold { background: rgba(255,201,77,.14); color: var(--gold); }
.dot { width: 8px; height: 8px; border-radius: 50%; background: currentColor; }

.plans { grid-template-columns: repeat(auto-fit, minmax(280px, 1fr)); }
.plan { position: relative; border-radius: 20px; padding: 22px; background: var(--surface); border: 1px solid var(--line); }
.plan.t1 { border-color: rgba(139,124,255,.5); box-shadow: 0 20px 60px -35px var(--violet); }
.plan.t2 { border-color: rgba(255,201,77,.55); box-shadow: 0 20px 60px -35px var(--gold);
  background: linear-gradient(160deg, rgba(255,201,77,.08), transparent 45%), var(--surface); }
.plan .name { font-size: 20px; font-weight: 800; }
.plan .price { font-size: 32px; font-weight: 800; margin: 10px 0 2px; }
.plan .price small { font-size: 14px; color: var(--muted); font-weight: 500; }
.plan ul { padding: 0 18px 0 0; margin: 14px 0; color: var(--muted); line-height: 1.9; }
.plan .badges { display: flex; gap: 6px; flex-wrap: wrap; }

.drawer { position: fixed; inset: 0; background: rgba(0,0,0,.55); z-index: 20; display: flex; justify-content: flex-start; }
.drawer-panel { width: min(620px, 100%); height: 100%; overflow: auto; background: var(--surface); border-right: 1px solid var(--line); padding: 26px; position: relative; animation: slide .2s ease-out; }
.drawer-panel .close { position: absolute; left: 18px; top: 18px; }
.drawer h2 { margin: 0 0 4px; font-size: 20px; }
.drawer .sub { color: var(--muted); margin-bottom: 20px; font-size: 13px; }
.drawer section { margin-bottom: 22px; }
.drawer section h4 { margin: 0 0 10px; font-size: 14px; color: var(--muted); }
@keyframes slide { from { transform: translateX(-30px); opacity: 0; } }
.row { display: flex; gap: 10px; align-items: end; flex-wrap: wrap; }
.row > label { flex: 1; min-width: 140px; }
.list-item { display: flex; justify-content: space-between; align-items: center; gap: 10px; padding: 10px 12px; border-radius: 10px; background: var(--surface2); margin-bottom: 8px; font-size: 14px; }
.list-item small { color: var(--muted); display: block; }

.switch { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 14px; background: var(--surface2); border-radius: 12px; margin-bottom: 12px; color: var(--text); font-size: 15px; }
.switch input { width: 46px; height: 26px; appearance: none; background: var(--line); border-radius: 99px; position: relative; cursor: pointer; margin: 0; border: 0; flex: none; }
.switch input::after { content: ''; position: absolute; top: 3px; right: 3px; width: 20px; height: 20px; border-radius: 50%; background: #fff; transition: right .15s; }
.switch input:checked { background: var(--ok); }
.switch input:checked::after { right: 23px; }
.switch.danger input:checked { background: var(--err); }

.codes-out { background: var(--surface2); border-radius: 12px; padding: 14px; max-height: 260px; overflow: auto; display: grid; grid-template-columns: repeat(auto-fill, minmax(170px, 1fr)); gap: 8px; }
.codes-out span { background: var(--bg); padding: 8px; border-radius: 8px; text-align: center; }

.toast { position: fixed; bottom: 24px; left: 50%; transform: translate(-50%, 30px); background: var(--surface3); border: 1px solid var(--line); padding: 12px 20px; border-radius: 12px; opacity: 0; transition: .25s; z-index: 50; pointer-events: none; font-weight: 500; }
.toast.show { opacity: 1; transform: translate(-50%, 0); }
.toast.err { border-color: var(--err); color: var(--err); }
.msg { min-height: 20px; color: var(--err); font-size: 14px; margin: 10px 0 0; }
.skeleton { height: 120px; border-radius: var(--radius); background: linear-gradient(90deg, var(--surface) 25%, var(--surface2) 50%, var(--surface) 75%); background-size: 200% 100%; animation: sh 1.2s infinite; }
@keyframes sh { to { background-position: -200% 0; } }

@media (max-width: 980px) {
  .shell { grid-template-columns: 1fr; }
  .side { position: fixed; inset: 0 0 0 auto; width: 260px; z-index: 30; transform: translateX(100%); transition: transform .2s; }
  .side.open { transform: none; box-shadow: -20px 0 60px #000; }
  #menuBtn { display: inline-block; }
  .cols-2, .cols-even { grid-template-columns: 1fr; }
  .page { padding: 18px 14px 60px; }
  .top { padding: 14px; }
}

/* light theme */
html[data-theme="light"] {
  --bg: #F3F4F9; --surface: #FFFFFF; --surface2: #ECEEF6; --surface3: #DFE3F0; --line: #D6DAE8;
  --text: #1C2140; --muted: #5B6288;
}
html[data-theme="light"] .top { background: rgba(243,244,249,.85); }
html[data-theme="light"] .login { background: radial-gradient(900px 500px at 80% -10%, rgba(91,61,245,.12), transparent), radial-gradient(700px 400px at 0% 110%, rgba(255,201,77,.18), transparent), var(--bg); }
html[data-theme="light"] .chart text { fill: #5B6288; }
html[data-theme="light"] tbody tr:hover { background: rgba(91,61,245,.06); }

/* print / PDF reports */
@media print {
  :root { --bg: #fff; --surface: #fff; --surface2: #f6f6f8; --surface3: #eee; --line: #ddd; --text: #111; --muted: #555; }
  .side, .top, #topActions, .toast, .drawer, .btn { display: none !important; }
  .shell { display: block; }
  .page { padding: 0; max-width: none; }
  body { background: #fff; }
  .card { border: 1px solid #ccc; box-shadow: none; break-inside: avoid; }
  .table-wrap { border-color: #ccc; }
  th, td { border-color: #ddd; }
  tr { break-inside: avoid; }
}
