/* ============================================================
   Contractor Accounting System — design system
   Font: Dubai (bundled). Direction: RTL.
   ============================================================ */

@font-face { font-family: 'Dubai'; src: url('/fonts/Dubai-Light.ttf') format('truetype'); font-weight: 300; font-display: swap; }
@font-face { font-family: 'Dubai'; src: url('/fonts/Dubai-Regular.ttf') format('truetype'); font-weight: 400; font-display: swap; }
@font-face { font-family: 'Dubai'; src: url('/fonts/Dubai-Medium.ttf') format('truetype'); font-weight: 500; font-display: swap; }
@font-face { font-family: 'Dubai'; src: url('/fonts/Dubai-Bold.ttf') format('truetype'); font-weight: 700; font-display: swap; }

:root {
  --font-family: 'Dubai', Tahoma, system-ui, sans-serif;

  /* Identity */
  --ink: #13274A;
  --ink-2: #1C3561;
  --ink-line: rgba(255, 255, 255, 0.12);
  --on-ink: #FFFFFF;
  --on-ink-muted: rgba(255, 255, 255, 0.68);

  /* Actions */
  --primary: #1F4FA3;
  --primary-hover: #183F86;
  --primary-light: #E9EFFA;
  --primary-border: #C5D3EE;

  /* Neutrals (names kept for existing markup) */
  --slate-50: #F7F8FA;
  --slate-100: #EEF1F5;
  --slate-200: #DDE2EA;
  --slate-300: #C5CCD8;
  --slate-400: #8A95A5;
  --slate-500: #5E6B7D;
  --slate-600: #4A5567;
  --slate-700: #3B4657;
  --slate-800: #1A2230;
  --slate-900: #121926;

  /* Money: credit / debit / info / warning */
  --emerald-50: #EAF5F0;
  --emerald-100: #CFE8DC;
  --emerald-600: #12795A;
  --emerald-700: #0E6249;
  --rose-50: #FBEDEC;
  --rose-100: #F3D3D0;
  --rose-600: #B4372F;
  --rose-700: #962C25;
  --sky-50: #EAF2FA;
  --sky-100: #CFE0F2;
  --sky-600: #2468A8;
  --sky-700: #1C5288;
  --amber-50: #FBF3E4;
  --amber-100: #F2DFB8;
  --amber-600: #A86A12;
  --amber-700: #8A560D;
  --violet-50: #F1EDFA;
  --violet-100: #DDD3F2;
  --violet-700: #5B3E9E;

  --bg-app: #F2F4F7;
  --bg-card: #FFFFFF;
  --overlay: rgba(14, 22, 36, 0.55);

  /* Shape */
  --radius-sm: 8px;
  --radius-md: 12px;
  --radius-lg: 16px;
  --radius-xl: 22px;
  --radius-full: 9999px;

  --shadow-xs: 0 1px 2px rgba(18, 25, 38, 0.05);
  --shadow-sm: 0 1px 3px rgba(18, 25, 38, 0.07), 0 1px 2px rgba(18, 25, 38, 0.04);
  --shadow-lg: 0 16px 32px -12px rgba(18, 25, 38, 0.22);
  --focus-ring: 0 0 0 3px rgba(31, 79, 163, 0.28);

  color-scheme: light;
}

