/* =============================================
   EXECUTIVE PORTAL - Cohesive Portal Theme
   Directly inherits and extends main.css tokens
   ============================================= */

/* Complete layout isolation from main.css */
html, body {
  height: 100% !important;
  width: 100% !important;
  margin: 0 !important;
  padding: 0 !important;
  overflow: hidden !important;
}

/* Shell Layout — fixed viewport filling the real screen without iOS dvh clipping */
.of-shell {
  display: flex;
  position: fixed !important;
  inset: 0 !important;
  width: 100% !important;
  height: 100% !important;
  max-height: none !important;
  min-height: 0 !important;
  overflow: hidden !important;
  background: var(--bg-base);
  color: var(--text-primary);
  z-index: 1;
}

/* Sidebar overrides & refinements */
.of-sidebar {
  width: var(--sidebar-w, 252px);
  height: 100vh;
  background: var(--bg-surface);
  border-right: 1px solid var(--border-default);
  display: flex;
  flex-direction: column;
  padding: 1.5rem 0.95rem;
  position: sticky;
  top: 0;
  flex-shrink: 0;
  overflow-y: auto;
  overflow-x: hidden;
  z-index: 100;
}

.of-nav {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
  margin-top: 0.25rem;
}

.of-nav .nav-item {
  position: relative;
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0.65rem 0.85rem;
  border-radius: var(--radius-sm, 6px);
  color: var(--text-secondary);
  font-family: var(--font-ui);
  font-size: 0.875rem;
  font-weight: 500;
  transition: all var(--transition, 0.25s ease);
  text-decoration: none;
  border: none;
  background: transparent;
  width: 100%;
  text-align: left;
  cursor: pointer;
}

.of-nav .nav-item:hover {
  background: var(--surface-hover);
  color: var(--text-primary);
}

.of-nav .nav-item:active {
  transform: scale(0.98);
}

.of-nav .nav-item.active {
  background: var(--bg-surface-raised);
  color: var(--text-primary);
  font-weight: 600;
}

.of-nav .nav-item.active::before {
  content: "";
  position: absolute;
  left: 0;
  top: 20%;
  bottom: 20%;
  width: 3px;
  background: var(--accent);
  border-radius: 0 2px 2px 0;
}

.of-nav .nav-item.active .nav-icon {
  color: var(--accent);
}

/* Main Content Area — the sole scroll container (mirrors .main-content).
   margin-inline auto centers the capped width on ultrawide monitors */
.of-main {
  flex: 1;
  min-width: 0;
  max-width: 1400px;
  margin-inline: auto;
  overflow-y: auto;
  overflow-x: hidden;
}

.of-view {
  display: none;
  padding: 0 2rem 2rem;
  animation: ofFade 0.3s ease;
  width: 100%;
  max-width: 100%;
  box-sizing: border-box;
}

.of-view.active {
  display: block;
}

@keyframes ofFade {
  from { opacity: 0; transform: translateY(8px); }
  to   { opacity: 1; transform: translateY(0); }
}

/* =============================================
   SKELETON SHIMMER LOADERS
   ============================================= */
.skeleton {
  background: linear-gradient(
    90deg,
    rgba(255, 255, 255, 0.03) 0%,
    rgba(255, 255, 255, 0.09) 50%,
    rgba(255, 255, 255, 0.03) 100%
  ) !important;
  background-size: 200% 100% !important;
  animation: ofSkeletonShimmer 1.5s infinite ease-in-out !important;
  border-radius: var(--radius-sm, 6px);
  position: relative;
  overflow: hidden;
}

[data-theme="light"] .skeleton {
  background: linear-gradient(
    90deg,
    rgba(0, 0, 0, 0.04) 0%,
    rgba(0, 0, 0, 0.09) 50%,
    rgba(0, 0, 0, 0.04) 100%
  ) !important;
  background-size: 200% 100% !important;
}

@keyframes ofSkeletonShimmer {
  0% { background-position: 200% 0; }
  100% { background-position: -200% 0; }
}

.skeleton-card {
  width: 100%;
  min-height: 86px;
  border-radius: var(--radius-md, 8px);
  border: 1px solid var(--border-default, #28313A);
  background: var(--bg-surface);
}

.skeleton-stack {
  display: flex;
  flex-direction: column;
  gap: 0.65rem;
  padding: 1rem;
  background: var(--bg-surface);
  border: 1px solid var(--border-default);
  border-radius: var(--radius-md);
  width: 100%;
}

.skeleton-title {
  height: 18px;
  width: 45%;
  border-radius: 4px;
  margin-bottom: 0.35rem;
}

.skeleton-line {
  height: 12px;
  width: 100%;
  border-radius: 4px;
}

.skeleton-line.short {
  width: 60%;
}

.skeleton-avatar {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  flex-shrink: 0;
}

/* Sticky section title comes from main.css `.view-header`
   (each head carries both classes); spacing matches it */
.of-view-head {
  margin-bottom: 1.75rem;
}

.of-view-head h2 {
  font-family: var(--font-ui);
  font-size: 1.5rem;
  font-weight: 700;
  color: var(--text-primary);
  letter-spacing: -0.01em;
}

.of-view-head p {
  color: var(--text-secondary);
  font-size: 0.875rem;
  margin-top: 0.2rem;
}

/* ---------- Stat Cards Grid & Interactive Popovers ---------- */
.of-stat-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 1rem;
  margin-bottom: 1.5rem;
  width: 100%;
  max-width: 100%;
  box-sizing: border-box;
}

.of-stat {
  background: var(--bg-surface);
  border: 1px solid var(--border-default);
  border-radius: var(--radius-md, 8px);
  padding: 1rem 1.15rem;
  transition: border-color var(--transition), transform var(--transition), box-shadow var(--transition);
  position: relative;
  cursor: pointer;
  user-select: none;
  min-width: 0;
  max-width: 100%;
  box-sizing: border-box;
  overflow: hidden;
}

.of-stat:hover {
  border-color: var(--border-hover);
  transform: translateY(-1.5px);
  box-shadow: var(--shadow-card-hover);
}

.of-stat .of-stat-label {
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-secondary);
  font-weight: 600;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 0.4rem;
}

