/* ============================================================
   AgriTech Pro - Main Stylesheet
   Green theme, clean, fast-loading
   ============================================================ */

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

:root {
  --green-900: #064e3b;
  --green-800: #065f46;
  --green-700: #047857;
  --green-600: #059669;
  --green-500: #10b981;
  --green-100: #d1fae5;
  --green-50:  #f0fdf4;
  --red-600:   #dc2626;
  --red-100:   #fee2e2;
  --blue-600:  #2563eb;
  --blue-100:  #dbeafe;
  --yellow-500:#f59e0b;
  --yellow-100:#fef3c7;
  --gray-900:  #111827;
  --gray-700:  #374151;
  --gray-500:  #6b7280;
  --gray-200:  #e5e7eb;
  --gray-100:  #f3f4f6;
  --gray-50:   #f9fafb;
  --white:     #ffffff;
  --shadow-sm: 0 1px 3px rgba(0,0,0,0.08);
  --shadow-md: 0 2px 8px rgba(0,0,0,0.06);
  --shadow-lg: 0 8px 24px rgba(0,0,0,0.12);
  --radius-sm: 6px;
  --radius-md: 10px;
  --radius-lg: 14px;
  --font: 'Inter', system-ui, -apple-system, sans-serif;
}

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

body {
  font-family: var(--font);
  background: #f8fafc;
  color: var(--gray-900);
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

/* ============================================================
   LAYOUT
   ============================================================ */

.app-wrapper {
  display: flex;
  height: 100vh;
  overflow: hidden;
}

.sidebar {
  width: 220px;
  background: linear-gradient(180deg, var(--green-800) 0%, var(--green-700) 100%);
  color: white;
  display: flex;
  flex-direction: column;
  flex-shrink: 0;
  transition: width 0.28s ease;
  overflow: hidden;
}

.sidebar.collapsed { width: 60px; }

.sidebar-brand {
  padding: 16px 12px;
  border-bottom: 1px solid rgba(255,255,255,0.12);
  display: flex;
  align-items: center;
  justify-content: space-between;
  min-height: 58px;
}

.sidebar-brand-logo {
  display: flex;
  align-items: center;
  gap: 9px;
  overflow: hidden;
  white-space: nowrap;
}

.sidebar-brand-text {
  font-weight: 700;
  font-size: 14px;
  overflow: hidden;
  text-overflow: ellipsis;
  opacity: 1;
  transition: opacity 0.2s;
}

.collapsed .sidebar-brand-text { opacity: 0; width: 0; }

.sidebar-nav {
  flex: 1;
  padding: 10px 6px;
  overflow-y: auto;
  overflow-x: hidden;
}

.sidebar-nav::-webkit-scrollbar { width: 3px; }
.sidebar-nav::-webkit-scrollbar-thumb { background: rgba(255,255,255,0.2); border-radius: 2px; }

.nav-btn {
  width: 100%;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  background: transparent;
  border: none;
  color: rgba(255,255,255,0.85);
  border-radius: var(--radius-sm);
  cursor: pointer;
  font-size: 13px;
  font-weight: 400;
  font-family: var(--font);
  margin-bottom: 2px;
  transition: background 0.15s, color 0.15s;
  white-space: nowrap;
  overflow: hidden;
}

.nav-btn:hover { background: rgba(255,255,255,0.1); color: white; }
.nav-btn.active { background: rgba(255,255,255,0.2); color: white; font-weight: 600; }
.collapsed .nav-btn { justify-content: center; padding: 10px; }
.collapsed .nav-btn span { display: none; }

.main-panel {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

/* ============================================================
   TOPBAR
   ============================================================ */

.topbar {
  height: 56px;
  background: var(--white);
  border-bottom: 1px solid var(--gray-200);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 20px;
  flex-shrink: 0;
  gap: 12px;
}

.search-box {
  display: flex;
  align-items: center;
  gap: 8px;
  background: var(--gray-100);
  padding: 7px 12px;
  border-radius: var(--radius-sm);
  width: 200px;
}

.search-box input {
  border: none;
  background: transparent;
  outline: none;
  font-size: 13px;
  font-family: var(--font);
  color: var(--gray-700);
  width: 100%;
}

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

.lang-select {
  padding: 6px 10px;
  border: 1px solid var(--gray-200);
  border-radius: var(--radius-sm);
  font-size: 13px;
  font-family: var(--font);
  background: white;
  cursor: pointer;
}

.user-badge {
  display: flex;
  align-items: center;
  gap: 8px;
  padding-left: 14px;
  border-left: 1px solid var(--gray-200);
}

.user-avatar {
  width: 32px; height: 32px;
  border-radius: 8px;
  background: linear-gradient(135deg, var(--green-600), var(--green-700));
  display: flex; align-items: center; justify-content: center;
  flex-shrink: 0;
}

.user-info { line-height: 1.3; }
.user-name { font-weight: 600; font-size: 12px; }
.user-role { font-size: 11px; color: var(--gray-500); }

.logout-btn {
  display: flex; align-items: center; gap: 4px;
  padding: 6px 10px;
  background: var(--red-100);
  color: var(--red-600);
  border: none; border-radius: var(--radius-sm);
  font-size: 12px; font-weight: 600;
  cursor: pointer; font-family: var(--font);
  transition: opacity 0.15s;
}
.logout-btn:hover { opacity: 0.8; }

/* ============================================================
   CONTENT AREA
   ============================================================ */

.content {
  flex: 1;
  overflow-y: auto;
  overflow-x: hidden;
}

.content::-webkit-scrollbar { width: 5px; }
.content::-webkit-scrollbar-thumb { background: var(--gray-200); border-radius: 3px; }

.page { padding: 22px; }
.page-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 20px;
  flex-wrap: wrap;
  gap: 10px;
}

.page-title { font-size: 22px; font-weight: 800; }

/* ============================================================
   CARDS
   ============================================================ */

.card {
  background: var(--white);
  border-radius: var(--radius-lg);
  padding: 20px;
  box-shadow: var(--shadow-md);
}

.card + .card { margin-top: 16px; }

.stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(175px, 1fr));
  gap: 14px;
  margin-bottom: 22px;
}

