/* ======================================================
   ROOT / THEME (Light default)
====================================================== */
:root{
  --bg: #ffffff;
  --bg-soft: #f7f7f8;
  --text: #111827;
  --muted: #6b7280;
  --border: #2b2f36;
  --card: #ffffff;

  --primary: #2563eb;
  --primary-hover: #1d4ed8;

  --danger: #dc2626;
  --danger-hover: #b91c1c;

  --success: #22c55e;

  --shadow: 0 8px 24px rgba(0,0,0,.06);
  --radius: 16px;
}

/* ======================================================
   SOFT DARK THEME (B)
====================================================== */
html[data-theme="dark"]{
  --bg: #0f141b;
  --bg-soft: #0b1016;
  --text: #e5e7eb;
  --muted: #a3aab8;
  --border: #3a4350;
  --card: #121a23;

  --shadow: 0 14px 40px rgba(0,0,0,.35);
}

/* ======================================================
   BASE
====================================================== */
*{ box-sizing:border-box; }
html,body{ height:100%; }

body{
  margin:0;
  font-family: system-ui, -apple-system, BlinkMacSystemFont,
               "Segoe UI", Roboto, Ubuntu, Cantarell, Arial;
  background: linear-gradient(180deg, var(--bg) 0%, var(--bg-soft) 100%);
  color: var(--text);
}

a{ text-decoration:none; color:inherit; }

.container{
  max-width:980px;
  margin:auto;
  padding:16px;
}

/* ======================================================
   HEADER / NAV
====================================================== */
.topbar{
  position:sticky;
  top:0;
  z-index:100;
  background: rgba(255,255,255,.92);
  backdrop-filter: blur(10px);
  border-bottom:1px solid rgba(0,0,0,.08);
}

html[data-theme="dark"] .topbar{
  background: rgba(18,26,35,.82);
  border-bottom-color: rgba(255,255,255,.08);
}

.topbar-inner{
  max-width:980px;
  margin:auto;
  padding:12px 16px;
  display:flex;
  align-items:center;
  justify-content:space-between;
  gap:12px;
}

/* Brand */
.brand{
  display:flex;
  align-items:center;
  gap:10px;
  font-weight:700;
}

.brand-badge{
  width:34px;
  height:34px;
  border-radius:10px;
  border:2px solid var(--border);
  display:flex;
  align-items:center;
  justify-content:center;
  font-weight:800;
}

.brand > div:last-child{
  display:flex;
  flex-direction:column;
  justify-content:center;
  line-height:1.1;
}

.brand-title{ font-weight:650; }

/* ======================================================
   NAV PILLS
====================================================== */
.nav{
  display:flex;
  align-items:center;
  gap:8px;
}

.nav a{
  height:36px;
  padding:0 12px;
  display:inline-flex;
  align-items:center;
  justify-content:center;
  border-radius:999px;
  border:1px solid rgba(0,0,0,.15);
  background:#fff;
  font-size:14px;
  line-height:1;
}

html[data-theme="dark"] .nav a{
  border-color: rgba(255,255,255,.12);
  background: rgba(255,255,255,.04);
}

.nav a.active,
.mobile-menu a.active{
  color: var(--primary);
  border-color: var(--primary);
  background: rgba(37,99,235,.10);
  font-weight:650;
}

/* ======================================================
   HEADER ACTION BUTTONS
====================================================== */
.header-actions{
  display:flex;
  align-items:center;
  justify-content:center;
  gap:8px;
}

/* Icon buttons */
.icon-btn,
.theme-toggle{
  width:36px;
  height:36px;
  display:inline-flex;
  align-items:center;
  justify-content:center;
  padding:0;
  border-radius:999px;
  border:1px solid rgba(0,0,0,.15);
  cursor:pointer;
  line-height:1;
  font-size:16px;
}

.icon-btn span,
.theme-toggle span{
  display:inline-flex;
  align-items:center;
  justify-content:center;
  line-height:1;
}

/* ======================================================
   THEME TOGGLE – INVERTED (HIGH VISIBILITY)
====================================================== */

/* LIGHT MODE → dark toggle */
html:not([data-theme="dark"]) .theme-toggle{
  background:#111827;
  color:#ffffff;
  border-color:#111827;
}