.of-stat .of-stat-label > span:first-child {
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.of-stat .of-stat-value {
  font-family: var(--font-proxima);
  font-size: var(--font-size-kpi-value, 1.5625rem);
  font-weight: 600;
  color: var(--text-primary);
  margin-top: 0.35rem;
  font-variant-numeric: tabular-nums;
  font-feature-settings: "tnum";
  letter-spacing: -0.02em;
}

.of-stat .of-stat-sub {
  font-size: 0.75rem;
  color: var(--text-tertiary);
  margin-top: 0.35rem;
}

.of-prog-badge-grid {
  display: flex;
  align-items: center;
  gap: 0.3rem;
  flex-wrap: wrap;
  margin-top: 0.35rem;
  min-height: 28px;
}

.of-prog-chip {
  font-size: 0.72rem;
  font-weight: 600;
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid var(--border-default);
  padding: 2px 6px;
  border-radius: 5px;
  color: var(--text-secondary);
  display: inline-flex;
  align-items: center;
  gap: 3px;
  white-space: nowrap;
}

.of-prog-chip strong {
  color: var(--text-primary);
  font-weight: 700;
}

[data-theme="light"] .of-prog-chip {
  background: rgba(0, 0, 0, 0.04);
}

.of-stat.is-green .of-stat-value { color: var(--status-positive); }
.of-stat.is-red   .of-stat-value { color: var(--status-negative); }

/* Popover Tooltip for Stat Cards */
.of-stat .stat-popover {
  display: none;
  position: absolute;
  top: calc(100% + 8px);
  left: 0;
  min-width: 220px;
  width: max-content;
  max-width: min(320px, calc(100vw - 2rem));
  background: var(--bg-surface-elevated, var(--bg-surface));
  border: 1px solid var(--border-default);
  border-radius: var(--radius-md, 8px);
  padding: 0.9rem 1rem;
  box-shadow: var(--shadow-popover);
  z-index: 60;
  pointer-events: none;
  box-sizing: border-box;
  /* Neutralize main.css's shared .stat-popover hidden state (opacity 0 /
     visibility hidden / -8px shift) — this portal toggles with display */
  opacity: 1;
  visibility: visible;
  transform: none;
  transition: none;
}

/* Right-column cards align popover to right so it never overflows screen edge */
.of-stat:nth-child(even) .stat-popover,
.of-stat:nth-child(2n) .stat-popover {
  left: auto !important;
  right: 0 !important;
}

.of-stat.hover-active {
  border-color: var(--accent);
  /* Lift above sibling cards — their own stacking contexts would
     otherwise paint over the popover */
  z-index: 55;
}

.of-stat.hover-active .stat-popover {
  display: block;
  animation: ofPopIn 0.2s cubic-bezier(0.16, 1, 0.3, 1);
  pointer-events: auto;
}

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

.stat-pop-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 0.82rem;
  color: var(--text-secondary);
  padding: 0.25rem 0;
  font-variant-numeric: tabular-nums;
}

.stat-pop-row.income span:last-child { color: var(--status-positive); }
.stat-pop-row.expense span:last-child { color: var(--status-negative); }

.stat-pop-row.total {
  border-top: 1px solid var(--border-default);
  margin-top: 0.45rem;
  padding-top: 0.45rem;
  font-weight: 700;
  color: var(--text-primary);
}

/* ---------- Charts & Dashboard Grids ---------- */
.of-chart-box {
  position: relative;
  height: 300px;
  min-height: 300px;
}

.dashboard-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(360px, 1fr));
  gap: 1.25rem;
  margin-bottom: 1.5rem;
}

.of-cards {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(360px, 1fr));
  gap: 1.25rem;
  margin-bottom: 1.5rem;
}

.of-card {
  background: var(--bg-surface);
  border: 1px solid var(--border-default);
  border-radius: var(--radius-md, 8px);
  padding: 1.35rem;
  box-shadow: var(--shadow-card);
}

.of-card h3 {
  font-size: 0.95rem;
  font-weight: 700;
  color: var(--text-primary);
  margin-bottom: 1.1rem;
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.of-card h3 iconify-icon {
  color: var(--accent);
  font-size: 1.15rem;
}

.of-list-title {
  font-size: 1.05rem;
  font-weight: 700;
  color: var(--text-primary);
  margin: 1.75rem 0 1rem;
}

.of-record-layout {
  display: grid;
  grid-template-columns: 1.4fr 1fr;
  gap: 1.25rem;
  align-items: start;
}

/* ---------- Filter Bar ---------- */
.of-filter-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  flex-wrap: wrap;
  margin-bottom: 1.25rem;
}

/* Search + sort pair inside the filter bar */
.of-filter-tools {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  flex: 1;
  min-width: 0;
  max-width: 560px;
}

.of-filter-tools .of-search {
  flex: 1;
  min-width: 0;
  max-width: none;
  margin-bottom: 0;
}

.of-filter-tools .of-sort-select {
  flex-shrink: 0;
}

.of-filter-tabs {
  display: flex;
  background: var(--bg-surface-raised);
  border: 1px solid var(--border-default);
  border-radius: var(--radius-sm, 6px);
  padding: 3px;
  gap: 2px;
}

.of-filter-btn {
  background: transparent;
  border: none;
  color: var(--text-secondary);
  font-size: 0.8rem;
  font-weight: 600;
  padding: 0.4rem 0.85rem;
  border-radius: 4px;
  cursor: pointer;
  transition: all var(--transition);
}

.of-filter-btn:hover {
  color: var(--text-primary);
}

.of-filter-btn:active {
  transform: scale(0.98);
}

.of-filter-btn.active {
  background: var(--bg-surface);
  color: var(--text-primary);
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.2);
}

.of-sort-select {
  padding: 0.45rem 0.85rem;
  background: var(--bg-surface-raised);
  border: 1px solid var(--border-default);
  border-radius: var(--radius-sm, 6px);
  color: var(--text-primary);
  font-size: 0.82rem;
  outline: none;
}

/* ---------- Forms ---------- */
.of-form {
  display: flex;
  flex-direction: column;
  gap: 0.9rem;
}

.of-form-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.85rem;
}

.of-field label {
  display: block;
  font-size: 0.76rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-secondary);
  margin-bottom: 0.35rem;
}

.of-field small {
  font-weight: 400;
  color: var(--text-tertiary);
  text-transform: none;
}

.of-field input,
.of-field select,
.of-field textarea {
  width: 100%;
  padding: 0.7rem 0.85rem;
  background: var(--bg-surface-raised);
  border: 1px solid var(--border-default);
  border-radius: var(--radius-sm, 6px);
  font-size: 0.9rem;
  font-family: inherit;
  color: var(--text-primary);
  transition: border-color var(--transition), box-shadow var(--transition);
  outline: none;
}

.of-field input:focus,
.of-field select:focus,
.of-field textarea:focus {
  border-color: var(--border-focus);
  box-shadow: 0 0 0 3px rgba(249, 115, 22, 0.15);
}

