/* ============ KNJ Farm — gaya tampilan ============ */
:root {
  --hijau: #166534;
  --hijau-tua: #14532d;
  --hijau-muda: #dcfce7;
  --bg: #f2f5f2;
  --kartu: #ffffff;
  --teks: #1a2e1a;
  --teks-2: #5b6b5b;
  --garis: #e2e8e2;
  --sehat: #16a34a;
  --sakit: #d97706;
  --mati: #dc2626;
  --terjual: #2563eb;
  --hilang: #9333ea;
  --jantan: #2563eb;
  --betina: #db2777;
  --radius: 14px;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f1712;
    --kartu: #1a241c;
    --teks: #e8f0e8;
    --teks-2: #94a894;
    --garis: #2a382c;
    --hijau-muda: #163b24;
  }
}
* { box-sizing: border-box; margin: 0; padding: 0; -webkit-tap-highlight-color: transparent; }
html { -webkit-text-size-adjust: 100%; }
body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  background: var(--bg); color: var(--teks); font-size: 16px;
}
button, input, select, textarea { font: inherit; color: inherit; }
img { display: block; }

.muat-awal { text-align: center; padding: 40vh 20px 0; font-size: 18px; color: var(--teks-2); }

/* ---------- kerangka ---------- */
.topbar {
  position: sticky; top: 0; z-index: 20;
  background: linear-gradient(135deg, var(--hijau-tua), var(--hijau));
  color: #fff; padding: calc(env(safe-area-inset-top) + 12px) 16px 12px;
  display: flex; align-items: center; gap: 10px;
}
.topbar h1 { font-size: 19px; font-weight: 800; letter-spacing: .2px; flex: 1; }
.topbar .kembali {
  background: rgba(255,255,255,.15); border: 0; color: #fff; border-radius: 10px;
  padding: 7px 12px; font-size: 15px; font-weight: 600;
}
.topbar .chip-user { font-size: 12px; background: rgba(255,255,255,.18); padding: 5px 10px; border-radius: 99px; font-weight: 600; }

/* ruang bawah dilebihkan supaya tombol bulat "+" tidak menutupi baris
   terakhir daftar ayam — dulu ayam paling bawah tidak bisa ditekan */
.isi { padding: 14px 14px calc(env(safe-area-inset-bottom) + 140px); max-width: 760px; margin: 0 auto; }

.tabbar {
  position: fixed; bottom: 0; left: 0; right: 0; z-index: 20;
  display: flex; background: var(--kartu); border-top: 1px solid var(--garis);
  padding-bottom: env(safe-area-inset-bottom);
}
.tabbar button {
  flex: 1; background: none; border: 0; padding: 9px 0 7px; font-size: 10.5px;
  color: var(--teks-2); font-weight: 600; display: flex; flex-direction: column; align-items: center; gap: 2px;
}
.tabbar button .iko { font-size: 22px; line-height: 1; }
.tabbar button.aktif { color: var(--hijau); }

