/* ============ Tokens ============ */
:root {
  --bg: #f5f6f8;
  --surface: #ffffff;
  --surface-2: #f9fafb;
  --border: #e6e8ec;
  --text: #17202b;
  --muted: #667085;
  --faint: #98a2b3;
  --primary: #0f766e;
  --primary-soft: #e6f4f2;
  --primary-ink: #ffffff;
  --accent: #4f46e5;
  --s1: #0f9488;
  --s2: #a5b4c8;
  --s3: #f59e0b;
  --s4: #ef4444;
  --s5: #6366f1;
  --ok: #12805c;   --ok-soft: #e3f5ec;
  --warn: #b45309; --warn-soft: #fdf1dc;
  --bad: #c0362c;  --bad-soft: #fde8e6;
  --info: #2563eb; --info-soft: #e7eefd;
  --shadow: 0 1px 2px rgba(16,24,40,.04), 0 1px 3px rgba(16,24,40,.06);
  --shadow-lg: 0 20px 50px -12px rgba(16,24,40,.25);
  --radius: 14px;
  --sidebar: 256px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0d1117; --surface: #151b23; --surface-2: #1a212b; --border: #262f3b;
    --text: #e6eaf0; --muted: #9aa4b2; --faint: #6b7584;
    --primary: #2dd4bf; --primary-soft: #11302d; --primary-ink: #04201d; --accent: #818cf8;
    --s1: #2dd4bf; --s2: #4b5a70;
    --ok: #4ade80; --ok-soft: #12291d; --warn: #fbbf24; --warn-soft: #2d2410;
    --bad: #f87171; --bad-soft: #321716; --info: #60a5fa; --info-soft: #14213a;
    --shadow: 0 1px 2px rgba(0,0,0,.3); --shadow-lg: 0 20px 50px -12px rgba(0,0,0,.6);
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #0d1117; --surface: #151b23; --surface-2: #1a212b; --border: #262f3b;
  --text: #e6eaf0; --muted: #9aa4b2; --faint: #6b7584;
  --primary: #2dd4bf; --primary-soft: #11302d; --primary-ink: #04201d; --accent: #818cf8;
  --s1: #2dd4bf; --s2: #4b5a70;
  --ok: #4ade80; --ok-soft: #12291d; --warn: #fbbf24; --warn-soft: #2d2410;
  --bad: #f87171; --bad-soft: #321716; --info: #60a5fa; --info-soft: #14213a;
  --shadow: 0 1px 2px rgba(0,0,0,.3); --shadow-lg: 0 20px 50px -12px rgba(0,0,0,.6);
  color-scheme: dark;
}

/* ============ Base ============ */
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  font-family: 'IBM Plex Sans Arabic', system-ui, 'Segoe UI', Tahoma, sans-serif;
  background: var(--bg); color: var(--text); font-size: 14px; line-height: 1.6;
  -webkit-font-smoothing: antialiased;
  overflow-x: clip;
}
a { color: inherit; text-decoration: none; }
button, input, select, textarea { font: inherit; color: inherit; }
h1, h2, h3, h4 { margin: 0; line-height: 1.35; }
.ic { width: 18px; height: 18px; flex: none; }
.num { font-variant-numeric: tabular-nums; direction: ltr; unicode-bidi: isolate; }
.muted { color: var(--muted); }
.faint { color: var(--faint); }
.hide { display: none !important; }

