@import url('https://fonts.googleapis.com/css2?family=Plus+Jakarta+Sans:wght@300;400;500;600;700;800&family=JetBrains+Mono:wght@400;500;600;700&display=swap');

/* ==========================================================================
   ARAMIRBREW ERP - MODERN INDUSTRIAL DESIGN SYSTEM (V2 REBOOT)
   Design Philosophy: Clean, High-Contrast Industrial SaaS (Linear / Stripe style)
   Holding Aramir - Asunción, Paraguay
   ========================================================================== */

:root {
  /* Slate & Neutral Base Canvas */
  --bg-app: #0b0f17;             /* Deep Slate 950 base */
  --bg-sidebar: #0f172a;         /* Slate 900 sidebar */
  --bg-main: #0b0f17;            /* Slate 950 canvas */
  --bg-header: rgba(15, 23, 42, 0.75); /* Frosted Header */
  
  --bg-card: #141e33;            /* Elevated card */
  --bg-card-hover: #1a2742;      /* Hover state */
  --bg-surface: #1e293b;         /* Muted surface */
  --bg-input: #0b0f17;           /* Input field background */
  
  --border-subtle: rgba(255, 255, 255, 0.07);
  --border-strong: rgba(255, 255, 255, 0.14);
  --border-focus: #f59e0b;
  
  /* Brand Industrial Color Accents */
  --amber-primary: #f59e0b;      /* Beer Golden Amber 500 */
  --amber-hover: #d97706;        /* Amber 600 */
  --amber-dark: #b45309;         /* Amber 700 */
  --amber-glow: rgba(245, 158, 11, 0.18);
  --amber-surface: rgba(245, 158, 11, 0.08);

  --emerald-primary: #10b981;    /* Emerald 500 */
  --emerald-surface: rgba(16, 185, 129, 0.1);
  --emerald-glow: rgba(16, 185, 129, 0.2);

  --sky-primary: #0ea5e9;        /* Sky 500 */
  --sky-surface: rgba(14, 165, 233, 0.1);

  --rose-primary: #f43f5e;       /* Rose 500 */
  --rose-surface: rgba(244, 63, 94, 0.1);

  --purple-primary: #a855f7;
  --purple-surface: rgba(168, 85, 247, 0.1);

  /* High-legibility Typography */
  --text-main: #f8fafc;          /* Pure slate 50 */
  --text-secondary: #94a3b8;     /* Slate 400 */
  --text-muted: #64748b;         /* Slate 500 */
  --text-on-accent: #000000;

  /* Typography Scales */
  --font-sans: 'Plus Jakarta Sans', -apple-system, BlinkMacSystemFont, sans-serif;
  --font-mono: 'JetBrains Mono', monospace;

  /* Elevation Shadows */
  --shadow-card: 0 4px 16px -2px rgba(0, 0, 0, 0.45);
  --shadow-popover: 0 12px 32px -4px rgba(0, 0, 0, 0.6);
  --shadow-glow: 0 0 24px -4px rgba(245, 158, 11, 0.25);
}

/* ==========================================================================
   RESET & GLOBAL STYLES
   ========================================================================== */
* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

body {
  background-color: var(--bg-app);
  color: var(--text-main);
  font-family: var(--font-sans);
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  min-height: 100vh;
  overflow-x: hidden;
}

/* Scrollbar Styling */
::-webkit-scrollbar {
  width: 6px;
  height: 6px;
}
::-webkit-scrollbar-track {
  background: var(--bg-app);
}
::-webkit-scrollbar-thumb {
  background: var(--bg-surface);
  border-radius: 3px;
}
::-webkit-scrollbar-thumb:hover {
  background: var(--amber-primary);
}

/* ==========================================================================
   APP SHELL LAYOUT (Sidebar + Main Workspace)
   ========================================================================== */
.app-shell {
  display: flex;
  min-height: 100vh;
  width: 100vw;
  background-color: var(--bg-app);
}

/* 1. SIDEBAR */
.app-sidebar {
  width: 260px;
  background-color: var(--bg-sidebar);
  border-right: 1px solid var(--border-subtle);
  display: flex;
  flex-direction: column;
  position: sticky;
  top: 0;
  height: 100vh;
  z-index: 50;
  flex-shrink: 0;
  transition: width 0.2s cubic-bezier(0.4, 0, 0.2, 1);
}

.sidebar-header {
  padding: 1.25rem 1.25rem 1rem;
  display: flex;
  align-items: center;
  gap: 0.75rem;
  border-bottom: 1px solid var(--border-subtle);
}

