/* ================================================================
   Stock Management System - Main Stylesheet
   Design: Clean operational UI, monochrome with teal accent
   ================================================================ */

/* ── Fonts ───────────────────────────────────────────────────── */
@import url('https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600&family=JetBrains+Mono:wght@400;500&display=swap');

/* ── CSS Variables ───────────────────────────────────────────── */
:root {
  /* Brand */
  --accent:        #0D9488;
  --accent-light:  #CCFBF1;
  --accent-dark:   #0F766E;
  --accent-text:   #134E4A;

  /* Surfaces */
  --bg-page:       #F1F5F9;
  --bg-card:       #FFFFFF;
  --bg-sidebar:    #0F172A;
  --bg-sidebar-hover: #1E293B;
  --bg-input:      #FFFFFF;
  --bg-table-odd:  #F8FAFC;

  /* Text */
  --text-primary:  #0F172A;
  --text-secondary:#475569;
  --text-muted:    #94A3B8;
  --text-sidebar:  #94A3B8;
  --text-sidebar-active: #FFFFFF;

  /* Borders */
  --border:        #E2E8F0;
  --border-focus:  #0D9488;

  /* Status */
  --success-bg:    #F0FDF4;
  --success-text:  #166534;
  --success-border:#BBF7D0;
  --danger-bg:     #FEF2F2;
  --danger-text:   #991B1B;
  --danger-border: #FECACA;
  --warning-bg:    #FEF3C7;
  --warning-text:  #78350F;
  --warning-border:#FCD34D;
  --info-bg:       #EFF6FF;
  --info-text:     #1E40AF;
  --info-border:   #BFDBFE;

  /* Shadows */
  --shadow-sm:     0 1px 2px rgba(0,0,0,.06);
  --shadow-md:     0 4px 12px rgba(0,0,0,.08);
  --shadow-lg:     0 8px 24px rgba(0,0,0,.10);

  /* Layout */
  --sidebar-width: 240px;
  --topbar-height: 60px;
  --radius:        8px;
  --radius-lg:     12px;

  /* Typography */
  --font:          'Inter', system-ui, sans-serif;
  --font-mono:     'JetBrains Mono', monospace;
}

/* ── Dark mode ───────────────────────────────────────────────── */
[data-theme="dark"] {
  --bg-page:       #0F172A;
  --bg-card:       #1E293B;
  --bg-sidebar:    #020617;
  --bg-sidebar-hover: #1E293B;
  --bg-input:      #1E293B;
  --bg-table-odd:  #172033;

  --text-primary:  #F1F5F9;
  --text-secondary:#94A3B8;
  --text-muted:    #475569;

  --border:        #334155;
  --border-focus:  #14B8A6;
  --accent:        #14B8A6;
  --accent-light:  #134E4A;
  --accent-dark:   #0D9488;
  --accent-text:   #CCFBF1;

  --success-bg:    #052E16;
  --success-text:  #86EFAC;
  --success-border:#14532D;
  --danger-bg:     #450A0A;
  --danger-text:   #FCA5A5;
  --danger-border: #7F1D1D;
  --warning-bg:    #451A03;
  --warning-text:  #FCD34D;
  --warning-border:#78350F;
  --info-bg:       #1E1B4B;
  --info-text:     #A5B4FC;
  --info-border:   #312E81;

  --shadow-sm:     0 1px 2px rgba(0,0,0,.3);
  --shadow-md:     0 4px 12px rgba(0,0,0,.4);
}

/* ── Reset & base ────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

html { font-size: 15px; -webkit-text-size-adjust: 100%; }

body {
  font-family: var(--font);
  background: var(--bg-page);
  color: var(--text-primary);
  line-height: 1.6;
  min-height: 100vh;
  transition: background .2s, color .2s;
}

a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }

img, svg { max-width: 100%; }

/* ── Layout ──────────────────────────────────────────────────── */
.layout { display: flex; min-height: 100vh; }

/* ── Sidebar ─────────────────────────────────────────────────── */
.sidebar {
  width: var(--sidebar-width);
  background: var(--bg-sidebar);
  display: flex;
  flex-direction: column;
  position: fixed;
  top: 0; left: 0;
  height: 100vh;
  height: 100dvh; /* actual visible viewport on mobile browsers with dynamic toolbars */
  z-index: 200;
  transition: transform .25s ease, width .25s ease;
  overflow: hidden;
}

.sidebar-brand {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 18px 20px;
  border-bottom: 1px solid rgba(255,255,255,.06);
  flex-shrink: 0;
}

.sidebar-brand .brand-icon {
  width: 34px; height: 34px;
  background: var(--accent);
  border-radius: 8px;
  display: flex; align-items: center; justify-content: center;
  flex-shrink: 0;
}