/* ============ Layout ============ */
.app { display: flex; min-height: 100vh; }
.sidebar {
  width: var(--sidebar); flex: none; background: var(--surface); border-inline-start: 0;
  border-inline-end: 1px solid var(--border); position: sticky; top: 0; height: 100vh;
  display: flex; flex-direction: column; padding: 18px 14px; gap: 14px; overflow-y: auto; z-index: 30;
}
.brand { display: flex; align-items: center; gap: 10px; padding: 0 6px; }
.brand-mark {
  width: 38px; height: 38px; border-radius: 11px; display: grid; place-items: center;
  background: linear-gradient(135deg, var(--primary), var(--accent)); color: #fff; font-weight: 700; font-size: 20px;
}
.brand-text { display: flex; flex-direction: column; line-height: 1.25; }
.brand-text strong { font-size: 15px; }
.brand-text span { font-size: 12px; color: var(--muted); }
.search-trigger {
  display: flex; align-items: center; gap: 8px; width: 100%; padding: 8px 10px; border-radius: 10px;
  background: var(--surface-2); border: 1px solid var(--border); color: var(--muted); cursor: pointer; font-size: 13px;
}
.search-trigger span { flex: 1; text-align: start; }
kbd { font-family: inherit; font-size: 11px; background: var(--surface); border: 1px solid var(--border); border-radius: 6px; padding: 0 6px; direction: ltr; }
.nav { display: flex; flex-direction: column; gap: 2px; flex: 1; }
.nav-group { font-size: 11.5px; color: var(--faint); font-weight: 600; padding: 12px 10px 4px; }
.nav-link {
  display: flex; align-items: center; gap: 10px; padding: 8px 10px; border-radius: 9px; color: var(--muted);
  font-weight: 500; transition: background .15s, color .15s;
}
.nav-link:hover { background: var(--surface-2); color: var(--text); }
.nav-link.active { background: var(--primary-soft); color: var(--primary); }
.nav-link span { flex: 1; }
.badge { font-style: normal; font-size: 11px; min-width: 20px; height: 20px; border-radius: 10px; display: grid; place-items: center; background: var(--bad); color: #fff; padding: 0 6px; }
.plan-card { background: var(--surface-2); border: 1px solid var(--border); border-radius: 12px; padding: 12px; font-size: 12.5px; }
.plan-top { display: flex; gap: 8px; align-items: center; color: var(--primary); }
.plan-top strong { color: var(--text); font-size: 13px; }
.plan-card p { margin: 6px 0 10px; color: var(--muted); }

.main { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.topbar {
  position: sticky; top: 0; z-index: 20; display: flex; align-items: center; gap: 12px;
  padding: 12px 28px; background: color-mix(in srgb, var(--bg) 85%, transparent); backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--border);
}
.crumbs { flex: 1; display: flex; align-items: center; gap: 6px; color: var(--muted); font-size: 13px; min-width: 0; }
.crumbs strong { color: var(--text); font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.crumbs .ic { width: 14px; height: 14px; }
.topbar-actions { display: flex; align-items: center; gap: 8px; }
.icon-btn {
  width: 36px; height: 36px; border-radius: 10px; display: grid; place-items: center; border: 1px solid var(--border);
  background: var(--surface); cursor: pointer; color: var(--muted); position: relative;
}
.icon-btn:hover { color: var(--text); }
.notif b { position: absolute; top: 8px; inset-inline-end: 9px; width: 7px; height: 7px; border-radius: 50%; background: var(--bad); border: 2px solid var(--surface); }
.me { display: flex; align-items: center; gap: 8px; padding-inline-start: 6px; }
.me-text { display: flex; flex-direction: column; line-height: 1.2; }
.me-text strong { font-size: 13px; }
.me-text span { font-size: 11.5px; color: var(--muted); }
.avatar {
  width: 34px; height: 34px; border-radius: 50%; display: grid; place-items: center; font-size: 12px; font-weight: 600;
  background: var(--primary-soft); color: var(--primary); flex: none;
}
.avatar.sm { width: 26px; height: 26px; font-size: 10.5px; }
.view { padding: 24px 28px 48px; outline: none; animation: fade .25s ease; max-width: 1480px; width: 100%; }
@keyframes fade { from { opacity: 0; transform: translateY(4px); } to { opacity: 1; transform: none; } }
.only-mobile { display: none; }

/* ============ Page header ============ */
.page-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 16px; margin-bottom: 20px; flex-wrap: wrap; }
.page-head h1 { font-size: 22px; font-weight: 700; }
.page-head p { margin: 4px 0 0; color: var(--muted); }
.head-actions { display: flex; gap: 8px; flex-wrap: wrap; }

/* ============ Buttons ============ */
.btn {
  display: inline-flex; align-items: center; gap: 6px; border-radius: 10px; padding: 8px 14px; font-weight: 600; font-size: 13px;
  border: 1px solid var(--border); background: var(--surface); cursor: pointer; transition: transform .1s, background .15s; white-space: nowrap;
}
.btn:active { transform: scale(.97); }
.btn:hover { background: var(--surface-2); }
.btn-primary { background: var(--primary); color: var(--primary-ink); border-color: transparent; }
.btn-primary:hover { background: color-mix(in srgb, var(--primary) 88%, #000); }
.btn-ghost { background: transparent; }
.btn-sm { padding: 6px 11px; font-size: 12.5px; }
.btn .ic { width: 16px; height: 16px; }
.seg { display: inline-flex; background: var(--surface-2); border: 1px solid var(--border); border-radius: 10px; padding: 3px; gap: 2px; }
.seg button { border: 0; background: none; padding: 5px 12px; border-radius: 7px; cursor: pointer; color: var(--muted); font-weight: 500; font-size: 13px; }
.seg button.on { background: var(--surface); color: var(--text); box-shadow: var(--shadow); }

/* ============ Cards & grid ============ */
.grid { display: grid; gap: 16px; }
.g-4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.g-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.g-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.g-main { grid-template-columns: minmax(0, 2fr) minmax(0, 1fr); }
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); }
.card-pad { padding: 18px; }
.card-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 16px 18px 0; }
.card-head h3 { font-size: 15px; font-weight: 600; }
.card-head p { margin: 2px 0 0; color: var(--muted); font-size: 12.5px; }
.card-body { padding: 14px 18px 18px; }
.mt { margin-top: 16px; }

