/* =========================================
   MERON ADMIN DASHBOARD — style.css
   Modern, mobile-first design
   ========================================= */

:root {
  --bg:           #0f1117;
  --surface:      #1a1d27;
  --surface-2:    #222636;
  --surface-3:    #2a2e42;
  --border:       #2e3350;
  --border-light: #3a3f5c;
  --text:         #e8eaf0;
  --text-muted:   #8b91b0;
  --text-faint:   #555d80;

  --primary:      #f5c842;
  --primary-dark: #d9ae2a;
  --primary-glow: rgba(245,200,66,.18);

  --green:        #22d67a;
  --green-bg:     rgba(34,214,122,.12);
  --red:          #ff4d6d;
  --red-bg:       rgba(255,77,109,.12);
  --amber:        #f5a623;
  --amber-bg:     rgba(245,166,35,.1);

  --radius-sm:    6px;
  --radius:       12px;
  --radius-lg:    18px;

  --shadow:       0 2px 12px rgba(0,0,0,.35);
  --shadow-lg:    0 8px 32px rgba(0,0,0,.45);

  --topbar-h:     58px;
  --font:         'DM Sans', system-ui, sans-serif;
  --mono:         'JetBrains Mono', monospace;
}

*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

html { scroll-behavior: smooth; }

body {
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  line-height: 1.5;
  min-height: 100vh;
  -webkit-font-smoothing: antialiased;
}

/* ── UTILITIES ─────────────────────────────── */
.hidden { display: none !important; }

/* ── BUTTONS ────────────────────────────────── */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 9px 18px;
  font-family: var(--font);
  font-size: 13.5px;
  font-weight: 600;
  border: none;
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: background .15s, transform .1s, opacity .15s, box-shadow .15s;
  white-space: nowrap;
  line-height: 1;
}
.btn:active { transform: scale(.96); }
.btn:disabled, .btn.busy {
  opacity: .55;
  cursor: not-allowed;
  transform: none;
}

.btn-primary {
  background: var(--primary);
  color: #1a1400;
  box-shadow: 0 0 0 0 var(--primary-glow);
}
.btn-primary:hover:not(:disabled) {
  background: var(--primary-dark);
  box-shadow: 0 0 20px var(--primary-glow);
}

.btn-secondary {
  background: var(--surface-3);
  color: var(--text);
  border: 1px solid var(--border-light);
}
.btn-secondary:hover:not(:disabled) { background: var(--border); }

.btn-ghost {
  background: transparent;
  color: var(--text-muted);
  border: 1px solid var(--border);
}
.btn-ghost:hover:not(:disabled) {
  background: var(--surface-3);
  color: var(--text);
  border-color: var(--border-light);
}

.btn-danger-ghost {
  background: transparent;
  color: var(--red);
  border: 1px solid rgba(255,77,109,.3);
}
.btn-danger-ghost:hover:not(:disabled) {
  background: var(--red-bg);
  border-color: var(--red);
}

.btn-sm { padding: 7px 13px; font-size: 12.5px; }
.btn-full { width: 100%; justify-content: center; padding: 13px; font-size: 15px; }

/* ── INPUTS ─────────────────────────────────── */
.input-text,
.input-select,
input[type="text"],
input[type="date"],
input[type="month"],
select, textarea {
  width: 100%;
  background: var(--surface-3);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text);
  font-family: var(--font);
  font-size: 14px;
  padding: 10px 13px;
  outline: none;
  transition: border-color .15s, box-shadow .15s;
  appearance: none;
  -webkit-appearance: none;
}
.input-text:focus,
.input-select:focus,
input:focus, select:focus, textarea:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px var(--primary-glow);
}
input::placeholder { color: var(--text-faint); }
select {
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='8' viewBox='0 0 12 8'%3E%3Cpath d='M1 1l5 5 5-5' stroke='%238b91b0' stroke-width='1.5' fill='none' stroke-linecap='round'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 12px center;
  padding-right: 34px;
}

