:root {
  color-scheme: light;
  --bg: #f7f4f8;
  --surface: #ffffff;
  --surface-alt: #f4ecf7;
  --ink: #3f3150;
  --muted: #7d6f86;
  --line: #e7dfea;
  --primary: #9b58c6;
  --primary-dark: #763a9e;
  --accent: #178fa0;
  --accent-soft: #dff7f8;
  --peach: #f3b27f;
  --pink: #de8ab8;
  --warning: #c58b24;
  --danger: #b42318;
  --success: #167047;
  --shadow: 0 12px 30px rgba(89, 55, 112, .08);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: Arial, Helvetica, sans-serif;
  min-height: 100vh;
}

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

button {
  border: 0;
  cursor: pointer;
}

.app-shell {
  display: grid;
  grid-template-columns: 280px 1fr;
  min-height: 100vh;
}

.sidebar {
  background: linear-gradient(180deg, #fff 0%, #fbf7fc 55%, #f2e9f7 100%);
  color: var(--ink);
  padding: 24px 24px 70px;
  display: flex;
  flex-direction: column;
  gap: 28px;
  border-right: 1px solid var(--line);
  position: relative;
}

.brand {
  display: flex;
  gap: 14px;
  align-items: flex-start;
  flex-direction: column;
}

.brand-logo {
  width: 100%;
  max-width: 220px;
  aspect-ratio: 961 / 678;
  object-fit: contain;
  border-radius: 8px;
  background: #fff;
  box-shadow: 0 14px 34px rgba(143, 73, 190, .16);
}

.brand h1,
.topbar h2,
.topbar p,
.panel h3 {
  margin: 0;
}

.brand h1 {
  font-size: 20px;
  color: var(--primary-dark);
}

.nav {
  display: grid;
  gap: 8px;
}

.nav-item,
.secondary,
.ghost,
.primary,
.file-button {
  border-radius: 8px;
  min-height: 42px;
  padding: 10px 13px;
  text-align: left;
}

.nav-item {
  background: transparent;
  color: var(--ink);
  font-weight: 700;
}

.nav-item.active,
.nav-item:hover {
  background: var(--primary);
  color: #fff;
}

.backup-box {
  margin-top: auto;
  display: grid;
  gap: 10px;
  padding-top: 14px;
  border-top: 1px solid rgba(181, 107, 221, .2);
}

.full {
  width: 100%;
  text-align: center;
}

.secondary,
.file-button {
  background: var(--accent-soft);
  color: #116f80;
}

.ghost {
  background: transparent;
  color: var(--primary);
  border: 1px solid var(--line);
}

.primary {
  background: var(--primary);
  color: #fff;
  text-align: center;
  font-weight: 700;
}

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

.file-button {
  display: grid;
  place-items: center;
  cursor: pointer;
}

.file-button input {
  display: none;
}

.content {
  padding: 28px;
  min-width: 0;
}

.topbar {
  display: flex;
  justify-content: space-between;
  gap: 18px;
  align-items: center;
  margin-bottom: 24px;
}

.user-badge {
  display: flex;
  align-items: center;
  gap: 10px;
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
}

.user-badge button {
  min-height: 34px;
  border-radius: 8px;
  padding: 7px 10px;
  background: var(--surface-alt);
  color: var(--primary-dark);
}

.eyebrow {
  color: var(--accent);
  font-size: 12px;
  font-weight: 800;
  letter-spacing: 0;
  text-transform: uppercase;
}

.topbar h2 {
  font-size: 30px;
}

.search-wrap {
  width: min(360px, 100%);
}

input,
select,
textarea {
  width: 100%;
  border: 1px solid var(--line);
  background: #fff;
  color: var(--ink);
  border-radius: 8px;
  padding: 10px 12px;
  outline: none;
}

input:focus,
select:focus,
textarea:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(181, 107, 221, .18);
}

.view {
  display: none;
}

.active-view {
  display: block;
}

.metrics {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 14px;
  margin-bottom: 18px;
}

.metric,
.panel {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
}

.metric {
  padding: 16px;
}

.metric span {
  color: var(--muted);
  font-size: 13px;
}

.metric strong {
  display: block;
  margin-top: 10px;
  font-size: 26px;
  color: var(--primary-dark);
}

