/* ============================================================
   TG Farmhub — Shared Styles
   Used by all modules (index, inventory, workers, spraytracker)
   ============================================================ */

/* CSS VARIABLES */
:root {
  --bg: #FAF6EF;
  --bg-card: #FFFFFF;
  --bg-hover: #F0E8D8;
  --bg-input: #FFFFFF;
  --border: #E0D5C5;
  --border-light: #D0C5B5;
  --text: #2A1A3E;
  --text-muted: #8A7A6A;
  --text-dim: #A89A8A;
  --white: #2A1A3E;
  --green: #D4AF37;
  --green-light: #6B4C8A;
  --green-pale: rgba(107,76,138,0.08);
  --gold: #D4AF37;
  --gold-light: #E8C44A;
  --gold-pale: rgba(212,175,55,0.10);
  --red: #C44040;
  --red-pale: rgba(196,64,64,0.08);
  --good: #3A8A3A;
  --good-bg: rgba(58,138,58,0.10);
  --low: #C4960A;
  --low-bg: rgba(196,150,10,0.10);
  --critical: #C44040;
  --critical-bg: rgba(196,64,64,0.08);
  --purple: #6B4C8A;
  --purple-light: #8B6CAA;
  --sidebar-w: 220px;
  --overlay-subtle: rgba(0,0,0,0.03);
  --overlay-light: rgba(0,0,0,0.05);
  --overlay-medium: rgba(0,0,0,0.08);
}

/* RESET & BASE */
* { margin:0; padding:0; box-sizing:border-box; }

body {
  font-family: 'Plus Jakarta Sans', sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.5;
  height: 100vh;
  overflow: hidden;
}

#app { display:flex; height:100vh; }

/* SCROLLBAR */
::-webkit-scrollbar { width:8px; }
::-webkit-scrollbar-track { background:var(--bg); }
::-webkit-scrollbar-thumb { background:var(--border); border-radius:4px; }
::-webkit-scrollbar-thumb:hover { background:var(--border-light); }

/* ============================================================
   SIDEBAR
   ============================================================ */
.sidebar {
  width: var(--sidebar-w);
  background: var(--bg);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  flex-shrink: 0;
  overflow: hidden;
}

.sidebar-brand {
  padding: 18px 16px;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  gap: 12px;
  min-height: 90px;
}

.sidebar-logo {
  width: 84px;
  height: 84px;
  border-radius: 8px;
  background: transparent;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  overflow: hidden;
  padding: 0;
}

.sidebar-logo img { width:100%; height:100%; object-fit:contain; }

.sidebar-brand-text {
  font-weight: 800;
  font-size: 15px;
  color: var(--gold-light);
  line-height: 1.2;
}

.sidebar-brand-sub {
  font-size: 11px;
  color: var(--text-dim);
  font-weight: 500;
}

.sidebar-nav {
  padding: 12px 0;
  flex: 1;
  overflow-y: auto;
}

.nav-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 16px;
  cursor: pointer;
  border-left: 3px solid transparent;
  color: var(--text-muted);
  font-weight: 500;
  font-size: 13px;
  transition: all 0.15s;
  white-space: nowrap;
  text-decoration: none;
}

.nav-item:hover { background:var(--overlay-subtle); }

.nav-item.active {
  border-left-color: var(--purple);
  background: rgba(107,76,138,0.06);
  color: var(--purple);
  font-weight: 700;
}

.nav-item svg { width:18px; height:18px; flex-shrink:0; }

.sidebar-sync {
  padding: 12px 16px;
  border-top: 1px solid var(--border);
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 11px;
  color: var(--text-dim);
  cursor: pointer;
}

.sidebar-sync:hover { color:var(--text-muted); }
.sidebar-sync svg { width:14px; height:14px; }

/* ---- Company Switcher ---- */
.company-switcher {
  padding: 8px 12px;
  border-bottom: 1px solid var(--border);
  display: flex;
  gap: 4px;
}
.company-switcher .company-btn {
  flex: 1;
  padding: 7px 4px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: transparent;
  color: var(--text-muted);
  font-size: 10px;
  font-weight: 600;
  cursor: pointer;
  text-align: center;
  line-height: 1.3;
  transition: all 0.15s;
}
.company-switcher .company-btn:hover {
  border-color: var(--text-muted);
}
.company-switcher .company-btn.active {
  background: var(--green);
  border-color: var(--green);
  color: #fff;
}
@media (max-width: 768px) {
  .company-switcher {
    padding: 6px 10px;
  }
  .company-switcher .company-btn {
    font-size: 9px;
    padding: 6px 3px;
  }
}