:root[data-theme="dark"] {
  --ink: #0B1830;
  --ink-2: #13284A;
  --ink-line: rgba(255, 255, 255, 0.10);

  --primary: #5B8DE0;
  --primary-hover: #79A3EA;
  --primary-light: #1A2A47;
  --primary-border: #2C4370;

  --slate-50: #1C2738;
  --slate-100: #222E41;
  --slate-200: #2C384B;
  --slate-300: #3A475C;
  --slate-400: #7D899B;
  --slate-500: #98A3B3;
  --slate-600: #B3BCC9;
  --slate-700: #C9D0DA;
  --slate-800: #E3E7ED;
  --slate-900: #F1F3F6;

  --emerald-50: #15302A;
  --emerald-100: #1E4237;
  --emerald-600: #4CC08F;
  --emerald-700: #6FD3A7;
  --rose-50: #3A1F22;
  --rose-100: #4E2A2C;
  --rose-600: #F07468;
  --rose-700: #F59A90;
  --sky-50: #182C42;
  --sky-100: #21405F;
  --sky-600: #6AA9E6;
  --sky-700: #8DBEEE;
  --amber-50: #33280F;
  --amber-100: #4A3A17;
  --amber-600: #E0A54A;
  --amber-700: #EBBC70;
  --violet-50: #2A2240;
  --violet-100: #3A2F58;
  --violet-700: #BBA6EE;

  --bg-app: #0F1622;
  --bg-card: #172131;
  --overlay: rgba(4, 8, 14, 0.7);
  --shadow-xs: 0 1px 2px rgba(0, 0, 0, 0.3);
  --shadow-sm: 0 1px 3px rgba(0, 0, 0, 0.35);
  --shadow-lg: 0 16px 32px -12px rgba(0, 0, 0, 0.6);
  --focus-ring: 0 0 0 3px rgba(91, 141, 224, 0.35);

  color-scheme: dark;
}

/* ---------- Base ---------- */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

