/* ============================================================
   KANDANG — Global Styles
   Aesthetic: Warm organic / earthy farmhouse
   Fonts: Lora (display) + DM Sans (body)
============================================================ */

:root {
  --cream:     #F7F3EC;
  --cream-dark:#EDE6D6;
  --brown:     #6B4C2A;
  --brown-mid: #8C6340;
  --brown-lt:  #C4A882;
  --green:     #4A7C59;
  --green-lt:  #D4EAD7;
  --amber:     #D47C1A;
  --amber-lt:  #FAECD0;
  --red:       #B94040;
  --red-lt:    #F5DADA;
  --text:      #2C1E0F;
  --text-mid:  #6B5840;
  --text-lt:   #A89078;
  --border:    rgba(107,76,42,0.15);
  --border-md: rgba(107,76,42,0.25);
  --radius:    12px;
  --radius-sm: 8px;
  --shadow:    0 2px 16px rgba(107,76,42,0.10);
}

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

html { font-size: 16px; }

body {
  font-family: 'DM Sans', sans-serif;
  background: var(--cream);
  color: var(--text);
  min-height: 100vh;
  line-height: 1.6;
}

/* ---- Typography ---- */
h1, h2, h3 { font-family: 'Lora', serif; font-weight: 500; line-height: 1.25; }
h1 { font-size: 2rem; }
h2 { font-size: 1.4rem; }
h3 { font-size: 1.1rem; }

/* ---- Layout ---- */
.page { min-height: 100vh; }
.hidden { display: none !important; }

.container {
  max-width: 480px;
  margin: 0 auto;
  padding: 0 1.25rem;
}

/* ---- Topbar ---- */
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 1rem 1.25rem;
  border-bottom: 1px solid var(--border);
  background: var(--cream);
  position: sticky;
  top: 0;
  z-index: 10;
}
.topbar-logo {
  font-family: 'Lora', serif;
  font-size: 1.2rem;
  font-weight: 500;
  color: var(--brown);
}
.topbar-logo span { color: var(--amber); }
.topbar-nav { display: flex; gap: 4px; }
.topbar-nav button {
  background: none;
  border: none;
  padding: 6px 10px;
  border-radius: var(--radius-sm);
  font-size: 13px;
  font-family: 'DM Sans', sans-serif;
  color: var(--text-mid);
  cursor: pointer;
  transition: background 0.15s, color 0.15s;
}
.topbar-nav button:hover { background: var(--cream-dark); color: var(--brown); }
.topbar-nav button.active { background: var(--brown); color: var(--cream); }

/* ---- Cards ---- */
.card {
  background: #fff;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.25rem;
}

/* ---- Buttons ---- */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 10px 20px;
  border-radius: var(--radius-sm);
  font-family: 'DM Sans', sans-serif;
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
  border: none;
  transition: opacity 0.15s, transform 0.1s;
  text-decoration: none;
}
.btn:active { transform: scale(0.97); }
.btn-primary  { background: var(--brown); color: var(--cream); }
.btn-primary:hover  { opacity: 0.88; }
.btn-outline  { background: transparent; border: 1px solid var(--border-md); color: var(--text-mid); }
.btn-outline:hover  { background: var(--cream-dark); }
.btn-danger   { background: var(--red-lt); color: var(--red); border: 1px solid rgba(185,64,64,0.2); }
.btn-success  { background: var(--green); color: #fff; }
.btn-success:hover { opacity: 0.88; }
.btn-full { width: 100%; }

/* ---- Form Elements ---- */
.form-group { margin-bottom: 1rem; }
.form-group label {
  display: block;
  font-size: 13px;
  font-weight: 500;
  color: var(--text-mid);
  margin-bottom: 5px;
}
input[type="email"],
input[type="password"],
input[type="text"],
input[type="number"],
select,
textarea {
  width: 100%;
  padding: 10px 12px;
  border: 1px solid var(--border-md);
  border-radius: var(--radius-sm);
  font-family: 'DM Sans', sans-serif;
  font-size: 14px;
  background: #fff;
  color: var(--text);
  outline: none;
  transition: border-color 0.15s;
}
input:focus, select:focus, textarea:focus {
  border-color: var(--brown-lt);
  box-shadow: 0 0 0 3px rgba(107,76,42,0.08);
}
textarea { resize: vertical; min-height: 72px; }
.form-hint { font-size: 12px; color: var(--text-lt); margin-top: 4px; }

/* ---- Auth Page ---- */
#page-auth {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  background: var(--cream);
  padding: 2rem 1.25rem;
}
.auth-box {
  width: 100%;
  max-width: 380px;
}
.auth-header { text-align: center; margin-bottom: 2rem; }
.auth-header .logo-big {
  font-family: 'Lora', serif;
  font-size: 2.2rem;
  color: var(--brown);
  display: block;
  margin-bottom: 4px;
}
.auth-header .logo-big span { color: var(--amber); }
.auth-header p { color: var(--text-lt); font-size: 14px; }
.auth-divider {
  text-align: center;
  margin: 1.25rem 0;
  font-size: 13px;
  color: var(--text-lt);
}
.auth-toggle {
  text-align: center;
  margin-top: 1.25rem;
  font-size: 13px;
  color: var(--text-mid);
}
.auth-toggle a {
  color: var(--brown);
  cursor: pointer;
  text-decoration: underline;
}
.auth-error {
  background: var(--red-lt);
  color: var(--red);
  border-radius: var(--radius-sm);
  padding: 10px 14px;
  font-size: 13px;
  margin-bottom: 1rem;
  display: none;
}

