/* ==========================================================================
   Mi Palta — estilos. Mobile first: la base es el celular y se ajusta
   hacia arriba para tablet y escritorio.
   ========================================================================== */

:root {
  --green-900: #2f4a1f;
  --green-700: #4f7a34;
  --green-600: #5e8f3e;
  --green-400: #93b86a;
  --green-200: #d6e6bf;
  --green-100: #ebf3dc;
  --cream: #fbf7ea;
  --cream-dark: #f1e9cf;
  --pit: #8a5a3b;
  --pit-light: #f3e3d3;
  --text: #2b3521;
  --muted: #5f6b53;
  --danger: #b3261e;
  --danger-bg: #fbe9e7;
  --radius: 20px;
  --radius-small: 14px;
  --shadow: 0 2px 10px rgba(47, 74, 31, 0.08);
  --tap: 52px; /* alto mínimo de lo que se toca con el dedo */
  color-scheme: light;
}

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

html {
  -webkit-text-size-adjust: 100%;
  scroll-behavior: smooth;
}

body {
  margin: 0;
  min-height: 100vh;
  background: var(--cream);
  color: var(--text);
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  font-size: 17px;
  line-height: 1.5;
}

img {
  max-width: 100%;
  display: block;
}

a {
  color: var(--green-700);
}

h1, h2, h3 {
  line-height: 1.2;
  color: var(--green-900);
}

h1 { font-size: 1.8rem; margin: 0.25rem 0 0.5rem; }
h2 { font-size: 1.35rem; margin: 0 0 0.75rem; }
h3 { font-size: 1.1rem; margin: 1.25rem 0 0.5rem; }

p { margin: 0 0 0.75rem; }

[hidden] {
  display: none !important;
}

.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
}

.honeypot {
  position: absolute;
  left: -10000px;
  width: 1px;
  height: 1px;
  overflow: hidden;
}

.muted { color: var(--muted); }
.center { text-align: center; }
.hint { margin: -0.35rem 0 0.5rem; font-size: 0.9rem; color: var(--muted); }

/* --- Layout -------------------------------------------------------------- */

.container {
  width: 100%;
  max-width: 720px;
  margin: 0 auto;
  padding: 1rem 1rem calc(2rem + env(safe-area-inset-bottom, 0px));
  display: grid;
  gap: 1rem;
}

.auth-page {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: calc(1rem + env(safe-area-inset-top, 0px)) 1rem calc(1rem + env(safe-area-inset-bottom, 0px));
}

.auth-page .card {
  width: 100%;
  max-width: 440px;
}

.card {
  background: #fff;
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 1.25rem;
  border: 1px solid var(--green-100);
  scroll-margin-top: 90px;
}

.stack {
  display: grid;
  gap: 0.75rem;
}

.footer {
  text-align: center;
  font-size: 0.9rem;
}

.loading {
  text-align: center;
  padding: 3rem 1rem;
  color: var(--muted);
}

/* --- Barra superior ------------------------------------------------------ */

.topbar {
  position: sticky;
  top: 0;
  z-index: 10;
  background: var(--green-700);
  color: #fff;
  padding-top: env(safe-area-inset-top, 0px);
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.12);
}

.topbar-inner {
  max-width: 720px;
  margin: 0 auto;
  padding: 0.6rem 1rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
}

.topbar-title {
  margin: 0;
  font-size: 1.25rem;
  font-weight: 700;
}

.topbar-subtitle {
  margin: 0;
  font-size: 0.85rem;
  opacity: 0.9;
}

.topbar .btn-ghost {
  color: #fff;
  border-color: rgba(255, 255, 255, 0.6);
}

/* --- Botones ------------------------------------------------------------- */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.4rem;
  min-height: var(--tap);
  padding: 0.7rem 1.2rem;
  border-radius: 999px;
  border: 2px solid transparent;
  font: inherit;
  font-weight: 600;
  text-align: center;
  text-decoration: none;
  cursor: pointer;
  transition: background-color 0.15s, border-color 0.15s;
  -webkit-tap-highlight-color: transparent;
  position: relative;
}

.btn:disabled {
  opacity: 0.6;
  cursor: not-allowed;
}

.btn:focus-visible,
.link-button:focus-visible,
input:focus-visible,
textarea:focus-visible,
.entry-photo:focus-visible,
label.btn:focus-within {
  outline: 3px solid var(--green-400);
  outline-offset: 2px;
}

