/* ═══════════════════════════════════════════════
   AGROTRACK — DESIGN SYSTEM
   Agronómico Futurista Corporativo (Alma Campesina)
   ═══════════════════════════════════════════════ */

:root {
  --void: #060a06;
  --void-deep: #020402;
  --soil: #0d1408;
  --surface: #0f1a0c;
  --surface-alt: #111d0e;
  --card-bg: rgba(10, 22, 8, 0.75);
  --card-border: rgba(0, 255, 136, 0.12);

  --emerald: #00ff88;
  --emerald-dim: #00cc66;
  --emerald-glow: rgba(0, 255, 136, 0.35);
  --emerald-soft: rgba(0, 255, 136, 0.08);

  --gold: #f5a623;
  --gold-dim: #d4891a;
  --gold-glow: rgba(245, 166, 35, 0.35);

  --cyan: #00e5ff;
  --cyan-dim: #00b8d4;
  --cyan-glow: rgba(0, 229, 255, 0.35);

  --success: #00ff88;
  --warning: #ffab00;
  --danger: #ff3d57;
  --info: #00b8ff;

  --text-primary: #f0f4f0;
  --text-secondary: #889688;
  --text-muted: #5a6a58;
  --text-inverse: #060a06;

  --font-sans: 'Inter', system-ui, -apple-system, sans-serif;
  --font-mono: 'JetBrains Mono', ui-monospace, monospace;

  --space-xs: 4px; --space-sm: 8px; --space-md: 16px;
  --space-lg: 24px; --space-xl: 32px; --space-2xl: 48px;

  --radius-sm: 2px; --radius-md: 6px; --radius-lg: 12px;

  --shadow-card: 0 1px 0 rgba(0,255,136,0.10), 0 4px 24px rgba(0,0,0,0.4);
  --shadow-glow: 0 0 30px var(--emerald-glow);
  --shadow-cyan: 0 0 20px var(--cyan-glow);

  --ease-out: cubic-bezier(0.16, 1, 0.3, 1);
  --ease-spring: cubic-bezier(0.34, 1.56, 0.64, 1);
}

*, *::before, *::after { margin: 0; padding: 0; box-sizing: border-box; }
html { font-size: 16px; scroll-behavior: smooth; }
body {
  font-family: var(--font-sans);
  background: var(--void);
  color: var(--text-primary);
  line-height: 1.5;
  overflow-x: hidden;
  -webkit-font-smoothing: antialiased;
}

#particle-canvas {
  position: fixed; top: 0; left: 0;
  width: 100%; height: 100%;
  pointer-events: none; z-index: 0;
}

.scanline-overlay {
  position: fixed; inset: 0;
  pointer-events: none; z-index: 1;
  background: repeating-linear-gradient(
    0deg, transparent, transparent 2px,
    rgba(0,0,0,0.03) 2px, rgba(0,0,0,0.03) 4px);
}

.scan-line {
  position: fixed; top: 0; left: 0;
  width: 100%; height: 2px;
  background: linear-gradient(90deg, transparent,
    rgba(0,255,136,0.15) 20%, rgba(0,255,136,0.35) 50%,
    rgba(0,255,136,0.15) 80%, transparent);
  pointer-events: none; z-index: 2;
  animation: scanDown 6s linear infinite;
}
@keyframes scanDown {
  0% { top: -2px; }
  100% { top: 100%; }
}

.app-container {
  position: relative;
  z-index: 10;
  display: flex;
  min-height: 100vh;
}

.sidebar {
  width: 260px;
  min-width: 260px;
  background: rgba(4, 10, 4, 0.85);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  border-right: 1px solid var(--card-border);
  display: flex;
  flex-direction: column;
  padding: var(--space-lg);
  position: sticky;
  top: 0; height: 100vh;
  z-index: 20;
}

