/* ============================================================
   Venkateshwara Farms — Purchase Management
   Design: Swiss Modernism / Executive Dashboard
   Font: Inter (Google Fonts)
   ============================================================ */

@import url('https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700&display=swap');

/* ── Design tokens ────────────────────────────────────────── */
:root {
  /* Brand greens */
  --green-900: #0D2318;
  --green-800: #1C3829;
  --green-700: #2E7D32;
  --green-500: #4CAF50;
  --green-400: #66BB6A;
  --green-100: #E8F5E9;
  --green-50:  #F0FBF1;

  /* Semantic aliases */
  --primary:        var(--green-700);
  --primary-dark:   var(--green-800);
  --accent:         var(--green-500);
  --accent-hover:   #388E3C;

  /* Legacy aliases — keep existing class usages working */
  --green-dark:  var(--green-800);
  --green-mid:   var(--green-700);
  --green-light: var(--green-400);
  --green-pale:  var(--green-100);

  /* Surfaces */
  --bg:        #F8FAFC;
  --white:     #FFFFFF;
  --surface:   #FFFFFF;
  --surface-2: #F8FAFC;

  /* Typography */
  --text:       #0F1A16;
  --text-muted: #5A6A64;
  --text-light: #8FA399;

  /* Borders */
  --border:    rgba(0, 0, 0, .08);
  --border-md: rgba(0, 0, 0, .12);

  /* Elevation — 2-layer system (ring + blur) */
  --shadow-sm:    0 0 0 1px rgba(0,0,0,.06), 0 1px 3px rgba(0,0,0,.05);
  --shadow:       0 0 0 1px rgba(0,0,0,.06), 0 2px 6px rgba(0,0,0,.06), 0 8px 20px rgba(0,0,0,.04);
  --shadow-hover: 0 0 0 1px rgba(0,0,0,.08), 0 4px 12px rgba(0,0,0,.08), 0 16px 32px rgba(0,0,0,.06);
  --shadow-deep:  0 0 0 1px rgba(0,0,0,.10), 0 8px 24px rgba(0,0,0,.12), 0 24px 48px rgba(0,0,0,.08);

  /* Shape */
  --radius:    8px;
  --radius-lg: 12px;
  --radius-xl: 16px;

  /* Sidebar */
  --sidebar-w: 240px;

  /* Danger */
  --danger:       #DC2626;
  --danger-hover: #B91C1C;
  --danger-light: #FEF2F2;
}

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

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

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

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

/* ══════════════════════════════════════════════════════════
   SIDEBAR
════════════════════════════════════════════════════════════ */
.sidebar {
  width: var(--sidebar-w);
  background: var(--green-900);
  color: #fff;
  display: flex;
  flex-direction: column;
  position: fixed;
  top: 0; left: 0; bottom: 0;
  z-index: 100;
  transition: transform .25s cubic-bezier(.4,0,.2,1);
  border-right: 1px solid rgba(255,255,255,.04);
  overflow-y: auto;
}

.sidebar-header {
  padding: 1.25rem 1rem 1rem;
  border-bottom: 1px solid rgba(255,255,255,.07);
}

.sidebar-brand {
  display: flex;
  align-items: center;
  gap: .7rem;
  margin-bottom: .3rem;
}

