:root {
  --primary-color: #2ecc71; /* Emerald Green */
  --primary-hover: #27ae60;
  --bg-color: #f8fafc;
  --surface-color: rgba(255, 255, 255, 0.7);
  --glass-border: rgba(255, 255, 255, 0.5);
  --text-dark: #2c3e50; /* Deep Charcoal */
  --text-light: #64748b;
  --success: #27ae60;
  --danger: #e74c3c;
  --warning: #f1c40f;
}

html, body {
  overflow-x: hidden;
  position: relative;
  width: 100%;
}

body {
  font-family: 'Inter', sans-serif;
  background: linear-gradient(135deg, #f0f7f4 0%, #e8eaed 100%);
  background-attachment: fixed;
  color: var(--text-dark);
  margin: 0;
  padding: 0;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

.glass-panel {
  background: var(--surface-color);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border: 1px solid var(--glass-border);
  box-shadow: 0 8px 32px 0 rgba(46, 204, 113, 0.07);
  border-radius: 16px;
}

/* Navigation & Header Overhaul */
header {
  padding: 0 2rem;
  height: 80px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin: 1rem 2rem;
  z-index: 1000;
  position: relative;
}

.logo-link {
  display: flex;
  align-items: center;
  gap: 12px;
  text-decoration: none;
  flex: 0 0 260px;
}

.logo-img {
  height: 64px;
  width: auto;
  filter: drop-shadow(0 2px 4px rgba(0,0,0,0.1));
  mix-blend-mode: multiply;
  border-radius: 8px;
}

header .logo {
  font-size: 1.6rem;
  font-weight: 800;
  background: linear-gradient(135deg, #2ecc71 0%, #27ae60 100%);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  margin: 0;
}

/* DESKTOP Navigation Section */
.desktop-nav-container {
  display: flex;
  flex: 1;
  justify-content: space-between;
  align-items: center;
  height: 100%;
}

@media (max-width: 768px) {
  .desktop-nav-container {
    display: none;
  }
}

nav.main-nav {
  flex: 1;
  display: flex;
  justify-content: center;
}

nav.main-nav ul {
  list-style: none;
  display: flex;
  align-items: center;
  gap: 0.5rem;
  margin: 0;
  padding: 0;
}

nav.main-nav a {
  text-decoration: none;
  color: var(--text-dark);
  font-weight: 600;
  font-size: 0.95rem;
  padding: 0.6rem 1rem;
  border-radius: 10px;
  transition: all 0.2s ease;
  display: block;
}

nav.main-nav a:hover:not(.dropbtn) {
  background: rgba(46, 204, 113, 0.08);
  color: var(--primary-color);
}

/* User Zone */
.user-zone {
  flex: 0 0 240px;
  display: flex;
  justify-content: flex-end;
}

/* Hamburger Menu Toggle */
.mobile-menu-toggle {
  display: none;
  background: none;
  border: none;
  cursor: pointer;
  padding: 0.5rem;
  z-index: 3000;
}

/* Mobile drawer: hidden by default on desktop */
.mobile-drawer {
  display: none;
}

/* Close button inside mobile drawer */
.mobile-drawer-close {
  position: absolute;
  top: 1.2rem;
  right: 1.5rem;
  background: none;
  border: none;
  cursor: pointer;
  font-size: 2rem;
  line-height: 1;
  color: var(--text-dark);
  z-index: 9100;
  padding: 0.5rem;
  transition: color 0.2s;
}
.mobile-drawer-close:hover {
  color: var(--primary-color);
}

.hamburger-box { width: 30px; height: 24px; display: inline-block; position: relative; }
.hamburger-inner { width: 100%; height: 2px; background-color: var(--primary-color); position: absolute; left: 0; top: 50%; transform: translateY(-50%); transition: all 0.3s; }
.hamburger-inner::before, .hamburger-inner::after { content: ""; width: 100%; height: 2px; background-color: var(--primary-color); position: absolute; transition: all 0.3s; }
.hamburger-inner::before { top: -8px; }
.hamburger-inner::after { top: 8px; }

.mobile-menu-toggle.active .hamburger-inner { background-color: transparent; }
.mobile-menu-toggle.active .hamburger-inner::before { top: 0; transform: rotate(45deg); background-color: var(--danger); }
.mobile-menu-toggle.active .hamburger-inner::after { top: 0; transform: rotate(-45deg); background-color: var(--danger); }

/* Professional Dropdown */
.dropdown {
  position: relative;
}

.dropdown-content {
  display: none;
  position: absolute;
  top: 100%;
  left: 50%;
  transform: translateX(-50%);
  min-width: 200px;
  background: white;
  backdrop-filter: blur(20px);
  border: 1px solid rgba(0,0,0,0.1);
  border-radius: 12px;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.15);
  padding: 0.5rem 0;
  z-index: 2000;
  margin-top: 0;
}

.dropdown-content::before {
  content: "";
  position: absolute;
  top: -20px;
  left: 0;
  width: 100%;
  height: 20px;
}

.dropdown:hover .dropdown-content {
  display: block;
}

.dropdown-content a {
  padding: 0.8rem 1.2rem !important;
  font-size: 0.9rem !important;
  color: var(--text-dark);
  border-radius: 0 !important;
  font-weight: 500 !important;
}

.dropdown-content a:hover {
  background: var(--primary-color) !important;
  color: #fff !important;
}

.user-profile-trigger {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  background: rgba(255,255,255,0.4);
  padding: 0.5rem 1rem;
  border-radius: 12px;
  border: 1px solid var(--glass-border);
  cursor: pointer;
  transition: all 0.2s ease;
}

.user-profile-trigger:hover {
  background: rgba(255,255,255,0.6);
  border-color: var(--primary-color);
}

.user-avatar {
  width: 34px;
  height: 34px;
  background: var(--primary-color);
  color: #fff;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: 0.85rem;
}

.user-meta {
  display: flex;
  flex-direction: column;
  line-height: 1.2;
}

.user-meta .username {
  font-weight: 700;
  font-size: 0.9rem;
}

.user-meta .institution {
  font-size: 0.7rem;
  color: var(--text-light);
  font-weight: 500;
}

.user-dropdown-content {
  right: 0 !important;
  left: auto !important;
  transform: none !important;
  min-width: 240px;
}

.dropdown:hover .user-dropdown-content {
  display: block;
}

.dropdown-header {
  padding: 1rem 1.2rem;
  border-bottom: 1px solid rgba(0,0,0,0.05);
  margin-bottom: 0.5rem;
}

.dropdown-header .label {
  font-size: 0.65rem;
  text-transform: uppercase;
  color: var(--text-light);
  font-weight: 700;
  letter-spacing: 0.5px;
}

.dropdown-header .value {
  font-size: 0.95rem;
  font-weight: 700;
  color: var(--primary-color);
}

/* Ensure the divider is clean */
.dropdown-divider {
  height: 1px;
  background: rgba(0,0,0,0.05);
  margin: 0.5rem 0;
}

/* Main Container */
main {
  flex: 1;
  padding: 2rem;
  max-width: 1200px;
  margin: 0 auto;
  width: 100%;
  box-sizing: border-box;
}

/* Dashboard Cards */
.dashboard-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
  gap: 1.5rem;
  margin-bottom: 2rem;
}

.stat-card {
  padding: 2rem;
  text-align: center;
  transition: transform 0.3s ease, box-shadow 0.3s ease;
  cursor: pointer;
  position: relative;
  overflow: hidden;
}

.stat-card:hover {
  transform: translateY(-5px);
  box-shadow: 0 12px 40px 0 rgba(99, 102, 241, 0.15);
}

.stat-card::before {
  content: "";
  position: absolute;
  top: 0; left: 0; width: 100%; height: 4px;
  background: var(--primary-color);
  opacity: 0;
  transition: opacity 0.3s ease;
}
.stat-card:hover::before { opacity: 1; }

.stat-card h3 { margin: 0; font-size: 1.1rem; color: var(--text-light); }
.stat-card p { margin: 0.5rem 0 0; font-size: 2.5rem; font-weight: 700; color: var(--text-dark); }

/* Tables */
.table-container {
  overflow-x: auto;
  padding: 1rem;
  margin-top: 2rem;
}

table {
  width: 100%;
  border-collapse: separate;
  border-spacing: 0;
  text-align: left;
}

th {
  padding: 1rem;
  color: var(--text-light);
  font-weight: 600;
  border-bottom: 2px solid rgba(0,0,0,0.05);
}

td {
  padding: 1rem;
  border-bottom: 1px solid rgba(0,0,0,0.05);
  transition: background 0.2s ease;
}

tr:hover td { background: rgba(255,255,255,0.4); }

/* Status Badges */
.badge {
  padding: 0.25rem 0.75rem;
  border-radius: 999px;
  font-size: 0.85rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}
.badge.pending, .badge.draft { background: var(--warning); color: #fff; }
.badge.approved, .badge.fulfilled { background: var(--success); color: #fff; }
.badge.rejected, .badge.cancelled { background: var(--danger); color: #fff; }

/* Forms */
.form-group { margin-bottom: 1.5rem; }
.form-group label { display: block; margin-bottom: 0.5rem; font-weight: 500; }
.form-input, .form-select {
  width: 100%; padding: 0.75rem;
  border: 1px solid var(--glass-border);
  border-radius: 8px;
  background: rgba(255,255,255,0.8);
  font-family: inherit;
  transition: all 0.3s ease;
  box-sizing: border-box;
}
.form-input:focus, .form-select:focus {
  outline: none; border-color: var(--primary-color);
  box-shadow: 0 0 0 3px rgba(99,102,241,0.2);
}

/* Buttons */
.btn {
  display: inline-block; padding: 0.75rem 1.5rem;
  border-radius: 8px; font-weight: 600; cursor: pointer;
  text-decoration: none; border: none; transition: all 0.2s ease;
}
.btn-primary { background: var(--primary-color); color: #fff; }
.btn-primary:hover { background: var(--primary-hover); transform: translateY(-2px); box-shadow: 0 4px 12px rgba(99,102,241,0.3); }

/* Actions */
.action-forms { display: flex; gap: 0.5rem; }
.btn-sm { padding: 0.4rem 0.8rem; font-size: 0.85rem; }
.btn-success { background: var(--success); color: #fff; }
.btn-danger { background: var(--danger); color: #fff; }

/* Micro animations */
@keyframes fadeIn { from { opacity: 0; transform: translateY(10px); } to { opacity: 1; transform: translateY(0); } }
.animate-fade-in { animation: fadeIn 0.5s ease forwards; }

.messages { padding: 0 2rem; }
.alert { padding: 1rem; border-radius: 8px; margin-bottom: 1rem; font-weight: 500; }
.alert-success { background: #d1fae5; color: #065f46; }
.alert-warning { background: #fee2e2; color: #991b1b; }

/* --- Mobile Responsiveness Overhaul --- */
@media (max-width: 768px) {
  header {
    height: 70px;
    margin: 0.5rem 1rem;
    padding: 0 1.5rem;
    flex-direction: row;
    justify-content: space-between;
    align-items: center;
  }
  
  header .logo-link {
    flex: none;
    gap: 8px;
  }

  header .logo-img {
    height: 38px;
  }
  
  header .logo {
    flex: none;
    font-size: 1.25rem;
  }

  .mobile-menu-toggle {
    display: block;
  }

  /* --- The New Full-Page Mobile Drawer --- */
  .mobile-drawer {
    display: block; /* Override global display:none for mobile */
    position: fixed;
    top: 0;
    left: 0;
    width: 100vw;
    height: 100vh;
    background: #ffffff;
    z-index: 9000; /* Sit above everything */
    transform: translateX(100%);
    transition: transform 0.4s cubic-bezier(0.16, 1, 0.3, 1);
    visibility: hidden;
    pointer-events: none;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
  }

  .mobile-drawer.active {
    transform: translateX(0);
    visibility: visible;
    pointer-events: auto;
  }

  .mobile-drawer-content {
    padding: 100px 2rem 5rem;
    display: flex;
    flex-direction: column;
    gap: 3rem;
    min-height: 100%;
    box-sizing: border-box;
  }

  .mobile-nav ul {
    list-style: none;
    padding: 0;
    margin: 0;
    display: flex;
    flex-direction: column;
    gap: 2rem;
  }

  .mobile-nav a {
    text-decoration: none;
    color: var(--text-dark);
    font-size: 1.5rem;
    font-weight: 700;
    display: block;
    transition: color 0.2s ease;
  }

  .mobile-nav a:hover {
    color: var(--primary-color);
  }

  /* Handle Dropdowns in Mobile (Flatten them) */
  .mobile-nav .dropdown-content {
    display: block;
    position: static;
    box-shadow: none;
    padding: 1rem 0 0 1.5rem;
    background: none;
    visibility: visible;
    opacity: 1;
    pointer-events: auto;
    transform: none;
  }

  .mobile-nav .dropdown-content a {
    font-size: 1.1rem;
    font-weight: 500;
    margin-bottom: 1rem;
    color: var(--text-light);
  }

  .mobile-nav .dropbtn {
    /* Match regular nav link style */
    font-size: 1.5rem;
    font-weight: 700;
    color: var(--text-dark);
    text-decoration: none;
    display: block;
    pointer-events: none; /* Label only, not clickable */
    padding: 0;
    background: none;
    border: none;
    text-transform: none;
    letter-spacing: normal;
  }

  .mobile-lang-zone, .mobile-user-zone {
    border-top: 1px solid var(--glass-border);
    padding-top: 2rem;
  }

  body.menu-open {
    overflow: hidden; /* Prevent background scroll without position:fixed jump */
  }
  main {
    padding: 1rem;
  }
  
  .glass-panel {
    border-radius: 12px;
  }
  
  .dashboard-grid {
    grid-template-columns: 1fr;
  }
  
  div[style*="grid-template-columns: 1fr 1fr"], 
  div[style*="grid-template-columns:1fr 1fr"], 
  div[style*="grid-template-columns: 2fr 1fr"] {
    grid-template-columns: 1fr !important;
  }

  .messages {
    padding: 0 1rem;
  }

  .table-container {
    padding: 0.5rem;
    -webkit-overflow-scrolling: touch;
  }
  
  th, td {
    padding: 0.75rem 0.5rem;
    font-size: 0.9rem;
  }
  
  .btn {
    padding: 0.6rem 1rem;
  }

  /* --- BOQ Table → Card Layout on Mobile --- */
  #itemsTable thead {
    display: none; /* Hide the header row */
  }

  #itemsTable tr {
    display: block;
    background: rgba(255,255,255,0.6);
    border: 1px solid var(--glass-border);
    border-radius: 12px;
    padding: 1rem;
    margin-bottom: 1rem;
  }

  #itemsTable td {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.75rem;
    padding: 0.5rem 0;
    border-bottom: 1px solid rgba(0,0,0,0.05);
  }

  #itemsTable td:last-child {
    border-bottom: none;
    padding-top: 0.75rem;
    justify-content: flex-end;
  }

  /* Show data-label as the left label */
  #itemsTable td::before {
    content: attr(data-label);
    font-size: 0.75rem;
    font-weight: 700;
    color: var(--text-light);
    text-transform: uppercase;
    letter-spacing: 0.5px;
    flex: 0 0 auto;
    min-width: 80px;
  }

  #itemsTable td .form-input {
    flex: 1;
    min-width: 0;
  }

  #itemsTable td[data-label=" "]::before {
    display: none; /* No label for the remove button cell */
  }

  /* Autocomplete dropdown should still work in card layout */
  #itemsTable td[style*="position: relative"] {
    position: relative !important;
    flex-direction: column;
    align-items: stretch;
  }

  #itemsTable td[style*="position: relative"]::before {
    align-self: flex-start;
  }
}