/* DARK MODE → light toggle */
html[data-theme="dark"] .theme-toggle{
  background:#f9fafb;
  color:#111827;
  border-color:#f9fafb;
}

/* Hover feedback */
.theme-toggle:hover{
  transform: scale(1.05);
  transition: transform .15s ease;
}

/* ======================================================
   TYPOGRAPHY
====================================================== */
.page-title{ font-size:22px; margin:18px 0 4px; }
.page-sub{ font-size:14px; color:var(--muted); margin-bottom:14px; }
.help{ font-size:13px; color:var(--muted); }

/* ======================================================
   GRID / LAYOUT
====================================================== */
.grid{ display:grid; gap:12px; }

@media(min-width:720px){
  .grid.cols-2{ grid-template-columns:1fr 1fr; }
}

.row{ display:grid; gap:10px; }

@media(min-width:720px){
  .row.cols-2{ grid-template-columns:1fr 1fr; }
  .row.cols-3{ grid-template-columns:1fr 1fr 1fr; }
}

/* ======================================================
   CARD
====================================================== */
.card{
  background:var(--card);
  border:2px solid var(--border);
  border-radius:var(--radius);
  padding:14px;
  box-shadow:var(--shadow);
}

.card h3{ margin:0 0 6px; }

/* ======================================================
   FORMS
====================================================== */
label{ font-size:13px; color:var(--muted); margin-bottom:6px; display:block; }

input, select{
  width:100%;
  padding:11px 12px;
  border-radius:12px;
  border:1px solid rgba(0,0,0,.2);
  font-size:15px;
  background:#fff;
  color:var(--text);
}

html[data-theme="dark"] input,
html[data-theme="dark"] select{
  border-color: rgba(255,255,255,.14);
  background: rgba(255,255,255,.04);
}

/* ======================================================
   BUTTONS
====================================================== */
.btn{
  display:inline-flex;
  align-items:center;
  justify-content:center;
  gap:6px;
  padding:10px 14px;
  border-radius:12px;
  border:1px solid rgba(0,0,0,.15);
  background:#fff;
  font-weight:600;
  cursor:pointer;
}

html[data-theme="dark"] .btn{
  border-color: rgba(255,255,255,.14);
  background: rgba(255,255,255,.04);
}

.btn.primary{
  background:var(--primary);
  border-color:var(--primary);
  color:#fff;
}

.btn.primary:hover{ background:var(--primary-hover); }

.btn.danger{
  background:var(--danger);
  border-color:var(--danger);
  color:#fff;
}

.btn.danger:hover{ background:var(--danger-hover); }

.actions{ display:flex; gap:8px; flex-wrap:wrap; }

/* ======================================================
   ALERTS
====================================================== */
.alert{
  border-radius:14px;
  padding:12px 14px;
  margin-bottom:12px;
  border:1px solid;
}

.alert.success{
  background:#f0fdf4;
  border-color:#22c55e;
  color:#166534;
}

.alert.error{
  background:#fef2f2;
  border-color:#ef4444;
  color:#7f1d1d;
}

html[data-theme="dark"] .alert.success{
  background: rgba(34,197,94,.10);
  border-color: rgba(34,197,94,.35);
  color:#b7f7cf;
}

html[data-theme="dark"] .alert.error{
  background: rgba(239,68,68,.10);
  border-color: rgba(239,68,68,.35);
  color:#ffd0d0;
}

/* ======================================================
   TABLE
====================================================== */
.table-wrap{
  overflow-x:auto;
  border-radius:14px;
  border:1px solid rgba(0,0,0,.15);
  background:#fff;
}

html[data-theme="dark"] .table-wrap{
  border-color: rgba(255,255,255,.12);
  background: rgba(255,255,255,.02);
}

/* ======================================================
   MOBILE MENU
====================================================== */
.desktop-nav{ display:flex; }
.mobile-menu-btn{ display:none; }

@media(max-width:720px){
  .desktop-nav{ display:none; }
  .mobile-menu-btn{ display:inline-flex; }
}

.mobile-menu{
  display:none;
  flex-direction:column;
  gap:4px;
  padding:8px 16px 12px;
  border-top:1px solid rgba(0,0,0,.08);
  background:#fff;
}