.sidebar-icon {
  width: 32px; height: 32px;
  background: rgba(255,255,255,.10);
  border-radius: 8px;
  display: flex; align-items: center; justify-content: center;
  flex-shrink: 0;
  border: 1px solid rgba(255,255,255,.12);
}
.sidebar-icon svg { width: 16px; height: 16px; color: #fff; }

.sidebar-title {
  font-size: .9rem;
  font-weight: 700;
  letter-spacing: -.01em;
  color: #fff;
}

.sidebar-subtitle {
  font-size: .72rem;
  color: rgba(255,255,255,.42);
  letter-spacing: .01em;
}

.sidebar-nav {
  flex: 1;
  padding: .75rem .625rem;
  display: flex;
  flex-direction: column;
  gap: 2px;
  list-style: none;
}

.nav-link {
  display: flex;
  align-items: center;
  gap: .625rem;
  padding: .6rem .75rem;
  color: rgba(255,255,255,.60);
  text-decoration: none;
  font-size: .84rem;
  font-weight: 500;
  border-radius: var(--radius);
  transition: background .15s, color .15s;
  cursor: pointer;
  letter-spacing: .005em;
}

.nav-link svg { width: 16px; height: 16px; flex-shrink: 0; }

.nav-link:hover {
  background: rgba(255,255,255,.08);
  color: rgba(255,255,255,.90);
  text-decoration: none;
}

.nav-link.active {
  background: rgba(255,255,255,.12);
  color: #fff;
  font-weight: 600;
}

.sidebar-footer {
  padding: .5rem .625rem .875rem;
  border-top: 1px solid rgba(255,255,255,.07);
}

.logout-link { color: rgba(255,255,255,.45); }
.logout-link:hover { color: #FCA5A5; background: rgba(220,38,38,.12); }

/* ── Legacy sidebar classes kept for safety ── */
.sidebar-logo { display: flex; align-items: center; gap: 10px; padding: 20px 16px 16px; border-bottom: 1px solid rgba(255,255,255,.08); }
.logo-icon { font-size: 22px; }
.logo-text { color: #fff; font-size: 16px; font-weight: 700; }
.nav-links { list-style: none; padding: 12px 0; flex: 1; }
.nav-links li a { display: flex; align-items: center; gap: 10px; padding: 10px 16px; color: rgba(255,255,255,.7); font-size: 14px; }
.nav-links li a:hover { background: rgba(255,255,255,.08); color: #fff; text-decoration: none; }
.nav-links li a.active { background: rgba(255,255,255,.12); color: #fff; font-weight: 600; }
.nav-icon { font-size: 16px; min-width: 20px; text-align: center; }
.logout-btn { display: block; padding: 8px 12px; border-radius: var(--radius); color: rgba(255,255,255,.7); font-size: 13px; text-align: center; }
.logout-btn:hover { background: rgba(255,255,255,.08); color: #fff; text-decoration: none; }

/* ── Main content ── */
.main-content {
  margin-left: var(--sidebar-w);
  flex: 1;
  padding: 1.75rem 2rem;
  min-width: 0;
  max-width: 1400px;
}

/* ══════════════════════════════════════════════════════════
   MOBILE HEADER
════════════════════════════════════════════════════════════ */
.mobile-header {
  display: none;
  position: fixed; top: 0; left: 0; right: 0; z-index: 200;
  background: var(--green-900);
  padding: .75rem 1rem;
  align-items: center; gap: .75rem;
  box-shadow: 0 2px 8px rgba(0,0,0,.25);
}
.hamburger {
  background: none; border: none; color: #fff;
  font-size: 22px; cursor: pointer; padding: 0;
  width: 28px; height: 28px;
  display: flex; align-items: center; justify-content: center;
}
.mobile-title { color: #fff; font-size: 15px; font-weight: 600; }

/* ══════════════════════════════════════════════════════════
   PAGE HEADER
════════════════════════════════════════════════════════════ */
.page-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 1.5rem;
  flex-wrap: wrap; gap: .5rem;
}

.page-header h1,
.page-header h2 {
  font-size: 1.35rem;
  font-weight: 700;
  color: var(--text);
  letter-spacing: -.02em;
}

.page-subtitle {
  font-size: .72rem;
  font-weight: 600;
  background: var(--green-100);
  color: var(--green-700);
  padding: .25rem .7rem;
  border-radius: 20px;
  letter-spacing: .04em;
  text-transform: uppercase;
}

/* ══════════════════════════════════════════════════════════
   CARDS
════════════════════════════════════════════════════════════ */
.card {
  background: var(--surface);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow);
  padding: 1.375rem;
  margin-bottom: 1.25rem;
}

.card-title {
  font-size: .95rem;
  font-weight: 700;
  color: var(--text);
  letter-spacing: -.01em;
  margin-bottom: 1rem;
}

.card-header-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 1rem;
  flex-wrap: wrap; gap: .5rem;
}
.card-header-row .card-title { margin-bottom: 0; }

/* ══════════════════════════════════════════════════════════
   KPI CARDS
════════════════════════════════════════════════════════════ */
.kpi-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 1rem;
  margin-bottom: 1.375rem;
}

.kpi-card {
  background: var(--surface);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow);
  padding: 1.25rem;
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: .75rem;
  transition: box-shadow .2s;
  text-align: left;
  border-top: none;
}
.kpi-card:hover { box-shadow: var(--shadow-hover); }

.kpi-body { display: flex; flex-direction: column; gap: .25rem; flex: 1; min-width: 0; }

.kpi-value {
  font-size: 1.75rem;
  font-weight: 700;
  color: var(--text);
  letter-spacing: -.03em;
  line-height: 1.1;
  font-variant-numeric: tabular-nums;
}

.kpi-label {
  font-size: .7rem;
  font-weight: 700;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: .07em;
  margin-top: .25rem;
}

.kpi-icon {
  width: 40px; height: 40px;
  background: var(--green-100);
  border-radius: 10px;
  display: flex; align-items: center; justify-content: center;
  flex-shrink: 0;
  margin-top: .1rem;
  font-size: 18px;
}
.kpi-icon svg { width: 20px; height: 20px; color: var(--green-700); }

/* ══════════════════════════════════════════════════════════
   CHARTS
════════════════════════════════════════════════════════════ */
.chart-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(320px, 1fr));
  gap: 1rem;
  margin-bottom: 1.25rem;
}