.of-field select option {
  background: var(--bg-surface);
  color: var(--text-primary);
}

/* ---------- Animated dropdowns (shared component from main system) ---------- */
/* Match the trigger to the portal's input sizing */
.of-field .dd-trigger {
  padding: 0.7rem 0.85rem;
}
/* Lift the field holding an open menu above its siblings so the menu is
   never covered (same trick main.css applies to .form-group) */
.of-field:has(.dd.dd-open) {
  position: relative;
  z-index: 60;
}
/* Filter-bar sort dropdown keeps the compact .of-sort-select sizing */
.of-filter-bar .dd-trigger {
  padding: 0.45rem 0.85rem;
  font-size: 0.82rem;
}

.of-check {
  display: inline-flex;
  align-items: center;
  gap: 0.65rem;
  font-size: 0.84rem;
  font-weight: 500;
  color: var(--text-primary);
  cursor: pointer;
  user-select: none;
}

.of-check input[type="checkbox"] {
  appearance: none;
  -webkit-appearance: none;
  width: 18px !important;
  height: 18px !important;
  min-width: 18px !important;
  min-height: 18px !important;
  border-radius: 4px;
  background: var(--bg-surface-raised, #161D25) !important;
  border: 1.5px solid var(--border-default, #28313A) !important;
  display: inline-grid !important;
  place-content: center !important;
  margin: 0 !important;
  padding: 0 !important;
  cursor: pointer;
  vertical-align: middle;
  transition: all 0.18s cubic-bezier(0.4, 0, 0.2, 1);
  position: relative;
  flex-shrink: 0;
  box-shadow: none !important;
}

.of-check input[type="checkbox"]:hover {
  border-color: var(--primary) !important;
  background: var(--surface-hover, #1D2733) !important;
}

.of-check input[type="checkbox"]:focus-visible {
  outline: 2px solid var(--primary);
  outline-offset: 2px;
}

.of-check input[type="checkbox"]::before {
  content: "";
  width: 9px;
  height: 5px;
  border-left: 2px solid #FFFFFF;
  border-bottom: 2px solid #FFFFFF;
  transform: rotate(-45deg) scale(0) translate(0.5px, -0.5px);
  transform-origin: center;
  transition: transform 0.15s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}

.of-check input[type="checkbox"]:checked {
  background: var(--primary) !important;
  border-color: var(--primary) !important;
}

.of-check input[type="checkbox"]:checked::before {
  transform: rotate(-45deg) scale(1) translate(0.5px, -0.5px);
}

[data-theme="light"] .of-check input[type="checkbox"] {
  background: #F8FAFC !important;
  border-color: #CBD5E1 !important;
}

[data-theme="light"] .of-check input[type="checkbox"]:checked {
  background: var(--primary) !important;
  border-color: var(--primary) !important;
}

.of-error {
  background: rgba(239, 68, 68, 0.1);
  border: 1px solid var(--status-negative);
  color: var(--status-negative);
  padding: 0.65rem 0.9rem;
  border-radius: var(--radius-sm, 6px);
  font-size: 0.82rem;
  line-height: 1.4;
  animation: ofFade 0.3s ease;
}

/* ---------- Buttons ---------- */
.of-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.45rem;
  border: none;
  border-radius: var(--radius-sm, 6px);
  padding: 0.65rem 1.25rem;
  font-size: 0.875rem;
  font-weight: 600;
  cursor: pointer;
  text-decoration: none;
  transition: all var(--transition, 0.25s ease);
  user-select: none;
  -webkit-tap-highlight-color: transparent;
}

.of-btn:disabled {
  opacity: 0.38 !important;
  cursor: not-allowed !important;
  pointer-events: none !important;
  transform: none !important;
  box-shadow: none !important;
}

.of-btn:active:not(:disabled) {
  transform: scale(0.98);
}

.of-btn-primary {
  background: linear-gradient(135deg, #FF6B1A 0%, #FF5000 100%);
  color: #FFFFFF;
  border: 1px solid rgba(255, 255, 255, 0.16);
  font-weight: 700;
  letter-spacing: 0.015em;
  box-shadow: 0 4px 16px rgba(255, 80, 0, 0.28), 0 1px 2px rgba(0, 0, 0, 0.2);
  transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
  text-shadow: 0 1px 2px rgba(0, 0, 0, 0.2);
}

.of-btn-primary:hover:not(:disabled) {
  background: linear-gradient(135deg, #FF7B2E 0%, #FF5E14 100%);
  border-color: rgba(255, 255, 255, 0.28);
  box-shadow: 0 6px 22px rgba(255, 94, 20, 0.42), 0 2px 4px rgba(0, 0, 0, 0.25);
  transform: translateY(-1px);
}

.of-btn-primary:active:not(:disabled) {
  transform: translateY(0) scale(0.98);
  filter: brightness(0.95);
  box-shadow: 0 2px 8px rgba(255, 80, 0, 0.3);
}

.of-btn-secondary {
  background: var(--bg-surface-raised);
  color: var(--text-primary);
  border: 1px solid var(--border-default);
}

.of-btn-secondary:hover:not(:disabled) {
  background: var(--surface-hover);
  border-color: var(--border-hover);
  color: var(--text-primary);
  transform: translateY(-1px);
}

.of-btn-ghost {
  background: var(--bg-surface-raised);
  color: var(--text-primary);
  border: 1px solid var(--border-default);
}

.of-btn-ghost:hover:not(:disabled) {
  background: var(--surface-hover);
  border-color: var(--border-hover);
  color: var(--text-primary);
}

.of-btn-danger {
  background: var(--status-negative);
  color: #FFFFFF;
}

.of-btn-danger:hover:not(:disabled) {
  filter: brightness(1.1);
}

/* ---------- Scrollables & Tables ---------- */
.of-table-wrap {
  overflow-x: auto;
  overflow-y: visible;
  border: 1px solid var(--border-default);
  border-radius: var(--radius-sm, 6px);
  background: var(--bg-surface);
  -webkit-overflow-scrolling: touch;
}

/* Custom Scrollbars */
.of-table-wrap::-webkit-scrollbar,
.of-scrollable-list::-webkit-scrollbar,
.of-main::-webkit-scrollbar,
.of-sidebar::-webkit-scrollbar,
.of-modal-card::-webkit-scrollbar {
  width: 5px;
  height: 5px;
}

.of-table-wrap::-webkit-scrollbar-track,
.of-scrollable-list::-webkit-scrollbar-track,
.of-main::-webkit-scrollbar-track,
.of-sidebar::-webkit-scrollbar-track,
.of-modal-card::-webkit-scrollbar-track {
  background: transparent;
}

.of-table-wrap::-webkit-scrollbar-thumb,
.of-scrollable-list::-webkit-scrollbar-thumb,
.of-main::-webkit-scrollbar-thumb,
.of-sidebar::-webkit-scrollbar-thumb,
.of-modal-card::-webkit-scrollbar-thumb {
  background: var(--scrollbar-thumb, rgba(255, 255, 255, 0.16));
  border-radius: 999px;
}

.of-table-wrap::-webkit-scrollbar-thumb:hover,
.of-scrollable-list::-webkit-scrollbar-thumb:hover,
.of-main::-webkit-scrollbar-thumb:hover,
.of-sidebar::-webkit-scrollbar-thumb:hover,
.of-modal-card::-webkit-scrollbar-thumb:hover {
  background: var(--scrollbar-thumb-hover, rgba(255, 255, 255, 0.32));
}

.of-table-wrap::-webkit-scrollbar-button,
.of-scrollable-list::-webkit-scrollbar-button,
.of-main::-webkit-scrollbar-button,
.of-sidebar::-webkit-scrollbar-button,
.of-modal-card::-webkit-scrollbar-button {
  display: none !important;
  width: 0 !important;
  height: 0 !important;
}

.of-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.85rem;
  text-align: left;
}

.of-table th {
  font-size: 0.72rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-secondary);
  padding: 0.75rem 0.85rem;
  background: var(--bg-surface-raised);
  border-bottom: 1px solid var(--border-default);
  white-space: nowrap;
}

.of-table th.of-col-check,
.of-table td.of-col-check {
  width: 44px;
  min-width: 44px;
  max-width: 44px;
  text-align: center;
  padding: 0.65rem 0.4rem;
}

.of-check-input {
  width: 17px;
  height: 17px;
  cursor: pointer;
  accent-color: var(--primary);
  border-radius: 4px;
  vertical-align: middle;
}

.of-table td {
  padding: 0.75rem 0.85rem;
  border-bottom: 1px solid var(--border-default);
  color: var(--text-primary);
  vertical-align: middle;
}

.of-table tr:last-child td {
  border-bottom: none;
}

.of-table tr:hover td {
  background: var(--surface-hover);
}

.of-table tr.of-row-selected td {
  background: rgba(249, 115, 22, 0.08) !important;
}

.of-table .num {
  font-family: var(--font-proxima);
  font-variant-numeric: tabular-nums;
  font-feature-settings: "tnum";
  white-space: nowrap;
}

.of-table .num.is-pos {
  color: var(--status-positive);
  font-weight: 700;
}

.of-table .num.is-neg {
  color: var(--status-negative);
  font-weight: 700;
}

/* Role-change dropdowns inside the People table keep the compact row size */
.of-table .dd-trigger {
  padding: 0.35rem 0.6rem;
  font-size: 0.78rem;
}

.of-search {
  width: 100%;
  max-width: 360px;
  padding: 0.65rem 0.85rem;
  background: var(--bg-surface-raised);
  border: 1px solid var(--border-default);
  border-radius: var(--radius-sm, 6px);
  font-size: 0.85rem;
  color: var(--text-primary);
  margin-bottom: 1rem;
  outline: none;
  transition: border-color var(--transition);
}

/* Pagination Controls */
.of-pagination {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  margin-top: 1rem;
  padding-top: 0.85rem;
  border-top: 1px solid var(--border-default);
  flex-wrap: wrap;
}

.of-pagination-info {
  font-size: 0.8rem;
  color: var(--text-secondary);
  font-family: var(--font-ui);
}

.of-pagination-controls {
  display: flex;
  align-items: center;
  gap: 0.35rem;
}

.of-page-btn {
  background: var(--bg-surface-raised);
  border: 1px solid var(--border-default);
  color: var(--text-secondary);
  font-size: 0.78rem;
  font-weight: 600;
  padding: 0.35rem 0.65rem;
  border-radius: var(--radius-sm, 6px);
  cursor: pointer;
  transition: all var(--transition);
  min-width: 30px;
  height: 30px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.25rem;
  user-select: none;
}

.of-page-btn:hover:not(:disabled) {
  background: var(--surface-hover);
  color: var(--text-primary);
  border-color: var(--border-hover);
}

.of-page-btn.active {
  background: var(--primary);
  color: #FFFFFF;
  border-color: var(--primary);
  font-weight: 700;
}

.of-page-btn:disabled {
  opacity: 0.35;
  cursor: not-allowed;
}

.of-search:focus {
  border-color: var(--border-focus);
  box-shadow: 0 0 0 3px rgba(249, 115, 22, 0.15);
}

/* ---------- Event Detail Modal Popup ---------- */
.of-modal-card {
  max-width: 640px;
  max-height: 90vh;
  max-height: 90dvh;
  overflow-y: auto;
  padding: 1.75rem;
  border-radius: var(--radius-md, 10px);
  position: relative;
  background: var(--bg-surface);
  border: 1px solid var(--border-default);
  box-shadow: 0 24px 64px rgba(0, 0, 0, 0.6);
}

.of-modal-head {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 1rem;
  margin-bottom: 1.25rem;
  padding-bottom: 0.85rem;
  border-bottom: 1px solid var(--border-default);
}

.of-modal-head h3 {
  font-family: var(--font-ui);
  font-size: 1.35rem;
  font-weight: 700;
  color: var(--text-primary);
  margin: 0.35rem 0 0.15rem;
  letter-spacing: -0.01em;
}

.of-modal-close {
  background: var(--bg-surface-raised);
  border: 1px solid var(--border-default);
  color: var(--text-secondary);
  font-size: 1.2rem;
  width: 34px;
  height: 34px;
  border-radius: 8px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all var(--transition);
  flex-shrink: 0;
}

.of-modal-close:hover {
  color: var(--text-primary);
  background: var(--surface-hover);
  border-color: var(--border-hover);
}

/* 3-Column Modal Stats Bar */
.of-modal-stats {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 0.75rem;
  margin-bottom: 1.35rem;
}

.of-modal-stat {
  background: var(--bg-surface-raised);
  border: 1px solid var(--border-default);
  border-radius: var(--radius-sm, 6px);
  padding: 0.85rem 1rem;
  display: flex;
  flex-direction: column;
  transition: border-color var(--transition);
}

.of-modal-stat .of-stat-label {
  font-size: 0.7rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-secondary);
  font-weight: 600;
}

.of-modal-stat .of-stat-value {
  font-family: var(--font-digits, inherit);
  font-size: 1.35rem;
  font-weight: 800;
  color: var(--text-primary);
  margin-top: 0.25rem;
  font-variant-numeric: tabular-nums;
  letter-spacing: -0.01em;
}

.of-modal-stat.is-allocated .of-stat-value { color: var(--text-primary); }
.of-modal-stat.is-spent .of-stat-value     { color: var(--status-negative); }
.of-modal-stat.is-remaining .of-stat-value { color: var(--status-positive); }

/* Modal Dropdown Styling */
.of-modal-card .dd {
  width: 100%;
  position: relative;
}

.of-modal-card .dd-trigger {
  width: 100%;
  padding: 0.7rem 0.85rem;
  background: var(--bg-surface-raised);
  border: 1px solid var(--border-default);
  border-radius: var(--radius-sm, 6px);
  font-size: 0.9rem;
  color: var(--text-primary);
  display: flex;
  justify-content: space-between;
  align-items: center;
  cursor: pointer;
  outline: none;
  transition: border-color var(--transition), box-shadow var(--transition);
}

.of-modal-card .dd-trigger:focus,
.of-modal-card .dd.dd-open .dd-trigger {
  border-color: var(--border-focus);
  box-shadow: 0 0 0 3px rgba(249, 115, 22, 0.15);
}

.of-modal-card .dd-menu {
  z-index: 10050 !important;
}

@media (max-width: 600px) {
  .of-modal-stats {
    grid-template-columns: 1fr;
  }
  /* Keep the modal off the screen edges and readable on phones */
  .of-modal-card {
    width: calc(100% - 1.5rem);
    max-width: 480px;
    padding: 1.15rem 1rem;
    max-height: 88dvh;
  }
  .of-modal-head h3 {
    font-size: 1.2rem;
  }
  /* Toasts span the width instead of a 360px column pinned to the corner */
  #of-toast-holder {
    top: 0.9rem;
    left: 1rem;
    right: 1rem;
  }
  .of-toast {
    max-width: none;
  }
}

