/* TuLancho — small overrides on top of Pico. Green/palm accent, mobile-first. */

:root {
  --pico-primary: #2f7d4f;
  --pico-primary-hover: #276843;
  --pico-primary-focus: rgba(47, 125, 79, 0.25);
  --pico-primary-inverse: #fff;
}
:root:not([data-theme="dark"]),
[data-theme="light"] {
  --pico-primary: #2f7d4f;
  --pico-primary-hover: #276843;
}

/* Top navigation */
.tl-nav {
  border-bottom: 1px solid var(--pico-muted-border-color);
  margin-bottom: 1rem;
}
.tl-brand {
  font-weight: 700;
  text-decoration: none;
}
.tl-user {
  font-size: 0.85rem;
  color: var(--pico-muted-color);
}
.tl-logout {
  margin: 0;
}
.tl-logout button {
  margin: 0;
  padding: 0.3rem 0.75rem;
  font-size: 0.85rem;
}

/* --- Collapsible mobile navigation (no JS; a checkbox drives the overlay) ---
   On desktop the drawer is transparent (display:contents), so the links and the
   user/logout group sit directly in the nav bar exactly as before. Below Pico's
   breakpoint the bar shows only the brand + a "Menú" button, and the drawer turns
   into a centered floating card over a dimmed (still-visible) page. */
.tl-nav-drawer {
  display: contents;
}
/* These controls exist only for the mobile overlay. */
.tl-menu-open,
.tl-menu-backdrop,
.tl-menu-head,
.tl-menu-close {
  display: none;
}

@media (max-width: 767px) {
  /* Hamburger button in the top bar */
  .tl-menu-open {
    display: inline-flex;
    align-items: center;
    gap: 0.35rem;
    margin: 0;
    padding: 0.35rem 0.8rem;
    font-size: 0.9rem;
    font-weight: 600;
    line-height: 1;
    color: #fff;
    background: var(--pico-primary);
    border: 1px solid var(--pico-primary);
    border-radius: var(--pico-border-radius);
    cursor: pointer;
    user-select: none;
  }
  .tl-menu-icon {
    font-size: 1.15rem;
  }

  /* Closed by default; the checked toggle reveals the card + backdrop. */
  .tl-nav-drawer {
    display: none;
  }
  .tl-menu-backdrop {
    position: fixed;
    inset: 0;
    z-index: 1000;
    background: rgba(0, 0, 0, 0.25);
    backdrop-filter: blur(4px);
    -webkit-backdrop-filter: blur(4px);
  }
  .tl-menu-toggle:checked ~ .tl-nav .tl-menu-backdrop {
    display: block;
  }
  .tl-menu-toggle:checked ~ .tl-nav .tl-nav-drawer {
    display: block;
    position: fixed;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    z-index: 1001;
    width: min(22rem, 88vw);
    max-height: 82vh;
    overflow-y: auto;
    padding: 0.5rem 0.75rem 0.75rem;
    background: linear-gradient(135deg, rgba(255, 255, 255, 0.7), rgba(255, 255, 255, 0.45));
    backdrop-filter: blur(24px) saturate(180%);
    -webkit-backdrop-filter: blur(24px) saturate(180%);
    border: 1px solid rgba(255, 255, 255, 0.7);
    border-radius: var(--pico-border-radius);
    box-shadow: 0 16px 48px rgba(0, 0, 0, 0.25),
                inset 0 1px 0 rgba(255, 255, 255, 0.7);
  }

  /* Card header: title + close (✕) */
  .tl-menu-head {
    position: relative;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0.25rem 0.25rem 0.5rem;
    margin-bottom: 0.25rem;
    border-bottom: 1px solid var(--pico-muted-border-color);
  }
  .tl-menu-close {
    position: absolute;
    right: 0.1rem;
    top: 0.1rem;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 2rem;
    height: 2rem;
    font-size: 1.1rem;
    line-height: 1;
    color: var(--pico-muted-color);
    background: transparent;
    border: 0;
    cursor: pointer;
    border-radius: var(--pico-border-radius);
  }
  .tl-menu-close:hover {
    background: rgba(0, 0, 0, 0.06);
    color: var(--pico-color);
  }

  /* Stacked links with generous tap targets */
  .tl-nav-main,
  .tl-nav-side {
    display: block;
    margin: 0;
    padding: 0;
  }
  .tl-nav-main li,
  .tl-nav-side li {
    display: block;
    padding: 0;
  }
  .tl-nav-main a {
    display: block;
    padding: 0.7rem 0.5rem;
    border-radius: var(--pico-border-radius);
    text-decoration: none;
    text-align: center;
  }
  .tl-nav-main a:hover {
    background: var(--pico-primary-focus);
  }
  /* Current page: a legible green "you are here" pill, not clickable */
  .tl-nav-main a[aria-current="page"] {
    color: #1b5e34;
    background: #d5efdd;
    font-weight: 600;
    pointer-events: none;
    cursor: default;
  }

  /* User + logout below a divider */
  .tl-nav-side {
    margin-top: 0.5rem;
    padding-top: 0.5rem;
    border-top: 1px solid var(--pico-muted-border-color);
  }
  .tl-nav-side .tl-user {
    padding: 0.35rem 0.5rem;
    text-align: center;
  }
  .tl-logout button {
    width: 100%;
  }
}

