/* ═══════════════════════════════════════════════════════════════════════════
   LUNARAE FARM ERP — Design System CSS
   Inspired by Linear · Stripe · Vercel · Notion
   Dark mode default. Light mode via [data-theme="light"].
═══════════════════════════════════════════════════════════════════════════ */

/* ─── DESIGN TOKENS ──────────────────────────────────────────────────────── */

:root,
[data-theme="dark"] {
  /* Backgrounds */
  --bg-base:         #07070d;
  --bg-primary:      #0d0d16;
  --bg-secondary:    #111120;
  --bg-card:         #16162a;
  --bg-card-hover:   #1c1c33;
  --bg-elevated:     #1e1e35;
  --bg-border:       #252540;
  --bg-border-light: #2d2d50;

  /* Brand / Primary */
  --color-primary:        #22c55e;
  --color-primary-hover:  #16a34a;
  --color-primary-active: #15803d;
  --color-primary-muted:  rgba(34, 197, 94, 0.12);
  --color-primary-text:   #4ade80;

  /* Semantic */
  --color-success:        #22c55e;
  --color-success-muted:  rgba(34, 197, 94, 0.12);
  --color-warning:        #f59e0b;
  --color-warning-muted:  rgba(245, 158, 11, 0.12);
  --color-danger:         #ef4444;
  --color-danger-muted:   rgba(239, 68, 68, 0.12);
  --color-info:           #3b82f6;
  --color-info-muted:     rgba(59, 130, 246, 0.12);

  /* Accent */
  --color-purple: #a855f7;
  --color-teal:   #14b8a6;
  --color-orange: #f97316;

  /* Text */
  --text-primary:   #f1f5f9;
  --text-secondary: #94a3b8;
  --text-muted:     #64748b;
  --text-disabled:  #334155;

  /* Link */
  --color-link:       #60a5fa;
  --color-link-hover: #93c5fd;

  /* Shadows */
  --shadow-sm: 0 1px 2px rgba(0,0,0,0.4);
  --shadow-md: 0 4px 8px rgba(0,0,0,0.5), 0 1px 2px rgba(0,0,0,0.3);
  --shadow-lg: 0 10px 25px rgba(0,0,0,0.6), 0 4px 8px rgba(0,0,0,0.4);
  --shadow-primary-glow: 0 0 0 3px rgba(34,197,94,0.2);
  --shadow-danger-glow:  0 0 0 3px rgba(239,68,68,0.2);

  /* Dimensions */
  --sidebar-width:    260px;
  --topbar-height:    60px;
  --radius-sm:  4px;
  --radius-md:  6px;
  --radius-lg:  8px;
  --radius-xl:  12px;
  --radius-full:9999px;

  /* Transitions */
  --transition-fast: 150ms ease;
  --transition-base: 200ms ease;
  --transition-slow: 300ms ease;
}

[data-theme="light"] {
  --bg-base:         #ffffff;
  --bg-primary:      #f8fafc;
  --bg-secondary:    #f1f5f9;
  --bg-card:         #ffffff;
  --bg-card-hover:   #f8fafc;
  --bg-elevated:     #ffffff;
  --bg-border:       #e2e8f0;
  --bg-border-light: #cbd5e1;
  --text-primary:    #0f172a;
  --text-secondary:  #475569;
  --text-muted:      #94a3b8;
  --text-disabled:   #cbd5e1;
  --shadow-sm: 0 1px 3px rgba(0,0,0,0.08);
  --shadow-md: 0 4px 12px rgba(0,0,0,0.08), 0 1px 3px rgba(0,0,0,0.06);
  --shadow-lg: 0 10px 25px rgba(0,0,0,0.10), 0 4px 8px rgba(0,0,0,0.06);
}

/* ─── RESET & BASE ───────────────────────────────────────────────────────── */

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

html { font-size: 15px; scroll-behavior: smooth; }

body {
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  background: var(--bg-primary);
  color: var(--text-primary);
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
}

a { color: var(--color-link); text-decoration: none; }
a:hover { color: var(--color-link-hover); }

/* ─── SCROLLBAR ──────────────────────────────────────────────────────────── */
::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--bg-border-light); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: var(--text-muted); }

/* ─── LAYOUT ─────────────────────────────────────────────────────────────── */

.app-body {
  display: flex;
  height: 100vh;
  overflow: hidden;
  background: var(--bg-base);
}

.app-layout {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-width: 0;
  height: 100vh;
  overflow: hidden;
}

/* ─── SIDEBAR ────────────────────────────────────────────────────────────── */

