/* Dashboard & Admin Portal Styles */

/* Reset body padding for dashboard layout */
body.dashboard-body {
  padding: 0;
  margin: 0;
  min-height: 100vh;
}

/* Top Navigation Bar */
.top-nav {
  background: var(--primary);
  color: #fff;
  padding: 0 24px;
  height: 60px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  z-index: 100;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.15);
}

.nav-brand {
  display: flex;
  align-items: center;
  gap: 10px;
}

.nav-brand a {
  display: flex;
  align-items: center;
  gap: 8px;
  color: #fff;
  text-decoration: none;
}

.nav-logo {
  font-size: 28px;
}

.nav-title {
  font-size: 20px;
  font-weight: 700;
  color: #fff;
}

.nav-user {
  display: flex;
  align-items: center;
  gap: 16px;
  font-size: 14px;
}

.nav-link {
  color: rgba(255, 255, 255, 0.9);
  text-decoration: none;
  padding: 6px 12px;
  border-radius: 6px;
  transition: background 0.2s;
}

.nav-link:hover {
  background: rgba(255, 255, 255, 0.15);
}

.admin-badge {
  background: var(--success);
  color: #fff;
  padding: 3px 8px;
  border-radius: 4px;
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
}

/* Dashboard Layout */
.dashboard-layout {
  display: flex;
  min-height: 100vh;
  padding-top: 60px; /* Account for fixed nav */
}

/* Sidebar */
.sidebar {
  width: 240px;
  background: var(--panel);
  border-right: 1px solid var(--border);
  position: fixed;
  top: 60px;
  left: 0;
  bottom: 0;
  display: flex;
  flex-direction: column;
  z-index: 50;
}

.sidebar-nav {
  flex: 1;
  padding: 16px 12px;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.nav-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 16px;
  border-radius: 8px;
  color: var(--text);
  text-decoration: none;
  font-size: 14px;
  font-weight: 500;
  transition: all 0.2s;
}

.nav-item:hover {
  background: var(--bg);
}

.nav-item.active {
  background: var(--primary);
  color: #fff;
}

.nav-icon {
  font-size: 18px;
  width: 24px;
  text-align: center;
}

.nav-divider {
  height: 1px;
  background: var(--border);
  margin: 12px 0;
}

/* Security Badge */
.security-badge {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 16px;
  margin: 12px;
  background: #e8f5e9;
  border-radius: 8px;
  border: 1px solid #c8e6c9;
}

.security-icon {
  font-size: 24px;
}

.security-text {
  display: flex;
  flex-direction: column;
  font-size: 12px;
}

.security-text strong {
  color: #2e7d32;
  font-size: 13px;
}

.security-text span {
  color: #558b2f;
}

/* Main Content */
.main-content {
  flex: 1;
  margin-left: 240px;
  padding: 24px;
  background: var(--bg);
  min-height: calc(100vh - 60px);
}

/* View Management */
.view {
  display: none;
}

.view.active {
  display: block;
}

.view-header {
  margin-bottom: 24px;
}

.view-header h1 {
  text-align: left;
  margin: 0 0 8px 0;
  font-size: 28px;
}

.view-subtitle {
  color: var(--muted);
  margin: 0;
  font-size: 15px;
}

/* Stats Grid */
.stats-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 16px;
  margin-bottom: 24px;
}

.stat-card {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 20px;
  display: flex;
  align-items: center;
  gap: 16px;
}

.stat-icon {
  font-size: 32px;
  width: 56px;
  height: 56px;
  background: var(--bg);
  border-radius: 12px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.stat-content {
  display: flex;
  flex-direction: column;
}

.stat-value {
  font-size: 24px;
  font-weight: 700;
  color: var(--primary);
}

.stat-label {
  font-size: 13px;
  color: var(--muted);
}

/* Quick Actions */
.quick-actions {
  display: flex;
  gap: 12px;
}

.btn-large {
  padding: 14px 24px;
  font-size: 15px;
}

/* Card Header */
.card-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 16px;
}

.card-header h3 {
  margin: 0;
}

.card-link {
  color: var(--primary);
  text-decoration: none;
  font-size: 14px;
  font-weight: 500;
}

.card-link:hover {
  text-decoration: underline;
}

/* Tests List */
.tests-list {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.test-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 16px;
  background: var(--bg);
  border-radius: 8px;
  border: 1px solid var(--border);
  transition: all 0.2s;
}

.test-item:hover {
  border-color: var(--primary);
  box-shadow: 0 2px 8px rgba(0, 51, 102, 0.1);
}

.test-info {
  flex: 1;
}