/* ---------- komponen umum ---------- */
.kartu {
  background: var(--kartu); border-radius: var(--radius); padding: 14px;
  margin-bottom: 12px; box-shadow: 0 1px 3px rgba(0,0,0,.05);
}
.kartu h3 { font-size: 13px; text-transform: uppercase; letter-spacing: .6px; color: var(--teks-2); margin-bottom: 10px; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.tile { background: var(--kartu); border-radius: var(--radius); padding: 13px 14px; box-shadow: 0 1px 3px rgba(0,0,0,.05); }
.tile .angka { font-size: 26px; font-weight: 800; line-height: 1.15; }
.tile .label { font-size: 12.5px; color: var(--teks-2); font-weight: 600; margin-top: 2px; }
.tile.merah { background: #fef2f2; }
.tile.merah .angka, .tile.merah .label { color: var(--mati); }
@media (prefers-color-scheme: dark) { .tile.merah { background: #3a1717; } }

/* Warna teks badge sengaja lebih gelap daripada warna status biasa: label ini
   dibaca di kandang, sambil berdiri di bawah sinar matahari. */
.badge { display: inline-block; font-size: 12px; font-weight: 800; padding: 4px 10px; border-radius: 99px; white-space: nowrap; }
.b-Sehat   { background: rgba(22,163,74,.20);  color: #14682f; }
.b-Sakit   { background: rgba(217,119,6,.20);  color: #9a4a06; }
.b-Mati    { background: rgba(220,38,38,.20);  color: #b91c1c; }
.b-Terjual { background: rgba(37,99,235,.20);  color: #1d4ed8; }
.b-Hilang  { background: rgba(147,51,234,.20); color: #7e22ce; }
.b-minus   { background: rgba(217,119,6,.22);  color: #9a4a06; }
@media (prefers-color-scheme: dark) {
  .b-Sehat   { color: #6ee7a0; }
  .b-Sakit   { color: #fbbf24; }
  .b-Mati    { color: #fca5a5; }
  .b-Terjual { color: #93c5fd; }
  .b-Hilang  { color: #d8b4fe; }
  .b-minus   { color: #fbbf24; }
}

.jk-Jantan { color: var(--jantan); font-weight: 800; }
.jk-Betina { color: var(--betina); font-weight: 800; }
.jk-x { color: var(--teks-2); font-weight: 800; }

.btn {
  display: block; width: 100%; border: 0; border-radius: 12px; padding: 14px;
  font-size: 16px; font-weight: 700; text-align: center; cursor: pointer;
}
.btn-utama { background: var(--hijau); color: #fff; }
.btn-abu { background: var(--garis); color: var(--teks); }
.btn-bahaya { background: rgba(220,38,38,.1); color: var(--mati); }
.btn-kecil { width: auto; display: inline-block; padding: 9px 14px; font-size: 14px; border-radius: 10px; }
.btn:disabled { opacity: .5; }

.baris-aksi { display: flex; gap: 10px; margin: 12px 0; }
.baris-aksi .btn { flex: 1; }

/* daftar ayam */
.item-ayam {
  display: flex; align-items: center; gap: 12px; background: var(--kartu);
  border-radius: var(--radius); padding: 10px 12px; margin-bottom: 9px;
  box-shadow: 0 1px 3px rgba(0,0,0,.05); cursor: pointer; border: 0; width: 100%; text-align: left;
}
.thumb {
  width: 56px; height: 56px; border-radius: 12px; object-fit: cover; flex-shrink: 0;
  background: var(--hijau-muda);
}
.thumb-teks {
  width: 56px; height: 56px; border-radius: 12px; flex-shrink: 0; background: var(--hijau-muda);
  display: flex; align-items: center; justify-content: center; font-size: 26px;
}
.item-ayam .tengah { flex: 1; min-width: 0; }
.item-ayam .wb { font-weight: 800; font-size: 16.5px; }
.item-ayam .sub { font-size: 12.5px; color: var(--teks-2); margin-top: 2px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.fab {
  position: fixed; right: 18px; bottom: calc(env(safe-area-inset-bottom) + 72px); z-index: 21;
  width: 58px; height: 58px; border-radius: 50%; border: 0; background: var(--hijau);
  color: #fff; font-size: 30px; font-weight: 500; box-shadow: 0 4px 14px rgba(20,83,45,.4);
}

/* form */
.form-grup { margin-bottom: 14px; }
.form-grup label { display: block; font-size: 13px; font-weight: 700; color: var(--teks-2); margin-bottom: 6px; }
.input, select.input, textarea.input {
  width: 100%; border: 1.5px solid var(--garis); border-radius: 11px; padding: 12px;
  font-size: 16px; background: var(--kartu); appearance: none; -webkit-appearance: none;
}
.input:focus { outline: none; border-color: var(--hijau); }
textarea.input { resize: vertical; min-height: 68px; }
select.input {
  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' stroke='%23888' stroke-width='2' fill='none'/%3E%3C/svg%3E");
  background-repeat: no-repeat; background-position: right 12px center; padding-right: 34px;
}
.segmen { display: flex; background: var(--garis); border-radius: 11px; padding: 3px; gap: 3px; }
.segmen button { flex: 1; border: 0; background: none; padding: 10px 4px; border-radius: 9px; font-size: 14px; font-weight: 700; color: var(--teks-2); }
.segmen button.aktif { background: var(--kartu); color: var(--teks); box-shadow: 0 1px 3px rgba(0,0,0,.12); }

.kotak-foto {
  width: 108px; height: 108px; border-radius: 14px; border: 2px dashed var(--garis);
  background: var(--kartu); display: flex; flex-direction: column; align-items: center; justify-content: center;
  font-size: 12px; color: var(--teks-2); gap: 4px; overflow: hidden; padding: 0;
}
.kotak-foto img { width: 100%; height: 100%; object-fit: cover; }
.kotak-foto .iko { font-size: 30px; }

/* filter bar */
.panel-saring { display: flex; gap: 8px; overflow-x: auto; padding-bottom: 10px; -webkit-overflow-scrolling: touch; }
.panel-saring select {
  border: 1.5px solid var(--garis); background: var(--kartu); border-radius: 99px;
  padding: 7px 26px 7px 12px; font-size: 13.5px; font-weight: 600; appearance: none; -webkit-appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='10' height='7'%3E%3Cpath d='M1 1l4 4 4-4' stroke='%23888' stroke-width='2' fill='none'/%3E%3C/svg%3E");
  background-repeat: no-repeat; background-position: right 9px center;
}
.cari { position: relative; margin-bottom: 10px; }
.cari input {
  width: 100%; border: 1.5px solid var(--garis); border-radius: 12px; background: var(--kartu);
  padding: 12px 12px 12px 38px; font-size: 16px;
}
.cari::before { content: "🔍"; position: absolute; left: 12px; top: 50%; transform: translateY(-50%); font-size: 14px; opacity: .55; }

/* detail */
.foto-besar { width: 100%; max-height: 330px; object-fit: cover; border-radius: var(--radius); background: var(--hijau-muda); }
.galeri { display: flex; gap: 8px; overflow-x: auto; margin-top: 8px; -webkit-overflow-scrolling: touch; }
.galeri img, .galeri button { width: 64px; height: 64px; border-radius: 10px; object-fit: cover; flex-shrink: 0; }
.galeri button { border: 2px dashed var(--garis); background: var(--kartu); font-size: 22px; color: var(--teks-2); }
.tabel-data { width: 100%; }
.tabel-data td { padding: 8px 0; border-bottom: 1px solid var(--garis); font-size: 15px; vertical-align: top; }
.tabel-data tr:last-child td { border-bottom: 0; }
.tabel-data td:first-child { color: var(--teks-2); font-weight: 600; width: 42%; font-size: 13.5px; }
.chip-induk {
  display: inline-flex; align-items: center; gap: 6px; background: var(--hijau-muda);
  border: 0; color: var(--teks); border-radius: 99px; padding: 7px 13px; font-size: 14px; font-weight: 700;
}

/* log */
.item-log { display: flex; gap: 10px; padding: 11px 0; border-bottom: 1px solid var(--garis); }
.item-log:last-child { border-bottom: 0; }
.item-log .iko { font-size: 19px; width: 26px; text-align: center; flex-shrink: 0; }
.item-log .tengah { flex: 1; min-width: 0; }
.item-log .judul { font-size: 14.5px; font-weight: 700; }
.item-log .det { font-size: 13px; color: var(--teks-2); margin-top: 1px; word-break: break-word; }
.item-log .meta { font-size: 11.5px; color: var(--teks-2); margin-top: 3px; }
.item-log .meta b { color: var(--hijau); }
.foto-log { width: 44px; height: 44px; border-radius: 8px; object-fit: cover; flex-shrink: 0; }

/* rekap */
.tabel-rekap { width: 100%; border-collapse: collapse; font-size: 13.5px; }
.tabel-rekap th { text-align: right; font-size: 11px; color: var(--teks-2); padding: 6px 4px; border-bottom: 1.5px solid var(--garis); }
.tabel-rekap th:first-child, .tabel-rekap td:first-child { text-align: left; }
.tabel-rekap td { padding: 9px 4px; border-bottom: 1px solid var(--garis); text-align: right; font-weight: 600; }
.tabel-rekap td.merah { color: var(--mati); font-weight: 800; }

/* modal */
#modal-wadah .tirai {
  position: fixed; inset: 0; background: rgba(0,0,0,.45); z-index: 50;
  display: flex; align-items: flex-end; justify-content: center;
}
.modal {
  background: var(--bg); width: 100%; max-width: 560px; max-height: 88vh; overflow-y: auto;
  border-radius: 20px 20px 0 0; padding: 18px 16px calc(env(safe-area-inset-bottom) + 18px);
  -webkit-overflow-scrolling: touch;
}
.modal h2 { font-size: 18px; margin-bottom: 14px; display: flex; justify-content: space-between; align-items: center; }
/* 44px = ukuran minimal yang nyaman ditekan jari, apalagi tangan berdebu */
.modal h2 .tutup { background: var(--garis); border: 0; border-radius: 99px; width: 44px; height: 44px; font-size: 18px; }
.panel-saring select, .panel-saring input, .chip-induk { min-height: 44px; }
.btn:active, .chip-induk:active, .modal h2 .tutup:active { filter: brightness(.92); }
.foto-penuh { position: fixed; inset: 0; z-index: 60; background: rgba(0,0,0,.92); display: flex; align-items: center; justify-content: center; }
.foto-penuh img { max-width: 100%; max-height: 100%; object-fit: contain; }

/* toast */
#toast-wadah { position: fixed; top: calc(env(safe-area-inset-top) + 10px); left: 0; right: 0; z-index: 70; display: flex; flex-direction: column; align-items: center; gap: 8px; pointer-events: none; }
.toast {
  background: #1f2937; color: #fff; padding: 11px 18px; border-radius: 12px; font-size: 14.5px;
  font-weight: 600; max-width: 92%; box-shadow: 0 4px 14px rgba(0,0,0,.3); text-align: center;
}
.toast.galat { background: var(--mati); }
.toast.sukses { background: var(--sehat); }

/* login */
.login-wadah { min-height: 100vh; min-height: 100dvh; display: flex; flex-direction: column; justify-content: center; padding: 28px 22px calc(env(safe-area-inset-bottom) + 28px); max-width: 430px; margin: 0 auto; }
.login-logo { text-align: center; margin-bottom: 26px; }
.login-logo .iko { font-size: 64px; }
.login-logo h1 { font-size: 26px; font-weight: 900; color: var(--hijau); margin-top: 6px; }
.login-logo p { color: var(--teks-2); font-size: 14px; margin-top: 4px; }
.pilih-nama { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 14px; }
.pilih-nama button {
  border: 1.5px solid var(--garis); background: var(--kartu); border-radius: 99px;
  padding: 9px 16px; font-size: 15px; font-weight: 700;
}
.pilih-nama button.aktif { border-color: var(--hijau); background: var(--hijau-muda); color: var(--hijau); }

.info-offline { background: #fef3c7; color: #92400e; font-size: 13px; font-weight: 600; padding: 9px 14px; border-radius: 10px; margin-bottom: 12px; text-align: center; }
.kosong { text-align: center; color: var(--teks-2); padding: 44px 20px; font-size: 15px; }
.kosong .iko { font-size: 44px; display: block; margin-bottom: 10px; }
.ket-kecil { font-size: 12.5px; color: var(--teks-2); margin-top: 8px; line-height: 1.5; }
.subjudul { font-size: 14px; font-weight: 800; margin: 16px 0 8px; }

/* ---------- cetak (kartu ayam & laporan) ---------- */
.cetak-wadah { display: none; }
.cetak-kartu, .cetak-laporan { color: #111; background: #fff; }
.ck-head { display: flex; justify-content: space-between; align-items: center;
  border-bottom: 3px solid #166534; padding-bottom: 8px; margin-bottom: 12px; }
.ck-logo { font-size: 20px; font-weight: 900; color: #166534; }
.ck-wb { font-size: 26px; font-weight: 900; letter-spacing: .5px; }
.ck-isi { display: flex; gap: 16px; align-items: flex-start; }
.ck-foto { width: 210px; flex-shrink: 0; }
.ck-foto img { width: 210px; height: 210px; object-fit: cover; border-radius: 8px; border: 1px solid #ccc; }
.ck-nofoto { width: 210px; height: 210px; display: flex; align-items: center; justify-content: center;
  font-size: 90px; background: #eef6ee; border-radius: 8px; }
.ck-tabel { flex: 1; border-collapse: collapse; font-size: 15px; }
.ck-tabel td { padding: 6px 4px; border-bottom: 1px solid #e2e2e2; vertical-align: top; }
.ck-tabel td:first-child { color: #555; font-weight: 600; width: 40%; }
.ck-kaki { margin-top: 14px; font-size: 11px; color: #888; text-align: center; }

@media print {
  body.mode-cetak > *:not(.cetak-wadah) { display: none !important; }
  body.mode-cetak .cetak-wadah { display: block !important; }
  .cetak-laporan .tile { border: 1px solid #ccc; box-shadow: none; background: #fff !important; }
  .cetak-laporan .tile .angka, .cetak-laporan .tile .label { color: #111 !important; }
  .cetak-laporan .kartu { box-shadow: none; border: 1px solid #eee; page-break-inside: avoid; }
  .cetak-laporan .foto-log { display: none; }
  @page { margin: 12mm; }
}
