/* ===== ORCA Agency Dashboard styles (modified) ===== */
:root {
  --orca-blue: #1E5EFF;
  --orca-blue-dark: #1849cc;
  --orca-navy: #0D1B2A;
  --bg: #f5f7fb;
  --card: #ffffff;
  --border: #e4e7ec;
  --text: #0D1B2A;
  --muted: #6b7280;
  --muted-soft: #9aa0a6;
  --danger: #dc2626;
  --success: #16a34a;
  --warning: #f59e0b;
  --radius: 10px;
  --shadow: 0 1px 2px rgba(0,0,0,.04), 0 4px 14px rgba(13,27,42,.06);
  --shadow-lg: 0 8px 30px rgba(13,27,42,.12);
  --font-en: "Inter", system-ui, -apple-system, sans-serif;
  --font-ar: "Tajawal", system-ui, sans-serif;
  --transition: 180ms cubic-bezier(.4,.0,.2,1);
  --surface-2: #f1f5f9;       /* hover / secondary surface (light mode)  */
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; height: 100%; }
body {
  font-family: var(--font-ar);
  background: var(--bg);
  color: var(--text);
  -webkit-font-smoothing: antialiased;
  font-size: 14px;
  line-height: 1.5;
  overflow-x: hidden; /* prevent horizontal scroll on mobile */
}
html[lang="en"] body { font-family: var(--font-en); }

a { color: var(--orca-blue); text-decoration: none; transition: color var(--transition); }
a:hover { text-decoration: underline; }
button { font-family: inherit; cursor: pointer; transition: background var(--transition), color var(--transition), transform var(--transition), box-shadow var(--transition); }
button:active { transform: scale(.97); }

/* Splash — large prominent logo at the top of the page on first load */
.splash {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: flex-start;
  min-height: 100vh;
  background: var(--bg);
  padding-top: 12vh;
}
.splash-logo {
  width: 220px;
  height: 220px;
  object-fit: contain;
  opacity: .95;
  transform: none;
  will-change: opacity;
  animation: pulse 1.5s ease-in-out infinite;
}
@keyframes pulse { 0%,100%{opacity:.72;} 50%{opacity:1;} }

/* ===== Layout shell — RTL FIX =====
   The DOM order is <sidebar> then <main>. We use logical grid columns in BOTH
   directions; the browser flips them visually for RTL. The previous version
   re-flipped them in RTL which made the sidebar stretch and cover the screen.
*/
.shell {
  display: grid;
  grid-template-columns: 240px minmax(0, 1fr); /* minmax prevents content overflow */
  min-height: 100vh;
}
/* No RTL override — let CSS Grid + dir="rtl" handle the flip naturally. */

