/* ═══════════════════════════════════════════════════════════
   MAPA — layout.css  |  auth screen · app shell · sidebar · topbar
   ═══════════════════════════════════════════════════════════ */

/* ── App root ─────────────────────────────────────────────── */
#app-root { display: flex; flex-direction: column; height: 100vh; overflow: hidden; }

/* ══════════════════════════════════════════════════════════
   AUTH SCREEN
   ══════════════════════════════════════════════════════════ */
#view-auth {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  background: var(--bg);
  padding: 24px;
}

.auth-card {
  background: var(--card);
  border: 1px solid var(--border2);
  border-radius: var(--r-lg);
  padding: 40px 32px;
  width: 100%;
  max-width: 380px;
  text-align: center;
  box-shadow: var(--sh-3);
}

/* ASPHORA brand images (index.html) */
.auth-logo-img { width: 190px; max-width: 80%; display: block; margin: 0 auto 14px; }
.tb-brand-img  { width: 34px; height: 34px; display: block; border-radius: var(--r-md); }
/* Sidebar header carries no logo (brand lives in the topbar) — keep room
   for the absolutely-positioned collapse toggle above the project name */
.sid-logo-mark { min-height: 24px; }

.auth-logo {
  width: 64px;
  height: 64px;
  background: var(--sidebar-bg);
  border-radius: var(--r-lg);
  display: flex;
  align-items: center;
  justify-content: center;
  margin: 0 auto 20px;
  font-size: 26px;
  font-weight: 700;
  color: #fff;
  letter-spacing: -0.5px;
  font-family: "Plus Jakarta Sans", "Inter", system-ui, sans-serif;
}

.auth-title {
  font-size: 21px;
  font-weight: 700;
  color: var(--text);
  letter-spacing: -0.3px;
  margin-bottom: 4px;
  font-family: "Plus Jakarta Sans", "Inter", system-ui, sans-serif;
}

.auth-tagline {
  font-size: 12px;
  color: var(--text3);
  margin-bottom: 8px;
}

.auth-project {
  font-size: 11px;
  font-weight: 600;
  color: var(--blue2);
  background: rgba(59,130,246,0.1);
  border: 1px solid rgba(59,130,246,0.2);
  border-radius: var(--r-sm);
  padding: 4px 12px;
  display: inline-block;
  margin-bottom: 28px;
}

.auth-divider {
  height: 1px;
  background: var(--border);
  margin: 24px 0;
}

/* Email/password form */
.auth-form { display: flex; flex-direction: column; gap: 10px; text-align: left; }
.auth-input {
  width: 100%;
  padding: 13px 14px;
  background: var(--bg3);
  border: 1px solid var(--border2);
  border-radius: var(--r-md);
  color: var(--text);
  font-size: 15px;
  font-family: inherit;
  outline: none;
  transition: border-color var(--dur);
  box-sizing: border-box;
}
.auth-input:focus { border-color: var(--blue2); }
.auth-input::placeholder { color: var(--text3); }

/* OR separator */
.auth-or {
  display: flex;
  align-items: center;
  gap: 10px;
  margin: 18px 0 14px;
  color: var(--text3);
  font-size: 11px;
}
.auth-or::before, .auth-or::after {
  content: '';
  flex: 1;
  height: 1px;
  background: var(--border);
}

.auth-footer {
  font-size: 11px;
  color: var(--text3);
  margin-top: 20px;
}

/* Unauthorized panel */
.auth-denied {
  display: none;
  margin-top: 16px;
  background: rgba(220,38,38,0.08);
  border: 1px solid rgba(220,38,38,0.2);
  border-radius: var(--r-md);
  padding: 16px;
}
.auth-denied.show { display: block; }
.auth-denied-title { font-size: 13px; font-weight: 700; color: var(--red2); margin-bottom: 4px; }
.auth-denied-body  { font-size: 12px; color: var(--text2); }
.auth-denied-email { font-size: 11px; color: var(--text3); margin-top: 6px; font-family: monospace; }

/* ══════════════════════════════════════════════════════════
   APP SHELL — shared for Dashboard + role header
   ══════════════════════════════════════════════════════════ */
