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

:root {
  --navy:   #0A1628;
  --navy2:  #132040;
  --navy3:  #1e2f52;
  --blue:   #2563EB;
  --green:  #16A34A;
  --red:    #DC2626;
  --gray:   #64748B;
  --light:  #F1F5F9;
  --white:  #FFFFFF;
  --border: #CBD5E1;
  --font:   -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  --radius: 14px;
  --shadow: 0 4px 24px rgba(0,0,0,.12);
}

html, body {
  height: 100%;
  font-family: var(--font);
  background: var(--light);
  color: var(--navy);
  -webkit-tap-highlight-color: transparent;
  overscroll-behavior: none;
}

/* ───────────── App shell ───────────── */
#app {
  display: flex;
  flex-direction: column;
  height: 100dvh;
  max-width: 480px;
  margin: 0 auto;
  background: var(--white);
  position: relative;
}

/* ───────────── Header ───────────── */
.app-header {
  background: var(--navy);
  color: var(--white);
  padding: 16px 20px 14px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-shrink: 0;
}
.app-header h1 {
  font-size: 18px;
  font-weight: 700;
  letter-spacing: -0.3px;
}
.app-header .tarif-badge {
  font-size: 11px;
  background: var(--navy3);
  padding: 3px 8px;
  border-radius: 20px;
  opacity: .85;
}

/* ───────────── Screens ───────────── */
.screen {
  display: none;
  flex: 1;
  overflow-y: auto;
  padding: 20px;
  padding-bottom: 90px; /* bottom nav clearance */
}
.screen.active { display: block; }

/* ───────────── Bottom nav ───────────── */
.bottom-nav {
  position: fixed;
  bottom: 0;
  left: 50%;
  transform: translateX(-50%);
  width: 100%;
  max-width: 480px;
  background: var(--white);
  border-top: 1px solid var(--border);
  display: flex;
  z-index: 100;
  padding-bottom: env(safe-area-inset-bottom);
}
.nav-btn {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 3px;
  padding: 10px 4px 8px;
  border: none;
  background: none;
  cursor: pointer;
  color: var(--gray);
  font-size: 10px;
  font-weight: 500;
  transition: color .15s;
}
.nav-btn.active { color: var(--navy); }
.nav-btn svg { width: 22px; height: 22px; }
.nav-btn .nav-dot {
  width: 5px; height: 5px;
  border-radius: 50%;
  background: var(--blue);
  display: none;
  margin-top: 2px;
}
.nav-btn.active .nav-dot { display: block; }

/* ───────────── Cards ───────────── */
.card {
  background: var(--white);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 18px;
  margin-bottom: 14px;
}
.card-title {
  font-size: 12px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .6px;
  color: var(--gray);
  margin-bottom: 14px;
}

/* ───────────── Forms ───────────── */
.field { margin-bottom: 14px; }
.field label {
  display: block;
  font-size: 13px;
  font-weight: 500;
  color: var(--navy);
  margin-bottom: 5px;
}
.field label .hint {
  font-weight: 400;
  color: var(--gray);
  margin-left: 4px;
}
input[type="number"], input[type="text"], input[type="password"] {
  width: 100%;
  padding: 11px 14px;
  border: 1.5px solid var(--border);
  border-radius: 10px;
  font-size: 15px;
  font-family: var(--font);
  color: var(--navy);
  background: var(--white);
  transition: border-color .15s;
  -webkit-appearance: none;
}
input:focus {
  outline: none;
  border-color: var(--blue);
}
input.ocr-result {
  font-size: 22px;
  font-weight: 700;
  text-align: center;
  letter-spacing: .5px;
  background: var(--light);
}

/* ───────────── Buttons ───────────── */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 13px 20px;
  border-radius: 12px;
  font-size: 15px;
  font-weight: 600;
  font-family: var(--font);
  border: none;
  cursor: pointer;
  transition: opacity .15s, transform .1s;
  -webkit-appearance: none;
}
.btn:active { transform: scale(.97); }
.btn-primary {
  background: var(--navy);
  color: var(--white);
  width: 100%;
}
.btn-secondary {
  background: var(--light);
  color: var(--navy);
  width: 100%;
  border: 1.5px solid var(--border);
}
.btn-camera {
  background: var(--navy2);
  color: var(--white);
  flex: 1;
}
.btn-sm {
  padding: 9px 16px;
  font-size: 13px;
  border-radius: 8px;
}
.btn:disabled { opacity: .45; cursor: default; }