.input-select--sm { padding: 6px 32px 6px 10px; font-size: 13px; }
.input-group { margin-bottom: 20px; }
.input-group label {
  display: block;
  font-size: 13px;
  font-weight: 600;
  color: var(--text-muted);
  margin-bottom: 8px;
  letter-spacing: .3px;
  text-transform: uppercase;
}

/* ── LOGIN SCREEN ────────────────────────────── */
.login-screen {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  position: relative;
  overflow: hidden;
}

.login-bg-shapes {
  position: absolute;
  inset: 0;
  pointer-events: none;
}
.shape {
  position: absolute;
  border-radius: 50%;
  filter: blur(80px);
  opacity: .25;
}
.shape-1 {
  width: 500px; height: 500px;
  background: var(--primary);
  top: -150px; left: -150px;
}
.shape-2 {
  width: 400px; height: 400px;
  background: #7c5cbf;
  bottom: -120px; right: -100px;
}
.shape-3 {
  width: 300px; height: 300px;
  background: var(--green);
  top: 40%; left: 55%;
}

.login-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 40px 36px;
  width: 100%;
  max-width: 420px;
  box-shadow: var(--shadow-lg);
  position: relative;
  z-index: 1;
}

.login-logo {
  display: flex;
  align-items: center;
  gap: 14px;
  margin-bottom: 28px;
}
.logo-icon {
  width: 46px; height: 46px;
  background: var(--primary);
  border-radius: var(--radius-sm);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 22px;
  font-weight: 800;
  color: #1a1400;
  flex-shrink: 0;
  box-shadow: 0 4px 16px var(--primary-glow);
}
.logo-icon--small { width: 32px; height: 32px; font-size: 15px; border-radius: 6px; }
.brand-name { font-size: 20px; font-weight: 700; color: var(--text); }
.brand-sub {
  display: block;
  font-size: 12px;
  color: var(--text-muted);
  font-weight: 400;
}

.login-hint {
  font-size: 14px;
  color: var(--text-muted);
  margin-bottom: 28px;
}

.status-msg {
  font-size: 13px;
  min-height: 20px;
  margin-bottom: 16px;
  font-weight: 500;
  border-radius: var(--radius-sm);
  padding: 0;
  transition: padding .2s;
}
.status-msg:not(:empty) { padding: 10px 14px; }
.status-msg.err { background: var(--red-bg); color: var(--red); }
.status-msg.ok  { background: var(--green-bg); color: var(--green); }

/* ── TOPBAR ──────────────────────────────────── */
.topbar {
  position: sticky;
  top: 0;
  z-index: 100;
  height: var(--topbar-h);
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 0 20px;
  backdrop-filter: blur(12px);
}
.topbar-left { display: flex; align-items: center; gap: 10px; }
.topbar-logo { display: flex; align-items: center; gap: 10px; }
.topbar-center { flex: 1; text-align: center; }
.welcome-text { font-size: 14px; color: var(--text-muted); }
.welcome-text strong { color: var(--text); font-weight: 600; }
.topbar-right {
  display: flex;
  align-items: center;
  gap: 8px;
}

/* MOBILE ACTION BAR (replaces topbar buttons on small screens) */
.mobile-action-bar {
  display: none;
  gap: 6px;
  padding: 10px 16px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  scrollbar-width: none;
}
.mobile-action-bar::-webkit-scrollbar { display: none; }
.mobile-action-bar .btn { flex-shrink: 0; }

/* ── MAIN LAYOUT ─────────────────────────────── */
.dashboard-main {
  max-width: 1600px;
  margin: 0 auto;
  padding: 24px 20px 60px;
  display: flex;
  flex-direction: column;
  gap: 20px;
}

