/* =========================================================================
   Dashboard — dense, functional register for daily back-office use.
   Same token system as the public site, different layout logic.

   ALL SCREENS: sidebar is a slide-in drawer (hidden by default, opens via toggle).
   No desktop navbar — mobile-first layout only.
   ========================================================================= */

:root {
  --sidebar-w-collapsed: 64px;
  --sidebar-w-expanded: 232px;
}

* { min-width: 0; }

html, body { overflow-x: hidden; width: 100%; }

/* --- App shell ---------------------------------------------------------- */
.app-shell {
  display: flex;
  flex-direction: column;
  min-height: 100vh;
  width: 100%;
  max-width: 100vw;
  background: var(--cotton);
}

/* --- Sidebar ------------------------------------------------------------
   Slide-in drawer — hidden by default, opens via toggle.
   Same behavior across ALL screen sizes. ------------------------------- */
.app-sidebar {
  display: none;
}

.app-sidebar.is-open {
  display: flex;
  flex-direction: column;
  position: fixed;
  inset: 0;
  z-index: 60;
  width: min(280px, 84vw);
  height: 100vh;
  background: var(--ink-indigo-deep);
  color: var(--cotton);
  box-shadow: var(--shadow-lift);
  overflow-y: auto;
  overflow-x: hidden;
}

.sidebar-scrim {
  display: none;
}

.sidebar-scrim.is-visible {
  display: block;
  position: fixed;
  inset: 0;
  background: rgba(16,27,51,0.45);
  z-index: 55;
}

/* --- Brand -------------------------------------------------------------- */
.app-sidebar__brand {
  display: flex;
  align-items: center;
  gap: 0.6em;
  white-space: nowrap;
  padding: var(--space-2) var(--space-3);
  border-bottom: 1px solid var(--line-dark);
  margin-bottom: var(--space-2);
  flex-shrink: 0;
}

.app-sidebar.is-open .app-sidebar__brand {
  justify-content: flex-start;
}

.app-sidebar__brand-text {
  display: none;
  overflow: hidden;
}

.app-sidebar.is-open .app-sidebar__brand-text {
  display: block;
}

/* --- Navigation wrapper ------------------------------------------------- */
.app-nav {
  flex: 1;
  overflow-x: hidden;
}

/* --- Section labels --------------------------------------------------- */
.app-nav__section {
  margin-top: var(--space-3);
}

/* --- Labels ------------------------------------------------------------ */
.app-nav__label {
  padding: 0 var(--space-3);
  font-size: 0.68rem;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: rgba(247,244,236,0.4);
  margin-bottom: 0.5em;
  display: none;
  white-space: nowrap;
}

.app-sidebar.is-open .app-nav__label {
  display: block;
}

/* --- Nav links --------------------------------------------------------- */
.app-nav a {
  display: flex;
  align-items: center;
  gap: 0.9em;
  padding: 0.75em 0;
  justify-content: flex-start;
  font-size: 0.9rem;
  color: rgba(247,244,236,0.82);
  border-left: 3px solid transparent;
  border-bottom: none;
  transition: background 0.12s ease, color 0.12s ease;
  white-space: nowrap;
  text-decoration: none;
}

.app-sidebar.is-open .app-nav a {
  padding: 0.7em var(--space-3);
}

.app-nav a svg {
  flex-shrink: 0;
}

.app-nav a span.nav-label {
  display: none;
  overflow: hidden;
  text-overflow: ellipsis;
}

.app-sidebar.is-open .app-nav a span.nav-label {
  display: inline;
}

.app-nav a:hover {
  background: rgba(247,244,236,0.06);
  color: #fff;
}

.app-nav a[aria-current="page"] {
  background: rgba(200,155,60,0.14);
  border-left-color: var(--thread-gold);
  color: var(--thread-gold-light);
  font-weight: 600;
}

/* --- Badge -------------------------------------------------------------- */
.app-nav__badge {
  margin-left: auto;
  background: var(--thread-gold);
  color: var(--ink-indigo-deep);
  font-size: 0.7rem;
  font-weight: 700;
  border-radius: 999px;
  padding: 0.1em 0.5em;
  display: none;
}

.app-sidebar.is-open .app-nav__badge {
  display: inline-block;
}

/* --- Sidebar footer ----------------------------------------------------- */
.app-sidebar__foot {
  padding: var(--space-2);
  border-top: 1px solid var(--line-dark);
  font-size: 0.82rem;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.5em;
}

.app-sidebar.is-open .app-sidebar__foot {
  align-items: stretch;
  padding: var(--space-3);
}

.app-sidebar__foot .sync-widget span:not(.sync-dot),
.app-sidebar__foot .btn-block {
  display: none;
}

.app-sidebar.is-open .app-sidebar__foot .sync-widget span:not(.sync-dot),
.app-sidebar.is-open .app-sidebar__foot .btn-block {
  display: block;
}

.sidebar-expand-toggle {
  display: none;
}

/* --- Main content ------------------------------------------------------- */
.app-main {
  display: flex;
  flex-direction: column;
  min-height: 100vh;
  width: 100%;
  min-width: 0;
  overflow-x: hidden;
  flex: 1;
}