/* ---------- Event Cards Grid ---------- */
.of-events-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(290px, 1fr));
  gap: 1.15rem;
}

.of-event-card {
  background: var(--bg-surface);
  border: 1px solid var(--border-default);
  border-radius: var(--radius-md, 8px);
  padding: 1.25rem;
  cursor: pointer;
  transition: border-color var(--transition), transform var(--transition), box-shadow var(--transition);
  position: relative;
  display: flex;
  flex-direction: column;
}

.of-event-card:hover {
  border-color: var(--accent);
  transform: translateY(-2px);
  box-shadow: var(--shadow-card-hover);
}

.of-event-card h4 {
  font-size: 1rem;
  font-weight: 700;
  color: var(--text-primary);
  margin: 0.5rem 0 0.25rem;
}

.of-event-card .of-event-date {
  font-size: 0.75rem;
  color: var(--text-secondary);
  display: flex;
  align-items: center;
  gap: 0.35rem;
  margin-bottom: 0.5rem;
}

.of-event-card p {
  font-size: 0.82rem;
  color: var(--text-secondary);
  margin-bottom: 0.85rem;
  line-height: 1.4;
  flex: 1;
}

.of-budget-bar {
  height: 6px;
  border-radius: 999px;
  background: var(--bg-surface-raised);
  border: 1px solid var(--border-default);
  overflow: hidden;
  margin-bottom: 0.45rem;
}

