:root {
  --primary: #1E7B34;
  --primary-hover: #166027;
  --primary-soft: rgba(30, 123, 52, 0.08);
  --leaf: #7CB342;
  --secondary: #F2C811;
  --secondary-soft: rgba(242, 200, 17, 0.16);
  --bg: #F4F8F9;
  --surface: #FFFFFF;
  --surface-alt: #F9FBFC;
  --text: #1F2933;
  --text-secondary: #4B5563;
  --text-muted: #6B7280;
  --border: rgba(31, 41, 51, 0.09);
  --border-strong: rgba(31, 41, 51, 0.16);
  --danger: #B91C1C;
  --danger-soft: #FEF2F2;
  --warning: #B45309;
  --warning-soft: #FFFBEB;
  --success: #15803D;
  --success-soft: #F0FDF4;
  --info: #0369A1;
  --info-soft: #F0F9FF;
  --radius-sm: 8px;
  --radius-md: 12px;
  --radius-lg: 16px;
  --shadow-sm: 0 1px 2px rgba(31, 41, 51, 0.05);
  --shadow-md: 0 8px 24px rgba(31, 41, 51, 0.08);
  --sidebar-w: 244px;
}

*, *::before, *::after { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: 'Cairo', 'Tajawal', 'Segoe UI', Tahoma, sans-serif;
  font-size: 14px;
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
}

a { color: inherit; text-decoration: none; }

.num, td.num, th.num, .tabular {
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}
.ltr-num {
  direction: ltr;
  unicode-bidi: isolate;
  display: inline-block;
  font-variant-numeric: tabular-nums;
}

/* App Shell */
.app-shell {
  display: flex;
  min-height: 100vh;
}

.sidebar {
  width: var(--sidebar-w);
  flex-shrink: 0;
  background: var(--surface);
  border-left: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  position: fixed;
  top: 0;
  right: 0;
  bottom: 0;
  z-index: 40;
  transition: transform 0.2s cubic-bezier(0.2, 0.8, 0.2, 1);
}

.brand-strip {
  height: 4px;
  background: linear-gradient(90deg, var(--primary) 0%, var(--primary) 72%, var(--secondary) 72%, var(--secondary) 100%);
}

