/* App shell — dashboard, login, admin screens */

.auth-body {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: linear-gradient(160deg, var(--brand-dark), #133d26);
}
.auth-card {
  background: var(--white);
  width: 380px;
  max-width: 92vw;
  padding: 36px 32px;
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}
.auth-brand { font-family: var(--font-display); font-size: 1.4rem; font-weight: 700; color: var(--brand-dark); text-align: center; }
.auth-brand span { color: var(--brand); }
.auth-sub { text-align: center; color: var(--muted); margin: 6px 0 24px; font-size: 0.9rem; }
.auth-hint-heading { text-align: center; color: var(--brand-dark); font-size: 0.78rem; font-weight: 700; text-transform: uppercase; letter-spacing: 0.04em; margin: 22px 0 4px; }
.auth-hint { text-align: center; color: var(--muted); font-size: 0.8rem; margin-top: 4px; }
.auth-hint code { background: var(--canvas); padding: 2px 6px; border-radius: 6px; }
.auth-hint-fill {
  background: none; border: none; padding: 0; margin: 0;
  font: inherit; color: inherit; cursor: pointer;
  border-bottom: 1px dashed var(--muted);
}
.auth-hint-fill:hover { color: var(--brand); border-bottom-color: var(--brand); }
.auth-hint-fill:hover code { background: #e8f5ec; }
.auth-back { display: block; text-align: center; margin-top: 14px; color: var(--brand); font-size: 0.85rem; font-weight: 600; }

.form-label { display: block; font-size: 0.85rem; font-weight: 600; color: var(--brand-dark); margin-bottom: 14px; }
.form-input {
  display: block;
  width: 100%;
  margin-top: 6px;
  padding: 11px 14px;
  border: 1px solid var(--border);
  border-radius: 10px;
  font-size: 0.95rem;
  font-family: inherit;
}
.form-input:focus { outline: none; border-color: var(--brand); box-shadow: 0 0 0 3px rgba(21,128,61,0.15); }
.btn-block { width: 100%; text-align: center; border: none; cursor: pointer; }

.alert { padding: 10px 14px; border-radius: 10px; font-size: 0.85rem; margin-bottom: 16px; }
.alert-error { background: #fdecec; color: #b91c1c; border: 1px solid #f7c9c9; }
.alert-success { background: #e8f5ec; color: var(--brand); border: 1px solid #b7e4c7; }

/* Shell layout */
.shell { display: flex; min-height: 100vh; }
.sidebar {
  width: 230px;
  background: var(--brand-dark);
  color: #d7e7dc;
  flex-shrink: 0;
  padding: 22px 0;
  box-shadow: 4px 0 24px rgba(11,47,30,0.18);
  position: relative;
  z-index: 1;
}
.sidebar-brand { font-family: var(--font-display); font-weight: 700; color: var(--white); padding: 0 22px 22px; font-size: 1.1rem; display: flex; align-items: center; gap: 10px; }
.sidebar-brand span { color: #86efac; }
.sidebar-brand-icon {
  width: 30px; height: 30px; border-radius: 8px;
  background: rgba(255,255,255,0.1);
  display: flex; align-items: center; justify-content: center;
  color: #86efac; font-size: 0.95rem; flex-shrink: 0;
}
.sidebar-section { padding: 0 22px; font-size: 0.68rem; font-weight: 700; text-transform: uppercase; letter-spacing: 0.09em; color: #6b9880; margin: 20px 0 8px; }
.sidebar-group-toggle {
  display: flex; align-items: center; justify-content: space-between; width: 100%;
  background: none; border: none; cursor: pointer; font-family: inherit;
}
.sidebar-group-toggle i { font-size: 0.7rem; transition: transform 0.15s ease; }
.sidebar-group-toggle.open i { transform: rotate(180deg); }
.sidebar-group { display: none; }
.sidebar-group.open { display: block; }
.sidebar-link {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 22px;
  color: #d7e7dc;
  font-size: 0.9rem;
  font-weight: 500;
  border-left: 3px solid transparent;
  transition: background 0.15s ease, border-color 0.15s ease;
}
.sidebar-link i { width: 16px; text-align: center; font-size: 0.85rem; opacity: 0.8; flex-shrink: 0; }
.sidebar-link:hover { background: rgba(255,255,255,0.06); }
.sidebar-link.active { background: linear-gradient(90deg, rgba(21,128,61,0.35), rgba(21,128,61,0.08)); border-left-color: #4ade80; color: var(--white); font-weight: 700; }
.sidebar-link.active i { opacity: 1; color: #86efac; }
.sidebar-install-btn { width: 100%; background: none; border: none; border-left: 3px solid transparent; text-align: left; cursor: pointer; font-family: inherit; }
.sidebar-install-btn:hover { background: rgba(74,222,128,0.12); border-left-color: #4ade80; }

.main { flex: 1; min-width: 0; }
.app-topbar {
  background: var(--white);
  border-bottom: 1px solid var(--border);
  box-shadow: 0 2px 10px rgba(11,47,30,0.05);
  padding: 16px 28px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  position: relative;
  z-index: 2;
}
.app-topbar h1 { font-size: 1.2rem; color: var(--brand-dark); }
.topbar-user { display: flex; align-items: center; gap: 14px; font-size: 0.88rem; }
.farm-select {
  padding: 7px 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--brand-dark);
  background: var(--canvas);
}
.farm-label { background: var(--canvas); padding: 6px 12px; border-radius: 8px; font-weight: 600; font-size: 0.85rem; color: var(--brand-dark); }
.role-badge { background: #e8f5ec; color: var(--brand); padding: 4px 12px; border-radius: 999px; font-weight: 700; font-size: 0.72rem; text-transform: uppercase; }
.app-content { padding: 28px; }

.stat-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(210px, 1fr)); gap: 18px; margin-bottom: 30px; }
.stat-card {
  background: var(--white);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px 22px;
  box-shadow: 0 1px 2px rgba(11,47,30,0.04), 0 8px 20px rgba(11,47,30,0.05);
  transition: transform 0.15s ease, box-shadow 0.15s ease, border-color 0.15s ease;
}
.stat-card.clickable { cursor: pointer; }
.stat-card.clickable:hover { transform: translateY(-3px); box-shadow: var(--shadow); border-color: var(--brand); }
.stat-card.highlight { border-left: 4px solid var(--brand); }
.stat-card.highlight.alert { border-left-color: #b91c1c; }
.stat-card .stat-label { font-size: 0.8rem; color: var(--muted); font-weight: 600; display: flex; align-items: center; gap: 8px; }
.stat-card .stat-value { font-family: var(--font-display); font-size: 1.9rem; font-weight: 700; color: var(--brand-dark); margin-top: 6px; }
.stat-card .stat-sub { font-size: 0.78rem; color: var(--muted); margin-top: 4px; }
.stat-icon {
  width: 26px; height: 26px; border-radius: 7px; flex-shrink: 0;
  background: #e8f5ec; color: var(--brand);
  display: flex; align-items: center; justify-content: center;
  font-size: 0.78rem;
}
.stat-icon.alert { background: #fdecec; color: #b91c1c; }
.stat-icon.kids { background: #fff7e6; color: #b45309; }

.report-header {
  display: flex; align-items: flex-end; justify-content: space-between; gap: 16px;
  flex-wrap: wrap;
  padding-bottom: 18px; margin-bottom: 22px;
  border-bottom: 2px solid var(--border);
}
.report-header-title { font-family: var(--font-display); font-size: 1.3rem; font-weight: 800; color: var(--brand-dark); }
.report-header-meta { font-size: 0.85rem; color: var(--muted); margin-top: 4px; }

.child-summary-banner {
  display: flex; align-items: center; gap: 16px;
  background: var(--white);
  border: 1px solid var(--border);
  border-left: 4px solid var(--brand);
  border-radius: var(--radius);
  padding: 18px 22px;
  margin-bottom: 22px;
}
.child-summary-icon {
  width: 44px; height: 44px; border-radius: 10px; flex-shrink: 0;
  background: var(--canvas); color: var(--brand);
  display: flex; align-items: center; justify-content: center;
  font-size: 1.2rem;
}
.child-summary-value { font-family: var(--font-display); font-size: 1.7rem; font-weight: 800; color: var(--brand-dark); line-height: 1.1; }
.child-summary-label { font-size: 0.85rem; font-weight: 600; color: var(--brand-dark); }
.child-summary-sub { font-size: 0.78rem; color: var(--muted); margin-top: 2px; }

.stock-formula { font-size: 0.82rem; color: var(--muted); margin: -4px 0 14px; font-style: italic; }

/* Revenue hero */
.revenue-hero {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 1px;
  background: var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  margin-bottom: 26px;
  box-shadow: var(--shadow);
}
.revenue-hero-item {
  background: var(--brand-dark);
  color: var(--white);
  padding: 22px 20px;
}
.revenue-hero-item:last-child { background: var(--brand); }
.revenue-hero-label { font-size: 0.78rem; text-transform: uppercase; letter-spacing: 0.04em; color: #b7d9c3; font-weight: 600; }
.revenue-hero-value { font-family: var(--font-display); font-size: 1.6rem; font-weight: 700; margin-top: 8px; }
.revenue-hero-big { font-size: 1.9rem; }

/* Charts */
.chart-row { display: grid; grid-template-columns: 2fr 1fr; gap: 20px; margin-bottom: 26px; align-items: stretch; }
.chart-panel { display: flex; flex-direction: column; }
.chart-panel h2 { font-size: 1.05rem; color: var(--brand-dark); margin-bottom: 14px; }
.chart-wrap { position: relative; flex: 1; min-height: 240px; }
.chart-panel-narrow .chart-wrap { max-height: 280px; }

/* Neon/glow variant for the revenue charts */
.panel.chart-panel-dark {
  background: radial-gradient(120% 160% at 0% 0%, #123322 0%, #06120b 55%, #020604 100%);
  border: 1px solid rgba(74, 222, 128, 0.18);
  box-shadow: 0 1px 2px rgba(0,0,0,0.3), 0 12px 30px rgba(0,0,0,0.35), inset 0 0 60px rgba(21,128,61,0.06);
}
.panel.chart-panel-dark h2 { color: #d9f9e5; }
.chart-panel-dark .chart-wrap canvas { filter: drop-shadow(0 0 7px rgba(74, 222, 128, 0.55)); }

/* Revenue chart date filter */
.revenue-filter-bar { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; margin-bottom: 14px; }
.rf-btn {
  padding: 8px 16px; border-radius: 999px; border: 2px solid var(--border);
  background: var(--white); color: var(--brand-dark);
  font-size: 0.85rem; font-weight: 600; cursor: pointer; white-space: nowrap;
}
.rf-btn:hover { border-color: var(--brand); }
.rf-btn.active { background: var(--brand); border-color: var(--brand); color: var(--white); }
.rf-custom { display: none; align-items: center; gap: 8px; flex-wrap: wrap; }
.rf-custom.open { display: flex; }
.rf-custom .form-input { padding: 7px 10px; width: auto; }
.rf-custom span { color: var(--muted); font-size: 0.85rem; }

@media (max-width: 900px) {
  .revenue-hero { grid-template-columns: repeat(2, 1fr); }
  .chart-row { grid-template-columns: 1fr; }
}

.panel {
  background: var(--white); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 22px; margin-bottom: 22px;
  box-shadow: 0 1px 2px rgba(11,47,30,0.04), 0 8px 20px rgba(11,47,30,0.05);
}
.panel h2 { font-family: var(--font-display); font-size: 1.05rem; color: var(--brand-dark); margin-bottom: 16px; }

table.data-table { width: 100%; border-collapse: collapse; font-size: 0.9rem; }
.data-table th { text-align: left; color: var(--muted); font-size: 0.75rem; text-transform: uppercase; letter-spacing: 0.03em; padding: 10px 12px; border-bottom: 2px solid var(--border); }
.data-table td { padding: 12px; border-bottom: 1px solid var(--border); }
.data-table tr:hover td { background: var(--canvas); }
.pill { padding: 3px 10px; border-radius: 999px; font-size: 0.75rem; font-weight: 700; }
.pill-active { background: #e8f5ec; color: var(--brand); }
.pill-locked { background: #fdecec; color: #b91c1c; }
.pill-inactive { background: #f1f1ef; color: var(--muted); }
.pill-kids { background: #fff7e6; color: #b45309; }
.pill-kids i { margin-right: 4px; }
.pill-quarantine { background: #eef2ff; color: #4338ca; }

.report-panel { padding: 20px 22px; margin-bottom: 16px; }
.report-panel .table-toolbar { margin-bottom: 14px; }
.report-collection-line { color: var(--muted); font-size: 0.85rem; margin: 12px 0 0; }
.report-collection-line i { color: var(--brand); margin-right: 5px; }
.report-collection-line strong { color: var(--brand-dark); }
.report-feed-section { margin-top: 18px; padding-top: 16px; border-top: 1px solid var(--border); }
.report-feed-section h3 { font-family: var(--font-display); font-size: 0.75rem; text-transform: uppercase; letter-spacing: 0.04em; color: var(--muted); margin-bottom: 10px; font-weight: 700; }
.compact-table th, .compact-table td { padding: 8px 12px; font-size: 0.85rem; }

.age-chip-row { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 8px; }
.age-chip {
  padding: 8px 14px; border-radius: 999px; border: 2px solid var(--border);
  background: var(--white); color: var(--brand-dark);
  font-size: 0.82rem; font-weight: 600; cursor: pointer;
}
.age-chip:hover { border-color: var(--brand); }
.age-chip.active { background: var(--brand); border-color: var(--brand); color: var(--white); }

/* Add-animal modal & tabs */
.modal-overlay {
  display: none;
  position: fixed; inset: 0;
  background: rgba(11,47,30,0.45);
  align-items: center; justify-content: center;
  z-index: 50;
}
.modal-overlay.open { display: flex; }
.modal-box {
  background: var(--white);
  border-radius: var(--radius);
  width: 520px;
  max-width: 92vw;
  max-height: 88vh;
  overflow-y: auto;
  padding: 26px;
  box-shadow: var(--shadow);
}
.modal-box h2 { color: var(--brand-dark); font-size: 1.1rem; margin-bottom: 4px; }
.modal-close { float: right; background: none; border: none; font-size: 1.3rem; cursor: pointer; color: var(--muted); }

.tabs { display: flex; gap: 4px; margin: 16px 0 18px; background: var(--canvas); border-radius: 10px; padding: 4px; }
.tab-btn {
  flex: 1; text-align: center; padding: 9px 12px; border: none; background: transparent;
  border-radius: 8px; font-weight: 600; font-size: 0.88rem; color: var(--muted); cursor: pointer;
}
.tab-btn.active { background: var(--white); color: var(--brand-dark); box-shadow: 0 2px 6px rgba(11,47,30,0.1); }
.tab-panel { display: none; }
.tab-panel.active { display: block; }

.table-toolbar { display: flex; justify-content: space-between; align-items: center; margin-bottom: 16px; }

/* Feed / consumption history modals */
.history-modal .modal-box { border-radius: 18px; }
.history-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 14px; flex-shrink: 0; }
.history-head h2 { margin-bottom: 2px; }
.history-sub { color: var(--muted); font-size: 0.85rem; margin: 0 0 16px; flex-shrink: 0; }
.history-occupancy-badge {
  display: inline-flex; align-items: center; gap: 6px; flex-shrink: 0;
  background: var(--brand-light); color: var(--brand-dark);
  border: 1px solid rgba(21,128,61,0.25);
  padding: 6px 14px; border-radius: 999px; font-size: 0.78rem; font-weight: 700; white-space: nowrap;
}

.history-filter-bar {
  display: flex; gap: 16px; flex-wrap: wrap; align-items: flex-end;
  background: var(--canvas); border: 1px solid var(--border); border-radius: 12px;
  padding: 14px 16px; margin-bottom: 18px; flex-shrink: 0;
}
.history-filter-bar .form-label { margin-bottom: 0; font-size: 0.78rem; }
.history-filter-bar .form-input { margin-top: 6px; background: var(--white); }
.history-filter-bar .btn { flex-shrink: 0; }

.history-table-wrap {
  overflow-y: auto; flex: 1 1 auto; min-height: 0;
  border: 1px solid var(--border); border-radius: 12px;
}
table.history-table { font-size: 0.85rem; }
.history-table thead th {
  position: sticky; top: 0; z-index: 1;
  background: var(--canvas); color: var(--brand-dark);
  border-bottom: 2px solid var(--border-strong);
}
.history-table tbody tr:nth-child(even) td { background: rgba(11,47,30,0.015); }
.history-table tbody tr:hover td { background: var(--brand-light); }
.history-table td, .history-table th { white-space: nowrap; }
.history-table .col-num { text-align: right; font-variant-numeric: tabular-nums; }
.history-table .pen-code { font-weight: 700; color: var(--brand-dark); }

.usage-breakdown { display: flex; gap: 10px; align-items: baseline; font-variant-numeric: tabular-nums; }
.usage-breakdown span { display: inline-flex; align-items: center; gap: 3px; font-size: 0.78rem; font-weight: 600; color: var(--muted); }
.usage-breakdown .usage-used { color: var(--brand-dark); font-weight: 700; }
.usage-breakdown .usage-flag.is-nonzero { color: #b45309; }

.animal-count-chip {
  display: inline-flex; align-items: center; gap: 5px;
  background: var(--brand-light); color: var(--brand-dark);
  padding: 3px 10px; border-radius: 999px; font-size: 0.78rem; font-weight: 700;
  font-variant-numeric: tabular-nums;
}
.animal-count-chip i { color: var(--brand); font-size: 0.72rem; }

.pill-warn { background: #fff7e6; color: #b45309; }

.pagination { display: flex; align-items: center; justify-content: center; gap: 6px; margin-top: 18px; flex-wrap: wrap; }
.pagination button {
  min-width: 34px; height: 34px; padding: 0 10px;
  border: 1px solid var(--border); background: var(--white); color: var(--brand-dark);
  border-radius: 8px; font-size: 0.85rem; font-weight: 600; cursor: pointer;
}
.pagination button:hover:not(:disabled) { border-color: var(--brand); color: var(--brand); }
.pagination button.active { background: var(--brand); border-color: var(--brand); color: var(--white); }
.pagination button:disabled { opacity: 0.4; cursor: not-allowed; }
.pagination .pagination-ellipsis { padding: 0 4px; color: var(--muted); }
.loading-row td { text-align: center; color: var(--muted); padding: 20px; }

/* Mobile/tablet nav: sidebar becomes an off-canvas drawer, opened via the topbar hamburger */
.app-menu-btn {
  display: none;
  align-items: center; justify-content: center;
  width: 38px; height: 38px; flex-shrink: 0;
  border: 1px solid var(--border); border-radius: 8px;
  background: var(--white); color: var(--brand-dark);
  font-size: 1rem; cursor: pointer;
}
.app-topbar-title { display: flex; align-items: center; gap: 14px; min-width: 0; }
.app-topbar-title h1 { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.sidebar-overlay {
  display: none;
  position: fixed; inset: 0;
  background: rgba(11,47,30,0.5);
  z-index: 39;
}
.sidebar-overlay.open { display: block; }

@media (max-width: 1024px) {
  .app-menu-btn { display: flex; }
  .sidebar {
    position: fixed; top: 0; left: 0; z-index: 40;
    height: 100vh; width: 270px; max-width: 82vw;
    overflow-y: auto;
    transform: translateX(-100%);
    transition: transform 0.22s ease;
  }
  .sidebar.open { transform: translateX(0); }
}

@media (max-width: 640px) {
  .app-content { padding: 16px; }
  .app-topbar { padding: 12px 16px; flex-wrap: wrap; row-gap: 10px; }
  .app-topbar h1 { font-size: 1.02rem; }
  .topbar-user { font-size: 0.8rem; gap: 8px; flex-wrap: wrap; }
  .panel { padding: 16px; }
  .table-toolbar { flex-wrap: wrap; gap: 10px; align-items: flex-start; }
}

/* Any panel holding a wide table scrolls horizontally instead of squeezing content unreadable */
.panel { overflow-x: auto; }
