:root {
  --bg: #eef2f7;
  --bg-2: #f8fafc;
  --ink: #172033;
  --muted: #667085;
  --line: #d8deea;
  --card: #ffffff;
  --primary: #4f46e5;
  --primary-dark: #312e81;
  --good: #059669;
  --danger: #dc2626;
  --warning: #f59e0b;
  --shadow-sm: 0 8px 18px rgba(16, 24, 40, .08);
  --shadow: 0 18px 45px rgba(16, 24, 40, .12), 0 2px 0 rgba(255, 255, 255, .85) inset;
  --shadow-strong: 0 28px 70px rgba(16, 24, 40, .2);
  --radius: 14px;
}

* { box-sizing: border-box; }

[hidden] { display: none !important; }

html { scroll-behavior: smooth; }

body {
  margin: 0;
  color: var(--ink);
  font-family: Arial, Helvetica, sans-serif;
  background:
    radial-gradient(circle at top left, rgba(79, 70, 229, .10), transparent 32rem),
    linear-gradient(145deg, #f8fafc 0%, #edf2f8 42%, #e7edf6 100%);
}

a { color: inherit; text-decoration: none; }
h1, h2, h3, p { margin-top: 0; }
h1 { letter-spacing: .01em; }
p { line-height: 1.5; }

input, select, textarea, button { font: inherit; }

input, select, textarea {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 11px;
  padding: 11px 13px;
  color: var(--ink);
  background: linear-gradient(#fff, #f9fbff);
  box-shadow: 0 1px 0 rgba(255, 255, 255, .9) inset, 0 1px 2px rgba(16, 24, 40, .04);
  outline: none;
  transition: border-color .18s ease, box-shadow .18s ease, transform .18s ease;
}

input[type="checkbox"],
input[type="radio"] {
  width: auto;
}

select {
  cursor: pointer;
  appearance: auto;
}

select[data-expanded="true"] {
  position: relative;
  z-index: 30;
  border-color: var(--primary);
  box-shadow: 0 18px 36px rgba(79, 70, 229, .16), 0 0 0 4px rgba(79, 70, 229, .12);
}

input:focus, select:focus, textarea:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 4px rgba(79, 70, 229, .12), 0 9px 24px rgba(16, 24, 40, .08);
}

textarea { min-height: 92px; resize: vertical; }

label {
  display: flex;
  flex-direction: column;
  gap: 7px;
  font-size: 13px;
  font-weight: 800;
  color: #566176;
}

.sidebar {
  position: fixed;
  inset: 0 auto 0 0;
  width: 268px;
  color: #cbd5e1;
  display: flex;
  flex-direction: column;
  border-right: 1px solid rgba(255, 255, 255, .08);
  background:
    linear-gradient(155deg, rgba(30, 41, 59, .88), rgba(2, 6, 23, .98)),
    #07111f;
  box-shadow: 18px 0 40px rgba(15, 23, 42, .20);
  z-index: 10;
}

.brand {
  padding: 26px 24px;
  border-bottom: 1px solid rgba(255, 255, 255, .08);
}

.brand strong { display: block; color: #fff; font-size: 22px; }

.brand span {
  display: block;
  margin-top: 6px;
  font-size: 10px;
  letter-spacing: .2em;
  text-transform: uppercase;
  color: #94a3b8;
}

.sidebar nav {
  padding: 20px 12px;
  display: flex;
  flex-direction: column;
  gap: 7px;
  overflow: auto;
}

.sidebar a {
  border-radius: 12px;
  padding: 12px 14px;
  color: #cbd5e1;
  transition: transform .18s ease, background .18s ease, box-shadow .18s ease, color .18s ease;
}

.sidebar a:hover {
  transform: translateX(3px);
  background: rgba(255, 255, 255, .08);
  color: #fff;
}

.sidebar a.active {
  color: #fff;
  background: linear-gradient(145deg, rgba(79, 70, 229, .95), rgba(49, 46, 129, .94));
  box-shadow: 0 14px 28px rgba(49, 46, 129, .35), 0 1px 0 rgba(255, 255, 255, .18) inset;
}

.sidebar-footer {
  margin-top: auto;
  padding: 15px;
  border-top: 1px solid rgba(255, 255, 255, .08);
}

.profile { display: block; margin-bottom: 10px; }
.profile b, .profile span { display: block; }
.profile span { text-transform: capitalize; color: #94a3b8; font-size: 12px; }
.logout { display: block; text-align: center; background: rgba(15, 23, 42, .86); }

.mobile-topbar, .sidebar-overlay {
  display: none;
}

.main {
  margin-left: 268px;
  padding: clamp(22px, 3vw, 42px);
  min-height: 100vh;
}

.page-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 18px;
  margin-bottom: 26px;
}

.page-head h1 { font-size: clamp(26px, 3vw, 34px); margin-bottom: 7px; }
.page-head p { color: var(--muted); margin-bottom: 0; }

.panel {
  background:
    linear-gradient(180deg, rgba(255, 255, 255, .98), rgba(248, 250, 252, .96));
  border: 1px solid rgba(203, 213, 225, .82);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  transform: translateZ(0);
  transition: transform .18s ease, box-shadow .18s ease, border-color .18s ease;
}

.panel {
  padding: clamp(18px, 2.2vw, 26px);
  margin-bottom: 24px;
}

.panel:hover, .stat:hover {
  transform: translateY(-2px);
  box-shadow: var(--shadow-strong);
  border-color: rgba(148, 163, 184, .95);
}

.stat:hover {
  box-shadow:
    0 24px 52px rgba(16, 24, 40, .16),
    0 5px 0 rgba(203, 213, 225, .82),
    0 1px 0 rgba(255, 255, 255, .94) inset;
}

.grid-2, .grid-3, .grid-4, .grid-5 {
  display: grid;
  gap: 20px;
}

.grid-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.grid-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.grid-4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.grid-5 { grid-template-columns: repeat(5, minmax(0, 1fr)); }
.span-2 { grid-column: span 2; }
.stats {
  margin-bottom: 24px;
  align-items: stretch;
}

.stat {
  padding: 22px;
  position: relative;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  min-height: 128px;
  background:
    linear-gradient(180deg, var(--kpi-card-bg-top, #ffffff), var(--kpi-card-bg-bottom, #ffffff));
  border: 1px solid var(--kpi-card-border, rgba(203, 213, 225, .86));
  border-radius: var(--radius);
  box-shadow:
    0 18px 38px rgba(16, 24, 40, .12),
    0 5px 0 rgba(203, 213, 225, .78),
    0 1px 0 rgba(255, 255, 255, .92) inset;
  transform: translateZ(0);
  transition: transform .18s ease, box-shadow .18s ease, border-color .18s ease;
}

.dashboard-kpi-section {
  --kpi-card-bg-top: #ffffff;
  --kpi-card-bg-bottom: #ffffff;
  --kpi-card-border: rgba(203, 213, 225, .86);
}

.kpi-tone-slate {
  --kpi-card-bg-top: #ffffff;
  --kpi-card-bg-bottom: #f8fafc;
  --kpi-card-border: rgba(203, 213, 225, .90);
}

.kpi-tone-green {
  --kpi-card-bg-top: #ffffff;
  --kpi-card-bg-bottom: #f7fdf9;
  --kpi-card-border: rgba(187, 226, 205, .90);
}

.kpi-tone-blue {
  --kpi-card-bg-top: #ffffff;
  --kpi-card-bg-bottom: #f7fbff;
  --kpi-card-border: rgba(191, 219, 254, .85);
}

.kpi-tone-amber {
  --kpi-card-bg-top: #ffffff;
  --kpi-card-bg-bottom: #fffaf0;
  --kpi-card-border: rgba(253, 230, 138, .82);
}

.kpi-tone-lilac {
  --kpi-card-bg-top: #ffffff;
  --kpi-card-bg-bottom: #fbfaff;
  --kpi-card-border: rgba(221, 214, 254, .82);
}

.kpi-tone-mint {
  --kpi-card-bg-top: #ffffff;
  --kpi-card-bg-bottom: #f4fffb;
  --kpi-card-border: rgba(167, 243, 208, .86);
}

.stat span {
  display: block;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.25;
  font-weight: 800;
  margin-bottom: 10px;
  min-height: 32px;
  overflow-wrap: anywhere;
}

.stat small {
  display: block;
  color: #64748b;
  font-size: 12px;
  font-weight: 900;
  line-height: 1.3;
  margin: -4px 0 10px;
  overflow-wrap: anywhere;
}

.company-kpi-section {
  margin: 0 0 24px;
}

.company-kpi-section .section-head {
  margin-bottom: 12px;
}

.company-kpis {
  margin-bottom: 0;
}

.company-kpi-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 20px;
}

.stat b {
  display: block;
  font-size: clamp(21px, 1.8vw, 28px);
  line-height: 1.05;
  position: relative;
  z-index: 1;
  overflow-wrap: anywhere;
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border: 0;
  border-radius: 11px;
  padding: 11px 16px;
  font-weight: 900;
  cursor: pointer;
  color: #273143;
  background: linear-gradient(180deg, #f8fafc, #e5eaf2);
  box-shadow: 0 4px 0 #cbd5e1, 0 12px 22px rgba(15, 23, 42, .10);
  transition: transform .14s ease, box-shadow .14s ease, filter .14s ease;
}

.btn:hover { transform: translateY(-2px); filter: brightness(1.03); }
.btn:active { transform: translateY(2px); box-shadow: 0 1px 0 #cbd5e1, 0 5px 12px rgba(15, 23, 42, .10); }
.btn.primary { background: linear-gradient(180deg, #6366f1, #4338ca); color: #fff; box-shadow: 0 4px 0 #312e81, 0 14px 24px rgba(79, 70, 229, .24); }
.btn.danger { background: linear-gradient(180deg, #ef4444, #b91c1c); color: #fff; box-shadow: 0 4px 0 #7f1d1d, 0 14px 24px rgba(220, 38, 38, .20); }
.btn.subtle { background: linear-gradient(180deg, #fff, #edf2f8); color: #334155; }
.btn.good-bg, .good-bg { background: linear-gradient(180deg, #10b981, #047857); color: #fff; box-shadow: 0 4px 0 #065f46, 0 14px 24px rgba(5, 150, 105, .20); }
.btn.small { font-size: 12px; padding: 8px 11px; border-radius: 9px; }
.btn.full { width: 100%; }

.button-row, .actions, .bulk-actions, .inline-form {
  display: flex;
  gap: 11px;
  align-items: center;
  flex-wrap: wrap;
}

.compact-label {
  display: inline-flex;
  flex: 1 1 210px;
  min-width: 180px;
  gap: 6px;
}

.compact-label select {
  width: 100%;
}

.form-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 19px;
}

.form-grid h2 { grid-column: 1 / -1; margin: 12px 0 0; }
.form-actions { grid-column: 1 / -1; display: flex; justify-content: flex-end; }

.custom-field {
  margin-top: 6px;
  border-color: rgba(79, 70, 229, .34);
  background: linear-gradient(180deg, #fff, #f3f6ff);
}

.filters {
  display: grid;
  grid-template-columns: repeat(6, minmax(130px, 1fr));
  gap: 13px;
  align-items: start;
  overflow: visible;
}

.filters.titled-filters {
  grid-template-columns: repeat(5, minmax(150px, 1fr));
}

.filters.report-filters {
  grid-template-columns: repeat(4, minmax(145px, 1fr)) auto auto;
}

.report-filters .btn {
  align-self: end;
}

.filters label {
  min-width: 0;
}

.table-wrap {
  overflow: auto;
  border-radius: var(--radius);
}

table {
  width: 100%;
  border-collapse: separate;
  border-spacing: 0;
  font-size: 14px;
}

th {
  background: linear-gradient(180deg, #f8fafc, #eef2f7);
  color: var(--muted);
  text-align: left;
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: .06em;
}

th, td {
  padding: 14px 15px;
  border-bottom: 1px solid #e8edf5;
  vertical-align: top;
}

tbody tr {
  transition: background .16s ease, box-shadow .16s ease, transform .16s ease;
}

tbody tr:hover {
  background: #f8fbff;
  box-shadow: 0 8px 18px rgba(15, 23, 42, .06);
}

td small { display: block; color: var(--muted); margin-top: 5px; }
.empty { text-align: center; color: #98a2b3; padding: 30px; }

.pagination {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 8px;
  padding: 16px 0 0;
  flex-wrap: wrap;
}

.pagination .active {
  color: #fff;
  background: linear-gradient(180deg, #6366f1, #4338ca);
  box-shadow: 0 4px 0 #312e81, 0 14px 24px rgba(79, 70, 229, .24);
}

.pagination-top .pagination {
  justify-content: flex-start;
  padding: 0 0 16px;
}

.pill {
  display: inline-block;
  border-radius: 999px;
  background: linear-gradient(180deg, #eef2ff, #dfe6ff);
  color: #3730a3;
  padding: 5px 10px;
  font-size: 12px;
  font-weight: 900;
  box-shadow: 0 2px 0 rgba(99, 102, 241, .18);
}

.pill.sold { background: linear-gradient(180deg, #f1f5f9, #e2e8f0); color: #475569; }
.pill.transit { background: linear-gradient(180deg, #fff7ed, #fed7aa); color: #9a3412; box-shadow: 0 2px 0 rgba(234, 88, 12, .16); }
.good { color: var(--good); }
.good-dark,
.stat b.good-dark {
  color: #065f46;
}
.bad { color: var(--danger); }
.muted { color: #98a2b3; }

.flash {
  margin: 0 0 18px;
  padding: 14px 16px;
  border-radius: 12px;
  background: #eef2ff;
  color: #3730a3;
  border: 1px solid #c7d2fe;
  box-shadow: var(--shadow-sm);
}

.flash.success { background: #ecfdf5; color: #047857; border-color: #a7f3d0; }
.flash.error { background: #fef2f2; color: #b91c1c; border-color: #fecaca; }
.flash.info { background: #eff6ff; color: #1d4ed8; border-color: #bfdbfe; }

.login-shell {
  min-height: 100vh;
  min-height: 100dvh;
  display: flex;
  align-items: flex-start;
  justify-content: center;
  background:
    radial-gradient(circle at 20% 15%, rgba(99, 102, 241, .34), transparent 24rem),
    linear-gradient(145deg, #1e1b4b, #0f172a);
  padding: clamp(18px, 7vh, 56px) 20px;
  overflow-y: auto;
}

.login-card {
  width: 100%;
  max-width: 420px;
  background: linear-gradient(180deg, rgba(255,255,255,.98), rgba(248,250,252,.96));
  border: 1px solid rgba(255,255,255,.82);
  border-radius: 18px;
  padding: 36px;
  box-shadow: 0 34px 90px rgba(0,0,0,.32), 0 2px 0 rgba(255,255,255,.8) inset;
  display: flex;
  flex-direction: column;
  gap: 18px;
  margin: auto 0;
}

.login-icon {
  width: 66px;
  height: 66px;
  border-radius: 50%;
  background: linear-gradient(145deg, #eef2ff, #c7d2fe);
  color: var(--primary);
  font-weight: 900;
  display: flex;
  align-items: center;
  justify-content: center;
  margin: 0 auto;
  box-shadow: 0 12px 28px rgba(79, 70, 229, .20);
}

.login-card h1, .login-card p { text-align: center; }
.login-submit {
  display: block;
  width: 100%;
  min-height: 48px;
  border: 0;
  border-radius: 12px;
  padding: 13px 18px;
  background: linear-gradient(180deg, #6366f1, #4338ca);
  color: #fff;
  font-weight: 900;
  cursor: pointer;
  box-shadow: 0 4px 0 #312e81, 0 16px 28px rgba(79, 70, 229, .28);
}

.login-submit:hover { filter: brightness(1.04); transform: translateY(-1px); }
.login-submit:active { transform: translateY(2px); box-shadow: 0 1px 0 #312e81, 0 8px 16px rgba(79, 70, 229, .22); }
.hint { font-size: 12px; color: var(--muted); text-align: center; }

.bar-row {
  display: grid;
  grid-template-columns: 120px 1fr 36px;
  gap: 10px;
  align-items: center;
  margin: 11px 0;
}

.bar-row i {
  display: block;
  height: 10px;
  background: linear-gradient(90deg, #4f46e5, #0ea5e9);
  border-radius: 999px;
  min-width: 3px;
  box-shadow: 0 4px 10px rgba(79, 70, 229, .18);
}

.chart {
  width: 100%;
  height: 320px;
  border-radius: 16px;
  padding: 10px;
  background:
    linear-gradient(180deg, rgba(255,255,255,.82), rgba(248,250,252,.72)),
    radial-gradient(circle at top right, rgba(79,70,229,.10), transparent 18rem);
  box-shadow: inset 0 2px 12px rgba(15, 23, 42, .04);
}

.modal {
  position: fixed;
  inset: 0;
  background: rgba(2, 6, 23, .66);
  display: none;
  align-items: center;
  justify-content: center;
  padding: 20px;
  z-index: 50;
  backdrop-filter: blur(4px);
}

.modal.open { display: flex; }

.modal-card {
  background: linear-gradient(180deg, #fff, #f8fafc);
  border: 1px solid rgba(255, 255, 255, .82);
  border-radius: 18px;
  width: min(580px, 100%);
  max-height: 90vh;
  overflow: auto;
  padding: 26px;
  position: relative;
  box-shadow: 0 34px 90px rgba(0,0,0,.30);
  animation: liftIn .18s ease-out;
}

@keyframes liftIn {
  from { opacity: 0; transform: translateY(12px) scale(.98); }
  to { opacity: 1; transform: translateY(0) scale(1); }
}

.modal-close {
  position: absolute;
  top: 14px;
  right: 14px;
  border: 0;
  background: #eef2f7;
  border-radius: 50%;
  width: 34px;
  height: 34px;
  cursor: pointer;
  box-shadow: 0 3px 0 #cbd5e1;
}

.breakdown { display: grid; grid-template-columns: 1fr auto; gap: 12px; }
.breakdown dt { color: var(--muted); }
.breakdown dd { margin: 0; font-weight: 900; }
.sale-detail-breakdown dd {
  text-align: right;
  overflow-wrap: anywhere;
}

.list {
  list-style: none;
  margin: 16px 0 0;
  padding: 0;
  max-height: 440px;
  overflow: auto;
}

.list.tall { max-height: 560px; }
.list li { display: flex; justify-content: space-between; align-items: center; gap: 12px; padding: 13px 0; border-bottom: 1px solid #edf0f5; }
.icon { border: 0; background: transparent; color: #64748b; cursor: pointer; }
.icon.danger { color: var(--danger); }
.user-card .role { text-transform: uppercase; font-size: 11px; color: var(--primary); font-weight: 900; }

.calc-total {
  padding: 14px;
  border-radius: 12px;
  background: linear-gradient(180deg, #f8fafc, #eef2f7);
  border: 1px solid #dbe3ef;
  box-shadow: 0 5px 14px rgba(15, 23, 42, .06) inset;
}

.calc-total span { display: block; color: var(--muted); font-size: 12px; }
.calc-total b { font-size: 23px; }
.payment-line { display: flex; gap: 8px; align-items: center; justify-content: flex-end; margin-top: 8px; font-size: 12px; }
.split-actions { display: flex; align-items: center; justify-content: space-between; gap: 20px; border-top: 1px solid #edf0f5; padding-top: 16px; margin-top: 16px; }
.danger-zone { border-color: #fecaca; background: linear-gradient(180deg, #fff, #fff7f7); }
.link { border: 0; background: transparent; color: var(--primary); font-weight: 900; cursor: pointer; padding: 0; }

.sold-vehicles-panel {
  overflow: visible;
}

.sold-filter-buttons {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 10px;
  flex-wrap: wrap;
}

.sold-period-controls {
  display: flex;
  align-items: flex-end;
  justify-content: flex-end;
  gap: 12px;
  flex-wrap: wrap;
}

.sold-month-select {
  width: min(240px, 100%);
}

.sold-filter-buttons .btn {
  gap: 8px;
}

.sold-filter-buttons span {
  min-width: 24px;
  padding: 3px 7px;
  border-radius: 999px;
  color: inherit;
  background: rgba(255, 255, 255, .26);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, .28);
}

.sold-filter-buttons .subtle span {
  background: #e2e8f0;
  color: #475569;
}

.sold-period-summary {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 14px;
  padding: 13px 15px;
  border-radius: 12px;
  border: 1px solid #e5eaf2;
  background: linear-gradient(180deg, #fff, #f8fafc);
}

.sold-period-summary span {
  color: var(--muted);
  font-weight: 800;
  font-size: 13px;
}

.compact-table {
  margin-bottom: 0;
}

.section-head {
  display: flex;
  justify-content: space-between;
  gap: 18px;
  margin-bottom: 18px;
}

.section-head p {
  color: var(--muted);
  margin-bottom: 0;
}

.payments-workflow {
  overflow: visible;
}

.payment-stats {
  margin-bottom: 18px;
}

.payment-filters {
  grid-template-columns: minmax(260px, 2fr) minmax(170px, .8fr) auto auto;
  margin-bottom: 20px;
}

.payment-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 18px;
}

.payment-card {
  border: 1px solid rgba(203, 213, 225, .88);
  border-radius: 16px;
  padding: 18px;
  background:
    linear-gradient(180deg, rgba(255,255,255,.98), rgba(248,250,252,.95));
  box-shadow: 0 16px 34px rgba(16, 24, 40, .10), 0 2px 0 rgba(255,255,255,.9) inset;
  transition: transform .18s ease, box-shadow .18s ease, border-color .18s ease;
}

.payment-card:hover {
  transform: translateY(-2px);
  box-shadow: 0 24px 52px rgba(16, 24, 40, .15);
}

.payment-card.needs-payment {
  border-color: rgba(245, 158, 11, .38);
}

.payment-card.is-cleared {
  border-color: rgba(16, 185, 129, .34);
}

.payment-card-head {
  display: flex;
  justify-content: space-between;
  gap: 14px;
  align-items: flex-start;
}

.payment-card h3 {
  margin-bottom: 4px;
}

.payment-card p {
  color: var(--muted);
  font-size: 13px;
  margin-bottom: 0;
}

.payment-progress {
  height: 12px;
  margin: 16px 0;
  border-radius: 999px;
  background: #e5eaf2;
  overflow: hidden;
  box-shadow: inset 0 2px 5px rgba(15, 23, 42, .10);
}

.payment-progress div {
  height: 100%;
  border-radius: inherit;
  background: linear-gradient(90deg, #10b981, #4f46e5);
  box-shadow: 0 6px 12px rgba(16, 185, 129, .18);
}

.payment-amounts {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 10px;
}

.payment-amounts div {
  padding: 12px;
  border: 1px solid #e5eaf2;
  border-radius: 12px;
  background: linear-gradient(180deg, #fff, #f8fafc);
}

.payment-amounts span {
  display: block;
  color: var(--muted);
  font-size: 11px;
  font-weight: 900;
  text-transform: uppercase;
  letter-spacing: .05em;
  margin-bottom: 5px;
}

.payment-amounts b {
  font-size: 16px;
}

.payment-actions {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  margin-top: 16px;
}

.payment-history {
  margin-top: 16px;
  padding-top: 14px;
  border-top: 1px solid #edf0f5;
}

.payment-history .payment-line {
  justify-content: space-between;
  padding: 8px 0;
  border-bottom: 1px dashed #e5eaf2;
}

.payment-list-wrap {
  overflow: visible;
}

.payment-list-table .pill {
  margin-top: 8px;
}

.payment-list-row.needs-payment td:first-child {
  border-left: 4px solid rgba(245, 158, 11, .72);
}

.payment-list-row.is-cleared td:first-child {
  border-left: 4px solid rgba(16, 185, 129, .72);
}

.payment-list-row .actions {
  align-items: stretch;
}

.payment-list-row .btn {
  white-space: nowrap;
}

.list-progress {
  min-width: 120px;
  margin: 0 0 7px;
}

.payment-history-row td {
  background: #f8fafc;
}

.payment-history-row .payment-history {
  margin-top: 0;
  padding-top: 0;
  border-top: 0;
}

.modal-summary {
  margin: 14px 0 16px;
}

.audit-filters {
  grid-template-columns: 1.6fr repeat(5, minmax(120px, 1fr)) auto auto;
}

.audit-detail {
  width: 100%;
  max-width: 420px;
  white-space: pre-wrap;
  word-break: break-word;
  overflow-wrap: anywhere;
  margin: 0;
  padding: 10px;
  border-radius: 10px;
  background: #f7f9fc;
  border: 1px solid #e5eaf2;
  color: #334155;
  font: 12px/1.45 Consolas, "Courier New", monospace;
}

@media print {
  body.report-print-snapshot {
    background: #fff;
  }
  body.report-print-snapshot .sidebar,
  body.report-print-snapshot .mobile-topbar,
  body.report-print-snapshot .sidebar-overlay,
  body.report-print-snapshot .button-row,
  body.report-print-snapshot .report-filters,
  body.report-print-snapshot .pagination {
    display: none !important;
  }
  body.report-print-snapshot .main {
    margin-left: 0;
    padding: 0;
  }
  body.report-print-snapshot .panel,
  body.report-print-snapshot .stat {
    box-shadow: none;
    break-inside: avoid;
  }
  body.report-print-snapshot .panel:hover,
  body.report-print-snapshot .stat:hover {
    transform: none;
    box-shadow: none;
  }
}

.batch-month-filter {
  grid-template-columns: minmax(220px, 320px) auto;
}

.batch-sales-panel {
  overflow: visible;
}

.batch-sales-table {
  font-size: 13px;
}

.batch-sales-table th,
.batch-sales-table td {
  padding: 10px;
}

.batch-sales-table input,
.batch-sales-table textarea {
  min-width: 120px;
  padding: 9px 10px;
  border-radius: 9px;
}

.batch-sales-table textarea {
  min-width: 190px;
  min-height: 48px;
}

.batch-save-bottom {
  margin-top: 18px;
}

@media (max-width: 1100px) {
  .grid-5, .grid-4, .grid-3 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .company-kpi-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .filters, .form-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .filters.report-filters { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .payment-grid { grid-template-columns: 1fr; }
  .payment-filters { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}

@media (max-width: 860px) {
  body.sidebar-open { overflow: hidden; }

  .mobile-topbar {
    position: sticky;
    top: 0;
    z-index: 40;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 14px;
    padding: 12px 14px;
    color: #fff;
    background:
      linear-gradient(155deg, rgba(30, 41, 59, .96), rgba(2, 6, 23, .98)),
      #07111f;
    border-bottom: 1px solid rgba(255, 255, 255, .10);
    box-shadow: 0 12px 30px rgba(15, 23, 42, .22);
  }

  .mobile-topbar strong,
  .mobile-topbar small {
    display: block;
    text-align: right;
  }

  .mobile-topbar small {
    color: #94a3b8;
    font-size: 11px;
    text-transform: capitalize;
  }

  .mobile-menu-btn {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    min-height: 42px;
    border: 1px solid rgba(255, 255, 255, .14);
    border-radius: 12px;
    padding: 10px 13px;
    color: #fff;
    background: rgba(255, 255, 255, .08);
    font-weight: 900;
    cursor: pointer;
    box-shadow: 0 8px 20px rgba(0, 0, 0, .16);
  }

  .mobile-menu-btn i {
    display: grid;
    gap: 4px;
  }

  .mobile-menu-btn span {
    display: block;
    width: 16px;
    height: 2px;
    border-radius: 999px;
    background: currentColor;
  }

  .sidebar {
    width: min(86vw, 312px);
    transform: translateX(-105%);
    transition: transform .24s ease;
    z-index: 60;
  }

  .sidebar-open .sidebar {
    transform: translateX(0);
  }

  .sidebar-overlay {
    position: fixed;
    inset: 0;
    z-index: 55;
    background: rgba(2, 6, 23, .54);
    backdrop-filter: blur(2px);
  }

  .sidebar-open .sidebar-overlay {
    display: block;
  }

  .sidebar nav {
    display: flex;
    flex-direction: column;
    grid-template-columns: none;
    padding: 14px 12px 20px;
  }

  .sidebar a {
    min-height: 46px;
    display: flex;
    align-items: center;
  }

  .main {
    margin-left: 0;
    padding: 18px 14px 28px;
  }

  .grid-2, .grid-3, .grid-4, .grid-5, .filters, .form-grid { grid-template-columns: 1fr; }
  .filters.titled-filters { grid-template-columns: 1fr; }
  .filters.report-filters { grid-template-columns: 1fr; }
  .span-2 { grid-column: auto; }
  .page-head, .split-actions, .payment-card-head { flex-direction: column; }
  .page-head {
    gap: 12px;
    margin-bottom: 18px;
  }
  .page-head h1 {
    font-size: 25px;
    line-height: 1.15;
  }
  .panel {
    padding: 16px;
    margin-bottom: 18px;
    border-radius: 12px;
  }
  .stat {
    padding: 16px;
    min-height: 112px;
  }
  .stat span {
    min-height: auto;
    font-size: 12px;
  }
  .stat b {
    font-size: clamp(20px, 6vw, 25px);
  }
  .button-row, .actions, .bulk-actions, .inline-form, .payment-actions {
    align-items: stretch;
  }
  .button-row > *, .actions > *, .bulk-actions > *, .inline-form > *, .payment-actions > * {
    flex: 1 1 auto;
  }
  .sold-filter-buttons {
    justify-content: stretch;
  }
  .sold-filter-buttons .btn {
    flex: 1 1 auto;
  }
  .sold-period-controls {
    width: 100%;
    align-items: stretch;
    justify-content: stretch;
  }
  .sold-month-select {
    width: 100%;
  }
  .sold-period-summary {
    align-items: flex-start;
    flex-direction: column;
  }
  .table-wrap {
    margin-left: -14px;
    margin-right: -14px;
    border-radius: 0;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
  }
  table {
    min-width: 760px;
  }
  .table-wrap.responsive-table-wrap {
    margin-left: 0;
    margin-right: 0;
    overflow: visible;
    border-radius: 12px;
  }
  table.responsive-table {
    min-width: 0;
    width: 100%;
  }
  table.responsive-table thead {
    display: none;
  }
  table.responsive-table,
  table.responsive-table tbody,
  table.responsive-table tr,
  table.responsive-table td {
    display: block;
    width: 100%;
  }
  table.responsive-table tr {
    margin-bottom: 12px;
    padding: 12px;
    border: 1px solid #e5eaf2;
    border-radius: 12px;
    background: linear-gradient(180deg, #fff, #f8fafc);
    box-shadow: 0 10px 22px rgba(15, 23, 42, .08), 0 2px 0 rgba(255, 255, 255, .9) inset;
  }
  table.responsive-table tr:last-child {
    margin-bottom: 0;
  }
  table.responsive-table tbody tr:hover {
    transform: none;
  }
  table.responsive-table td {
    display: grid;
    grid-template-columns: minmax(92px, 38%) minmax(0, 1fr);
    gap: 12px;
    align-items: start;
    padding: 9px 0;
    border-bottom: 1px solid #edf0f5;
    word-break: break-word;
  }
  table.responsive-table td:last-child {
    border-bottom: 0;
  }
  table.responsive-table td::before {
    content: attr(data-label);
    color: var(--muted);
    font-size: 11px;
    font-weight: 900;
    letter-spacing: .05em;
    text-transform: uppercase;
  }
  table.responsive-table td[data-label=""]::before {
    display: none;
  }
  table.responsive-table td.mobile-full {
    grid-template-columns: 1fr;
  }
  table.responsive-table td.empty {
    display: block;
    text-align: center;
    padding: 16px;
  }
  table.responsive-table td.empty::before {
    display: none;
  }
  input, select, textarea, .btn, .login-submit {
    min-height: 46px;
  }
  select[data-expanded="true"] { max-height: 60vh; }
  .payment-filters, .payment-amounts, .audit-filters { grid-template-columns: 1fr; }
  .payment-list-row.needs-payment td:first-child,
  .payment-list-row.is-cleared td:first-child {
    border-left: 0;
  }
  .payment-list-table .pill {
    width: fit-content;
  }
  .list-progress {
    min-width: 0;
  }
  .payment-history-row td {
    background: linear-gradient(180deg, #fff, #f8fafc);
  }
  .batch-month-filter { grid-template-columns: 1fr; }
  .batch-sales-table input,
  .batch-sales-table textarea {
    min-width: 0;
    width: 100%;
  }
  .batch-sales-table textarea {
    min-height: 78px;
  }
  .payment-card {
    padding: 15px;
  }
  .payment-amounts b {
    font-size: 15px;
  }
  .modal {
    padding: 12px;
    align-items: flex-start;
    overflow-y: auto;
  }
  .modal-card {
    width: 100%;
    max-height: none;
    margin: 18px 0;
  }
  .chart {
    height: 260px;
  }
}

@media (max-width: 480px) {
  .main {
    padding-left: 10px;
    padding-right: 10px;
  }
  .panel {
    padding: 14px;
  }
  .dashboard-kpi-section.stats,
  .dashboard-kpi-section .stats,
  .company-kpi-grid {
    grid-template-columns: 1fr;
    gap: 14px;
  }
  .stats {
    margin-bottom: 18px;
  }
  .stat {
    min-height: 104px;
    padding: 15px;
  }
  .table-wrap {
    margin-left: -10px;
    margin-right: -10px;
  }
  .payment-amounts div {
    padding: 10px;
  }
}
