/*
  app.css — ElectroDB responsive styles (mobile-first)
*/

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

:root {
  --brand: #2563eb;
  --brand-dark: #1d4ed8;
  --bg: #f8fafc;
  --surface: #ffffff;
  --border: #e2e8f0;
  --text: #1e293b;
  --text-muted: #64748b;
  --success: #16a34a;
  --warning: #d97706;
  --danger: #dc2626;
  --radius: 8px;
  --shadow: 0 1px 3px rgba(0,0,0,0.08);
  --sidenav-w: 220px;
}

body {
  font-family: 'Inter', system-ui, -apple-system, sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 14px;
  line-height: 1.5;
}

.hidden { display: none !important; }

/* ── AUTH ─────────────────────────────────────────────────────────────────── */

.auth-screen {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: linear-gradient(135deg, #1e293b 0%, #0f172a 100%);
  padding: 20px;
}
.auth-card {
  background: var(--surface);
  border-radius: 12px;
  padding: 40px 32px;
  width: 100%;
  max-width: 380px;
  box-shadow: 0 20px 60px rgba(0,0,0,0.3);
}
.auth-logo {
  font-size: 28px;
  font-weight: 700;
  text-align: center;
  margin-bottom: 4px;
}
.auth-sub {
  text-align: center;
  color: var(--text-muted);
  margin-bottom: 24px;
  font-size: 13px;
}
.auth-card input {
  width: 100%;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-size: 14px;
  margin-bottom: 12px;
  outline: none;
  transition: border-color 0.15s;
}
.auth-card input:focus { border-color: var(--brand); }
.auth-toggle { text-align: center; margin-top: 16px; font-size: 13px; color: var(--text-muted); }
.auth-toggle a { color: var(--brand); text-decoration: none; font-weight: 500; }
.auth-error { color: var(--danger); text-align: center; margin-top: 12px; font-size: 13px; min-height: 20px; }

/* ── BUTTONS ─────────────────────────────────────────────────────────────── */

.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 8px 16px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--text);
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.15s;
  text-decoration: none;
  white-space: nowrap;
}
.btn:hover { background: #f1f5f9; }
.btn-primary { background: var(--brand); color: #fff; border-color: var(--brand); }
.btn-primary:hover { background: var(--brand-dark); }
.btn-danger { background: var(--danger); color: #fff; border-color: var(--danger); }
.btn-danger:hover { opacity: 0.9; }
.btn-success { background: var(--success); color: #fff; border-color: var(--success); }
.btn-sm { padding: 5px 10px; font-size: 12px; }
.btn-full { width: 100%; justify-content: center; }

/* ── TOPBAR ──────────────────────────────────────────────────────────────── */

.topbar {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  height: 52px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  padding: 0 16px;
  z-index: 100;
  box-shadow: var(--shadow);
}
.topbar-brand { font-weight: 700; font-size: 16px; margin-left: 8px; }
.topbar-right { margin-left: auto; display: flex; align-items: center; gap: 12px; }
.user-email { font-size: 12px; color: var(--text-muted); }
.menu-toggle {
  background: none;
  border: none;
  font-size: 22px;
  cursor: pointer;
  padding: 4px 8px;
  border-radius: 4px;
}
.menu-toggle:hover { background: #f1f5f9; }

/* ── SIDENAV ─────────────────────────────────────────────────────────────── */

.sidenav {
  position: fixed;
  top: 52px;
  left: -260px;
  bottom: 0;
  width: var(--sidenav-w);
  background: var(--surface);
  border-right: 1px solid var(--border);
  padding: 12px 0;
  transition: left 0.25s ease;
  z-index: 90;
  overflow-y: auto;
}
.sidenav.open { left: 0; }
.nav-link {
  display: block;
  padding: 10px 20px;
  color: var(--text-muted);
  text-decoration: none;
  font-weight: 500;
  font-size: 14px;
  transition: all 0.15s;
  border-left: 3px solid transparent;
}
.nav-link:hover { color: var(--text); background: #f8fafc; }
.nav-link.active { color: var(--brand); border-left-color: var(--brand); background: #eff6ff; }
.nav-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.3);
  z-index: 80;
  display: none;
}
.nav-overlay.show { display: block; }

/* ── CONTENT ─────────────────────────────────────────────────────────────── */

.content {
  margin-top: 52px;
  padding: 20px 16px;
  min-height: calc(100vh - 52px);
}

/* ── MODAL ────────────────────────────────────────────────────────────────── */

.modal {
  position: fixed;
  inset: 0;
  z-index: 200;
  display: flex;
  align-items: center;
  justify-content: center;
}
.modal-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(0,0,0,0.4);
}
.modal-body {
  position: relative;
  background: var(--surface);
  border-radius: 12px;
  width: 90%;
  max-width: 560px;
  max-height: 85vh;
  overflow-y: auto;
  padding: 24px;
  box-shadow: 0 20px 60px rgba(0,0,0,0.2);
}
.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 16px;
}
.modal-header h2 { font-size: 18px; }
.modal-close {
  background: none;
  border: none;
  font-size: 24px;
  cursor: pointer;
  color: var(--text-muted);
  line-height: 1;
}

/* ── CARDS & TABLES ──────────────────────────────────────────────────────── */

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
  box-shadow: var(--shadow);
  margin-bottom: 16px;
}
.card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 12px;
  flex-wrap: wrap;
  gap: 8px;
}
.card-header h2 { font-size: 16px; font-weight: 600; }

.stat-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
  gap: 12px;
  margin-bottom: 20px;
}
.stat-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  text-align: center;
}
.stat-val { font-size: 28px; font-weight: 700; color: var(--brand); }
.stat-label { font-size: 12px; color: var(--text-muted); margin-top: 4px; }

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}
th, td {
  text-align: left;
  padding: 8px 10px;
  border-bottom: 1px solid var(--border);
}
th { background: #f8fafc; font-weight: 600; font-size: 12px; text-transform: uppercase; letter-spacing: 0.03em; color: var(--text-muted); }
tr:hover td { background: #f8fafc; }
.table-wrap { overflow-x: auto; }

/* ── FORMS ────────────────────────────────────────────────────────────────── */

.form-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: 12px;
}
.form-field label {
  display: block;
  font-size: 12px;
  font-weight: 600;
  color: var(--text-muted);
  margin-bottom: 4px;
  text-transform: uppercase;
  letter-spacing: 0.03em;
}
.form-field input,
.form-field select,
.form-field textarea {
  width: 100%;
  padding: 8px 10px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-size: 14px;
  font-family: inherit;
  outline: none;
  transition: border-color 0.15s;
}
.form-field input:focus,
.form-field select:focus,
.form-field textarea:focus { border-color: var(--brand); }
.form-field textarea { resize: vertical; min-height: 60px; }
.form-actions {
  display: flex;
  gap: 8px;
  justify-content: flex-end;
  margin-top: 16px;
}

/* ── BADGES ──────────────────────────────────────────────────────────────── */

.badge {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 12px;
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.03em;
}
.badge-active { background: #dcfce7; color: #166534; }
.badge-completed { background: #dbeafe; color: #1e40af; }
.badge-cancelled { background: #fee2e2; color: #991b1b; }
.badge-pending { background: #fef3c7; color: #92400e; }
.badge-in_progress { background: #e0e7ff; color: #3730a3; }
.badge-good { background: #dcfce7; color: #166534; }
.badge-fair { background: #fef3c7; color: #92400e; }
.badge-needs-repair { background: #fee2e2; color: #991b1b; }

/* ── SCAN ────────────────────────────────────────────────────────────────── */

.scan-result { padding: 12px; font-size: 14px; min-height: 40px; }
.scan-result .found { color: var(--success); }
.scan-result .not-found { color: var(--danger); }

/* ── TOOLBAR ─────────────────────────────────────────────────────────────── */

.toolbar {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  align-items: center;
  margin-bottom: 12px;
}
.toolbar input[type="search"] {
  flex: 1;
  min-width: 160px;
  padding: 8px 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-size: 14px;
  outline: none;
}
.toolbar input[type="search"]:focus { border-color: var(--brand); }
.toolbar select {
  padding: 8px 10px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-size: 13px;
  outline: none;
}

/* ── LOW STOCK ALERT ─────────────────────────────────────────────────────── */

.low-stock { color: var(--danger); font-weight: 600; }

/* ── CLICKABLE ROWS ──────────────────────────────────────────────────────── */

tr[data-id] { cursor: pointer; }

/* ── DESKTOP ─────────────────────────────────────────────────────────────── */

@media (min-width: 768px) {
  .menu-toggle { display: none; }
  .sidenav { left: 0; }
  .content { margin-left: var(--sidenav-w); padding: 24px 32px; }
  .nav-overlay { display: none !important; }
  .form-grid { grid-template-columns: 1fr 1fr; }
  .form-field.full { grid-column: 1 / -1; }
}

@media (min-width: 1024px) {
  .content { max-width: 1100px; }
}

/* ── PRINT ───────────────────────────────────────────────────────────────── */

@media print {
  .topbar, .sidenav, .nav-overlay, .toolbar, .btn { display: none !important; }
  .content { margin: 0; padding: 0; }
}

/* ── PERMISSIONS / ROLE BADGES ───────────────────────────────────────────── */

.nav-hidden { display: none !important; }

.role-badge {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 12px;
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.role-viewer { background: #e0e0e0; color: #616161; }
.role-field { background: #e3f2fd; color: #1565c0; }
.role-manager { background: #fff3e0; color: #e65100; }
.role-admin { background: #fce4ec; color: #c62828; }

.role-select {
  padding: 4px 8px;
  border: 1px solid #ddd;
  border-radius: 6px;
  font-size: 13px;
  cursor: pointer;
}