.sidebar-user {
  padding: 10px 16px;
  border-top: 1px solid var(--border);
  display: flex;
  align-items: center;
  gap: 8px;
}

/* ============================================================
   MAIN LAYOUT
   ============================================================ */
.main-content {
  flex: 1;
  overflow: auto;
  padding: 24px 28px;
}

.main-content > .page {
  max-width: 1200px;
  margin: 0 auto;
}

.page { display:none; }
.page.active { display:block; }

.page-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 20px;
  flex-wrap: wrap;
  gap: 12px;
}

.page-title {
  font-family: 'Playfair Display', serif;
  font-size: 24px;
  font-weight: 700;
  color: var(--white);
}

.page-subtitle {
  font-size: 12px;
  color: var(--text-muted);
  margin-top: 2px;
}

.header-actions { display:flex; gap:8px; flex-wrap:wrap; }

/* ============================================================
   BUTTONS
   ============================================================ */
.btn {
  padding: 8px 16px;
  border-radius: 8px;
  font-size: 12px;
  font-weight: 700;
  border: none;
  cursor: pointer;
  font-family: inherit;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  transition: all 0.15s;
  white-space: nowrap;
}

.btn:hover { filter:brightness(1.1); }
.btn svg { width:14px; height:14px; }
.btn:disabled { opacity:0.4; cursor:not-allowed; filter:none; }

.btn-primary { background:var(--green); color:#1A0E2E; }
.btn-outline { background:transparent; border:1px solid var(--border); color:var(--text); }
.btn-outline:hover { border-color:var(--border-light); background:var(--overlay-subtle); }
.btn-danger { background:var(--red-pale); color:var(--red); border:1px solid rgba(232,96,96,0.25); }
.btn-sm { padding:6px 12px; font-size:11px; min-height:32px; }

/* ============================================================
   FORM ELEMENTS
   ============================================================ */
input, select, textarea {
  padding: 9px 12px;
  border-radius: 8px;
  font-size: 13px;
  font-family: inherit;
  border: 1px solid var(--border);
  background: var(--bg-input);
  color: var(--text);
  outline: none;
  transition: border-color 0.15s;
}

input:focus, select:focus, textarea:focus { border-color:var(--green); }
select { cursor:pointer; }
textarea { resize:vertical; }

.form-field { margin-bottom:14px; }
.form-field label {
  display: block;
  font-size: 11px;
  font-weight: 700;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  margin-bottom: 5px;
}

.form-row { display:flex; gap:12px; }
.form-row .form-field { flex:1; }

.inline-input, .inline-select {
  padding: 6px 8px;
  font-size: 13px;
  font-family: inherit;
  color: var(--text);
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: 6px;
  outline: none;
}
.inline-input:focus, .inline-select:focus { border-color:var(--green); }

/* ============================================================
   TABLES
   ============================================================ */
.data-table {
  background: var(--bg-card);
  border-radius: 10px;
  border: 1px solid var(--border);
  overflow: hidden;
  margin-bottom: 18px;
}

.table-header {
  padding: 12px 16px;
  border-bottom: 1px solid var(--border);
  font-weight: 700;
  font-size: 14px;
}

.table-toolbar {
  padding: 12px 14px;
  display: flex;
  gap: 10px;
  align-items: center;
  border-bottom: 1px solid var(--border);
  flex-wrap: wrap;
}

.table-wrap { overflow-x:auto; }

table { width:100%; border-collapse:collapse; }

th {
  text-align: left;
  padding: 9px 16px;
  font-size: 10px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-muted);
  background: var(--bg);
  border-bottom: 1px solid var(--border);
}

td {
  padding: 10px 16px;
  font-size: 13px;
  border-bottom: 1px solid var(--border);
  color: var(--text);
  max-width: 220px;
  overflow-wrap: break-word;
  word-break: break-word;
}

tr.clickable { cursor:pointer; transition:background 0.1s; }
tr.clickable:hover { background:var(--bg-hover); }

.td-bold { font-weight:600; color:var(--white); }
.td-gold { color:var(--gold-light); font-size:12px; }

/* Text truncation helper */
.td-truncate { max-width:180px; overflow:hidden; text-overflow:ellipsis; white-space:nowrap; }


/* ============================================================
   CARDS
   ============================================================ */
.cards-grid {
  display: grid;
  grid-template-columns: repeat(4,1fr);
  gap: 14px;
  margin-bottom: 22px;
}

.summary-card {
  background: var(--bg-card);
  border-radius: 10px;
  padding: 16px;
  border: 1px solid var(--border);
  transition: border-color 0.2s, transform 0.15s;
}

.summary-card[onclick]:hover {
  border-color: var(--gold);
  transform: translateY(-2px);
}