#app-shell {
  display: flex;
  flex-direction: column;
  height: 100vh;
  overflow: hidden;
}

/* Admin layout: topbar + view-dashboard must fill 100vh */
body.is-admin {
  height: 100vh;
  overflow: hidden;
  display: flex;
  flex-direction: column;
}
body.is-admin #view-dashboard {
  flex: 1;
  display: flex;
  overflow: hidden;
  min-height: 0;
}

/* ── Topbar ───────────────────────────────────────────────── */
.topbar {
  /* iOS PWA: keep content clear of the status bar / notch */
  height: calc(var(--top-h) + env(safe-area-inset-top, 0px));
  padding-top: env(safe-area-inset-top, 0px);
  background: var(--bg2);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  flex-wrap: nowrap;
  padding-left: 16px;
  padding-right: 16px;
  gap: 10px;
  flex-shrink: 0;
  z-index: 200;
}

.tb-brand {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  flex-shrink: 0;
  /* Center the wordmark over the sidebar column: span its full width and
     cancel the topbar's 16px left padding so brand-center = sidebar-center */
  width: var(--sid-w);
  margin-left: -16px;
}

.tb-brand-mark {
  width: 28px;
  height: 28px;
  background: linear-gradient(to bottom, #1976d1, #0d48a2);
  border-radius: var(--r-sm);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 12px;
  font-weight: 700;
  color: #fff;
  letter-spacing: -0.3px;
  font-family: "Plus Jakarta Sans", "Inter", system-ui, sans-serif;
  flex-shrink: 0;
}

.tb-brand-name {
  font-size: 15.5px;
  font-weight: 700;
  color: var(--text);
  letter-spacing: -0.2px;
  font-family: "Plus Jakarta Sans", "Inter", system-ui, sans-serif;
}
/* Brand wordmark: the "O" in ASPHORA is the signature orange (matches login) */
.brand-o { color: #ea580c; }

.tb-sep {
  width: 1px;
  height: 18px;
  background: var(--border2);
  flex-shrink: 0;
}

.tb-project {
  font-size: 11px;
  color: var(--text3);
  flex: 1;
  min-width: 0;
}
.tb-project strong { color: var(--text2); font-weight: 500; }

.tb-right {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-shrink: 0;
  margin-left: auto; /* pin controls to the right edge on every width */
}

/* Online/offline badge */
.status-badge {
  display: flex;
  align-items: center;
  gap: 5px;
  font-size: 11px;
  color: var(--text3);
  background: var(--bg3);
  border: 1px solid var(--border);
  border-radius: var(--r-sm);
  padding: 4px 9px;
  white-space: nowrap;
}
.status-dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--text3);
  flex-shrink: 0;
  transition: background 0.3s;
}
.status-dot.online  { background: var(--green2); }
.status-dot.offline { background: var(--red2); }

/* User pill */
.user-pill {
  display: flex;
  align-items: center;
  gap: 7px;
  font-size: 12px;
  color: var(--text2);
  cursor: pointer;
  padding: 4px 8px;
  border-radius: var(--r-md);
  transition: background var(--dur);
}
.user-pill:hover { background: var(--bg3); }
.user-avatar {
  width: 26px;
  height: 26px;
  border-radius: 50%;
  object-fit: cover;
  background: var(--blue);
  color: #fff;
  font-size: 11px;
  font-weight: 700;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  overflow: hidden;
}
.user-name { max-width: 120px; }
.user-role {
  font-size: 9.5px;
  font-weight: 700;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  padding: 2px 6px;
  border-radius: var(--r-sm);
  background: rgba(59,130,246,0.12);
  color: var(--blue2);
  flex-shrink: 0;
}
.user-role.role-operator { background: rgba(5,150,105,0.12); color: var(--green2); }
.user-role.role-stock    { background: rgba(217,119,6,0.12);  color: var(--amber2); }
.user-role.role-admin    { background: rgba(124,58,237,0.12); color: var(--purple2); }
.user-role.role-viewer   { background: rgba(14,165,233,0.12); color: var(--blue2); }

/* ── Body split (sidebar + content) ─────────────────────── */
.body-wrap {
  display: flex;
  flex: 1;
  overflow: hidden;
}