/* ───────────── Reading section ───────────── */
.reading-block {
  margin-bottom: 18px;
}
.reading-label {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 8px;
}
.reading-label .tarif-tag {
  font-size: 11px;
  font-weight: 700;
  padding: 2px 8px;
  border-radius: 20px;
  background: var(--navy);
  color: var(--white);
}
.reading-label .tarif-tag.nt { background: var(--blue); }
.reading-row {
  display: flex;
  gap: 10px;
  align-items: flex-end;
}
.reading-row input { flex: 1; }
.prev-reading {
  font-size: 12px;
  color: var(--gray);
  margin-top: 5px;
}
.prev-reading span { color: var(--navy); font-weight: 600; }

/* ───────────── Camera ───────────── */
#camera-overlay {
  display: none;
  position: fixed;
  inset: 0;
  z-index: 200;
  background: #000;
  flex-direction: column;
}
#camera-overlay.open { display: flex; }

#camera-video {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.camera-ui {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: space-between;
  padding: 40px 20px 60px;
}

.camera-header {
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.camera-title {
  color: var(--white);
  font-size: 16px;
  font-weight: 700;
}
.btn-close-cam {
  width: 40px; height: 40px;
  border-radius: 50%;
  background: rgba(255,255,255,.2);
  border: none;
  color: var(--white);
  font-size: 20px;
  cursor: pointer;
  display: flex; align-items: center; justify-content: center;
}

/* Viewfinder frame */
.viewfinder {
  width: 80%;
  aspect-ratio: 2 / 1;
  position: relative;
  border-radius: 8px;
  overflow: hidden;
}
/* Darkened corners via box-shadow inset */
.viewfinder::before {
  content: '';
  position: absolute;
  inset: 0;
  box-shadow: 0 0 0 2000px rgba(0,0,0,.55);
  border-radius: 8px;
  z-index: 1;
  pointer-events: none;
}
/* Bright border */
.viewfinder::after {
  content: '';
  position: absolute;
  inset: 0;
  border: 2px solid rgba(255,255,255,.8);
  border-radius: 8px;
  z-index: 2;
  pointer-events: none;
}
/* Crosshair */
.crosshair {
  position: absolute;
  top: 50%; left: 50%;
  transform: translate(-50%,-50%);
  z-index: 3;
}
.crosshair::before, .crosshair::after {
  content: '';
  position: absolute;
  background: rgba(255,255,255,.6);
}
.crosshair::before { width: 24px; height: 2px; top: -1px; left: -12px; }
.crosshair::after  { width: 2px; height: 24px; top: -12px; left: -1px; }

/* Corner markers */
.corner {
  position: absolute;
  width: 18px; height: 18px;
  border-color: var(--white);
  border-style: solid;
  z-index: 3;
}
.corner-tl { top: 8px; left: 8px;  border-width: 3px 0 0 3px; border-radius: 3px 0 0 0; }
.corner-tr { top: 8px; right: 8px; border-width: 3px 3px 0 0; border-radius: 0 3px 0 0; }
.corner-bl { bottom: 8px; left: 8px;  border-width: 0 0 3px 3px; border-radius: 0 0 0 3px; }
.corner-br { bottom: 8px; right: 8px; border-width: 0 3px 3px 0; border-radius: 0 0 3px 0; }

.camera-hint {
  color: rgba(255,255,255,.8);
  font-size: 13px;
  text-align: center;
}

.btn-shutter {
  width: 68px; height: 68px;
  border-radius: 50%;
  background: var(--white);
  border: 4px solid rgba(255,255,255,.4);
  cursor: pointer;
  transition: transform .1s;
}
.btn-shutter:active { transform: scale(.92); }

/* OCR spinner overlay on camera */
#ocr-spinner {
  display: none;
  position: absolute;
  inset: 0;
  background: rgba(10,22,40,.85);
  z-index: 5;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 16px;
  color: var(--white);
  font-size: 15px;
}
#ocr-spinner.show { display: flex; }
.spinner-ring {
  width: 44px; height: 44px;
  border: 3px solid rgba(255,255,255,.2);
  border-top-color: var(--white);
  border-radius: 50%;
  animation: spin .8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ───────────── Result screen ───────────── */
.verdict-box {
  background: var(--navy);
  border-radius: var(--radius);
  padding: 28px 20px;
  text-align: center;
  margin-bottom: 16px;
  color: var(--white);
}
.verdict-label {
  font-size: 13px;
  opacity: .65;
  margin-bottom: 8px;
  font-weight: 500;
}
.verdict-amount {
  font-size: 64px;
  font-weight: 800;
  line-height: 1;
  letter-spacing: -2px;
}
.verdict-amount.preplatek { color: #4ADE80; }
.verdict-amount.nedoplatek { color: #F87171; }
.verdict-sub {
  font-size: 14px;
  opacity: .6;
  margin-top: 6px;
}

.stats-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  margin-bottom: 14px;
}
.stat-card {
  background: var(--light);
  border-radius: 10px;
  padding: 14px;
  text-align: center;
}
.stat-value {
  font-size: 20px;
  font-weight: 700;
  color: var(--navy);
}
.stat-label {
  font-size: 11px;
  color: var(--gray);
  margin-top: 2px;
}

/* Accordion */
.accordion {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  margin-bottom: 14px;
  overflow: hidden;
}
.accordion-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 18px;
  cursor: pointer;
  font-size: 14px;
  font-weight: 600;
  background: var(--white);
  user-select: none;
}
.accordion-head .chevron {
  font-size: 12px;
  color: var(--gray);
  transition: transform .2s;
}
.accordion.open .accordion-head .chevron { transform: rotate(180deg); }
.accordion-body {
  display: none;
  border-top: 1px solid var(--border);
  padding: 14px 18px;
}
.accordion.open .accordion-body { display: block; }
.breakdown-row {
  display: flex;
  justify-content: space-between;
  font-size: 13px;
  padding: 5px 0;
  border-bottom: 1px solid var(--light);
}
.breakdown-row:last-child { border-bottom: none; }
.breakdown-row .val { font-weight: 600; color: var(--navy); }
.breakdown-total {
  display: flex;
  justify-content: space-between;
  font-size: 14px;
  font-weight: 700;
  padding-top: 10px;
  margin-top: 6px;
  border-top: 2px solid var(--border);
}

.result-actions {
  display: flex;
  flex-direction: column;
  gap: 10px;
  margin-top: 4px;
}

/* ───────────── History ───────────── */
.history-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 14px 18px;
  border: 1px solid var(--border);
  border-radius: 12px;
  margin-bottom: 10px;
  cursor: pointer;
  transition: background .1s;
}
.history-item:active { background: var(--light); }
.history-item .hi-date { font-size: 13px; color: var(--gray); }
.history-item .hi-sp   { font-size: 12px; color: var(--gray); margin-top: 2px; }
.history-item .hi-amount {
  font-size: 18px;
  font-weight: 800;
  letter-spacing: -.5px;
}
.hi-amount.preplatek { color: var(--green); }
.hi-amount.nedoplatek { color: var(--red); }
.empty-state {
  text-align: center;
  color: var(--gray);
  font-size: 14px;
  padding: 60px 20px;
}
.empty-state .es-icon { font-size: 48px; margin-bottom: 12px; }