.sidebar {
  background: var(--orca-navy);
  color: #fff;
  padding: 22px 16px;
  display: flex;
  flex-direction: column;
  gap: 4px;
  position: sticky;
  top: 0;
  height: 100vh;
  overflow-y: auto;
  z-index: 40;
  transition: transform var(--transition);
}
.sidebar-brand { display:flex; flex-direction:column; align-items:center; gap:0px; padding: 10px 6px 20px; }
.sidebar-brand img { width: 152px; height: 152px; object-fit: contain; }
.sidebar-brand .title { font-weight: 800; font-size: 19px; line-height: 1.15; }
.sidebar-brand .subtitle { font-size: 14px; font-weight:500; opacity: .85; text-align: center; margin-top: -40px; }
.nav-link {
  display: flex; align-items: center; gap: 12px;
  padding: 10px 12px; border-radius: 8px;
  color: rgba(255,255,255,.78); font-weight: 500;
  cursor: pointer; transition: background var(--transition), color var(--transition), transform var(--transition);
  font-size: 14px; position: relative;
}
.nav-link:hover { background: rgba(255,255,255,.06); color: #fff; text-decoration: none; transform: translateX(2px); }
html[dir="rtl"] .nav-link:hover { transform: translateX(-2px); }
.nav-link.active { background: var(--orca-blue); color: #fff; }
.nav-link svg { width: 18px; height: 18px; flex-shrink: 0; }
.nav-link .badge { margin-inline-start: auto; }
[data-tasks-badge] { background: var(--orca-blue) !important; color: #fff !important; border-color: transparent !important; padding: 2px 7px !important; }
.sidebar-footer { margin-top: auto; padding-top: 14px; border-top: 1px solid rgba(255,255,255,.08); font-size: 12px; opacity: .65; }

.main {
  display: flex;
  flex-direction: column;
  min-height: 100vh;
  min-width: 0; /* critical: prevents grid blowout when content is wide */
}
.topbar {
  background: #fff; border-bottom: 1px solid var(--border);
  padding: 14px 28px; display:flex; align-items:center; justify-content: space-between;
  position: sticky; top: 0; z-index: 30;
  gap: 12px;
}
.topbar-left { display:flex; align-items:center; gap: 12px; min-width: 0; }
.topbar-left h2 { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.topbar-actions { display:flex; align-items:center; gap: 6px; flex-wrap: nowrap; }
.icon-btn {
  background: transparent; border: 1px solid transparent; border-radius: 8px;
  width: 36px; height: 36px; display:inline-flex; align-items:center; justify-content:center;
  color: var(--muted); transition: background var(--transition), color var(--transition); position: relative;
}
.icon-btn:hover { background: var(--bg); color: var(--text); }
.icon-btn svg { width: 18px; height: 18px; }
.icon-btn .dot {
  position: absolute; top: 6px; inset-inline-end: 6px;
  min-width: 16px; height: 16px; border-radius: 999px; background: var(--danger);
  color: #fff; font-size: 10px; font-weight: 700; display:inline-flex; align-items:center; justify-content:center;
  padding: 0 4px;
}
.menu-btn { display: none; }
.user-pill { display:flex; align-items:center; gap: 8px; padding: 6px 12px; background: var(--bg); border-radius: 999px; font-size: 13px; }
.user-avatar { width: 28px; height: 28px; border-radius: 50%; background: var(--orca-blue); color: #fff; display:inline-flex; align-items:center; justify-content:center; font-weight:600; font-size:12px; }

.content {
  padding: 28px; flex: 1;
  max-width: 100%;
  min-width: 0;
  animation: pageEnter .25s ease;
}
@keyframes pageEnter { from { opacity:0; transform: translateY(6px); } to { opacity:1; transform: translateY(0); } }

/* Cards */
.card {
  background: var(--card); border: 1px solid var(--border);
  border-radius: var(--radius); box-shadow: var(--shadow);
  transition: box-shadow var(--transition), transform var(--transition);
}
.card-hover:hover { box-shadow: var(--shadow-lg); transform: translateY(-1px); }
.card-header { padding: 18px 22px; border-bottom: 1px solid var(--border); display:flex; align-items:center; justify-content:space-between; gap:12px; flex-wrap: wrap; }
.card-title { font-size: 16px; font-weight: 600; margin:0; }
.card-body { padding: 22px; }
.card-body.compact { padding: 0; }

/* Typography */
h1, h2, h3, h4 { margin: 0; color: var(--text); font-weight: 700; line-height: 1.25; }
h1 { font-size: 28px; }
h2 { font-size: 20px; }
h3 { font-size: 16px; }
.muted { color: var(--muted); }
.text-sm { font-size: 13px; }
.text-xs { font-size: 12px; }
.font-medium { font-weight: 500; }
.font-bold { font-weight: 700; }

/* Buttons */
.btn {
  display: inline-flex; align-items: center; gap: 8px; padding: 9px 16px;
  border-radius: 8px; border: 1px solid transparent; font-weight: 500;
  font-size: 14px; transition: background var(--transition), border-color var(--transition), color var(--transition), transform var(--transition), box-shadow var(--transition);
  background: var(--orca-blue); color: #fff;
  white-space: nowrap;
}
.btn:hover { background: var(--orca-blue-dark); box-shadow: 0 4px 12px rgba(30,94,255,.25); }
.btn.outline { background: transparent; color: var(--text); border-color: var(--border); box-shadow: none; }
.btn.outline:hover { background: var(--bg); border-color: var(--orca-blue); color: var(--orca-blue); }
.btn.ghost { background: transparent; color: var(--text); box-shadow: none; }
.btn.ghost:hover { background: var(--bg); }
.btn.danger { background: var(--danger); }
.btn.danger:hover { background: #b91c1c; box-shadow: 0 4px 12px rgba(220,38,38,.25); }
.btn.success { background: var(--success); }
.btn.success:hover { background: #15803d; box-shadow: 0 4px 12px rgba(22,163,74,.25); }
.btn.warning { background: var(--warning); color: #fff; }
.btn.warning:hover { background: #d97706; }
.btn.sm { padding: 6px 12px; font-size: 13px; }
.btn.lg { padding: 12px 22px; font-size: 15px; }
.btn.block { width: 100%; justify-content: center; }
.btn:disabled { opacity: .55; cursor: not-allowed; }
.btn svg { width: 16px; height: 16px; }

/* Inputs */
.input, .select, .textarea {
  width: 100%; padding: 9px 12px; border-radius: 8px; border: 1px solid var(--border);
  font-family: inherit; font-size: 14px; background: #fff; color: var(--text);
  transition: border-color var(--transition), box-shadow var(--transition);
}
.input:focus, .select:focus, .textarea:focus { outline: none; border-color: var(--orca-blue); box-shadow: 0 0 0 3px rgba(30,94,255,.12); }
.input.with-icon { padding-inline-start: 36px; }
.field { display: flex; flex-direction: column; gap: 6px; }
.field label { font-size: 13px; font-weight: 500; color: var(--text); }
.input-icon-wrap { position: relative; display: inline-block; max-width: 100%; }
.input-icon-wrap > .input { width: 240px; max-width: 100%; }
.input-icon-wrap svg { position: absolute; inset-inline-start: 12px; top: 50%; transform: translateY(-50%); width: 16px; height: 16px; color: var(--muted); pointer-events: none; }
.textarea { min-height: 100px; resize: vertical; font-family: inherit; }

/* Grids */
.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)); }

/* Stack utility */
.stack { display: flex; flex-direction: column; gap: 22px; }
.row { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.row.between { justify-content: space-between; }
.row.nowrap { flex-wrap: nowrap; }
.spacer { flex: 1; }

/* Badge */
.badge { display: inline-block; padding: 3px 10px; border-radius: 999px; font-size: 12px; font-weight: 500; background: var(--bg); color: var(--text); border: 1px solid var(--border); }
.badge.primary { background: rgba(30,94,255,.12); color: var(--orca-blue); border-color: transparent; }
.badge.success { background: rgba(22,163,74,.12); color: var(--success); border-color: transparent; }
.badge.warning { background: rgba(245,158,11,.14); color: #b45309; border-color: transparent; }
.badge.danger  { background: rgba(220,38,38,.12); color: var(--danger); border-color: transparent; }
.badge.muted   { background: var(--bg); color: var(--muted); border-color: transparent; }

/* Table */
.table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; }
.table { width: 100%; border-collapse: collapse; }
.table th, .table td { padding: 12px 18px; text-align: start; border-bottom: 1px solid var(--border); font-size: 14px; vertical-align: middle; }
.table th { background: #fafbfd; font-weight: 600; color: var(--muted); font-size: 12px; text-transform: uppercase; letter-spacing: .04em; white-space: nowrap; }
.table tbody tr { transition: background var(--transition); }
.table tbody tr:hover { background: rgba(30,94,255,.03); }
.table tbody tr:last-child td { border-bottom: 0; }
.row-actions { display: inline-flex; gap: 4px; }

/* Tabs */
.tabs { display:flex; gap: 2px; padding: 4px; background: var(--bg); border-radius: 10px; width: fit-content; max-width: 100%; overflow-x: auto; }
.tab { padding: 8px 18px; border-radius: 8px; cursor: pointer; font-size: 14px; font-weight: 500; color: var(--muted); background: transparent; border: 0; white-space: nowrap; }
.tab.active { background: #fff; color: var(--text); box-shadow: var(--shadow); }

/* KPI cards */
.kpi {
  background: #fff; border: 1px solid var(--border); border-radius: var(--radius);
  padding: 18px 20px; box-shadow: var(--shadow);
  transition: transform var(--transition), box-shadow var(--transition);
}
.kpi:hover { transform: translateY(-2px); box-shadow: var(--shadow-lg); }
.kpi-head { display:flex; align-items:center; justify-content:space-between; margin-bottom: 14px; }
.kpi-head .title { font-size: 13px; color: var(--muted); font-weight: 500; }
.kpi-head svg { width: 20px; height: 20px; }
.kpi-value { font-size: 26px; font-weight: 700; }
.kpi-blue svg { color: var(--orca-blue); }
.kpi-green svg { color: #10b981; }
.kpi-purple svg { color: #8b5cf6; }
.kpi-rose svg { color: #f43f5e; }
.kpi-amber svg { color: #f59e0b; }
.kpi-indigo svg { color: #6366f1; }

/* Toast */
.toast-host { position: fixed; bottom: 20px; inset-inline-end: 20px; display: flex; flex-direction: column; gap: 8px; z-index: 99; pointer-events: none; }
.toast { background: #fff; border: 1px solid var(--border); padding: 12px 16px; border-radius: 8px; box-shadow: var(--shadow-lg); min-width: 240px; max-width: calc(100vw - 40px); pointer-events: auto; animation: slideIn .25s cubic-bezier(.4,.0,.2,1); }
.toast.error { border-color: var(--danger); }
.toast.success { border-color: var(--success); }
.toast .t-title { font-weight: 600; font-size: 14px; }
.toast .t-desc { font-size: 13px; color: var(--muted); margin-top: 2px; }
@keyframes slideIn { from { opacity:0; transform: translateY(8px); } to { opacity:1; transform: translateY(0); } }

/* Modal */
.modal-backdrop { position: fixed; inset: 0; background: rgba(13,27,42,.45); z-index: 60; display:flex; align-items:center; justify-content:center; padding: 20px; animation: fade .15s ease; }
@keyframes fade { from {opacity:0} to {opacity:1} }
.modal { background: #fff; border-radius: 12px; max-width: 520px; width: 100%; box-shadow: 0 20px 50px rgba(0,0,0,.2); max-height: 90vh; overflow-y: auto; animation: modalIn .2s cubic-bezier(.4,.0,.2,1); }
.modal.lg { max-width: 720px; }
@keyframes modalIn { from { opacity: 0; transform: translateY(12px) scale(.98); } to { opacity:1; transform: translateY(0) scale(1); } }
.modal-header { padding: 18px 22px; border-bottom: 1px solid var(--border); display:flex; align-items:center; justify-content:space-between; }
.modal-title { font-size: 17px; font-weight: 600; margin: 0; }
.modal-body { padding: 22px; }
.modal-footer { padding: 14px 22px; border-top: 1px solid var(--border); display:flex; justify-content: flex-end; gap: 8px; flex-wrap: wrap; }

/* Auth */
.auth-screen { min-height: 100vh; display:flex; align-items:center; justify-content:center; padding: 24px; background: linear-gradient(135deg, #f5f7fb, #eef1fa); }
.auth-card { background: #fff; padding: 36px; border-radius: 16px; max-width: 440px; width: 100%; box-shadow: 0 12px 40px rgba(13,27,42,.10); animation: modalIn .3s cubic-bezier(.4,.0,.2,1); }
.auth-logo { width: 148px; height: 148px; display:flex; align-items:center; justify-content:center; margin: 0 auto 22px; }
.auth-logo img { width: 100%; height: 100%; object-fit: contain; }
.auth-card h1 { text-align: center; margin: 0 0 6px; font-size: 19px; }
.auth-sub { text-align: center; color: var(--muted); margin-bottom: 22px; }
.auth-foot { text-align: center; margin-top: 18px; font-size: 13px; color: var(--muted); }

/* RTL fix-ups */
html[dir="rtl"] .input.with-icon { padding-inline-start: 12px; padding-inline-end: 36px; }

/* Dashboard editor */
.section-wrap { position: relative; }
.section-wrap.editing { border: 2px dashed rgba(30,94,255,.4); border-radius: 12px; padding: 12px; }
.section-toolbar { display:flex; align-items:center; gap: 4px; margin-bottom: 8px; padding: 4px 8px; background: rgba(30,94,255,.06); border: 1px solid rgba(30,94,255,.2); border-radius: 8px; }
.section-toolbar .label { font-size: 12px; font-weight: 500; color: var(--orca-blue); padding: 0 6px; }

/* Rich text editor */
.rt-wrap { border: 1px solid var(--border); border-radius: 8px; overflow: hidden; background: #fff; }
.rt-toolbar { display: flex; flex-wrap: wrap; gap: 4px; padding: 8px; background: #fafbfd; border-bottom: 1px solid var(--border); align-items: center; }
.rt-toolbar select { height: 32px; padding: 0 8px; border-radius: 6px; border: 1px solid var(--border); background: #fff; font-size: 13px; }
.rt-btn { width: 30px; height: 30px; display:inline-flex; align-items:center; justify-content:center; border: 0; border-radius: 6px; background: transparent; color: var(--text); }
.rt-btn:hover { background: var(--bg); }
.rt-btn svg { width: 16px; height: 16px; }
.rt-divider { width: 1px; height: 22px; background: var(--border); margin: 0 4px; }
.rt-color-swatch { width: 22px; height: 22px; border-radius: 4px; border: 1px solid var(--border); cursor: pointer; padding: 0; }
.rt-area { padding: 16px; min-height: 180px; outline: none; font-size: 14px; line-height: 1.6; }
.rt-area[data-placeholder]:empty:before { content: attr(data-placeholder); color: var(--muted); }

/* Task board */
.kanban { display: grid; grid-template-columns: repeat(4, minmax(0,1fr)); gap: 16px; }
.kanban-col { background: #fff; border: 1px solid var(--border); border-radius: var(--radius); padding: 14px; min-height: 360px; }
.kanban-col h3 { display:flex; align-items:center; justify-content:space-between; margin-bottom: 12px; font-size: 14px; }
.kanban-card { background: #fafbfd; border: 1px solid var(--border); border-radius: 8px; padding: 12px; margin-bottom: 8px; cursor: pointer; transition: transform var(--transition), box-shadow var(--transition); }
.kanban-card:hover { transform: translateY(-2px); box-shadow: var(--shadow); border-color: var(--orca-blue); }
.kanban-card .title { font-weight: 500; font-size: 14px; }
.kanban-card .meta { display:flex; justify-content:space-between; margin-top: 8px; font-size: 12px; color: var(--muted); flex-wrap: wrap; gap: 4px; }
.kanban-col.pending h3::before { color: var(--muted); }

/* Inbox */
.inbox-shell { display: grid; grid-template-columns: minmax(280px, 360px) minmax(0,1fr); gap: 16px; min-height: 60vh; }
.inbox-list { background: #fff; border: 1px solid var(--border); border-radius: var(--radius); overflow: hidden; }
.inbox-item { display: flex; flex-direction: column; gap: 4px; padding: 12px 16px; border-bottom: 1px solid var(--border); cursor: pointer; transition: background var(--transition); position: relative; }
.inbox-item:hover { background: var(--bg); }
.inbox-item.active { background: rgba(30,94,255,.08); }
.inbox-item.unread { background: rgba(30,94,255,.04); }
.inbox-item.unread::before { content:""; position:absolute; inset-block:0; inset-inline-start:0; width:3px; background: var(--orca-blue); }
.inbox-item .ttl { font-weight: 600; font-size: 14px; }
.inbox-item .preview { font-size: 12px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.inbox-item .when { font-size: 11px; color: var(--muted); }
.inbox-pane { background: #fff; border: 1px solid var(--border); border-radius: var(--radius); padding: 22px; }
.inbox-empty { text-align: center; padding: 60px 20px; color: var(--muted); }
.notif-icon { width: 32px; height: 32px; border-radius: 8px; display: inline-flex; align-items:center; justify-content:center; flex-shrink: 0; }
.notif-icon.task_assigned    { background: rgba(30,94,255,.12); color: var(--orca-blue); }
.notif-icon.task_submitted   { background: rgba(245,158,11,.14); color: #b45309; }
.notif-icon.task_approved    { background: rgba(22,163,74,.12); color: var(--success); }
.notif-icon.task_rejected    { background: rgba(220,38,38,.12); color: var(--danger); }
.notif-icon.task_needs_changes { background: rgba(245,158,11,.14); color: #b45309; }
.notif-icon.system           { background: var(--bg); color: var(--muted); }

/* Printable document */
.doc-actions { display:flex; gap: 8px; flex-wrap: wrap; }
.printable-doc {
  background: #fff; color: #000; width: 210mm; max-width: 100%; min-height: 297mm; margin: 0 auto;
  position: relative; box-shadow: 0 8px 30px rgba(13,27,42,.12); overflow: hidden;
}
/* Responsive document scale wrapper — wraps the auto-scaled quotation/invoice/contract sheets */
.doc-scale-wrap {
  width: 100%;
  overflow: hidden;
  position: relative;
}
/* Brand corners — supplied design uses two diagonal accents:
   ‣ navy block in the top-start (logical) corner
   ‣ blue block in the bottom-end (logical) corner
   Old single .doc-corner kept for backwards compatibility. */
.doc-corner { position: absolute; width: 220px; height: 220px; pointer-events: none; overflow: hidden; }
.doc-corner::before, .doc-corner::after {
  content: ""; position: absolute; width: 140%; height: 140%;
}
.doc-corner-tl { top: 0; inset-inline-start: 0; }
.doc-corner-tl::before {
  top: -55%; inset-inline-start: -45%;
  background: var(--orca-navy);
  transform: rotate(-22deg);
}
.doc-corner-tl::after {
  top: -65%; inset-inline-start: -25%;
  background: var(--orca-blue);
  transform: rotate(-22deg);
  opacity: .85;
}
.doc-corner-br { bottom: 0; inset-inline-end: 0; }
.doc-corner-br::before {
  bottom: -55%; inset-inline-end: -45%;
  background: var(--orca-blue);
  transform: rotate(-22deg);
}
.doc-corner-br::after {
  bottom: -65%; inset-inline-end: -25%;
  background: var(--orca-navy);
  transform: rotate(-22deg);
  opacity: .85;
}
/* Legacy single corner still works (top-end) */
.doc-corner:not(.doc-corner-tl):not(.doc-corner-br) { top: 0; inset-inline-end: 0; }
.doc-corner:not(.doc-corner-tl):not(.doc-corner-br)::before {
  top: -55%; inset-inline-end: -45%;
  background: var(--orca-navy); transform: rotate(22deg);
}
.doc-corner:not(.doc-corner-tl):not(.doc-corner-br)::after {
  top: -65%; inset-inline-end: -25%;
  background: var(--orca-blue); transform: rotate(22deg); opacity: .85;
}
.doc-brand-name {
  font-size: 12px; letter-spacing: 3px;
  color: var(--orca-blue); font-weight: 700; margin-top: 8px;
}
.doc-page { position: relative; padding: 48px; z-index: 2; }
.doc-header { display:flex; justify-content: space-between; align-items: flex-start; margin-bottom: 36px; gap: 20px; flex-wrap: wrap; }
.doc-header-left img { height: 56px; margin-bottom: 14px; }
.doc-header-left h2 { font-size: 26px; color: var(--orca-navy); letter-spacing: 2px; margin: 0; }
.doc-header-left .accent-line { width: 60px; height: 5px; background: var(--orca-blue); margin-top: 8px; }
.doc-meta { background: #f8f9fa; padding: 16px; border-bottom: 2px solid var(--orca-blue); border-inline-end: 2px solid var(--orca-blue); border-radius: 0 0 0 14px; font-size: 12px; }
html[dir="rtl"] .doc-meta { border-radius: 0 0 14px 0; }
.doc-meta table { border-collapse: collapse; }
.doc-meta td { padding: 3px 8px; }
.doc-meta td.k { font-weight: 600; color: var(--orca-navy); }
.doc-parties { display: grid; grid-template-columns: 1fr 1fr; gap: 28px; margin-bottom: 36px; }
.doc-parties h3 { font-size: 11px; color: var(--orca-blue); letter-spacing: 1.4px; text-transform: uppercase; margin-bottom: 8px; }
.doc-parties .name { font-size: 17px; font-weight: 700; color: var(--orca-navy); margin-bottom: 4px; }
.doc-parties p { margin: 2px 0; color: #555; font-size: 13px; }
.doc-table { width: 100%; border-collapse: collapse; font-size: 13px; }
.doc-table thead { background: var(--orca-navy); color: #fff; }
.doc-table th, .doc-table td { padding: 10px 14px; text-align: start; }
.doc-table tbody tr:nth-child(even) { background: #f8f9fa; }
.doc-table tbody { border-bottom: 2px solid var(--orca-navy); }
.doc-totals { display: flex; justify-content: flex-end; margin-top: 18px; }
.doc-totals table { width: 280px; max-width: 100%; font-size: 13px; }
.doc-totals td { padding: 6px 4px; }
.doc-totals tr.total { background: var(--orca-blue); color: #fff; font-weight: 700; }
.doc-totals tr.total td { padding: 12px 14px; font-size: 16px; }
.doc-section { margin: 24px 0; }
.doc-section h3 { font-size: 11px; color: var(--orca-blue); letter-spacing: 1.4px; text-transform: uppercase; margin-bottom: 8px; }
.doc-section .body { border-inline-start: 4px solid var(--orca-blue); padding-inline-start: 14px; font-size: 14px; line-height: 1.7; }
.doc-signatures { display: grid; grid-template-columns: 1fr 1fr; gap: 60px; margin: 60px 0 30px; }
.doc-signatures .sig { text-align: center; padding-top: 50px; border-top: 2px solid var(--orca-navy); }
.doc-signatures .sig-label { font-size: 11px; color: #777; }
.doc-signatures .sig-name { font-weight: 700; color: var(--orca-navy); margin-top: 4px; }
.doc-footer { padding-top: 16px; border-top: 2px solid var(--orca-navy); margin-top: 28px; text-align: center; font-size: 11px; color: var(--muted); }
.doc-footer .thanks { font-weight: 700; color: var(--orca-navy); margin-bottom: 4px; }

/* ── Global @page rule ─────────────────────────────────────────────────────
   Sets zero browser margins for ALL document types so our A4 pages fill
   exactly one physical page (contracts, invoices).
   Quotations inject their own @page { margin: 5mm } inside a <style> tag
   that is rendered after this stylesheet, so their rule wins for quotations. */
@page { size: A4 portrait; margin: 0; }

/* Print */
@media print {
  html, body { margin: 0 !important; padding: 0 !important; }
  body { background: #fff; }
  .no-print, .topbar, .sidebar, #toast-host { display: none !important; }
  .content { padding: 0; overflow: visible !important; }
  .printable-doc { box-shadow: none; width: 100%; min-height: auto; }

  /* Mobile card view must never appear in print — the full A4 sheet always prints */
  .doc-mobile-preview { display: none !important; }

  /* Reset ALL JS-applied inline styles (transform, height, overflow, width).
     The beforeprint JS handler also clears these, but this CSS is a hard
     fallback for Safari iOS / Android WebViews that may not fire beforeprint. */
  .quotation-sheet,
  .invoice-sheet,
  .ctr-page {
    transform: none !important;
    transform-origin: unset !important;
    margin-left: 0 !important;
    margin-right: 0 !important;
    margin-bottom: 0 !important;
    width: 100% !important;
    max-width: 100% !important;
  }

  /* Parent containers — clear JS-set height / overflow that would clip the document */
  #doc-content,
  .quotation-doc,
  .invoice-doc {
    height: auto !important;
    overflow: visible !important;
    max-width: 100% !important;
    width: 100% !important;
    margin: 0 auto !important;
    padding: 0 !important;
  }

  .doc-scale-wrap,
  .stack {
    height: auto !important;
    overflow: visible !important;
  }
}

/* Dropdown menu */
.dropdown { position: relative; }
.dropdown-menu {
  position: absolute; top: calc(100% + 6px); inset-inline-end: 0;
  background: #fff; border: 1px solid var(--border); border-radius: 8px;
  box-shadow: 0 8px 24px rgba(13,27,42,.10); min-width: 220px; padding: 6px;
  z-index: 50; max-height: 360px; overflow-y: auto;
  animation: modalIn .15s ease;
}
.dropdown-item { display: block; width: 100%; padding: 8px 12px; border-radius: 6px; background: transparent; border: 0; text-align: start; font-size: 14px; color: var(--text); cursor: pointer; }
.dropdown-item:hover { background: var(--bg); }
.dropdown-label { padding: 6px 12px; font-size: 11px; color: var(--muted); text-transform: uppercase; letter-spacing: .06em; }
.dropdown-sep { height: 1px; background: var(--border); margin: 4px 0; }

/* Empty state */
.empty { text-align: center; padding: 48px 24px; color: var(--muted); }

/* Notice block */
.notice-info    { background: #eff6ff; border: 1px solid #bfdbfe; border-radius: 12px; padding: 16px; color: #1e3a8a; }
.notice-warn    { background: #fffbeb; border: 1px solid #fde68a; border-radius: 12px; padding: 16px; color: #92400e; }
.notice-success { background: #ecfdf5; border: 1px solid #a7f3d0; border-radius: 12px; padding: 16px; color: #065f46; }
.notice-default { background: var(--bg); border: 1px solid var(--border); border-radius: 12px; padding: 16px; }

/* Misc */
hr.sep { border: 0; border-top: 1px solid var(--border); margin: 18px 0; }
.invoice-prose { line-height: 1.7; }
.invoice-prose p { margin: 8px 0; }

/* Drawer */
.drawer-backdrop { position: fixed; inset: 0; background: rgba(13,27,42,.45); z-index: 60; animation: fade .15s ease; }
.drawer { position: fixed; top: 0; bottom: 0; inset-inline-end: 0; background: #fff; width: 420px; max-width: 95vw; z-index: 61; padding: 22px; overflow-y: auto; box-shadow: -10px 0 30px rgba(0,0,0,.1); animation: drawerIn .25s cubic-bezier(.4,.0,.2,1); }
@keyframes drawerIn { from { transform: translateX(100%); } to { transform: translateX(0); } }
html[dir="rtl"] .drawer { animation-name: drawerInRtl; }
@keyframes drawerInRtl { from { transform: translateX(-100%); } to { transform: translateX(0); } }
.drawer h2 { margin-bottom: 18px; }

/* Status pills used by tasks */
.pill-status { display:inline-block; padding: 3px 10px; border-radius: 999px; font-size: 11px; font-weight: 600; text-transform: uppercase; letter-spacing: .04em; }
.pill-pending { background: #f1f5f9; color: #475569; }
.pill-in_progress { background: #fef3c7; color: #92400e; }
.pill-blocked { background: #fee2e2; color: #b91c1c; }
.pill-done, .pill-approved { background: #dcfce7; color: #166534; }
.pill-submitted { background: #dbeafe; color: #1e40af; }
.pill-rejected { background: #fee2e2; color: #b91c1c; }
.pill-needs_changes { background: #ffedd5; color: #9a3412; }

/* Skeleton loader */
.skeleton { background: linear-gradient(90deg, #eef2f7 0%, #f7f9fc 50%, #eef2f7 100%); background-size: 200% 100%; animation: shimmer 1.4s infinite linear; border-radius: 6px; height: 14px; }
@keyframes shimmer { 0% { background-position: 200% 0; } 100% { background-position: -200% 0; } }

/* ===== Responsive layout ===== */

/* Tablet: shrink the sidebar */
@media (max-width: 1100px) {
  .shell { grid-template-columns: 200px minmax(0, 1fr); }
  .grid-4 { grid-template-columns: repeat(2, minmax(0,1fr)); }
  .kanban { grid-template-columns: repeat(2, minmax(0,1fr)); }
}

/* Phone: collapse sidebar to off-canvas drawer + show hamburger */
@media (max-width: 820px) {
  .shell { grid-template-columns: minmax(0, 1fr); }
  .sidebar {
    position: fixed; top: 0; bottom: 0; inset-inline-start: 0; width: 260px; height: 100vh;
    transform: translateX(-100%);
    box-shadow: 4px 0 20px rgba(0,0,0,.12);
  }
  html[dir="rtl"] .sidebar { transform: translateX(100%); inset-inline-start: auto; inset-inline-end: 0; box-shadow: -4px 0 20px rgba(0,0,0,.12); }
  .sidebar.open { transform: translateX(0); }
  .menu-btn { display: inline-flex; }
  .topbar { padding: 12px 16px; }
  .content { padding: 18px; overflow-x: hidden; }
  .grid-2, .grid-3 { grid-template-columns: 1fr; }
  .user-pill span:not(.user-avatar):not(.badge) { display: none; }
  .inbox-shell { grid-template-columns: 1fr; }
  .doc-parties { grid-template-columns: 1fr; }
  h1 { font-size: 22px; }
  .topbar-left h2 { display: none; }

  /* Document toolbar — compact on phones so buttons don't overflow */
  .doc-actions { gap: 5px; flex-wrap: wrap; }
  .doc-actions .btn { font-size: 12px; padding: 6px 10px; }

  /* Allow the A4 wrappers to be constrained by the viewport */
  .quotation-doc,
  .invoice-doc {
    max-width: 100% !important;
    width: 100% !important;
    overflow: hidden;
  }
  .ctr-page { overflow: hidden; }
}

/* ── Mobile card preview (480 px and below) ──────────────────────────────── */

/* Hidden by default on all screens; CSS below activates it on narrow screens */
.doc-mobile-preview { display: none; }

@media (max-width: 479px) {
  /* Replace the A4-scaled sheet with the card preview on very narrow screens */
  .quotation-doc,
  .invoice-doc { display: none !important; }

  .doc-mobile-preview {
    display: block;
    background: #fff;
    border-radius: 12px;
    overflow: hidden;
    box-shadow: 0 2px 16px rgba(13,27,42,.10);
    font-family: 'Tajawal', Arial, sans-serif;
    font-size: 14px;
    color: #0B1D45;
  }

  /* Header band */
  .dmp-header {
    display: flex;
    align-items: center;
    gap: 12px;
    background: #0B1D45;
    padding: 16px;
  }
  .dmp-logo { width: 48px; height: 48px; object-fit: contain; flex-shrink: 0; }
  .dmp-header-right { flex: 1; min-width: 0; }
  .dmp-doc-type { font-size: 18px; font-weight: 800; color: #fff; letter-spacing: 1px; }
  .dmp-serial { font-size: 12px; color: rgba(255,255,255,.6); font-family: monospace; margin-top: 2px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

  /* Meta row */
  .dmp-section { padding: 12px 16px; border-bottom: 1px solid #e5e9f2; }
  .dmp-row { display: flex; justify-content: space-between; align-items: center; padding: 5px 0; font-size: 13px; gap: 8px; }
  .dmp-label { color: #6b7280; font-weight: 500; flex-shrink: 0; }

  /* Cards */
  .dmp-card { margin: 12px; border: 1px solid #e5e9f2; border-radius: 10px; padding: 14px; }
  .dmp-card-title,
  .dmp-section-title {
    font-size: 10px; font-weight: 700; color: #1E5EFF;
    letter-spacing: 1.5px; text-transform: uppercase; margin-bottom: 8px;
  }
  .dmp-section-title { padding: 8px 16px 0; margin-bottom: 0; }
  .dmp-name { font-size: 16px; font-weight: 700; color: #0B1D45; }
  .dmp-sub  { font-size: 13px; color: #555; margin-top: 3px; }

  /* Items list */
  .dmp-items { padding: 0 12px 4px; }
  .dmp-item { display: flex; gap: 12px; padding: 10px 0; border-bottom: 1px solid #f0f2f8; align-items: flex-start; }
  .dmp-item:last-child { border-bottom: none; }
  .dmp-item-num {
    width: 24px; height: 24px; border-radius: 50%;
    background: #1E5EFF; color: #fff; font-size: 11px; font-weight: 700;
    display: flex; align-items: center; justify-content: center; flex-shrink: 0; margin-top: 1px;
  }
  .dmp-item-body { flex: 1; min-width: 0; }
  .dmp-item-desc { font-weight: 600; font-size: 13px; }
  .dmp-item-note { font-size: 11px; color: #6b7280; margin-top: 2px; }
  .dmp-item-meta { display: flex; justify-content: space-between; margin-top: 6px; font-size: 12px; color: #6b7280; }
  .dmp-item-meta strong { color: #0B1D45; }

  /* Totals block */
  .dmp-totals { margin: 12px; border: 1px solid #e5e9f2; border-radius: 10px; overflow: hidden; }
  .dmp-totals .dmp-row { padding: 8px 14px; font-size: 13px; border-bottom: 1px solid #f0f2f8; }
  .dmp-totals .dmp-row:last-of-type { border-bottom: none; }
  .dmp-total-row {
    display: flex; justify-content: space-between; align-items: center;
    background: #0B1D45; color: #fff; padding: 12px 14px; font-weight: 700; font-size: 15px;
  }

  /* Notes */
  .dmp-notes-text { margin: 6px 0 0; font-size: 13px; line-height: 1.7; color: #444; }

  /* Footer */
  .dmp-footer {
    background: #f8faff; border-top: 1px solid #e5e9f2;
    padding: 14px 16px; font-size: 12px; color: #6b7280;
    text-align: center; line-height: 1.8;
  }
}

@media (max-width: 600px) {
  .kanban { grid-template-columns: 1fr; }
  .grid-4 { grid-template-columns: 1fr; }
  .modal { max-height: 95vh; }
  .toast-host { inset-inline-end: 10px; bottom: 10px; }
  .toast { min-width: 200px; }
}

/* Mobile sidebar backdrop */
.sidebar-backdrop { display: none; }
@media (max-width: 820px) {
  .sidebar-backdrop.open {
    display: block; position: fixed; inset: 0; background: rgba(13,27,42,.45); z-index: 39;
    animation: fade .15s ease;
  }
}

/* ============================================================
   Inline content editor (WordPress-like)
   ============================================================ */
body.edit-mode { padding-bottom: 64px; }
.cms-editable {
  outline: 1.5px dashed rgba(13, 110, 253, 0.55) !important;
  outline-offset: 2px;
  cursor: text;
  transition: background-color .12s ease;
  border-radius: 4px;
  min-height: 1em;
}
.cms-editable:hover { background-color: rgba(13, 110, 253, 0.07); }
.cms-editable:focus {
  outline-color: rgba(13, 110, 253, 1) !important;
  background-color: rgba(13, 110, 253, 0.10);
}
#cms-bar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 80;
  background: linear-gradient(180deg, #0d1b2a, #1b2a3d);
  color: #fff; padding: 10px 16px;
  display: flex; align-items: center; gap: 12px; flex-wrap: wrap;
  box-shadow: 0 -6px 20px rgba(0,0,0,.25);
}
#cms-bar .cms-bar-title { font-weight: 600; }
#cms-bar .cms-bar-status { color: #ffd166; font-size: 13px; flex: 1; }
#cms-bar .btn { padding: 6px 12px; }

/* Username in topbar: adapts to theme */
.user-pill > span:not(.user-avatar):not(.badge) {
  color: #0f172a;  /* light mode — dark/black */
}
html[data-theme="dark"] .user-pill > span:not(.user-avatar):not(.badge) {
  color: #ffffff;  /* dark mode — white */
}

/* CMS edit-bar buttons: always white text (bar has a dark bg in both modes) */
#cms-bar .btn.outline,
#cms-bar .btn.ghost {
  color: #ffffff !important;
  border-color: rgba(255,255,255,0.35) !important;
}
#cms-bar .btn.outline:hover  { background: rgba(255,255,255,0.10) !important; }
#cms-bar .btn.ghost:hover    { background: rgba(255,255,255,0.08) !important; }

/* ============================================================
   Task private message thread
   ============================================================ */
.thread-item { padding: 12px 0; border-bottom: 1px solid var(--border); }
.thread-item:last-child { border-bottom: 0; }
.attachment-chip {
  display: inline-flex; align-items: center; gap: 6px; margin-top: 6px;
  background: var(--surface-2, #f1f5f9); border-radius: 6px; padding: 4px 10px;
  font-size: 13px;
}
.attachment-chip a { color: inherit; text-decoration: none; }
.msg-thread {
  display: flex; flex-direction: column; gap: 10px;
  max-height: 360px; overflow-y: auto; padding: 4px;
  background: var(--surface-2, #f8fafc); border-radius: 8px;
  border: 1px solid var(--border);
}
.msg-bubble {
  background: #fff; border: 1px solid var(--border);
  padding: 10px 12px; border-radius: 10px; max-width: 80%;
  align-self: flex-start;
}
.msg-bubble.mine {
  align-self: flex-end;
  background: #e7f1ff; border-color: #bdd6fa;
}
.msg-bubble.role-admin { border-color: #ffd6a5; background: #fff7e8; }
.msg-bubble.mine.role-admin { background: #ffe6c2; }
.msg-bubble .msg-meta {
  display: flex; justify-content: space-between; gap: 8px;
  font-size: 12px; margin-bottom: 4px; color: var(--muted);
}
.msg-bubble .msg-body { font-size: 14px; }
.msg-composer { margin-top: 12px; display: flex; flex-direction: column; gap: 8px; }

/* Larger task status pill in detail view */
.pill-status.lg { font-size: 13px; padding: 4px 10px; }

/* Two-column task detail layout */
.task-detail-grid {
  grid-template-columns: minmax(0, 2fr) minmax(280px, 1fr);
  gap: 18px;
}
@media (max-width: 900px) {
  .task-detail-grid { grid-template-columns: 1fr; }
  .msg-bubble { max-width: 95%; }
}

/* ============================================================
   Settings page (tabs + help boxes)
   ============================================================ */
.tabs { display: flex; gap: 4px; border-bottom: 2px solid var(--border); margin-bottom: 16px; }
.tab {
  background: transparent; border: 0; padding: 10px 16px;
  border-bottom: 2px solid transparent; margin-bottom: -2px;
  cursor: pointer; font: inherit; color: var(--muted);
  transition: color .15s, border-color .15s;
}
.tab:hover { color: var(--text); }
.tab.active { color: var(--primary, #0d6efd); border-bottom-color: var(--primary, #0d6efd); }
.tab-pane { animation: fade .2s ease; }
.help-box {
  background: var(--surface-2, #f8fafc); border: 1px solid var(--border);
  border-radius: 8px; padding: 10px 14px; margin-bottom: 10px;
}
.help-box summary { cursor: pointer; font-weight: 500; }
.help-box ol { margin: 8px 0 0 0; padding-inline-start: 22px; }
.help-box code {
  background: rgba(13,110,253,.08); padding: 1px 6px; border-radius: 4px;
  font-family: ui-monospace, monospace; font-size: 13px;
}
.override-row {
  display: flex; flex-direction: column; gap: 6px;
  padding: 10px; border: 1px solid var(--border); border-radius: 8px;
  background: var(--surface-2, #f8fafc);
}

/* Top-bar settings dropdown menu */
.popover-menu {
  background: #fff; border: 1px solid var(--border);
  border-radius: 8px; box-shadow: 0 8px 24px rgba(13,27,42,.18);
  padding: 4px; z-index: 60; min-width: 220px;
}
.popover-menu button {
  display: block; width: 100%; text-align: inherit;
  background: transparent; border: 0; padding: 8px 12px; border-radius: 6px;
  cursor: pointer; font: inherit; color: var(--text);
}
.popover-menu button:hover { background: var(--surface-2, #f1f5f9); }
html[dir="rtl"] .popover-menu { text-align: right; }

/* When body is in edit mode, prevent navigation through editable links */
body.edit-mode .nav-link.cms-editable,
body.edit-mode a.cms-editable { pointer-events: auto; }
body.edit-mode a.cms-editable { text-decoration: none; }

/* ============================================================
   THEME TOGGLE BUTTON (sun / moon in the topbar)
   ============================================================ */
.theme-toggle {
  display: inline-flex; align-items: center; justify-content: center;
  width: 38px; height: 38px; border-radius: 10px;
  background: transparent; color: var(--text);
  border: 1px solid var(--border);
  cursor: pointer; transition: background var(--transition), color var(--transition), transform var(--transition);
}
.theme-toggle:hover { background: var(--surface-2, #f1f5f9); transform: rotate(-12deg); }
.theme-toggle svg { width: 20px; height: 20px; }

/* Back-button in the topbar */
.topbar-back {
  display: inline-flex; align-items: center; justify-content: center;
  width: 36px; height: 36px; border-radius: 8px;
  background: transparent; color: var(--text);
  border: 1px solid var(--border); cursor: pointer;
  transition: background var(--transition), transform var(--transition);
}
.topbar-back:hover { background: var(--surface-2, #f1f5f9); }
.topbar-back svg { width: 18px; height: 18px; }
html[dir="rtl"] .topbar-back svg { transform: scaleX(-1); }

/* ============================================================
   PROFESSIONAL DARK MODE
   Activated by `data-theme="dark"` on <html>. Stored in localStorage
   so it persists between visits. The sidebar logo is swapped to
   /assets/orca-white.png by sidebar.js when this flag is on.
   ============================================================ */
html { transition: background-color var(--transition), color var(--transition); }

html[data-theme="dark"] {
  --orca-blue: #4d8bff;
  --orca-blue-dark: #3a72e6;
  --orca-navy: #060d18;       /* even deeper navy for the side-rail   */
  --bg: #0a1320;              /* page background                      */
  --card: #131e2e;            /* card / panel background              */
  --border: #1f2a3c;          /* subtle borders between elements      */
  --text: #e8edf5;
  --muted: #8b94a3;
  --muted-soft: #6b7280;
  --danger: #ef4444;
  --success: #22c55e;
  --warning: #fbbf24;
  --shadow: 0 1px 2px rgba(0,0,0,.3), 0 4px 14px rgba(0,0,0,.45);
  --shadow-lg: 0 10px 36px rgba(0,0,0,.55);
  --surface-2: #1a2638;       /* hover / secondary surface            */
}

html[data-theme="dark"] body { background: var(--bg); color: var(--text); }

  /* Deadline reminder banner: amber in light mode, dark surface in dark mode */
  #deadline-banner {
    background: #fffbeb !important;
    border: 1.5px solid #f59e0b !important;
    color: #92400e !important;
    border-radius: 8px;
    padding: 10px 16px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
    font-size: 13px;
    flex-wrap: wrap;
  }
  html[data-theme="dark"] #deadline-banner {
    background: var(--surface-2) !important;
    border-color: var(--border) !important;
    color: var(--text) !important;
  }

html[data-theme="dark"] .splash { background: var(--bg); }
html[data-theme="dark"] .splash-logo { filter: drop-shadow(0 4px 18px rgba(77,139,255,.35)); }

html[data-theme="dark"] .topbar,
html[data-theme="dark"] .card,
html[data-theme="dark"] .modal,
html[data-theme="dark"] .drawer,
html[data-theme="dark"] .popover-menu {
  background: var(--card);
  border-color: var(--border);
  color: var(--text);
}

html[data-theme="dark"] .input,
html[data-theme="dark"] .textarea,
html[data-theme="dark"] .select {
  background: #0f1827;
  color: var(--text);
  border-color: var(--border);
}
html[data-theme="dark"] .input::placeholder,
html[data-theme="dark"] .textarea::placeholder { color: var(--muted-soft); }
html[data-theme="dark"] .input:focus,
html[data-theme="dark"] .textarea:focus,
html[data-theme="dark"] .select:focus {
  outline: 2px solid rgba(77,139,255,.35); outline-offset: 1px;
  border-color: var(--orca-blue);
}

html[data-theme="dark"] .btn.outline,
html[data-theme="dark"] .btn.ghost {
  color: var(--text); border-color: var(--border); background: transparent;
}
html[data-theme="dark"] .btn.ghost:hover,
html[data-theme="dark"] .btn.outline:hover { background: var(--surface-2); }

html[data-theme="dark"] .badge.muted,
html[data-theme="dark"] .pill-status.pill-pending { background: #1f2a3c; color: #cbd5e1; }

/* Dark-mode status pills — keep them legible (was white-on-white before).
   We pair each tinted background with a bright readable foreground so the
   "in progress / blocked / done / submitted / rejected / needs changes"
   chips stay distinguishable in either theme. */
html[data-theme="dark"] .pill-status.pill-in_progress  { background: rgba(251,191,36,.18); color: #fcd34d; }
html[data-theme="dark"] .pill-status.pill-blocked      { background: rgba(239,68,68,.20);  color: #fca5a5; }
html[data-theme="dark"] .pill-status.pill-done,
html[data-theme="dark"] .pill-status.pill-approved     { background: rgba(34,197,94,.18);  color: #86efac; }
html[data-theme="dark"] .pill-status.pill-submitted    { background: rgba(59,130,246,.20); color: #93c5fd; }
html[data-theme="dark"] .pill-status.pill-rejected     { background: rgba(239,68,68,.20);  color: #fca5a5; }
html[data-theme="dark"] .pill-status.pill-needs_changes{ background: rgba(249,115,22,.20); color: #fdba74; }
html[data-theme="dark"] .nav-link { color: rgba(255,255,255,.78); }
html[data-theme="dark"] .nav-link:hover { background: rgba(255,255,255,.07); color: #fff; }

html[data-theme="dark"] table.table thead th { background: #0f1827; color: var(--muted); border-color: var(--border); }
html[data-theme="dark"] table.table td,
html[data-theme="dark"] table.table th { border-color: var(--border); }
html[data-theme="dark"] table.table tr:hover { background: var(--surface-2); }

html[data-theme="dark"] .help-box {
  background: #0f1827; border-color: var(--border); color: var(--text);
}
html[data-theme="dark"] .help-box code { background: rgba(77,139,255,.18); color: #cfe0ff; }

html[data-theme="dark"] .override-row { background: #0f1827; border-color: var(--border); }

html[data-theme="dark"] .toast { background: #131e2e; color: var(--text); border: 1px solid var(--border); }

html[data-theme="dark"] .theme-toggle { color: #ffd76b; }
html[data-theme="dark"] .theme-toggle:hover { background: rgba(255,215,107,.10); }

/* Smooth global colour transitions when toggling */
body, .topbar, .card, .modal, .drawer, .input, .textarea, .select,
.btn, .nav-link, .badge, .pill-status, table.table {
  transition: background-color var(--transition), color var(--transition), border-color var(--transition);
}

/* ============================================================
   ROUND 3 — Comprehensive dark-mode polish
   The previous theme only covered cards and form controls. Many
   surfaces hard-coded `background:#fff` or `#fafbfd`, which produced
   the unreadable "black-on-black" pages the user reported. The block
   below gives every surface a sensible dark counterpart.
   ============================================================ */

/* Auth screens (login / register) */
html[data-theme="dark"] .auth-screen {
  background: radial-gradient(1200px 700px at 50% -10%, #15233a 0%, #0a1320 60%, #060d18 100%);
  color: var(--text);
}
html[data-theme="dark"] .auth-card {
  background: var(--card);
  border: 1px solid var(--border);
  color: var(--text);
  box-shadow: var(--shadow-lg);
}
html[data-theme="dark"] .auth-card h1,
html[data-theme="dark"] .auth-card h2,
html[data-theme="dark"] .auth-card label { color: var(--text); }
html[data-theme="dark"] .auth-card .muted,
html[data-theme="dark"] .auth-card .hint { color: var(--muted); }

/* KPI / dashboard cards */
html[data-theme="dark"] .kpi,
html[data-theme="dark"] .stat-card,
html[data-theme="dark"] .summary-card {
  background: var(--card);
  border: 1px solid var(--border);
  color: var(--text);
}
html[data-theme="dark"] .kpi .label,
html[data-theme="dark"] .kpi small,
html[data-theme="dark"] .stat-card small { color: var(--muted); }
html[data-theme="dark"] .kpi .value,
html[data-theme="dark"] .stat-card .value { color: var(--text); }

/* Kanban board (tasks) */
html[data-theme="dark"] .kanban,
html[data-theme="dark"] .kanban-board { background: transparent; }
html[data-theme="dark"] .kanban-col {
  background: #101a2a;
  border: 1px solid var(--border);
}
html[data-theme="dark"] .kanban-col h3,
html[data-theme="dark"] .kanban-col header { color: var(--text); }
html[data-theme="dark"] .kanban-card,
html[data-theme="dark"] .task-card {
  background: var(--card);
  border: 1px solid var(--border);
  color: var(--text);
  box-shadow: 0 1px 2px rgba(0,0,0,.4);
}
html[data-theme="dark"] .kanban-card:hover,
html[data-theme="dark"] .task-card:hover {
  background: var(--surface-2);
  border-color: rgba(77,139,255,.4);
}
html[data-theme="dark"] .kanban-card .muted,
html[data-theme="dark"] .task-card .muted { color: var(--muted); }

/* Tabs */
html[data-theme="dark"] .tabs { border-bottom-color: var(--border); }
html[data-theme="dark"] .tab { color: var(--muted); }
html[data-theme="dark"] .tab:hover { color: var(--text); }
html[data-theme="dark"] .tab.active {
  background: var(--card);
  color: var(--orca-blue);
  border-color: var(--border);
  border-bottom-color: var(--card);
}

/* Generic table headers (extra rules for non-".table" tables in detail pages) */
html[data-theme="dark"] table th,
html[data-theme="dark"] .table-wrap thead th,
html[data-theme="dark"] .table thead th { background: #0f1827; color: var(--muted); }

/* Dropdown / popover menus (notifications, employee picker, etc.) */
html[data-theme="dark"] .dropdown-menu,
html[data-theme="dark"] .menu,
html[data-theme="dark"] .ctx-menu {
  background: var(--card);
  border: 1px solid var(--border);
  color: var(--text);
  box-shadow: var(--shadow-lg);
}
html[data-theme="dark"] .dropdown-menu .item:hover,
html[data-theme="dark"] .menu .item:hover,
html[data-theme="dark"] .ctx-menu .item:hover { background: var(--surface-2); }
html[data-theme="dark"] .dropdown-menu .divider,
html[data-theme="dark"] .menu .divider { background: var(--border); }

/* Inbox (notifications page) */
html[data-theme="dark"] .inbox-list,
html[data-theme="dark"] .inbox-pane {
  background: var(--card);
  border: 1px solid var(--border);
  color: var(--text);
}
html[data-theme="dark"] .inbox-item { border-bottom-color: var(--border); color: var(--text); }
html[data-theme="dark"] .inbox-item:hover { background: var(--surface-2); }
html[data-theme="dark"] .inbox-item.active,
html[data-theme="dark"] .inbox-item.selected { background: rgba(77,139,255,.12); }
html[data-theme="dark"] .inbox-item.unread { border-inline-start: 3px solid var(--orca-blue); }
html[data-theme="dark"] .inbox-empty,
html[data-theme="dark"] .inbox-pane .muted { color: var(--muted); }

/* Rich-text editor (documents) */
html[data-theme="dark"] .rt-wrap,
html[data-theme="dark"] .rt-editor {
  background: #0f1827;
  border: 1px solid var(--border);
  color: var(--text);
}
html[data-theme="dark"] .rt-toolbar {
  background: var(--card);
  border-bottom: 1px solid var(--border);
}
html[data-theme="dark"] .rt-toolbar button { color: var(--text); background: transparent; }
html[data-theme="dark"] .rt-toolbar button:hover { background: var(--surface-2); }

/* Task chat / message bubbles */
html[data-theme="dark"] .msg,
html[data-theme="dark"] .chat-msg { color: var(--text); }
html[data-theme="dark"] .msg-bubble {
  background: #1a2638;
  color: var(--text);
  border: 1px solid var(--border);
}
html[data-theme="dark"] .msg-bubble.role-admin,
html[data-theme="dark"] .msg-bubble.from-admin {
  background: rgba(77,139,255,.18);
  border-color: rgba(77,139,255,.35);
}
html[data-theme="dark"] .msg-meta,
html[data-theme="dark"] .msg-time { color: var(--muted); }

/* Empty / placeholder states */
html[data-theme="dark"] .empty,
html[data-theme="dark"] .placeholder,
html[data-theme="dark"] .no-data {
  background: #0f1827;
  border: 1px dashed var(--border);
  color: var(--muted);
}

/* Notice banners (info / warning / success) */
html[data-theme="dark"] .notice,
html[data-theme="dark"] .notice-info {
  background: rgba(77,139,255,.10);
  border: 1px solid rgba(77,139,255,.30);
  color: #cfe0ff;
}
html[data-theme="dark"] .notice-success {
  background: rgba(34,197,94,.10);
  border-color: rgba(34,197,94,.30);
  color: #bbf7d0;
}
html[data-theme="dark"] .notice-warning {
  background: rgba(251,191,36,.10);
  border-color: rgba(251,191,36,.30);
  color: #fde68a;
}
html[data-theme="dark"] .notice-danger,
html[data-theme="dark"] .notice-error {
  background: rgba(239,68,68,.10);
  border-color: rgba(239,68,68,.30);
  color: #fecaca;
}

/* Skeleton shimmer (loading state) */
html[data-theme="dark"] .skeleton {
  background: linear-gradient(90deg, #131e2e 0%, #1a2638 50%, #131e2e 100%);
}

/* The printable document preview keeps a white surface even in dark mode
   — printed PDFs/Word exports must stay legible on paper. Force this
   regardless of theme so the user can preview what the export will look
   like. */
html[data-theme="dark"] .printable-doc,
html[data-theme="dark"] .doc-page {
  background: #ffffff;
  color: #111827;
}
html[data-theme="dark"] .printable-doc table,
html[data-theme="dark"] .printable-doc th,
html[data-theme="dark"] .printable-doc td {
  background: transparent;
  color: inherit;
  border-color: #e5e7eb;
}

/* Sidebar always stays dark navy regardless of theme — the white logo
   in components/sidebar.js depends on this. Re-assert here so any
   future tweaks to the light-mode sidebar styling don't accidentally
   bleed white into dark mode. */
.sidebar { background: var(--orca-navy); color: #fff; }
html[data-theme="dark"] .sidebar { background: var(--orca-navy); }
html[data-theme="dark"] .sidebar .nav-link.active {
  background: rgba(77,139,255,.18);
  color: #fff;
}

/* ============================================================
   ROUND 3 — Smoother page navigation
   Cross-fade + subtle slide-in for #page when its content changes.
   The router replaces the inner HTML on every route change; adding a
   short animation makes navigation feel instant rather than jumpy.
   ============================================================ */
@keyframes orca-page-in {
  from { opacity: 0; transform: translateY(6px); }
  to   { opacity: 1; transform: translateY(0); }
}
#page > * { animation: orca-page-in 220ms cubic-bezier(.2,.8,.2,1) both; }

/* Nav links get a softer hover transition */
.nav-link, .topbar a, .topbar button { transition: background-color var(--transition), color var(--transition); }

/* ============================================================
   ROUND 3 — Print typography (PDF / Word export)
   The browser's "Print → Save as PDF" path is what the export
   buttons rely on. Embed the Tajawal font so Arabic stays
   consistent and tighten the layout.
   NOTE: @page margin is set globally at the top of this file
   (@page { size: A4 portrait; margin: 0 }) so contract pages
   (height:297mm) fill exactly one physical A4 page. Do NOT add
   another @page rule here — last-wins in CSS means it would
   override the zero-margin rule and recreate blank pages.
   ============================================================ */
@media print {
  html, body {
    background: #ffffff !important;
    color: #111827 !important;
    font-family: "Tajawal", "Segoe UI", Tahoma, Arial, sans-serif !important;
    -webkit-print-color-adjust: exact;
    print-color-adjust: exact;
  }
  .printable-doc, .doc-page {
    background: #ffffff !important;
    color: #111827 !important;
    box-shadow: none !important;
    border: 0 !important;
    margin: 0 !important;
    padding: 0 !important;
  }
  .printable-doc h1, .printable-doc h2, .printable-doc h3 {
    color: #0b1730 !important;
    page-break-after: avoid;
  }
  .printable-doc table { border-collapse: collapse; width: 100%; font-size: 11pt; }
  .printable-doc table th {
    background: #f3f4f6 !important;
    color: #0b1730 !important;
    font-weight: 700;
    padding: 6pt 8pt;
    border-bottom: 1pt solid #cbd5e1 !important;
  }
  .printable-doc table td {
    padding: 5pt 8pt;
    border-bottom: 1pt solid #e5e7eb !important;
  }
  .printable-doc tr { page-break-inside: avoid; }
  .printable-doc .accent-line { background: #0b1730 !important; }
  /* Keep brand corners visible in PDF/print exports — the previous
     rule hid them, which dropped the ORCA branding from PDFs. */
  .printable-doc .doc-corner { display: block !important; }
  .no-print, .sidebar, .topbar, .toast, .modal-backdrop { display: none !important; }
}

/* ============================================================
   ROUND 4 — Dashboard task-overview KPI status pills
   The dashboard renders 5 KPI cards summarising tasks by status
   (pending, in_progress, blocked, submitted, done). Previously
   each card had a hard-coded pale background colour set inline,
   which made them look like white blocks in dark mode.
   We now expose the theme-aware variables here so both light and
   dark backgrounds get a tint that matches the status colour.
   ============================================================ */
.kpi-status {
  border-left: 4px solid transparent;
  background: var(--surface, #ffffff);
  transition: background .2s ease, border-color .2s ease;
}
.kpi-status[data-status="pending"]     { border-left-color: var(--orca-blue,#1E5EFF); background: #eff6ff; }
.kpi-status[data-status="in_progress"] { border-left-color: #0ea5e9; background: #e0f2fe; }
.kpi-status[data-status="blocked"]     { border-left-color: #6366f1; background: #e0e7ff; }
.kpi-status[data-status="submitted"]   { border-left-color: #8b5cf6; background: #f5f3ff; }
.kpi-status[data-status="done"]        { border-left-color: #0284c7; background: #dbeafe; }

/* Dark-mode tints — keep the colour cue but match the navy palette */
html[data-theme="dark"] .kpi-status                            { background: var(--surface, #1a2335); color: var(--text, #e2e8f0); }
html[data-theme="dark"] .kpi-status[data-status="pending"]     { background: rgba(30,94,255,.13);   }
html[data-theme="dark"] .kpi-status[data-status="in_progress"] { background: rgba(14,165,233,.14);  }
html[data-theme="dark"] .kpi-status[data-status="blocked"]     { background: rgba(99,102,241,.14);  }
html[data-theme="dark"] .kpi-status[data-status="submitted"]   { background: rgba(139,92,246,.14);  }
html[data-theme="dark"] .kpi-status[data-status="done"]        { background: rgba(2,132,199,.14);   }
html[data-theme="dark"] .kpi-status .kpi-head .title           { color: var(--muted-soft, #94a3b8); }
html[data-theme="dark"] .kpi-status .kpi-value                 { color: var(--text, #e2e8f0); }

/* ============================================================
   ROUND 4 — Document templates (contract + invoice redesign)
   Larger 110px logo, dark-navy / blue diagonal corner bands,
   bismillah cover sheet, party cards, signature boxes, dark
   "BILLED TO" card and a payment-methods grid.
   ============================================================ */
.doc-logo-xl {
  width: 110px !important;
  height: 110px !important;
  object-fit: contain;
  margin-bottom: 8px;
  filter: drop-shadow(0 4px 14px rgba(13,27,42,.12));
}
.doc-brand-tag {
  display: inline-block;
  background: #0D1B2A;
  color: #fff;
  padding: 6px 14px;
  border-radius: 6px;
  font-weight: 700;
  letter-spacing: 1px;
  font-size: 12px;
}
.doc-meta-table {
  width: 100%;
  border-collapse: collapse;
  margin: 12px 0 18px;
  font-size: 13px;
}
.doc-meta-table .k {
  background: #f1f5f9;
  color: #334155;
  font-weight: 600;
  width: 130px;
  padding: 6px 10px;
}
.doc-meta-table td {
  padding: 6px 10px;
  border-bottom: 1px solid #e2e8f0;
}

/* ----- Party cards (used on the cover + quote layouts) ----- */
.doc-party-card {
  background: #f8fafc;
  border: 1px solid #e2e8f0;
  border-inline-start: 4px solid #1E5EFF;
  padding: 14px 16px;
  border-radius: 8px;
}
.doc-party-card h3 {
  margin: 0 0 8px;
  color: #0D1B2A;
  font-size: 13px;
  text-transform: uppercase;
  letter-spacing: 1px;
}
.doc-party-card .name { font-weight: 700; color: #0D1B2A; font-size: 15px; }
.doc-party-card p { margin: 4px 0; color: #475569; font-size: 13px; }

/* ----- Contract: cover sheet ----- */
.doc-template-contract .doc-page { page-break-after: always; min-height: 297mm; position: relative; }
.doc-template-contract .doc-page:last-child { page-break-after: auto; }
.doc-cover {
  text-align: center;
  padding: 60px 40px 40px;
}
.doc-cover-logo {
  width: 160px;
  height: 160px;
  object-fit: contain;
  margin: 0 auto 18px;
  display: block;
  filter: drop-shadow(0 6px 20px rgba(13,27,42,.18));
}
.doc-bismillah {
  font-family: "Tajawal", "Amiri", serif;
  font-size: 22px;
  color: #0D1B2A;
  margin: 8px 0 24px;
  letter-spacing: 1px;
}
.doc-cover-title {
  font-size: 38px;
  color: #0D1B2A;
  margin: 12px 0 6px;
  letter-spacing: 2px;
  font-weight: 800;
}
.doc-cover-serial {
  display: inline-block;
  font-family: monospace;
  background: #1E5EFF;
  color: #fff;
  padding: 6px 16px;
  border-radius: 999px;
  font-size: 14px;
  margin-bottom: 26px;
}
.doc-cover-meta { max-width: 520px; margin: 0 auto 26px; text-align: start; }
.doc-cover .doc-parties { max-width: 720px; margin: 24px auto 0; }

/* ----- Contract: last (signature) page ----- */
.doc-last { text-align: center; padding: 50px 40px; }
.doc-last-title {
  color: #0D1B2A;
  font-size: 26px;
  letter-spacing: 1px;
  margin: 12px 0 32px;
}
.doc-signature-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 28px;
  max-width: 720px;
  margin: 0 auto;
}
.doc-signature-box {
  background: #f8fafc;
  border: 2px solid #cbd5e1;
  border-radius: 10px;
  padding: 22px 18px;
  text-align: center;
  min-height: 200px;
}
.doc-signature-box .sig-label {
  text-transform: uppercase;
  letter-spacing: 2px;
  color: #1E5EFF;
  font-weight: 700;
  font-size: 12px;
  margin-bottom: 12px;
}
.doc-signature-box .sig-name {
  font-size: 16px;
  font-weight: 700;
  color: #0D1B2A;
  margin-bottom: 60px;
}
.doc-signature-box .sig-line {
  border-top: 2px solid #0D1B2A;
  margin: 0 12px 8px;
}
.doc-signature-box .sig-meta { color: #64748b; font-size: 12px; }

/* ----- Invoice template (matches invoice.jpeg) ----- */
.doc-template-invoice .invoice-head-grid {
  display: grid;
  grid-template-columns: 1.4fr 1fr;
  gap: 18px;
  margin: 12px 0 22px;
}
.invoice-billed-to {
  background: #0D1B2A;
  color: #fff;
  padding: 22px 22px;
  border-radius: 10px;
  position: relative;
  overflow: hidden;
}
.invoice-billed-to::before {
  content: "";
  position: absolute;
  inset: auto -30px -30px auto;
  width: 120px;
  height: 120px;
  background: linear-gradient(135deg, #1E5EFF, transparent);
  border-radius: 50%;
  opacity: .35;
}
.invoice-billed-to .bt-label {
  text-transform: uppercase;
  letter-spacing: 3px;
  font-size: 11px;
  color: #93c5fd;
  margin-bottom: 8px;
}
.invoice-billed-to .bt-name {
  font-size: 20px;
  font-weight: 700;
  margin-bottom: 8px;
}
.invoice-billed-to .bt-line {
  font-size: 13px;
  color: #cbd5e1;
  margin: 2px 0;
  position: relative;
  z-index: 1;
}
.invoice-meta-card {
  background: #f8fafc;
  border: 1px solid #e2e8f0;
  border-radius: 10px;
  padding: 14px 16px;
}
.invoice-meta-card .doc-meta-table { margin: 0; }

/* ----- Invoice: payment methods grid ----- */
.invoice-payment-block { margin: 24px 0 12px; }
.invoice-payment-block h3 {
  color: #0D1B2A;
  border-inline-start: 4px solid #1E5EFF;
  padding-inline-start: 10px;
  margin: 0 0 12px;
  font-size: 16px;
}
.invoice-payment-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 14px;
}
.pm-card {
  border: 1px solid #e2e8f0;
  border-radius: 10px;
  padding: 16px;
  text-align: center;
  background: #ffffff;
  transition: transform .15s ease, box-shadow .15s ease;
}
.pm-card:hover { transform: translateY(-2px); box-shadow: 0 6px 18px rgba(13,27,42,.08); }
.pm-card .pm-icon { font-size: 26px; margin-bottom: 8px; }
.pm-card .pm-title { font-weight: 700; color: #0D1B2A; margin-bottom: 6px; font-size: 14px; }
.pm-card .pm-line { color: #475569; font-size: 12px; margin: 2px 0; word-break: break-all; }

/* ----- Footer band shared by all templates ----- */
.doc-footer-band {
  margin-top: 28px;
  background: linear-gradient(135deg, #0D1B2A 0%, #1E5EFF 100%);
  color: #fff;
  padding: 16px 22px;
  border-radius: 10px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-wrap: wrap;
  gap: 8px;
}
.doc-footer-band .thanks { font-weight: 700; font-size: 15px; letter-spacing: 1px; }
.doc-footer-band .iban-line { font-size: 12px; opacity: .9; font-family: monospace; }

/* ----- Dark-mode adjustments for document preview only -----
   The on-screen preview uses the dashboard surfaces, but the
   printable document itself must always look like white paper. */
html[data-theme="dark"] .printable-doc { background: #ffffff; color: #0f172a; }
html[data-theme="dark"] .doc-party-card { background: #f8fafc; color: #0f172a; }
html[data-theme="dark"] .invoice-meta-card { background: #f8fafc; color: #0f172a; }
html[data-theme="dark"] .pm-card { background: #ffffff; color: #0f172a; }

/* ----- Responsive (preview only — print always uses 2-up) ---- */
@media (max-width: 720px) {
  .doc-template-invoice .invoice-head-grid { grid-template-columns: 1fr; }
  .invoice-payment-grid { grid-template-columns: 1fr; }
  .doc-signature-grid   { grid-template-columns: 1fr; }
}

/* Print rules for the new templates — make sure dark-navy survives */
@media print {
  .doc-template-contract .doc-page,
  .doc-template-invoice  .doc-page { page-break-after: always; }
  .doc-template-contract .doc-page:last-child,
  .doc-template-invoice  .doc-page:last-child { page-break-after: auto; }
  .invoice-billed-to    { background: #0D1B2A !important; color: #ffffff !important; }
  .invoice-billed-to .bt-line { color: #cbd5e1 !important; }
  .doc-footer-band      { background: #0D1B2A !important; color: #ffffff !important; }
  .doc-cover-serial     { background: #1E5EFF !important; color: #ffffff !important; }
  .doc-brand-tag        { background: #0D1B2A !important; color: #ffffff !important; }
  .doc-signature-box    { border: 2px solid #cbd5e1 !important; }
}


  /* ============================================================
     CONTRACT LETTERHEAD TEMPLATE  (ctr-* prefix)
     ============================================================ */
  @import url('https://fonts.googleapis.com/css2?family=Amiri:ital,wght@0,400;0,700;1,400&display=swap');
  .ctr-printable { display:flex; flex-direction:column; gap:32px; margin:0 auto; max-width:210mm; }
  .ctr-page { background:#ffffff; width:210mm; min-height:297mm; max-width:100%; position:relative; box-shadow:0 8px 30px rgba(13,27,42,.12); overflow:hidden; display:flex; flex-direction:column; font-family:"Tajawal",system-ui,sans-serif; }
  .ctr-top-band { width:100%; height:50px; background:#1E5EFF; flex-shrink:0; position:relative; overflow:hidden; }
  .ctr-top-corner { position:absolute; top:-28px; inset-inline-end:-28px; width:130px; height:130px; background:#0a0a0a; transform:rotate(22deg); }
  .ctr-logo-row { display:flex; align-items:center; padding:5px 32px 4px; flex-shrink:0; position:relative; justify-content:center; }
  .ctr-logo { width:105px; height:105px; object-fit:contain; filter:drop-shadow(0 2px 10px rgba(13,27,42,.13)); position:absolute; right:26px; top:56px; transform:none; z-index:2; }
  .ctr-title-wrap { display:flex; flex-direction:column; align-items:center; text-align:center; }
  .ctr-title-ar { font-size:21px; font-weight:700; color:#0D1B2A; letter-spacing:1px; font-family:"Tajawal",sans-serif; }
  .ctr-title-underline { width:100%; height:3px; background:#1E5EFF; margin-top:5px; }
  .ctr-body { flex:1; padding:10px 32px 18px; display:flex; flex-direction:column; gap:12px; }
  .ctr-bismillah { text-align:center; font-family:"Amiri","Tajawal",serif; font-size:24px; color:#0D1B2A; padding:6px 0 2px; letter-spacing:1px; }
  .ctr-fields-row { display:flex; gap:16px; }
  .ctr-labeled-field { flex:1; display:flex; border:1px solid #c5cde0; border-radius:3px; overflow:hidden; }
  .ctr-field-label { background:#1E4ECC; color:#fff; padding:8px 14px; font-weight:700; font-size:13px; white-space:nowrap; display:flex; align-items:center; order:2; }
  [dir="ltr"] .ctr-field-label { order:1; }
  .ctr-field-value { flex:1; padding:8px 12px; font-size:13px; color:#1a1a1a; order:1; }
  [dir="ltr"] .ctr-field-value { order:2; }
  .ctr-section-box { border:1px solid #c5cde0; border-radius:3px; overflow:hidden; }
  .ctr-section-header { background:#0D1B2A; color:#fff; padding:9px 18px; font-weight:700; font-size:14px; text-align:center; letter-spacing:.5px; }
  .ctr-subject-content,.ctr-terms-content { padding:10px 18px; font-size:13px; line-height:1.75; min-height:60px; }
  .ctr-subject-lines,.ctr-terms-lines { padding:10px 18px 6px; }
  .ctr-line { border-bottom:1px solid #d1d9e8; height:24px; margin-bottom:8px; }
  .ctr-quran-verse { text-align:center; font-family:"Amiri","Tajawal",serif; font-size:22px; color:#1E5EFF; padding:10px 18px; line-height:1.8; letter-spacing:.5px; }
  .ctr-intro-section { display:flex; flex-direction:column; align-items:center; gap:12px; padding:4px 0 8px; width:100%; }
  .ctr-intro-btn { background:#1E5EFF; color:#fff; padding:10px 36px; font-size:15px; font-weight:700; border-radius:5px; letter-spacing:.5px; }
  /* ── Arabic RTL fix ───────────────────────────────────────────────────────
     Any non-zero letter-spacing breaks Arabic character shaping: glyphs lose
     their connections and appear as isolated characters rendered LTR.
     Scope the reset to RTL pages only so English contracts are unaffected. */
  .ctr-page[dir="rtl"] .ctr-title-ar,
  .ctr-page[dir="rtl"] .ctr-bismillah,
  .ctr-page[dir="rtl"] .ctr-quran-verse,
  .ctr-page[dir="rtl"] .ctr-intro-btn,
  .ctr-page[dir="rtl"] .ctr-section-header,
  .ctr-page[dir="rtl"] .ctr-party-header,
  .ctr-page[dir="rtl"] .ctr-sig-header { letter-spacing: 0 !important; }
  .ctr-intro-content { width:100%; min-height:40px; font-size:13px; line-height:1.9; }
  .ctr-blank-body { padding-top:35px; }
  .ctr-page-last .ctr-body { padding-top:35px; }
  .ctr-page-blank .ctr-logo-row,
  .ctr-page-last  .ctr-logo-row { padding-top:46px !important; }
  .ctr-blank-lines { display:flex; flex-direction:column; flex:1; gap:6px; }
  .ctr-parties-grid { display:grid; grid-template-columns:1fr 1fr; gap:14px; }
  .ctr-party-box { border:1.5px solid #1E5EFF; border-radius:5px; overflow:hidden; }
  .ctr-party-header { background:#0D1B2A; color:#fff; padding:9px 14px; font-weight:700; font-size:14px; display:flex; align-items:center; gap:8px; }
  .ctr-party-field { display:flex; align-items:flex-end; gap:8px; padding:5px 14px; border-bottom:1px solid #edf0f7; }
  .ctr-party-field:last-child { border-bottom:0; }
  .ctr-party-field-label { font-size:12px; color:#334155; white-space:nowrap; font-weight:500; }
  .ctr-party-field-line { flex:1; border-bottom:1px solid #b0bad0; min-height:18px; font-size:13px; color:#1a1a1a; padding-bottom:1px; }
  .ctr-sig-grid { display:grid; grid-template-columns:1fr 1fr; gap:14px; margin-top:4px; }
  .ctr-sig-box { border:1.5px solid #1E5EFF; border-radius:5px; overflow:hidden; }
  .ctr-sig-header { background:#0D1B2A; color:#fff; padding:9px 14px; font-weight:700; font-size:14px; display:flex; align-items:center; gap:8px; }
  .ctr-sig-area { padding:12px 14px 10px; }
  .ctr-sig-line-area { height:50px; border-bottom:1px dashed #b0bad0; margin-bottom:12px; }
  .ctr-footer-band { background:#1E5EFF; color:#fff; padding:13px 28px; flex-shrink:0; position:relative; overflow:hidden; margin-top:auto; }
  .ctr-bottom-corner { position:absolute; bottom:-28px; inset-inline-start:-28px; width:110px; height:110px; background:#0a0a0a; transform:rotate(22deg); }
  .ctr-footer-items { display:flex; justify-content:space-around; align-items:center; gap:16px; font-size:13px; position:relative; z-index:1; }
  .ctr-footer-item { display:flex; align-items:center; gap:6px; white-space:nowrap; }
  .ctr-footer-item svg { flex-shrink:0; opacity:.9; }
  html[data-theme="dark"] .ctr-page, html[data-theme="dark"] .ctr-party-field-line, html[data-theme="dark"] .ctr-sig-line-area { background:#ffffff !important; color:#0f172a !important; }
  html[data-theme="dark"] .ctr-party-field-label, html[data-theme="dark"] .ctr-title-ar { color:#1a1a1a !important; }
  /* Global print footer — hidden on screen, shown as fixed element in print */
  @media print {
      /* Ensure colours, backgrounds and shadows print correctly */
      * { -webkit-print-color-adjust: exact !important; print-color-adjust: exact !important; }

      .ctr-printable { gap: 0 !important; max-width: 100%; }

      /* ── PAGE RULES ───────────────────────────────────────────────────────
         All three sections use display:flex + flex-direction:column so that
         margin-top:auto on the footer reliably pins it to the bottom.

         Page 1 (cover) — height:297mm + overflow:hidden = exactly one A4 sheet.
           The body's flex:1 consumes all free space, naturally pushing the footer
           to the very bottom of the 297mm box without any position:absolute trick
           (which caused Chrome to bleed the footer onto the following page).

         Page 2 (agreement) — height:auto + min-height:297mm.
           Short text: container is exactly 297mm → footer at A4 bottom. ✓
           Long text:  container grows beyond 297mm → footer at end of content,
           which falls on the last physical page of that section. ✓
           page-break-after:avoid prevents a spurious forced break at the end.

         Page 3 (signatures) — same min-height strategy.
           page-break-before:always guarantees it always opens a fresh page. */

      /* ── page-break baseline: always after each section ── */
      .ctr-page {
        page-break-after: always !important; break-after: page !important;
        box-shadow: none !important;
        width: 210mm !important; max-width: 100% !important; margin: 0 auto !important;
        display: flex !important; flex-direction: column !important;
        font-size: 11px !important;
        height: 297mm !important;
        overflow: hidden !important;
        box-sizing: border-box !important;
      }

      /* ── Page 2: agreement – height follows content, min A4 ── */
      .ctr-page.ctr-page-blank {
        page-break-after: auto !important; break-after: auto !important;
        height: auto !important; min-height: 297mm !important;
        overflow: visible !important;
      }

      /* ── Page 3: signatures – always fresh page, height follows content ── */
      .ctr-page.ctr-page-last {
        page-break-before: always !important; break-before: page !important;
        page-break-after: auto !important;  break-after: auto !important;
        height: auto !important; min-height: 297mm !important;
        overflow: visible !important;
      }

      /* ── Invoice / quotation passthrough ── */
      .invoice-sheet { width: 100% !important; transform: none !important; margin: 0 !important; }
      #doc-content.invoice-doc { width: 100% !important; max-width: 100% !important; overflow: visible !important; }

      /* ── Header sizing ── */
      .ctr-top-band  { height: 38px !important; flex-shrink: 0 !important; flex-grow: 0 !important; }
      .ctr-logo      { width: 82px !important; height: 82px !important; top: 42px !important; right: 20px !important; transform: none !important; }
      .ctr-logo-row  { padding: 4px 24px 3px !important; flex-shrink: 0 !important; flex-grow: 0 !important; }
      .ctr-bismillah  { font-size: 17px !important; padding: 2px 0 0 !important; }
      .ctr-quran-verse { font-size: 15px !important; padding: 4px 12px !important; }

      /* ── Body: fills all remaining flex space ──
         flex:1 1 auto + min-height:0 lets the body grow on pages 2 & 3 while
         also allowing it to shrink properly within the 297mm page-1 box. */
      .ctr-body {
        padding: 6px 18px 8px !important;
        gap: 8px !important;
        flex: 1 1 auto !important;
        min-height: 0 !important;
      }
      /* Page 1 body is clipped by overflow:hidden on the page; no extra rule needed.
         Pages 2 & 3 bodies must be allowed to overflow so long text grows naturally. */
      .ctr-page-blank .ctr-body,
      .ctr-page-last  .ctr-body {
        overflow: visible !important;
        padding-top: 25px !important;
      }
      .ctr-page-blank .ctr-logo-row,
      .ctr-page-last  .ctr-logo-row { padding-top: 36px !important; }

      /* ── Footer strategy ───────────────────────────────────────────────────
         margin-top:auto in a flex column always pushes the footer below the
         body's flex:1 space.  Combined with page-break-before:avoid it stays
         with the last line of content and never orphans onto a new page.     */
      .ctr-footer-band {
        position: relative !important;
        bottom: auto !important; left: auto !important; right: auto !important;
        margin-top: auto !important;
        padding: 10px 28px !important;
        flex-shrink: 0 !important; flex-grow: 0 !important;
        page-break-before: avoid !important; break-before: avoid !important;
      }

      /* ── Avoid mid-element page breaks ── */
      .ctr-bismillah, .ctr-quran-verse,
      .ctr-intro-section, .ctr-intro-btn { page-break-inside: avoid; break-inside: avoid; }
      .ctr-party-field   { padding: 3px 10px !important; page-break-inside: avoid; break-inside: avoid; }
      .ctr-party-box, .ctr-sig-box       { page-break-inside: avoid; break-inside: avoid; }
      .ctr-parties-grid, .ctr-sig-grid   { page-break-inside: avoid; break-inside: avoid; }
      .ctr-section-box, .ctr-labeled-field { page-break-inside: avoid; break-inside: avoid; }

      /* ── Force-print colours ── */
      .ctr-top-band      { background: #1E5EFF !important; }
      .ctr-field-label   { background: #1E4ECC !important; color: #fff !important; }
      .ctr-section-header { background: #0D1B2A !important; color: #fff !important; }
      .ctr-party-header, .ctr-sig-header { background: #0D1B2A !important; color: #fff !important; }
      .ctr-footer-band   { background: #1E5EFF !important; color: #fff !important; }
      .ctr-intro-btn     { background: #1E5EFF !important; color: #fff !important; }
      .ctr-quran-verse   { color: #1E5EFF !important; }
      .ctr-top-corner, .ctr-bottom-corner { background: #000 !important; }
    }
  @media screen and (max-width:760px) {
    /* Grid layouts stack on mobile */
    .ctr-parties-grid,
    .ctr-sig-grid            { grid-template-columns: 1fr !important; gap: 10px !important; }
    .ctr-fields-row          { flex-direction: column; gap: 8px !important; }

    /* Contract page fills screen width */
    .ctr-page                { width: 100% !important; min-width: 0 !important;
                               border-radius: 8px; box-shadow: none;
                               margin: 0 auto !important; }
    .ctr-printable           { gap: 16px !important; }

    /* Header: logo + title row wraps nicely */
    .ctr-header              { flex-wrap: wrap; gap: 8px; min-height: 0 !important; padding: 10px 14px !important; }
    .ctr-logo                { height: 48px !important; width: auto !important; }
    .ctr-header-title        { font-size: 14px !important; }

    /* Body padding tighter on phone */
    .ctr-body                { padding: 10px 14px 14px !important; gap: 10px !important; }

    /* Subject box readable on small screens */
    .ctr-subject-box         { padding: 10px 12px !important; font-size: 13px !important; }

    /* Party boxes */
    .ctr-party-box           { padding: 0 !important; font-size: 12px !important; }
    .ctr-party-header        { padding: 7px 12px !important; font-size: 12px !important; }
    .ctr-party-fields        { padding: 6px 0 !important; }
    .ctr-party-field         { padding: 4px 10px !important; flex-wrap: wrap; }
    .ctr-party-field-label   { font-size: 11px !important; min-width: 80px; }
    .ctr-party-field-line    { font-size: 12px !important; }

    /* Section boxes (terms) */
    .ctr-section-box         { padding: 0 !important; }
    .ctr-section-header      { padding: 7px 12px !important; font-size: 12px !important; }
    .ctr-intro-content       { padding: 8px 12px !important; font-size: 12px !important; line-height: 1.8 !important; }

    /* Signature boxes */
    .ctr-sig-box             { font-size: 12px !important; }
    .ctr-sig-header          { padding: 7px 12px !important; font-size: 12px !important; }
    .ctr-sig-area            { padding: 8px 12px 8px !important; }

    /* Fields row on cover page */
    .ctr-fields-row-item     { font-size: 11px !important; }

    /* Footer band */
    .ctr-footer-band         { padding: 8px 14px !important; }
    .ctr-footer-items        { flex-wrap: wrap; gap: 8px !important; font-size: 11px !important; }
    .ctr-footer-item         { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 100%; }

    /* Bismillah / Quran verse */
    .ctr-bismillah           { font-size: 15px !important; }
    .ctr-quran-verse         { font-size: 11px !important; }
  }

  @media screen and (max-width: 480px) {
    .ctr-body                { padding: 8px 10px 12px !important; }
    .ctr-party-field-label   { min-width: 70px; font-size: 10px !important; }
    .ctr-party-field-line    { font-size: 11px !important; }
    .ctr-footer-items        { justify-content: flex-start; }
  }
  
/* ============================================================
   FEATURE BATCH 3 — COMPREHENSIVE RESPONSIVE DESIGN
   Supplements the existing breakpoints with deeper mobile polish
   ============================================================ */

/* ── Auth screens: full-width card on small phones ── */
@media (max-width: 500px) {
  .auth-screen { padding: 12px; align-items: flex-start; padding-top: 24px; }
  .auth-card {
    width: 100%;
    max-width: 100%;
    border-radius: 16px;
    padding: 24px 18px;
  }
  .auth-logo img { width: 148px; height: 148px; }
  .auth-card h1 { font-size: 19px; }
  .auth-card .grid.grid-2 { grid-template-columns: 1fr; }
}

/* ── Topbar: tighter on small phones ── */
@media (max-width: 480px) {
  .topbar-actions .btn.ghost.sm span { display: none; }
  .topbar-actions .btn.ghost.sm { min-width: 36px; justify-content: center; }
  .user-pill .badge { display: none; }
  .content { padding: 14px; }
  h1 { font-size: 20px; }
}

/* ── Tables: always scrollable inside a .table-wrap ── */
.table-wrap {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  border-radius: 0 0 var(--radius) var(--radius);
}
@media (max-width: 820px) {
  .table th, .table td { padding: 10px 12px; font-size: 13px; }
}
@media (max-width: 600px) {
  .table th, .table td { padding: 8px 10px; font-size: 12px; }
  .row-actions { flex-direction: column; gap: 4px; }
  .row-actions .btn { width: 100%; }
}

/* ── KPI cards: 2-up on phone instead of 4-up ── */
@media (max-width: 600px) {
  .grid-4 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .kpi { padding: 14px 10px; }
  .kpi-value { font-size: 28px; }
}

/* ── Modal: full-screen on small phones ── */
@media (max-width: 600px) {
  .modal {
    width: 100%;
    max-width: 100%;
    margin: 0;
    border-radius: 16px 16px 0 0;
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    max-height: 92vh;
    overflow-y: auto;
  }
  .modal-backdrop { align-items: flex-end; }
}

/* ── Cards: reduce padding on small phones ── */
@media (max-width: 600px) {
  .card-body { padding: 14px; }
  .card-header { padding: 12px 14px; }
  .card-body.compact { padding: 0; }
}

/* ── Document preview: full-width on mobile ── */
@media screen and (max-width: 820px) {
  .printable-doc,
  .doc-page {
    width: 100% !important;
    min-height: auto !important;
    border-radius: 8px;
  }
  .ctr-page {
    border-radius: 8px;
  }
  .document-view-shell {
    flex-direction: column;
    gap: 12px;
  }
  .doc-actions-bar {
    flex-wrap: wrap;
    gap: 8px;
  }
  .doc-actions-bar .btn { flex: 1 1 auto; }
}

/* ── Employee detail: stack on mobile ── */
@media (max-width: 820px) {
  .grid[style*="minmax(280px"] {
    grid-template-columns: 1fr !important;
  }
}

/* ── Settings tabs: wrap on mobile ── */
@media (max-width: 600px) {
  .tabs { flex-wrap: wrap; width: 100%; }
  .tab { flex: 1 1 auto; text-align: center; font-size: 12px; padding: 7px 8px; }
}

/* ── Stack spacing: tighter on phones ── */
@media (max-width: 600px) {
  .stack { gap: 12px; }
}

/* ── Row actions: always visible on mobile ── */
@media (max-width: 820px) {
  .row-actions { display: flex; flex-wrap: wrap; gap: 6px; }
}

/* ── Sidebar: ensure z-index above content ── */
@media (max-width: 820px) {
  .sidebar { z-index: 40; transition: transform .25s cubic-bezier(.4,0,.2,1); }
}

/* ── Prevent text overflow in table cells on mobile ── */
@media (max-width: 820px) {
  .table td { word-break: break-word; }
  .table .font-medium { word-break: break-word; }
}

/* ── Permissions toggle in employee modal ── */
.perm-toggle input:focus-visible + span {
  outline: 2px solid var(--orca-blue);
  outline-offset: 2px;
  border-radius: 24px;
}

/* ── Pending-users badge on tab ── */
#pending-badge {
  font-weight: 700;
  line-height: 1;
  border-radius: 999px;
  padding: 2px 7px;
  font-size: 11px;
  vertical-align: middle;
  margin-inline-start: 6px;
}

/* ============================================================
   MOBILE RESPONSIVE — Sidebar overlay + full layout collapse
   All JS toggle logic (toggleSidebar / openSidebar / closeSidebar)
   already exists in app.js. These styles make it actually work.
   ============================================================ */

/* ── Sidebar backdrop ─────────────────────────────────────────
   Sits behind the open sidebar, dims the content, and lets the
   user tap outside to close. Must be in CSS (not inline style)
   so the transition and z-index stack correctly.               */
.sidebar-backdrop {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(13, 27, 42, .55);
  z-index: 199;
  backdrop-filter: blur(2px);
  -webkit-backdrop-filter: blur(2px);
}
.sidebar-backdrop.open {
  display: block;
  animation: fade .2s ease;
}

/* ── Back button in topbar ────────────────────────────────────
   Shown only on mobile; hidden on desktop where the sidebar
   provides navigation context.                                 */
.topbar-back {
  display: none;
  background: transparent;
  border: 1px solid transparent;
  border-radius: 8px;
  width: 36px;
  height: 36px;
  align-items: center;
  justify-content: center;
  color: var(--muted);
  flex-shrink: 0;
  cursor: pointer;
  transition: background var(--transition), color var(--transition);
}
.topbar-back svg { width: 18px; height: 18px; display: block; }
.topbar-back:hover { background: var(--bg); color: var(--text); }

/* ── ≤ 768 px — main mobile breakpoint ───────────────────────
   Tablet and phone. Sidebar becomes a fixed slide-in drawer;
   the shell grid collapses to a single column.                 */
@media (max-width: 768px) {

  /* Show the back navigation button */
  .topbar-back { display: inline-flex; }

  /* Shell: sidebar is no longer a grid column */
  .shell {
    grid-template-columns: 1fr !important;
  }

  /* Sidebar: fixed overlay, starts fully off-screen */
  .sidebar {
    position: fixed;
    top: 0;
    bottom: 0;
    inset-inline-start: 0;
    width: 270px;
    max-width: 85vw;
    height: 100dvh;        /* modern browsers */
    height: 100vh;         /* fallback */
    z-index: 200;
    transform: translateX(-100%);
    transition: transform .27s cubic-bezier(.4, 0, .2, 1),
                box-shadow .27s ease;
    box-shadow: none;
  }
  /* RTL: sidebar slides in from the right */
  html[dir="rtl"] .sidebar {
    inset-inline-start: 0;
    transform: translateX(100%);
  }
  /* Open state — overrides both LTR and RTL closed positions */
  .sidebar.open {
    transform: translateX(0) !important;
    box-shadow: 0 0 60px rgba(13, 27, 42, .45);
  }

  /* Show the hamburger menu button */
  .menu-btn {
    display: inline-flex !important;
  }

  /* Topbar: tighter horizontal padding */
  .topbar {
    padding: 10px 14px;
    gap: 6px;
  }
  .topbar-left h2 {
    font-size: 14px;
    max-width: 180px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }

  /* Page content: reduce padding on tablets/phones */
  .content {
    padding: 14px !important;
  }

  /* 2-col and 3-col grids: collapse to 1 column */
  .grid-2,
  .grid-3 {
    grid-template-columns: 1fr !important;
  }

  /* Kanban board: stack all columns vertically */
  .kanban {
    grid-template-columns: 1fr !important;
  }

  /* Inbox: list on top, reading pane below */
  .inbox-shell {
    grid-template-columns: 1fr !important;
    min-height: auto;
  }

  /* Document party/signature grids */
  .doc-parties,
  .doc-signatures {
    grid-template-columns: 1fr !important;
    gap: 16px;
  }
  .doc-page {
    padding: 24px 18px !important;
  }

  /* Row: allow flex wrapping */
  .row.between {
    flex-wrap: wrap;
    gap: 8px;
  }

  /* h1: slightly smaller on mobile */
  h1 { font-size: 22px; }

  /* Stack: tighter gap */
  .stack { gap: 14px; }
}

/* ── ≤ 480 px — small phone: declutter the topbar ────────────
   On 375 px screens the topbar overflows unless we hide labels
   and compress the user pill down to just the avatar.          */
@media (max-width: 480px) {

  /* Topbar: minimal padding */
  .topbar { padding: 8px 10px; gap: 4px; }

  /* Hide text labels inside all topbar action buttons */
  .topbar-actions > .btn span,
  .topbar-actions > .btn > span {
    display: none !important;
  }
  .topbar-actions > .btn {
    padding: 7px;
    min-width: 34px;
    justify-content: center;
  }

  /* User pill: show avatar only */
  .user-pill > span:not(.user-avatar),
  .user-pill > .badge {
    display: none;
  }
  .user-pill {
    padding: 3px;
    border-radius: 50%;
    background: transparent;
  }

  /* Topbar title: shorter */
  .topbar-left h2 {
    max-width: 110px;
    font-size: 13px;
  }

  /* Content: tightest padding */
  .content { padding: 10px !important; }

  /* KPIs: 2 per row on small phones */
  .grid-4 {
    grid-template-columns: repeat(2, minmax(0, 1fr)) !important;
  }

  /* Card body: tighter */
  .card-body { padding: 12px !important; }
  .card-header { padding: 10px 12px !important; }

  /* Tables: smallest font */
  .table th, .table td { padding: 7px 8px; font-size: 12px; }

  /* Tabs: full-width, wrap */
  .tabs { flex-wrap: wrap; width: 100%; }
  .tab { flex: 1 1 auto; text-align: center; font-size: 12px; padding: 6px 8px; }
}

/* ===== Quotation — full-width header/footer PNGs ===== */
.quotation-header-image,
.quotation-footer {
  width: 100%;
  max-width: 100%;
  margin-left: 0;
  margin-right: 0;
  line-height: 0;
  font-size: 0;
  flex-shrink: 0;
  align-self: stretch;
}

.quotation-header-image {
  margin-top: 0;
  margin-bottom: 0;
}

.quotation-footer {
  margin-top: 12px;
  margin-bottom: 0;
}

.quotation-header-image img,
.quotation-footer img {
  width: 100% !important;
  max-width: 100% !important;
  height: auto !important;
  display: block !important;
  vertical-align: top;
}

.stack > #doc-content.quotation-doc,
.stack > #doc-content {
  width: 100%;
  max-width: 100%;
  min-width: 0;
}

#doc-content.quotation-doc .quotation-header-image,
#doc-content.quotation-doc .quotation-footer {
  width: 100%;
  max-width: 100%;
}

#doc-content.quotation-doc .quotation-header-image img,
#doc-content.quotation-doc .quotation-footer img {
  width: 100% !important;
  max-width: 100% !important;
  height: auto !important;
  display: block !important;
}

@media print {
  #doc-content.quotation-doc .quotation-header-image,
  #doc-content.quotation-doc .quotation-footer {
    width: 100% !important;
    max-width: 100% !important;
  }
}

/* Ensure printable-doc does not clip the new images */
.printable-doc {
  overflow: visible !important;
}


  /* ============================================================
     RESPONSIVE DOCUMENT VIEWER — mobile / tablet / desktop
     Contract pages fill the full viewport width (no scaling).
     Invoice/Quotation use CSS transform-scale to preserve their
     pixel-perfect A4 designs on small screens.
     ============================================================ */

  /* Container that holds the generated #doc-content */
  .stack {
    overflow-x: hidden;
  }

  /* ── Contract — full-width responsive on all screen sizes ─────
     The contract's internal layout already collapses grids and
     flex rows at ≤760px (see the ctr-* media query above). We
     simply let the page fill 100% width and drop the fixed A4
     height so it doesn't overflow on mobile. */
  .ctr-printable {
    width: 100% !important;
    max-width: 100% !important;
  }
  /* Each contract page looks like an A4 sheet on screen (like Word).
     min-height:297mm keeps the A4 proportions; overflow:visible lets
     pages that have more content than 297mm grow naturally instead of
     clipping — same page-break behaviour as in PDF. */
  .ctr-page {
    width: 100% !important;
    max-width: 210mm !important;
    margin-left: auto !important;
    margin-right: auto !important;
    min-height: 297mm !important;
    transform: none !important;
    margin-bottom: 40px !important;
    overflow: visible !important;
  }

  /* ── Invoice outer wrapper ─────────────────────────────────── */
  #doc-content.invoice-doc {
    width: 100% !important;
    max-width: 100% !important;
    overflow-x: hidden;
  }
  /* Invoice inner sheet — natural A4 width, scaled per breakpoint */
  .invoice-sheet {
    width: 210mm;
    transform-origin: top center;
    margin-left: auto;
    margin-right: auto;
    padding: 0 !important;
    overflow: hidden;
  }

    @media screen and (max-width: 860px) {
      .printable-doc {
        width: 100% !important;
        max-width: 100% !important;
        min-height: auto !important;
        overflow-x: clip;
      }
      /* Quotation sheet */
      #doc-content.quotation-doc {
        width: 100% !important;
        max-width: 100% !important;
        font-size: 11px !important;
      }
      #doc-content.quotation-doc .quotation-sheet {
        width: 210mm;
        transform-origin: top left;
        transform: scale(0.85);
        margin-bottom: calc((0.85 - 1) * 297mm);
      }
      /* Invoice sheet — scale from center */
      .invoice-sheet {
        transform: scale(0.85);
        margin-bottom: calc((0.85 - 1) * 200mm);
      }
    }

    /* Tablet: 601-750px */
    @media screen and (min-width: 601px) and (max-width: 750px) {
      #doc-content.quotation-doc .quotation-sheet {
        transform: scale(0.75);
        margin-bottom: calc((0.75 - 1) * 297mm);
      }
      .invoice-sheet {
        transform: scale(0.75);
        margin-bottom: calc((0.75 - 1) * 200mm);
      }
    }

    /* Medium phone: ≤600px */
    @media screen and (max-width: 600px) {
      #doc-content.quotation-doc .quotation-sheet {
        transform: scale(0.55);
        margin-bottom: calc((0.55 - 1) * 297mm);
      }
      .invoice-sheet {
        transform: scale(0.55);
        margin-bottom: calc((0.55 - 1) * 200mm);
      }
    }

    /* Small phone: ≤420px */
    @media screen and (max-width: 420px) {
      #doc-content.quotation-doc .quotation-sheet {
        transform: scale(0.50);
        margin-bottom: calc((0.50 - 1) * 297mm);
      }
      .invoice-sheet {
        transform: scale(0.50);
        margin-bottom: calc((0.50 - 1) * 200mm);
      }
    }

    /* Very small phone: ≤380px */
    @media screen and (max-width: 380px) {
      #doc-content.quotation-doc .quotation-sheet {
        transform: scale(0.46);
        margin-bottom: calc((0.46 - 1) * 297mm);
      }
      .invoice-sheet {
        transform: scale(0.46);
        margin-bottom: calc((0.46 - 1) * 200mm);
      }
    }

    /* Doc-actions toolbar wraps neatly on small screens */
    @media screen and (max-width: 640px) {
      .doc-actions {
        flex-direction: column;
        width: 100%;
      }
      .doc-actions .btn,
      .doc-actions button {
        width: 100%;
        justify-content: center;
      }
    }

    /* Contract responsive: parties and sig grids collapse to single column */
    @media screen and (max-width: 720px) {
      .ctr-parties-grid { grid-template-columns: 1fr !important; }
      .ctr-sig-grid     { grid-template-columns: 1fr !important; }
    }

/* ============================================================
   CONTRACT — FULLY RESPONSIVE ON MOBILE / TABLET
   All contract pages are always visible on screen (no content
   is hidden). JavaScript in _initDocScale() scales each
   .ctr-page to exactly fit the viewport width using
   transform-origin: top center, so everything is centered and
   readable without any horizontal scrolling.
   On print, resetForPrint() clears all transforms so every page
   prints at full A4 size with correct margins.
   ============================================================ */
@media screen and (max-width: 900px) {
  /* Clip any sub-pixel overflow from the CSS transform */
  .ctr-printable {
    overflow-x: hidden;
    width: 100%;
  }
  /* Each page is already centered by JS via top-center transform-origin;
     ensure no extra horizontal margin shifts it off-center */
  .ctr-page {
    margin-left: auto !important;
    margin-right: auto !important;
  }
}

@media print {
  /* Always print all contract pages at full A4 size */
  .ctr-page {
    transform: none !important;
    transform-origin: initial !important;
    margin-bottom: 0 !important;
    display: block !important;
  }
}

/* ── Sidebar user profile / avatar area ─────────────────────────── */
.sidebar-user-section {
  padding: 6px 10px 10px;
  border-top: 1px solid rgba(255,255,255,.07);
  margin-top: 4px;
}
.sidebar-user-wrap {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 10px;
  border-radius: 8px;
  cursor: pointer;
  transition: background .18s;
  min-width: 0;
  user-select: none;
}
.sidebar-user-wrap:hover { background: rgba(255,255,255,.07); }
.sidebar-user-avatar {
  width: 36px; height: 36px;
  border-radius: 50%;
  overflow: hidden;
  background: var(--primary, #1E5EFF);
  display: flex; align-items: center; justify-content: center;
  flex-shrink: 0;
  border: 2px solid rgba(255,255,255,.15);
}
.sidebar-user-avatar-img  { width: 100%; height: 100%; object-fit: cover; display: block; }
.sidebar-user-avatar-ini  { font-size: 13px; font-weight: 700; color: #fff; line-height: 1; letter-spacing: .5px; }
.sidebar-user-info        { flex: 1; min-width: 0; }
.sidebar-user-name        { font-size: 13px; font-weight: 600; color: rgba(255,255,255,.9); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.sidebar-user-role        { font-size: 11px; color: rgba(255,255,255,.4); text-transform: capitalize; margin-top: 1px; }


/* ═══════════════════════════════════════════════════════════════════════
   PERFORMANCE OPTIMISATIONS
   ═══════════════════════════════════════════════════════════════════════ */

/* Promote GPU layers for animated / scrolled elements */
.sidebar          { will-change: transform; contain: layout style; }
.modal            { will-change: transform, opacity; }
.modal-backdrop   { will-change: opacity; }
.topbar           { contain: layout style; }

/* Prevent expensive full-page repaints on card list updates */
.card             { contain: layout; }
.table tbody tr   { contain: layout; }

/* Smooth transitions stay cheap with containment */
.nav-link         { will-change: background-color; }
.btn              { will-change: background-color, box-shadow; }

/* Lazy load images — applied at component level via loading="lazy" attr;
   also ensure images never force layout by setting explicit dimensions */
img[loading="lazy"] { display: block; }

/* Debounce visual reflow on resize for contract pages */
.ctr-page         { contain: layout; }

/* Reduce reflow on search-result list changes */
#cli-list, #emp-list, #doc-list { contain: layout; }


/* ── Client profile avatars ─────────────────────────────────────────────── */
.cli-avatar {
  width:36px;height:36px;border-radius:50%;object-fit:cover;
  display:inline-block;vertical-align:middle;flex-shrink:0;
  border:2px solid var(--border);background:var(--bg);
  transition:box-shadow var(--transition);
}
.cli-avatar-init {
  width:36px;height:36px;border-radius:50%;
  background:linear-gradient(135deg,#1E5EFF 0%,#1849cc 100%);
  color:#fff;font-weight:700;font-size:13px;
  display:inline-flex;align-items:center;justify-content:center;
  flex-shrink:0;vertical-align:middle;
  border:2px solid rgba(255,255,255,.15);user-select:none;
}
.cli-name-cell {
  display:flex;align-items:center;gap:10px;text-decoration:none;
}
.cli-name-cell:hover .cli-avatar,
.cli-name-cell:hover .cli-avatar-init { box-shadow:0 0 0 3px rgba(30,94,255,.22); }
.cli-avatar-lg {
  width:76px;height:76px;border-radius:50%;object-fit:cover;display:block;
  border:3px solid var(--border);background:var(--bg);flex-shrink:0;
  transition:opacity var(--transition),box-shadow var(--transition);
}
.cli-avatar-init-lg {
  width:76px;height:76px;border-radius:50%;
  background:linear-gradient(135deg,#1E5EFF 0%,#1849cc 100%);
  color:#fff;font-weight:700;font-size:26px;
  display:flex;align-items:center;justify-content:center;
  flex-shrink:0;border:3px solid rgba(255,255,255,.15);user-select:none;
}
.cli-avatar-wrap {
  position:relative;display:inline-block;cursor:pointer;
}
.cli-avatar-wrap:hover .cli-avatar-lg,
.cli-avatar-wrap:hover .cli-avatar-init-lg { opacity:.82;box-shadow:0 0 0 4px rgba(30,94,255,.25); }
.cli-avatar-overlay {
  position:absolute;inset:0;border-radius:50%;
  background:rgba(13,27,42,.40);color:#fff;font-size:20px;
  display:flex;align-items:center;justify-content:center;
  opacity:0;transition:opacity var(--transition);pointer-events:none;
}
.cli-avatar-wrap:hover .cli-avatar-overlay { opacity:1; }
.cli-photo-picker {
  width:80px;height:80px;border-radius:50%;
  border:2px dashed var(--border);background:var(--bg);
  display:flex;flex-direction:column;align-items:center;justify-content:center;
  cursor:pointer;transition:border-color var(--transition),background var(--transition);
  overflow:hidden;flex-shrink:0;margin:0 auto 4px;
}
.cli-photo-picker:hover { border-color:var(--orca-blue);background:rgba(30,94,255,.05); }
.cli-photo-picker img { width:100%;height:100%;object-fit:cover;border-radius:50%; }
.cli-photo-picker-icon { font-size:22px;color:var(--muted);line-height:1; }
.cli-photo-picker-label { font-size:10px;color:var(--muted);margin-top:3px; }

/* ── Skeleton loader ────────────────────────────────────────────────────── */
@keyframes skeletonShimmer {
  0%{background-position:200% 0}100%{background-position:-200% 0}
}
.skeleton {
  background:linear-gradient(90deg,var(--border) 25%,var(--bg-alt,rgba(255,255,255,.06)) 50%,var(--border) 75%);
  background-size:400% 100%;
  animation:skeletonShimmer 1.4s ease infinite;
  border-radius:4px;
}

/* ── Connection status dot ──────────────────────────────────────────────── */
.conn-dot {
  width:9px;height:9px;border-radius:50%;flex-shrink:0;
  display:inline-block;align-self:center;
  transition:background .4s,box-shadow .4s;
  margin:0 3px;cursor:default;
}
.conn-dot.online {
  background:#22c55e;
  box-shadow:0 0 0 3px rgba(34,197,94,0.20);
  animation:connPulse 2.8s ease infinite;
}
.conn-dot.offline {
  background:#94a3b8;
  box-shadow:none;
  animation:none;
}
@keyframes connPulse {
  0%,100%{box-shadow:0 0 0 3px rgba(34,197,94,0.20);}
  50%      {box-shadow:0 0 0 7px rgba(34,197,94,0.06);}
}
