:root {
  --bg: #f3efe6;
  --bg-deep: #e7e0d2;
  --surface: rgba(255, 252, 246, 0.92);
  --ink: #1c241c;
  --muted: #5c675c;
  --line: #d5cdb8;
  --accent: #1f6b4a;
  --accent-2: #c45c26;
  --accent-soft: #d8efe3;
  --danger: #a33b2d;
  --warn: #9a6b12;
  --ok: #1f6b4a;
  --shadow: 0 18px 50px rgba(40, 48, 36, 0.08);
  --radius: 18px;
  --font: "Manrope", system-ui, sans-serif;
  --display: "Fraunces", Georgia, serif;
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

html {
  scroll-behavior: smooth;
}

body {
  margin: 0;
  min-height: 100vh;
  font-family: var(--font);
  color: var(--ink);
  background:
    radial-gradient(1200px 600px at 10% -10%, #dff0e4 0%, transparent 55%),
    radial-gradient(900px 500px at 100% 0%, #f4dcc8 0%, transparent 50%),
    linear-gradient(180deg, var(--bg), var(--bg-deep));
  line-height: 1.55;
  font-size: 16px;
}

.bg-glow {
  position: fixed;
  inset: 0;
  pointer-events: none;
  background-image: url("data:image/svg+xml,%3Csvg viewBox='0 0 200 200' xmlns='http://www.w3.org/2000/svg'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.85' numOctaves='2' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)' opacity='0.04'/%3E%3C/svg%3E");
  z-index: 0;
}

.site-header,
.main,
.site-footer {
  position: relative;
  z-index: 1;
}

.site-header {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 1rem;
  max-width: 1100px;
  margin: 0 auto;
  padding: 1.25rem 1.25rem 0.5rem;
}

.brand {
  display: inline-flex;
  align-items: center;
  gap: 0.65rem;
  text-decoration: none;
  color: var(--ink);
}

.brand-mark {
  display: grid;
  place-items: center;
  width: 40px;
  height: 40px;
  border-radius: 12px;
  background: var(--accent);
  color: #f7fff8;
}

.brand-text {
  font-family: var(--display);
  font-size: 1.45rem;
  font-weight: 700;
  letter-spacing: -0.02em;
}

.nav {
  display: flex;
  flex-wrap: wrap;
  gap: 0.35rem;
  margin-left: auto;
}

.nav-link {
  text-decoration: none;
  color: var(--muted);
  padding: 0.55rem 0.85rem;
  border-radius: 999px;
  min-height: 44px;
  display: inline-flex;
  align-items: center;
  transition: background 0.2s, color 0.2s;
  cursor: pointer;
}

.nav-link:hover,
.nav-link.is-active {
  background: rgba(31, 107, 74, 0.1);
  color: var(--accent);
}

.badge-warn {
  text-decoration: none;
  background: #fff3d6;
  color: var(--warn);
  border: 1px solid #ead39a;
  border-radius: 999px;
  padding: 0.4rem 0.75rem;
  font-size: 0.85rem;
  font-weight: 600;
  cursor: pointer;
}

.main {
  max-width: 1100px;
  margin: 0 auto;
  padding: 1rem 1.25rem 3rem;
}

.site-footer {
  max-width: 1100px;
  margin: 0 auto;
  padding: 0 1.25rem 2rem;
  color: var(--muted);
  font-size: 0.9rem;
}

.page-head {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  gap: 1rem;
  align-items: flex-end;
  margin: 1rem 0 1.5rem;
}

.user-bar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.55rem;
}

.user-name {
  font-weight: 600;
  color: var(--muted);
  font-size: 0.92rem;
}

.inline-form {
  display: inline;
  margin: 0;
}

.btn-sm {
  min-height: 36px;
  padding: 0.35rem 0.75rem;
  font-size: 0.9rem;
}

.auth-card {
  max-width: 460px;
  margin: 1.5rem auto;
}

.auth-form {
  display: grid;
  gap: 0.35rem;
  margin-top: 1.25rem;
}

.auth-switch {
  margin-top: 1.25rem;
  color: var(--muted);
}

.textarea {
  min-height: 220px;
  resize: vertical;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 0.88rem;
  line-height: 1.45;
}

.eyebrow {
  margin: 0;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  font-size: 0.75rem;
  font-weight: 600;
  color: var(--accent-2);
}

.page-title {
  margin: 0.2rem 0;
  font-family: var(--display);
  font-size: clamp(1.9rem, 4vw, 2.6rem);
  letter-spacing: -0.03em;
  line-height: 1.15;
}

.page-sub {
  margin: 0;
  color: var(--muted);
  max-width: 42rem;
}

.kpi-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 1rem;
  margin-bottom: 1.25rem;
}

.kpi-card,
.panel {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  backdrop-filter: blur(8px);
}

.kpi-card {
  padding: 1.15rem 1.25rem;
}

.kpi-label {
  margin: 0;
  color: var(--muted);
  font-size: 0.9rem;
}

.kpi-value {
  margin: 0.35rem 0 0;
  font-family: var(--display);
  font-size: 2rem;
  letter-spacing: -0.03em;
}

.currency {
  font-size: 1.1rem;
  color: var(--muted);
}

.panel {
  padding: 1.25rem;
  margin-bottom: 1.25rem;
}

.panel-head {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 1rem;
  margin-bottom: 1rem;
}

.panel-head h2 {
  margin: 0;
  font-size: 1.15rem;
  font-family: var(--display);
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.45rem;
  min-height: 44px;
  padding: 0.65rem 1.1rem;
  border-radius: 12px;
  border: 1px solid transparent;
  font: inherit;
  font-weight: 600;
  text-decoration: none;
  cursor: pointer;
  transition: transform 0.15s, background 0.2s, border-color 0.2s, opacity 0.2s;
}

.btn:hover {
  transform: translateY(-1px);
}

.btn:disabled {
  opacity: 0.55;
  cursor: not-allowed;
  transform: none;
}

.btn-primary {
  background: var(--accent);
  color: #f7fff8;
}

.btn-primary:hover {
  background: #18553b;
}

.btn-secondary {
  background: var(--accent-soft);
  color: var(--accent);
  border-color: #b7dcc8;
}

.btn-ghost {
  background: transparent;
  border-color: var(--line);
  color: var(--ink);
}

.btn-danger {
  background: #f8e8e5;
  color: var(--danger);
  border-color: #e7c4bd;
}

.btn-lg {
  width: 100%;
  margin-top: 1rem;
  min-height: 52px;
  font-size: 1.05rem;
}

.actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
}

