/* ===== DESIGN TOKENS ===== */
:root {
  --sidebar-width:   252px;
  --header-height:   58px;

  /* Backgrounds */
  --color-bg:          #f1f5f2;
  --color-bg-subtle:   #f8fafc;
  --color-card:        #ffffff;
  --color-card-border: #e2e8f0;

  /* Sidebar */
  --color-sidebar-bg:     #0a2416;
  --color-sidebar-hover:  rgba(255,255,255,0.07);
  --color-sidebar-active: #007038;

  /* Brand */
  --color-primary:       #007038;
  --color-primary-dark:  #005830;
  --color-primary-light: #e8f3ec;
  --color-primary-mid:   rgba(0,112,56,0.12);

  /* Semantic */
  --color-success:       #059669;
  --color-success-light: #d1fae5;
  --color-success-mid:   rgba(5,150,105,0.12);
  --color-warning:       #d97706;
  --color-warning-light: #fef3c7;
  --color-warning-mid:   rgba(217,119,6,0.12);
  --color-danger:        #dc2626;
  --color-danger-light:  #fee2e2;
  --color-danger-mid:    rgba(220,38,38,0.12);
  --color-info:          #0284c7;
  --color-info-light:    #e0f2fe;
  --color-info-mid:      rgba(2,132,199,0.12);

  /* Text */
  --color-text:           #0f172a;
  --color-text-secondary: #475569;
  --color-text-muted:     #94a3b8;
  --color-border:         #e2e8f0;
  --color-border-dark:    #cbd5e1;
  --color-input-bg:       #f8fafc;

  /* Shadows */
  --shadow-xs: 0 1px 2px rgba(0,0,0,0.05);
  --shadow-sm: 0 1px 3px rgba(0,0,0,0.06), 0 1px 2px rgba(0,0,0,0.04);
  --shadow-md: 0 4px 12px rgba(0,0,0,0.08), 0 2px 4px rgba(0,0,0,0.04);
  --shadow-lg: 0 12px 24px rgba(0,0,0,0.1), 0 4px 8px rgba(0,0,0,0.06);
  --shadow-xl: 0 24px 48px rgba(0,0,0,0.14), 0 8px 16px rgba(0,0,0,0.08);

  /* Radii */
  --radius-sm:  6px;
  --radius-md:  10px;
  --radius-lg:  14px;
  --radius-xl:  20px;

  /* Animation */
  --transition:    150ms ease;
  --transition-md: 250ms ease;

  /* Typography */
  --font: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
  --font-mono: 'SF Mono', 'Cascadia Code', Consolas, 'Courier New', monospace;
}

/* ===== RESET ===== */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html { font-size: 14.5px; scroll-behavior: smooth; -webkit-text-size-adjust: 100%; }
body {
  font-family: var(--font);
  background: var(--color-bg);
  color: var(--color-text);
  line-height: 1.6;
  min-height: 100vh;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}
a { color: var(--color-primary); text-decoration: none; }
a:hover { text-decoration: underline; }
input, select, textarea, button { font-family: inherit; font-size: inherit; }
img { max-width: 100%; display: block; }
ul { list-style: none; }
h1,h2,h3,h4,h5,h6 { line-height: 1.3; }

/* ===== LAYOUT ===== */
#app-wrapper { display: flex; min-height: 100vh; }

/* ===== SIDEBAR ===== */
#sidebar {
  width: var(--sidebar-width);
  min-height: 100vh;
  background: var(--color-sidebar-bg);
  position: fixed;
  left: 0; top: 0; bottom: 0;
  overflow-y: auto;
  z-index: 200;
  display: flex;
  flex-direction: column;
  transition: transform var(--transition-md);
  scrollbar-width: thin;
  scrollbar-color: rgba(255,255,255,0.08) transparent;
}
#sidebar::-webkit-scrollbar { width: 4px; }
#sidebar::-webkit-scrollbar-thumb { background: rgba(255,255,255,0.1); border-radius: 2px; }