html[data-theme="dark"] .mobile-menu{
  background: rgba(18,26,35,.96);
  border-top-color: rgba(255,255,255,.08);
}

.mobile-menu.open{ display:flex; }

.mobile-menu a{
  height:36px;
  display:flex;
  align-items:center;
  padding:0 12px;
  border-radius:10px;
  border:1px solid rgba(0,0,0,.12);
  background:#fff;
}

html[data-theme="dark"] .mobile-menu a{
  border-color: rgba(255,255,255,.12);
  background: rgba(255,255,255,.04);
}

/* ======================================================
   FOOTER
====================================================== */
.footer-space{ height:24px; }

/* ======================================================
   SHOW ONLY ONE THEME BUTTON
====================================================== */
.desktop-only{ display:inline-flex; }
.mobile-only{ display:none; }

@media(max-width:720px){
  .desktop-only{ display:none; }
  .mobile-only{ display:inline-flex; }
}

/* ======================================================
   HEADER ACTIONS (ensure alignment)
====================================================== */
.header-actions{
  display:flex;
  align-items:center;
  justify-content:center;
  gap:8px;
}

/* ======================================================
   MODAL OVERLAY (REQUIRED for Stock Manager popup)
====================================================== */
.modal-backdrop{
  position:fixed;
  inset:0;
  background:rgba(17,24,39,.55);
  display:none;
  align-items:center;
  justify-content:center;
  padding:16px;
  z-index:9999;
}

.modal-backdrop.is-open{ display:flex; }

.modal{
  width:100%;
  max-width:520px;
  background:var(--card);
  border-radius:18px;
  border:2px solid var(--border);
  box-shadow:0 20px 60px rgba(0,0,0,.22);
  overflow:hidden;
}

.modal-header{
  padding:14px 16px;
  border-bottom:1px solid rgba(0,0,0,.08);
  display:flex;
  align-items:center;
  justify-content:space-between;
  gap:10px;
}

html[data-theme="dark"] .modal-header{
  border-bottom-color: rgba(255,255,255,.08);
}

.modal-title{ margin:0; font-size:18px; }
.modal-sub{ margin:4px 0 0; font-size:13px; color:var(--muted); }

.modal-body{ padding:14px 16px; }

.modal-footer{
  padding:12px 16px;
  border-top:1px solid rgba(0,0,0,.08);
  display:flex;
  align-items:center;
  justify-content:flex-end;
  gap:10px;
}

html[data-theme="dark"] .modal-footer{
  border-top-color: rgba(255,255,255,.08);
}

/* Radio cards inside modal */
.radio-row{
  display:flex;
  gap:12px;
  flex-wrap:wrap;
  margin:10px 0 12px;
}

.radio-card{
  flex:1;
  min-width:200px;
  border:1px solid rgba(0,0,0,.14);
  border-radius:14px;
  padding:12px;
  background:#fff;
}

html[data-theme="dark"] .radio-card{
  border-color: rgba(255,255,255,.12);
  background: rgba(255,255,255,.03);
}

.radio-card input{ width:auto; }
.radio-card strong{ display:block; margin-top:6px; }
.radio-card small{ display:block; margin-top:4px; color:var(--muted); }

/* KPI boxes */
.kpi{
  display:grid;
  grid-template-columns:1fr 1fr 1fr;
  gap:10px;
  margin-top:10px;
}

@media(max-width:520px){
  .kpi{ grid-template-columns:1fr; }
}

.kpi .box{
  border:1px solid rgba(0,0,0,.12);
  border-radius:14px;
  padding:10px 12px;
  background:rgba(0,0,0,.02);
}

html[data-theme="dark"] .kpi .box{
  border-color: rgba(255,255,255,.10);
  background: rgba(255,255,255,.03);
}

.kpi .label{ font-size:12px; color:var(--muted); }
.kpi .val{ font-size:18px; font-weight:800; margin-top:4px; }