/* ---- Dashboard ---- */
.dash-header {
  padding: 1.5rem 1.25rem 1rem;
}
.dash-date {
  font-size: 13px;
  color: var(--text-lt);
  margin-bottom: 4px;
}
.metrics-row {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 10px;
  margin-bottom: 1.25rem;
}
.metric-card {
  background: var(--cream-dark);
  border-radius: var(--radius-sm);
  padding: 12px;
}
.metric-card .m-label { font-size: 11px; color: var(--text-lt); margin-bottom: 2px; }
.metric-card .m-val   { font-size: 20px; font-weight: 500; font-family: 'Lora', serif; color: var(--brown); }
.metric-card .m-sub   { font-size: 11px; color: var(--text-lt); }

.section-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 10px;
}
.section-title { font-size: 13px; font-weight: 500; color: var(--text-mid); text-transform: uppercase; letter-spacing: 0.06em; }

/* Donut chart section */
.chart-section {
  padding: 0 1.25rem 1.25rem;
}
.chart-card {
  background: #fff;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.25rem;
}
.chart-inner {
  display: flex;
  align-items: center;
  gap: 1.5rem;
}
.chart-wrap {
  position: relative;
  width: 160px;
  height: 160px;
  flex-shrink: 0;
}
.chart-center {
  position: absolute;
  top: 50%; left: 50%;
  transform: translate(-50%, -50%);
  text-align: center;
  pointer-events: none;
}
.chart-center .big { font-size: 26px; font-weight: 500; font-family: 'Lora', serif; color: var(--brown); }
.chart-center .sm  { font-size: 11px; color: var(--text-lt); }
.chart-legend { flex: 1; display: flex; flex-direction: column; gap: 9px; }
.legend-item { display: flex; align-items: center; gap: 8px; font-size: 13px; }
.legend-dot  { width: 10px; height: 10px; border-radius: 50%; flex-shrink: 0; }
.legend-name { flex: 1; color: var(--text-mid); }
.legend-val  { font-weight: 500; color: var(--text); }
.legend-pct  { font-size: 11px; color: var(--text-lt); min-width: 30px; text-align: right; }