.of-budget-fill {
  height: 100%;
  background: var(--accent);
  border-radius: 999px;
  transition: width 0.5s ease;
}

.of-budget-fill.over {
  background: var(--status-negative);
}

.of-budget-labels {
  display: flex;
  justify-content: space-between;
  font-size: 0.74rem;
  color: var(--text-secondary);
  font-family: var(--font-digits, inherit);
  font-variant-numeric: tabular-nums;
}

.of-over-note {
  margin-top: 0.45rem;
  font-size: 0.74rem;
  color: var(--status-negative);
  font-weight: 600;
}

.of-event-actions {
  display: flex;
  gap: 0.5rem;
  flex-wrap: wrap;
  margin-top: 0.9rem;
  padding-top: 0.75rem;
  border-top: 1px solid var(--border-default);
}

.of-event-actions .of-btn {
  padding: 0.4rem 0.75rem;
  font-size: 0.76rem;
}

.of-transfer-preview {
  padding: 0.9rem 1rem;
  background: var(--bg-surface-raised);
  border: 1px dashed var(--border-default);
  border-radius: var(--radius-sm, 6px);
  font-size: 0.82rem;
  display: flex;
  justify-content: space-between;
  gap: 1rem;
  flex-wrap: wrap;
  color: var(--text-primary);
  animation: ofFade 0.3s ease;
}

.of-transfer-preview strong {
  font-family: var(--font-digits, inherit);
  font-variant-numeric: tabular-nums;
}

.of-event-balance {
  font-size: 0.9rem;
  color: var(--text-secondary);
  line-height: 1.65;
}

.of-event-balance strong {
  color: var(--text-primary);
  font-family: var(--font-digits, inherit);
  font-variant-numeric: tabular-nums;
}

/* ---------- Scrollable List Items (Alerts, Recent, Announcements) ---------- */
.of-scrollable-list {
  max-height: 280px;
  overflow-y: auto;
  padding-right: 0.3rem;
}

.of-alert-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 0.75rem;
  padding: 0.7rem 0;
  border-bottom: 1px solid var(--border-default);
  font-size: 0.84rem;
  color: var(--text-primary);
}

.of-alert-item:last-child {
  border-bottom: none;
}

.of-alert-item.is-over strong {
  color: var(--status-negative);
  font-weight: 700;
}

.of-recent-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 0.75rem;
  padding: 0.7rem 0;
  border-bottom: 1px solid var(--border-default);
  font-size: 0.84rem;
  color: var(--text-primary);
}

.of-recent-item:last-child {
  border-bottom: none;
}

/* Long descriptions shrink and ellipsize instead of pushing the amount out */
.of-recent-item .of-recent-main {
  min-width: 0;
}