.brand-badge-icon {
  width: 36px;
  height: 36px;
  border-radius: 8px;
  background: linear-gradient(135deg, #f59e0b, #d97706);
  display: flex;
  align-items: center;
  justify-content: center;
  color: #000;
  font-weight: 800;
  box-shadow: 0 2px 10px rgba(245, 158, 11, 0.35);
  flex-shrink: 0;
}

.brand-meta {
  display: flex;
  flex-direction: column;
}

.brand-name {
  font-size: 1.05rem;
  font-weight: 800;
  letter-spacing: -0.02em;
  color: #fff;
}
.brand-name span {
  color: var(--amber-primary);
}

.brand-sub {
  font-size: 0.68rem;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  font-weight: 600;
}

/* Sidebar Navigation Items */
.sidebar-content {
  flex: 1;
  overflow-y: auto;
  padding: 1rem 0.75rem;
  display: flex;
  flex-direction: column;
  gap: 1.5rem;
}

.nav-group-title {
  font-size: 0.68rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text-muted);
  padding: 0 0.5rem 0.4rem;
}

.nav-group-items {
  display: flex;
  flex-direction: column;
  gap: 0.2rem;
}

.side-nav-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.6rem 0.75rem;
  border-radius: 8px;
  color: var(--text-secondary);
  font-size: 0.85rem;
  font-weight: 600;
  text-decoration: none;
  cursor: pointer;
  border: 1px solid transparent;
  transition: all 0.15s ease;
  user-select: none;
}

.side-nav-item .nav-label-box {
  display: flex;
  align-items: center;
  gap: 0.65rem;
}

.side-nav-item svg {
  color: var(--text-muted);
  transition: color 0.15s ease;
}

.side-nav-item:hover {
  background-color: var(--bg-card);
  color: var(--text-main);
}
.side-nav-item:hover svg {
  color: var(--text-main);
}

.side-nav-item.active {
  background-color: var(--amber-surface);
  border-color: rgba(245, 158, 11, 0.3);
  color: var(--amber-primary);
}
.side-nav-item.active svg {
  color: var(--amber-primary);
}

.nav-pill-badge {
  font-family: var(--font-mono);
  font-size: 0.65rem;
  font-weight: 700;
  padding: 0.15rem 0.45rem;
  border-radius: 4px;
}

/* Sidebar Footer (System Status & User) */
.sidebar-footer {
  padding: 0.85rem 1rem;
  border-top: 1px solid var(--border-subtle);
  background: rgba(11, 15, 23, 0.4);
  display: flex;
  flex-direction: column;
  gap: 0.65rem;
}

.system-status-indicator {
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-size: 0.72rem;
  color: var(--text-muted);
}

.live-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--emerald-primary);
  box-shadow: 0 0 8px var(--emerald-primary);
  display: inline-block;
  margin-right: 0.35rem;
}

/* 2. MAIN WORKSPACE */
.app-main {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-width: 0; /* Prevents overflow bugs in flex children */
  overflow-y: auto;
  height: 100vh;
}

/* Top Cockpit Header */
.top-header {
  position: sticky;
  top: 0;
  z-index: 40;
  background: var(--bg-header);
  backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--border-subtle);
  padding: 0.75rem 1.5rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.breadcrumb-trail {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  font-size: 0.85rem;
}
.breadcrumb-trail .sec-parent {
  color: var(--text-muted);
  font-weight: 500;
}
.breadcrumb-trail .sec-sep {
  color: var(--text-muted);
}
.breadcrumb-trail .sec-current {
  color: var(--text-main);
  font-weight: 700;
}

.header-actions {
  display: flex;
  align-items: center;
  gap: 0.75rem;
}

.time-chip {
  font-family: var(--font-mono);
  font-size: 0.75rem;
  color: var(--text-secondary);
  background: var(--bg-card);
  border: 1px solid var(--border-subtle);
  padding: 0.3rem 0.6rem;
  border-radius: 6px;
}

.role-badge-select {
  background: var(--bg-card);
  border: 1px solid var(--border-subtle);
  color: var(--amber-primary);
  font-family: var(--font-sans);
  font-weight: 700;
  font-size: 0.78rem;
  padding: 0.3rem 0.6rem;
  border-radius: 6px;
  cursor: pointer;
  outline: none;
}
.role-badge-select option {
  background: var(--bg-card);
  color: var(--text-main);
}

/* Main Content Workspace */
.content-canvas {
  padding: 1.5rem;
  max-width: 1500px;
  margin: 0 auto;
  width: 100%;
}

/* ==========================================================================
   CARDS & KPI DECKS (Modern Linear/Stripe Style)
   ========================================================================== */
.kpi-row {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 1rem;
  margin-bottom: 1.5rem;
}

.metric-card {
  background: var(--bg-card);
  border: 1px solid var(--border-subtle);
  border-radius: 10px;
  padding: 1.15rem 1.25rem;
  box-shadow: var(--shadow-card);
  position: relative;
  overflow: hidden;
  transition: border-color 0.15s ease, transform 0.15s ease;
}

