:root {
  --bg: #f3f4f6;
  --surface: #ffffff;
  --surface-hover: #f9fafb;
  --text: #111827;
  --text-secondary: #6b7280;
  --text-muted: #9ca3af;
  --border: #e5e7eb;
  --border-light: #f3f4f6;
  --primary: #111827;
  --primary-hover: #1f2937;
  --primary-bg: #f3f4f6;
  --income: #059669;
  --income-bg: #ecfdf5;
  --income-text: #047857;
  --cost: #dc2626;
  --cost-bg: #fef2f2;
  --cost-text: #b91c1c;
  --margin: #2563eb;
  --margin-bg: #eff6ff;
  --danger: #dc2626;
  --danger-bg: #fef2f2;
  --radius: 12px;
  --radius-sm: 8px;
  --radius-xs: 6px;
  --shadow: 0 1px 2px rgba(0,0,0,.06);
  --shadow-md: 0 4px 12px rgba(0,0,0,.1);
  --font: -apple-system, BlinkMacSystemFont, 'Segoe UI', system-ui, sans-serif;
  --header-h: 56px;
}

*, *::before, *::after { margin: 0; padding: 0; box-sizing: border-box; }

html { font-size: 16px; -webkit-text-size-adjust: 100%; }

/* ── Body: scroll lock when modal is open ── */
body.modal-open {
  overflow: hidden;
  position: fixed;
  width: 100%;
}

body {
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  padding-bottom: 80px;
  min-height: 100vh;
  line-height: 1.5;
}

/* ── Header ── */
.header {
  background: var(--primary);
  color: white;
  height: var(--header-h);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 16px;
  position: sticky;
  top: 0;
  z-index: 10;
}
.header h1 { font-size: 18px; font-weight: 700; letter-spacing: -.3px; }
.header .sub { font-size: 11px; opacity: .6; display: block; }
.header-left, .header-right { display: flex; align-items: center; gap: 8px; }
.lang-toggle {
  background: rgba(255,255,255,.15);
  border: none;
  color: white;
  font-size: 12px;
  font-weight: 600;
  padding: 4px 10px;
  border-radius: 6px;
  cursor: pointer;
  transition: background .15s;
}
.lang-toggle:hover { background: rgba(255,255,255,.25); }

/* ── Status dot (online/offline) ── */
.status-dot {
  width: 8px; height: 8px;
  border-radius: 50%;
  background: #22c55e;
  flex-shrink: 0;
  transition: background .3s;
}
.status-dot.offline { background: #ef4444; }

/* ── Sync indicator ── */
.sync-indicator {
  width: 8px; height: 8px;
  border-radius: 50%;
  background: #22c55e;
  flex-shrink: 0;
  transition: all .3s;
}
.sync-indicator.syncing {
  background: #f59e0b;
  animation: pulse 1s ease-in-out infinite;
}
.sync-indicator.error {
  background: #ef4444;
}
@keyframes pulse {
  0%, 100% { opacity: 1; transform: scale(1); }
  50% { opacity: .5; transform: scale(1.3); }
}

/* ── Container ── */
.container { max-width: 600px; margin: 0 auto; padding: 12px; }

/* ── Cards ── */
.card {
  background: var(--surface);
  border-radius: var(--radius);
  padding: 16px;
  margin-bottom: 10px;
  box-shadow: var(--shadow);
  transition: box-shadow .15s;
}
.card:hover { box-shadow: var(--shadow-md); }
.card-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 10px;
}
.card-title { font-size: 15px; font-weight: 600; }
.card-date { font-size: 12px; color: var(--text-muted); }
.card-stats { display: flex; gap: 8px; margin-bottom: 10px; }
.project-card { cursor: pointer; }

/* ── Stat Cards ── */
.stat-card {
  flex: 1;
  background: var(--bg);
  border-radius: var(--radius-sm);
  padding: 10px 8px;
  text-align: center;
  min-width: 0;
}
.stat-label { font-size: 10px; color: var(--text-secondary); text-transform: uppercase; letter-spacing: .3px; margin-bottom: 2px; }
.stat-value { font-size: 17px; font-weight: 700; font-variant-numeric: tabular-nums; }
.stat-value.income { color: var(--income); }
.stat-value.cost { color: var(--cost); }
.stat-value.primary { color: var(--primary); }

