/* Military theme redesign. Loaded last so it owns the app look. */
:root {
  --topbar-height: 66px;
  --bottom-nav-height: 76px;
  --sidebar-width: 260px;
  --sidebar-collapsed-width: 84px;
  --radius: 8px;
  --font-ui: "Segoe UI", "Helvetica Neue", ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, Arial, sans-serif;
  --font-display: "Trebuchet MS", "Segoe UI", "Arial Narrow", Arial, sans-serif;
  --nav-active-glow: rgba(141, 211, 81, 0.34);
  --nav-active-border: rgba(176, 229, 111, 0.5);
  --nav-hover-surface: rgba(124, 153, 86, 0.12);
  --nav-glass: rgba(255, 255, 255, 0.035);
  --nav-item-bg: rgba(255, 255, 255, 0.06);
  --nav-item-border: rgba(255, 255, 255, 0.078);
  --nav-item-shadow: 0 12px 28px rgba(0, 0, 0, 0.22);
  --nav-item-shadow-hover: 0 18px 38px rgba(0, 0, 0, 0.26);
  --nav-item-inner: inset 0 1px 0 rgba(255, 255, 255, 0.055);
  --nav-inactive-opacity: 0.74;
  --nav-active-fill-top: rgba(156, 212, 92, 0.48);
  --nav-active-fill-bottom: rgba(87, 129, 44, 0.28);
  --nav-indicator: linear-gradient(180deg, rgba(223, 250, 184, 0.98), rgba(113, 178, 54, 0.78));
  --page-header-bg: linear-gradient(135deg, rgba(255, 255, 255, 0.045), rgba(255, 255, 255, 0.01));
  --page-header-border: rgba(210, 229, 154, 0.12);
  --chip-success-bg: rgba(112, 179, 78, 0.18);
  --chip-success-text: #dff2c7;
  --chip-warning-bg: rgba(187, 154, 67, 0.2);
  --chip-warning-text: #f5e2a5;
  --chip-danger-bg: rgba(176, 85, 85, 0.18);
  --chip-danger-text: #ffd2d2;
}

html[data-theme="dark"],
:root:not([data-theme]) {
  color-scheme: dark;
  --bg-base: #080d08;
  --bg-page: #0b1009;
  --bg-camo-1: #0d160b;
  --bg-camo-2: #172312;
  --bg-camo-3: #26371c;
  --bg-camo-4: #43542b;
  --panel: #11180f;
  --panel-strong: #162015;
  --panel-soft: rgba(16, 23, 15, 0.9);
  --surface: rgba(215, 219, 187, 0.055);
  --surface-strong: rgba(215, 219, 187, 0.095);
  --text-main: #f2f6ea;
  --text-soft: #aeb99a;
  --text-faint: #7b866f;
  --brand: #c8cf86;
  --primary: #6c7f46;
  --primary-hover: #7a8d50;
  --primary-deep: #4c5f33;
  --accent: #b59c63;
  --danger: #985347;
  --danger-hover: #7c4239;
  --border-color: rgba(200, 207, 134, 0.18);
  --card-border: rgba(200, 207, 134, 0.12);
  --shadow-card: 0 18px 48px rgba(0, 0, 0, 0.34);
  --shadow-panel: 0 12px 30px rgba(0, 0, 0, 0.26);
  --camo-image: url("../../assets/themes/darkTheme.jpg");
  --page-accent: rgba(108, 127, 70, 0.11);
  --nav-active-glow: rgba(151, 177, 94, 0.2);
  --nav-active-border: rgba(181, 196, 116, 0.34);
  --nav-hover-surface: rgba(104, 121, 73, 0.12);
  --nav-active-fill-top: rgba(142, 163, 88, 0.38);
  --nav-active-fill-bottom: rgba(79, 98, 50, 0.22);
  --chip-success-bg: rgba(108, 127, 70, 0.2);
  --chip-success-text: #e4ebc8;
  --chip-warning-bg: rgba(168, 143, 83, 0.22);
  --chip-warning-text: #f0e0b0;
  --chip-danger-bg: rgba(152, 83, 71, 0.22);
  --chip-danger-text: #f7d7d0;
}

