:root {
  --bg: #06111f;
  --panel: rgba(12, 26, 45, 0.92);
  --panel-strong: rgba(18, 35, 58, 0.96);
  --border: rgba(148, 163, 184, 0.18);
  --text: #f8fafc;
  --muted: #94a3b8;
  --primary: #3b82f6;
  --primary-strong: #2563eb;
  --danger: #ef4444;
  --success: #22c55e;
  --warning: #f59e0b;
  --shadow: 0 24px 70px rgba(0, 0, 0, 0.35);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  color: var(--text);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  background: radial-gradient(circle at top left, #1d4ed8 0, transparent 28rem),
              radial-gradient(circle at bottom right, #0891b2 0, transparent 32rem),
              var(--bg);
}

.background-grid {
  position: fixed;
  inset: 0;
  pointer-events: none;
  opacity: 0.36;
  background-image:
    linear-gradient(rgba(96, 165, 250, 0.12) 1px, transparent 1px),
    linear-gradient(90deg, rgba(96, 165, 250, 0.12) 1px, transparent 1px);
  background-size: 34px 34px;
  mask-image: linear-gradient(to bottom, black, transparent 85%);
}

a {
  color: #93c5fd;
  text-decoration: none;
}

a:hover {
  color: #bfdbfe;
}

.sidebar {
  position: fixed;
  inset: 0 auto 0 0;
  width: 280px;
  padding: 24px;
  display: flex;
  flex-direction: column;
  gap: 28px;
  background: rgba(4, 13, 27, 0.78);
  border-right: 1px solid var(--border);
  backdrop-filter: blur(18px);
  z-index: 2;
}

.brand {
  display: flex;
  align-items: center;
  gap: 14px;
}

.brand-mark {
  width: 44px;
  height: 44px;
  display: grid;
  place-items: center;
  border-radius: 14px;
  background: linear-gradient(135deg, var(--primary), #06b6d4);
  color: white;
  font-weight: 900;
  box-shadow: 0 14px 40px rgba(37, 99, 235, 0.35);
}

.brand-mark.large {
  width: 62px;
  height: 62px;
  border-radius: 18px;
  margin: 0 auto 16px;
  font-size: 1.25rem;
}

.brand-title {
  font-weight: 800;
  letter-spacing: -0.03em;
}

.brand-subtitle {
  color: var(--muted);
  font-size: 0.86rem;
}

nav {
  display: grid;
  gap: 10px;
}

.nav-link {
  display: block;
  padding: 13px 14px;
  border: 1px solid transparent;
  border-radius: 14px;
  color: #dbeafe;
  background: rgba(255, 255, 255, 0.035);
}

.nav-link:hover,
.primary-link {
  background: rgba(59, 130, 246, 0.18);
  border-color: rgba(96, 165, 250, 0.35);
  color: white;
}

.sidebar-footer {
  margin-top: auto;
  display: grid;
  gap: 12px;
}

.user-pill {
  padding: 12px;
  border-radius: 16px;
  background: rgba(255, 255, 255, 0.06);
  border: 1px solid var(--border);
}

.user-pill span,
.user-pill small {
  display: block;
}

.user-pill small {
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.08em;
  font-size: 0.72rem;
  margin-top: 2px;
}

.logout-link {
  color: #fecaca;
}

.main {
  position: relative;
  z-index: 1;
  margin-left: 280px;
  padding: 34px;
  min-height: 100vh;
}

.auth-main {
  position: relative;
  z-index: 1;
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px;
}

.card {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 24px;
  box-shadow: var(--shadow);
  backdrop-filter: blur(18px);
}

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

h1,
h2,
h3,
p {
  margin-top: 0;
}

h1 {
  font-size: clamp(2rem, 3vw, 3rem);
  letter-spacing: -0.055em;
  margin-bottom: 7px;
}

h2 {
  letter-spacing: -0.035em;
}

p {
  color: var(--muted);
  line-height: 1.55;
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 42px;
  padding: 10px 16px;
  border: 1px solid transparent;
  border-radius: 14px;
  color: white;
  background: rgba(255, 255, 255, 0.08);
  cursor: pointer;
  font-weight: 750;
  font-size: 0.95rem;
}

.btn:hover {
  color: white;
  transform: translateY(-1px);
}

.btn-primary {
  background: linear-gradient(135deg, var(--primary), var(--primary-strong));
  box-shadow: 0 14px 34px rgba(37, 99, 235, 0.28);
}

.btn-secondary {
  background: rgba(148, 163, 184, 0.14);
  border-color: rgba(148, 163, 184, 0.18);
}

.btn-ghost {
  color: #cbd5e1;
  background: transparent;
  border-color: var(--border);
}

.btn-danger {
  background: rgba(239, 68, 68, 0.14);
  border-color: rgba(239, 68, 68, 0.35);
  color: #fecaca;
}

.btn-small {
  min-height: 34px;
  padding: 7px 11px;
  border-radius: 11px;
  font-size: 0.82rem;
}

.button-row {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
}

.flash-wrap {
  display: grid;
  gap: 10px;
  margin-bottom: 18px;
}

.flash {
  padding: 13px 16px;
  border-radius: 16px;
  border: 1px solid var(--border);
  background: rgba(255, 255, 255, 0.08);
}

.flash-success {
  border-color: rgba(34, 197, 94, 0.35);
  background: rgba(34, 197, 94, 0.1);
}

.flash-danger {
  border-color: rgba(239, 68, 68, 0.35);
  background: rgba(239, 68, 68, 0.1);
}

.flash-warning {
  border-color: rgba(245, 158, 11, 0.35);
  background: rgba(245, 158, 11, 0.1);
}

.login-card {
  width: min(440px, 100%);
  padding: 34px;
}

.login-brand {
  text-align: center;
  margin-bottom: 28px;
}

.login-brand h1 {
  margin-bottom: 6px;
}

.form-card,
.filters-card {
  padding: 24px;
}

.form-stack {
  display: grid;
  gap: 18px;
}

label {
  display: grid;
  gap: 8px;
  font-weight: 700;
  color: #e2e8f0;
}

input,
select,
textarea {
  width: 100%;
  border: 1px solid rgba(148, 163, 184, 0.22);
  border-radius: 14px;
  background: rgba(15, 23, 42, 0.85);
  color: var(--text);
  padding: 12px 13px;
  font: inherit;
  outline: none;
}

input:focus,
select:focus,
textarea:focus {
  border-color: rgba(96, 165, 250, 0.72);
  box-shadow: 0 0 0 4px rgba(59, 130, 246, 0.12);
}

small {
  color: var(--muted);
  font-weight: 500;
}

.info-box {
  padding: 14px;
  border-radius: 16px;
  background: rgba(59, 130, 246, 0.1);
  border: 1px solid rgba(96, 165, 250, 0.2);
  color: #dbeafe;
}

.stats-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 16px;
  margin-bottom: 20px;
}

.stat-card {
  padding: 22px;
}

.stat-card span {
  color: var(--muted);
}

.stat-card strong {
  display: block;
  font-size: 2.2rem;
  margin-top: 8px;
  letter-spacing: -0.06em;
}

.section-title-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  padding: 22px 22px 0;
}

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

table {
  width: 100%;
  border-collapse: collapse;
}

th,
td {
  text-align: left;
  padding: 14px 18px;
  border-bottom: 1px solid var(--border);
  vertical-align: top;
}

th {
  color: #cbd5e1;
  font-size: 0.82rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
}

tr:last-child td {
  border-bottom: none;
}

code {
  color: #bae6fd;
  background: rgba(14, 165, 233, 0.08);
  border: 1px solid rgba(14, 165, 233, 0.15);
  border-radius: 9px;
  padding: 3px 6px;
  white-space: normal;
}

.badge {
  display: inline-flex;
  align-items: center;
  padding: 5px 9px;
  border-radius: 999px;
  background: rgba(59, 130, 246, 0.13);
  border: 1px solid rgba(96, 165, 250, 0.26);
  color: #bfdbfe;
  text-transform: capitalize;
  font-size: 0.82rem;
  font-weight: 800;
}

.empty-state {
  padding: 44px 22px;
  text-align: center;
}

.filters-grid {
  display: grid;
  grid-template-columns: repeat(6, minmax(0, 1fr));
  gap: 14px;
  align-items: end;
}

.filter-actions {
  display: flex;
  gap: 10px;
  align-items: end;
  flex-wrap: wrap;
}

.receipt-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 18px;
  padding: 20px;
}