.summary-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin-bottom: 14px; }
.summary-grid .stat-card { padding: 14px 8px; background: var(--surface); box-shadow: var(--shadow); border-radius: var(--radius); }
.summary-grid .stat-value { font-size: 20px; }

/* ── Progress ── */
.progress-section { margin-top: 4px; }
.progress-label { font-size: 11px; color: var(--text-secondary); text-align: center; margin-bottom: 4px; }
.progress-bar { height: 5px; background: var(--border); border-radius: 3px; overflow: hidden; }
.progress-fill { height: 100%; background: var(--income); border-radius: 3px; transition: width .3s ease; }

/* ── Sections ── */
.section {
  background: var(--surface);
  border-radius: var(--radius);
  padding: 16px;
  margin-bottom: 10px;
  box-shadow: var(--shadow);
}
.section-title {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 14px;
  font-weight: 600;
  margin-bottom: 12px;
}
.section-icon { display: flex; align-items: center; }
.section-income .section-title { color: var(--income-text); }
.section-cost .section-title { color: var(--cost-text); }
.section-margin .section-title { color: var(--margin); }
.section-tasks .section-title { color: var(--primary); }
.party-name { font-weight: 400; font-size: 12px; color: var(--text-secondary); }
.task-count { font-weight: 400; font-size: 12px; color: var(--text-secondary); margin-right: auto; }

/* ── Detail ── */
.detail-actions {
  display: flex;
  gap: 4px;
  margin-bottom: 8px;
}
.detail-header { text-align: center; margin-bottom: 16px; }
.detail-header h2 { font-size: 18px; font-weight: 700; }
.detail-meta { font-size: 12px; color: var(--text-secondary); margin-top: 2px; }

/* ── Payment List ── */
.payment-list {}
.payment-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 8px 0;
  border-bottom: 1px solid var(--border-light);
  gap: 8px;
}
.payment-item:last-child { border-bottom: none; }
.pay-info { display: flex; align-items: center; gap: 8px; min-width: 0; }
.pay-amount { font-weight: 600; font-size: 14px; white-space: nowrap; }
.pay-amount.income { color: var(--income); }
.pay-amount.cost { color: var(--cost); }
.pay-note { font-size: 12px; color: var(--text-secondary); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.pay-meta { display: flex; align-items: center; gap: 4px; flex-shrink: 0; }
.pay-date { font-size: 11px; color: var(--text-muted); }
.empty-section { font-size: 13px; color: var(--text-muted); text-align: center; padding: 12px 0; }

/* ── Task List ── */
.task-list {}
.task-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 0;
  border-bottom: 1px solid var(--border-light);
}
.task-item:last-child { border-bottom: none; }
.task-item.done .task-text { text-decoration: line-through; color: var(--text-muted); }
.task-text { flex: 1; font-size: 14px; min-width: 0; }
.task-actions { display: flex; gap: 2px; opacity: 0; transition: opacity .15s; }
.task-item:hover .task-actions { opacity: 1; }
@media (hover:none) { .task-actions { opacity: 1; } }

/* Custom checkbox */
.task-check { position: relative; display: flex; align-items: center; cursor: pointer; }
.task-check input { position: absolute; opacity: 0; width: 0; height: 0; }
.checkmark {
  width: 20px; height: 20px;
  border: 2px solid var(--border); border-radius: 4px;
  display: flex; align-items: center; justify-content: center;
  transition: all .15s;
}
.task-check input:checked ~ .checkmark {
  background: var(--income); border-color: var(--income);
}
.task-check input:checked ~ .checkmark::after {
  content: ''; width: 6px; height: 10px;
  border: solid white; border-width: 0 2px 2px 0;
  transform: rotate(45deg); margin-top: -2px;
}