/* ── STATS ───────────────────────────────────── */
.stats-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 16px;
}
.stat-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
  display: flex;
  align-items: flex-start;
  gap: 16px;
  box-shadow: var(--shadow);
  transition: border-color .2s;
}
.stat-card:hover { border-color: var(--border-light); }
.stat-icon { font-size: 28px; line-height: 1; margin-top: 2px; }
.stat-content { flex: 1; min-width: 0; }
.stat-label {
  font-size: 11.5px;
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: .5px;
  margin-bottom: 8px;
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}
.stat-value {
  font-size: 30px;
  font-weight: 700;
  color: var(--text);
  font-variant-numeric: tabular-nums;
  line-height: 1;
}
.stat-value--sm {
  font-size: 15px;
  font-weight: 600;
  line-height: 1.6;
}
.stat-month-select {
  padding: 3px 24px 3px 8px;
  font-size: 11px;
  height: auto;
}

/* ── PANELS ──────────────────────────────────── */
.panel {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  overflow: hidden;
}
.panel-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 18px 22px;
  border-bottom: 1px solid var(--border);
  flex-wrap: wrap;
}
.panel-title {
  font-size: 15px;
  font-weight: 700;
  color: var(--text);
}
.panel-actions {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}

/* ── FILTERS ─────────────────────────────────── */
.filters-grid {
  padding: 18px 22px;
  display: grid;
  /* Desktop: search, location, dept, payment, currency, date-range */
  grid-template-columns: 2fr 1fr 1fr 1fr 1fr 1.8fr;
  gap: 14px;
  align-items: end;
}
.filter-item--full     { /* desktop: first column, normal flow */ }
.filter-item--daterange { /* desktop: last column, normal flow */ }

/* Date range inner layout — always side by side */
.date-range-group {
  display: flex;
  align-items: flex-end;
  gap: 8px;
}
.date-range-part { flex: 1; min-width: 0; }
.date-range-sep {
  color: var(--text-faint);
  font-size: 14px;
  padding-bottom: 11px;
  flex-shrink: 0;
}

/* Date range inner layout */
.date-range-group {
  display: flex;
  align-items: flex-end;
  gap: 10px;
}
.date-range-part {
  flex: 1;
}
.date-range-sep {
  color: var(--text-faint);
  font-size: 16px;
  padding-bottom: 10px;
  flex-shrink: 0;
}

.filter-item label {
  display: block;
  font-size: 11.5px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .4px;
  color: var(--text-muted);
  margin-bottom: 7px;
}

/* ── TABLE ───────────────────────────────────── */
.table-wrap {
  width: 100%;
  /* Mobile: no overflow clipping — table scrolls with page naturally */
  overflow-x: visible;
}
.data-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
  white-space: nowrap;
}
.data-table th {
  background: var(--surface-2);
  color: var(--text-muted);
  font-size: 11.5px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .4px;
  padding: 11px 14px;
  text-align: left;
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
}
.data-table td {
  padding: 11px 14px;
  border-bottom: 1px solid var(--border);
  color: var(--text);
  vertical-align: middle;
  font-family: var(--font);
  font-size: 13.5px;
}
.data-table tr:last-child td { border-bottom: none; }
.data-table tbody tr:hover td { background: var(--surface-2); }

th.sortable { cursor: pointer; user-select: none; }
th.sortable:hover { color: var(--primary); }

.empty-state {
  text-align: center;
  color: var(--text-faint);
  padding: 40px !important;
  font-size: 14px;
}

