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

:root {
  /* Premium Brand Colors */
  --brand-navy: #22372C;
  --brand-gold: #B99A4B;
  --brand-green: #406A51;
  --brand-green-light: #5E826A;
  --brand-green-dark: #244735;
  
  /* UI Colors */
  --bg-color: #F7F7F2;
  --surface: rgba(255, 255, 255, 0.85);
  --surface-solid: #FFFFFF;
  --text-primary: #1F2937;
  --text-secondary: #4B5563;
  --border: rgba(0, 0, 0, 0.08);
  --danger: #EF4444;
  --success: #10B981;
  
  /* Effects */
  --shadow-sm: 0 4px 6px -1px rgba(0, 0, 0, 0.05), 0 2px 4px -1px rgba(0, 0, 0, 0.03);
  --shadow-md: 0 10px 15px -3px rgba(0, 0, 0, 0.08), 0 4px 6px -2px rgba(0, 0, 0, 0.04);
  --shadow-lg: 0 20px 25px -5px rgba(0, 0, 0, 0.08), 0 10px 10px -5px rgba(0, 0, 0, 0.04);
  --glass-blur: blur(16px);
  --radius-md: 12px;
  --radius-lg: 20px;
  --radius-xl: 28px;
  --transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background-color: var(--bg-color);
  background-image: 
    radial-gradient(at 0% 0%, rgba(27, 90, 65, 0.08) 0px, transparent 50%),
    radial-gradient(at 100% 0%, rgba(199, 146, 44, 0.08) 0px, transparent 50%),
    radial-gradient(at 100% 100%, rgba(11, 38, 81, 0.05) 0px, transparent 50%);
  background-attachment: fixed;
  color: var(--text-primary);
  font-family: 'Inter', sans-serif;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

a { color: var(--brand-green); text-decoration: none; transition: var(--transition); }
a:hover { color: var(--brand-gold); }

/* --- Forms & Buttons --- */
button, input, select, textarea { font: inherit; }

button {
  background: linear-gradient(135deg, var(--brand-green) 0%, var(--brand-green-dark) 100%);
  border: none;
  border-radius: var(--radius-md);
  color: white;
  padding: 12px 20px;
  font-weight: 600;
  cursor: pointer;
  box-shadow: var(--shadow-sm);
  transition: var(--transition);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
}
button:hover {
  transform: translateY(-2px);
  box-shadow: var(--shadow-md);
  background: linear-gradient(135deg, var(--brand-green-light) 0%, var(--brand-green) 100%);
}
button:active { transform: translateY(0); }

button.secondary { background: rgba(27, 90, 65, 0.1); color: var(--brand-green); box-shadow: none; }
button.secondary:hover { background: rgba(27, 90, 65, 0.15); }

button.danger { background: linear-gradient(135deg, #EF4444 0%, #DC2626 100%); }
button.danger:hover { background: linear-gradient(135deg, #F87171 0%, #EF4444 100%); }

button.ghost { background: transparent; color: var(--text-secondary); border: 1px solid var(--border); box-shadow: none; }
button.ghost:hover { background: rgba(0,0,0,0.03); color: var(--text-primary); }

button:disabled { opacity: 0.6; cursor: not-allowed; transform: none; box-shadow: none; }

input, select, textarea {
  width: 100%;
  background: var(--surface-solid);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 12px 16px;
  color: var(--text-primary);
  outline: none;
  transition: var(--transition);
  box-shadow: 0 1px 2px rgba(0,0,0,0.02) inset;
}
input:focus, select:focus, textarea:focus {
  border-color: var(--brand-gold);
  box-shadow: 0 0 0 4px rgba(199, 146, 44, 0.15);
}
textarea { min-height: 100px; resize: vertical; }

/* --- Glassmorphism Cards --- */
.glass-panel {
  background: var(--surface);
  backdrop-filter: var(--glass-blur);
  -webkit-backdrop-filter: var(--glass-blur);
  border: 1px solid rgba(255, 255, 255, 0.5);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-md);
}

/* --- Login Page --- */
.login-page { min-height: 100vh; display: grid; place-items: center; padding: 24px; }
.login-card {
  width: min(440px, 100%);
  padding: 40px;
  text-align: center;
  border-radius: var(--radius-xl);
}
.login-card img { width: 140px; margin-bottom: 24px; }
.login-card h1 { font-size: 28px; margin: 0 0 8px; font-weight: 800; color: var(--brand-navy); }
.login-card p { margin: 0 0 32px; color: var(--text-secondary); }
.form-stack { display: grid; gap: 20px; text-align: left; }
.form-stack label { display: grid; gap: 8px; font-weight: 600; font-size: 14px; color: var(--text-secondary); }
.error { display: none; color: var(--danger); font-size: 14px; font-weight: 600; padding: 12px; background: rgba(239, 68, 68, 0.1); border-radius: var(--radius-md); }
.error.show { display: block; animation: shake 0.4s ease-in-out; }

@keyframes shake {
  0%, 100% { transform: translateX(0); }
  25% { transform: translateX(-5px); }
  75% { transform: translateX(5px); }
}

/* --- Admin Layout --- */
.shell { min-height: 100vh; display: grid; grid-template-columns: 280px 1fr; }

/* Sidebar */
.sidebar {
  background: var(--brand-green-dark);
  color: white;
  padding: 32px 24px;
  position: sticky;
  top: 0;
  height: 100vh;
  display: flex;
  flex-direction: column;
}
.sidebar-logo {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 40px;
  padding-bottom: 24px;
  border-bottom: 1px solid rgba(255,255,255,0.1);
}
.sidebar-logo img { width: 48px; border-radius: 8px; background: white; padding: 4px; }
.sidebar-logo h2 { margin: 0; font-size: 18px; font-weight: 700; line-height: 1.2; }

.sidebar nav { display: grid; gap: 8px; flex: 1; }
.sidebar a, .sidebar button.nav-btn {
  display: flex;
  align-items: center;
  gap: 12px;
  background: transparent;
  color: rgba(255, 255, 255, 0.7);
  padding: 14px 16px;
  border-radius: var(--radius-md);
  font-weight: 600;
  transition: var(--transition);
  border: none;
  width: 100%;
  text-align: left;
}
.sidebar a:hover, .sidebar button.nav-btn:hover, .sidebar a.active {
  background: rgba(255, 255, 255, 0.1);
  color: white;
}
.sidebar a.active { border-left: 4px solid var(--brand-gold); }
.sidebar .small { font-size: 12px; color: rgba(255,255,255,0.5); margin-top: auto; text-align: center; }

/* Main Content */
.main { padding: 40px; max-width: 1600px; width: 100%; margin: 0 auto; }
.topbar { display: flex; align-items: center; justify-content: space-between; gap: 20px; margin-bottom: 32px; }
.topbar h1 { margin: 0; font-size: 32px; font-weight: 800; color: var(--brand-navy); letter-spacing: -0.02em; }
.topbar p { margin: 6px 0 0; color: var(--text-secondary); font-size: 16px; }
.actions { display: flex; gap: 12px; flex-wrap: wrap; }

/* Stats Grid */
.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 20px; margin-bottom: 32px; }
.stat-card {
  padding: 24px;
  position: relative;
  overflow: hidden;
}
.stat-card::after {
  content: '';
  position: absolute;
  top: 0; right: 0; width: 80px; height: 100%;
  background: linear-gradient(90deg, transparent, rgba(199, 146, 44, 0.05));
}
.stat-card span { display: block; color: var(--text-secondary); font-weight: 600; font-size: 14px; text-transform: uppercase; letter-spacing: 0.05em; }
.stat-card strong { display: block; font-size: 36px; font-weight: 800; color: var(--brand-navy); margin-top: 8px; line-height: 1; }

/* Panels */
.panel { padding: 24px; margin-bottom: 24px; }
.panel-title { display: flex; justify-content: space-between; align-items: center; margin-bottom: 20px; }
.panel-title h2 { margin: 0; font-size: 20px; font-weight: 700; color: var(--brand-navy); }
.filters { display: grid; grid-template-columns: 2fr 1.5fr auto auto; gap: 12px; margin-bottom: 20px; }
.import-row { display: grid; grid-template-columns: 1fr auto auto; gap: 12px; align-items: center; }

/* Table */
.table-wrap { overflow: auto; border: 1px solid var(--border); border-radius: var(--radius-md); background: var(--surface-solid); }
table { width: 100%; border-collapse: collapse; }
th, td { padding: 16px; border-bottom: 1px solid var(--border); text-align: left; }
th { 
  background: #F3F4F6; 
  color: var(--text-secondary); 
  font-size: 12px; 
  font-weight: 700; 
  text-transform: uppercase; 
  letter-spacing: 0.05em; 
  position: sticky; 
  top: 0;
}
td { font-size: 14px; color: var(--text-primary); }
td.notes { max-width: 300px; white-space: normal; color: var(--text-secondary); }
tr { transition: var(--transition); }
tr:hover { background: #F9FAFB; }
.badge { display: inline-block; padding: 4px 10px; background: rgba(199, 146, 44, 0.15); color: #9A6F1D; border-radius: 20px; font-weight: 700; font-size: 12px; }

.row-actions { display: flex; gap: 8px; }
.row-actions button, .row-actions a { padding: 8px 12px; font-size: 13px; border-radius: 8px; }
.row-actions button { background: #F3F4F6; color: var(--text-secondary); }
.row-actions button:hover { background: #E5E7EB; color: var(--text-primary); }
.row-actions a.view { background: rgba(27, 90, 65, 0.1); color: var(--brand-green); }
.row-actions a.view:hover { background: rgba(27, 90, 65, 0.15); }

/* --- Modal --- */
.modal {
  position: fixed; inset: 0; background: rgba(15, 23, 42, 0.6); backdrop-filter: blur(4px);
  display: none; align-items: center; justify-content: center; padding: 20px; z-index: 50;
  opacity: 0; transition: opacity 0.3s ease;
}
.modal.show { display: flex; opacity: 1; }
.modal-card {
  width: min(720px, 100%); background: var(--surface-solid); border-radius: var(--radius-xl);
  box-shadow: var(--shadow-lg); padding: 32px; transform: translateY(20px); transition: transform 0.3s ease;
}
.modal.show .modal-card { transform: translateY(0); }
.modal-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 24px; padding-bottom: 16px; border-bottom: 1px solid var(--border); }
.modal-head h2 { margin: 0; font-size: 24px; color: var(--brand-navy); font-weight: 800; }
.form-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 20px; }
.form-grid .full { grid-column: 1 / -1; }
.field label { display: block; margin-bottom: 8px; font-weight: 600; font-size: 14px; color: var(--text-secondary); }
.modal-actions { display: flex; justify-content: flex-end; gap: 12px; margin-top: 32px; padding-top: 24px; border-top: 1px solid var(--border); }

/* --- Public Item Page --- */
.item-page { min-height: 100vh; display: grid; place-items: center; padding: 24px; }
.item-card { width: min(800px, 100%); background: var(--surface-solid); border-radius: var(--radius-xl); box-shadow: var(--shadow-lg); overflow: hidden; }
.item-card header { background: var(--brand-green); padding: 24px; text-align: center; }
.item-card header img { height: 60px; object-fit: contain; }
.item-content { padding: 40px; }
.item-content h1 { margin: 0 0 24px; font-size: 36px; font-weight: 800; color: var(--brand-navy); border-bottom: 2px solid var(--border); padding-bottom: 16px; }
.details { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 16px; margin-bottom: 32px; }
.detail { background: var(--bg-color); border: 1px solid var(--border); border-radius: var(--radius-md); padding: 20px; transition: var(--transition); }
.detail:hover { transform: translateY(-2px); box-shadow: var(--shadow-sm); border-color: rgba(199, 146, 44, 0.3); }
.detail span { display: block; color: var(--text-secondary); font-weight: 600; font-size: 13px; text-transform: uppercase; letter-spacing: 0.05em; }
.detail strong { display: block; font-size: 24px; margin-top: 8px; color: var(--brand-navy); }
.detail.notes { grid-column: 1 / -1; }
.detail.notes strong { font-size: 18px; font-weight: 500; line-height: 1.6; }
.qr-line { display: grid; grid-template-columns: 200px 1fr; gap: 32px; align-items: center; background: #F8FAF9; padding: 24px; border-radius: var(--radius-lg); border: 1px dashed rgba(27, 90, 65, 0.3); }
.qr-line img { width: 100%; border-radius: var(--radius-md); background: white; padding: 12px; box-shadow: var(--shadow-sm); }
.qr-line .barcode-img { max-width: 320px; }
.qr-line p strong { color: var(--brand-navy); font-size: 18px; display: block; margin-bottom: 12px; }

/* --- Print Labels --- */
.print-page { background: #E5E7EB; margin: 0; min-height: 100vh; }
.print-toolbar { position: sticky; top: 0; z-index: 10; display: flex; gap: 12px; align-items: center; padding: 16px 24px; background: var(--surface-solid); border-bottom: 1px solid var(--border); box-shadow: var(--shadow-sm); }
.label-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(92mm, 1fr)); gap: 10mm; padding: 10mm; justify-content: center; }

/* Saudi Biochar official-label palette */
.print-card {
  width: 92mm;
  height: 118mm;
  border: 2mm solid #406A51; 
  background: #FFFFFF; 
  box-shadow: var(--shadow-md); 
  overflow: hidden; 
  break-inside: avoid;
  display: flex;
  flex-direction: column;
}
.label-head {
  height: 16mm;
  background: #406A51;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1.5mm;
  border-bottom: 0.8mm solid #B99A4B;
}
.label-head img { width: 100%; height: 11mm; object-fit: contain; }
.label-body {
  flex: 1;
  padding: 3mm;
  display: flex;
  flex-direction: column;
  background: linear-gradient(180deg, #FFFFFF 0%, #F7F7F2 100%);
}
.label-row {
  display: flex;
  align-items: center;
  margin-bottom: 1.2mm;
}
.label-row b {
  width: 20mm;
  font-size: 10pt;
  color: #244735;
  font-weight: 800;
  letter-spacing: 0.02em;
}
.label-row span {
  flex: 1;
  min-height: 6.5mm;
  background: rgba(64, 106, 81, 0.10);
  border: 0.35mm solid rgba(64, 106, 81, 0.24);
  border-radius: 1.5mm;
  display: flex;
  align-items: center;
  padding: 0 2.5mm;
  font-weight: 800;
  font-size: 10.5pt;
  color: #244735;
}
.label-row span small {
  margin-left: 1.5mm;
  font-size: 8pt;
  font-weight: 800;
  color: #406A51;
  line-height: 1;
}
.qr-box {
  margin-top: auto;
  align-self: center;
  width: 30mm;
  height: 33mm;
  border: 0.8mm solid #244735;
  border-radius: 1.5mm;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 1mm;
  background: #FFFFFF;
}
.qr-box img { width: 24mm; height: 24mm; margin-bottom: 0.8mm; }
.qr-box strong { font-size: 9.5pt; color: #244735; font-weight: 800; }

/* Responsive Media Queries */
@media(max-width: 1024px) {
  .shell { grid-template-columns: 240px 1fr; }
}
@media(max-width: 900px) {
  .shell { grid-template-columns: 1fr; }
  .sidebar { height: auto; position: relative; padding: 20px; }
  .sidebar nav { grid-template-columns: repeat(auto-fit, minmax(140px, 1fr)); }
  .main { padding: 20px; }
  .filters, .import-row { grid-template-columns: 1fr; }
  .form-grid { grid-template-columns: 1fr; }
  .qr-line { grid-template-columns: 1fr; text-align: center; }
  .qr-line img { margin: 0 auto; max-width: 200px; }
  .topbar { flex-direction: column; align-items: flex-start; }
}

/* Print Specific Rules */
@media print {
  @page { size: A4; margin: 0; }
  body { background: white; -webkit-print-color-adjust: exact; print-color-adjust: exact; }
  .print-toolbar { display: none; }
  .label-grid { padding: 4mm; gap: 4mm; grid-template-columns: repeat(2, 92mm); justify-content: start; }
  .print-card { box-shadow: none; margin-bottom: 4mm; }
}

/* ===== FORCE ONE LABEL PER PAGE — print only ===== */
@media print {
  @page { size: 100mm 150mm; margin: 0; }
  html, body { margin: 0 !important; padding: 0 !important; }
  .print-toolbar { display: none !important; }
  .label-grid {
    display: block !important;
    grid-template-columns: none !important;
    width: 100% !important;
    gap: 0 !important;
  }
  .print-card,
  .label-card,
  .label-item,
  .label,
  .label-grid > * {
    page-break-after: always !important;
    break-after: page !important;
    page-break-inside: avoid !important;
    break-inside: avoid !important;
    display: block !important;
    width: 100mm !important;
    height: 150mm !important;
    box-sizing: border-box !important;
    overflow: hidden !important;
    margin: 0 !important;
  }
  .print-card:last-child,
  .label-card:last-child,
  .label-item:last-child,
  .label:last-child,
  .label-grid > *:last-child {
    page-break-after: auto !important;
    break-after: auto !important;
  }
}

/* ===== CENTER LABEL ON PAGE (print only) ===== */
@media print {
  html, body, .label-grid {
    margin: 0 !important;
    padding: 0 !important;
    width: 92mm !important;
    background: #fff !important;
  }
  .label-grid {
    display: flex !important;
    flex-direction: column !important;
    align-items: center !important;
    justify-content: flex-start !important;
  }
  .print-card,
  .label-card,
  .label-item,
  .label,
  .label-grid > * {
    margin: 0 auto !important;
    padding: 0 !important;
    border: 0 !important;
    box-shadow: none !important;
    transform: none !important;
    float: none !important;
    position: relative !important;
    left: 0 !important;
    right: 0 !important;
    top: 0 !important;
  }
}