html[data-theme="light"] {
  color-scheme: light;
  --bg-base: #e7e3da;
  --bg-page: #f1ede4;
  --bg-camo-1: #efebe2;
  --bg-camo-2: #d2cec3;
  --bg-camo-3: #9da39a;
  --bg-camo-4: #545b54;
  --panel: #f7f3eb;
  --panel-strong: #fcfaf4;
  --panel-soft: rgba(248, 244, 236, 0.9);
  --surface: rgba(71, 78, 65, 0.062);
  --surface-strong: rgba(71, 78, 65, 0.11);
  --text-main: #1d2320;
  --text-soft: #596057;
  --text-faint: #7f867d;
  --brand: #2f5a36;
  --primary: #486b3b;
  --primary-hover: #5a8149;
  --accent: #8d7a59;
  --danger: #a2443a;
  --danger-hover: #83372f;
  --border-color: rgba(67, 75, 64, 0.14);
  --card-border: rgba(67, 75, 64, 0.1);
  --shadow-card: 0 18px 44px rgba(77, 82, 68, 0.12);
  --shadow-panel: 0 10px 26px rgba(77, 82, 68, 0.1);
  --camo-image: url("../../assets/themes/lightTheme.jpg");
  --nav-active-glow: rgba(84, 122, 78, 0.08);
  --nav-active-border: rgba(92, 124, 76, 0.22);
  --nav-hover-surface: rgba(76, 88, 79, 0.045);
  --nav-glass: rgba(255, 255, 255, 0.48);
  --nav-item-bg: rgba(255, 255, 255, 0.82);
  --nav-item-border: rgba(70, 74, 71, 0.065);
  --nav-item-shadow: 0 10px 24px rgba(62, 64, 62, 0.06);
  --nav-item-shadow-hover: 0 16px 28px rgba(62, 64, 62, 0.09);
  --nav-item-inner: inset 0 1px 0 rgba(255, 255, 255, 0.92);
  --nav-inactive-opacity: 0.86;
  --nav-active-fill-top: rgba(198, 213, 179, 0.82);
  --nav-active-fill-bottom: rgba(171, 191, 148, 0.58);
  --nav-indicator: linear-gradient(180deg, rgba(91, 126, 73, 0.94), rgba(63, 95, 55, 0.82));
  --page-header-bg: linear-gradient(135deg, rgba(251, 248, 241, 0.9), rgba(241, 236, 224, 0.82));
  --page-header-border: rgba(72, 89, 62, 0.1);
  --chip-success-bg: rgba(100, 151, 78, 0.14);
  --chip-success-text: #295033;
  --chip-warning-bg: rgba(162, 133, 73, 0.18);
  --chip-warning-text: #694d1f;
  --chip-danger-bg: rgba(173, 96, 87, 0.16);
  --chip-danger-text: #7c2e2e;
  --page-accent: rgba(88, 112, 72, 0.09);
}

html {
  scroll-behavior: smooth;
}

body {
  min-height: 100vh;
  font-family: var(--font-ui);
  color: var(--text-main);
  background-color: var(--bg-base);
  background-image:
    linear-gradient(145deg, var(--bg-page), var(--bg-base));
  background-size: auto;
  background-attachment: fixed;
  -webkit-font-smoothing: antialiased;
}

html[dir="rtl"] body {
  direction: rtl;
}

html[dir="rtl"] input[type="email"],
html[dir="rtl"] input[type="number"],
html[dir="rtl"] input[type="date"],
html[dir="rtl"] input[type="time"],
html[dir="rtl"] input[type="month"],
html[dir="rtl"] #chatUserSearchInput,
html[dir="rtl"] #userSearchInput,
html[dir="rtl"] #messageInput {
  direction: ltr;
  text-align: left;
}

body::before {
  content: "";
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: -1;
  background:
    linear-gradient(90deg, rgba(255, 255, 255, 0.022) 1px, transparent 1px),
    linear-gradient(0deg, rgba(255, 255, 255, 0.018) 1px, transparent 1px);
  background-size: 52px 52px;
  opacity: 0.02;
  mix-blend-mode: overlay;
}

button,
input,
textarea,
select {
  font: inherit;
  border-radius: var(--radius);
}

button {
  -webkit-tap-highlight-color: transparent;
}

button:focus-visible,
input:focus-visible,
textarea:focus-visible,
select:focus-visible {
  outline: 3px solid rgba(120, 154, 69, 0.34);
  outline-offset: 2px;
}

.topbar {
  height: var(--topbar-height);
  border-bottom: 1px solid var(--border-color);
  background:
    linear-gradient(90deg, rgba(0, 0, 0, 0.04), transparent),
    var(--camo-image),
    var(--panel-soft);
  background-size: auto, 1180px 760px, auto;
  color: var(--text-main);
  backdrop-filter: blur(18px) saturate(1.1);
  box-shadow: var(--shadow-panel);
}

html[data-theme="dark"] body {
  background-image:
    linear-gradient(180deg, rgba(7, 11, 7, 0.22), rgba(7, 11, 7, 0.08)),
    linear-gradient(145deg, var(--bg-page), var(--bg-base));
}

html[data-theme="dark"] .topbar {
  background:
    linear-gradient(180deg, rgba(7, 11, 7, 0.82), rgba(10, 15, 9, 0.66)),
    linear-gradient(90deg, rgba(6, 9, 6, 0.28), rgba(6, 9, 6, 0.1)),
    var(--camo-image),
    var(--panel-soft);
  background-size: auto, auto, 1180px 320px, auto;
  background-position: center, center, center top, center;
  background-repeat: no-repeat, no-repeat, repeat-x, no-repeat;
  border-bottom-color: rgba(200, 207, 134, 0.16);
}

html[data-theme="dark"] .sidebar {
  background:
    linear-gradient(180deg, rgba(8, 12, 8, 0.9), rgba(11, 16, 9, 0.92)),
    linear-gradient(90deg, rgba(8, 12, 8, 0.34), rgba(8, 12, 8, 0.12)),
    var(--camo-image),
    var(--panel-soft);
  background-size: auto, auto, 420px 300px, auto;
  background-position: center top, center top, center top, center top;
  background-repeat: no-repeat, no-repeat, repeat, no-repeat;
  border-right-color: rgba(200, 207, 134, 0.14);
}

html[data-theme="dark"] .menu-toggle,
html[data-theme="dark"] .theme-toggle-btn {
  background: rgba(12, 18, 11, 0.78);
  border-color: rgba(200, 207, 134, 0.18);
  color: #f2f6ea;
  box-shadow:
    0 10px 22px rgba(0, 0, 0, 0.18),
    inset 0 1px 0 rgba(255, 255, 255, 0.05);
}