.sidebar-logo {
  padding: 18px 18px 14px;
  border-bottom: 1px solid rgba(255,255,255,0.07);
  margin-bottom: 6px;
}
.logo-mark { display: flex; align-items: center; gap: 11px; }
.logo-icon {
  width: 42px; height: 42px;
  background: #fff;
  border-radius: 11px;
  display: flex; align-items: center; justify-content: center;
  padding: 4px;
  flex-shrink: 0;
  box-shadow: 0 4px 14px rgba(0,0,0,0.25);
}
.logo-img { width: 100%; height: 100%; object-fit: contain; display: block; }
.logo-text strong { display: block; color: #f1f5f9; font-size: 1rem; font-weight: 800; letter-spacing: -0.3px; line-height: 1.2; }
.logo-text span   { color: rgba(255,255,255,0.38); font-size: 0.7rem; letter-spacing: 0.3px; }

.sidebar-section-label {
  padding: 14px 18px 4px;
  font-size: 0.65rem;
  font-weight: 700;
  letter-spacing: 0.1em;
  color: rgba(255,255,255,0.28);
  text-transform: uppercase;
}

#sidebar nav { padding: 0 8px; }

.nav-item {
  display: flex;
  align-items: center;
  gap: 9px;
  padding: 8px 10px;
  border-radius: 8px;
  color: rgba(255,255,255,0.62);
  font-size: 0.855rem;
  font-weight: 500;
  cursor: pointer;
  transition: background var(--transition), color var(--transition);
  margin-bottom: 2px;
  border: none;
  background: none;
  width: 100%;
  text-align: left;
  user-select: none;
}
.nav-item:hover { background: var(--color-sidebar-hover); color: rgba(255,255,255,0.9); }
.nav-item.active {
  background: var(--color-sidebar-active);
  color: #fff;
  font-weight: 600;
  box-shadow: 0 2px 10px rgba(0,112,56,0.4);
}
.nav-item .nav-icon { font-size: 1rem; width: 20px; text-align: center; flex-shrink: 0; }
.portal-order-items-detail { padding: 10px 4px; background: var(--color-bg-subtle); border-radius: var(--radius-sm); }
.nav-badge {
  margin-left: auto; background: var(--color-danger); color: #fff;
  font-size: 0.7rem; font-weight: 700; line-height: 1;
  min-width: 18px; height: 18px; border-radius: 9px;
  display: flex; align-items: center; justify-content: center; padding: 0 5px;
}

.sidebar-footer {
  margin-top: auto;
  padding: 14px 10px;
  border-top: 1px solid rgba(255,255,255,0.07);
}
.sidebar-backup-btn {
  width: 100%;
  padding: 8px 12px;
  border-radius: 8px;
  border: 1px solid rgba(255,255,255,0.12);
  background: transparent;
  color: rgba(255,255,255,0.6);
  font-size: 0.8rem;
  cursor: pointer;
  transition: all var(--transition);
  display: flex; align-items: center; gap: 7px; justify-content: center;
}
.sidebar-backup-btn:hover { background: rgba(255,255,255,0.08); color: rgba(255,255,255,0.9); }
.sidebar-version { text-align: center; color: rgba(255,255,255,0.18); font-size: 0.68rem; margin-top: 7px; }
.sidebar-brand {
  text-align: center;
  color: rgba(255,255,255,0.22);
  font-size: 0.6rem;
  line-height: 1.5;
  margin-top: 6px;
  padding: 0 8px;
}
.sidebar-brand strong { color: rgba(255,255,255,0.38); font-weight: 700; }

/* ===== MAIN CONTENT ===== */
/* min-width: 0 overrides the flex-item default of "never shrink below your
   content's natural width" — without it, a wide table anywhere on the page
   would stretch this column past the viewport instead of letting its own
   .table-responsive wrapper handle the horizontal scroll. */
#main-content { margin-left: var(--sidebar-width); flex: 1; min-width: 0; min-height: 100vh; display: flex; flex-direction: column; }

/* ===== TOP HEADER ===== */
#top-header {
  background: var(--color-card);
  border-bottom: 1px solid var(--color-border);
  padding: 0 22px;
  height: var(--header-height);
  display: flex;
  align-items: center;
  justify-content: space-between;
  position: sticky;
  top: 0;
  z-index: 100;
  box-shadow: 0 1px 0 var(--color-border);
}
#page-title { font-size: 1.05rem; font-weight: 700; color: var(--color-text); display: flex; align-items: center; gap: 8px; }
.header-actions { display: flex; align-items: center; gap: 8px; }