.of-recent-item .of-recent-desc {
  font-weight: 600;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.of-recent-item .is-neg {
  color: var(--status-negative);
  font-weight: 700;
  font-family: var(--font-digits, inherit);
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

.of-recent-item .is-pos {
  color: var(--status-positive);
  font-weight: 700;
  font-family: var(--font-digits, inherit);
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

.of-recent-item .of-when {
  color: var(--text-tertiary);
  font-size: 0.72rem;
  margin-top: 0.15rem;
  display: block;
}

.of-announce-item {
  padding: 0.75rem 0;
  border-bottom: 1px solid var(--border-default);
  font-size: 0.86rem;
}

.of-announce-item:last-child {
  border-bottom: none;
}

.of-announce-item strong {
  display: block;
  color: var(--text-primary);
}

.of-announce-item p {
  color: var(--text-secondary);
  margin-top: 0.25rem;
  line-height: 1.45;
}

.of-announce-item .of-when {
  color: var(--text-tertiary);
  font-size: 0.72rem;
  margin-top: 0.35rem;
  display: block;
}

/* ---------- Receipts Chip ---------- */
.receipt-attach-row {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  flex-wrap: wrap;
}

.receipt-chip {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  font-size: 0.76rem;
  padding: 0.35rem 0.7rem;
  border: 1px solid var(--border-default);
  border-radius: 999px;
  background: var(--bg-surface-raised);
  color: var(--text-primary);
  animation: ofFade 0.3s ease;
}

.receipt-chip.hidden {
  display: none;
}

.receipt-chip-remove {
  background: none;
  border: none;
  color: var(--text-secondary);
  font-size: 1.1rem;
  line-height: 1;
  cursor: pointer;
  display: flex;
  align-items: center;
}

.receipt-chip-remove:hover {
  color: var(--status-negative);
}

/* ---------- Gate / Restricted Screen ---------- */
.of-gate {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 1rem;
  text-align: center;
  color: var(--text-secondary);
  padding: 1.5rem;
  background: var(--bg-base);
}

.of-gate h2 {
  font-family: var(--font-ui);
  font-size: 1.6rem;
  color: var(--text-primary);
  font-weight: 700;
}

.of-gate p {
  max-width: 420px;
  font-size: 0.95rem;
  line-height: 1.5;
}

.of-gate iconify-icon {
  color: var(--status-warning);
}

/* ---------- Toasts ---------- */
#of-toast-holder {
  position: fixed;
  top: 1.25rem;
  right: 1.25rem;
  z-index: 10001;
  display: flex;
  flex-direction: column;
  gap: 0.6rem;
}

.of-toast {
  background: var(--bg-surface-elevated, var(--bg-surface));
  color: var(--text-primary);
  padding: 0.8rem 1.1rem;
  border-radius: var(--radius-md, 8px);
  font-size: 0.85rem;
  font-weight: 500;
  border: 1px solid var(--border-default);
  box-shadow: var(--shadow-popover);
  animation: ofToastIn 0.25s cubic-bezier(0.16, 1, 0.3, 1);
  max-width: 360px;
}

.of-toast.success { border-left: 4px solid var(--status-positive); }
.of-toast.error   { border-left: 4px solid var(--status-negative); }
.of-toast.warning { border-left: 4px solid var(--status-warning); }

@keyframes ofToastIn {
  from { opacity: 0; transform: translateX(16px); }
  to   { opacity: 1; transform: translateX(0); }
}

/* ---------- Responsive ---------- */

/* Small tablets (≤1024px): main.css forces .dashboard-grid to two tracks here,
   but the portal sidebar is still visible and the charts get cramped — keep
   single-column dashboards and stacked record layout until the sidebar leaves */
@media (max-width: 1024px) {
  .dashboard-grid,
  .of-cards {
    grid-template-columns: 1fr;
  }
  .of-record-layout {
    grid-template-columns: 1fr;
  }
}

/* ---------- Mobile Header ---------- */
.of-mobile-header {
  display: none;
}

/* ---------- Mobile Layout & Navigation ---------- */
.of-bottom-nav {
  display: none;
}

@media (max-width: 900px) {
  .of-shell {
    position: fixed !important;
    inset: 0 !important;
    width: 100% !important;
    height: 100% !important;
    max-height: none !important;
    min-height: 0 !important;
    flex-direction: column !important;
    overflow: hidden !important;
    z-index: 1 !important;
  }
  .of-sidebar {
    display: none !important;
  }
  .of-mobile-header {
    display: flex !important;
    align-items: center;
    justify-content: space-between;
    padding: calc(0.75rem + env(safe-area-inset-top, 0px)) calc(1rem + env(safe-area-inset-right, 0px)) 0.75rem calc(1rem + env(safe-area-inset-left, 0px)) !important;
    min-height: calc(56px + env(safe-area-inset-top, 0px));
    background: var(--bg-surface);
    border-bottom: 1px solid var(--border-default);
    position: sticky;
    top: 0;
    z-index: 100;
    gap: 0.75rem;
    width: 100% !important;
    box-sizing: border-box !important;
    flex-shrink: 0 !important;
  }
  .of-mobile-brand {
    display: flex;
    align-items: center;
    gap: 0.65rem;
  }
  .of-mobile-logo {
    width: 32px;
    height: 32px;
    object-fit: contain;
    border-radius: 6px;
  }
  .of-mobile-brand h2 {
    font-size: 0.95rem;
    font-weight: 700;
    margin: 0;
    color: var(--text-primary);
    letter-spacing: -0.01em;
    line-height: 1.2;
  }
  .of-mobile-role {
    display: inline-block;
    font-size: 0.68rem;
    font-weight: 700;
    color: var(--primary-hover);
    background: rgba(249, 115, 22, 0.15);
    border: 1px solid rgba(249, 115, 22, 0.35);
    padding: 0.1rem 0.45rem;
    border-radius: 999px;
    letter-spacing: 0.02em;
  }
  [data-theme="light"] .of-mobile-role {
    color: #EA580C;
    background: #FFF7ED;
    border-color: #FFEDD5;
  }
  .of-mobile-actions {
    display: flex;
    align-items: center;
    gap: 0.25rem;
  }
  .of-mobile-actions .btn-icon {
    width: 36px;
    height: 36px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    border-radius: 50%;
    background: transparent;
    border: none;
    color: var(--text-secondary);
    font-size: 1.25rem;
    text-decoration: none;
    cursor: pointer;
    transition: all 0.18s ease;
  }
  .of-mobile-actions .btn-icon:hover,
  .of-mobile-actions .btn-icon:active {
    color: var(--text-primary);
    background: rgba(255, 255, 255, 0.08);
  }
  [data-theme="light"] .of-mobile-actions .btn-icon:hover,
  [data-theme="light"] .of-mobile-actions .btn-icon:active {
    background: rgba(0, 0, 0, 0.06);
  }
  .of-mobile-actions .of-logout-action:hover,
  .of-mobile-actions .of-logout-action:active,
  .sidebar-actions .of-logout-action:hover,
  .sidebar-actions .of-logout-action:active {
    color: var(--status-negative);
    background: rgba(239, 68, 68, 0.12);
  }

  .of-main {
    height: 100% !important;
    min-height: 0 !important;
    flex: 1 1 0% !important;
    width: 100% !important;
    max-width: 100% !important;
    overflow-y: auto !important;
    overflow-x: hidden !important;
    -webkit-overflow-scrolling: touch !important;
    touch-action: pan-y pinch-zoom !important;
    overscroll-behavior-y: contain;
    /* Clean scroll clearance: 58px floating nav + 12px float gap + safe-area inset */
    padding-bottom: calc(78px + env(safe-area-inset-bottom, 14px)) !important;
  }

  .of-view {
    width: 100% !important;
    box-sizing: border-box !important;
    padding: 0 0.85rem 0 !important;
  }

  .of-view > *:last-child,
  .of-cards:last-child,
  .dashboard-grid:last-child {
    margin-bottom: 0 !important;
  }

  /* Prevent iOS zoom on inputs */
  body input,
  body select,
  body textarea,
  .of-field input,
  .of-field select,
  .of-field textarea,
  .of-sort-select {
    font-size: 16px !important;
  }
  .of-view-head {
    padding-top: 1rem;
    margin-bottom: 1rem;
  }

  .of-bottom-nav {
    display: flex !important;
    position: fixed !important;
    /* Floating-tab offset shared with .bottom-nav.visible (main.css) — both
       portals identical. max() parks the pill directly on top of the iPhone
       home-indicator zone in the standalone PWA (no extra gap below it) and
       keeps the plain 10px float in browsers where the inset is 0 */
    bottom: max(env(safe-area-inset-bottom, 0px), 10px) !important;
    left: 10px !important;
    right: 10px !important;
    width: auto !important;
    max-width: 480px !important;
    margin: 0 auto !important;
    z-index: 1000 !important;
    box-sizing: border-box !important;
    
    background: rgba(17, 24, 32, 0.9) !important;
    backdrop-filter: blur(24px) saturate(180%) !important;
    -webkit-backdrop-filter: blur(24px) saturate(180%) !important;
    border: 1px solid rgba(255, 255, 255, 0.1) !important;
    border-radius: 30px !important;
    padding: 4px 4px !important;
    justify-content: space-around !important;
    align-items: center !important;
    gap: 2px !important;
    
    box-shadow: 
      0 12px 36px -4px rgba(0, 0, 0, 0.5),
      0 4px 14px rgba(0, 0, 0, 0.25),
      inset 0 1px 1px rgba(255, 255, 255, 0.12) !important;
    overflow: visible !important;
    transition: transform 0.32s cubic-bezier(0.16, 1, 0.3, 1), opacity 0.25s ease, background 0.2s ease !important;
    will-change: transform, opacity !important;
  }

  .of-bottom-nav.nav-hidden,
  body.ursa-open .of-bottom-nav,
  body:has(#ursa-drawer.active) .of-bottom-nav {
    transform: translateY(calc(100% + 40px + env(safe-area-inset-bottom, 0px))) !important;
    opacity: 0 !important;
    pointer-events: none !important;
    visibility: hidden !important;
  }

  [data-theme="light"] .of-bottom-nav {
    background: rgba(255, 255, 255, 0.92) !important;
    border: 1px solid rgba(0, 0, 0, 0.08) !important;
    box-shadow: 
      0 12px 36px -4px rgba(0, 0, 0, 0.12),
      0 4px 12px rgba(0, 0, 0, 0.06),
      inset 0 1px 1px rgba(255, 255, 255, 0.8) !important;
  }

  .of-bottom-nav > button,
  .of-bottom-nav > a {
    flex: 1 1 0% !important;
    min-width: 0 !important;
    height: 48px !important;
    padding: 3px 1px !important;
    border-radius: 12px !important;
    color: var(--text-tertiary) !important;
    background: none !important;
    border: none !important;
    display: flex !important;
    flex-direction: column !important;
    align-items: center !important;
    justify-content: center !important;
    cursor: pointer !important;
    position: relative !important;
    touch-action: manipulation !important;
    text-decoration: none !important;
    -webkit-tap-highlight-color: transparent !important;
    transition: color 0.15s ease !important;
  }

  .of-bottom-nav > button iconify-icon,
  .of-bottom-nav > a iconify-icon {
    font-size: 1.25rem !important;
    line-height: 1 !important;
    display: flex !important;
    align-items: center !important;
    justify-content: center !important;
    color: var(--text-tertiary) !important;
    transition: color 0.15s ease !important;
  }

  .of-bottom-nav > button span,
  .of-bottom-nav > a span {
    font-size: 0.68rem !important;
    font-weight: 500 !important;
    letter-spacing: 0.01em !important;
    line-height: 1.2 !important;
    margin-top: 3px !important;
    white-space: nowrap !important;
    overflow: hidden !important;
    text-overflow: ellipsis !important;
    max-width: 100% !important;
    color: var(--text-tertiary) !important;
    transition: color 0.15s ease !important;
  }

  /* Unread Executive Notification Orange Badge */
  .of-bottom-nav > button.has-unread iconify-icon,
  .of-bottom-nav > a.has-unread iconify-icon,
  .of-nav .nav-item.has-unread .nav-icon {
    position: relative !important;
  }
  .of-bottom-nav > button.has-unread iconify-icon::after,
  .of-bottom-nav > a.has-unread iconify-icon::after,
  .of-nav .nav-item.has-unread .nav-icon::after {
    content: '' !important;
    position: absolute !important;
    top: -2px !important;
    right: -3px !important;
    width: 8px !important;
    height: 8px !important;
    border-radius: 50% !important;
    background: var(--primary) !important;
    border: 1.5px solid var(--bg-surface, #0E1520) !important;
  }

  /* Sliding Active Indicator removed - only the icon is orange */
  .of-bottom-nav .of-bottom-nav-indicator {
    display: none !important;
  }

  .of-bottom-nav > button.active,
  [data-theme="light"] .of-bottom-nav > button.active {
    background: none !important;
  }

  .of-bottom-nav > button.active iconify-icon {
    color: var(--primary) !important;
    transform: none !important;
    filter: none !important;
  }

  .of-bottom-nav > button.active span {
    font-weight: 600 !important;
    color: var(--text-primary) !important;
  }

  /* Main System Link Special Highlight */
  .of-bottom-nav > a.of-nav-link-main {
    color: var(--text-tertiary) !important;
  }
  .of-bottom-nav > a.of-nav-link-main iconify-icon {
    color: var(--primary) !important;
  }
  .of-bottom-nav > a.of-nav-link-main:active {
    background: none !important;
  }

  /* Tap Interaction */
  .of-bottom-nav > button:active,
  .of-bottom-nav > a:active {
    transform: scale(0.96) !important;
  }

  .of-form-row {
    grid-template-columns: 1fr;
    gap: 0.75rem;
  }
  .of-filter-bar {
    flex-direction: column;
    align-items: stretch;
  }

  /* Executive More Button Micro-interaction */
  #of-bottom-nav-more-btn {
    transition: transform 0.2s cubic-bezier(0.34, 1.56, 0.64, 1), background 0.2s ease, color 0.2s ease !important;
  }
  #of-bottom-nav-more-btn:active {
    transform: scale(0.88) !important;
  }
  #of-bottom-nav-more-btn[aria-expanded="true"] iconify-icon {
    transform: rotate(90deg) scale(1.12) !important;
    color: var(--primary) !important;
    transition: transform 0.3s cubic-bezier(0.34, 1.56, 0.64, 1), color 0.2s ease !important;
  }
  #of-bottom-nav-more-btn:not([aria-expanded="true"]) iconify-icon {
    transition: transform 0.25s cubic-bezier(0.16, 1, 0.3, 1), color 0.2s ease !important;
  }
}