.sidebar-brand .brand-icon svg { width: 18px; height: 18px; stroke: #fff; }

.sidebar-brand .brand-name {
  font-size: .82rem;
  font-weight: 600;
  color: #fff;
  line-height: 1.25;
  letter-spacing: .01em;
}

.sidebar-brand .brand-sub {
  font-size: .72rem;
  color: var(--text-sidebar);
}

.sidebar-section-label {
  padding: 18px 20px 6px;
  font-size: .68rem;
  font-weight: 600;
  letter-spacing: .08em;
  text-transform: uppercase;
  color: var(--text-muted);
}

.sidebar nav {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  overflow-x: hidden;
  -webkit-overflow-scrolling: touch;
  padding-bottom: 20px;
}

.sidebar nav a {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 9px 20px;
  font-size: .84rem;
  font-weight: 500;
  color: var(--text-sidebar);
  text-decoration: none;
  border-left: 3px solid transparent;
  transition: background .15s, color .15s, border-color .15s;
}

.sidebar nav a:hover {
  background: var(--bg-sidebar-hover);
  color: #fff;
}

.sidebar nav a.active {
  background: var(--bg-sidebar-hover);
  color: #fff;
  border-left-color: var(--accent);
}

.sidebar nav a svg {
  width: 17px; height: 17px;
  stroke: currentColor;
  flex-shrink: 0;
  opacity: .8;
}

.sidebar nav a.active svg { opacity: 1; }

.sidebar-footer {
  padding: 14px 20px;
  border-top: 1px solid rgba(255,255,255,.06);
  flex-shrink: 0;
}

.sidebar-footer .user-info {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 10px;
}

.user-avatar {
  width: 32px; height: 32px;
  border-radius: 50%;
  background: var(--accent);
  color: #fff;
  font-size: .75rem;
  font-weight: 600;
  display: flex; align-items: center; justify-content: center;
  flex-shrink: 0;
}

.user-details { overflow: hidden; }
.user-details .name { font-size: .82rem; font-weight: 500; color: #fff; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.user-details .role-badge { font-size: .68rem; color: var(--text-sidebar); text-transform: capitalize; }

.sidebar-footer-links { display: flex; gap: 8px; flex-wrap: wrap; }
.sidebar-footer-links a {
  font-size: .75rem;
  color: var(--text-muted);
  text-decoration: none;
  padding: 3px 0;
}
.sidebar-footer-links a:hover { color: var(--text-sidebar); }

/* ── Main content ────────────────────────────────────────────── */
.main-content {
  margin-left: var(--sidebar-width);
  flex: 1;
  display: flex;
  flex-direction: column;
  min-height: 100vh;
  transition: margin-left .25s ease;
}

/* ── Topbar ──────────────────────────────────────────────────── */
.topbar {
  height: var(--topbar-height);
  background: var(--bg-card);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 24px;
  position: sticky;
  top: 0;
  z-index: 100;
  box-shadow: var(--shadow-sm);
}

.topbar-left { display: flex; align-items: center; gap: 14px; }

.topbar-left .page-title {
  font-size: 1rem;
  font-weight: 600;
  color: var(--text-primary);
}

.hamburger {
  display: none;
  background: none;
  border: none;
  cursor: pointer;
  padding: 4px;
  color: var(--text-secondary);
}
.hamburger svg { width: 22px; height: 22px; }

.topbar-right { display: flex; align-items: center; gap: 10px; }

/* Theme toggle */
.theme-toggle {
  width: 34px; height: 34px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: transparent;
  cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  color: var(--text-secondary);
  transition: background .15s, border-color .15s;
}
.theme-toggle:hover { background: var(--bg-table-odd); border-color: var(--border-focus); }
.theme-toggle svg { width: 16px; height: 16px; }

/* ── Page body ───────────────────────────────────────────────── */
.page-body { padding: 24px; flex: 1; }

.page-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 24px;
  flex-wrap: wrap;
  gap: 12px;
}

.page-header h1 { font-size: 1.25rem; font-weight: 600; }

.breadcrumb {
  font-size: .8rem;
  color: var(--text-muted);
  display: flex;
  align-items: center;
  gap: 6px;
  margin-top: 2px;
}
.breadcrumb span { color: var(--text-muted); }
.breadcrumb a { color: var(--accent); }

/* ── Cards ───────────────────────────────────────────────────── */
.card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-sm);
  overflow: hidden;
}

.card-header {
  padding: 16px 20px;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
}

.card-title { font-size: .95rem; font-weight: 600; }

.card-body { padding: 20px; }

/* ── Stat cards ──────────────────────────────────────────────── */
.stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
  gap: 16px;
  margin-bottom: 24px;
}

.stat-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 18px 20px;
  display: flex;
  align-items: center;
  gap: 14px;
  box-shadow: var(--shadow-sm);
  transition: box-shadow .2s;
}

.stat-card:hover { box-shadow: var(--shadow-md); }

