/* ============================================================
   FarmFlow Design System — main.css
   
   Design concept: "Field-to-Ledger"
   A poultry farm management app needs data density, instant 
   legibility, and calm authority. Not a dashboard template.
   
   Palette: Deep forest green primary (#1A3D2B), warm amber
   accent (#D4860A), off-white canvas (#F7F5F0), slate text.
   The green grounds the product in agriculture; the amber
   signals urgency/attention; the off-white is warmer than #fff.
   
   Signature: The left-side navigation has a solid deep green
   column — every other element respects this anchor.
   
   Typography: system-ui for data; no web font requests on
   shared hosting (avoids external requests for speed).
   ============================================================ */

/* ---------------------------------------------------------------
   CSS CUSTOM PROPERTIES (Design Tokens)
--------------------------------------------------------------- */
:root {
  /* Primary — deep forest green */
  --color-primary-900: #0D2016;
  --color-primary-800: #1A3D2B;   /* Main nav background */
  --color-primary-700: #245235;
  --color-primary-600: #2E6B43;
  --color-primary-500: #3A8554;
  --color-primary-100: #E8F2EC;
  --color-primary-50:  #F3F8F5;

  /* Accent — warm amber */
  --color-amber-700:   #A8670A;
  --color-amber-600:   #D4860A;   /* Primary accent */
  --color-amber-100:   #FEF3DC;
  --color-amber-50:    #FFFBF0;

  /* Semantic status colours */
  --color-success-700: #1A6B35;
  --color-success-100: #D9F0E2;
  --color-danger-700:  #9B1C1C;
  --color-danger-100:  #FDE8E8;
  --color-warning-700: #92600A;
  --color-warning-100: #FEF3DC;
  --color-info-700:    #1E4F8A;
  --color-info-100:    #DBEAFE;

  /* Neutral greys */
  --color-neutral-900: #111827;
  --color-neutral-800: #1F2937;
  --color-neutral-700: #374151;
  --color-neutral-600: #4B5563;
  --color-neutral-500: #6B7280;
  --color-neutral-400: #9CA3AF;
  --color-neutral-300: #D1D5DB;
  --color-neutral-200: #E5E7EB;
  --color-neutral-100: #F3F4F6;
  --color-neutral-50:  #F9FAFB;

  /* Canvas */
  --color-canvas:      #F7F5F0;   /* Warm off-white — not pure #fff */
  --color-surface:     #FFFFFF;
  --color-border:      #E0DDD6;   /* Matches warm canvas tint */

  /* Typography */
  --font-sans: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
  --font-mono: 'SF Mono', 'Fira Code', 'Consolas', monospace;

  /* Type scale */
  --text-xs:   0.75rem;    /* 12px */
  --text-sm:   0.875rem;   /* 14px */
  --text-base: 1rem;       /* 16px */
  --text-lg:   1.125rem;   /* 18px */
  --text-xl:   1.25rem;    /* 20px */
  --text-2xl:  1.5rem;     /* 24px */
  --text-3xl:  1.875rem;   /* 30px */
  --text-4xl:  2.25rem;    /* 36px */

  /* Font weights — bold and legible per PRD instruction #7 */
  --weight-normal:    400;
  --weight-medium:    500;
  --weight-semibold:  600;
  --weight-bold:      700;
  --weight-extrabold: 800;

  /* Spacing scale (4px base) */
  --space-1:  0.25rem;
  --space-2:  0.5rem;
  --space-3:  0.75rem;
  --space-4:  1rem;
  --space-5:  1.25rem;
  --space-6:  1.5rem;
  --space-8:  2rem;
  --space-10: 2.5rem;
  --space-12: 3rem;
  --space-16: 4rem;

  /* Border radius */
  --radius-sm:  4px;
  --radius-md:  8px;
  --radius-lg:  12px;
  --radius-xl:  16px;
  --radius-full: 9999px;

  /* Shadows */
  --shadow-sm:  0 1px 2px rgba(0,0,0,0.06), 0 1px 3px rgba(0,0,0,0.08);
  --shadow-md:  0 4px 6px rgba(0,0,0,0.07), 0 2px 4px rgba(0,0,0,0.06);
  --shadow-lg:  0 10px 15px rgba(0,0,0,0.08), 0 4px 6px rgba(0,0,0,0.05);

  /* Layout */
  --sidebar-width:      260px;
  --sidebar-collapsed:  72px;
  --topbar-height:      60px;
  --content-max-width:  1280px;

  /* Transition */
  --transition-fast: 150ms ease;
  --transition-base: 250ms ease;
}

/* ---------------------------------------------------------------
   RESET & BASE
--------------------------------------------------------------- */
*, *::before, *::after { box-sizing: border-box; }

html {
  font-size: 16px;
  -webkit-text-size-adjust: 100%;
  scroll-behavior: smooth;
}

body {
  margin: 0;
  font-family: var(--font-sans);
  font-size: var(--text-base);
  font-weight: var(--weight-normal);
  line-height: 1.6;
  color: var(--color-neutral-800);
  background-color: var(--color-canvas);
  -webkit-font-smoothing: antialiased;
}

a { color: var(--color-primary-600); text-decoration: none; }
a:hover { color: var(--color-primary-800); text-decoration: underline; }