/* ══════════════════════════════════════════════════════════
   TABLES
════════════════════════════════════════════════════════════ */
.table-wrap { overflow-x: auto; }

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

.data-table th {
  text-align: left;
  padding: .55rem .875rem;
  background: var(--bg);
  color: var(--text);
  font-weight: 700;
  font-size: .72rem;
  text-transform: uppercase;
  letter-spacing: .07em;
  white-space: nowrap;
  border-bottom: 1px solid var(--border-md);
}

.data-table td {
  padding: .625rem .875rem;
  border-bottom: 1px solid var(--border);
  vertical-align: middle;
  color: var(--text);
}

.data-table tbody tr:last-child td { border-bottom: none; }
.data-table tbody tr:hover td { background: #F5FBF6; }

.amount-cell {
  font-weight: 700;
  color: var(--text);
  white-space: nowrap;
  font-variant-numeric: tabular-nums;
}
.actions-cell { white-space: nowrap; }
.row-inactive td { color: var(--text-muted); }
.total-amount {
  font-size: 1.05rem;
  font-weight: 700;
  color: var(--primary);
  font-variant-numeric: tabular-nums;
}
.serial-cell {
  color: var(--text-muted);
  font-size: 12px;
  white-space: nowrap;
  font-variant-numeric: tabular-nums;
  font-weight: 600;
}

/* ══════════════════════════════════════════════════════════
   BADGES
════════════════════════════════════════════════════════════ */
.badge-vendor {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  background: var(--green-100);
  color: var(--green-800);
  padding: .15rem .55rem;
  border-radius: 6px;
  font-size: .73rem;
  font-weight: 600;
  letter-spacing: .02em;
  border: none;
  white-space: nowrap;
  text-decoration: none;
}
.badge-vendor:hover { background: #C8E6C9; text-decoration: none; }

.supplier-badge { margin: 2px 3px 2px 0; }
.supplier-count {
  display: inline-flex; align-items: center; justify-content: center;
  background: var(--green-700); color: #fff;
  border-radius: 8px; font-size: 10px; font-weight: 700;
  min-width: 16px; height: 16px; padding: 0 4px;
}
.suppliers-cell { min-width: 160px; }
.text-muted { color: var(--text-muted); font-size: 12px; }
.badge-active {
  display: inline-block; background: var(--green-100); color: var(--green-700);
  padding: .15rem .55rem; border-radius: 6px;
  font-size: .73rem; font-weight: 600;
  letter-spacing: .02em;
}
.badge-inactive {
  display: inline-block; background: #F5F5F5; color: #9E9E9E;
  padding: .15rem .55rem; border-radius: 6px;
  font-size: .73rem; font-weight: 500;
}

/* ══════════════════════════════════════════════════════════
   BUTTONS
════════════════════════════════════════════════════════════ */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: .35rem;
  padding: .55rem 1.1rem;
  border-radius: var(--radius);
  font-size: .84rem;
  font-weight: 600;
  cursor: pointer;
  text-decoration: none;
  border: none;
  transition: background .15s, color .15s, box-shadow .15s, transform .1s;
  line-height: 1;
  white-space: nowrap;
  font-family: inherit;
  letter-spacing: .01em;
}
.btn:hover { text-decoration: none; }
.btn:active { transform: scale(.98); }

.btn-primary {
  background: var(--accent);
  color: #fff;
  box-shadow: 0 1px 2px rgba(0,0,0,.12);
}
.btn-primary:hover {
  background: var(--accent-hover);
  box-shadow: 0 1px 3px rgba(0,0,0,.16), 0 4px 12px rgba(76,175,80,.30);
}

.btn-secondary {
  background: var(--surface);
  color: var(--text);
  border: 1px solid var(--border-md);
  box-shadow: var(--shadow-sm);
}
.btn-secondary:hover {
  background: var(--bg);
  border-color: var(--border-md);
}

.btn-danger {
  background: var(--danger);
  color: #fff;
  box-shadow: 0 1px 2px rgba(0,0,0,.12);
}
.btn-danger:hover { background: var(--danger-hover); }

.btn-sm { padding: .375rem .8rem; font-size: .79rem; }
.btn-xs { padding: .25rem .6rem; font-size: .72rem; }
.btn-full { width: 100%; padding: .75rem 1rem; font-size: .9rem; }
.btn-disabled {
  opacity: .45;
  cursor: not-allowed;
  pointer-events: none;
  background: var(--bg) !important;
  color: var(--text-muted) !important;
  box-shadow: none !important;
  border: 1px solid var(--border) !important;
}

/* ══════════════════════════════════════════════════════════
   FORMS
════════════════════════════════════════════════════════════ */
.form-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  gap: 1rem 1.25rem;
  margin-bottom: 1rem;
}