.val.positive{ color:#166534; }
.val.negative{ color:#7f1d1d; }

html[data-theme="dark"] .val.positive{ color:#86efac; }
html[data-theme="dark"] .val.negative{ color:#fca5a5; }

/* ======================================================
   TABLE FIX (Stock Manager row alignment)
   Paste at END of CSS to override any broken styles
====================================================== */
.table-wrap{
  overflow-x:auto;
  -webkit-overflow-scrolling: touch;
}

.table-wrap table{
  width:100%;
  border-collapse:collapse;
  table-layout: fixed;              /* IMPORTANT: keeps columns aligned */
  min-width: 720px;                 /* ensures spacing even on small screens */
}

.table-wrap th,
.table-wrap td{
  padding:12px 12px;
  border-bottom:1px solid rgba(0,0,0,.08);
  vertical-align:middle;
  white-space:nowrap;
  overflow:hidden;
  text-overflow:ellipsis;
  text-align:left;
}

html[data-theme="dark"] .table-wrap th,
html[data-theme="dark"] .table-wrap td{
  border-bottom-color: rgba(255,255,255,.08);
}

/* Column widths */
.table-wrap th:nth-child(1),
.table-wrap td:nth-child(1){ width: 24%; }   /* SKU */
.table-wrap th:nth-child(2),
.table-wrap td:nth-child(2){ width: 38%; }   /* FSN */

.table-wrap th:nth-child(3),
.table-wrap td:nth-child(3){
  width: 18%;
  text-align:right;                            /* stock number right aligned */
}

.table-wrap th:nth-child(4),
.table-wrap td:nth-child(4){
  width: 20%;
  text-align:center;                           /* button centered */
}

/* make action buttons not shrink weirdly */
.table-wrap td:nth-child(4) .btn{
  min-width: 84px;
}

/* ======================================================
   SKU TABLE ACTION BUTTONS – THEME CONSISTENT
====================================================== */

/* actions container */
.table-wrap td:nth-child(4) .actions{
  display:flex;
  align-items:center;
  justify-content:center;
  gap:8px;
}

/* base button size (compact pill) */
.table-wrap td:nth-child(4) .btn{
  height:32px;
  padding:0 12px;
  min-width:auto;              /* IMPORTANT: remove fat width */
  font-size:13px;
  border-radius:999px;
  line-height:1;
  font-weight:600;
}

/* EDIT → neutral outline */
.table-wrap td:nth-child(4) .btn:not(.danger){
  background:transparent;
  border:1px solid var(--border);
  color:var(--text);
}

.table-wrap td:nth-child(4) .btn:not(.danger):hover{
  background:rgba(0,0,0,.04);
}

/* DELETE → red outline (not filled) */
.table-wrap td:nth-child(4) .btn.danger{
  background:transparent;
  border:1px solid var(--danger);
  color:var(--danger);
}

.table-wrap td:nth-child(4) .btn.danger:hover{
  background:rgba(220,38,38,.08);
}

/* Dark mode tuning */
html[data-theme="dark"] .table-wrap td:nth-child(4) .btn:not(.danger){
  border-color: rgba(255,255,255,.35);
  color: var(--text);
}

html[data-theme="dark"] .table-wrap td:nth-child(4) .btn.danger{
  border-color: rgba(239,68,68,.6);
  color: #fca5a5;
}

/* ======================================================
   CONSIGNMENT MANAGER TABLE FIX
   - Ensures "Actions" column is visible (5th column)
   - Reduces row height
====================================================== */

.table-wrap table.cons-table{
  table-layout: auto !important;   /* override fixed layout from stock table rules */
  min-width: 0 !important;         /* allow it to fit without forcing 720px */
  width: 100%;
}

.table-wrap table.cons-table th,
.table-wrap table.cons-table td{
  padding: 8px 10px !important;    /* reduce row height */
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.table-wrap table.cons-table th:nth-child(1),
.table-wrap table.cons-table td:nth-child(1){ width: 22%; }  /* Number */

.table-wrap table.cons-table th:nth-child(2),
.table-wrap table.cons-table td:nth-child(2){ width: 28%; }  /* Name */

.table-wrap table.cons-table th:nth-child(3),
.table-wrap table.cons-table td:nth-child(3){ width: 18%; }  /* Status */

.table-wrap table.cons-table th:nth-child(4),
.table-wrap table.cons-table td:nth-child(4){ width: 20%; }  /* Created */

.table-wrap table.cons-table th:nth-child(5),
.table-wrap table.cons-table td:nth-child(5){
  width: 12%;
  text-align: center;
  overflow: visible;
}

/* Make buttons compact in Actions column */
.table-wrap table.cons-table td:nth-child(5) .actions{
  display:flex;
  justify-content:center;
  gap:8px;
  flex-wrap:nowrap;
}

.table-wrap table.cons-table td:nth-child(5) .btn{
  height: 30px;
  padding: 0 12px;
  border-radius: 999px;
  font-size: 13px;
}

/* ======================================================
   STOCK MANAGER TABLE FIX (show all columns)
====================================================== */
.table-wrap.stock-wrap table.stock-table{
  table-layout: auto !important;
  min-width: 980px;     /* ensures Pack Size + Reserved + Available never disappear */
  width: 100%;
}

.table-wrap.stock-wrap th,
.table-wrap.stock-wrap td{
  white-space: nowrap;
}

/* Ensure the Print button looks distinct in the table */
.btn.primary {
    background-color: #2563eb;
    color: white !important;
}

/* Fix for table action spacing */
.table-wrap td .actions {
    display: flex;
    justify-content: center;
    gap: 8px;
}

/* Enable text wrapping for table headers in consignment forms */
#itemsTable th {
  white-space: normal !important; /* Allows text to wrap to the next line */
  vertical-align: bottom;
  line-height: 1.2;
  padding: 8px 4px !important;
  font-size: 13px;
  word-wrap: break-word;
}

/* Specific widths to ensure labels remain readable */
#itemsTable th:nth-child(4) { width: 100px; } /* Available (packets) */
#itemsTable th:nth-child(5) { width: 100px; } /* Ordered Packs */
#itemsTable th:nth-child(6) { width: 100px; } /* Short (packets) */

/* Fix for Consignment Table Layout and Readability */
#itemsTable {
    table-layout: fixed; /* Force respect of percentage widths */
    width: 100%;
}

#itemsTable th {
    white-space: normal !important; /* Enable text wrapping */
    word-wrap: break-word;
    vertical-align: bottom; /* Align multi-line headers to the bottom */
    line-height: 1.2;
    padding: 10px 5px !important;
    font-size: 13px;
    background-color: var(--bg-soft);
}

/* Specific styling for Available column highlight */
#itemsTable th:nth-child(4), 
#itemsTable td:nth-child(4) {
    background-color: rgba(34, 197, 94, 0.05); /* Soft green highlight */
}

/* Ensure inputs fit within narrow columns */
#itemsTable td input, 
#itemsTable td select {
    width: 100%;
    padding: 6px 4px;
    font-size: 13px;
    border-radius: 8px;
}