img, svg { display: block; max-width: 100%; }

input, select, textarea, button {
  font-family: inherit;
  font-size: inherit;
}

h1, h2, h3, h4, h5, h6 {
  margin: 0 0 var(--space-4);
  font-weight: var(--weight-bold);
  line-height: 1.25;
  color: var(--color-neutral-900);
}

p { margin: 0 0 var(--space-4); }
p:last-child { margin-bottom: 0; }

/* ---------------------------------------------------------------
   APP LAYOUT — Sidebar + Main
--------------------------------------------------------------- */
.app-layout {
  display: flex;
  min-height: 100vh;
}

/* ---------------------------------------------------------------
   SIDEBAR NAVIGATION
--------------------------------------------------------------- */
.sidebar {
  position: fixed;
  top: 0;
  left: 0;
  width: var(--sidebar-width);
  height: 100vh;
  background-color: var(--color-primary-800);
  display: flex;
  flex-direction: column;
  z-index: 100;
  overflow-y: auto;
  overflow-x: hidden;
  transition: width var(--transition-base), transform var(--transition-base);
}

/* Sidebar brand/logo area */
.sidebar__brand {
  padding: var(--space-6) var(--space-5);
  border-bottom: 1px solid rgba(255,255,255,0.1);
  flex-shrink: 0;
}
.sidebar__brand-name {
  font-size: var(--text-xl);
  font-weight: var(--weight-extrabold);
  color: #FFFFFF;
  letter-spacing: -0.02em;
  display: flex;
  align-items: center;
  gap: var(--space-3);
}
.sidebar__brand-icon {
  width: 32px;
  height: 32px;
  background-color: var(--color-amber-600);
  border-radius: var(--radius-md);
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}
.sidebar__farm-name {
  font-size: var(--text-xs);
  color: rgba(255,255,255,0.55);
  font-weight: var(--weight-medium);
  margin-top: var(--space-1);
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

/* Nav sections */
.sidebar__nav {
  flex: 1;
  padding: var(--space-4) 0;
  overflow-y: auto;
}

.nav-section {
  margin-bottom: var(--space-2);
}
.nav-section__label {
  padding: var(--space-3) var(--space-5) var(--space-1);
  font-size: var(--text-xs);
  font-weight: var(--weight-semibold);
  color: rgba(255,255,255,0.35);
  text-transform: uppercase;
  letter-spacing: 0.08em;
}

/* Individual nav items */
.nav-item {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  padding: var(--space-3) var(--space-5);
  color: rgba(255,255,255,0.75);
  font-size: var(--text-sm);
  font-weight: var(--weight-medium);
  border: none;
  background: none;
  cursor: pointer;
  width: 100%;
  text-align: left;
  transition: background var(--transition-fast), color var(--transition-fast);
  text-decoration: none;
  border-radius: 0;
}
.nav-item:hover {
  background: rgba(255,255,255,0.08);
  color: #FFFFFF;
  text-decoration: none;
}
.nav-item.active {
  background: rgba(255,255,255,0.12);
  color: #FFFFFF;
  font-weight: var(--weight-semibold);
  border-right: 3px solid var(--color-amber-600);
}
.nav-item__icon {
  width: 20px;
  height: 20px;
  flex-shrink: 0;
  opacity: 0.8;
}
.nav-item.active .nav-item__icon { opacity: 1; }

/* Notification badge on nav item */
.nav-badge {
  margin-left: auto;
  background: var(--color-amber-600);
  color: #fff;
  font-size: var(--text-xs);
  font-weight: var(--weight-bold);
  min-width: 20px;
  height: 20px;
  border-radius: var(--radius-full);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0 var(--space-1);
}

/* Sidebar footer — user info */
.sidebar__footer {
  padding: var(--space-4) var(--space-5);
  border-top: 1px solid rgba(255,255,255,0.1);
  flex-shrink: 0;
}
.sidebar__user {
  display: flex;
  align-items: center;
  gap: var(--space-3);
}
.sidebar__user-avatar {
  width: 36px;
  height: 36px;
  background-color: var(--color-primary-600);
  border-radius: var(--radius-full);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: var(--text-sm);
  font-weight: var(--weight-bold);
  color: #fff;
  flex-shrink: 0;
}
.sidebar__user-info { flex: 1; min-width: 0; }
.sidebar__user-name {
  font-size: var(--text-sm);
  font-weight: var(--weight-semibold);
  color: #fff;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.sidebar__user-role {
  font-size: var(--text-xs);
  color: rgba(255,255,255,0.5);
  text-transform: capitalize;
}
.sidebar__logout {
  color: rgba(255,255,255,0.5);
  font-size: var(--text-xs);
  text-decoration: none;
  transition: color var(--transition-fast);
}
.sidebar__logout:hover { color: var(--color-danger-100); text-decoration: none; }

/* ---------------------------------------------------------------
   MAIN CONTENT AREA
--------------------------------------------------------------- */
.main-content {
  margin-left: var(--sidebar-width);
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  width: calc(100% - var(--sidebar-width));
  transition: margin-left var(--transition-base), width var(--transition-base);
}

/* Top bar */
.topbar {
  position: sticky;
  top: 0;
  height: var(--topbar-height);
  background: var(--color-surface);
  border-bottom: 1px solid var(--color-border);
  display: flex;
  align-items: center;
  padding: 0 var(--space-6);
  gap: var(--space-4);
  z-index: 50;
  box-shadow: var(--shadow-sm);
}
.topbar__menu-btn {
  display: none;
  border: none;
  background: none;
  cursor: pointer;
  color: var(--color-neutral-600);
  padding: var(--space-2);
  border-radius: var(--radius-md);
}
.topbar__menu-btn:hover { background: var(--color-neutral-100); }
.topbar__breadcrumb {
  flex: 1;
  font-size: var(--text-sm);
  color: var(--color-neutral-500);
  display: flex;
  align-items: center;
  gap: var(--space-2);
}
.topbar__breadcrumb-current {
  color: var(--color-neutral-900);
  font-weight: var(--weight-semibold);
}
.topbar__actions {
  display: flex;
  align-items: center;
  gap: var(--space-3);
}
.topbar__notif-btn {
  position: relative;
  background: none;
  border: none;
  cursor: pointer;
  color: var(--color-neutral-600);
  padding: var(--space-2);
  border-radius: var(--radius-md);
  transition: background var(--transition-fast);
}
.topbar__notif-btn:hover { background: var(--color-neutral-100); }
.topbar__notif-count {
  position: absolute;
  top: 2px;
  right: 2px;
  background: var(--color-amber-600);
  color: #fff;
  font-size: 10px;
  font-weight: var(--weight-bold);
  min-width: 16px;
  height: 16px;
  border-radius: var(--radius-full);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0 3px;
}
.topbar__notif-count:empty { display: none; }

/* Page content wrapper */
.page-content {
  flex: 1;
  padding: var(--space-8) var(--space-6);
  max-width: var(--content-max-width);
  width: 100%;
}

/* Page header inside content */
.page-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: var(--space-4);
  margin-bottom: var(--space-8);
  flex-wrap: wrap;
}
.page-header__title {
  font-size: var(--text-2xl);
  font-weight: var(--weight-extrabold);
  color: var(--color-neutral-900);
  margin: 0;
  line-height: 1.2;
}
.page-header__subtitle {
  font-size: var(--text-sm);
  color: var(--color-neutral-500);
  margin-top: var(--space-1);
  font-weight: var(--weight-normal);
}
.page-header__actions {
  display: flex;
  gap: var(--space-3);
  flex-shrink: 0;
  flex-wrap: wrap;
}

