.section-heading {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 16px;
  margin-bottom: 20px;
}

.eyebrow {
  color: var(--primary);
  font-size: 0.8rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  margin-bottom: 4px;
}

.section-heading h1,
.section-heading h2 {
  font-size: 1.5rem;
  font-family: var(--font-brand);
}

.section-icon {
  font-size: 1.4rem;
  color: var(--primary);
}

.summary-card {
  padding: 20px;
  border-radius: var(--radius-md);
  background: var(--background);
  margin-bottom: 20px;
}

.summary-card span {
  display: block;
  color: var(--text-muted);
  margin-bottom: 6px;
}

.summary-card strong {
  font-size: 2rem;
}

.chart-card {
  min-height: 320px;
  display: grid;
  place-items: center;
}

.upload-zone {
  border: 2px dashed var(--border);
  border-radius: var(--radius-md);
  padding: 42px 20px;
  text-align: center;
  transition: border-color var(--duration-base) var(--ease-standard),
              background-color var(--duration-base) var(--ease-standard),
              transform var(--duration-fast) var(--ease-standard);
}

.upload-zone.dragover {
  border-color: var(--primary);
  background: color-mix(in srgb, var(--primary-soft) 22%, var(--surface));
  transform: scale(1.01);
}

.upload-icon {
  font-size: 2.5rem;
  color: var(--primary);
  margin-bottom: 14px;
  transition: transform var(--duration-base) var(--ease-standard);
}

.upload-zone.dragover .upload-icon {
  transform: translateY(-3px);
}

.upload-zone h3 {
  margin-bottom: 8px;
}

.upload-zone p {
  color: var(--text-muted);
  margin-bottom: 20px;
}

.button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  border: 0;
  border-radius: var(--radius-sm);
  padding: 11px 16px;
  font-weight: 700;
  transition: background-color var(--duration-base) var(--ease-standard),
              transform var(--duration-fast) var(--ease-standard),
              box-shadow var(--duration-base) var(--ease-standard);
}

/* BUG FIX: icons inside buttons had no explicit size, so each Font Awesome
   glyph rendered at that icon's own natural bounding box instead of a
   shared size — some (like fa-file-csv) sit on a visibly wider/taller
   glyph box than a simple glyph like fa-xmark, so buttons side by side
   (e.g. "กรอง" / "ล้าง" / "ส่งออก CSV") showed one icon looking small and
   another looking oversized even at the same font-size. Pinning every
   button icon to the same fixed box fixes that regardless of which glyph
   it is. */
.button i {
  font-size: 15px;
  width: 1em;
  line-height: 1;
  text-align: center;
  flex-shrink: 0;
}

.button:hover {
  transform: translateY(-1px);
}

.button:active {
  transform: translateY(0) scale(0.98);
}

.button:disabled {
  opacity: 0.6;
  cursor: not-allowed;
  transform: none;
}

.button-primary {
  background: var(--primary);
  color: white;
}

.button-primary:hover:not(:disabled) {
  background: var(--primary-dark);
  box-shadow: var(--shadow-sm);
}

.button-secondary {
  background: var(--background);
  color: var(--text);
}

.button-secondary:hover:not(:disabled) {
  background: var(--border);
}

.button-text {
  background: transparent;
  color: var(--primary);
  padding: 8px 10px;
}

.button-text:hover:not(:disabled) {
  background: color-mix(in srgb, var(--primary-soft) 20%, transparent);
}

.status {
  margin-top: 16px;
  padding: 12px;
  border-radius: var(--radius-sm);
  background: var(--background);
  color: var(--text-muted);
  transition: color var(--duration-base) var(--ease-standard);
}

.status.success {
  color: var(--success);
}

.status.error {
  color: var(--danger);
}

.result-card {
  margin-top: 18px;
  padding: 18px;
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  /* Entrance animation is handled by GSAP (animateResultCardIn in
     animations.js) — a CSS `animation` here used to fight GSAP over
     opacity/transform and could leave the card stuck semi-transparent. */
}

.result-card h3 {
  margin-bottom: 14px;
}

.result-row {
  display: flex;
  justify-content: space-between;
  gap: 20px;
  padding: 10px 0;
  border-bottom: 1px solid var(--border);
}

.result-row:last-of-type {
  border-bottom: 0;
}

.result-row span {
  color: var(--text-muted);
}

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

/* BUG FIX: `.hidden` is a utility class meant to always win, but it sat
   earlier in this file than `.user-chip` (and other component rules) that
   also set `display`. Same specificity (one class each) + later source
   order = the component's `display` wins over `.hidden`'s `display: none`
   on any element carrying both classes — e.g. `<span class="user-chip
   hidden">` in the header. That's exactly why the little user-circle icon
   was showing next to "เข้าสู่ระบบ / สมัครสมาชิก" even as a guest: the
   *element* was correctly hidden by JS logic, but the CSS cascade
   overrode it back to visible. `!important` makes this utility class
   immune to source order, which is the whole point of a "hidden" toggle. */
.hidden {
  display: none !important;
}

