/* ===================================================================
   Sistema de Gestão de Gado — Design tokens
   Paleta: pasto (verde profundo) + couro/terra (marrom) sobre fundo
   claro neutro. Tipografia: Fraunces (display) + Inter (corpo/dados)
   + IBM Plex Mono (números, para reforçar a leitura tipo "caderno
   de registro de fazenda").
   =================================================================== */

:root {
  --color-bg: #F5F2EA;
  --color-surface: #FFFFFF;
  --color-surface-alt: #FBF9F4;

  --color-primary: #24402F;
  --color-primary-dark: #152B1D;
  --color-primary-soft: #E4ECE2;

  --color-accent: #A8632C;
  --color-accent-soft: #F0DFC9;

  --color-success: #4C7A52;
  --color-success-soft: #E3EDE2;
  --color-warning: #B5832A;
  --color-warning-soft: #F6E9D2;
  --color-danger: #A8432F;
  --color-danger-soft: #F3DFD8;
  --color-info: #3E6FA0;
  --color-info-soft: #DEE9F2;

  --color-text: #221F18;
  --color-text-muted: #6E6A5C;
  --color-border: #E2DDCC;

  --font-display: "Fraunces", Georgia, serif;
  --font-body: "Inter", -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  --font-mono: "IBM Plex Mono", "Courier New", monospace;

  --radius-sm: 6px;
  --radius-md: 10px;
  --radius-lg: 16px;

  --shadow-card: 0 1px 2px rgba(20, 24, 16, 0.06), 0 4px 12px rgba(20, 24, 16, 0.06);
  --shadow-modal: 0 12px 40px rgba(15, 20, 12, 0.28);

  --sidebar-width: 264px;
}

@import url('https://fonts.googleapis.com/css2?family=Fraunces:opsz,wght@9..144,400;9..144,600;9..144,700&family=Inter:wght@400;500;600;700&family=IBM+Plex+Mono:wght@500;600&display=swap');

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }

body {
  background: var(--color-bg);
  color: var(--color-text);
  font-family: var(--font-body);
  font-size: 14px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

a { color: inherit; }

/* ---------- Layout ---------- */

.app-shell {
  display: flex;
  min-height: 100vh;
}

.sidebar {
  width: var(--sidebar-width);
  flex-shrink: 0;
  background: var(--color-primary-dark);
  color: #EFEDE3;
  padding: 22px 0 22px;
  position: sticky;
  top: 0;
  height: 100vh;
  overflow-y: auto;
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 0 22px 20px;
  border-bottom: 1px solid rgba(255,255,255,0.08);
  margin-bottom: 14px;
}

.brand-mark {
  width: 30px;
  height: 30px;
  border-radius: 50%;
  background: var(--color-accent);
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}
.brand-mark svg { width: 17px; height: 17px; }

.brand-name {
  font-family: var(--font-display);
  font-weight: 600;
  font-size: 16.5px;
  letter-spacing: 0.01em;
  color: #FAF8F0;
}
.brand-sub {
  font-size: 10.5px;
  color: #AFC2AB;
  letter-spacing: 0.06em;
  text-transform: uppercase;
}

.nav-group { margin-bottom: 6px; }
.nav-group-label {
  font-size: 10.5px;
  letter-spacing: 0.09em;
  text-transform: uppercase;
  color: #8AA286;
  padding: 14px 22px 6px;
  font-weight: 600;
}

.nav-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 22px;
  cursor: pointer;
  color: #D7DCC9;
  font-size: 13.5px;
  font-weight: 500;
  border-left: 3px solid transparent;
  transition: background 0.12s, color 0.12s;
  user-select: none;
}
.nav-item:hover { background: rgba(255,255,255,0.05); color: #fff; }
.nav-item.active {
  background: rgba(168, 99, 44, 0.18);
  border-left-color: var(--color-accent);
  color: #fff;
}
.nav-dot {
  width: 6px; height: 6px; border-radius: 50%;
  background: currentColor; opacity: 0.55; flex-shrink: 0;
}

.main {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 18px 32px;
  border-bottom: 1px solid var(--color-border);
  background: var(--color-surface);
  position: sticky;
  top: 0;
  z-index: 5;
}
.topbar-title {
  font-family: var(--font-display);
  font-size: 21px;
  font-weight: 600;
}
.topbar-sub { color: var(--color-text-muted); font-size: 12.5px; margin-top: 2px; }

.content { padding: 28px 32px 60px; flex: 1; }

/* ---------- Buttons ---------- */

.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-family: var(--font-body);
  font-weight: 600;
  font-size: 13px;
  padding: 9px 16px;
  border-radius: var(--radius-sm);
  border: 1px solid transparent;
  cursor: pointer;
  transition: filter 0.12s, background 0.12s;
}
.btn-primary { background: var(--color-primary); color: #fff; }
.btn-primary:hover { filter: brightness(1.12); }
.btn-accent { background: var(--color-accent); color: #fff; }
.btn-accent:hover { filter: brightness(1.1); }
.btn-ghost { background: transparent; border-color: var(--color-border); color: var(--color-text); }
.btn-ghost:hover { background: var(--color-surface-alt); }
.btn-danger { background: var(--color-danger-soft); color: var(--color-danger); }
.btn-sm { padding: 5px 10px; font-size: 12px; }

/* ---------- KPI cards (estilo "ficha de curral") ---------- */

.kpi-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 16px;
  margin-bottom: 28px;
}

.kpi-card {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-top: 3px solid var(--color-accent);
  border-radius: var(--radius-md);
  padding: 16px 18px;
  box-shadow: var(--shadow-card);
  position: relative;
}
.kpi-label {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--color-text-muted);
  font-weight: 600;
  margin-bottom: 8px;
}
.kpi-value {
  font-family: var(--font-mono);
  font-size: 26px;
  font-weight: 600;
  color: var(--color-primary);
  line-height: 1.1;
}
.kpi-value.danger { color: var(--color-danger); }
.kpi-value.success { color: var(--color-success); }
.kpi-foot { font-size: 11.5px; color: var(--color-text-muted); margin-top: 6px; }