.sidebar-logo {
  display: flex; align-items: center; gap: var(--space-sm);
  margin-bottom: var(--space-xl);
  padding-bottom: var(--space-lg);
  border-bottom: 1px solid var(--card-border);
}
.logo-icon {
  width: 36px; height: 36px;
  border-radius: var(--radius-md);
  background: linear-gradient(135deg, var(--emerald), #00aa55);
  display: flex; align-items: center; justify-content: center;
  font-size: 18px;
  box-shadow: 0 0 20px var(--emerald-glow);
  animation: logoPulse 3s ease-in-out infinite;
}
@keyframes logoPulse {
  0%, 100% { box-shadow: 0 0 20px var(--emerald-glow); }
  50% { box-shadow: 0 0 35px rgba(0,255,136,0.55); }
}
.logo-text {
  font-family: var(--font-mono);
  font-size: 18px; font-weight: 700;
  letter-spacing: -0.5px;
  color: var(--text-primary);
}
.logo-text span { color: var(--emerald); }

.sidebar-nav {
  display: flex; flex-direction: column;
  gap: var(--space-xs);
  flex: 1;
}

.nav-item {
  display: flex; align-items: center;
  gap: var(--space-sm);
  padding: 10px 12px;
  border-radius: var(--radius-md);
  font-size: 14px; font-weight: 500;
  color: var(--text-secondary);
  cursor: pointer;
  transition: all 0.2s var(--ease-out);
  border: 1px solid transparent;
  text-decoration: none;
  position: relative;
}
.nav-item:hover {
  color: var(--text-primary);
  background: var(--emerald-soft);
}
.nav-item.active {
  color: var(--emerald);
  background: var(--emerald-soft);
  border-color: rgba(0, 255, 136, 0.2);
  box-shadow: inset 0 0 20px rgba(0, 255, 136, 0.04);
}
.nav-item.active::before {
  content: '';
  position: absolute;
  left: -4px; top: 50%;
  transform: translateY(-50%);
  width: 3px; height: 20px;
  background: var(--emerald);
  border-radius: 3px;
  box-shadow: 0 0 10px var(--emerald-glow);
}
.nav-icon { font-size: 18px; width: 22px; text-align: center; flex-shrink: 0; }
.nav-badge {
  margin-left: auto;
  font-size: 11px; font-weight: 600;
  padding: 2px 8px;
  border-radius: 10px;
  background: var(--emerald-soft);
  color: var(--emerald);
  font-family: var(--font-mono);
}

.sidebar-footer {
  margin-top: auto;
  padding-top: var(--space-lg);
  border-top: 1px solid var(--card-border);
  font-size: 12px;
  color: var(--text-muted);
}
.status-indicator {
  display: flex; align-items: center;
  gap: 6px;
  margin-bottom: var(--space-sm);
}
.status-dot {
  width: 8px; height: 8px;
  border-radius: 50%;
  background: var(--emerald);
  box-shadow: 0 0 8px var(--emerald-glow);
  animation: statusPulse 2s ease-in-out infinite;
}
@keyframes statusPulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.4; }
}

.main-content {
  flex: 1;
  padding: var(--space-xl);
  overflow-y: auto;
  max-height: 100vh;
}

.topbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: var(--space-xl);
}
.page-title-section h1 {
  font-size: 28px; font-weight: 800;
  letter-spacing: -0.5px;
  color: var(--text-primary);
  margin-bottom: 2px;
}
.page-title-section .subtitle {
  font-size: 13px;
  color: var(--text-muted);
  font-family: var(--font-mono);
  letter-spacing: 0.5px;
}
.topbar-actions {
  display: flex; align-items: center; gap: var(--space-md);
}

.btn {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 9px 18px;
  border-radius: var(--radius-md);
  font-size: 14px; font-weight: 600;
  font-family: var(--font-sans);
  cursor: pointer;
  transition: all 0.2s var(--ease-out);
  border: 1px solid transparent;
  text-decoration: none;
  white-space: nowrap;
}
.btn-primary {
  background: var(--emerald);
  color: var(--text-inverse);
  border-color: var(--emerald);
  box-shadow: 0 0 20px rgba(0,255,136,0.2);
}
.btn-primary:hover {
  box-shadow: 0 0 35px rgba(0,255,136,0.4);
  transform: translateY(-1px);
}
.btn-ghost {
  background: transparent;
  color: var(--text-secondary);
  border-color: var(--card-border);
}
.btn-ghost:hover {
  color: var(--text-primary);
  border-color: rgba(0,255,136,0.25);
  background: var(--emerald-soft);
}
.btn-sm { padding: 5px 12px; font-size: 12px; }
.btn-danger {
  background: transparent;
  color: var(--danger);
  border-color: rgba(255,61,87,0.3);
}
.btn-danger:hover {
  background: rgba(255,61,87,0.1);
  border-color: var(--danger);
}

.htmx-indicator { display: none; }
.htmx-request .htmx-indicator { display: inline-block; }

