/* =========================================================================
 * app.css — shared design layer for the auth and app shells. Consumes CSS
 * custom properties injected by includes/authLayout.php + includes/layout.php
 * from PHP constants (BRAND_PRIMARY, BRAND_ACCENT, ...), so each deployment
 * themes itself without touching this file.
 * ========================================================================= */

:root {
  /* Typography */
  --font-sans: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto,
               'Helvetica Neue', Arial, sans-serif;

  /* Surfaces */
  --surface-page: #f6f7fb;
  --surface-card: #ffffff;
  --surface-muted: #f3f4f6;
  --border-subtle: #e5e7eb;

  /* Text */
  --text-strong: #111827;
  --text-body:   #374151;
  --text-muted:  #6b7280;

  /* Elevation */
  --shadow-sm: 0 1px 2px rgba(17, 24, 39, .06), 0 1px 3px rgba(17, 24, 39, .04);
  --shadow-md: 0 4px 6px -1px rgba(17, 24, 39, .07), 0 2px 4px -2px rgba(17, 24, 39, .05);
  --shadow-lg: 0 20px 40px -12px rgba(17, 24, 39, .18), 0 8px 16px -8px rgba(17, 24, 39, .12);

  /* Radius */
  --radius-sm: .5rem;
  --radius-md: .75rem;
  --radius-lg: 1rem;

  /* Bootstrap overrides — brand variables come in via inline <style> in the
     layout <head>, so --brand-primary etc. are always defined. */
  --bs-primary: var(--brand-primary);
  --bs-primary-rgb: var(--brand-primary-rgb);
  --bs-link-color: var(--brand-primary);
  --bs-link-hover-color: var(--brand-primary-dark);
  --bs-body-font-family: var(--font-sans);
  --bs-body-color: var(--text-body);
  --bs-body-bg: var(--surface-page);
  --bs-border-color: var(--border-subtle);
}

/* -------------------------------------------------------------------------
 * Global type + surface
 * ------------------------------------------------------------------------- */
body {
  font-family: var(--font-sans);
  color: var(--text-body);
  background: var(--surface-page);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}
h1, h2, h3, h4, h5, h6, .fw-bold { color: var(--text-strong); letter-spacing: -.01em; }
.text-muted { color: var(--text-muted) !important; }
code { background: var(--surface-muted); padding: .1rem .35rem; border-radius: .35rem; color: var(--text-body); }

/* -------------------------------------------------------------------------
 * Buttons — brand-tinted primary, softer outline, uniform height
 * ------------------------------------------------------------------------- */
.btn {
  --bs-btn-padding-y: .55rem;
  --bs-btn-padding-x: 1rem;
  --bs-btn-font-weight: 500;
  --bs-btn-border-radius: var(--radius-sm);
  transition: box-shadow .15s ease, transform .05s ease;
}
.btn-primary {
  --bs-btn-bg: var(--brand-primary);
  --bs-btn-border-color: var(--brand-primary);
  --bs-btn-hover-bg: var(--brand-primary-dark);
  --bs-btn-hover-border-color: var(--brand-primary-dark);
  --bs-btn-active-bg: var(--brand-primary-dark);
  --bs-btn-active-border-color: var(--brand-primary-dark);
  --bs-btn-focus-shadow-rgb: var(--brand-primary-rgb);
}
.btn-primary:hover { box-shadow: 0 6px 14px -6px rgba(var(--brand-primary-rgb), .55); }
.btn-outline-primary {
  --bs-btn-color: var(--brand-primary);
  --bs-btn-border-color: var(--brand-primary);
  --bs-btn-hover-bg: var(--brand-primary);
  --bs-btn-hover-border-color: var(--brand-primary);
}
.btn-lg { --bs-btn-padding-y: .7rem; --bs-btn-padding-x: 1.25rem; }
.btn-sm { --bs-btn-padding-y: .35rem; --bs-btn-padding-x: .7rem; }

/* -------------------------------------------------------------------------
 * Cards — soft shadow, hairline border, no default header stripe
 * ------------------------------------------------------------------------- */