.metric-card:hover {
  border-color: rgba(245, 158, 11, 0.35);
  transform: translateY(-1px);
}

.metric-card .metric-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 0.5rem;
}

.metric-card .metric-title {
  font-size: 0.75rem;
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.metric-card .metric-icon {
  font-size: 1rem;
  opacity: 0.8;
}

.metric-card .metric-val {
  font-family: var(--font-mono);
  font-size: 1.75rem;
  font-weight: 800;
  color: var(--text-main);
  letter-spacing: -0.03em;
}

.metric-card .metric-sub {
  font-size: 0.75rem;
  color: var(--text-secondary);
  margin-top: 0.25rem;
  display: flex;
  align-items: center;
  gap: 0.35rem;
}

/* Glass Card / Modern Section Container */
.modern-card {
  background: var(--bg-card);
  border: 1px solid var(--border-subtle);
  border-radius: 12px;
  box-shadow: var(--shadow-card);
  margin-bottom: 1.5rem;
  overflow: hidden;
}

.modern-card-header {
  padding: 1rem 1.25rem;
  border-bottom: 1px solid var(--border-subtle);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
}

.modern-card-title {
  font-size: 0.95rem;
  font-weight: 700;
  color: var(--text-main);
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.modern-card-body {
  padding: 1.25rem;
}

/* ==========================================================================
   BUTTONS & BADGES
   ========================================================================== */
.btn {
  font-family: var(--font-sans);
  font-size: 0.82rem;
  font-weight: 600;
  padding: 0.5rem 0.9rem;
  border-radius: 7px;
  border: 1px solid transparent;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.45rem;
  transition: all 0.12s ease;
  user-select: none;
}
.btn:active {
  transform: scale(0.98);
}

.btn-primary {
  background: var(--amber-primary);
  color: #000;
  font-weight: 700;
}
.btn-primary:hover {
  background: var(--amber-hover);
}

.btn-secondary {
  background: var(--bg-surface);
  border: 1px solid var(--border-subtle);
  color: var(--text-main);
}
.btn-secondary:hover {
  background: var(--bg-card-hover);
  border-color: var(--border-strong);
}

.btn-emerald {
  background: var(--emerald-primary);
  color: #000;
  font-weight: 700;
}
.btn-emerald:hover {
  background: #059669;
}

.btn-rose {
  background: var(--rose-primary);
  color: #fff;
}
.btn-rose:hover {
  background: #e11d48;
}

/* Status Badges */
.badge {
  display: inline-flex;
  align-items: center;
  gap: 0.3rem;
  padding: 0.2rem 0.5rem;
  border-radius: 5px;
  font-size: 0.72rem;
  font-weight: 700;
  letter-spacing: 0.02em;
}

.badge-amber {
  background: var(--amber-surface);
  color: var(--amber-primary);
  border: 1px solid rgba(245, 158, 11, 0.3);
}

.badge-emerald {
  background: var(--emerald-surface);
  color: var(--emerald-primary);
  border: 1px solid rgba(16, 185, 129, 0.3);
}

.badge-sky {
  background: var(--sky-surface);
  color: var(--sky-primary);
  border: 1px solid rgba(14, 165, 233, 0.3);
}

.badge-rose {
  background: var(--rose-surface);
  color: var(--rose-primary);
  border: 1px solid rgba(244, 63, 94, 0.3);
}

.badge-purple {
  background: var(--purple-surface);
  color: var(--purple-primary);
  border: 1px solid rgba(168, 85, 247, 0.3);
}

.badge-muted {
  background: var(--bg-surface);
  color: var(--text-muted);
  border: 1px solid var(--border-subtle);
}

/* ==========================================================================
   DATA TABLES (Modern, High Legibility, 48px Rows)
   ========================================================================== */
.table-responsive {
  overflow-x: auto;
  width: 100%;
}

.modern-table {
  width: 100%;
  border-collapse: collapse;
  text-align: left;
  font-size: 0.84rem;
}

.modern-table th {
  padding: 0.75rem 1rem;
  background: rgba(11, 15, 23, 0.6);
  color: var(--text-muted);
  font-weight: 700;
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  border-bottom: 1px solid var(--border-subtle);
  white-space: nowrap;
}

.modern-table td {
  padding: 0.85rem 1rem;
  border-bottom: 1px solid var(--border-subtle);
  color: var(--text-main);
  vertical-align: middle;
}

.modern-table tr:last-child td {
  border-bottom: none;
}

.modern-table tr:hover td {
  background: rgba(255, 255, 255, 0.02);
}

/* Monospace Values */
.mono-val {
  font-family: var(--font-mono);
  font-weight: 600;
}

/* ==========================================================================
   FORM INPUTS & CONTROLS
   ========================================================================== */
.input-control, select.input-control {
  background: var(--bg-input);
  border: 1px solid var(--border-subtle);
  border-radius: 6px;
  color: var(--text-main);
  font-family: var(--font-sans);
  font-size: 0.84rem;
  padding: 0.5rem 0.75rem;
  outline: none;
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
  width: 100%;
}

.input-control:focus, select.input-control:focus {
  border-color: var(--amber-primary);
  box-shadow: 0 0 0 2px rgba(245, 158, 11, 0.2);
}

/* ==========================================================================
   MODALS (Clean Glass Blur)
   ========================================================================== */
.modal-overlay {
  position: fixed;
  top: 0;
  left: 0;
  width: 100vw;
  height: 100vh;
  background: rgba(11, 15, 23, 0.75);
  backdrop-filter: blur(8px);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.18s ease;
}

.modal-overlay.active {
  opacity: 1;
  pointer-events: auto;
}

.modal-sheet {
  background: var(--bg-card);
  border: 1px solid var(--border-strong);
  border-radius: 14px;
  width: 90%;
  max-width: 650px;
  max-height: 90vh;
  overflow-y: auto;
  box-shadow: var(--shadow-popover);
  transform: translateY(10px) scale(0.98);
  transition: transform 0.18s cubic-bezier(0.16, 1, 0.3, 1);
}

.modal-overlay.active .modal-sheet {
  transform: translateY(0) scale(1);
}

.modal-header {
  padding: 1.15rem 1.5rem;
  border-bottom: 1px solid var(--border-subtle);
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.modal-title {
  font-size: 1.05rem;
  font-weight: 800;
  color: var(--text-main);
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.modal-close-btn {
  background: transparent;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  font-size: 1.25rem;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 32px;
  height: 32px;
  border-radius: 6px;
  transition: all 0.1s ease;
}
.modal-close-btn:hover {
  background: var(--bg-surface);
  color: var(--text-main);
}

.modal-body {
  padding: 1.5rem;
}

.modal-footer {
  padding: 1rem 1.5rem;
  border-top: 1px solid var(--border-subtle);
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 0.75rem;
  background: rgba(11, 15, 23, 0.3);
}

/* ==========================================================================
   SECTION SWITCHING (Clean SPA Transition)
   ========================================================================== */
.module-view {
  display: none;
  animation: fadeInView 0.15s ease forwards;
}

.module-view.active {
  display: block;
}

@keyframes fadeInView {
  from {
    opacity: 0;
    transform: translateY(4px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

/* ==========================================================================
   SYNC CHIP (Local-First Supabase Outbox Pill)
   ========================================================================== */
.sync-chip {
  display: inline-flex;
  align-items: center;
  gap: 0.45rem;
  background: rgba(16, 185, 129, 0.1);
  border: 1px solid rgba(16, 185, 129, 0.25);
  color: var(--emerald-primary);
  font-family: var(--font-mono);
  font-size: 0.72rem;
  padding: 0.25rem 0.55rem;
  border-radius: 9999px;
  cursor: pointer;
  transition: all var(--transition-fast);
  user-select: none;
}
.sync-chip:hover {
  background: rgba(16, 185, 129, 0.18);
  border-color: var(--emerald-primary);
}
.sync-chip.offline {
  background: rgba(245, 158, 11, 0.1);
  border-color: rgba(245, 158, 11, 0.3);
  color: var(--amber-primary);
}
.sync-chip.error {
  background: rgba(244, 63, 94, 0.1);
  border-color: rgba(244, 63, 94, 0.3);
  color: var(--rose-primary);
}
.sync-chip .sync-dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: currentColor;
  box-shadow: 0 0 6px currentColor;
}

/* ==========================================================================
   RESPONSIVE DESIGN (Smartphone & Tablet Ergonomics)
   ========================================================================== */

/* Universal mobile-friendly defaults */
html, body {
  max-width: 100vw;
  overflow-x: hidden;
  -webkit-tap-highlight-color: transparent;
}
button, a, input, select {
  touch-action: manipulation;
}

/* Tablet view (769px to 1024px) */
@media (min-width: 769px) and (max-width: 1024px) {
  .app-sidebar {
    width: 72px;
  }
  .brand-meta, .nav-group-title, .nav-item-text, .nav-pill-badge, .system-status-indicator span:last-child {
    display: none;
  }
  .side-nav-item {
    justify-content: center;
    padding: 0.75rem 0;
  }
  .content-canvas {
    padding: 1.25rem;
  }
}

/* Desktop guards (>= 769px) */
@media (min-width: 769px) {
  .mobile-menu-toggle {
    display: none !important;
  }
  .sidebar-backdrop {
    display: none !important;
  }
  .mobile-sidebar-close {
    display: none !important;
  }
  .mobile-bottom-nav {
    display: none !important;
  }
}

/* Smartphone & Small Tablet view (<= 768px) */
@media (max-width: 768px) {
  .app-shell {
    position: relative;
    width: 100vw;
    max-width: 100vw;
    overflow-x: hidden;
  }

  /* Off-canvas persistent drawer */
  .app-sidebar {
    position: fixed !important;
    top: 0 !important;
    left: 0 !important;
    width: 290px !important;
    max-width: 86vw !important;
    height: 100vh !important;
    height: 100dvh !important;
    z-index: 1200 !important;
    transform: translateX(-100%);
    transition: transform 0.28s cubic-bezier(0.16, 1, 0.3, 1), box-shadow 0.28s ease !important;
    box-shadow: none;
    background-color: var(--bg-sidebar) !important;
  }

  .app-sidebar.mobile-open {
    transform: translateX(0) !important;
    box-shadow: 0 0 50px rgba(0, 0, 0, 0.85) !important;
  }

  /* Blur backdrop */
  .sidebar-backdrop {
    position: fixed;
    inset: 0;
    background: rgba(11, 15, 23, 0.75);
    backdrop-filter: blur(5px);
    -webkit-backdrop-filter: blur(5px);
    z-index: 1150;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.25s ease;
  }

  .sidebar-backdrop.active {
    opacity: 1;
    pointer-events: auto;
  }

  /* Mobile close button in drawer header */
  .mobile-sidebar-close {
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--bg-card);
    border: 1px solid var(--border-subtle);
    color: var(--text-muted);
    width: 34px;
    height: 34px;
    border-radius: 8px;
    cursor: pointer;
    font-size: 1.1rem;
    margin-left: auto;
    transition: all 0.15s ease;
  }
  .mobile-sidebar-close:active {
    transform: scale(0.9);
    color: var(--amber-primary);
    border-color: var(--amber-primary);
  }

  /* Main viewport on mobile */
  .app-main {
    width: 100vw !important;
    min-width: 0 !important;
    height: 100vh !important;
    height: 100dvh !important;
    padding-bottom: 72px !important;
    overflow-x: hidden;
  }

  /* Top cockpit header on mobile */
  .top-header {
    padding: 0.65rem 0.85rem;
    gap: 0.6rem;
  }

  .mobile-menu-toggle {
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--bg-surface);
    border: 1px solid var(--border-subtle);
    color: var(--text-main);
    width: 38px;
    height: 38px;
    border-radius: 8px;
    cursor: pointer;
    flex-shrink: 0;
    transition: all 0.12s ease;
  }
  .mobile-menu-toggle:active {
    transform: scale(0.92);
    border-color: var(--amber-primary);
    color: var(--amber-primary);
  }

  .breadcrumb-trail {
    font-size: 0.8rem;
    min-width: 0;
    flex: 1;
  }
  .breadcrumb-trail .sec-parent,
  .breadcrumb-trail .sec-sep {
    display: none !important;
  }
  .breadcrumb-trail .sec-current {
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    max-width: 170px;
    font-size: 0.85rem;
    display: block;
  }

  .header-actions {
    gap: 0.4rem;
    flex-shrink: 0;
  }
  .sync-chip, .time-chip {
    display: none !important;
  }
  .user-master-info {
    display: none !important;
  }
  .user-master-badge {
    padding: 0.2rem !important;
  }
  .user-master-avatar {
    width: 34px !important;
    height: 34px !important;
    font-size: 0.8rem !important;
  }

  /* Content canvas on mobile */
  .content-canvas {
    padding: 0.85rem 0.85rem 4rem 0.85rem !important;
  }

  /* Native-style Mobile Bottom Navigation */
  .mobile-bottom-nav {
    display: flex !important;
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    height: 60px;
    background: rgba(15, 23, 42, 0.95);
    backdrop-filter: blur(14px);
    -webkit-backdrop-filter: blur(14px);
    border-top: 1px solid var(--border-subtle);
    z-index: 1000;
    justify-content: space-around;
    align-items: center;
    padding-bottom: env(safe-area-inset-bottom, 0px);
    box-shadow: 0 -4px 20px rgba(0, 0, 0, 0.45);
  }

  .bottom-nav-item {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    color: var(--text-muted);
    font-size: 0.65rem;
    font-weight: 600;
    text-decoration: none;
    padding: 0.35rem 0.3rem;
    border-radius: 8px;
    gap: 0.15rem;
    transition: color 0.15s ease;
    flex: 1;
    text-align: center;
    cursor: pointer;
    user-select: none;
  }
  .bottom-nav-item svg {
    width: 20px;
    height: 20px;
    stroke: currentColor;
    transition: transform 0.15s ease;
  }
  .bottom-nav-item:active svg {
    transform: scale(0.88);
  }
  .bottom-nav-item.active {
    color: var(--amber-primary);
  }
  .bottom-nav-item.active svg {
    stroke: var(--amber-primary);
  }

  /* Prevent iOS Safari auto-zoom on input focus */
  input, select, textarea {
    font-size: 16px !important;
  }

  /* Mobile grids: fluid single-column layout */
  .tanks-grid {
    grid-template-columns: 1fr !important;
    gap: 0.85rem !important;
  }
  .metrics-grid, .overview-grid, .stats-row {
    grid-template-columns: repeat(2, 1fr) !important;
    gap: 0.65rem !important;
  }
  .admin-grid, .comercio-grid, .pos-grid-layout {
    grid-template-columns: 1fr !important;
    gap: 1rem !important;
  }

  /* Mobile Modals (Bottom Sheet) */
  .modal-overlay {
    padding: 0.5rem;
    align-items: flex-end;
  }
  .modal-sheet {
    width: 100% !important;
    max-width: 100% !important;
    max-height: 88vh;
    max-height: 88dvh;
    overflow-y: auto;
    border-bottom-left-radius: 0 !important;
    border-bottom-right-radius: 0 !important;
    padding: 1.25rem 1rem !important;
  }

  /* Table responsive scrolling */
  .table-container, .table-responsive {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    max-width: 100%;
  }

  /* Ergonomic touch button heights */
  .btn {
    min-height: 44px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
  }
  .key-btn {
    min-height: 52px;
    font-size: 1.2rem;
  }
}

/* Very narrow smartphones (< 380px) */
@media (max-width: 380px) {
  .metrics-grid, .overview-grid, .stats-row {
    grid-template-columns: 1fr !important;
  }
  .breadcrumb-trail .sec-current {
    max-width: 120px;
  }
  .bottom-nav-item span {
    font-size: 0.58rem;
  }
}


/* ==========================================================================
   MASTER USER BADGE & UNIVERSAL ACCESS (Step 1)
   ========================================================================== */
.user-master-badge {
  display: inline-flex;
  align-items: center;
  gap: 0.55rem;
  background: linear-gradient(135deg, rgba(245, 158, 11, 0.08), rgba(217, 119, 6, 0.03));
  border: 1px solid rgba(245, 158, 11, 0.25);
  border-radius: 9999px;
  padding: 0.25rem 0.75rem 0.25rem 0.35rem;
  user-select: none;
  cursor: pointer;
  transition: all var(--transition-fast);
}
.user-master-badge:hover {
  background: linear-gradient(135deg, rgba(245, 158, 11, 0.15), rgba(217, 119, 6, 0.06));
  border-color: var(--amber-primary);
}
.user-master-avatar {
  width: 26px;
  height: 26px;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--amber-primary), #d97706);
  color: #0b0f17;
  font-weight: 800;
  font-size: 0.7rem;
  display: flex;
  align-items: center;
  justify-content: center;
  letter-spacing: -0.02em;
  box-shadow: 0 2px 4px rgba(245, 158, 11, 0.3);
}
.user-master-info {
  display: flex;
  flex-direction: column;
  line-height: 1.1;
  text-align: left;
}
.user-master-name {
  font-size: 0.75rem;
  font-weight: 700;
  color: var(--text-main);
  letter-spacing: -0.01em;
}
.user-master-title {
  font-size: 0.62rem;
  font-weight: 600;
  color: var(--amber-primary);
  text-transform: uppercase;
  letter-spacing: 0.03em;
}

/* ==========================================================================
   BODEGA: PLANT STORAGE ZONES (Ambientes de Planta) (Step 2)
   ========================================================================== */
.plant-zones-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(260px, 1fr));
  gap: 1rem;
  margin-bottom: 1.25rem;
}
.plant-zone-card {
  background: var(--bg-card);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-md);
  padding: 1rem;
  position: relative;
  overflow: hidden;
  transition: all var(--transition-fast);
}
.plant-zone-card:hover {
  border-color: var(--border-focus);
  transform: translateY(-2px);
  box-shadow: var(--shadow-sm);
}
.plant-zone-card.cold-room {
  border-top: 3px solid var(--sky-primary);
}
.plant-zone-card.dry-silo {
  border-top: 3px solid var(--amber-primary);
}
.plant-zone-card.cip-room {
  border-top: 3px solid var(--rose-primary);
}
.plant-zone-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 0.65rem;
}
.plant-zone-title {
  font-size: 0.85rem;
  font-weight: 700;
  color: var(--text-main);
  display: flex;
  align-items: center;
  gap: 0.45rem;
}
.plant-zone-temp {
  font-family: var(--font-mono);
  font-size: 0.72rem;
  font-weight: 700;
  padding: 0.15rem 0.45rem;
  border-radius: var(--radius-sm);
}
.plant-zone-desc {
  font-size: 0.74rem;
  color: var(--text-muted);
  margin-bottom: 0.65rem;
  line-height: 1.35;
}
.plant-zone-items {
  font-size: 0.72rem;
  color: var(--text-secondary);
  display: flex;
  flex-wrap: wrap;
  gap: 0.35rem;
}
.plant-zone-tag {
  background: var(--bg-input);
  border: 1px solid var(--border-subtle);
  padding: 0.15rem 0.45rem;
  border-radius: 4px;
}

