/* ==========================================================================
   0. DESIGN SYSTEM CORE VARIABLES (LIGHT SYSTEM DEFAULT & REAL-TIME AUTOMATION)
   ========================================================================== */
:root {
    --bg-primary: #f4f6f9;
    --bg-card: #ffffff;
    --border-color: #dddddd;
    --border-subtle: #eeeeee;
    
    --text-main: #333333;
    --text-heading: #1a1a1a;
    --text-muted: #666666;
    
    --accent-primary: #007bff;
    --accent-success: #28a745;
    --accent-success-hover: #218838;
    --accent-danger: #dc3545;
    --accent-danger-hover: #bd2130;
    
    --badge-active-bg: #e8f5e9;
    --badge-suspended-bg: #fce8e6;
    --badge-neutral-bg: #e9ecef;
}

/* AUTOMATIC OS THEME OVERRIDES TRIGGERED VIA ROOT DATA-THEME ATTRIBUTE */
[data-theme="dark"] {
    --bg-primary: #121212;
    --bg-card: #1e1e1e;
    --border-color: #333333;
    --border-subtle: #2d2d2d;
    
    --text-main: #e0e0e0;
    --text-heading: #ffffff;
    --text-muted: #aaaaaa;
    
    --accent-primary: #3792ff;
    --badge-active-bg: rgba(40, 167, 69, 0.15);
    --badge-suspended-bg: rgba(220, 53, 69, 0.15);
    --badge-neutral-bg: #2d2d2d;
}

/* ==========================================================================
   1. GLOBAL STYLES, SANITIZATION & CROSS-FADE TIMINGS
   ========================================================================== */
* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
    /* Delivers fluid color switches when user shifts OS theme preferences */
    transition: background-color 0.25s ease, border-color 0.25s ease, color 0.25s ease;
}

body { 
    font-family: 'Segoe UI', system-ui, -apple-system, sans-serif; 
    background-color: var(--bg-primary); 
    color: var(--text-main);
    line-height: 1.5;
    -webkit-font-smoothing: antialiased;
    padding: 0; /* Gutters managed by inner panels */
}

/* Standardized Field Form Resets */
input[type="text"],
input[type="number"],
input[type="email"],
input[type="password"],
select,
textarea {
    width: 100% !important; 
    padding: 11px;
    border: 1px solid var(--border-color);
    border-radius: 6px;
    font-size: 15px;
    background-color: var(--bg-card);
    color: var(--text-main);
    font-family: inherit;
}

input:focus, select:focus, textarea:focus {
    outline: none;
    border-color: var(--accent-primary);
    box-shadow: 0 0 0 3px rgba(0, 123, 255, 0.15);
}

/* ==========================================================================
   2. REUSABLE CARDS & MODULE GRID SYSTEMS (MOBILE FIRST)
   ========================================================================== */
.card-wrapper,
.report-section {
    background-color: var(--bg-card) !important; 
    padding: 20px !important; 
    border-radius: 6px !important; 
    box-shadow: 0 2px 4px rgba(0,0,0,0.02) !important; 
    margin-bottom: 25px !important;
    border: 1px solid var(--border-subtle);
}

.form-grid-row {
    display: grid;
    grid-template-columns: 1fr;
    gap: 15px;
    align-items: flex-end;
}

.grid-cards, .metrics-row { 
    display: grid; 
    grid-template-columns: 1fr; 
    gap: 15px; 
    margin-bottom: 25px; 
}

.card, .metric-box { 
    background-color: var(--bg-card); 
    padding: 20px; 
    border-radius: 6px; 
    box-shadow: 0 2px 4px rgba(0,0,0,0.03); 
    border-left: 5px solid var(--accent-success); 
}
.card.staff { border-left-color: var(--accent-primary); }
.metric-box { border-left-color: var(--text-heading); }

.card h4, .metric-box h4 { margin: 0 0 8px 0; color: var(--text-muted); font-size: 13px; text-transform: uppercase; letter-spacing: 0.5px; }
.card .value, .metric-box .num { font-size: 24px; font-weight: bold; color: var(--text-heading); }

.low-stock-card { 
    background-color: #fff3cd; 
    color: #856404; 
    padding: 15px; 
    border-radius: 6px; 
    font-weight: bold; 
    margin-bottom: 25px; 
    border-left: 5px solid #ffc107; 
}
[data-theme="dark"] .low-stock-card {
    background-color: rgba(255, 193, 7, 0.12);
    color: #ffe082;
}

/* ==========================================================================
   3. APP VIEWPORT STRUCTURAL LAYOUTS & SIDEBAR (MOBILE-FIRST DEFAULT)
   ========================================================================== */
.app-container {
    display: flex;
    flex-direction: column;
    min-height: 100vh;
}

.main-content-panel {
    flex: 1;
    padding: 15px;
    width: 100%;
}

