/* ===== RESET & BASE ===== */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --bg: #f4f5f7;
  --surface: #ffffff;
  --primary: #1a1a2e;
  --primary-light: #2d2d4e;
  --accent: #4f46e5;
  --accent-hover: #4338ca;
  --danger: #dc2626;
  --success: #16a34a;
  --muted: #6b7280;
  --border: #e5e7eb;
  --text: #111827;
  --radius: 10px;
  --shadow: 0 1px 3px rgba(0,0,0,.1);
}

html { font-size: 16px; }
body { font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
       background: var(--bg); color: var(--text); line-height: 1.5; }

a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }

/* ===== NAVBAR ===== */
.navbar {
  background: var(--primary);
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 16px;
  height: 56px;
  position: sticky;
  top: 0;
  z-index: 100;
}
.nav-brand { color: #fff; font-size: 1.2rem; font-weight: 700; letter-spacing: -0.5px; }
.nav-brand:hover { text-decoration: none; }
.nav-links { display: flex; align-items: center; gap: 4px; }
.nav-links a { color: rgba(255,255,255,.75); padding: 6px 10px; border-radius: 6px; font-size: .9rem; transition: background .15s; }
.nav-links a:hover, .nav-links a.active { background: rgba(255,255,255,.15); color: #fff; text-decoration: none; }
.nav-logout { margin-left: 8px; }

/* ===== MAIN ===== */
.main { max-width: 800px; margin: 0 auto; padding: 20px 16px 80px; }

/* ===== LOGIN ===== */
.login-page { display: flex; align-items: center; justify-content: center; min-height: 100vh; }
.login-box { background: var(--surface); border-radius: var(--radius); box-shadow: var(--shadow); padding: 40px 32px; width: 100%; max-width: 360px; }
.login-box h1 { font-size: 1.8rem; margin-bottom: 4px; }
.login-box .subtitle { color: var(--muted); margin-bottom: 24px; }

/* ===== PAGE HEADER ===== */
.page-header { display: flex; align-items: center; gap: 12px; margin-bottom: 20px; flex-wrap: wrap; }
.page-header h2 { flex: 1; font-size: 1.4rem; }
.btn-back { color: var(--muted); font-size: .9rem; }
.btn-back:hover { color: var(--text); }

/* ===== BUTTONS ===== */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 9px 18px;
  border-radius: 8px;
  font-size: .9rem;
  font-weight: 500;
  cursor: pointer;
  border: none;
  transition: background .15s, opacity .15s;
  white-space: nowrap;
}
.btn-primary  { background: var(--accent);  color: #fff; }
.btn-primary:hover  { background: var(--accent-hover); text-decoration: none; }
.btn-secondary { background: var(--border); color: var(--text); }
.btn-secondary:hover { background: #d1d5db; text-decoration: none; }
.btn-danger   { background: var(--danger); color: #fff; }
.btn-danger:hover { opacity: .9; }
.btn-block    { width: 100%; justify-content: center; padding: 12px; }
.btn-text     { background: none; color: var(--muted); padding: 6px 4px; font-size: .85rem; }
.btn-sm       { padding: 6px 12px; font-size: .85rem; }

/* ===== FORMS ===== */
.form-group { margin-bottom: 16px; }
.form-group label { display: block; font-size: .85rem; font-weight: 500; margin-bottom: 4px; color: var(--muted); }
.form-group input, .form-group select, .form-group textarea {
  width: 100%;
  padding: 10px 12px;
  border: 1.5px solid var(--border);
  border-radius: 8px;
  font-size: 1rem;
  font-family: inherit;
  background: var(--surface);
  transition: border-color .15s;
  appearance: auto;
}
.form-group input:focus, .form-group select:focus, .form-group textarea:focus {
  outline: none;
  border-color: var(--accent);
}
.form-group small { display: block; color: var(--muted); font-size: .78rem; margin-top: 4px; }
.form-group--sm { flex: 0 0 120px; }
.form-group--xs { flex: 0 0 90px; }
.flex-grow { flex: 1; }

.form-row { display: flex; gap: 12px; flex-wrap: wrap; }
.form-row .form-group { flex: 1; min-width: 120px; }

.form-toggle { display: flex; align-items: center; }
.toggle-label { display: flex; align-items: center; gap: 10px; cursor: pointer; }
.toggle-label input[type=checkbox] { width: 18px; height: 18px; }
.toggle-text { font-size: .95rem; color: var(--text); }

.form-actions { display: flex; gap: 10px; flex-wrap: wrap; margin-top: 8px; }

/* ===== FILTER BAR ===== */
.filter-bar {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 16px;
  flex-wrap: wrap;
}
.filter-bar select, .filter-bar input[type=month] {
  padding: 8px 10px;
  border: 1.5px solid var(--border);
  border-radius: 8px;
  font-size: .9rem;
  background: var(--surface);
}

/* ===== SUMMARY BAR ===== */
.summary-bar {
  background: var(--surface);
  border-radius: var(--radius);
  padding: 10px 16px;
  margin-bottom: 12px;
  font-size: .9rem;
  color: var(--muted);
  box-shadow: var(--shadow);
}

/* ===== STATS GRID ===== */
.stats-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); gap: 12px; margin-bottom: 24px; }
.stat-card { background: var(--surface); border-radius: var(--radius); padding: 16px; box-shadow: var(--shadow); }
.stat-label { font-size: .78rem; color: var(--muted); text-transform: uppercase; letter-spacing: .03em; margin-bottom: 4px; }
.stat-value { font-size: 1.4rem; font-weight: 700; line-height: 1.2; }
.stat-sub { font-size: .78rem; color: var(--muted); margin-top: 4px; }

/* ===== SECTION GRID ===== */
.section-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(300px, 1fr)); gap: 20px; }
.section-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 10px; }
.section-header h3 { font-size: 1rem; }