.card {
  --bs-card-border-color: var(--border-subtle);
  --bs-card-border-radius: var(--radius-md);
  --bs-card-inner-border-radius: calc(var(--radius-md) - 1px);
  --bs-card-cap-bg: transparent;
  box-shadow: var(--shadow-sm);
}
.card.card-elevated { border: 0; box-shadow: var(--shadow-lg); border-radius: var(--radius-lg); }
.card-header {
  border-bottom-color: var(--border-subtle);
  background: transparent;
  padding: 1rem 1.25rem;
  font-weight: 600;
  color: var(--text-strong);
}
.card-header.bg-light { background: var(--surface-muted) !important; }

/* -------------------------------------------------------------------------
 * Forms — floating labels + input groups, brand focus ring
 * ------------------------------------------------------------------------- */
.form-control, .form-select {
  border-color: var(--border-subtle);
  border-radius: var(--radius-sm);
  padding: .625rem .85rem;
  transition: border-color .15s ease, box-shadow .15s ease;
}
.form-control:focus, .form-select:focus {
  border-color: var(--brand-primary);
  box-shadow: 0 0 0 4px rgba(var(--brand-primary-rgb), .15);
}
.form-label {
  font-weight: 500;
  color: var(--text-strong);
  margin-bottom: .375rem;
  font-size: .875rem;
}
.form-text { color: var(--text-muted); }
.input-group-text {
  background: var(--surface-muted);
  border-color: var(--border-subtle);
  color: var(--text-muted);
}
.form-control-lg.otp-input {
  letter-spacing: .6rem;
  font-size: 1.5rem;
  font-weight: 600;
  text-align: center;
  padding-left: 1.6rem; /* balance letter-spacing so the caret centers */
}

/* -------------------------------------------------------------------------
 * Alerts — softer, brand-friendly
 * ------------------------------------------------------------------------- */