/* Stock Progress Bars */
.stock-bar-wrap {
  width: 100%;
  height: 6px;
  background: var(--bg-input);
  border-radius: 9999px;
  overflow: hidden;
  margin-top: 0.35rem;
}
.stock-bar-fill {
  height: 100%;
  border-radius: 9999px;
  transition: width 0.3s ease;
}

/* ==========================================================================
   COMPRAS: TIMELINE & RECEPCIÓN RÁPIDA (Step 2)
   ========================================================================== */
.po-flow-steps {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  background: var(--bg-card);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-md);
  padding: 0.85rem 1.25rem;
  margin-bottom: 1.25rem;
  overflow-x: auto;
}
.po-flow-step {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  font-size: 0.75rem;
  color: var(--text-secondary);
  white-space: nowrap;
}
.po-flow-step.active {
  color: var(--amber-primary);
  font-weight: 700;
}
.po-flow-step-num {
  width: 20px;
  height: 20px;
  border-radius: 50%;
  background: var(--bg-input);
  border: 1px solid var(--border-subtle);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.68rem;
  font-weight: 800;
}
.po-flow-step.active .po-flow-step-num {
  background: var(--amber-primary);
  color: #000;
  border-color: var(--amber-primary);
}
.po-flow-sep {
  color: var(--border-focus);
  font-size: 0.8rem;
}