.receipt-card {
  overflow: hidden;
  border: 1px solid var(--border);
  border-radius: 20px;
  background: rgba(255, 255, 255, 0.045);
}

.receipt-preview {
  display: grid;
  place-items: center;
  height: 260px;
  background: rgba(255, 255, 255, 0.04);
  overflow: hidden;
}

.receipt-preview img,
.preview-panel img {
  width: 100%;
  height: 100%;
  object-fit: contain;
  background: white;
}

.receipt-card-body {
  padding: 16px;
}

.receipt-card-body h3 {
  margin-bottom: 6px;
  letter-spacing: -0.025em;
}

.receipt-card-body p {
  margin-bottom: 12px;
  font-size: 0.92rem;
}

.receipt-meta {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 13px;
  color: var(--muted);
}

.detail-grid {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 360px;
  gap: 20px;
  align-items: start;
}

.preview-panel {
  min-height: 680px;
  overflow: hidden;
  padding: 18px;
}

.detail-panel {
  padding: 24px;
  position: sticky;
  top: 24px;
}

dl {
  display: grid;
  gap: 10px;
  margin: 0 0 22px;
}

dt {
  color: var(--muted);
  font-size: 0.78rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
}

dd {
  margin: 0 0 8px;
  word-break: break-word;
}

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