@keyframes card-in {
  from {
    opacity: 0;
    transform: translateY(6px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

.spinner {
  display: inline-block;
  animation: spin 0.8s linear infinite;
}

/* ---------- User menu / brand lockup ---------- */

.brand-logo {
  height: 32px;
  width: auto;
  display: block;
}

.user-menu {
  display: flex;
  align-items: center;
  gap: 12px;
}

.user-chip {
  display: flex;
  align-items: center;
  gap: 8px;
  color: var(--text-muted);
  font-size: 0.9rem;
}

.user-chip i {
  color: var(--primary);
}

/* ---------- Auth pages ---------- */

.auth-shell {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px;
}

.auth-card {
  width: min(400px, 100%);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-md);
  padding: 32px 28px;
  /* Entrance animation is handled by GSAP (animatePageIn in
     animations.js) — a CSS `animation` here used to fight GSAP over
     opacity/transform and could leave the card stuck semi-transparent
     or invisible after navigating to this page. */
  position: relative;
}

.auth-back {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  background: none;
  border: none;
  padding: 4px 0;
  margin-bottom: 12px;
  color: var(--text-muted);
  font-size: 0.85rem;
  font-weight: 600;
  cursor: pointer;
  text-decoration: none;
  transition: color var(--duration-fast) var(--ease-standard);
}

.auth-back:hover {
  color: var(--primary);
}

.auth-brand {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
  margin-bottom: 24px;
  text-align: center;
}

.auth-brand img {
  height: 56px;
  width: auto;
}

.auth-brand strong {
  font-family: var(--font-brand);
  font-size: 1.4rem;
  color: var(--text);
}

.auth-brand span {
  color: var(--primary);
  font-size: 0.85rem;
  font-weight: 600;
}

.field {
  margin-bottom: 16px;
}

.field label {
  display: block;
  font-size: 0.85rem;
  font-weight: 700;
  margin-bottom: 6px;
  color: var(--text);
}

.field input {
  width: 100%;
  padding: 11px 14px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--background);
  color: var(--text);
  transition: border-color var(--duration-base) var(--ease-standard),
              box-shadow var(--duration-base) var(--ease-standard);
}

.field input:focus-visible,
.field select:focus-visible {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--primary) 22%, transparent);
}

.field select {
  width: 100%;
  padding: 11px 14px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--background);
  color: var(--text);
}

/* ---------- Filter bar ---------- */
/* REDESIGNED: was a single 4-column grid with the search field sharing a
   row with two date pickers, a select, and three same-weight buttons all
   crammed together. Now it's a soft card of its own, split into a top row
   (date range + category) and a bottom row (search + actions), with the
   primary "กรอง" action visually distinct from "ล้าง"/"ส่งออก CSV" so the
   eye lands on the one action that actually matters most. */

.filter-bar {
  display: flex;
  flex-direction: column;
  gap: 16px;
  margin-bottom: 20px;
  padding: 18px 20px;
  background: var(--background);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
}

.filter-bar-row {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 14px;
}

.filter-bar-row-bottom {
  grid-template-columns: 1fr auto;
  align-items: end;
}

.filter-field {
  margin-bottom: 0;
}

.filter-field-search {
  grid-column: 1;
}

.filter-search-input {
  position: relative;
  display: flex;
  align-items: center;
}

.filter-search-input i {
  position: absolute;
  left: 14px;
  color: var(--text-muted);
  font-size: 14px;
  pointer-events: none;
}

.filter-search-input input {
  width: 100%;
  padding-left: 38px;
}

.filter-actions {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  justify-content: flex-end;
}

.button-ghost {
  background: transparent;
  color: var(--text-muted);
  border: 1px solid var(--border);
}

.button-ghost:hover:not(:disabled) {
  background: var(--surface);
  color: var(--text);
}

@media (max-width: 720px) {
  .filter-bar-row,
  .filter-bar-row-bottom {
    grid-template-columns: 1fr;
  }

  .filter-actions {
    justify-content: stretch;
  }

  .filter-actions .button {
    flex: 1;
  }
}

/* ---------- Recent expenses list ---------- */

.expense-list {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.expense-empty {
  color: var(--text-muted);
  text-align: center;
  padding: 20px 0;
}

.expense-row {
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 14px 16px;
}

.expense-row-view {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
}

.expense-row-main {
  display: flex;
  flex-direction: column;
  gap: 2px;
  min-width: 0;
}

.expense-row-main strong {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.expense-row-meta {
  color: var(--text-muted);
  font-size: 0.85rem;
}

.expense-row-amount {
  font-weight: 700;
  white-space: nowrap;
}

.expense-row-actions {
  display: flex;
  gap: 4px;
  flex-shrink: 0;
}

.expense-row-edit {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 10px;
  margin-top: 4px;
}

.expense-row-edit input,
.expense-row-edit select {
  padding: 9px 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--background);
  color: var(--text);
}

.expense-row-edit .expense-row-actions {
  grid-column: 1 / -1;
  justify-content: flex-end;
}

.auth-card .button {
  width: 100%;
  margin-top: 6px;
}

.auth-switch {
  margin-top: 18px;
  text-align: center;
  color: var(--text-muted);
  font-size: 0.9rem;
}

.auth-switch a {
  color: var(--primary);
  font-weight: 700;
  text-decoration: none;
}

.auth-switch a:hover {
  text-decoration: underline;
}

.auth-status {
  min-height: 20px;
  margin-bottom: 14px;
  font-size: 0.88rem;
  color: var(--danger);
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.001ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.001ms !important;
    scroll-behavior: auto !important;
  }
}