.sidebar-header {
  padding: 12px 14px;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.sidebar-brand {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
}

.sidebar-brand img {
  width: 60px;
  height: auto;
  object-fit: contain;
  flex-shrink: 0;
}

.sidebar-brand-title {
  font-size: 14px;
  font-weight: 700;
  color: var(--text);
  line-height: 1.3;
}

.sidebar-brand-sub {
  font-size: 11px;
  color: var(--text-muted);
}

.sidebar-nav {
  flex: 1;
  overflow-y: auto;
  padding: 12px;
}

.nav-section {
  margin-top: 9px;
  margin-bottom: 3px;
  padding: 0 10px;
  font-size: 11px;
  font-weight: 600;
  color: var(--text-muted);
}
.nav-section:first-child { margin-top: 2px; }

.nav-link {
  display: flex;
  align-items: center;
  gap: 9px;
  min-height: 29px;
  padding: 4px 10px;
  border-radius: var(--radius-sm);
  color: var(--text-secondary);
  font-weight: 500;
  font-size: 13px;
  margin-bottom: 1px;
  transition: background-color 0.15s ease, color 0.15s ease;
}
.nav-link:hover {
  background: var(--bg);
  color: var(--text);
}
.nav-link.active {
  background: var(--primary-soft);
  color: var(--primary);
  font-weight: 600;
}
.nav-link svg { flex-shrink: 0; opacity: 0.85; }
.nav-link.active svg { opacity: 1; color: var(--primary); }

.sidebar-footer {
  padding: 12px 16px;
  border-top: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.main-wrap {
  flex: 1;
  margin-right: var(--sidebar-w);
  min-width: 0;
  display: flex;
  flex-direction: column;
  transition: margin-right 0.2s cubic-bezier(0.2, 0.8, 0.2, 1);
}

.sidebar-toggle-btn {
  padding: 0 8px;
  min-height: 34px;
  color: var(--text-secondary);
}
.sidebar-toggle-btn:hover {
  color: var(--primary);
  background: var(--primary-soft);
}

.topbar {
  height: 60px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  padding: 0 24px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
}

.topbar-title-group {
  display: flex;
  align-items: center;
  gap: 12px;
  min-width: 0;
}
.topbar-title {
  margin: 0;
  font-size: 18px;
  font-weight: 600;
  color: var(--text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.topbar-actions {
  display: flex;
  align-items: center;
  gap: 10px;
}

.page-content {
  padding: 24px;
  max-width: 1520px;
  width: 100%;
  margin: 0 auto;
}

/* Cards & Grid */
.card {
  background: var(--surface);
  border: 1px solid rgba(31, 41, 51, 0.08);
  border-radius: 14px;
  box-shadow: 0 2px 10px rgba(15, 23, 42, 0.035);
  min-width: 0;
}

.card-header {
  padding: 15px 20px;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
}
.card-title {
  margin: 0;
  font-size: 15px;
  font-weight: 600;
  color: var(--text);
  display: flex;
  align-items: center;
  gap: 8px;
}
.card-body { padding: 20px; }

.kpi-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(175px, 1fr));
  gap: 14px;
  margin-bottom: 20px;
}

.kpi-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 18px 20px;
  box-shadow: var(--shadow-sm);
  display: flex;
  flex-direction: column;
  gap: 6px;
  position: relative;
}
.kpi-card.accent { border-top: 3px solid var(--primary); }
.kpi-card.gold { border-top: 3px solid var(--secondary); }
.kpi-card.warn { border-top: 3px solid var(--warning); }
.kpi-card.danger { border-top: 3px solid var(--danger); }

.kpi-label { font-size: 12.5px; color: var(--text-muted); font-weight: 500; }
.kpi-value { font-size: 22px; font-weight: 700; color: var(--text); font-variant-numeric: tabular-nums; }
.kpi-meta { font-size: 12px; color: var(--text-secondary); }

.grid-2 { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 20px; }
.grid-3 { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 16px; }
.grid-4 { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 16px; }
.grid-dashboard { display: grid; grid-template-columns: minmax(0, 2fr) minmax(0, 1fr); gap: 20px; }

/* Buttons */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  min-height: 38px;
  padding: 0 15px;
  border-radius: 10px;
  border: 1px solid transparent;
  font-family: inherit;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  transition: background-color 0.16s ease, border-color 0.16s ease, box-shadow 0.16s ease, transform 0.1s ease;
  white-space: nowrap;
}
.btn:active { transform: translateY(1px); }
.btn:focus-visible { outline: 2px solid var(--primary); outline-offset: 2px; }