.inline-reset {
  display: flex;
  gap: 8px;
  align-items: center;
}

.inline-reset input {
  width: 160px;
  padding: 7px 10px;
  border-radius: 10px;
}

.error-card {
  padding: 32px;
  width: min(680px, 100%);
}

@media (max-width: 1120px) {
  .stats-grid,
  .receipt-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .filters-grid {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }

  .detail-grid {
    grid-template-columns: 1fr;
  }

  .detail-panel {
    position: static;
  }
}

@media (max-width: 820px) {
  .sidebar {
    position: static;
    width: auto;
    min-height: auto;
  }

  .main {
    margin-left: 0;
    padding: 20px;
  }

  nav {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .page-header {
    align-items: flex-start;
    flex-direction: column;
  }

  .stats-grid,
  .receipt-grid,
  .filters-grid {
    grid-template-columns: 1fr;
  }

  .receipt-preview {
    height: 220px;
  }

  .preview-panel {
    min-height: 420px;
  }
}


.install-pwa-btn {
  position: fixed;
  right: 18px;
  bottom: 18px;
  z-index: 20;
  border: 1px solid rgba(96, 165, 250, 0.42);
  border-radius: 999px;
  color: white;
  background: linear-gradient(135deg, var(--primary), var(--primary-strong));
  box-shadow: 0 18px 44px rgba(37, 99, 235, 0.38);
  padding: 12px 18px;
  font-weight: 850;
  cursor: pointer;
}

.install-pwa-btn:hover {
  transform: translateY(-1px);
}

@media (display-mode: standalone) {
  .install-pwa-btn {
    display: none !important;
  }
}

@media (max-width: 560px) {
  body {
    -webkit-tap-highlight-color: transparent;
  }

  .sidebar {
    padding: 16px;
    gap: 16px;
  }

  .brand-mark {
    width: 38px;
    height: 38px;
    border-radius: 12px;
  }

  nav {
    grid-template-columns: 1fr 1fr;
    gap: 8px;
  }

  .nav-link {
    text-align: center;
    padding: 11px 10px;
    border-radius: 12px;
  }

  .main {
    padding: 16px;
  }

  .form-card,
  .filters-card,
  .login-card {
    padding: 18px;
    border-radius: 20px;
  }

  .btn {
    width: 100%;
    min-height: 48px;
  }

  input,
  select,
  textarea {
    font-size: 16px;
  }

  .install-pwa-btn {
    left: 16px;
    right: 16px;
    width: calc(100% - 32px);
  }
}

.crop-card {
  border: 1px solid rgba(148, 163, 184, 0.22);
  border-radius: 18px;
  padding: 16px;
  background: rgba(15, 23, 42, 0.48);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.04);
}

