/* TIBaOne CRM v2 visual layer. Presentation only, loaded after legacy styles. */
:root {
  --primary: #5d51d4;
  --primary-hover: #4e42bb;
  --primary-soft: #eeecfc;
  --primary-text: #5043b7;
  --bg: #f6f7fb;
  --canvas: #f6f7fb;
  --surface: #ffffff;
  --surface-2: #fafbfe;
  --panel: #ffffff;
  --panel-soft: #fafbfe;
  --surface2: #fafbfe;
  --ink: #24283d;
  --ink-strong: #24283d;
  --ink2: #42495f;
  --muted: #66718a;
  --line: #e9ecf3;
  --line-strong: #dce1ec;
  --green: #16765b;
  --green-soft: #e9f6ef;
  --orange: #986006;
  --orange-soft: #fff4df;
  --blue: #386ec4;
  --blue-soft: #edf3ff;
  --red: #bd3f56;
  --red-soft: #fff0f2;
  --brand: var(--primary);
  --brand-dark: var(--primary-hover);
  --brand-soft: var(--primary-soft);
  --brand-ink: #ffffff;
  --accent: var(--primary);
  --accent-dark: var(--primary-hover);
  --accent-soft: var(--primary-soft);
  --link: var(--primary-text);
  --link-hover: var(--primary-hover);
  --active-bg: var(--primary-soft);
  --active-ink: var(--primary-text);
  --hover-surface: var(--surface-2);
  --signal: var(--primary);
  --signal-soft: var(--primary-soft);
  --success: var(--green);
  --success-soft: var(--green-soft);
  --pos: var(--green);
  --danger: var(--red);
  --danger-soft: var(--red-soft);
  --neg: var(--red);
  --warning: var(--orange);
  --warning-soft: var(--orange-soft);
  --nav: var(--surface);
  --nav-soft: var(--surface-2);
  --nav-ink: var(--ink);
  --nav-muted: var(--muted);
  --focus: #8a7de9;
  --radius: 14px;
  --radius-small: 8px;
  --shadow: 0 3px 4px rgba(23, 32, 61, .01), 0 12px 48px rgba(38, 35, 64, .035);
  --shadow-hover: 0 8px 28px rgba(38, 35, 64, .10);
  --sidebar-width: 230px;
  color-scheme: light;
}

[data-theme="dark"] {
  --bg: #171a27;
  --canvas: #171a27;
  --surface: #212535;
  --surface-2: #252a3c;
  --panel: #212535;
  --panel-soft: #252a3c;
  --surface2: #252a3c;
  --ink: #e5e8f2;
  --ink-strong: #f4f5fa;
  --ink2: #d3d8e7;
  --muted: #a2abc1;
  --line: #343a50;
  --line-strong: #47506b;
  --primary: #8f82f2;
  --primary-hover: #a99fff;
  --primary-soft: #363052;
  --primary-text: #c0b4ff;
  --brand: var(--primary);
  --brand-dark: var(--primary-hover);
  --brand-soft: var(--primary-soft);
  --accent: var(--primary);
  --accent-dark: var(--primary-hover);
  --accent-soft: var(--primary-soft);
  --link: #c0b4ff;
  --link-hover: #ded9ff;
  --active-bg: #363052;
  --active-ink: #d5ceff;
  --green: #8fd7ba;
  --green-soft: #233e3a;
  --orange: #edc280;
  --orange-soft: #433a2b;
  --blue: #a4c2f5;
  --blue-soft: #29394f;
  --red: #fca1b1;
  --red-soft: #49313e;
  --success: var(--green);
  --success-soft: var(--green-soft);
  --danger: var(--red);
  --danger-soft: var(--red-soft);
  --warning: var(--orange);
  --warning-soft: var(--orange-soft);
  --nav: var(--surface);
  --nav-soft: var(--surface-2);
  --nav-ink: var(--ink);
  --nav-muted: var(--muted);
  --shadow: 0 10px 36px rgba(0, 0, 0, .18);
  --shadow-hover: 0 14px 38px rgba(0, 0, 0, .28);
  color-scheme: dark;
}