/* ---------- Charts ---------- */

.charts-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(320px, 1fr));
  gap: 16px;
  margin-bottom: 28px;
}
.chart-card {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  padding: 18px;
  box-shadow: var(--shadow-card);
}
.chart-card h3 {
  font-family: var(--font-display);
  font-size: 15px;
  font-weight: 600;
  margin: 0 0 14px;
}
.chart-card canvas { max-height: 260px; }

/* ---------- Tabela genérica ---------- */

.panel {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-card);
  overflow: hidden;
}
.panel-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 18px;
  border-bottom: 1px solid var(--color-border);
  gap: 12px;
  flex-wrap: wrap;
}
.panel-head input[type="search"] {
  border: 1px solid var(--color-border);
  border-radius: var(--radius-sm);
  padding: 7px 11px;
  font-size: 13px;
  width: 220px;
  font-family: var(--font-body);
}

table { width: 100%; border-collapse: collapse; font-size: 13px; }
thead th {
  text-align: left;
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--color-text-muted);
  background: var(--color-surface-alt);
  padding: 10px 14px;
  border-bottom: 1px solid var(--color-border);
  white-space: nowrap;
}
tbody td {
  padding: 10px 14px;
  border-bottom: 1px solid var(--color-border);
  vertical-align: middle;
}
tbody tr:hover { background: var(--color-surface-alt); }
tbody tr:last-child td { border-bottom: none; }
.table-actions { display: flex; gap: 6px; justify-content: flex-end; }
.cell-muted { color: var(--color-text-muted); }
.empty-state {
  padding: 48px 20px;
  text-align: center;
  color: var(--color-text-muted);
}

/* ---------- Badge "brinco de identificação" (signature element) ---------- */

.tag-pill {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 3px 10px 3px 16px;
  border-radius: 4px 10px 10px 4px;
  font-size: 11.5px;
  font-weight: 600;
  position: relative;
  white-space: nowrap;
}
.tag-pill::before {
  content: "";
  position: absolute;
  left: 5px;
  top: 50%;
  transform: translateY(-50%);
  width: 5px;
  height: 5px;
  border-radius: 50%;
  background: var(--color-surface);
  box-shadow: 0 0 0 1px currentColor inset;
}
.tag-pill.is-success { background: var(--color-success-soft); color: var(--color-success); }
.tag-pill.is-warning { background: var(--color-warning-soft); color: var(--color-warning); }
.tag-pill.is-danger  { background: var(--color-danger-soft);  color: var(--color-danger); }
.tag-pill.is-info    { background: var(--color-info-soft);    color: var(--color-info); }
.tag-pill.is-muted   { background: var(--color-border);       color: var(--color-text-muted); }

/* ---------- Modal / Formulário ---------- */

.modal-backdrop {
  position: fixed; inset: 0;
  background: rgba(21, 30, 18, 0.45);
  display: flex; align-items: center; justify-content: center;
  z-index: 50;
  padding: 20px;
}
.modal {
  background: var(--color-surface);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-modal);
  width: 100%;
  max-width: 560px;
  max-height: 88vh;
  overflow-y: auto;
}
.modal-head {
  display: flex; align-items: center; justify-content: space-between;
  padding: 18px 22px;
  border-bottom: 1px solid var(--color-border);
}
.modal-head h3 { font-family: var(--font-display); font-size: 17px; margin: 0; }
.modal-close { cursor: pointer; color: var(--color-text-muted); font-size: 18px; background: none; border: none; }
.modal-body { padding: 20px 22px; }
.modal-foot {
  display: flex; justify-content: flex-end; gap: 10px;
  padding: 16px 22px; border-top: 1px solid var(--color-border);
}

.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 14px 16px; }
.form-field { display: flex; flex-direction: column; gap: 5px; }
.form-field.full { grid-column: 1 / -1; }
.form-field label { font-size: 12px; font-weight: 600; color: var(--color-text-muted); }
.form-field input, .form-field select, .form-field textarea {
  border: 1px solid var(--color-border);
  border-radius: var(--radius-sm);
  padding: 8px 10px;
  font-size: 13.5px;
  font-family: var(--font-body);
  background: var(--color-surface-alt);
}
.form-field input:focus, .form-field select:focus, .form-field textarea:focus {
  outline: 2px solid var(--color-accent);
  outline-offset: 1px;
  background: var(--color-surface);
}
.form-field textarea { resize: vertical; min-height: 64px; }
.form-hint { font-size: 11px; color: var(--color-text-muted); }

.toast {
  position: fixed; bottom: 22px; right: 22px;
  background: var(--color-primary-dark); color: #fff;
  padding: 12px 18px; border-radius: var(--radius-sm);
  font-size: 13px; box-shadow: var(--shadow-modal);
  z-index: 80; max-width: 320px;
}
.toast.is-danger { background: var(--color-danger); }

.loading-row td { text-align: center; color: var(--color-text-muted); padding: 30px; }

@media (max-width: 880px) {
  .sidebar { display: none; }
  .form-grid { grid-template-columns: 1fr; }
}
