/* ============================================================
   HR System — Unified Visual & Responsive Layer
   Loaded after legacy styles to provide one consistent system.
   ============================================================ */

@font-face {
  font-family: "Tajawal Local";
  src: url("../fonts/tajawal/Tajawal-Regular.ttf") format("truetype");
  font-weight: 400;
  font-style: normal;
  font-display: swap;
}
@font-face {
  font-family: "Tajawal Local";
  src: url("../fonts/tajawal/Tajawal-Medium.ttf") format("truetype");
  font-weight: 500;
  font-style: normal;
  font-display: swap;
}
@font-face {
  font-family: "Tajawal Local";
  src: url("../fonts/tajawal/Tajawal-Bold.ttf") format("truetype");
  font-weight: 700;
  font-style: normal;
  font-display: swap;
}
@font-face {
  font-family: "Tajawal Local";
  src: url("../fonts/tajawal/Tajawal-ExtraBold.ttf") format("truetype");
  font-weight: 800;
  font-style: normal;
  font-display: swap;
}

:root {
  --font-sans: "Inter", "Tajawal Local", "Segoe UI", sans-serif;
  --font-ar: "Tajawal Local", "Segoe UI", Tahoma, sans-serif;

  --bg-base: #0a1020;
  --bg-surface: #111a2e;
  --bg-card: #152038;
  --bg-elevated: #1d2a44;
  --bg-soft: #18243c;
  --bg-hover: rgba(148, 163, 184, .08);
  --bg-active: rgba(99, 102, 241, .14);

  --text-primary: #f7f9fc;
  --text-secondary: #c9d3e3;
  --text-muted: #8795ac;
  --border: #273753;
  --border-light: #344764;

  --success: #18b981;
  --success-subtle: rgba(24, 185, 129, .13);
  --warning: #f5a524;
  --warning-subtle: rgba(245, 165, 36, .14);
  --danger: #ef5b72;
  --danger-subtle: rgba(239, 91, 114, .13);
  --info: #3b9df8;
  --info-subtle: rgba(59, 157, 248, .13);
  --purple: #a78bfa;
  --purple-subtle: rgba(167, 139, 250, .13);
  --cyan: #22d3ee;
  --cyan-subtle: rgba(34, 211, 238, .12);
  --orange: #fb923c;
  --orange-subtle: rgba(251, 146, 60, .13);
  --pink: #f472b6;
  --pink-subtle: rgba(244, 114, 182, .13);

  --surface-shadow: 0 10px 30px rgba(1, 7, 20, .16);
  --surface-shadow-lg: 0 20px 55px rgba(1, 7, 20, .24);
  --focus-ring: 0 0 0 4px color-mix(in srgb, var(--primary) 18%, transparent);
  --content-max: 1720px;
  --content-pad: clamp(18px, 2.4vw, 36px);
  --control-height: 44px;
}

[data-theme="light"] {
  --bg-base: #f3f6fa;
  --bg-surface: #ffffff;
  --bg-card: #ffffff;
  --bg-elevated: #f0f4f8;
  --bg-soft: #f7f9fc;
  --bg-hover: rgba(15, 23, 42, .045);
  --bg-active: rgba(99, 102, 241, .09);

  --text-primary: #172033;
  --text-secondary: #46546a;
  --text-muted: #718096;
  --border: #dfe6ef;
  --border-light: #edf1f6;

  --surface-shadow: 0 10px 30px rgba(30, 47, 70, .07);
  --surface-shadow-lg: 0 22px 55px rgba(30, 47, 70, .11);
}

html {
  color-scheme: dark;
  background: var(--bg-base);
}
[data-theme="light"] { color-scheme: light; }

body {
  font-family: var(--font-sans);
  background-color: var(--bg-base);
  background-image:
    radial-gradient(circle at 92% 5%, color-mix(in srgb, var(--primary) 9%, transparent), transparent 28rem),
    radial-gradient(circle at 8% 92%, rgba(34, 211, 238, .045), transparent 25rem);
  background-attachment: fixed;
  color: var(--text-primary);
  font-size: 14px;
  line-height: 1.65;
}
[dir="rtl"] body { font-family: var(--font-ar); }