.btn-primary {
  background: var(--green-700);
  color: #fff;
}

.btn-primary:hover:not(:disabled) {
  background: var(--green-900);
}

.btn-secondary {
  background: var(--green-100);
  color: var(--green-900);
  border-color: var(--green-200);
}

.btn-secondary:hover:not(:disabled) {
  background: var(--green-200);
}

.btn-ghost {
  background: transparent;
  color: var(--green-900);
  border-color: var(--green-200);
}

.btn-danger {
  background: var(--danger);
  color: #fff;
}

.btn-danger-text {
  color: var(--danger);
}

.btn-small {
  min-height: 44px;
  padding: 0.45rem 0.9rem;
  font-size: 0.95rem;
}

.link-button {
  background: none;
  border: 0;
  padding: 0.5rem;
  margin: -0.5rem 0;
  font: inherit;
  color: var(--green-700);
  text-decoration: underline;
  cursor: pointer;
}

.is-recording {
  background: var(--danger-bg);
  border-color: var(--danger);
  color: var(--danger);
}

/* --- Formularios --------------------------------------------------------- */

.field {
  display: grid;
  gap: 0.35rem;
  margin-bottom: 1rem;
}

.field > span,
.field > label,
.field-label {
  font-weight: 600;
}

.field small {
  color: var(--muted);
  font-weight: 400;
}

input[type="text"],
input[type="email"],
input[type="password"],
input[type="date"],
textarea {
  width: 100%;
  min-height: var(--tap);
  padding: 0.75rem 0.9rem;
  border: 2px solid var(--green-200);
  border-radius: var(--radius-small);
  background: #fff;
  color: var(--text);
  font: inherit;
  font-size: 1rem; /* 16px o más: evita el zoom automático en iPhone */
}

textarea {
  resize: vertical;
  min-height: 8rem;
}

input:focus,
textarea:focus {
  border-color: var(--green-600);
}

.checkbox {
  display: flex;
  align-items: flex-start;
  gap: 0.6rem;
  margin: 0.5rem 0 1rem;
}

.checkbox input {
  width: 24px;
  height: 24px;
  margin-top: 0.1rem;
  accent-color: var(--green-700);
  flex-shrink: 0;
}

.form-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.75rem;
}

.form-actions .btn {
  flex: 1 1 180px;
}

.dictation {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.5rem 0.75rem;
  margin-top: 0.25rem;
}

.dictate-status {
  margin: 0;
  font-size: 0.95rem;
  color: var(--muted);
  flex: 1 1 200px;
}

.photo-buttons {
  display: grid;
  grid-template-columns: 1fr;
  gap: 0.6rem;
}

.photo-preview {
  margin-top: 0.75rem;
  display: grid;
  gap: 0.5rem;
  justify-items: start;
}

.photo-preview img {
  max-height: 260px;
  border-radius: var(--radius-small);
  object-fit: cover;
}

/* --- Mensajes ------------------------------------------------------------ */

.message {
  padding: 0.75rem 1rem;
  border-radius: var(--radius-small);
  margin: 0.5rem 0 1rem;
}

.message-error {
  background: var(--danger-bg);
  color: var(--danger);
}

.message-success {
  background: var(--green-100);
  color: var(--green-900);
}

.message-info {
  background: var(--pit-light);
  color: #5b3a24;
}

/* --- Portada y login ----------------------------------------------------- */

.brand {
  display: inline-block;
  font-weight: 700;
  text-decoration: none;
  margin-bottom: 0.5rem;
}

.hero {
  text-align: center;
}

.hero-avocado {
  font-size: 4.5rem;
  line-height: 1;
}

.subtitle {
  font-size: 1.1rem;
  color: var(--muted);
}

.hero-list {
  list-style: none;
  padding: 0;
  margin: 1.25rem 0 1.5rem;
  text-align: left;
  display: grid;
  gap: 0.5rem;
}

.hero-list li {
  background: var(--cream);
  border-radius: var(--radius-small);
  padding: 0.6rem 0.9rem;
}

/* --- Contador ------------------------------------------------------------ */

