/* ============ IAU DT Dashboard — styles & themes ============ */
:root, [data-theme="navy"] {
  --primary: #0b3a6e; --primary-2: #1d5fa6; --accent: #c9a227; --accent-2: #6a8caf;
  --bg: #f3f6fa; --surface: #ffffff; --surface-2: #f7f9fc; --border: #e2e8f0;
  --text: #1a2433; --muted: #64748b; --sidebar: #0b2d55; --sidebar-text: #dbe6f3;
  --ok: #16a34a; --warn: #d97706; --bad: #dc2626; --info: #2563eb; --na: #94a3b8;
  --shadow: 0 1px 3px rgba(15,23,42,.06), 0 6px 18px rgba(15,23,42,.05);
}
[data-theme="green"] { --primary:#006c35; --primary-2:#1f8f52; --accent:#b8975a; --accent-2:#6fae8a; --sidebar:#00452a; --sidebar-text:#d8efe2; --bg:#f2f7f4; }
[data-theme="teal"] { --primary:#0f766e; --primary-2:#14b8a6; --accent:#f59e0b; --accent-2:#5eead4; --sidebar:#134e4a; --sidebar-text:#ccfbf1; --bg:#f0f9f8; }
[data-theme="royal"] { --primary:#4c1d95; --primary-2:#7c3aed; --accent:#d4a017; --accent-2:#a78bfa; --sidebar:#2e1065; --sidebar-text:#ede9fe; --bg:#f6f4fb; }
[data-theme="dark"] {
  --primary:#60a5fa; --primary-2:#3b82f6; --accent:#fbbf24; --accent-2:#93c5fd;
  --bg:#0b1220; --surface:#121a2b; --surface-2:#18233a; --border:#24314d;
  --text:#e5edf8; --muted:#94a3b8; --sidebar:#070d18; --sidebar-text:#cbd5e1;
  --shadow: 0 1px 3px rgba(0,0,0,.4);
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body { font-family: 'IBM Plex Sans Arabic', 'Inter', system-ui, sans-serif; background: var(--bg); color: var(--text); font-size: 14px; line-height: 1.55; }
[dir="ltr"] body, body[dir="ltr"] { font-family: 'Inter', 'IBM Plex Sans Arabic', system-ui, sans-serif; }
a { color: var(--primary-2); }
button { font-family: inherit; }

/* ---------- Layout ---------- */
#app-shell { display: grid; grid-template-columns: 260px 1fr; min-height: 100vh; }
#sidebar { background: var(--sidebar); color: var(--sidebar-text); position: sticky; top: 0; height: 100vh; overflow-y: auto; display: flex; flex-direction: column; z-index: 40; }
.brand { display: flex; gap: 10px; align-items: center; padding: 18px 16px; border-bottom: 1px solid rgba(255,255,255,.08); }
.brand-logo { width: 52px; height: 52px; border-radius: 12px; background: #fff; object-fit: contain; padding: 3px; flex-shrink: 0; }
.brand-title { font-weight: 700; font-size: 13.5px; line-height: 1.35; color: #fff; }
.brand-sub { font-size: 11px; opacity: .75; }
.nav-list { list-style: none; margin: 0; padding: 10px 8px; flex: 1; }
.nav-list a { display: flex; gap: 12px; align-items: center; color: var(--sidebar-text); text-decoration: none; padding: 10px 12px; border-radius: 10px; font-size: 13.5px; margin-bottom: 2px; transition: background .15s; }
.nav-list a i { width: 18px; text-align: center; opacity: .85; }
.nav-list a:hover { background: rgba(255,255,255,.07); }
.nav-list a.active { background: rgba(255,255,255,.14); color: #fff; font-weight: 600; box-shadow: inset 3px 0 0 var(--accent); }
[dir="rtl"] .nav-list a.active { box-shadow: inset -3px 0 0 var(--accent); }
.sidebar-foot { padding: 12px 16px; font-size: 11px; opacity: .7; border-top: 1px solid rgba(255,255,255,.08); }

#main { min-width: 0; display: flex; flex-direction: column; }
#topbar { position: sticky; top: 0; z-index: 30; background: var(--surface); border-bottom: 1px solid var(--border); display: flex; align-items: center; gap: 12px; padding: 10px 22px; }
#topbar h1 { font-size: 17px; margin: 0; flex: 1; font-weight: 700; }
#topbar .subtitle { display: block; font-size: 11.5px; color: var(--muted); font-weight: 400; }
.top-actions { display: flex; gap: 8px; align-items: center; }
.icon-btn { border: 1px solid var(--border); background: var(--surface-2); color: var(--text); height: 36px; min-width: 36px; padding: 0 10px; border-radius: 10px; cursor: pointer; display: inline-flex; align-items: center; gap: 6px; font-size: 13px; }
.icon-btn:hover { border-color: var(--primary-2); color: var(--primary-2); }
#menu-toggle { display: none; }
.theme-dots { display: flex; gap: 5px; }
.theme-dot { width: 20px; height: 20px; border-radius: 50%; border: 2px solid var(--surface); outline: 1px solid var(--border); cursor: pointer; padding: 0; }
.theme-dot.active { outline: 2px solid var(--text); }

#content { padding: 22px; max-width: 1500px; width: 100%; margin: 0 auto; }
.view { display: none; animation: fade .25s ease; }
.view.active { display: block; }
@keyframes fade { from { opacity: 0; transform: translateY(4px); } to { opacity: 1; transform: none; } }

/* ---------- Cards / grid ---------- */
.grid { display: grid; gap: 16px; }
.g-2 { grid-template-columns: repeat(2, minmax(0,1fr)); }
.g-3 { grid-template-columns: repeat(3, minmax(0,1fr)); }
.g-4 { grid-template-columns: repeat(4, minmax(0,1fr)); }
.g-6 { grid-template-columns: repeat(6, minmax(0,1fr)); }
.span-2 { grid-column: span 2; }
.card { background: var(--surface); border: 1px solid var(--border); border-radius: 14px; padding: 18px; box-shadow: var(--shadow); min-width: 0; }
.card h3 { margin: 0 0 12px; font-size: 15px; display: flex; align-items: center; gap: 8px; }
.card h3 i { color: var(--primary-2); }
.card h3 .right { margin-inline-start: auto; font-size: 12px; font-weight: 400; color: var(--muted); }
.section-title { font-size: 16px; font-weight: 700; margin: 26px 0 12px; display: flex; gap: 8px; align-items: center; }
.section-title:first-child { margin-top: 0; }
.mb { margin-bottom: 16px; }

.kpi-card { position: relative; overflow: hidden; }
.kpi-card .label { color: var(--muted); font-size: 12.5px; }
.kpi-card .value { font-size: 28px; font-weight: 800; color: var(--primary); line-height: 1.2; margin-top: 4px; }
[data-theme="dark"] .kpi-card .value { color: var(--text); }
.kpi-card .delta { font-size: 12px; margin-top: 4px; }
.kpi-card .ico { position: absolute; inset-inline-end: 14px; top: 14px; width: 40px; height: 40px; border-radius: 12px; display: grid; place-items: center; background: color-mix(in srgb, var(--primary-2) 12%, transparent); color: var(--primary-2); font-size: 17px; }
.up { color: var(--ok); } .down { color: var(--bad); }

.hero { background: linear-gradient(120deg, var(--primary), var(--primary-2)); color: #fff; border-radius: 16px; padding: 22px 24px; display: flex; gap: 20px; align-items: center; margin-bottom: 16px; }
.hero img { width: 84px; height: 84px; background: #fff; border-radius: 16px; padding: 4px; object-fit: contain; }
.hero h2 { margin: 0 0 4px; font-size: 21px; }
.hero p { margin: 0; opacity: .92; font-size: 13.5px; }
.hero .vision { font-size: 15px; font-weight: 600; margin-top: 8px; }
.hero-badges { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 10px; }
.hero-badges span { background: rgba(255,255,255,.16); padding: 3px 10px; border-radius: 99px; font-size: 12px; }

/* ---------- Chart containers ---------- */
.chart-box { position: relative; height: 280px; }
.chart-box.tall { height: 360px; }
.chart-box.short { height: 220px; }

/* ---------- Badges / pills ---------- */
.badge { display: inline-flex; align-items: center; gap: 4px; padding: 2px 9px; border-radius: 99px; font-size: 11.5px; font-weight: 600; white-space: nowrap; }
.st-inprogress { background: #dbeafe; color: #1d4ed8; }
.st-early { background: #dcfce7; color: #15803d; }
.st-scheduled { background: #fef3c7; color: #b45309; }
.st-future { background: #e2e8f0; color: #475569; }
.st-late { background: #fee2e2; color: #b91c1c; }
.st-alert { background: #ffedd5; color: #c2410c; }
.st-done { background: #d1fae5; color: #047857; }
[data-theme="dark"] .badge { filter: brightness(.9) saturate(1.2); }
.lv-high { background: #fee2e2; color: #b91c1c; } .lv-medium { background: #fef3c7; color: #b45309; } .lv-low { background: #dcfce7; color: #15803d; }
.code { font-family: ui-monospace, Consolas, monospace; font-size: 12px; color: var(--muted); direction: ltr; unicode-bidi: embed; }

/* ---------- Progress ---------- */
.progress { height: 8px; background: var(--surface-2); border: 1px solid var(--border); border-radius: 99px; overflow: hidden; position: relative; }
.progress > span { display: block; height: 100%; background: linear-gradient(90deg, var(--primary-2), var(--accent-2)); border-radius: 99px; }
.progress .plan-mark { position: absolute; top: -2px; bottom: -2px; width: 2px; background: var(--accent); }
.prog-row { display: flex; align-items: center; gap: 8px; font-size: 12px; }
.prog-row .progress { flex: 1; }

/* ---------- Tables ---------- */
.table-wrap { overflow-x: auto; }
table.data { width: 100%; border-collapse: collapse; font-size: 13px; }
table.data th { text-align: start; background: var(--surface-2); color: var(--muted); font-weight: 600; font-size: 12px; padding: 10px; border-bottom: 1px solid var(--border); white-space: nowrap; position: sticky; top: 0; }
table.data td { padding: 10px; border-bottom: 1px solid var(--border); vertical-align: middle; }
table.data tr:hover td { background: var(--surface-2); }
table.data tr.clickable { cursor: pointer; }

/* ---------- Toolbar / filters ---------- */
.toolbar { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 14px; align-items: center; }
.toolbar input, .toolbar select, .field input, .field select, .field textarea { height: 36px; border: 1px solid var(--border); background: var(--surface); color: var(--text); border-radius: 10px; padding: 0 10px; font-family: inherit; font-size: 13px; }
.field textarea { height: auto; padding: 8px 10px; width: 100%; }
.toolbar input[type="search"] { min-width: 220px; flex: 1; }
.btn { height: 36px; padding: 0 14px; border-radius: 10px; border: none; background: var(--primary); color: #fff; cursor: pointer; font-size: 13px; display: inline-flex; gap: 6px; align-items: center; font-weight: 600; }
.btn:hover { filter: brightness(1.1); }
.btn.ghost { background: transparent; color: var(--primary-2); border: 1px solid var(--border); }
.btn.danger { background: var(--bad); }
.seg { display: inline-flex; border: 1px solid var(--border); border-radius: 10px; overflow: hidden; }
.seg button { border: none; background: var(--surface); color: var(--text); padding: 0 12px; height: 34px; cursor: pointer; font-size: 12.5px; }
.seg button.active { background: var(--primary); color: #fff; }

/* ---------- Heatmap (Qiyas standards) ---------- */
.heat-legend { display: flex; gap: 14px; flex-wrap: wrap; font-size: 12px; color: var(--muted); margin-bottom: 10px; }
.heat-legend i { display: inline-block; width: 12px; height: 12px; border-radius: 3px; vertical-align: middle; margin-inline-end: 4px; }
.persp-block { margin-bottom: 14px; }
.persp-head { font-weight: 700; font-size: 13px; margin-bottom: 6px; display: flex; gap: 8px; align-items: center; }
.persp-head .score { margin-inline-start: auto; font-size: 12px; color: var(--muted); font-weight: 500; }
.axis-row { display: grid; grid-template-columns: 210px 1fr; gap: 10px; align-items: center; padding: 3px 0; }
.axis-name { font-size: 12.5px; color: var(--muted); }
.axis-name b { color: var(--text); font-weight: 600; }
.cells { display: flex; flex-wrap: wrap; gap: 4px; }
.cell { min-width: 52px; height: 26px; border-radius: 6px; display: grid; place-items: center; font-size: 10.5px; font-weight: 700; color: #fff; cursor: pointer; direction: ltr; border: 2px solid transparent; transition: transform .1s; }
.cell:hover { transform: scale(1.07); }
.cell.F { background: var(--ok); } .cell.P { background: var(--warn); } .cell.N { background: var(--bad); } .cell.X { background: var(--na); } .cell.null { background: transparent; color: var(--muted); border: 1px dashed var(--border); }
.cell.d-up { background: var(--ok); } .cell.d-down { background: var(--bad); } .cell.d-same { background: var(--na); } .cell.d-new { background: var(--info); }
.cell.sim { border-color: var(--text); box-shadow: 0 0 0 2px var(--accent); }
.cell.changed::after { content: '•'; position: relative; inset-inline-start: 2px; color: #fff; }

/* ---------- Gantt ---------- */
.gantt { min-width: 860px; }
.gantt-head, .gantt-row { display: grid; grid-template-columns: 300px 1fr; align-items: center; }
.gantt-months { display: grid; grid-template-columns: repeat(12, 1fr); font-size: 11px; color: var(--muted); text-align: center; border-bottom: 1px solid var(--border); padding-bottom: 6px; }
.gantt-row { border-bottom: 1px dashed var(--border); min-height: 32px; }
.gantt-row.group { background: var(--surface-2); font-weight: 700; font-size: 12.5px; }
.gantt-label { font-size: 12px; padding: 6px 8px; }
.gantt-track { position: relative; height: 32px; background-image: linear-gradient(to right, var(--border) 1px, transparent 1px); background-size: calc(100%/12) 100%; }
[dir="rtl"] .gantt-track { background-image: linear-gradient(to left, var(--border) 1px, transparent 1px); }
.gantt-bar { position: absolute; top: 8px; height: 16px; border-radius: 6px; font-size: 10px; color: #fff; display: flex; align-items: center; padding: 0 6px; white-space: nowrap; overflow: hidden; }
.gb-done { background: var(--ok); } .gb-ongoing { background: var(--primary-2); } .gb-periodic { background: var(--accent); } .gb-external { background: #7c3aed; }
.gantt-today { position: absolute; top: 0; bottom: 0; width: 2px; background: var(--bad); z-index: 2; }

/* ---------- Lists ---------- */
.list { list-style: none; margin: 0; padding: 0; }
.list li { padding: 9px 0; border-bottom: 1px solid var(--border); display: flex; gap: 10px; align-items: flex-start; font-size: 13px; }
.list li:last-child { border-bottom: none; }
.list li .dot { width: 26px; height: 26px; flex-shrink: 0; border-radius: 8px; display: grid; place-items: center; background: color-mix(in srgb, var(--primary-2) 12%, transparent); color: var(--primary-2); font-weight: 700; font-size: 12px; }
.check-item { cursor: pointer; }
.check-item input { margin-top: 3px; accent-color: var(--primary); width: 16px; height: 16px; }
.check-item.done span { text-decoration: line-through; color: var(--muted); }

.pillar-card { border-top: 4px solid var(--primary-2); }
.pillar-card .pnum { font-size: 11px; color: var(--muted); }
.pillar-card h4 { margin: 4px 0 8px; font-size: 14px; }
.obj-chip { background: var(--surface-2); border: 1px solid var(--border); padding: 6px 8px; border-radius: 8px; font-size: 12px; margin-top: 6px; }

.eco { display: flex; align-items: center; gap: 8px; padding: 8px 0; border-bottom: 1px solid var(--border); font-size: 13px; }
.eco .badge { margin-inline-start: auto; }
.eco-covered { background: #dcfce7; color: #15803d; } .eco-partial { background: #fef3c7; color: #b45309; } .eco-absent { background: #fee2e2; color: #b91c1c; }

.dim-bar { display: grid; grid-template-columns: 170px 1fr 70px; gap: 10px; align-items: center; padding: 6px 0; font-size: 12.5px; }
.dim-track { height: 12px; background: var(--surface-2); border-radius: 99px; position: relative; border: 1px solid var(--border); }
.dim-track .now { position: absolute; inset-block: 0; inset-inline-start: 0; border-radius: 99px; }
.dim-track .tgt { position: absolute; top: -4px; bottom: -4px; width: 3px; background: var(--text); border-radius: 2px; }

.member { display: flex; gap: 10px; align-items: center; padding: 7px 0; border-bottom: 1px solid var(--border); }
.avatar { width: 34px; height: 34px; border-radius: 50%; background: var(--primary); color: #fff; display: grid; place-items: center; font-weight: 700; font-size: 13px; flex-shrink: 0; }
.member small { color: var(--muted); display: block; }

.risk-matrix { display: grid; grid-template-columns: repeat(2, 1fr); gap: 12px; }
.risk-card { border-inline-start: 4px solid var(--bad); }
.risk-card.medium { border-inline-start-color: var(--warn); }
.risk-card .resp { font-size: 12.5px; color: var(--muted); margin-top: 6px; }

.empty { text-align: center; color: var(--muted); padding: 30px; }
.note { font-size: 12px; color: var(--muted); }
.callout { background: color-mix(in srgb, var(--accent) 14%, var(--surface)); border: 1px solid color-mix(in srgb, var(--accent) 40%, transparent); padding: 12px 14px; border-radius: 12px; font-size: 13px; }

/* ---------- Modal ---------- */
#modal { position: fixed; inset: 0; background: rgba(2,6,23,.55); display: none; align-items: center; justify-content: center; z-index: 100; padding: 16px; }
#modal.open { display: flex; }
.modal-box { background: var(--surface); border-radius: 16px; width: min(680px, 100%); max-height: 90vh; overflow-y: auto; padding: 22px; box-shadow: 0 20px 50px rgba(0,0,0,.3); }
.modal-box h3 { margin: 0 0 4px; }
.modal-close { float: inline-end; }
.field { margin-bottom: 12px; }
.field label { display: block; font-size: 12px; color: var(--muted); margin-bottom: 4px; }
.field input, .field select { width: 100%; }
.kv { display: grid; grid-template-columns: 140px 1fr; gap: 6px 12px; font-size: 13px; margin: 12px 0; }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; }

#toast { position: fixed; bottom: 20px; inset-inline-start: 50%; transform: translateX(-50%); background: var(--text); color: var(--surface); padding: 10px 18px; border-radius: 10px; font-size: 13px; opacity: 0; pointer-events: none; transition: opacity .25s; z-index: 200; }
[dir="rtl"] #toast { transform: translateX(50%); }
#toast.show { opacity: 1; }

.logo-preview { width: 110px; height: 110px; border: 1px dashed var(--border); border-radius: 14px; object-fit: contain; background: #fff; padding: 6px; }
.theme-option { border: 2px solid var(--border); border-radius: 12px; padding: 10px; cursor: pointer; text-align: center; font-size: 12.5px; background: var(--surface); color: var(--text); }
.theme-option.active { border-color: var(--primary-2); }
.theme-swatch { height: 36px; border-radius: 8px; margin-bottom: 6px; }

/* ---------- Responsive ---------- */
@media (max-width: 1200px) { .g-4 { grid-template-columns: repeat(2, minmax(0,1fr)); } .g-6 { grid-template-columns: repeat(3, minmax(0,1fr)); } }
@media (max-width: 960px) {
  #app-shell { grid-template-columns: 1fr; }
  #sidebar { position: fixed; inset-block: 0; inset-inline-start: 0; width: 270px; transform: translateX(-100%); transition: transform .25s; }
  [dir="rtl"] #sidebar { transform: translateX(100%); }
  body.nav-open #sidebar { transform: none; }
  body.nav-open::after { content: ''; position: fixed; inset: 0; background: rgba(0,0,0,.4); z-index: 35; }
  #menu-toggle { display: inline-flex; }
  .g-2, .g-3 { grid-template-columns: 1fr; }
  .span-2 { grid-column: auto; }
  .risk-matrix { grid-template-columns: 1fr; }
}
@media (max-width: 600px) {
  #content { padding: 14px; }
  #topbar { padding: 10px 12px; flex-wrap: wrap; }
  #topbar h1 { font-size: 15px; }
  .theme-dots, .hide-sm { display: none; }
  .g-4, .g-6 { grid-template-columns: repeat(2, minmax(0,1fr)); }
  .kpi-card .value { font-size: 22px; }
  .kpi-card .ico { display: none; }
  .hero { flex-direction: column; text-align: center; padding: 18px; }
  .hero-badges { justify-content: center; }
  .axis-row { grid-template-columns: 1fr; gap: 4px; }
  .dim-bar { grid-template-columns: 110px 1fr 54px; }
  .kv { grid-template-columns: 1fr; }
  .toolbar input[type="search"] { min-width: 0; width: 100%; }
}
@media print {
  #sidebar, #topbar .top-actions, .toolbar { display: none !important; }
  #app-shell { display: block; }
  .card { break-inside: avoid; box-shadow: none; }
}