/* ── Sidebar (Dashboard only) ────────────────────────────── */
.sidebar {
  width: var(--sid-w);
  background: linear-gradient(to bottom, #1976d1, #0d48a2);
  display: flex;
  flex-direction: column;
  flex-shrink: 0;
  overflow: hidden;
  transition: width 0.25s var(--ease);
  z-index: 100;
}
.sidebar.collapsed { width: var(--sid-w-col); }

/* Logo + project info */
.sid-logo {
  padding: 18px 10px 14px;
  border-bottom: 1px solid rgba(255,255,255,0.07);
  flex-shrink: 0;
  overflow: hidden;
  text-align: center;
}
.sid-logo-mark {
  display: flex;
  align-items: center;
  justify-content: center;
  margin-bottom: 12px;
  white-space: nowrap;
  position: relative;
}
.sid-logo-text {
  display: flex;
  align-items: center;
}
.sid-logo-slashes {
  font-family: 'DM Mono', monospace;
  font-size: 17px;
  font-weight: 500;
  color: rgba(255,255,255,0.75);
  letter-spacing: -1px;
}
.sid-logo-wordmark {
  font-size: 17px;
  font-weight: 700;
  color: #fff;
  margin-left: 5px;
  letter-spacing: 0.01em;
}
.sid-toggle-btn {
  background: none;
  border: none;
  cursor: pointer;
  color: rgba(255,255,255,0.38);
  padding: 4px 6px;
  border-radius: var(--r-sm);
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  transition: color 0.15s, background 0.15s;
  position: absolute;
  right: 0;
}
.sid-toggle-btn { color: rgba(255,255,255,0.70); }
.sid-toggle-btn:hover { color: #fff; background: rgba(255,255,255,0.12); }
.sid-toggle-open   { display: block; }
.sid-toggle-closed { display: none; }
.sidebar.collapsed .sid-logo-text     { display: none; }
.sidebar.collapsed .sid-logo-mark    { margin-bottom: 0; }
.sidebar.collapsed .sid-toggle-btn   { position: static; }
.sidebar.collapsed .sid-toggle-open  { display: none; }
.sidebar.collapsed .sid-toggle-closed { display: block; }
.sidebar.collapsed .sid-logo         { padding: 14px 10px; }
.sid-prj-name {
  font-size: 12px;
  font-weight: 600;
  color: #fff;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  line-height: 1.4;
}
.sid-prj-loc {
  font-size: 10.5px;
  color: rgba(255,255,255,0.65);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  margin-top: 2px;
}
.sidebar.collapsed .sid-prj-name,
.sidebar.collapsed .sid-prj-loc { display: none; }

/* Nav scroll area */
.sid-nav {
  flex: 1;
  overflow-y: auto;
  padding: 8px 8px;
  scrollbar-width: thin;
  scrollbar-color: rgba(255,255,255,0.12) transparent;
}
.sid-nav::-webkit-scrollbar { width: 4px; }
.sid-nav::-webkit-scrollbar-thumb { background: rgba(255,255,255,0.12); border-radius: 2px; }

.sid-group-lbl {
  font-size: 9.5px;
  font-weight: 700;
  letter-spacing: 0.10em;
  text-transform: uppercase;
  color: rgba(255,255,255,0.60);
  padding: 14px 10px 5px;
  white-space: nowrap;
  overflow: hidden;
}
.sidebar.collapsed .sid-group-lbl { opacity: 0; }

/* Nav items */
.nav-item {
  display: flex;
  align-items: center;
  gap: 9px;
  padding: 7px 10px;
  border-radius: var(--r-sm);
  cursor: pointer;
  transition: background var(--dur), color var(--dur);
  color: rgba(255,255,255,0.85);
  position: relative;
  white-space: nowrap;
  overflow: hidden;
  user-select: none;
}
.nav-item:hover  { background: rgba(255,255,255,0.12); color: #fff; }
.nav-item.active { background: rgba(255,255,255,0.18); color: #fff; font-weight: 500; }
.nav-item.active::before {
  content: "";
  position: absolute;
  left: 0; top: 20%; bottom: 20%;
  width: 3px;
  background: #fff;
  border-radius: 0 3px 3px 0;
}

.nav-icon {
  width: 30px;
  height: 30px;
  border-radius: var(--r-sm);
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  transition: color var(--dur);
  color: rgba(255,255,255,0.75);
}
.nav-icon svg { width: 16px; height: 16px; }
.nav-item:hover  .nav-icon { color: #fff; }
.nav-item.active .nav-icon { color: #fff; }
.nav-label { font-size: 13px; }
.sidebar.collapsed .nav-label { display: none; }

/* LIVE pulse dot */
.nav-live { position: relative; }
.nav-live::after {
  content: "";
  position: absolute;
  right: 10px; top: 50%;
  transform: translateY(-50%);
  width: 7px; height: 7px;
  background: var(--red2);
  border-radius: 50%;
  animation: pulse-live 1.8s infinite;
}
.sidebar.collapsed .nav-live::after { right: 6px; }
@keyframes pulse-live {
  0%,100% { opacity: 1; transform: translateY(-50%) scale(1); }
  50%      { opacity: 0.4; transform: translateY(-50%) scale(1.35); }
}

/* Bottom section: single account row → upward popover menu */
.sid-bottom {
  flex-shrink: 0;
  padding: 8px;
  border-top: 1px solid rgba(255,255,255,0.07);
  position: relative; /* anchor for the absolute popover */
}

/* Compact account row (avatar + name + caret) */
.sid-account {
  display: flex;
  align-items: center;
  gap: 8px;
  width: 100%;
  padding: 8px 10px;
  border: none;
  border-radius: var(--r-md);
  background: rgba(255,255,255,0.06);
  color: #fff;
  cursor: pointer;
  font-family: inherit;
  transition: background var(--dur) var(--ease);
}
.sid-account:hover { background: rgba(255,255,255,0.12); }
.sid-account .user-name { color: #fff; font-size: 12.5px; font-weight: 600; flex: 1; min-width: 0; text-align: left; }
.sid-account-caret { color: rgba(255,255,255,0.6); flex-shrink: 0; transition: transform var(--dur) var(--ease); }
.sid-account[aria-expanded="true"] .sid-account-caret { transform: rotate(180deg); }
.sidebar.collapsed .sid-account { justify-content: center; padding: 8px 4px; }
.sidebar.collapsed .sid-account .user-name,
.sidebar.collapsed .sid-account-caret { display: none; }

/* Popover menu — a normal theme surface floating above the blue rail */
.sid-account-menu {
  position: absolute;
  left: 8px;
  right: 8px;
  bottom: calc(100% - 2px);
  background: var(--card);
  border: 1px solid var(--border2);
  border-radius: var(--r-md);
  box-shadow: var(--sh-3);
  padding: 6px;
  z-index: 300;
  animation: samRise 0.14s var(--ease);
}
@keyframes samRise { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }
.sidebar.collapsed .sid-account-menu { left: 8px; right: auto; width: 220px; }

.sam-identity {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 8px 10px;
}
.sam-avatar { width: 34px; height: 34px; font-size: 13px; }
.sam-id-text { display: flex; flex-direction: column; min-width: 0; flex: 1; }
.sam-name  { font-size: 13px; font-weight: 700; color: var(--text); }
.sam-email { font-size: 11px; color: var(--text3); }
.sam-sep { height: 1px; background: var(--border); margin: 4px 0; }

.sam-item {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  padding: 9px 8px;
  border: none;
  background: none;
  border-radius: var(--r-sm);
  color: var(--text);
  font-family: inherit;
  font-size: 13px;
  cursor: pointer;
  text-align: left;
  transition: background var(--dur) var(--ease);
}
.sam-item:hover { background: var(--bg3); }
.sam-ico { width: 17px; height: 17px; flex-shrink: 0; color: var(--text2); }
.sam-label { flex: 1; }
.sam-value {
  font-size: 11px; font-weight: 700;
  color: var(--text3);
  background: var(--bg3);
  padding: 2px 8px; border-radius: var(--r-full);
}
.sam-danger { color: var(--red2); }
.sam-danger .sam-ico { color: var(--red2); }
.sam-danger:hover { background: rgba(220,38,38,0.10); }
.sid-reported-by {
  font-size: 10px;
  color: rgba(255,255,255,0.22);
  padding: 6px 10px 14px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.sidebar.collapsed .sid-reported-by { display: none; }

/* ── Main content area ───────────────────────────────────── */
.main-col {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-width: 0;
  overflow: hidden;
}

.page-wrap {
  flex: 1;
  overflow-y: auto;
  padding: 20px 24px;
}

.page-header {
  margin-bottom: 20px;
}
.page-title {
  font-size: 17px;
  font-weight: 700;
  color: var(--text);
  letter-spacing: -0.2px;
  font-family: "Plus Jakarta Sans", "Inter", system-ui, sans-serif;
  margin-bottom: 2px;
}
.page-sub {
  font-size: 11px;
  color: var(--text3);
}

/* ── Role placeholder views (Day 1) ─────────────────────── */
.role-placeholder {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  gap: 16px;
  padding: 32px;
  text-align: center;
}
.role-placeholder-icon {
  font-size: 56px;
  line-height: 1;
}
.role-placeholder-title {
  font-size: 20px;
  font-weight: 700;
  color: var(--text);
  font-family: "Plus Jakarta Sans", "Inter", system-ui, sans-serif;
}
.role-placeholder-sub {
  font-size: 13px;
  color: var(--text3);
  max-width: 280px;
}

/* ── Mobile operator/stock header ───────────────────────── */
.mob-header {
  height: var(--top-h);
  background: var(--bg2);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  padding: 0 16px;
  gap: 10px;
  flex-shrink: 0;
  z-index: 100;
}
.mob-header-title {
  flex: 1;
  font-size: 15px;
  font-weight: 700;
  color: var(--text);
  text-align: center;
  letter-spacing: -0.2px;
}
.mob-header-action {
  width: 34px;
  height: 34px;
  border-radius: var(--r-md);
  background: transparent;
  border: none;
  color: var(--text2);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 18px;
  transition: background var(--dur);
}
.mob-header-action:hover { background: var(--bg3); }

/* ── Hamburger (mobile only) ─────────────────────────────── */
.hb-btn {
  display: none;
  background: none;
  border: none;
  cursor: pointer;
  color: var(--text2);
  padding: 6px;
  border-radius: var(--r-sm);
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  transition: background var(--dur);
}
.hb-btn:hover { background: var(--bg3); }

/* Mobile sidebar backdrop */
.sidebar-backdrop {
  display: none;
  position: fixed;
  top: var(--top-h);
  left: 0; right: 0; bottom: 0;
  background: rgba(0,0,0,0.45);
  z-index: 250;
}
.sidebar-backdrop.show { display: block; }

/* ── Responsive ─────────────────────────────────────────── */
@media (max-width: 768px) {
  .page-wrap { padding: 16px; }
  .hb-btn    { display: flex; }
  /* Mobile: sidebar is an overlay, so don't reserve/centre its column —
     brand sits naturally after the hamburger */
  .tb-brand  { width: auto; margin-left: 0; justify-content: flex-start; }
  .sidebar {
    position: fixed;
    top: var(--top-h);
    left: 0;
    bottom: 0;
    transform: translateX(-100%);
    transition: transform 0.25s var(--ease);
    z-index: 300;
    box-shadow: 4px 0 24px rgba(0,0,0,0.3);
  }
  .sidebar.mobile-open { transform: translateX(0); }
  .sidebar.collapsed   { width: var(--sid-w); }  /* ignore desktop-collapse state on mobile */
  .tb-project { display: none; }
  .tb-sep    { display: none; }
  .user-name { display: none; }
  .status-badge { display: none; }
}

/* ── Admin viewing stock / operator ─────────────────────── */
/* When admin navigates to stock or operator view, topbar stays
   visible. Suppress the redundant mobile headers and fix heights. */
body.is-admin #view-stock {
  height: auto;
  flex: 1;
  min-height: 0;
}
body.is-admin .st-hdr { display: none !important; }

body.is-admin #view-operator { flex: 1; min-height: 0; }
body.is-admin .op-screen     { height: auto; flex: 1; min-height: 0; }
body.is-admin #view-operator .mob-header { display: none !important; }