/* Perfect alignment for Consignment/Stock Tables */
#itemsTable {
    table-layout: fixed;
    width: 100%;
    border-collapse: collapse;
}

#itemsTable th {
    white-space: normal !important;
    word-wrap: break-word;
    /* Center align header text to the input below */
    text-align: center !important; 
    vertical-align: middle;
    line-height: 1.2;
    padding: 12px 5px !important;
    font-size: 13px;
    background-color: var(--bg-soft);
    border-bottom: 2px solid var(--border);
}

#itemsTable td {
    text-align: center;
    padding: 10px 5px !important;
    vertical-align: middle;
}

#itemsTable td input, 
#itemsTable td select {
    width: 100%;
    /* Ensure inputs themselves are centered if needed */
    text-align: center; 
    padding: 8px;
    border-radius: 8px;
    box-sizing: border-box;
}

/* Maintain left-alignment for SKU dropdown text for better readability */
#itemsTable td select {
    text-align-last: center; /* Centers the selected text in dropdown */
}

/* Professional Report Styling */
#itemsTable {
    border-collapse: collapse;
    margin-top: 20px;
}

#itemsTable th {
    background-color: #f3f4f6 !important; /* Soft gray header */
    color: #374151 !important;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    border: 1px solid #e5e7eb;
}

#itemsTable tr:nth-child(even) {
    background-color: #fafafa; /* Zebra striping for readability */
}

#itemsTable td {
    border: 1px solid #e5e7eb;
    padding: 12px 15px !important;
}

/* Specific styling for the shortage column to grab attention */
.text-danger-bold {
    color: #dc2626;
    font-weight: 700;
    background-color: #fef2f2;
}

