:root {
  color-scheme: light;
  font-family: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  background: #f3f4f6;
  color: #111827;
}

body {
  margin: 0;
  background: #f3f4f6;
}

main {
  max-width: 1100px;
  margin: 0 auto;
  padding: 18px;
  padding-bottom: calc(104px + env(safe-area-inset-bottom));
}

.topbar {
  position: relative;
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 18px;
}

.topbar h1 {
  margin: 0 0 4px;
  font-size: 1.8rem;
}

.topbar p {
  margin: 0;
  color: #6b7280;
}

.settings-wrap {
  position: relative;
}

.icon-button {
  width: 44px;
  height: 44px;
  margin: 0;
  padding: 0;
  border-radius: 999px;
  background: white;
  color: #111827;
  box-shadow: 0 8px 24px rgba(15, 23, 42, 0.08);
}

.settings-menu {
  position: absolute;
  top: 52px;
  right: 0;
  z-index: 50;
  width: 240px;
  padding: 12px;
  border-radius: 16px;
  background: white;
  box-shadow: 0 18px 50px rgba(15, 23, 42, 0.22);
}

.settings-user {
  padding: 8px 4px 12px;
  color: #6b7280;
  font-size: 0.9rem;
  word-break: break-word;
}

h2,
p {
  margin-top: 0;
}

.card {
  background: white;
  border-radius: 20px;
  padding: 18px;
  margin-bottom: 18px;
  box-shadow: 0 8px 30px rgba(15, 23, 42, 0.08);
}

.app-page {
  display: none;
}

.app-page.active {
  display: block;
}

.mobile-nav {
  position: fixed;
  left: 10px;
  right: 10px;
  bottom: 10px;
  z-index: 40;
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 6px;
  padding: 8px;
  padding-bottom: calc(8px + env(safe-area-inset-bottom));
  border-radius: 22px;
  background: rgba(255, 255, 255, 0.94);
  box-shadow: 0 18px 50px rgba(15, 23, 42, 0.22);
  backdrop-filter: blur(14px);
}

.nav-button {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 3px;
  min-height: 54px;
  margin: 0;
  padding: 7px 4px;
  border-radius: 16px;
  background: transparent;
  color: #6b7280;
  font-size: 0.78rem;
}

.nav-button span {
  font-size: 1.15rem;
  line-height: 1;
}

.nav-button small {
  font-size: 0.68rem;
  font-weight: 800;
}

.nav-button.active {
  background: #111827;
  color: white;
}

label {
  display: block;
  margin-top: 14px;
  font-weight: 800;
}

input,
textarea,
select,
button {
  display: block;
  width: 100%;
  box-sizing: border-box;
  margin-top: 8px;
  padding: 12px;
  font: inherit;
}

input,
textarea,
select {
  border: 1px solid #d1d5db;
  border-radius: 12px;
  background: white;
}

textarea {
  min-height: 74px;
  resize: vertical;
}

button,
.button {
  cursor: pointer;
  border: 0;
  border-radius: 14px;
  background: #111827;
  color: white;
  font-weight: 800;
}

button:disabled {
  cursor: not-allowed;
  background: #d1d5db;
  color: #6b7280;
}

button.loading {
  opacity: 0.85;
}

button.secondary {
  background: #e5e7eb;
  color: #111827;
}

.button {
  display: block;
  text-align: center;
  text-decoration: none;
}

.actions-row {
  display: flex;
  gap: 10px;
  margin-top: 14px;
  margin-bottom: 14px;
  flex-wrap: wrap;
}

.actions-row button {
  flex: 1 1 160px;
}

.drop-zone {
  border: 2px dashed #cbd5e1;
  border-radius: 18px;
  padding: 18px;
  margin-top: 10px;
  text-align: center;
  background: #f8fafc;
  cursor: pointer;
  transition: border-color 0.15s ease, background 0.15s ease;
}

.drop-zone:hover,
.drop-zone.dragover {
  border-color: #2563eb;
  background: #eff6ff;
}

.drop-zone-icon {
  font-size: 2rem;
  margin-bottom: 6px;
}

.drop-zone strong {
  display: block;
  margin-bottom: 4px;
}

.drop-zone span {
  display: block;
  color: #6b7280;
  font-size: 0.92rem;
}

.file-preview {
  margin-top: 12px;
}