.counter {
  text-align: center;
  background: linear-gradient(160deg, var(--green-100), #fff 70%);
  border: 2px solid var(--green-200);
}

.counter-lead {
  font-size: 1.1rem;
  color: var(--muted);
  margin-bottom: 0.25rem;
}

.counter-days {
  font-size: clamp(2.8rem, 14vw, 4rem);
  font-weight: 800;
  color: var(--green-700);
  line-height: 1.05;
  margin-bottom: 0.25rem;
}

.counter-weeks {
  font-size: 1.2rem;
  font-weight: 600;
  color: var(--pit);
}

.counter-start {
  color: var(--muted);
  display: flex;
  flex-wrap: wrap;
  gap: 0.25rem 0.75rem;
  justify-content: center;
  align-items: center;
}

/* --- Etapas -------------------------------------------------------------- */

.stages {
  list-style: none;
  padding: 0;
  margin: 0;
  display: grid;
  gap: 0.6rem;
}

.stage {
  display: flex;
  gap: 0.9rem;
  align-items: flex-start;
  padding: 0.8rem 0.9rem;
  border-radius: var(--radius-small);
  background: var(--cream);
  border: 2px solid transparent;
}

.stage p {
  margin: 0;
}

.stage-emoji {
  font-size: 1.8rem;
  line-height: 1;
}

.stage-label {
  font-size: 0.8rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--muted);
}

.stage-name {
  font-weight: 700;
}

.stage-range {
  font-size: 0.92rem;
  color: var(--muted);
}

.stage-done {
  opacity: 0.7;
}

.stage-current {
  background: var(--green-100);
  border-color: var(--green-600);
  opacity: 1;
}

.stage-badge {
  display: inline-block;
  margin-top: 0.35rem !important;
  padding: 0.15rem 0.6rem;
  border-radius: 999px;
  background: var(--green-700);
  color: #fff;
  font-size: 0.85rem;
  font-weight: 600;
}

/* --- Historial ----------------------------------------------------------- */

.entries {
  list-style: none;
  padding: 0;
  margin: 0;
  display: grid;
  gap: 0.9rem;
}

.entry {
  border: 1px solid var(--green-200);
  border-radius: var(--radius-small);
  padding: 1rem;
  background: #fff;
}

.entry-meta {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  color: var(--muted);
  font-weight: 600;
  margin-bottom: 0.35rem;
}

.badge {
  background: var(--pit-light);
  color: var(--pit);
  border-radius: 999px;
  padding: 0.1rem 0.6rem;
  font-size: 0.85rem;
}

.entry-title {
  margin: 0.2rem 0 0.4rem;
}

.entry-content {
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}

.entry-photo {
  display: block;
  padding: 0;
  border: 0;
  background: none;
  cursor: zoom-in;
  margin: 0.25rem 0 0.75rem;
  border-radius: var(--radius-small);
  overflow: hidden;
}

.entry-photo img {
  max-height: 320px;
  width: auto;
  object-fit: cover;
}

.entry-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
}

/* --- Consejos ------------------------------------------------------------ */

.tips {
  padding-left: 1.2rem;
  margin: 0;
  display: grid;
  gap: 0.5rem;
}

/* --- Importación --------------------------------------------------------- */

.import-summary {
  margin-top: 1rem;
  padding: 1rem;
  border-radius: var(--radius-small);
  background: var(--cream);
  border: 1px solid var(--cream-dark);
}

.import-summary ul {
  margin: 0 0 0.75rem;
  padding-left: 1.2rem;
}

/* --- Diálogos ------------------------------------------------------------ */

.dialog {
  border: 0;
  border-radius: var(--radius);
  padding: 1.25rem;
  width: min(92vw, 440px);
  box-shadow: 0 10px 40px rgba(0, 0, 0, 0.25);
  color: var(--text);
}

.dialog::backdrop {
  background: rgba(30, 40, 20, 0.55);
}

.dialog h3 {
  margin-top: 0;
}

.dialog-photo {
  width: min(96vw, 900px);
  padding: 0.75rem;
}

.dialog-photo form {
  display: grid;
  gap: 0.75rem;
}

.dialog-photo img {
  max-height: 78vh;
  margin: 0 auto;
  border-radius: var(--radius-small);
}

/* --- Pantallas más grandes ---------------------------------------------- */