html[data-theme="dark"] .brand,
html[data-theme="dark"] .user-email,
html[data-theme="dark"] .role-badge {
  text-shadow: 0 1px 2px rgba(0, 0, 0, 0.45);
}

@media (min-width: 769px) {
  .topbar {
    height: 88px;
    min-height: 88px;
    padding: 0 20px;
  }

  .topbar-left,
  .auth-header {
    min-height: 88px;
  }

  html[data-theme="dark"] .topbar {
    background:
      linear-gradient(180deg, rgba(7, 11, 7, 0.76), rgba(10, 15, 9, 0.58)),
      linear-gradient(90deg, rgba(6, 9, 6, 0.2), rgba(6, 9, 6, 0.06)),
      var(--camo-image),
      var(--panel-soft);
    background-size: auto, auto, 1380px 420px, auto;
    background-position: center, center, center top, center;
    background-repeat: no-repeat, no-repeat, repeat-x, no-repeat;
    backdrop-filter: blur(14px) saturate(1.06);
  }

  html[data-theme="light"] .topbar {
    background:
      linear-gradient(90deg, rgba(250, 248, 242, 0.76) 0%, rgba(250, 248, 242, 0.68) 34%, rgba(250, 248, 242, 0.5) 48%, rgba(250, 248, 242, 0.68) 64%, rgba(250, 248, 242, 0.8) 100%),
      linear-gradient(180deg, rgba(255, 255, 255, 0.06), rgba(255, 255, 255, 0.01)),
      var(--camo-image),
      linear-gradient(180deg, #f6f3ec, #ece8de) !important;
    background-size: auto, auto, 1260px 250px, auto !important;
    background-position: center center, center center, center top, center center !important;
    background-repeat: no-repeat, no-repeat, repeat-x, no-repeat !important;
  }
}

.brand {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  color: var(--brand);
  font-size: 20px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.brand::before {
  content: "";
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: var(--accent);
  box-shadow: 0 0 0 4px rgba(195, 163, 93, 0.18);
}

.theme-toggle-btn {
  min-height: 40px;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  border: 1px solid var(--border-color);
  background: var(--surface);
  color: var(--text-main);
  padding: 8px 12px;
  cursor: pointer;
  font-weight: 800;
}

.theme-toggle-btn:hover {
  background: var(--surface-strong);
}

.menu-toggle,
.user-box-header button,
.action-btn,
.small-btn,
.green-btn,
#backToUsersBtn,
#sendMessageBtn,
.attach-file-btn {
  min-height: 44px;
  border-radius: var(--radius) !important;
  box-shadow: none !important;
}

.menu-toggle,
.theme-toggle-btn {
  border-color: var(--border-color);
  background: var(--surface);
  color: var(--text-main);
}

.action-btn,
.green-btn,
.user-box-header button,
.small-btn.promote-btn,
#backToUsersBtn,
#sendMessageBtn {
  border: 1px solid rgba(255, 255, 255, 0.08);
  background: linear-gradient(180deg, var(--primary), var(--primary-deep, #3f5f28)) !important;
  color: #fff !important;
  font-weight: 850;
}

.action-btn:hover,
.green-btn:hover,
.user-box-header button:hover,
.small-btn.promote-btn:hover,
#backToUsersBtn:hover,
#sendMessageBtn:hover {
  background: linear-gradient(180deg, var(--primary-hover), var(--primary)) !important;
  transform: translateY(-1px);
}

#logoutBtn {
  border: 1px solid rgba(210, 203, 136, 0.18) !important;
  background: linear-gradient(180deg, rgba(78, 94, 48, 0.96), rgba(56, 68, 34, 0.98)) !important;
  color: #f4eed3 !important;
  box-shadow:
    inset 0 1px 0 rgba(255, 255, 255, 0.06),
    0 10px 20px rgba(0, 0, 0, 0.18) !important;
}

#logoutBtn:hover {
  background: linear-gradient(180deg, rgba(92, 111, 57, 0.98), rgba(63, 78, 38, 0.98)) !important;
  color: #fff7dc !important;
}

button:disabled,
.action-btn:disabled,
.small-btn:disabled,
.green-btn:disabled,
#backToUsersBtn:disabled,
#sendMessageBtn:disabled,
.attach-file-btn:disabled {
  opacity: 1 !important;
  cursor: not-allowed !important;
  transform: none !important;
  border-color: rgba(127, 141, 116, 0.26) !important;
  background: linear-gradient(180deg, rgba(113, 124, 101, 0.34), rgba(73, 84, 65, 0.28)) !important;
  color: var(--text-faint) !important;
  box-shadow: none !important;
  filter: grayscale(0.55) saturate(0.65);
}

button:disabled:hover,
.action-btn:disabled:hover,
.small-btn:disabled:hover,
.green-btn:disabled:hover,
#backToUsersBtn:disabled:hover,
#sendMessageBtn:disabled:hover,
.attach-file-btn:disabled:hover {
  background: linear-gradient(180deg, rgba(113, 124, 101, 0.34), rgba(73, 84, 65, 0.28)) !important;
  color: var(--text-faint) !important;
  transform: none !important;
}