.header { 
    display: flex; 
    flex-direction: column; 
    gap: 10px;
    align-items: flex-start; 
    border-bottom: 2px solid var(--border-color); 
    padding-bottom: 15px; 
    margin-bottom: 25px;
}

.header h1 {
    font-size: 24px;
    font-weight: 700;
    color: var(--text-heading);
}

/* Mobile Drawer (Hidden off-screen right by default) */
.nav-sidebar {
    position: fixed;
    top: 0;
    right: -280px; 
    width: 280px;
    height: 100vh;
    background-color: #1a1a1a;
    box-shadow: -4px 0 15px rgba(0,0,0,0.2);
    z-index: 1050;
    display: flex;
    flex-direction: column;
    padding: 25px;
    transition: right 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

.nav-sidebar.open {
    right: 0;
}

.menu-list {
    display: flex;
    flex-direction: column;
    gap: 10px;
    margin-top: 20px;
    width: 100% !important;
}

.menu-link {
    background: transparent !important; 
    color: #ffffff !important;
    padding: 12px 16px;
    border-radius: 6px;
    text-decoration: none !important;
    font-weight: 600;
    font-size: 14px;
    text-align: left;
    display: block;
    width: 100% !important;
}
.menu-link:hover {
    background: rgba(255, 255, 255, 0.08) !important;
}

/* Hamburger Trigger Stack Buttons */
.mobile-menu-trigger {
    display: flex;
    flex-direction: column;
    justify-content: space-between;
    width: 26px;
    height: 18px;
    background: transparent;
    border: none;
    cursor: pointer;
    z-index: 1100;
    position: fixed;
    top: 20px;
    right: 20px;
}
.mobile-menu-trigger span {
    display: block;
    width: 100%;
    height: 3px;
    background-color: #212529;
    border-radius: 2px;
    transition: all 0.3s ease;
}
[data-theme="dark"] .mobile-menu-trigger span {
    background-color: #ffffff;
}

/* Transformations making lines shape into an X cross */
.mobile-menu-trigger.active span:nth-child(1) { transform: translateY(7.5px) rotate(45deg); }
.mobile-menu-trigger.active span:nth-child(2) { opacity: 0; }
.mobile-menu-trigger.active span:nth-child(3) { transform: translateY(-7.5px) rotate(-45deg); }

.sidebar-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100vw;
    height: 100vh;
    background: rgba(0, 0, 0, 0.4);
    z-index: 1040;
    display: none;
    opacity: 0;
    transition: opacity 0.3s ease;
}
.sidebar-overlay.active {
    display: block;
    opacity: 1;
}

/* ==========================================================================
   4. INTERACTIVE BUTTON LEVERS & UTILITY BADGES
   ========================================================================== */
.btn { 
    display: inline-block;
    width: 100%; 
    padding: 12px; 
    border: none; 
    cursor: pointer; 
    border-radius: 6px; 
    color: #ffffff; 
    font-weight: bold;
    font-size: 15px;
    text-align: center;
}
.btn:disabled { opacity: 0.6; cursor: not-allowed; }

.btn-suspend { background-color: var(--accent-danger); }
.btn-suspend:hover { background-color: var(--accent-danger-hover); }
.btn-activate { background-color: var(--accent-success); }
.btn-activate:hover { background-color: var(--accent-success-hover); }

