/* Pirchei Receipt PWA — mobile-first */
:root {
  --accent: #667eea;
  --accent-2: #764ba2;
  --green: #28a745;
  --blue: #0078d4;
  --whatsapp: #25D366;
  --gray: #6c757d;
  --bg: #f0f0f5;
  --card: #ffffff;
  --text: #333;
  --muted: #888;
  --border: #ddd;
  --danger: #dc3545;
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  padding-bottom: env(safe-area-inset-bottom);
}

/* Header */
.app-header {
  background: var(--accent);
  color: white;
  padding: 18px 16px calc(18px + env(safe-area-inset-top)) 16px;
  padding-top: max(18px, env(safe-area-inset-top));
  text-align: center;
  position: relative;
}
.app-header h1 { margin: 0; font-size: 1.4rem; font-weight: 700; }
.app-header .subtitle { font-size: 0.85rem; opacity: 0.9; margin-top: 2px; }
.back-link {
  position: absolute; left: 12px; top: 50%; transform: translateY(-50%);
  color: white; text-decoration: none; font-size: 1.4rem;
}
.install-btn {
  position: absolute; right: 12px; top: 50%; transform: translateY(-50%);
  background: white; color: var(--accent); border: none;
  padding: 6px 12px; border-radius: 6px; font-weight: 600; cursor: pointer;
}
.install-btn:hover { background: #f3f3f3; }

/* Main */
.app {
  max-width: 760px;
  margin: 0 auto;
  padding: 12px;
}

/* Form */
.form { background: var(--card); border-radius: 10px; padding: 14px; box-shadow: 0 1px 3px rgba(0,0,0,0.05); }
fieldset {
  border: 1px solid var(--border);
  border-radius: 8px;
  margin: 10px 0;
  padding: 10px 12px;
}
fieldset legend { font-weight: 600; font-size: 0.95rem; padding: 0 6px; }
fieldset label { display: inline-flex; align-items: center; margin-right: 14px; cursor: pointer; }
fieldset label input { margin-right: 6px; }

label.block { display: block; margin: 10px 0; }
label.block > span { display: block; font-weight: 600; font-size: 0.9rem; margin-bottom: 4px; }

input[type="text"], input[type="number"], input[type="email"], input[type="tel"],
input[type="date"], input[type="search"], select {
  width: 100%;
  padding: 10px 12px;
  font-size: 1rem;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: white;
  font-family: inherit;
}
input:focus, select:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 2px rgba(102,126,234,0.2); }

.row { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; margin: 10px 0; }
.row label { display: block; }
.row label > span { display: block; font-weight: 600; font-size: 0.85rem; margin-bottom: 4px; }
@media (max-width: 640px) {
  .row { grid-template-columns: 1fr 1fr; }
}

.req { color: var(--danger); }