/* ===== ITEM LIST ===== */
.item-list { list-style: none; background: var(--surface); border-radius: var(--radius); box-shadow: var(--shadow); overflow: hidden; }
.item-list li { display: flex; align-items: center; justify-content: space-between; border-bottom: 1px solid var(--border); }
.item-list li:last-child { border-bottom: none; }
.item-list li > a { flex: 1; display: flex; align-items: center; gap: 10px; padding: 12px 16px; color: var(--text); }
.item-list li > a:hover { background: var(--bg); text-decoration: none; }
.item-list--full li > a { padding: 14px 16px; }

.item-info { display: flex; flex-direction: column; gap: 2px; }
.item-main { font-weight: 500; }
.item-sub  { font-size: .8rem; color: var(--muted); }
.item-amount { font-weight: 600; padding-right: 16px; white-space: nowrap; }
.item-amount.muted { color: var(--muted); }
.item-right { display: flex; align-items: center; gap: 8px; padding-right: 16px; }

/* ===== RECEIPT THUMB ===== */
.receipt-thumb { width: 40px; height: 40px; object-fit: cover; border-radius: 6px; flex-shrink: 0; }
.receipt-thumb--empty { display: flex; align-items: center; justify-content: center; background: var(--bg); font-size: 1.2rem; }

