:root {
  --bg: #f4f5f7;
  --surface: #ffffff;
  --surface-2: #f9fafb;
  --border: #e4e6eb;
  --text: #1c2230;
  --text-2: #4b5363;
  --muted: #7a8293;
  --navy: #15213b;
  --navy-2: #1e2d4f;
  --gold: #b8912b;
  --gold-soft: #f6efd9;
  --primary: #1f4fa3;
  --primary-soft: #e8eefa;
  --danger: #c0392b;
  --danger-soft: #fbeaea;
  --success: #17803d;
  --success-soft: #e7f5ec;
  --warning: #a86a00;
  --warning-soft: #fdf3dc;
  --info: #2a6f97;
  --info-soft: #e6f1f7;
  --series-1: #2a78d6;
  --series-2: #eb6834;
  --radius: 10px;
  --shadow: 0 1px 2px rgba(16, 24, 40, .06), 0 1px 3px rgba(16, 24, 40, .08);
  --font: 'IBM Plex Sans Arabic', 'Segoe UI', Tahoma, sans-serif;
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body { font-family: var(--font); background: var(--bg); color: var(--text); font-size: 14px; line-height: 1.6; }
a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }
h1, h2, h3, h4 { margin: 0; font-weight: 600; }
button, input, select, textarea { font-family: inherit; font-size: inherit; }
.ltr { direction: ltr; unicode-bidi: embed; display: inline-block; }
.num { font-variant-numeric: tabular-nums; }

