:root {
  color-scheme: light;
  --brand: #8a1f2d;
  --brand-dark: #6a1622;
  --bg: #f4f2f1;
  --card: #ffffff;
  --text: #262322;
  --muted: #756f6c;
  --border: #e2ddda;
  --error: #b3261e;
  --ok: #2e7d32;
  --radius: 14px;
  font-size: 16px;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
}

body {
  min-height: 100vh;
  padding-bottom: env(safe-area-inset-bottom);
}

.view { display: none; min-height: 100vh; }
.view.active { display: block; }

/* LOGIN */
#view-login.active {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
}
.login-card {
  background: var(--card);
  border-radius: var(--radius);
  padding: 32px 24px;
  width: 100%;
  max-width: 360px;
  box-shadow: 0 4px 24px rgba(0,0,0,0.08);
  text-align: center;
}
.login-logo { width: 64px; height: 64px; border-radius: 16px; margin-bottom: 12px; }
.login-card h1 { font-size: 1.25rem; margin: 0 0 4px; }
.login-card .subtitle { color: var(--muted); margin: 0 0 20px; font-size: 0.9rem; }
.login-card form { text-align: left; display: flex; flex-direction: column; gap: 14px; }

/* FORMS */
label {
  display: flex;
  flex-direction: column;
  gap: 6px;
  font-size: 0.85rem;
  color: var(--muted);
  font-weight: 600;
}
input, select, textarea {
  font-size: 1rem;
  padding: 12px 14px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: #fff;
  color: var(--text);
  font-family: inherit;
  width: 100%;
}
input:focus, select:focus, textarea:focus {
  outline: 2px solid var(--brand);
  outline-offset: 1px;
}
textarea { resize: vertical; }

button {
  font-size: 1rem;
  font-weight: 700;
  padding: 14px 18px;
  border-radius: 10px;
  border: none;
  background: var(--brand);
  color: #fff;
  cursor: pointer;
}
button:active { background: var(--brand-dark); }
button:disabled { opacity: 0.6; cursor: not-allowed; }

.icon-btn {
  background: none;
  color: var(--brand);
  font-weight: 600;
  padding: 8px 6px;
  width: 3.5rem;
  text-align: left;
}

.error-text {
  color: var(--error);
  font-size: 0.85rem;
  font-weight: 600;
  margin: 0;
}

/* TOPBAR */
.topbar {
  position: sticky;
  top: 0;
  z-index: 5;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 14px 16px;
  padding-top: calc(14px + env(safe-area-inset-top));
  background: var(--brand);
  color: #fff;
}
.topbar strong { font-size: 1rem; }
.topbar-sub { display: block; font-size: 0.75rem; opacity: 0.85; }
.topbar .icon-btn { color: #fff; }

/* LIST */
.list-container {
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  padding-bottom: 100px;
}
.ficha-card {
  background: var(--card);
  border-radius: var(--radius);
  padding: 14px 16px;
  box-shadow: 0 1px 4px rgba(0,0,0,0.06);
  display: flex;
  flex-direction: column;
  gap: 4px;
  cursor: pointer;
}
.ficha-card .titulo { font-weight: 700; }
.ficha-card .meta { color: var(--muted); font-size: 0.85rem; }
.badge {
  align-self: flex-start;
  font-size: 0.7rem;
  font-weight: 700;
  padding: 2px 8px;
  border-radius: 999px;
  text-transform: uppercase;
}
.badge.creada { background: #e3f3e3; color: var(--ok); }
.badge.pendiente { background: #fff3d6; color: #8a6d00; }
.badge.error { background: #fbe3e1; color: var(--error); }

.empty-state {
  color: var(--muted);
  text-align: center;
  padding: 40px 16px;
}

.fab {
  position: fixed;
  right: 16px;
  bottom: calc(16px + env(safe-area-inset-bottom));
  border-radius: 999px;
  padding: 16px 22px;
  box-shadow: 0 4px 16px rgba(0,0,0,0.25);
}

/* FICHA FORM */
.ficha-form {
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 16px;
  padding-bottom: 60px;
}
.row-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
@media (max-width: 420px) {
  .row-2 { grid-template-columns: 1fr; }
}
.preview-fotos {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}
.preview-fotos img, .preview-fotos .file-chip {
  width: 64px;
  height: 64px;
  object-fit: cover;
  border-radius: 8px;
  border: 1px solid var(--border);
}
.preview-fotos .file-chip {
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.65rem;
  text-align: center;
  padding: 4px;
  color: var(--muted);
}

/* DETAIL */
.detail-container { padding: 16px; display: flex; flex-direction: column; gap: 12px; }
.detail-field { display: flex; justify-content: space-between; gap: 12px; font-size: 0.95rem; }
.detail-field .label { color: var(--muted); }
.nota-item {
  background: var(--card);
  border-radius: 10px;
  padding: 10px 12px;
  font-size: 0.9rem;
}
.nota-item .fecha { color: var(--muted); font-size: 0.75rem; }
.add-nota-form { border-top: 1px solid var(--border); margin-top: 8px; }

.toast {
  position: fixed;
  left: 50%;
  bottom: 24px;
  transform: translateX(-50%);
  background: var(--text);
  color: #fff;
  padding: 10px 18px;
  border-radius: 999px;
  font-size: 0.9rem;
  z-index: 20;
}