/* Image row */
.image-row { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; margin-top: 6px; }
.image-row button {
  padding: 8px 12px;
  background: #f0f0f5;
  border: 1px solid var(--border);
  border-radius: 6px;
  cursor: pointer;
  font-weight: 600;
}
.image-row button:hover { background: #e0e0e8; }

.preview-wrap { margin-top: 10px; text-align: center; }
.preview-wrap img { max-width: 100%; max-height: 240px; border: 1px solid var(--border); border-radius: 6px; }
.preview-hint { font-size: 0.8rem; margin: 4px 0 6px; }
.preview-actions { display: flex; flex-wrap: wrap; gap: 4px; justify-content: center; margin-top: 6px; }
.preview-wrap .link { background: none; border: 1px solid transparent; color: var(--accent); cursor: pointer; padding: 6px 10px; font-size: 0.9rem; border-radius: 4px; font-weight: 600; }
.preview-wrap .link:hover { background: #eef0ff; }
.preview-wrap .link.danger { color: var(--danger); }
.preview-wrap .link.danger:hover { background: #fdecee; }

/* Action buttons */
.actions { display: grid; grid-template-columns: repeat(4, 1fr); gap: 6px; margin-top: 14px; }
@media (max-width: 640px) { .actions { grid-template-columns: repeat(2, 1fr); } }
.actions button, .actions .button-link {
  display: block;
  padding: 12px 4px;
  border: none;
  border-radius: 6px;
  color: white;
  font-weight: 600;
  font-size: 0.95rem;
  cursor: pointer;
  background: var(--gray);
  text-decoration: none;
  text-align: center;
  font-family: inherit;
}
.actions button.primary { background: var(--accent); }
#btn-save { background: var(--green); }
#btn-print { background: #17a2b8; }
#btn-email { background: var(--blue); }
#btn-whatsapp { background: var(--whatsapp); }
.actions .button-link { background: #6f42c1; }
#btn-new { background: var(--gray); }

/* Status */
.status { margin-top: 12px; padding: 8px; text-align: center; min-height: 1.3em; color: var(--green); font-weight: 500; }
.status.error { color: var(--danger); }

/* History */
.filter-bar { display: flex; gap: 8px; margin: 10px 0; flex-wrap: wrap; }
.filter-bar select, .filter-bar input { flex: 1; min-width: 140px; }
.filter-bar button { padding: 8px 14px; background: var(--accent); color: white; border: none; border-radius: 6px; cursor: pointer; }
.summary { padding: 6px 4px; }
.history-list { background: var(--card); border-radius: 10px; padding: 4px; }
.history-row {
  display: grid;
  grid-template-columns: 90px 1fr auto;
  gap: 8px;
  padding: 10px 8px;
  border-bottom: 1px solid var(--border);
  cursor: pointer;
  align-items: center;
}
.history-row:hover { background: #fafaff; }
.history-row .date { font-size: 0.85rem; color: var(--muted); }
.history-row .donor { font-weight: 600; }
.history-row .meta { font-size: 0.8rem; color: var(--muted); }
.history-row .amount { font-weight: 700; color: var(--accent); text-align: right; }

/* Camera modal */
.camera-modal, .crop-modal {
  border: none; padding: 0; background: rgba(0,0,0,0.85);
  width: 100vw; height: 100vh; max-width: 100vw; max-height: 100vh;
}
.camera-modal::backdrop, .crop-modal::backdrop { background: rgba(0,0,0,0.85); }
.camera-wrap { display: flex; flex-direction: column; height: 100vh; }
.camera-wrap video { flex: 1; width: 100%; object-fit: cover; }
.camera-actions, .crop-actions {
  background: #111; padding: 14px;
  display: flex; gap: 10px; justify-content: center; align-items: center;
  padding-bottom: max(14px, env(safe-area-inset-bottom));
}
.camera-actions button, .crop-actions button {
  padding: 12px 24px; border-radius: 8px; border: none;
  background: #444; color: white; font-weight: 600; font-size: 1rem; cursor: pointer;
}
.camera-actions button.primary, .crop-actions button.primary { background: var(--accent); }

/* Crop modal */
.crop-wrap { display: flex; flex-direction: column; height: 100vh; }
.crop-canvas-wrap {
  flex: 1; position: relative;
  display: flex; align-items: center; justify-content: center;
  overflow: hidden;
}
#crop-canvas { max-width: 100%; max-height: 100%; touch-action: none; }
.crop-overlay { position: absolute; border: 2px solid #fff; box-shadow: 0 0 0 9999px rgba(0,0,0,0.4); pointer-events: none; }
.crop-handle {
  position: absolute; width: 22px; height: 22px;
  background: var(--accent); border: 2px solid white; border-radius: 50%;
  pointer-events: auto;
  touch-action: none;
  cursor: grab;
}
.crop-handle[data-corner="tl"] { top: -11px; left: -11px; }
.crop-handle[data-corner="tr"] { top: -11px; right: -11px; }
.crop-handle[data-corner="bl"] { bottom: -11px; left: -11px; }
.crop-handle[data-corner="br"] { bottom: -11px; right: -11px; }

/* Toast */
.toast {
  position: fixed; bottom: 16px; left: 50%; transform: translateX(-50%);
  background: #333; color: white; padding: 12px 18px; border-radius: 8px;
  box-shadow: 0 4px 12px rgba(0,0,0,0.2);
  display: flex; gap: 10px; align-items: center; z-index: 1000;
}
.toast button { background: var(--accent); color: white; border: none; padding: 6px 12px; border-radius: 4px; cursor: pointer; }

.muted { color: var(--muted); }
.muted-btn { background: var(--gray) !important; }
.hidden { display: none !important; }