.test-name {
  font-weight: 600;
  font-size: 15px;
  color: var(--text);
  margin-bottom: 4px;
}

.test-meta {
  font-size: 13px;
  color: var(--muted);
}

.test-actions {
  display: flex;
  gap: 8px;
}

.empty-state {
  text-align: center;
  color: var(--muted);
  padding: 40px 20px;
}

/* Search Bar */
.search-bar {
  display: flex;
  gap: 12px;
  flex-wrap: wrap;
}

.search-input {
  flex: 1;
  min-width: 200px;
}

.filter-select {
  width: 150px;
}

/* Settings */
.settings-row {
  display: flex;
  justify-content: space-between;
  padding: 16px 0;
  border-bottom: 1px solid var(--border);
}

.settings-row:last-child {
  border-bottom: none;
}

.settings-label {
  font-weight: 500;
  color: var(--muted);
}

.settings-value {
  font-weight: 500;
}

.settings-form {
  max-width: 400px;
}

.settings-form .form-group {
  margin-bottom: 16px;
}

.form-error {
  color: var(--danger);
  font-size: 14px;
  margin-bottom: 12px;
  min-height: 20px;
}

.form-success {
  color: var(--success);
  font-size: 14px;
  margin-bottom: 12px;
  min-height: 20px;
}

.danger-card {
  border-color: var(--danger);
  background: #fef2f2;
}

.danger-card h3 {
  color: var(--danger);
}

/* Mobile Bottom Navigation */
.mobile-nav {
  display: none;
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  background: var(--panel);
  border-top: 1px solid var(--border);
  padding: 8px 0;
  padding-bottom: max(8px, env(safe-area-inset-bottom));
  z-index: 100;
}

.mobile-nav-item {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  padding: 8px;
  color: var(--muted);
  text-decoration: none;
  font-size: 11px;
}

.mobile-nav-item.active {
  color: var(--primary);
}

.mobile-nav-icon {
  font-size: 20px;
}

/* Admin-specific styles */
.admin-only {
  color: #7c3aed;
}

.admin-only:hover {
  background: #f3e8ff;
}

/* Table styles for admin */
.data-table {
  width: 100%;
  border-collapse: collapse;
}

.data-table th,
.data-table td {
  padding: 12px 16px;
  text-align: left;
  border-bottom: 1px solid var(--border);
}

.data-table th {
  background: var(--bg);
  font-weight: 600;
  font-size: 13px;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.data-table tbody tr:hover {
  background: var(--bg);
}

.status-badge {
  display: inline-block;
  padding: 4px 10px;
  border-radius: 12px;
  font-size: 12px;
  font-weight: 500;
}

.status-active {
  background: #dcfce7;
  color: #166534;
}

.status-disabled {
  background: #fee2e2;
  color: #991b1b;
}

/* Loading state */
.loading {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 40px;
  color: var(--muted);
}

.loading::after {
  content: '';
  width: 24px;
  height: 24px;
  margin-left: 12px;
  border: 3px solid var(--border);
  border-top-color: var(--primary);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

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

/* Responsive */
@media (max-width: 1024px) {
  .stats-grid {
    grid-template-columns: repeat(2, 1fr);
  }
}

@media (max-width: 768px) {
  .sidebar {
    display: none;
  }
  
  .main-content {
    margin-left: 0;
    padding: 16px;
    padding-bottom: 80px; /* Space for mobile nav */
  }
  
  .mobile-nav {
    display: flex;
  }
  
  .stats-grid {
    grid-template-columns: 1fr 1fr;
    gap: 12px;
  }
  
  .stat-card {
    padding: 16px;
  }
  
  .stat-icon {
    font-size: 24px;
    width: 44px;
    height: 44px;
  }
  
  .stat-value {
    font-size: 20px;
  }
  
  .quick-actions {
    flex-direction: column;
  }
  
  .search-bar {
    flex-direction: column;
  }
  
  .filter-select {
    width: 100%;
  }
  
  .view-header h1 {
    font-size: 24px;
  }
  
  .test-item {
    flex-direction: column;
    align-items: flex-start;
    gap: 12px;
  }
  
  .test-actions {
    width: 100%;
  }
  
  .test-actions .btn {
    flex: 1;
  }
  
  .nav-user span:first-child {
    display: none;
  }
}

@media (max-width: 480px) {
  .stats-grid {
    grid-template-columns: 1fr;
  }
  
  .top-nav {
    padding: 0 16px;
  }
  
  .nav-title {
    font-size: 18px;
  }
}

/* Admin Dashboard specific */
.admin-stats-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 16px;
  margin-bottom: 24px;
}

.admin-stat-card {
  background: linear-gradient(135deg, var(--primary) 0%, #004d99 100%);
  color: #fff;
  border-radius: 12px;
  padding: 24px;
}

.admin-stat-card .stat-value {
  color: #fff;
  font-size: 32px;
}

.admin-stat-card .stat-label {
  color: rgba(255, 255, 255, 0.8);
}

@media (max-width: 1024px) {
  .admin-stats-grid {
    grid-template-columns: repeat(2, 1fr);
  }
}

@media (max-width: 480px) {
  .admin-stats-grid {
    grid-template-columns: 1fr;
  }
}

/* Toggle Switch */
.toggle-switch {
  position: relative;
  width: 48px;
  height: 26px;
  background: var(--border);
  border-radius: 13px;
  cursor: pointer;
  transition: background 0.3s;
}

.toggle-switch.active {
  background: var(--success);
}

.toggle-switch::after {
  content: '';
  position: absolute;
  top: 3px;
  left: 3px;
  width: 20px;
  height: 20px;
  background: #fff;
  border-radius: 50%;
  transition: transform 0.3s;
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.2);
}

.toggle-switch.active::after {
  transform: translateX(22px);
}

/* Charts placeholder */
.chart-container {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 24px;
  min-height: 300px;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--muted);
}

