:root {
  --sidebar-width: 280px;
  --sidebar-collapsed: 84px;
  --ink: #12232e;
  --ink-soft: #4a6472;
  --panel: #f3f7f9;
  --surface: #ffffff;
  --line: rgba(18, 35, 46, 0.08);
  --teal: #7eb000;
  --teal-bright: #a2d900;
  --teal-deep: #4d6f00;
  --sidebar-bg: linear-gradient(165deg, #1a2208 0%, #243010 48%, #1c280c 100%);
  --sidebar-glow: radial-gradient(ellipse at 20% 0%, rgba(162, 217, 0, 0.28), transparent 55%);
  --shadow-soft: 0 18px 40px rgba(40, 60, 0, 0.12);
  --radius: 18px;
  --font-ui: "Noto Sans Arabic", "Outfit", sans-serif;
  --font-brand: "Outfit", "Noto Sans Arabic", sans-serif;
  --ease: cubic-bezier(0.22, 1, 0.36, 1);
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-right: env(safe-area-inset-right, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --safe-left: env(safe-area-inset-left, 0px);
  --space: clamp(0.85rem, 2.5vw, 1.5rem);
  --topbar-h: 4.25rem;
  --bottom-nav-h: 0px;
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

html {
  font-size: clamp(14px, 0.35vw + 13.5px, 16px);
  height: 100%;
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
}

body {
  margin: 0;
  min-height: 100%;
  min-height: 100dvh;
  font-family: var(--font-ui);
  color: var(--ink);
  background:
    radial-gradient(circle at 85% 10%, rgba(43, 181, 160, 0.12), transparent 30%),
    radial-gradient(circle at 10% 90%, rgba(18, 64, 71, 0.08), transparent 35%),
    var(--panel);
  overflow-x: hidden;
}

body.nav-locked {
  overflow: hidden;
  touch-action: none;
}

a {
  text-decoration: none;
  color: inherit;
}

img,
svg {
  max-width: 100%;
}

.app-shell {
  display: grid;
  grid-template-columns: var(--sidebar-width) minmax(0, 1fr);
  min-height: 100vh;
  min-height: 100dvh;
  width: 100%;
  max-width: 100vw;
  transition: grid-template-columns 0.35s var(--ease);
}

.app-shell.is-collapsed {
  grid-template-columns: var(--sidebar-collapsed) minmax(0, 1fr);
}

/* ---------- Sidebar ---------- */
.sidebar {
  position: sticky;
  top: 0;
  inset-inline-start: 0;
  width: 100%;
  max-width: var(--sidebar-width);
  height: 100vh;
  height: 100dvh;
  display: flex;
  flex-direction: column;
  padding:
    calc(1.15rem + var(--safe-top))
    calc(0.9rem + var(--safe-left))
    calc(1rem + var(--safe-bottom))
    0.9rem;
  background: var(--sidebar-bg);
  color: #e8f4f2;
  overflow: hidden;
  z-index: 40;
  isolation: isolate;
  transition: max-width 0.35s var(--ease);
}

.app-shell.is-collapsed .sidebar {
  max-width: var(--sidebar-collapsed);
}

.sidebar::before {
  content: "";
  position: absolute;
  inset: 0;
  background: var(--sidebar-glow);
  pointer-events: none;
  z-index: -1;
}

.sidebar::after {
  content: "";
  position: absolute;
  inset-inline-end: -40%;
  bottom: -20%;
  width: min(220px, 55vw);
  height: min(220px, 55vw);
  border-radius: 50%;
  background: rgba(43, 181, 160, 0.12);
  filter: blur(8px);
  pointer-events: none;
  z-index: -1;
}

.sidebar-brand {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0.55rem 0.55rem 1.1rem;
  border-bottom: 1px solid rgba(255, 255, 255, 0.08);
  margin-bottom: 0.85rem;
  position: relative;
}

.brand-mark {
  width: 42px;
  height: 42px;
  flex-shrink: 0;
  display: grid;
  place-items: center;
  border-radius: 14px;
  color: #dffaf4;
  background: #fff;
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.12);
  transition: transform 0.35s var(--ease);
  overflow: hidden;
}

.brand-mark svg {
  width: 22px;
  height: 22px;
}

.brand-mark-logo img {
  width: 100%;
  height: 100%;
  object-fit: contain;
  display: block;
  background: #fff;
}

.brand-text {
  display: flex;
  flex-direction: column;
  min-width: 0;
  flex: 1;
  transition: opacity 0.25s var(--ease), transform 0.25s var(--ease);
}

.brand-name {
  font-family: var(--font-brand);
  font-weight: 700;
  font-size: 0.92rem;
  letter-spacing: 0.01em;
  line-height: 1.25;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  color: #e8f7a8;
}

.brand-tagline {
  font-size: 0.68rem;
  color: rgba(232, 244, 242, 0.72);
  margin-top: 0.12rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.sidebar-collapse,
.sidebar-close {
  width: 40px;
  height: 40px;
  border: 0;
  border-radius: 12px;
  background: rgba(255, 255, 255, 0.06);
  color: rgba(232, 244, 242, 0.85);
  display: grid;
  place-items: center;
  cursor: pointer;
  flex-shrink: 0;
  transition: background 0.2s ease, transform 0.35s var(--ease);
  -webkit-tap-highlight-color: transparent;
}

.sidebar-collapse:hover,
.sidebar-close:hover {
  background: rgba(43, 181, 160, 0.25);
}

.sidebar-collapse svg,
.sidebar-close svg {
  width: 18px;
  height: 18px;
  transition: transform 0.35s var(--ease);
}

.sidebar-close {
  display: none;
}

.sidebar-nav {
  display: flex;
  flex-direction: column;
  gap: 0.2rem;
  flex: 1;
  overflow-y: auto;
  overscroll-behavior: contain;
  -webkit-overflow-scrolling: touch;
  padding: 0 0.25rem;
  scrollbar-width: thin;
  scrollbar-color: rgba(255, 255, 255, 0.2) transparent;
}

.nav-section {
  margin: 0.85rem 0.7rem 0.35rem;
  font-size: 0.72rem;
  font-weight: 600;
  letter-spacing: 0.08em;
  color: rgba(232, 244, 242, 0.45);
  transition: opacity 0.2s ease;
}

.sidebar .nav-link {
  position: relative;
  display: flex;
  align-items: center;
  gap: 0.75rem;
  min-height: 48px;
  padding: 0.72rem 0.85rem;
  border-radius: 14px;
  color: rgba(232, 244, 242, 0.78);
  font-weight: 500;
  transition: background 0.22s ease, color 0.22s ease, transform 0.22s var(--ease);
  -webkit-tap-highlight-color: transparent;
}

@media (hover: hover) and (pointer: fine) {
  .sidebar .nav-link:hover {
    background: rgba(255, 255, 255, 0.07);
    color: #fff;
    transform: translateX(-2px);
  }
}

.sidebar .nav-link:active {
  background: rgba(255, 255, 255, 0.1);
  color: #fff;
}

.sidebar .nav-link.active {
  background: linear-gradient(120deg, rgba(43, 181, 160, 0.28), rgba(43, 181, 160, 0.12));
  color: #fff;
  box-shadow: inset 0 0 0 1px rgba(43, 181, 160, 0.35);
}

.sidebar .nav-link.active::before {
  content: "";
  position: absolute;
  inset-inline-start: 0;
  top: 50%;
  transform: translateY(-50%);
  width: 3px;
  height: 55%;
  border-radius: 0 4px 4px 0;
  background: var(--teal-bright);
  box-shadow: 0 0 12px rgba(43, 181, 160, 0.55);
}

.nav-icon {
  width: 22px;
  height: 22px;
  flex-shrink: 0;
  display: grid;
  place-items: center;
}

.nav-icon svg {
  width: 20px;
  height: 20px;
}

.nav-label {
  flex: 1;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  transition: opacity 0.2s ease, width 0.2s ease;
}

.nav-badge {
  min-width: 1.5rem;
  height: 1.5rem;
  padding: 0 0.4rem;
  border-radius: 999px;
  display: inline-grid;
  place-items: center;
  font-size: 0.72rem;
  font-weight: 700;
  font-family: var(--font-brand);
  color: #072822;
  background: linear-gradient(135deg, #d4f56a, #a2d900);
  transition: opacity 0.2s ease, transform 0.2s ease;
}

.sidebar-footer {
  margin-top: auto;
  padding-top: 0.75rem;
  border-top: 1px solid rgba(255, 255, 255, 0.08);
  display: flex;
  flex-direction: column;
  gap: 0.55rem;
}

.user-chip {
  display: flex;
  align-items: center;
  gap: 0.7rem;
  padding: 0.65rem 0.7rem;
  border-radius: 16px;
  background: rgba(255, 255, 255, 0.06);
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.06);
}

.user-avatar {
  width: 38px;
  height: 38px;
  border-radius: 12px;
  display: grid;
  place-items: center;
  font-weight: 700;
  color: #072822;
  background: linear-gradient(145deg, #d4f56a, #a2d900);
  flex-shrink: 0;
}

.user-meta {
  display: flex;
  flex-direction: column;
  min-width: 0;
  transition: opacity 0.2s ease;
}

.user-name {
  font-size: 0.9rem;
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.user-role {
  font-size: 0.75rem;
  color: #7ef0d8;
}

/* Collapsed sidebar (desktop) — stay edge-docked, icons stay in the rail */
.app-shell.is-collapsed .brand-text,
.app-shell.is-collapsed .nav-label,
.app-shell.is-collapsed .nav-badge,
.app-shell.is-collapsed .nav-section,
.app-shell.is-collapsed .user-meta {
  opacity: 0;
  width: 0;
  max-width: 0;
  flex: 0 0 0;
  margin: 0;
  padding: 0;
  overflow: hidden;
  pointer-events: none;
  white-space: nowrap;
}

.app-shell.is-collapsed .sidebar {
  padding-inline: 0.55rem;
}

.app-shell.is-collapsed .sidebar-brand {
  justify-content: center;
  padding: 0.55rem 0 1.1rem;
  gap: 0;
}

.app-shell.is-collapsed .sidebar-collapse {
  position: absolute;
  inset-inline-end: 0.35rem;
  top: calc(1.15rem + var(--safe-top));
  width: 32px;
  height: 32px;
  z-index: 2;
}

.app-shell.is-collapsed .sidebar-collapse svg {
  transform: rotate(180deg);
}

.app-shell.is-collapsed .sidebar .nav-link {
  justify-content: center;
  padding-inline: 0.55rem;
  gap: 0;
}

.app-shell.is-collapsed .nav-icon {
  margin: 0;
}

.app-shell.is-collapsed .user-chip {
  justify-content: center;
  padding: 0.55rem;
  gap: 0;
}

.app-shell.is-collapsed .brand-mark {
  transform: scale(1.02);
}

/* ---------- Main panel ---------- */
.main-panel {
  display: flex;
  flex-direction: column;
  min-width: 0;
  width: 100%;
  min-height: 100vh;
  min-height: 100dvh;
}

.topbar {
  display: flex;
  align-items: center;
  gap: clamp(0.55rem, 2vw, 1rem);
  padding:
    calc(0.85rem + var(--safe-top))
    calc(var(--space) + var(--safe-right))
    0.85rem
    calc(var(--space) + var(--safe-left));
  position: sticky;
  top: 0;
  z-index: 20;
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  background: rgba(243, 247, 249, 0.88);
  border-bottom: 1px solid transparent;
  min-height: var(--topbar-h);
}

.topbar-title {
  flex: 1;
  min-width: 0;
}

.topbar-title h1 {
  margin: 0;
  font-size: clamp(1.05rem, 2.5vw, 1.35rem);
  font-weight: 700;
  letter-spacing: -0.01em;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.topbar-title p {
  margin: 0.15rem 0 0;
  color: var(--ink-soft);
  font-size: clamp(0.78rem, 1.6vw, 0.88rem);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.topbar-actions {
  display: flex;
  align-items: center;
  gap: 0.45rem;
  flex-shrink: 0;
}

.icon-btn,
.ghost-btn,
.primary-btn {
  border: 0;
  cursor: pointer;
  font-family: inherit;
  -webkit-tap-highlight-color: transparent;
}

.icon-btn {
  width: 44px;
  height: 44px;
  border-radius: 12px;
  display: grid;
  place-items: center;
  background: var(--surface);
  color: var(--ink);
  box-shadow: 0 1px 0 var(--line), var(--shadow-soft);
  flex-shrink: 0;
}

.icon-btn svg {
  width: 20px;
  height: 20px;
}

@media (hover: hover) and (pointer: fine) {
  .icon-btn:hover {
    color: var(--teal);
  }

  .primary-btn:hover {
    filter: brightness(1.05);
  }
}

.ghost-btn,
.primary-btn {
  min-height: 44px;
  height: 44px;
  padding: 0 clamp(0.75rem, 2vw, 1rem);
  border-radius: 12px;
  font-weight: 600;
  font-size: clamp(0.82rem, 1.8vw, 0.9rem);
  white-space: nowrap;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.35rem;
}

.ghost-btn {
  background: var(--surface);
  color: var(--ink);
  box-shadow: 0 1px 0 var(--line);
}

.primary-btn {
  color: #fff;
  background: linear-gradient(135deg, var(--teal-bright), var(--teal));
  box-shadow: 0 10px 24px rgba(126, 176, 0, 0.28);
}

.btn-short {
  display: none;
}

.content-area {
  flex: 1;
  width: 100%;
  max-width: 100%;
  min-width: 0;
  padding: 0.5rem clamp(0.65rem, 1.8vw, var(--space)) 1.5rem;
  padding-inline-end: calc(clamp(0.65rem, 1.8vw, var(--space)) + var(--safe-right));
  padding-inline-start: calc(clamp(0.65rem, 1.8vw, var(--space)) + var(--safe-left));
  animation: rise-in 0.45s var(--ease) both;
  overflow-x: clip;
}

.app-footer {
  padding:
    0.85rem
    calc(var(--space) + var(--safe-right))
    calc(1.25rem + var(--safe-bottom))
    calc(var(--space) + var(--safe-left));
  color: var(--ink-soft);
  font-size: 0.82rem;
}

.sidebar-overlay {
  display: none;
}

@keyframes rise-in {
  from {
    opacity: 0;
    transform: translateY(10px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

/* Welcome page */
.welcome-panel {
  background: var(--surface);
  border-radius: clamp(14px, 3vw, calc(var(--radius) + 4px));
  padding: clamp(1.15rem, 4vw, 2rem) clamp(1rem, 3.5vw, 1.75rem);
  box-shadow: var(--shadow-soft);
  border: 1px solid var(--line);
  max-width: 720px;
  width: 100%;
}

.welcome-panel h2 {
  margin: 0 0 0.5rem;
  font-size: clamp(1.25rem, 4vw, 1.7rem);
  font-weight: 700;
  line-height: 1.35;
}

.welcome-panel p {
  margin: 0;
  color: var(--ink-soft);
  line-height: 1.75;
  font-size: clamp(0.9rem, 2.2vw, 1rem);
}

.welcome-stats {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: clamp(0.55rem, 2vw, 0.85rem);
  margin-top: clamp(1rem, 3vw, 1.5rem);
}

.stat {
  padding: clamp(0.85rem, 2.5vw, 1rem);
  border-radius: 14px;
  background: linear-gradient(160deg, rgba(43, 181, 160, 0.1), rgba(18, 64, 71, 0.04));
  min-width: 0;
}

.stat strong {
  display: block;
  font-family: var(--font-brand);
  font-size: clamp(1.15rem, 3.5vw, 1.4rem);
  color: var(--teal-deep);
}

.stat span {
  font-size: clamp(0.72rem, 2vw, 0.82rem);
  color: var(--ink-soft);
  display: block;
  line-height: 1.4;
}

/* ---------- Tablet ---------- */
@media (max-width: 1100px) and (min-width: 993px) {
  :root {
    --sidebar-width: 248px;
  }

  .welcome-stats {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }
}

/* ---------- Mobile & tablet drawer ---------- */
@media (max-width: 992px) {
  .app-shell,
  .app-shell.is-collapsed {
    grid-template-columns: minmax(0, 1fr);
  }

  .sidebar {
    position: fixed;
    inset-block: 0;
    inset-inline-start: 0;
    width: min(88vw, 320px);
    max-width: 100%;
    /* LTR: docked left — hide off the left edge (not across the center) */
    transform: translate3d(-110%, 0, 0);
    transition: transform 0.35s var(--ease);
    box-shadow: 12px 0 40px rgba(8, 24, 28, 0.28);
    padding-inline: 0.85rem;
    padding-inline-start: calc(0.85rem + var(--safe-left));
    will-change: transform;
    pointer-events: none;
  }

  html[dir="rtl"] .sidebar {
    /* RTL: docked right — hide off the right edge (not across the center) */
    transform: translate3d(110%, 0, 0);
    box-shadow: -12px 0 40px rgba(8, 24, 28, 0.28);
  }

  .app-shell.is-open .sidebar {
    transform: translate3d(0, 0, 0);
    pointer-events: auto;
  }

  .sidebar-collapse {
    display: none;
  }

  .sidebar-close {
    display: grid;
    margin-inline-start: auto;
  }

  .app-shell.is-collapsed .brand-text,
  .app-shell.is-collapsed .nav-label,
  .app-shell.is-collapsed .nav-badge,
  .app-shell.is-collapsed .nav-section,
  .app-shell.is-collapsed .user-meta {
    opacity: 1;
    width: auto;
    overflow: visible;
    pointer-events: auto;
  }

  .app-shell.is-collapsed .sidebar .nav-link,
  .app-shell.is-collapsed .user-chip,
  .app-shell.is-collapsed .sidebar-brand {
    justify-content: flex-start;
    padding-inline: 0.85rem;
  }

  .sidebar-overlay {
    display: block;
    position: fixed;
    inset: 0;
    background: rgba(8, 24, 28, 0.5);
    backdrop-filter: blur(3px);
    -webkit-backdrop-filter: blur(3px);
    z-index: 30;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.3s ease;
  }

  .app-shell.is-open .sidebar-overlay[hidden] {
    display: block;
  }

  .app-shell.is-open .sidebar-overlay {
    opacity: 1;
    pointer-events: auto;
  }

  .topbar-actions .ghost-btn {
    display: none;
  }

  .welcome-stats {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .welcome-stats .stat:last-child {
    grid-column: 1 / -1;
  }
}

/* ---------- Small phones ---------- */
@media (max-width: 576px) {
  .topbar {
    gap: 0.5rem;
    padding-block: calc(0.65rem + var(--safe-top)) 0.65rem;
  }

  .icon-btn {
    width: 42px;
    height: 42px;
  }

  .ghost-btn,
  .primary-btn {
    min-height: 44px;
    height: auto;
    min-width: 0;
  }

  .btn-full {
    display: none;
  }

  .btn-short {
    display: inline;
  }

  .topbar-title p {
    display: none;
  }

  .topbar-title h1 {
    font-size: 1.05rem;
  }

  .welcome-stats {
    grid-template-columns: 1fr;
  }

  .welcome-stats .stat:last-child {
    grid-column: auto;
  }

  .sidebar {
    width: min(92vw, 100%);
  }

  .brand-name {
    font-size: 0.82rem;
  }

  .brand-tagline {
    font-size: 0.62rem;
  }

  .report-summary {
    grid-template-columns: 1fr;
  }

  .report-filters .field-btn > div {
    width: 100%;
  }

  .report-filters .field-btn .primary-btn,
  .report-filters .field-btn .ghost-btn {
    flex: 1 1 auto;
  }

  .app-footer {
    text-align: center;
    line-height: 1.6;
  }

  .table-wrap {
    border: 0;
  }
}

/* ---------- Very small screens ---------- */
@media (max-width: 360px) {
  .primary-btn {
    padding-inline: 0.65rem;
  }

  .brand-tagline {
    display: none;
  }
}

/* ---------- Landscape phones ---------- */
@media (max-width: 992px) and (max-height: 480px) and (orientation: landscape) {
  .sidebar {
    padding-block: 0.55rem;
  }

  .sidebar-brand {
    padding-bottom: 0.55rem;
    margin-bottom: 0.45rem;
  }

  .sidebar .nav-link {
    min-height: 40px;
    padding-block: 0.45rem;
  }

  .nav-section {
    margin-top: 0.45rem;
  }

  .user-chip {
    padding-block: 0.4rem;
  }

  .topbar-title p {
    display: none;
  }
}

/* ---------- Patient forms & list ---------- */
.dash-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.65rem;
  margin-top: 1.35rem;
}

.textarea {
  min-height: 96px;
  height: auto;
  resize: vertical;
  line-height: 1.6;
}

.expense-day-label {
  margin: 0 0 0.85rem;
  color: var(--ink-soft);
  font-size: 0.92rem;
}

.amount-cell {
  font-family: var(--font-brand);
  font-weight: 700;
  color: #a13328;
}

.details-cell {
  max-width: 320px;
  white-space: normal;
  line-height: 1.5;
}

.expense-table tfoot td,
.data-table tfoot td {
  background: #f7fafb;
  border-bottom: 0;
}

.report-cards {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 1rem;
}

.report-card {
  display: flex;
  flex-direction: column;
  gap: 0.45rem;
  padding: 1.25rem;
  border-radius: 16px;
  background: linear-gradient(160deg, rgba(43, 181, 160, 0.1), rgba(18, 64, 71, 0.04));
  border: 1px solid var(--line);
  transition: transform 0.2s var(--ease), box-shadow 0.2s ease;
}

.report-card:hover {
  transform: translateY(-2px);
  box-shadow: var(--shadow-soft);
}

.report-card strong {
  font-size: 1.1rem;
}

.report-card span:last-child {
  color: var(--ink-soft);
  font-size: 0.88rem;
  line-height: 1.5;
}

.report-card-icon {
  width: 42px;
  height: 42px;
  display: grid;
  place-items: center;
  border-radius: 12px;
  color: var(--teal-deep);
  background: rgba(43, 181, 160, 0.18);
  margin-bottom: 0.35rem;
}

.report-card-icon.expense {
  color: #a13328;
  background: rgba(192, 57, 43, 0.1);
}

.report-card-icon svg {
  width: 22px;
  height: 22px;
}

.report-filters {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 0.75rem;
  margin-bottom: 1.1rem;
  padding: 1rem 1.1rem;
  border-radius: 14px;
  background: #f7fafb;
  border: 1px solid var(--line);
  width: 100%;
}

.report-filters .field-btn {
  justify-content: flex-end;
}

.report-summary {
  display: flex;
  flex-wrap: wrap;
  gap: 0.55rem;
  margin-bottom: 1rem;
}

.report-summary .mini-stat {
  flex: 1;
  min-width: 120px;
}

@media (max-width: 900px) {
  .report-cards {
    grid-template-columns: 1fr;
  }

  .report-filters {
    grid-template-columns: 1fr 1fr;
  }
}

@media (max-width: 576px) {
  .report-filters {
    grid-template-columns: 1fr;
  }
}

.form-panel,
.list-panel {
  background: var(--surface);
  border-radius: clamp(14px, 3vw, calc(var(--radius) + 4px));
  padding: clamp(1.1rem, 3.5vw, 1.75rem);
  box-shadow: var(--shadow-soft);
  border: 1px solid var(--line);
  width: 100%;
  min-width: 0;
}

.form-shell {
  width: 100%;
  max-width: min(920px, 100%);
  margin-inline: auto;
  display: grid;
  gap: 0;
  animation: rise-in 0.4s var(--ease) both;
}

.form-panel {
  max-width: min(920px, 100%);
  margin-inline: auto;
  padding: 0;
  overflow: hidden;
}

.form-shell .form-panel,
.form-shell > .form-body {
  max-width: none;
  margin: 0;
}

.list-panel,
.list-panel.report-panel {
  max-width: none;
  width: 100%;
}

.form-panel-head,
.list-toolbar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.85rem;
  margin-bottom: 1.25rem;
}

.list-toolbar {
  justify-content: space-between;
  width: 100%;
  padding-bottom: 1rem;
  border-bottom: 1px solid var(--line);
}

.list-toolbar > .list-stats {
  order: 0;
}

.list-toolbar > .dt-toolbar-extra {
  order: 1;
  margin-inline-start: auto;
}

.list-toolbar > .primary-btn,
.list-toolbar > .ghost-btn {
  order: 2;
  flex-shrink: 0;
}

/* Entry form hero — compact to avoid page scroll */
.content-area:has(.form-shell) {
  padding-block: 0.35rem 0.75rem;
}

.form-hero {
  display: flex;
  flex-wrap: nowrap;
  align-items: center;
  gap: 0.65rem;
  padding: 0.65rem 1rem;
  background:
    radial-gradient(ellipse at 100% 0%, rgba(162, 217, 0, 0.2), transparent 50%),
    linear-gradient(135deg, #1a2208 0%, #2a3a12 55%, #1c280c 100%);
  color: #f4f8ec;
}

.form-hero-icon {
  width: 36px;
  height: 36px;
  border-radius: 10px;
  display: grid;
  place-items: center;
  background: rgba(162, 217, 0, 0.18);
  border: 1px solid rgba(162, 217, 0, 0.28);
  flex-shrink: 0;
}

.form-hero-icon svg {
  width: 18px;
  height: 18px;
  color: var(--teal-bright);
}

.form-hero-text {
  flex: 1;
  min-width: 0;
}

.form-kicker {
  display: none;
}

.form-hero h2,
.form-panel-head h2,
.list-panel h2 {
  margin: 0;
  font-size: clamp(1rem, 2.4vw, 1.2rem);
  font-weight: 700;
  line-height: 1.25;
}

.form-hero p {
  display: none;
}

.form-panel-head p {
  margin: 0.35rem 0 0;
  font-size: 0.88rem;
  line-height: 1.55;
  color: var(--ink-soft);
}

.form-hero-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.35rem;
  flex-shrink: 0;
}

.form-hero .ghost-btn {
  background: rgba(255, 255, 255, 0.08);
  border-color: rgba(255, 255, 255, 0.18);
  color: #f4f8ec;
  min-height: 34px;
  padding: 0.35rem 0.75rem;
  font-size: 0.82rem;
}

.form-hero .ghost-btn:hover {
  background: rgba(255, 255, 255, 0.14);
}

.form-panel-head {
  justify-content: space-between;
}

.form-body {
  padding: 0.75rem 0.9rem 0.85rem;
}

.entry-form,
.patient-form {
  display: grid;
  gap: 0.65rem;
}

.form-section {
  padding: 0.7rem 0.85rem 0.8rem;
  border-radius: 12px;
  border: 1px solid var(--line);
  background:
    linear-gradient(180deg, rgba(126, 176, 0, 0.04), transparent 40%),
    #fbfcfd;
}

.form-section-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 0.5rem;
  margin-bottom: 0.55rem;
  padding-bottom: 0.4rem;
  border-bottom: 1px dashed rgba(18, 35, 46, 0.1);
}

.form-section-head h3 {
  margin: 0;
  font-size: 0.86rem;
  font-weight: 700;
  color: var(--teal-deep);
}

.form-section-head p {
  display: none;
}

.patient-form .form-grid,
.entry-form .form-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 0.55rem 0.85rem;
}

.entry-form .form-grid.form-grid-3 {
  grid-template-columns: repeat(3, minmax(0, 1fr));
}

@media (max-width: 800px) {
  .entry-form .form-grid.form-grid-3 {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}

.field {
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
  min-width: 0;
}

.field-span {
  grid-column: 1 / -1;
}

.field label:not(.check-label) {
  font-weight: 600;
  font-size: 0.8rem;
  color: var(--ink);
}

.input {
  width: 100%;
  min-height: 38px;
  padding: 0.4rem 0.7rem;
  border: 1px solid rgba(18, 35, 46, 0.1);
  border-radius: 10px;
  background: #fff;
  color: var(--ink);
  font-family: inherit;
  font-size: 0.88rem;
  outline: none;
  transition: border-color 0.2s ease, box-shadow 0.2s ease;
  box-shadow: none;
}

.input:hover {
  border-color: rgba(126, 176, 0, 0.35);
}

.input:focus {
  border-color: rgba(126, 176, 0, 0.65);
  box-shadow: 0 0 0 3px rgba(162, 217, 0, 0.16);
  background: #fff;
}

select.input {
  cursor: pointer;
  appearance: none;
  background-image:
    linear-gradient(45deg, transparent 50%, var(--ink-soft) 50%),
    linear-gradient(135deg, var(--ink-soft) 50%, transparent 50%);
  background-position:
    calc(100% - 16px) calc(50% - 2px),
    calc(100% - 10px) calc(50% - 2px);
  background-size: 5px 5px, 5px 5px;
  background-repeat: no-repeat;
  padding-inline-end: 2rem;
}

html[dir="rtl"] select.input {
  background-position:
    16px calc(50% - 2px),
    10px calc(50% - 2px);
  padding-inline-end: 0.7rem;
  padding-inline-start: 2rem;
}

.input.textarea,
textarea.input {
  min-height: 56px;
  max-height: 72px;
  resize: vertical;
  line-height: 1.45;
  padding-top: 0.5rem;
}

.field-error {
  color: #c0392b;
  font-size: 0.72rem;
  line-height: 1.2;
}

.field-hint {
  display: none;
}

.field-hint a {
  color: var(--teal-deep);
  font-weight: 600;
}

.form-alert {
  margin: 0;
  padding: 0.55rem 0.75rem;
  border-radius: 10px;
  background: rgba(192, 57, 43, 0.08);
  border: 1px solid rgba(192, 57, 43, 0.2);
  color: #a13328;
  font-weight: 600;
  font-size: 0.82rem;
}

.form-alert:empty {
  display: none;
}

.field-check {
  justify-content: flex-end;
}

.check-label {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  min-height: 38px;
  width: 100%;
  padding: 0.4rem 0.7rem;
  border-radius: 10px;
  background: linear-gradient(135deg, rgba(126, 176, 0, 0.1), rgba(126, 176, 0, 0.04));
  border: 1px solid rgba(126, 176, 0, 0.22);
  cursor: pointer;
  font-weight: 600;
  font-size: 0.86rem;
  transition: border-color 0.2s ease, background 0.2s ease;
}

.check-label:hover {
  border-color: rgba(126, 176, 0, 0.4);
  background: linear-gradient(135deg, rgba(126, 176, 0, 0.14), rgba(126, 176, 0, 0.06));
}

.check-label input {
  width: 1rem;
  height: 1rem;
  accent-color: var(--teal-deep);
  flex-shrink: 0;
}

.field-check small {
  display: none;
}

.form-actions {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.5rem;
  margin-top: 0;
  padding: 0.55rem 0.75rem;
  border-radius: 12px;
  background: linear-gradient(180deg, #f7faf4, #fff);
  border: 1px solid var(--line);
}

.form-actions .primary-btn {
  min-width: 120px;
  justify-content: center;
  min-height: 38px;
  padding: 0.4rem 1rem;
  box-shadow: 0 4px 12px rgba(77, 111, 0, 0.16);
}

.form-actions .ghost-btn {
  min-height: 38px;
  padding: 0.4rem 0.9rem;
}

.list-stats {
  display: flex;
  gap: 0.55rem;
}

.mini-stat {
  min-width: 88px;
  padding: 0.55rem 0.75rem;
  border-radius: 12px;
  background: rgba(43, 181, 160, 0.1);
}

.mini-stat.warn {
  background: rgba(192, 57, 43, 0.08);
}

.mini-stat strong {
  display: block;
  font-family: var(--font-brand);
  font-size: 1.15rem;
  color: var(--teal-deep);
}

.mini-stat.warn strong {
  color: #a13328;
}

.mini-stat span {
  font-size: 0.75rem;
  color: var(--ink-soft);
}

.list-filters {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  flex: 1;
  min-width: min(100%, 280px);
}

.search-input {
  flex: 1;
  min-width: 160px;
}

.list-filters .input {
  min-height: 44px;
  width: auto;
}

.toast-success {
  margin-bottom: 1rem;
  padding: 0.75rem 1rem;
  border-radius: 12px;
  background: rgba(43, 181, 160, 0.12);
  color: var(--teal-deep);
  border: 1px solid rgba(43, 181, 160, 0.25);
  font-weight: 600;
}

.table-wrap {
  width: 100%;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  border-radius: 14px;
  border: 1px solid var(--line);
}

.data-table {
  width: 100%;
  border-collapse: collapse;
  min-width: 780px;
}

.data-table th,
.data-table td {
  padding: 0.85rem 0.75rem;
  text-align: start;
  border-bottom: 1px solid var(--line);
  vertical-align: middle;
}

.data-table th {
  font-size: 0.78rem;
  color: var(--ink-soft);
  background: #f7fafb;
  white-space: nowrap;
}

.data-table tbody tr:last-child td {
  border-bottom: 0;
}

.data-table tbody tr:hover {
  background: rgba(43, 181, 160, 0.04);
}

.empty-cell {
  text-align: center !important;
  color: var(--ink-soft);
  padding: 2rem 1rem !important;
}

.badge {
  display: inline-flex;
  align-items: center;
  min-height: 28px;
  padding: 0 0.65rem;
  border-radius: 999px;
  font-size: 0.78rem;
  font-weight: 700;
}

.badge.paid {
  background: rgba(43, 181, 160, 0.15);
  color: var(--teal-deep);
}

.badge.unpaid {
  background: rgba(192, 57, 43, 0.1);
  color: #a13328;
}

.row-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.35rem;
  white-space: nowrap;
}

.inline-form {
  display: inline;
}

.link-btn {
  border: 0;
  background: transparent;
  color: var(--teal);
  font-family: inherit;
  font-weight: 600;
  font-size: 0.82rem;
  cursor: pointer;
  padding: 0.2rem 0.35rem;
}

.link-btn.danger {
  color: #a13328;
}

/* Three-dot action dropdown */
.action-menu {
  position: relative;
  display: inline-flex;
  justify-content: center;
  width: 100%;
}

.action-menu-toggle {
  width: 36px;
  height: 36px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: #fff;
  color: var(--ink);
  font-size: 1.25rem;
  line-height: 1;
  cursor: pointer;
  display: grid;
  place-items: center;
  box-shadow: 0 1px 0 var(--line);
  -webkit-tap-highlight-color: transparent;
}

.action-menu-toggle:hover,
.action-menu.is-open .action-menu-toggle {
  color: var(--teal);
  border-color: rgba(43, 181, 160, 0.35);
  background: rgba(43, 181, 160, 0.08);
}

.action-menu-panel {
  position: absolute;
  inset-inline-end: 0;
  top: calc(100% + 6px);
  z-index: 50;
  min-width: 148px;
  padding: 0.35rem;
  border-radius: 12px;
  background: #fff;
  border: 1px solid var(--line);
  box-shadow: var(--shadow-soft);
  display: flex;
  flex-direction: column;
  gap: 0.15rem;
}

.action-menu-panel[hidden] {
  display: none !important;
}

.action-menu-form {
  margin: 0;
  display: block;
}

.action-menu-item {
  display: block;
  width: 100%;
  text-align: start;
  border: 0;
  background: transparent;
  color: var(--ink);
  font-family: inherit;
  font-size: 0.88rem;
  font-weight: 600;
  padding: 0.65rem 0.75rem;
  border-radius: 9px;
  cursor: pointer;
  text-decoration: none;
}

.action-menu-item:hover {
  background: rgba(43, 181, 160, 0.1);
  color: var(--teal-deep);
}

.action-menu-item.danger {
  color: #a13328;
}

.action-menu-item.danger:hover {
  background: rgba(192, 57, 43, 0.08);
  color: #a13328;
}

.action-menu-backdrop {
  position: fixed;
  inset: 0;
  z-index: 90;
  background: rgba(8, 24, 28, 0.42);
  backdrop-filter: blur(2px);
  -webkit-backdrop-filter: blur(2px);
}

.action-menu-backdrop[hidden] {
  display: none !important;
}

body.action-menu-open {
  overflow: hidden;
}

@media (max-width: 768px) {
  .patient-form .form-grid,
  .entry-form .form-grid {
    grid-template-columns: 1fr;
  }

  .form-hero {
    flex-wrap: wrap;
    align-items: center;
  }

  .form-hero-actions {
    width: 100%;
  }

  .form-hero-actions .ghost-btn {
    flex: 1 1 auto;
    justify-content: center;
    text-align: center;
  }

  .form-actions .primary-btn,
  .form-actions .ghost-btn {
    flex: 1 1 auto;
  }

  .list-toolbar {
    flex-direction: column;
    align-items: stretch;
  }

  .list-toolbar > .dt-toolbar-extra {
    margin-inline-start: 0;
    width: 100%;
  }

  .list-toolbar > .dt-toolbar-extra .input {
    flex: 1 1 auto;
    width: 100%;
    min-width: 0;
  }

  .list-stats {
    width: 100%;
  }

  .mini-stat {
    flex: 1;
  }

  .list-filters {
    width: 100%;
  }

  .list-toolbar > .primary-btn,
  .list-toolbar > .ghost-btn,
  .dash-actions > .primary-btn,
  .dash-actions > .ghost-btn,
  .form-actions > .primary-btn,
  .form-actions > .ghost-btn {
    width: 100%;
  }

  .dt-toolbar-extra {
    width: 100%;
  }

  .dt-toolbar-extra .input,
  .dt-toolbar-extra .ghost-btn {
    flex: 1 1 100%;
    width: 100%;
  }

  .action-menu {
    justify-content: flex-end;
  }

  .action-menu-panel {
    position: fixed;
    inset-inline: 0.85rem;
    inset-inline-end: 0.85rem;
    bottom: calc(0.85rem + var(--safe-bottom));
    top: auto;
    z-index: 100;
    min-width: 0;
    width: auto;
    padding: 0.55rem;
    border-radius: 16px;
    box-shadow: 0 18px 50px rgba(8, 24, 28, 0.28);
  }

  .action-menu-item {
    min-height: 48px;
    display: flex;
    align-items: center;
    font-size: 0.95rem;
    padding-inline: 0.95rem;
  }

  .report-summary {
    display: grid;
    grid-template-columns: 1fr 1fr;
  }

  .report-summary .mini-stat {
    min-width: 0;
  }

  .welcome-panel,
  .form-panel,
  .list-panel {
    padding: 1rem 0.9rem;
  }

  .field[style*="grid-column"] {
    grid-column: 1 / -1 !important;
  }

  .data-table {
    min-width: 0;
  }

  .data-table thead {
    display: none;
  }

  .data-table,
  .data-table tbody,
  .data-table tr,
  .data-table td {
    display: block;
    width: 100%;
  }

  .data-table tr {
    padding: 0.85rem;
    border-bottom: 1px solid var(--line);
  }

  .data-table td {
    display: flex;
    justify-content: space-between;
    gap: 0.75rem;
    padding: 0.35rem 0;
    border: 0;
  }

  .data-table td::before {
    content: attr(data-label);
    color: var(--ink-soft);
    font-size: 0.8rem;
    flex-shrink: 0;
  }

  .data-table td.row-actions {
    display: flex;
    justify-content: flex-start;
    padding-top: 0.65rem;
  }

  .data-table td.row-actions::before {
    display: none;
  }

  .empty-cell {
    display: block !important;
  }

  .empty-cell::before {
    display: none;
  }
}

/* ---------- Reduced motion ---------- */
@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}

/* ---------- Installed PWA (standalone) ---------- */
html.is-pwa body {
  padding-top: env(safe-area-inset-top, 0px);
}

html.is-pwa .topbar {
  padding-top: calc(0.55rem + env(safe-area-inset-top, 0px));
}

html.is-pwa .mobile-bottom-nav {
  padding-bottom: calc(0.4rem + env(safe-area-inset-bottom, 0px));
}

/* ---------- Branch / tenant switcher ---------- */
.branch-pill {
  display: inline-block;
  padding: 0.1rem 0.45rem;
  border-radius: 999px;
  background: rgba(126, 176, 0, 0.16);
  color: var(--teal-deep);
  font-weight: 600;
  font-size: 0.78rem;
}

.branch-switch-form {
  margin: 0;
}

.branch-switch-select {
  min-height: 38px;
  min-width: 9.5rem;
  max-width: 42vw;
  padding-block: 0.35rem;
  font-size: 0.86rem;
  font-weight: 600;
}

.visually-hidden {
  position: absolute !important;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

tr.is-current-branch td {
  background: rgba(126, 176, 0, 0.08);
}

/* ---------- PWA install bar ---------- */
.pwa-install-bar {
  position: fixed;
  inset-inline: 0.85rem;
  bottom: calc(0.85rem + var(--safe-bottom));
  z-index: 80;
  display: flex;
  align-items: center;
  gap: 0.65rem;
  padding: 0.75rem 0.85rem;
  border-radius: 16px;
  background: #1a2208;
  color: #f4f8ec;
  box-shadow: 0 16px 40px rgba(20, 30, 5, 0.35);
  animation: rise-in 0.35s var(--ease) both;
}

.pwa-install-bar[hidden] {
  display: none !important;
}

.pwa-install-text {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 0.1rem;
}

.pwa-install-text strong {
  font-size: 0.92rem;
}

.pwa-install-text span {
  font-size: 0.75rem;
  opacity: 0.75;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.pwa-install-bar .primary-btn[hidden] {
  display: none !important;
}

.pwa-install-bar .primary-btn {
  min-height: 38px;
  padding: 0.4rem 0.9rem;
  flex-shrink: 0;
}

.pwa-install-bar .ghost-btn {
  min-width: 36px;
  min-height: 36px;
  padding: 0;
  border-color: rgba(255, 255, 255, 0.2);
  color: #f4f8ec;
  background: transparent;
  flex-shrink: 0;
}

@media (display-mode: standalone) {
  body {
    padding-top: env(safe-area-inset-top, 0px);
  }

  .topbar {
    padding-top: calc(0.55rem + env(safe-area-inset-top, 0px));
  }

  .pwa-install-bar {
    display: none !important;
  }
}

/* ---------- Auth (login / register) — modern split ---------- */
.auth-body {
  margin: 0;
  min-height: 100dvh;
  font-family: var(--font-ui);
  color: var(--ink);
  background: #0f1608;
}

.auth-stage {
  display: grid;
  grid-template-columns: minmax(0, 1.05fr) minmax(0, 0.95fr);
  min-height: 100dvh;
  width: 100%;
}

.auth-showcase {
  position: relative;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  padding:
    clamp(1.5rem, 4vw, 2.75rem)
    clamp(1.25rem, 4vw, 3rem)
    clamp(1.25rem, 3vw, 2rem);
  overflow: hidden;
  color: #f3f8e8;
  background:
    linear-gradient(155deg, #14200a 0%, #1e2e0e 42%, #243812 100%);
}

.auth-showcase-glow {
  position: absolute;
  inset: -20% -10% auto auto;
  width: min(70vw, 520px);
  height: min(70vw, 520px);
  border-radius: 50%;
  background: radial-gradient(circle, rgba(162, 217, 0, 0.35), transparent 68%);
  animation: auth-glow 8s ease-in-out infinite alternate;
  pointer-events: none;
}

.auth-showcase-grid {
  position: absolute;
  inset: 0;
  background-image:
    linear-gradient(rgba(255, 255, 255, 0.035) 1px, transparent 1px),
    linear-gradient(90deg, rgba(255, 255, 255, 0.035) 1px, transparent 1px);
  background-size: 42px 42px;
  mask-image: linear-gradient(180deg, rgba(0, 0, 0, 0.55), transparent 85%);
  pointer-events: none;
}

.auth-showcase-inner {
  position: relative;
  z-index: 1;
  max-width: 28rem;
  animation: auth-rise 0.7s var(--ease) both;
}

.auth-logo-wrap {
  width: 88px;
  height: 88px;
  border-radius: 22px;
  overflow: hidden;
  margin-bottom: 1.5rem;
  box-shadow:
    0 0 0 1px rgba(162, 217, 0, 0.25),
    0 18px 40px rgba(0, 0, 0, 0.35);
  animation: auth-float 5.5s ease-in-out infinite;
}

.auth-logo {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

.auth-showcase-kicker {
  margin: 0 0 0.55rem;
  font-family: var(--font-brand);
  font-size: 0.78rem;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: rgba(210, 235, 150, 0.75);
}

.auth-showcase-brand {
  margin: 0;
  font-family: var(--font-brand);
  font-size: clamp(2.1rem, 4.5vw, 3.1rem);
  font-weight: 800;
  line-height: 1.1;
  letter-spacing: -0.02em;
}

.auth-showcase-tag {
  margin: 0.75rem 0 0;
  font-size: clamp(1rem, 2vw, 1.15rem);
  line-height: 1.55;
  color: rgba(236, 244, 220, 0.82);
}

.auth-showcase-points {
  list-style: none;
  margin: 1.75rem 0 0;
  padding: 0;
  display: grid;
  gap: 0.65rem;
}

.auth-showcase-points li {
  position: relative;
  padding-inline-start: 1.35rem;
  font-size: 0.92rem;
  color: rgba(236, 244, 220, 0.78);
}

.auth-showcase-points li::before {
  content: "";
  position: absolute;
  inset-inline-start: 0;
  top: 0.45rem;
  width: 0.55rem;
  height: 0.55rem;
  border-radius: 50%;
  background: linear-gradient(135deg, #a2d900, #7eb000);
  box-shadow: 0 0 12px rgba(162, 217, 0, 0.55);
}

.auth-showcase-copy {
  position: relative;
  z-index: 1;
  margin: 2rem 0 0;
  font-size: 0.78rem;
  color: rgba(236, 244, 220, 0.45);
}

.auth-panel {
  display: grid;
  place-items: center;
  padding: clamp(1.25rem, 4vw, 2.5rem);
  background:
    radial-gradient(ellipse at 80% 0%, rgba(162, 217, 0, 0.12), transparent 42%),
    radial-gradient(circle at 10% 100%, rgba(36, 56, 12, 0.06), transparent 40%),
    linear-gradient(180deg, #f5f8f1 0%, #eef3e8 100%);
}

.auth-panel-card {
  width: min(420px, 100%);
  padding: clamp(1.35rem, 3.5vw, 2rem);
  border-radius: 24px;
  background: rgba(255, 255, 255, 0.88);
  border: 1px solid rgba(18, 35, 46, 0.08);
  box-shadow:
    0 24px 60px rgba(30, 45, 10, 0.1),
    0 1px 0 rgba(255, 255, 255, 0.8) inset;
  backdrop-filter: blur(10px);
  animation: auth-rise 0.65s 0.08s var(--ease) both;
}

.auth-mobile-brand {
  display: none;
  align-items: center;
  gap: 0.75rem;
  margin-bottom: 1.25rem;
}

.auth-mobile-brand img {
  width: 48px;
  height: 48px;
  border-radius: 14px;
  object-fit: cover;
}

.auth-mobile-brand strong {
  display: block;
  font-family: var(--font-brand);
  font-size: 1rem;
}

.auth-mobile-brand span {
  display: block;
  font-size: 0.78rem;
  color: var(--ink-soft);
  margin-top: 0.1rem;
}

.auth-head {
  margin-bottom: 1.35rem;
}

.auth-eyebrow {
  margin: 0 0 0.4rem;
  font-size: 0.78rem;
  font-weight: 600;
  letter-spacing: 0.04em;
  color: var(--teal-deep);
}

.auth-title {
  margin: 0;
  font-family: var(--font-brand);
  font-size: clamp(1.45rem, 3.2vw, 1.85rem);
  font-weight: 700;
  line-height: 1.25;
  color: var(--ink);
}

.auth-sub {
  margin: 0.5rem 0 0;
  color: var(--ink-soft);
  font-size: 0.92rem;
  line-height: 1.6;
}

.auth-form {
  display: grid;
  gap: 0.95rem;
}

.auth-form .field label:not(.check-label) {
  font-size: 0.84rem;
  margin-bottom: 0.15rem;
}

.auth-input-wrap {
  position: relative;
  display: flex;
  align-items: center;
}

.auth-input-icon {
  position: absolute;
  inset-inline-start: 0.85rem;
  width: 20px;
  height: 20px;
  color: var(--ink-soft);
  pointer-events: none;
  z-index: 1;
}

.auth-input-icon svg {
  width: 100%;
  height: 100%;
}

.auth-input {
  padding-inline-start: 2.65rem !important;
  padding-inline-end: 2.75rem !important;
  min-height: 50px;
  border-radius: 14px;
  background: #fff;
}

.auth-input-plain {
  min-height: 50px;
  border-radius: 14px;
}

.auth-eye {
  position: absolute;
  inset-inline-end: 0.45rem;
  width: 40px;
  height: 40px;
  border: 0;
  border-radius: 10px;
  background: transparent;
  color: var(--ink-soft);
  cursor: pointer;
  display: grid;
  place-items: center;
}

.auth-eye:hover {
  color: var(--teal-deep);
  background: rgba(126, 176, 0, 0.1);
}

.auth-eye svg {
  width: 20px;
  height: 20px;
}

.auth-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
}

.auth-remember {
  margin: 0;
  min-height: 42px;
  width: auto;
  padding: 0.4rem 0.75rem;
}

.auth-submit {
  width: 100%;
  min-height: 52px;
  justify-content: center;
  gap: 0.55rem;
  margin-top: 0.25rem;
  border-radius: 14px;
  font-size: 1rem;
  font-weight: 700;
  box-shadow: 0 12px 28px rgba(77, 111, 0, 0.28);
  transition: transform 0.2s var(--ease), box-shadow 0.2s var(--ease);
}

.auth-submit svg {
  width: 18px;
  height: 18px;
  transform: scaleX(-1);
}

.auth-submit:hover {
  transform: translateY(-1px);
  box-shadow: 0 16px 32px rgba(77, 111, 0, 0.34);
}

.auth-switch {
  margin: 1.15rem 0 0;
  text-align: center;
  color: var(--ink-soft);
  font-size: 0.9rem;
}

.auth-switch a {
  color: var(--teal-deep);
  font-weight: 700;
}

@keyframes auth-rise {
  from {
    opacity: 0;
    transform: translateY(14px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

@keyframes auth-glow {
  from { transform: translate(0, 0) scale(1); opacity: 0.85; }
  to { transform: translate(-8%, 6%) scale(1.08); opacity: 1; }
}

@keyframes auth-float {
  0%, 100% { transform: translateY(0); }
  50% { transform: translateY(-6px); }
}

@media (max-width: 960px) {
  .auth-stage {
    grid-template-columns: 1fr;
  }

  .auth-showcase {
    min-height: auto;
    padding: 1.35rem 1.25rem 1.5rem;
  }

  .auth-showcase-points,
  .auth-showcase-copy {
    display: none;
  }

  .auth-logo-wrap {
    width: 64px;
    height: 64px;
    border-radius: 16px;
    margin-bottom: 0.85rem;
  }

  .auth-showcase-brand {
    font-size: 1.75rem;
  }

  .auth-showcase-tag {
    margin-top: 0.4rem;
    font-size: 0.95rem;
  }

  .auth-panel {
    padding: 1.25rem 1rem 1.75rem;
    align-items: start;
  }

  .auth-mobile-brand {
    display: none;
  }
}

@media (max-width: 520px) {
  .auth-panel-card {
    padding: 1.15rem 1rem 1.25rem;
    border-radius: 18px;
  }

  .auth-showcase {
    text-align: center;
  }

  .auth-logo-wrap {
    margin-inline: auto;
  }
}

@media (prefers-reduced-motion: reduce) {
  .auth-showcase-glow,
  .auth-logo-wrap,
  .auth-showcase-inner,
  .auth-panel-card {
    animation: none !important;
  }
}

.logout-form {
  margin: 0.35rem 0 0;
}

.logout-btn {
  width: 100%;
  border: 0;
  background: transparent;
  cursor: pointer;
  font: inherit;
  color: inherit;
  text-align: right;
}

.logout-btn:hover {
  color: #fff;
}

/* ---------- Dashboard ---------- */
.dash {
  display: grid;
  gap: 1.15rem;
  width: 100%;
  animation: rise-in 0.45s var(--ease) both;
}

.dash-hero {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-end;
  justify-content: space-between;
  gap: 1rem;
  padding: clamp(1.1rem, 3vw, 1.6rem) clamp(1rem, 3vw, 1.5rem);
  border-radius: calc(var(--radius) + 2px);
  background:
    radial-gradient(ellipse at 100% 0%, rgba(162, 217, 0, 0.22), transparent 45%),
    linear-gradient(135deg, #1a2208 0%, #2a3a12 55%, #1c280c 100%);
  color: #f4f8ec;
  box-shadow: var(--shadow-soft);
}

.dash-kicker {
  margin: 0 0 0.35rem;
  font-size: 0.78rem;
  opacity: 0.75;
  letter-spacing: 0.02em;
}

.dash-hero h2 {
  margin: 0;
  font-size: clamp(1.25rem, 3.5vw, 1.65rem);
  font-weight: 700;
  line-height: 1.35;
}

.dash-lead {
  margin: 0.45rem 0 0;
  opacity: 0.78;
  font-size: 0.92rem;
  line-height: 1.55;
  max-width: 36rem;
}

.dash-hero-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
}

.dash-hero-actions .ghost-btn {
  background: rgba(255, 255, 255, 0.08);
  border-color: rgba(255, 255, 255, 0.18);
  color: #f4f8ec;
}

.dash-hero-actions .ghost-btn:hover {
  background: rgba(255, 255, 255, 0.14);
}

.dash-hero-actions .primary-btn {
  background: linear-gradient(135deg, var(--teal-bright), var(--teal));
  color: #1a2208;
  border: 0;
}

.kpi-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 0.75rem;
}

.kpi-card {
  position: relative;
  overflow: hidden;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 16px;
  padding: 1rem 1.05rem 0.95rem;
  box-shadow: 0 8px 24px rgba(40, 60, 0, 0.05);
  transition: transform 0.25s var(--ease), box-shadow 0.25s var(--ease);
}

.kpi-card::before {
  content: "";
  position: absolute;
  inset-inline-start: 0;
  inset-block: 0;
  width: 4px;
  background: var(--teal);
  opacity: 0.85;
}

.kpi-card:hover {
  transform: translateY(-2px);
  box-shadow: 0 14px 28px rgba(40, 60, 0, 0.1);
}

.kpi-label {
  display: block;
  font-size: 0.8rem;
  color: var(--ink-soft);
  margin-bottom: 0.35rem;
}

.kpi-value {
  display: block;
  font-family: var(--font-brand);
  font-size: clamp(1.25rem, 2.8vw, 1.55rem);
  font-weight: 700;
  color: var(--ink);
  letter-spacing: -0.02em;
  line-height: 1.2;
}

.kpi-hint {
  display: block;
  margin-top: 0.35rem;
  font-size: 0.72rem;
  color: var(--ink-soft);
}

.kpi-teal::before { background: var(--teal); }
.kpi-green::before { background: var(--teal-deep); }
.kpi-amber::before { background: #c48a1a; }
.kpi-warn::before { background: #c04545; }
.kpi-net::before { background: #2b78a0; }
.kpi-slate::before { background: #5a7a88; }

.kpi-warn .kpi-value { color: #a83535; }
.kpi-net .kpi-value { color: #1f6a8a; }
.kpi-green .kpi-value { color: var(--teal-deep); }

.chart-grid {
  display: grid;
  grid-template-columns: 1.4fr 1.4fr 1fr 1fr;
  gap: 0.85rem;
}

.chart-card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 16px;
  padding: 1rem 1.1rem 1.05rem;
  box-shadow: 0 8px 24px rgba(40, 60, 0, 0.05);
  min-width: 0;
}

.chart-card-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 0.75rem;
  margin-bottom: 0.65rem;
}

.chart-card-head h3 {
  margin: 0;
  font-size: 0.98rem;
  font-weight: 700;
}

.chart-card-head span {
  font-size: 0.75rem;
  color: var(--ink-soft);
  white-space: nowrap;
}

.chart-wrap {
  position: relative;
  height: 240px;
}

.chart-wrap-donut {
  height: 220px;
}

.dash-bottom {
  display: grid;
  grid-template-columns: 1.7fr 1fr;
  gap: 0.85rem;
}

.recent-table-wrap {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}

.recent-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.88rem;
}

.recent-table th,
.recent-table td {
  padding: 0.65rem 0.45rem;
  text-align: right;
  border-bottom: 1px solid var(--line);
  vertical-align: top;
}

.recent-table th {
  color: var(--ink-soft);
  font-weight: 600;
  font-size: 0.75rem;
}

.recent-table td strong {
  display: block;
  font-size: 0.9rem;
}

.recent-table td small {
  display: block;
  color: var(--ink-soft);
  font-size: 0.72rem;
  margin-top: 0.15rem;
}

.empty-dash {
  text-align: center;
  color: var(--ink-soft);
  padding: 1.5rem !important;
}

.quick-links {
  display: grid;
  gap: 0.55rem;
}

.quick-links a {
  display: flex;
  flex-direction: column;
  gap: 0.15rem;
  padding: 0.75rem 0.85rem;
  border-radius: 12px;
  border: 1px solid var(--line);
  background: linear-gradient(160deg, rgba(126, 176, 0, 0.06), transparent 70%);
  transition: border-color 0.2s var(--ease), transform 0.2s var(--ease);
}

.quick-links a:hover {
  border-color: rgba(126, 176, 0, 0.35);
  transform: translateX(-2px);
}

.quick-links a span {
  font-weight: 600;
  font-size: 0.9rem;
}

.quick-links a small {
  color: var(--ink-soft);
  font-size: 0.75rem;
}

@media (max-width: 1200px) {
  .chart-grid {
    grid-template-columns: 1fr 1fr;
  }

  .chart-card-sm {
    min-height: 0;
  }
}

@media (max-width: 900px) {
  .kpi-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .dash-bottom {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 640px) {
  .chart-grid {
    grid-template-columns: 1fr;
  }

  .chart-wrap,
  .chart-wrap-donut {
    height: 210px;
  }

  .dash-hero-actions {
    width: 100%;
  }

  .dash-hero-actions .primary-btn,
  .dash-hero-actions .ghost-btn {
    flex: 1 1 auto;
    justify-content: center;
    text-align: center;
  }
}

/* ---------- Chat ---------- */
.main-panel:has(.chat-app) {
  min-height: 0;
  height: 100dvh;
  overflow: hidden;
}

.main-panel:has(.chat-app) .app-footer {
  display: none;
}

@media (max-width: 992px) {
  .main-panel:has(.chat-app) {
    height: calc(100dvh - var(--bottom-nav-h));
    padding-bottom: 0;
  }
}

.content-area:has(.chat-app) {
  padding-block: 0.35rem 0.75rem;
  display: flex;
  flex-direction: column;
  flex: 1;
  min-height: 0;
  overflow: hidden;
}

.chat-app {
  display: grid;
  grid-template-columns: minmax(220px, 280px) minmax(0, 1fr);
  width: 100%;
  flex: 1;
  min-height: 0;
  height: 100%;
  max-height: none;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: calc(var(--radius) + 2px);
  box-shadow: var(--shadow-soft);
  overflow: hidden;
}

.chat-sidebar {
  display: flex;
  flex-direction: column;
  min-width: 0;
  min-height: 0;
  overflow: hidden;
  border-inline-end: 1px solid var(--line);
  background: linear-gradient(180deg, #f7faf4, #fff 40%);
}

.chat-sidebar-head {
  padding: 0.85rem 1rem 0.55rem;
}

.chat-sidebar-head h2 {
  margin: 0;
  font-size: 1.05rem;
}

.chat-sidebar-head p {
  margin: 0.2rem 0 0;
  font-size: 0.78rem;
  color: var(--ink-soft);
}

.chat-search-wrap {
  padding: 0 0.85rem 0.65rem;
}

.chat-search-wrap .input {
  min-height: 36px;
  font-size: 0.86rem;
}

.chat-sidebar-head,
.chat-search-wrap {
  flex-shrink: 0;
}

.chat-contacts {
  flex: 1 1 auto;
  min-height: 0;
  overflow-x: hidden;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  overscroll-behavior: contain;
  padding: 0.25rem 0.55rem 0.75rem;
  display: flex;
  flex-direction: column;
  gap: 0.3rem;
}

.chat-contact {
  display: flex;
  align-items: center;
  gap: 0.65rem;
  width: 100%;
  border: 0;
  background: transparent;
  text-align: right;
  padding: 0.55rem 0.6rem;
  border-radius: 12px;
  cursor: pointer;
  font: inherit;
  color: inherit;
  transition: background 0.2s ease;
}

.chat-contact:hover {
  background: rgba(126, 176, 0, 0.08);
}

.chat-contact.is-active {
  background: rgba(126, 176, 0, 0.14);
  box-shadow: inset 0 0 0 1px rgba(126, 176, 0, 0.25);
}

.chat-avatar {
  width: 36px;
  height: 36px;
  border-radius: 12px;
  display: grid;
  place-items: center;
  flex-shrink: 0;
  font-weight: 700;
  font-family: var(--font-brand);
  font-size: 0.95rem;
  color: var(--teal-deep);
  background: rgba(126, 176, 0, 0.16);
}

.chat-contact-meta {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 0.1rem;
}

.chat-contact-meta strong {
  font-size: 0.88rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.chat-preview {
  font-size: 0.72rem;
  color: var(--ink-soft);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.chat-unread {
  min-width: 1.35rem;
  height: 1.35rem;
  padding: 0 0.35rem;
  border-radius: 999px;
  display: inline-grid;
  place-items: center;
  font-size: 0.7rem;
  font-weight: 700;
  color: #fff;
  background: #c04545;
  flex-shrink: 0;
}

.chat-empty-hint {
  margin: 1rem 0.5rem;
  text-align: center;
  color: var(--ink-soft);
  font-size: 0.85rem;
}

.chat-main {
  display: flex;
  flex-direction: column;
  min-width: 0;
  min-height: 0;
  height: 100%;
  overflow: hidden;
  background: #fbfcfd;
}

.chat-main-head {
  display: flex;
  align-items: center;
  flex-shrink: 0;
  padding: 0.7rem 1rem;
  border-bottom: 1px solid var(--line);
  background: #fff;
}

.chat-peer {
  display: flex;
  align-items: center;
  gap: 0.65rem;
}

.chat-peer strong {
  display: block;
  font-size: 0.95rem;
}

.chat-peer small {
  color: var(--ink-soft);
  font-size: 0.75rem;
}

.chat-empty {
  flex: 1 1 auto;
  min-height: 0;
  display: grid;
  place-items: center;
  padding: 1.5rem;
  overflow: auto;
}

.chat-empty-card {
  text-align: center;
  color: var(--ink-soft);
  max-width: 240px;
}

.chat-empty-card svg {
  width: 42px;
  height: 42px;
  margin-bottom: 0.65rem;
  color: var(--teal-deep);
  opacity: 0.7;
}

.chat-empty-card strong {
  display: block;
  color: var(--ink);
  margin-bottom: 0.25rem;
}

.chat-empty-card p {
  margin: 0;
  font-size: 0.85rem;
}

.chat-thread {
  flex: 1 1 auto;
  min-height: 0;
  overflow-x: hidden;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  overscroll-behavior: contain;
  padding: 0.85rem 1rem;
  display: flex;
  flex-direction: column;
  gap: 0.55rem;
  background:
    radial-gradient(circle at 90% 10%, rgba(126, 176, 0, 0.06), transparent 35%),
    #fbfcfd;
}

.chat-bubble {
  max-width: min(78%, 420px);
  display: flex;
  flex-direction: column;
  gap: 0.2rem;
  flex-shrink: 0;
}

.chat-bubble.is-mine {
  align-self: flex-start;
}

.chat-bubble.is-theirs {
  align-self: flex-end;
}

.chat-bubble-body {
  padding: 0.55rem 0.8rem;
  border-radius: 14px;
  font-size: 0.9rem;
  line-height: 1.5;
  white-space: pre-wrap;
  word-break: break-word;
}

.chat-bubble.is-mine .chat-bubble-body {
  background: linear-gradient(135deg, #4d6f00, #7eb000);
  color: #fff;
  border-bottom-right-radius: 4px;
}

.chat-bubble.is-theirs .chat-bubble-body {
  background: #fff;
  border: 1px solid var(--line);
  color: var(--ink);
  border-bottom-left-radius: 4px;
}

.chat-bubble-time {
  font-size: 0.68rem;
  color: var(--ink-soft);
  padding-inline: 0.25rem;
}

.chat-bubble.is-mine .chat-bubble-time {
  text-align: start;
}

.chat-bubble.is-theirs .chat-bubble-time {
  text-align: end;
}

.chat-bubble.is-new {
  animation: rise-in 0.25s var(--ease) both;
}

.chat-composer {
  display: flex;
  flex-shrink: 0;
  gap: 0.5rem;
  padding: 0.65rem 0.85rem;
  border-top: 1px solid var(--line);
  background: #fff;
}

.chat-composer .input {
  flex: 1;
  min-height: 40px;
}

.chat-composer .primary-btn {
  min-height: 40px;
  padding-inline: 1.1rem;
  flex-shrink: 0;
}

@media (max-width: 800px) {
  .chat-app {
    grid-template-columns: 1fr;
    grid-template-rows: minmax(140px, 32%) minmax(0, 1fr);
  }

  .chat-sidebar {
    border-inline-end: 0;
    border-bottom: 1px solid var(--line);
    max-height: none;
    min-height: 0;
  }

  .chat-main {
    min-height: 0;
  }
}

/* User permissions */
.perm-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
  gap: 0.45rem;
}

.perm-check {
  min-height: 38px;
  font-size: 0.84rem;
}

.perm-chip {
  display: inline-block;
  margin: 0.1rem;
  padding: 0.12rem 0.45rem;
  border-radius: 999px;
  font-size: 0.7rem;
  font-weight: 600;
  background: rgba(126, 176, 0, 0.14);
  color: var(--teal-deep);
  white-space: nowrap;
}

/* ---------- Mobile bottom navigation (fixed bar) ---------- */
.mobile-bottom-nav {
  display: none;
}

@media (max-width: 992px) {
  :root {
    --bottom-nav-h: calc(3.75rem + var(--safe-bottom));
  }

  .mobile-bottom-nav {
    display: flex !important;
    position: fixed;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 45;
    align-items: stretch;
    justify-content: space-around;
    gap: 0.15rem;
    width: 100%;
    min-height: var(--bottom-nav-h);
    margin: 0;
    padding:
      0.4rem 0.4rem
      calc(0.4rem + var(--safe-bottom));
    background: rgba(255, 255, 255, 0.97);
    border-top: 1px solid var(--line);
    box-shadow: 0 -8px 28px rgba(40, 60, 0, 0.12);
    backdrop-filter: blur(14px);
    -webkit-backdrop-filter: blur(14px);
  }

  .mb-nav-item {
    flex: 1 1 0;
    min-width: 0;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 0.2rem;
    padding: 0.4rem 0.15rem;
    border: 0;
    border-radius: 12px;
    background: transparent;
    color: var(--ink-soft);
    font: inherit;
    text-decoration: none;
    cursor: pointer;
    -webkit-tap-highlight-color: transparent;
    transition: color 0.2s ease, background 0.2s ease;
  }

  .mb-nav-item:hover,
  .mb-nav-item:focus-visible {
    color: var(--teal-deep);
    background: rgba(126, 176, 0, 0.1);
    outline: none;
  }

  .mb-nav-item.active {
    color: var(--teal-deep);
    background: rgba(126, 176, 0, 0.14);
    font-weight: 700;
  }

  .mb-nav-icon {
    position: relative;
    width: 22px;
    height: 22px;
    display: grid;
    place-items: center;
  }

  .mb-nav-icon svg {
    width: 20px;
    height: 20px;
  }

  .mb-nav-label {
    font-size: 0.7rem;
    line-height: 1.2;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    max-width: 100%;
  }

  .mb-nav-badge {
    position: absolute;
    top: -0.35rem;
    inset-inline-end: -0.55rem;
    min-width: 1.05rem;
    height: 1.05rem;
    padding: 0 0.28rem;
    border-radius: 999px;
    display: inline-grid;
    place-items: center;
    font-size: 0.62rem;
    font-weight: 700;
    color: #fff;
    background: #c04545;
    line-height: 1;
  }

  .mb-nav-badge[hidden] {
    display: none !important;
  }

  .main-panel {
    padding-bottom: var(--bottom-nav-h);
  }

  .app-footer {
    padding-bottom: calc(0.85rem + var(--safe-bottom));
  }

  .pwa-install-bar {
    bottom: calc(var(--bottom-nav-h) + 0.55rem) !important;
  }
}