::selection {
  color: #fff;
  background: color-mix(in srgb, var(--primary) 78%, #000);
}

:focus-visible {
  outline: 2px solid var(--primary);
  outline-offset: 2px;
}

a { text-underline-offset: 3px; }
hr { border-color: var(--border); }

/* App shell */
.app-wrapper { min-width: 0; }
.main-content {
  width: calc(100% - var(--sidebar-width));
  background: transparent;
}
.sidebar.collapsed ~ .main-content {
  width: calc(100% - var(--sidebar-collapsed));
}

.sidebar {
  background:
    linear-gradient(180deg, color-mix(in srgb, var(--bg-surface) 94%, var(--primary) 6%), var(--bg-surface));
  border-inline-end-color: var(--border);
  box-shadow: 14px 0 35px rgba(1, 7, 20, .08);
}
[dir="rtl"] .sidebar { box-shadow: -14px 0 35px rgba(1, 7, 20, .08); }

.sidebar-logo {
  padding-inline: 17px;
  background: color-mix(in srgb, var(--bg-surface) 92%, var(--primary) 8%);
}
.sidebar-logo-icon {
  border: 1px solid rgba(255, 255, 255, .16);
  border-radius: 13px;
  background: linear-gradient(145deg, var(--primary), color-mix(in srgb, var(--primary) 55%, var(--secondary)));
  box-shadow: 0 8px 22px color-mix(in srgb, var(--primary) 28%, transparent);
}
.sidebar-logo-name { font-weight: 800; letter-spacing: -.01em; }
.sidebar-nav { padding-block: 12px; }
.nav-section {
  padding: 14px 18px 6px;
  color: var(--text-muted);
  letter-spacing: .09em;
}
.nav-group-toggle,
.nav-item {
  border: 1px solid transparent;
  border-radius: 11px;
}
.nav-group-toggle:hover,
.nav-item:hover {
  border-color: color-mix(in srgb, var(--border) 72%, transparent);
  background: var(--bg-hover);
}
.nav-item.active {
  border-color: color-mix(in srgb, var(--primary) 24%, transparent);
  background: linear-gradient(90deg, var(--primary-subtle), transparent);
  color: color-mix(in srgb, var(--primary) 62%, #fff);
  font-weight: 700;
}
.sidebar-footer {
  margin: 8px;
  padding: 11px;
  border: 1px solid var(--border);
  border-radius: 14px;
  background: var(--bg-soft);
}
.user-avatar { box-shadow: 0 6px 18px color-mix(in srgb, var(--primary) 22%, transparent); }

/* Top bar */
.topbar {
  min-width: 0;
  padding-inline: clamp(16px, 2vw, 28px);
  background: color-mix(in srgb, var(--bg-surface) 90%, transparent);
  border-bottom-color: var(--border);
  box-shadow: 0 6px 25px rgba(1, 7, 20, .055);
  backdrop-filter: blur(18px) saturate(145%);
}
.topbar-toggle,
.topbar-btn {
  border: 1px solid transparent;
  border-radius: 11px;
}
.topbar-toggle {
  background: var(--bg-elevated);
  border-color: var(--border);
}
.topbar-toggle:hover,
.topbar-btn:hover {
  border-color: var(--border-light);
  background: var(--bg-hover);
  color: var(--text-primary);
}
.topbar-search { max-width: 520px; }
.topbar-search input {
  height: 42px;
  border-color: var(--border);
  background: var(--bg-elevated);
  box-shadow: inset 0 1px rgba(255, 255, 255, .025);
}
.topbar-search input:focus {
  border-color: var(--primary);
  background: var(--bg-card);
  box-shadow: var(--focus-ring);
}
.lang-toggle {
  height: 36px;
  padding-inline: 13px;
  border-radius: 10px;
  background: var(--bg-elevated);
}

/* Content and page headers */
.page-content {
  width: min(100%, var(--content-max));
  margin-inline: auto;
  padding: var(--content-pad);
}
.page-header {
  position: relative;
  align-items: flex-end;
  margin-bottom: 24px;
  padding-bottom: 18px;
  border-bottom: 1px solid var(--border);
}
.page-header::after {
  content: "";
  position: absolute;
  inset-inline-start: 0;
  bottom: -1px;
  width: 58px;
  height: 3px;
  border-radius: 3px;
  background: linear-gradient(90deg, var(--primary), var(--secondary));
}
.page-title {
  font-size: clamp(21px, 2vw, 28px);
  font-weight: 800;
  line-height: 1.25;
  letter-spacing: -.025em;
}
.page-subtitle,
.page-header p {
  max-width: 840px;
  color: var(--text-muted);
  line-height: 1.7;
}
.page-actions { gap: 8px; }

/* Unified surfaces */
.card,
.kpi-card,
.section-card,
.profile-card,
.filter-panel,
[class*="-filter-bar"],
[class*="-stat-card"] {
  border-color: var(--border);
  border-radius: 16px;
  background-color: var(--bg-card);
  box-shadow: var(--surface-shadow);
}
.card {
  transform: none;
  overflow: visible;
}
.card:hover {
  transform: none;
  border-color: color-mix(in srgb, var(--primary) 24%, var(--border));
  box-shadow: var(--surface-shadow);
}
.card:focus-within { z-index: 20; }
.card-header {
  min-height: 60px;
  padding: 16px 20px;
  border-bottom-color: var(--border);
  background: color-mix(in srgb, var(--bg-elevated) 35%, transparent);
}
.card-title {
  font-size: 15px;
  font-weight: 800;
}
.card-title::before {
  width: 4px;
  height: 18px;
  background: linear-gradient(var(--primary), var(--secondary));
}
.card-body { padding: 20px; }
.card-footer {
  padding: 14px 20px;
  border-top-color: var(--border);
  background: var(--bg-soft);
}

.kpi-card {
  border-radius: 16px;
  box-shadow: var(--surface-shadow);
}
.kpi-card:hover {
  transform: translateY(-2px);
  box-shadow: var(--surface-shadow-lg);
}

/* Color rhythm for repeated statistics */
.stats-grid > :nth-child(6n + 1),
.grid-4 > :nth-child(6n + 1) { --stat-accent: var(--info); }
.stats-grid > :nth-child(6n + 2),
.grid-4 > :nth-child(6n + 2) { --stat-accent: var(--success); }
.stats-grid > :nth-child(6n + 3),
.grid-4 > :nth-child(6n + 3) { --stat-accent: var(--purple); }
.stats-grid > :nth-child(6n + 4),
.grid-4 > :nth-child(6n + 4) { --stat-accent: var(--warning); }
.stats-grid > :nth-child(6n + 5),
.grid-4 > :nth-child(6n + 5) { --stat-accent: var(--cyan); }
.stats-grid > :nth-child(6n + 6),
.grid-4 > :nth-child(6n + 6) { --stat-accent: var(--pink); }
.stats-grid > *,
.grid-4 > [class*="card"] {
  border-top: 3px solid var(--stat-accent, var(--primary));
}

/* Buttons */
.btn {
  min-height: 40px;
  height: auto;
  padding: 9px 16px;
  border-radius: 10px;
  font-weight: 700;
  line-height: 1.15;
  box-shadow: none;
}
.btn:hover { transform: translateY(-1px); }
.btn:active { transform: translateY(0) scale(.98); }
.btn-sm {
  min-height: 34px;
  padding: 7px 11px;
  font-size: 12px;
}
.btn-lg {
  min-height: 48px;
  padding: 12px 22px;
}
.btn-primary {
  background: linear-gradient(145deg, var(--primary), var(--primary-hover));
  border-color: var(--primary);
  box-shadow: 0 8px 18px color-mix(in srgb, var(--primary) 20%, transparent);
}
.btn-secondary {
  background: linear-gradient(145deg, var(--secondary), var(--secondary-hover));
}
.btn-warning { color: #211500; }
.btn-outline,
.btn-ghost,
.btn-secondary:is(.btn-outline, .btn-ghost) {
  border-color: var(--border);
  background: var(--bg-elevated);
  color: var(--text-secondary);
}
.btn-icon {
  width: 40px;
  padding: 0;
}

/* Forms */
.form-group { margin-bottom: 18px; }
.form-label,
label.form-label {
  margin-bottom: 7px;
  color: var(--text-secondary);
  font-size: 12px;
  font-weight: 700;
}
.form-control,
.form-select,
input:not([type="checkbox"]):not([type="radio"]):not([type="hidden"]):not([type="file"]),
select,
textarea {
  max-width: 100%;
  border-color: var(--border);
  border-radius: 10px;
  background-color: var(--bg-elevated);
  color: var(--text-primary);
}
.form-control,
.form-select {
  min-height: var(--control-height);
}
input:not([type="checkbox"]):not([type="radio"]):not([type="hidden"]):not([type="file"]),
select {
  min-height: 42px;
}
textarea {
  line-height: 1.65;
}
.form-control:hover,
.form-select:hover,
input:hover,
select:hover,
textarea:hover {
  border-color: var(--border-light);
}
.form-control:focus,
.form-select:focus,
input:focus,
select:focus,
textarea:focus {
  border-color: var(--primary);
  background-color: var(--bg-card);
  box-shadow: var(--focus-ring);
  outline: none;
}
.form-control::placeholder,
input::placeholder,
textarea::placeholder { color: var(--text-muted); opacity: .8; }

input[type="checkbox"],
input[type="radio"] {
  width: 18px;
  height: 18px;
  accent-color: var(--primary);
}
input[type="file"] {
  max-width: 100%;
  padding: 7px;
  border: 1px dashed var(--border);
  border-radius: 10px;
  background: var(--bg-elevated);
}

.form-row { gap: 16px; }
.filter-bar,
[class*="-filter-bar"] {
  gap: 12px;
  padding: 16px;
  border: 1px solid var(--border);
  background: var(--bg-card);
}
.filter-bar .form-control,
.filter-bar .form-select { max-width: 240px; }

/* Search/select libraries */
.ts-control,
.select2-container--default .select2-selection--single,
.select2-container--default .select2-selection--multiple,
.ss-display {
  min-height: var(--control-height) !important;
  border-color: var(--border) !important;
  border-radius: 10px !important;
  background: var(--bg-elevated) !important;
  color: var(--text-primary) !important;
  box-shadow: none !important;
}
.ts-dropdown,
.select2-dropdown,
.ss-dropdown {
  border-color: var(--border) !important;
  border-radius: 12px !important;
  background: var(--bg-card) !important;
  box-shadow: var(--surface-shadow-lg) !important;
}
.ts-dropdown .active,
.select2-results__option--highlighted,
.ss-option:hover {
  background: var(--primary-subtle) !important;
  color: var(--text-primary) !important;
}

/* Tables: consistent, readable, and scroll-safe */
.table-wrapper,
.table-responsive {
  width: 100%;
  border: 1px solid var(--border);
  border-radius: 14px;
  background: var(--bg-card);
  box-shadow: var(--surface-shadow);
  overflow: auto;
  overscroll-behavior-inline: contain;
}
.table,
table.table {
  width: 100%;
  border-collapse: separate;
  border-spacing: 0;
  background: transparent;
}
.table thead th,
table.table thead th {
  position: sticky;
  top: 0;
  z-index: 2;
  padding: 13px 16px;
  border-bottom: 1px solid var(--border);
  background: var(--bg-elevated);
  color: var(--text-muted);
  font-size: 11px;
  font-weight: 800;
  white-space: nowrap;
}
.table tbody td,
table.table tbody td {
  padding: 13px 16px;
  border-bottom: 1px solid var(--border);
  color: var(--text-secondary);
  vertical-align: middle;
}
.table tbody tr:last-child td { border-bottom: 0; }
.table tbody tr:hover td {
  background: var(--bg-hover);
  color: var(--text-primary);
}
.table .actions-cell {
  min-width: max-content;
  flex-wrap: wrap;
}

/* Direct tables inside cards get safe scrolling on smaller screens */
.card > table,
.card > .table { width: 100%; }

/* Badges, alerts, tabs and pagination */
.badge,
[class*="status-badge"] {
  min-height: 24px;
  padding: 5px 9px;
  border: 1px solid transparent;
  border-radius: 999px;
  font-size: 10px;
  font-weight: 800;
  line-height: 1.1;
}
.badge-success { border-color: color-mix(in srgb, var(--success) 24%, transparent); }
.badge-warning { border-color: color-mix(in srgb, var(--warning) 24%, transparent); }
.badge-danger { border-color: color-mix(in srgb, var(--danger) 24%, transparent); }
.badge-info { border-color: color-mix(in srgb, var(--info) 24%, transparent); }
.badge-primary { border-color: color-mix(in srgb, var(--primary) 24%, transparent); }

.alert {
  border: 1px solid var(--border);
  border-inline-start-width: 4px;
  border-radius: 12px;
  box-shadow: none;
}
.tabs {
  gap: 5px;
  padding: 5px;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: var(--bg-card);
  overflow-x: auto;
  flex-wrap: nowrap;
  scrollbar-width: none;
}
.tab-btn {
  flex: 0 0 auto;
  border: 0;
  border-radius: 9px;
}
.tab-btn.active {
  background: var(--primary-subtle);
  color: color-mix(in srgb, var(--primary) 62%, #fff);
}
.pagination {
  gap: 6px;
}
.page-link {
  min-width: 36px;
  min-height: 36px;
  border-color: var(--border);
  border-radius: 9px;
  background: var(--bg-card);
}
.page-link.active {
  background: var(--primary);
  border-color: var(--primary);
  box-shadow: 0 6px 16px color-mix(in srgb, var(--primary) 20%, transparent);
}

/* Modals and overlays */
.modal-overlay,
[id$="Modal"][style*="position:fixed"],
[id$="Modal"][style*="position: fixed"] {
  padding: 20px;
  background: rgba(3, 8, 18, .68) !important;
  backdrop-filter: blur(10px);
}
.modal,
.modal-overlay > div,
[id$="Modal"] > div {
  border-color: var(--border) !important;
  border-radius: 18px;
  background: var(--bg-card) !important;
  box-shadow: var(--surface-shadow-lg);
}
.modal-header,
.modal-footer {
  border-color: var(--border);
  background: var(--bg-soft);
}
.modal-title { font-weight: 800; }
.dropdown-menu {
  border-color: var(--border);
  border-radius: 12px;
  background: var(--bg-card);
  box-shadow: var(--surface-shadow-lg);
}
.toast {
  border-color: var(--border);
  border-radius: 13px;
  background: var(--bg-card);
  box-shadow: var(--surface-shadow-lg);
}

/* Empty states and utility blocks */
.empty-state,
.table-empty,
.kpi-empty {
  border: 1px dashed var(--border);
  border-radius: 14px;
  background: var(--bg-soft);
}
.info-row {
  border-bottom-color: var(--border);
}
.progress,
.progress-bar,
.kpi-progress {
  border-radius: 999px;
  overflow: hidden;
}

/* Employee portal shell */
.portal-container {
  width: min(100%, 760px);
  max-width: 760px;
  margin-inline: auto;
  padding: clamp(16px, 3vw, 28px);
}
.portal-container .p-card {
  margin-bottom: 16px;
  padding: clamp(16px, 2.8vw, 24px);
  border: 1px solid var(--border);
  border-radius: 18px;
  background:
    linear-gradient(145deg, color-mix(in srgb, var(--bg-card) 96%, var(--primary) 4%), var(--bg-card));
  box-shadow: var(--surface-shadow);
}
.portal-container .p-card::before {
  height: 3px;
  opacity: 1;
  background: linear-gradient(90deg, var(--primary), var(--secondary), var(--cyan));
}
.portal-container .p-card h1,
.portal-container .p-card h2,
.portal-container .p-card h3 {
  color: var(--text-primary);
  font-weight: 800;
  line-height: 1.35;
}
.portal-container .p-card p { color: var(--text-secondary); }
.portal-container .btn,
.portal-container button,
.portal-container input,
.portal-container select,
.portal-container textarea { font-family: inherit; }
.portal-container img { max-width: 100%; }
.portal-container [style*="display:grid"],
.portal-container [style*="display: grid"] { min-width: 0; }

/* Legacy inline-layout support */
.page-content [style*="border-radius:20px"],
.page-content [style*="border-radius: 20px"] {
  border-radius: 16px !important;
}
.page-content [style*="background:var(--bg-surface)"],
.page-content [style*="background: var(--bg-surface)"] {
  border-color: var(--border) !important;
}

/* Tablet */
@media (max-width: 1180px) {
  :root { --content-pad: 24px; }
  .grid-4 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .grid-3 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .page-actions { width: 100%; }
}

@media (max-width: 900px) {
  :root { --content-pad: 20px; }

  .grid-2,
  .grid-3,
  .grid-4,
  .grid-auto,
  .premium-grid-2 {
    grid-template-columns: minmax(0, 1fr);
  }

  .page-content [style*="display:grid"][style*="grid-template-columns"]:not(.calendar-grid):not(.annual-calendar):not(.week-grid):not(.kpi-review-row):not(.kpi-review-details__head) {
    grid-template-columns: repeat(2, minmax(0, 1fr)) !important;
  }

  .filter-bar,
  [class*="-filter-bar"] {
    align-items: stretch;
    flex-wrap: wrap;
  }

  .filter-bar > *,
  [class*="-filter-bar"] > * {
    flex: 1 1 190px;
    max-width: none;
  }
}

/* Mobile */
@media (max-width: 768px) {
  :root {
    --content-pad: 14px;
    --topbar-height: 64px;
    --control-height: 46px;
  }

  body {
    font-size: 14px;
    background-image: none;
  }

  .main-content,
  .sidebar.collapsed ~ .main-content {
    width: 100% !important;
    margin-inline-start: 0 !important;
  }

  .sidebar {
    width: min(88vw, 310px) !important;
    max-width: 310px;
    box-shadow: none;
  }
  .sidebar.mobile-open {
    box-shadow: 0 0 0 100vmax rgba(3, 8, 18, .58), var(--surface-shadow-lg) !important;
  }
  .sidebar-nav { padding: 12px 10px; }
  .nav-item,
  .nav-group-toggle {
    min-height: 46px;
    margin-bottom: 4px !important;
    padding: 10px 12px !important;
    border-radius: 10px;
    font-size: 14px !important;
  }
  .nav-icon,
  .nav-group-icon {
    width: 23px;
    height: 23px;
    margin-inline-end: 7px;
  }

  .topbar {
    min-height: var(--topbar-height);
    height: var(--topbar-height);
    padding: max(8px, env(safe-area-inset-top)) 12px 8px;
    gap: 6px;
  }
  .topbar-toggle {
    width: 42px !important;
    height: 42px !important;
    margin-inline-end: 4px !important;
  }
  .topbar-actions { gap: 4px; flex-wrap: nowrap; }
  .topbar-btn {
    width: 38px;
    height: 38px;
  }
  .lang-toggle {
    height: 36px;
    padding-inline: 10px;
  }
  .mobile-topbar-title {
    max-width: 34vw;
    overflow: hidden;
    color: var(--text-primary);
    background: none;
    -webkit-text-fill-color: currentColor;
    white-space: nowrap;
    text-overflow: ellipsis;
  }

  .page-content {
    width: 100%;
    max-width: 100vw;
    padding: 16px 12px 72px;
    overflow-x: clip;
  }
  .page-header {
    align-items: stretch;
    gap: 12px;
    margin-bottom: 18px;
    padding-bottom: 14px;
  }
  .page-title { font-size: 21px; }
  .page-subtitle,
  .page-header p { font-size: 12px; }
  .page-actions {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 8px;
  }
  .page-actions .btn {
    width: 100%;
    min-width: 0;
    min-height: 44px;
    padding-inline: 10px;
    white-space: normal;
  }

  .card-header {
    align-items: flex-start;
    padding: 14px 15px;
  }
  .card-body { padding: 15px; }
  .card-footer { padding: 12px 15px; }

  .grid-2,
  .grid-3,
  .grid-4,
  .grid-auto,
  .form-row,
  .form-row.cols-2,
  .form-row.cols-3,
  .premium-grid-2,
  .stats-grid {
    grid-template-columns: minmax(0, 1fr) !important;
    gap: 12px;
  }

  .page-content [style*="display:grid"][style*="grid-template-columns"]:not(.calendar-grid):not(.annual-calendar):not(.week-grid):not(.kpi-review-row):not(.kpi-review-details__head):not(.kpi-cycle-row) {
    grid-template-columns: minmax(0, 1fr) !important;
  }

  .filter-bar,
  [class*="-filter-bar"],
  .page-content .card > form[style*="display:flex"],
  .page-content .card > form[style*="display: flex"] {
    display: flex !important;
    flex-direction: column !important;
    align-items: stretch !important;
    gap: 10px !important;
    padding: 14px !important;
  }
  .filter-bar > *,
  [class*="-filter-bar"] > *,
  .page-content .card > form[style*="display:flex"] > *,
  .page-content .card > form[style*="display: flex"] > * {
    width: 100% !important;
    min-width: 0 !important;
    max-width: none !important;
    flex: 1 1 auto !important;
  }
  .filter-bar .form-control,
  .filter-bar .form-select { max-width: none; }

  .btn { min-height: 42px; }
  .btn-sm { min-height: 36px; }

  /* Restore semantic tables; horizontal scroll is safer than unlabeled cards. */
  .table-responsive,
  .table-wrapper,
  .card:has(> table),
  .card:has(> .table) {
    max-width: 100%;
    overflow-x: auto !important;
    overflow-y: hidden;
    -webkit-overflow-scrolling: touch;
  }
  .table,
  .table tbody,
  .table thead,
  .table tr,
  .table th,
  .table td {
    display: revert !important;
    width: auto;
    text-align: start !important;
  }
  .table {
    width: 100% !important;
    min-width: 720px !important;
    white-space: nowrap;
  }
  .table thead { display: table-header-group !important; }
  .table tbody { display: table-row-group !important; }
  .table tr {
    display: table-row !important;
    border: 0 !important;
    border-radius: 0 !important;
    box-shadow: none !important;
  }
  .table th,
  .table td {
    display: table-cell !important;
    padding: 12px 13px !important;
    border-bottom: 1px solid var(--border) !important;
  }
  .table td:not(:last-child) { border-bottom: 1px solid var(--border) !important; }
  .table .actions-cell {
    display: flex !important;
    width: max-content;
    min-width: 150px;
  }
  .card > table,
  .card > .table {
    min-width: 720px;
  }
  .page-content table:not(.table) {
    display: block;
    width: 100%;
    max-width: 100%;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
  }

  .tabs {
    margin-inline: -2px;
    padding: 4px;
  }
  .tab-btn {
    min-height: 40px;
    padding: 9px 12px;
    font-size: 12px;
  }
  .pagination {
    justify-content: flex-start;
    overflow-x: auto;
    padding-bottom: 4px;
    flex-wrap: nowrap;
  }
  .page-link { flex: 0 0 auto; }

  .modal-overlay,
  [id$="Modal"][style*="position:fixed"],
  [id$="Modal"][style*="position: fixed"] {
    align-items: flex-end !important;
    padding: 0 !important;
  }
  .modal,
  .modal-overlay > div,
  [id$="Modal"] > div {
    width: 100% !important;
    max-width: 100% !important;
    max-height: min(92dvh, 760px) !important;
    margin: 0 !important;
    border-radius: 20px 20px 0 0 !important;
  }
  .modal-header,
  .modal-body,
  .modal-footer {
    padding-inline: 16px;
  }
  .modal-footer {
    display: grid;
    grid-template-columns: 1fr;
  }
  .modal-footer .btn { width: 100%; }

  .toast-container {
    inset-inline: 10px;
    bottom: 12px;
    width: auto;
    max-width: none;
  }

  .portal-container {
    width: 100%;
    max-width: 100%;
    padding: 14px 11px max(24px, env(safe-area-inset-bottom));
  }
  .portal-container .p-card {
    margin-bottom: 12px;
    padding: 15px;
    border-radius: 15px;
  }
}

@media (max-width: 520px) {
  .page-actions { grid-template-columns: 1fr; }
  .page-title { font-size: 19px; }
  .topbar-actions .topbar-btn:nth-of-type(n + 4) { display: none; }
  .lang-toggle { padding-inline: 8px; }
  .card,
  .kpi-card,
  .section-card,
  [class*="-stat-card"] { border-radius: 13px; }
  .card-header,
  .card-body { padding-inline: 13px; }
  .table { min-width: 650px !important; }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    scroll-behavior: auto !important;
    animation-duration: .01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: .01ms !important;
  }
}

@media print {
  body { background: #fff !important; }
  .sidebar,
  .topbar,
  .no-print,
  .page-actions { display: none !important; }
  .main-content {
    width: 100% !important;
    margin: 0 !important;
  }
  .page-content {
    width: 100% !important;
    max-width: none !important;
    padding: 0 !important;
  }
  .card {
    box-shadow: none !important;
    break-inside: avoid;
  }
}