.crop-card[hidden] {
  display: none !important;
}

.crop-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 14px;
}

.crop-header strong {
  display: block;
  color: var(--text);
  font-size: 1rem;
}

.crop-header small,
.crop-help {
  display: block;
  color: var(--muted);
  line-height: 1.45;
}

.crop-mode-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 10px;
  margin-bottom: 14px;
}

.crop-mode-option {
  cursor: pointer;
  border: 1px solid rgba(148, 163, 184, 0.25);
  border-radius: 15px;
  padding: 12px;
  background: rgba(2, 6, 23, 0.38);
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 4px 8px;
  align-items: start;
}

.crop-mode-option input {
  width: auto;
  margin-top: 3px;
  accent-color: var(--primary);
}

.crop-mode-option span {
  color: var(--text);
  font-weight: 800;
}

.crop-mode-option small {
  grid-column: 2;
  color: var(--muted);
}

.crop-mode-option:has(input:checked) {
  border-color: rgba(34, 211, 238, 0.65);
  box-shadow: 0 0 0 3px rgba(34, 211, 238, 0.12);
  background: rgba(14, 165, 233, 0.14);
}

.crop-canvas-wrap {
  display: grid;
  place-items: center;
  border: 1px dashed rgba(148, 163, 184, 0.28);
  border-radius: 16px;
  overflow: hidden;
  background: rgba(2, 6, 23, 0.55);
  min-height: 240px;
  touch-action: none;
}

#cropCanvas {
  display: block;
  max-width: 100%;
  height: auto;
  cursor: grab;
  user-select: none;
  touch-action: none;
}

#cropCanvas:active {
  cursor: grabbing;
}

.crop-actions {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  margin-top: 12px;
}

.crop-help {
  margin: 12px 0 0;
  font-size: 0.9rem;
}

@media (max-width: 720px) {
  .crop-mode-grid {
    grid-template-columns: 1fr;
  }

  .crop-card {
    padding: 12px;
  }

  .crop-canvas-wrap {
    min-height: 220px;
  }
}


.file-choice-block {
  display: grid;
  gap: 12px;
}

.file-choice-title {
  font-weight: 800;
  color: #e2e8f0;
}

.file-choice-note {
  margin: 0;
  font-size: 0.94rem;
}

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

.file-choice-card {
  cursor: pointer;
  display: grid;
  gap: 6px;
  border: 1px solid rgba(96, 165, 250, 0.25);
  border-radius: 18px;
  padding: 18px;
  background: rgba(59, 130, 246, 0.10);
  transition: transform 0.16s ease, border-color 0.16s ease, background 0.16s ease;
}

.file-choice-card:hover {
  transform: translateY(-1px);
  border-color: rgba(96, 165, 250, 0.55);
  background: rgba(59, 130, 246, 0.16);
}

.file-choice-card span:not(.file-choice-icon) {
  font-weight: 900;
  color: var(--text);
}

.file-choice-icon {
  width: 44px;
  height: 44px;
  display: grid;
  place-items: center;
  border-radius: 14px;
  background: rgba(255, 255, 255, 0.10);
  font-size: 1.35rem;
}

.visually-hidden-file {
  position: absolute;
  width: 1px;
  height: 1px;
  opacity: 0;
  overflow: hidden;
  pointer-events: none;
}

.selected-files {
  padding: 13px 14px;
  border: 1px solid rgba(34, 197, 94, 0.28);
  border-radius: 16px;
  background: rgba(34, 197, 94, 0.08);
}

.selected-files strong {
  display: block;
  margin-bottom: 8px;
}

.selected-files ul {
  margin: 0;
  padding-left: 18px;
  color: var(--muted);
}

.selected-files li {
  margin: 4px 0;
  word-break: break-word;
}

@media (max-width: 720px) {
  .file-choice-grid {
    grid-template-columns: 1fr;
  }
}
