/* ── Reset & Base ── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --blue-dark:  #1F4E79;
  --blue:       #2E75B6;
  --blue-light: #D6E4F0;
  --green:      #1E7E34;
  --red:        #C0392B;
  --gray-0:     #F8F9FA;
  --gray-1:     #E9ECEF;
  --gray-2:     #CED4DA;
  --gray-4:     #6C757D;
  --gray-8:     #212529;
  --radius:     12px;
  --shadow:     0 2px 12px rgba(0,0,0,.12);
}

html, body {
  height: 100%;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  background: var(--gray-0);
  color: var(--gray-8);
  -webkit-font-smoothing: antialiased;
}

/* ── Screens ── */
.screen { display: none; min-height: 100dvh; flex-direction: column; }
.screen.active { display: flex; }

.screen-body {
  flex: 1;
  padding: 20px 16px 32px;
  overflow-y: auto;
}
.screen-body.center {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 20px;
  text-align: center;
}

/* ── Header ── */
.app-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: var(--blue-dark);
  color: #fff;
  padding: 14px 16px;
  min-height: 56px;
}
.header-title { font-size: 1.05rem; font-weight: 600; }

.btn-icon {
  background: none;
  border: none;
  color: #fff;
  cursor: pointer;
  padding: 4px;
  display: flex;
  align-items: center;
  border-radius: 6px;
}
.btn-icon svg { width: 22px; height: 22px; }
.btn-icon:hover { background: rgba(255,255,255,.15); }

/* ── Login ── */
#screen-login {
  background: linear-gradient(160deg, var(--blue-dark) 0%, var(--blue) 100%);
  align-items: center;
  justify-content: center;
  padding: 24px;
}

.login-card {
  background: #fff;
  border-radius: var(--radius);
  padding: 32px 24px;
  width: 100%;
  max-width: 380px;
  box-shadow: var(--shadow);
  text-align: center;
}

.logo-wrap {
  margin: 0 auto 12px;
  display: flex;
  align-items: center;
  justify-content: center;
}
.login-logo {
  width: 200px;
  max-width: 100%;
  height: auto;
}

.subtitle { color: var(--gray-4); font-size: .9rem; margin-bottom: 24px; }

/* ── Fields ── */
.field { margin-bottom: 16px; text-align: left; }
.field label {
  display: block;
  font-size: .8rem;
  font-weight: 600;
  color: var(--gray-4);
  text-transform: uppercase;
  letter-spacing: .04em;
  margin-bottom: 6px;
}
.field input {
  width: 100%;
  padding: 12px 14px;
  border: 1.5px solid var(--gray-2);
  border-radius: 8px;
  font-size: 1rem;
  background: #fff;
  transition: border-color .2s;
  -webkit-appearance: none;
}
.field input:focus,
.field textarea:focus {
  outline: none;
  border-color: var(--blue);
  box-shadow: 0 0 0 3px var(--blue-light);
}

.field textarea {
  width: 100%;
  padding: 12px 14px;
  border: 1.5px solid var(--gray-2);
  border-radius: 8px;
  font-size: 1rem;
  font-family: inherit;
  background: #fff;
  transition: border-color .2s;
  resize: vertical;
  min-height: 72px;
}

.optional {
  font-weight: 400;
  text-transform: none;
  color: var(--gray-4);
  font-size: .75rem;
  letter-spacing: 0;
}
.required-mark {
  color: var(--red);
  font-weight: 700;
  margin-left: 2px;
}

/* ── Buttons ── */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 13px 22px;
  border: none;
  border-radius: 10px;
  font-size: 1rem;
  font-weight: 600;
  cursor: pointer;
  transition: opacity .15s, transform .1s;
  -webkit-tap-highlight-color: transparent;
}
.btn:active { transform: scale(.97); }
.btn:disabled { opacity: .45; cursor: not-allowed; }

.btn-primary { background: var(--blue-dark); color: #fff; }
.btn-primary:hover:not(:disabled) { background: var(--blue); }

.btn-secondary {
  background: #fff;
  color: var(--blue-dark);
  border: 1.5px solid var(--blue-dark);
}

.btn-full { width: 100%; margin-top: 8px; }

/* Capture button — big, prominent */
.btn-capture {
  background: var(--blue-dark);
  color: #fff;
  flex-direction: column;
  gap: 10px;
  padding: 28px 40px;
  border-radius: 20px;
  font-size: 1.1rem;
  box-shadow: var(--shadow);
}
.btn-capture svg { width: 44px; height: 44px; }

/* Payment type buttons */
.payment-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  margin-bottom: 20px;
}
.payment-grid .btn-payment:last-child {
  grid-column: 1 / -1;
}

.btn-payment {
  background: #fff;
  color: var(--gray-8);
  border: 2px solid var(--gray-2);
  border-radius: 10px;
  flex-direction: column;
  gap: 4px;
  padding: 14px 10px;
  font-size: .9rem;
  line-height: 1.3;
  text-align: center;
}
.btn-payment small { color: var(--gray-4); font-weight: 400; }
.btn-payment.selected {
  border-color: var(--blue-dark);
  background: var(--blue-light);
  color: var(--blue-dark);
}
.payment-icon { font-size: 1.6rem; }

/* ── Welcome / camera screen ── */
.welcome-text { margin-bottom: 8px; }
.welcome-text p:first-child { font-size: 1.2rem; font-weight: 600; color: var(--blue-dark); }

.hint { color: var(--gray-4); font-size: .9rem; }
.hint.small { font-size: .82rem; margin-bottom: 4px; }