/* --- Global Page Loader --- */
.global-loader {
  display: none; /* Hidden by default */
  position: fixed;
  top: 0;
  left: 0;
  width: 100vw;
  height: 100vh;
  background: rgba(255, 255, 255, 0.85);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  z-index: 9999;
  justify-content: center;
  align-items: center;
  flex-direction: column;
}

.spinner {
  width: 50px;
  height: 50px;
  border: 4px solid rgba(99, 102, 241, 0.2);
  border-top-color: var(--primary-color);
  border-radius: 50%;
  animation: spin 1s linear infinite;
  box-shadow: 0 0 20px rgba(99, 102, 241, 0.4);
}

.loader-text {
  margin-top: 1.5rem;
  font-weight: 700;
  color: var(--primary-color);
  font-size: 1.1rem;
  letter-spacing: 1px;
  animation: pulse 1.5s ease-in-out infinite;
}

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

@keyframes pulse {
  0%, 100% { opacity: 1; transform: scale(1); }
  50% { opacity: 0.7; transform: scale(0.95); }
}

/* ============================================================
   Custom Autocomplete Dropdown (BOQ Item Descriptions)
   ============================================================ */
.ac-dropdown {
  display: none;
  position: absolute;
  top: 100%;
  left: 0;
  right: 0;
  background: #fff;
  border: 1px solid var(--glass-border);
  border-radius: 0 0 10px 10px;
  box-shadow: 0 8px 24px rgba(0,0,0,0.12);
  z-index: 5000;
  max-height: 220px;
  overflow-y: auto;
}

