/* AGH Farms Manager – mobile-first styles (green / amber, card based) */
:root {
  --green: #2e7d32; --green-dark: #1b5e20; --green-soft: #eaf3e8; --green-line: #cfe2cc;
  --amber: #ffa90a; --amber-dark: #e08e00;
  --bg: #f5f8f3; --card: #fff; --text: #17261a; --muted: #6a7b6c; --danger: #c62828;
  --radius: 18px; --shadow: 0 2px 8px rgba(20, 50, 25, .12);
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html { -webkit-text-size-adjust: 100%; }
body { margin: 0; background: var(--bg); color: var(--text); font: 16px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; padding-bottom: env(safe-area-inset-bottom); }
a { color: var(--green); }
h1, h2, h3 { margin: 0; }
.muted { color: var(--muted); } .small { font-size: .85rem; }
.ico { flex: none; vertical-align: middle; }

/* ---------- app bar + drawer ---------- */
.appbar { position: sticky; top: 0; z-index: 20; display: flex; align-items: center; gap: 8px; min-height: 60px; padding: env(safe-area-inset-top) 8px 0; background: var(--green); color: #fff; border-bottom: 3px solid var(--amber); }
.appbar h1 { font-size: 1.2rem; font-weight: 600; flex: 1; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.appbar-actions { display: flex; }
.icon-btn { display: inline-flex; align-items: center; justify-content: center; width: 44px; height: 44px; border: 0; border-radius: 50%; background: transparent; color: inherit; cursor: pointer; text-decoration: none; list-style: none; }
.icon-btn:active { background: rgba(255,255,255,.18); }
.icon-btn-light { color: var(--green); } .icon-btn-light:active { background: var(--green-soft); }
.scrim { position: fixed; inset: 0; background: rgba(0,0,0,.45); opacity: 0; pointer-events: none; transition: opacity .2s; z-index: 40; }
.drawer { position: fixed; top: 0; bottom: 0; left: 0; width: min(78vw, 320px); background: #fafafa; z-index: 50; transform: translateX(-100%); transition: transform .22s ease; overflow-y: auto; box-shadow: 4px 0 18px rgba(0,0,0,.25); }
body.menu-open .drawer { transform: none; } body.menu-open .scrim { opacity: 1; pointer-events: auto; }
.drawer-head { background: var(--green); color: #fff; padding: calc(env(safe-area-inset-top) + 24px) 20px 18px; display: grid; gap: 2px; }
.drawer-head span { opacity: .85; font-size: .92rem; }
.drawer-logo { width: 62px; height: 62px; object-fit: contain; margin-bottom: 8px; }
.drawer-label { margin: 18px 20px 4px; font-size: .78rem; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); font-weight: 700; }
.drawer a, .drawer button { display: flex; align-items: center; gap: 14px; width: 100%; padding: 14px 20px; color: var(--text); background: none; border: 0; font: inherit; text-decoration: none; text-align: left; cursor: pointer; }
.drawer a:active, .drawer button:active { background: var(--green-soft); }
.drawer .ico { color: var(--muted); }

/* ---------- layout ---------- */
.wrap { width: 100%; max-width: 720px; margin: 0 auto; padding: 14px 14px 110px; }
.wrap-flush { padding: 0; }
.wrap-flush > .wrap { padding-top: 6px; }
.section-title { font-size: 1.05rem; margin: 20px 2px 10px; }
.count { color: var(--muted); font-size: .9rem; margin: 0 2px 10px; }

.flash { padding: 12px 14px; border-radius: 12px; margin: 0 0 12px; font-size: .95rem; }
.flash-ok { background: #e3f3e2; color: var(--green-dark); border: 1px solid var(--green-line); }
.flash-err { background: #fdeaea; color: #8e1b1b; border: 1px solid #f3c4c4; }
.wrap-flush > .flash { position: fixed; z-index: 30; top: calc(env(safe-area-inset-top) + 10px); left: 14px; right: 14px; max-width: 692px; margin: 0 auto; box-shadow: var(--shadow); animation: toast 4.5s ease forwards; }
@keyframes toast { 0%, 85% { opacity: 1; transform: none; } 100% { opacity: 0; transform: translateY(-12px); visibility: hidden; } }

/* ---------- buttons & fields ---------- */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 8px; min-height: 46px; padding: 0 20px; border-radius: 14px; border: 1.5px solid var(--green-line); background: #fff; color: var(--green-dark); font: inherit; font-weight: 600; text-decoration: none; cursor: pointer; }
.btn:active { background: var(--green-soft); }
.btn-primary { background: var(--green); border-color: var(--green); color: #fff; }
.btn-primary:active { background: var(--green-dark); }
.btn-block { display: flex; width: 100%; }
.btn-small { min-height: 36px; padding: 0 12px; font-size: .9rem; border-radius: 12px; }
.field { display: block; margin-bottom: 14px; }
.field > span { display: block; font-size: .88rem; font-weight: 600; color: #3a4d3c; margin-bottom: 5px; }
.field small, .hint { color: var(--muted); font-weight: 400; font-size: .8rem; }
.hint { display: block; margin-top: 5px; }
input[type=text], input[type=email], input[type=password], input[type=number], input[type=date], input[type=search], input:not([type]), select, textarea {
  width: 100%; min-height: 48px; padding: 10px 14px; border: 1.5px solid var(--green-line); border-radius: 14px; background: #f8fbf7; color: var(--text); font: inherit; appearance: none; -webkit-appearance: none; }
input[type=date] { min-width: 0; }
select { background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='8'%3E%3Cpath d='M1 1l5 5 5-5' fill='none' stroke='%232e7d32' stroke-width='2'/%3E%3C/svg%3E"); background-repeat: no-repeat; background-position: right 14px center; padding-right: 38px; }
textarea { resize: vertical; }
input:disabled { opacity: .65; }
input:focus, select:focus, textarea:focus { outline: 3px solid rgba(46,125,50,.25); border-color: var(--green); }
.row2 { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.check { display: flex; align-items: center; gap: 8px; font-size: .92rem; }
.check input { width: 20px; height: 20px; accent-color: var(--green); }
.form-actions { display: grid; grid-template-columns: 1fr 2fr; gap: 12px; margin-top: 4px; }

/* ---------- landing / auth ---------- */
.landing { background: linear-gradient(180deg, #2f3b4a 0%, #8a4b46 22%, #e0644a 40%, #f2a14d 52%, #4d7a3a 53%, #2e7d32 70%, #1b5e20 100%) fixed; min-height: 100vh; }
.landing-main { max-width: 440px; margin: 0 auto; padding: calc(env(safe-area-inset-top) + 28px) 18px 30px; }
.landing-hero { text-align: center; color: #fff; margin-bottom: 22px; text-shadow: 0 1px 8px rgba(0,0,0,.35); }
.landing-logo { width: 104px; height: 104px; object-fit: contain; filter: drop-shadow(0 2px 6px rgba(0,0,0,.35)); }
.landing-hero h1 { font-size: 1.75rem; margin-top: 8px; }
.landing-hero p { margin: 6px 0 0; opacity: .95; }
.auth-card { background: #fff; border-radius: 24px; padding: 18px; box-shadow: 0 10px 30px rgba(0,0,0,.28); }
.seg { display: grid; grid-auto-flow: column; grid-auto-columns: 1fr; gap: 4px; padding: 4px; background: var(--bg); border: 1px solid var(--green-line); border-radius: 16px; margin-bottom: 18px; }
.seg a { text-align: center; padding: 11px 6px; border-radius: 12px; text-decoration: none; font-weight: 600; color: var(--muted); }
.seg a.on { background: var(--green-soft); color: var(--green-dark); box-shadow: inset 0 0 0 1.5px var(--green-line); }
.auth-switch { text-align: center; margin: 16px 0 2px; color: var(--muted); }
.landing-foot { text-align: center; color: rgba(255,255,255,.85); font-size: .85rem; margin-top: 18px; }

/* ---------- dashboard ---------- */
.greet h2 { font-size: 1.4rem; } .greet p { margin: 2px 0 14px; color: var(--muted); }
.tiles { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; }
.tile { background: var(--card); border-radius: 16px; padding: 12px 8px; text-align: center; box-shadow: var(--shadow); border-top: 4px solid var(--amber); }
.tile b { display: block; font-size: 1.6rem; color: var(--green); line-height: 1.1; }
.tile span { font-size: .78rem; color: var(--muted); }
.tile-main { background: var(--green); }
.tile-main b { color: #fff; } .tile-main span { color: #dcefd9; }
.filters { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-bottom: 14px; }
.searchbox { grid-column: 1 / -1; display: flex; align-items: center; gap: 8px; padding: 0 14px; border: 1.5px solid var(--green-line); border-radius: 14px; background: var(--green-soft); color: var(--green); }
.searchbox input { border: 0; background: transparent; min-height: 46px; padding: 0; outline: 0 !important; color: var(--text); }
.filters select { background-color: var(--green-soft); }
.cards { list-style: none; margin: 0; padding: 0; display: grid; gap: 10px; }
.card { display: flex; align-items: center; gap: 12px; padding: 12px 14px; background: var(--card); border-radius: 16px; box-shadow: var(--shadow); border-left: 5px solid var(--amber); color: inherit; text-decoration: none; }
.card:active { background: #fbfdfa; transform: scale(.995); }
.thumb { width: 64px; height: 64px; border-radius: 14px; object-fit: cover; flex: none; background: #fff3d6; }
.thumb-empty { display: inline-flex; align-items: center; justify-content: center; font-size: 2rem; }
.cow-main { flex: 1; min-width: 0; display: grid; }
.cow-tag { font-size: 1.1rem; } .cow-name { color: var(--muted); }
.cow-sub { color: var(--muted); font-size: .8rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.cow-side { display: grid; gap: 6px; justify-items: end; align-self: stretch; align-content: space-between; }
.gender { color: var(--green); }
.chip { display: inline-block; padding: 2px 10px; border-radius: 99px; font-size: .74rem; font-weight: 600; background: #eef2ec; color: #44574a; }
.chip-lactating { background: #fff0cf; color: #8a5a00; } .chip-pregnant { background: #e6efff; color: #214a99; }
.chip-active { background: var(--green-soft); color: var(--green-dark); }
.chip-sold, .chip-deceased { background: #f1e7e7; color: #7a3030; }
.empty { text-align: center; padding: 34px 16px; background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow); }
.empty p { color: var(--muted); } .empty-emoji { font-size: 3rem; }
.fab { position: fixed; right: 16px; bottom: calc(16px + env(safe-area-inset-bottom)); z-index: 15; display: inline-flex; align-items: center; gap: 8px; min-height: 52px; padding: 0 22px; background: var(--green); color: #fff; border-radius: 99px; font-weight: 700; text-decoration: none; box-shadow: 0 6px 16px rgba(0,0,0,.3); }
.fab:active { background: var(--green-dark); }

/* ---------- cattle detail ---------- */
.hero { position: relative; height: 200px; padding-top: env(safe-area-inset-top); background: linear-gradient(180deg, #5d6371 0%, #c8604d 38%, #f0a057 52%, #5a8441 53%, #2f6a2e 100%); color: #fff; }
.hero-back { position: absolute; left: 8px; top: calc(env(safe-area-inset-top) + 10px); background: rgba(0,0,0,.18); }
.kebab { position: absolute; right: 8px; top: calc(env(safe-area-inset-top) + 10px); z-index: 5; }
.kebab summary { background: rgba(0,0,0,.18); }
.kebab summary::-webkit-details-marker { display: none; }
.kebab-menu { position: absolute; right: 0; top: 50px; min-width: 200px; background: #fff; border-radius: 14px; box-shadow: 0 8px 24px rgba(0,0,0,.28); overflow: hidden; }
.kebab-menu a, .kebab-menu button { display: flex; align-items: center; gap: 12px; width: 100%; padding: 14px 16px; background: none; border: 0; font: inherit; color: var(--text); text-decoration: none; text-align: left; cursor: pointer; }
.kebab-menu a:active, .kebab-menu button:active { background: var(--green-soft); }
.kebab-menu .danger { color: var(--danger); }
.hero-avatar { position: absolute; left: 50%; top: calc(env(safe-area-inset-top) + 20px); transform: translateX(-50%); width: 104px; height: 104px; border-radius: 50%; background: #fff; border: 3px solid #ffffffd9; box-shadow: 0 4px 14px rgba(0,0,0,.3); overflow: hidden; display: block; }
.avatar { width: 100%; height: 100%; object-fit: cover; display: flex; align-items: center; justify-content: center; font-size: 3.4rem; background: #fff3d6; }
.hero-tag { position: absolute; left: 16px; bottom: 12px; display: flex; align-items: baseline; gap: 10px; text-shadow: 0 2px 8px rgba(0,0,0,.6); }
.hero-tag b { font-size: 2.6rem; line-height: 1; } .hero-tag span { font-size: 1.1rem; opacity: .95; }
.tabs { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; padding: 6px; margin: 10px 0 14px; background: #f3f6f1; border: 1px solid var(--green-line); border-radius: 18px; }
.tabs a { display: flex; align-items: center; justify-content: center; gap: 8px; min-height: 48px; border-radius: 14px; text-decoration: none; color: var(--muted); font-weight: 600; }
.tabs a.on { background: var(--green-soft); color: var(--green-dark); box-shadow: inset 0 0 0 1.5px var(--green-line); }
.tabs a.on .ico { color: var(--green); } .tabs small { font-weight: 500; }

.panel { background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow); margin-bottom: 14px; overflow: hidden; }
.panel-head { background: var(--amber); color: #fff; font-size: 1rem; font-weight: 700; padding: 11px 16px; }
.panel-head-row { display: flex; align-items: center; justify-content: space-between; gap: 8px; padding: 6px 8px 6px 16px; }
.panel-head-row h3 { font-size: 1rem; } .panel-head-row .icon-btn-light { color: #fff; } .panel-head-row .btn { background: #fff; border-color: #fff; color: var(--amber-dark); }
.panel-body { padding: 8px 16px 14px; }
.panel > form.panel-body, .panel > .panel-body { padding-top: 14px; }
.drow { display: flex; gap: 12px; padding: 9px 0; border-bottom: 1px solid #eef3ec; }
.drow:last-child { border-bottom: 0; }
.dl { flex: 0 0 42%; color: #4a5b4d; font-weight: 600; font-size: .92rem; }
.dv { flex: 1; color: var(--green); min-width: 0; overflow-wrap: anywhere; }
.dv .ok, .ok { color: var(--green); } .dv .warn, .warn { color: var(--amber-dark); }
.dv a { font-weight: 600; }
.cards-tight { gap: 8px; } .cards-tight .thumb { width: 52px; height: 52px; }

.photo-pick { display: flex; gap: 14px; align-items: center; }
.photo-preview { width: 112px; height: 112px; flex: none; border-radius: 18px; overflow: hidden; background: #fff3d6; display: flex; align-items: center; justify-content: center; font-size: 3rem; border: 2px dashed var(--green-line); }
.photo-preview img { width: 100%; height: 100%; object-fit: cover; }
.photo-actions { flex: 1; display: grid; gap: 8px; }

.timeline { list-style: none; margin: 0; padding: 0; display: grid; gap: 10px; }
.timeline li { display: flex; gap: 12px; align-items: flex-start; background: var(--card); border-radius: 16px; padding: 12px 8px 12px 14px; box-shadow: var(--shadow); border-left: 5px solid var(--green); }
.tl-date { flex: 0 0 84px; color: var(--muted); font-size: .85rem; padding-top: 2px; }
.tl-body { flex: 1; min-width: 0; } .tl-body p { margin: 4px 0 0; color: #3f5143; font-size: .92rem; }
.signout { margin-top: 6px; }

@media (min-width: 640px) {
  .tiles { grid-template-columns: repeat(6, 1fr); }
  .filters { grid-template-columns: 2fr 1fr 1fr; } .searchbox { grid-column: auto; }
  .hero { height: 230px; }
}
@media (max-width: 360px) { .row2 { grid-template-columns: 1fr; } .photo-pick { flex-direction: column; align-items: stretch; } .photo-preview { margin: 0 auto; } }

/* ---------- v2: gallery, admin, install sheet ---------- */
.linkbtn { background: none; border: 0; padding: 6px; font: inherit; color: var(--green); text-decoration: underline; cursor: pointer; }
.linkbtn-light { color: #fff; }
.btn-danger { color: var(--danger); border-color: #efc7c7; }
.btn-danger:active { background: #fdeaea; }
.panel-head small { font-weight: 500; opacity: .9; }

.gallery { position: relative; margin-bottom: 14px; border-radius: 16px; overflow: hidden; background: #111; }
.gallery-track { display: flex; overflow-x: auto; scroll-snap-type: x mandatory; scrollbar-width: none; -webkit-overflow-scrolling: touch; overscroll-behavior-x: contain; }
.gallery-track::-webkit-scrollbar { display: none; }
.slide { position: relative; flex: 0 0 100%; margin: 0; scroll-snap-align: center; scroll-snap-stop: always; aspect-ratio: 4 / 3; }
.slide a { display: block; width: 100%; height: 100%; }
.slide img { width: 100%; height: 100%; object-fit: cover; display: block; }
.slide figcaption { position: absolute; left: 0; right: 0; bottom: 0; display: flex; align-items: center; justify-content: space-between; padding: 26px 10px 10px 14px; background: linear-gradient(transparent, rgba(0,0,0,.72)); color: #fff; }
.slide-date { display: inline-flex; align-items: center; gap: 6px; font-weight: 600; text-shadow: 0 1px 4px rgba(0,0,0,.6); }
.slide-del { display: inline-flex; align-items: center; justify-content: center; width: 38px; height: 38px; border: 0; border-radius: 50%; background: rgba(0,0,0,.45); color: #fff; cursor: pointer; }
.gal-nav { position: absolute; top: 50%; transform: translateY(-50%); width: 40px; height: 40px; border: 0; border-radius: 50%; background: rgba(0,0,0,.4); color: #fff; display: flex; align-items: center; justify-content: center; cursor: pointer; }
.gal-prev { left: 8px; } .gal-next { right: 8px; }
.gallery-count { position: absolute; top: 10px; right: 10px; padding: 3px 11px; border-radius: 99px; background: rgba(0,0,0,.55); color: #fff; font-size: .82rem; font-weight: 600; }
.gallery-add { display: grid; gap: 4px; }
.gallery-add .field { margin: 8px 0 4px; }
.gallery-full { margin: 0; }

.tiles-4 { grid-template-columns: repeat(2, 1fr); margin-bottom: 4px; }
.user-card { display: block; }
.user-top { display: flex; gap: 12px; align-items: flex-start; }
.user-avatar { flex: none; width: 46px; height: 46px; border-radius: 50%; background: var(--green-soft); color: var(--green-dark); display: flex; align-items: center; justify-content: center; font-weight: 700; font-size: 1.2rem; border: 2px solid var(--green-line); }
.user-id { min-width: 0; display: flex; flex-wrap: wrap; gap: 4px 6px; align-items: center; }
.user-id > b { font-size: 1.05rem; margin-right: 2px; }
.user-email { flex-basis: 100%; color: var(--muted); font-size: .85rem; overflow-wrap: anywhere; }
.user-off { opacity: .72; border-left-color: #b9b9b9; }
.user-meta { display: grid; grid-template-columns: 1fr 1fr; gap: 8px 12px; margin: 12px 0 4px; }
.user-meta div { background: var(--bg); border-radius: 10px; padding: 6px 10px; }
.user-meta dt { font-size: .72rem; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; }
.user-meta dd { margin: 0; font-weight: 600; color: var(--green-dark); font-size: .92rem; }
.manage { margin-top: 8px; border-top: 1px solid #eef3ec; padding-top: 6px; }
.manage summary { cursor: pointer; color: var(--green); font-weight: 600; padding: 8px 0; list-style: none; }
.manage summary::-webkit-details-marker { display: none; }
.manage summary::after { content: ' ▾'; }
.manage-body { display: grid; gap: 8px; padding-bottom: 4px; }
.tl-fail { border-left-color: var(--danger); }
.tl-fail .tl-body b { color: var(--danger); }
.timeline .tl-body p { overflow-wrap: anywhere; }

.sheet { position: fixed; inset: 0; z-index: 80; background: rgba(0,0,0,.5); display: flex; align-items: flex-end; justify-content: center; padding: 12px; }
.sheet[hidden] { display: none; }
.sheet-card { width: 100%; max-width: 480px; background: #fff; border-radius: 22px; padding: 20px; box-shadow: 0 -6px 30px rgba(0,0,0,.3); }
.sheet-card h2 { font-size: 1.15rem; margin-bottom: 10px; }
.sheet-card p { margin: 0 0 10px; }
[hidden] { display: none !important; }
@media (min-width: 640px) { .tiles-4 { grid-template-columns: repeat(4, 1fr); } }