.app-topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: var(--space-2) var(--space-3);
  background: #fff;
  border-bottom: 1px solid var(--line);
  position: sticky;
  top: 0;
  z-index: 19;
  gap: var(--space-2);
  flex-wrap: wrap;
}

.app-topbar__title {
  font-family: var(--font-display);
  font-size: 1.15rem;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.app-topbar__actions {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  flex-wrap: wrap;
}

.app-content {
  padding: var(--space-4);
  flex: 1;
  min-width: 0;
  max-width: 100%;
  overflow-x: hidden;
}

@media (max-width: 640px) {
  .app-content {
    padding: var(--space-3);
  }
}

/* --- Menu toggle (hamburger) — visible on ALL screen sizes ------------ */
.menu-toggle {
  display: inline-flex;
  background: none;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  padding: 0.5em 0.7em;
  flex-shrink: 0;
  cursor: pointer;
}

/* --- Stat cards --------------------------------------------------------- */
.stat-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: var(--space-3);
  margin-bottom: var(--space-4);
}

@media (max-width: 900px) {
  .stat-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}

@media (max-width: 480px) {
  .stat-grid {
    grid-template-columns: minmax(0, 1fr);
  }
}

.stat-card {
  background: #fff;
  border-radius: var(--radius-md);
  padding: var(--space-3);
  box-shadow: var(--shadow-card);
  border-top: 3px solid var(--thread-gold);
  min-width: 0;
  overflow: hidden;
}

.stat-card__label {
  font-size: 0.82rem;
  color: var(--charcoal-soft);
  font-weight: 600;
}

.stat-card__value {
  font-family: var(--font-display);
  font-size: 2.1rem;
  margin-top: 0.15em;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* --- Panels ------------------------------------------------------------ */
.panel {
  background: #fff;
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-card);
  margin-bottom: var(--space-4);
}

.panel__head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: var(--space-3);
  border-bottom: 1px solid var(--line);
}

.panel__head h3 {
  font-size: 1.05rem;
}

.panel__body {
  padding: var(--space-3);
  min-width: 0;
}

.panel__body--flush {
  padding: 0;
  min-width: 0;
}

/* --- Data table ------------------------------------------------------ */
.table-scroll {
  width: 100%;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}

.data-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.92rem;
  min-width: 480px;
}

.data-table th {
  text-align: left;
  padding: 0.8em 1em;
  font-size: 0.76rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--charcoal-soft);
  border-bottom: 1px solid var(--line);
  white-space: nowrap;
}

.data-table td {
  padding: 0.85em 1em;
  border-bottom: 1px solid var(--line);
  vertical-align: middle;
}

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

.data-table tr:hover td {
  background: var(--cotton-dim);
}

.data-table__empty {
  padding: var(--space-4);
  text-align: center;
  color: var(--charcoal-soft);
}

.clickable-row {
  cursor: pointer;
}

.clickable-row:hover td {
  background: var(--cotton-dim);
}

.clickable-row td a {
  position: relative;
  z-index: 1;
}

.row-link {
  display: block;
}

.table-toolbar {
  display: flex;
  gap: var(--space-2);
  flex-wrap: wrap;
  align-items: center;
  margin-bottom: var(--space-3);
}

.table-toolbar input,
.table-toolbar select {
  width: auto;
  min-width: 180px;
}

/* --- Activity feed --------------------------------------------------- */
.activity-list li {
  display: flex;
  gap: 0.8em;
  padding: 0.7em 0;
  border-bottom: 1px solid var(--line);
  font-size: 0.9rem;
}

.activity-list li:last-child {
  border-bottom: none;
}

.activity-list__dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  margin-top: 0.5em;
  flex-shrink: 0;
  background: var(--thread-gold);
}

.activity-list__time {
  color: var(--charcoal-soft);
  font-size: 0.78rem;
  display: block;
  margin-top: 0.2em;
}

/* --- Customer typeahead (measurement form) --------------------------- */
.customer-suggestions {
  display: none;
  position: absolute;
  left: 0;
  right: 0;
  top: 100%;
  background: #fff;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  box-shadow: var(--shadow-lift);
  max-height: 220px;
  overflow-y: auto;
  z-index: 30;
  margin-top: 2px;
}

.customer-suggestions.is-open {
  display: block;
}

.customer-suggestion {
  padding: 0.6em 0.9em;
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 0.6em;
  cursor: pointer;
  border-bottom: 1px solid var(--cotton-dim);
}

.customer-suggestion:last-child {
  border-bottom: none;
}

.customer-suggestion:hover {
  background: var(--cotton-dim);
}

.customer-suggestion__name {
  font-weight: 600;
  font-size: 0.92rem;
}

.customer-suggestion__contact {
  font-size: 0.72rem;
  color: var(--charcoal-soft);
  white-space: nowrap;
}

/* --- Style manager (image-only add/remove) ------------------------------ */
.style-manager-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
  gap: var(--space-2);
  margin-top: var(--space-3);
}