/* ==========================================================================
   ESCANDALLO: COST WATERFALL & MARGIN SIMULATOR (Step 2)
   ========================================================================== */
.waterfall-bar-container {
  background: var(--bg-input);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-md);
  padding: 1rem;
  margin-bottom: 1rem;
}
.waterfall-bar-track {
  display: flex;
  height: 14px;
  border-radius: 9999px;
  overflow: hidden;
  margin: 0.65rem 0;
  background: rgba(255,255,255,0.05);
}
.waterfall-bar-seg {
  height: 100%;
  transition: width 0.3s ease;
}
.waterfall-legend {
  display: flex;
  flex-wrap: wrap;
  gap: 0.85rem;
  font-size: 0.72rem;
  color: var(--text-secondary);
}
.waterfall-legend-item {
  display: flex;
  align-items: center;
  gap: 0.35rem;
}
.waterfall-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
}


/* ==========================================================================
   UNIVERSAL FORMS, TABLES & MODULE DESIGN SYSTEM INTEGRATION
   ========================================================================== */

/* Universal Form Controls */
.form-group {
  margin-bottom: 1rem;
}
.form-label {
  display: block;
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--text-muted);
  margin-bottom: 0.35rem;
}
.form-select, .form-input, .form-control, .input-control, select.input-control {
  background: var(--bg-input);
  border: 1px solid var(--border-subtle);
  border-radius: 6px;
  color: var(--text-main);
  font-family: var(--font-sans);
  font-size: 0.84rem;
  padding: 0.5rem 0.75rem;
  outline: none;
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
  width: 100%;
}
.form-select:focus, .form-input:focus, .form-control:focus, .input-control:focus, select.input-control:focus {
  border-color: var(--amber-primary);
  box-shadow: 0 0 0 2px rgba(245, 158, 11, 0.2);
}
.form-select option {
  background: var(--bg-card);
  color: var(--text-main);
}

