:root {
  /* Brand — calm, desaturated sage green */
  --brand-50: #f1f5ec;
  --brand-100: #e4ebdb;
  --brand-200: #c9d8b8;
  --brand-500: #618c4e;
  --brand-600: #4f7a3d;
  --brand-700: #40662f;
  --brand-800: #355426;

  /* Neutrals — warm gray-green */
  --ink: #21261d;
  --gray-800: #363d30;
  --gray-600: #5c6455;
  --text-muted: #7c8471;
  --border: #e6e8e0;
  --border-strong: #d4d8ca;
  --surface: #fdfdfc;
  --bg: #f4f5f0;

  /* Sidebar — soft dark olive */
  --side-bg: #20261b;
  --side-bg2: #272e21;
  --side-text: #a8b19b;
  --side-text-hover: #e8ece1;
  --side-active: rgba(255, 255, 255, .07);

  /* Semantic — muted */
  --red: #b5473f;
  --red-bg: #f8eeed;
  --amber: #a97f24;
  --amber-bg: #f7f1e1;
  --blue: #3a76b1;
  --blue-bg: #edf2f8;
  --green: var(--brand-600);
  --green-bg: var(--brand-50);

  /* Data-viz series (CVD-validated set, fixed order) */
  --viz-1: #4f7a3d;   /* sage — field / primary series */
  --viz-2: #3a76b1;   /* slate blue — scheduling */
  --viz-3: #b08a3e;   /* sand — waiting parts */
  --viz-4: #b4664f;   /* terracotta — client approval */
  --viz-5: #7c62b5;   /* violet — spare */
  --viz-track: #e7ecdf;   /* unfilled track / de-emphasis */
  --viz-dim: #b6c0a8;     /* de-emphasised series (sparkline) */
  --grid: #e4e5dd;        /* hairline gridline */

  --radius: 12px;
  --shadow-sm: 0 1px 2px rgba(28, 33, 22, .05);
  --shadow-md: 0 6px 22px rgba(28, 33, 22, .08);
  --sidebar-w: 256px;
}

* { box-sizing: border-box; margin: 0; padding: 0; }
html, body { height: 100%; }
body {
  font-family: 'Tajawal', 'Segoe UI', Tahoma, sans-serif;
  background: var(--bg);
  color: var(--ink);
  font-size: 14px;
  -webkit-font-smoothing: antialiased;
}
a { color: var(--brand-700); text-decoration: none; }
button { font-family: inherit; }
.svg-ic { flex-shrink: 0; vertical-align: -3px; }