.file-info,
.pdf-preview {
  padding: 10px;
  border-radius: 12px;
  background: white;
  border: 1px solid #e5e7eb;
  font-weight: 800;
  text-align: left;
}

.file-preview img {
  width: 100%;
  max-height: 120px;
  border-radius: 14px;
  border: 1px solid #e5e7eb;
  margin-top: 10px;
  object-fit: contain;
  background: white;
}

#file {
  display: none;
}

.message {
  white-space: normal;
  background: #f3f4f6;
  color: #111827;
  padding: 12px;
  border-radius: 14px;
  font-weight: 800;
  margin-top: 14px;
  margin-bottom: 10px;
}

.message.success {
  background: #dcfce7;
}

.message.warning {
  background: #fef3c7;
}

.message.error {
  background: #fee2e2;
}

.message.info {
  background: #dbeafe;
}

.invoice {
  padding: 15px;
  border: 1px solid #e5e7eb;
  border-radius: 16px;
  margin-top: 12px;
  background: #fafafa;
  line-height: 1.45;
}

.invoice button {
  margin-top: 10px;
}

.invoice.selectable {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 12px;
  align-items: center;
}

.file-select-row {
  display: flex;
  align-items: flex-start;
  gap: 12px;
  margin: 0;
  font-weight: 400;
}

.file-select-row input[type="checkbox"] {
  width: auto;
  margin-top: 3px;
}

.file-select-row strong {
  font-weight: 900;
}

.file-select-row small {
  color: #6b7280;
}

.thumb {
  width: 74px;
  height: 74px;
  object-fit: cover;
  border-radius: 14px;
  border: 1px solid #e5e7eb;
  background: white;
}

.thumb.placeholder {
  display: grid;
  place-items: center;
  font-weight: 900;
  color: #6b7280;
  background: #f3f4f6;
}

.sticky-action {
  position: sticky;
  bottom: calc(92px + env(safe-area-inset-bottom));
  z-index: 10;
  margin-top: 18px;
  box-shadow: 0 12px 30px rgba(15, 23, 42, 0.25);
}

.summary-filters {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
  gap: 14px;
  margin-bottom: 16px;
}

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

.summary-card {
  background: #f8fafc;
  border: 1px solid #e5e7eb;
  border-radius: 16px;
  padding: 16px;
}

.summary-card strong {
  display: block;
  margin-bottom: 10px;
  color: #374151;
}

.summary-card span {
  font-size: 1.35rem;
  font-weight: 900;
  color: #111827;
}

.modal {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: grid;
  place-items: center;
  padding: 16px;
  background: rgba(15, 23, 42, 0.55);
  overflow-y: auto;
}

.modal-card {
  width: min(560px, 100%);
  max-height: calc(100vh - 32px);
  overflow-y: auto;
  background: white;
  border-radius: 18px;
  padding: 22px;
  box-shadow: 0 20px 60px rgba(15, 23, 42, 0.35);
}

.modal-actions {
  position: sticky;
  bottom: 0;
  display: grid;
  gap: 10px;
  margin-top: 18px;
  padding-top: 12px;
  background: white;
}

.hidden {
  display: none !important;
}

a {
  color: #1d4ed8;
  font-weight: 700;
}

@media (min-width: 801px) {
  main {
    padding-bottom: 120px;
  }

  .mobile-nav {
    left: 50%;
    right: auto;
    width: min(720px, calc(100% - 32px));
    transform: translateX(-50%);
  }
}

@media (max-width: 420px) {
  main {
    padding: 14px;
    padding-bottom: calc(104px + env(safe-area-inset-bottom));
  }

  .card {
    padding: 16px;
  }

  .topbar h1 {
    font-size: 1.6rem;
  }

  .topbar p {
    font-size: 0.9rem;
  }

  .invoice.selectable {
    grid-template-columns: 1fr;
  }

  .thumb {
    width: 100%;
    height: 130px;
    object-fit: contain;
  }

  .nav-button small {
    font-size: 0.62rem;
  }
}

#global-message-wrap {
  position: sticky;
  top: 12px;
  z-index: 60;
  margin-bottom: 12px;
}

#upload-result {
  margin: 0;
  box-shadow: 0 12px 30px rgba(15, 23, 42, 0.12);
}

.upload-actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  margin-top: 12px;
}

#file,
#camera-file {
  display: none;
}