:root {
  --bg: #f5f7f3;
  --surface: #ffffff;
  --surface-2: #eef4ef;
  --ink: #18211b;
  --muted: #627062;
  --line: #dbe4d9;
  --primary: #236b4b;
  --primary-2: #164832;
  --accent: #c66b2c;
  --warning: #fff4df;
  --shadow: 0 18px 45px rgba(34, 48, 38, 0.08);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: Arial, Helvetica, sans-serif;
  overflow-x: hidden;
}

button,
input,
select,
textarea {
  font: inherit;
}

button {
  cursor: pointer;
}

.app-hidden {
  display: none !important;
}

.login-screen {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 20px;
  background: linear-gradient(135deg, #17291f 0%, #236b4b 100%);
}

.login-card {
  width: min(430px, 100%);
  display: grid;
  gap: 16px;
  background: var(--surface);
  border: 1px solid rgba(255, 255, 255, 0.2);
  border-radius: 8px;
  box-shadow: var(--shadow);
  padding: 24px;
}

.login-card label {
  display: grid;
  gap: 7px;
  color: var(--muted);
  font-size: 0.9rem;
}

.login-brand {
  margin-bottom: 8px;
}

.login-note {
  margin: 0;
  color: var(--muted);
  font-size: 0.88rem;
  line-height: 1.4;
}

.app-shell {
  display: grid;
  grid-template-columns: 280px minmax(0, 1fr);
  min-height: 100vh;
}

.sidebar {
  background: #17291f;
  color: #f7fbf7;
  padding: 22px;
  display: flex;
  flex-direction: column;
  gap: 26px;
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
}

.brand-mark {
  width: 44px;
  height: 44px;
  border-radius: 8px;
  background: #e6f2e8;
  color: #17291f;
  display: grid;
  place-items: center;
  font-weight: 800;
}

.brand span,
.sync-card span,
.timeline span,
.record-card span,
.pasture-row span,
.queue-list span,
.connection-state span,
.metric small {
  display: block;
  color: var(--muted);
  font-size: 0.9rem;
  line-height: 1.35;
}

.sidebar .brand span,
.sidebar .sync-card span {
  color: #bad0c0;
}

.nav {
  display: grid;
  gap: 8px;
}

.nav-item {
  border: 0;
  border-radius: 8px;
  background: transparent;
  color: #dce9df;
  text-align: left;
  padding: 12px 14px;
}

.nav-item:hover,
.nav-item.active {
  background: #244534;
  color: #ffffff;
}

.sync-card {
  margin-top: auto;
  border: 1px solid rgba(255, 255, 255, 0.12);
  border-radius: 8px;
  padding: 14px;
  display: flex;
  gap: 10px;
  align-items: flex-start;
}

.status-dot,
.large-dot {
  width: 11px;
  height: 11px;
  border-radius: 50%;
  background: var(--accent);
  box-shadow: 0 0 0 4px rgba(198, 107, 44, 0.18);
  flex: 0 0 auto;
  margin-top: 4px;
}

.main {
  padding: 28px;
  overflow: hidden;
  min-width: 0;
}

.topbar {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  align-items: flex-start;
  margin-bottom: 24px;
}

.eyebrow {
  margin: 0 0 6px;
  color: var(--muted);
  font-size: 0.92rem;
}

h1,
h2,
p {
  margin-top: 0;
}

h1 {
  margin-bottom: 0;
  font-size: 2rem;
}

h2 {
  font-size: 1.05rem;
  margin-bottom: 16px;
}

.top-actions {
  display: flex;
  align-items: center;
  gap: 10px;
}

.user-chip {
  display: flex;
  align-items: center;
  gap: 8px;
  color: var(--muted);
}

.property-picker {
  display: grid;
  gap: 5px;
}

.select-label {
  color: var(--muted);
  font-size: 0.9rem;
}

select,
input,
textarea {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #ffffff;
  color: var(--ink);
  padding: 11px 12px;
  min-height: 42px;
}

.view {
  display: none;
}

.active-view {
  display: block;
}

.metric-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 14px;
  margin-bottom: 18px;
}

.metric,
.panel,
.record-card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
}

.metric {
  padding: 18px;
}

.metric span {
  color: var(--muted);
  font-size: 0.9rem;
}

.metric strong {
  display: block;
  font-size: 2rem;
  margin: 8px 0 4px;
}

.metric.warning {
  background: var(--warning);
  border-color: #edd7ad;
}

.content-grid {
  display: grid;
  gap: 18px;
}

.two-columns {
  grid-template-columns: minmax(0, 1.2fr) minmax(320px, 0.8fr);
}

.panel {
  padding: 20px;
}

.panel-header,
.toolbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  margin-bottom: 16px;
}

.panel-header h2 {
  margin-bottom: 0;
}

.primary,
.icon-btn,
.record-card button {
  border: 0;
  border-radius: 8px;
  padding: 11px 14px;
  min-height: 42px;
  font-weight: 700;
}

.primary {
  background: var(--primary);
  color: #ffffff;
}

.primary:hover {
  background: var(--primary-2);
}

.primary.small {
  min-height: 34px;
  padding: 8px 12px;
}

.icon-btn,
.record-card button {
  background: var(--surface-2);
  color: var(--primary-2);
}

.record-card button.danger,
button.danger {
  background: #fde7e4;
  color: #9b2c1f;
}

.card-actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}

.full {
  width: 100%;
}

.pasture-list,
.timeline,
.queue-list {
  display: grid;
  gap: 12px;
}

.pasture-row,
.timeline-item,
.queue-list div,
.summary-box {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 14px;
  background: #fbfdfb;
}