/* ================= LOGIN ================= */
.login-wrap {
  min-height: 100vh;
  display: flex; align-items: stretch;
  background: var(--bg);
}
.login-side {
  flex: 1.1;
  background: linear-gradient(160deg, #1d2417 0%, #2a3520 55%, #37472a 100%);
  color: #dfe5d6;
  display: flex; flex-direction: column; justify-content: center;
  padding: 64px;
  position: relative; overflow: hidden;
}
.login-side::after {
  content: '';
  position: absolute; inset-inline-end: -140px; bottom: -140px;
  width: 420px; height: 420px; border-radius: 50%;
  background: radial-gradient(circle, rgba(151, 183, 116, .22), transparent 65%);
}
.login-side img { width: 96px; background: #fff; border-radius: 18px; padding: 10px; margin-bottom: 28px; }
.login-side h1 { font-size: 30px; color: #fff; margin-bottom: 8px; font-weight: 800; }
.login-side .lead { font-size: 15px; line-height: 1.9; color: #b9c9ac; max-width: 420px; }
.login-side .feat { margin-top: 34px; display: grid; gap: 12px; }
.login-side .feat div { display: flex; align-items: center; gap: 10px; font-size: 13.5px; color: #cfdcc3; }
.login-side .feat svg { color: #8fc356; }

.login-panel {
  flex: 1;
  display: flex; align-items: center; justify-content: center;
  padding: 40px 24px;
}
.login-card { width: 100%; max-width: 400px; }
.login-brand { display: none; text-align: center; margin-bottom: 22px; }
.login-brand img {
  width: 88px; background: #fff; border-radius: 20px; padding: 10px;
  box-shadow: 0 6px 24px rgba(45, 66, 32, .14); margin-bottom: 12px;
}
.login-brand h1 { font-size: 20px; font-weight: 800; color: var(--brand-800); }
.login-card h2 { font-size: 22px; margin-bottom: 4px; font-weight: 800; }
.login-card .sub { color: var(--text-muted); margin-bottom: 26px; font-size: 13.5px; }
.login-error {
  background: var(--red-bg); color: var(--red); border: 1px solid #f0cccc;
  border-radius: 8px; padding: 9px 12px; margin-bottom: 14px; font-size: 13px; display: none;
}
.login-btn { width: 100%; justify-content: center; margin-top: 20px; padding: 12px; font-size: 14.5px; }

/* demo accounts — tappable chips */
.demo-box { margin-top: 22px; }
.demo-title {
  font-size: 12px; font-weight: 700; color: var(--text-muted); margin-bottom: 9px; text-align: center;
}
.demo-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.demo-acc {
  background: var(--surface); border: 1px solid var(--border); border-radius: 10px;
  padding: 8px 10px; cursor: pointer; text-align: start; transition: .12s;
  display: flex; flex-direction: column; gap: 2px; min-width: 0;
}
.demo-acc b { font-size: 12px; color: var(--gray-800); }
.demo-acc span {
  font-size: 10.5px; color: var(--text-muted);
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap; display: block;
}
.demo-acc:hover { border-color: var(--brand-500); background: var(--brand-50); }
.demo-acc.active { border-color: var(--brand-600); background: var(--brand-50); box-shadow: 0 0 0 2px rgba(106,167,44,.18); }

@media (max-width: 860px) {
  .login-side { display: none; }
  .login-brand { display: block; }
  .login-wrap { background: linear-gradient(180deg, #eef3e7 0%, var(--bg) 260px); }
  .login-panel { padding: 34px 20px; align-items: flex-start; }
  .login-card h2, .login-card .sub { text-align: center; }
  .login-card input { padding: 12px 13px; font-size: 16px; } /* 16px prevents iOS auto-zoom */
}

/* ================= LAYOUT ================= */
.layout { display: flex; min-height: 100vh; }
.sidebar {
  width: var(--sidebar-w);
  background: linear-gradient(180deg, var(--side-bg), var(--side-bg2));
  color: var(--side-text); flex-shrink: 0; display: flex; flex-direction: column;
  position: sticky; top: 0; height: 100vh; overflow-y: auto;
}
.sidebar::-webkit-scrollbar { width: 5px; }
.sidebar::-webkit-scrollbar-thumb { background: rgba(255,255,255,.14); border-radius: 3px; }
.sidebar .brand {
  display: flex; align-items: center; gap: 12px; padding: 20px 18px;
  border-bottom: 1px solid rgba(255,255,255,.07);
}
.sidebar .brand img { width: 42px; background: #fff; border-radius: 10px; padding: 4px; }
.sidebar .brand div { line-height: 1.3; }
.sidebar .brand b { font-size: 15px; display: block; color: #f4f8ef; font-weight: 800; }
.sidebar .brand span { font-size: 11px; color: #8a9c7d; }
.nav { padding: 14px 12px; flex: 1; }
.nav a {
  display: flex; align-items: center; gap: 11px; color: var(--side-text);
  padding: 9px 12px; border-radius: 8px; margin-bottom: 1px; font-size: 13.5px; font-weight: 500;
  border-inline-start: 3px solid transparent; transition: background .12s, color .12s;
}
.nav a svg { opacity: .75; }
.nav a:hover { background: rgba(255,255,255,.06); color: var(--side-text-hover); }
.nav a.active {
  background: var(--side-active); color: #fff; font-weight: 700;
  border-inline-start-color: var(--brand-500);
}
.nav a.active svg { opacity: 1; color: #aac48e; }
.nav .nav-sec {
  font-size: 10.5px; color: #6d7f60; margin: 18px 12px 6px;
  text-transform: uppercase; letter-spacing: 1.2px; font-weight: 700;
}
.sidebar .side-foot { padding: 14px 12px; border-top: 1px solid rgba(255,255,255,.07); }
.sidebar .side-foot button {
  width: 100%; display: flex; align-items: center; justify-content: center; gap: 8px;
  background: rgba(255,255,255,.05); color: var(--side-text); border: 1px solid rgba(255,255,255,.1);
  border-radius: 8px; padding: 9px; font-size: 13px; font-weight: 600; cursor: pointer;
}
.sidebar .side-foot button:hover { background: rgba(255,255,255,.1); color: #fff; }

.main { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.topbar {
  background: var(--surface); border-bottom: 1px solid var(--border);
  padding: 0 24px; height: 60px;
  display: flex; align-items: center; gap: 12px; position: sticky; top: 0; z-index: 40;
}
.topbar .title {
  font-size: 16px; font-weight: 800; flex: 1; color: var(--ink);
  min-width: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.icon-btn {
  background: var(--surface); border: 1px solid var(--border); width: 38px; height: 38px;
  border-radius: 9px; cursor: pointer; position: relative; color: var(--gray-600);
  display: inline-flex; align-items: center; justify-content: center; transition: .12s;
}
.icon-btn:hover { background: var(--bg); border-color: var(--border-strong); color: var(--ink); }
.icon-btn .badge {
  position: absolute; top: -5px; inset-inline-end: -5px; background: var(--red); color: #fff;
  font-size: 10px; min-width: 17px; height: 17px; border-radius: 9px;
  display: flex; align-items: center; justify-content: center; padding: 0 3px; font-weight: 700;
}
.lang-btn { width: auto; padding: 0 12px; gap: 7px; font-weight: 700; font-size: 12.5px; }
.user-chip {
  display: flex; align-items: center; gap: 10px; padding: 5px 6px 5px 14px; border-radius: 9px;
  transition: background .12s;
}
.user-chip:hover { background: var(--bg); }
html[dir="rtl"] .user-chip { padding: 5px 14px 5px 6px; }
.user-chip .avatar {
  width: 34px; height: 34px; background: linear-gradient(135deg, var(--brand-500), var(--brand-700));
  color: #fff; border-radius: 9px; display: flex; align-items: center; justify-content: center; font-weight: 800; font-size: 14px;
}
.user-chip .meta { line-height: 1.2; }
.user-chip .meta b { font-size: 13px; display: block; }
.user-chip .meta span { font-size: 11px; color: var(--text-muted); }

.content { padding: 26px 28px; flex: 1; max-width: 1560px; }

/* ================= CARDS / GRID ================= */
.grid { display: grid; gap: 16px; }
.grid > * { min-width: 0; }
.cols-2 { grid-template-columns: repeat(2, 1fr); }
.cols-3 { grid-template-columns: repeat(3, 1fr); }
.cols-4 { grid-template-columns: repeat(4, 1fr); }
@media (max-width: 1100px) { .cols-4, .cols-3 { grid-template-columns: repeat(2, 1fr); } }
@media (max-width: 700px) { .cols-4, .cols-3, .cols-2 { grid-template-columns: 1fr; } }

.card {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); box-shadow: var(--shadow-sm); padding: 20px;
}
.card h3 {
  font-size: 14px; font-weight: 800; margin: -4px 0 14px; padding-bottom: 10px; color: var(--ink);
  display: flex; align-items: center; justify-content: space-between; gap: 8px;
  border-bottom: 1px solid var(--border);
}
.card h3 .h-ic { color: var(--brand-600); }

.stat { display: flex; align-items: center; gap: 14px; }
.stat .ic {
  width: 46px; height: 46px; border-radius: 11px; display: flex; align-items: center;
  justify-content: center; background: var(--green-bg); color: var(--brand-600);
}
.stat .ic.red { background: var(--red-bg); color: var(--red); }
.stat .ic.amber { background: var(--amber-bg); color: var(--amber); }
.stat .ic.blue { background: var(--blue-bg); color: var(--blue); }
.stat .num { font-size: 25px; font-weight: 800; line-height: 1.1; }
.stat .lbl { font-size: 12px; color: var(--text-muted); margin-top: 3px; font-weight: 600; }

/* ================= PAGE HEAD ================= */
.page-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 20px; flex-wrap: wrap; }
.page-head h2 { font-size: 19px; font-weight: 800; display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.page-head h2 .h-ic { color: var(--brand-600); }
.page-head .actions { display: flex; gap: 8px; flex-wrap: wrap; }

/* ================= BUTTONS ================= */
.btn {
  border: 1px solid transparent; border-radius: 8px; padding: 8px 16px; font-size: 13px; font-weight: 700;
  cursor: pointer; display: inline-flex; align-items: center; gap: 7px; transition: .13s; line-height: 1.4;
}
.btn svg { margin-inline-start: -2px; }
.btn-primary { background: var(--brand-600); color: #fff; box-shadow: var(--shadow-sm); }
.btn-primary:hover { background: var(--brand-700); }
.btn-outline { background: var(--surface); color: var(--brand-700); border-color: var(--brand-200); }
.btn-outline:hover { background: var(--brand-50); border-color: var(--brand-500); }
.btn-ghost { background: var(--surface); color: var(--gray-800); border-color: var(--border); }
.btn-ghost:hover { background: var(--bg); border-color: var(--border-strong); }
.btn-danger { background: var(--surface); color: var(--red); border-color: #eeD3d3; }
.btn-danger:hover { background: var(--red-bg); border-color: #e3b6b6; }
.btn-sm { padding: 4px 10px; font-size: 12px; border-radius: 7px; }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn:active:not(:disabled) { transform: translateY(1px); }
:focus-visible { outline: 2px solid var(--brand-500); outline-offset: 2px; border-radius: 4px; }
.kpi-link { cursor: pointer; transition: border-color .12s, box-shadow .12s; }
.kpi-link:hover { border-color: var(--red); box-shadow: 0 2px 10px rgba(181, 71, 63, .12); }

/* ================= TABLES ================= */
.table-wrap {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); box-shadow: var(--shadow-sm); overflow: auto;
}
table { width: 100%; border-collapse: collapse; min-width: 640px; }
.table-wrap { max-height: 72vh; }
th {
  text-align: start; font-size: 11px; color: var(--text-muted); font-weight: 700;
  padding: 11px 16px; border-bottom: 1px solid var(--border); white-space: nowrap;
  background: #fafbf8; text-transform: uppercase; letter-spacing: .6px;
  position: sticky; top: 0; z-index: 2;
}
td {
  padding: 11px 16px; border-bottom: 1px solid var(--border); font-size: 13.5px;
  vertical-align: middle; font-variant-numeric: tabular-nums;
}
tr:last-child td { border-bottom: none; }
tbody tr { transition: background .1s; }
tbody tr:hover { background: #fafbf7; }
tbody tr.clickable:hover { background: var(--brand-50); cursor: pointer; }
.empty { text-align: center; color: var(--text-muted); padding: 44px !important; font-size: 13px; }

/* ================= BADGES ================= */
.pill {
  display: inline-flex; align-items: center; gap: 5px; padding: 2.5px 10px; border-radius: 6px;
  font-size: 11.5px; font-weight: 700; white-space: nowrap; border: 1px solid transparent;
}
.pill::before { content: ''; width: 6px; height: 6px; border-radius: 50%; background: currentColor; opacity: .75; }
.pill.green { background: var(--green-bg); color: var(--brand-700); border-color: #d8e9c2; }
.pill.gray  { background: #f1f3ee; color: var(--gray-600); border-color: var(--border); }
.pill.red   { background: var(--red-bg); color: var(--red); border-color: #f0d4d4; }
.pill.amber { background: var(--amber-bg); color: var(--amber); border-color: #eedfbc; }
.pill.blue  { background: var(--blue-bg); color: var(--blue); border-color: #cfe1f2; }

/* ================= FORMS ================= */
.form-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 13px 14px; }
.form-grid .full { grid-column: 1 / -1; }
@media (max-width: 600px) { .form-grid { grid-template-columns: 1fr; } }
label.fld { display: block; font-size: 12px; font-weight: 700; color: var(--gray-800); }
label.fld span { display: block; margin-bottom: 5px; }
input, select, textarea {
  width: 100%; border: 1px solid var(--border-strong); border-radius: 8px; padding: 8.5px 12px;
  font-family: inherit; font-size: 13.5px; background: var(--surface); color: var(--ink); transition: border-color .12s, box-shadow .12s;
}
input:focus, select:focus, textarea:focus {
  outline: none; border-color: var(--brand-500); box-shadow: 0 0 0 3px rgba(106, 167, 44, .14);
}
textarea { resize: vertical; min-height: 74px; }

/* ================= MODAL ================= */
.modal-overlay {
  position: fixed; inset: 0; background: rgba(16, 24, 12, .5); z-index: 100;
  display: flex; align-items: flex-start; justify-content: center; padding: 48px 16px; overflow-y: auto;
  backdrop-filter: blur(2px);
}
.modal {
  background: var(--surface); border-radius: 14px; width: 100%; max-width: 620px; padding: 26px;
  box-shadow: 0 24px 64px rgba(0,0,0,.28); animation: pop .16s ease; position: relative;
}
.modal.wide { max-width: 900px; }
.modal h3 {
  margin: -4px 0 20px; padding-bottom: 12px; font-size: 16px; font-weight: 800;
  border-bottom: 1px solid var(--border);
}
.modal .modal-x {
  position: absolute; top: 18px; inset-inline-end: 18px;
  width: 30px; height: 30px; border: none; background: var(--bg); border-radius: 8px;
  cursor: pointer; color: var(--gray-600); display: flex; align-items: center; justify-content: center;
}
.modal .modal-x:hover { background: var(--red-bg); color: var(--red); }
.confirm-modal h3 { border-bottom: none; padding-bottom: 0; }
.modal .modal-actions { display: flex; justify-content: flex-end; gap: 9px; margin-top: 22px; }
@keyframes pop { from { transform: translateY(12px); opacity: 0; } to { transform: none; opacity: 1; } }

/* confirm dialog */
.confirm-modal { max-width: 420px; }
.confirm-ic {
  width: 54px; height: 54px; border-radius: 50%; margin: 0 auto 14px;
  background: var(--red-bg); color: var(--red);
  display: flex; align-items: center; justify-content: center;
}
.confirm-ic.safe { background: var(--brand-50); color: var(--brand-700); }
.confirm-msg { text-align: center; color: var(--gray-600); font-size: 14px; line-height: 1.8; margin-bottom: 6px; }
.btn-danger-solid { background: var(--red); color: #fff; }
.btn-danger-solid:hover { background: #9e3a33; }

/* ================= TOAST ================= */
#toast-root { position: fixed; bottom: 20px; inset-inline-start: 20px; z-index: 200; display: flex; flex-direction: column; gap: 8px; }
.toast {
  background: var(--gray-800); color: #fff; border-radius: 9px; padding: 11px 18px; font-size: 13px;
  box-shadow: var(--shadow-md); animation: pop .18s ease; font-weight: 600;
}
.toast.error { background: var(--red); }
.toast.success { background: var(--brand-700); }

/* ================= NOTIFICATIONS ================= */
.notif-panel {
  position: absolute; top: 54px; inset-inline-end: 76px; width: 360px; max-height: 440px; overflow-y: auto;
  background: var(--surface); border: 1px solid var(--border); border-radius: 12px;
  box-shadow: var(--shadow-md); z-index: 90; padding: 8px;
}
.notif-item { padding: 10px 12px; border-radius: 8px; font-size: 13px; display: block; color: var(--ink); }
.notif-item:hover { background: var(--bg); }
.notif-item.unread { background: var(--brand-50); }
.notif-item .t { color: var(--text-muted); font-size: 11px; margin-top: 3px; }

/* ================= DETAIL PAGES ================= */
.kv { display: grid; grid-template-columns: repeat(auto-fill, minmax(210px, 1fr)); gap: 14px 22px; }
.kv .k { font-size: 11px; color: var(--text-muted); font-weight: 700; margin-bottom: 3px; text-transform: uppercase; letter-spacing: .4px; }
.kv .v { font-size: 13.5px; font-weight: 600; }
.section-title { font-size: 15px; font-weight: 800; margin: 22px 0 10px; }

/* timeline */
.timeline { position: relative; padding-inline-start: 22px; }
.timeline::before { content: ''; position: absolute; inset-inline-start: 7px; top: 6px; bottom: 6px; width: 2px; background: var(--border); }
.tl-item { position: relative; padding-bottom: 16px; }
.tl-item::before {
  content: ''; position: absolute; inset-inline-start: -21px; top: 4px; width: 11px; height: 11px;
  border-radius: 50%; background: var(--brand-500); border: 2.5px solid var(--surface); box-shadow: 0 0 0 2px var(--brand-500);
}
.tl-item .tl-status { font-weight: 800; font-size: 13px; }
.tl-item .tl-meta { color: var(--text-muted); font-size: 11.5px; }

/* drawing viewer */
.viewer-toolbar {
  display: flex; align-items: center; gap: 6px; padding: 0 2px 10px;
}
.viewer-toolbar .vz-level {
  min-width: 52px; text-align: center; font-size: 12.5px; font-weight: 700; color: var(--gray-800);
  background: var(--bg); border: 1px solid var(--border); border-radius: 8px; padding: 8px 6px;
}
.drawing-stage {
  position: relative; width: 100%; height: 72vh; border: 1px solid var(--border-strong);
  border-radius: 10px; overflow: hidden; background:
    repeating-conic-gradient(#fafbf8 0% 25%, #f2f4ee 0% 50%) 0 0 / 22px 22px;
  cursor: grab; touch-action: none; user-select: none;
}
.drawing-stage.grabbing { cursor: grabbing; }
.drawing-stage.pin-mode { cursor: crosshair; }
.drawing-stage:fullscreen { border-radius: 0; height: 100vh; background: #fff; }
.stage-inner { position: absolute; top: 0; left: 0; transform-origin: 0 0; line-height: 0; }
.stage-inner img { display: block; max-width: none; pointer-events: none; }
.pin { position: absolute; transform: translate(-50%, -100%); cursor: pointer; z-index: 5; line-height: 0; transition: transform .1s; }
.pin:hover { transform: translate(-50%, -100%) scale(1.2); }

/* attachments */
.attach-grid { display: flex; flex-wrap: wrap; gap: 10px; }
.attach-card { width: 132px; border: 1px solid var(--border); border-radius: 10px; overflow: hidden; background: var(--surface); position: relative; }
.attach-card img { width: 100%; height: 86px; object-fit: cover; display: block; }
.attach-card .file-ic { height: 86px; display: flex; align-items: center; justify-content: center; background: var(--bg); color: var(--text-muted); }
.attach-card .nm { font-size: 11px; padding: 5px 8px; word-break: break-all; color: var(--gray-600); }
.attach-card .tag-lbl { position: absolute; top: 5px; inset-inline-start: 5px; }
.attach-card .del {
  position: absolute; top: 5px; inset-inline-end: 5px; background: rgba(20,28,15,.6); color: #fff;
  border: none; border-radius: 6px; cursor: pointer; width: 22px; height: 22px;
  display: flex; align-items: center; justify-content: center;
}
.attach-card .del:hover { background: var(--red); }

/* filters bar */
.filters { display: flex; gap: 10px; margin-bottom: 16px; flex-wrap: wrap; }
.filters input, .filters select { width: auto; min-width: 170px; }

/* bar chart (reports) */
.hbar { display: flex; align-items: center; gap: 10px; margin-bottom: 9px; }
.hbar .lbl { width: 170px; font-size: 12.5px; text-align: end; flex-shrink: 0; color: var(--gray-800); font-weight: 600; }
.hbar .track { flex: 1; background: #eef1ea; border-radius: 5px; height: 22px; overflow: hidden; }
.hbar .fill {
  height: 100%; background: linear-gradient(90deg, var(--brand-500), var(--brand-600));
  border-radius: 5px; display: flex; align-items: center; color: #fff; font-size: 11.5px; padding: 0 8px; min-width: 26px; font-weight: 700;
}

.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--border); margin-bottom: 18px; flex-wrap: wrap; }
.tabs button {
  background: none; border: none; padding: 9px 16px; font-size: 13.5px; font-weight: 700; color: var(--text-muted);
  cursor: pointer; border-bottom: 2px solid transparent; margin-bottom: -1px;
}
.tabs button.active { color: var(--brand-700); border-color: var(--brand-600); }

/* ================= DASHBOARD / DATA-VIZ ================= */
.kpi { display: flex; flex-direction: column; gap: 6px; min-width: 0; }
.kpi .k-label { font-size: 12px; font-weight: 700; color: var(--text-muted); }
.kpi .k-row { display: flex; align-items: flex-end; gap: 10px; }
.kpi .k-value { font-size: 30px; font-weight: 800; line-height: 1; color: var(--ink); }
.kpi .k-sub { font-size: 11.5px; color: var(--text-muted); }
.kpi .k-spark { margin-inline-start: auto; }
.delta {
  display: inline-flex; align-items: center; gap: 3px; font-size: 11.5px; font-weight: 700;
  padding: 2px 7px; border-radius: 6px;
}
.delta.good { color: #35682a; background: var(--brand-50); }
.delta.bad  { color: var(--red); background: var(--red-bg); }
.delta.flat { color: var(--text-muted); background: var(--bg); }

.viz-title { font-size: 13px; font-weight: 800; color: var(--ink); margin-bottom: 2px; }
.viz-sub { font-size: 11.5px; color: var(--text-muted); margin-bottom: 12px; }
.viz-axis { font-size: 10.5px; fill: var(--text-muted); }
.viz-grid { stroke: var(--grid); stroke-width: 1; }

.legend { display: flex; flex-direction: column; gap: 8px; }
.legend .lg-item { display: flex; align-items: center; gap: 8px; font-size: 12.5px; color: var(--gray-800); }
.legend .lg-item .sw { width: 10px; height: 10px; border-radius: 3px; flex-shrink: 0; }
.legend .lg-item .lg-n { margin-inline-start: auto; font-weight: 800; color: var(--ink); }

.meter { display: flex; align-items: center; gap: 10px; }
.meter .m-track { flex: 1; height: 8px; background: var(--viz-track); border-radius: 4px; overflow: hidden; }
.meter .m-fill { height: 100%; border-radius: 4px; background: var(--brand-500); }
.meter .m-val { font-size: 11.5px; font-weight: 700; color: var(--text-muted); white-space: nowrap; }

.viz-tip {
  position: fixed; z-index: 300; pointer-events: none; display: none;
  background: var(--gray-800); color: #fff; border-radius: 8px; padding: 7px 11px;
  font-size: 12px; font-weight: 600; box-shadow: var(--shadow-md); max-width: 240px;
}
.viz-tip .tp-sub { color: #cbd2c0; font-weight: 500; font-size: 11px; }

.list-row { display: flex; align-items: center; gap: 10px; padding: 9px 0; border-bottom: 1px solid var(--border); font-size: 13px; }
.list-row:last-child { border-bottom: none; }
.list-row .lr-main { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.list-row .lr-sub { font-size: 11.5px; color: var(--text-muted); }

/* maps */
.map-box {
  height: 280px; border-radius: 10px; border: 1px solid var(--border);
  position: relative; z-index: 0; overflow: hidden;
}
.map-box.small { height: 220px; }
.leaflet-container { font-family: inherit; }

/* open-row affordance */
.open-cell { width: 84px; text-align: end; color: var(--text-muted); white-space: nowrap; }
.open-cell .open-hint {
  font-size: 11.5px; font-weight: 700; color: var(--brand-700);
  opacity: 0; transition: opacity .12s; margin-inline-end: 4px;
}
tbody tr.clickable:hover .open-cell .open-hint { opacity: 1; }
tbody tr.clickable:hover .open-cell { color: var(--brand-700); }
html[dir="rtl"] .open-cell svg { transform: scaleX(-1); }

/* data-table pagination footer */
.dt-foot { display: flex; align-items: center; gap: 6px; margin-top: 12px; flex-wrap: wrap; }
.dt-pg {
  min-width: 32px; height: 32px; border: 1px solid var(--border); background: var(--surface);
  border-radius: 7px; cursor: pointer; font-size: 13px; font-weight: 700; color: var(--gray-800); padding: 0 8px;
}
.dt-pg:hover:not(:disabled) { border-color: var(--brand-500); color: var(--brand-700); }
.dt-pg.active { background: var(--brand-600); border-color: var(--brand-600); color: #fff; }
.dt-pg:disabled { opacity: .4; cursor: default; }
.dt-ell { color: var(--text-muted); padding: 0 2px; }
.dt-size { padding: 5px 8px; font-size: 12.5px; }

/* Saudi Riyal symbol */
.money { white-space: nowrap; display: inline-flex; align-items: center; gap: 3px; unicode-bidi: embed; }
.sar { width: .85em; height: .95em; flex-shrink: 0; opacity: .85; }

.muted { color: var(--text-muted); font-size: 12.5px; }
.mb8 { margin-bottom: 8px; } .mb16 { margin-bottom: 16px; } .mt16 { margin-top: 16px; }
.row { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.spacer { flex: 1; }
.loading { display: flex; align-items: center; justify-content: center; padding: 80px; color: var(--text-muted); }
.spinner {
  width: 30px; height: 30px; border: 3px solid var(--border); border-top-color: var(--brand-600);
  border-radius: 50%; animation: spin .7s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* content scrollbars */
.content::-webkit-scrollbar, .table-wrap::-webkit-scrollbar, .modal-overlay::-webkit-scrollbar { width: 9px; height: 9px; }
.content::-webkit-scrollbar-thumb, .table-wrap::-webkit-scrollbar-thumb, .modal-overlay::-webkit-scrollbar-thumb {
  background: var(--border-strong); border-radius: 5px;
}
.table-wrap::-webkit-scrollbar-thumb:hover { background: var(--gray-600); }

@media (max-width: 900px) {
  html, body { overflow-x: hidden; } /* off-canvas sidebar must not widen the page */
  .sidebar { position: fixed; inset-inline-start: -270px; transition: .25s; z-index: 80; }
  .sidebar.open { inset-inline-start: 0; }
  .burger { display: inline-flex !important; }
  .content { padding: 18px 14px; }

  /* custom-ratio grids (inline styles) collapse to a single column on small screens */
  .grid[style*="grid-template-columns"] { grid-template-columns: 1fr !important; }

  /* filters become full-width stacked controls */
  .filters input, .filters select { flex: 1 1 100%; min-width: 0 !important; width: 100%; }

  .page-head h2 { font-size: 17px; }
  .kpi .k-value { font-size: 26px; }
  .viewer-toolbar { flex-wrap: wrap; }
  .drawing-stage { height: 58vh; }
  .notif-panel { inset-inline-end: 10px; inset-inline-start: 10px; width: auto; }
  .user-chip .meta { display: none; } /* avatar only on narrow topbar */
  .content, .page-head .actions { max-width: 100%; }
  .page-head .actions .btn { flex: 1 1 auto; justify-content: center; }
}
.burger { display: none; }

@media print {
  .sidebar, .topbar, .page-head .actions, .btn, .filters { display: none !important; }
  .content { padding: 0; }
  body { background: #fff; }
  .card, .table-wrap { box-shadow: none; border: 1px solid #ddd; }
}