.stats-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: var(--space-md);
  margin-bottom: var(--space-xl);
}
.stat-card {
  background: var(--card-bg);
  backdrop-filter: blur(12px);
  border: 1px solid var(--card-border);
  border-radius: var(--radius-lg);
  padding: var(--space-lg);
  position: relative;
  overflow: hidden;
  transition: all 0.3s var(--ease-out);
}
.stat-card:hover {
  border-color: rgba(0,255,136,0.25);
  box-shadow: var(--shadow-card);
  transform: translateY(-2px);
}
.stat-card-header {
  display: flex; justify-content: space-between; align-items: center;
  margin-bottom: var(--space-sm);
}
.stat-card-label {
  font-size: 12px; font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 1px;
  color: var(--text-muted);
}
.stat-card-icon { font-size: 20px; }
.stat-card-value {
  font-size: 36px; font-weight: 800;
  letter-spacing: -1px;
  font-family: var(--font-mono);
  background: linear-gradient(180deg, var(--text-primary) 0%, var(--text-secondary) 100%);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}
.stat-card-change {
  display: flex; align-items: center; gap: 4px;
  font-size: 12px; font-weight: 500;
  margin-top: var(--space-xs);
}
.stat-card-change.up { color: var(--emerald); }
.stat-card-change.down { color: var(--danger); }

.section-panel {
  background: var(--card-bg);
  backdrop-filter: blur(12px);
  border: 1px solid var(--card-border);
  border-radius: var(--radius-lg);
  margin-bottom: var(--space-lg);
  overflow: hidden;
}
.section-header {
  display: flex; justify-content: space-between; align-items: center;
  padding: var(--space-lg);
  border-bottom: 1px solid var(--card-border);
}
.section-header h2 {
  font-size: 18px; font-weight: 700;
  letter-spacing: -0.3px;
}
.section-header-actions { display: flex; gap: var(--space-sm); }
.section-body { padding: var(--space-lg); overflow-x: auto; }

.holo-table {
  width: 100%; border-collapse: collapse;
  font-size: 13px;
}
.holo-table thead th {
  text-align: left;
  padding: 10px 14px;
  font-size: 11px; font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 1px;
  color: var(--text-muted);
  border-bottom: 1px solid var(--card-border);
  white-space: nowrap;
}
.holo-table tbody td {
  padding: 12px 14px;
  border-bottom: 1px solid rgba(255,255,255,0.03);
  color: var(--text-secondary);
  transition: background 0.2s var(--ease-out);
}
.holo-table tbody tr:hover { background: var(--emerald-soft); }
.holo-table tbody tr:hover td { color: var(--text-primary); }
.holo-table .mono {
  font-family: var(--font-mono);
  font-size: 12px;
}

.badge {
  display: inline-flex; align-items: center; gap: 5px;
  padding: 3px 10px;
  border-radius: 20px;
  font-size: 11px; font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}
.badge::before {
  content: '';
  width: 6px; height: 6px;
  border-radius: 50%;
}
.badge-success {
  background: rgba(0, 255, 136, 0.1);
  color: var(--emerald);
}
.badge-success::before { background: var(--emerald); box-shadow: 0 0 6px var(--emerald-glow); }
.badge-warning {
  background: rgba(255, 171, 0, 0.1);
  color: var(--warning);
}
.badge-warning::before { background: var(--warning); }
.badge-danger {
  background: rgba(255, 61, 87, 0.1);
  color: var(--danger);
}
.badge-danger::before { background: var(--danger); }
.badge-info {
  background: rgba(0, 184, 255, 0.1);
  color: var(--info);
}
.badge-info::before { background: var(--info); }
.badge-cyan {
  background: rgba(0, 229, 255, 0.1);
  color: var(--cyan);
}
.badge-cyan::before { background: var(--cyan); }

.card-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: var(--space-md);
}
.holo-card {
  background: var(--card-bg);
  backdrop-filter: blur(12px);
  border: 1px solid var(--card-border);
  border-radius: var(--radius-lg);
  padding: var(--space-lg);
  transition: all 0.3s var(--ease-out);
}
.holo-card:hover {
  border-color: rgba(0,255,136,0.25);
  box-shadow: var(--shadow-card);
  transform: translateY(-2px);
}
.holo-card-top {
  display: flex; justify-content: space-between; align-items: flex-start;
  margin-bottom: var(--space-md);
}
.holo-card-id {
  font-family: var(--font-mono);
  font-size: 11px;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 1px;
}
.holo-card-title {
  font-size: 16px; font-weight: 700;
  margin-bottom: 4px;
  color: var(--text-primary);
}
.holo-card-subtitle {
  font-size: 12px; color: var(--text-muted);
  font-family: var(--font-mono);
}
.holo-card-details {
  display: flex; flex-direction: column;
  gap: 8px;
  margin-top: var(--space-md);
  padding-top: var(--space-md);
  border-top: 1px solid var(--card-border);
}
.holo-card-row {
  display: flex; justify-content: space-between;
  font-size: 13px;
}
.holo-card-row .label { color: var(--text-muted); }
.holo-card-row .value {
  font-weight: 600;
  font-family: var(--font-mono);
  font-size: 12px;
}

