/* ===== VARIABLES ===== */
:root {
  --primary: #2d6a4f;
  --primary-dark: #1b4332;
  --primary-light: #40916c;
  --primary-hover: #245c44;
  --accent: #74c69d;
  --bg: #f4f7f5;
  --surface: #ffffff;
  --border: #dde5e0;
  --text: #1a2e1e;
  --text-muted: #6b7c72;
  --danger: #dc2626;
  --danger-hover: #b91c1c;
  --success: #16a34a;
  --warning: #d97706;
  --sidebar-width: 240px;
  --radius: 8px;
  --shadow: 0 1px 3px rgba(0,0,0,0.08), 0 1px 2px rgba(0,0,0,0.06);
  --shadow-md: 0 4px 6px rgba(0,0,0,0.07), 0 2px 4px rgba(0,0,0,0.06);
  --shadow-lg: 0 10px 25px rgba(0,0,0,0.12), 0 4px 10px rgba(0,0,0,0.08);
}

/* ===== RESET ===== */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html, body { height: 100%; font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif; font-size: 15px; color: var(--text); background: var(--bg); }
a { cursor: pointer; }
button { cursor: pointer; font-family: inherit; }
input, select, textarea { font-family: inherit; font-size: 15px; }

/* ===== UTILITIES ===== */
.hidden { display: none !important; }
.text-muted { color: var(--text-muted); }
.link { color: var(--primary); text-decoration: none; font-weight: 500; }
.link:hover { text-decoration: underline; }
.required { color: var(--danger); }
.optional { color: var(--text-muted); font-size: 13px; font-weight: 400; }

/* ===== LOGIN ===== */
.login-screen {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: linear-gradient(135deg, var(--primary-dark) 0%, var(--primary) 50%, var(--primary-light) 100%);
  padding: 20px;
}
.login-card {
  background: var(--surface);
  border-radius: 16px;
  padding: 40px;
  width: 100%;
  max-width: 400px;
  box-shadow: var(--shadow-lg);
}
.login-logo { font-size: 48px; text-align: center; margin-bottom: 12px; }
.login-title { font-size: 24px; font-weight: 700; text-align: center; color: var(--primary-dark); margin-bottom: 4px; }
.login-subtitle { text-align: center; color: var(--text-muted); margin-bottom: 28px; }

/* ===== APP LAYOUT ===== */
.app { display: flex; height: 100vh; overflow: hidden; }

/* ===== SIDEBAR ===== */
.sidebar {
  width: var(--sidebar-width);
  background: var(--primary-dark);
  display: flex;
  flex-direction: column;
  flex-shrink: 0;
  height: 100vh;
  overflow-y: auto;
  z-index: 100;
}
.sidebar-header {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 20px 16px 16px;
  border-bottom: 1px solid rgba(255,255,255,0.1);
}
.sidebar-logo { font-size: 24px; }
.sidebar-title { color: white; font-weight: 700; font-size: 15px; line-height: 1.2; }
.sidebar-nav { flex: 1; padding: 12px 8px; display: flex; flex-direction: column; gap: 2px; }
.nav-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  border-radius: var(--radius);
  color: rgba(255,255,255,0.75);
  text-decoration: none;
  font-size: 14px;
  font-weight: 500;
  transition: background 0.15s, color 0.15s;
}
.nav-item:hover { background: rgba(255,255,255,0.1); color: white; }
.nav-item.active { background: var(--primary-light); color: white; }
.nav-icon { font-size: 16px; width: 20px; text-align: center; }
.sidebar-footer {
  padding: 12px 16px;
  border-top: 1px solid rgba(255,255,255,0.1);
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.sidebar-user { display: flex; align-items: center; gap: 10px; }
.sidebar-user-avatar {
  width: 34px; height: 34px;
  background: var(--accent);
  border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  font-weight: 700; font-size: 14px; color: var(--primary-dark);
  flex-shrink: 0;
}
.sidebar-user-name { color: white; font-size: 13px; font-weight: 600; }
.sidebar-user-role { color: rgba(255,255,255,0.5); font-size: 12px; text-transform: capitalize; }
.sidebar-signout { width: 100%; justify-content: center; }

/* ===== MOBILE HEADER ===== */
.mobile-header {
  display: none;
  position: fixed;
  top: 0; left: 0; right: 0;
  height: 56px;
  background: var(--primary-dark);
  align-items: center;
  justify-content: space-between;
  padding: 0 16px;
  z-index: 200;
}
.mobile-title { color: white; font-weight: 700; font-size: 16px; }
.mobile-menu-btn { background: none; border: none; color: white; font-size: 22px; padding: 4px 8px; }
.sidebar-overlay {
  display: none;
  position: fixed; inset: 0;
  background: rgba(0,0,0,0.4);
  z-index: 99;
}

/* ===== MAIN CONTENT ===== */
.main-content {
  flex: 1;
  overflow-y: auto;
  padding: 28px;
  background: var(--bg);
}

/* ===== PAGE HEADER ===== */
.page-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 24px;
}
.page-header h2 { font-size: 22px; font-weight: 700; color: var(--primary-dark); }