.split,
.grid-two {
  display: grid;
  grid-template-columns: minmax(300px, 420px) minmax(0, 1fr);
  gap: 18px;
}

#dashboard .split {
  grid-template-columns: repeat(2, minmax(0, 1fr));
}

.dashboard-grid {
  display: grid;
  grid-template-columns: minmax(0, 1.5fr) minmax(280px, .7fr);
  gap: 18px;
  margin-top: 12px;
}

.dashboard-chart {
  min-height: 300px;
}

.today-summary {
  display: grid;
  gap: 12px;
}

.today-summary div {
  background: linear-gradient(135deg, #fff, var(--surface-alt));
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 14px;
}

.today-summary span {
  color: var(--muted);
  display: block;
  font-size: 12px;
  font-weight: 700;
  margin-bottom: 8px;
}

.today-summary strong {
  color: var(--primary-dark);
  font-size: 24px;
}

.quick-actions,
.dashboard-actions {
  display: grid;
  gap: 10px;
}

.dashboard-actions {
  grid-template-columns: repeat(3, minmax(0, 1fr));
  margin: -2px 0 18px;
}

.quick-actions button,
.dashboard-actions button {
  min-height: 44px;
  border-radius: 8px;
  background: linear-gradient(135deg, var(--primary), var(--accent));
  color: #fff;
  font-weight: 800;
  text-align: center;
}

.panel {
  padding: 18px;
  min-width: 0;
}

.panel-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 16px;
}

.panel h3 {
  font-size: 18px;
}

.panel-subtitle,
.muted-small {
  color: var(--muted);
  font-size: 12px;
}

.panel-subtitle {
  margin: 6px 0 0;
}

.form-panel {
  align-self: start;
}

form {
  display: grid;
  gap: 13px;
}

label {
  display: grid;
  gap: 6px;
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
}

.check-line {
  display: flex;
  align-items: center;
  gap: 8px;
}

.check-line input {
  width: auto;
}

.inline-fields {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}

.table-wrap {
  overflow-x: auto;
}

table {
  width: 100%;
  border-collapse: collapse;
  min-width: 720px;
}

th,
td {
  padding: 12px 10px;
  text-align: left;
  border-bottom: 1px solid var(--line);
  vertical-align: middle;
}

th {
  color: var(--muted);
  font-size: 12px;
  text-transform: uppercase;
}

.tag {
  display: inline-flex;
  align-items: center;
  min-height: 28px;
  padding: 4px 10px;
  border-radius: 8px;
  background: var(--accent-soft);
  color: #116f80;
  font-size: 12px;
  font-weight: 800;
}

.status-pill {
  display: inline-flex;
  align-items: center;
  min-height: 28px;
  padding: 4px 10px;
  border-radius: 8px;
  font-size: 12px;
  font-weight: 800;
}

.status-success {
  background: #e8f8ef;
  color: #167047;
}

.status-warning {
  background: #fff4dc;
  color: #9a650d;
}

.status-danger {
  background: #fff0ed;
  color: var(--danger);
}

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

.row-actions button {
  min-height: 34px;
  border-radius: 8px;
  padding: 7px 10px;
  background: var(--surface-alt);
  color: var(--primary-dark);
}

.row-actions .print {
  background: var(--accent-soft);
  color: #116f80;
}

.row-actions .reset {
  background: #fff4dc;
  color: #9a650d;
}

.row-actions .danger {
  background: #fff0ed;
  color: var(--danger);
}

.low {
  color: var(--warning);
  font-weight: 800;
}

.positive {
  color: var(--success);
  font-weight: 800;
}

.list-item {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  padding: 12px 0;
  border-bottom: 1px solid var(--line);
}

.list-item:last-child {
  border-bottom: 0;
}

.list-item span {
  color: var(--muted);
  font-size: 13px;
}

.list-empty {
  color: var(--muted);
  padding: 12px 0;
}

.sale-total {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  gap: 12px;
  background: linear-gradient(135deg, var(--surface-alt), var(--accent-soft));
  border-radius: 8px;
  padding: 14px;
}

.sale-total span {
  color: var(--muted);
}

