/* ===== AGREE AGRO CRM Global Styles ===== */
@import url('https://fonts.googleapis.com/css2?family=DM+Sans:wght@300;400;500;600&family=Playfair+Display:wght@700&display=swap');

:root {
  --ink: #0d1117;
  --paper: #f8f5f0;
  --sidebar-bg: #0d1117;
  --sidebar-text: rgba(255,255,255,.65);
  --sidebar-active: #fff;
  --accent: #c8451f;
  --accent2: #2563eb;
  --green: #16a34a;
  --muted: #6b7280;
  --border: #e5ddd5;
  --card-bg: #fff;
  --shadow: 0 2px 16px rgba(0,0,0,.07);
  --shadow-lg: 0 8px 32px rgba(0,0,0,.12);
  --radius: 12px;
  --sidebar-w: 240px;
}

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

body {
  font-family: 'DM Sans', sans-serif;
  background: var(--paper);
  color: var(--ink);
  min-height: 100vh;
}

/* Layout */
.layout { display: flex; min-height: 100vh; }

/* Sidebar */
.sidebar {
  width: var(--sidebar-w);
  background: var(--sidebar-bg);
  position: fixed;
  top: 0; left: 0; bottom: 0;
  overflow-y: auto;
  z-index: 100;
  display: flex;
  flex-direction: column;
  transition: transform .3s;
}
.sidebar-header {
  padding: 28px 24px 20px;
  border-bottom: 1px solid rgba(255,255,255,.07);
}
.brand-mark {
  width: 40px; height: 40px;
  background: var(--accent);
  border-radius: 10px;
  display: flex; align-items: center; justify-content: center;
  font-family: 'Playfair Display', serif;
  font-size: 18px; color: #fff;
  margin-bottom: 12px;
}
.sidebar-title {
  font-size: 13px; font-weight: 600;
  color: #fff; letter-spacing: .5px;
  text-transform: uppercase;
}
.sidebar-subtitle {
  font-size: 11px; color: rgba(255,255,255,.35);
  margin-top: 2px;
}
.nav-section { padding: 20px 0 8px; }
.nav-label {
  padding: 0 24px 8px;
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 1.2px;
  color: rgba(255,255,255,.25);
  font-weight: 600;
}
.nav-link {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 11px 24px;
  color: var(--sidebar-text);
  text-decoration: none;
  font-size: 14px;
  font-weight: 400;
  transition: all .15s;
  border-left: 3px solid transparent;
}
.nav-link:hover { color: #fff; background: rgba(255,255,255,.05); }
.nav-link.active {
  color: var(--sidebar-active);
  background: rgba(255,255,255,.08);
  border-left-color: var(--accent);
  font-weight: 500;
}
.nav-icon { width: 18px; text-align: center; font-size: 16px; }
.sidebar-footer {
  margin-top: auto;
  padding: 20px 24px;
  border-top: 1px solid rgba(255,255,255,.07);
}
.user-info { display: flex; align-items: center; gap: 10px; }
.user-avatar {
  width: 32px; height: 32px;
  background: var(--accent);
  border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  font-size: 13px; color: #fff; font-weight: 600; flex-shrink: 0;
}
.user-name { font-size: 13px; color: #fff; font-weight: 500; }
.user-role { font-size: 11px; color: rgba(255,255,255,.4); }
.btn-logout {
  background: none; border: none;
  color: rgba(255,255,255,.4);
  font-size: 18px; cursor: pointer;
  margin-left: auto;
  transition: color .15s;
}
.btn-logout:hover { color: var(--accent); }

/* Main content */
.main-content {
  margin-left: var(--sidebar-w);
  flex: 1;
  display: flex;
  flex-direction: column;
  min-height: 100vh;
}

/* Topbar */
.topbar {
  background: #fff;
  border-bottom: 1px solid var(--border);
  padding: 0 32px;
  height: 64px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  position: sticky; top: 0; z-index: 50;
}
.page-title {
  font-family: 'Playfair Display', serif;
  font-size: 22px;
  color: var(--ink);
}
.topbar-actions { display: flex; align-items: center; gap: 12px; }
.mobile-menu-btn {
  display: none;
  background: none; border: none;
  font-size: 20px; cursor: pointer; color: var(--ink);
}

/* Content area */
.content { padding: 28px 32px; }

/* Cards */
.card {
  background: var(--card-bg);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 24px;
}
.card-header {
  display: flex; align-items: center;
  justify-content: space-between;
  margin-bottom: 20px;
}
.card-title {
  font-size: 16px; font-weight: 600;
  color: var(--ink);
}

/* Stat cards */
.stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 20px;
  margin-bottom: 28px;
}
.stat-card {
  background: var(--card-bg);
  border-radius: var(--radius);
  padding: 24px;
  box-shadow: var(--shadow);
  display: flex;
  align-items: flex-start;
  gap: 16px;
  transition: transform .2s, box-shadow .2s;
}
.stat-card:hover { transform: translateY(-2px); box-shadow: var(--shadow-lg); }
.stat-icon {
  width: 48px; height: 48px;
  border-radius: 12px;
  display: flex; align-items: center; justify-content: center;
  font-size: 22px; flex-shrink: 0;
}
.stat-icon.blue { background: #dbeafe; }
.stat-icon.orange { background: #ffedd5; }
.stat-icon.green { background: #dcfce7; }
.stat-icon.purple { background: #f3e8ff; }
.stat-value { font-size: 26px; font-weight: 700; color: var(--ink); line-height: 1.1; }
.stat-label { font-size: 13px; color: var(--muted); margin-top: 4px; }
.stat-change { font-size: 12px; margin-top: 6px; }
.stat-change.up { color: var(--green); }

/* Buttons */
.btn {
  padding: 9px 18px;
  border-radius: 8px;
  font-family: 'DM Sans', sans-serif;
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
  border: none;
  display: inline-flex; align-items: center; gap: 6px;
  transition: all .15s;
  text-decoration: none;
}
.btn-primary { background: var(--ink); color: #fff; }
.btn-primary:hover { background: var(--accent); }
.btn-success { background: var(--green); color: #fff; }
.btn-success:hover { opacity: .9; }
.btn-danger { background: #dc2626; color: #fff; }
.btn-danger:hover { opacity: .9; }
.btn-secondary {
  background: var(--paper);
  color: var(--ink);
  border: 1px solid var(--border);
}
.btn-secondary:hover { border-color: var(--ink); }
.btn-sm { padding: 6px 12px; font-size: 13px; }
.btn-icon { padding: 7px; border-radius: 6px; }

/* Forms */
.form-row { display: grid; grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); gap: 20px; }
.form-group { margin-bottom: 18px; }
.form-label {
  display: block; font-size: 13px;
  font-weight: 500; color: var(--ink);
  margin-bottom: 6px;
}
.form-label .req { color: var(--accent); }
.form-control {
  width: 100%;
  padding: 10px 14px;
  border: 1.5px solid var(--border);
  border-radius: 8px;
  font-family: 'DM Sans', sans-serif;
  font-size: 14px; color: var(--ink);
  background: #fff;
  transition: border-color .15s;
  outline: none;
}
.form-control:focus { border-color: var(--accent2); }
.form-control.is-invalid { border-color: var(--accent); }
.invalid-feedback { color: var(--accent); font-size: 12px; margin-top: 4px; }
select.form-control { cursor: pointer; }

/* Table */
.table-wrapper { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
thead th {
  text-align: left;
  padding: 12px 16px;
  font-size: 12px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .7px;
  color: var(--muted);
  border-bottom: 2px solid var(--border);
  white-space: nowrap;
}
tbody td {
  padding: 14px 16px;
  font-size: 14px;
  border-bottom: 1px solid #f3ede5;
  vertical-align: middle;
}
tbody tr:hover { background: #faf8f5; }
tbody tr:last-child td { border-bottom: none; }
.td-name { font-weight: 500; }
.td-order { font-family: monospace; font-size: 13px; color: var(--accent); font-weight: 600; }
.td-phone { color: var(--muted); font-size: 13px; }
.td-amount { font-weight: 600; }

/* Badges */
.badge {
  padding: 4px 10px;
  border-radius: 20px;
  font-size: 12px;
  font-weight: 500;
}
.badge-success { background: #dcfce7; color: #15803d; }
.badge-warning { background: #fef3c7; color: #b45309; }
.badge-danger { background: #fee2e2; color: #b91c1c; }
.badge-info { background: #dbeafe; color: #1d4ed8; }
.badge-admin { background: #f3e8ff; color: #7e22ce; }

/* Search bar */
.search-bar {
  display: flex; gap: 12px; flex-wrap: wrap;
  margin-bottom: 20px;
}
.search-input {
  flex: 1; min-width: 200px;
  padding: 9px 14px;
  border: 1.5px solid var(--border);
  border-radius: 8px;
  font-family: 'DM Sans', sans-serif;
  font-size: 14px; outline: none;
}
.search-input:focus { border-color: var(--accent2); }

/* Pagination */
#pagination { display: flex; gap: 6px; justify-content: center; margin-top: 20px; }
.pg-btn {
  min-width: 36px; height: 36px;
  border: 1.5px solid var(--border);
  background: #fff;
  border-radius: 8px;
  font-size: 14px; cursor: pointer;
  transition: all .15s;
}
.pg-btn:hover { border-color: var(--ink); }
.pg-btn.active { background: var(--ink); color: #fff; border-color: var(--ink); }
.pg-dots { border: none; background: none; font-size: 14px; color: var(--muted); }

/* Modal */
.modal-overlay {
  position: fixed; inset: 0;
  background: rgba(0,0,0,.5);
  display: none;
  align-items: center; justify-content: center;
  z-index: 999;
  padding: 20px;
}
.modal-overlay.show { display: flex; }
.modal {
  background: #fff;
  border-radius: var(--radius);
  width: 100%; max-width: 640px;
  max-height: 90vh;
  overflow-y: auto;
  box-shadow: var(--shadow-lg);
  animation: modalIn .2s ease-out;
}
@keyframes modalIn { from { opacity:0; transform:scale(.96); } to { opacity:1; transform:scale(1); } }
.modal-header {
  padding: 24px 28px 0;
  display: flex; align-items: center; justify-content: space-between;
}
.modal-title { font-family: 'Playfair Display', serif; font-size: 22px; }
.modal-close {
  background: none; border: none;
  font-size: 22px; cursor: pointer;
  color: var(--muted);
  width: 32px; height: 32px;
  display: flex; align-items: center; justify-content: center;
  border-radius: 50%;
  transition: background .15s;
}
.modal-close:hover { background: var(--paper); }
.modal-body { padding: 24px 28px; }
.modal-footer {
  padding: 0 28px 24px;
  display: flex; gap: 10px; justify-content: flex-end;
}

/* Toast */
#toastContainer {
  position: fixed;
  bottom: 24px; right: 24px;
  z-index: 9999;
  display: flex; flex-direction: column; gap: 10px;
}
.toast {
  padding: 14px 20px;
  border-radius: 10px;
  font-size: 14px;
  min-width: 280px;
  box-shadow: var(--shadow-lg);
  opacity: 0; transform: translateX(20px);
  transition: all .3s;
  display: flex; align-items: center; gap: 10px;
}
.toast.show { opacity: 1; transform: translateX(0); }
.toast-success { background: var(--ink); color: #fff; }
.toast-error { background: #dc2626; color: #fff; }
.toast-warning { background: #b45309; color: #fff; }

/* Empty state */
.empty-state {
  text-align: center; padding: 60px 20px;
  color: var(--muted);
}
.empty-icon { font-size: 48px; margin-bottom: 16px; }
.empty-title { font-size: 18px; font-weight: 600; color: var(--ink); margin-bottom: 8px; }

/* Loading */
.loading {
  text-align: center; padding: 40px;
  color: var(--muted); font-size: 14px;
}
.spinner-sm {
  display: inline-block;
  width: 18px; height: 18px;
  border: 2px solid rgba(0,0,0,.1);
  border-top-color: var(--ink);
  border-radius: 50%;
  animation: spin .7s linear infinite;
  vertical-align: middle;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* Admin-only elements */
.admin-only { display: none; }
body.is-admin .admin-only { display: inherit; }

/* Responsive */
@media (max-width: 900px) {
  .sidebar { transform: translateX(-100%); }
  .sidebar.open { transform: translateX(0); }
  .main-content { margin-left: 0; }
  .mobile-menu-btn { display: block; }
  .content { padding: 20px 16px; }
  .topbar { padding: 0 16px; }
}
@media (max-width: 600px) {
  .stats-grid { grid-template-columns: repeat(2, 1fr); }
  .form-row { grid-template-columns: 1fr; }
}