.summary-card .sc-label {
  font-size: 11px;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  font-weight: 700;
  margin-bottom: 4px;
}

.summary-card .sc-value { font-size:24px; font-weight:800; }
.summary-card .sc-sub { font-size:11px; color:var(--text-dim); margin-top:2px; }

/* ============================================================
   BADGES
   ============================================================ */
.badge {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 2px 10px;
  border-radius: 12px;
  font-size: 11px;
  font-weight: 700;
}

.badge-good { background:var(--good-bg); color:var(--good); }
.badge-low { background:var(--low-bg); color:var(--low); }
.badge-critical { background:var(--critical-bg); color:var(--critical); }
.badge-in { background:var(--good-bg); color:var(--good); }
.badge-out { background:var(--critical-bg); color:var(--critical); }
.badge-active { background:var(--good-bg); color:var(--good); }
.badge-inactive { background:var(--critical-bg); color:var(--critical); }

/* ============================================================
   MODALS
   ============================================================ */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.6);
  display: flex;
  justify-content: center;
  align-items: center;
  z-index: 999;
  backdrop-filter: blur(4px);
  animation: fadeIn 0.2s ease;
}

.modal-box {
  background: var(--bg-card);
  border-radius: 14px;
  padding: 28px;
  width: 90vw;
  max-width: 500px;
  max-height: 90vh;
  overflow-y: auto;
  box-shadow: 0 20px 60px rgba(0,0,0,0.4);
  border: 1px solid var(--border);
}

.modal-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 20px;
}

.modal-title {
  font-family: 'Playfair Display', serif;
  font-size: 18px;
  font-weight: 700;
  color: var(--white);
}

.modal-close {
  background: none;
  border: none;
  cursor: pointer;
  color: var(--text-muted);
  padding: 4px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 8px;
}

.modal-close:hover { color:var(--text); background:var(--bg-hover); }
.modal-close svg { width:18px; height:18px; }

.modal-actions { display:flex; gap:10px; justify-content:flex-end; margin-top:20px; }

/* ============================================================
   OFFLINE BANNER
   ============================================================ */
.offline-banner {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  z-index: 10001;
  background: var(--red);
  color: white;
  text-align: center;
  padding: 8px 16px;
  font-size: 13px;
  font-weight: 600;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  animation: slideDown 0.3s ease;
}

.offline-banner svg { flex-shrink: 0; }

@keyframes slideDown { from { transform:translateY(-100%); } to { transform:translateY(0); } }

/* ============================================================
   NOTIFICATIONS
   ============================================================ */
.notification-container {
  position: fixed;
  top: 20px;
  right: 20px;
  z-index: 9999;
  display: flex;
  flex-direction: column;
  gap: 8px;
  pointer-events: none;
}

.notification {
  padding: 10px 18px;
  border-radius: 10px;
  font-weight: 600;
  font-size: 13px;
  box-shadow: 0 8px 24px rgba(0,0,0,0.3);
  animation: slideIn 0.3s ease;
  display: flex;
  align-items: center;
  gap: 8px;
  color: white;
  pointer-events: auto;
}

.notification.success { background:var(--good); color:white; }
.notification.success, .notification.info { color:white; }
.notification.warning { background:var(--gold); color:#1a1a1a; }
.notification.error { background:var(--red); color:white; }
.notification.info { background:#3A7AC8; }

/* ============================================================
   TOGGLE SWITCH
   ============================================================ */
.toggle { position:relative; width:36px; height:20px; display:inline-block; cursor:pointer; }
.toggle input { display:none; }
.toggle-slider {
  position: absolute;
  inset: 0;
  background: var(--border);
  border-radius: 20px;
  transition: background 0.2s;
}
.toggle-slider::after {
  content: "";
  position: absolute;
  left: 2px;
  top: 2px;
  width: 16px;
  height: 16px;
  background: var(--text-muted);
  border-radius: 50%;
  transition: all 0.2s;
}
.toggle input:checked + .toggle-slider { background:var(--green); }
.toggle input:checked + .toggle-slider::after { left:18px; background:white; }

/* SAVE TICK */
.save-tick {
  color: var(--good);
  font-weight: 700;
  opacity: 0;
  transition: opacity 0.3s;
}
.save-tick.show { opacity:1; }

/* ============================================================
   LOADING OVERLAY
   ============================================================ */
.loading-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.45);
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  z-index: 9998;
  gap: 14px;
  backdrop-filter: blur(2px);
  transition: opacity 0.2s;
}

.loading-spinner {
  width: 36px;
  height: 36px;
  border: 3px solid var(--border);
  border-top-color: var(--green-light);
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
}