/* Flock cards */
.flock-section { padding: 0 1.25rem 1.25rem; }
.flock-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.flock-card {
  background: #fff;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.flock-card-top { display: flex; align-items: center; gap: 10px; }
.flock-avatar {
  width: 40px; height: 40px;
  border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  font-size: 20px;
  flex-shrink: 0;
}
.chicken-photo {
  width: 100%;
  height: 100%;
  object-fit: cover;
  border-radius: 50%;
  display: block;
}
.flock-card-name  { font-size: 13px; font-weight: 500; color: var(--text); }
.flock-card-count { font-size: 11px; color: var(--text-lt); }
.flock-card-eggs  { font-size: 22px; font-family: 'Lora', serif; font-weight: 500; color: var(--brown); }
.flock-card-sub   { font-size: 11px; color: var(--text-lt); }
.progress-track   { height: 4px; background: var(--border); border-radius: 2px; overflow: hidden; }
.progress-fill    { height: 100%; border-radius: 2px; transition: width 0.4s ease; }

/* CTA button */
.cta-section { padding: 0 1.25rem 2rem; }
.btn-cta {
  width: 100%;
  padding: 14px;
  background: var(--brown);
  color: var(--cream);
  border: none;
  border-radius: var(--radius);
  font-family: 'Lora', serif;
  font-size: 1rem;
  font-weight: 500;
  cursor: pointer;
  transition: opacity 0.15s, transform 0.1s;
}
.btn-cta:hover  { opacity: 0.88; }
.btn-cta:active { transform: scale(0.98); }
.btn-cta.already {
  background: var(--green-lt);
  color: var(--green);
  border: 1px solid rgba(74,124,89,0.3);
}

/* Empty state */
.empty-state {
  text-align: center;
  padding: 3rem 1.25rem;
  color: var(--text-lt);
}
.empty-state .icon { font-size: 3rem; margin-bottom: 1rem; }
.empty-state p { font-size: 14px; line-height: 1.6; margin-bottom: 1.25rem; }

/* ---- Modal ---- */
#modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(44,30,15,0.45);
  display: flex;
  align-items: flex-end;
  justify-content: center;
  z-index: 100;
  padding: 0;
}
@media (min-height: 600px) {
  #modal-overlay { align-items: center; padding: 1rem; }
}
#modal-content {
  background: var(--cream);
  width: 100%;
  max-width: 480px;
  border-radius: var(--radius) var(--radius) 0 0;
  overflow: hidden;
  max-height: 92vh;
  overflow-y: auto;
}
@media (min-height: 600px) {
  #modal-content { border-radius: var(--radius); max-height: 88vh; }
}
.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 1.1rem 1.25rem;
  border-bottom: 1px solid var(--border);
  background: var(--cream);
  position: sticky;
  top: 0;
}
.modal-header h3 { font-size: 1rem; }
.modal-close {
  width: 30px; height: 30px;
  border-radius: 50%;
  border: 1px solid var(--border-md);
  background: none;
  font-size: 16px;
  color: var(--text-mid);
  cursor: pointer;
  display: flex; align-items: center; justify-content: center;
}
.modal-close:hover { background: var(--cream-dark); }
.modal-body   { padding: 1.25rem; }
.modal-footer {
  padding: 1rem 1.25rem;
  border-top: 1px solid var(--border);
  display: flex;
  gap: 8px;
  background: var(--cream);
  position: sticky;
  bottom: 0;
}

/* ---- Egg Input Rows ---- */
.egg-rows { display: flex; flex-direction: column; gap: 10px; margin-bottom: 1rem; }
.egg-row {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px;
  background: #fff;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  transition: border-color 0.15s, background 0.15s;
}
.egg-row.filled { border-color: rgba(74,124,89,0.4); background: #fafffe; }
.egg-row-icon {
  width: 38px; height: 38px;
  border-radius: 50%;
  font-size: 20px;
  display: flex; align-items: center; justify-content: center;
  flex-shrink: 0;
}
.egg-row-meta { flex: 1; min-width: 0; }
.egg-row-name { font-size: 13px; font-weight: 500; }
.egg-row-sub  { font-size: 11px; color: var(--text-lt); }
.counter      { display: flex; align-items: center; gap: 8px; }
.counter-btn  {
  width: 32px; height: 32px;
  border-radius: 50%;
  border: 1px solid var(--border-md);
  background: var(--cream);
  font-size: 18px;
  font-weight: 400;
  color: var(--brown);
  cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  user-select: none;
  transition: background 0.1s;
  line-height: 1;
}
.counter-btn:hover  { background: var(--cream-dark); }
.counter-btn:active { transform: scale(0.92); }
.counter-val { font-size: 16px; font-weight: 500; font-family: 'Lora', serif; color: var(--brown); min-width: 28px; text-align: center; }
.pct-pill {
  font-size: 11px;
  padding: 2px 8px;
  border-radius: 99px;
  background: var(--cream-dark);
  color: var(--text-lt);
  flex-shrink: 0;
  min-width: 38px;
  text-align: center;
}
.pct-pill.good { background: var(--green-lt);  color: var(--green); }
.pct-pill.mid  { background: var(--amber-lt);  color: var(--amber); }
.pct-pill.bad  { background: var(--red-lt);    color: var(--red); }

.total-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 14px;
  background: var(--cream-dark);
  border-radius: var(--radius-sm);
  margin-bottom: 1rem;
}
.total-bar .tl { font-size: 13px; color: var(--text-mid); }
.total-bar .tv { font-size: 16px; font-weight: 500; font-family: 'Lora', serif; color: var(--brown); }