.reset-btn,
.small-btn.demote-btn,
.cancel-upload-btn,
#removeSelectedFileBtn {
  background: linear-gradient(180deg, var(--danger), var(--danger-hover)) !important;
  color: #fff !important;
}

.app-layout {
  min-height: calc(100vh - var(--topbar-height));
}

.sidebar {
  border-right: 1px solid var(--border-color);
  background:
    linear-gradient(180deg, rgba(0, 0, 0, 0.12), rgba(0, 0, 0, 0.18)),
    var(--camo-image),
    var(--panel-soft);
  background-size: auto, 340px 250px, auto;
  background-position: center top, center top, center top;
  background-repeat: no-repeat, repeat, no-repeat;
  backdrop-filter: blur(18px) saturate(1.1);
}

.sidebar-header {
  color: var(--text-faint);
  letter-spacing: 0.16em;
}

.side-link,
.bottom-nav-link {
  color: var(--text-main);
  border-radius: var(--radius);
}

.side-link:hover,
.bottom-nav-link:hover {
  background: var(--nav-hover-surface);
}

.side-link.active-link,
.bottom-nav-link.active-link {
  border-color: var(--nav-active-border);
  background:
    linear-gradient(180deg, var(--nav-active-fill-top), var(--nav-active-fill-bottom));
  color: #f6fbe8;
  box-shadow: 0 0 0 1px rgba(212, 244, 169, 0.08) inset, 0 0 18px var(--nav-active-glow);
}

html[data-theme="light"] .side-link.active-link,
html[data-theme="light"] .bottom-nav-link.active-link {
  color: #1e2b18;
}

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

.app-avatar {
  position: relative;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 42px;
  height: 42px;
  border-radius: 50%;
  overflow: hidden;
  border: 1px solid var(--card-border);
  background: linear-gradient(180deg, rgba(120, 154, 69, 0.92), rgba(77, 99, 43, 0.84));
  color: #f6f8ef;
  font-weight: 800;
  letter-spacing: 0.03em;
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.18), 0 12px 24px rgba(0, 0, 0, 0.14);
}

.app-avatar-image {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

.app-avatar-fallback {
  text-transform: uppercase;
}

.app-avatar-md {
  width: 42px;
  height: 42px;
  font-size: 14px;
}

.app-avatar-xl {
  width: 84px;
  height: 84px;
  font-size: 28px;
}

.app-avatar-xxl {
  width: 104px;
  height: 104px;
  font-size: 34px;
}

.page {
  animation: page-enter 0.28s ease;
}

.page > .card,
.card,
.login-card,
.modal-card {
  border-radius: var(--radius) !important;
  border: 1px solid var(--card-border) !important;
  background:
    linear-gradient(180deg, rgba(255, 255, 255, 0.035), transparent),
    var(--panel-soft) !important;
  color: var(--text-main);
  box-shadow: var(--shadow-card) !important;
  backdrop-filter: blur(14px) saturate(1.05);
}

.top-row {
  position: relative;
  padding: 18px 18px 16px;
  border-radius: calc(var(--radius) + 6px);
  border: 1px solid var(--page-header-border);
  background:
    radial-gradient(circle at top right, var(--page-accent), transparent 38%),
    var(--page-header-bg);
}

.top-row > div:first-child h2 {
  font-family: var(--font-display);
  letter-spacing: -0.03em;
}

.top-row > div:first-child .muted {
  max-width: 62ch;
}

.inner-card,
.admin-box,
.dashboard-stat,
.financial-summary-item,
.documents-section,
.user-item,
.messages-container,
.selected-file-preview,
.chat-upload-progress-wrap {
  border-radius: var(--radius) !important;
  border-color: var(--card-border) !important;
  background: var(--surface) !important;
}

h1,
h2,
h3 {
  color: var(--text-main) !important;
  line-height: 1.15;
  letter-spacing: -0.01em;
}

h2 {
  font-size: 30px;
  font-weight: 900;
  font-family: var(--font-display);
}

h3 {
  font-size: 20px;
  font-weight: 850;
  font-family: var(--font-display);
}

.muted,
.login-subtitle,
.user-subtitle {
  color: var(--text-soft) !important;
  line-height: 1.55;
}

.user-email,
.role-badge,
.user-role-chip {
  color: var(--text-main);
}

input,
textarea,
select,
.admin-search,
#chatUserSearchInput,
#messageInput {
  min-height: 46px;
  border: 1px solid var(--card-border) !important;
  background: var(--panel-strong) !important;
  color: var(--text-main) !important;
  box-shadow: none !important;
}

.empty-state {
  border: 1px dashed var(--card-border);
  border-radius: calc(var(--radius) + 4px);
  background:
    radial-gradient(circle at top, var(--page-accent), transparent 45%),
    var(--surface);
  padding: 20px 18px;
  text-align: center;
  line-height: 1.55;
}

.status-taken,
.status-pending,
.status-neutral {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 6px 10px;
  border-radius: 999px;
  font-size: 12px;
  line-height: 1;
  font-weight: 800;
}

.status-taken {
  color: var(--chip-success-text) !important;
  background: var(--chip-success-bg);
}

.status-pending {
  color: var(--chip-warning-text) !important;
  background: var(--chip-warning-bg);
}

.status-neutral {
  color: var(--text-soft) !important;
  background: var(--surface-strong);
}

.dashboard-status-value {
  width: fit-content;
}