.pasture-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 160px;
  gap: 14px;
  align-items: center;
}

progress,
meter {
  width: 100%;
  height: 12px;
}

.timeline-item {
  border-left: 4px solid var(--primary);
}

.timeline-item.pending {
  border-left-color: var(--accent);
}

.toolbar input {
  flex: 1;
  min-width: 160px;
}

.table-wrap {
  overflow-x: auto;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
}

table {
  width: 100%;
  border-collapse: collapse;
  min-width: 840px;
}

th,
td {
  text-align: left;
  padding: 14px 16px;
  border-bottom: 1px solid var(--line);
  vertical-align: middle;
}

th {
  color: var(--muted);
  font-size: 0.9rem;
  background: #f9fbf8;
}

tbody tr {
  cursor: pointer;
}

.badge {
  display: inline-flex;
  align-items: center;
  border-radius: 999px;
  padding: 5px 10px;
  font-size: 0.82rem;
  font-weight: 700;
  white-space: nowrap;
}

.badge.ok {
  background: #e4f5e9;
  color: #17633c;
}

.badge.sync {
  background: #fff0d8;
  color: #8a4c12;
}

.animal-photo,
.photo-preview {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface-2);
  overflow: hidden;
}

.animal-photo {
  width: 46px;
  height: 46px;
  display: inline-grid;
  place-items: center;
  color: var(--primary-2);
  font-size: 0.75rem;
  font-weight: 800;
}

.animal-photo img,
.photo-preview img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

.photo-preview {
  min-height: 130px;
  display: grid;
  place-items: center;
  color: var(--muted);
  font-size: 0.9rem;
}

.cards-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 14px;
}

.record-card {
  padding: 18px;
  display: grid;
  gap: 12px;
}

.form-layout {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 360px;
  gap: 18px;
  align-items: start;
}

.movement-form {
  display: grid;
  gap: 14px;
}

.movement-form label {
  display: grid;
  gap: 7px;
  color: var(--muted);
  font-size: 0.9rem;
}

.movement-form label > input,
.movement-form label > select,
.movement-form label > textarea {
  color: var(--ink);
}

.summary-box {
  margin-bottom: 12px;
}

.summary-box span {
  display: block;
  color: var(--muted);
  font-size: 0.9rem;
  margin-bottom: 5px;
}

.connection-state {
  display: flex;
  gap: 16px;
  align-items: flex-start;
  padding: 18px;
  background: var(--warning);
  border: 1px solid #edd7ad;
  border-radius: 8px;
  margin-bottom: 16px;
}

.connection-state.synced {
  background: #e4f5e9;
  border-color: #badfca;
}

.connection-state.synced .large-dot {
  background: var(--primary);
  box-shadow: 0 0 0 4px rgba(35, 107, 75, 0.18);
}

.large-dot {
  width: 18px;
  height: 18px;
}

#toast {
  position: fixed;
  right: 22px;
  bottom: 22px;
  background: #17291f;
  color: #ffffff;
  padding: 13px 16px;
  border-radius: 8px;
  box-shadow: var(--shadow);
  opacity: 0;
  transform: translateY(12px);
  pointer-events: none;
  transition: opacity 0.2s ease, transform 0.2s ease;
}

#toast.show {
  opacity: 1;
  transform: translateY(0);
}

dialog {
  width: min(460px, calc(100vw - 28px));
  max-height: calc(100dvh - 28px);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
  padding: 0;
  overflow: auto;
}

dialog::backdrop {
  background: rgba(18, 31, 23, 0.45);
}

.dialog-card {
  display: grid;
  gap: 14px;
  padding: 20px;
}

.dialog-actions {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 8px;
}

.dialog-actions button {
  min-width: 0;
}

.dialog-card label {
  display: grid;
  gap: 7px;
  color: var(--muted);
  font-size: 0.9rem;
}

.dialog-status {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fbfdfb;
  color: var(--ink);
  font-weight: 700;
  padding: 10px 12px;
}

.conditional-fields {
  display: grid;
  gap: 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fbfdfb;
  padding: 14px;
}

.conditional-fields[hidden] {
  display: none;
}

@media (max-width: 980px) {
  .app-shell {
    grid-template-columns: 1fr;
  }

  .sidebar {
    position: sticky;
    top: 0;
    z-index: 10;
    padding: 14px;
    overflow: hidden;
  }

  .nav {
    display: flex;
    overflow-x: auto;
    padding-bottom: 2px;
    min-width: 0;
  }

  .nav-item {
    white-space: nowrap;
    flex: 0 0 auto;
  }

  .sync-card {
    display: none;
  }

  .metric-grid,
  .cards-grid,
  .two-columns,
  .form-layout {
    grid-template-columns: 1fr;
  }

  .main {
    padding: 18px;
  }

  .topbar,
  .toolbar {
    flex-direction: column;
    align-items: stretch;
  }

  .top-actions {
    align-items: stretch;
    flex-direction: column;
  }

  .property-picker {
    width: 100%;
  }
}

@media (max-width: 560px) {
  dialog {
    width: calc(100vw - 16px);
    max-height: calc(100dvh - 16px);
  }

  .dialog-card {
    padding: 16px;
  }

  .dialog-actions {
    grid-template-columns: 1fr 1fr;
  }

  .brand {
    align-items: flex-start;
  }

  h1 {
    font-size: 1.55rem;
  }

  .metric strong {
    font-size: 1.55rem;
  }

  .pasture-row {
    grid-template-columns: 1fr;
  }

  .panel-header {
    align-items: flex-start;
    flex-direction: column;
  }
}