/* ---- Settings Page ---- */
.settings-section { padding: 1.25rem; }
.settings-section + .settings-section { border-top: 1px solid var(--border); }
.settings-section h3 { margin-bottom: 1rem; }
.flock-setting-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px;
  background: #fff;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  margin-bottom: 8px;
}
.flock-setting-info { flex: 1; }
.flock-setting-name  { font-size: 14px; font-weight: 500; }
.flock-setting-count { font-size: 12px; color: var(--text-lt); }
.flock-setting-actions { display: flex; gap: 6px; }
.icon-btn {
  width: 30px; height: 30px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border-md);
  background: none;
  font-size: 14px;
  cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  color: var(--text-mid);
}
.icon-btn:hover { background: var(--cream-dark); }
.icon-btn.danger:hover { background: var(--red-lt); color: var(--red); border-color: rgba(185,64,64,0.3); }

/* Chicken type picker */
.chicken-picker { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin-bottom: 1rem; }
.chicken-option {
  border: 1px solid var(--border-md);
  border-radius: var(--radius-sm);
  padding: 10px 6px;
  text-align: center;
  cursor: pointer;
  transition: border-color 0.15s, background 0.15s;
}
.chicken-option:hover { background: var(--cream-dark); }
.chicken-option.selected { border-color: var(--brown); background: var(--amber-lt); }
.chicken-option .icon  {
  font-size: 24px;
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 28px;
  margin-bottom: 4px;
}
.chicken-option .icon .chicken-photo {
  width: 28px;
  height: 28px;
}
.chicken-option .cname { font-size: 11px; color: var(--text-mid); }

/* ---- History Page ---- */
.history-section { padding: 1.25rem; }
.history-filter { display: flex; gap: 8px; margin-bottom: 1.25rem; }
.history-filter select { flex: 1; }
.history-group-date {
  font-size: 12px;
  font-weight: 500;
  color: var(--text-lt);
  text-transform: uppercase;
  letter-spacing: 0.06em;
  margin: 1rem 0 8px;
}
.history-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  background: #fff;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  margin-bottom: 6px;
}
.history-icon { font-size: 20px; }
.history-info { flex: 1; }
.history-name  { font-size: 13px; font-weight: 500; }
.history-notes { font-size: 11px; color: var(--text-lt); }
.history-count { font-size: 16px; font-weight: 500; font-family: 'Lora', serif; color: var(--brown); }

/* ---- Toast ---- */
#toast {
  position: fixed;
  bottom: 1.5rem;
  left: 50%;
  transform: translateX(-50%);
  background: var(--text);
  color: var(--cream);
  padding: 10px 20px;
  border-radius: 99px;
  font-size: 13px;
  z-index: 200;
  white-space: nowrap;
  animation: toast-in 0.2s ease;
}
@keyframes toast-in { from { opacity: 0; transform: translateX(-50%) translateY(10px); } to { opacity: 1; transform: translateX(-50%) translateY(0); } }

/* ---- Loading spinner ---- */
.spinner {
  width: 36px; height: 36px;
  border: 3px solid var(--border);
  border-top-color: var(--brown);
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
  margin: 3rem auto;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ---- Responsive ---- */
@media (max-width: 400px) {
  .flock-grid { grid-template-columns: 1fr; }
  .metrics-row { grid-template-columns: repeat(3, 1fr); }
}