* { box-sizing: border-box; }
html { min-width: 320px; scroll-behavior: smooth; }
body {
  margin: 0;
  color: var(--ink);
  background: var(--bg);
  font: 14px/1.5 -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  -webkit-font-smoothing: antialiased;
}
body.nav-open { overflow: hidden; }
button, input, select, textarea { font: inherit; }
a { color: var(--link); text-decoration: none; }
a:hover { color: var(--link-hover); }
h1, h2, h3, h4 { color: var(--ink-strong); font-family: inherit; }
h1 { font-size: clamp(25px, 2.1vw, 29px); line-height: 1.22; letter-spacing: -.032em; }
h2 { font-size: 16px; line-height: 1.3; letter-spacing: -.015em; }
h3 { font-size: 15px; line-height: 1.35; }
:where(a, button, input, select, textarea, summary, [tabindex]):focus-visible {
  outline: 3px solid var(--focus);
  outline-offset: 3px;
}
.skip-link {
  position: fixed;
  z-index: 1000;
  top: -80px;
  left: 16px;
  padding: 11px 14px;
  border-radius: 8px;
  color: #fff;
  background: var(--primary);
}
.skip-link:focus { top: 12px; color: #fff; }

/* Application shell */
.app-authenticated .topbar {
  position: sticky;
  z-index: 35;
  top: 0;
  width: calc(100% - var(--sidebar-width));
  min-height: 70px;
  margin-left: var(--sidebar-width);
  padding: 0 30px;
  gap: 18px;
  color: var(--ink);
  background: color-mix(in srgb, var(--surface) 96%, transparent);
  border-bottom: 1px solid var(--line);
  box-shadow: none;
  backdrop-filter: blur(14px);
}
.topbar::after { display: none; }
.topbar-brand { display: none; }
.top-actions {
  min-width: 0;
  display: flex;
  align-items: center;
  gap: 4px;
  overflow-x: auto;
  scrollbar-width: none;
}
.top-actions::-webkit-scrollbar { display: none; }
.top-actions a {
  min-height: 38px;
  display: inline-flex;
  align-items: center;
  padding: 0 12px;
  border-radius: 8px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 600;
  white-space: nowrap;
}
.top-actions a:hover { color: var(--ink); background: var(--surface-2); }
.top-actions a.active { color: var(--primary-text); background: var(--primary-soft); box-shadow: none; }
.user-menu { margin-left: auto; gap: 8px; color: var(--ink); }
.theme-toggle, .user-chip {
  min-height: 38px;
  color: var(--ink);
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 9px;
}
.theme-toggle:hover, .user-chip:hover { color: var(--primary-text); background: var(--primary-soft); border-color: var(--primary-soft); }
.user-chip i { color: var(--primary-text); background: var(--primary-soft); border: 0; }
.user-dropdown-panel { min-width: 230px; border-color: var(--line); border-radius: 11px; background: var(--surface); box-shadow: var(--shadow-hover); }
.user-dropdown-panel a, .user-dropdown-panel button { border-radius: 7px; color: var(--ink); }
.user-dropdown-panel a:hover, .user-dropdown-panel button:hover { color: var(--primary-text); background: var(--primary-soft); }
.language-switcher .theme-toggle.active { color: var(--primary-text); border-color: var(--primary); background: var(--primary-soft); }
.mobile-nav-toggle { display: none; }

.app-shell { display: block; min-height: calc(100vh - 70px); }
.sidenav {
  display: flex;
  flex-direction: column;
  position: fixed;
  z-index: 45;
  inset: 0 auto 0 0;
  width: var(--sidebar-width);
  height: 100dvh;
  padding: 21px 15px 16px;
  overflow-y: hidden;
  overscroll-behavior: contain;
  color: var(--ink);
  background: var(--surface);
  border-right: 1px solid var(--line);
  scrollbar-width: thin;
}
.sidenav > * { flex-shrink: 0; }
.sidenav > .operational-nav {
  flex: 1 1 auto;
  min-height: 0;
  overflow-y: auto;
  scrollbar-width: thin;
}
.sidebar-partners {
  margin-top: auto;
  padding: 22px 10px 2px;
  display: grid;
  gap: 8px;
  justify-items: center;
}
.order-editor .is-required-empty { border-color: #ec2274; background-image: linear-gradient(#ec227407, #ec227407); }
.order-editor [aria-invalid="true"] { border-color: #ec2274; box-shadow: 0 0 0 2px #ec227420; }
.field-validation-message { display: block; color: #cf155e; margin-top: 5px; }
[data-theme="dark"] .sidebar-partners img { filter: brightness(0) invert(1); }
.sidebar-partners img {
  display: block;
  width: 100%;
  max-width: 154px;
  height: 42px;
  padding: 7px 9px;
  object-fit: contain;
  background: transparent;
  border: 0;
  border-radius: 0;
}
.sidebar-brand {
  width: 100%;
  height: 54px;
  display: flex;
  padding: 0 8px 14px;
  overflow: hidden;
}
.sidebar-brand .brand-logo { width: 100%; height: 100%; object-fit: contain; object-position: left center; filter: none; }
.workspace-card {
  min-height: 56px;
  display: flex;
  align-items: center;
  gap: 10px;
  margin: 3px 2px 21px;
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--surface);
}
.workspace-card > span:last-child { min-width: 0; display: grid; gap: 2px; }
.workspace-card strong { overflow: hidden; color: var(--ink-strong); font-size: 12px; text-overflow: ellipsis; white-space: nowrap; }
.workspace-card small { overflow: hidden; color: var(--muted); font-size: 10px; text-overflow: ellipsis; white-space: nowrap; }
.workspace-icon {
  width: 30px;
  height: 30px;
  display: grid;
  flex: 0 0 auto;
  place-items: center;
  border: 1px solid var(--line);
  border-radius: 8px;
  color: var(--primary-text);
  background: var(--surface-2);
}
.workspace-icon svg { width: 17px; height: 17px; }
.nav-group > p {
  margin: 17px 12px 8px;
  color: #8a91a3;
  font-size: 9px;
  font-weight: 750;
  letter-spacing: .16em;
}
.nav-group > p:first-child { margin-top: 0; }
.nav-item {
  position: relative;
  min-height: 40px;
  display: flex;
  align-items: center;
  gap: 10px;
  margin: 3px 0;
  padding: 8px 11px;
  color: var(--muted);
  border-radius: 9px;
  font-size: 12.5px;
  font-weight: 550;
}
.nav-icon { width: 21px; height: 21px; color: currentColor; background: transparent; border: 0; }
.nav-icon svg { width: 18px; height: 18px; }
.nav-item:hover { color: var(--ink); background: var(--surface-2); }
.nav-item:hover .nav-icon { color: inherit; background: transparent; border: 0; }
.nav-item.active { color: var(--primary-text); background: var(--primary-soft); font-weight: 650; }
.nav-item.active .nav-icon { color: inherit; background: transparent; border: 0; }
.nav-item.active::before {
  content: "";
  position: absolute;
  top: 10px;
  bottom: 10px;
  left: -15px;
  width: 3px;
  border-radius: 0 3px 3px 0;
  background: var(--primary);
}
.nav-item.active::after { display: none; }
.mobile-only-nav { display: none; }
.nav-unread { margin-left: auto; color: #fff; background: var(--primary); }
.mailbox-nav-subs { margin: 4px 0 11px 21px; padding-left: 9px; border-left-color: var(--line); }
.mailbox-nav-subs a { min-height: 32px; color: var(--muted); border-radius: 7px; font-size: 11px; }
.mailbox-nav-subs a:hover, .mailbox-nav-subs a.active { color: var(--primary-text); background: var(--primary-soft); }
.mobile-quick-actions { display: none; }
.mobile-nav-shade { display: none; }

.app-authenticated .container {
  width: auto;
  max-width: 1800px;
  min-height: calc(100vh - 70px);
  margin: 0 auto 0 var(--sidebar-width);
  padding: 30px 34px 64px;
}
.app-shell + .app-footer {
  margin-left: var(--sidebar-width);
  padding: 16px 34px;
  color: var(--muted);
  background: var(--surface);
  border-color: var(--line);
}
.app-footer span:first-child { color: var(--ink); }

/* Page hierarchy and surfaces */
.page-head { align-items: flex-start; gap: 18px; margin-bottom: 24px; }
.page-head h1 { margin: 1px 0 5px; }
.page-head p, .page-head .muted { max-width: 820px; margin: 0; color: var(--muted); font-size: 12px; }
.eyebrow { margin-bottom: 7px; color: var(--muted); font-size: 10px; font-weight: 700; letter-spacing: .13em; }
.actions { gap: 8px; }
.panel, .form-section, .route-builder, .assignment-builder, .lead-form-section,
.search-history-card, .campaign-card, .recipient-panel, .lead-mail-panel, .mailbox-main,
.stats article, .order-ledger-card, .settings-card, .form-card, .distribution-form-card,
.profile-section, .quote-section, .access-section {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  color: var(--ink);
  background: var(--surface);
  box-shadow: var(--shadow);
}
.panel { padding: 21px; }
.panel:hover { border-color: var(--line-strong); }
.section-head, .section-heading, .step-heading, .route-builder-head, .api-panel-head,
.lead-form-section-head, .profile-section-head, .quote-section-head { border-color: var(--line); }
.section-heading h2, .section-head h2, .panel-title { color: var(--ink-strong); }
.muted, .hint, small { color: var(--muted); }
.empty-state { padding: 54px 24px; color: var(--muted); }

/* Controls */
label { color: var(--ink); font-size: 12px; font-weight: 650; }
input, select, textarea {
  min-height: 43px;
  padding: 9px 11px;
  color: var(--ink-strong);
  background: var(--surface);
  border: 1px solid var(--line-strong);
  border-radius: 8px;
  box-shadow: none;
}
textarea { min-height: 104px; }
input:hover, select:hover, textarea:hover { border-color: #b8c0d3; }
input:focus, select:focus, textarea:focus { border-color: var(--primary); box-shadow: 0 0 0 3px color-mix(in srgb, var(--primary) 16%, transparent); }
input[type="checkbox"], input[type="radio"] { min-height: 0; accent-color: var(--primary); }
input[type="file"] { background: var(--surface-2); }
.button, a.button, button.button, .mail-compose-button, .row-save,
.button-primary, button[type="submit"]:not(.link-button):not(.button-quiet) {
  min-height: 39px;
  padding: 8px 14px;
  color: #fff;
  background: var(--primary);
  border: 1px solid var(--primary);
  border-radius: 8px;
  box-shadow: 0 3px 6px rgba(93, 81, 212, .10);
  font-size: 12px;
  font-weight: 650;
}
.button:hover, a.button:hover, button.button:hover, .mail-compose-button:hover, .row-save:hover,
.button-primary:hover, button[type="submit"]:not(.link-button):not(.button-quiet):hover {
  color: #fff;
  background: var(--primary-hover);
  border-color: var(--primary-hover);
  transform: none;
  box-shadow: none;
}
.button.secondary, .button.ghost, .button-secondary, .button-quiet,
a.button.secondary, a.button.ghost, a.button-secondary, a.button-quiet,
button.button.secondary, button.button.ghost, button.button-secondary, button.button-quiet {
  color: var(--ink);
  background: var(--surface);
  border-color: var(--line);
  box-shadow: none;
}
.button.secondary:hover, .button.ghost:hover, .button-secondary:hover, .button-quiet:hover {
  color: var(--primary-text);
  background: var(--primary-soft);
  border-color: var(--primary-soft);
}
.button-danger, .button.danger { color: #fff; background: var(--red); border-color: var(--red); }
.button-danger:hover, .button.danger:hover { color: #fff; background: #a93249; border-color: #a93249; }
.link-danger, .subtle-danger { color: var(--red); }
.link-button { color: var(--primary-text); }
.alert {
  color: var(--ink);
  background: var(--blue-soft);
  border: 1px solid color-mix(in srgb, var(--blue) 25%, var(--line));
  border-left: 3px solid var(--blue);
  border-radius: 9px;
}
.alert-success { background: var(--green-soft); border-left-color: var(--green); }
.alert-warning { background: var(--orange-soft); border-left-color: var(--orange); }
.alert-error { background: var(--red-soft); border-left-color: var(--red); }
.badge, .status-pill, .order-status, .document-type, .partner-role, .stage-badge,
.distribution-status, .invoice-tab-count {
  min-height: 24px;
  padding: 3px 8px;
  border: 1px solid var(--line);
  border-radius: 6px;
  box-shadow: none;
  font-size: 10px;
  font-weight: 650;
}

/* Lists, tables and tabs */
.table-wrap {
  width: 100%;
  overflow: auto;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
  scrollbar-width: thin;
}
.table-wrap:focus-visible { outline-offset: 2px; }
table { width: 100%; border-collapse: collapse; color: var(--ink); font-size: 12px; }
thead, th { background: var(--surface-2); }
th {
  height: 43px;
  padding: 10px 17px;
  color: var(--muted);
  border-color: var(--line);
  font-size: 10.5px;
  font-weight: 600;
  letter-spacing: .045em;
}
td { padding: 15px 17px; color: var(--ink); border-color: var(--line); }
tbody tr:hover { background: var(--surface-2); }
tbody tr.is-selected { background: var(--primary-soft); }
.list-row { border-color: var(--line); }
.list-row:hover { background: var(--surface-2); }
.tabs, .order-tabs, .directory-tabs, .invoice-tabs {
  gap: 19px;
  padding-inline: 20px;
  overflow-x: auto;
  border-color: var(--line);
  scrollbar-width: thin;
}
.tab, .order-tabs a, .directory-tabs a, .invoice-tab {
  min-height: 48px;
  display: inline-flex;
  align-items: center;
  color: var(--muted);
  border-bottom: 2px solid transparent;
  font-size: 12px;
  white-space: nowrap;
}
.tab.active, .order-tabs a.active, .directory-tabs a.active, .invoice-tab.active {
  color: var(--primary-text);
  border-color: var(--primary);
  background: transparent;
  font-weight: 650;
}
.pagination { gap: 5px; }
.pagination a, .pagination span { border-color: var(--line); border-radius: 6px; }
.pagination .current, .pagination [aria-current="page"] { color: var(--primary-text); background: var(--primary-soft); }

/* Operational workspaces */
.stats { gap: 16px; }
.stats article { padding: 18px 19px; }
.stats strong { color: var(--ink-strong); }
.finance-hero, .order-financial-summary, .order-settlement-summary { background: var(--surface); border-color: var(--line); }
.finance-kpi, .order-kpi, .summary-card { background: var(--surface-2); border-color: var(--line); border-radius: 10px; }
.transport-editor, .order-editor, .campaign-layout, .mailbox-layout,
.directory-profile-layout, .person-profile-layout { gap: 20px; }
.transport-filters, .filters, .inbound-filter-form { gap: 12px; }
.order-ledger-card { border-left-color: var(--primary); }
.order-ledger-card:hover { border-color: color-mix(in srgb, var(--primary) 35%, var(--line)); box-shadow: var(--shadow-hover); }
.order-ledger-card.is-selected { border-color: var(--primary); box-shadow: 0 0 0 2px color-mix(in srgb, var(--primary) 16%, transparent); }
.order-bulk-toolbar {
  top: 80px;
  color: var(--ink);
  background: color-mix(in srgb, var(--surface) 94%, transparent);
  border-color: var(--line);
  box-shadow: var(--shadow);
}
.wizard-head, .sticky-actions, .lead-form-actions { border-color: var(--line); background: color-mix(in srgb, var(--surface) 95%, transparent); box-shadow: var(--shadow); }
.wizard-step.active, .wizard-step.current { color: var(--primary-text); }
.wizard-step.active i, .wizard-step.current i { color: var(--primary-text); border-color: var(--primary); background: var(--primary-soft); }
.wizard-step.done i { color: #fff; border-color: var(--primary); background: var(--primary); }
.route-card, .assignment-card, .additional-cost-row { border-color: var(--line); background: var(--surface-2); border-radius: 10px; }
.profile-monogram, .profile-person-avatar { color: var(--primary-text); background: var(--primary-soft); }
.directory-profile-hero { border-top-color: var(--primary); }
.profile-aside { top: 88px; }
.lead-form-section-head, .quote-section-head { background: var(--surface-2); }
.stage-chip, .stage-badge { border-radius: 6px; }
.mailbox-sidebar, .conversation-list { border-color: var(--line); background: var(--surface); }
.mail-message-row:hover, .conversation-item:hover { background: var(--surface-2); }
.mail-message-row.unread, .conversation-item.active { background: var(--primary-soft); }
.distribution-head, .invoice-list-header { border-color: var(--line); }
.distribution-sheet-table td, .distribution-sheet-table th { border-color: var(--line); }
.selection-bar { color: var(--primary-text); background: var(--primary-soft); }

/* Calendar and maps */
.transport-calendar, .calendar-workspace, .calendar-detail-panel {
  color: var(--ink);
  background: var(--surface);
  border-color: var(--line);
}
.calendar-toolbar, .calendar-day-head, .calendar-detail-panel { background: var(--surface-2); }
.transport-calendar .calendar-day, .transport-calendar .calendar-weekday { border-color: var(--line); }
.transport-calendar .calendar-day:hover { background: var(--surface-2); }
.transport-calendar .calendar-day.is-today { box-shadow: inset 0 0 0 2px var(--primary); }
.calendar-order { border-left-color: var(--primary); }
.calendar-order:hover, .calendar-order.is-active { background: var(--primary-soft); }
.map-card, .order-map-shell, .map-panel { border-color: var(--line); background: var(--surface-2); }
.leaflet-container { color: #24283d; background: #e9edf5; }
[data-theme="dark"] .leaflet-container { filter: brightness(.86) contrast(.96); }

/* Dialogs and document preview */
dialog, .partner-dialog, .contact-dialog, .modal {
  color: var(--ink);
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: 0 24px 72px rgba(26, 24, 54, .25);
}
dialog::backdrop, .modal-overlay { background: rgba(20, 22, 38, .55); backdrop-filter: blur(3px); }
.document-popup {
  width: min(1040px, calc(100vw - 48px));
  height: min(84vh, 820px);
  border-color: var(--line);
  border-radius: var(--radius);
  background: var(--surface);
}
.document-popup-head {
  min-height: 56px;
  color: var(--ink);
  background: var(--surface);
  border-color: var(--line);
}
.document-popup-close { color: var(--muted); background: var(--surface-2); border-color: var(--line); }
.document-popup-close:hover { color: #fff; background: var(--red); border-color: var(--red); }
.document-popup-body { position: relative; min-height: 0; background: #e9ebf1; }
.document-popup-frame { display: block; width: 100%; height: 100%; border: 0; background: #e9ebf1; }
.document-popup-body.is-loading .document-popup-frame,
.document-popup-body.has-error .document-popup-frame { visibility: hidden; }
.document-popup-status,
.document-popup-error {
  position: absolute;
  inset: 0;
  z-index: 2;
  display: grid;
  place-content: center;
  justify-items: center;
  gap: 10px;
  padding: 28px;
  color: var(--ink);
  background: var(--surface-2);
  text-align: center;
}
.document-popup-status[hidden], .document-popup-error[hidden] { display: none; }
.document-popup-status span, .document-popup-error span { color: var(--muted); }
.document-popup-spinner { width: 32px; height: 32px; border: 3px solid var(--line); border-top-color: var(--accent); border-radius: 50%; animation: document-popup-spin .8s linear infinite; }
.document-popup-fallback-actions { display: flex; flex-wrap: wrap; justify-content: center; gap: 10px; margin-top: 6px; }
@keyframes document-popup-spin { to { transform: rotate(360deg); } }
@media (prefers-reduced-motion: reduce) { .document-popup-spinner { animation-duration: 1.8s; } }
.document-preview-panel { max-width: 1060px; margin-inline: auto; }
.pdf-preview-frame, .document-preview-frame { max-height: min(74vh, 820px); border-radius: 9px; }

/* Authentication and error states */
.app-anonymous { background: var(--surface); }
.auth-container { min-height: 100dvh; padding: 32px 20px; background: linear-gradient(135deg, #211c41 0 45%, var(--surface) 45%); }
.auth-card {
  width: min(100%, 420px);
  padding: 32px;
  border: 1px solid var(--line);
  border-radius: 16px;
  background: var(--surface);
  box-shadow: 0 24px 72px rgba(23, 20, 58, .18);
}
.auth-brand-logo { width: min(100%, 300px); max-height: 90px; }
.auth-help { margin-bottom: 0; text-align: center; }
.auth-language-switcher { width: min(100%, 420px); }

/* Responsive behavior */
@media (min-width: 1650px) {
  :root { --sidebar-width: 240px; }
}

@media (max-width: 1280px) {
  :root { --sidebar-width: 215px; }
  .app-authenticated .container { padding: 26px 25px 58px; }
  .app-authenticated .topbar { padding-inline: 24px; }
}

@media (max-width: 1000px) {
  .stats { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .form-grid, .grid-two { gap-inline: 17px; }
  .directory-profile-layout, .person-profile-layout { grid-template-columns: 1fr; }
  .profile-aside { position: static; }
}

@media (max-width: 850px) {
  :root { --sidebar-width: 0px; }
  .app-authenticated .topbar {
    width: 100%;
    min-height: 65px;
    margin-left: 0;
    padding: 0 15px;
  }
  .mobile-nav-toggle {
    width: 38px;
    height: 38px;
    display: grid;
    flex: 0 0 auto;
    place-content: center;
    gap: 4px;
    padding: 0;
    color: var(--ink);
    background: var(--surface-2);
    border: 1px solid var(--line);
    border-radius: 9px;
  }
  .mobile-nav-toggle span { width: 17px; height: 2px; display: block; border-radius: 2px; background: currentColor; }
  .topbar-brand { width: 116px; height: 42px; display: flex; min-width: 116px; }
  .topbar-brand .brand-logo { width: 100%; height: 100%; object-fit: contain; }
  .app-authenticated .topbar .top-actions { display: none; }
  .sidenav {
    z-index: 90;
    width: min(286px, calc(100vw - 48px));
    transform: translateX(-104%);
    transition: transform .2s ease;
    box-shadow: 20px 0 60px rgba(20, 22, 38, .18);
  }
  .sidenav.is-open { transform: translateX(0); }
  .mobile-quick-actions {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 6px;
    margin: 0 2px 17px;
  }
  .mobile-quick-actions a {
    min-height: 34px;
    display: grid;
    place-items: center;
    padding: 6px;
    border: 1px solid var(--line);
    border-radius: 7px;
    color: var(--muted);
    background: var(--surface-2);
    font-size: 10.5px;
    font-weight: 650;
    text-align: center;
  }
  .mobile-quick-actions a:hover { color: var(--primary-text); background: var(--primary-soft); border-color: var(--primary-soft); }
  .mobile-nav-shade {
    position: fixed;
    z-index: 80;
    inset: 0;
    display: block;
    background: rgba(20, 22, 38, .52);
    backdrop-filter: blur(2px);
  }
  .mobile-nav-shade[hidden] { display: none; }
  .operational-nav { display: block; }
  .operational-nav > p, .operational-nav .nav-subs, .operational-nav .directory-desktop { display: block; }
  .operational-nav .mobile-only-nav { display: none; }
  .operational-nav .nav-item { display: flex; min-height: 40px; padding: 8px 11px; font-size: 12.5px; }
  .operational-nav .nav-item.active::before { display: block; }
  .app-authenticated .container { margin-left: 0; padding: 24px 18px 52px; }
  .app-shell + .app-footer { margin-left: 0; padding: 15px 18px; }
  body { padding-bottom: 0; }
}

@media (max-width: 620px) {
  h1 { font-size: 25px; }
  .app-authenticated .topbar { gap: 8px; padding-inline: 11px; }
  .topbar-brand { width: 96px; min-width: 96px; }
  .user-menu { gap: 4px; }
  .theme-toggle { width: 36px; min-width: 36px; padding: 0; }
  .theme-toggle [data-theme-label] { display: none; }
  .user-chip { padding-inline: 5px; }
  .user-chip > span { display: none; }
  .language-switcher { gap: 2px; }
  .language-switcher .theme-toggle { width: 32px; min-width: 32px; height: 36px; }
  .app-authenticated .container { padding: 22px 14px 44px; }
  .page-head { align-items: stretch; flex-direction: column; gap: 15px; }
  .page-head .actions, .page-head > .button { width: 100%; }
  .page-head .actions > * { flex: 1 1 130px; }
  .page-head > .button { width: 100%; min-height: 44px; flex: 0 0 auto; }
  .panel { padding: 16px; }
  .stats { grid-template-columns: 1fr; gap: 10px; }
  .form-grid, .grid-two, .grid-2, .grid-3, .grid-4 { grid-template-columns: 1fr; }
  .span-2, .field-wide { grid-column: auto; }
  .table-wrap { border-radius: 10px; }
  th, td { padding-inline: 13px; }
  .document-popup { width: 100vw; height: 100dvh; max-width: none; max-height: none; border: 0; border-radius: 0; }
  .auth-container { background: var(--surface); }
  .auth-card { padding: 25px 20px; border: 0; box-shadow: none; }
}

@media (max-width: 390px) {
  .topbar-brand { width: 82px; min-width: 82px; }
  .mobile-nav-toggle { width: 36px; height: 36px; }
  .page-head .actions { display: grid; grid-template-columns: 1fr; }
  .page-head .actions > * { width: 100%; }
  .button, a.button, button.button { min-height: 42px; }
  .app-footer { flex-direction: column; gap: 3px; }
}

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

@media (forced-colors: active) {
  .nav-item.active::before, .calendar-order { forced-color-adjust: none; background: Highlight; }
}