/* ===== STATS ===== */
.stats-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 16px;
  margin-bottom: 24px;
}
.stat-card {
  background: var(--surface);
  border-radius: var(--radius);
  padding: 20px;
  box-shadow: var(--shadow);
  border-left: 4px solid var(--primary-light);
}
.stat-value { font-size: 32px; font-weight: 700; color: var(--primary-dark); line-height: 1; }
.stat-label { font-size: 13px; color: var(--text-muted); margin-top: 6px; font-weight: 500; }

/* ===== CARDS ===== */
.card {
  background: var(--surface);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  overflow: hidden;
  margin-bottom: 20px;
}
.card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 20px;
  border-bottom: 1px solid var(--border);
  font-weight: 600;
  font-size: 14px;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.05em;
}
.form-card { padding: 28px; }

/* ===== TABLES ===== */
.table-container { overflow-x: auto; }
.data-table { width: 100%; border-collapse: collapse; font-size: 14px; }
.data-table th {
  text-align: left;
  padding: 12px 16px;
  font-size: 12px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-muted);
  background: #f9fbfa;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}
.data-table td {
  padding: 12px 16px;
  border-bottom: 1px solid var(--border);
  vertical-align: top;
}
.data-table tbody tr:last-child td { border-bottom: none; }
.data-table tbody tr:hover { background: #f9fbfa; }
.description-cell { max-width: 300px; }

/* ===== BADGES ===== */
.badge {
  display: inline-block;
  padding: 3px 10px;
  border-radius: 20px;
  font-size: 12px;
  font-weight: 600;
  white-space: nowrap;
}
.badge-orange  { background: #fff3e0; color: #e65100; }
.badge-blue    { background: #e3f2fd; color: #1565c0; }
.badge-purple  { background: #f3e5f5; color: #6a1b9a; }
.badge-teal    { background: #e0f2f1; color: #00695c; }
.badge-yellow  { background: #fffde7; color: #f57f17; }
.badge-gray    { background: #f5f5f5; color: #616161; }
.badge-green   { background: #e8f5e9; color: #2e7d32; }
.badge-admin   { background: #fce4ec; color: #880e4f; }
.badge-user    { background: #e8f5e9; color: #1b5e20; }

/* ===== BUTTONS ===== */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 9px 18px;
  border-radius: var(--radius);
  border: none;
  font-size: 14px;
  font-weight: 600;
  text-decoration: none;
  transition: background 0.15s, opacity 0.15s, transform 0.1s;
  white-space: nowrap;
}
.btn:active { transform: scale(0.98); }
.btn:disabled { opacity: 0.6; cursor: not-allowed; }
.btn-primary { background: var(--primary); color: white; }
.btn-primary:hover:not(:disabled) { background: var(--primary-hover); }
.btn-secondary { background: white; color: var(--text); border: 1px solid var(--border); }
.btn-secondary:hover:not(:disabled) { background: #f5f5f5; }
.btn-danger { background: var(--danger); color: white; }
.btn-danger:hover:not(:disabled) { background: var(--danger-hover); }
.btn-ghost { background: transparent; color: rgba(255,255,255,0.7); border: 1px solid rgba(255,255,255,0.2); }
.btn-ghost:hover:not(:disabled) { background: rgba(255,255,255,0.1); color: white; }
.btn-sm { padding: 5px 12px; font-size: 13px; }
.btn-block { width: 100%; }

/* ===== FORMS ===== */
.form-group { display: flex; flex-direction: column; gap: 6px; margin-bottom: 20px; }
.form-group label { font-size: 14px; font-weight: 600; color: var(--text); }
.form-row { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
input[type="text"],
input[type="password"],
input[type="date"],
input[type="email"],
select,
textarea {
  padding: 10px 12px;
  border: 1.5px solid var(--border);
  border-radius: var(--radius);
  font-size: 14px;
  color: var(--text);
  background: white;
  transition: border-color 0.15s, box-shadow 0.15s;
  width: 100%;
}
input:focus, select:focus, textarea:focus {
  outline: none;
  border-color: var(--primary-light);
  box-shadow: 0 0 0 3px rgba(64, 145, 108, 0.15);
}
textarea { resize: vertical; }
.form-actions {
  display: flex;
  gap: 12px;
  justify-content: flex-end;
  padding-top: 8px;
  border-top: 1px solid var(--border);
  margin-top: 8px;
}

/* ===== FILTERS ===== */
.filter-row {
  display: flex;
  gap: 10px;
  padding: 16px 20px;
  border-bottom: 1px solid var(--border);
  flex-wrap: wrap;
  align-items: center;
  background: #f9fbfa;
}
.filter-select, .filter-input {
  padding: 8px 12px;
  border: 1.5px solid var(--border);
  border-radius: var(--radius);
  font-size: 14px;
  background: white;
  min-width: 150px;
}
.filter-input { min-width: 200px; }
.filter-select:focus, .filter-input:focus {
  outline: none;
  border-color: var(--primary-light);
}

/* ===== EQUIPMENT ===== */
.equipment-category-card { margin-bottom: 16px; }
.equipment-grid {
  padding: 12px 20px 16px;
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
  gap: 10px;
}
.equipment-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 14px;
  border: 1.5px solid var(--border);
  border-radius: var(--radius);
  background: #fafcfb;
  gap: 10px;
}
.equipment-name { font-weight: 600; font-size: 14px; }
.equipment-meta { font-size: 12px; color: var(--text-muted); margin-top: 2px; flex: 1; }
.equipment-actions { display: flex; gap: 6px; flex-shrink: 0; margin-top: 6px; }
.equipment-item:hover { background: #f0f7f3; border-color: var(--primary-light); }
.equipment-item { transition: background 0.15s, border-color 0.15s; }

/* ===== EQUIPMENT DETAIL ===== */
.equip-detail-header { display: flex; align-items: center; justify-content: space-between; flex-wrap: wrap; gap: 8px; }

/* ===== TABS ===== */
.tabs { display: flex; gap: 4px; margin-bottom: 20px; border-bottom: 2px solid var(--border); }
.admin-tab {
  padding: 10px 20px;
  border: none;
  background: none;
  font-size: 14px;
  font-weight: 600;
  color: var(--text-muted);
  border-bottom: 2px solid transparent;
  margin-bottom: -2px;
  transition: color 0.15s, border-color 0.15s;
}
.admin-tab:hover { color: var(--primary); }
.admin-tab.active { color: var(--primary); border-bottom-color: var(--primary); }

/* ===== ADMIN ACTIONS ===== */
.admin-section-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 16px;
}

/* ===== ALERTS ===== */
.alert {
  padding: 12px 16px;
  border-radius: var(--radius);
  font-size: 14px;
  margin-bottom: 20px;
}
.alert-danger { background: #fef2f2; color: #991b1b; border: 1px solid #fecaca; }
.alert-success { background: #f0fdf4; color: #166534; border: 1px solid #bbf7d0; }

/* ===== EMPTY STATE ===== */
.empty-state {
  text-align: center;
  color: var(--text-muted);
  padding: 48px 20px;
  font-size: 14px;
}

/* ===== MODAL ===== */
.modal-overlay {
  position: fixed; inset: 0;
  background: rgba(0,0,0,0.45);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
  padding: 20px;
}
.modal {
  background: white;
  border-radius: 12px;
  width: 100%;
  max-width: 460px;
  box-shadow: var(--shadow-lg);
  overflow: hidden;
}
.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 20px 24px 16px;
  border-bottom: 1px solid var(--border);
}
.modal-header h3 { font-size: 17px; font-weight: 700; }
.modal-close {
  background: none; border: none;
  font-size: 22px; color: var(--text-muted);
  width: 32px; height: 32px;
  display: flex; align-items: center; justify-content: center;
  border-radius: 6px;
}
.modal-close:hover { background: var(--bg); }
#modal-body { padding: 20px 24px 24px; }
.modal-actions { display: flex; gap: 10px; justify-content: flex-end; padding-top: 8px; margin-top: 8px; border-top: 1px solid var(--border); }

/* ===== TOAST ===== */
.toast {
  position: fixed;
  bottom: 24px; right: 24px;
  padding: 12px 20px;
  border-radius: var(--radius);
  font-size: 14px;
  font-weight: 500;
  box-shadow: var(--shadow-md);
  z-index: 2000;
  animation: slideUp 0.2s ease;
  max-width: 320px;
}
.toast-success { background: #166534; color: white; }
.toast-error { background: #991b1b; color: white; }
@keyframes slideUp { from { transform: translateY(12px); opacity: 0; } to { transform: translateY(0); opacity: 1; } }

/* ===== BRANDING ADMIN ===== */
.branding-layout { display: grid; grid-template-columns: 1fr 1fr; gap: 24px; align-items: start; }
.branding-form { margin-bottom: 0; }
.emoji-grid { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 10px; }
.emoji-btn {
  font-size: 22px; width: 44px; height: 44px;
  border: 2px solid var(--border); border-radius: var(--radius);
  background: white; transition: border-color 0.15s, transform 0.1s;
}
.emoji-btn:hover { border-color: var(--primary-light); transform: scale(1.1); }
.emoji-btn.active { border-color: var(--primary); background: #f0fdf4; }
.color-row { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; }
.color-swatches { display: flex; gap: 8px; flex-wrap: wrap; }
.color-swatch {
  width: 32px; height: 32px; border-radius: 50%;
  border: 3px solid transparent; cursor: pointer;
  transition: transform 0.1s, border-color 0.15s;
}
.color-swatch:hover { transform: scale(1.15); }
.color-swatch.active { border-color: var(--text); transform: scale(1.1); }
.custom-color-wrap {
  display: flex; flex-direction: column; align-items: center; gap: 4px;
  cursor: pointer; font-size: 12px; color: var(--text-muted);
}
.custom-color-wrap input[type="color"] {
  width: 36px; height: 36px; border: 2px solid var(--border);
  border-radius: 50%; padding: 2px; cursor: pointer; background: none;
}
.custom-color-label { font-size: 11px; color: var(--text-muted); }

/* Branding preview */
.branding-preview { position: sticky; top: 20px; }
.preview-label { font-size: 12px; font-weight: 600; color: var(--text-muted); text-transform: uppercase; letter-spacing: 0.05em; margin-bottom: 10px; }
.preview-card { border-radius: 12px; overflow: hidden; box-shadow: var(--shadow-md); display: flex; height: 280px; border: 1px solid var(--border); }
.preview-sidebar {
  width: 130px; flex-shrink: 0;
  background: var(--primary-dark);
  padding: 12px 8px;
  display: flex; flex-direction: column; gap: 8px;
  transition: background 0.3s;
}
.preview-header { display: flex; align-items: center; gap: 6px; padding: 4px; }
.preview-header span:first-child { font-size: 18px; }
.preview-header span:last-child { color: white; font-size: 11px; font-weight: 700; line-height: 1.2; }
.preview-nav-items { display: flex; flex-direction: column; gap: 3px; margin-top: 4px; }
.preview-nav { color: rgba(255,255,255,0.7); font-size: 10px; padding: 6px 8px; border-radius: 5px; }
.preview-nav.active { background: var(--primary-light); color: white; transition: background 0.3s; }
.preview-content { flex: 1; background: var(--bg); padding: 14px; display: flex; flex-direction: column; gap: 12px; }
.preview-stat-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.preview-stat { background: white; border-radius: 6px; padding: 10px; font-size: 11px; text-align: center; border-left: 3px solid var(--primary-light); }
.preview-stat strong { font-size: 18px; color: var(--primary-dark); display: block; }
.preview-btn { background: var(--primary); color: white; border-radius: 6px; padding: 8px 12px; font-size: 11px; font-weight: 700; text-align: center; transition: background 0.3s; }

@media (max-width: 900px) {
  .branding-layout { grid-template-columns: 1fr; }
  .branding-preview { position: static; }
}

/* ===== RESPONSIVE ===== */
@media (max-width: 768px) {
  .mobile-header { display: flex; }
  .sidebar-overlay { display: block; }

  .sidebar {
    position: fixed;
    left: -var(--sidebar-width);
    transform: translateX(-100%);
    transition: transform 0.25s ease;
    top: 0; bottom: 0;
  }
  .sidebar.open { transform: translateX(0); }
  .sidebar-overlay.open { display: block; }

  .main-content { padding: 16px; padding-top: 72px; }
  .stats-grid { grid-template-columns: repeat(2, 1fr); gap: 12px; }
  .form-row { grid-template-columns: 1fr; }
  .filter-row { gap: 8px; }
  .filter-select, .filter-input { min-width: 120px; flex: 1; }
  .page-header h2 { font-size: 18px; }
  .equipment-grid { grid-template-columns: 1fr; }
}

@media (max-width: 480px) {
  .stats-grid { grid-template-columns: 1fr 1fr; }
  .login-card { padding: 28px 20px; }
  .form-card { padding: 20px; }
}

/* Service alert card */
.service-alerts { margin-bottom: 20px; }
.alert-card { background: #fffbeb; border: 1px solid #fcd34d; border-radius: var(--radius); padding: 16px; margin-bottom: 12px; }
.alert-card.overdue { background: #fef2f2; border-color: #fca5a5; }
.alert-row { display: flex; align-items: center; gap: 10px; padding: 6px 0; border-bottom: 1px solid rgba(0,0,0,0.06); }
.alert-row:last-child { border-bottom: none; }
.badge-overdue { background: #fee2e2; color: #991b1b; padding: 2px 8px; border-radius: 4px; font-size: 11px; font-weight: 700; }
.badge-due-soon { background: #fef3c7; color: #92400e; padding: 2px 8px; border-radius: 4px; font-size: 11px; font-weight: 700; }
.badge-scheduled { background: #dcfce7; color: #166534; padding: 2px 8px; border-radius: 4px; font-size: 11px; font-weight: 700; }

/* Photo gallery */
.photo-gallery { display: flex; flex-wrap: wrap; gap: 10px; padding: 16px 0; }
.photo-thumb { position: relative; width: 120px; }
.photo-thumb img { width: 120px; height: 90px; object-fit: cover; border-radius: 6px; border: 1px solid var(--border); cursor: pointer; display: block; }
.photo-thumb .photo-caption { font-size: 11px; color: var(--text-muted); margin-top: 3px; text-align: center; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.photo-thumb .photo-delete { position: absolute; top: 3px; right: 3px; background: rgba(0,0,0,0.6); color: white; border: none; border-radius: 50%; width: 20px; height: 20px; font-size: 12px; display: flex; align-items: center; justify-content: center; cursor: pointer; line-height: 1; padding: 0; }
.photo-upload-btn { width: 120px; height: 90px; border: 2px dashed var(--border); border-radius: 6px; display: flex; flex-direction: column; align-items: center; justify-content: center; cursor: pointer; color: var(--text-muted); font-size: 12px; background: none; gap: 4px; }
.photo-upload-btn:hover { border-color: var(--primary); color: var(--primary); }

/* Photo drop zone on add-record form */
.photo-drop-zone { display: flex; align-items: center; gap: 10px; padding: 14px 16px; border: 2px dashed var(--border); border-radius: var(--radius); cursor: pointer; color: var(--text-muted); font-size: 13px; background: var(--bg); transition: border-color 0.15s, color 0.15s; }
.photo-drop-zone:hover { border-color: var(--primary); color: var(--primary); }
.photo-preview-strip { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 10px; }
.photo-preview-item { position: relative; }
.photo-preview-item img { width: 80px; height: 60px; object-fit: cover; border-radius: 6px; border: 1px solid var(--border); display: block; }
.photo-preview-remove { position: absolute; top: 2px; right: 2px; background: rgba(0,0,0,0.6); color: white; border: none; border-radius: 50%; width: 18px; height: 18px; font-size: 11px; display: flex; align-items: center; justify-content: center; cursor: pointer; padding: 0; line-height: 1; }

/* Record detail modal */
.record-row:hover td { background: var(--bg); }
.record-detail { display: flex; flex-direction: column; gap: 12px; }
.record-detail-meta { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; padding-bottom: 12px; border-bottom: 1px solid var(--border); }
.record-detail-row { display: flex; gap: 12px; font-size: 14px; }
.record-detail-label { color: var(--text-muted); min-width: 90px; font-size: 13px; }
.record-detail-description { background: var(--bg); border-radius: var(--radius); padding: 14px; font-size: 14px; line-height: 1.6; white-space: pre-wrap; word-break: break-word; }
.record-detail-photos-header { display: flex; align-items: center; gap: 10px; margin-top: 4px; }
.record-detail-photos-header strong { flex: 1; }
.reminder-status { display: flex; align-items: center; gap: 8px; margin-bottom: 12px; padding: 10px 14px; border-radius: var(--radius); }
.reminder-status.overdue { background: #fef2f2; }
.reminder-status.due-soon { background: #fffbeb; }
.reminder-status.scheduled { background: #f0fdf4; }

/* Print styles */
@media print {
  .sidebar, .mobile-header, .sidebar-overlay, .page-header button, #equip-detail-add-btn,
  .equipment-actions, .btn, .modal-overlay, #toast { display: none !important; }
  .main-content { margin: 0 !important; padding: 0 !important; }
  .card { box-shadow: none !important; border: 1px solid #ccc; }
  body { font-size: 12px; }
}
