:root {
  --bg: #14181C;
  --panel: #1D2227;
  --panel-border: #2E343B;
  --rule: #2A2F35;
  --ink-light: #EDE6D6;
  --ink-muted: #8A9099;
  --amber: #E8A33D;
  --teal: #2F6F62;
  --red: #C0432E;
  --card-bg: #EDE6D6;
  --card-ink: #1B1F23;
  --card-muted: #5B5445;
  --card-photo-bg: #DCD3BC;

  --font-body: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  --font-slab: Georgia, "Times New Roman", serif;
  --font-mono: "SFMono-Regular", Consolas, "Liberation Mono", Menlo, monospace;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  font-family: var(--font-body);
  color: var(--ink-light);
}

.font-slab { font-family: var(--font-slab); }
.font-mono { font-family: var(--font-mono); }

button { font-family: inherit; }

@keyframes riseIn { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: translateY(0); } }
.rise-in { animation: riseIn .25s ease-out both; }
@media (prefers-reduced-motion: reduce) { .rise-in { animation: none; } }

@keyframes spin { to { transform: rotate(360deg); } }
.spinner { width: 16px; height: 16px; border: 2px solid rgba(255,255,255,.25); border-top-color: currentColor; border-radius: 50%; display: inline-block; animation: spin .7s linear infinite; }

/* Header */
.app-header { position: sticky; top: 0; z-index: 20; background: var(--bg); border-bottom: 1px solid var(--rule); }
.header-inner { max-width: 672px; margin: 0 auto; padding: 24px 20px 16px; }
.eyebrow-row { display: flex; align-items: center; gap: 8px; margin-bottom: 6px; color: var(--amber); }
.eyebrow-text { font-size: 11px; letter-spacing: .22em; }
.eyebrow-rule { width: 34px; height: 2px; background: var(--amber); border-radius: 2px; margin-bottom: 10px; }
.app-title { font-size: 28px; font-weight: 700; margin: 0; color: var(--ink-light); }
.app-subtitle { font-size: 14px; margin: 4px 0 0; color: var(--ink-muted); }
.header-top { display: flex; align-items: flex-start; justify-content: space-between; gap: 12px; flex-wrap: wrap; }
.header-user-col { display: flex; flex-direction: column; align-items: flex-end; gap: 6px; padding-top: 2px; max-width: 100%; }
.header-user-col .app-subtitle { max-width: 220px; overflow-wrap: anywhere; text-align: right; }

.search-wrap { position: relative; margin-top: 16px; }
.search-icon { position: absolute; left: 12px; top: 50%; transform: translateY(-50%); color: var(--ink-muted); pointer-events: none; }
.search-input { width: 100%; font-size: 14px; border-radius: 8px; padding: 12px 12px 12px 36px; outline: none; background: var(--panel); color: var(--ink-light); border: 1px solid var(--panel-border); }

.chips-row { display: flex; gap: 8px; margin-top: 12px; overflow-x: auto; padding-bottom: 4px; }
.chip { flex-shrink: 0; border-radius: 999px; padding: 6px 14px; font-size: 12px; font-weight: 600; white-space: nowrap; background: var(--panel); color: var(--ink-muted); border: 1px solid var(--panel-border); cursor: pointer; }
.chip.active { background: var(--amber); color: var(--bg); border-color: var(--amber); }

/* Main / list */
main { max-width: 672px; margin: 0 auto; padding: 20px 20px 112px; }
.list { display: flex; flex-direction: column; gap: 20px; }
.group-header { display: flex; align-items: center; gap: 8px; margin-bottom: 8px; padding: 0 2px; }
.group-title { font-size: 16px; font-weight: 700; color: var(--ink-light); }
.group-count { font-size: 11px; color: var(--ink-muted); }
.group-rule { flex: 1; height: 1px; background: var(--rule); }
.group-items { display: flex; flex-direction: column; gap: 12px; }