/* ===== BACKUP REMINDER ===== */
#backup-reminder {
  background: linear-gradient(90deg, #fef9ec, #fef3c7);
  border-bottom: 1px solid #fde68a;
  padding: 9px 22px;
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 0.845rem;
  color: #92400e;
}
#backup-reminder.hidden { display: none; }
.backup-reminder-text { flex: 1; }
.backup-reminder-text strong { color: #78350f; }

/* ===== WELCOME BANNER ===== */
#welcome-banner {
  background: linear-gradient(135deg, #005830 0%, #007038 55%, #38a050 100%);
  border-radius: var(--radius-xl);
  padding: 26px 30px;
  margin: 20px 20px 24px;
  color: white;
  display: flex;
  align-items: center;
  gap: 22px;
  box-shadow: 0 8px 30px rgba(0,112,56,0.25);
}
#welcome-banner.hidden { display: none; }
.welcome-icon { font-size: 2.8rem; line-height: 1; }
.welcome-text h2 { font-size: 1.35rem; font-weight: 800; margin-bottom: 5px; }
.welcome-text p  { opacity: 0.85; margin-bottom: 14px; font-size: 0.875rem; }
.welcome-actions { display: flex; gap: 10px; flex-wrap: wrap; }

/* ===== SECTIONS ===== */
.section { display: none; flex: 1; }
.section:not(.hidden) { display: block; }
.section.hidden { display: none; }
.section-body { padding: 20px 22px 32px; }
.section-toolbar { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; margin-bottom: 16px; }

/* ===== CARDS ===== */
.card {
  background: var(--color-card);
  border-radius: var(--radius-lg);
  border: 1px solid var(--color-card-border);
  box-shadow: var(--shadow-sm);
}
.card-header {
  padding: 14px 18px;
  border-bottom: 1px solid var(--color-border);
  display: flex; align-items: center; justify-content: space-between;
}
.card-title { font-size: 0.9rem; font-weight: 700; color: var(--color-text); }
.card-body { padding: 18px; }

/* ===== KPI CARDS — QuickBooks style ===== */
.kpi-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 14px;
  margin-bottom: 20px;
}
.kpi-card {
  background: var(--color-card);
  border-radius: var(--radius-lg);
  border: 1px solid var(--color-border);
  padding: 18px 18px 16px;
  box-shadow: var(--shadow-sm);
  transition: transform var(--transition), box-shadow var(--transition);
  cursor: default;
  position: relative;
  overflow: hidden;
}
.kpi-card::before {
  content: '';
  position: absolute;
  top: 0; left: 0;
  width: 3px; height: 100%;
  border-radius: 3px 0 0 3px;
}
.kpi-card.kpi-primary::before  { background: var(--color-primary); }
.kpi-card.kpi-success::before  { background: var(--color-success); }
.kpi-card.kpi-warning::before  { background: var(--color-warning); }
.kpi-card.kpi-danger::before   { background: var(--color-danger); }
.kpi-card.kpi-info::before     { background: var(--color-info); }