.kpi { padding: 16px 18px; display: flex; flex-direction: column; gap: 6px; position: relative; overflow: hidden; cursor: default; transition: transform .15s, box-shadow .15s; }
.kpi:hover { transform: translateY(-2px); box-shadow: var(--shadow-lg); }
.kpi-top { display: flex; align-items: center; justify-content: space-between; color: var(--muted); font-size: 13px; }
.kpi-ic { width: 34px; height: 34px; border-radius: 10px; display: grid; place-items: center; background: var(--primary-soft); color: var(--primary); }
.kpi-ic.warn { background: var(--warn-soft); color: var(--warn); }
.kpi-ic.bad { background: var(--bad-soft); color: var(--bad); }
.kpi-ic.info { background: var(--info-soft); color: var(--info); }
.kpi-val { font-size: 26px; font-weight: 700; letter-spacing: -.3px; }
.kpi-val small { font-size: 13px; font-weight: 500; color: var(--muted); margin-inline-start: 4px; }
.kpi-foot { display: flex; align-items: center; justify-content: space-between; font-size: 12.5px; }
.delta { display: inline-flex; align-items: center; gap: 3px; font-weight: 600; }
.delta.up { color: var(--ok); } .delta.dn { color: var(--bad); }
.delta .ic { width: 14px; height: 14px; }

/* ============ Pills / status ============ */
.pill { display: inline-flex; align-items: center; gap: 5px; font-size: 12px; font-weight: 600; padding: 2px 9px; border-radius: 20px; white-space: nowrap; }
.pill::before { content: ''; width: 6px; height: 6px; border-radius: 50%; background: currentColor; }
.pill.ok { background: var(--ok-soft); color: var(--ok); }
.pill.warn { background: var(--warn-soft); color: var(--warn); }
.pill.bad { background: var(--bad-soft); color: var(--bad); }
.pill.info { background: var(--info-soft); color: var(--info); }
.pill.mute { background: var(--surface-2); color: var(--muted); border: 1px solid var(--border); }
.tag { font-size: 11.5px; padding: 1px 8px; border-radius: 6px; background: var(--surface-2); border: 1px solid var(--border); color: var(--muted); white-space: nowrap; }
.dot { width: 8px; height: 8px; border-radius: 50%; display: inline-block; flex: none; }

/* ============ Tables ============ */
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
th { text-align: start; font-size: 12px; font-weight: 600; color: var(--muted); padding: 10px 14px; border-bottom: 1px solid var(--border); background: var(--surface-2); white-space: nowrap; }
td.num { white-space: nowrap; }
td { padding: 11px 14px; border-bottom: 1px solid var(--border); vertical-align: middle; }
tr:last-child td { border-bottom: 0; }
tbody tr { transition: background .12s; }
tbody tr.clickable { cursor: pointer; }
tbody tr:hover { background: var(--surface-2); }
.cell-main { font-weight: 600; }
.cell-sub { font-size: 12px; color: var(--muted); }

/* ============ Progress ============ */
.bar { height: 7px; background: var(--surface-2); border: 1px solid var(--border); border-radius: 10px; overflow: hidden; }
.bar > i { display: block; height: 100%; background: var(--primary); border-radius: 10px; transition: width .6s ease; }
.bar.warn > i { background: var(--s3); } .bar.bad > i { background: var(--s4); }

/* ============ Charts ============ */
.chart { width: 100%; height: auto; display: block; }
.ch-grid { stroke: var(--border); stroke-dasharray: 3 4; }
.ch-axis { fill: var(--faint); font-size: 11px; font-family: inherit; }
.ch-bar { transition: opacity .15s; }
.ch-bar:hover { opacity: .75; }
.ch-bar.s1, .dn.s1 { fill: var(--s1); stroke: var(--s1); }
.ch-bar.s2, .dn.s2 { fill: var(--s2); stroke: var(--s2); }
.ch-bar.s1 { stroke: none; } .ch-bar.s2 { stroke: none; }
.dn { fill: none !important; }
.dn.s3 { stroke: var(--s3); } .dn.s4 { stroke: var(--s4); } .dn.s5 { stroke: var(--s5); }
.dn-track { stroke: var(--surface-2); }
.donut, .ring { position: relative; flex: none; }
.donut svg, .ring svg { width: 100%; height: 100%; }
.donut-c { position: absolute; inset: 0; display: grid; place-items: center; text-align: center; }
.ring span { position: absolute; inset: 0; display: grid; place-items: center; font-size: 12px; font-weight: 700; }
.legend { display: flex; flex-wrap: wrap; gap: 14px; font-size: 12.5px; color: var(--muted); }
.legend span { display: inline-flex; align-items: center; gap: 6px; }
.lg { width: 10px; height: 10px; border-radius: 3px; display: inline-block; }
.spark { width: 100%; height: 36px; }
.sp-line { fill: none; stroke: var(--s1); stroke-width: 2; }
.sp-area { fill: var(--s1); opacity: .12; }
.spark.s4 .sp-line { stroke: var(--s4); } .spark.s4 .sp-area { fill: var(--s4); }