/* ---------- 2x2 Grid for Stat Cards on Medium Screens (≤1024px) ---------- */
@media (max-width: 1024px) {
  .of-stat-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 0.85rem;
    width: 100%;
    max-width: 100%;
    box-sizing: border-box;
  }
  .of-stat {
    min-width: 0;
    max-width: 100%;
    box-sizing: border-box;
  }
}

/* ---------- 2x2 Grid for Stat Cards on Mobile (≤640px) ---------- */
@media (max-width: 640px) {
  .of-stat-grid {
    display: grid !important;
    grid-template-columns: repeat(2, minmax(0, 1fr)) !important;
    gap: 0.5rem !important;
    margin-bottom: 1rem !important;
    width: 100% !important;
    max-width: 100% !important;
    box-sizing: border-box !important;
  }
  .of-stat {
    min-width: 0 !important;
    max-width: 100% !important;
    width: 100% !important;
    box-sizing: border-box !important;
    padding: 0.65rem 0.5rem !important;
    border-radius: var(--radius-md, 8px) !important;
    touch-action: manipulation !important;
    -webkit-tap-highlight-color: transparent !important;
  }
  .of-stat .of-stat-label {
    font-size: clamp(0.56rem, 2.3vw, 0.62rem) !important;
    letter-spacing: 0.03em !important;
    min-width: 0 !important;
    max-width: 100% !important;
  }
  .of-stat .of-stat-label > span:first-child {
    min-width: 0 !important;
    overflow: hidden !important;
    text-overflow: ellipsis !important;
    white-space: nowrap !important;
  }
  .of-stat .of-stat-value {
    font-size: clamp(0.82rem, 3.4vw, 1.05rem) !important;
    margin-top: 0.2rem !important;
    line-height: 1.2 !important;
    min-width: 0 !important;
    max-width: 100% !important;
    overflow: visible !important;
    text-overflow: clip !important;
    white-space: nowrap !important;
  }
  .of-stat .of-stat-sub {
    font-size: 0.6rem !important;
    margin-top: 0.15rem !important;
    white-space: nowrap !important;
    overflow: hidden !important;
    text-overflow: ellipsis !important;
    min-width: 0 !important;
    max-width: 100% !important;
  }
}