/* ---------------------------------------------------------------
   STAT / KPI CARDS (Dashboard)
--------------------------------------------------------------- */
.stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  gap: var(--space-5);
  margin-bottom: var(--space-8);
}

.stat-card {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-lg);
  padding: var(--space-6);
  display: flex;
  flex-direction: column;
  gap: var(--space-3);
  box-shadow: var(--shadow-sm);
  transition: box-shadow var(--transition-fast);
}
.stat-card:hover { box-shadow: var(--shadow-md); }

.stat-card__label {
  font-size: var(--text-xs);
  font-weight: var(--weight-semibold);
  color: var(--color-neutral-500);
  text-transform: uppercase;
  letter-spacing: 0.07em;
}
.stat-card__value {
  font-size: var(--text-3xl);
  font-weight: var(--weight-extrabold);
  color: var(--color-neutral-900);
  line-height: 1;
}
.stat-card__sub {
  font-size: var(--text-xs);
  color: var(--color-neutral-500);
}
.stat-card__icon {
  width: 40px;
  height: 40px;
  border-radius: var(--radius-md);
  display: flex;
  align-items: center;
  justify-content: center;
}
.stat-card__icon--green  { background: var(--color-primary-100); color: var(--color-primary-700); }
.stat-card__icon--amber  { background: var(--color-amber-100);   color: var(--color-amber-700);   }
.stat-card__icon--red    { background: var(--color-danger-100);  color: var(--color-danger-700);  }
.stat-card__icon--blue   { background: var(--color-info-100);    color: var(--color-info-700);    }

/* ---------------------------------------------------------------
   CARDS / PANELS
--------------------------------------------------------------- */
.card {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-lg);
  overflow: hidden;
  box-shadow: var(--shadow-sm);
  margin-bottom: var(--space-6);
}
.card--flat { box-shadow: none; }

.card__header {
  padding: var(--space-5) var(--space-6);
  border-bottom: 1px solid var(--color-border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-4);
  flex-wrap: wrap;
}
.card__title {
  font-size: var(--text-base);
  font-weight: var(--weight-bold);
  color: var(--color-neutral-900);
  margin: 0;
}
.card__subtitle {
  font-size: var(--text-xs);
  color: var(--color-neutral-500);
  margin-top: 2px;
}
.card__body { padding: var(--space-6); }
.card__body--tight { padding: var(--space-4); }
.card__footer {
  padding: var(--space-4) var(--space-6);
  border-top: 1px solid var(--color-border);
  background: var(--color-neutral-50);
}

/* Grid of cards */
.cards-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(340px, 1fr));
  gap: var(--space-5);
  margin-bottom: var(--space-6);
}
.cards-grid--2 { grid-template-columns: repeat(2, 1fr); }
.cards-grid--3 { grid-template-columns: repeat(3, 1fr); }