/* Universal Data Tables */
.table-container, .table-responsive {
  width: 100%;
  overflow-x: auto;
  border: 1px solid var(--border-subtle);
  border-radius: var(--border-radius-md);
  background: var(--bg-card);
}
.data-table, .modern-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.82rem;
  text-align: left;
}
.data-table th, .modern-table th {
  background: var(--bg-surface);
  color: var(--text-muted);
  font-weight: 600;
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  padding: 0.65rem 0.85rem;
  border-bottom: 1px solid var(--border-subtle);
}
.data-table td, .modern-table td {
  padding: 0.65rem 0.85rem;
  border-bottom: 1px solid var(--border-subtle);
  color: var(--text-primary);
}
.data-table tr:hover td, .modern-table tr:hover td {
  background: rgba(245, 158, 11, 0.04);
}

/* Admin Escandallo Styles */
.admin-grid {
  display: grid;
  grid-template-columns: 2fr 1fr;
  gap: 1.5rem;
}
@media (max-width: 1024px) {
  .admin-grid {
    grid-template-columns: 1fr;
  }
}
.margin-card {
  background: var(--bg-card);
  border: 1px solid var(--border-subtle);
  border-radius: var(--border-radius-md);
  padding: 1.15rem;
  margin-bottom: 1rem;
  transition: border-color var(--transition-fast);
}
.margin-card:hover {
  border-color: var(--border-focus);
}
.zero-leak-locked {
  background: rgba(244, 63, 94, 0.06);
  border: 2px dashed var(--rose-primary);
  border-radius: var(--border-radius-lg);
  padding: 2.5rem 1.5rem;
  text-align: center;
  margin-top: 1.5rem;
}