/* ===== Modal Styles ===== */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.5);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
  padding: 20px;
}

.modal-content {
  background: var(--panel);
  border-radius: 12px;
  width: 100%;
  max-width: 540px;
  max-height: 90vh;
  overflow-y: auto;
  box-shadow: 0 20px 40px rgba(0, 0, 0, 0.2);
}

.modal-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 20px 24px;
  border-bottom: 1px solid var(--border);
}

.modal-header h2 {
  margin: 0;
  font-size: 20px;
}

.modal-close {
  background: none;
  border: none;
  font-size: 28px;
  color: var(--muted);
  cursor: pointer;
  padding: 0;
  line-height: 1;
}

.modal-close:hover {
  color: var(--text);
}

.modal-content form {
  padding: 24px;
}

.modal-content .form-group {
  margin-bottom: 16px;
}

.modal-content label {
  display: block;
  font-size: 14px;
  font-weight: 500;
  margin-bottom: 6px;
}

.modal-content input,
.modal-content select,
.modal-content textarea {
  width: 100%;
  padding: 10px 12px;
  font-size: 15px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: #fff;
}

.modal-content textarea {
  resize: vertical;
  font-family: inherit;
}

.modal-content input:focus,
.modal-content select:focus,
.modal-content textarea:focus {
  outline: none;
  border-color: var(--primary);
}

.form-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
}

.modal-actions {
  display: flex;
  gap: 12px;
  justify-content: flex-end;
  margin-top: 24px;
  padding-top: 20px;
  border-top: 1px solid var(--border);
}

/* ===== Sites List Styles ===== */
.sites-list {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.site-card {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 16px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  transition: all 0.2s;
}

.site-card:hover {
  border-color: var(--primary);
  box-shadow: 0 2px 8px rgba(0, 51, 102, 0.08);
}

.site-info {
  flex: 1;
}

.site-name {
  font-size: 16px;
  font-weight: 600;
  color: var(--text);
  margin-bottom: 4px;
}

.site-address {
  font-size: 14px;
  color: var(--muted);
}

.site-meta {
  display: flex;
  align-items: center;
  gap: 16px;
  margin-top: 8px;
}

.site-calc-count {
  font-size: 13px;
  color: var(--muted);
  background: var(--panel);
  padding: 4px 10px;
  border-radius: 4px;
}

.site-actions {
  display: flex;
  gap: 8px;
}

.site-actions .btn {
  padding: 6px 12px;
  font-size: 13px;
}

/* Responsive modal */
@media (max-width: 600px) {
  .modal-content {
    max-width: 100%;
    margin: 10px;
  }
  
  .form-row {
    grid-template-columns: 1fr;
  }
  
  .modal-actions {
    flex-direction: column;
  }
  
  .modal-actions .btn {
    width: 100%;
  }
}

/* Site Detail View */
.site-info-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 16px;
}

.site-info-item {
  padding: 12px;
  background: var(--bg-card);
  border-radius: 6px;
}

.site-info-label {
  font-size: 12px;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.5px;
  margin-bottom: 4px;
}

.site-info-value {
  font-size: 15px;
  color: var(--text-primary);
}

.site-info-value.empty {
  color: var(--text-muted);
  font-style: italic;
}

/* Calculation Type Buttons */
.calc-type-buttons {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
  gap: 12px;
}