/* ---------------------------------------------------------------
   BUTTONS
--------------------------------------------------------------- */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-2);
  padding: 0.625rem var(--space-5);
  font-size: var(--text-sm);
  font-weight: var(--weight-bold);
  border-radius: var(--radius-md);
  border: 2px solid transparent;
  cursor: pointer;
  text-decoration: none;
  transition: background var(--transition-fast), color var(--transition-fast), border-color var(--transition-fast), box-shadow var(--transition-fast);
  white-space: nowrap;
  line-height: 1;
  user-select: none;
}
.btn:focus-visible {
  outline: 3px solid var(--color-amber-600);
  outline-offset: 2px;
}
.btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

/* Primary */
.btn--primary {
  background: var(--color-primary-600);
  color: #fff;
  border-color: var(--color-primary-600);
}
.btn--primary:hover:not(:disabled) {
  background: var(--color-primary-700);
  border-color: var(--color-primary-700);
  color: #fff;
  text-decoration: none;
}

/* Secondary (outlined) */
.btn--secondary {
  background: transparent;
  color: var(--color-primary-700);
  border-color: var(--color-primary-600);
}
.btn--secondary:hover:not(:disabled) {
  background: var(--color-primary-50);
  text-decoration: none;
}

/* Danger */
.btn--danger {
  background: var(--color-danger-700);
  color: #fff;
  border-color: var(--color-danger-700);
}
.btn--danger:hover:not(:disabled) {
  background: #7a1515;
  border-color: #7a1515;
  color: #fff;
  text-decoration: none;
}

/* Danger outline */
.btn--danger-outline {
  background: transparent;
  color: var(--color-danger-700);
  border-color: var(--color-danger-700);
}
.btn--danger-outline:hover:not(:disabled) {
  background: var(--color-danger-100);
  text-decoration: none;
}

/* Ghost */
.btn--ghost {
  background: transparent;
  color: var(--color-neutral-600);
  border-color: var(--color-neutral-300);
}
.btn--ghost:hover:not(:disabled) {
  background: var(--color-neutral-100);
  text-decoration: none;
}

/* Amber / accent */
.btn--accent {
  background: var(--color-amber-600);
  color: #fff;
  border-color: var(--color-amber-600);
}
.btn--accent:hover:not(:disabled) {
  background: var(--color-amber-700);
  border-color: var(--color-amber-700);
  color: #fff;
  text-decoration: none;
}

/* Sizes */
.btn--sm  { padding: 0.375rem var(--space-4); font-size: var(--text-xs); }
.btn--lg  { padding: 0.875rem var(--space-8); font-size: var(--text-base); }
.btn--icon {
  padding: 0.5rem;
  aspect-ratio: 1;
}
.btn--full { width: 100%; }
.btn--loading { position: relative; color: transparent !important; }
.btn--loading::after {
  content: '';
  position: absolute;
  width: 16px; height: 16px;
  border: 2px solid rgba(255,255,255,0.4);
  border-top-color: #fff;
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
}

/* ---------------------------------------------------------------
   FORMS
--------------------------------------------------------------- */
.form-group {
  margin-bottom: var(--space-5);
}
.form-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: var(--space-5);
}
.form-grid--2 { grid-template-columns: repeat(2, 1fr); }
.form-grid--3 { grid-template-columns: repeat(3, 1fr); }

.form-label {
  display: block;
  font-size: var(--text-sm);
  font-weight: var(--weight-semibold);
  color: var(--color-neutral-700);
  margin-bottom: var(--space-2);
}
.form-label .required {
  color: var(--color-danger-700);
  margin-left: 2px;
}

.form-control {
  display: block;
  width: 100%;
  padding: 0.625rem var(--space-4);
  font-size: var(--text-sm);
  font-weight: var(--weight-medium);
  color: var(--color-neutral-900);
  background: var(--color-surface);
  border: 2px solid var(--color-neutral-300);
  border-radius: var(--radius-md);
  transition: border-color var(--transition-fast), box-shadow var(--transition-fast);
  appearance: none;
  line-height: 1.5;
}
.form-control:focus {
  outline: none;
  border-color: var(--color-primary-600);
  box-shadow: 0 0 0 3px rgba(46, 107, 67, 0.15);
}
.form-control::placeholder { color: var(--color-neutral-400); font-weight: var(--weight-normal); }
.form-control--error {
  border-color: var(--color-danger-700);
  background: #fff8f8;
}
.form-control--error:focus {
  box-shadow: 0 0 0 3px rgba(155, 28, 28, 0.15);
}

select.form-control {
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='8' viewBox='0 0 12 8'%3E%3Cpath d='M1 1l5 5 5-5' stroke='%236B7280' stroke-width='2' fill='none' stroke-linecap='round'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 14px center;
  padding-right: 2.5rem;
  cursor: pointer;
}

textarea.form-control {
  resize: vertical;
  min-height: 100px;
}

.form-hint {
  font-size: var(--text-xs);
  color: var(--color-neutral-500);
  margin-top: var(--space-1);
}

.form-error {
  font-size: var(--text-xs);
  font-weight: var(--weight-semibold);
  color: var(--color-danger-700);
  margin-top: var(--space-1);
  display: flex;
  align-items: center;
  gap: var(--space-1);
}
.form-error::before {
  content: '⚠';
  font-size: 11px;
}