/* ── Buttons ── */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 10px 20px;
  border: none;
  border-radius: var(--radius-sm);
  font-size: 14px;
  font-weight: 600;
  font-family: inherit;
  cursor: pointer;
  transition: all .15s;
  white-space: nowrap;
}
.btn-primary { background: var(--primary); color: white; }
.btn-primary:hover { background: var(--primary-hover); }
.btn-outline { background: transparent; border: 1.5px solid var(--border); color: var(--text); }
.btn-outline:hover { border-color: var(--primary); color: var(--primary); }
.btn-danger { background: var(--danger); color: white; }
.btn-danger:hover { opacity: .9; }
.btn-ghost { background: transparent; color: var(--text-secondary); }
.btn-ghost:hover { background: var(--primary-bg); color: var(--text); }
.btn-text { background: transparent; border: none; color: var(--primary); cursor: pointer; }
.btn-text:hover { opacity: .7; }
.btn-sm { padding: 6px 12px; font-size: 12px; }
.btn-full { width: 100%; justify-content: center; padding: 10px; margin-top: 8px; }

/* Icon buttons */
.btn-icon {
  display: inline-flex; align-items: center; justify-content: center;
  width: 36px; height: 36px; border: none; background: transparent;
  border-radius: var(--radius-xs); cursor: pointer; color: var(--text-secondary);
  transition: all .15s;
}
.btn-icon:hover { background: var(--primary-bg); color: var(--text); }
.btn-icon-sm { width: 28px; height: 28px; }
.btn-icon-danger:hover { background: var(--danger-bg); color: var(--danger); }

/* ── FAB ── */
.fab {
  position: fixed; bottom: 24px; left: 50%; transform: translateX(-50%);
  width: 52px; height: 52px; border-radius: 50%;
  background: var(--primary); color: white; border: none;
  display: flex; align-items: center; justify-content: center;
  cursor: pointer; box-shadow: 0 4px 14px rgba(0,0,0,.25);
  z-index: 20; transition: transform .15s;
}
.fab:hover { transform: translateX(-50%) scale(1.05); }
.fab svg { width: 24px; height: 24px; }

/* ── Modal ── */
.modal-overlay {
  position: fixed; inset: 0; background: rgba(0,0,0,.5);
  z-index: 30; display: flex; align-items: flex-end; justify-content: center;
}
.modal {
  background: var(--surface); border-radius: 16px 16px 0 0;
  width: 100%; max-width: 600px; max-height: 85vh;
  overflow-y: auto; animation: slideUp .2s ease;
}
.modal-sm { max-width: 380px; }
@keyframes slideUp { from { transform: translateY(100%); } to { transform: translateY(0); } }
.modal-header {
  display: flex; justify-content: space-between; align-items: center;
  padding: 16px 20px; border-bottom: 1px solid var(--border-light);
  position: sticky; top: 0; background: var(--surface); z-index: 1;
}
.modal-header h3 { font-size: 16px; font-weight: 600; }
.modal-body { padding: 16px 20px 20px; }
.modal-body p { font-size: 14px; color: var(--text-secondary); line-height: 1.6; margin-bottom: 16px; }
.modal-actions { display: flex; gap: 8px; margin-top: 16px; }
.modal-actions .btn { flex: 1; }

/* ── Forms ── */
.form-group { margin-bottom: 14px; }
.form-group label {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 13px;
  font-weight: 600;
  color: var(--text);
  margin-bottom: 6px;
}
.form-group label .icon-field {
  width: 16px; height: 16px;
  color: var(--text-muted);
  flex-shrink: 0;
}
.form-group input, .form-group textarea, .form-group select {
  width: 100%; padding: 12px 14px;
  border: 1.5px solid var(--border); border-radius: var(--radius-sm);
  font-size: 15px; font-family: inherit; background: var(--surface); color: var(--text);
  transition: border-color .15s, box-shadow .15s;
}
.form-group input:focus, .form-group textarea:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(0,0,0,.06);
}
.form-group input::placeholder, .form-group textarea::placeholder {
  color: var(--text-muted);
  font-size: 13px;
  opacity: .8;
}
.form-group textarea { resize: vertical; min-height: 72px; }
.form-row { display: flex; gap: 8px; }
.form-row .form-group { flex: 1; min-width: 0; }
.form-row input { width: 100%; box-sizing: border-box; }
/* Date field: text trigger visible, real date input invisibly overlaid */
.date-field { position: relative; }
.date-hidden { position: absolute; top: 0; left: 0; width: 100% !important; height: 100%; opacity: 0; cursor: pointer; z-index: 2; }
.date-hidden::-webkit-calendar-picker-indicator { position: absolute; top: 0; left: 0; width: 100%; height: 100%; cursor: pointer; }
/* ── Kill ALL bounce everywhere (iOS Safari rubber-band fix) ── */
html { height: 100%; overflow: hidden; }
body { height: 100%; overflow-y: auto; overflow-x: hidden; overscroll-behavior: none; -webkit-overflow-scrolling: auto; scrollbar-width: none; -ms-overflow-style: none; }
body::-webkit-scrollbar { display: none; width: 0; }
/* Inside modal too */
.modal, .modal-body { overscroll-behavior: none; overflow-x: hidden; scrollbar-width: none; -ms-overflow-style: none; }
.modal-body::-webkit-scrollbar, .modal::-webkit-scrollbar { display: none; width: 0; }
.form-help { font-size: 11px; color: var(--text-muted); margin-top: 4px; padding-inline-start: 2px; }