.progress-bar-wrap {
  height: 6px;
  background: rgba(255,255,255,0.04);
  border-radius: 3px;
  overflow: hidden;
  margin-top: 6px;
}
.progress-bar-fill {
  height: 100%;
  border-radius: 3px;
  transition: width 0.8s var(--ease-spring);
  position: relative;
}
.progress-bar-fill::after {
  content: '';
  position: absolute;
  top: 0; left: 0; right: 0; bottom: 0;
  background: linear-gradient(90deg, transparent, rgba(255,255,255,0.3), transparent);
  animation: shimmer 2s ease-in-out infinite;
}
@keyframes shimmer {
  0% { transform: translateX(-100%); }
  100% { transform: translateX(100%); }
}
.progress-green  { background: linear-gradient(90deg, var(--emerald-dim), var(--emerald)); }
.progress-gold   { background: linear-gradient(90deg, var(--gold-dim), var(--gold)); }
.progress-cyan   { background: linear-gradient(90deg, var(--cyan-dim), var(--cyan)); }
.progress-warn   { background: linear-gradient(90deg, #ff8c00, var(--warning)); }
.progress-danger { background: linear-gradient(90deg, #cc0033, var(--danger)); }

.activity-feed {
  display: flex; flex-direction: column;
}
.activity-item {
  display: flex; gap: var(--space-md);
  padding: 12px 0;
  border-bottom: 1px solid rgba(255,255,255,0.03);
}
.activity-item:last-child { border-bottom: none; }
.activity-dot {
  width: 10px; height: 10px;
  border-radius: 50%;
  margin-top: 4px;
  flex-shrink: 0;
  box-shadow: 0 0 8px var(--emerald-glow);
}
.activity-dot.green { background: var(--emerald); }
.activity-dot.cyan { background: var(--cyan); }
.activity-dot.gold { background: var(--gold); }
.activity-body { flex: 1; font-size: 13px; }
.activity-body .act-title {
  font-weight: 600;
  color: var(--text-primary);
  margin-bottom: 2px;
}
.activity-body .act-detail {
  color: var(--text-muted);
  font-size: 12px;
  font-family: var(--font-mono);
}

.flow-viz {
  display: flex; align-items: center;
  gap: var(--space-md);
  padding: var(--space-lg) 0;
  overflow-x: auto;
}
.flow-node { display: flex; flex-direction: column; align-items: center; gap: 6px; flex-shrink: 0; }
.flow-node-dot {
  width: 48px; height: 48px;
  border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  font-size: 20px; font-weight: 700;
  font-family: var(--font-mono);
  border: 2px solid;
}
.flow-node-dot.origin {
  background: rgba(0,255,136,0.1);
  border-color: var(--emerald);
  color: var(--emerald);
  box-shadow: 0 0 20px var(--emerald-glow);
}
.flow-node-dot.warehouse {
  background: rgba(0,229,255,0.1);
  border-color: var(--cyan);
  color: var(--cyan);
}
.flow-node-dot.destination {
  background: rgba(245,166,35,0.1);
  border-color: var(--gold);
  color: var(--gold);
}
.flow-node-label {
  font-size: 11px; color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 1px;
  font-weight: 600;
}
.flow-edge {
  width: 60px; height: 2px;
  position: relative;
  flex-shrink: 0;
}
.flow-edge::before {
  content: '';
  position: absolute;
  top: 0; left: 0; right: 0; bottom: 0;
  background: linear-gradient(90deg, var(--emerald), var(--cyan), var(--gold));
  animation: flowMove 1.5s linear infinite;
}
@keyframes flowMove {
  0% { background-position: 0% 50%; }
  100% { background-position: 200% 50%; }
}
.flow-edge::after {
  content: '▶';
  position: absolute;
  right: -6px; top: 50%;
  transform: translateY(-50%);
  font-size: 8px;
  color: var(--gold);
}

.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(2, 4, 2, 0.85);
  backdrop-filter: blur(8px);
  z-index: 100;
  display: none;
  align-items: center;
  justify-content: center;
}
.modal-overlay.open { display: flex; }
.modal {
  background: var(--surface);
  border: 1px solid var(--card-border);
  border-radius: var(--radius-lg);
  width: 90%;
  max-width: 720px;
  max-height: 85vh;
  overflow-y: auto;
  padding: var(--space-xl);
  box-shadow: 0 0 60px rgba(0,0,0,0.6);
  animation: modalIn 0.3s var(--ease-spring);
}
@keyframes modalIn {
  from { opacity: 0; transform: scale(0.92) translateY(20px); }
  to { opacity: 1; transform: scale(1) translateY(0); }
}
.modal h3 { font-size: 20px; font-weight: 700; margin-bottom: var(--space-lg); }

.form-group { margin-bottom: var(--space-md); }
.form-group label {
  display: block;
  font-size: 12px; font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 1px;
  color: var(--text-muted);
  margin-bottom: 6px;
}
.form-input {
  width: 100%;
  padding: 10px 14px;
  background: var(--void-deep);
  border: 1px solid var(--card-border);
  border-radius: var(--radius-md);
  color: var(--text-primary);
  font-family: var(--font-sans);
  font-size: 14px;
  transition: border-color 0.2s var(--ease-out);
  outline: none;
}
.form-input:focus {
  border-color: var(--emerald);
  box-shadow: 0 0 12px var(--emerald-soft);
}
.form-input::placeholder { color: var(--text-muted); }
select.form-input {
  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='%235a6a58' stroke-width='2'%3E%3Cpath d='M6 9l6 6 6-6'%3E%3C/path%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 12px center;
  padding-right: 36px;
}
.form-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: var(--space-md);
}
.modal-actions {
  display: flex; justify-content: flex-end;
  gap: var(--space-sm);
  margin-top: var(--space-xl);
}

.dual-panel {
  display: grid;
  grid-template-columns: 2fr 1fr;
  gap: var(--space-lg);
  margin-bottom: var(--space-lg);
}

@media (max-width: 1400px) {
  .stats-grid { grid-template-columns: repeat(2, 1fr); }
}
@media (max-width: 1024px) {
  .dual-panel { grid-template-columns: 1fr; }
}
@media (max-width: 900px) {
  .sidebar {
    width: 60px;
    min-width: 60px;
    padding: var(--space-md) var(--space-sm);
  }
  .sidebar .logo-text,
  .sidebar .sidebar-footer span { display: none; }
  .sidebar-logo { justify-content: center; }
  .nav-item { justify-content: center; padding: 10px 8px; }
  .nav-item span:not(.nav-icon) { display: none; }
  .nav-badge { display: none; }
  .main-content { padding: var(--space-md); }
  .stats-grid { grid-template-columns: 1fr 1fr; }
  .page-title-section h1 { font-size: 22px; }
}
@media (max-width: 600px) {
  .stats-grid { grid-template-columns: 1fr; }
  .topbar { flex-direction: column; align-items: flex-start; gap: var(--space-md); }
  .form-row { grid-template-columns: 1fr; }
}

::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb {
  background: rgba(0, 255, 136, 0.15);
  border-radius: 3px;
}
::-webkit-scrollbar-thumb:hover { background: rgba(0, 255, 136, 0.3); }

.messages {
  position: fixed;
  top: 20px; right: 20px;
  z-index: 200;
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.message {
  padding: 12px 18px;
  border-radius: var(--radius-md);
  background: var(--surface);
  border-left: 3px solid var(--emerald);
  color: var(--text-primary);
  font-size: 13px;
  box-shadow: var(--shadow-card);
  animation: msgIn 0.3s var(--ease-spring);
  max-width: 400px;
}
.message-error {
  border-left-color: var(--danger);
}
@keyframes msgIn {
  from { opacity: 0; transform: translateX(20px); }
  to { opacity: 1; transform: translateX(0); }
}

.glitch-hover {
  transition: text-shadow 0.2s;
}
.glitch-hover:hover {
  text-shadow: 0 0 8px var(--emerald-glow), 1px 0 rgba(0,255,136,0.4);
}

.filtros {
  display: flex;
  gap: var(--space-md);
  margin-bottom: var(--space-md);
  flex-wrap: wrap;
  align-items: end;
}
.filtros .form-group { margin-bottom: 0; min-width: 180px; }
.filtros .form-input { padding: 8px 12px; font-size: 13px; }

.actions-cell {
  display: flex;
  gap: 6px;
}

table form { display: inline; }