.loading-text {
  font-size: 13px;
  font-weight: 600;
  color: var(--text);
}

/* ============================================================
   ACCESSIBILITY
   ============================================================ */

/* Focus-visible ring for keyboard navigation */
.btn:focus-visible,
button:focus-visible,
a:focus-visible,
input:focus-visible,
select:focus-visible,
textarea:focus-visible,
.nav-item:focus-visible {
  outline: 2px solid var(--gold);
  outline-offset: 2px;
}

/* Skip to main content link (hidden until focused) */
.skip-link {
  position: absolute;
  top: -100%;
  left: 16px;
  background: var(--green);
  color: white;
  padding: 8px 16px;
  border-radius: 0 0 8px 8px;
  z-index: 10000;
  font-size: 13px;
  font-weight: 700;
  text-decoration: none;
  transition: top 0.2s;
}
.skip-link:focus { top: 0; }

/* ============================================================
   ANIMATIONS
   ============================================================ */
@keyframes fadeIn { from { opacity:0; } to { opacity:1; } }
@keyframes slideIn { from { opacity:0; transform:translateY(-10px); } to { opacity:1; transform:translateY(0); } }
@keyframes spin { from { transform:rotate(0deg); } to { transform:rotate(360deg); } }

/* ============================================================
   RESPONSIVE
   ============================================================ */
@media (max-width:900px) {
  .cards-grid { grid-template-columns:repeat(2,1fr); }
}

@media (max-width:768px) {
  body { overflow:auto !important; height:auto !important; }
  #app { flex-direction:column !important; height:auto !important; min-height:100vh; }

  .sidebar {
    width:100% !important;
    height:auto !important;
    flex-direction:column !important;
    border-right:none !important;
    border-bottom:1px solid var(--border) !important;
  }
  .sidebar-brand { padding:8px 12px !important; min-height:auto !important; border-bottom:none !important; }
  .sidebar-logo { width:40px !important; height:40px !important; }
  .sidebar-nav { display:flex; flex-wrap:wrap; padding:4px 8px; }
  #sidebar-user { display:none !important; }
  .sidebar-sync { display:none !important; }
  .mobile-logout { display:flex !important; }
  .nav-item { padding:6px 10px !important; border-left:none !important; border-bottom:2px solid transparent; font-size:12px !important; }
  .nav-item.active { border-bottom-color:var(--green-light); border-left-color:transparent !important; }

  .main-content { padding:14px 10px !important; overflow:visible !important; }
  .page-header { flex-direction:column !important; align-items:flex-start !important; gap:8px !important; }
  .page-title { font-size:18px !important; }

  .cards-grid { grid-template-columns:repeat(2,1fr) !important; gap:8px !important; }
  .summary-card { padding:10px !important; }

  .modal-box { max-width:95vw !important; width:95vw !important; max-height:85vh !important; }
  .form-row { flex-direction:column !important; }

  /* Mobile touch targets */
  .btn-sm { min-height:36px; padding:8px 14px; font-size:12px; }
  .btn { min-height:40px; }

  /* Tables: ensure horizontal scroll */
  .table-wrap, .data-table { overflow-x:auto !important; -webkit-overflow-scrolling:touch; }
  table { min-width:500px; }
  td { max-width:160px; }
}

@media (max-width:400px) {
  .cards-grid { grid-template-columns:1fr !important; }
  .nav-item { padding:8px !important; }
}

/* ============================================================
   DESKTOP (≥1024px) — larger text for readability
   ============================================================ */
@media (min-width: 1024px) {
  body { font-size: 16px; }
  .page-title { font-size: 28px; }
  .page-subtitle { font-size: 14px; }
  .sidebar-brand-text { font-size: 17px; }
  .nav-item { font-size: 14px; padding: 10px 20px; }
  .btn { font-size: 14px; padding: 10px 20px; }
  .btn-sm { font-size: 13px; }
  input, select, textarea { font-size: 14px; }
  label { font-size: 12px; }
  td, th { font-size: 14px; padding: 10px 14px; }
  .summary-card .sc-value { font-size: 28px; }
  .summary-card .sc-label { font-size: 12px; }
}

/* ============================================================
   PRINT
   ============================================================ */
@media print {
  .sidebar, .sidebar-sync, .header-actions, .btn, .notification-container { display:none !important; }
  body { background:white; color:black; overflow:visible; height:auto; }
  #app { display:block; height:auto; }
  .main-content { padding:0; overflow:visible; }
  .page { display:block !important; }
  .data-table { border:1px solid #ccc; }
  th { background:#f5f5f5; color:#333; }
  td { color:#333; border-color:#ddd; }
}