.text-link {
  color: var(--accent);
  text-decoration: none;
  font-weight: 600;
  cursor: pointer;
}

.text-link:hover {
  text-decoration: underline;
}

.cat-bars {
  display: grid;
  gap: 0.85rem;
}

.cat-row {
  display: grid;
  gap: 0.35rem;
  text-decoration: none;
  color: inherit;
  cursor: pointer;
  padding: 0.35rem 0.15rem;
  border-radius: 10px;
  transition: background 0.2s;
}

.cat-row:hover {
  background: rgba(31, 107, 74, 0.05);
}

.cat-meta {
  display: flex;
  justify-content: space-between;
  gap: 1rem;
  font-weight: 600;
}

.cat-count {
  color: var(--muted);
  font-size: 0.85rem;
}

.bar-track {
  height: 8px;
  border-radius: 999px;
  background: #ebe4d4;
  overflow: hidden;
}

.bar-fill {
  height: 100%;
  background: linear-gradient(90deg, var(--accent), #3d9a6f);
  border-radius: inherit;
  min-width: 2px;
  transition: width 0.4s ease;
}

.receipt-cards {
  list-style: none;
  margin: 0;
  padding: 0;
  display: grid;
  gap: 0.75rem;
}

.receipt-card {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 1rem;
  align-items: center;
  padding: 1rem 1.1rem;
  border-radius: 14px;
  border: 1px solid var(--line);
  background: #fffcf7;
  text-decoration: none;
  color: inherit;
  cursor: pointer;
  transition: border-color 0.2s, box-shadow 0.2s;
}

.receipt-cards.dense .receipt-card {
  grid-template-columns: 64px 1fr auto;
}

.receipt-card:hover {
  border-color: #b7dcc8;
  box-shadow: 0 8px 24px rgba(40, 48, 36, 0.06);
}

.receipt-card-main {
  display: grid;
  gap: 0.15rem;
}

.receipt-card-sum {
  font-family: var(--display);
  font-size: 1.25rem;
  font-weight: 700;
  white-space: nowrap;
}

.receipt-thumb {
  width: 64px;
  height: 64px;
  border-radius: 10px;
  overflow: hidden;
  background: var(--bg-deep);
}

.receipt-thumb img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.muted {
  color: var(--muted);
  font-size: 0.92rem;
}

.empty-state {
  text-align: center;
  padding: 2rem 1rem;
  color: var(--muted);
}

.filter-row {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  margin-bottom: 1.25rem;
}

.chip {
  text-decoration: none;
  color: var(--muted);
  border: 1px solid var(--line);
  background: var(--surface);
  border-radius: 999px;
  padding: 0.45rem 0.9rem;
  min-height: 40px;
  display: inline-flex;
  align-items: center;
  cursor: pointer;
  transition: background 0.2s, color 0.2s;
}

.chip:hover,
.chip.is-active {
  background: var(--accent);
  border-color: var(--accent);
  color: #f7fff8;
}

.table-wrap {
  overflow-x: auto;
}

.data-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.95rem;
}