.card { display: flex; border-radius: 12px; overflow: hidden; background: var(--card-bg); border: 1px solid rgba(46,52,59,.15); }
.card-photo { width: 96px; flex-shrink: 0; background: var(--card-photo-bg); display: flex; align-items: center; justify-content: center; }
.card-photo img { width: 100%; height: 100%; object-fit: cover; display: block; }
.card-body { flex: 1; padding: 12px 16px; min-width: 0; }
.card-top { display: flex; align-items: flex-start; justify-content: space-between; gap: 8px; }
.card-name { font-size: 18px; font-weight: 700; color: var(--card-ink); margin: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.card-delete { flex-shrink: 0; padding: 4px; border-radius: 6px; background: none; border: none; cursor: pointer; color: #8A7C5A; }
.card-coords { font-size: 12px; margin: 4px 0 0; color: var(--card-muted); }
.card-date { font-size: 11px; margin: 2px 0 0; color: var(--card-muted); opacity: .75; }
.card-maps-btn { margin-top: 8px; display: inline-flex; align-items: center; gap: 6px; font-size: 12px; font-weight: 600; border-radius: 999px; padding: 6px 12px; background: var(--card-ink); color: var(--amber); border: none; cursor: pointer; }

.empty { text-align: center; padding: 64px 0; }
.empty-title { font-size: 18px; color: var(--ink-light); margin: 0; }
.empty-sub { font-size: 14px; margin: 4px 0 0; color: var(--ink-muted); }
.empty-error { font-size: 13px; color: var(--red); margin: 0; }
.empty-hint { font-size: 12px; margin-top: 8px; color: var(--ink-muted); }

/* FAB + toast */
.fab { position: fixed; bottom: 24px; right: 20px; width: 58px; height: 58px; border-radius: 999px; background: var(--amber); border: none; display: flex; align-items: center; justify-content: center; box-shadow: 0 8px 20px rgba(0,0,0,.4); cursor: pointer; z-index: 20; color: var(--bg); }
.toast { position: fixed; bottom: 96px; left: 50%; transform: translateX(-50%); z-index: 30; padding: 8px 16px; border-radius: 8px; font-size: 14px; font-weight: 500; background: var(--panel); color: var(--ink-light); border: 1px solid var(--panel-border); display: none; }
.toast.show { display: block; }

/* Modales */
.overlay { position: fixed; inset: 0; z-index: 40; display: none; align-items: flex-end; justify-content: center; background: rgba(10,12,14,.6); }
.overlay.show { display: flex; }
@media (min-width: 640px) { .overlay { align-items: center; } }

.modal { width: 100%; max-width: 420px; border-radius: 20px 20px 0 0; padding: 20px; max-height: 90vh; overflow-y: auto; background: var(--panel); border: 1px solid var(--panel-border); }
@media (min-width: 640px) { .modal { border-radius: 20px; } }

.modal-small { max-width: 360px; border-radius: 16px; }

.modal-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 16px; }
.modal-title { font-size: 20px; font-weight: 700; color: var(--ink-light); margin: 0; }
.modal-close-btn { background: none; border: none; cursor: pointer; color: var(--ink-muted); padding: 4px; }

.field-label { display: block; font-size: 11px; letter-spacing: .05em; color: var(--ink-muted); margin-bottom: 6px; }
.text-input { width: 100%; border-radius: 8px; padding: 10px 12px; font-size: 14px; outline: none; background: var(--bg); color: var(--ink-light); border: 1px solid var(--panel-border); margin-bottom: 16px; }

.chip-select { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 16px; }
.chip-select .chip:not(.active) { background: var(--bg); }

.photo-btn { width: 100%; display: flex; align-items: center; justify-content: center; gap: 8px; border-radius: 8px; padding: 12px; font-size: 14px; font-weight: 500; margin-bottom: 16px; background: var(--bg); color: var(--ink-light); border: 1px dashed #3A4149; cursor: pointer; }
.photo-preview { width: 100%; height: 144px; object-fit: cover; border-radius: 8px; margin-bottom: 16px; display: none; }
.photo-preview.show { display: block; }

.gps-btn { width: 100%; display: flex; align-items: center; justify-content: center; gap: 8px; border-radius: 8px; padding: 12px; font-size: 14px; font-weight: 600; margin-bottom: 4px; background: var(--amber); color: var(--bg); border: none; cursor: pointer; }
.gps-coords { font-size: 12px; margin: 8px 0; color: var(--ink-muted); display: none; }
.gps-coords.show { display: block; }
.gps-error { font-size: 12px; margin: 8px 0; color: var(--red); display: none; }
.gps-error.show { display: block; }

.save-btn { width: 100%; margin-top: 16px; padding: 12px; border-radius: 8px; font-size: 14px; font-weight: 700; background: var(--amber); color: var(--bg); border: none; cursor: pointer; }
.save-btn:disabled { opacity: .4; cursor: not-allowed; }

.btn-row { display: flex; gap: 12px; margin-top: 16px; }
.btn-cancel { flex: 1; padding: 10px; border-radius: 8px; font-size: 14px; font-weight: 600; background: #2A2F35; color: var(--ink-light); border: none; cursor: pointer; }
.btn-danger { flex: 1; padding: 10px; border-radius: 8px; font-size: 14px; font-weight: 600; background: var(--red); color: #F5F1E8; border: none; cursor: pointer; }

/* PIN */
.pin-screen { position: fixed; inset: 0; z-index: 50; display: none; align-items: center; justify-content: center; padding: 0 24px; background: var(--bg); }
.pin-screen.show { display: flex; }
.pin-box { width: 100%; max-width: 320px; }

.field-row { display: flex; gap: 8px; }
.field-row > * { flex: 1; min-width: 0; }

.hidden { display: none !important; }
.photo-modal-img { max-width: 92vw; max-height: 88vh; border-radius: 12px; display: block; object-fit: contain; }

@media (max-width: 380px) {
  .app-title { font-size: 24px; }
  .field-row { flex-direction: column; }
  .field-row > * { margin-bottom: 10px; }
  .field-row > *:last-child { margin-bottom: 0; }
  .header-user-col .app-subtitle { max-width: 140px; }
  .card-photo { width: 76px; }
}

@media (min-width: 900px) {
  .header-inner, main { max-width: 820px; }
  .card-photo { width: 120px; }
}