body {
  font-family: var(--font-family);
  font-size: 15px;
  background-color: var(--bg-app);
  color: var(--slate-800);
  direction: rtl;
  min-height: 100vh;
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

button, input, select, textarea { font: inherit; color: inherit; }
:focus-visible { outline: none; box-shadow: var(--focus-ring); }

.icon { width: 18px; height: 18px; flex-shrink: 0; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.icon-sm { width: 15px; height: 15px; }
.icon-lg { width: 22px; height: 22px; }

/* ============================================================
   Top navigation: identity band + section bar
   ============================================================ */
.app-header { position: sticky; top: 0; z-index: 100; }

.masthead {
  background: var(--ink);
  background-image: linear-gradient(180deg, var(--ink-2) 0%, var(--ink) 100%);
  color: var(--on-ink);
}

.bar-inner {
  max-width: 1440px;
  margin: 0 auto;
  padding: 0 28px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 20px;
}

.masthead .bar-inner { height: 68px; }

.nav-brand { display: flex; align-items: center; gap: 14px; text-decoration: none; color: inherit; min-width: 0; flex: 1 1 auto; }

.brand-emblem {
  width: 44px;
  height: 44px;
  border-radius: 14px;
  border: 1px solid rgba(255, 255, 255, 0.28);
  background: rgba(255, 255, 255, 0.08);
  display: grid;
  place-items: center;
  flex-shrink: 0;
}
.brand-emblem .icon { width: 24px; height: 24px; stroke-width: 1.6; }

.brand-text { min-width: 0; }
.brand-text h1 { font-size: 18px; font-weight: 700; line-height: 1.25; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.brand-text p { font-size: 12.5px; color: var(--on-ink-muted); line-height: 1.3; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

.masthead-actions { display: flex; align-items: center; gap: 10px; flex-shrink: 0; }

.btn-on-ink {
  background: #FFFFFF;
  color: var(--ink);
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.2);
}
.btn-on-ink:hover { background: #E9EFFA; }
:root[data-theme="dark"] .btn-on-ink { background: var(--primary); color: #fff; }
:root[data-theme="dark"] .btn-on-ink:hover { background: var(--primary-hover); }

.icon-btn-ink {
  width: 40px;
  height: 40px;
  border-radius: var(--radius-full);
  border: 1px solid var(--ink-line);
  background: transparent;
  color: var(--on-ink);
  display: grid;
  place-items: center;
  cursor: pointer;
  transition: background 0.15s;
}
.icon-btn-ink:hover { background: rgba(255, 255, 255, 0.1); }

.masthead-divider { width: 1px; height: 28px; background: var(--ink-line); margin: 0 4px; }

/* User menu */
.user-menu-wrap { position: relative; }

.user-chip {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 4px 6px 4px 12px;
  border-radius: var(--radius-full);
  border: 1px solid var(--ink-line);
  background: rgba(255, 255, 255, 0.04);
  color: var(--on-ink);
  cursor: pointer;
  transition: background 0.15s;
}
.user-chip:hover, .user-chip[aria-expanded="true"] { background: rgba(255, 255, 255, 0.12); }

.avatar {
  width: 34px;
  height: 34px;
  border-radius: 50%;
  background: #DDE7F7;
  color: var(--ink);
  display: grid;
  place-items: center;
  font-size: 13px;
  font-weight: 700;
  flex-shrink: 0;
}
.avatar-lg { width: 44px; height: 44px; font-size: 15px; }

.user-chip-text { text-align: right; line-height: 1.25; }
.user-chip-text strong { display: block; font-size: 13.5px; font-weight: 700; }
.user-chip-text span { display: block; font-size: 11.5px; color: var(--on-ink-muted); }

.user-menu {
  position: absolute;
  top: calc(100% + 10px);
  left: 0;
  width: 260px;
  background: var(--bg-card);
  color: var(--slate-800);
  border: 1px solid var(--slate-200);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg);
  padding: 8px;
  z-index: 200;
  animation: menuIn 0.14s ease-out;
}

@keyframes menuIn { from { opacity: 0; transform: translateY(-4px); } to { opacity: 1; transform: none; } }

.user-menu-head { display: flex; align-items: center; gap: 12px; padding: 10px 10px 12px; border-bottom: 1px solid var(--slate-200); margin-bottom: 6px; }
.user-menu-head strong { display: block; font-size: 14.5px; font-weight: 700; }
.user-menu-head span { display: block; font-size: 12.5px; color: var(--slate-500); direction: ltr; text-align: right; }

.menu-item {
  width: 100%;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 9px 10px;
  border: none;
  background: transparent;
  border-radius: var(--radius-sm);
  font-size: 14px;
  font-weight: 500;
  color: var(--slate-700);
  cursor: pointer;
  text-align: right;
}
.menu-item:hover { background: var(--slate-100); color: var(--slate-900); }
.menu-item.danger { color: var(--rose-600); }
.menu-item.danger:hover { background: var(--rose-50); }
.menu-sep { height: 1px; background: var(--slate-200); margin: 6px 4px; }

/* Section bar */
.section-bar {
  background: var(--bg-card);
  border-bottom: 1px solid var(--slate-200);
  box-shadow: var(--shadow-xs);
}
.section-bar .bar-inner { height: 54px; }

.nav-menu { display: flex; align-items: stretch; gap: 4px; height: 100%; overflow-x: auto; scrollbar-width: none; }
.nav-menu::-webkit-scrollbar { display: none; }

.nav-tab-btn {
  position: relative;
  background: transparent;
  border: none;
  padding: 0 14px;
  font-size: 14.5px;
  font-weight: 500;
  color: var(--slate-500);
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 8px;
  white-space: nowrap;
  transition: color 0.15s;
}
.nav-tab-btn::after {
  content: '';
  position: absolute;
  right: 10px;
  left: 10px;
  bottom: 0;
  height: 3px;
  border-radius: 3px 3px 0 0;
  background: transparent;
  transition: background 0.15s;
}
.nav-tab-btn:hover { color: var(--slate-900); }
.nav-tab-btn.active { color: var(--primary); font-weight: 700; }
.nav-tab-btn.active::after { background: var(--primary); }
.nav-tab-btn:focus-visible { box-shadow: inset var(--focus-ring); border-radius: var(--radius-sm); }

.today-date { font-size: 13px; color: var(--slate-500); white-space: nowrap; display: flex; align-items: center; gap: 6px; }

/* ============================================================
   Buttons — pill shaped
   ============================================================ */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 40px;
  padding: 0 20px;
  border-radius: var(--radius-full);
  font-size: 14px;
  font-weight: 700;
  line-height: 1;
  border: 1px solid transparent;
  cursor: pointer;
  text-decoration: none;
  white-space: nowrap;
  transition: background 0.15s, border-color 0.15s, color 0.15s, box-shadow 0.15s;
  user-select: none;
}
.btn:active { transform: translateY(1px); }
.btn:disabled { opacity: 0.55; cursor: not-allowed; }

.btn-primary { background: var(--primary); color: #fff; box-shadow: 0 1px 2px rgba(31, 79, 163, 0.25); }
.btn-primary:hover { background: var(--primary-hover); }

.btn-secondary { background: var(--bg-card); color: var(--slate-700); border-color: var(--slate-300); }
.btn-secondary:hover { background: var(--slate-50); border-color: var(--slate-400); color: var(--slate-900); }

.btn-success { background: var(--emerald-600); color: #fff; }
.btn-success:hover { background: var(--emerald-700); }
:root[data-theme="dark"] .btn-success, :root[data-theme="dark"] .btn-primary { color: #0F1622; }

.btn-danger { background: var(--rose-50); color: var(--rose-600); border-color: var(--rose-100); }
.btn-danger:hover { background: var(--rose-600); color: #fff; border-color: var(--rose-600); }

.btn-sm { min-height: 34px; padding: 0 14px; font-size: 13px; }
.btn-icon { width: 34px; height: 34px; min-height: 34px; padding: 0; border-radius: 50%; }
.btn-block { width: 100%; }

/* ============================================================
   Page & surfaces
   ============================================================ */
.page-container { max-width: 1440px; margin: 28px auto 64px; padding: 0 28px; }

.card {
  background: var(--bg-card);
  border: 1px solid var(--slate-200);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-xs);
  padding: 24px;
  margin-bottom: 24px;
}

.card-header { display: flex; align-items: center; justify-content: space-between; margin-bottom: 20px; flex-wrap: wrap; gap: 16px; }
.card-title-group { display: flex; align-items: center; gap: 14px; }

.card-icon-badge {
  width: 42px;
  height: 42px;
  border-radius: 12px;
  background: var(--primary-light);
  color: var(--primary);
  display: grid;
  place-items: center;
  flex-shrink: 0;
}

.card-title-group h2 { font-size: 18px; font-weight: 700; color: var(--slate-900); line-height: 1.3; }
.card-title-group p { font-size: 13px; color: var(--slate-500); }

.header-tools { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }

.split-layout { display: grid; grid-template-columns: minmax(300px, 1fr) 2.5fr; gap: 24px; align-items: start; }
.split-layout.even { grid-template-columns: minmax(300px, 1fr) 2fr; }

/* KPI cards */
.stats-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(260px, 1fr)); gap: 18px; margin-bottom: 24px; }

.stat-card {
  background: var(--bg-card);
  border: 1px solid var(--slate-200);
  border-radius: var(--radius-lg);
  padding: 20px 22px;
  box-shadow: var(--shadow-xs);
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
  position: relative;
  overflow: hidden;
}
.stat-card::before { content: ''; position: absolute; top: 0; right: 0; bottom: 0; width: 4px; background: var(--slate-300); }
.stat-card.primary::before { background: var(--primary); }
.stat-card.emerald::before { background: var(--emerald-600); }
.stat-card.rose::before { background: var(--rose-600); }
.stat-card.sky::before { background: var(--sky-600); }
.stat-card.amber::before { background: var(--amber-600); }

.stat-info { min-width: 0; }
.stat-info p { font-size: 13.5px; font-weight: 500; color: var(--slate-500); margin-bottom: 6px; }
.stat-info h3 { font-size: clamp(19px, 1.75vw, 26px); font-weight: 700; color: var(--slate-900); font-variant-numeric: tabular-nums; line-height: 1.25; white-space: nowrap; }
.stat-subtext { font-size: 12.5px; color: var(--slate-400); margin-top: 6px; }

.stat-icon { width: 46px; height: 46px; border-radius: 14px; display: grid; place-items: center; flex-shrink: 0; background: var(--slate-100); color: var(--slate-600); }
.stat-icon .icon { width: 22px; height: 22px; }
.stat-card.primary .stat-icon { background: var(--primary-light); color: var(--primary); }
.stat-card.emerald .stat-icon { background: var(--emerald-50); color: var(--emerald-600); }
.stat-card.rose .stat-icon { background: var(--rose-50); color: var(--rose-600); }
.stat-card.sky .stat-icon { background: var(--sky-50); color: var(--sky-600); }
.stat-card.amber .stat-icon { background: var(--amber-50); color: var(--amber-600); }

/* Settlement ratio */
.ratio-progress-box { background: var(--bg-card); border: 1px solid var(--slate-200); border-radius: var(--radius-lg); padding: 16px 22px; margin-bottom: 24px; }
.ratio-label-row { display: flex; justify-content: space-between; flex-wrap: wrap; gap: 8px; font-size: 14px; font-weight: 500; margin-bottom: 10px; }
.ratio-bar-track { height: 10px; background: var(--rose-100); border-radius: var(--radius-full); overflow: hidden; display: flex; }
.ratio-bar-fill { background: var(--emerald-600); height: 100%; border-radius: var(--radius-full); transition: width 0.5s ease; }

/* Summary strip above the ledger */
.summary-strip { display: flex; flex-wrap: wrap; gap: 8px 28px; font-size: 14px; font-weight: 500; margin-bottom: 16px; background: var(--slate-50); padding: 12px 18px; border-radius: var(--radius-md); border: 1px solid var(--slate-200); }
.summary-strip b { font-weight: 700; }

/* ============================================================
   Tables
   ============================================================ */
.table-container { border: 1px solid var(--slate-200); border-radius: var(--radius-md); overflow: hidden; background: var(--bg-card); }
.table-responsive { overflow-x: auto; -webkit-overflow-scrolling: touch; }

table { width: 100%; border-collapse: collapse; text-align: right; font-size: 14px; }

th {
  background: var(--slate-50);
  color: var(--slate-500);
  font-weight: 500;
  padding: 12px 18px;
  border-bottom: 1px solid var(--slate-200);
  white-space: nowrap;
  font-size: 13px;
}

td { padding: 13px 18px; border-bottom: 1px solid var(--slate-100); color: var(--slate-700); font-variant-numeric: tabular-nums; vertical-align: middle; }
tbody tr:last-child td { border-bottom: none; }
tbody tr { transition: background-color 0.12s ease; }
tbody tr:hover { background-color: var(--slate-50); }
tfoot td { background: var(--slate-100); font-weight: 700; border-top: 1px solid var(--slate-200); }

.empty-row { text-align: center; color: var(--slate-400); padding: 28px !important; }

/* ============================================================
   Badges
   ============================================================ */
.badge { display: inline-flex; align-items: center; gap: 5px; padding: 2px 10px; border-radius: var(--radius-full); font-size: 12.5px; font-weight: 500; line-height: 1.6; white-space: nowrap; border: 1px solid transparent; }

.badge-slate { background: var(--slate-100); color: var(--slate-700); border-color: var(--slate-200); }
.badge-emerald { background: var(--emerald-50); color: var(--emerald-700); border-color: var(--emerald-100); }
.badge-rose { background: var(--rose-50); color: var(--rose-700); border-color: var(--rose-100); }
.badge-sky { background: var(--sky-50); color: var(--sky-700); border-color: var(--sky-100); }
.badge-amber { background: var(--amber-50); color: var(--amber-700); border-color: var(--amber-100); }
.badge-indigo { background: var(--primary-light); color: var(--primary); border-color: var(--primary-border); font-weight: 700; }

.badge-role-employer { background: var(--emerald-50); color: var(--emerald-700); border-color: var(--emerald-100); }
.badge-role-partner { background: var(--amber-50); color: var(--amber-700); border-color: var(--amber-100); }
.badge-role-contractor { background: var(--sky-50); color: var(--sky-700); border-color: var(--sky-100); }
.badge-role-supplier { background: var(--violet-50); color: var(--violet-700); border-color: var(--violet-100); }
.badge-role-worker { background: var(--rose-50); color: var(--rose-700); border-color: var(--rose-100); }
.badge-role-other { background: var(--slate-100); color: var(--slate-600); border-color: var(--slate-200); }

/* Filter pills */
.filter-pills { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 16px; }
.filter-pill { background: var(--bg-card); border: 1px solid var(--slate-300); padding: 6px 16px; border-radius: var(--radius-full); font-size: 13.5px; font-weight: 500; color: var(--slate-600); cursor: pointer; transition: background 0.15s, color 0.15s, border-color 0.15s; }
.filter-pill:hover { background: var(--slate-100); color: var(--slate-900); }
.filter-pill.active { background: var(--primary); color: #fff; border-color: var(--primary); }
:root[data-theme="dark"] .filter-pill.active { color: #0F1622; }

.counter-badge { font-size: 12px; font-weight: 500; color: var(--slate-500); background: var(--bg-card); border: 1px solid var(--slate-200); padding: 3px 10px; border-radius: var(--radius-full); white-space: nowrap; }

/* ============================================================
   Forms
   ============================================================ */
.filter-panel { background: var(--slate-50); border: 1px solid var(--slate-200); border-radius: var(--radius-lg); padding: 18px; margin-bottom: 18px; display: flex; gap: 14px; align-items: flex-end; flex-wrap: wrap; }

.form-field { display: flex; flex-direction: column; flex: 1; min-width: 170px; }
.form-field.wide { flex: 2; min-width: 220px; }
.form-field + .form-field { margin-top: 0; }
.form-stack .form-field { margin-bottom: 14px; }
.form-field label { font-size: 13px; font-weight: 500; color: var(--slate-600); margin-bottom: 6px; }
.form-hint { font-size: 12px; color: var(--slate-400); margin-top: 4px; }

.input-control, .select-control {
  font-size: 14px;
  min-height: 42px;
  padding: 8px 14px;
  border: 1px solid var(--slate-300);
  border-radius: var(--radius-md);
  background: var(--bg-card);
  color: var(--slate-800);
  outline: none;
  transition: border-color 0.15s, box-shadow 0.15s;
  width: 100%;
}
.input-control:focus, .select-control:focus { border-color: var(--primary); box-shadow: var(--focus-ring); }
.input-control::placeholder { color: var(--slate-400); }
.input-ltr { direction: ltr; text-align: left; }

.amount-preview { font-size: 12.5px; font-weight: 700; margin-top: 4px; }

/* ============================================================
   Modals
   ============================================================ */
.modal-overlay { position: fixed; inset: 0; background: var(--overlay); backdrop-filter: blur(6px); -webkit-backdrop-filter: blur(6px); display: flex; align-items: center; justify-content: center; z-index: 1000; padding: 20px; }

.modal-box { background: var(--bg-card); border-radius: var(--radius-xl); max-width: 680px; width: 100%; max-height: 90vh; overflow-y: auto; box-shadow: var(--shadow-lg); border: 1px solid var(--slate-200); animation: modalEnter 0.22s cubic-bezier(0.16, 1, 0.3, 1); }
.modal-box.narrow { max-width: 440px; }

@keyframes modalEnter { from { transform: translateY(14px) scale(0.98); opacity: 0; } to { transform: none; opacity: 1; } }

.modal-header-bar { display: flex; align-items: center; justify-content: space-between; padding: 18px 24px; border-bottom: 1px solid var(--slate-200); }
.modal-header-bar h3 { font-size: 18px; font-weight: 700; color: var(--slate-900); }

.modal-close-btn { width: 36px; height: 36px; border-radius: 50%; border: none; background: transparent; color: var(--slate-400); cursor: pointer; display: grid; place-items: center; transition: background 0.15s, color 0.15s; }
.modal-close-btn:hover { color: var(--slate-800); background: var(--slate-100); }

.modal-body { padding: 22px 24px; }
.modal-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 14px; }
.modal-grid .full { grid-column: 1 / -1; }

.modal-footer { display: flex; justify-content: flex-end; gap: 10px; padding: 16px 24px; border-top: 1px solid var(--slate-200); background: var(--slate-50); border-radius: 0 0 var(--radius-xl) var(--radius-xl); }

/* ============================================================
   Toasts
   ============================================================ */
#toast-container { position: fixed; bottom: 24px; left: 24px; z-index: 9999; display: flex; flex-direction: column; gap: 10px; }

.toast-item { background: var(--bg-card); color: var(--slate-800); border: 1px solid var(--slate-200); border-radius: var(--radius-full); padding: 10px 18px 10px 20px; box-shadow: var(--shadow-lg); font-size: 14px; font-weight: 500; display: flex; align-items: center; gap: 10px; min-width: 280px; animation: toastSlideIn 0.3s cubic-bezier(0.16, 1, 0.3, 1); transition: opacity 0.3s, transform 0.3s; }
.toast-item .icon { color: var(--primary); }
.toast-item.success .icon { color: var(--emerald-600); }
.toast-item.error .icon { color: var(--rose-600); }

@keyframes toastSlideIn { from { transform: translateX(-24px); opacity: 0; } to { transform: none; opacity: 1; } }

/* ============================================================
   Sign-in page
   ============================================================ */
.auth-page { min-height: 100vh; display: grid; grid-template-columns: minmax(360px, 5fr) 7fr; }

.auth-identity {
  background: var(--ink);
  background-image: linear-gradient(160deg, var(--ink-2) 0%, var(--ink) 70%);
  color: var(--on-ink);
  padding: 48px;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  position: relative;
  overflow: hidden;
}

/* faint ledger lines: a nod to the paper journal this system replaces */
.auth-identity::after {
  content: '';
  position: absolute;
  inset: 0;
  background-image: repeating-linear-gradient(180deg, transparent 0 39px, rgba(255, 255, 255, 0.05) 39px 40px);
  pointer-events: none;
}

.auth-identity > * { position: relative; z-index: 1; }
.auth-identity h2 { font-size: 34px; font-weight: 700; line-height: 1.35; margin: 28px 0 12px; max-width: 14em; text-wrap: balance; }
.auth-identity p { color: var(--on-ink-muted); font-size: 15.5px; max-width: 30em; }
.auth-foot { font-size: 13px; color: var(--on-ink-muted); }

.auth-form-side { display: flex; align-items: center; justify-content: center; padding: 40px 24px; background: var(--bg-app); }

.auth-card { width: 100%; max-width: 420px; background: var(--bg-card); border: 1px solid var(--slate-200); border-radius: var(--radius-xl); box-shadow: var(--shadow-sm); padding: 34px 32px; }
.auth-card h3 { font-size: 22px; font-weight: 700; color: var(--slate-900); }
.auth-card .lead { font-size: 14px; color: var(--slate-500); margin: 4px 0 24px; }

.auth-error { display: flex; gap: 8px; align-items: flex-start; background: var(--rose-50); color: var(--rose-700); border: 1px solid var(--rose-100); border-radius: var(--radius-md); padding: 10px 14px; font-size: 13.5px; margin-bottom: 16px; }


/* ============================================================
   Table toolbar: add button (start/right), search, filters (end/left)
   ============================================================ */
.table-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
  padding: 12px 14px;
  background: var(--slate-50);
  border: 1px solid var(--slate-200);
  border-bottom: none;
  border-radius: var(--radius-md) var(--radius-md) 0 0;
}
.table-toolbar + .table-container, .table-toolbar + .filter-panel + .table-container { border-radius: 0 0 var(--radius-md) var(--radius-md); }
.table-toolbar + .filter-panel { border-radius: 0; margin-bottom: 0; border-bottom: none; background: var(--bg-card); }

.toolbar-main { display: flex; align-items: center; gap: 10px; flex: 1 1 320px; min-width: 0; }
.toolbar-filters { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }

.search-box { position: relative; flex: 1; max-width: 380px; min-width: 180px; }
.search-box .icon { position: absolute; right: 13px; top: 50%; transform: translateY(-50%); color: var(--slate-400); pointer-events: none; width: 16px; height: 16px; }
.search-box input {
  width: 100%;
  min-height: 36px;
  padding: 6px 38px 6px 14px;
  border: 1px solid var(--slate-300);
  border-radius: var(--radius-full);
  background: var(--bg-card);
  font-size: 13.5px;
  color: var(--slate-800);
  outline: none;
  transition: border-color 0.15s, box-shadow 0.15s;
}
.search-box input:focus { border-color: var(--primary); box-shadow: var(--focus-ring); }
.search-box input::placeholder { color: var(--slate-400); }
.search-box input::-webkit-search-cancel-button { cursor: pointer; }

.select-sm {
  min-height: 36px;
  width: auto;
  min-width: 140px;
  max-width: 220px;
  padding: 4px 12px;
  font-size: 13.5px;
  border-radius: var(--radius-full);
}

.table-empty { padding: 28px; text-align: center; color: var(--slate-400); font-size: 14px; border-top: 1px solid var(--slate-100); }

/* Mixed-direction values (document codes, usernames) */
.ltr { direction: ltr; unicode-bidi: isolate; }

/* Hide write actions for read-only users and admin-only areas for others */
body.role-viewer .can-write { display: none !important; }
body:not(.role-admin) .admin-only { display: none !important; }

.row-actions { display: flex; gap: 6px; justify-content: center; flex-wrap: nowrap; }

.user-cell { display: flex; align-items: center; gap: 10px; }
.user-cell .avatar { width: 34px; height: 34px; font-size: 12px; background: var(--primary-light); color: var(--primary); }
.user-cell small { display: block; color: var(--slate-500); font-size: 12.5px; }
.you-tag { font-size: 11.5px; color: var(--slate-500); font-weight: 500; margin-inline-start: 4px; }

/* Role descriptions */
.role-list { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 14px; }
.role-item { border: 1px solid var(--slate-200); border-radius: var(--radius-md); padding: 14px 16px; background: var(--slate-50); }
.role-item h4 { font-size: 15px; font-weight: 700; color: var(--slate-900); margin-bottom: 4px; display: flex; align-items: center; gap: 8px; }
.role-item p { font-size: 13.5px; color: var(--slate-500); }

/* Choice cards (radio) */
.choice-group { display: grid; gap: 10px; }
.choice {
  display: flex;
  gap: 10px;
  align-items: flex-start;
  padding: 12px 14px;
  border: 1px solid var(--slate-300);
  border-radius: var(--radius-md);
  cursor: pointer;
  transition: border-color 0.15s, background 0.15s;
}
.choice:has(input:checked) { border-color: var(--primary); background: var(--primary-light); }
.choice input { margin-top: 5px; accent-color: var(--primary); }
.choice strong { display: block; font-size: 14px; font-weight: 700; color: var(--slate-800); }
.choice span { display: block; font-size: 12.5px; color: var(--slate-500); }

/* Copyable link box */
.link-box { display: flex; gap: 8px; align-items: stretch; }
.link-box input { flex: 1; font-size: 12.5px; }
.notice { display: flex; gap: 10px; align-items: flex-start; background: var(--sky-50); color: var(--sky-700); border: 1px solid var(--sky-100); border-radius: var(--radius-md); padding: 12px 14px; font-size: 13.5px; margin-bottom: 16px; }
.notice .icon { margin-top: 2px; }

@media (max-width: 760px) {
  .toolbar-main { flex-basis: 100%; }
  .search-box { max-width: none; }
  .toolbar-filters { width: 100%; }
  .toolbar-filters .select-sm { flex: 1; max-width: none; }
  .link-box { flex-direction: column; }
}

/* ============================================================
   Utilities
   ============================================================ */
.text-emerald { color: var(--emerald-600) !important; font-weight: 700; }
.text-rose { color: var(--rose-600) !important; font-weight: 700; }
.text-sky { color: var(--sky-600) !important; font-weight: 700; }
.text-amber { color: var(--amber-600) !important; font-weight: 700; }
.text-muted { color: var(--slate-500) !important; }
.hidden { display: none !important; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

/* ============================================================
   Responsive
   ============================================================ */
@media (max-width: 1100px) {
  .split-layout, .split-layout.even { grid-template-columns: 1fr; }
  .today-date { display: none; }
}

@media (max-width: 760px) {
  .bar-inner { padding: 0 16px; }
  .page-container { padding: 0 16px; margin-top: 18px; }
  .brand-text p, .user-chip-text, .masthead-divider { display: none; }
  .user-chip { padding: 3px; }
  .btn-new-doc span { display: none; }
  .btn-new-doc { width: 40px; padding: 0; }
  .brand-text h1 { font-size: 15px; }
  .masthead-actions { gap: 8px; }
  .brand-emblem { width: 38px; height: 38px; border-radius: 12px; }
  .card { padding: 18px; }
  .auth-page { grid-template-columns: 1fr; }
  .auth-identity { padding: 28px 22px; }
  .auth-identity h2 { font-size: 24px; margin-top: 18px; }
  .auth-identity .auth-foot { display: none; }
  #toast-container { left: 16px; right: 16px; }
  .toast-item { min-width: 0; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: 0.01ms !important; transition-duration: 0.01ms !important; }
}

/* Amounts never wrap inside table cells */
td.text-rose, td.text-emerald, td.text-sky, td.text-amber, td[style*="color"] { white-space: nowrap; }