/* ---------- Small Phones (≤480px) ---------- */
@media (max-width: 480px) {
  .of-view {
    padding-left: 0.85rem;
    padding-right: 0.85rem;
  }
  .of-view-head {
    position: static !important;
    background: transparent !important;
    border-bottom: none !important;
    margin-bottom: 0.75rem !important;
    padding-top: 0.75rem !important;
  }
  .of-view-head h2 {
    font-size: 1.3rem;
  }
  .of-card {
    padding: 1rem !important;
  }
  .of-field {
    margin-bottom: 0.75rem !important;
  }
  .of-field label {
    font-size: 0.8rem !important;
    margin-bottom: 0.25rem !important;
  }
  .of-field input,
  .of-field select,
  .of-field textarea {
    padding: 0.65rem 0.85rem !important;
  }
  .of-record-layout {
    grid-template-columns: 1fr !important;
    gap: 1rem !important;
  }
  .of-chart-box {
    height: 300px !important;
    min-height: 300px !important;
  }
  /* The 290px event-card track overflows 320px screens — force single column */
  .of-events-grid {
    grid-template-columns: 1fr;
  }
  /* Search and sort stack so neither is squeezed off-screen */
  .of-filter-tools {
    flex-direction: column;
    align-items: stretch;
  }
  .of-filter-tools .of-sort-select {
    width: 100%;
  }
  .of-table th,
  .of-table td {
    padding: 0.6rem 0.7rem;
    font-size: 0.8rem;
  }
  /* Full-width action buttons inside event cards = comfortable tap targets */
  .of-event-actions .of-btn {
    flex: 1 1 auto;
  }
  .of-transfer-preview {
    flex-direction: column;
    gap: 0.5rem;
  }
}

/* ---------- Enrolled Roster Mobile Responsiveness & Polish ---------- */
@media (max-width: 768px) {
  .of-view-head {
    flex-direction: column;
    align-items: flex-start;
    gap: 0.85rem;
  }
  .of-header-actions {
    width: 100%;
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem;
  }
}

@media (max-width: 640px) {
  .of-header-actions {
    display: grid !important;
    grid-template-columns: 1fr 1fr;
    gap: 0.5rem;
    width: 100%;
  }
  .of-header-actions #of-roster-add-btn {
    grid-column: 1 / -1;
    justify-content: center;
  }
  .of-header-actions .of-btn {
    justify-content: center;
    padding: 0.5rem 0.6rem;
    font-size: 0.8rem;
  }
  .of-filter-bar {
    flex-direction: column;
    align-items: stretch;
    gap: 0.65rem;
  }
  .of-filter-tabs {
    width: 100%;
    display: flex;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
  }
  .of-filter-btn {
    flex: 1;
    text-align: center;
    white-space: nowrap;
    padding: 0.35rem 0.4rem;
    font-size: 0.75rem;
  }
  #of-roster-year-filter {
    width: 100% !important;
  }
  .of-pagination {
    flex-direction: column;
    align-items: center;
    text-align: center;
    gap: 0.6rem;
  }
}