/* ───────────── Settings ───────────── */
.settings-section-title {
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .7px;
  color: var(--gray);
  margin: 20px 0 10px;
}
.settings-section-title:first-child { margin-top: 0; }

.api-key-row {
  display: flex;
  gap: 10px;
  align-items: flex-end;
}
.api-key-row input { flex: 1; }

.masked-key {
  font-size: 13px;
  color: var(--gray);
  margin-top: 6px;
}

.info-box {
  background: #EFF6FF;
  border: 1px solid #BFDBFE;
  border-radius: 10px;
  padding: 12px 14px;
  font-size: 12px;
  color: #1E40AF;
  line-height: 1.5;
  margin-bottom: 14px;
}

/* ───────────── Toast ───────────── */
#toast {
  position: fixed;
  bottom: 90px;
  left: 50%;
  transform: translateX(-50%) translateY(20px);
  background: var(--navy);
  color: var(--white);
  padding: 10px 20px;
  border-radius: 24px;
  font-size: 14px;
  font-weight: 500;
  white-space: nowrap;
  opacity: 0;
  transition: opacity .2s, transform .2s;
  z-index: 500;
  pointer-events: none;
}
#toast.show {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}

/* ───────────── Date row ───────────── */
.date-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 16px;
  background: var(--navy);
  color: var(--white);
  border-radius: 12px;
  margin-bottom: 18px;
  font-size: 14px;
}
.date-row .date-val { font-weight: 700; font-size: 15px; }