/* Login */
.tl-login {
  max-width: 26rem;
  margin-top: 3rem;
}

/* Month picker */
.tl-monthpick {
  display: flex;
  gap: 0.5rem;
  align-items: center;
  max-width: 22rem;
}
.tl-monthpick input {
  margin: 0;
}
.tl-monthpick button {
  margin: 0;
  width: auto;
  white-space: nowrap;
}

/* Totals cards */
.tl-totals article {
  margin: 0;
  padding: 0.75rem 1rem;
  text-align: center;
}
.tl-totals h3 {
  margin: 0;
  font-size: 1.25rem;
}
.tl-totals p {
  margin: 0;
  font-size: 0.8rem;
  color: var(--pico-muted-color);
}

/* Spacing around the "+ Nuevo gasto" action */
.tl-actionbar {
  margin: 1.25rem 0;
}

@media (max-width: 767px) {
  /* Tighter total cards — the default padding makes three tall stacked boxes */
  .tl-totals article {
    padding: 0.5rem 0.85rem;
  }
  .tl-totals article hgroup {
    margin: 0;
  }
  .tl-totals h3 {
    font-size: 1.1rem;
  }
  .tl-totals.grid {
    gap: 0.6rem;
  }

  /* Stack the filters so the date pickers stop overflowing off-screen.
     Pico lays out role="search" forms as an inline-flex row (nowrap), so we
     override to block and let each full-width field stack. */
  .tl-filters.grid {
    display: block;
  }
  .tl-filters.grid label {
    display: block;
    margin: 0 0 0.6rem 0;
    min-width: 0;
  }
  .tl-filters.grid input,
  .tl-filters.grid select,
  .tl-filters.grid button {
    width: 100%;
    min-width: 0;
  }
}

/* Right-align numeric columns */
.tl-num {
  text-align: right;
  font-variant-numeric: tabular-nums;
}