/* Comercio SIFEN & B2B Styles */
.comercio-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1.5rem;
}
@media (max-width: 1024px) {
  .comercio-grid {
    grid-template-columns: 1fr;
  }
}
.sifen-doc-card {
  background: rgba(0, 0, 0, 0.35);
  border: 1px solid var(--border-subtle);
  border-radius: 8px;
  padding: 0.85rem;
  font-size: 0.82rem;
  transition: border-color var(--transition-fast);
}
.sifen-doc-card:hover {
  border-color: var(--border-focus);
}
.cdc-badge {
  background: rgba(245, 158, 11, 0.08);
  border: 1px solid rgba(245, 158, 11, 0.25);
  color: var(--amber-primary);
  padding: 0.25rem 0.5rem;
  border-radius: 4px;
  word-break: break-all;
  display: inline-block;
  margin: 0.35rem 0;
  font-family: var(--font-mono);
  font-size: 0.72rem;
}
.tax-box {
  background: var(--bg-input);
  border: 1px solid var(--border-subtle);
  border-radius: 8px;
  padding: 0.85rem;
  margin-bottom: 1.25rem;
  font-size: 0.82rem;
}
.tax-row {
  display: flex;
  justify-content: space-between;
  margin-bottom: 0.35rem;
}

/* Barriles Smart QR Tracking */
.scanner-box {
  background: rgba(0, 0, 0, 0.4);
  border: 2px dashed rgba(245, 158, 11, 0.4);
  border-radius: 12px;
  padding: 1.5rem;
  text-align: center;
  margin-bottom: 1.25rem;
  position: relative;
}
.scanner-target {
  width: 140px;
  height: 140px;
  margin: 0 auto 0.75rem;
  border: 2px solid var(--amber-primary);
  border-radius: 12px;
  display: flex;
  align-items: center;
  justify-content: center;
  position: relative;
  background: rgba(245, 158, 11, 0.05);
}
.scanner-laser {
  position: absolute;
  width: 100%;
  height: 2px;
  background: var(--amber-primary);
  box-shadow: 0 0 8px var(--amber-primary);
  animation: scanLaser 2s infinite ease-in-out;
}
@keyframes scanLaser {
  0%, 100% { top: 10%; }
  50% { top: 90%; }
}