.empty-state strong {
  display: block;
  margin-bottom: 6px;
  color: var(--text-main);
  font-weight: 850;
}

@keyframes page-enter {
  from {
    opacity: 0;
    transform: translateY(10px);
  }

  to {
    opacity: 1;
    transform: translateY(0);
  }
}

input::placeholder,
textarea::placeholder,
.admin-search::placeholder,
#chatUserSearchInput::placeholder,
#messageInput::placeholder {
  color: var(--text-faint) !important;
}

table {
  border-radius: var(--radius);
  border-color: var(--card-border) !important;
  background: var(--panel-soft) !important;
}

th {
  background: var(--surface-strong) !important;
  color: var(--text-main) !important;
}

td {
  color: var(--text-main) !important;
  border-bottom-color: var(--card-border) !important;
}

tr:hover {
  background: var(--surface) !important;
}

.dashboard-grid,
.financial-grid,
.documents-grid,
.admin-grid {
  gap: 16px;
}

#financial > .card,
#documents > .card,
#financial .card.inner-card,
.financial-section,
.financial-summary-card,
.documents-section {
  border-radius: var(--radius) !important;
  background:
    linear-gradient(180deg, rgba(255, 255, 255, 0.035), transparent),
    var(--panel-soft) !important;
}

#financial .top-row h2,
.financial-section h3,
.financial-summary-card h3,
#financial .card.inner-card h3 {
  letter-spacing: -0.01em;
}

#financial .top-row h2 {
  font-size: 28px;
}

.financial-section h3,
.financial-summary-card h3,
#financial .card.inner-card h3 {
  font-size: 20px;
}

.financial-summary-grid {
  gap: 12px;
}

.financial-bills-header,
.documents-summary-header {
  margin-bottom: 16px;
}

.financial-bills-header h3,
.documents-summary-header h3 {
  margin-bottom: 0;
}

.dashboard-medication-actions {
  display: flex;
  flex-direction: column;
  gap: 10px;
  margin-top: 15px;
}

.medication-reminder-title {
  margin-bottom: 8px;
}

.medication-reminder-copy {
  margin-bottom: 10px;
}

.medication-reminder-copy-last {
  margin-bottom: 0;
}

.documents-field {
  grid-template-columns: 150px minmax(0, 1fr);
}

.chat-input {
  position: sticky;
  bottom: 0;
  padding-top: 10px;
  background: linear-gradient(180deg, transparent, var(--panel) 35%);
}

.message {
  border-radius: var(--radius) !important;
}

.message.sent {
  background: var(--primary) !important;
  color: #fff !important;
}

.message.received {
  background: var(--surface-strong) !important;
  color: var(--text-main) !important;
}

.chat-badge {
  background: var(--accent) !important;
  color: #111;
}

html[data-theme="light"] .topbar,
html[data-theme="light"] .sidebar,
html[data-theme="light"] .bottom-nav {
  background-color: rgba(251, 250, 243, 0.92) !important;
}

html[data-theme="light"] .action-btn,
html[data-theme="light"] .green-btn,
html[data-theme="light"] .user-box-header button,
html[data-theme="light"] #sendMessageBtn,
html[data-theme="light"] #backToUsersBtn {
  color: #fff !important;
}

@media (min-width: 901px) {
  #sidebarOutlet {
    align-self: stretch;
  }

  .sidebar {
    position: relative;
    top: auto;
    height: auto;
    align-self: stretch;
    min-height: calc(100vh - var(--topbar-height));
    flex: 1 0 auto;
  }
}