.or-divider { color: var(--gray-4); font-size: .85rem; margin: 4px 0; }

/* ── Section labels ── */
.section-label {
  font-size: .78rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .06em;
  color: var(--blue-dark);
  margin: 20px 0 8px;
}

/* ── Receipt preview ── */
.receipt-preview-wrap {
  width: 100%;
  max-height: 220px;
  overflow: hidden;
  border-radius: var(--radius);
  border: 1.5px solid var(--gray-2);
  background: var(--gray-1);
  display: flex;
  align-items: center;
  justify-content: center;
  margin-bottom: 8px;
}
#receipt-preview {
  width: 100%;
  max-height: 220px;
  object-fit: contain;
}

/* ── Spinner ── */
.spinner {
  width: 52px;
  height: 52px;
  border: 5px solid var(--blue-light);
  border-top-color: var(--blue-dark);
  border-radius: 50%;
  animation: spin .8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

.status-msg { color: var(--gray-4); font-size: .95rem; }

/* ── Success ── */
.success-icon {
  width: 72px;
  height: 72px;
  background: var(--green);
  color: #fff;
  border-radius: 50%;
  font-size: 2.2rem;
  display: flex;
  align-items: center;
  justify-content: center;
}

.summary-card {
  background: #fff;
  border-radius: var(--radius);
  border: 1.5px solid var(--gray-1);
  box-shadow: var(--shadow);
  width: 100%;
  max-width: 360px;
  overflow: hidden;
  margin-bottom: 8px;
}
.summary-row {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  padding: 12px 16px;
  border-bottom: 1px solid var(--gray-1);
  gap: 12px;
}
.summary-row:last-child { border-bottom: none; }
.summary-label { font-size: .82rem; color: var(--gray-4); font-weight: 600; text-transform: uppercase; white-space: nowrap; }
.summary-value { font-size: .95rem; font-weight: 600; text-align: right; }
.summary-value.filename { font-size: .78rem; word-break: break-all; color: var(--blue-dark); }

/* ── Errors ── */
.error-msg {
  background: #FDE8E8;
  color: var(--red);
  border: 1px solid #F5C6CB;
  border-radius: 8px;
  padding: 10px 14px;
  font-size: .9rem;
  margin: 8px 0;
}
.hidden { display: none !important; }

/* ── Banners + pills ── */
.install-banner {
  position: sticky; top: 0; z-index: 30;
  background: var(--blue-dark); color: #fff;
  padding: 10px 14px;
  display: flex; align-items: center; gap: 8px;
  font-size: .9rem;
}
.install-banner .btn-sm { padding: 6px 12px; font-size: .85rem; }
.install-banner .btn-icon { color: #fff; margin-left: auto; }

.offline-banner {
  position: sticky; top: 0; z-index: 29;
  background: #f59e0b; color: #1a1a1a;
  padding: 8px 14px; text-align: center; font-size: .85rem;
}

.queue-pill {
  background: #fff7ed; color: #9a3412; border: 1px solid #fdba74;
  padding: 8px 12px; border-radius: 999px; font-size: .85rem; font-weight: 600;
}

.parse-pill {
  display: inline-block; background: var(--blue-light); color: var(--blue-dark);
  border-radius: 999px; padding: 2px 8px; font-size: .7rem; font-weight: 700;
  margin-left: 6px; vertical-align: middle;
}

/* ── Forms ── */
.checkbox-row {
  display: flex; align-items: center; gap: 8px;
  font-size: .9rem; color: var(--gray-4); margin: 8px 0;
}
.checkbox-row input { width: 18px; height: 18px; }

.field.two-col {
  display: grid; grid-template-columns: 1fr 1fr; gap: 10px;
}
.field.two-col > div > label { display: block; }

.btn-link {
  background: none; border: none; color: var(--blue);
  text-decoration: underline; cursor: pointer; padding: 8px;
  font-size: .9rem; display: block; margin: 8px auto 0; width: 100%;
}

/* ── Recent list ── */
.recent-list { display: flex; flex-direction: column; gap: 8px; }
.recent-item {
  background: #fff; border: 1px solid var(--gray-1);
  border-radius: 8px; padding: 10px 12px; font-size: .9rem;
}
.recent-line { line-height: 1.5; }
.recent-line .muted { color: var(--gray-4); margin-left: 6px; font-size: .82rem; }

/* ── Admin ── */
.btn-row { display: flex; flex-wrap: wrap; gap: 8px; margin: 8px 0; }
.btn-row .btn { padding: 8px 14px; font-size: .85rem; }
.admin-section { margin-bottom: 28px; }
.admin-section h2 { font-size: 1.1rem; margin-bottom: 12px; color: var(--blue-dark); }
.admin-table {
  width: 100%; border-collapse: collapse; font-size: .85rem; background: #fff;
  border: 1px solid var(--gray-1); border-radius: 8px; overflow: hidden;
}
.admin-table th, .admin-table td {
  padding: 8px 10px; text-align: left; border-bottom: 1px solid var(--gray-1);
}
.admin-table th { background: var(--gray-0); font-weight: 700; color: var(--gray-8); }
.admin-table tr:last-child td { border-bottom: none; }
.admin-table button {
  background: var(--blue-light); color: var(--blue-dark); border: none;
  padding: 5px 10px; border-radius: 6px; font-size: .8rem; cursor: pointer; margin-right: 4px;
}

/* ── Tablets / desktop ── */
@media (min-width: 480px) {
  .screen-body { max-width: 520px; margin: 0 auto; }
  .app-header { padding: 14px 24px; }
}