.calc-type-btn {
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 20px 16px;
  background: var(--bg-card);
  border: 2px solid var(--border);
  border-radius: 8px;
  text-decoration: none;
  transition: all 0.15s ease;
}

.calc-type-btn:hover {
  border-color: var(--primary);
  background: #f0f7ff;
}

.calc-type-icon {
  font-size: 28px;
  margin-bottom: 8px;
}

.calc-type-name {
  font-size: 13px;
  font-weight: 500;
  color: var(--text-primary);
  text-align: center;
}

.badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 24px;
  height: 24px;
  padding: 0 8px;
  background: var(--primary);
  color: white;
  border-radius: 12px;
  font-size: 12px;
  font-weight: 600;
}

@media (max-width: 600px) {
  .calc-type-buttons {
    grid-template-columns: repeat(2, 1fr);
  }
}

/* Global Site ID display */
.global-id-display {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 14px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 6px;
  font-family: 'SF Mono', Monaco, 'Courier New', monospace;
  font-size: 16px;
  font-weight: 600;
  color: var(--primary);
}

.global-id-hint {
  font-size: 12px;
  font-weight: 400;
  color: var(--muted);
  font-family: inherit;
}

.field-hint {
  display: block;
  font-size: 12px;
  color: var(--muted);
  margin-top: 4px;
}

/* Clients list */
.clients-list {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.client-card {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  padding: 16px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  cursor: pointer;
  transition: all 0.15s ease;
}

.client-card:hover {
  border-color: var(--primary);
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.08);
}

.client-info h4 {
  margin: 0 0 4px;
  font-size: 16px;
  font-weight: 600;
}

.client-contact {
  font-size: 14px;
  color: var(--muted);
}

.client-sites-count {
  font-size: 13px;
  color: var(--primary);
  margin-top: 8px;
}

.client-actions {
  display: flex;
  gap: 8px;
  align-items: center;
}

.client-card.inactive {
  opacity: 0.6;
}

.client-card.inactive:hover {
  opacity: 0.8;
}

.inactive-label {
  font-size: 12px;
  font-weight: normal;
  color: var(--muted);
}

/* ============================================
   LIST FILTERS (Search & Dropdowns)
   ============================================ */

.list-filters {
  display: flex;
  gap: 12px;
  padding: 16px 0;
  border-bottom: 1px solid var(--border);
  margin-bottom: 8px;
}

.search-input {
  flex: 1;
  padding: 10px 14px;
  font-size: 14px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--bg);
  color: var(--text);
}

.search-input:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(255, 107, 53, 0.1);
}

.search-input::placeholder {
  color: var(--muted);
}

.filter-select {
  padding: 10px 14px;
  font-size: 14px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--bg);
  color: var(--text);
  min-width: 140px;
  cursor: pointer;
}

.filter-select:focus {
  outline: none;
  border-color: var(--primary);
}

@media (max-width: 600px) {
  .list-filters {
    flex-direction: column;
  }
  
  .filter-select {
    width: 100%;
  }
}

/* ============================================
   DIRECTIONS BUTTON & MENU
   ============================================ */

.site-directions {
  position: relative;
  margin-top: 12px;
}

.btn-directions {
  background: var(--primary);
  color: #fff;
  border: none;
  padding: 10px 20px;
  font-size: 14px;
  font-weight: 500;
  border-radius: 8px;
  cursor: pointer;
  transition: all 0.2s ease;
}

.btn-directions:hover {
  background: #e55a2b;
  transform: translateY(-1px);
}

.directions-menu {
  display: none;
  position: absolute;
  top: 100%;
  left: 0;
  margin-top: 8px;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 8px;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
  min-width: 160px;
  z-index: 100;
  overflow: hidden;
}

.directions-menu.show {
  display: block;
}

.directions-menu a {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 12px 16px;
  color: var(--text);
  text-decoration: none;
  font-size: 14px;
  transition: background 0.15s ease;
}

.directions-menu a:hover {
  background: var(--bg);
}

.directions-menu a span {
  font-size: 18px;
}

/* Site card enhancements */
.site-ids {
  display: flex;
  gap: 12px;
  margin-top: 4px;
  font-size: 12px;
}

.site-global-id {
  color: var(--primary);
  font-family: 'SF Mono', Monaco, 'Courier New', monospace;
  font-weight: 500;
}

.site-contractor-ref {
  color: var(--muted);
}

.site-client-name {
  color: var(--text-secondary);
  font-size: 13px;
  margin-top: 2px;
}

/* Form section headers */
.form-section-header {
  font-size: 13px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: var(--primary);
  margin: 20px 0 12px;
  padding-bottom: 6px;
  border-bottom: 1px solid var(--border);
}