/* supplier scroll */
.supplierCell { max-width: 160px; }
.supplierScroll {
  max-width: 160px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* ── PAYMENT BADGES ──────────────────────────── */
.payBadge {
  display: inline-block;
  padding: 3px 10px;
  border-radius: 20px;
  font-size: 11.5px;
  font-weight: 600;
  letter-spacing: .2px;
  background: var(--surface-3);
  color: var(--text-muted);
}
.payBadge.green { background: var(--green-bg); color: var(--green); }
.payBadge.red   { background: var(--red-bg); color: var(--red); }
.payBadge.clickable { cursor: pointer; }
.payBadge.clickable:hover { filter: brightness(1.2); }
.paymentCell { display: flex; flex-direction: column; gap: 3px; }
.paymentDate { font-size: 11px; color: var(--text-faint); font-family: var(--font); }

/* ── CURRENCY BADGE ──────────────────────────── */
.badge {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 4px;
  font-size: 11px;
  font-weight: 700;
  font-family: var(--font);
  background: var(--surface-3);
  color: var(--primary);
  border: 1px solid var(--border);
  letter-spacing: .3px;
}

/* ── COPYABLE CELLS ──────────────────────────── */
.copyableCell {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  cursor: pointer;
  border-radius: var(--radius-sm);
  padding: 2px 6px;
  transition: background .15s;
}
.copyableCell:hover { background: var(--surface-3); }
.copyHint {
  font-size: 10px;
  color: var(--text-faint);
  opacity: 0;
  transition: opacity .15s;
}
.copyableCell:hover .copyHint { opacity: 1; }
.copyableStrong { font-weight: 500; font-family: var(--font); font-size: 13px; letter-spacing: 0; }

/* ── FILE LINK ───────────────────────────────── */
.fileLink {
  color: var(--primary);
  text-decoration: none;
  font-size: 12.5px;
  font-weight: 500;
}
.fileLink:hover { text-decoration: underline; }
.muted { color: var(--text-faint); font-size: 12px; }

/* ── ROW ACTIONS ─────────────────────────────── */
.rowActions { display: flex; gap: 6px; }
.col-actions { width: 120px; }

/* ── EDIT INPUTS IN TABLE ────────────────────── */
.editInput, .editSelect {
  width: 100%;
  background: var(--surface-3);
  border: 1px solid var(--primary);
  border-radius: var(--radius-sm);
  color: var(--text);
  font-family: var(--font);
  font-size: 13px;
  padding: 6px 9px;
  outline: none;
  min-width: 90px;
}
.editSelect {
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='8' viewBox='0 0 12 8'%3E%3Cpath d='M1 1l5 5 5-5' stroke='%238b91b0' stroke-width='1.5' fill='none' stroke-linecap='round'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 8px center;
  padding-right: 26px;
  appearance: none;
}

/* ── SUPPLIER SUMMARY TABLE EXTRAS ──────────── */
.summaryDiffUp   { color: var(--green); font-weight: 600; }
.summaryDiffDown { color: var(--red); font-weight: 600; }
.summaryDiffSame { color: var(--text-muted); }
.summaryRowUp td { background: rgba(34,214,122,.04); }
.summaryRowDown td { background: rgba(255,77,109,.04); }
.summaryTagNew {
  display: inline-block;
  margin-left: 6px;
  padding: 1px 6px;
  border-radius: 4px;
  font-size: 10px;
  font-weight: 700;
  background: var(--amber-bg);
  color: var(--amber);
  letter-spacing: .3px;
  text-transform: uppercase;
}

/* ── PAGINATION ──────────────────────────────── */
.pagination-controls {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}
.page-size-wrap {
  display: flex;
  align-items: center;
  gap: 7px;
  font-size: 12.5px;
  color: var(--text-muted);
}
.pagination-info {
  font-size: 13px;
  color: var(--text-muted);
  white-space: nowrap;
  font-variant-numeric: tabular-nums;
}
.pagination-footer {
  display: none;
  align-items: center;
  justify-content: center;
  gap: 12px;
  padding: 14px 20px;
  border-top: 1px solid var(--border);
}

/* ── TOAST ───────────────────────────────────── */
.toast {
  position: fixed;
  bottom: 28px;
  left: 50%;
  transform: translateX(-50%) translateY(20px);
  background: var(--surface-2);
  border: 1px solid var(--border-light);
  color: var(--text);
  padding: 12px 24px;
  border-radius: 40px;
  font-size: 14px;
  font-weight: 500;
  opacity: 0;
  pointer-events: none;
  transition: opacity .25s, transform .25s;
  box-shadow: var(--shadow-lg);
  z-index: 9999;
  white-space: nowrap;
  max-width: calc(100vw - 40px);
  text-align: center;
}
.toast.show {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}

/* =========================================
   RESPONSIVE — MOBILE FIRST
   ========================================= */

@media (max-width: 1200px) {
  .stats-grid { grid-template-columns: repeat(2, 1fr); }
  .filters-grid {
    grid-template-columns: 2fr 1fr 1fr 1fr 1.6fr;
  }
}

@media (max-width: 900px) {
  .topbar-right { display: none; }
  .mobile-action-bar { display: flex; }

  .stats-grid { grid-template-columns: repeat(2, 1fr); gap: 12px; }

  .filters-grid {
    grid-template-columns: 1fr 1fr;
    padding: 14px 16px;
    gap: 12px;
  }
  .filter-item--full      { grid-column: 1 / -1; }
  .filter-item--daterange { grid-column: 1 / -1; }

  .dashboard-main { padding: 16px 12px 60px; gap: 16px; }
  .panel-header { padding: 14px 16px; }
  .panel-title { font-size: 14px; }
}

@media (max-width: 640px) {
  .stats-grid { grid-template-columns: 1fr 1fr; gap: 10px; }
  .stat-card { padding: 14px; gap: 10px; }
  .stat-icon { font-size: 22px; }
  .stat-value { font-size: 24px; }
  .stat-value--sm { font-size: 13px; }

  .filters-grid {
    grid-template-columns: 1fr 1fr;
    gap: 10px;
    padding: 12px 14px;
  }
  .filter-item--full      { grid-column: 1 / -1; }
  .filter-item--daterange { grid-column: 1 / -1; }

  .pagination-controls {
    display: none;
  }
  .pagination-footer {
    display: flex;
  }

  .topbar-center { display: none; }
  .brand-name { display: none; }

  .login-card { padding: 28px 22px; }
  .dashboard-main { padding: 12px 10px 60px; }
  .panel-header { flex-direction: column; align-items: flex-start; gap: 10px; }
  .panel-actions { width: 100%; }

  /* Mobile table: allow horizontal scroll, set min widths */
  .invoices-table { font-size: 12px; }
  .data-table th, .data-table td { padding: 9px 10px; }
  .col-actions { width: 100px; }
  .rowActions { flex-direction: column; gap: 4px; }
  .rowActions .btn { padding: 5px 9px; font-size: 11px; }
}

@media (max-width: 380px) {
  .stats-grid { grid-template-columns: 1fr; }
  .mobile-action-bar { gap: 4px; padding: 8px 12px; }
}

/* ── PRINT ───────────────────────────────────── */
@media print {
  .topbar, .mobile-action-bar, .panel-header .btn,
  .pagination-controls, .pagination-footer,
  .editBtn, .deleteBtn, .saveBtn, .cancelBtn { display: none !important; }
  body { background: #fff; color: #000; }
  .panel { box-shadow: none; border: 1px solid #ccc; }
  .data-table th { background: #f5f5f5; color: #333; }
  .data-table td { color: #222; }
}


/* =========================================
   LIGHT THEME — override CSS variables on body
   Toggled by adding class "light" to <body>
   ========================================= */
body.light {
  --bg:           #f0f2f8;
  --surface:      #ffffff;
  --surface-2:    #f5f7fc;
  --surface-3:    #eceef7;
  --border:       #dde0ee;
  --border-light: #c8cce0;
  --text:         #1a1d2e;
  --text-muted:   #525878;
  --text-faint:   #9098b8;

  --primary:      #e6a800;
  --primary-dark: #c99200;
  --primary-glow: rgba(230,168,0,.2);

  --green:        #16a05a;
  --green-bg:     rgba(22,160,90,.12);
  --red:          #d42b50;
  --red-bg:       rgba(212,43,80,.1);
  --amber:        #cc7700;
  --amber-bg:     rgba(204,119,0,.1);

  --shadow:       0 1px 6px rgba(0,0,0,.07);
  --shadow-lg:    0 6px 24px rgba(0,0,0,.11);

  background: var(--bg);
  color: var(--text);
}

/* These need explicit overrides because they use non-variable colors */
body.light .login-bg-shapes .shape-1 { background: #f5c842; opacity: .12; }
body.light .login-bg-shapes .shape-2 { background: #9b7fd4; opacity: .10; }
body.light .login-bg-shapes .shape-3 { background: #22d67a; opacity: .08; }

body.light .toast {
  background: #1e2235;
  border-color: #3a3f5c;
  color: #e8eaf0;
}

/* Dark theme toggle icon shows sun in light mode */
body.light #themeToggleBtn,
body.light #themeToggleBtn2 { color: var(--text-muted); }

/* Login screen theme button */
.theme-btn-login {
  position: absolute;
  top: 20px;
  right: 20px;
  z-index: 10;
  font-size: 18px;
  border: none;
  background: rgba(255,255,255,.08);
  backdrop-filter: blur(8px);
  border-radius: 50%;
  width: 42px;
  height: 42px;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0;
  cursor: pointer;
  transition: background .2s, transform .15s;
}
.theme-btn-login:hover { background: rgba(255,255,255,.15); transform: scale(1.1); }
body.light .theme-btn-login { background: rgba(0,0,0,.06); }
body.light .theme-btn-login:hover { background: rgba(0,0,0,.12); }

/* =========================================
   SUPPLIER PANEL — MOBILE FIXES
   ========================================= */

/* Make the month select full-width and more tappable on mobile */
@media (max-width: 640px) {
  /* Supplier panel: stack header vertically */
  .panel-header .panel-actions {
    width: 100%;
    flex-direction: column;
    gap: 8px;
  }

  /* Month select fills width */
  #supplierMonth {
    width: 100%;
    padding: 12px 36px 12px 14px;
    font-size: 15px;
    border-radius: var(--radius-sm);
    min-height: 46px;
  }

  /* Load Summary button fills width */
  #loadSupplierSummaryBtn {
    width: 100%;
    justify-content: center;
    padding: 12px;
    font-size: 14px;
  }

  /* Supplier summary table: hide less important cols on small screens */
  .data-table th:nth-child(4),
  .data-table td:nth-child(4),
  .data-table th:nth-child(6),
  .data-table td:nth-child(6) {
    display: none;
  }

  /* Bigger tap targets for all selects and inputs */
  .input-select, .input-text,
  input[type="date"], select {
    min-height: 44px;
    font-size: 16px; /* prevents iOS zoom on focus */
  }

  /* Filter grid full width on mobile */
  .filters-grid select,
  .filters-grid input {
    font-size: 16px; /* prevents iOS auto-zoom */
  }
}

/* Stat amount month select — always compact */
.stat-month-select {
  min-height: unset !important;
  font-size: 11px !important;
  padding: 3px 24px 3px 8px !important;
}

/* Supplier panel actions always stack nicely */
.panel-actions--supplier {
  flex-direction: column;
  width: 100%;
  max-width: 320px;
  gap: 8px;
}
.panel-actions--supplier select,
.panel-actions--supplier button {
  width: 100%;
}

@media (min-width: 641px) {
  .panel-actions--supplier {
    flex-direction: row;
    width: auto;
    max-width: none;
  }
  .panel-actions--supplier select { width: 160px; }
  .panel-actions--supplier button { width: auto; }
}

/* Stack panel header on mobile */
.panel-header--stack {
  flex-direction: column;
  align-items: flex-start;
  gap: 12px;
}
@media (min-width: 641px) {
  .panel-header--stack {
    flex-direction: row;
    align-items: center;
  }
}

/* =========================================
   TABLE SCROLL — DESKTOP ONLY
   Mobile scrolls with the page naturally (no clipping).
   Desktop gets overflow-x with a visible scrollbar.
   ========================================= */
@media (min-width: 901px) {
  .table-wrap {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: thin;
    scrollbar-color: var(--border-light) transparent;
  }
  .table-wrap::-webkit-scrollbar       { height: 8px; }
  .table-wrap::-webkit-scrollbar-track { background: var(--surface-2); border-radius: 4px; }
  .table-wrap::-webkit-scrollbar-thumb { background: var(--border-light); border-radius: 4px; }
  .table-wrap::-webkit-scrollbar-thumb:hover { background: var(--text-faint); }

  /* Sticky column headers */
  .invoices-table thead th {
    position: sticky;
    top: 0;
    z-index: 2;
    background: var(--surface-2);
  }
}

@media (max-width: 900px) {
  /* Mobile: let the whole panel be scrollable with the page */
  .table-wrap {
    overflow-x: visible;
    width: 100%;
  }
  /* Make the panel itself scroll horizontally instead */
  .panel:has(.invoices-table) {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
  }
}

/* Sticky horizontal scroll mirror at bottom of viewport */
.scroll-mirror-wrap {
  position: sticky;
  bottom: 0;
  z-index: 10;
  overflow-x: auto;
  overflow-y: hidden;
  background: var(--surface);
  border-top: 1px solid var(--border);
  scrollbar-width: thin;
  scrollbar-color: var(--border-light) transparent;
  display: none; /* shown by JS when table overflows */
}
.scroll-mirror-wrap::-webkit-scrollbar { height: 8px; }
.scroll-mirror-wrap::-webkit-scrollbar-track { background: var(--surface-2); }
.scroll-mirror-wrap::-webkit-scrollbar-thumb { background: var(--border-light); border-radius: 4px; }
.scroll-mirror-inner { height: 1px; }

@media (min-width: 901px) {
  .scroll-mirror-wrap { display: block; }
}

/* ── MOBILE TABLE: native smooth scroll ── */
@media (max-width: 900px) {
  .panel--table {
    overflow: visible;
  }

  .panel--table .table-wrap {
    display: block;
    width: 100%;
    overflow-x: auto;
    overflow-y: visible;
    /* iOS momentum scrolling — no touch-action lock */
    -webkit-overflow-scrolling: touch;
    /* Let browser decide scroll direction naturally */
    touch-action: auto;
    scrollbar-width: none;
    -ms-overflow-style: none;
  }
  .panel--table .table-wrap::-webkit-scrollbar {
    display: none;
  }

  .panel--table .data-table {
    min-width: 860px;
    width: max-content;
    /* Prevents layout collapse that causes scroll jank */
    table-layout: fixed;
  }

  .scroll-mirror-wrap { display: none !important; }
}

/* ── SUPPLIER SUMMARY TABLE — MOBILE FIX ── */
@media (max-width: 900px) {
  /* Make supplier summary panel scroll horizontally like invoices */
  .panel--supplier-summary .table-wrap {
    display: block;
    width: 100%;
    overflow-x: scroll;
    overflow-y: visible;
    -webkit-overflow-scrolling: touch;
    touch-action: pan-x;
    scrollbar-width: none;
    -ms-overflow-style: none;
  }
  .panel--supplier-summary .table-wrap::-webkit-scrollbar {
    display: none;
  }
  .panel--supplier-summary .data-table {
    min-width: 600px;
    width: max-content;
  }

  /* Un-hide all columns in supplier summary on mobile
     (we only hide them in the invoices table) */
  .panel--supplier-summary .data-table th,
  .panel--supplier-summary .data-table td {
    display: table-cell !important;
  }
}

/* ── ALWAYS VISIBLE SCROLLBAR ON DESKTOP TABLE ── */
@media (min-width: 901px) {
  .table-wrap {
    overflow-x: scroll !important; /* always show scrollbar track */
    scrollbar-width: thin;
    scrollbar-color: var(--border-light) var(--surface-2);
  }
  .table-wrap::-webkit-scrollbar {
    height: 10px;
    display: block !important;
  }
  .table-wrap::-webkit-scrollbar-track {
    background: var(--surface-2);
    border-radius: 0;
    border-top: 1px solid var(--border);
  }
  .table-wrap::-webkit-scrollbar-thumb {
    background: var(--border-light);
    border-radius: 5px;
    border: 2px solid var(--surface-2);
  }
  .table-wrap::-webkit-scrollbar-thumb:hover {
    background: var(--text-faint);
  }
}