.sidebar {
  width: var(--sidebar-width);
  min-width: var(--sidebar-width);
  background: var(--bg-secondary);
  border-right: 1px solid var(--bg-border);
  display: flex;
  flex-direction: column;
  height: 100vh;
  overflow: hidden;
  transition: width var(--transition-base), min-width var(--transition-base);
  flex-shrink: 0;
}

.sidebar.collapsed {
  width: 64px;
  min-width: 64px;
}

.sidebar-header {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 16px 14px;
  border-bottom: 1px solid var(--bg-border);
  min-height: 61px;
}

.sidebar-logo {
  flex-shrink: 0;
  display: flex;
  align-items: center;
}

.sidebar-farm-info {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
}

.sidebar-farm-name {
  font-size: 13px;
  font-weight: 600;
  color: var(--text-primary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.sidebar-farm-code {
  font-size: 11px;
  color: var(--text-muted);
  font-weight: 500;
  letter-spacing: 0.04em;
}

.sidebar-collapse-btn {
  background: none;
  border: none;
  cursor: pointer;
  color: var(--text-muted);
  padding: 4px;
  border-radius: var(--radius-md);
  transition: color var(--transition-fast), background var(--transition-fast);
  flex-shrink: 0;
}
.sidebar-collapse-btn:hover { color: var(--text-primary); background: var(--bg-border); }

/* Sidebar Navigation */

.sidebar-nav {
  flex: 1;
  overflow-y: auto;
  padding: 8px 0;
}

.nav-section {
  padding: 8px 0;
}

.nav-section + .nav-section {
  border-top: 1px solid var(--bg-border);
}

.nav-section-label {
  display: block;
  font-size: 10px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text-muted);
  padding: 8px 16px 4px;
}

.sidebar.collapsed .nav-section-label,
.sidebar.collapsed .sidebar-farm-info,
.sidebar.collapsed .sidebar-collapse-btn,
.sidebar.collapsed .nav-item-label,
.sidebar.collapsed .nav-group-chevron,
.sidebar.collapsed .sidebar-user-info { display: none; }

/* Nav Items */

.nav-item,
.nav-group-toggle {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 7px 16px;
  color: var(--text-secondary);
  font-size: 13px;
  font-weight: 500;
  border-radius: 0;
  cursor: pointer;
  transition: color var(--transition-fast), background var(--transition-fast);
  width: 100%;
  border: none;
  background: none;
  text-align: left;
  text-decoration: none;
  position: relative;
}

.nav-item:hover,
.nav-group-toggle:hover {
  color: var(--text-primary);
  background: var(--bg-card-hover);
}

.nav-item-active {
  color: var(--color-primary-text) !important;
  background: var(--color-primary-muted) !important;
}

.nav-item-active::before {
  content: '';
  position: absolute;
  left: 0;
  top: 0;
  bottom: 0;
  width: 2px;
  background: var(--color-primary);
  border-radius: 0 2px 2px 0;
}

.nav-item-icon { flex-shrink: 0; opacity: 0.7; }
.nav-item-active .nav-item-icon { opacity: 1; }

/* Nav Groups (collapsible) */

.nav-group-toggle { justify-content: flex-start; }
.nav-group-chevron { margin-left: auto; flex-shrink: 0; transition: transform var(--transition-fast); opacity: 0.5; }
.nav-group.nav-group-active .nav-group-chevron { transform: rotate(180deg); }

.nav-subgroup {
  display: none;
  padding-left: 42px;
  padding-bottom: 4px;
}

.nav-subgroup.nav-subgroup-open { display: block; }

.nav-subitem {
  display: block;
  padding: 5px 12px;
  font-size: 12.5px;
  color: var(--text-muted);
  border-radius: var(--radius-md);
  margin: 1px 6px 1px 0;
  transition: color var(--transition-fast), background var(--transition-fast);
  text-decoration: none;
}

.nav-subitem:hover { color: var(--text-secondary); background: var(--bg-card-hover); }
.nav-subitem-active { color: var(--color-primary-text) !important; font-weight: 500; }

/* Sidebar User */

.sidebar-user {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 12px 14px;
  border-top: 1px solid var(--bg-border);
}

.sidebar-user-avatar {
  width: 30px;
  height: 30px;
  border-radius: var(--radius-full);
  background: var(--color-primary-muted);
  color: var(--color-primary-text);
  font-size: 12px;
  font-weight: 700;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.sidebar-user-info { flex: 1; min-width: 0; }

.sidebar-user-name {
  display: block;
  font-size: 12px;
  font-weight: 600;
  color: var(--text-primary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.sidebar-user-role {
  display: block;
  font-size: 11px;
  color: var(--text-muted);
}

.sidebar-user-settings {
  color: var(--text-muted);
  padding: 4px;
  border-radius: var(--radius-md);
  transition: color var(--transition-fast);
  flex-shrink: 0;
}
.sidebar-user-settings:hover { color: var(--text-primary); }

/* ─── TOPBAR ─────────────────────────────────────────────────────────────── */

.topbar {
  height: var(--topbar-height);
  min-height: var(--topbar-height);
  background: var(--bg-secondary);
  border-bottom: 1px solid var(--bg-border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 20px;
  gap: 12px;
  position: sticky;
  top: 0;
  z-index: 50;
}

.topbar-left { display: flex; align-items: center; gap: 12px; flex: 1; min-width: 0; }
.topbar-right { display: flex; align-items: center; gap: 8px; flex-shrink: 0; }

.topbar-menu-btn {
  background: none;
  border: none;
  cursor: pointer;
  color: var(--text-muted);
  padding: 6px;
  border-radius: var(--radius-md);
  transition: color var(--transition-fast);
  display: none;
}
@media (max-width: 1023px) { .topbar-menu-btn { display: flex; } }
.topbar-menu-btn:hover { color: var(--text-primary); }

.breadcrumb { display: flex; align-items: center; gap: 6px; font-size: 13px; }
.breadcrumb-link { color: var(--text-muted); transition: color var(--transition-fast); }
.breadcrumb-link:hover { color: var(--text-secondary); }
.breadcrumb-sep { color: var(--bg-border-light); }
.breadcrumb-current { color: var(--text-secondary); font-weight: 500; }

.topbar-search-btn {
  display: flex;
  align-items: center;
  gap: 8px;
  background: var(--bg-card);
  border: 1px solid var(--bg-border);
  border-radius: var(--radius-lg);
  padding: 6px 12px;
  cursor: pointer;
  color: var(--text-muted);
  font-size: 13px;
  font-family: inherit;
  transition: border-color var(--transition-fast), color var(--transition-fast);
  min-width: 220px;
}
.topbar-search-btn:hover { border-color: var(--bg-border-light); color: var(--text-secondary); }
.topbar-search-btn span { flex: 1; text-align: left; }
.topbar-search-btn kbd {
  font-size: 10px;
  background: var(--bg-border);
  border-radius: 3px;
  padding: 2px 5px;
  font-family: inherit;
  color: var(--text-muted);
}

.topbar-icon-btn {
  background: none;
  border: none;
  cursor: pointer;
  color: var(--text-muted);
  padding: 7px;
  border-radius: var(--radius-md);
  position: relative;
  transition: color var(--transition-fast), background var(--transition-fast);
}
.topbar-icon-btn:hover { color: var(--text-primary); background: var(--bg-card-hover); }

.notif-badge {
  position: absolute;
  top: 4px; right: 4px;
  min-width: 16px;
  height: 16px;
  background: var(--color-danger);
  color: white;
  font-size: 9px;
  font-weight: 700;
  border-radius: var(--radius-full);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0 3px;
}

/* Notification Dropdown */
.topbar-notif-wrapper, .topbar-user-wrapper { position: relative; }

.notif-dropdown, .user-dropdown {
  position: absolute;
  top: calc(100% + 8px);
  right: 0;
  background: var(--bg-elevated);
  border: 1px solid var(--bg-border-light);
  border-radius: var(--radius-xl);
  box-shadow: var(--shadow-lg);
  min-width: 320px;
  z-index: 100;
  animation: dropdown-in 150ms ease;
}

.notif-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 14px 16px 10px;
  font-size: 13px;
  font-weight: 600;
  color: var(--text-primary);
  border-bottom: 1px solid var(--bg-border);
}

.notif-mark-read {
  background: none;
  border: none;
  cursor: pointer;
  font-size: 12px;
  color: var(--color-link);
  font-family: inherit;
  padding: 2px;
}
.notif-mark-read:hover { color: var(--color-link-hover); }

.notif-list { max-height: 320px; overflow-y: auto; }

.notif-item {
  display: flex;
  gap: 10px;
  padding: 10px 16px;
  border-bottom: 1px solid var(--bg-border);
  font-size: 12.5px;
  transition: background var(--transition-fast);
}
.notif-item:hover { background: var(--bg-card-hover); }
.notif-item-unread { background: var(--color-primary-muted); }
.notif-item-icon { flex-shrink: 0; font-size: 16px; margin-top: 2px; }
.notif-item-text { flex: 1; }
.notif-item-title { color: var(--text-primary); font-weight: 500; }
.notif-item-time { color: var(--text-muted); font-size: 11px; margin-top: 2px; }

.notif-footer {
  padding: 10px 16px;
  text-align: center;
  font-size: 12px;
}

.notif-loading { padding: 20px; text-align: center; color: var(--text-muted); font-size: 13px; }

/* User Dropdown */
.topbar-user-btn {
  display: flex;
  align-items: center;
  gap: 8px;
  background: none;
  border: none;
  cursor: pointer;
  color: var(--text-secondary);
  font-size: 13px;
  font-weight: 500;
  font-family: inherit;
  padding: 6px 8px;
  border-radius: var(--radius-lg);
  transition: color var(--transition-fast), background var(--transition-fast);
}
.topbar-user-btn:hover { color: var(--text-primary); background: var(--bg-card-hover); }

.topbar-avatar {
  width: 28px;
  height: 28px;
  border-radius: var(--radius-full);
  background: var(--color-primary-muted);
  color: var(--color-primary-text);
  font-size: 11px;
  font-weight: 700;
  display: flex;
  align-items: center;
  justify-content: center;
}

.topbar-username { font-weight: 500; }

.user-dropdown { min-width: 240px; }

.user-dropdown-header {
  padding: 14px 16px;
  border-bottom: 1px solid var(--bg-border);
}
.user-dropdown-name { font-size: 13px; font-weight: 600; color: var(--text-primary); }
.user-dropdown-role { font-size: 11px; color: var(--color-primary-text); margin-top: 2px; }
.user-dropdown-email { font-size: 11px; color: var(--text-muted); margin-top: 1px; }

.dropdown-divider { border: none; border-top: 1px solid var(--bg-border); margin: 4px 0; }

.dropdown-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 16px;
  font-size: 13px;
  color: var(--text-secondary);
  cursor: pointer;
  transition: color var(--transition-fast), background var(--transition-fast);
  font-family: inherit;
  background: none;
  border: none;
  width: 100%;
  text-align: left;
  text-decoration: none;
}
.dropdown-item:hover { color: var(--text-primary); background: var(--bg-card-hover); }
.dropdown-item-danger { color: var(--color-danger) !important; }
.dropdown-item-danger:hover { background: var(--color-danger-muted) !important; }

@keyframes dropdown-in {
  from { opacity: 0; transform: translateY(-4px); }
  to   { opacity: 1; transform: translateY(0); }
}

/* ─── MAIN CONTENT ───────────────────────────────────────────────────────── */

.main-content {
  flex: 1;
  overflow-y: auto;
  padding: 28px 28px 48px;
}

/* ─── PAGE HEADER ────────────────────────────────────────────────────────── */

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

.page-header-left {}
.page-title { font-size: 22px; font-weight: 700; color: var(--text-primary); line-height: 1.2; }
.page-subtitle { font-size: 13px; color: var(--text-muted); margin-top: 4px; }
.page-header-actions { display: flex; align-items: center; gap: 8px; flex-shrink: 0; }

/* ─── STAT CARDS ─────────────────────────────────────────────────────────── */

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

.stat-card {
  background: var(--bg-card);
  border: 1px solid var(--bg-border);
  border-radius: var(--radius-xl);
  padding: 20px;
  transition: border-color var(--transition-fast), box-shadow var(--transition-fast);
}
.stat-card:hover { border-color: var(--bg-border-light); box-shadow: var(--shadow-sm); }

.stat-card-label { font-size: 12px; font-weight: 500; color: var(--text-muted); text-transform: uppercase; letter-spacing: 0.06em; }
.stat-card-value { font-size: 32px; font-weight: 700; color: var(--text-primary); line-height: 1.1; margin-top: 8px; }
.stat-card-sub { font-size: 12px; color: var(--text-muted); margin-top: 6px; }

.stat-card-trend { display: flex; align-items: center; gap: 4px; font-size: 12px; margin-top: 6px; }
.trend-up { color: var(--color-success); }
.trend-down { color: var(--color-danger); }
.trend-neutral { color: var(--text-muted); }

.stat-card-icon {
  width: 36px;
  height: 36px;
  border-radius: var(--radius-lg);
  display: flex;
  align-items: center;
  justify-content: center;
  margin-bottom: 12px;
}
.stat-icon-green  { background: var(--color-success-muted); color: var(--color-primary-text); }
.stat-icon-blue   { background: var(--color-info-muted);    color: #60a5fa; }
.stat-icon-amber  { background: var(--color-warning-muted); color: #fbbf24; }
.stat-icon-red    { background: var(--color-danger-muted);  color: #f87171; }
.stat-icon-purple { background: rgba(168,85,247,0.12);      color: var(--color-purple); }

/* ─── CARDS ──────────────────────────────────────────────────────────────── */

.card {
  background: var(--bg-card);
  border: 1px solid var(--bg-border);
  border-radius: var(--radius-xl);
  overflow: hidden;
}

.card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 20px;
  border-bottom: 1px solid var(--bg-border);
}

.card-title { font-size: 14px; font-weight: 600; color: var(--text-primary); }
.card-subtitle { font-size: 12px; color: var(--text-muted); margin-top: 2px; }
.card-body { padding: 20px; }
.card-footer {
  padding: 12px 20px;
  border-top: 1px solid var(--bg-border);
  background: var(--bg-secondary);
  font-size: 12px;
  color: var(--text-muted);
}

/* ─── BUTTONS ────────────────────────────────────────────────────────────── */

.btn {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  padding: 8px 16px;
  font-size: 13px;
  font-weight: 500;
  font-family: inherit;
  border-radius: var(--radius-md);
  border: 1px solid transparent;
  cursor: pointer;
  transition: background var(--transition-fast), color var(--transition-fast), border-color var(--transition-fast), box-shadow var(--transition-fast);
  text-decoration: none;
  white-space: nowrap;
  line-height: 1;
}

.btn-sm { padding: 6px 12px; font-size: 12px; }
.btn-lg { padding: 10px 20px; font-size: 14px; }

.btn-primary {
  background: var(--color-primary);
  color: #fff;
  border-color: var(--color-primary);
}
.btn-primary:hover { background: var(--color-primary-hover); border-color: var(--color-primary-hover); }
.btn-primary:active { background: var(--color-primary-active); }
.btn-primary:focus { box-shadow: var(--shadow-primary-glow); }

.btn-secondary {
  background: var(--bg-card);
  color: var(--text-secondary);
  border-color: var(--bg-border-light);
}
.btn-secondary:hover { background: var(--bg-card-hover); color: var(--text-primary); border-color: var(--text-muted); }

.btn-danger {
  background: var(--color-danger);
  color: #fff;
  border-color: var(--color-danger);
}
.btn-danger:hover { background: #dc2626; }
.btn-danger:focus { box-shadow: var(--shadow-danger-glow); }

.btn-ghost {
  background: transparent;
  color: var(--text-secondary);
  border-color: transparent;
}
.btn-ghost:hover { background: var(--bg-card-hover); color: var(--text-primary); }

.btn-icon {
  padding: 7px;
  border-radius: var(--radius-md);
}

.btn:disabled, .btn[disabled] {
  opacity: 0.4;
  cursor: not-allowed;
  pointer-events: none;
}

/* ─── FORMS ──────────────────────────────────────────────────────────────── */

.form-group { margin-bottom: 20px; }

.form-label {
  display: block;
  font-size: 12.5px;
  font-weight: 500;
  color: var(--text-secondary);
  margin-bottom: 6px;
}

.form-label-required::after { content: ' *'; color: var(--color-danger); }

.form-control {
  width: 100%;
  background: var(--bg-card);
  border: 1px solid var(--bg-border-light);
  border-radius: var(--radius-md);
  padding: 9px 12px;
  font-size: 13px;
  font-family: inherit;
  color: var(--text-primary);
  transition: border-color var(--transition-fast), box-shadow var(--transition-fast);
  outline: none;
}

.form-control::placeholder { color: var(--text-muted); }
.form-control:focus { border-color: var(--color-primary); box-shadow: var(--shadow-primary-glow); }
.form-control:disabled { opacity: 0.5; cursor: not-allowed; }
.form-control.is-invalid { border-color: var(--color-danger); }
.form-control.is-invalid:focus { box-shadow: var(--shadow-danger-glow); }

.form-select {
  appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 24 24' fill='none' stroke='%2364748b' stroke-width='2'%3E%3Cpolyline points='6,9 12,15 18,9'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 12px center;
  padding-right: 36px;
  cursor: pointer;
}

.form-hint { font-size: 11.5px; color: var(--text-muted); margin-top: 5px; }
.form-error { font-size: 11.5px; color: var(--color-danger); margin-top: 5px; }

.form-row { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 16px; }
.form-row-2 { grid-template-columns: 1fr 1fr; }
.form-row-3 { grid-template-columns: 1fr 1fr 1fr; }

/* ─── TABLES ─────────────────────────────────────────────────────────────── */

.table-wrap { overflow-x: auto; }

.table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}

.table th {
  text-align: left;
  padding: 10px 16px;
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-muted);
  background: var(--bg-secondary);
  border-bottom: 1px solid var(--bg-border);
  white-space: nowrap;
}

.table td {
  padding: 12px 16px;
  border-bottom: 1px solid var(--bg-border);
  color: var(--text-secondary);
  vertical-align: middle;
}

.table tr:last-child td { border-bottom: none; }
.table tr:hover td { background: var(--bg-card-hover); }
.table td strong { color: var(--text-primary); font-weight: 500; }

.table-sortable th { cursor: pointer; user-select: none; }
.table-sortable th:hover { color: var(--text-secondary); }

/* ─── BADGES ─────────────────────────────────────────────────────────────── */

.badge {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 3px 8px;
  border-radius: var(--radius-full);
  font-size: 11px;
  font-weight: 500;
  white-space: nowrap;
  border: 1px solid transparent;
}

.badge-success { background: var(--color-success-muted); color: var(--color-primary-text); border-color: rgba(34,197,94,0.2); }
.badge-warning { background: var(--color-warning-muted); color: #fbbf24; border-color: rgba(245,158,11,0.2); }
.badge-danger  { background: var(--color-danger-muted);  color: #f87171; border-color: rgba(239,68,68,0.2); }
.badge-info    { background: var(--color-info-muted);    color: #60a5fa; border-color: rgba(59,130,246,0.2); }
.badge-neutral { background: var(--bg-border);           color: var(--text-muted); }
.badge-purple  { background: rgba(168,85,247,0.12);      color: var(--color-purple); }

/* ─── ALERTS ─────────────────────────────────────────────────────────────── */

.alert {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  padding: 12px 16px;
  border-radius: var(--radius-lg);
  font-size: 13px;
  margin-bottom: 16px;
  border: 1px solid transparent;
}

.alert-success { background: var(--color-success-muted); color: var(--color-primary-text); border-color: rgba(34,197,94,0.2); }
.alert-danger  { background: var(--color-danger-muted);  color: #f87171; border-color: rgba(239,68,68,0.2); }
.alert-warning { background: var(--color-warning-muted); color: #fbbf24; border-color: rgba(245,158,11,0.2); }
.alert-info    { background: var(--color-info-muted);    color: #60a5fa; border-color: rgba(59,130,246,0.2); }

/* ─── TOAST NOTIFICATIONS ────────────────────────────────────────────────── */

.flash-container {
  position: fixed;
  top: 72px;
  right: 20px;
  z-index: 9999;
  display: flex;
  flex-direction: column;
  gap: 8px;
  max-width: 380px;
}

.toast {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 12px 16px;
  border-radius: var(--radius-lg);
  font-size: 13px;
  font-weight: 500;
  box-shadow: var(--shadow-lg);
  border: 1px solid transparent;
  animation: toast-in 250ms ease;
  cursor: pointer;
}

.toast-success { background: #052e16; color: #4ade80; border-color: rgba(34,197,94,0.3); }
.toast-danger  { background: #450a0a; color: #fca5a5; border-color: rgba(239,68,68,0.3); }
.toast-info    { background: #0c1a3a; color: #93c5fd; border-color: rgba(59,130,246,0.3); }
.toast-warning { background: #451a03; color: #fcd34d; border-color: rgba(245,158,11,0.3); }

@keyframes toast-in {
  from { opacity: 0; transform: translateX(20px); }
  to   { opacity: 1; transform: translateX(0); }
}

/* ─── MODALS ─────────────────────────────────────────────────────────────── */

.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.7);
  backdrop-filter: blur(4px);
  z-index: 900;
  display: flex;
  align-items: center;
  justify-content: center;
  animation: fade-in 150ms ease;
}

.modal {
  background: var(--bg-elevated);
  border: 1px solid var(--bg-border-light);
  border-radius: var(--radius-xl);
  box-shadow: var(--shadow-xl);
  width: 90%;
  max-width: 520px;
  max-height: 90vh;
  display: flex;
  flex-direction: column;
  animation: modal-in 200ms ease;
}

.modal-lg { max-width: 720px; }
.modal-sm { max-width: 360px; }

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 18px 24px 16px;
  border-bottom: 1px solid var(--bg-border);
}

.modal-title { font-size: 15px; font-weight: 600; color: var(--text-primary); }

.modal-close {
  background: none;
  border: none;
  cursor: pointer;
  color: var(--text-muted);
  padding: 4px;
  border-radius: var(--radius-md);
  transition: color var(--transition-fast);
}
.modal-close:hover { color: var(--text-primary); }

.modal-body { padding: 20px 24px; overflow-y: auto; flex: 1; }
.modal-footer {
  padding: 14px 24px;
  border-top: 1px solid var(--bg-border);
  display: flex;
  justify-content: flex-end;
  gap: 8px;
}

@keyframes modal-in {
  from { opacity: 0; transform: scale(0.97) translateY(-8px); }
  to   { opacity: 1; transform: scale(1) translateY(0); }
}

@keyframes fade-in {
  from { opacity: 0; }
  to   { opacity: 1; }
}

/* ─── PAGINATION ─────────────────────────────────────────────────────────── */

.pagination {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 14px 20px;
  border-top: 1px solid var(--bg-border);
  font-size: 12.5px;
  color: var(--text-muted);
}

.pagination-pages { display: flex; gap: 4px; }

.page-btn {
  min-width: 30px;
  height: 30px;
  padding: 0 8px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: var(--radius-md);
  background: none;
  border: 1px solid transparent;
  cursor: pointer;
  font-size: 12px;
  font-family: inherit;
  color: var(--text-secondary);
  transition: background var(--transition-fast), color var(--transition-fast);
  text-decoration: none;
}
.page-btn:hover { background: var(--bg-card-hover); color: var(--text-primary); }
.page-btn-active { background: var(--color-primary-muted) !important; color: var(--color-primary-text) !important; border-color: rgba(34,197,94,0.2) !important; font-weight: 600; }
.page-btn:disabled { opacity: 0.4; cursor: not-allowed; }

/* ─── SEARCH MODAL ───────────────────────────────────────────────────────── */

.search-modal[hidden] { display: none !important; }

.search-modal {
  position: fixed;
  inset: 0;
  z-index: 9000;
  display: flex;
  align-items: flex-start;
  justify-content: center;
  padding-top: 80px;
}

.search-modal-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(0,0,0,0.6);
  backdrop-filter: blur(4px);
}

.search-modal-panel {
  position: relative;
  width: 90%;
  max-width: 580px;
  background: var(--bg-elevated);
  border: 1px solid var(--bg-border-light);
  border-radius: var(--radius-xl);
  box-shadow: var(--shadow-lg);
  overflow: hidden;
  animation: modal-in 200ms ease;
}

.search-modal-input-wrap {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 14px 18px;
  border-bottom: 1px solid var(--bg-border);
  color: var(--text-muted);
}

.search-modal-input {
  flex: 1;
  background: none;
  border: none;
  outline: none;
  font-size: 15px;
  font-family: inherit;
  color: var(--text-primary);
}
.search-modal-input::placeholder { color: var(--text-muted); }

.search-esc-key {
  font-size: 10px;
  background: var(--bg-border);
  border-radius: 3px;
  padding: 2px 6px;
  color: var(--text-muted);
  font-family: inherit;
}

.search-modal-results { padding: 8px; max-height: 400px; overflow-y: auto; }

.search-placeholder { padding: 24px; text-align: center; color: var(--text-muted); }
.search-placeholder p { font-size: 13px; }
.search-hint { margin-top: 8px; font-size: 12px; }
.search-hint kbd { background: var(--bg-border); border-radius: 3px; padding: 2px 5px; font-family: inherit; font-size: 10px; margin: 0 2px; }

/* ─── EMPTY STATE ────────────────────────────────────────────────────────── */

.empty-state {
  text-align: center;
  padding: 60px 20px;
  color: var(--text-muted);
}

.empty-state-icon {
  width: 48px;
  height: 48px;
  margin: 0 auto 16px;
  background: var(--bg-border);
  border-radius: var(--radius-xl);
  display: flex;
  align-items: center;
  justify-content: center;
}

.empty-state-title { font-size: 15px; font-weight: 600; color: var(--text-secondary); margin-bottom: 8px; }
.empty-state-text  { font-size: 13px; color: var(--text-muted); margin-bottom: 20px; }

/* ─── SKELETON LOADERS ───────────────────────────────────────────────────── */

@keyframes skeleton-pulse {
  0%, 100% { opacity: 1; }
  50%       { opacity: 0.4; }
}

.skeleton {
  background: var(--bg-border);
  border-radius: var(--radius-md);
  animation: skeleton-pulse 1.5s ease-in-out infinite;
}

.skeleton-text { height: 14px; }
.skeleton-title { height: 20px; }
.skeleton-avatar { width: 36px; height: 36px; border-radius: var(--radius-full); }
.skeleton-card { height: 120px; border-radius: var(--radius-xl); }

/* ─── FILTER BAR ─────────────────────────────────────────────────────────── */

.filter-bar {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 16px;
  flex-wrap: wrap;
}

.filter-bar .form-control { max-width: 280px; }

.filter-chips { display: flex; gap: 6px; flex-wrap: wrap; }

.filter-chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 4px 10px;
  background: var(--color-primary-muted);
  color: var(--color-primary-text);
  border-radius: var(--radius-full);
  font-size: 12px;
  font-weight: 500;
}

.filter-chip-remove {
  background: none;
  border: none;
  cursor: pointer;
  color: inherit;
  opacity: 0.6;
  padding: 0;
  font-size: 14px;
  line-height: 1;
}
.filter-chip-remove:hover { opacity: 1; }

/* ─── AUTH LAYOUT ────────────────────────────────────────────────────────── */

.auth-body {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--bg-base);
  background-image:
    radial-gradient(ellipse at 20% 50%, rgba(34,197,94,0.03) 0%, transparent 60%),
    radial-gradient(ellipse at 80% 20%, rgba(59,130,246,0.03) 0%, transparent 60%);
  padding: 24px;
}

.auth-container {
  width: 100%;
  max-width: 380px;
}

.auth-brand {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 32px;
}

.auth-brand-text { display: flex; flex-direction: column; }
.auth-brand-name { font-size: 16px; font-weight: 700; color: var(--text-primary); }
.auth-brand-tagline { font-size: 11px; color: var(--text-muted); }

.auth-card {
  background: var(--bg-card);
  border: 1px solid var(--bg-border);
  border-radius: var(--radius-xl);
  padding: 28px;
  box-shadow: var(--shadow-md);
}

.auth-card-title { font-size: 18px; font-weight: 700; color: var(--text-primary); margin-bottom: 4px; }
.auth-card-subtitle { font-size: 13px; color: var(--text-muted); margin-bottom: 24px; }

.auth-footer { text-align: center; font-size: 12px; color: var(--text-muted); margin-top: 20px; }

/* ─── TIMELINE (for animal events) ──────────────────────────────────────── */

.timeline { display: flex; flex-direction: column; gap: 0; position: relative; }
.timeline::before {
  content: '';
  position: absolute;
  left: 15px;
  top: 20px;
  bottom: 20px;
  width: 1px;
  background: var(--bg-border);
}

.timeline-item {
  display: flex;
  gap: 16px;
  padding: 12px 0;
  position: relative;
}

.timeline-dot {
  width: 30px;
  height: 30px;
  border-radius: var(--radius-full);
  border: 2px solid var(--bg-border);
  background: var(--bg-card);
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  z-index: 1;
}

.timeline-content { flex: 1; min-width: 0; padding-top: 4px; }
.timeline-title { font-size: 13px; font-weight: 500; color: var(--text-primary); }
.timeline-meta { font-size: 12px; color: var(--text-muted); margin-top: 2px; }
.timeline-body { font-size: 12.5px; color: var(--text-secondary); margin-top: 6px; }

/* ─── CHART WRAPPERS ─────────────────────────────────────────────────────── */

.chart-wrap { position: relative; }
.chart-wrap canvas { max-width: 100%; }

/* ─── UTILITIES ──────────────────────────────────────────────────────────── */

.text-primary   { color: var(--text-primary); }
.text-secondary { color: var(--text-secondary); }
.text-muted     { color: var(--text-muted); }
.text-success   { color: var(--color-primary-text); }
.text-danger    { color: var(--color-danger); }
.text-warning   { color: var(--color-warning); }
.text-info      { color: var(--color-info); }

.font-medium   { font-weight: 500; }
.font-semibold { font-weight: 600; }
.font-bold     { font-weight: 700; }

.text-xs  { font-size: 11px; }
.text-sm  { font-size: 12.5px; }
.text-base{ font-size: 15px; }
.text-lg  { font-size: 17px; }
.text-xl  { font-size: 20px; }
.text-2xl { font-size: 24px; }

.flex { display: flex; }
.flex-1 { flex: 1; }
.items-center { align-items: center; }
.justify-between { justify-content: space-between; }
.gap-2 { gap: 8px; }
.gap-3 { gap: 12px; }
.gap-4 { gap: 16px; }

.mt-1 { margin-top: 4px; }
.mt-2 { margin-top: 8px; }
.mt-4 { margin-top: 16px; }
.mt-6 { margin-top: 24px; }
.mb-4 { margin-bottom: 16px; }
.mb-6 { margin-bottom: 24px; }

.w-full { width: 100%; }

.truncate { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

.divider { border: none; border-top: 1px solid var(--bg-border); margin: 16px 0; }

.section-title {
  font-size: 13px;
  font-weight: 600;
  color: var(--text-secondary);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  margin-bottom: 12px;
}

/* ─── RESPONSIVE ─────────────────────────────────────────────────────────── */

@media (max-width: 1023px) {
  .sidebar {
    position: fixed;
    left: -260px;
    z-index: 200;
    transition: left var(--transition-base);
  }
  .sidebar.mobile-open { left: 0; }
  .app-layout { margin-left: 0; }
  .main-content { padding: 16px; }
}

@media (max-width: 767px) {
  .stat-grid { grid-template-columns: 1fr 1fr; }
  .form-row-2, .form-row-3 { grid-template-columns: 1fr; }
  .page-header { flex-direction: column; align-items: flex-start; }
  .topbar-search-btn { display: none; }
  .topbar-username { display: none; }
}

@media (max-width: 479px) {
  .stat-grid { grid-template-columns: 1fr; }
  .pagination { flex-direction: column; gap: 8px; }
}