.kpi-card:hover { transform: translateY(-2px); box-shadow: var(--shadow-md); }
.kpi-card-header { display: flex; align-items: flex-start; justify-content: space-between; margin-bottom: 10px; }
.kpi-icon {
  width: 38px; height: 38px;
  border-radius: var(--radius-md);
  display: flex; align-items: center; justify-content: center;
  font-size: 1.1rem;
}
.kpi-trend { display: flex; align-items: center; gap: 3px; font-size: 0.72rem; font-weight: 700; border-radius: 20px; padding: 2px 7px; }
.kpi-trend.up   { background: var(--color-success-light); color: var(--color-success); }
.kpi-trend.down { background: var(--color-danger-light);  color: var(--color-danger); }
.kpi-trend.neutral { background: #f1f5f9; color: var(--color-text-muted); }

.kpi-value {
  font-size: 1.7rem;
  font-weight: 900;
  color: var(--color-text);
  line-height: 1;
  margin-bottom: 4px;
  letter-spacing: -0.8px;
}
.kpi-label { font-size: 0.775rem; color: var(--color-text-secondary); font-weight: 500; letter-spacing: 0.01em; }

/* Section-specific KPI row widths (Stock In / Stock Out / Expenses) */
.kpi-grid-cols-3      { grid-template-columns: repeat(3, 1fr); max-width: 600px; margin-bottom: 20px; }
.kpi-grid-cols-4      { grid-template-columns: repeat(4, 1fr); max-width: 780px; margin-bottom: 20px; }
.kpi-grid-cols-3-wide { grid-template-columns: repeat(3, 1fr); max-width: 700px; margin-bottom: 20px; }

/* ===== BUTTONS ===== */
.btn {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 7px 14px;
  border-radius: var(--radius-md);
  font-size: 0.845rem;
  font-weight: 600;
  cursor: pointer;
  border: none;
  transition: all var(--transition);
  white-space: nowrap;
  line-height: 1.4;
  font-family: inherit;
  text-decoration: none;
}
.btn:disabled { opacity: 0.5; cursor: not-allowed; }
.btn-primary  { background: var(--color-primary); color: white; box-shadow: 0 1px 3px rgba(0,112,56,0.3); }
.btn-primary:hover:not(:disabled)  { background: var(--color-primary-dark); box-shadow: 0 4px 12px rgba(0,112,56,0.35); transform: translateY(-1px); }
.btn-success  { background: var(--color-success); color: white; }
.btn-success:hover:not(:disabled)  { background: #047857; transform: translateY(-1px); }
.btn-danger   { background: var(--color-danger);  color: white; }
.btn-danger:hover:not(:disabled)   { background: #b91c1c; transform: translateY(-1px); }
.btn-warning  { background: var(--color-warning); color: white; }
.btn-warning:hover:not(:disabled)  { background: #b45309; }
.btn-outline  { background: white; border: 1.5px solid var(--color-border); color: var(--color-text-secondary); }
.btn-outline:hover:not(:disabled)  { border-color: var(--color-primary); color: var(--color-primary); background: var(--color-primary-light); }
.btn-ghost    { background: transparent; color: var(--color-text-secondary); }
.btn-ghost:hover:not(:disabled)    { background: var(--color-bg); color: var(--color-text); }
.btn-sm  { padding: 5px 10px; font-size: 0.78rem; }
.btn-lg  { padding: 10px 20px; font-size: 0.95rem; }
.btn-xs  { padding: 3px 8px; font-size: 0.7rem; border-radius: 5px; }
.btn-icon {
  background: none;
  border: 1.5px solid transparent;
  border-radius: 7px;
  padding: 5px 7px;
  cursor: pointer;
  font-size: 0.82rem;
  transition: all var(--transition);
  color: var(--color-text-muted);
  line-height: 1;
  font-family: inherit;
  display: inline-flex; align-items: center;
}
.btn-icon:hover         { background: var(--color-bg); border-color: var(--color-border); color: var(--color-text); }
.btn-icon.btn-delete:hover { background: var(--color-danger-light); border-color: var(--color-danger-light); color: var(--color-danger); }
.btn-icon.btn-edit:hover   { background: var(--color-info-light);   border-color: var(--color-info-light);   color: var(--color-info); }

/* ===== FORM CONTROLS ===== */
.form-group { margin-bottom: 15px; }
.form-label { display: block; font-size: 0.8rem; font-weight: 700; color: var(--color-text); margin-bottom: 4px; }
.form-label .required { color: var(--color-danger); margin-left: 2px; }
.form-control {
  width: 100%;
  padding: 8px 11px;
  border: 1.5px solid var(--color-border);
  border-radius: var(--radius-md);
  background: var(--color-input-bg);
  color: var(--color-text);
  font-size: 0.855rem;
  transition: border-color var(--transition), box-shadow var(--transition), background var(--transition);
  outline: none;
  -webkit-appearance: none;
}
.form-control:focus { border-color: var(--color-primary); box-shadow: 0 0 0 3px rgba(0,112,56,0.1); background: white; }
.form-control::placeholder { color: var(--color-text-muted); }
select.form-control { cursor: pointer; background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 12 12'%3E%3Cpath fill='%2394a3b8' d='M6 8L1 3h10z'/%3E%3C/svg%3E"); background-repeat: no-repeat; background-position: right 10px center; padding-right: 28px; }
textarea.form-control { resize: vertical; min-height: 76px; }
.form-row { display: grid; gap: 12px; }
.form-row.cols-2 { grid-template-columns: 1fr 1fr; }
.form-row.cols-3 { grid-template-columns: 1fr 1fr 1fr; }
.form-hint { font-size: 0.73rem; color: var(--color-text-muted); margin-top: 3px; }
.form-control[readonly] { background: var(--color-bg); color: var(--color-text-muted); cursor: not-allowed; }
.form-label-sm { display: block; font-size: 0.74rem; font-weight: 700; color: var(--color-text-secondary); margin-bottom: 4px; }
.input-with-unit { display: flex; align-items: center; gap: 8px; }
.input-with-unit .form-control { flex: 1; }
.input-with-unit .input-unit { font-size: 0.8rem; font-weight: 700; color: var(--color-text-muted); flex-shrink: 0; }

/* Custom currency fields */
.custom-currency-row {
  margin-top: 10px;
  padding: 12px 14px;
  background: var(--color-bg-subtle);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
}
.custom-currency-fields {
  display: grid; grid-template-columns: 1fr auto; gap: 10px; margin-bottom: 6px;
}
.custom-currency-fields > div:last-child { width: 120px; }

.checkbox-group { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 4px; }
.checkbox-label {
  display: inline-flex; align-items: center; gap: 5px;
  font-size: 0.78rem;
  padding: 4px 10px;
  border: 1.5px solid var(--color-border);
  border-radius: 20px;
  cursor: pointer;
  transition: all var(--transition);
  color: var(--color-text-secondary);
  user-select: none;
}
.checkbox-label input { position: absolute; opacity: 0; width: 0; height: 0; }
.checkbox-label:has(input:checked) { background: var(--color-primary-light); border-color: var(--color-primary); color: var(--color-primary); font-weight: 600; }

/* ===== SEARCH ===== */
.search-wrapper { position: relative; }
.search-wrapper .search-icon { position: absolute; left: 10px; top: 50%; transform: translateY(-50%); color: var(--color-text-muted); font-size: 0.85rem; pointer-events: none; }
.search-input { padding-left: 30px !important; width: 220px; }

/* ===== MODALS ===== */
#modal-overlay {
  position: fixed; inset: 0;
  background: rgba(15,23,42,0.55);
  backdrop-filter: blur(4px);
  z-index: 500;
  display: flex; align-items: center; justify-content: center;
  padding: 16px;
}
#modal-overlay.hidden { display: none; }
.modal {
  background: white;
  border-radius: var(--radius-xl);
  box-shadow: var(--shadow-xl);
  width: 100%;
  max-width: 560px;
  max-height: 92vh;
  overflow-y: auto;
  animation: modal-in 200ms cubic-bezier(0.34, 1.56, 0.64, 1);
}
.modal.modal-wide { max-width: 700px; }
.modal.modal-xl { max-width: 820px; }
.modal.hidden { display: none; }

/* ===== MULTI-PRODUCT STOCK OUT LINES ===== */
.stockout-lines-card { margin: 16px 0 14px; border: 1px solid var(--color-border); border-radius: var(--radius-md); overflow: hidden; }
.stockout-lines-header,
.stockout-line-row {
  display: grid;
  grid-template-columns: 1fr 70px 100px 100px 32px;
  gap: 8px;
  align-items: center;
  padding: 8px 12px;
}
.stockout-lines-header {
  background: #f8fafc;
  font-size: 0.7rem; font-weight: 700; text-transform: uppercase; letter-spacing: 0.05em;
  color: var(--color-text-secondary);
  border-bottom: 1px solid var(--color-border);
}
.stockout-line-row { border-bottom: 1px solid #f0f4f8; }
.stockout-line-row:last-child { border-bottom: none; }
.stockout-line-row .form-control { padding: 6px 8px; font-size: 0.82rem; }
.line-subtotal { font-weight: 700; font-size: 0.85rem; text-align: right; }
#btn-add-order-line { margin: 10px 12px 12px; }

.stockout-order-total {
  display: flex; align-items: center; justify-content: space-between;
  padding: 12px 14px; background: var(--color-bg-subtle); border-radius: var(--radius-md);
  font-size: 0.95rem; font-weight: 700; margin-bottom: 14px;
}
.stockout-order-total strong { font-size: 1.2rem; color: var(--color-primary); }

@media (max-width: 640px) {
  .stockout-lines-header { display: none; }
  .stockout-line-row { grid-template-columns: 1fr 1fr; row-gap: 6px; }
  .line-subtotal { grid-column: 1 / -1; text-align: left; }
  /* Still readable and zoom-free even though this widget keeps a compact
     spreadsheet-style row instead of full-height labeled fields */
  .stockout-line-row .form-control { font-size: 16px; min-height: 40px; }
}

/* ===== STOCK OUT ORDER GROUPING (table) ===== */
.order-toggle-icon { display: inline-block; width: 14px; color: var(--color-text-muted); font-size: 0.7rem; }
tr.stockout-order-line td:first-child { padding-left: 26px; }
@keyframes modal-in {
  from { opacity: 0; transform: translateY(-16px) scale(0.96); }
  to   { opacity: 1; transform: translateY(0) scale(1); }
}
.modal-header {
  padding: 18px 22px 14px;
  border-bottom: 1px solid var(--color-border);
  display: flex; align-items: center; justify-content: space-between;
  background: var(--color-bg-subtle);
  border-radius: var(--radius-xl) var(--radius-xl) 0 0;
}
.modal-title { font-size: 1rem; font-weight: 800; }
.modal-close { background: none; border: none; cursor: pointer; font-size: 1.1rem; color: var(--color-text-muted); padding: 4px; border-radius: 6px; line-height: 1; transition: all var(--transition); }
.modal-close:hover { background: var(--color-danger-light); color: var(--color-danger); }
.modal-body { padding: 18px 22px; }
.modal-footer { padding: 13px 22px; border-top: 1px solid var(--color-border); display: flex; align-items: center; justify-content: flex-end; gap: 8px; background: var(--color-bg-subtle); border-radius: 0 0 var(--radius-xl) var(--radius-xl); }

/* ===== BADGES ===== */
.badge {
  display: inline-flex; align-items: center; gap: 3px;
  padding: 2px 8px;
  border-radius: 20px;
  font-size: 0.71rem;
  font-weight: 700;
  white-space: nowrap;
  letter-spacing: 0.01em;
}
.badge-success   { background: var(--color-success-light); color: #065f46; }
.badge-warning   { background: var(--color-warning-light); color: #92400e; }
.badge-danger    { background: var(--color-danger-light);  color: #991b1b; }
.badge-primary   { background: var(--color-primary-light); color: #005830; }
.badge-secondary { background: #f1f5f9; color: #475569; }
.badge-info      { background: var(--color-info-light); color: #075985; }

/* ===== TOAST ===== */
#toast-container {
  position: fixed; bottom: 20px; right: 20px;
  z-index: 2000;
  display: flex; flex-direction: column; gap: 8px;
  max-width: 340px;
}
.toast {
  display: flex; align-items: flex-start; gap: 10px;
  padding: 12px 14px;
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-lg);
  font-size: 0.845rem;
  opacity: 0;
  transform: translateX(20px);
  transition: all 260ms ease;
  background: white;
  border: 1px solid var(--color-border);
}
.toast.show { opacity: 1; transform: translateX(0); }
.toast-success { border-left: 3px solid var(--color-success); }
.toast-error   { border-left: 3px solid var(--color-danger); }
.toast-warning { border-left: 3px solid var(--color-warning); }
.toast-info    { border-left: 3px solid var(--color-info); }
.toast-message { flex: 1; color: var(--color-text); line-height: 1.4; }
.toast-close   { background: none; border: none; cursor: pointer; color: var(--color-text-muted); font-size: 0.8rem; padding: 0; line-height: 1; flex-shrink: 0; }

/* ===== AUTH SCREENS ===== */
.auth-screen {
  position: fixed; inset: 0; z-index: 3000;
  display: flex; align-items: center; justify-content: center;
  background: linear-gradient(135deg, #005830 0%, #007038 55%, #38a050 100%);
  padding: 16px;
}
.auth-screen.hidden { display: none; }
.auth-spinner {
  width: 42px; height: 42px; border-radius: 50%;
  border: 4px solid rgba(255,255,255,0.3); border-top-color: #fff;
  animation: auth-spin 0.8s linear infinite;
}
@keyframes auth-spin { to { transform: rotate(360deg); } }

.login-card {
  background: white; border-radius: var(--radius-xl); box-shadow: var(--shadow-xl);
  padding: 40px 36px; width: 100%; max-width: 380px; text-align: center;
}
.login-logo { font-size: 2.6rem; margin-bottom: 8px; }
.login-logo-img { display: block; width: 150px; max-width: 60%; height: auto; margin: 0 auto 14px; }
.sr-only { position: absolute; width: 1px; height: 1px; margin: -1px; padding: 0; overflow: hidden; clip: rect(0,0,0,0); white-space: nowrap; border: 0; }
.login-card h1 { font-size: 1.3rem; font-weight: 800; margin-bottom: 6px; }
.login-sub { font-size: 0.85rem; color: var(--color-text-secondary); margin-bottom: 24px; }
.login-google-btn { width: 100%; justify-content: center; }
.login-error { margin-top: 14px; font-size: 0.8rem; color: var(--color-danger); }
.login-error.hidden { display: none; }

/* ===== SIDEBAR USER / LOGOUT ===== */
.sidebar-user { padding: 4px 6px 10px; }
.sidebar-user-email {
  display: block; font-size: 0.68rem; color: rgba(255,255,255,0.4);
  text-align: center; margin-bottom: 6px;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.sidebar-logout-btn {
  width: 100%; padding: 8px 12px; border-radius: 8px;
  border: 1px solid rgba(255,255,255,0.12); background: transparent;
  color: rgba(255,255,255,0.6); font-size: 0.8rem; cursor: pointer;
  display: flex; align-items: center; gap: 7px; justify-content: center;
  transition: all var(--transition); font-family: inherit;
}
.sidebar-logout-btn:hover { background: rgba(220,38,38,0.15); color: #fca5a5; }

/* ===== HAMBURGER / MOBILE ===== */
#hamburger-btn { display: none; background: none; border: none; cursor: pointer; font-size: 1.3rem; color: var(--color-text); padding: 4px; line-height: 1; }
#sidebar-overlay { display: none; position: fixed; inset: 0; background: rgba(0,0,0,0.5); z-index: 150; }

/* ===== MOBILE BOTTOM NAVIGATION ===== */
#mobile-bottom-nav {
  display: none;
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 180;
  background: var(--color-sidebar-bg);
  border-top: 1px solid rgba(255,255,255,0.08);
  padding: 4px 4px calc(4px + env(safe-area-inset-bottom));
  box-shadow: 0 -4px 16px rgba(0,0,0,0.18);
}
.mobile-nav-item {
  flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 2px; min-height: 56px; padding: 6px 2px;
  background: none; border: none; cursor: pointer;
  color: rgba(255,255,255,0.55); font-family: inherit;
  border-radius: 10px; transition: background var(--transition), color var(--transition);
}
.mobile-nav-icon { font-size: 1.35rem; line-height: 1; }
.mobile-nav-label { font-size: 0.62rem; font-weight: 600; letter-spacing: 0.01em; white-space: nowrap; }
.mobile-nav-item.active { color: #fff; background: rgba(0,112,56,0.35); }
.mobile-nav-item:active { background: rgba(255,255,255,0.1); }

/* ===== MOBILE FLOATING ACTION BUTTON ===== */
.mobile-fab {
  display: none;
  position: fixed; right: 16px; z-index: 190;
  width: 56px; height: 56px; border-radius: 50%;
  align-items: center; justify-content: center;
  background: var(--color-primary); color: white;
  font-size: 1.8rem; font-weight: 400; line-height: 1;
  border: none; cursor: pointer; font-family: inherit;
  box-shadow: 0 6px 20px rgba(0,112,56,0.45);
  transition: transform var(--transition);
}
.mobile-fab:active { transform: scale(0.94); }
.mobile-fab.hidden { display: none !important; }

/* ===== EMPTY STATE ===== */
.empty-state { text-align: center; padding: 56px 24px; color: var(--color-text-secondary); }
.empty-state .empty-icon { font-size: 3.2rem; margin-bottom: 12px; }
.empty-state h3 { font-size: 1.05rem; font-weight: 700; color: var(--color-text); margin-bottom: 8px; }
.empty-state p  { font-size: 0.855rem; max-width: 300px; margin: 0 auto 16px; color: var(--color-text-secondary); }
.empty-state-small { text-align: center; padding: 16px; color: var(--color-text-muted); font-size: 0.84rem; }

/* ===== FILTER TABS ===== */
.filter-tabs { display: flex; gap: 3px; background: #f1f5f9; padding: 3px; border-radius: var(--radius-md); }
.filter-tab {
  padding: 5px 12px; border: none; border-radius: 7px;
  background: none; font-size: 0.78rem; font-weight: 600;
  cursor: pointer; color: var(--color-text-secondary); transition: all var(--transition);
  font-family: inherit;
}
.filter-tab.active  { background: white; color: var(--color-text); box-shadow: var(--shadow-xs); }
.filter-tab:hover:not(.active) { color: var(--color-text); }

/* ===== SUB VIEWS ===== */
.sub-view { display: none; }
.sub-view:not(.hidden) { display: block; }
.sub-view.hidden { display: none; }

/* ===== SECTION HEADER ===== */
.section-head {
  display: flex; align-items: flex-start; justify-content: space-between; flex-wrap: wrap; gap: 12px;
  margin-bottom: 18px;
}
.section-head h2 { font-size: 1.1rem; font-weight: 800; color: var(--color-text); }
.section-head-left { display: flex; flex-direction: column; gap: 2px; }
.section-desc { font-size: 0.8rem; color: var(--color-text-secondary); }
.section-head-right { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }

/* ===== STAT PILL ===== */
.stat-pill {
  display: inline-flex; align-items: center; gap: 5px;
  padding: 3px 10px; border-radius: 20px;
  font-size: 0.77rem; font-weight: 700;
  background: #f1f5f9; color: var(--color-text-secondary);
}
.stat-pill.green { background: var(--color-success-light); color: #065f46; }
.stat-pill.amber { background: var(--color-warning-light); color: #92400e; }
.stat-pill.red   { background: var(--color-danger-light);  color: #991b1b; }

/* ===== LINK ===== */
.link { color: var(--color-primary); font-size: 0.845rem; cursor: pointer; }
.link:hover { text-decoration: underline; }

/* ===== MARGIN PREVIEW ===== */
#margin-preview {
  background: var(--color-bg-subtle);
  border: 1px dashed var(--color-border-dark);
  border-radius: var(--radius-sm);
  padding: 6px 10px;
  font-size: 0.79rem;
  color: var(--color-text-secondary);
  margin-top: 4px;
}

/* ===== SCROLLBAR ===== */
::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: #cbd5e1; border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: #94a3b8; }

/* ===== LOADING SKELETON ===== */
@keyframes skeleton-pulse { 0%,100%{opacity:1} 50%{opacity:0.4} }
.skeleton { background: #e2e8f0; border-radius: 4px; animation: skeleton-pulse 1.5s ease infinite; }

/* ===== PRINT ===== */
@media print {
  #sidebar, #top-header, #toast-container, .table-actions, .btn:not(.print-visible) { display: none !important; }
  #main-content { margin-left: 0; }
  .card { box-shadow: none; border: 1px solid #ddd; }
}

/* ===== TABLET ===== */
@media (max-width: 1100px) {
  .kpi-grid { grid-template-columns: repeat(4, 1fr); }
}
@media (max-width: 860px) {
  .kpi-grid { grid-template-columns: repeat(2, 1fr); }
}

/* ===== MOBILE ===== */
@media (max-width: 768px) {
  #sidebar { transform: translateX(-100%); }
  #sidebar.open { transform: translateX(0); box-shadow: var(--shadow-xl); }
  #sidebar-overlay.open { display: block; }
  #main-content { margin-left: 0; }
  #hamburger-btn { display: flex; align-items: center; justify-content: center; min-width: 48px; min-height: 48px; }
  .kpi-grid { grid-template-columns: repeat(2, 1fr); }
  .form-row.cols-2, .form-row.cols-3 { grid-template-columns: 1fr; }
  .section-body { padding: 14px 16px 24px; }
  .kpi-grid-cols-3, .kpi-grid-cols-4, .kpi-grid-cols-3-wide { grid-template-columns: repeat(2, 1fr); }

  /* Header can wrap to a second line instead of overflowing when title + action
     buttons don't fit a narrow viewport */
  #top-header { padding: 10px 14px; height: auto; min-height: var(--header-height); flex-wrap: wrap; row-gap: 8px; }
  .header-actions { flex-wrap: wrap; }
  .header-actions .btn { padding: 8px 12px; font-size: 0.8rem; }

  /* Touch targets: no :hover on touch, so interactive controls need to be
     comfortably tappable (~48px) instead of sized for a mouse pointer */
  .btn, .btn-sm { min-height: 48px; padding: 11px 16px; }
  .btn-xs { min-height: 40px; padding: 8px 12px; }
  .btn-icon { min-width: 48px; min-height: 48px; padding: 10px; justify-content: center; }
  .nav-item { min-height: 48px; }
  .filter-tab { min-height: 48px; }
  .modal-close { min-width: 48px; min-height: 48px; justify-content: center; }
  .sidebar-logout-btn { min-height: 48px; }
  .login-google-btn { min-height: 48px; }

  /* Modals take the full width and dock to the bottom on mobile. `dvh` (where
     supported) tracks the visual viewport as the on-screen keyboard opens, so
     the sheet doesn't get taller than what's actually visible; browsers that
     don't understand `dvh` simply ignore that line and keep the `vh` value. */
  #modal-overlay { padding: 0; align-items: flex-end; }
  .modal, .modal.modal-wide, .modal.modal-xl {
    max-width: 100%; width: 100%;
    max-height: 90vh;
    max-height: 90dvh;
    border-radius: var(--radius-xl) var(--radius-xl) 0 0;
  }
  .modal-header, .modal-footer { padding: 14px 16px; }
  .modal-body { padding: 16px; }

  /* Bigger, easier-to-hit form fields; 16px text stops iOS Safari from
     auto-zooming the page when a field is focused */
  .form-control { min-height: 48px; font-size: 16px; }
  select.form-control { padding-top: 10px; padding-bottom: 10px; }
  textarea.form-control { min-height: 96px; }
  .form-group { margin-bottom: 18px; }

  /* Mobile bottom navigation replaces the old two-item bottom tab bar */
  #mobile-bottom-nav { display: flex; }
  .mobile-fab { display: flex; bottom: calc(72px + env(safe-area-inset-bottom)); }
  .section-body { padding-bottom: calc(76px + env(safe-area-inset-bottom)); }

  /* The FAB takes over the section header's primary "+ Add" button so the
     same action isn't offered twice */
  .section-head-right .btn-primary { display: none; }
}
@media (max-width: 480px) {
  .kpi-grid { grid-template-columns: 1fr; }
  .kpi-value { font-size: 1.35rem; }
  #toast-container { left: 12px; right: 12px; bottom: 12px; max-width: none; }
  .kpi-grid-cols-3, .kpi-grid-cols-4, .kpi-grid-cols-3-wide { grid-template-columns: 1fr; }
}
@media (max-width: 380px) {
  .kpi-grid { grid-template-columns: 1fr; }
}