/* Checkbox & radio */
.form-check {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  cursor: pointer;
  padding: var(--space-1) 0;
}
.form-check input[type="checkbox"],
.form-check input[type="radio"] {
  width: 18px;
  height: 18px;
  cursor: pointer;
  accent-color: var(--color-primary-600);
  flex-shrink: 0;
}
.form-check__label {
  font-size: var(--text-sm);
  font-weight: var(--weight-medium);
  color: var(--color-neutral-700);
  user-select: none;
}

/* Radio group — pill style */
.radio-group {
  display: flex;
  gap: var(--space-2);
  flex-wrap: wrap;
}
.radio-pill { display: none; }
.radio-pill + label {
  display: inline-flex;
  align-items: center;
  padding: var(--space-2) var(--space-4);
  border: 2px solid var(--color-neutral-300);
  border-radius: var(--radius-full);
  font-size: var(--text-sm);
  font-weight: var(--weight-semibold);
  color: var(--color-neutral-600);
  cursor: pointer;
  transition: all var(--transition-fast);
  user-select: none;
}
.radio-pill:checked + label {
  border-color: var(--color-primary-600);
  background: var(--color-primary-100);
  color: var(--color-primary-800);
}

/* ---------------------------------------------------------------
   TABLES
--------------------------------------------------------------- */
.table-wrapper {
  overflow-x: auto;
  border-radius: var(--radius-lg);
  border: 1px solid var(--color-border);
  background: var(--color-surface);
}

table.table {
  width: 100%;
  border-collapse: collapse;
  font-size: var(--text-sm);
}
.table thead tr {
  background: var(--color-neutral-50);
}
.table th {
  padding: var(--space-3) var(--space-4);
  font-size: var(--text-xs);
  font-weight: var(--weight-bold);
  color: var(--color-neutral-500);
  text-transform: uppercase;
  letter-spacing: 0.06em;
  text-align: left;
  border-bottom: 2px solid var(--color-border);
  white-space: nowrap;
}
.table td {
  padding: var(--space-4);
  border-bottom: 1px solid var(--color-border);
  color: var(--color-neutral-800);
  vertical-align: middle;
}
.table td:first-child, .table th:first-child { padding-left: var(--space-6); }
.table td:last-child,  .table th:last-child  { padding-right: var(--space-6); }
.table tbody tr:last-child td { border-bottom: none; }
.table tbody tr:hover { background: var(--color-neutral-50); }

/* Specific table cell styles */
.table .td-code {
  font-family: var(--font-mono);
  font-size: var(--text-xs);
  font-weight: var(--weight-bold);
  color: var(--color-primary-700);
}
.table .td-num {
  font-variant-numeric: tabular-nums;
  font-weight: var(--weight-semibold);
  text-align: right;
}
.table .td-actions {
  text-align: right;
  white-space: nowrap;
}
.table .td-muted { color: var(--color-neutral-400); font-size: var(--text-xs); }