.form-group { display: flex; flex-direction: column; gap: .35rem; }
.form-group-full,
.form-group.full-width { grid-column: 1 / -1; }
.form-group-actions { display: flex; align-items: flex-end; gap: .5rem; }

.form-group label {
  font-size: .75rem;
  font-weight: 700;
  color: var(--text-muted);
  letter-spacing: .06em;
  text-transform: uppercase;
}

.form-group input,
.form-group select,
.form-group textarea {
  padding: .6rem .8rem;
  border: 1px solid var(--border-md);
  border-radius: var(--radius);
  font-size: .9rem;
  font-family: inherit;
  color: var(--text);
  background: var(--surface);
  transition: border-color .15s, box-shadow .15s;
  width: 100%;
}
.form-group textarea { resize: vertical; min-height: 68px; line-height: 1.45; }

.form-group input:focus,
.form-group select:focus,
.form-group textarea:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(76,175,80,.14);
}

.form-group input[readonly] {
  background: var(--bg);
  color: var(--primary);
  cursor: default;
  font-weight: 700;
}

.required,
.req { color: var(--danger); font-size: .9em; }

.form-actions {
  margin-top: 1.5rem;
  padding-top: 1.25rem;
  border-top: 1px solid var(--border);
  display: flex;
  gap: .625rem;
  align-items: center;
  flex-wrap: wrap;
}

.hint-text { color: var(--text-muted); font-size: .82rem; margin-bottom: .75rem; line-height: 1.5; }

/* ── Filter bar ── */
.filter-form { display: flex; flex-wrap: wrap; gap: .75rem; align-items: flex-end; }
.filter-form .form-group { min-width: 140px; flex: 1; }

/* ══════════════════════════════════════════════════════════
   PURCHASE FORM (item rows table)
════════════════════════════════════════════════════════════ */
.purchase-form { }

.item-rows-table {
  width: 100%;
  border-collapse: separate;
  border-spacing: 0;
  margin-bottom: .75rem;
}
.item-rows-table th {
  text-align: left;
  padding: .5rem .6rem;
  background: var(--bg);
  color: var(--text-muted);
  font-weight: 700;
  font-size: .68rem;
  text-transform: uppercase;
  letter-spacing: .07em;
  border-bottom: 1px solid var(--border-md);
}
.item-rows-table td {
  padding: .45rem .4rem;
  vertical-align: middle;
}
.item-rows-table input,
.item-rows-table select {
  width: 100%;
  padding: .5rem .6rem;
  border: 1px solid var(--border-md);
  border-radius: 6px;
  font-size: .88rem;
  font-family: inherit;
  background: var(--surface);
  transition: border-color .15s, box-shadow .15s;
}
.item-rows-table input:focus,
.item-rows-table select:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(76,175,80,.14);
}

.btn-remove-row {
  background: transparent;
  border: none;
  color: var(--danger);
  font-size: 18px;
  cursor: pointer;
  padding: 4px 8px;
  border-radius: 6px;
  line-height: 1;
  transition: background .15s;
}
.btn-remove-row:hover { background: var(--danger-light); }

/* ══════════════════════════════════════════════════════════
   FLASH MESSAGES
════════════════════════════════════════════════════════════ */
.flash-container { margin-bottom: 1.25rem; }

.flash {
  display: flex;
  align-items: flex-start;
  gap: .6rem;
  padding: .8rem 1rem;
  border-radius: var(--radius);
  margin-bottom: .5rem;
  font-size: .88rem;
  font-weight: 500;
  box-shadow: var(--shadow-sm);
  animation: slideDown .2s ease;
}

@keyframes slideDown {
  from { opacity: 0; transform: translateY(-6px); }
  to   { opacity: 1; transform: translateY(0); }
}