/* Ledger Profile Status Badges */
.status-active, .status-paid { color: #28a745; font-weight: bold; background-color: var(--badge-active-bg); padding: 4px 8px; border-radius: 4px; display: inline-block;}
.status-suspended, .status-pending { color: #dc3545; font-weight: bold; background-color: var(--badge-suspended-bg); padding: 4px 8px; border-radius: 4px; display: inline-block;}
.status-returned { color: var(--text-muted); font-weight: bold; background-color: var(--badge-neutral-bg); padding: 4px 8px; border-radius: 4px; display: inline-block;}
.badge-danger { background-color: var(--accent-danger); color: white; padding: 2px 6px; border-radius: 4px; font-size: 11px; font-weight: bold; text-transform: uppercase; margin-left: 5px; display: inline-block; }
.prod-thumb { width: 45px; height: 45px; object-fit: cover; border-radius: 4px; background-color: var(--badge-neutral-bg); border: 1px solid var(--border-color); }

/* ==========================================================================
   5. FLEXIBLE RETAIL POINT OF SALE TERMINAL ELEMENTS
   ========================================================================== */
.pos-container { 
    display: flex;
    flex-direction: column; 
    gap: 20px; 
    margin-top: 20px; 
}

.product-grid { 
    display: grid; 
    grid-template-columns: repeat(2, 1fr) !important; /* Forces 2 grid layouts on narrow phone screens */
    gap: 10px !important; 
}

.product-item { 
    padding: 15px 8px; 
    border-radius: 6px; 
    text-align: center; 
    cursor: pointer; 
    border: 1px solid var(--border-color); 
    box-shadow: 0 4px 6px rgba(0,0,0,0.05);
    display: flex;
    flex-direction: column;
    justify-content: flex-end;
    min-height: 120px;
}
.product-item h4 { font-size: 13px; margin-bottom: 4px; color:#ffffff !important; text-shadow:0 1px 3px #000; font-weight: 600; }
.product-item .price { font-size: 13px; font-weight: bold; color:#28a745 !important; text-shadow:0 1px 3px #000; }
.product-item .stock { font-size: 10px; color:#cccccc !important; text-shadow:0 1px 2px #000; font-weight: 500; }

.cart-panel { 
    background-color: var(--bg-card); 
    padding: 15px; 
    border-radius: 6px; 
    box-shadow: 0 2px 4px rgba(0,0,0,0.04); 
    border: 1px solid var(--border-color);
}

.cart-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 14px;
  margin-bottom: 20px;
  box-shadow: none;
}

.cart-table th,
.cart-table td {
  padding: 8px;
  border-bottom: 1px solid var(--border-subtle);
}

.cart-total {
  font-size: 18px;
  font-weight: bold;
  text-align: right;
  margin-bottom: 20px;
  color: var(--text-heading);
}

/* ==========================================================================
6. RESPONSIVE TABLE CONTAINERS OVERFLOW FIXES (CLIFF MITIGATION)
========================================================================== */
table {
  width: 100%;
  border-collapse: collapse;
  background-color: var(--bg-card);
}

th,
td {
  padding: 12px 10px;
  border: 1px solid var(--border-subtle);
  text-align: left;
  font-size: 14px;
}

th {
  background-color: #212529;
  color: #ffffff;
  font-weight: 600;
}

[data-theme="dark"] th {
  background-color: #2a2a2a;
  color: #ffffff;
}

.table-responsive {
  width: 100%;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch; /* Kinetic scrolling tracking for mobile finger sweeps */
  border: 1px solid var(--border-color);
  border-radius: 6px;
  background-color: var(--bg-card);
}

.table-responsive table {
  margin-top: 0;
}

/* ==========================================================================
   8. SMARTPHONE VIEWPORT ADJUSTMENT (FORCE COMPACT CART POSITIONING)
   ========================================================================== */
@media (max-width: 480px) {
    /* Hide any product entries beyond the first 4 elements when search is empty */
    #catalogGrid:not(.searching) .product-item:nth-child(n+5) {
        display: none !important;
    }
    
    /* Bring up the cart panel so cashiers don't have to scroll deep down */
    .cart-panel {
        margin-top: 10px !important;
    }
}


/* ==========================================================================
7. PROGRESSIVE DESKTOP MEDIA QUERIES (BREAKPOINT SCALE UP ENHANCEMENTS)
========================================================================== */
/* Medium Devices & Tablet monitors (768px Width and Up) */
@media (min-width: 768px) {
  .app-container {
    flex-direction: row;
  }

  /* Pushes content right to preserve a fixed full height 260px workspace lane */
  .main-content-panel {
    margin-left: 260px;
    padding: 30px 40px;
  }

  .header {
    flex-direction: row;
    justify-content: space-between;
    align-items: center;
  }

  /* Transforms Mobile Side Drawer into fixed full height left column */
  .nav-sidebar {
    left: 0 !important;
    right: auto !important;
    width: 260px;
    position: fixed;
    background-color: #1a1a1a;
    box-shadow: 2px 0 10px rgba(0, 0, 0, 0.03);
    border-right: 1px solid var(--border-color);
  }

  /* Disable layout mobile drawer elements toggle switches buttons links */
  .mobile-menu-trigger,
  .sidebar-overlay {
    display: none !important;
  }

  .grid-cards,
  .metrics-row {
    grid-template-columns: repeat(2, 1fr);
  }

  .form-grid-row {
    grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  }

  .btn {
    width: auto;
  }

  /* Branch checkout and baskets containers layouts elements apart side-by-side */
  .pos-container {
    display: grid !important;
    grid-template-columns: 1.1fr 0.9fr;
    gap: 20px;
  }

  .product-grid {
    grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)) !important;
    gap: 12px !important;
  }

  .product-item {
    padding: 20px 10px;
    min-height: 130px;
  }
}

/* Widescreen Displays (1024px Width and Up) */
@media (min-width: 1024px) {
  .grid-cards,
  .metrics-row {
    grid-template-columns: repeat(3, 1fr);
  }

  .pos-container {
    grid-template-columns: 1.3fr 0.7fr;
    gap: 30px;
  }

  .product-grid {
    grid-template-columns: repeat(auto-fill, minmax(160px, 1fr)) !important;
  }
}