.stat-card {
  background: var(--white);
  border-radius: var(--radius-lg);
  padding: 18px;
  box-shadow: var(--shadow-md);
  display: flex;
  align-items: center;
  gap: 14px;
}

.stat-icon {
  width: 44px; height: 44px;
  border-radius: 10px;
  display: flex; align-items: center; justify-content: center;
  flex-shrink: 0;
}

.stat-value { font-size: 22px; font-weight: 800; }
.stat-label { font-size: 12px; color: var(--gray-500); margin-top: 2px; }

/* ============================================================
   TABLES
   ============================================================ */

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

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

th {
  padding: 10px 12px;
  text-align: left;
  font-weight: 600;
  font-size: 12px;
  border-bottom: 2px solid var(--gray-200);
  background: var(--gray-50);
  white-space: nowrap;
}

td {
  padding: 10px 12px;
  border-bottom: 1px solid var(--gray-100);
  vertical-align: middle;
}

tr:last-child td { border-bottom: none; }
tr:hover td { background: #fafafa; }

.empty-row { text-align: center; padding: 32px; color: var(--gray-500); font-size: 13px; }

/* ============================================================
   BADGES
   ============================================================ */

.badge {
  display: inline-block;
  padding: 3px 9px;
  border-radius: 20px;
  font-size: 11px;
  font-weight: 600;
  white-space: nowrap;
}

.badge-green  { background: var(--green-100); color: #065f46; }
.badge-red    { background: var(--red-100);   color: var(--red-600); }
.badge-blue   { background: var(--blue-100);  color: var(--blue-600); }
.badge-yellow { background: var(--yellow-100); color: #92400e; }
.badge-gray   { background: var(--gray-100);  color: var(--gray-700); }

/* ============================================================
   BUTTONS
   ============================================================ */

.btn {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 9px 18px;
  border: none; border-radius: var(--radius-sm);
  font-size: 13px; font-weight: 600;
  font-family: var(--font);
  cursor: pointer;
  transition: opacity 0.15s, transform 0.1s;
  white-space: nowrap;
}

.btn:active { transform: scale(0.97); }
.btn:disabled { opacity: 0.55; cursor: not-allowed; }

.btn-primary {
  background: linear-gradient(135deg, var(--green-600), var(--green-700));
  color: white;
}

.btn-primary:hover { opacity: 0.9; }

.btn-secondary {
  background: var(--gray-100);
  color: var(--gray-700);
}

.btn-secondary:hover { background: var(--gray-200); }

.btn-danger {
  background: var(--red-100);
  color: var(--red-600);
}

.btn-icon {
  padding: 6px;
  background: var(--blue-100);
  color: var(--blue-600);
  border: none; border-radius: var(--radius-sm);
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  transition: opacity 0.15s;
}

.btn-icon:hover { opacity: 0.75; }
.btn-icon-red   { background: var(--red-100); color: var(--red-600); }
.btn-icon-green { background: var(--green-100); color: var(--green-700); }

.btn-group { display: flex; gap: 6px; }

/* ============================================================
   FORMS
   ============================================================ */

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

.form-label {
  display: block;
  font-size: 13px;
  font-weight: 500;
  margin-bottom: 5px;
  color: var(--gray-700);
}

.form-control {
  width: 100%;
  padding: 10px 12px;
  border: 2px solid var(--gray-200);
  border-radius: var(--radius-sm);
  font-size: 14px;
  font-family: var(--font);
  color: var(--gray-900);
  background: white;
  outline: none;
  transition: border-color 0.15s;
}

.form-control:focus { border-color: var(--green-500); }
.form-control:disabled { background: var(--gray-100); color: var(--gray-500); cursor: not-allowed; }
.form-control.readonly { background: var(--gray-50); color: var(--green-700); font-weight: 600; }

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

.form-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(175px, 1fr));
  gap: 12px;
}

.form-grid-2 { grid-template-columns: 1fr 1fr; }
.span-2 { grid-column: span 2; }

.form-error {
  background: var(--red-100);
  color: var(--red-600);
  padding: 10px 14px;
  border-radius: var(--radius-sm);
  margin-bottom: 14px;
  font-size: 13px;
  display: flex; align-items: center; gap: 6px;
}

.form-success {
  background: var(--green-50);
  color: #065f46;
  padding: 10px 14px;
  border-radius: var(--radius-sm);
  margin-bottom: 14px;
  font-size: 13px;
  display: flex; align-items: center; gap: 6px;
}

/* ============================================================
   MODAL
   ============================================================ */

.modal-overlay {
  position: fixed; inset: 0;
  background: rgba(0,0,0,0.48);
  display: flex; align-items: center; justify-content: center;
  z-index: 1000;
  padding: 20px;
  backdrop-filter: blur(2px);
}

.modal {
  background: white;
  border-radius: var(--radius-lg);
  width: 100%;
  max-width: 560px;
  max-height: 88vh;
  overflow: hidden;
  display: flex; flex-direction: column;
  box-shadow: var(--shadow-lg);
  animation: modal-in 0.18s ease;
}

.modal.modal-wide { max-width: 820px; }

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

.modal-header {
  display: flex; justify-content: space-between; align-items: center;
  padding: 14px 18px;
  border-bottom: 1px solid var(--gray-200);
  background: var(--gray-50);
  flex-shrink: 0;
}

.modal-title { font-size: 15px; font-weight: 700; }

.modal-close {
  background: var(--gray-200);
  border: none; border-radius: 5px;
  padding: 5px; cursor: pointer;
  display: flex; align-items: center;
  transition: background 0.15s;
}

.modal-close:hover { background: var(--gray-300); }

.modal-body {
  overflow-y: auto;
  flex: 1;
  padding: 18px;
}

.modal-footer {
  padding: 12px 18px;
  border-top: 1px solid var(--gray-200);
  display: flex; justify-content: flex-end; gap: 10px;
  flex-shrink: 0;
  background: var(--gray-50);
}

/* ============================================================
   LINE ITEMS (Sales, Purchases, Projections)
   ============================================================ */

.line-items-box {
  background: var(--green-50);
  border-radius: var(--radius-md);
  padding: 14px;
  margin: 14px 0;
}

.line-items-header {
  display: flex; justify-content: space-between; align-items: center;
  margin-bottom: 10px;
}

.line-items-label { font-weight: 600; font-size: 13px; color: #065f46; }

.line-item-row {
  display: grid;
  grid-template-columns: 2fr 52px 1fr 1fr 36px;
  gap: 6px;
  margin-bottom: 7px;
  align-items: center;
}

.line-item-row.purchases { grid-template-columns: 2fr 52px 1fr 1fr 36px; }

.line-items-total {
  text-align: right;
  padding-top: 10px;
  margin-top: 10px;
  border-top: 2px solid var(--green-100);
  font-size: 15px;
  font-weight: 800;
  color: #065f46;
}

/* ============================================================
   AUTH SCREEN
   ============================================================ */

.auth-wrapper {
  min-height: 100vh;
  display: flex; align-items: center; justify-content: center;
  background: linear-gradient(135deg, var(--green-800), var(--green-600));
  padding: 20px;
}

.auth-card {
  background: white;
  border-radius: 20px;
  width: 100%;
  max-width: 420px;
  overflow: hidden;
  box-shadow: 0 20px 60px rgba(0,0,0,0.25);
}

.auth-header {
  background: linear-gradient(135deg, var(--green-600), var(--green-700));
  padding: 30px;
  text-align: center;
  color: white;
}

.auth-logo { display: flex; align-items: center; justify-content: center; gap: 10px; margin-bottom: 6px; }
.auth-title { font-size: 26px; font-weight: 800; letter-spacing: -0.5px; }
.auth-subtitle { font-size: 13px; opacity: 0.88; }

.auth-body { padding: 26px; }
.auth-body h2 { text-align: center; margin-bottom: 20px; font-size: 18px; }

.auth-switch { text-align: center; margin-top: 18px; font-size: 13px; }
.auth-switch a { color: var(--green-600); font-weight: 600; cursor: pointer; text-decoration: none; }
.auth-switch a:hover { text-decoration: underline; }

.auth-demo-hint {
  background: var(--green-50);
  border: 1px solid var(--green-100);
  color: #065f46;
  padding: 10px 14px;
  border-radius: var(--radius-sm);
  margin-bottom: 16px;
  font-size: 12px;
  line-height: 1.5;
}

/* ============================================================
   SETTINGS SIDEBAR
   ============================================================ */

.settings-wrap { display: flex; gap: 20px; }

.settings-nav {
  width: 200px;
  flex-shrink: 0;
}

.settings-tab {
  width: 100%;
  display: flex; align-items: center; gap: 8px;
  padding: 9px 12px;
  background: transparent;
  border: 2px solid transparent;
  border-radius: var(--radius-sm);
  cursor: pointer;
  font-size: 12px; font-weight: 400;
  font-family: var(--font);
  color: var(--gray-700);
  margin-bottom: 3px;
  text-align: left;
  transition: all 0.15s;
}

.settings-tab:hover { background: var(--gray-100); }
.settings-tab.active { background: var(--green-50); border-color: var(--green-600); color: var(--green-700); font-weight: 600; }

.settings-content { flex: 1; min-width: 0; }

/* ============================================================
   REPORT TABS
   ============================================================ */

.report-tabs { display: flex; gap: 8px; margin-bottom: 16px; flex-wrap: wrap; }

.report-tab {
  padding: 8px 14px;
  border: none; border-radius: var(--radius-sm);
  font-size: 13px; font-weight: 500;
  font-family: var(--font);
  cursor: pointer;
  background: var(--gray-100);
  color: var(--gray-700);
  transition: all 0.15s;
}

.report-tab.active {
  background: linear-gradient(135deg, var(--green-600), var(--green-700));
  color: white;
}

/* ============================================================
   LOADING / SPINNER
   ============================================================ */

.spinner {
  width: 30px; height: 30px;
  border: 3px solid var(--gray-200);
  border-top-color: var(--green-600);
  border-radius: 50%;
  animation: spin 0.75s linear infinite;
  display: inline-block;
}

@keyframes spin { to { transform: rotate(360deg); } }

.loading-row {
  text-align: center; padding: 36px;
  color: var(--gray-500); font-size: 13px;
}

/* ============================================================
   TOTALS ROW
   ============================================================ */

.totals-row {
  text-align: right;
  padding: 14px 12px;
  border-top: 2px solid var(--gray-200);
  font-size: 14px;
}

.totals-amount { font-weight: 800; font-size: 17px; color: var(--green-700); }

/* ============================================================
   SUBSCRIPTION CARDS
   ============================================================ */

.sub-cards { display: grid; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); gap: 16px; margin-bottom: 30px; }

.sub-card {
  border: 2px solid var(--gray-200);
  border-radius: var(--radius-lg);
  padding: 22px;
  text-align: center;
  transition: border-color 0.15s;
}

.sub-card:hover { border-color: var(--green-500); }
.sub-card-price { font-size: 32px; font-weight: 800; color: var(--green-600); margin: 10px 0; }

/* ============================================================
   RESPONSIVE
   ============================================================ */

@media (max-width: 768px) {
  .sidebar { width: 60px; }
  .sidebar-brand-text, .nav-btn span { display: none; }
  .nav-btn { justify-content: center; padding: 10px; }
  .page { padding: 14px; }
  .topbar { padding: 0 12px; }
  .search-box { width: 140px; }
  .form-grid { grid-template-columns: 1fr; }
  .settings-wrap { flex-direction: column; }
  .settings-nav { width: 100%; display: flex; flex-wrap: wrap; gap: 4px; }
  .line-item-row { grid-template-columns: 1fr 1fr; }
}

@media (max-width: 480px) {
  .stats-grid { grid-template-columns: 1fr 1fr; }
  .modal { max-width: 100%; margin: 0; border-radius: 16px 16px 0 0; align-self: flex-end; }
  .topbar-right .user-info { display: none; }
}

/* ============================================================
   PRINT STYLES
   ============================================================ */

@media print {
  .sidebar, .topbar, .modal-overlay { display: none !important; }
  .content { overflow: visible; }
  .card { box-shadow: none; border: 1px solid #ddd; }
}