/* Section divider inside modal */
.form-section-title {
  font-size: 14px;
  font-weight: 700;
  color: var(--text);
  padding: 10px 0 8px;
  margin-bottom: 12px;
  border-bottom: 1px solid var(--border-light);
  display: flex;
  align-items: center;
  gap: 8px;
}
.form-section-title.income { color: var(--income-text); }
.form-section-title.cost { color: var(--cost-text); }
.form-section-title .icon { width: 18px; height: 18px; }

/* ── Toast ── */
.toast {
  position: fixed; bottom: 90px; left: 50%; transform: translateX(-50%);
  padding: 10px 20px; border-radius: var(--radius-sm);
  font-size: 13px; font-weight: 500; z-index: 40;
  display: none; white-space: nowrap; box-shadow: var(--shadow-md);
  animation: fadeIn .2s ease;
}
.toast.show { display: block; }
.toast-success { background: var(--primary); color: white; }
.toast-error { background: var(--danger); color: white; }
@keyframes fadeIn { from { opacity: 0; transform: translateX(-50%) translateY(8px); } to { opacity: 1; transform: translateX(-50%) translateY(0); } }

/* ── Empty ── */
.empty-state { text-align: center; padding: 48px 20px; color: var(--text-muted); }
.empty-icon svg { width: 48px; height: 48px; opacity: .4; margin-bottom: 12px; }
.empty-state p { font-size: 14px; line-height: 1.6; }

/* ── Camera ── */
.camera-container { position: relative; width: 100%; }
.camera-container video { width: 100%; border-radius: var(--radius-sm); background: #000; }
.camera-container canvas { width: 100%; border-radius: var(--radius-sm); }
.camera-controls { display: flex; justify-content: center; gap: 12px; padding: 16px 0; }
.camera-controls .btn { flex: 1; max-width: 200px; }

/* ── Image ── */
.contract-image { margin-top: 8px; cursor: pointer; }
.contract-image img { width: 100%; max-height: 120px; object-fit: cover; border-radius: var(--radius-sm); border: 1px solid var(--border); }
.image-lightbox { display: flex; align-items: center; justify-content: center; width: 100%; min-height: 100vh; padding: 20px; }
.btn-close-lightbox { position: fixed; top: 16px; left: 50%; transform: translateX(-50%); background: var(--primary); color: white; border: none; width: 36px; height: 36px; border-radius: 50%; cursor: pointer; display: flex; align-items: center; justify-content: center; }

/* ── Icons ── */
.icon { width: 20px; height: 20px; display: inline-block; vertical-align: middle; flex-shrink: 0; }
.btn-icon .icon, .btn .icon { pointer-events: none; }

/* ── Nero section ── */
.section-nero { border: 1.5px dashed var(--border); }

/* ── Responsive ── */
@media(max-width:400px) {
  .stat-value { font-size: 15px; }
  .summary-grid .stat-value { font-size: 18px; }
  .card { padding: 12px; }
  .section { padding: 12px; }
  .modal-body { padding: 12px 16px 16px; }
}
@media(min-width:768px) {
  .modal { border-radius: 16px; margin-bottom: 40px; }
}