/* ===== BADGES ===== */
.badge { font-size: .72rem; font-weight: 600; padding: 2px 8px; border-radius: 20px; text-transform: uppercase; letter-spacing: .04em; }
.badge--firma   { background: #dcfce7; color: #166534; }
.badge--private { background: #f3f4f6; color: var(--muted); }
.badge--sent    { background: #dbeafe; color: #1e40af; }
.badge--draft   { background: #fef9c3; color: #854d0e; }

/* ===== ALERTS ===== */
.alert { padding: 12px 16px; border-radius: 8px; margin-bottom: 16px; font-size: .9rem; }
.alert-error   { background: #fee2e2; color: #991b1b; }
.alert-success { background: #dcfce7; color: #166534; }

/* ===== CAMERA / SCAN ===== */
.camera-section { margin-bottom: 20px; }
.camera-area { border: 2.5px dashed var(--border); border-radius: var(--radius); padding: 32px 16px; text-align: center; cursor: pointer; transition: border-color .15s; }
.camera-area:hover { border-color: var(--accent); }
.camera-label { display: flex; flex-direction: column; align-items: center; gap: 8px; cursor: pointer; }
.camera-icon { font-size: 3rem; }
.hidden { display: none !important; }

#photoPreview { text-align: center; }
#photoPreview img { max-width: 100%; max-height: 300px; border-radius: var(--radius); }
#photoPreview button { margin-top: 10px; }

.scan-status { display: flex; align-items: center; justify-content: center; gap: 10px; padding: 12px; color: var(--muted); }

.spinner {
  width: 18px; height: 18px;
  border: 2.5px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin .7s linear infinite;
  display: inline-block;
}
@keyframes spin { to { transform: rotate(360deg); } }

.receipt-image-view { margin-bottom: 16px; }
.receipt-image-view img { max-width: 100%; max-height: 220px; border-radius: var(--radius); }

/* ===== CARDS ===== */
.card { background: var(--surface); border-radius: var(--radius); box-shadow: var(--shadow); padding: 20px; margin-bottom: 16px; }
.card h3 { font-size: 1rem; margin-bottom: 16px; padding-bottom: 10px; border-bottom: 1px solid var(--border); }

/* ===== INVOICE ROWS ===== */
.invoice-row-inner { display: flex; gap: 10px; align-items: flex-end; margin-bottom: 10px; flex-wrap: wrap; }
.invoice-row-inner .form-group { margin-bottom: 0; }
.remove-row { background: none; border: none; color: var(--muted); cursor: pointer; font-size: 1.1rem; padding: 10px 4px; align-self: flex-end; }
.remove-row:hover { color: var(--danger); }

/* ===== TOTALS ===== */
.invoice-totals { padding: 16px 20px; }
.totals-grid { display: grid; grid-template-columns: 1fr auto; gap: 6px 20px; }
.totals-grid span { font-size: .95rem; }
.totals-grid span:nth-child(even) { text-align: right; font-weight: 500; }
.total-final { font-size: 1.1rem !important; font-weight: 700 !important; padding-top: 8px; border-top: 2px solid var(--primary); }

/* ===== MODAL ===== */
.modal-overlay { position: fixed; inset: 0; background: rgba(0,0,0,.4); z-index: 200; }
.modal { position: fixed; top: 50%; left: 50%; transform: translate(-50%, -50%); z-index: 300;
         background: var(--surface); border-radius: var(--radius); box-shadow: 0 8px 32px rgba(0,0,0,.2);
         padding: 28px; width: calc(100% - 32px); max-width: 440px; }
.modal h3 { margin-bottom: 16px; }
.modal-actions { display: flex; gap: 10px; margin-top: 16px; }

/* ===== EMPTY STATE ===== */
.empty-state { color: var(--muted); padding: 20px; text-align: center; background: var(--surface); border-radius: var(--radius); }

/* ===== SCANNER ===== */
.scanner-mount { margin-bottom: 20px; }

.sc-live, .sc-adjust, .sc-result { width: 100%; }

.sc-video-wrap { position: relative; background: #000; border-radius: var(--radius); overflow: hidden; aspect-ratio: 3/4; }
.sc-video-wrap video { width: 100%; height: 100%; display: block; object-fit: cover; }
.sc-guide { position: absolute; inset: 0; width: 100%; height: 100%; pointer-events: none; }

.sc-btn { width: 100%; justify-content: center; margin-top: 10px; }
.sc-file-label { display: block; text-align: center; margin-top: 8px; cursor: pointer; }

.sc-hint { font-size: .82rem; color: var(--muted); margin-bottom: 8px; text-align: center; }
.sc-canvas-wrap { padding: 0 20px; }
.sc-canvas { width: 100%; border-radius: var(--radius); touch-action: none; display: block; cursor: crosshair; }

.sc-result-img { width: 100%; border-radius: var(--radius); display: block; margin-bottom: 8px; }

/* ===== RESPONSIVE ===== */
@media (max-width: 480px) {
  .stats-grid { grid-template-columns: 1fr 1fr; }
  .stat-value { font-size: 1.1rem; }
  .form-group--sm, .form-group--xs { flex: 0 0 100%; }
  .invoice-row-inner { flex-direction: column; }
  .invoice-row-inner .form-group { flex: 0 0 100%; }
  .nav-links a { padding: 6px 7px; font-size: .82rem; }
}