@media (max-width: 1024px) {
  .main-content {
    padding: 18px 16px 104px;
  }

  .financial-grid,
  .documents-grid,
  .dashboard-grid {
    grid-template-columns: 1fr;
  }

  .documents-field {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 900px) {
  .topbar {
    position: sticky;
    height: auto;
    min-height: 58px;
    padding: calc(8px + env(safe-area-inset-top)) 12px 8px;
    flex-direction: row;
    align-items: center;
  }

  .topbar-left {
    flex: 1;
  }

  .auth-header {
    width: auto;
    justify-content: flex-end;
  }

  .user-meta {
    display: flex;
    align-items: center;
    gap: 6px;
    max-width: 34vw;
    min-width: 0;
  }

  .user-email {
    max-width: 18vw;
    font-size: 14px;
  }

  .theme-toggle-text {
    display: none;
  }

  .theme-toggle-btn,
  .user-box-header button {
    min-height: 40px;
    padding: 9px 11px;
  }

  .sidebar {
    width: min(84vw, 320px);
    min-width: min(84vw, 320px);
    padding-top: 4px;
  }

  .bottom-nav {
    height: auto;
    min-height: var(--bottom-nav-height);
    display: grid;
    grid-auto-flow: column;
    grid-auto-columns: minmax(68px, 1fr);
    grid-template-columns: none;
    overflow-x: auto;
    overscroll-behavior-x: contain;
    padding: 8px 10px calc(8px + env(safe-area-inset-bottom));
    background: var(--panel-soft) !important;
    border-top: 1px solid var(--border-color);
    backdrop-filter: blur(18px);
    scrollbar-width: none;
  }

  .bottom-nav::-webkit-scrollbar {
    display: none;
  }

  .bottom-nav-link {
    min-height: 54px;
    padding: 7px 8px;
    white-space: nowrap;
  }
}

@media (max-width: 768px) {
  .auth-header {
    width: 100%;
    display: grid;
    grid-template-columns: auto auto minmax(0, 1fr);
    grid-template-areas:
      "language theme user"
      "logout logout logout";
    align-items: center;
    gap: 8px;
  }

  .user-meta {
    width: auto;
    max-width: min(58vw, 240px);
    min-width: 0;
    display: grid;
    grid-template-columns: auto minmax(0, 1fr) auto;
    align-items: center;
    grid-area: user;
    justify-self: end;
  }

  .user-email {
    max-width: 100%;
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    font-size: 14px;
  }

  html[dir="rtl"] .auth-header {
    grid-template-columns: minmax(0, 1fr) auto auto;
    grid-template-areas:
      "user theme language"
      "logout logout logout";
  }

  html[dir="rtl"] .user-meta {
    justify-self: start;
  }

  .main-content {
    padding: 12px 10px 104px;
  }

  .card,
  .page > .card {
    padding: 14px;
  }

  .top-row {
    gap: 10px;
    margin-bottom: 14px;
    padding: 14px 14px 13px;
  }

  .top-row > div:first-child {
    min-width: 0;
  }

  h2,
  #financial .top-row h2 {
    font-size: 22px;
  }

  h3,
  .financial-section h3,
  .financial-summary-card h3,
  #financial .card.inner-card h3 {
    font-size: 18px;
  }

  .page-actions,
  .admin-actions,
  .financial-actions-row {
    width: 100%;
  }

  .page-actions > *,
  .admin-actions > *,
  .financial-actions-row > *,
  .action-btn,
  .green-btn {
    width: 100%;
  }

  table,
  thead,
  tbody,
  th,
  td,
  tr {
    display: block;
  }

  thead {
    display: none;
  }

  tr {
    border-radius: var(--radius);
    border: 1px solid var(--card-border);
    background: var(--surface) !important;
    margin-bottom: 12px;
  }

  td {
    padding: 12px;
  }

  td::before {
    color: var(--brand);
    font-size: 12px;
    text-transform: uppercase;
  }

  .messages-container {
    height: min(58vh, 430px);
  }

  .chat-input {
    flex-direction: row;
    align-items: center;
  }

  #sendMessageBtn {
    width: auto;
    margin-top: 0;
  }

  .top-row > div:first-child .muted {
    max-width: none;
  }
}

@media (max-width: 480px) {
  .brand {
    font-size: 16px;
    letter-spacing: 0.06em;
  }

  .user-meta {
    max-width: min(60vw, 250px);
  }

  .user-email {
    max-width: 100%;
    font-size: 13px;
  }

  .menu-toggle {
    min-width: 42px;
    min-height: 40px;
    padding: 8px 10px;
  }

  .dashboard-stat strong,
  .financial-summary-item strong {
    font-size: 18px;
  }

  .documents-image-preview {
    height: 150px;
  }

  .chat-input {
    gap: 8px;
  }

  #messageInput {
    min-width: 0;
  }

  #sendMessageBtn {
    padding: 11px 12px;
  }
}

/* Light mode readability hardening against older page-specific dark styles. */
html[data-theme="light"] body,
html[data-theme="light"] .main-content,
html[data-theme="light"] .page,
html[data-theme="light"] .card,
html[data-theme="light"] .inner-card,
html[data-theme="light"] .dashboard-card,
html[data-theme="light"] .financial-section,
html[data-theme="light"] .financial-summary-card,
html[data-theme="light"] .documents-section,
html[data-theme="light"] .admin-box,
html[data-theme="light"] .user-item,
html[data-theme="light"] .messages-container,
html[data-theme="light"] table,
html[data-theme="light"] td,
html[data-theme="light"] th,
html[data-theme="light"] label,
html[data-theme="light"] span,
html[data-theme="light"] strong,
html[data-theme="light"] p,
html[data-theme="light"] pre {
  color: var(--text-main) !important;
}

html[data-theme="light"] .muted,
html[data-theme="light"] .login-subtitle,
html[data-theme="light"] .user-subtitle,
html[data-theme="light"] .financial-field label,
html[data-theme="light"] .documents-field label,
html[data-theme="light"] .dashboard-stat span,
html[data-theme="light"] .financial-summary-item span {
  color: var(--text-soft) !important;
}

html[data-theme="light"] .page > .card,
html[data-theme="light"] .card,
html[data-theme="light"] .inner-card,
html[data-theme="light"] .dashboard-card,
html[data-theme="light"] .financial-section,
html[data-theme="light"] .financial-summary-card,
html[data-theme="light"] .documents-section,
html[data-theme="light"] .admin-box,
html[data-theme="light"] .user-item,
html[data-theme="light"] .messages-container,
html[data-theme="light"] table {
  background: var(--panel-soft) !important;
  border-color: var(--card-border) !important;
}

html[data-theme="light"] .dashboard-stat,
html[data-theme="light"] .financial-summary-item,
html[data-theme="light"] .financial-result-row,
html[data-theme="light"] #financialBillsList .financial-bill-row,
html[data-theme="light"] .documents-summary-box,
html[data-theme="light"] .message.received {
  background: var(--surface) !important;
  color: var(--text-main) !important;
}

html[data-theme="light"] .user-role-chip,
html[data-theme="light"] .role-badge {
  background: rgba(73, 109, 47, 0.12) !important;
  border-color: rgba(73, 109, 47, 0.34) !important;
  color: #24371b !important;
}

