/* Base + page grid: topbar / (sidebar + main) / footer */

* {
  box-sizing: border-box;
}

html {
  /* Slightly below the 16px default -- scales every rem-based size in the
     app down a notch without having to touch each declaration. */
  font-size: 93.75%;
}

html,
body {
  height: 100%;
}

body {
  margin: 0;
  font-family: "Segoe UI", "Inter", system-ui, -apple-system, sans-serif;
  background: var(--color-bg);
  color: var(--color-text);
  transition: background var(--transition-medium), color var(--transition-medium);
}

/* height, not min-height: pins the grid to the viewport so the middle
   (1fr) row is a real scroll container via .main's own overflow-y (below)
   instead of growing past the viewport and pushing the footer down when a
   page (e.g. a long list) has more content than fits on screen. */
.app-shell {
  display: grid;
  grid-template-rows: var(--topbar-height) 1fr var(--footer-height);
  grid-template-columns: 1fr;
  height: 100vh;
}

/* ---------- Top bar ---------- */

.topbar {
  grid-row: 1;
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding-inline: 1rem;
  border-block-end: 1px solid var(--color-border);
  background: var(--color-surface);
}

.topbar__sidebar-toggle {
  margin-inline-end: 0.25rem;
}

.topbar__brand {
  font-size: 1.375rem;
  font-weight: 800;
  letter-spacing: 0.01em;
  background: var(--brand-gradient);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
  user-select: none;
}

.topbar__spacer {
  flex: 1;
}

/* ---------- Body: sidebar + main ---------- */

.app-body {
  grid-row: 2;
  display: flex;
  min-height: 0;
}

.sidebar {
  flex: 0 0 var(--sidebar-width);
  width: var(--sidebar-width);
  overflow-x: hidden;
  overflow-y: auto;
  /* Column so a footer block (e.g. Back to app) can sit at the
     bottom: .sidebar__nav takes the free space (below). */
  display: flex;
  flex-direction: column;
  background: var(--color-surface);
  border-inline-end: 1px solid var(--color-border);
  transition: flex-basis var(--transition-medium), width var(--transition-medium);
}

.sidebar[data-collapsed="true"] {
  flex-basis: var(--sidebar-width-collapsed);
  width: var(--sidebar-width-collapsed);
}

.sidebar__nav {
  flex: 1 0 auto;
  padding: 0.75rem;
  display: flex;
  flex-direction: column;
  /* Spacing matches iShariah's (and iFaraid's) sidebar. */
  gap: 0.125rem;
}

.sidebar__section-label {
  padding-inline: 0.5rem;
  margin-block: 0.5rem 0.25rem;
  font-size: 0.6875rem;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--color-text-muted);
  white-space: nowrap;
  overflow: hidden;
}

/* Section header: label + optional action buttons on one row. As tall as an
   .icon-btn, with or without one, and 0.5rem above the first row (the
   margin plus the nav's gap), as in iShariah. */
.sidebar__section-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  min-block-size: 2.25rem;
  padding-inline-start: 0.5rem;
  margin-block: 0.5rem 0.375rem;
}

.sidebar__section-header .sidebar__section-label {
  margin-block: 0;
}

.sidebar[data-collapsed="true"] .sidebar__section-header {
  justify-content: center;
  padding-inline-start: 0;
}

.sidebar__section-actions {
  display: flex;
  align-items: center;
  gap: 0.125rem;
}

.sidebar[data-collapsed="true"] .sidebar__section-label,
.sidebar[data-collapsed="true"] .nav-item__label {
  opacity: 0;
  pointer-events: none;
}

.nav-item {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0.5rem 0.625rem;
  border-radius: var(--radius-sm);
  color: var(--color-text);
  text-decoration: none;
  cursor: pointer;
  white-space: nowrap;
  overflow: hidden;
  border: none;
  background: transparent;
  font: inherit;
  text-align: start;
  width: 100%;
}

.nav-item:hover {
  background: var(--color-surface-alt);
}

.nav-item[aria-current="page"] {
  background: var(--color-surface-alt);
  color: var(--color-accent);
  font-weight: 600;
}

.nav-item__icon {
  flex: 0 0 auto;
  width: 1.25rem;
  text-align: center;
}

.nav-item__label {
  transition: opacity var(--transition-fast);
}

/* ---------- Sidebar footer (pinned to the bottom of the sidebar; e.g. Feedback, Back to app) ---------- */

.sidebar__footer {
  flex: 0 0 auto;
  position: sticky;
  inset-block-end: 0;
  padding: 0.5rem 0.75rem 0.75rem;
  border-block-start: 1px solid var(--color-border);
  background: var(--color-surface);
}

.sidebar__footer .nav-item:focus-visible {
  outline: 2px solid var(--color-accent);
  outline-offset: -2px;
}

.main {
  flex: 1;
  min-width: 0;
  overflow-y: auto;
  padding: 1.5rem;
}

/* ---------- Workspace: bar + main (index.html, zakat.html, nisab.html) ----------
   Controls for the current screen (its title) sit in a bar above the
   scrolling .main, so they stay in view. Wraps .main in a column; admin.html
   has no wrapper and keeps .main directly in .app-body. */

.workspace {
  flex: 1;
  min-width: 0;
  min-height: 0;
  display: flex;
  flex-direction: column;
}

.workspace > .main {
  min-height: 0;
}

.workspace-bar {
  flex: 0 0 auto;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem 0.75rem;
  padding-block: 0.5rem;
  padding-inline: 1.5rem;
  border-block-end: 1px solid var(--color-border);
  background: var(--color-surface);
}

.workspace-bar__title {
  font-size: 0.9375rem;
  font-weight: 700;
}

/* ---------- Footer ---------- */

.footer {
  grid-row: 3;
  display: flex;
  align-items: center;
  justify-content: flex-end;
  padding-inline: 1rem;
  border-block-start: 1px solid var(--color-border);
  background: var(--color-surface);
  font-size: 0.75rem;
  color: var(--color-text-muted);
}

@media (max-width: 720px) {
  .sidebar {
    position: fixed;
    inset-block: var(--topbar-height) var(--footer-height);
    inset-inline-start: 0;
    z-index: 20;
    box-shadow: var(--shadow-md);
  }

  .sidebar[data-collapsed="true"] {
    flex-basis: 0;
    width: 0;
    border-inline-end: none;
  }
}