/* Status badges */
.tl-badge {
  display: inline-block;
  padding: 0.1rem 0.5rem;
  border-radius: 1rem;
  font-size: 0.75rem;
  font-weight: 600;
  text-transform: capitalize;
  white-space: nowrap;
}
.tl-pagado   { background: #d5efdd; color: #1b5e34; }
.tl-parcial  { background: #fdf0cf; color: #8a6300; }
.tl-pendiente{ background: #f6d9d6; color: #8a2b21; }
.tl-exento   { background: #e2e3e5; color: #494c50; }

@media (prefers-color-scheme: dark) {
  .tl-pagado   { background: #12341f; color: #8fe0a8; }
  .tl-parcial  { background: #3a2f0a; color: #e7c766; }
  .tl-pendiente{ background: #3a1512; color: #e79a90; }
  .tl-exento   { background: #2a2c2f; color: #b5b8bc; }
}

/* Data tables → tappable data-cards on mobile.
   Below Pico's breakpoint a `.tl-cards` table turns each row into a bordered
   card. Shared scaffolding lives here; each table sets its own grid-template-
   areas and picks which fields are prominent. A `.tl-row-link` inside a card
   stretches over the whole card so any tap opens the detail view. */
@media (max-width: 767px) {
  .tl-cards thead {
    display: none;
  }
  .tl-cards,
  .tl-cards tbody {
    display: block;
  }
  /* Neutralise Pico's zebra striping — cards read by their own border. */
  .tl-cards.striped > tbody > tr:nth-child(odd) {
    background: transparent;
  }
  .tl-cards tbody tr {
    position: relative;
    display: grid;
    grid-template-columns: 1fr auto;
    gap: 0.1rem 0.6rem;
    padding: 0.7rem 0.9rem;
    margin-bottom: 0.6rem;
    border: 1px solid var(--pico-muted-border-color);
    border-radius: var(--pico-border-radius);
  }
  .tl-cards td {
    display: block;
    padding: 0;
    border: 0;
  }
  /* Small, muted secondary fields with an inline "Label: " prefix */
  .tl-cards td.tl-meta {
    font-size: 0.78rem;
    color: var(--pico-muted-color);
  }
  .tl-cards td.tl-meta::before {
    content: attr(data-label) ": ";
    font-weight: 600;
  }
  /* Whole card is a tap target where a row link is present */
  .tl-row-link::after {
    content: "";
    position: absolute;
    inset: 0;
    z-index: 1;
    border-radius: var(--pico-border-radius);
  }
  .tl-cards tbody tr:has(.tl-row-link):active {
    background: var(--pico-primary-focus);
  }
  /* Empty-state row spans the whole card */
  .tl-cards td.tl-empty {
    grid-column: 1 / -1;
    color: var(--pico-muted-color);
  }

  /* --- Gastos: date + amount prominent, description, then meta --- */
  .tl-gastos tbody tr {
    grid-template-areas:
      "date   amount"
      "desc   desc"
      "cat    cat"
      "zona   photo";
  }
  .tl-gastos td[data-label="Fecha"] { grid-area: date; font-weight: 600; }
  .tl-gastos td[data-label="Fecha"] a { text-decoration: none; }
  .tl-gastos td[data-label="Monto"] {
    grid-area: amount;
    text-align: right;
    font-weight: 700;
    font-size: 1.1rem;
  }
  .tl-gastos td[data-label="Descripción"] { grid-area: desc; font-size: 0.95rem; }
  .tl-gastos td[data-label="Categoría"] { grid-area: cat; }
  .tl-gastos td[data-label="Zona"]      { grid-area: zona; }
  .tl-gastos td[data-label="Fotos"]     { grid-area: photo; text-align: right; }

  /* --- Depósitos: date + amount prominent, note, then who / proof meta --- */
  .tl-depositos tbody tr {
    grid-template-areas:
      "date   amount"
      "note   note"
      "who    proof";
  }
  .tl-depositos td[data-label="Fecha"] { grid-area: date; font-weight: 600; }
  .tl-depositos td[data-label="Monto"] {
    grid-area: amount;
    text-align: right;
    font-weight: 700;
    font-size: 1.1rem;
  }
  .tl-depositos td[data-label="Nota"]        { grid-area: note; font-size: 0.95rem; }
  .tl-depositos td[data-label="Registró"]    { grid-area: who; text-align: left; }
  .tl-depositos td[data-label="Comprobante"] { grid-area: proof; text-align: right; }

  /* --- Aprobaciones list: request + amount, status, then Sí % / votes --- */
  .tl-aprobs tbody tr {
    grid-template-areas:
      "req    amount"
      "status status"
      "yes    votes";
  }
  .tl-aprobs td[data-label="Solicitud"] { grid-area: req; }
  .tl-aprobs td[data-label="Solicitud"] a {
    font-weight: 600;
    text-decoration: none;
  }
  .tl-aprobs td[data-label="Monto"] {
    grid-area: amount;
    text-align: right;
    font-weight: 700;
    font-size: 1.1rem;
  }
  .tl-aprobs td[data-label="Estado"] { grid-area: status; margin-top: 0.15rem; }
  .tl-aprobs td[data-label="Sí"]    { grid-area: yes; text-align: left; }
  .tl-aprobs td[data-label="Votos"] { grid-area: votes; text-align: right; }

  /* --- Voters tally: socio + vote, hectares/weight, comment --- */
  .tl-voters tbody tr {
    grid-template-areas:
      "name    vote"
      "hect    peso"
      "comment comment";
  }
  .tl-voters td[data-label="Socio"] { grid-area: name; font-weight: 600; }
  .tl-voters td[data-label="Voto"]  { grid-area: vote; text-align: right; }
  .tl-voters td[data-label="Hectáreas"] { grid-area: hect; text-align: left; }
  .tl-voters td[data-label="Peso"]      { grid-area: peso; text-align: right; }
  .tl-voters td[data-label="Comentario"] {
    grid-area: comment;
    font-size: 0.8rem;
    color: var(--pico-muted-color);
    font-style: italic;
    margin-top: 0.15rem;
  }

  /* --- Palm inventory by-zone: zona + total, then the four state counts --- */
  .tl-palmzone tbody tr {
    grid-template-columns: 1fr 1fr;
    grid-template-areas:
      "zone total"
      "sem  viv"
      "hij  mue";
  }
  .tl-palmzone td[data-label="Zona"]  { grid-area: zone; font-weight: 600; }
  .tl-palmzone td[data-label="Total"] {
    grid-area: total;
    text-align: right;
    font-weight: 700;
    font-size: 1.1rem;
  }
  .tl-palmzone td[data-label="Sembradas"] { grid-area: sem; text-align: left; }
  .tl-palmzone td[data-label="Vivero"]    { grid-area: viv; text-align: left; }
  .tl-palmzone td[data-label="Hijuelos"]  { grid-area: hij; text-align: left; }
  .tl-palmzone td[data-label="Muertas"]   { grid-area: mue; text-align: left; }
  /* The totals row reads as a bolder summary card. */
  .tl-palmzone tr.tl-palmtotal {
    border-color: var(--pico-primary);
  }

  /* --- Palm history: date + total, the four counts, then who recorded it --- */
  .tl-palmhist tbody tr {
    grid-template-columns: 1fr 1fr;
    grid-template-areas:
      "date total"
      "sem  viv"
      "hij  mue"
      "who  who";
  }
  .tl-palmhist td[data-label="Fecha"] { grid-area: date; font-weight: 600; }
  .tl-palmhist td[data-label="Total"] {
    grid-area: total;
    text-align: right;
    font-weight: 700;
    font-size: 1.1rem;
  }
  .tl-palmhist td[data-label="Sembradas"] { grid-area: sem; text-align: left; }
  .tl-palmhist td[data-label="Vivero"]    { grid-area: viv; text-align: left; }
  .tl-palmhist td[data-label="Hijuelos"]  { grid-area: hij; text-align: left; }
  .tl-palmhist td[data-label="Muertas"]   { grid-area: mue; text-align: left; }
  .tl-palmhist td[data-label="Registró"]  { grid-area: who; text-align: left; margin-top: 0.15rem; }
}

/* Inline pay form (native <details>, no JS) */
.tl-pay summary {
  margin: 1.25rem 0;
  white-space: nowrap;
}
.tl-pay form {
  margin-top: 0.75rem;
  min-width: 16rem;
}
.tl-pay button[type="submit"] {
  margin-top: 0.25rem;
}

/* Caja chica highlight card */
.tl-totals article.tl-caja {
  border: 1px solid var(--pico-primary);
}
.tl-totals article.tl-caja h3 {
  color: var(--pico-primary);
}

/* Gasto filters */
.tl-filters {
  align-items: end;
  gap: 0.5rem;
}
.tl-filters label {
  margin: 0;
}
.tl-filters input,
.tl-filters select,
.tl-filters button {
  margin: 0;
}

/* Palm inventory entry: add/remove-row controls and the running total. */
.tl-palm-actions {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 0.5rem 0.75rem;
  margin: 0.5rem 0 1rem;
}
.tl-palm-actions #tl-add-row {
  width: auto;
  margin: 0;
}
.tl-palm-total {
  font-size: 0.9rem;
  color: var(--pico-muted-color);
}
.tl-palm-entry td.tl-palm-rm {
  text-align: center;
  vertical-align: middle;
}
.tl-palm-entry td.tl-palm-rm button {
  width: auto;
  margin: 0;
  padding: 0.25rem 0.6rem;
}
/* Visually-hidden (screen-reader-only) label */
.tl-vh {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
}

/* Palm inventory entry form. The capture table has four columns (Zona/Estado
   dropdowns + Año/Cantidad). On a phone those columns collapse until the selects
   show only their arrow — unreadable. Below Pico's breakpoint, stack each row
   into a labeled card so every field is full-width. Desktop keeps the table. */
@media (max-width: 767px) {
  .tl-palm-entry thead {
    display: none;
  }
  .tl-palm-entry,
  .tl-palm-entry tbody,
  .tl-palm-entry tr,
  .tl-palm-entry td {
    display: block;
    width: 100%;
  }
  .tl-palm-entry tr {
    border: 1px solid var(--pico-muted-border-color);
    border-radius: var(--pico-border-radius);
    padding: 0.5rem 0.85rem 0.75rem;
    margin-bottom: 0.75rem;
  }
  .tl-palm-entry td {
    padding: 0.35rem 0 0;
    border: 0;
  }
  .tl-palm-entry td::before {
    content: attr(data-label);
    display: block;
    font-size: 0.8rem;
    font-weight: 600;
    color: var(--pico-muted-color);
    margin-bottom: 0.15rem;
  }
  .tl-palm-entry td select,
  .tl-palm-entry td input {
    margin: 0;
    width: 100%;
  }
  /* Remove-row button: no label, right-aligned under its card. */
  .tl-palm-entry td.tl-palm-rm::before {
    display: none;
  }
  .tl-palm-entry td.tl-palm-rm {
    text-align: right;
    padding-top: 0.5rem;
  }
}

/* Photo thumbnails on the expense detail */
.tl-photos {
  gap: 0.5rem;
}
.tl-photos img {
  width: 100%;
  height: auto;
  border-radius: var(--pico-border-radius);
  object-fit: cover;
}

/* Dashboard charts — give Chart.js a bounded box so it doesn't grow endlessly */
.tl-chart {
  position: relative;
  height: 260px;
}

/* Approval tally */
.tl-tally {
  margin-top: 1rem;
}
.tl-tally progress {
  margin: 0.25rem 0;
}

/* Flash messages */
.tl-error, .tl-ok {
  padding: 0.6rem 0.9rem;
  border-radius: var(--pico-border-radius);
}
.tl-error { background: #f6d9d6; color: #8a2b21; }
.tl-ok    { background: #d5efdd; color: #1b5e34; }
@media (prefers-color-scheme: dark) {
  .tl-error { background: #3a1512; color: #e79a90; }
  .tl-ok    { background: #12341f; color: #8fe0a8; }
}