/* Custom highlighting for shortages */
.text-danger {
    color: #dc2626 !important;
    background-color: #fef2f2;
    padding: 2px 6px;
    border-radius: 4px;
    font-weight: bold;
}

.shortage-row {
    border-left: 4px solid #dc2626 !important;
}

/* Mobile-First Card View for Tables */
@media (max-width: 720px) {
    /* Target the button inside the filter-section/form to ensure black text */
    .filter-section .btn {
        color: #000000 !important; 
        border: 1px solid rgba(0,0,0,0.3);
    }

    /* Keep the Primary button text white */
    .btn.primary {
        color: #ffffff !important;
    }

    /* Hide the original table headers on mobile */
    .table-wrap table thead {
        display: none;
    }

    /* Transform table rows into cards */
    .table-wrap table, 
    .table-wrap tbody, 
    .table-wrap tr, 
    .table-wrap td {
        display: block;
        width: 100% !important;
    }

    .table-wrap tr {
        margin-bottom: 15px;
        border: 2px solid var(--border);
        border-radius: 12px;
        padding: 10px;
        background: var(--card);
    }

    .table-wrap td {
        text-align: left !important;
        padding: 8px 5px !important;
        border: none !important;
        display: flex;
        justify-content: space-between;
        align-items: center;
    }

    /* Add labels before the data using data-attributes */
    .table-wrap td::before {
        content: attr(data-label);
        font-weight: 700;
        color: var(--muted);
        font-size: 12px;
        text-transform: uppercase;
    }

    /* Make the SKU/Name stand out at the top of the card */
    .table-wrap td:first-child {
        background: var(--bg-soft);
        margin: -10px -10px 10px -10px;
        padding: 12px !important;
        border-radius: 10px 10px 0 0;
        font-size: 16px;
        font-weight: 800;
        display: block;
    }
    
    .table-wrap td:first-child::before {
        display: none; /* Hide label for the main heading */
    }

    /* Adjust inputs for thumb-friendly tapping */
    input, select, .btn {
        height: 48px !important; /* Larger touch target */
        font-size: 16px !important; /* Prevents iOS auto-zoom */
    }
}

/* Optimized Mobile Accessibility & Readability */
@media (max-width: 720px) {
    /* Improve touch targets for mobile thumbs */
    input, select, .btn {
        height: 48px !important; 
        font-size: 16px !important; 
        margin-bottom: 5px;
    }

    /* Fix Apply button text visibility in Dark/Light mode */
    .filter-section .btn {
        color: var(--text) !important;
        background: var(--bg);
        border: 1px solid rgba(0,0,0,0.2);
    }

    /* Table to Card Conversion */
    .table-wrap table thead { display: none; }
    .table-wrap table, .table-wrap tbody, .table-wrap tr, .table-wrap td {
        display: block;
        width: 100% !important;
    }

    .table-wrap tr {
        margin-bottom: 20px;
        border: 2px solid var(--border);
        border-radius: 16px;
        padding: 10px;
        background: var(--card);
        box-shadow: var(--shadow);
    }

    .table-wrap td {
        display: flex;
        justify-content: space-between;
        align-items: center;
        padding: 12px 5px !important;
        border-bottom: 1px solid rgba(0,0,0,0.05) !important;
    }

    /* Display the data-label added in PHP/JS */
    .table-wrap td::before {
        content: attr(data-label);
        font-weight: 700;
        color: var(--muted);
        font-size: 12px;
        text-transform: uppercase;
    }

    /* Highlight the first item (SKU) as a card header */
    .table-wrap td:first-child {
        background: var(--bg-soft);
        margin: -10px -10px 10px -10px;
        padding: 15px !important;
        border-radius: 14px 14px 0 0;
        display: block;
        text-align: center;
        font-weight: 800;
        color: var(--primary);
    }
    .table-wrap td:first-child::before { display: none; }
}

@media print {
    /* Hide the topbar and all site navigation */
    .topbar, .mobile-menu, .nav, .header-actions, .btn, .no-print {
        display: none !important;
    }
    
    /* Ensure the body and html have no margins to fit the 3x5 size */
    html, body {
        margin: 0 !important;
        padding: 0 !important;
        background: #fff !important;
    }

    .label-container {
        border: none !important;
        box-shadow: none !important;
    }
}