.btn-primary {
  background: linear-gradient(180deg, #21883A 0%, #1E7B34 100%);
  color: #fff;
  box-shadow: 0 2px 6px rgba(30, 123, 52, 0.24);
}
.btn-primary:hover {
  background: linear-gradient(180deg, #1E7B34 0%, #166027 100%);
  box-shadow: 0 3px 10px rgba(30, 123, 52, 0.3);
}

.btn-secondary {
  background: var(--secondary);
  color: var(--text);
  border-color: rgba(31, 41, 51, 0.14);
  box-shadow: 0 1px 3px rgba(31, 41, 51, 0.08);
}
.btn-secondary:hover { background: #e3bb0c; }

.btn-outline {
  background: var(--surface);
  color: var(--text);
  border-color: #D5DEE6;
  box-shadow: 0 1px 2px rgba(15, 23, 42, 0.04);
}
.btn-outline:hover { background: #F8FAFC; border-color: #BDC8D4; }

.btn-ghost { background: transparent; color: var(--text-secondary); }
.btn-ghost:hover { background: #EEF2F5; color: var(--text); }

.btn-danger {
  background: var(--danger);
  color: #fff;
  box-shadow: 0 2px 6px rgba(185, 28, 28, 0.2);
}
.btn-danger:hover { background: #991b1b; }

.btn-soft-neutral { background: #F8FAFC; color: #334155; border-color: #DCE4EC; }
.btn-soft-neutral:hover { background: #EFF4F8; border-color: #CBD5E1; color: var(--text); }

.btn-soft-amber { background: #FFFBEB; color: #92400E; border-color: #FDE68A; }
.btn-soft-amber:hover { background: #FEF3C7; border-color: #FCD34D; }

.btn-soft-danger { background: #FEF2F2; color: var(--danger); border-color: #FECACA; }
.btn-soft-danger:hover { background: #FEE2E2; border-color: #FCA5A5; }

.btn-soft-primary { background: #ECFDF3; color: #166534; border-color: #B7E4C7; }
.btn-soft-primary:hover { background: #DDFCEB; border-color: #86EFAC; }

.btn-whatsapp { background: #15803D; color: #fff; box-shadow: 0 2px 6px rgba(21, 128, 61, 0.22); }
.btn-whatsapp:hover { background: #166534; }
.btn-soft-whatsapp { background: #ECFDF5; color: #15803D; border-color: #A7F3D0; }
.btn-soft-whatsapp:hover { background: #D1FAE5; }

.btn-sm { min-height: 34px; padding: 0 12px; font-size: 12.5px; border-radius: 9px; }
.btn-xs { min-height: 29px; padding: 0 10px; font-size: 12px; font-weight: 600; border-radius: 8px; }
.btn-pill { border-radius: 999px; }

/* Forms */
.form-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 14px;
}
.form-group { display: flex; flex-direction: column; gap: 5px; }
.form-label { font-size: 12.5px; font-weight: 600; color: var(--text-secondary); }
.form-control {
  min-height: 38px;
  padding: 7px 11px;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  background: var(--surface);
  color: var(--text);
  font-family: inherit;
  font-size: 13.5px;
  width: 100%;
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}
.form-control:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(30, 123, 52, 0.12);
}
textarea.form-control { min-height: 76px; resize: vertical; }

/* Tables */
.table-wrap { overflow-x: auto; width: 100%; }
table.data-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13.5px;
}
.data-table th {
  text-align: right;
  padding: 9px 10px;
  background: var(--surface-alt);
  color: var(--text-secondary);
  font-weight: 600;
  font-size: 12px;
  border-bottom: 1px solid var(--border-strong);
  white-space: nowrap;
}
.data-table th.num { text-align: left; }
.data-table td {
  padding: 9px 10px;
  border-bottom: 1px solid var(--border);
  color: var(--text);
  vertical-align: middle;
}
.data-table td.num { text-align: left; font-weight: 500; }
.data-table tbody tr:hover { background: rgba(30, 123, 52, 0.025); }
.data-table tbody tr:last-child td { border-bottom: none; }

/* Badges & Status Dots */
.badge {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 3px 10px;
  border-radius: 999px;
  font-size: 11.5px;
  font-weight: 600;
  white-space: nowrap;
  border: 1px solid transparent;
}
.badge-dot { width: 6px; height: 6px; border-radius: 50%; background: currentColor; }
.badge-success { background: #ECFDF3; color: #15803D; border-color: #BBF7D0; }
.badge-warning { background: #FFFBEB; color: #B45309; border-color: #FDE68A; }
.badge-danger { background: #FEF2F2; color: #B91C1C; border-color: #FECACA; }
.badge-info { background: #F0F9FF; color: #0369A1; border-color: #BAE6FD; }
.badge-neutral { background: #F8FAFC; color: #475569; border-color: #E2E8F0; }
.badge-gold { background: var(--secondary-soft); color: #7C5800; border-color: #FDE68A; }

/* Segmented Pill Tabs */
.tabs {
  display: inline-flex;
  flex-wrap: wrap;
  gap: 4px;
  padding: 5px;
  background: #E9F0EC;
  border: 1px solid rgba(30, 123, 52, 0.08);
  border-radius: 12px;
  margin-bottom: 18px;
  max-width: 100%;
  overflow-x: auto;
}
.tab-btn {
  padding: 7px 15px;
  border: none;
  border-radius: 9px;
  background: transparent;
  font-family: inherit;
  font-size: 13px;
  font-weight: 600;
  color: var(--text-secondary);
  cursor: pointer;
  white-space: nowrap;
  transition: background-color 0.15s ease, color 0.15s ease, box-shadow 0.15s ease;
}
.tab-btn:hover { color: var(--text); background: rgba(255, 255, 255, 0.55); }
.tab-btn.active {
  background: #FFFFFF;
  color: var(--primary);
  font-weight: 700;
  box-shadow: 0 2px 6px rgba(15, 23, 42, 0.08);
}

/* Alert Banners */
.alert {
  padding: 12px 16px;
  border-radius: var(--radius-sm);
  border: 1px solid transparent;
  display: flex;
  align-items: flex-start;
  gap: 10px;
  margin-bottom: 16px;
  font-size: 13.5px;
}
.alert-warning { background: var(--warning-soft); border-color: #FDE68A; color: #92400E; }
.alert-danger { background: var(--danger-soft); border-color: #FECACA; color: #991B1B; }
.alert-success { background: var(--success-soft); border-color: #BBF7D0; color: #166534; }
.alert-info { background: var(--info-soft); border-color: #BAE6FD; color: #075985; }

/* Modals */
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, 0.45);
  display: none;
  align-items: center;
  justify-content: center;
  padding: 16px;
  z-index: 60;
}
.modal-backdrop.open { display: flex; }
.modal-box {
  background: var(--surface);
  border-radius: var(--radius-lg);
  width: 100%;
  max-width: 640px;
  max-height: 92vh;
  display: flex;
  flex-direction: column;
  box-shadow: var(--shadow-md);
  border: 1px solid var(--border);
}
.modal-box.modal-lg { max-width: 880px; }
.modal-header {
  padding: 16px 20px;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.modal-title { margin: 0; font-size: 16px; font-weight: 700; }
.modal-body { padding: 20px; overflow-y: auto; }
.modal-footer {
  padding: 14px 20px;
  border-top: 1px solid var(--border);
  display: flex;
  justify-content: flex-end;
  gap: 10px;
}

/* Autocomplete Dropdown */
.autocomplete-wrap { position: relative; }
.autocomplete-list {
  position: absolute;
  top: 100%;
  right: 0;
  left: 0;
  background: var(--surface);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  box-shadow: var(--shadow-md);
  max-height: 280px;
  overflow-y: auto;
  z-index: 50;
  display: none;
}
.autocomplete-list.open { display: block; }
.autocomplete-item {
  padding: 9px 12px;
  cursor: pointer;
  border-bottom: 1px solid var(--border);
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
}
.autocomplete-item:hover, .autocomplete-item.focused { background: var(--primary-soft); }

/* Toast */
.toast-container {
  position: fixed;
  bottom: 20px;
  left: 20px;
  z-index: 90;
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.toast {
  background: var(--text);
  color: #fff;
  padding: 11px 16px;
  border-radius: var(--radius-sm);
  font-size: 13.5px;
  font-weight: 500;
  box-shadow: var(--shadow-md);
  display: flex;
  align-items: center;
  gap: 8px;
}
.toast.success { background: var(--primary); }
.toast.error { background: var(--danger); }

.kbd {
  display: inline-block;
  padding: 1px 6px;
  font-size: 11px;
  font-family: monospace;
  background: var(--bg);
  border: 1px solid var(--border-strong);
  border-radius: 4px;
  color: var(--text-secondary);
}

.mobile-only { display: none; }
.print-only { display: none; }
.sidebar-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, 0.45);
  z-index: 35;
}

.sub-items-cell {
  padding: 6px 14px 12px 14px !important;
  background: #FAFDFB;
  border-bottom: 1px solid var(--border-strong) !important;
}
.sub-items-list {
  display: flex;
  flex-direction: column;
  gap: 4px;
  padding: 8px 12px;
  background: #FFFFFF;
  border: 1px solid var(--border);
  border-right: 3px solid var(--primary);
  border-radius: 8px;
}
.sub-item-row {
  display: grid;
  grid-template-columns: 2.2fr 1fr 0.8fr 0.9fr 1fr;
  gap: 10px;
  align-items: center;
  padding: 4px 0;
  font-size: 12.5px;
  border-bottom: 1px dashed rgba(31, 41, 51, 0.08);
}
.sub-item-row:last-child { border-bottom: none; }
.sub-item-head {
  font-size: 11.5px;
  color: var(--text-muted);
  font-weight: 600;
  border-bottom: 1px solid var(--border);
  padding-bottom: 5px;
}
.sub-item-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 14px;
  padding-top: 6px;
  margin-top: 2px;
  border-top: 1px solid var(--border);
  font-size: 12px;
  color: var(--text-secondary);
}
.party-banner {
  background: linear-gradient(135deg, #FFFFFF 0%, #F7FBF8 100%);
  border: 1px solid rgba(30, 123, 52, 0.14);
  border-radius: 14px;
  padding: 20px 24px;
  margin-bottom: 16px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 20px;
  flex-wrap: wrap;
  box-shadow: 0 3px 12px rgba(15, 23, 42, 0.04);
  border-top: 4px solid var(--primary);
}
.party-identity {
  display: flex;
  align-items: center;
  gap: 15px;
  min-width: 0;
}
.party-avatar {
  width: 50px;
  height: 50px;
  border-radius: 14px;
  background: linear-gradient(135deg, #E8F6EC 0%, #D5F0DD 100%);
  border: 1px solid #B7E4C7;
  color: var(--primary);
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  box-shadow: 0 2px 6px rgba(30, 123, 52, 0.1);
}
.meta-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 6px;
}
.meta-chip {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 2px 9px;
  border-radius: 7px;
  background: #F1F5F9;
  border: 1px solid #E2E8F0;
  font-size: 12px;
  color: var(--text-secondary);
}
.party-cluster {
  display: flex;
  align-items: center;
  gap: 14px;
  flex-wrap: wrap;
}
.balance-pill-card {
  padding: 10px 16px;
  border-radius: 12px;
  border: 1px solid #FECACA;
  background: #FFF6F6;
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  min-width: 148px;
}
.balance-pill-card.settled {
  border-color: #BBF7D0;
  background: #F2FCF5;
}
.vr-divider {
  width: 1px;
  height: 42px;
  background: var(--border-strong);
}
.stats-row {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 12px;
  margin-bottom: 16px;
}
.stat-tile {
  background: var(--surface);
  border: 1px solid rgba(31, 41, 51, 0.08);
  border-radius: 13px;
  padding: 14px 16px;
  box-shadow: 0 2px 6px rgba(15, 23, 42, 0.03);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}
.stat-tile-icon {
  width: 36px;
  height: 36px;
  border-radius: 10px;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}
.stat-tile-label { font-size: 12px; color: var(--text-muted); margin-bottom: 2px; }
.stat-tile-val { font-size: 17px; font-weight: 700; color: var(--text); }
.date-pill-group {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
  background: #F8FAFC;
  border: 1px solid #E2E8F0;
  border-radius: 11px;
  padding: 4px 10px 4px 4px;
}
.date-pill-group .form-control {
  min-height: 32px;
  padding: 4px 8px;
  border-radius: 8px;
  background: #fff;
  width: auto;
}
.items-chip {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 2px 9px;
  font-family: inherit;
  font-size: 11.5px;
  font-weight: 600;
  color: #166534;
  background: #ECFDF3;
  border: 1px solid #B7E4C7;
  border-radius: 99px;
  cursor: pointer;
  transition: background-color 0.15s ease, transform 0.1s ease;
}
.items-chip:hover { background: #DDFCEB; }
.ref-tag {
  display: inline-block;
  padding: 3px 10px;
  border-radius: 8px;
  font-size: 12.5px;
  font-weight: 700;
  background: #EEF7F0;
  color: var(--primary);
  border: 1px solid rgba(30, 123, 52, 0.16);
}
.ref-tag:hover { background: #DFF1E4; }
.ref-tag.neutral {
  background: #F8FAFC;
  color: #334155;
  border-color: #E2E8F0;
}
.row-actions {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  flex-wrap: nowrap;
}
.ledger-table tbody td { padding: 13px 14px; }
.period-strip {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  background: #FAFDFB;
  border-bottom: 1px solid var(--border);
}
.period-stat {
  padding: 12px 18px;
  border-left: 1px solid var(--border);
}
.period-stat:last-child { border-left: none; }
.period-stat-label { font-size: 11.5px; color: var(--text-muted); margin-bottom: 2px; }
.period-stat-val { font-size: 16px; font-weight: 700; color: var(--text); }

/* Unified Calm Summary Strip for List Pages */
.kpi-strip {
  background: var(--surface);
  border: 1px solid var(--border);
  border-top: 3px solid var(--primary);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-sm);
  margin-bottom: 16px;
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  overflow: hidden;
}
.kpi-strip.cols-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.kpi-strip.cols-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.kpi-strip-item {
  padding: 14px 18px;
  border-left: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  gap: 3px;
}
.kpi-strip-item:last-child { border-left: none; }
.kpi-strip-label { font-size: 12px; color: var(--text-muted); font-weight: 500; }
.kpi-strip-val { font-size: 20px; font-weight: 700; color: var(--text); line-height: 1.3; }

/* Aligned Single-Row Filter Bar */
.filter-bar {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  align-items: flex-end;
  width: 100%;
}
.filter-field { flex: 1 1 140px; min-width: 130px; display: flex; flex-direction: column; gap: 4px; }
.filter-field.search { flex: 2 1 220px; min-width: 190px; }
.filter-actions { display: flex; gap: 8px; align-items: center; flex-shrink: 0; }
.filter-actions .btn { min-height: 41px; padding: 0 18px; }

/* Quick search + add item row & invoice save grid */
.search-item-row { display: flex; gap: 8px; align-items: center; }
.invoice-action-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }

@media (max-width: 760px) {
  .vr-divider { display: none !important; }
  .stats-row { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
  .period-strip { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
  .kpi-strip { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
  .kpi-strip.cols-3 { grid-template-columns: 1fr; }
  .kpi-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
  .kpi-card { padding: 12px; gap: 3px; }
  .kpi-value { font-size: clamp(14.5px, 4.2vw, 18px); }
  .sub-item-row { grid-template-columns: 1.5fr 1fr 0.8fr 1fr; }
  .sub-item-row .hide-sm { display: none; }
  .shortcuts-hint { display: none !important; }

  /* Compact stat tiles on phones so large amounts & badges never collide */
  .stat-tile { position: relative; padding: 11px 12px; gap: 6px; min-width: 0; align-items: flex-start; }
  .stat-tile > div:first-child { min-width: 0; width: 100%; }
  .stat-tile .stat-label { padding-left: 32px; font-size: 11px; line-height: 1.3; }
  .stat-tile .stat-value { font-size: clamp(14px, 4vw, 17px); line-height: 1.3; }
  .stat-tile .stat-icon { position: absolute; top: 10px; left: 10px; width: 26px; height: 26px; border-radius: 7px; }
  .stat-tile .stat-icon svg { width: 14px; height: 14px; }

  /* Tables: keep headers crisp & prevent wide 6+ col tables collapsing into tall 1-word towers */
  .data-table th { white-space: nowrap; font-size: 11.5px; padding: 9px 8px; }
  .data-table td { padding: 9px 8px; font-size: 12.5px; }
  .table-wrap > .data-table:has(thead tr th:nth-child(6)) { min-width: 620px; }
}

@media (max-width: 640px) {
  .topbar-title { font-size: 15px; }
  .topbar-actions .btn { padding: 6px 10px; font-size: 12.5px; }
  .card-header { padding: 12px 14px; gap: 8px; }
  .card-body { padding: 14px; }
  .card-title { font-size: 14.5px; }

  /* Tabs: clean multi-column pill tray */
  .tabs { width: 100%; display: flex; flex-wrap: wrap; gap: 4px; }
  .tab-link { flex: 1 1 auto; justify-content: center; text-align: center; padding: 8px 10px; font-size: 12.5px; }

  /* Party / Safe banners */
  .party-banner { padding: 14px; gap: 12px; flex-direction: column; align-items: stretch; }
  .party-identity { align-items: flex-start; gap: 10px; }
  .party-avatar { width: 42px; height: 42px; border-radius: 10px; }
  .party-title-lg { font-size: 17px; }
  .party-cluster { width: 100%; flex-wrap: wrap; gap: 8px; }
  .balance-pill-card { flex: 1 0 100%; display: flex; align-items: center; justify-content: space-between; gap: 8px; padding: 10px 14px; text-align: right; }
  .party-cluster > .btn { flex: 1 1 calc(50% - 4px); justify-content: center; }
  .party-cluster > .btn:nth-child(2):last-child { flex-basis: 100%; }
  .party-cluster > div:not(.balance-pill-card):not(.vr-divider) { width: 100%; display: grid !important; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; }
  .party-cluster > div:not(.balance-pill-card):not(.vr-divider) > .btn { width: 100%; justify-content: center; }
  .party-cluster > div:not(.balance-pill-card):not(.vr-divider) > .btn:first-child:nth-last-child(odd) { grid-column: 1 / -1; }

  /* Date filter bar & adjacent export actions */
  .date-pill-group { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; width: 100%; padding: 10px; border-radius: 12px; }
  .date-pill-group > span,
  .date-pill-group > label { display: none; }
  .date-pill-group > select,
  .date-pill-group > input.form-control {
    width: 100% !important; min-width: 0; min-height: 38px;
    background: var(--surface); border: 1px solid var(--border-strong); border-radius: 8px; padding: 6px 10px;
  }
  .date-pill-group > button,
  .date-pill-group > .btn { grid-column: 1 / -1; width: 100%; justify-content: center; min-height: 38px; }
  .date-pill-group + div { width: 100%; display: grid !important; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; }
  .date-pill-group + div > .btn { width: 100%; justify-content: center; }
  .date-pill-group + div > .btn:first-child:nth-last-child(odd) { grid-column: 1 / -1; }

  /* Filter bars across list pages */
  .filter-bar { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; align-items: end; width: 100%; }
  .filter-bar > .fg,
  .filter-bar > .filter-field { min-width: 0 !important; width: 100% !important; flex: none !important; }
  .filter-bar > .filter-field.search,
  .filter-bar > .fg:has(input[type="text"]),
  .filter-bar > .fg:has(input:not([type])),
  .filter-bar:not(:has(input[type="text"])) > .fg:nth-child(odd):last-of-type,
  .filter-bar > label:has(input[type="checkbox"]),
  .filter-bar > .filter-actions { grid-column: 1 / -1; }
  .filter-bar > .filter-actions { display: flex; align-items: center; justify-content: space-between; gap: 10px; flex-wrap: nowrap; }
  .filter-bar > .filter-actions > .btn { flex: 1 1 auto; justify-content: center; }
  .filter-bar > button[type="submit"],
  .filter-bar > a.btn { grid-column: 1 / -1; width: 100%; justify-content: center; }
  .filter-bar .form-control { width: 100% !important; min-width: 0; }

  /* Search + add item row & invoice action buttons */
  .search-item-row { flex-direction: column; align-items: stretch; }
  .search-item-row > .btn { width: 100%; justify-content: center; }
  .invoice-action-grid .btn { white-space: normal; text-align: center; line-height: 1.3; padding: 8px 10px; }

  /* Modals */
  .modal-backdrop { padding: 10px; }
  .modal-box { max-height: 94vh; border-radius: 14px; }
  .modal-header, .modal-body, .modal-footer { padding: 14px 16px; }
  .modal-footer { flex-wrap: wrap; gap: 8px; }
  .modal-footer > .btn { flex: 1 1 auto; justify-content: center; }
}

@media (max-width: 380px) {
  .invoice-action-grid { grid-template-columns: 1fr; }
}

@media (min-width: 961px) {
  body.sidebar-collapsed .sidebar { transform: translateX(100%); }
  body.sidebar-collapsed .main-wrap { margin-right: 0; }
}

@media (max-width: 960px) {
  .sidebar { transform: translateX(100%); }
  .sidebar.open { transform: translateX(0); }
  .sidebar-overlay.open { display: block; }
  .main-wrap { margin-right: 0; }
  .mobile-only { display: inline-flex; }
  .grid-dashboard, .grid-2, .grid-3, .grid-4 { grid-template-columns: 1fr; }
  .page-content { padding: 12px; }
  .topbar { height: auto; min-height: 54px; padding: 8px 12px; flex-wrap: wrap; gap: 8px; }
  .topbar-actions { flex-wrap: wrap; gap: 6px; }
  .btn:not(.btn-xs):not(.btn-sm), .form-control { min-height: 44px; }
  .btn-xs { min-height: 32px; }
  .date-pill-group .form-control { min-height: 36px; }
  .table-wrap { -webkit-overflow-scrolling: touch; max-width: 100%; }
}

@media print {
  @page { size: A4; margin: 10mm; }
  .sidebar, .topbar, .no-print, .tabs { display: none !important; }
  .print-only { display: block !important; }
  .main-wrap { margin-right: 0 !important; }
  .page-content { padding: 0 !important; max-width: 100% !important; }
  body { background: #fff !important; font-size: 12.5px; }
  .card { border: 1px solid #d1d5db !important; box-shadow: none !important; margin-bottom: 12px !important; }
  .table-wrap { overflow: visible !important; }
  tr { break-inside: avoid; }
  .kpi-grid { grid-template-columns: repeat(4, 1fr) !important; gap: 8px !important; margin-bottom: 12px !important; }
  .kpi-card { padding: 10px 12px !important; }
  .kpi-value { font-size: 16px !important; }
}