.sale-total strong {
  display: block;
  margin-top: 6px;
  font-size: 20px;
}

.sale-total small {
  color: var(--muted);
  line-height: 1.4;
}

.report-filter {
  margin-bottom: 18px;
}

.report-controls {
  display: grid;
  grid-template-columns: repeat(2, minmax(180px, 1fr)) repeat(3, auto);
  gap: 12px;
  align-items: end;
}

.report-controls button {
  text-align: center;
  white-space: nowrap;
}

#printReportsButton {
  order: 1;
}

.report-metrics {
  margin-top: 0;
}

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

.chart-panel canvas {
  width: 100%;
  display: block;
}

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

.report-summary div,
.payment-row {
  background: linear-gradient(135deg, #fff, var(--surface-alt));
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 12px;
}

.report-summary span {
  color: var(--muted);
  display: block;
  font-size: 12px;
  font-weight: 700;
  margin-bottom: 6px;
}

.report-summary strong {
  color: var(--primary-dark);
  font-size: 20px;
}

.payment-report {
  display: grid;
  gap: 10px;
}

.payment-line {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 8px;
}

.payment-line span {
  white-space: nowrap;
}

.progress {
  height: 8px;
  overflow: hidden;
  border-radius: 999px;
  background: #f1e7f7;
}

.progress span {
  display: block;
  height: 100%;
  border-radius: inherit;
  background: linear-gradient(90deg, var(--primary), var(--accent));
}

.toast {
  position: fixed;
  right: 20px;
  bottom: 20px;
  background: var(--primary-dark);
  color: #fff;
  padding: 12px 16px;
  border-radius: 8px;
  opacity: 0;
  transform: translateY(10px);
  transition: .2s ease;
  pointer-events: none;
  max-width: 360px;
}

.toast.show {
  opacity: 1;
  transform: translateY(0);
}

.login-overlay {
  position: fixed;
  inset: 0;
  z-index: 20;
  display: none;
  place-items: center;
  padding: 20px;
  background: rgba(63, 49, 80, .28);
  backdrop-filter: blur(8px);
}

body.locked .login-overlay {
  display: grid;
}

body.locked .app-shell {
  pointer-events: none;
  filter: blur(2px);
}

.login-card {
  width: min(390px, 100%);
  display: grid;
  gap: 14px;
  padding: 24px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  box-shadow: 0 24px 70px rgba(89, 55, 112, .22);
}

.login-card img {
  width: 210px;
  max-width: 100%;
  margin: 0 auto 4px;
  border-radius: 8px;
}

.login-card h2,
.login-card p {
  margin: 0;
  text-align: center;
}

.login-card p {
  color: var(--muted);
  font-size: 12px;
}

.app-version-footer {
  margin-top: auto;
  padding-top: 4px;
  border-top: 1px solid rgba(181, 107, 221, .22);
  color: var(--muted);
  font-size: 12px;
  overflow-wrap: anywhere;
}

.app-version-footer strong {
  display: block;
}

.app-version-footer strong {
  color: var(--primary-dark);
}

@media (max-width: 980px) {
  .app-shell {
    grid-template-columns: 1fr;
  }

  .sidebar {
    min-height: auto;
    padding-bottom: 24px;
  }

  .nav {
    grid-template-columns: repeat(5, minmax(100px, 1fr));
    overflow-x: auto;
  }

  .app-version-footer {
    position: static;
    width: auto;
    margin-top: 0;
    background: transparent;
  }

  .backup-box {
    grid-template-columns: repeat(3, minmax(150px, 1fr));
  }

  .metrics,
  .split,
  .grid-two,
  .report-grid,
  .dashboard-grid,
  #dashboard .split {
    grid-template-columns: 1fr;
  }

  .report-controls {
    grid-template-columns: 1fr 1fr;
  }
}

@media (max-width: 640px) {
  .content,
  .sidebar {
    padding: 18px;
  }

  .topbar {
    align-items: stretch;
    flex-direction: column;
  }

  .user-badge {
    justify-content: space-between;
  }

  .backup-box,
  .dashboard-actions,
  .inline-fields,
  .report-controls,
  .report-summary {
    grid-template-columns: 1fr;
  }

  .topbar h2 {
    font-size: 24px;
  }
}