.flash-success { background: #F0FDF4; color: #14532D; border: 1px solid #BBF7D0; }
.flash-error   { background: #FEF2F2; color: #7F1D1D; border: 1px solid #FECACA; }

/* ══════════════════════════════════════════════════════════
   EMPTY STATE
════════════════════════════════════════════════════════════ */
.empty-state {
  color: var(--text-muted);
  font-size: .92rem;
  padding: 2.5rem 1.5rem;
  text-align: center;
  line-height: 1.6;
}
.empty-state a { color: var(--primary); font-weight: 600; }

/* ══════════════════════════════════════════════════════════
   EXPORT PAGE
════════════════════════════════════════════════════════════ */
.export-buttons { display: flex; gap: .75rem; flex-wrap: wrap; }
.export-btn { font-size: .9rem; padding: .75rem 1.25rem; }

/* ══════════════════════════════════════════════════════════
   MODAL
════════════════════════════════════════════════════════════ */
.modal-overlay {
  position: fixed; inset: 0; z-index: 500;
  background: rgba(15, 26, 22, .55);
  display: flex; align-items: center; justify-content: center;
  padding: 1rem;
  backdrop-filter: blur(3px);
}
.modal-card {
  background: var(--surface);
  border-radius: var(--radius-xl);
  padding: 1.5rem 1.5rem 1.25rem;
  width: 100%;
  max-width: 480px;
  box-shadow: var(--shadow-deep);
}
.modal-card h2 {
  font-size: 1.05rem;
  font-weight: 700;
  margin-bottom: 1rem;
  color: var(--text);
  letter-spacing: -.01em;
}
.modal-card .form-actions { margin-top: 1rem; padding-top: 1rem; }

/* ══════════════════════════════════════════════════════════
   LOGIN PAGE
════════════════════════════════════════════════════════════ */
.login-body {
  min-height: 100vh;
  display: flex; align-items: center; justify-content: center;
  background: var(--green-900);
  background-image:
    radial-gradient(ellipse 80% 60% at 15% 60%, rgba(46,125,50,.25) 0%, transparent 70%),
    radial-gradient(ellipse 60% 40% at 85% 20%, rgba(76,175,80,.12) 0%, transparent 60%);
  padding: 1rem;
}

.login-card {
  background: var(--surface);
  border-radius: var(--radius-xl);
  padding: 2.5rem 2.25rem;
  width: 100%;
  max-width: 400px;
  box-shadow: var(--shadow-deep);
  text-align: center;
}

.login-logo {
  width: 60px; height: 60px;
  background: linear-gradient(145deg, var(--green-700), var(--green-500));
  border-radius: 14px;
  display: flex; align-items: center; justify-content: center;
  margin: 0 auto 1rem;
  box-shadow: 0 4px 16px rgba(46,125,50,.35);
  font-size: 28px;
}
.login-logo svg { width: 28px; height: 28px; color: #fff; }

.login-title {
  font-size: 1.25rem;
  font-weight: 700;
  color: var(--text);
  letter-spacing: -.02em;
  margin-bottom: .3rem;
}
.login-subtitle {
  color: var(--text-muted);
  margin-bottom: 1.75rem;
  font-size: .84rem;
}

.login-form { text-align: left; }
.login-form .form-group { margin-bottom: 1rem; }

/* ══════════════════════════════════════════════════════════
   RESPONSIVE
════════════════════════════════════════════════════════════ */
@media (max-width: 768px) {
  .mobile-header { display: flex; }
  .sidebar {
    transform: translateX(-100%);
    transition: transform .25s ease;
    top: 0;
  }
  .sidebar.open { transform: translateX(0); }
  .main-content {
    margin-left: 0;
    padding: 1rem;
    padding-top: 3.75rem;
  }
  .kpi-grid { grid-template-columns: repeat(2, 1fr); }
  .chart-grid { grid-template-columns: 1fr; }
  .form-grid { grid-template-columns: 1fr; }
  .export-buttons { flex-direction: column; }
  .data-table { font-size: 12px; }
  .data-table th, .data-table td { padding: .5rem .6rem; }
  .page-header h1, .page-header h2 { font-size: 1.15rem; }
  .kpi-value { font-size: 1.4rem; }
  .kpi-card { padding: 1rem; }
  .kpi-icon { width: 34px; height: 34px; }
  .kpi-icon svg { width: 17px; height: 17px; }
}

@media (max-width: 400px) {
  .kpi-grid { grid-template-columns: 1fr 1fr; }
  .kpi-value { font-size: 1.2rem; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: .01ms !important;
    transition-duration: .01ms !important;
  }
}