@media (min-width: 600px) {
  body { font-size: 18px; }
  .container { padding: 1.5rem 1.5rem 3rem; gap: 1.25rem; }
  .card { padding: 1.75rem; }
  .photo-buttons { grid-template-columns: 1fr 1fr; }
  .stages { grid-template-columns: 1fr 1fr; }
  .stages .stage:last-child { grid-column: 1 / -1; }
}

@media (prefers-reduced-motion: reduce) {
  html { scroll-behavior: auto; }
  * { transition: none !important; }
}

/* ==========================================================================
   FrutiApp: varios seguimientos, plantillas y administración
   ========================================================================== */

.topbar-actions {
  display: flex;
  gap: 0.5rem;
}

/* Pestañas de seguimientos, dentro de la barra superior */
.tracker-tabs {
  max-width: 720px;
  margin: 0 auto;
  padding: 0 1rem 0.6rem;
  display: flex;
  gap: 0.5rem;
  overflow-x: auto;
  scrollbar-width: none;
}

.tracker-tabs::-webkit-scrollbar {
  display: none;
}

.tracker-tabs:empty {
  display: none;
}

.tracker-tab {
  flex: 0 0 auto;
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  min-height: 44px;
  padding: 0.3rem 0.9rem 0.3rem 0.35rem;
  border-radius: 999px;
  border: 2px solid rgba(255, 255, 255, 0.35);
  background: rgba(255, 255, 255, 0.12);
  color: #fff;
  font: inherit;
  font-size: 0.95rem;
  font-weight: 600;
  text-decoration: none;
  cursor: pointer;
  white-space: nowrap;
}

.tracker-tab img {
  width: 32px;
  height: 32px;
  border-radius: 10px;
}

.tracker-tab.is-active {
  background: #fff;
  color: var(--green-900);
  border-color: #fff;
}

.tracker-tab-add {
  padding-left: 0.9rem;
  border-style: dashed;
}

/* Contador con ilustración */
.counter-illustration {
  width: 96px;
  height: 96px;
  margin: 0 auto 0.5rem;
  border-radius: 24px;
}

.counter-title {
  font-size: 1.4rem;
  margin: 0 0 0.25rem;
  color: var(--green-900);
}

/* Elegir plantilla */
.pick-intro h1 {
  margin-top: 0;
}

.plan-pill {
  display: inline-block;
  margin: 0.25rem 0 0;
  padding: 0.35rem 0.9rem;
  border-radius: 999px;
  background: var(--green-100);
  color: var(--green-900);
  font-weight: 600;
  font-size: 0.95rem;
}

.template-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 0.75rem;
}

.template-card {
  display: grid;
  justify-items: center;
  align-content: start;
  gap: 0.3rem;
  padding: 0.9rem 0.6rem 1rem;
  border: 2px solid var(--green-100);
  border-radius: var(--radius);
  background: #fff;
  font: inherit;
  color: var(--text);
  text-align: center;
  cursor: pointer;
  transition: border-color 0.15s, transform 0.15s;
}

.template-card:hover,
.template-card:focus-visible {
  border-color: var(--green-400);
  transform: translateY(-2px);
}

.template-card img {
  width: 84px;
  height: 84px;
  border-radius: 20px;
}

.template-name {
  font-weight: 700;
  line-height: 1.2;
}

.template-tagline {
  font-size: 0.88rem;
  color: var(--muted);
  line-height: 1.3;
}

.dialog-illustration {
  width: 88px;
  height: 88px;
  border-radius: 22px;
  margin-bottom: 0.5rem;
}

.limit-box {
  padding: 1rem;
  border-radius: var(--radius-small);
  background: var(--pit-light);
  margin-bottom: 1rem;
}

.divider {
  border: 0;
  border-top: 1px solid var(--green-100);
  margin: 1.25rem 0 0.75rem;
}

/* Administración */
.container-wide {
  max-width: 1100px;
}

.table-scroll {
  overflow-x: auto;
}

.admin-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.92rem;
}

.admin-table th,
.admin-table td {
  padding: 0.55rem 0.6rem;
  border-bottom: 1px solid var(--green-100);
  text-align: left;
  white-space: nowrap;
}

.admin-table th {
  color: var(--muted);
  font-weight: 600;
}

.row-highlight {
  background: var(--pit-light);
}

@media (min-width: 600px) {
  .template-grid {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }
}
