:root {
  /* Palette Constants */
  --p-olive: #555a3f;
  --p-cream: #f7f5eb;
  --p-gold: #e2d8a6;
  --p-taupe: #beb39f;
  --p-charcoal: #1c1c1c;
  --p-blue: #c2d6dd;

  /* Dark Theme (Default) */
  --bg: var(--p-charcoal);
  --fg: var(--p-cream);
  --muted: var(--p-taupe);
  --card: #232323;
  /* Slightly lighter charcoal */
  --card2: #2a2a2a;
  --card-gradient-end: #222;
  /* Dark gradient end */
  --line: #333;
  --accent: var(--p-gold);
  --brand-color: var(--p-olive);
  --input-bg: #2a2a2a;

  --font-head: 'Marcellus', serif;
  --font-body: 'Tenor Sans', sans-serif;
}

[data-theme="light"] {
  --bg: var(--p-cream);
  --fg: var(--p-charcoal);
  --muted: #6b6b6b;
  --card: #ffffff;
  --card2: #f0f0e8;
  /* Slight cream tint */
  --card-gradient-end: #ffffff;
  /* Light gradient end (flat or subtle) */
  --line: #dcdcdc;
  --accent: var(--p-olive);
  /* Darker accent for light mode readability */
  --brand-color: var(--p-olive);
  --input-bg: #ffffff;
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--fg);
  font: 16px/1.4 var(--font-body);
  /* Reduced from 1.5 to 1.4 */
  font-variant-numeric: tabular-nums;
  transition: background 0.3s, color 0.3s;
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 10;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 20px;
  background: var(--bg);
  border-bottom: 1px solid var(--line);
  box-shadow: 0 4px 20px rgba(0, 0, 0, 0.1);
  position: relative;
  /* For absolute positioning context */
}

.logo-container {
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  z-index: 2;
  /* Above title */
}

.page-title {
  position: absolute;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%);
  font-family: var(--font-head);
  font-weight: 400;
  letter-spacing: 0.5px;
  font-size: 1.5em;
  color: var(--accent);
  white-space: nowrap;
  z-index: 1;
  /* Below logo and controls */
  pointer-events: none;
}

.controls {
  flex: 0 0 auto;
  display: flex;
  justify-content: flex-end;
  gap: 12px;
  align-items: center;
  z-index: 2;
  /* Above title */
}

.logo-img {
  height: 45px;
  width: auto;
  transition: filter 0.3s;
}

/* Dark Theme: Invert black logo to white */
:root:not([data-theme="light"]) .logo-img {
  filter: invert(1) brightness(2);
}

/* ... existing button styles ... */

.theme-btn {
  /* ... existing styles ... */
  background: transparent;
  border: 1px solid var(--line);
  color: var(--fg);
  padding: 6px 10px;
  border-radius: 50%;
  cursor: pointer;
  font-size: 1.2em;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 36px;
  height: 36px;
  transition: all 0.2s;
}

[data-theme="light"] .theme-btn {
  border-color: #999;
  color: #333;
  background: rgba(0, 0, 0, 0.05);
}

.theme-btn:hover {
  background: var(--card2);
}

/* RESTORED ICON LOGIC */
[data-theme="light"] .icon-sun {
  display: none;
}

[data-theme="dark"] .icon-moon {
  display: none;
}

/* Default (Dark) logic: hide moon */
:root:not([data-theme="light"]) .icon-moon {
  display: none;
}

.date-form {
  display: flex;
  gap: 8px;
  align-items: center;
}

/* Visibility Toggles for Responsive Payment Display */
.mobile-only {
  display: none !important;
}

.desktop-only {
  display: block !important;
}

/* Mobile optimization */
@media (max-width: 600px) {
  .topbar {
    flex-direction: column;
    gap: 16px;
    padding: 16px;
    align-items: center;
  }

  .logo-container {
    justify-content: center;
    order: 1;
  }

  .page-title {
    position: static;
    transform: none;
    text-align: center;
    font-size: 1.4em;
    order: 2;
    margin: 0;
  }

  .controls {
    order: 3;
    width: 100%;
    justify-content: center;
    flex-wrap: nowrap;
    /* Keep all in one line */
  }

  .date-form {
    flex: 1;
    max-width: none;
  }

  .date-form label {
    display: none;
    /* Hide label on mobile to save space */
  }

  .date-form input[type='date'] {
    flex: 1;
    min-width: 120px;
  }

  /* ... existing mobile styles ... */
  .mobile-only {
    display: block !important;
  }

  .desktop-only {
    display: none !important;
  }

  .container {
    padding: 0 10px;
    margin: 20px auto;
  }
}

/* ... existing styles ... */

.payment-list {
  display: flex;
  flex-direction: column;
}

.payment-row {
  display: flex;
  justify-content: space-between;
  padding: 12px 0;
  border-bottom: 1px solid var(--line);
  font-size: 15px;
}

.payment-row:last-child {
  border-bottom: 0;
}