/* POS Mostrador .000 Styles */
.pos-grid-layout {
  display: grid;
  grid-template-columns: 1fr 380px;
  gap: 1.5rem;
}
@media (max-width: 1024px) {
  .pos-grid-layout {
    grid-template-columns: 1fr;
  }
}
.taps-deck {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(250px, 1fr));
  gap: 1rem;
}
.tap-card {
  background: var(--bg-card);
  border: 1px solid var(--border-subtle);
  border-radius: 10px;
  padding: 1rem;
  cursor: pointer;
  position: relative;
  transition: all 0.15s ease;
}
.tap-card:hover {
  border-color: var(--amber-primary);
  transform: translateY(-2px);
}
.keypad-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 0.4rem;
  margin-top: 0.6rem;
}
.key-btn {
  background: var(--bg-surface);
  border: 1px solid var(--border-subtle);
  color: var(--text-main);
  font-family: var(--font-mono);
  font-size: 1.1rem;
  font-weight: 700;
  padding: 0.65rem 0;
  border-radius: 6px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.08s ease;
}
.key-btn:active {
  transform: scale(0.95);
  background: rgba(245, 158, 11, 0.2);
}
.special-triple-zero {
  background: var(--amber-surface);
  color: var(--amber-primary);
  border-color: rgba(245, 158, 11, 0.3);
  font-weight: 800;
}

/* SPA Seamless Transitions */
.app-main {
  transition: opacity 0.14s ease-out;
}
.app-main.route-transitioning {
  opacity: 0.25;
  pointer-events: none;
}