.alert {
  border: 1px solid transparent;
  border-radius: var(--radius-sm);
  padding: .7rem .9rem;
  font-size: .9rem;
}
.alert-info    { background: #eef4ff; border-color: #dbeafe; color: #1e3a8a; }
.alert-success { background: #ecfdf5; border-color: #bbf7d0; color: #065f46; }
.alert-warning { background: #fffbeb; border-color: #fde68a; color: #78350f; }
.alert-danger  { background: #fef2f2; border-color: #fecaca; color: #991b1b; }

/* -------------------------------------------------------------------------
 * Badges — tuned for readability at small sizes
 * ------------------------------------------------------------------------- */
.badge {
  font-weight: 500;
  padding: .35em .6em;
  border-radius: .5rem;
  letter-spacing: .01em;
}

/* =========================================================================
 * AUTH SHELL — split-screen layout used by authLayout.php
 * ========================================================================= */
.auth-shell {
  min-height: 100vh;
  display: grid;
  grid-template-columns: 1fr;
}
@media (min-width: 992px) {
  .auth-shell { grid-template-columns: 1.05fr 1fr; }
}

/* Left brand panel — hidden below lg to keep the form breathing on mobile */
.auth-brand {
  display: none;
  position: relative;
  padding: 3rem;
  color: #fff;
  background:
    radial-gradient(120% 80% at 0% 0%, rgba(255,255,255,.14), transparent 60%),
    radial-gradient(80% 60% at 100% 100%, rgba(0,0,0,.25), transparent 60%),
    linear-gradient(135deg, var(--brand-primary), var(--brand-accent));
  overflow: hidden;
  isolation: isolate;
}
@media (min-width: 992px) { .auth-brand { display: flex; flex-direction: column; } }

.auth-brand::before,
.auth-brand::after {
  content: "";
  position: absolute;
  border-radius: 50%;
  filter: blur(40px);
  opacity: .35;
  z-index: -1;
}
.auth-brand::before { width: 320px; height: 320px; background: #fff; top: -80px; right: -80px; }
.auth-brand::after  { width: 260px; height: 260px; background: var(--brand-primary-dark); bottom: -60px; left: -40px; opacity: .55; }

.auth-brand__logo {
  display: inline-flex;
  align-items: center;
  gap: .65rem;
  font-weight: 700;
  font-size: 1.15rem;
  letter-spacing: -.01em;
}
.auth-brand__logo img { height: 32px; width: auto; }
.auth-brand__logo-mark {
  width: 36px; height: 36px;
  border-radius: 10px;
  display: inline-flex; align-items: center; justify-content: center;
  background: rgba(255,255,255,.16);
  backdrop-filter: blur(6px);
  font-weight: 700;
  font-size: 1.1rem;
}
.auth-brand__hero {
  margin-top: auto;
  max-width: 460px;
}
.auth-brand__hero h1 {
  color: #fff;
  font-size: clamp(1.6rem, 2.2vw, 2.3rem);
  line-height: 1.2;
  font-weight: 700;
  margin-bottom: .75rem;
  letter-spacing: -.02em;
}
.auth-brand__hero p {
  color: rgba(255,255,255,.85);
  font-size: 1rem;
  line-height: 1.55;
  margin-bottom: 2rem;
}
.auth-brand__features {
  list-style: none;
  padding: 0;
  margin: 0;
  display: flex;
  flex-direction: column;
  gap: .75rem;
}
.auth-brand__features li {
  display: flex;
  align-items: center;
  gap: .6rem;
  color: rgba(255,255,255,.92);
  font-size: .95rem;
}
.auth-brand__features li i {
  width: 22px; height: 22px;
  border-radius: 50%;
  background: rgba(255,255,255,.18);
  display: inline-flex; align-items: center; justify-content: center;
  font-size: .7rem;
}
.auth-brand__footer {
  margin-top: 2.5rem;
  font-size: .8rem;
  color: rgba(255,255,255,.7);
}

/* Right form panel */
.auth-form {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 2.5rem 1.25rem;
  background: var(--surface-page);
}
.auth-form__inner {
  width: 100%;
  max-width: 440px;
}
.auth-form__brand-mobile {
  display: flex;
  align-items: center;
  gap: .55rem;
  justify-content: center;
  font-weight: 700;
  color: var(--brand-primary);
  margin-bottom: 1.75rem;
}
@media (min-width: 992px) { .auth-form__brand-mobile { display: none; } }
.auth-form__brand-mobile img { height: 28px; }

.auth-form h1.auth-form__title {
  font-size: 1.6rem;
  font-weight: 700;
  color: var(--text-strong);
  margin-bottom: .35rem;
  letter-spacing: -.015em;
}
.auth-form__subtitle {
  color: var(--text-muted);
  font-size: .95rem;
  margin-bottom: 1.75rem;
}
.auth-form .card {
  border: 0;
  box-shadow: none;
  background: transparent;
}
.auth-form .card-body { padding: 0; }

.auth-alt {
  margin-top: 1.75rem;
  text-align: center;
  font-size: .875rem;
  color: var(--text-muted);
}
.auth-alt__divider {
  display: flex; align-items: center; gap: .75rem;
  color: var(--text-muted);
  font-size: .8rem;
  text-transform: uppercase;
  letter-spacing: .08em;
  margin: 1.5rem 0 1.25rem;
}
.auth-alt__divider::before,
.auth-alt__divider::after {
  content: ""; flex: 1; height: 1px; background: var(--border-subtle);
}
.auth-alt__row {
  display: flex; gap: .5rem; flex-wrap: wrap; justify-content: center;
}
.auth-alt__row a {
  display: inline-flex; align-items: center; gap: .45rem;
  padding: .55rem .9rem;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border-subtle);
  color: var(--text-body);
  text-decoration: none;
  font-weight: 500;
  font-size: .875rem;
  transition: border-color .15s, background .15s, color .15s;
}
.auth-alt__row a:hover {
  border-color: var(--brand-primary);
  color: var(--brand-primary);
  background: rgba(var(--brand-primary-rgb), .04);
}

/* =========================================================================
 * APP SHELL — used by layout.php
 *   Left sidebar (drawer on <lg, static column at lg+) + top bar + content.
 *   See docs/architecture-app-shell-sidebar.md for the design overview.
 * ========================================================================= */
:root {
  --sidebar-width: 260px;
  --topbar-height: 60px;
}

.app-body-shell { min-height: 100vh; }

.app-shell {
  display: block;
  min-height: 100vh;
}
@media (min-width: 992px) {
  .app-shell {
    display: grid;
    grid-template-columns: var(--sidebar-width) 1fr;
    align-items: stretch;
  }
}

/* -------- Sidebar --------
 *   Bootstrap defaults the offcanvas background to --bs-body-bg (grey) and
 *   forces `background-color: transparent !important` at lg+. Pin the
 *   offcanvas CSS variables + repeat the rule with matching specificity so
 *   our sidebar renders as a white panel on every viewport.
 * ------------------------------------------------------------------ */
.app-sidebar.offcanvas-lg {
  --bs-offcanvas-bg: #fff;
  --bs-offcanvas-color: var(--text-body);
  --bs-offcanvas-width: 300px;
  --bs-offcanvas-border-width: 0;
  --bs-offcanvas-box-shadow: var(--shadow-lg);
  background: #fff;
  border-right: 1px solid var(--border-subtle);
  display: flex;
  flex-direction: column;
}
@media (max-width: 991.98px) {
  .app-sidebar.offcanvas-lg.show { box-shadow: var(--shadow-lg); }
}
@media (min-width: 992px) {
  .app-sidebar.offcanvas-lg {
    background-color: #fff !important; /* beat Bootstrap's transparent !important */
    position: sticky;
    top: 0;
    height: 100vh;
    width: var(--sidebar-width);
    max-height: 100vh;
    overflow-y: auto;
  }
}

.app-sidebar__header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: .5rem;
  padding: 1rem 1.1rem;
  border-bottom: 1px solid var(--border-subtle);
  min-height: var(--topbar-height);
}
.app-sidebar__brand {
  display: inline-flex; align-items: center; gap: .6rem;
  font-weight: 700;
  color: var(--brand-primary);
  text-decoration: none;
  letter-spacing: -.01em;
  font-size: 1.05rem;
}
.app-sidebar__brand:hover { color: var(--brand-primary-dark); }
.app-sidebar__brand img { height: 28px; width: auto; }
.app-sidebar__brand-mark {
  width: 32px; height: 32px;
  border-radius: 9px;
  display: inline-flex; align-items: center; justify-content: center;
  background: linear-gradient(135deg, var(--brand-primary), var(--brand-accent));
  color: #fff;
  font-size: .95rem;
  font-weight: 700;
}
.app-sidebar__brand-name {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.app-sidebar__nav {
  flex: 1 1 auto;
  padding: .75rem .55rem;
  overflow-y: auto;
}

.app-nav {
  list-style: none;
  padding: 0;
  margin: 0;
  display: flex;
  flex-direction: column;
  gap: .15rem;
}
.app-nav__link {
  display: flex;
  align-items: center;
  gap: .7rem;
  width: 100%;
  padding: .6rem .75rem;
  border-radius: var(--radius-sm);
  color: var(--text-body);
  font-family: var(--font-sans);  /* buttons don't inherit font by default */
  font-weight: 500;
  font-size: .925rem;
  line-height: 1.4;
  text-decoration: none;
  border: 0;
  background: transparent;
  text-align: left;
  cursor: pointer;
  transition: background .15s, color .15s;
}
.app-nav__link:hover,
.app-nav__link:focus {
  background: rgba(var(--brand-primary-rgb), .07);
  color: var(--brand-primary);
}
.app-nav__link.is-active {
  background: rgba(var(--brand-primary-rgb), .12);
  color: var(--brand-primary);
  font-weight: 600;
}
.app-nav__icon {
  width: 20px;
  text-align: center;
  font-size: .95rem;
  color: currentColor;
  opacity: .85;
}
.app-nav__link.is-active .app-nav__icon { opacity: 1; }

.app-nav__group-toggle .app-nav__caret {
  margin-left: auto;
  font-size: .7rem;
  transition: transform .2s ease;
  opacity: .6;
}
.app-nav__group-toggle[aria-expanded="true"] .app-nav__caret {
  transform: rotate(180deg);
}

.app-nav--sub {
  padding: .1rem 0 .35rem 2.15rem;
  gap: 0;
}
.app-nav__sublink {
  display: block;
  padding: .45rem .7rem;
  border-radius: var(--radius-sm);
  color: var(--text-muted);
  font-size: .875rem;
  font-weight: 500;
  text-decoration: none;
  transition: background .15s, color .15s;
}
.app-nav__sublink:hover,
.app-nav__sublink:focus {
  background: rgba(var(--brand-primary-rgb), .06);
  color: var(--brand-primary);
}
.app-nav__sublink.is-active {
  background: rgba(var(--brand-primary-rgb), .12);
  color: var(--brand-primary);
  font-weight: 600;
}

/* -------- Body (topbar + main + footer) -------- */
.app-body {
  display: flex;
  flex-direction: column;
  min-width: 0; /* let grid child shrink to fit narrow viewports */
  min-height: 100vh;
}

.app-topbar {
  position: sticky;
  top: 0;
  z-index: 1020;
  display: flex;
  align-items: center;
  gap: .5rem;
  min-height: var(--topbar-height);
  padding: .55rem 1rem;
  background: rgba(255, 255, 255, .92);
  border-bottom: 1px solid var(--border-subtle);
  backdrop-filter: saturate(180%) blur(8px);
}
.app-topbar__toggle {
  background: transparent;
  border: 1px solid var(--border-subtle);
  color: var(--text-body);
  width: 40px;
  height: 40px;
  border-radius: var(--radius-sm);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  transition: background .15s, color .15s, border-color .15s;
}
.app-topbar__toggle:hover {
  background: rgba(var(--brand-primary-rgb), .08);
  color: var(--brand-primary);
  border-color: rgba(var(--brand-primary-rgb), .3);
}
.app-topbar__brand {
  display: inline-flex; align-items: center; gap: .55rem;
  font-weight: 700;
  color: var(--brand-primary);
  text-decoration: none;
  font-size: 1rem;
}
.app-topbar__brand img { height: 26px; }

.app-topbar__actions {
  display: flex;
  align-items: center;
  gap: .5rem;
}
.app-topbar__chip {
  display: inline-flex;
  align-items: center;
  gap: .45rem;
  padding: .45rem .75rem;
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-sm);
  background: #fff;
  color: var(--text-body);
  font-weight: 500;
  font-size: .875rem;
}
.app-topbar__chip:hover,
.app-topbar__chip:focus {
  border-color: rgba(var(--brand-primary-rgb), .35);
  color: var(--brand-primary);
  background: rgba(var(--brand-primary-rgb), .04);
}
.app-topbar__chip.dropdown-toggle::after {
  margin-left: .1rem;
  opacity: .55;
}

/* Dropdown menus in the topbar match the previous navbar styling */
.app-topbar .dropdown-menu {
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-md);
  padding: .35rem;
  margin-top: .35rem;
}
.app-topbar .dropdown-item {
  border-radius: var(--radius-sm);
  padding: .5rem .7rem;
  font-size: .9rem;
}
.app-topbar .dropdown-item:hover {
  background: rgba(var(--brand-primary-rgb), .08);
  color: var(--brand-primary);
}

.app-main {
  flex: 1 1 auto;
  padding: 1.75rem 0 3rem;
}
.app-container {
  max-width: 1400px;
  margin: 0 auto;
  padding: 0 1.5rem;
}

/* =========================================================================
 * PUBLIC SHELL — used by includes/publicLayout.php for anonymous visitors.
 *   Simple top header + centered content + footer. Downstream projects that
 *   need a richer shopfront should fork this + publicRouter.php into their
 *   own shop* equivalents.
 * ========================================================================= */
.public-container {
  max-width: 1200px;
  margin: 0 auto;
  padding: 0 1.5rem;
  width: 100%;
}

.public-header {
  background: #fff;
  border-bottom: 1px solid var(--border-subtle);
  padding: .9rem 0;
  position: sticky;
  top: 0;
  z-index: 1030;
}
.public-header .public-container {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
}
.public-header__brand {
  display: inline-flex;
  align-items: center;
  gap: .55rem;
  font-weight: 700;
  color: var(--brand-primary);
  text-decoration: none;
  font-size: 1.1rem;
  letter-spacing: -.01em;
}
.public-header__brand img { height: 28px; width: auto; }
.public-header__brand-mark {
  width: 32px; height: 32px;
  border-radius: 9px;
  display: inline-flex; align-items: center; justify-content: center;
  background: linear-gradient(135deg, var(--brand-primary), var(--brand-accent));
  color: #fff;
  font-size: .95rem;
  font-weight: 700;
}
.public-header__nav { display: flex; align-items: center; gap: .5rem; }

.public-main { padding: 3rem 0 4rem; min-height: calc(100vh - 60px - 60px); }

.public-footer {
  background: #fff;
  border-top: 1px solid var(--border-subtle);
  padding: 1.25rem 0;
  color: var(--text-muted);
  text-align: center;
  font-size: .8rem;
}

/* Page header — used at the top of every content page */
.page-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  margin-bottom: 1.5rem;
  flex-wrap: wrap;
}
.page-header__title {
  display: flex; align-items: center; gap: .75rem;
  font-size: 1.5rem;
  font-weight: 700;
  margin: 0;
  color: var(--text-strong);
  letter-spacing: -.015em;
}
.page-header__title .page-header__icon {
  width: 40px; height: 40px;
  display: inline-flex; align-items: center; justify-content: center;
  border-radius: var(--radius-sm);
  background: rgba(var(--brand-primary-rgb), .1);
  color: var(--brand-primary);
  font-size: 1rem;
}
.page-header__subtitle {
  color: var(--text-muted);
  font-size: .9rem;
  margin: .25rem 0 0;
  font-weight: 400;
}
.page-header__actions { display: flex; gap: .5rem; flex-wrap: wrap; }

/* Tables — replace default Bootstrap borders with hairlines and roomier rows */
.table {
  --bs-table-hover-bg: rgba(var(--brand-primary-rgb), .04);
  --bs-table-border-color: var(--border-subtle);
  margin-bottom: 0;
}
.table > thead {
  background: var(--surface-muted);
}
.table > thead th {
  font-weight: 600;
  color: var(--text-muted);
  font-size: .75rem;
  text-transform: uppercase;
  letter-spacing: .06em;
  padding: .85rem 1rem;
  border-bottom: 1px solid var(--border-subtle);
}
.table > tbody > tr > td {
  padding: .95rem 1rem;
  vertical-align: middle;
  border-color: var(--border-subtle);
}
.table > tbody > tr:last-child > td { border-bottom: 0; }

/* KPI cards for the dashboard */
.stat-card {
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-md);
  padding: 1.25rem;
  background: #fff;
  box-shadow: var(--shadow-sm);
  height: 100%;
  transition: transform .15s ease, box-shadow .15s ease;
}
.stat-card:hover { transform: translateY(-1px); box-shadow: var(--shadow-md); }
.stat-card__icon {
  width: 42px; height: 42px;
  border-radius: var(--radius-sm);
  display: inline-flex; align-items: center; justify-content: center;
  background: rgba(var(--brand-primary-rgb), .1);
  color: var(--brand-primary);
  margin-bottom: .85rem;
  font-size: 1.05rem;
}
.stat-card__label {
  font-size: .75rem;
  text-transform: uppercase;
  letter-spacing: .06em;
  color: var(--text-muted);
  font-weight: 600;
  margin-bottom: .25rem;
}
.stat-card__value {
  font-size: 1.6rem;
  font-weight: 700;
  color: var(--text-strong);
  line-height: 1.1;
  margin-bottom: .1rem;
}
.stat-card__delta { font-size: .8rem; color: var(--text-muted); }

/* Footer */
.app-footer {
  text-align: center;
  color: var(--text-muted);
  font-size: .8rem;
  padding: 1.25rem 0;
}
