/* ==========================================================================
   Taj Al Mada — Modern Executive UI/UX & Dark Mode Layer
   Screen-only rules: A4 print layouts in style.css remain untouched.
   ========================================================================== */

@media screen {
  :root {
    --surface: #ffffff;
    --surface-2: #f8fafd;
    --surface-hover: #f1f5fb;
    --bg: #f1f5f9;
    --ink: #0f172a;
    --ink-soft: #334155;
    --muted: #64748b;
    --line: #e2e8f0;
    --line-strong: #cbd5e1;
    --shadow-sm: 0 1px 2px rgba(15, 23, 42, 0.05);
    --shadow-md: 0 8px 24px -8px rgba(15, 23, 42, 0.09), 0 2px 6px -2px rgba(15, 23, 42, 0.04);
    --shadow-lg: 0 22px 50px -12px rgba(15, 23, 42, 0.22);
    --glass-top: rgba(255, 255, 255, 0.86);
    --radius-sm: 8px;
    --radius-md: 12px;
    --radius-lg: 16px;
    --skeleton-base: #e2e8f0;
    --skeleton-shine: #f8fafc;
  }

  [data-theme="dark"] {
    --surface: #111c2d;
    --surface-2: #162338;
    --surface-hover: #1c2c46;
    --bg: #0a1220;
    --ink: #f1f5f9;
    --ink-soft: #cbd5e1;
    --muted: #94a3b8;
    --line: #23334c;
    --line-strong: #324766;
    --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.35);
    --shadow-md: 0 10px 28px -8px rgba(0, 0, 0, 0.45);
    --shadow-lg: 0 24px 60px -12px rgba(0, 0, 0, 0.65);
    --glass-top: rgba(15, 25, 42, 0.88);
    --accent-soft: rgba(59, 130, 246, 0.16);
    --skeleton-base: #1c2a40;
    --skeleton-shine: #273a57;
  }

  html {
    scroll-behavior: smooth;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
  }

  body {
    background: var(--bg);
    color: var(--ink);
    font-size: 14.5px;
    line-height: 1.5;
    transition: background-color 0.2s ease, color 0.2s ease;
  }

  /* Custom subtle scrollbars */
  ::-webkit-scrollbar {
    width: 8px;
    height: 8px;
  }
  ::-webkit-scrollbar-track {
    background: transparent;
  }
  ::-webkit-scrollbar-thumb {
    background: rgba(100, 116, 139, 0.32);
    border-radius: 99px;
  }
  ::-webkit-scrollbar-thumb:hover {
    background: rgba(100, 116, 139, 0.5);
  }

  /* Sidebar polish */
  .rail {
    background: linear-gradient(180deg, #0b182c 0%, #0f213b 55%, #122947 100%);
    border-right: 1px solid rgba(255, 255, 255, 0.06);
    padding: 22px 14px 18px;
  }

  .brand {
    padding: 0 8px 20px;
    border-bottom: 1px solid rgba(255, 255, 255, 0.08);
  }

  .brand .mark {
    border-radius: 11px;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.25);
  }

  .nav-label {
    font-size: 11px;
    text-transform: uppercase;
    letter-spacing: 0.1em;
    font-weight: 700;
    color: rgba(186, 204, 232, 0.65);
    margin: 20px 10px 10px;
  }

  #nav {
    gap: 4px;
  }

  #nav button {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px 12px;
    font-size: 13.5px;
    font-weight: 600;
    color: rgba(219, 229, 245, 0.82);
    border-radius: 10px;
    border: 1px solid transparent;
    transition: background 0.16s ease, color 0.16s ease, transform 0.14s ease, border-color 0.16s ease;
  }

  #nav button:hover {
    background: rgba(255, 255, 255, 0.08);
    color: #ffffff;
    transform: translateX(2px);
  }

  #nav button[aria-current] {
    background: linear-gradient(90deg, rgba(255, 255, 255, 0.14), rgba(255, 255, 255, 0.06));
    border-color: rgba(255, 255, 255, 0.14);
    color: #ffffff;
    box-shadow: inset 3px 0 0 var(--nav-color, #d9b66d), 0 4px 12px rgba(0, 0, 0, 0.18);
  }

  #nav button .nav-ico {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 20px;
    height: 20px;
    flex: none;
    color: var(--nav-color, #9cbfff);
  }

  #nav button .nav-ico svg {
    width: 18px;
    height: 18px;
  }

  #nav button .nav-text {
    flex: 1;
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
  }

  #nav button .nav-badge {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 20px;
    height: 20px;
    padding: 0 6px;
    border-radius: 99px;
    font-size: 11px;
    font-weight: 700;
    background: rgba(239, 68, 68, 0.22);
    color: #fca5a5;
    border: 1px solid rgba(239, 68, 68, 0.35);
    font-variant-numeric: tabular-nums;
  }

  #nav button .nav-badge.info {
    background: rgba(148, 163, 184, 0.18);
    color: #cbd5e1;
    border-color: rgba(148, 163, 184, 0.22);
  }

  #nav [data-page="staff"] {
    --nav-color: #fbbf24;
  }

  /* Frosted Sticky Top Header */
  .top {
    position: sticky;
    top: 0;
    z-index: 60;
    height: 66px;
    background: var(--glass-top);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    border-bottom: 1px solid var(--line);
    box-shadow: var(--shadow-sm);
    padding: 0 28px;
  }

  .top b {
    color: var(--ink);
    font-size: 15px;
    letter-spacing: -0.01em;
  }

  .top span {
    color: var(--muted);
    border-left-color: var(--line);
    font-size: 13px;
  }

  /* Global Quick Search trigger in top bar */
  .cmd-trigger {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    min-height: 36px;
    padding: 5px 12px;
    border-radius: 10px;
    background: var(--surface-2);
    border: 1px solid var(--line);
    color: var(--muted);
    font-size: 13px;
    font-weight: 500;
    cursor: pointer;
    transition: border-color 0.15s ease, background 0.15s ease, color 0.15s ease;
  }

  .cmd-trigger:hover {
    border-color: var(--line-strong);
    background: var(--surface-hover);
    color: var(--ink);
  }

  .cmd-trigger kbd {
    font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
    font-size: 11px;
    font-weight: 600;
    padding: 2px 6px;
    border-radius: 5px;
    background: var(--surface);
    border: 1px solid var(--line);
    color: var(--muted);
  }

  .theme-toggle-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 36px;
    height: 36px;
    min-height: 36px;
    padding: 0;
    border-radius: 10px;
    background: var(--surface-2);
    border: 1px solid var(--line);
    color: var(--ink-soft);
    cursor: pointer;
    transition: background 0.15s ease, border-color 0.15s ease, transform 0.15s ease;
  }

  .theme-toggle-btn:hover {
    background: var(--surface-hover);
    border-color: var(--line-strong);
    color: var(--ink);
  }

  .theme-toggle-btn:active {
    transform: scale(0.94);
  }

  /* Subtle understated workspace notice */
  .notice {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    padding: 6px 12px;
    border-radius: 99px;
    background: var(--surface);
    border: 1px solid var(--line);
    color: var(--muted);
    font-size: 12px;
    box-shadow: var(--shadow-sm);
  }

  .notice b {
    color: var(--ink);
    font-weight: 700;
    display: inline-flex;
    align-items: center;
    gap: 6px;
  }

  .notice b::before {
    content: "";
    width: 7px;
    height: 7px;
    border-radius: 50%;
    background: #10b981;
    box-shadow: 0 0 0 3px rgba(16, 185, 129, 0.2);
  }

  .expiry-page .notice::before {
    display: none;
  }

  /* Smooth Page Transitions */
  @keyframes fadeSlideUp {
    from {
      opacity: 0;
      transform: translateY(8px);
    }
    to {
      opacity: 1;
      transform: translateY(0);
    }
  }

  main > section:not([hidden]),
  main > #dashboard:not([hidden]) {
    animation: fadeSlideUp 0.22s cubic-bezier(0.22, 1, 0.36, 1);
  }

  .page-header {
    margin: 18px 0 18px;
  }

  .page-header h1 {
    font-size: 26px;
    font-weight: 800;
    letter-spacing: -0.025em;
    color: var(--ink);
  }

  /* Elevated Surfaces & Cards */
  .workspace {
    background: var(--bg);
  }

  .panel,
  .list-panel,
  .records,
  .actions {
    background: var(--surface);
    border: 1px solid var(--line);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-md);
    transition: border-color 0.2s ease, box-shadow 0.2s ease;
  }

  .group {
    background: var(--surface-2);
    border-color: var(--line);
    border-radius: var(--radius-md);
  }

  /* Buttons micro-interactions */
  button {
    transition: background-color 0.15s ease, border-color 0.15s ease, color 0.15s ease, box-shadow 0.15s ease, transform 0.12s ease;
  }

  button:active:not(:disabled) {
    transform: scale(0.98);
  }

  .primary,
  .gold,
  .expiry-page #new {
    border-radius: 10px;
    font-weight: 600;
    box-shadow: 0 4px 12px -2px rgba(37, 99, 235, 0.28);
  }

  .primary:hover,
  .gold:hover,
  .expiry-page #new:hover {
    transform: translateY(-1px);
    box-shadow: 0 6px 16px -2px rgba(37, 99, 235, 0.36);
  }

  .light {
    background: var(--surface-2);
    border: 1px solid var(--line);
    color: var(--ink-soft);
    border-radius: 9px;
  }

  .light:hover {
    background: var(--surface-hover);
    border-color: var(--line-strong);
    color: var(--ink);
  }

  /* Executive Dashboard Banner + Live Pulse */
  .home-banner {
    border-radius: 20px;
    padding: 28px 30px;
    background: linear-gradient(125deg, #0d1f3c 0%, #173664 52%, #1d4e89 100%);
    box-shadow: 0 18px 40px -14px rgba(13, 31, 60, 0.45);
    border: 1px solid rgba(255, 255, 255, 0.1);
    margin: 0 0 22px;
  }

  .home-banner h2 {
    font-size: 27px;
    font-weight: 800;
    letter-spacing: -0.02em;
    margin: 8px 0 6px;
  }

  .home-banner p {
    font-size: 14.5px;
    color: rgba(219, 234, 254, 0.88);
  }

  .home-banner button {
    background: linear-gradient(135deg, #d9b66d, #c69c49);
    color: #0f172a;
    border: 0;
    font-weight: 700;
    padding: 11px 18px;
    border-radius: 11px;
    box-shadow: 0 8px 20px -4px rgba(217, 182, 109, 0.45);
  }

  .home-banner button:hover {
    filter: brightness(1.04);
    transform: translateY(-1px);
  }

  .banner-pulse {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
    margin-top: 16px;
  }

  .pulse-pill {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    padding: 6px 12px;
    border-radius: 99px;
    background: rgba(255, 255, 255, 0.1);
    border: 1px solid rgba(255, 255, 255, 0.14);
    backdrop-filter: blur(6px);
    font-size: 12.5px;
    color: #e2e8f0;
  }

  .pulse-pill strong {
    color: #ffffff;
    font-weight: 700;
    font-variant-numeric: tabular-nums;
  }

  .pulse-pill.warn strong {
    color: #fde047;
  }

  .pulse-pill.danger strong {
    color: #fca5a5;
  }

  /* Stat Cards */
  .dashboard-cards:not(.dashboard-add-cards) .stat-card {
    background: var(--surface);
    border: 1px solid var(--line);
    border-radius: 16px;
    padding: 20px;
    box-shadow: var(--shadow-md);
    transition: transform 0.18s ease, box-shadow 0.18s ease, border-color 0.18s ease;
  }

  .dashboard-cards:not(.dashboard-add-cards) .stat-card:hover {
    transform: translateY(-3px);
    box-shadow: 0 14px 30px -10px rgba(15, 23, 42, 0.15);
    border-color: var(--line-strong);
  }

  .dashboard-cards:not(.dashboard-add-cards) .stat-card strong {
    font-size: 32px;
    letter-spacing: -0.03em;
    font-variant-numeric: tabular-nums;
  }

  .dashboard-cards:not(.dashboard-add-cards) .stat-card > span:not(.home-icon):not(.stat-arrow) {
    color: var(--muted);
    font-weight: 600;
    font-size: 13px;
  }

  .dashboard-add-cards .stat-card {
    background: var(--surface);
    border: 1px dashed var(--line-strong);
    border-top: 1px dashed var(--line-strong);
    border-radius: 13px;
    color: var(--ink);
    min-height: 54px;
    padding: 12px 16px;
    font-size: 13.5px;
    box-shadow: var(--shadow-sm);
  }

  .dashboard-add-cards .stat-card:hover {
    border-style: solid;
    border-color: #2563eb;
    background: var(--accent-soft);
    transform: translateY(-2px);
  }

  /* Dashboard Highlights & Overview */
  .home-section-heading h2 {
    color: var(--ink);
    font-size: 18px;
    font-weight: 700;
  }

  .home-section-heading > span {
    color: var(--muted);
    font-size: 13px;
    font-weight: 600;
  }

  .home-bar > div {
    background: var(--surface-hover);
    height: 9px;
  }

  .home-bar i {
    transition: width 0.45s cubic-bezier(0.22, 1, 0.36, 1);
  }

  .home-expiry-row {
    color: var(--ink);
    border-bottom-color: var(--line);
    padding: 11px 8px;
    border-radius: 10px;
    transition: background 0.15s ease;
  }

  .home-expiry-row:hover {
    background: var(--surface-hover);
  }

  .dashboard-highlight {
    border-top-width: 3px;
  }

  .dashboard-highlight li + li {
    border-top-color: var(--line);
  }

  .dashboard-record {
    color: var(--ink);
    padding: 12px 10px;
    border-radius: 10px;
    transition: background 0.15s ease, transform 0.14s ease;
  }

  .dashboard-record small {
    color: var(--muted);
  }

  .dashboard-record:hover {
    background: var(--surface-hover);
    transform: translateX(2px);
  }

  /* Tables */
  .record-table thead th {
    font-size: 12px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    padding: 12px 14px;
    border-bottom: 1px solid var(--line);
  }

  .record-table td {
    padding: 12px 14px;
    border-bottom-color: var(--line);
    color: var(--ink);
  }

  .record-table tbody tr {
    transition: background-color 0.12s ease;
  }

  /* Inputs & Form Polish */
  input,
  textarea,
  select {
    background: var(--surface);
    color: var(--ink);
    border-color: var(--line-strong);
    border-radius: 10px;
    min-height: 41px;
    padding: 8px 12px;
  }

  input[readonly] {
    background: var(--surface-2);
  }

  input:user-invalid,
  select:user-invalid,
  textarea:user-invalid {
    border-color: #ef4444;
  }

  /* Drag & Drop File Dropzone Upgrade */
  .dropzone-wrap {
    position: relative;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 5px;
    padding: 16px 14px;
    border: 1.5px dashed var(--line-strong);
    border-radius: 12px;
    background: var(--surface-2);
    text-align: center;
    cursor: pointer;
    transition: border-color 0.16s ease, background 0.16s ease, box-shadow 0.16s ease;
  }

  .dropzone-wrap:hover,
  .dropzone-wrap.drag-over {
    border-color: #2563eb;
    background: var(--accent-soft);
    box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.12);
  }

  .dropzone-wrap input[type="file"] {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
    opacity: 0;
    cursor: pointer;
    min-height: 0;
    padding: 0;
    border: 0;
  }

  .dropzone-icon {
    font-size: 20px;
    line-height: 1;
    color: #2563eb;
  }

  .dropzone-title {
    font-size: 13px;
    font-weight: 600;
    color: var(--ink);
  }

  .dropzone-meta {
    font-size: 12px;
    color: var(--muted);
    overflow-wrap: anywhere;
  }

  /* Toast Notification */
  #toast {
    bottom: 22px;
    right: 22px;
    background: #0f172a;
    color: #f8fafc;
    border: 1px solid rgba(255, 255, 255, 0.12);
    border-left: 4px solid #d9b66d;
    border-radius: 12px;
    padding: 12px 18px;
    font-weight: 600;
    font-size: 13.5px;
    box-shadow: 0 18px 36px -8px rgba(15, 23, 42, 0.45);
    animation: fadeSlideUp 0.2s ease;
  }

  /* Skeleton Loader */
  @keyframes skeletonShimmer {
    0% { background-position: 200% 0; }
    100% { background-position: -200% 0; }
  }

  #workspace-skeleton {
    display: grid;
    gap: 18px;
    margin-top: 8px;
  }

  .skel-box {
    background: linear-gradient(90deg, var(--skeleton-base) 25%, var(--skeleton-shine) 50%, var(--skeleton-base) 75%);
    background-size: 200% 100%;
    animation: skeletonShimmer 1.35s infinite linear;
    border-radius: 14px;
  }

  .skel-banner {
    height: 148px;
    border-radius: 20px;
  }

  .skel-cards {
    display: grid;
    grid-template-columns: repeat(4, minmax(0, 1fr));
    gap: 14px;
  }

  .skel-card {
    height: 118px;
  }

  .skel-grid {
    display: grid;
    grid-template-columns: 1.2fr 1fr;
    gap: 18px;
  }

  .skel-panel {
    height: 220px;
  }

  @media (max-width: 1120px) {
    .skel-cards { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  }

  @media (max-width: 900px) {
    .skel-grid { grid-template-columns: 1fr; }
  }

  /* Command Palette (Ctrl+K) */
  #command-palette {
    width: min(620px, calc(100vw - 24px));
    max-height: 78dvh;
    margin-top: 8vh;
    padding: 0;
    border: 1px solid var(--line);
    border-radius: 16px;
    background: var(--surface);
    color: var(--ink);
    box-shadow: var(--shadow-lg);
    overflow: hidden;
  }

  #command-palette::backdrop {
    background: rgba(8, 15, 30, 0.58);
    backdrop-filter: blur(4px);
  }

  .cmd-head {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 14px 16px;
    border-bottom: 1px solid var(--line);
    background: var(--surface);
  }

  .cmd-head svg {
    color: var(--muted);
    flex: none;
  }

  .cmd-head input {
    border: 0;
    background: transparent;
    padding: 4px 0;
    min-height: 32px;
    font-size: 15px;
    color: var(--ink);
    box-shadow: none !important;
    outline: none !important;
  }

  .cmd-esc {
    font-size: 11px;
    font-weight: 700;
    padding: 4px 8px;
    border-radius: 6px;
    background: var(--surface-2);
    border: 1px solid var(--line);
    color: var(--muted);
    cursor: pointer;
    min-height: 0;
  }

  .cmd-results {
    max-height: 55dvh;
    overflow-y: auto;
    padding: 8px;
  }

  .cmd-group-label {
    font-size: 11px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    color: var(--muted);
    padding: 8px 10px 4px;
  }

  .cmd-item {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    width: 100%;
    text-align: left;
    background: transparent;
    border: 0;
    border-radius: 10px;
    padding: 10px 12px;
    color: var(--ink);
    font-weight: 600;
    cursor: pointer;
  }

  .cmd-item:hover,
  .cmd-item.selected {
    background: var(--accent-soft);
    color: #2563eb;
  }

  .cmd-item small {
    display: block;
    font-weight: 400;
    font-size: 12px;
    color: var(--muted);
  }

  .cmd-item .cmd-tag {
    font-size: 11px;
    font-weight: 700;
    padding: 3px 8px;
    border-radius: 99px;
    background: var(--surface-2);
    border: 1px solid var(--line);
    color: var(--muted);
    white-space: nowrap;
  }

  .cmd-empty {
    padding: 28px 16px;
    text-align: center;
    color: var(--muted);
    font-size: 13.5px;
  }

  /* ========================================================================
     DARK MODE COMPONENT OVERRIDES
     ======================================================================== */
  [data-theme="dark"] .expiry-page {
    background: var(--bg);
  }

  [data-theme="dark"] #language {
    background: var(--surface-2);
    border-color: var(--line);
  }

  [data-theme="dark"] #language button {
    color: var(--muted);
  }

  [data-theme="dark"] #language button[aria-pressed="true"] {
    background: #2563eb;
    color: #ffffff;
  }

  [data-theme="dark"] .user-chip {
    background: var(--surface-2);
    border-color: var(--line);
    color: var(--ink);
  }

  [data-theme="dark"] .staff-stat {
    background: var(--surface);
    border-color: var(--line);
  }

  [data-theme="dark"] .staff-stat strong {
    color: var(--ink);
  }

  [data-theme="dark"] .record-table thead,
  [data-theme="dark"] .record-table thead th,
  [data-theme="dark"] .expiry-table thead th,
  [data-theme="dark"] .invoice-items th {
    background: var(--surface-2);
    color: var(--ink-soft);
    border-bottom-color: var(--line);
  }

  [data-theme="dark"] .record-table tbody tr:nth-child(even),
  [data-theme="dark"] .task-table tr:nth-child(even),
  [data-theme="dark"] .invoice-items tbody tr:nth-child(even) {
    background: rgba(255, 255, 255, 0.02);
  }

  [data-theme="dark"] .record-table tbody tr:hover {
    background: var(--surface-hover);
  }

  [data-theme="dark"] #expiry-workspace .list-panel,
  [data-theme="dark"] .dossier-tabs,
  [data-theme="dark"] .task-deadlines section,
  [data-theme="dark"] .task-synced,
  [data-theme="dark"] .expiry-menu,
  [data-theme="dark"] .expiry-menu button,
  [data-theme="dark"] .expiry-menu-toggle,
  [data-theme="dark"] #dossier-client-results,
  [data-theme="dark"] #dossier-client-results button,
  [data-theme="dark"] .shared-client-options,
  [data-theme="dark"] .shared-client-options button,
  [data-theme="dark"] #remove-agreement,
  [data-theme="dark"] #dossier-editor.portal-editor {
    background: var(--surface);
    border-color: var(--line);
    color: var(--ink);
  }

  [data-theme="dark"] .dossier-tabs button {
    background: var(--surface-2);
    color: var(--ink-soft);
  }

  [data-theme="dark"] .dossier-tabs button[aria-selected="true"] {
    background: #2563eb;
    color: #ffffff;
  }

  [data-theme="dark"] .dossier-portal {
    background: #0f2428;
    border-color: #1f484f;
    border-top-color: #2dd4bf;
  }

  [data-theme="dark"] .dossier-client-picker input,
  [data-theme="dark"] .dossier-client-picker select,
  [data-theme="dark"] .app-date-picker select,
  [data-theme="dark"] .expiry-tools input,
  [data-theme="dark"] .expiry-tools select {
    background: var(--surface-2);
    color: var(--ink);
    border-color: var(--line-strong);
  }

  [data-theme="dark"] #dossier-client-results button:hover,
  [data-theme="dark"] .shared-client-options button:hover {
    background: var(--surface-hover);
  }

  [data-theme="dark"] .shared-client-options .client-picker-add,
  [data-theme="dark"] #dossier-client-results .client-picker-add {
    background: #142642;
    color: #60a5fa;
    border-top-color: var(--line);
  }

  [data-theme="dark"] dialog,
  [data-theme="dark"] #editor,
  [data-theme="dark"] .staff-dialog {
    background: var(--bg);
    color: var(--ink);
    border-color: var(--line);
  }

  [data-theme="dark"] .staff-dialog form,
  [data-theme="dark"] dialog .editor-header,
  [data-theme="dark"] .preview-bar {
    background: var(--surface);
    border-bottom-color: var(--line);
    color: var(--ink);
  }

  [data-theme="dark"] .staff-dialog h2,
  [data-theme="dark"] .staff-dialog label {
    color: var(--ink);
  }

  [data-theme="dark"] .staff-dialog input,
  [data-theme="dark"] .staff-dialog select {
    background: var(--surface-2);
    color: var(--ink);
    border-color: var(--line-strong);
  }

  [data-theme="dark"] .totals div {
    background: var(--surface-2);
  }

  [data-theme="dark"] .totals div:last-child {
    background: #1d4ed8;
    color: #ffffff;
  }

  [data-theme="dark"] .task-group summary {
    background: rgba(59, 130, 246, 0.14);
    color: #93c5fd;
  }

  [data-theme="dark"] .task-group.done summary {
    background: rgba(16, 185, 129, 0.14);
    color: #6ee7b7;
  }

  [data-theme="dark"] .task-group-add {
    background: var(--surface-2);
  }

  [data-theme="dark"] .task-link {
    background: rgba(59, 130, 246, 0.14);
    border-color: rgba(59, 130, 246, 0.28);
    color: #93c5fd;
  }

  [data-theme="dark"] .task-stats .stat-card:nth-child(1) { background: rgba(37, 99, 235, 0.15); color: #93c5fd; }
  [data-theme="dark"] .task-stats .stat-card:nth-child(2) { background: rgba(139, 92, 246, 0.15); color: #c4b5fd; }
  [data-theme="dark"] .task-stats .stat-card:nth-child(3) { background: rgba(239, 68, 68, 0.15); color: #fca5a5; }
  [data-theme="dark"] .task-stats .stat-card:nth-child(4) { background: rgba(22, 163, 74, 0.15); color: #86efac; }

  [data-theme="dark"] .client-dossier-link,
  [data-theme="dark"] .expiry-client-name,
  [data-theme="dark"] .invoice-list-total {
    color: #60a5fa;
  }

  [data-theme="dark"] [data-list-action="edit"],
  [data-theme="dark"] [data-task-action="edit"] {
    background: rgba(59, 130, 246, 0.16);
    color: #93c5fd;
    border-color: rgba(59, 130, 246, 0.3);
  }

  [data-theme="dark"] [data-list-action="preview"] {
    background: rgba(139, 92, 246, 0.16);
    color: #c4b5fd;
    border-color: rgba(139, 92, 246, 0.3);
  }

  [data-theme="dark"] [data-list-action="view"] {
    background: rgba(20, 184, 166, 0.16);
    color: #5eead4;
    border-color: rgba(20, 184, 166, 0.3);
  }

  [data-theme="dark"] .remove,
  [data-theme="dark"] .danger,
  [data-theme="dark"] [data-list-action="remove"],
  [data-theme="dark"] [data-task-action="remove"],
  [data-theme="dark"] .btn-danger {
    background: rgba(239, 68, 68, 0.16);
    color: #fca5a5;
    border-color: rgba(239, 68, 68, 0.32);
  }

  [data-theme="dark"] .home-icon {
    background: rgba(59, 130, 246, 0.18);
    color: #93c5fd;
  }
  [data-theme="dark"] .dashboard-cards [data-page="agreement"] .home-icon { background: rgba(139, 92, 246, 0.18); color: #c4b5fd; }
  [data-theme="dark"] .dashboard-cards [data-page="quotation"] .home-icon { background: rgba(245, 158, 11, 0.18); color: #fcd34d; }
  [data-theme="dark"] .dashboard-cards [data-page="invoice"] .home-icon { background: rgba(16, 185, 129, 0.18); color: #6ee7b7; }
  [data-theme="dark"] .home-icon.red { background: rgba(239, 68, 68, 0.18); color: #fca5a5; }
  [data-theme="dark"] .home-icon.amber { background: rgba(245, 158, 11, 0.18); color: #fcd34d; }
  [data-theme="dark"] .home-icon.purple { background: rgba(139, 92, 246, 0.18); color: #c4b5fd; }

  [data-theme="dark"] #mobile-menu-toggle {
    background: var(--surface-2);
    color: var(--ink);
    border-color: var(--line);
  }

  [data-theme="dark"] .auth-card {
    background: #111c2d;
    color: #f1f5f9;
    border-color: #23334c;
  }
  [data-theme="dark"] .auth-brand h1,
  [data-theme="dark"] .auth-field label {
    color: #f1f5f9;
  }
  [data-theme="dark"] .auth-subtitle,
  [data-theme="dark"] .auth-footer {
    color: #94a3b8;
  }
  [data-theme="dark"] .auth-field input {
    background: #162338;
    border-color: #324766;
    color: #f1f5f9;
  }
  [data-theme="dark"] .auth-submit {
    background: #2563eb;
  }

  @media (max-width: 900px) {
    .cmd-trigger span,
    .cmd-trigger kbd {
      display: none;
    }
    .cmd-trigger {
      padding: 0;
      width: 36px;
      justify-content: center;
    }
  }

  /* ========================================================================
     MOBILE VIEWPORT POLISH (<= 780px) — Zero overflow, crisp header & bottom bar
     ======================================================================== */
  @media (max-width: 780px) {
    html,
    body,
    .workspace {
      max-width: 100%;
      overflow-x: clip;
    }

    .top {
      height: auto;
      min-height: 58px;
      padding: 8px 12px;
      gap: 8px;
      flex-wrap: nowrap;
      align-items: center;
    }

    .top > div:first-of-type {
      display: none;
    }

    #mobile-menu-toggle {
      width: 38px;
      height: 38px;
      flex: 0 0 38px;
      min-height: 38px;
      border-radius: 10px;
      padding: 6px;
    }

    .top-actions {
      flex: 1;
      min-width: 0;
      justify-content: flex-end;
      flex-wrap: nowrap;
      gap: 6px;
      overflow-x: auto;
      scrollbar-width: none;
    }

    .top-actions::-webkit-scrollbar {
      display: none;
    }

    .cmd-trigger,
    .theme-toggle-btn {
      width: 34px;
      height: 34px;
      min-height: 34px;
      flex: none;
    }

    .install-app-btn {
      padding: 5px 9px;
      min-height: 34px;
      font-size: 12px;
      flex: none;
    }

    #language {
      flex: none;
      padding: 2px;
    }

    #language button {
      padding: 4px 7px;
      min-height: 28px;
      font-size: 12px;
    }

    .user-controls {
      margin-left: 0;
      gap: 4px;
      flex: none;
    }

    .user-chip {
      display: none;
    }

    #logout-btn {
      padding: 5px 9px;
      min-height: 34px;
      font-size: 12px;
      white-space: nowrap;
    }

    main {
      padding: 14px 14px calc(88px + env(safe-area-inset-bottom, 0px));
      max-width: 100%;
    }

    .notice {
      width: 100%;
      border-radius: 12px;
      padding: 8px 12px;
      flex-wrap: wrap;
      gap: 4px 8px;
    }

    .page-header {
      margin: 14px 0 14px;
      flex-wrap: wrap;
    }

    .page-header h1 {
      font-size: 22px;
    }

    .home-banner {
      padding: 20px 18px;
      border-radius: 16px;
      margin-bottom: 16px;
    }

    .home-banner h2 {
      font-size: 22px;
    }

    .banner-pulse {
      gap: 6px;
      margin-top: 12px;
    }

    .pulse-pill {
      font-size: 11.5px;
      padding: 4px 9px;
    }

    /* Crisp compact mobile bottom navigation bar */
    body:not(.auth-locked) #mobile-bottom-nav:not([hidden]) {
      position: fixed;
      left: 0;
      right: 0;
      bottom: 0;
      z-index: 400;
      display: grid;
      grid-template-columns: repeat(5, minmax(0, 1fr));
      align-items: center;
      background: rgba(12, 27, 50, 0.96);
      backdrop-filter: blur(12px);
      -webkit-backdrop-filter: blur(12px);
      border-top: 1px solid rgba(255, 255, 255, 0.12);
      padding: 6px 6px calc(8px + env(safe-area-inset-bottom, 0px));
      height: auto;
      box-shadow: 0 -8px 24px rgba(10, 18, 32, 0.28);
    }

    #mobile-bottom-nav .mbn-btn {
      grid-column: auto !important;
      width: 100%;
      min-height: 46px;
      margin: 0;
      padding: 4px 2px;
      border: 0;
      border-radius: 10px;
      background: transparent;
      color: rgba(219, 229, 245, 0.72);
      display: flex;
      flex-direction: column;
      align-items: center;
      justify-content: center;
      gap: 3px;
      font-size: 10.5px;
      font-weight: 600;
      line-height: 1.1;
      text-align: center;
    }

    #mobile-bottom-nav .mbn-icon,
    #mobile-bottom-nav .mbn-label {
      display: flex !important;
      align-items: center;
      justify-content: center;
      width: auto !important;
    }

    #mobile-bottom-nav .mbn-btn.active {
      color: #f3cf80;
      background: rgba(255, 255, 255, 0.1);
    }
  }

  /* ========================================================================
     MODERN INTERACTIVE CALENDAR DATE PICKER
     ======================================================================== */
  .modern-date-wrap {
    position: relative;
    display: flex;
    align-items: center;
    width: 100%;
    min-width: 0;
  }

  .modern-date-input {
    width: 100%;
    min-width: 0;
    padding-right: 60px !important;
    cursor: pointer;
    font-variant-numeric: tabular-nums;
  }

  .modern-date-btn,
  .modern-date-clear {
    position: absolute;
    top: 50%;
    transform: translateY(-50%);
    width: 30px;
    height: 30px;
    min-height: 30px;
    padding: 0;
    border: 0;
    border-radius: 7px;
    background: transparent;
    color: var(--muted);
    display: inline-grid;
    place-items: center;
    cursor: pointer;
  }

  .modern-date-btn {
    right: 6px;
  }

  .modern-date-clear {
    right: 34px;
    font-size: 16px;
    line-height: 1;
  }

  .modern-date-btn:hover,
  .modern-date-clear:hover {
    background: var(--surface-hover);
    color: #2563eb;
  }

  .modern-cal-popover {
    position: fixed;
    z-index: 10050;
    background: var(--surface);
    color: var(--ink);
    border: 1px solid var(--line);
    border-radius: 14px;
    padding: 12px;
    box-shadow: var(--shadow-lg);
    animation: fadeSlideUp 0.14s ease;
  }

  .cal-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 6px;
    margin-bottom: 10px;
  }

  .cal-nav {
    width: 30px;
    height: 30px;
    min-height: 30px;
    padding: 0;
    border-radius: 8px;
    border: 1px solid var(--line);
    background: var(--surface-2);
    color: var(--ink);
    font-size: 16px;
    line-height: 1;
    display: inline-grid;
    place-items: center;
  }

  .cal-nav:hover {
    background: var(--surface-hover);
    border-color: var(--line-strong);
  }

  .cal-selects {
    display: grid;
    grid-template-columns: 1.15fr 0.85fr;
    gap: 6px;
    flex: 1;
    min-width: 0;
  }

  .cal-selects select {
    min-height: 30px;
    height: 30px;
    padding: 2px 6px;
    font-size: 12.5px;
    font-weight: 700;
    border-radius: 8px;
    background: var(--surface-2);
    border-color: var(--line);
  }

  .cal-weekdays {
    display: grid;
    grid-template-columns: repeat(7, 1fr);
    gap: 2px;
    margin-bottom: 4px;
    text-align: center;
    font-size: 11px;
    font-weight: 700;
    color: var(--muted);
  }

  .cal-grid {
    display: grid;
    grid-template-columns: repeat(7, 1fr);
    gap: 3px;
  }

  .cal-day {
    width: 100%;
    aspect-ratio: 1 / 1;
    min-height: 32px;
    padding: 0;
    border: 1px solid transparent;
    border-radius: 8px;
    background: transparent;
    color: var(--ink);
    font-size: 13px;
    font-weight: 600;
    font-variant-numeric: tabular-nums;
    display: inline-grid;
    place-items: center;
  }

  .cal-day:hover:not(:disabled) {
    background: var(--accent-soft);
    color: #2563eb;
  }

  .cal-day.today:not(.selected) {
    border-color: #2563eb;
    color: #2563eb;
  }

  .cal-day.selected {
    background: #102441;
    color: #ffffff;
    box-shadow: 0 2px 8px rgba(16, 36, 65, 0.3);
  }

  [data-theme="dark"] .cal-day.selected {
    background: #2563eb;
  }

  .cal-day:disabled {
    opacity: 0.28;
    cursor: not-allowed;
  }

  .cal-foot {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-top: 10px;
    padding-top: 8px;
    border-top: 1px solid var(--line);
  }

  .cal-foot-btn {
    min-height: 28px;
    padding: 3px 10px;
    border-radius: 7px;
    background: var(--surface-2);
    border: 1px solid var(--line);
    color: var(--ink-soft);
    font-size: 12px;
    font-weight: 600;
  }

  .cal-foot-btn:hover {
    background: var(--surface-hover);
    color: var(--ink);
  }

  /* Unified Quick Client Dialog sizing */
  #quick-client-dialog {
    width: min(820px, calc(100vw - 24px));
    max-height: 92dvh;
    padding: 0;
    border-radius: 16px;
    border: 1px solid var(--line);
    background: var(--bg);
  }

  #quick-client-dialog .unified-section-title {
    margin: 16px 0 10px;
    padding-bottom: 6px;
    border-bottom: 1px solid var(--line);
    font-size: 14px;
    font-weight: 700;
    color: var(--accent);
  }

  #quick-client-dialog .unified-section-title:first-of-type {
    margin-top: 4px;
  }

  /* ========================================================================
     EXECUTIVE UNIFIED SEARCH INPUTS & RICH CLIENT DROPDOWNS
     ======================================================================== */
  .cmd-trigger {
    min-width: 215px;
    justify-content: space-between;
    padding: 6px 10px 6px 12px;
    border-radius: 11px;
    background: var(--surface-2);
    border: 1px solid var(--line);
    box-shadow: inset 0 1px 2px rgba(15, 23, 42, 0.03);
  }

  .cmd-trigger:hover {
    border-color: #93c5fd;
    box-shadow: 0 2px 8px rgba(37, 99, 235, 0.08);
  }

  .cmd-trigger #cmd-trigger-label {
    flex: 1;
    text-align: left;
  }

  input[type="search"].pro-search-input {
    padding-left: 38px !important;
    padding-right: 12px;
    border-radius: 11px;
    border: 1px solid var(--line-strong);
    background-color: var(--surface);
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' viewBox='0 0 24 24' fill='none' stroke='%2364748b' stroke-width='2.1' stroke-linecap='round' stroke-linejoin='round'%3E%3Ccircle cx='11' cy='11' r='8'/%3E%3Cpath d='m21 21-4.3-4.3'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: 12px center;
    background-size: 16px 16px;
    font-size: 13.5px;
    font-weight: 500;
    color: var(--ink);
    box-shadow: var(--shadow-sm);
    transition: border-color 0.16s ease, box-shadow 0.16s ease, background-color 0.16s ease;
  }

  input[type="search"].pro-search-input:hover {
    border-color: #94a3b8;
  }

  input[type="search"].pro-search-input:focus {
    outline: none !important;
    border-color: #2563eb !important;
    box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.16) !important;
  }

  input[type="search"].pro-search-input::-webkit-search-cancel-button {
    -webkit-appearance: none;
    appearance: none;
    width: 18px;
    height: 18px;
    border-radius: 50%;
    cursor: pointer;
    background: #e2e8f0 url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='10' height='10' viewBox='0 0 24 24' fill='none' stroke='%23475569' stroke-width='3' stroke-linecap='round'%3E%3Cpath d='M18 6 6 18M6 6l12 12'/%3E%3C/svg%3E") center / 10px 10px no-repeat;
  }

  input[type="search"].pro-search-input::-webkit-search-cancel-button:hover {
    background-color: #cbd5e1;
  }

  [data-theme="dark"] input[type="search"].pro-search-input::-webkit-search-cancel-button {
    background-color: #334155;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='10' height='10' viewBox='0 0 24 24' fill='none' stroke='%23e2e8f0' stroke-width='3' stroke-linecap='round'%3E%3Cpath d='M18 6 6 18M6 6l12 12'/%3E%3C/svg%3E");
  }

  /* Client Dossier Header Search Bar */
  .dossier-header > .dossier-client-picker {
    flex: 0 0 340px;
  }

  .dossier-client-picker label {
    font-size: 11.5px;
    font-weight: 700;
    letter-spacing: 0.06em;
    text-transform: uppercase;
    color: rgba(219, 234, 254, 0.78);
  }

  #dossier-client-search.pro-search-input {
    background-color: rgba(255, 255, 255, 0.96);
    border-color: rgba(255, 255, 255, 0.25);
    color: #0f172a;
    min-height: 44px;
    font-weight: 600;
    box-shadow: 0 6px 18px rgba(7, 17, 34, 0.22);
  }

  #dossier-client-search.pro-search-input:focus {
    background-color: #ffffff;
    border-color: #d9b66d !important;
    box-shadow: 0 0 0 3px rgba(217, 182, 109, 0.35), 0 8px 20px rgba(7, 17, 34, 0.25) !important;
  }

  [data-theme="dark"] #dossier-client-search.pro-search-input {
    background-color: #162338;
    border-color: rgba(148, 163, 184, 0.28);
    color: #f1f5f9;
  }

  /* Rich Client Dropdown Panel (Dossier + Agreements + Invoices + Tasks + Forms) */
  #dossier-client-results.pro-client-dropdown,
  .shared-client-options.pro-client-dropdown {
    margin-top: 6px;
    border-radius: 14px;
    border: 1px solid var(--line);
    background: var(--surface);
    color: var(--ink);
    box-shadow: 0 18px 42px -10px rgba(15, 23, 42, 0.28), 0 4px 12px -2px rgba(15, 23, 42, 0.08);
    max-height: 340px;
    overflow-y: auto;
    padding: 0;
    z-index: 10060;
  }

  .floating-client-dropdown {
    margin-top: 0 !important;
  }

  #dossier-client-results.pro-client-dropdown {
    min-width: min(370px, calc(100vw - 32px));
    left: auto;
    right: 0;
  }

  .cp-list-head {
    position: sticky;
    top: 0;
    z-index: 2;
    padding: 8px 14px;
    font-size: 11px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    color: var(--muted);
    background: var(--surface-2);
    border-bottom: 1px solid var(--line);
  }

  .pro-client-dropdown button.cp-option {
    display: flex !important;
    align-items: center;
    gap: 10px;
    width: 100%;
    padding: 9px 12px !important;
    border: 0;
    border-bottom: 1px solid var(--line);
    border-radius: 0;
    background: var(--surface);
    color: var(--ink);
    text-align: left;
    cursor: pointer;
    transition: background-color 0.12s ease;
  }

  .pro-client-dropdown button.cp-option:last-of-type {
    border-bottom: 0;
  }

  .pro-client-dropdown button.cp-option:hover,
  .pro-client-dropdown button.cp-option:focus {
    background: var(--surface-hover) !important;
    outline: none;
  }

  .pro-client-dropdown button.cp-option[aria-selected="true"] {
    background: var(--accent-soft) !important;
  }

  .cp-avatar {
    width: 34px;
    height: 34px;
    border-radius: 9px;
    background: linear-gradient(135deg, #e0ecff, #dbeafe);
    color: #1d4ed8;
    font-size: 12px;
    font-weight: 800;
    display: inline-grid;
    place-items: center;
    flex: none;
  }

  [data-theme="dark"] .cp-avatar {
    background: rgba(59, 130, 246, 0.22);
    color: #93c5fd;
  }

  .cp-body {
    flex: 1;
    min-width: 0;
    display: flex;
    flex-direction: column;
    gap: 2px;
  }

  .cp-top {
    display: flex;
    align-items: center;
    gap: 6px;
    min-width: 0;
  }

  .cp-name {
    font-size: 13.5px;
    font-weight: 700;
    color: var(--ink);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }

  .cp-code {
    flex: none;
    font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
    font-size: 10.5px;
    font-weight: 700;
    padding: 1px 6px;
    border-radius: 5px;
    background: var(--surface-2);
    border: 1px solid var(--line);
    color: var(--muted);
  }

  .cp-type {
    flex: none;
    font-size: 10px;
    font-weight: 700;
    padding: 1px 6px;
    border-radius: 99px;
    background: #fdf2f8;
    color: #be185d;
  }

  .cp-sub {
    font-size: 11.5px;
    color: var(--muted);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }

  .cp-check {
    flex: none;
    color: #2563eb;
    font-weight: 800;
    font-size: 14px;
  }

  .cp-empty {
    margin: 0;
    padding: 20px 14px;
    text-align: center;
    font-size: 13px;
    color: var(--muted);
  }

  .pro-client-dropdown button.client-picker-add {
    position: sticky;
    bottom: 0;
    z-index: 2;
    display: flex !important;
    align-items: center;
    justify-content: center;
    gap: 8px;
    width: 100%;
    padding: 11px 14px !important;
    border: 0;
    border-top: 1px solid var(--line);
    background: var(--surface-2) !important;
    color: #2563eb !important;
    font-size: 13px;
    font-weight: 700;
  }

  .pro-client-dropdown button.client-picker-add:hover {
    background: var(--accent-soft) !important;
  }

  .cp-add-ico {
    display: inline-grid;
    place-items: center;
    width: 20px;
    height: 20px;
    border-radius: 50%;
    background: #2563eb;
    color: #ffffff;
    font-size: 14px;
    line-height: 1;
  }

  @media (max-width: 780px) {
    .cmd-trigger {
      min-width: 0;
    }
    .dossier-header > .dossier-client-picker {
      flex: auto;
      width: 100%;
    }
    #dossier-client-results.pro-client-dropdown {
      min-width: 100%;
      left: 0;
      right: 0;
    }
  }

  /* ========================================================================
     UPGRADED CLIENT LIST, EXECUTIVE DOSSIER, SAUDIZATION & ALL POPUP MODALS
     ======================================================================== */
  .saudi-emp-cell {
    display: flex;
    align-items: center;
    gap: 10px;
    min-width: 0;
  }

  .saudi-name-btn {
    border: 0;
    background: transparent;
    padding: 0;
    min-height: 0;
    text-align: left;
    font-size: 14px;
    font-weight: 700;
    color: var(--ink);
    cursor: pointer;
  }

  .saudi-name-btn:hover {
    color: #2563eb;
    text-decoration: underline;
  }

  .saudi-sub {
    display: block;
    font-size: 12px;
    color: var(--muted);
    margin-top: 2px;
  }

  .cl-contact-cell {
    display: flex;
    flex-direction: column;
    gap: 2px;
    font-size: 13px;
  }

  .cl-contact-cell small {
    font-size: 12px;
    color: var(--muted);
  }

  .cl-type-pill {
    display: inline-block;
    padding: 3px 10px;
    border-radius: 99px;
    font-size: 11.5px;
    font-weight: 700;
  }

  .cl-type-main {
    background: #e0f2fe;
    color: #0369a1;
    border: 1px solid #bae6fd;
  }

  .cl-type-khedma {
    background: #fae8ff;
    color: #9333ea;
    border: 1px solid #f0abfc;
  }

  .cp-avatar-khedma {
    background: linear-gradient(135deg, #fae8ff, #f3e8ff) !important;
    color: #9333ea !important;
  }

  .cp-type-main {
    background: #e0f2fe !important;
    color: #0369a1 !important;
  }

  .cl-link-khedma {
    color: #9333ea !important;
  }

  .record-table tbody tr.cl-row-main td:first-child {
    box-shadow: inset 3.5px 0 0 #0284c7;
  }

  .record-table tbody tr.cl-row-khedma {
    background: #fdf4ff !important;
  }

  .record-table tbody tr.cl-row-khedma:hover {
    background: #fae8ff !important;
  }

  .record-table tbody tr.cl-row-khedma td:first-child {
    box-shadow: inset 3.5px 0 0 #a855f7;
  }

  .inv-pill.pill-main.active {
    background: #0369a1;
    border-color: #0369a1;
    color: #ffffff;
  }

  .inv-pill.pill-khedma.active {
    background: #9333ea;
    border-color: #9333ea;
    color: #ffffff;
  }

  .dossier-header.is-khedma {
    background: linear-gradient(125deg, #2b1042 0%, #4a196b 55%, #6b21a8 100%);
    border-left-color: #f0abfc;
  }

  .dos-pill.main {
    background: rgba(14, 165, 233, 0.25);
    border-color: rgba(125, 211, 252, 0.4);
    color: #e0f2fe;
  }

  .dos-pill.khedma {
    background: rgba(217, 70, 239, 0.28);
    border-color: rgba(240, 171, 252, 0.5);
    color: #fae8ff;
  }

  [data-theme="dark"] .cl-type-main {
    background: rgba(14, 165, 233, 0.2);
    color: #7dd3fc;
    border-color: rgba(56, 189, 248, 0.35);
  }

  [data-theme="dark"] .cl-type-khedma {
    background: rgba(192, 38, 211, 0.22);
    color: #f0abfc;
    border-color: rgba(232, 121, 249, 0.35);
  }

  [data-theme="dark"] .cp-avatar-khedma {
    background: rgba(192, 38, 211, 0.24) !important;
    color: #f0abfc !important;
  }

  [data-theme="dark"] .cl-link-khedma {
    color: #e879f9 !important;
  }

  [data-theme="dark"] .record-table tbody tr.cl-row-khedma {
    background: rgba(168, 85, 247, 0.09) !important;
  }

  [data-theme="dark"] .record-table tbody tr.cl-row-khedma:hover {
    background: rgba(168, 85, 247, 0.16) !important;
  }

  /* Executive Client Dossier Hero & Profile Cards */
  .dossier-header {
    padding: 24px 26px;
    border-radius: 18px;
    background: linear-gradient(125deg, #0c1d38 0%, #14305a 55%, #1a4375 100%);
    border: 1px solid rgba(255, 255, 255, 0.1);
    border-left: 4px solid #d9b66d;
    box-shadow: 0 18px 36px -14px rgba(12, 29, 56, 0.45);
  }

  .dos-hero-top {
    display: flex;
    align-items: center;
    gap: 14px;
    margin-top: 8px;
  }

  .dos-avatar {
    width: 52px;
    height: 52px;
    border-radius: 14px;
    background: linear-gradient(135deg, rgba(217, 182, 109, 0.24), rgba(217, 182, 109, 0.1));
    border: 1px solid rgba(217, 182, 109, 0.45);
    color: #f3cf80;
    font-size: 19px;
    font-weight: 800;
    display: inline-grid;
    place-items: center;
    flex: none;
  }

  .dos-hero-title h2 {
    margin: 0;
    font-size: 22px;
    font-weight: 800;
    letter-spacing: -0.02em;
    color: #ffffff;
  }

  .dos-arabic {
    margin: 2px 0 0;
    font-size: 14px;
    color: rgba(219, 234, 254, 0.85);
  }

  .dos-pills {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    margin-top: 7px;
  }

  .dos-pill {
    display: inline-block;
    padding: 2px 9px;
    border-radius: 99px;
    font-size: 11px;
    font-weight: 700;
    background: rgba(255, 255, 255, 0.12);
    border: 1px solid rgba(255, 255, 255, 0.16);
    color: #e2e8f0;
  }

  .dos-pill.code {
    font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
    background: rgba(59, 130, 246, 0.24);
    border-color: rgba(147, 197, 253, 0.35);
    color: #dbeafe;
  }

  .dos-pill.gold {
    background: rgba(217, 182, 109, 0.22);
    border-color: rgba(217, 182, 109, 0.42);
    color: #fde68a;
  }

  .dos-metrics {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    margin-top: 14px;
  }

  .dos-metric {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 5px 11px;
    border-radius: 10px;
    background: rgba(255, 255, 255, 0.08);
    border: 1px solid rgba(255, 255, 255, 0.13);
    font-size: 12.5px;
    color: rgba(226, 232, 240, 0.86);
  }

  .dos-metric strong {
    color: #ffffff;
    font-weight: 700;
    font-variant-numeric: tabular-nums;
  }

  .dos-metric.warn strong {
    color: #fde047;
  }

  .dossier-summary {
    margin-top: 14px;
    padding-top: 12px;
    border-top: 1px solid rgba(255, 255, 255, 0.12);
    gap: 10px 22px;
  }

  .dossier-summary dt {
    font-size: 10.5px;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: rgba(191, 219, 254, 0.72);
  }

  .dossier-summary dd {
    font-size: 13.5px;
    font-weight: 600;
    color: #ffffff;
  }

  .dos-tab-count {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 19px;
    height: 19px;
    padding: 0 5px;
    margin-left: 4px;
    border-radius: 99px;
    font-size: 11px;
    font-weight: 700;
    background: rgba(100, 116, 139, 0.14);
    color: inherit;
    font-variant-numeric: tabular-nums;
  }

  .dossier-tabs button[aria-selected="true"] .dos-tab-count {
    background: rgba(255, 255, 255, 0.22);
    color: #ffffff;
  }

  .pro-details {
    gap: 10px 14px;
  }

  .dos-detail-cell {
    padding: 9px 11px;
    border-radius: 10px;
    background: var(--surface-2);
    border: 1px solid var(--line);
  }

  .dos-detail-cell dt {
    font-size: 11px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    color: var(--muted);
  }

  .dos-detail-cell dd {
    margin: 4px 0 0;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
    font-size: 13.5px;
    font-weight: 600;
    color: var(--ink);
  }

  .dos-copy-btn {
    flex: none;
    width: 26px;
    height: 26px;
    min-height: 26px;
    padding: 0;
    border-radius: 6px;
    background: var(--surface);
    border: 1px solid var(--line);
    color: var(--muted);
    font-size: 13px;
    display: inline-grid;
    place-items: center;
  }

  .dos-copy-btn:hover {
    color: #2563eb;
    border-color: #93c5fd;
    background: var(--accent-soft);
  }

  /* ========================================================================
     UNIVERSAL POLISHED POPUP MODALS & POPOVER ACTION MENUS
     ======================================================================== */
  @keyframes modalPopIn {
    from {
      opacity: 0;
      transform: translateY(10px) scale(0.985);
    }
    to {
      opacity: 1;
      transform: translateY(0) scale(1);
    }
  }

  dialog:not(#preview) {
    border: 1px solid var(--line) !important;
    border-radius: 18px !important;
    background: var(--surface) !important;
    color: var(--ink) !important;
    box-shadow: 0 28px 70px -12px rgba(8, 15, 30, 0.42), 0 8px 24px -6px rgba(8, 15, 30, 0.18) !important;
    overflow: hidden;
  }

  dialog:not(#preview)[open] {
    animation: modalPopIn 0.18s cubic-bezier(0.22, 1, 0.36, 1);
  }

  dialog::backdrop {
    background: rgba(8, 15, 30, 0.58) !important;
    backdrop-filter: blur(5px);
    -webkit-backdrop-filter: blur(5px);
  }

  dialog:not(#preview) .editor-header {
    background: var(--surface-2) !important;
    border-bottom: 1px solid var(--line) !important;
    padding: 15px 20px !important;
  }

  dialog:not(#preview) .editor-header h2 {
    font-size: 17px;
    font-weight: 800;
    letter-spacing: -0.015em;
    color: var(--ink);
  }

  dialog:not(#preview) .dossier-editor-body {
    padding: 18px 20px !important;
    max-height: calc(88dvh - 132px);
    overflow-y: auto;
  }

  dialog:not(#preview) > form > .panel {
    border: 0 !important;
    border-radius: 0 !important;
    box-shadow: none !important;
    padding: 20px 22px !important;
    background: var(--surface) !important;
  }

  dialog:not(#preview) footer.actions {
    margin: 0 !important;
    padding: 13px 20px !important;
    border: 0 !important;
    border-top: 1px solid var(--line) !important;
    border-radius: 0 !important;
    background: var(--surface-2) !important;
    box-shadow: none !important;
    justify-content: flex-end;
  }

  #editor {
    background: var(--bg) !important;
  }

  #editor > #form {
    padding: 16px 20px 0 !important;
    max-height: calc(92dvh - 64px);
    overflow-y: auto;
  }

  #editor > #form > footer.actions {
    margin: 16px -20px 0 !important;
    position: sticky;
    bottom: 0;
  }

  /* Polished Floating Popover Action Menus (Saudization, Documents & Expiry, etc.) */
  .expiry-menu-toggle {
    width: 34px;
    height: 34px;
    min-width: 34px;
    min-height: 34px;
    border-radius: 9px;
    border: 1px solid var(--line);
    background: var(--surface-2);
    color: var(--ink-soft);
    display: inline-grid;
    place-items: center;
    transition: all 0.14s ease;
  }

  .expiry-menu-toggle:hover {
    background: var(--surface-hover);
    border-color: var(--line-strong);
    color: var(--ink);
  }

  .expiry-menu {
    min-width: 190px;
    width: auto;
    padding: 6px !important;
    border-radius: 13px !important;
    border: 1px solid var(--line) !important;
    background: var(--surface) !important;
    box-shadow: 0 18px 40px -10px rgba(15, 23, 42, 0.28), 0 4px 12px -2px rgba(15, 23, 42, 0.08) !important;
  }

  .expiry-menu button {
    display: flex !important;
    align-items: center;
    gap: 8px;
    width: 100%;
    min-height: 36px;
    padding: 7px 11px !important;
    border: 0 !important;
    border-radius: 8px !important;
    background: transparent !important;
    color: var(--ink) !important;
    font-size: 13px !important;
    font-weight: 600 !important;
    text-align: left;
  }

  .expiry-menu button:hover {
    background: var(--surface-hover) !important;
    color: #2563eb !important;
  }

  .expiry-menu button[data-saudi-action="cancel"],
  .expiry-menu button[data-expiry-action="remove"] {
    color: #dc2626 !important;
  }

  .expiry-menu button[data-saudi-action="cancel"]:hover,
  .expiry-menu button[data-expiry-action="remove"]:hover {
    background: rgba(239, 68, 68, 0.12) !important;
  }

  /* ========================================================================
     KHEDMA SERVICES — EXECUTIVE CLIENT-LIST STYLE UI (LIGHT & DARK MODE)
     ======================================================================== */
  .kh-main-panel {
    padding: 18px 20px !important;
  }

  .kh-top-bar {
    display: flex;
    align-items: flex-end;
    justify-content: space-between;
    gap: 14px;
    flex-wrap: wrap;
    margin-bottom: 14px;
  }

  .kh-search-wrap {
    flex: 1 1 280px;
    max-width: 440px;
    display: flex;
    flex-direction: column;
    gap: 6px;
  }

  .kh-search-label {
    font-size: 12.5px;
    font-weight: 700;
    color: var(--ink);
  }

  .kh-top-actions {
    display: flex;
    align-items: center;
    gap: 8px;
    flex-wrap: wrap;
  }

  .kh-plan-select {
    min-width: 140px;
    width: auto !important;
    min-height: 38px;
    padding: 6px 12px;
    border-radius: 10px;
    font-size: 13px;
    font-weight: 600;
  }

  .kh-plan-pill {
    display: inline-flex;
    align-items: center;
    padding: 4px 11px;
    border-radius: 999px;
    font-size: 12px;
    font-weight: 700;
    letter-spacing: 0.01em;
    white-space: nowrap;
  }

  .kh-plan-pill.basic {
    background: #f3e8ff;
    color: #7e22ce;
    border: 1px solid #e9d5ff;
  }

  .kh-plan-pill.standard {
    background: #dbeafe;
    color: #1d4ed8;
    border: 1px solid #bfdbfe;
  }

  .kh-plan-pill.premium {
    background: #fef3c7;
    color: #b45309;
    border: 1px solid #fde68a;
  }

  [data-theme="dark"] .kh-plan-pill.basic {
    background: rgba(168, 85, 247, 0.18);
    color: #d8b4fe;
    border-color: rgba(168, 85, 247, 0.35);
  }

  [data-theme="dark"] .kh-plan-pill.standard {
    background: rgba(59, 130, 246, 0.18);
    color: #93c5fd;
    border-color: rgba(59, 130, 246, 0.35);
  }

  [data-theme="dark"] .kh-plan-pill.premium {
    background: rgba(245, 158, 11, 0.18);
    color: #fcd34d;
    border-color: rgba(245, 158, 11, 0.35);
  }

  .kh-amount-cell {
    display: inline-flex;
    align-items: baseline;
    gap: 3px;
    white-space: nowrap;
    font-variant-numeric: tabular-nums;
  }

  .kh-amount-cell strong {
    font-size: 13.5px;
    color: var(--ink);
  }

  .kh-amount-cell small {
    font-size: 11.5px;
    color: var(--muted);
    font-weight: 600;
  }

  .kh-dates-cell {
    display: flex;
    flex-direction: column;
    gap: 2px;
    font-size: 12.5px;
    color: var(--ink-soft);
    white-space: nowrap;
  }

  .kh-dates-cell small {
    color: var(--muted);
    font-weight: 600;
  }

  .kh-date-overdue strong {
    color: #dc2626;
  }

  .kh-date-soon strong {
    color: #d97706;
  }

  [data-theme="dark"] .kh-date-overdue strong {
    color: #fca5a5;
  }

  [data-theme="dark"] .kh-date-soon strong {
    color: #fcd34d;
  }

  .kh-row-cancelled {
    opacity: 0.65;
  }

  .kh-renew-btn {
    padding: 6px 12px !important;
    font-size: 12.5px !important;
    font-weight: 700 !important;
  }

  .kh-view-top {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
    flex-wrap: wrap;
    margin-bottom: 12px;
  }

  .kh-sub-head {
    margin: 16px 0 8px;
    font-size: 13.5px;
    font-weight: 700;
    color: var(--ink);
  }

  [data-theme="dark"] .notice {
    background: rgba(30, 41, 59, 0.85) !important;
    border-color: #334155 !important;
    color: #cbd5e1 !important;
  }

  /* ========================================================================
     COMPANY FILES VAULT (PDF/JPG) & CLIENT PORTAL LINK MANAGER
     ======================================================================== */
  .dos-portal-share-btn {
    margin-top: 10px;
    width: 100%;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 7px;
    min-height: 38px;
    padding: 8px 14px;
    border-radius: 10px;
    border: 1px solid rgba(255, 255, 255, 0.28);
    background: rgba(255, 255, 255, 0.14);
    color: #ffffff;
    font-size: 13px;
    font-weight: 700;
    cursor: pointer;
    backdrop-filter: blur(6px);
    transition: all 0.16s ease;
  }

  .dos-portal-share-btn:hover {
    background: rgba(255, 255, 255, 0.24);
    border-color: rgba(255, 255, 255, 0.45);
    transform: translateY(-1px);
  }

  .cf-vault-head {
    margin-bottom: 12px;
    align-items: flex-start;
  }

  .cf-count-pill {
    display: inline-flex;
    align-items: center;
    padding: 2px 9px;
    margin-left: 8px;
    border-radius: 999px;
    font-size: 12px;
    font-weight: 700;
    background: #eff6ff;
    color: #1d4ed8;
    vertical-align: middle;
  }

  [data-theme="dark"] .cf-count-pill {
    background: rgba(59, 130, 246, 0.2);
    color: #93c5fd;
  }

  .cf-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(295px, 1fr));
    gap: 14px;
  }

  .cf-card {
    display: flex;
    flex-direction: column;
    gap: 12px;
    padding: 16px !important;
    border-radius: 14px !important;
    border: 1.5px solid var(--line) !important;
    transition: border-color 0.15s ease, box-shadow 0.15s ease, transform 0.15s ease;
  }

  .cf-card.has-file {
    border-color: rgba(22, 163, 74, 0.35) !important;
  }

  .cf-card.drag-over {
    border-color: #2563eb !important;
    box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.22) !important;
    transform: translateY(-2px);
  }

  .cf-card-head {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 10px;
  }

  .cf-card-head h3 {
    margin: 0 0 5px;
    font-size: 15px;
    font-weight: 700;
    color: var(--ink);
  }

  .cf-head-tools {
    display: flex;
    gap: 4px;
    flex: none;
  }

  .cf-mini-btn {
    width: 28px;
    height: 28px;
    min-height: 28px !important;
    padding: 0 !important;
    border-radius: 7px !important;
    border: 1px solid var(--line) !important;
    background: var(--surface-2) !important;
    color: var(--muted) !important;
    font-size: 14px;
    cursor: pointer;
    display: inline-grid;
    place-items: center;
  }

  .cf-mini-btn:hover {
    color: var(--ink) !important;
    border-color: var(--line-strong) !important;
  }

  .cf-mini-btn.danger:hover {
    background: rgba(239, 68, 68, 0.14) !important;
    color: #dc2626 !important;
    border-color: rgba(239, 68, 68, 0.35) !important;
  }

  .cf-status {
    display: inline-block;
    padding: 2px 8px;
    border-radius: 999px;
    font-size: 11px;
    font-weight: 700;
  }

  .cf-status.uploaded {
    background: #dcfce7;
    color: #166534;
  }

  .cf-status.missing {
    background: var(--surface-2);
    color: var(--muted);
  }

  [data-theme="dark"] .cf-status.uploaded {
    background: rgba(34, 197, 94, 0.18);
    color: #86efac;
  }

  .cf-file-meta {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px 12px;
    border-radius: 10px;
    background: var(--surface-2);
    border: 1px solid var(--line);
  }

  .cf-file-icon {
    width: 38px;
    height: 38px;
    border-radius: 9px;
    display: grid;
    place-items: center;
    font-size: 11px;
    font-weight: 800;
    letter-spacing: 0.04em;
    flex: none;
  }

  .cf-file-icon.pdf {
    background: #fee2e2;
    color: #b91c1c;
  }

  .cf-file-icon.img {
    background: #dbeafe;
    color: #1d4ed8;
  }

  [data-theme="dark"] .cf-file-icon.pdf {
    background: rgba(239, 68, 68, 0.2);
    color: #fca5a5;
  }

  [data-theme="dark"] .cf-file-icon.img {
    background: rgba(59, 130, 246, 0.2);
    color: #93c5fd;
  }

  .cf-file-info {
    min-width: 0;
    flex: 1;
  }

  .cf-file-info strong {
    display: block;
    font-size: 13px;
    color: var(--ink);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
  }

  .cf-file-info small {
    display: block;
    font-size: 11.5px;
    color: var(--muted);
    margin-top: 2px;
  }

  .cf-drop-prompt {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 6px;
    padding: 14px 10px;
    border-radius: 10px;
    border: 1.5px dashed var(--line-strong);
    color: var(--muted);
    font-size: 12px;
    text-align: center;
  }

  .cf-card-actions {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    margin-top: auto;
  }

  .cf-card-actions button {
    min-height: 34px !important;
    padding: 5px 11px !important;
    font-size: 12.5px !important;
  }

  .cf-preset-chips {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    margin-top: 12px;
  }

  /* Inline PDF / Image Preview Dialog */
  .cf-preview-dialog {
    width: min(960px, 95vw) !important;
    max-width: 960px !important;
    height: min(88dvh, 840px);
    padding: 0 !important;
    border-radius: 14px !important;
    overflow: hidden;
  }

  .cf-prev-shell {
    display: flex;
    flex-direction: column;
    height: 100%;
    background: var(--surface);
  }

  .cf-prev-bar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    padding: 12px 16px;
    border-bottom: 1px solid var(--line);
    background: var(--surface);
  }

  .cf-prev-bar strong {
    display: block;
    font-size: 15px;
    color: var(--ink);
  }

  .cf-prev-bar small {
    display: block;
    font-size: 12px;
    color: var(--muted);
  }

  .cf-prev-body {
    flex: 1;
    min-height: 0;
    background: #0f172a;
    display: flex;
    align-items: center;
    justify-content: center;
    overflow: auto;
  }

  .cf-prev-pdf {
    width: 100%;
    height: 100%;
    border: 0;
    background: #ffffff;
  }

  .cf-prev-img-wrap {
    padding: 18px;
    display: flex;
    align-items: center;
    justify-content: center;
    width: 100%;
    height: 100%;
    box-sizing: border-box;
  }

  .cf-prev-img-wrap img {
    max-width: 100%;
    max-height: 100%;
    object-fit: contain;
    border-radius: 8px;
    box-shadow: 0 12px 32px rgba(0, 0, 0, 0.45);
  }

  /* Client Portal Link Manager Modal */
  .cp-mgr-dialog {
    max-width: 620px !important;
    width: min(95vw, 620px) !important;
  }

  .cp-pw-gen-row {
    display: flex;
    gap: 6px;
    align-items: center;
  }

  .cp-pw-gen-row input {
    flex: 1;
  }

  .cp-open-link {
    display: inline-flex;
    align-items: center;
    padding: 6px 11px;
    border-radius: 8px;
    border: 1px solid var(--line);
    text-decoration: none;
    font-size: 12.5px;
    font-weight: 600;
    color: var(--ink);
    background: var(--surface);
    white-space: nowrap;
  }

  .cp-sections-grid {
    display: flex;
    flex-direction: column;
    gap: 8px;
  }
}

@media print {
  #workspace-skeleton,
  #command-palette,
  .cmd-trigger,
  .theme-toggle-btn {
    display: none !important;
  }
}