/* ============ Lists ============ */
.list { display: flex; flex-direction: column; }
.li { display: flex; align-items: center; gap: 12px; padding: 11px 0; border-bottom: 1px solid var(--border); }
.li:last-child { border-bottom: 0; }
.li-main { flex: 1; min-width: 0; }
.li-title { font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.li-sub { font-size: 12px; color: var(--muted); }
.li-ic { width: 34px; height: 34px; border-radius: 10px; display: grid; place-items: center; background: var(--surface-2); color: var(--muted); flex: none; }

/* ============ Projects ============ */
.proj-card { padding: 18px; display: flex; flex-direction: column; gap: 14px; cursor: pointer; transition: transform .15s, box-shadow .15s, border-color .15s; position: relative; overflow: hidden; }
.proj-card::before { content: ''; position: absolute; inset-block-start: 0; inset-inline: 0; height: 3px; background: var(--pc); }
.proj-card:hover { transform: translateY(-3px); box-shadow: var(--shadow-lg); border-color: color-mix(in srgb, var(--pc) 40%, var(--border)); }
.proj-top { display: flex; justify-content: space-between; align-items: flex-start; gap: 10px; }
.proj-top h3 { font-size: 15px; }
.proj-meta { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; font-size: 12.5px; }
.proj-meta b { display: block; font-size: 14px; }
.stages { display: flex; gap: 4px; }
.stages i { flex: 1; height: 5px; border-radius: 4px; background: var(--surface-2); border: 1px solid var(--border); }
.stages i.done { background: var(--primary); border-color: transparent; }
.stages i.now { background: var(--s3); border-color: transparent; }

.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--border); margin-bottom: 18px; overflow-x: auto; scrollbar-width: none; }
.tabs::-webkit-scrollbar { display: none; }
.tabs button { border: 0; background: none; padding: 10px 14px; cursor: pointer; color: var(--muted); font-weight: 600; border-bottom: 2px solid transparent; margin-bottom: -1px; white-space: nowrap; }
.tabs button.on { color: var(--primary); border-color: var(--primary); }