.data-table th,
.data-table td {
  text-align: left;
  padding: 0.7rem 0.55rem;
  border-bottom: 1px solid var(--line);
  vertical-align: top;
}

.data-table th {
  color: var(--muted);
  font-weight: 600;
  font-size: 0.82rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.detail-grid,
.detail-grid-single {
  display: grid;
  grid-template-columns: 1fr;
  gap: 1.25rem;
  align-items: start;
}

.meta-list {
  margin: 0;
  display: grid;
  gap: 0.85rem;
}

.meta-list > div {
  display: grid;
  gap: 0.15rem;
}

.meta-list dt {
  color: var(--muted);
  font-size: 0.85rem;
}

.meta-list dd {
  margin: 0;
  font-weight: 600;
}

.big-sum {
  font-family: var(--display);
  font-size: 2rem;
  font-weight: 700;
}

.receipt-photo {
  width: 100%;
  border-radius: 14px;
  border: 1px solid var(--line);
  display: block;
}

.photo-link {
  display: block;
  cursor: pointer;
}

.upload-panel,
.settings-panel {
  max-width: 640px;
}

.dropzone {
  position: relative;
  display: grid;
  justify-items: center;
  gap: 0.5rem;
  padding: 2rem 1.25rem;
  border: 2px dashed #c9d9c8;
  border-radius: 16px;
  background: linear-gradient(180deg, #f7fff9, #f4f0e6);
  text-align: center;
  cursor: pointer;
  transition: border-color 0.2s, background 0.2s;
}

.dropzone.is-drag {
  border-color: var(--accent);
  background: #eaf7ef;
}

.dropzone-title {
  font-weight: 700;
}

.dropzone-hint {
  color: var(--muted);
  font-size: 0.9rem;
}

.file-input {
  position: absolute;
  inset: 0;
  opacity: 0;
  cursor: pointer;
}

.preview-img {
  max-width: 100%;
  max-height: 280px;
  border-radius: 12px;
  margin-top: 0.75rem;
  border: 1px solid var(--line);
}

.field-label {
  display: block;
  font-weight: 600;
  margin-bottom: 0.4rem;
}

.text-input {
  width: 100%;
  min-height: 48px;
  border-radius: 12px;
  border: 1px solid var(--line);
  padding: 0.7rem 0.9rem;
  font: inherit;
  background: #fffcf7;
}

.text-input:focus {
  outline: 3px solid rgba(31, 107, 74, 0.25);
  border-color: var(--accent);
}

.field-help,
.field-error {
  font-size: 0.9rem;
  margin: 0.45rem 0 0;
}

.field-help {
  color: var(--muted);
}

.field-error {
  color: var(--danger);
}

.quick-links {
  display: flex;
  flex-wrap: wrap;
  gap: 0.65rem;
  margin-bottom: 1.25rem;
}

.settings-form {
  display: grid;
  gap: 0.35rem;
  margin-bottom: 1.25rem;
}

.masked-key {
  color: var(--muted);
  font-size: 0.92rem;
}

.callout {
  background: #f4f8f4;
  border: 1px solid #cfe0d4;
  border-radius: 14px;
  padding: 1rem 1.1rem;
  color: var(--muted);
}

.callout-warn {
  background: #fff7e8;
  border-color: #ead39a;
  color: #6d5215;
  margin-bottom: 1rem;
}

.callout-error {
  background: #fdf0ee;
  border-color: #e7c4bd;
  color: var(--danger);
  margin-bottom: 1rem;
}

.flash-list {
  list-style: none;
  margin: 0 0 1rem;
  padding: 0;
  display: grid;
  gap: 0.5rem;
}

.flash {
  padding: 0.85rem 1rem;
  border-radius: 12px;
  border: 1px solid var(--line);
  background: var(--surface);
}

.flash-success {
  background: #eaf7ef;
  border-color: #b7dcc8;
  color: var(--ok);
}

.flash-error {
  background: #fdf0ee;
  border-color: #e7c4bd;
  color: var(--danger);
}

.status {
  font-weight: 600;
}

.status-done { color: var(--ok); }
.status-error { color: var(--danger); }
.status-processing,
.status-pending { color: var(--warn); }

@media (max-width: 860px) {
  .kpi-grid,
  .detail-grid {
    grid-template-columns: 1fr;
  }

  .nav {
    margin-left: 0;
    width: 100%;
  }

  .receipt-cards.dense .receipt-card {
    grid-template-columns: 56px 1fr;
  }

  .receipt-cards.dense .receipt-card-sum {
    grid-column: 2;
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation: none !important;
    transition: none !important;
    scroll-behavior: auto !important;
  }
}