html[data-theme="light"] .user-role-chip.admin {
  background: rgba(157, 118, 48, 0.16) !important;
  border-color: rgba(157, 118, 48, 0.42) !important;
  color: #3b2b10 !important;
}

html[data-theme="light"] input,
html[data-theme="light"] textarea,
html[data-theme="light"] select,
html[data-theme="light"] .admin-search,
html[data-theme="light"] #chatUserSearchInput,
html[data-theme="light"] #messageInput {
  background: #fffdf7 !important;
  color: var(--text-main) !important;
  border-color: rgba(58, 76, 42, 0.24) !important;
}

html[data-theme="light"] .sidebar {
  background:
    linear-gradient(180deg, rgba(241, 242, 236, 0.66), rgba(223, 226, 216, 0.68)),
    var(--camo-image),
    #dde1d7 !important;
  background-size: auto, 900px 660px, auto !important;
  background-position: center top, center top, center top !important;
  background-repeat: no-repeat, repeat, no-repeat !important;
  backdrop-filter: blur(16px) saturate(1.01) !important;
  border-right-color: rgba(77, 93, 66, 0.12) !important;
}

html[data-theme="light"] .sidebar-header {
  color: rgba(82, 92, 78, 0.84) !important;
  font-weight: 800 !important;
  letter-spacing: 0.2em !important;
  font-size: 15px !important;
}

html[data-theme="light"] .side-link {
  color: #253026 !important;
  background: linear-gradient(180deg, rgba(255, 255, 255, 0.9), rgba(249, 246, 241, 0.78)) !important;
  border-color: rgba(72, 78, 71, 0.06) !important;
  box-shadow:
    0 12px 24px rgba(77, 82, 68, 0.07),
    inset 0 1px 0 rgba(255, 255, 255, 0.94) !important;
  opacity: var(--nav-inactive-opacity) !important;
}

html[data-theme="light"] .side-link.active-link {
  background: linear-gradient(180deg, rgba(203, 219, 184, 0.96), rgba(181, 202, 157, 0.82)) !important;
  border-color: rgba(92, 124, 76, 0.22) !important;
  color: #1e281f !important;
  box-shadow:
    0 0 0 1px rgba(255, 255, 255, 0.42) inset,
    0 0 14px rgba(84, 122, 78, 0.06),
    0 14px 28px rgba(77, 82, 68, 0.08) !important;
  opacity: 1 !important;
}

html[data-theme="light"] body {
  background-image:
    linear-gradient(180deg, rgba(255, 255, 255, 0.22), rgba(255, 255, 255, 0.08)),
    linear-gradient(145deg, var(--bg-page), var(--bg-base));
}

html[data-theme="light"] body::before {
  opacity: 0.03 !important;
}

html[data-theme="light"] .topbar {
  background:
    linear-gradient(90deg, rgba(250, 248, 242, 0.94) 0%, rgba(250, 248, 242, 0.9) 34%, rgba(250, 248, 242, 0.72) 48%, rgba(250, 248, 242, 0.9) 64%, rgba(250, 248, 242, 0.95) 100%),
    linear-gradient(180deg, rgba(255, 255, 255, 0.1), rgba(255, 255, 255, 0.02)),
    var(--camo-image),
    linear-gradient(180deg, #f6f3ec, #ece8de) !important;
  background-size: auto, auto, 820px 220px, auto !important;
  background-position: center center, center center, center top, center center !important;
  background-repeat: no-repeat, no-repeat, repeat-x, no-repeat !important;
  border-bottom-color: rgba(73, 86, 67, 0.1) !important;
  box-shadow: 0 10px 26px rgba(77, 82, 68, 0.08) !important;
  backdrop-filter: blur(14px) saturate(1.02) !important;
}

html[data-theme="light"] .top-row {
  box-shadow: 0 12px 24px rgba(84, 90, 74, 0.06);
}

html[data-theme="light"] .brand {
  color: #315938 !important;
}

html[data-theme="light"] .brand::before {
  background: #92724b !important;
  box-shadow: 0 0 0 4px rgba(146, 114, 75, 0.14) !important;
}

html[data-theme="light"] .user-email {
  color: #303733 !important;
}

html[data-theme="light"] .role-badge,
html[data-theme="light"] .user-role-chip.user {
  background: rgba(196, 210, 180, 0.72) !important;
  border-color: rgba(90, 117, 70, 0.16) !important;
  color: #29442d !important;
}

html[data-theme="light"] .user-role-chip.admin {
  background: rgba(220, 206, 171, 0.78) !important;
  border-color: rgba(133, 111, 62, 0.16) !important;
  color: #584421 !important;
}

html[data-theme="light"] .menu-toggle,
html[data-theme="light"] .theme-toggle-btn {
  background: rgba(255, 255, 255, 0.92) !important;
  border-color: rgba(75, 87, 71, 0.12) !important;
  color: #273025 !important;
  box-shadow: 0 8px 18px rgba(77, 82, 68, 0.06) !important;
}

html[data-theme="light"] .theme-toggle-btn:hover,
html[data-theme="light"] .menu-toggle:hover {
  background: rgba(248, 246, 240, 0.98) !important;
}

html[data-theme="light"] .auth-header,
html[data-theme="light"] .topbar-left {
  position: relative;
  z-index: 1;
}

html[data-theme="light"] .action-btn,
html[data-theme="light"] .green-btn,
html[data-theme="light"] .user-box-header button,
html[data-theme="light"] .small-btn.promote-btn,
html[data-theme="light"] #backToUsersBtn,
html[data-theme="light"] #sendMessageBtn {
  background: linear-gradient(180deg, #557940, #456334) !important;
  border-color: rgba(58, 85, 44, 0.18) !important;
  color: #ffffff !important;
  box-shadow: 0 10px 20px rgba(77, 82, 68, 0.1) !important;
}

html[data-theme="light"] .action-btn:hover,
html[data-theme="light"] .green-btn:hover,
html[data-theme="light"] .user-box-header button:hover,
html[data-theme="light"] .small-btn.promote-btn:hover,
html[data-theme="light"] #backToUsersBtn:hover,
html[data-theme="light"] #sendMessageBtn:hover {
  background: linear-gradient(180deg, #62894a, #4f713c) !important;
}

html[data-theme="light"] #logoutBtn {
  border-color: rgba(106, 122, 79, 0.2) !important;
  background: linear-gradient(180deg, rgba(120, 145, 86, 0.96), rgba(92, 115, 65, 0.98)) !important;
  color: #faf7ef !important;
  box-shadow: 0 10px 22px rgba(81, 91, 67, 0.12) !important;
}