.ac-item {
  padding: 10px 14px;
  cursor: pointer;
  font-size: 0.9rem;
  color: var(--text-dark);
  border-bottom: 1px solid rgba(0,0,0,0.04);
  transition: background 0.15s;
}

.ac-item:last-child {
  border-bottom: none;
  border-radius: 0 0 10px 10px;
}

.ac-item:hover, .ac-item.ac-active {
  background: rgba(99, 102, 241, 0.08);
  color: var(--primary-color);
}

.ac-item mark {
  background: rgba(99, 102, 241, 0.2);
  color: var(--primary-color);
  font-weight: 700;
  border-radius: 2px;
  padding: 0 2px;
}


/* ============================================================
   Attachment Cards
   ============================================================ */
.att-card {
  padding: 1rem;
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}

.att-preview {
  height: 140px;
  border-radius: 8px;
  overflow: hidden;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(0,0,0,0.04);
}

.att-icon-card {
  flex-direction: column;
  gap: 0.5rem;
}

.att-ext-badge {
  font-size: 0.65rem;
  font-weight: 800;
  letter-spacing: 1px;
  color: #fff;
  padding: 2px 8px;
  border-radius: 999px;
  text-transform: uppercase;
}

.att-filename {
  font-size: 0.8rem;
  font-weight: 600;
  word-break: break-all;
  color: var(--text-dark);
  margin: 0;
  line-height: 1.4;
}