/* ---------------------------------------------------------------
   BADGES
--------------------------------------------------------------- */
.badge {
  display: inline-flex;
  align-items: center;
  gap: var(--space-1);
  padding: 3px 10px;
  border-radius: var(--radius-full);
  font-size: var(--text-xs);
  font-weight: var(--weight-bold);
  line-height: 1;
  text-transform: capitalize;
  white-space: nowrap;
}
.badge--success  { background: var(--color-success-100); color: var(--color-success-700); }
.badge--danger   { background: var(--color-danger-100);  color: var(--color-danger-700);  }
.badge--warning  { background: var(--color-warning-100); color: var(--color-warning-700); }
.badge--info     { background: var(--color-info-100);    color: var(--color-info-700);    }
.badge--neutral  { background: var(--color-neutral-100); color: var(--color-neutral-700); }
.badge--primary  { background: var(--color-primary-100); color: var(--color-primary-800); }
.badge--dark     { background: var(--color-neutral-700); color: #fff;                     }

/* Stage badge colour map */
.badge--stage-stocked  { background: var(--color-neutral-100); color: var(--color-neutral-700); }
.badge--stage-brooding { background: var(--color-info-100);    color: var(--color-info-700);    }
.badge--stage-grow_out { background: var(--color-primary-100); color: var(--color-primary-800); }
.badge--stage-laying   { background: var(--color-success-100); color: var(--color-success-700); }
.badge--stage-decline  { background: var(--color-warning-100); color: var(--color-warning-700); }
.badge--stage-harvest  { background: var(--color-amber-100);   color: var(--color-amber-700);   }
.badge--stage-closed   { background: var(--color-neutral-200); color: var(--color-neutral-600); }

/* Role badges */
.role-badge--super-admin { background: #1a1a2e; color: #fff; }
.role-badge--admin       { background: var(--color-primary-100); color: var(--color-primary-800); }
.role-badge--manager     { background: var(--color-info-100);    color: var(--color-info-700); }
.role-badge--operator    { background: var(--color-neutral-100); color: var(--color-neutral-700); }
.role-badge--cashier     { background: var(--color-amber-100);   color: var(--color-amber-700); }

/* ---------------------------------------------------------------
   ALERTS / FLASH MESSAGES
--------------------------------------------------------------- */
.alert {
  display: flex;
  align-items: flex-start;
  gap: var(--space-3);
  padding: var(--space-4) var(--space-5);
  border-radius: var(--radius-md);
  border: 1px solid;
  margin-bottom: var(--space-5);
  font-size: var(--text-sm);
  font-weight: var(--weight-medium);
}
.alert__icon { flex-shrink: 0; margin-top: 1px; }
.alert__content { flex: 1; }
.alert__title   { font-weight: var(--weight-bold); margin-bottom: var(--space-1); }
.alert__dismiss {
  background: none;
  border: none;
  cursor: pointer;
  color: inherit;
  opacity: 0.6;
  padding: 0;
  font-size: var(--text-lg);
  line-height: 1;
  transition: opacity var(--transition-fast);
}
.alert__dismiss:hover { opacity: 1; }

.alert--success { background: var(--color-success-100); border-color: #8fcca6; color: var(--color-success-700); }
.alert--error   { background: var(--color-danger-100);  border-color: #f5a6a6; color: var(--color-danger-700);  }
.alert--warning { background: var(--color-warning-100); border-color: #e8c670; color: var(--color-warning-700); }
.alert--info    { background: var(--color-info-100);    border-color: #93b8ec; color: var(--color-info-700);    }

/* ---------------------------------------------------------------
   SKELETON LOADING STATES
   PRD Instruction #4: "Loading screens must be well optimized
   with skeleton screens"
--------------------------------------------------------------- */
@keyframes skeleton-pulse {
  0%, 100% { opacity: 1; }
  50%       { opacity: 0.4; }
}

.skeleton {
  background: var(--color-neutral-200);
  border-radius: var(--radius-sm);
  animation: skeleton-pulse 1.8s ease-in-out infinite;
  display: block;
}
.skeleton--text  { height: 1em;  width: 100%; margin-bottom: var(--space-2); }
.skeleton--title { height: 1.5em; width: 60%; margin-bottom: var(--space-3); }
.skeleton--stat  { height: 3rem; width: 80%; }
.skeleton--avatar{ width: 36px; height: 36px; border-radius: 50%; }
.skeleton--badge { height: 22px; width: 70px; border-radius: 99px; }
.skeleton--btn   { height: 38px; width: 100px; border-radius: var(--radius-md); }
.skeleton--row   { height: 52px; width: 100%; margin-bottom: 1px; }
.skeleton--card  { height: 160px; border-radius: var(--radius-lg); }

/* Loading state for tables */
.skeleton-table { width: 100%; }
.skeleton-table .skeleton-row {
  display: grid;
  grid-template-columns: 1fr 2fr 1fr 1fr 1fr;
  gap: var(--space-4);
  padding: var(--space-4) var(--space-6);
  border-bottom: 1px solid var(--color-border);
}

/* ---------------------------------------------------------------
   PAGINATION
--------------------------------------------------------------- */
.pagination {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: var(--space-4) var(--space-6);
  border-top: 1px solid var(--color-border);
  flex-wrap: wrap;
  gap: var(--space-3);
}
.pagination__info {
  font-size: var(--text-sm);
  color: var(--color-neutral-500);
}
.pagination__pages {
  display: flex;
  gap: var(--space-1);
}
.pagination__page {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 36px;
  height: 36px;
  border-radius: var(--radius-md);
  font-size: var(--text-sm);
  font-weight: var(--weight-semibold);
  border: 2px solid transparent;
  text-decoration: none;
  transition: all var(--transition-fast);
  color: var(--color-neutral-600);
  padding: 0 var(--space-2);
}
.pagination__page:hover {
  background: var(--color-neutral-100);
  text-decoration: none;
}
.pagination__page.active {
  background: var(--color-primary-800);
  color: #fff;
  border-color: var(--color-primary-800);
}
.pagination__page.disabled {
  opacity: 0.4;
  pointer-events: none;
}

/* ---------------------------------------------------------------
   EMPTY STATES
--------------------------------------------------------------- */
.empty-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: var(--space-16) var(--space-8);
  text-align: center;
}
.empty-state__icon {
  width: 60px;
  height: 60px;
  background: var(--color-neutral-100);
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  margin-bottom: var(--space-4);
  color: var(--color-neutral-400);
}
.empty-state__title {
  font-size: var(--text-lg);
  font-weight: var(--weight-bold);
  color: var(--color-neutral-700);
  margin-bottom: var(--space-2);
}
.empty-state__body {
  font-size: var(--text-sm);
  color: var(--color-neutral-500);
  max-width: 360px;
  margin-bottom: var(--space-6);
}

/* ---------------------------------------------------------------
   FILTER BARS
--------------------------------------------------------------- */
.filter-bar {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  flex-wrap: wrap;
  padding: var(--space-4) var(--space-6);
  border-bottom: 1px solid var(--color-border);
  background: var(--color-neutral-50);
}
.filter-bar .form-control {
  min-width: 160px;
  width: auto;
  flex: 1;
}
.filter-bar__spacer { flex: 1; }

/* ---------------------------------------------------------------
   MODALS
--------------------------------------------------------------- */
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.5);
  z-index: 200;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: var(--space-4);
  opacity: 0;
  pointer-events: none;
  transition: opacity var(--transition-base);
}
.modal-backdrop.open {
  opacity: 1;
  pointer-events: all;
}
.modal {
  background: var(--color-surface);
  border-radius: var(--radius-xl);
  width: 100%;
  max-width: 520px;
  max-height: 90vh;
  overflow-y: auto;
  box-shadow: var(--shadow-lg);
  transform: translateY(16px);
  transition: transform var(--transition-base);
}
.modal-backdrop.open .modal { transform: translateY(0); }
.modal__header {
  padding: var(--space-6);
  border-bottom: 1px solid var(--color-border);
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.modal__title { font-size: var(--text-lg); font-weight: var(--weight-bold); margin: 0; }
.modal__close {
  background: none;
  border: none;
  cursor: pointer;
  color: var(--color-neutral-500);
  font-size: var(--text-xl);
  padding: var(--space-1);
  border-radius: var(--radius-sm);
  transition: color var(--transition-fast);
}
.modal__close:hover { color: var(--color-neutral-900); }
.modal__body   { padding: var(--space-6); }
.modal__footer {
  padding: var(--space-4) var(--space-6);
  border-top: 1px solid var(--color-border);
  display: flex;
  justify-content: flex-end;
  gap: var(--space-3);
}

/* ---------------------------------------------------------------
   DETAIL / DEFINITION LISTS
--------------------------------------------------------------- */
.detail-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
  gap: var(--space-5);
}
.detail-item {}
.detail-item__label {
  font-size: var(--text-xs);
  font-weight: var(--weight-semibold);
  color: var(--color-neutral-500);
  text-transform: uppercase;
  letter-spacing: 0.06em;
  margin-bottom: var(--space-1);
}
.detail-item__value {
  font-size: var(--text-base);
  font-weight: var(--weight-semibold);
  color: var(--color-neutral-900);
}
.detail-item__value--large {
  font-size: var(--text-2xl);
  font-weight: var(--weight-extrabold);
}

/* ---------------------------------------------------------------
   AUTH LAYOUT (login page)
--------------------------------------------------------------- */
.auth-layout {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--color-canvas);
  padding: var(--space-4);
}
.auth-card {
  width: 100%;
  max-width: 420px;
  background: var(--color-surface);
  border-radius: var(--radius-xl);
  border: 1px solid var(--color-border);
  box-shadow: var(--shadow-lg);
  overflow: hidden;
}
.auth-card__header {
  background: var(--color-primary-800);
  padding: var(--space-8) var(--space-8) var(--space-6);
  text-align: center;
}
.auth-card__logo {
  width: 48px;
  height: 48px;
  background: var(--color-amber-600);
  border-radius: var(--radius-lg);
  display: flex;
  align-items: center;
  justify-content: center;
  margin: 0 auto var(--space-4);
}
.auth-card__app-name {
  font-size: var(--text-2xl);
  font-weight: var(--weight-extrabold);
  color: #fff;
  letter-spacing: -0.02em;
}
.auth-card__tagline {
  font-size: var(--text-sm);
  color: rgba(255,255,255,0.6);
  margin-top: var(--space-1);
}
.auth-card__body { padding: var(--space-8); }
.auth-card__title {
  font-size: var(--text-xl);
  font-weight: var(--weight-bold);
  color: var(--color-neutral-900);
  margin-bottom: var(--space-6);
}

/* ---------------------------------------------------------------
   PROFIT / LOSS COLOR UTILITIES
--------------------------------------------------------------- */
.text--success { color: var(--color-success-700); font-weight: var(--weight-semibold); }
.text--danger  { color: var(--color-danger-700);  font-weight: var(--weight-semibold); }
.text--warning { color: var(--color-warning-700); }
.text--muted   { color: var(--color-neutral-500); }
.text--bold    { font-weight: var(--weight-bold); }
.text--right   { text-align: right; }
.text--center  { text-align: center; }

/* ---------------------------------------------------------------
   NOTIFICATION ITEMS
--------------------------------------------------------------- */
.notif-list { list-style: none; padding: 0; margin: 0; }
.notif-item {
  display: flex;
  align-items: flex-start;
  gap: var(--space-3);
  padding: var(--space-4) var(--space-5);
  border-bottom: 1px solid var(--color-border);
  transition: background var(--transition-fast);
}
.notif-item:last-child { border-bottom: none; }
.notif-item.unread { background: var(--color-amber-50); }
.notif-item:hover  { background: var(--color-neutral-50); }
.notif-item__dot {
  width: 8px; height: 8px;
  background: var(--color-amber-600);
  border-radius: 50%;
  margin-top: 6px;
  flex-shrink: 0;
}
.notif-item.read .notif-item__dot { opacity: 0; }
.notif-item__body { flex: 1; }
.notif-item__title {
  font-size: var(--text-sm);
  font-weight: var(--weight-semibold);
  color: var(--color-neutral-800);
  margin-bottom: 2px;
}
.notif-item__msg {
  font-size: var(--text-xs);
  color: var(--color-neutral-500);
  line-height: 1.5;
}
.notif-item__time {
  font-size: var(--text-xs);
  color: var(--color-neutral-400);
  flex-shrink: 0;
}

/* ---------------------------------------------------------------
   STAGE TIMELINE (batch detail)
--------------------------------------------------------------- */
.stage-timeline { padding: 0; margin: 0; list-style: none; }
.stage-timeline__item {
  display: flex;
  gap: var(--space-4);
  padding-bottom: var(--space-5);
  position: relative;
}
.stage-timeline__item:not(:last-child)::before {
  content: '';
  position: absolute;
  left: 11px;
  top: 24px;
  bottom: 0;
  width: 2px;
  background: var(--color-border);
}
.stage-timeline__dot {
  width: 24px; height: 24px;
  border-radius: 50%;
  background: var(--color-primary-100);
  border: 2px solid var(--color-primary-500);
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 10px;
  color: var(--color-primary-700);
  font-weight: var(--weight-bold);
}
.stage-timeline__item.system .stage-timeline__dot { background: var(--color-neutral-100); border-color: var(--color-neutral-400); }
.stage-timeline__content { flex: 1; }
.stage-timeline__label { font-size: var(--text-sm); font-weight: var(--weight-semibold); }
.stage-timeline__meta  { font-size: var(--text-xs); color: var(--color-neutral-400); margin-top: 2px; }

/* ---------------------------------------------------------------
   ANIMATIONS
--------------------------------------------------------------- */
@keyframes spin {
  to { transform: rotate(360deg); }
}
@keyframes fadeIn {
  from { opacity: 0; transform: translateY(4px); }
  to   { opacity: 1; transform: translateY(0); }
}
@keyframes slideInRight {
  from { opacity: 0; transform: translateX(20px); }
  to   { opacity: 1; transform: translateX(0); }
}

.animate-fade-in    { animation: fadeIn 0.3s ease forwards; }
.animate-slide-in   { animation: slideInRight 0.3s ease forwards; }

/* Reduce motion for accessibility */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    transition-duration: 0.01ms !important;
  }
}