.style-manager-item {
  position: relative;
  display: block;
  border-radius: var(--radius-sm);
  overflow: hidden;
  aspect-ratio: 3/4;
  cursor: pointer;
  box-shadow: var(--shadow-card);
}

.style-manager-item__checkbox {
  position: absolute;
  top: 8px;
  left: 8px;
  width: 20px;
  height: 20px;
  z-index: 2;
  accent-color: var(--thread-gold);
}

.style-manager-item__img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
  transition: opacity 0.12s ease, transform 0.12s ease;
}

.style-manager-item__img--empty {
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--cotton-dim);
  color: var(--charcoal-soft);
  font-size: 0.8rem;
}

.style-manager-item__check {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(200,155,60,0.55);
  color: #fff;
  font-size: 2rem;
  font-weight: 700;
  opacity: 0;
  transition: opacity 0.12s ease;
  pointer-events: none;
}

.style-manager-item__checkbox:checked ~ .style-manager-item__check {
  opacity: 1;
}

.style-manager-item__checkbox:checked ~ .style-manager-item__img {
  transform: scale(1.04);
}

/* --- Measurement form (dynamic) --------------------------------------- */
.measurement-fields-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
  gap: var(--space-2) var(--space-3);
}

.measurement-field-unit {
  font-size: 0.78rem;
  color: var(--charcoal-soft);
  margin-left: 0.4em;
}

.category-pill-select {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5em;
  margin-bottom: var(--space-3);
}

.category-pill {
  padding: 0.5em 1.1em;
  border-radius: 999px;
  border: 1.5px solid var(--line);
  font-size: 0.88rem;
  font-weight: 600;
  background: #fff;
  transition: all 0.12s ease;
}

.category-pill.is-active,
.category-pill:hover {
  border-color: var(--thread-gold);
  background: rgba(200,155,60,0.1);
  color: var(--rust);
}

/* --- Subscription banner in dashboard (upcoming expiry hint) ------------- */
.sub-banner {
  display: flex;
  align-items: center;
  gap: 0.8em;
  justify-content: space-between;
  background: var(--ink-indigo);
  color: var(--cotton);
  padding: var(--space-2) var(--space-3);
  border-radius: var(--radius-md);
  margin-bottom: var(--space-4);
  font-size: 0.9rem;
  flex-wrap: wrap;
}

/* --- Sync widget --------------------------------------------------------- */
.sync-widget {
  display: flex;
  align-items: center;
  gap: 0.6em;
  font-size: 0.85rem;
  color: var(--charcoal-soft);
}

.sync-dot {
  width: 9px;
  height: 9px;
  border-radius: 50%;
  background: var(--status-ready);
}

.sync-dot.is-offline {
  background: var(--status-cancelled);
}

.sync-dot.is-syncing {
  background: var(--status-pending);
  animation: pulse 1s infinite;
}

@keyframes pulse {
  50% {
    opacity: 0.3;
  }
}

/* --- Install banner (PWA install prompt) ------------------------------ */
.install-banner {
  position: fixed;
  left: var(--space-3);
  right: var(--space-3);
  bottom: var(--space-3);
  z-index: 90;
  background: var(--ink-indigo-deep);
  color: var(--cotton);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-lift);
  padding: var(--space-3);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-3);
  flex-wrap: wrap;
  max-width: 480px;
  margin: 0 auto;
}

.install-banner__text {
  display: flex;
  flex-direction: column;
  gap: 0.2em;
  font-size: 0.88rem;
}

.install-banner__text strong {
  font-family: var(--font-display);
  font-size: 1.05rem;
}

.install-banner__text span {
  color: rgba(247,244,236,0.75);
}

.install-banner__actions {
  display: flex;
  align-items: center;
  gap: 0.5em;
  flex-shrink: 0;
}

.install-banner__dismiss {
  background: none;
  border: none;
  color: rgba(247,244,236,0.6);
  font-size: 1.3rem;
  line-height: 1;
  padding: 0.2em 0.4em;
}

.install-banner__dismiss:hover {
  color: #fff;
}

/* --- Login page --------------------------------------------------------- */
.auth-shell {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--ink-indigo);
  padding: var(--space-4);
}

.auth-card {
  width: 100%;
  max-width: 400px;
  background: var(--cotton);
  border-radius: var(--radius-lg);
  padding: var(--space-5) var(--space-4);
  box-shadow: var(--shadow-lift);
}

.auth-card__brand {
  text-align: center;
  margin-bottom: var(--space-4);
}

/* --- Expired page -------------------------------------------------------- */
.expired-shell {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--ink-indigo);
  padding: var(--space-4);
  text-align: center;
}

.expired-card {
  max-width: 460px;
  background: var(--cotton);
  border-radius: var(--radius-lg);
  padding: var(--space-5) var(--space-4);
  box-shadow: var(--shadow-lift);
}

.expired-card__icon {
  width: 56px;
  height: 56px;
  border-radius: 50%;
  background: rgba(162,74,62,0.12);
  color: var(--status-cancelled);
  display: flex;
  align-items: center;
  justify-content: center;
  margin: 0 auto var(--space-3);
}