.stat-icon {
  width: 44px; height: 44px;
  border-radius: 10px;
  display: flex; align-items: center; justify-content: center;
  flex-shrink: 0;
}
.stat-icon svg { width: 22px; height: 22px; stroke: currentColor; }
.stat-icon.teal    { background: var(--accent-light); color: var(--accent-dark); }
.stat-icon.green   { background: #DCFCE7; color: #166534; }
.stat-icon.red     { background: #FEE2E2; color: #991B1B; }
.stat-icon.amber   { background: #FEF3C7; color: #92400E; }
.stat-icon.blue    { background: var(--info-bg); color: var(--info-text); }
[data-theme="dark"] .stat-icon.green  { background: #052E16; color: #86EFAC; }
[data-theme="dark"] .stat-icon.red    { background: #450A0A; color: #FCA5A5; }
[data-theme="dark"] .stat-icon.amber  { background: #451A03; color: #FCD34D; }

.stat-body {}
.stat-label { font-size: .75rem; color: var(--text-muted); font-weight: 500; margin-bottom: 2px; }
.stat-value { font-size: 1.5rem; font-weight: 600; line-height: 1; font-family: var(--font-mono); }
.stat-sub   { font-size: .72rem; color: var(--text-muted); margin-top: 3px; }

/* ── Buttons ─────────────────────────────────────────────────── */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 8px 16px;
  font-size: .84rem;
  font-weight: 500;
  border-radius: var(--radius);
  border: 1px solid transparent;
  cursor: pointer;
  text-decoration: none;
  transition: background .15s, border-color .15s, box-shadow .15s, opacity .15s;
  white-space: nowrap;
  font-family: var(--font);
  line-height: 1.4;
}

.btn:disabled { opacity: .55; cursor: not-allowed; }
.btn svg { width: 15px; height: 15px; flex-shrink: 0; }

.btn-primary   { background: var(--accent);      color: #fff;                  border-color: var(--accent);      }
.btn-primary:hover   { background: var(--accent-dark); border-color: var(--accent-dark); text-decoration: none; }

.btn-secondary { background: var(--bg-card);     color: var(--text-primary);   border-color: var(--border);      }
.btn-secondary:hover { background: var(--bg-table-odd); border-color: var(--text-muted); text-decoration: none; }

.btn-danger    { background: #DC2626;             color: #fff;                  border-color: #DC2626;            }
.btn-danger:hover    { background: #B91C1C; border-color: #B91C1C; text-decoration: none; }

.btn-warning   { background: #D97706;             color: #fff;                  border-color: #D97706;            }

.btn-sm { padding: 5px 11px; font-size: .78rem; }
.btn-xs { padding: 3px 8px;  font-size: .74rem; }

/* ── Forms ───────────────────────────────────────────────────── */
.form-group { margin-bottom: 18px; }

label {
  display: block;
  font-size: .82rem;
  font-weight: 500;
  color: var(--text-secondary);
  margin-bottom: 6px;
}

label .required { color: #EF4444; margin-left: 2px; }

.form-control {
  width: 100%;
  padding: 9px 12px;
  font-size: .88rem;
  font-family: var(--font);
  background: var(--bg-input);
  color: var(--text-primary);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  outline: none;
  transition: border-color .15s, box-shadow .15s;
  line-height: 1.5;
}

.form-control:focus {
  border-color: var(--border-focus);
  box-shadow: 0 0 0 3px rgba(13,148,136,.12);
}

.form-control::placeholder { color: var(--text-muted); }

select.form-control { cursor: pointer; }

.pw-wrap { position: relative; }
.pw-wrap input { padding-right: 44px; }
.pw-toggle {
  position: absolute; right: 12px; top: 50%;
  transform: translateY(-50%);
  background: none; border: none; cursor: pointer;
  color: var(--text-muted); display: flex; align-items: center; padding: 0;
}
.pw-toggle svg { width: 18px; height: 18px; }
.pw-toggle:hover { color: var(--text-primary); }

textarea.form-control { resize: vertical; min-height: 90px; }

.form-hint { font-size: .75rem; color: var(--text-muted); margin-top: 4px; }
.form-error { font-size: .75rem; color: #EF4444; margin-top: 4px; }

.form-row {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  gap: 16px;
}

/* ── Table ───────────────────────────────────────────────────── */
.table-wrapper { overflow-x: auto; }

table {
  width: 100%;
  border-collapse: collapse;
  font-size: .85rem;
}

thead th {
  padding: 11px 14px;
  text-align: left;
  font-size: .76rem;
  font-weight: 600;
  letter-spacing: .04em;
  text-transform: uppercase;
  color: var(--text-muted);
  background: var(--bg-table-odd);
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}

tbody tr { border-bottom: 1px solid var(--border); transition: background .1s; }
tbody tr:last-child { border-bottom: none; }
tbody tr:hover { background: var(--bg-table-odd); }
tbody tr:nth-child(odd) { background: transparent; }

td {
  padding: 11px 14px;
  color: var(--text-primary);
  vertical-align: middle;
}

td .mono { font-family: var(--font-mono); font-size: .82rem; }

/* ── Badges ──────────────────────────────────────────────────── */
.badge {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 3px 8px;
  border-radius: 20px;
  font-size: .72rem;
  font-weight: 600;
  letter-spacing: .02em;
}

.badge-success { background: var(--success-bg); color: var(--success-text); border: 1px solid var(--success-border); }
.badge-danger  { background: var(--danger-bg);  color: var(--danger-text);  border: 1px solid var(--danger-border);  }
.badge-warning { background: var(--warning-bg); color: var(--warning-text); border: 1px solid var(--warning-border); }
.badge-info    { background: var(--info-bg);    color: var(--info-text);    border: 1px solid var(--info-border);    }
.badge-neutral { background: var(--bg-table-odd); color: var(--text-secondary); border: 1px solid var(--border); }

/* ── Alerts ──────────────────────────────────────────────────── */
.alert {
  padding: 12px 16px;
  border-radius: var(--radius);
  font-size: .86rem;
  margin-bottom: 18px;
  display: flex;
  align-items: flex-start;
  gap: 10px;
}
.alert svg { width: 17px; height: 17px; flex-shrink: 0; margin-top: 1px; }
.alert-success { background: var(--success-bg); color: var(--success-text); border: 1px solid var(--success-border); }
.alert-danger  { background: var(--danger-bg);  color: var(--danger-text);  border: 1px solid var(--danger-border);  }
.alert-warning { background: var(--warning-bg); color: var(--warning-text); border: 1px solid var(--warning-border); }
.alert-info    { background: var(--info-bg);    color: var(--info-text);    border: 1px solid var(--info-border);    }

/* ── Pagination ──────────────────────────────────────────────── */
.pagination { display: flex; align-items: center; gap: 4px; }
.pagination a, .pagination span {
  padding: 5px 10px;
  font-size: .8rem;
  border-radius: 6px;
  border: 1px solid var(--border);
  color: var(--text-secondary);
  text-decoration: none;
  transition: background .15s;
}
.pagination a:hover { background: var(--bg-table-odd); }
.pagination .active { background: var(--accent); border-color: var(--accent); color: #fff; font-weight: 600; }

/* ── Modals ──────────────────────────────────────────────────── */
.modal-backdrop {
  position: fixed; inset: 0;
  background: rgba(0,0,0,.45);
  z-index: 1000;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  animation: fadeIn .15s;
}
@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }

.modal {
  background: var(--bg-card);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg);
  width: 100%;
  max-width: 520px;
  max-height: 90vh;
  overflow-y: auto;
  animation: slideUp .18s;
}
@keyframes slideUp { from { transform: translateY(16px); opacity: 0; } to { transform: translateY(0); opacity: 1; } }

.modal-header {
  padding: 18px 20px;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.modal-title { font-size: 1rem; font-weight: 600; }

.modal-close {
  background: none; border: none; cursor: pointer;
  color: var(--text-muted); padding: 2px;
  display: flex; align-items: center;
  border-radius: 4px;
  transition: background .15s, color .15s;
}
.modal-close:hover { background: var(--bg-table-odd); color: var(--text-primary); }
.modal-close svg { width: 18px; height: 18px; }

.modal-body { padding: 20px; }
.modal-footer { padding: 16px 20px; border-top: 1px solid var(--border); display: flex; gap: 10px; justify-content: flex-end; }

/* ── Dropdown ────────────────────────────────────────────────── */
.dropdown { position: relative; }
.dropdown-menu {
  position: absolute;
  right: 0; top: calc(100% + 4px);
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-md);
  min-width: 180px;
  z-index: 300;
  display: none;
  animation: slideUp .15s;
}
.dropdown-menu.open { display: block; }
.dropdown-menu a {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 9px 14px;
  font-size: .84rem;
  color: var(--text-primary);
  text-decoration: none;
  transition: background .1s;
}
.dropdown-menu a:hover { background: var(--bg-table-odd); }
.dropdown-menu .divider { height: 1px; background: var(--border); margin: 4px 0; }
.dropdown-menu a.danger { color: #DC2626; }

/* ── Login page ──────────────────────────────────────────────── */
.login-wrap {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--bg-page);
  padding: 20px;
}

.login-card {
  width: 100%;
  max-width: 400px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg);
  overflow: hidden;
}

.login-header {
  background: var(--bg-sidebar);
  padding: 28px 30px 24px;
  text-align: center;
}

.login-logo {
  width: 48px; height: 48px;
  background: var(--accent);
  border-radius: 12px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  margin-bottom: 12px;
}
.login-logo svg { width: 26px; height: 26px; stroke: #fff; }

.login-header h1 { font-size: 1.1rem; font-weight: 600; color: #fff; }
.login-header p  { font-size: .8rem; color: var(--text-muted); margin-top: 4px; }

.login-body { padding: 28px 30px; }

/* ── Utility ─────────────────────────────────────────────────── */
.flex         { display: flex; }
.flex-center  { display: flex; align-items: center; }
.flex-between { display: flex; align-items: center; justify-content: space-between; }
.gap-2 { gap: 8px; }
.gap-3 { gap: 12px; }
.gap-4 { gap: 16px; }
.mt-1 { margin-top: 4px; }
.mt-2 { margin-top: 8px; }
.mt-3 { margin-top: 12px; }
.mt-4 { margin-top: 16px; }
.mb-4 { margin-bottom: 16px; }
.mb-6 { margin-bottom: 24px; }
.text-muted   { color: var(--text-muted); }
.text-sm      { font-size: .82rem; }
.text-right   { text-align: right; }
.font-mono    { font-family: var(--font-mono); }
.w-full       { width: 100%; }

/* ── Scrollbar ───────────────────────────────────────────────── */
::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 10px; }
::-webkit-scrollbar-thumb:hover { background: var(--text-muted); }

/* ── Sidebar mini toggle button ──────────────────────────────── */
.sidebar-mini-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 26px; height: 26px;
  background: none;
  border: 1px solid rgba(255,255,255,.1);
  border-radius: 6px;
  cursor: pointer;
  color: var(--text-sidebar);
  flex-shrink: 0;
  margin-left: auto;
  transition: background .15s, color .15s, transform .25s ease;
  -webkit-tap-highlight-color: transparent;
}
.sidebar-mini-btn:hover { background: var(--bg-sidebar-hover); color: #fff; }
.sidebar-mini-btn svg   { width: 14px; height: 14px; }

/* Mobile-only close (×) button inside the sidebar header */
.sidebar-close-btn {
  display: none;
  align-items: center;
  justify-content: center;
  width: 34px;
  height: 34px;
  border: none;
  border-radius: var(--radius);
  background: transparent;
  color: var(--text-sidebar);
  cursor: pointer;
  margin-left: auto;
  flex-shrink: 0;
  transition: background .15s, color .15s;
  -webkit-tap-highlight-color: transparent;
}
.sidebar-close-btn:hover { background: var(--bg-sidebar-hover); color: #fff; }

/* ── Sidebar mini (collapsed to icon rail) ───────────────────── */
:root { --sidebar-mini-width: 64px; }

.sidebar.mini { width: var(--sidebar-mini-width); }

.main-content.mini { margin-left: var(--sidebar-mini-width); }

/* Flip chevron when mini */
.sidebar.mini .sidebar-mini-btn { transform: rotate(180deg); }

/* Hide all text when mini */
.sidebar.mini .brand-text,
.sidebar.mini .sidebar-section-label .nav-label,
.sidebar.mini .nav-label,
.sidebar.mini .user-details,
.sidebar.mini .sidebar-footer-links { display: none; }

/* Mini: stack the toggle button ABOVE the logo so they don't collide in the
   narrow rail. */
.sidebar.mini .sidebar-brand {
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 10px;
  padding: 12px 0;
}
.sidebar.mini .sidebar-mini-btn { order: -1; margin: 0; }

/* Center icons in nav links */
.sidebar.mini nav a {
  justify-content: center;
  padding: 12px 0;
  gap: 0;
  border-left-color: transparent;
}
.sidebar.mini nav a.active { border-left-color: var(--accent); }
.sidebar.mini nav a svg { width: 20px; height: 20px; opacity: .8; }
.sidebar.mini nav a:hover svg,
.sidebar.mini nav a.active svg { opacity: 1; }

/* Section label becomes a thin divider */
.sidebar.mini .sidebar-section-label {
  padding: 10px 12px 4px;
  border-top: 1px solid rgba(255,255,255,.06);
  margin-top: 4px;
}
.sidebar.mini .sidebar-section-label:first-child { border-top: none; margin-top: 0; }

/* Footer when mini - center avatar only */
.sidebar.mini .sidebar-footer { padding: 12px 0; }
.sidebar.mini .user-info      { justify-content: center; margin-bottom: 0; }

/* ── Hover expands the minimized rail (overlays content; leaving re-collapses) ── */
.sidebar.mini:hover { width: var(--sidebar-width); }
.sidebar.mini:hover .brand-text,
.sidebar.mini:hover .nav-label,
.sidebar.mini:hover .sidebar-section-label .nav-label,
.sidebar.mini:hover .user-details,
.sidebar.mini:hover .sidebar-footer-links { display: revert; }
.sidebar.mini:hover .sidebar-brand {
  flex-direction: row;
  justify-content: flex-start;
  align-items: center;
  padding: 18px 20px;
  gap: 10px;
}
.sidebar.mini:hover .sidebar-mini-btn { order: 0; margin: 0 0 0 auto; }
.sidebar.mini:hover nav a {
  justify-content: flex-start;
  padding: 9px 20px;
  gap: 10px;
}
.sidebar.mini:hover nav a svg { width: 18px; height: 18px; }
.sidebar.mini:hover .sidebar-section-label {
  padding: 18px 20px 6px;
  border-top: none;
  margin-top: 0;
}
.sidebar.mini:hover .sidebar-footer { padding: 14px 20px; }
.sidebar.mini:hover .user-info { justify-content: flex-start; margin-bottom: 10px; }

/* ── Touch & interaction ─────────────────────────────────────── */
.btn, .sidebar nav a, .theme-toggle, .hamburger,
.pagination a, .modal-close, [data-dropdown] {
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
}

/* ── Sidebar overlay (CSS-driven) ────────────────────────────── */
#sidebar-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,.5);
  z-index: 199;
  -webkit-backdrop-filter: blur(2px);
  backdrop-filter: blur(2px);
}
#sidebar-overlay.show { display: block; }

/* ── Table scroll shadow hint ────────────────────────────────── */
.table-wrapper {
  -webkit-overflow-scrolling: touch;
  background:
    linear-gradient(to right, var(--bg-card) 20%, transparent),
    linear-gradient(to left,  var(--bg-card) 20%, transparent) right,
    radial-gradient(farthest-side at 0   50%, rgba(0,0,0,.12), transparent),
    radial-gradient(farthest-side at 100% 50%, rgba(0,0,0,.12), transparent) right;
  background-repeat: no-repeat;
  background-color: var(--bg-card);
  background-size: 30px 100%, 30px 100%, 12px 100%, 12px 100%;
  background-attachment: local, local, scroll, scroll;
}

/* ── Mobile table → card view (.table-cards on <table>) ─────── */
/* `screen` matters: a printed page is ~717px wide (A4 minus margins), which
   would otherwise trigger this card view and stack every row instead of
   printing it as a line item. Print keeps the real table (see @media print). */
@media screen and (max-width: 768px) {
  .table-cards thead { display: none; }
  .table-cards,
  .table-cards tbody { display: block; width: 100%; }
  .table-cards tr {
    display: block;
    margin: 0 12px 10px;
    width: calc(100% - 24px);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    background: var(--bg-card);
    overflow: hidden;
  }
  .table-cards td {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    padding: 9px 14px;
    border: none;
    border-bottom: 1px solid var(--bg-table-odd);
    font-size: .85rem;
    gap: 10px;
  }
  .table-cards td:last-child { border-bottom: none; }
  .table-cards td::before {
    content: attr(data-label);
    font-weight: 600;
    font-size: .72rem;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: .05em;
    flex-shrink: 0;
    min-width: 90px;
    padding-top: 2px;
  }
  .table-cards td[data-label=""] { justify-content: center; }
  .table-cards td[data-label=""]::before { display: none; }
  .table-cards td:first-child { background: var(--bg-table-odd); font-weight: 600; }
}

/* ── Responsive layout grids (sidebar + 2/3-col page layouts) ── */
.grid-side-l, .grid-side-r, .grid-2, .grid-3 {
  display: grid;
  gap: 20px;
  align-items: start;
}
.grid-side-l { grid-template-columns: var(--side-w, 320px) 1fr; }
.grid-side-r { grid-template-columns: 1fr var(--side-w, 300px); }
.grid-2      { grid-template-columns: 1fr 1fr; }
.grid-3      { grid-template-columns: repeat(3, 1fr); }

/* ── Tablet (769 – 1024px) ───────────────────────────────────── */
@media (min-width: 769px) and (max-width: 1024px) {
  .grid-3 { grid-template-columns: repeat(2, 1fr); }
  :root { --sidebar-width: 210px; }
  .page-body  { padding: 16px; }
  .stats-grid { grid-template-columns: repeat(2, 1fr); }
  .sidebar nav a { padding: 10px 18px; }
}

/* ── Mobile (≤ 768px) ────────────────────────────────────────── */
@media (max-width: 768px) {
  /* Mini state has no effect on mobile - sidebar is overlay-based */
  .sidebar.mini           { width: var(--sidebar-width) !important; }
  .sidebar.mini nav a     { justify-content: flex-start; padding: 13px 20px; gap: 10px; }
  .sidebar.mini .nav-label,
  .sidebar.mini .brand-text,
  .sidebar.mini .user-details,
  .sidebar.mini .sidebar-footer-links { display: revert; }
  .sidebar.mini .sidebar-brand { justify-content: flex-start; padding: 18px 20px; gap: 10px; }
  .sidebar.mini .sidebar-footer { padding: 14px 20px; }
  .sidebar.mini .user-info { justify-content: flex-start; margin-bottom: 10px; }
  .main-content.mini      { margin-left: 0 !important; }
  .sidebar-mini-btn       { display: none; }
  .sidebar-close-btn      { display: flex; }

  .sidebar { transform: translateX(-100%); }
  .sidebar.open { transform: translateX(0); box-shadow: var(--shadow-lg); }
  .main-content { margin-left: 0; }
  .hamburger { display: flex; }

  /* Prevent iOS auto-zoom on input focus */
  .form-control,
  select.form-control,
  textarea.form-control { font-size: 16px; }

  /* Comfortable touch targets */
  .btn     { min-height: 42px; }
  .btn-sm  { min-height: 38px; padding: 7px 13px; }
  .btn-xs  { min-height: 36px; padding: 6px 10px; font-size: .78rem; }

  /* Sidebar nav links - fat tap targets */
  .sidebar nav a { padding: 13px 20px; font-size: .88rem; }
  .sidebar-section-label { padding: 16px 20px 5px; }

  /* Topbar */
  .topbar { padding: 0 14px; }
  .breadcrumb { display: none; }

  /* Page */
  .page-body   { padding: 14px 12px; }
  .page-header { margin-bottom: 14px; }
  .page-header h1 { font-size: 1.1rem; }

  /* Cards */
  .card-header { padding: 12px 14px; gap: 8px; }
  .card-body   { padding: 14px; }

  /* Stats */
  .stats-grid  { grid-template-columns: 1fr 1fr; gap: 10px; margin-bottom: 16px; }
  .stat-card   { padding: 14px; gap: 10px; }
  .stat-value  { font-size: 1.3rem; }

  /* Tables */
  thead th { padding: 9px 10px; }
  td        { padding: 10px 10px; }

  /* Modal - bottom sheet on mobile */
  .modal-backdrop { align-items: flex-end; padding: 0; }
  .modal {
    max-width: 100%;
    border-radius: var(--radius-lg) var(--radius-lg) 0 0;
    max-height: 92vh;
  }

  /* Login */
  .login-header { padding: 22px 22px 18px; }
  .login-body   { padding: 22px; }

  /* Pagination */
  .pagination { flex-wrap: wrap; gap: 3px; }
  .pagination a, .pagination span { padding: 7px 11px; min-height: 36px; display: flex; align-items: center; }

  /* Sidebar + multi-column page layouts stack on mobile */
  .grid-side-l, .grid-side-r, .grid-2, .grid-3 { grid-template-columns: 1fr; gap: 16px; }

  /* Force any inline-overridden .form-row columns to stack on mobile */
  .form-row { grid-template-columns: 1fr !important; }
}

/* ── Small phones (≤ 480px) ──────────────────────────────────── */
@media (max-width: 480px) {
  .stats-grid { grid-template-columns: 1fr; gap: 8px; }
  .form-row   { grid-template-columns: 1fr; }
  .page-body  { padding: 10px; }
  .topbar     { padding: 0 10px; }

  /* Stack card header actions below title */
  .card-header { flex-direction: column; align-items: flex-start; }

  /* Sidebar */
  .sidebar-brand { padding: 14px 16px; }
  .sidebar-footer { padding: 12px 16px; }

  /* Login */
  .login-body   { padding: 18px 16px; }
  .login-header { padding: 20px 16px 16px; }
}

/* ── Notched phone safe areas ────────────────────────────────── */
@supports (padding: env(safe-area-inset-bottom)) {
  .sidebar      { padding-bottom: env(safe-area-inset-bottom); }
  .topbar       { padding-left:  max(14px, env(safe-area-inset-left));
                  padding-right: max(14px, env(safe-area-inset-right)); }
  .page-body    { padding-bottom: max(14px, env(safe-area-inset-bottom)); }
}

/* ── Print ───────────────────────────────────────────────────── */
@media print {
  .sidebar, .topbar, .no-print { display: none !important; }
  .main-content { margin-left: 0 !important; }
  body { background: #fff; color: #000; }
  .card { box-shadow: none; border: 1px solid #ddd; }

  /* Reports must print as line items, not stacked cards. Force real table
     layout and undo any card-view leftovers. */
  .table-wrapper { overflow: visible !important; }
  table.table-cards { display: table !important; width: 100% !important; table-layout: auto; }
  .table-cards thead { display: table-header-group !important; }  /* repeat header on each page */
  .table-cards tbody { display: table-row-group !important; }
  .table-cards tr {
    display: table-row !important;
    margin: 0 !important; width: auto !important;
    border: 0 !important; border-radius: 0 !important;
    background: transparent !important;
    page-break-inside: avoid; break-inside: avoid;
  }
  .table-cards th,
  .table-cards td {
    display: table-cell !important;
    border: 0 !important;
    border-bottom: 1px solid #ddd !important;
    padding: 5px 7px !important;
    font-size: 10px !important;
    background: transparent !important;
    font-weight: normal;
  }
  .table-cards thead th { font-weight: 700; border-bottom: 1.5px solid #999 !important; }
  .table-cards td::before { display: none !important; }   /* kill mobile data-labels */

  /* Keep colour-coded chips readable in mono print */
  .badge { border: 1px solid #999 !important; color: #000 !important; background: transparent !important; }
}

/* ── Topbar icon buttons ─────────────────────────────────── */
.topbar-icon-btn {
  width: 34px; height: 34px;
  border: 1px solid var(--border);
  background: transparent; border-radius: 8px;
  display: flex; align-items: center; justify-content: center;
  cursor: pointer; color: var(--text-secondary); position: relative;
  transition: background .15s, border-color .15s; flex-shrink: 0;
}
.topbar-icon-btn:hover { background: var(--bg-table-odd); border-color: var(--border-focus); color: var(--text-primary); }
.topbar-icon-btn svg { width: 16px; height: 16px; }

/* ── Notification bell ───────────────────────────────────── */
.notif-wrap { position: relative; }
.notif-badge {
  position: absolute; top: -5px; right: -5px;
  min-width: 16px; height: 16px;
  background: #dc2626; color: #fff; border-radius: 999px;
  font-size: .6rem; font-weight: 700;
  display: flex; align-items: center; justify-content: center;
  padding: 0 3px; line-height: 1;
  border: 2px solid var(--bg-card); pointer-events: none;
}
.notif-dropdown {
  position: absolute; top: calc(100% + 8px); right: 0;
  width: 290px; background: var(--bg-card);
  border: 1px solid var(--border); border-radius: var(--radius-lg);
  box-shadow: 0 8px 32px rgba(0,0,0,.14);
  z-index: 500; overflow: hidden; display: none; flex-direction: column;
}
.notif-dropdown.open { display: flex; }
.notif-header {
  padding: 10px 14px; font-size: .72rem; font-weight: 700;
  text-transform: uppercase; letter-spacing: .07em;
  color: var(--text-muted); border-bottom: 1px solid var(--border);
  display: flex; align-items: center; justify-content: space-between;
}
.notif-clear-link {
  font-size: .68rem; font-weight: 600; text-transform: none;
  letter-spacing: normal; color: var(--accent); text-decoration: none;
  cursor: pointer;
}
.notif-clear-link:hover { text-decoration: underline; }
.notif-item {
  display: flex; align-items: flex-start; gap: 10px;
  padding: 11px 14px; text-decoration: none;
  border-bottom: 1px solid var(--bg-table-odd);
  transition: background .1s; color: var(--text-primary);
}
.notif-item:last-child { border-bottom: none; }
.notif-item:hover { background: var(--bg-table-odd); }
.notif-item svg { flex-shrink: 0; margin-top: 1px; }
.notif-warning svg { color: var(--warning-text, #b45309); }
.notif-danger  svg { color: var(--danger-text, #991b1b); }
.notif-item-title { font-size: .83rem; font-weight: 600; margin-bottom: 1px; }
.notif-item-sub   { font-size: .74rem; color: var(--text-muted); }
.notif-empty { padding: 18px 14px; text-align: center; font-size: .82rem; color: var(--text-muted); }

/* ── Global search modal ─────────────────────────────────── */
#global-search-modal {
  position: fixed; inset: 0;
  background: rgba(15,23,42,.6); z-index: 2000;
  display: none; align-items: flex-start; justify-content: center;
  padding-top: 70px; backdrop-filter: blur(3px);
}
.gsr-box {
  background: var(--bg-card); border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: 0 24px 64px rgba(0,0,0,.22);
  width: 100%; max-width: 560px; overflow: hidden;
  max-height: calc(100vh - 120px);
  display: flex; flex-direction: column; margin: 0 16px;
}
.gsr-input-row {
  display: flex; align-items: center; gap: 10px;
  padding: 14px 16px; border-bottom: 1px solid var(--border);
}
.gsr-input-row svg { flex-shrink: 0; color: var(--text-muted); }
#gsr-input {
  flex: 1; border: none; outline: none;
  font-size: .97rem; background: transparent;
  color: var(--text-primary); font-family: var(--font-sans);
}
#gsr-input::placeholder { color: var(--text-muted); }
.gsr-esc {
  font-size: .68rem; padding: 2px 6px;
  border: 1px solid var(--border); border-radius: 4px;
  color: var(--text-muted); background: var(--bg-table-odd);
  font-family: var(--font-mono); flex-shrink: 0; white-space: nowrap;
}
#gsr-results { overflow-y: auto; }
.gsr-item {
  display: grid; grid-template-columns: 68px 1fr auto;
  align-items: center; gap: 8px;
  padding: 11px 16px; text-decoration: none;
  border-bottom: 1px solid var(--bg-table-odd); transition: background .1s;
}
.gsr-item:last-child { border-bottom: none; }
.gsr-item:hover,
.gsr-item.active { background: var(--bg-table-odd); }
.gsr-item.active { box-shadow: inset 3px 0 0 var(--accent); }
.gsr-type  { font-size: .67rem; font-weight: 700; text-transform: uppercase; letter-spacing: .06em; }
.gsr-label { font-size: .87rem; font-weight: 600; color: var(--text-primary); }
.gsr-sub   { font-size: .75rem; color: var(--text-muted); text-align: right; }
.gsr-loading, .gsr-empty { padding: 24px 16px; text-align: center; font-size: .84rem; color: var(--text-muted); }
.gsr-hint { padding: 10px 16px; font-size: .76rem; color: var(--text-muted); border-top: 1px solid var(--border); display: flex; align-items: center; gap: 6px; }

/* ── Items view toggle ───────────────────────────────────── */
.view-toggle { display: flex; border: 1px solid var(--border); border-radius: var(--radius); overflow: hidden; }
.view-btn {
  width: 32px; height: 32px;
  display: flex; align-items: center; justify-content: center;
  background: transparent; border: none; cursor: pointer;
  color: var(--text-muted); transition: background .12s, color .12s;
}
.view-btn:hover { background: var(--bg-table-odd); color: var(--text-primary); }
.view-btn.active { background: var(--accent); color: #fff; }
.view-btn svg { width: 14px; height: 14px; }

/* ── Items grid view ─────────────────────────────────────── */
.items-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(210px, 1fr)); gap: 14px; padding: 16px; }
.item-card {
  border: 1px solid var(--border); border-radius: var(--radius);
  background: var(--bg-card); display: flex; flex-direction: column;
  overflow: hidden; transition: box-shadow .15s, transform .15s;
}
.item-card:hover { box-shadow: 0 4px 18px rgba(0,0,0,.09); transform: translateY(-2px); }
.item-card-head {
  display: flex; align-items: center; justify-content: space-between;
  padding: 9px 11px; background: var(--bg-table-odd); border-bottom: 1px solid var(--border);
}
.item-card-body { padding: 11px; flex: 1; }
.item-card-name { font-weight: 700; font-size: .88rem; color: var(--text-primary); margin-bottom: 3px; line-height: 1.35; }
.item-card-meta { font-size: .73rem; color: var(--text-muted); margin-bottom: 6px; }
.item-stock-bar { height: 4px; background: var(--border); border-radius: 99px; overflow: hidden; margin: 6px 0 3px; }
.item-stock-fill { height: 100%; border-radius: 99px; }
.item-stock-fill.ok   { background: var(--accent); }
.item-stock-fill.low  { background: #dc2626; }
.item-card-foot { padding: 8px 11px; border-top: 1px solid var(--border); display: flex; gap: 6px; background: var(--bg-table-odd); }

/* ── Dashboard charts ────────────────────────────────────── */
.dash-charts { display: grid; grid-template-columns: 3fr 2fr; gap: 20px; margin-bottom: 24px; }
@media (max-width: 960px) { .dash-charts { grid-template-columns: 1fr; } }

/* ── Reports section labels ──────────────────────────────── */
.report-section-label {
  font-size: .72rem; font-weight: 700; text-transform: uppercase;
  letter-spacing: .08em; color: var(--text-muted);
  padding: 6px 0 10px; border-bottom: 1px solid var(--border);
  margin-bottom: 16px; grid-column: 1 / -1;
}

/* ── Mobile tweaks ───────────────────────────────────────── */
@media (max-width: 600px) {
  #global-search-modal { padding-top: 12px; }
  .notif-dropdown { width: 260px; right: -40px; }
}