/* Gantt */
.gantt { position: relative; }
.g-row { display: grid; grid-template-columns: 170px 1fr; align-items: center; gap: 12px; padding: 7px 0; }
.g-label { font-size: 13px; font-weight: 500; }
.g-track { position: relative; height: 26px; background: var(--surface-2); border-radius: 7px; }
.g-bar { position: absolute; top: 3px; bottom: 3px; border-radius: 6px; background: var(--primary); color: #fff; font-size: 11px; display: flex; align-items: center; padding: 0 8px; white-space: nowrap; overflow: hidden; }
.g-bar.active { background: var(--s3); color: #3b2300; }
.g-bar.todo { background: var(--s2); color: var(--text); }
.g-today { position: absolute; top: -4px; bottom: -4px; width: 2px; background: var(--bad); border-radius: 2px; }
.g-months { display: grid; grid-template-columns: 170px 1fr; gap: 12px; font-size: 11px; color: var(--faint); }
.g-months div:last-child { display: flex; justify-content: space-between; }

/* ============ Kanban ============ */
.board { display: grid; grid-template-columns: repeat(4, minmax(240px, 1fr)); gap: 14px; overflow-x: auto; padding-bottom: 6px; align-items: start; }
.col { background: var(--surface-2); border: 1px solid var(--border); border-radius: var(--radius); padding: 10px; min-height: 300px; transition: background .15s, border-color .15s; }
.col.over { background: var(--primary-soft); border-color: var(--primary); border-style: dashed; }
.col-head { display: flex; align-items: center; gap: 8px; padding: 4px 6px 10px; font-weight: 600; }
.col-head .count { margin-inline-start: auto; font-size: 12px; color: var(--muted); background: var(--surface); border: 1px solid var(--border); border-radius: 20px; padding: 0 8px; }
.kcard { background: var(--surface); border: 1px solid var(--border); border-radius: 11px; padding: 12px; margin-bottom: 8px; cursor: grab; box-shadow: var(--shadow); transition: transform .12s, box-shadow .12s; }
.kcard:hover { box-shadow: var(--shadow-lg); }
.kcard.dragging { opacity: .45; transform: rotate(-2deg); }
.kcard h4 { font-size: 13.5px; font-weight: 600; margin: 6px 0 10px; }
.kcard-foot { display: flex; align-items: center; justify-content: space-between; font-size: 12px; color: var(--muted); }
.kcard-foot .late { color: var(--bad); font-weight: 600; }
.prio { font-size: 11px; font-weight: 700; padding: 1px 7px; border-radius: 6px; }
.prio.urgent { background: var(--bad-soft); color: var(--bad); }
.prio.high { background: var(--warn-soft); color: var(--warn); }
.prio.medium { background: var(--info-soft); color: var(--info); }
.prio.low { background: var(--surface-2); color: var(--muted); border: 1px solid var(--border); }

/* ============ Site / snags ============ */
.chips { display: flex; gap: 6px; flex-wrap: wrap; }
.chip { border: 1px solid var(--border); background: var(--surface); padding: 5px 12px; border-radius: 20px; font-size: 12.5px; cursor: pointer; color: var(--muted); font-weight: 500; }
.chip.on { background: var(--text); color: var(--surface); border-color: var(--text); }
.sev { display: inline-flex; align-items: center; gap: 6px; font-size: 12.5px; font-weight: 600; }
.sev.critical { color: var(--bad); } .sev.high { color: var(--warn); } .sev.medium { color: var(--info); } .sev.low { color: var(--muted); }
.flow { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; }
.flow-step { padding: 6px 12px; border-radius: 9px; background: var(--surface-2); border: 1px solid var(--border); font-size: 12.5px; color: var(--muted); }
.flow-step.on { background: var(--primary); color: var(--primary-ink); border-color: transparent; }
.flow-step.past { color: var(--primary); border-color: var(--primary); }
.plan-view { position: relative; aspect-ratio: 16/9; border-radius: 12px; overflow: hidden; background: var(--surface-2); border: 1px solid var(--border); }
.plan-view svg { width: 100%; height: 100%; }
.plan-pin { position: absolute; transform: translate(50%, -100%); cursor: pointer; animation: drop .4s ease; }
.plan-pin span { display: grid; place-items: center; width: 28px; height: 28px; border-radius: 50% 50% 50% 0; transform: rotate(-45deg); color: #fff; font-size: 11px; font-weight: 700; box-shadow: 0 4px 10px rgba(0,0,0,.25); }
.plan-pin span b { transform: rotate(45deg); }
@keyframes drop { from { transform: translate(50%, -160%); opacity: 0; } }

/* ============ CRM pipeline ============ */
.pipe { display: grid; grid-template-columns: repeat(5, minmax(200px, 1fr)); gap: 12px; overflow-x: auto; }
.pipe .col { min-height: 220px; }
.lead { background: var(--surface); border: 1px solid var(--border); border-radius: 11px; padding: 11px 12px; margin-bottom: 8px; cursor: grab; box-shadow: var(--shadow); }
.lead strong { display: block; font-size: 13.5px; }
.lead .val { font-weight: 700; color: var(--primary); margin-top: 6px; }

/* ============ AI ============ */
.ai-wrap { display: grid; grid-template-columns: minmax(0, 1fr) 300px; gap: 16px; }
.chat { display: flex; flex-direction: column; height: calc(100vh - 210px); min-height: 460px; }
.chat-log { flex: 1; overflow-y: auto; padding: 18px; display: flex; flex-direction: column; gap: 14px; }
.msg { max-width: 82%; padding: 11px 14px; border-radius: 14px; line-height: 1.75; animation: fade .25s ease; }
.msg.me { align-self: flex-start; background: var(--primary); color: var(--primary-ink); border-end-start-radius: 4px; }
.msg.bot { align-self: flex-end; background: var(--surface-2); border: 1px solid var(--border); border-end-end-radius: 4px; }
.msg.bot table { margin-top: 8px; font-size: 12.5px; background: var(--surface); border-radius: 8px; overflow: hidden; }
.msg.bot td, .msg.bot th { padding: 6px 10px; }
.typing span { display: inline-block; width: 6px; height: 6px; margin: 0 2px; border-radius: 50%; background: var(--muted); animation: blink 1s infinite; }
.typing span:nth-child(2) { animation-delay: .15s; } .typing span:nth-child(3) { animation-delay: .3s; }
@keyframes blink { 50% { opacity: .2; } }
.chat-input { display: flex; gap: 8px; padding: 12px; border-top: 1px solid var(--border); }
.chat-input input { flex: 1; }
.suggest { display: flex; flex-direction: column; gap: 8px; }
.suggest button { text-align: start; border: 1px solid var(--border); background: var(--surface); border-radius: 10px; padding: 10px 12px; cursor: pointer; font-size: 13px; transition: border-color .15s; }
.suggest button:hover { border-color: var(--primary); color: var(--primary); }

/* ============ Portal ============ */
.portal-hero { background: linear-gradient(135deg, var(--primary), var(--accent)); color: #fff; border-radius: var(--radius); padding: 26px; display: flex; justify-content: space-between; gap: 20px; flex-wrap: wrap; align-items: center; }
.portal-hero h2 { font-size: 22px; }
.portal-hero p { margin: 4px 0 0; opacity: .85; }
.portal-hero .ring span { color: #fff; }
.portal-hero .dn-track { stroke: rgba(255,255,255,.2); }
.portal-hero .dn.s1 { stroke: #fff; }

/* ============ Forms ============ */
.field { display: flex; flex-direction: column; gap: 5px; }
.field label { font-size: 12.5px; font-weight: 600; color: var(--muted); }
.input, select.input, textarea.input {
  width: 100%; padding: 9px 12px; border-radius: 10px; border: 1px solid var(--border); background: var(--surface); outline: none; transition: border-color .15s, box-shadow .15s;
}
.input:focus { border-color: var(--primary); box-shadow: 0 0 0 3px var(--primary-soft); }
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
.form-grid .full { grid-column: 1 / -1; }
.searchbox { position: relative; }
.searchbox .ic { position: absolute; inset-inline-start: 10px; top: 50%; transform: translateY(-50%); color: var(--faint); width: 16px; height: 16px; }
.searchbox .input { padding-inline-start: 34px; min-width: 240px; }

/* ============ Overlay: modal / palette / drawer ============ */
.overlay { position: fixed; inset: 0; background: rgba(13,17,23,.45); backdrop-filter: blur(3px); z-index: 100; display: none; align-items: flex-start; justify-content: center; padding: 8vh 16px 16px; }
.overlay.open { display: flex; animation: fade .18s ease; }
.modal { width: min(560px, 100%); background: var(--surface); border-radius: 16px; box-shadow: var(--shadow-lg); border: 1px solid var(--border); max-height: 84vh; display: flex; flex-direction: column; animation: pop .2s ease; }
.modal.wide { width: min(760px, 100%); }
@keyframes pop { from { transform: scale(.97); opacity: 0; } }
.modal-head { display: flex; align-items: center; justify-content: space-between; padding: 16px 20px; border-bottom: 1px solid var(--border); }
.modal-head h3 { font-size: 16px; }
.modal-body { padding: 18px 20px; overflow-y: auto; }
.modal-foot { display: flex; justify-content: flex-start; gap: 8px; padding: 14px 20px; border-top: 1px solid var(--border); }
.note-hint { display: flex; gap: 8px; align-items: center; font-size: 12px; color: var(--muted); background: var(--surface-2); border: 1px dashed var(--border); padding: 8px 10px; border-radius: 9px; margin-top: 14px; }
.note-hint code { direction: ltr; font-size: 11.5px; color: var(--primary); }

.palette { width: min(600px, 100%); background: var(--surface); border-radius: 16px; box-shadow: var(--shadow-lg); border: 1px solid var(--border); overflow: hidden; animation: pop .18s ease; }
.palette input { width: 100%; border: 0; border-bottom: 1px solid var(--border); padding: 16px 18px; font-size: 15px; outline: none; background: transparent; }
.pal-list { max-height: 50vh; overflow-y: auto; padding: 6px; }
.pal-item { display: flex; align-items: center; gap: 10px; padding: 9px 12px; border-radius: 9px; cursor: pointer; }
.pal-item.sel, .pal-item:hover { background: var(--primary-soft); color: var(--primary); }
.pal-item small { margin-inline-start: auto; color: var(--faint); font-size: 11.5px; }
.pal-group { font-size: 11px; color: var(--faint); font-weight: 600; padding: 8px 12px 4px; }

/* ============ Toast ============ */
.toasts { position: fixed; bottom: 20px; inset-inline-start: 20px; z-index: 200; display: flex; flex-direction: column; gap: 8px; }
.toast { display: flex; align-items: center; gap: 10px; background: var(--text); color: var(--surface); padding: 11px 16px; border-radius: 12px; box-shadow: var(--shadow-lg); font-weight: 500; animation: slide .25s ease; max-width: 380px; }
.toast .ic { color: var(--s1); }
@keyframes slide { from { transform: translateY(12px); opacity: 0; } }

/* ============ Tour ============ */
.tour-tip { position: fixed; z-index: 300; width: 320px; background: var(--surface); border: 1px solid var(--border); border-radius: 14px; box-shadow: var(--shadow-lg); padding: 16px; animation: pop .2s ease; }
.tour-tip h4 { font-size: 15px; margin-bottom: 6px; }
.tour-tip p { margin: 0 0 12px; color: var(--muted); font-size: 13px; }
.tour-foot { display: flex; align-items: center; gap: 8px; }
.tour-foot span { margin-inline-end: auto; font-size: 12px; color: var(--faint); }
.tour-hl { position: relative; z-index: 250; box-shadow: 0 0 0 4px var(--primary), 0 0 0 9999px rgba(13,17,23,.5) !important; border-radius: 12px; }

/* ============ Misc ============ */
.welcome { background: linear-gradient(120deg, var(--primary-soft), transparent 70%); border: 1px solid var(--border); border-radius: var(--radius); padding: 18px 20px; display: flex; align-items: center; gap: 16px; justify-content: space-between; flex-wrap: wrap; margin-bottom: 16px; }
.welcome h2 { font-size: 18px; }
.welcome p { margin: 2px 0 0; color: var(--muted); }
.feature-row { display: flex; gap: 8px; flex-wrap: wrap; }
.empty { text-align: center; color: var(--muted); padding: 30px; }
.split { display: flex; justify-content: space-between; align-items: center; gap: 10px; }
.stack { display: flex; flex-direction: column; gap: 4px; }
.row { display: flex; align-items: center; gap: 8px; }
.toolbar { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; margin-bottom: 14px; }
.toolbar .spacer { flex: 1; }
.big-num { font-size: 30px; font-weight: 700; }

/* ============ Responsive ============ */
@media (max-width: 1200px) {
  .g-4 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .g-main, .ai-wrap { grid-template-columns: minmax(0, 1fr); }
}
@media (max-width: 900px) {
  .g-3 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .sidebar { position: fixed; inset-inline-start: 0; transform: translateX(100%); transition: transform .25s ease; box-shadow: var(--shadow-lg); }
  .sidebar.open { transform: none; }
  .only-mobile { display: grid; }
  .me-text { display: none; }
}
@media (max-width: 640px) {
  .g-4, .g-3, .g-2, .form-grid { grid-template-columns: minmax(0, 1fr); }
  .view { padding: 16px 16px 40px; }
  .topbar { padding: 10px 16px; }
  .topbar .btn span { display: none; }
  .g-row, .g-months { grid-template-columns: 100px 1fr; }
  .searchbox .input { min-width: 0; }
  .tour-tip { width: calc(100vw - 32px); }
}

/* ============ English / LTR ============ */
.i18n-pending body { visibility: hidden; }
.lang-btn { font-weight: 700; font-size: 12.5px; }
[dir="ltr"] .ic-chev { transform: scaleX(-1); }
@media (max-width: 900px) {
  [dir="ltr"] .sidebar { transform: translateX(-100%); }
  [dir="ltr"] .sidebar.open { transform: none; }
}

/* ============ Settings & permissions ============ */
.me { border: 0; background: none; cursor: pointer; border-radius: 12px; padding: 4px 8px; display: flex; align-items: center; gap: 8px; text-align: start; }
.me:hover { background: var(--surface-2); }
.me .ic-chevdown { width: 14px; height: 14px; color: var(--muted); }
.switch { position: relative; display: inline-block; width: 36px; height: 20px; flex: none; vertical-align: middle; }
.switch input { position: absolute; opacity: 0; width: 0; height: 0; }
.switch span { position: absolute; inset: 0; background: var(--border); border-radius: 20px; transition: background .2s; cursor: pointer; }
.switch span::before { content: ''; position: absolute; width: 16px; height: 16px; top: 2px; inset-inline-start: 2px; background: #fff; border-radius: 50%; transition: transform .2s; box-shadow: 0 1px 3px rgba(0,0,0,.25); }
.switch input:checked + span { background: var(--primary); }
.switch input:checked + span::before { transform: translateX(-16px); }
[dir="ltr"] .switch input:checked + span::before { transform: translateX(16px); }
.switch input:focus-visible + span { box-shadow: 0 0 0 3px var(--primary-soft); }
.switch input:disabled + span { opacity: .5; cursor: not-allowed; }
.matrix th, .matrix td { text-align: center; }
.matrix th:first-child, .matrix td:first-child { text-align: start; }
.roles-wrap { display: grid; grid-template-columns: 260px minmax(0, 1fr); gap: 16px; align-items: start; }
.role-item { display: flex; align-items: center; gap: 10px; width: 100%; border: 1px solid transparent; background: none; padding: 9px 10px; border-radius: 10px; cursor: pointer; text-align: start; }
.role-item:hover { background: var(--surface-2); }
.role-item.on { background: var(--primary-soft); border-color: color-mix(in srgb, var(--primary) 30%, transparent); }
.role-item .li-sub { display: block; }
.role-item .ic-lock { width: 14px; height: 14px; color: var(--faint); }
.banner { display: flex; align-items: center; gap: 10px; padding: 10px 14px; border-radius: 10px; background: var(--warn-soft); color: var(--warn); font-size: 13px; font-weight: 500; margin-bottom: 14px; }
.locked { display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 8px; min-height: 180px; color: var(--muted); text-align: center; }
.locked .ic { width: 26px; height: 26px; color: var(--faint); }
.masked { letter-spacing: 2px; color: var(--faint); }
.input-sm { padding: 5px 9px; font-size: 13px; width: auto; }
.title-input { font-size: 16px; font-weight: 700; border-color: transparent; padding: 2px 6px; background: transparent; }
.title-input:hover:not(:disabled) { border-color: var(--border); }
.title-input:disabled { color: var(--text); }
.chip-user { display: inline-flex; align-items: center; gap: 6px; font-size: 12.5px; padding: 3px 10px 3px 4px; border: 1px solid var(--border); border-radius: 20px; background: var(--surface-2); }
.btn.danger { color: var(--bad); }
.user-pick { width: 100%; border: 1px solid transparent; background: none; cursor: pointer; text-align: start; border-radius: 10px; padding: 10px; }
.user-pick:hover, .user-pick.on { background: var(--primary-soft); }
.tabs button .ic { width: 15px; height: 15px; vertical-align: -2px; }
.toast .ic-lock { color: var(--s3); }
@media (max-width: 900px) { .roles-wrap { grid-template-columns: minmax(0, 1fr); } }

/* ============ Login ============ */
body.logged-out .app { display: none; }
.auth { min-height: 100vh; display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); }
.auth-brand {
  background: radial-gradient(circle at 20% 15%, rgba(255,255,255,.14), transparent 40%), linear-gradient(150deg, #0f766e, #3730a3);
  color: #fff; padding: 40px 48px; display: flex; flex-direction: column; justify-content: space-between; gap: 32px; position: relative; overflow: hidden;
}
.auth-brand::after { content: ''; position: absolute; inset-inline-end: -120px; bottom: -120px; width: 380px; height: 380px; border-radius: 50%; border: 60px solid rgba(255,255,255,.06); }
.auth-brand .brand-mark { background: rgba(255,255,255,.18); }
.auth-brand h1 { font-size: 32px; font-weight: 700; max-width: 460px; }
.auth-brand p { opacity: .85; max-width: 440px; font-size: 15px; }
.auth-feats { display: flex; flex-direction: column; gap: 12px; margin-top: 22px; }
.auth-feats .row { gap: 10px; font-weight: 500; }
.auth-feats .ic { background: rgba(255,255,255,.16); border-radius: 9px; padding: 6px; width: 32px; height: 32px; }
.auth-stats { display: flex; gap: 28px; position: relative; z-index: 1; }
.auth-stats div { display: flex; flex-direction: column; }
.auth-stats b { font-size: 24px; }
.auth-stats span { opacity: .75; font-size: 12.5px; }
.auth-main { display: flex; flex-direction: column; align-items: center; justify-content: center; padding: 72px 20px 32px; gap: 16px; position: relative; background: var(--bg); }
.auth-tools { position: absolute; top: 18px; inset-inline-end: 18px; display: flex; gap: 8px; }
.auth-card { width: min(420px, 100%); background: var(--surface); border: 1px solid var(--border); border-radius: 18px; box-shadow: var(--shadow-lg); padding: 28px; animation: pop .25s ease; }
.auth-card.shake { animation: shake .4s ease; }
@keyframes shake { 20%, 60% { transform: translateX(-6px); } 40%, 80% { transform: translateX(6px); } }
.auth-head { margin-bottom: 20px; }
.auth-head .kpi-ic { margin-bottom: 12px; }
.auth-head h2 { font-size: 22px; }
.auth-head p { margin: 4px 0 0; color: var(--muted); }
#auth-form { display: flex; flex-direction: column; gap: 14px; }
.auth-btn { width: 100%; justify-content: center; padding: 11px 14px; font-size: 14px; }
.link-btn { border: 0; background: none; color: var(--primary); cursor: pointer; font-size: 12.5px; font-weight: 600; padding: 0; }
.pass-wrap { position: relative; }
.pass-wrap .input { padding-inline-end: 44px; }
.pass-wrap .icon-btn { position: absolute; inset-inline-end: 4px; top: 50%; transform: translateY(-50%); width: 32px; height: 32px; border: 0; background: none; }
.check { font-size: 13px; color: var(--muted); cursor: pointer; }
.check input { accent-color: var(--primary); width: 16px; height: 16px; }
.auth-err { display: flex; gap: 8px; align-items: center; background: var(--bad-soft); color: var(--bad); padding: 9px 12px; border-radius: 10px; font-size: 13px; font-weight: 500; }
.auth-or { display: flex; align-items: center; gap: 10px; color: var(--faint); font-size: 12px; }
.auth-or::before, .auth-or::after { content: ''; flex: 1; height: 1px; background: var(--border); }
.auth-note { margin: 0; font-size: 12px; color: var(--muted); text-align: center; }
.otp { display: grid; grid-template-columns: repeat(6, 1fr); gap: 8px; }
.otp .input { text-align: center; font-size: 20px; font-weight: 700; padding: 10px 0; }
.auth-demo { margin-top: 18px; border-top: 1px solid var(--border); padding-top: 14px; }
.auth-demo summary { cursor: pointer; font-weight: 600; display: flex; align-items: center; gap: 8px; list-style: none; }
.auth-demo summary::-webkit-details-marker { display: none; }
.auth-demo p { margin: 4px 0 10px; font-size: 12.5px; color: var(--muted); }
.demo-list { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; }
.demo-user { display: flex; align-items: center; gap: 8px; border: 1px solid var(--border); background: var(--surface-2); border-radius: 10px; padding: 7px 9px; cursor: pointer; text-align: start; min-width: 0; transition: border-color .15s; }
.demo-user:hover { border-color: var(--primary); }
.demo-user b { display: block; font-size: 12.5px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.demo-user .li-sub { font-size: 11.5px; }
.auth-foot { margin: 0; font-size: 12px; color: var(--faint); display: flex; align-items: center; gap: 6px; }
.auth-foot .ic { width: 14px; height: 14px; }

/* قائمة المستخدم وشريط العرض كمستخدم آخر */
.user-menu { position: fixed; z-index: 150; width: 270px; background: var(--surface); border: 1px solid var(--border); border-radius: 14px; box-shadow: var(--shadow-lg); padding: 6px; animation: pop .15s ease; }
.um-head { display: flex; gap: 10px; padding: 10px; border-bottom: 1px solid var(--border); margin-bottom: 4px; }
.um-head b { display: block; }
.user-menu button { display: flex; align-items: center; gap: 10px; width: 100%; border: 0; background: none; padding: 9px 10px; border-radius: 9px; cursor: pointer; text-align: start; font-weight: 500; }
.user-menu button:hover { background: var(--surface-2); }
.user-menu button.danger { color: var(--bad); }
#imp-bar { display: flex; align-items: center; gap: 10px; padding: 8px 28px; background: var(--warn-soft); color: var(--warn); font-size: 13px; font-weight: 500; border-bottom: 1px solid var(--border); }
#imp-bar span { flex: 1; }
@media (max-width: 900px) {
  .auth { grid-template-columns: minmax(0, 1fr); }
  .auth-brand { display: none; }
  .auth-main { padding-top: 72px; }
  #imp-bar { padding: 8px 16px; }
}
@media (max-width: 420px) { .demo-list { grid-template-columns: 1fr; } .auth-card { padding: 20px; } }