/* ---------- Layout ---------- */
.layout { display: flex; min-height: 100vh; }
.sidebar { width: 248px; background: var(--navy); color: #d7dceb; display: flex; flex-direction: column; position: sticky; top: 0; height: 100vh; flex-shrink: 0; }
.brand { padding: 20px 18px 16px; border-bottom: 1px solid rgba(255,255,255,.08); display: flex; gap: 10px; align-items: center; }
.brand-logo { width: 38px; height: 38px; border-radius: 9px; background: var(--gold); color: var(--navy); display: grid; place-items: center; flex-shrink: 0; }
.brand-name { font-weight: 700; color: #fff; font-size: 15px; line-height: 1.35; }
.brand-sub { font-size: 12px; color: #9aa4bd; }
.nav { padding: 10px 10px; flex: 1; overflow-y: auto; }
.nav a { display: flex; align-items: center; gap: 10px; padding: 9px 12px; border-radius: 8px; color: #c9d0e2; margin-bottom: 2px; font-weight: 500; }
.nav a:hover { background: var(--navy-2); text-decoration: none; color: #fff; }
.nav a.active { background: var(--gold); color: var(--navy); }
.nav a svg { flex-shrink: 0; }
.nav .badge-count { margin-inline-start: auto; background: var(--danger); color: #fff; border-radius: 10px; font-size: 11px; padding: 0 7px; line-height: 18px; }
.sidebar-foot { padding: 14px 18px; border-top: 1px solid rgba(255,255,255,.08); font-size: 12px; color: #8c96ae; }

.main { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.topbar { background: var(--surface); border-bottom: 1px solid var(--border); padding: 10px 24px; display: flex; align-items: center; gap: 16px; position: sticky; top: 0; z-index: 20; }
.menu-btn { display: none; }
.search-box { flex: 1; max-width: 460px; position: relative; }
.search-box input { width: 100%; padding: 8px 36px 8px 12px; border: 1px solid var(--border); border-radius: 8px; background: var(--surface-2); }
.search-box svg { position: absolute; right: 11px; top: 50%; transform: translateY(-50%); color: var(--muted); }
.user-switch { margin-inline-start: auto; display: flex; align-items: center; gap: 10px; }
.user-switch label { font-size: 12px; color: var(--muted); }
.user-switch select { padding: 6px 10px; border: 1px solid var(--border); border-radius: 8px; background: var(--surface); max-width: 230px; }
.avatar { width: 34px; height: 34px; border-radius: 50%; background: var(--primary-soft); color: var(--primary); display: grid; place-items: center; font-weight: 700; flex-shrink: 0; }
.avatar.lg { width: 52px; height: 52px; font-size: 20px; }

.content { padding: 24px; max-width: 1400px; width: 100%; }
.page-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 18px; flex-wrap: wrap; }
.page-head h1 { font-size: 22px; }
.page-head .sub { color: var(--muted); font-size: 13px; margin-top: 2px; }
.actions { display: flex; gap: 8px; flex-wrap: wrap; }

/* ---------- Components ---------- */
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); }
.card-head { padding: 14px 18px; border-bottom: 1px solid var(--border); display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.card-head h3 { font-size: 15px; }
.card-body { padding: 16px 18px; }
.card-body.flush { padding: 0; }

.grid { display: grid; gap: 16px; }
.grid-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.grid-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.grid-4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.span-2 { grid-column: span 2; }
.mb { margin-bottom: 16px; }

.stat { padding: 16px 18px; }
.stat .label { color: var(--muted); font-size: 13px; display: flex; align-items: center; gap: 6px; }
.stat .value { font-size: 24px; font-weight: 700; margin-top: 4px; }
.stat .hint { font-size: 12px; color: var(--muted); }
.stat .value.danger { color: var(--danger); }
.stat .value.success { color: var(--success); }

.btn { display: inline-flex; align-items: center; gap: 6px; padding: 8px 14px; border-radius: 8px; border: 1px solid var(--border); background: var(--surface); color: var(--text); cursor: pointer; font-weight: 500; white-space: nowrap; }
.btn:hover { background: var(--surface-2); text-decoration: none; }
.btn.primary { background: var(--primary); border-color: var(--primary); color: #fff; }
.btn.primary:hover { background: #1a438c; }
.btn.gold { background: var(--gold); border-color: var(--gold); color: #fff; }
.btn.danger { color: var(--danger); border-color: #f0c4bf; }
.btn.danger:hover { background: var(--danger-soft); }
.btn.sm { padding: 4px 10px; font-size: 13px; }
.btn.ghost { border-color: transparent; background: transparent; }
.btn.ghost:hover { background: var(--surface-2); }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.icon-btn { border: none; background: transparent; cursor: pointer; padding: 4px; border-radius: 6px; color: var(--muted); display: inline-grid; place-items: center; }
.icon-btn:hover { background: var(--surface-2); color: var(--text); }

.badge { display: inline-flex; align-items: center; gap: 4px; padding: 1px 9px; border-radius: 20px; font-size: 12px; font-weight: 500; white-space: nowrap; background: var(--surface-2); color: var(--text-2); border: 1px solid var(--border); }
.badge.green { background: var(--success-soft); color: var(--success); border-color: #c6e7d1; }
.badge.red { background: var(--danger-soft); color: var(--danger); border-color: #f2c9c4; }
.badge.yellow { background: var(--warning-soft); color: var(--warning); border-color: #f1dfaf; }
.badge.blue { background: var(--primary-soft); color: var(--primary); border-color: #ccd9f2; }
.badge.gold { background: var(--gold-soft); color: #7d5f12; border-color: #ead9a6; }
.badge.gray { background: #eef0f3; color: #535b6b; }

table.table { width: 100%; border-collapse: collapse; }
.table th, .table td { padding: 10px 14px; text-align: right; border-bottom: 1px solid var(--border); vertical-align: middle; }
.table th { font-size: 12px; color: var(--muted); font-weight: 600; background: var(--surface-2); white-space: nowrap; }
.table tr:last-child td { border-bottom: none; }
.table tbody tr:hover { background: #fafbfc; }
.table tr.clickable { cursor: pointer; }
.table .muted { color: var(--muted); font-size: 12px; }
.table-wrap { overflow-x: auto; }
.empty { padding: 28px; text-align: center; color: var(--muted); }

.tabs { display: flex; gap: 2px; border-bottom: 1px solid var(--border); margin-bottom: 16px; overflow-x: auto; }
.tabs a { padding: 9px 16px; color: var(--text-2); border-bottom: 2px solid transparent; font-weight: 500; white-space: nowrap; }
.tabs a:hover { color: var(--text); text-decoration: none; }
.tabs a.active { color: var(--primary); border-bottom-color: var(--primary); }
.tabs .count { font-size: 11px; background: var(--surface-2); border: 1px solid var(--border); border-radius: 10px; padding: 0 6px; margin-inline-start: 4px; }

.filters { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 14px; align-items: center; }
.filters input, .filters select { padding: 7px 10px; border: 1px solid var(--border); border-radius: 8px; background: var(--surface); }
.filters input[type=search] { min-width: 220px; }

.list { list-style: none; margin: 0; padding: 0; }
.list li { padding: 11px 18px; border-bottom: 1px solid var(--border); display: flex; gap: 12px; align-items: flex-start; }
.list li:last-child { border-bottom: none; }
.list .grow { flex: 1; min-width: 0; }
.list .title { font-weight: 500; }
.list .meta { font-size: 12px; color: var(--muted); }
.date-chip { min-width: 52px; text-align: center; border-radius: 8px; background: var(--surface-2); border: 1px solid var(--border); padding: 3px 4px; line-height: 1.25; }
.date-chip .d { font-weight: 700; font-size: 17px; }
.date-chip .m { font-size: 11px; color: var(--muted); }
.date-chip.today { background: var(--gold-soft); border-color: #ead9a6; }

.kv { display: grid; grid-template-columns: 140px 1fr; gap: 8px 14px; }
.kv dt { color: var(--muted); font-size: 13px; }
.kv dd { margin: 0; font-weight: 500; }

.alert { padding: 10px 14px; border-radius: 8px; margin-bottom: 14px; font-size: 13px; border: 1px solid; }
.alert.info { background: var(--info-soft); border-color: #c4dfee; color: #1f5675; }
.alert.success { background: var(--success-soft); border-color: #c6e7d1; color: var(--success); }
.alert.warning { background: var(--warning-soft); border-color: #f1dfaf; color: #7a4e00; }

.overdue { color: var(--danger); font-weight: 600; }
.text-muted { color: var(--muted); }
.small { font-size: 12px; }
.bold { font-weight: 600; }
.row { display: flex; align-items: center; gap: 8px; }
.between { justify-content: space-between; }
.wrap { flex-wrap: wrap; }

/* ---------- Team ---------- */
.team-card { padding: 18px; display: flex; flex-direction: column; gap: 12px; }
.team-card .head { display: flex; gap: 12px; align-items: center; }
.team-card .name { font-weight: 600; font-size: 15px; }
.team-card .mini-stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; text-align: center; background: var(--surface-2); border-radius: 8px; padding: 8px; }
.team-card .mini-stats b { display: block; font-size: 17px; }
.team-card .mini-stats span { font-size: 11px; color: var(--muted); }
.team-card .contact { font-size: 13px; color: var(--text-2); display: grid; gap: 2px; }

/* ---------- Kanban ---------- */
.kanban { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 16px; align-items: start; }
.kanban-col { background: #eceef2; border-radius: var(--radius); padding: 10px; }
.kanban-col h3 { font-size: 14px; padding: 4px 6px 10px; display: flex; justify-content: space-between; }
.task-card { background: var(--surface); border: 1px solid var(--border); border-radius: 8px; padding: 10px 12px; margin-bottom: 8px; box-shadow: var(--shadow); }
.task-card .t { font-weight: 500; margin-bottom: 4px; }
.task-card .meta { font-size: 12px; color: var(--muted); display: flex; flex-wrap: wrap; gap: 4px 10px; align-items: center; }
.task-card .foot { display: flex; justify-content: space-between; align-items: center; margin-top: 8px; }
.task-card.done .t { text-decoration: line-through; color: var(--muted); }

/* ---------- Calendar ---------- */
.cal { display: grid; grid-template-columns: repeat(7, minmax(0, 1fr)); border-top: 1px solid var(--border); border-right: 1px solid var(--border); }
.cal .dow { background: var(--surface-2); text-align: center; font-size: 12px; color: var(--muted); padding: 6px; border-left: 1px solid var(--border); border-bottom: 1px solid var(--border); font-weight: 600; }
.cal .cell { min-height: 104px; border-left: 1px solid var(--border); border-bottom: 1px solid var(--border); padding: 4px 5px; cursor: pointer; }
.cal .cell:hover { background: #fafbfc; }
.cal .cell.out { background: #fafafb; color: #b3b8c3; }
.cal .cell.today .dn { background: var(--gold); color: #fff; border-radius: 50%; }
.cal .cell.selected { outline: 2px solid var(--primary); outline-offset: -2px; }
.cal .dn { display: inline-grid; place-items: center; width: 24px; height: 24px; font-size: 12px; font-weight: 600; }
.cal .ev { display: block; font-size: 11px; padding: 1px 6px; border-radius: 4px; margin-top: 2px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.ev.hearing { background: var(--primary-soft); color: var(--primary); }
.ev.deadline { background: var(--danger-soft); color: var(--danger); }
.ev.meeting { background: var(--success-soft); color: var(--success); }
.ev.done { opacity: .55; text-decoration: line-through; }
.legend { display: flex; gap: 14px; font-size: 12px; color: var(--text-2); flex-wrap: wrap; }
.legend .sw { display: inline-block; width: 10px; height: 10px; border-radius: 3px; margin-inline-end: 5px; vertical-align: -1px; }

/* ---------- Chart ---------- */
.chart-wrap { position: relative; }
.chart-wrap svg { display: block; width: 100%; height: auto; direction: ltr; }
.chart-wrap .grid-line { stroke: #eceef1; stroke-width: 1; }
.chart-wrap .axis-label { fill: var(--muted); font-size: 11px; font-family: var(--font); }
.chart-wrap .hit { fill: transparent; cursor: default; }
.chart-wrap .hit:hover + .bar, .chart-wrap .bar:hover { opacity: .85; }
.chart-tip { position: fixed; z-index: 100; background: var(--navy); color: #fff; padding: 8px 10px; border-radius: 8px; font-size: 12px; pointer-events: none; box-shadow: 0 4px 14px rgba(0,0,0,.18); line-height: 1.5; }
.chart-tip .sw { display: inline-block; width: 8px; height: 8px; border-radius: 2px; margin-inline-end: 5px; }

/* ---------- Modal & forms ---------- */
.modal-backdrop { position: fixed; inset: 0; background: rgba(15, 22, 38, .45); display: flex; align-items: flex-start; justify-content: center; z-index: 50; padding: 40px 16px; overflow-y: auto; }
.modal { background: var(--surface); border-radius: 12px; width: 100%; max-width: 620px; box-shadow: 0 20px 50px rgba(0,0,0,.25); }
.modal.wide { max-width: 820px; }
.modal-head { padding: 16px 20px; border-bottom: 1px solid var(--border); display: flex; justify-content: space-between; align-items: center; }
.modal-head h3 { font-size: 17px; }
.modal-body { padding: 18px 20px; }
.modal-foot { padding: 12px 20px; border-top: 1px solid var(--border); display: flex; gap: 8px; justify-content: flex-start; background: var(--surface-2); border-radius: 0 0 12px 12px; }
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px 14px; }
.field { display: flex; flex-direction: column; gap: 4px; }
.field.full { grid-column: 1 / -1; }
.field label { font-size: 13px; color: var(--text-2); font-weight: 500; }
.field label .req { color: var(--danger); }
.field input, .field select, .field textarea { padding: 8px 10px; border: 1px solid var(--border); border-radius: 8px; background: var(--surface); width: 100%; }
.field input:focus, .field select:focus, .field textarea:focus { outline: 2px solid #b9cbee; border-color: var(--primary); }
.field textarea { min-height: 80px; resize: vertical; }
.field .hint { font-size: 12px; color: var(--muted); }
.check-list { display: flex; flex-wrap: wrap; gap: 6px 14px; padding: 6px 0; }
.check-list label { display: flex; align-items: center; gap: 6px; font-weight: 400; color: var(--text); }
.field.inline { flex-direction: row; align-items: center; gap: 8px; }
.invoice-lines td input[type=checkbox] { width: 16px; height: 16px; }

.toast { position: fixed; bottom: 22px; left: 22px; background: var(--navy); color: #fff; padding: 10px 16px; border-radius: 8px; z-index: 200; box-shadow: 0 6px 18px rgba(0,0,0,.2); animation: fade .2s ease; }
@keyframes fade { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }

.role-banner { background: var(--gold-soft); border-bottom: 1px solid #ead9a6; color: #6b510f; font-size: 12px; padding: 5px 24px; }
.search-group h3 { font-size: 14px; margin: 18px 0 8px; color: var(--text-2); }
.highlight { background: #fff3c4; border-radius: 2px; }
.progress { height: 6px; background: #eceef2; border-radius: 4px; overflow: hidden; }
.progress > span { display: block; height: 100%; background: var(--success); }

@media print {
  .sidebar, .topbar, .role-banner, .no-print { display: none !important; }
  .content { padding: 0; }
  .card { box-shadow: none; border: none; }
  body.has-modal #app { display: none; }
  .modal-backdrop { position: static; background: none; padding: 0; }
  .modal { box-shadow: none; max-width: none; }
  .modal-head, .modal-foot { display: none; }
  .modal .card { border: 1px solid var(--border); }
}

@media (max-width: 1100px) {
  .grid-4 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .grid-3 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}
@media (max-width: 860px) {
  .sidebar { position: fixed; right: 0; z-index: 40; transform: translateX(100%); transition: transform .2s; }
  .sidebar.open { transform: none; box-shadow: -10px 0 30px rgba(0,0,0,.25); }
  .menu-btn { display: inline-grid; }
  .grid-2, .grid-3, .kanban { grid-template-columns: minmax(0, 1fr); }
  .span-2 { grid-column: auto; }
  .content { padding: 16px; }
  .topbar { padding: 10px 16px; flex-wrap: wrap; }
  .user-switch label { display: none; }
  .form-grid { grid-template-columns: 1fr; }
  .cal .cell { min-height: 64px; }
  .cal .ev { font-size: 0; height: 6px; padding: 0; }
  .kv { grid-template-columns: 110px 1fr; }
}
@media (max-width: 560px) {
  .grid-4 { grid-template-columns: minmax(0, 1fr); }
}