/* ---------------------------------------------------------------
   RESPONSIVE — MOBILE & TABLET
   PRD Instruction #8: "optimized to function and display well on
   all devices and screen sizes"
--------------------------------------------------------------- */

/* Mobile sidebar overlay */
.sidebar-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.5);
  z-index: 99;
}
.sidebar-overlay.open { display: block; }

@media (max-width: 1024px) {
  .cards-grid--3 { grid-template-columns: repeat(2, 1fr); }
  .form-grid--3  { grid-template-columns: repeat(2, 1fr); }
}

@media (max-width: 768px) {
  /* Collapse sidebar to overlay on mobile */
  .sidebar {
    transform: translateX(-100%);
    box-shadow: none;
  }
  .sidebar.open {
    transform: translateX(0);
    box-shadow: var(--shadow-lg);
  }

  .main-content {
    margin-left: 0;
    width: 100%;
  }

  .topbar__menu-btn { display: flex; }

  .page-content {
    padding: var(--space-5) var(--space-4);
  }

  .page-header {
    margin-bottom: var(--space-5);
  }
  .page-header__title { font-size: var(--text-xl); }

  .stats-grid { grid-template-columns: repeat(2, 1fr); gap: var(--space-3); }
  .stat-card  { padding: var(--space-4); }
  .stat-card__value { font-size: var(--text-2xl); }

  .cards-grid,
  .cards-grid--2,
  .cards-grid--3 { grid-template-columns: 1fr; }

  .form-grid,
  .form-grid--2,
  .form-grid--3 { grid-template-columns: 1fr; }

  /* Tables scroll on mobile */
  .table-wrapper { border-radius: var(--radius-md); }
  .table th, .table td {
    padding: var(--space-3);
    font-size: var(--text-xs);
  }
  .table td:first-child, .table th:first-child { padding-left: var(--space-4); }
  .table td:last-child,  .table th:last-child  { padding-right: var(--space-4); }

  /* Hide less important table columns on mobile using data attributes */
  .table .hide-mobile { display: none; }

  .filter-bar { padding: var(--space-3) var(--space-4); gap: var(--space-2); }
  .filter-bar .form-control { min-width: 0; }

  .auth-card { border-radius: var(--radius-lg); }
  .auth-card__header { padding: var(--space-6); }
  .auth-card__body   { padding: var(--space-5); }

  .modal { border-radius: var(--radius-lg); margin: var(--space-4); }
  .modal-backdrop { padding: var(--space-2); }

  .detail-grid { grid-template-columns: repeat(2, 1fr); }

  .pagination { flex-direction: column; align-items: flex-start; }
  .pagination__pages { flex-wrap: wrap; }

  .btn--lg { padding: 0.75rem var(--space-6); }
}

@media (max-width: 480px) {
  .stats-grid { grid-template-columns: 1fr; }
  .detail-grid { grid-template-columns: 1fr; }
  .page-header { flex-direction: column; }
  .page-header__actions { width: 100%; }
  .page-header__actions .btn { flex: 1; justify-content: center; }
  .radio-group { flex-direction: column; }
  .topbar { padding: 0 var(--space-4); }
}

/* ---------------------------------------------------------------
   PRINT STYLES (for reports)
--------------------------------------------------------------- */
@media print {
  .sidebar, .topbar, .btn, .filter-bar, .pagination { display: none !important; }
  .main-content { margin-left: 0 !important; width: 100% !important; }
  .card { box-shadow: none; border: 1px solid #ccc; }
  body { background: #fff; color: #000; }
}