.payment-label {
  color: var(--muted);
  font-weight: 500;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.payment-value {
  font-weight: 700;
  font-variant-numeric: tabular-nums;
}

.payment-row.total-row {
  border-top: 2px solid var(--line);
  /* This will be the single thick line */
  margin-top: 8px;
  padding-top: 16px;
  padding-bottom: 4px;
}

/* Remove border from the last data row to avoid double lines */
.payment-row:nth-last-child(2) {
  border-bottom: 0;
}

.payment-row.total-row .payment-label,
.payment-row.total-row .payment-value {
  color: var(--accent);
  font-size: 1.1em;
  font-weight: 800;
}

.date-form label {
  color: var(--muted);
  font-size: 14px;
}

.date-form input[type='date'] {
  background: var(--input-bg);
  color: var(--fg);
  border: 1px solid var(--line);
  padding: 8px 12px;
  border-radius: 8px;
  font-family: inherit;
  font-size: 14px;
}

.date-form input[type='date']:focus {
  outline: 2px solid var(--accent);
  border-color: transparent;
}

/* Fix calendar icon color */
.date-form input[type='date'] {
  color-scheme: dark;
  /* Default for Dark Mode */
}

[data-theme="light"] .date-form input[type='date'] {
  color-scheme: light;
  /* Force Light scheme for Light Mode */
}

.date-form input[type='date']::-webkit-calendar-picker-indicator {
  /* Default icon in dark scheme is already white. No invert needed. */
  opacity: 1;
  cursor: pointer;
}

.date-form button {
  background: var(--accent);
  color: var(--btn-text, #000);
  /* Use variable with fallback to black */
  border: 0;
  padding: 8px 16px;
  border-radius: 8px;
  font-weight: 700;
  cursor: pointer;
  transition: transform 0.1s, filter 0.2s;
}

[data-theme="light"] .date-form button {
  color: var(--p-cream);
  /* Light text on Dark Olive background */
}

.date-form button:hover {
  filter: brightness(1.1);
}

.date-form button:active {
  transform: scale(0.96);
}

.container {
  max-width: 1100px;
  margin: 32px auto;
  padding: 0 20px;
}

.hint,
.empty,
.error,
.loading {
  color: var(--muted);
  text-align: center;
  padding: 60px 0;
  font-size: 1.1em;
}

.error {
  color: #ff6b6b;
  background: rgba(255, 107, 107, 0.1);
  border-radius: 12px;
}

.store {
  margin-bottom: 32px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--card);
  box-shadow: 0 4px 6px rgba(0, 0, 0, 0.3);
  overflow: hidden;
}

.store-title {
  margin: 0;
  padding: 20px 24px;
  background: var(--card2);
  border-bottom: 1px solid var(--line);
  font-size: 1.25em;
  font-weight: 700;
  color: var(--accent);
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.subsec {
  padding: 24px;
}

.subsec+.subsec {
  border-top: 1px solid var(--line);
}

.subsec-title {
  font-weight: 700;
  /* Increased from 600 */
  text-transform: uppercase;
  font-size: 0.9em;
  /* Increased from 0.85em */
  letter-spacing: 1.2px;
  /* Increased from 1px */
  color: var(--fg);
  /* Changed from muted to fg for better visibility */
  margin-bottom: 20px;
  /* Increased from 16px for more separation */
  padding-bottom: 8px;
  /* Added padding */
  border-bottom: 1px solid var(--line);
  /* Added subtle separator */
}

.table-wrap {
  overflow-x: auto;
  border-radius: 8px;
  border: 1px solid var(--line);
  /* Restored border */
}

.tbl {
  width: 100%;
  border-collapse: collapse;
  font-size: 15px;
}

.tbl th,
.tbl td {
  padding: 14px 16px;
  border-bottom: 1px solid var(--line);
}

.tbl th {
  text-align: left;
  background: var(--card2);
  color: var(--muted);
  font-weight: 600;
  font-size: 0.9em;
  border-bottom: none !important;
  /* Force removal with !important */
}

.tbl tr:last-child td {
  border-bottom: 0;
}

.tbl td.right,
.tbl th.right {
  text-align: right;
}

.tbl td.total,
.tbl th.total {
  text-align: right;
  font-weight: 700;
  color: var(--accent);
  background: rgba(255, 215, 0, 0.05);
}

.tbl tfoot td {
  border-top: 2px solid var(--line);
  background: var(--card2);
  font-weight: 700;
}

.note {
  color: var(--muted);
  font-size: 0.85em;
  margin-top: 12px;
  background: rgba(255, 255, 255, 0.03);
  padding: 8px 12px;
  border-radius: 6px;
  display: inline-block;
}

.card {
  border: 1px solid var(--accent);
  /* Highlight the total card */
  border-radius: 12px;
  padding: 24px;
  /* Use theme-aware gradient */
  background: linear-gradient(135deg, var(--card2), var(--card-gradient-end));
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
  gap: 8px;
  box-shadow: 0 0 20px rgba(255, 215, 0, 0.05);
  /* Subtle glow */
}

.highlight {
  /* Class kept for JS compatibility, handling done in .card */
  display: block;
}

.big {
  font-size: 2.2em;
  /* Reduced from 3em */
  font-weight: 800;
  color: var(--accent);
  line-height: 1;
  text-shadow: 0 2px 10px rgba(0, 0, 0, 0.5);
}

.mini {
  color: var(--muted);
  font-size: 0.9em;
  font-family: monospace;
}

.foot {
  color: var(--muted);
  font-size: 0.85em;
  text-align: center;
  padding: 40px 0;
  border-top: 1px solid var(--line);
  margin-top: 60px;
  opacity: 0.6;
}