html[data-theme="light"] #logoutBtn:hover {
  background: linear-gradient(180deg, rgba(132, 158, 95, 0.98), rgba(102, 127, 73, 0.98)) !important;
  color: #ffffff !important;
}

html[data-theme="light"] .card,
html[data-theme="light"] .page > .card,
html[data-theme="light"] .login-card,
html[data-theme="light"] .modal-card {
  background:
    linear-gradient(180deg, rgba(255, 255, 255, 0.96), rgba(250, 248, 243, 0.94)) !important;
  border-color: rgba(79, 89, 74, 0.08) !important;
  box-shadow: 0 20px 42px rgba(77, 82, 68, 0.08) !important;
}

html[data-theme="light"] .inner-card,
html[data-theme="light"] .admin-box,
html[data-theme="light"] .dashboard-stat,
html[data-theme="light"] .financial-summary-item,
html[data-theme="light"] .documents-section,
html[data-theme="light"] .user-item,
html[data-theme="light"] .messages-container,
html[data-theme="light"] .selected-file-preview,
html[data-theme="light"] .chat-upload-progress-wrap {
  background: linear-gradient(180deg, rgba(255, 255, 255, 0.94), rgba(248, 246, 241, 0.9)) !important;
  border-color: rgba(79, 89, 74, 0.08) !important;
  box-shadow: 0 10px 24px rgba(77, 82, 68, 0.05) !important;
}

html[data-theme="light"] h1,
html[data-theme="light"] h2,
html[data-theme="light"] h3,
html[data-theme="light"] #financial .top-row h2 {
  color: #232926 !important;
}

html[data-theme="light"] .muted,
html[data-theme="light"] .login-subtitle,
html[data-theme="light"] .user-subtitle,
html[data-theme="light"] .dashboard-stat span,
html[data-theme="light"] .documents-field label,
html[data-theme="light"] .medication-field-label {
  color: #626a62 !important;
}

html[data-theme="light"] strong,
html[data-theme="light"] .dashboard-stat strong,
html[data-theme="light"] .financial-summary-item strong {
  color: #1f2521 !important;
}

html[data-theme="light"] .user-name,
html[data-theme="light"] .chat-user-name,
html[data-theme="light"] #chatWithName {
  color: var(--text-main) !important;
}

html[data-theme="light"] .user-subtitle,
html[data-theme="light"] .chat-user-subtitle {
  color: var(--text-soft) !important;
}

.medication-schedule-form {
  display: grid;
  grid-template-columns: minmax(180px, 1.15fr) minmax(120px, 0.7fr) minmax(180px, 1fr) minmax(180px, 1fr) auto;
  align-items: end;
  gap: 12px;
  margin-top: 14px;
}

.medication-field {
  display: flex;
  flex-direction: column;
  gap: 6px;
  min-width: 0;
}

.medication-field-label {
  color: var(--text-soft);
  font-size: 12px;
  font-weight: 700;
  line-height: 1.25;
}

.medication-schedule-form input,
.medication-schedule-form select {
  min-height: 44px !important;
  height: 44px !important;
  max-height: 44px !important;
  padding: 10px 12px !important;
  line-height: 1.2 !important;
  box-sizing: border-box !important;
  align-self: flex-end;
}

.medication-field > input[type="date"],
.medication-field > input[type="number"] {
  display: block !important;
  width: 100% !important;
  min-height: 44px !important;
  height: 44px !important;
  max-height: 44px !important;
  padding-top: 10px !important;
  padding-bottom: 10px !important;
}

.medication-schedule-form button {
  align-self: end;
  min-height: 44px;
  height: 44px;
  white-space: nowrap;
}

@media (max-width: 980px) {
  .medication-schedule-form {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .medication-schedule-form button {
    width: 100%;
    grid-column: 1 / -1;
  }
}

@media (max-width: 640px) {
  .medication-schedule-form {
    grid-template-columns: 1fr;
  }

  .medication-schedule-form button {
    width: 100%;
    grid-column: auto;
  }
}
