/* ─── Base ──────────────────────────────────────────────── */
:root {
  --bg:        #0f1117;
  --bg2:       #1a1d2e;
  --bg3:       #22253a;
  --border:    #2d3048;
  --text:      #e2e8f0;
  --text-muted:#8892a4;
  --primary:   #4361ee;
  --success:   #4cc9a0;
  --warning:   #f8961e;
  --danger:    #f72585;
  --info:      #4cc9f0;
  --purple:    #7209b7;
  --pink:      #f72585;
  --radius:    12px;
  --shadow:    0 4px 24px rgba(0,0,0,.35);
}

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

body {
  background: var(--bg);
  color: var(--text);
  font-family: 'Inter', system-ui, -apple-system, sans-serif;
  min-height: 100vh;
}

/* ─── Navbar ────────────────────────────────────────────── */
.navbar {
  background: rgba(26,29,46,.92) !important;
  backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--border);
  padding: .6rem 0;
}

.navbar-brand { font-size: 1.05rem; letter-spacing: -.3px; }
.nav-link { color: var(--text-muted) !important; font-size: .875rem; transition: color .15s; }
.nav-link:hover, .nav-link.active { color: var(--text) !important; }
.nav-link.active { position: relative; }
.nav-link.active::after {
  content: '';
  position: absolute;
  bottom: -4px; left: 50%; transform: translateX(-50%);
  width: 20px; height: 2px;
  background: var(--primary);
  border-radius: 2px;
}

/* ─── Layout ────────────────────────────────────────────── */
.main-content { padding-top: 72px; min-height: 100vh; }
.auth-page    { min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: 24px; }

/* ─── Auth card ─────────────────────────────────────────── */
.auth-card {
  background: var(--bg2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 36px 32px;
  width: 100%;
  max-width: 420px;
  box-shadow: var(--shadow);
}
.auth-logo { text-align: center; margin-bottom: 28px; }

/* ─── Avatar ────────────────────────────────────────────── */
.avatar-circle {
  width: 34px; height: 34px;
  background: linear-gradient(135deg, var(--primary), var(--purple));
  border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  font-weight: 700; font-size: .85rem; color: #fff;
  flex-shrink: 0;
}
.avatar-sm { width: 28px; height: 28px; font-size: .75rem; }

/* ─── Forms ─────────────────────────────────────────────── */
.form-control, .form-select, .input-group-text {
  background: var(--bg3) !important;
  border-color: var(--border) !important;
  color: var(--text) !important;
}
.form-control:focus, .form-select:focus {
  border-color: var(--primary) !important;
  box-shadow: 0 0 0 3px rgba(67,97,238,.2) !important;
}
.form-control::placeholder { color: var(--text-muted) !important; }

/* ─── Password requirements ─────────────────────────────── */
.req { font-size: .78rem; color: var(--text-muted); transition: color .2s; }
.req.text-success { color: var(--success) !important; }

/* ─── KPI cards ─────────────────────────────────────────── */
.kpi-card {
  background: var(--bg2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  display: flex;
  align-items: center;
  gap: 14px;
  transition: border-color .2s, transform .15s;
}
.kpi-card:hover { border-color: var(--primary); transform: translateY(-1px); }
.kpi-icon { font-size: 1.5rem; flex-shrink: 0; }
.kpi-value { font-size: 1.5rem; font-weight: 700; line-height: 1; }
.kpi-label { font-size: .72rem; text-transform: uppercase; letter-spacing: .05em; color: var(--text-muted); margin-top: 2px; }
.kpi-sub { font-size: .72rem; color: var(--text-muted); margin-top: 2px; }

/* ─── Filter bar ────────────────────────────────────────── */
.filter-bar {
  background: var(--bg2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
}
.filter-group {
  display: flex;
  flex-direction: column;
  gap: 4px;
}
.filter-label {
  font-size: 0.7rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .04em;
  color: var(--text-muted);
}
.filter-input {
  min-width: 160px;
  background: var(--bg3);
  border-color: var(--border);
  color: var(--text);
}
.filter-input:focus {
  background: var(--bg3);
  border-color: var(--primary);
  color: var(--text);
  box-shadow: 0 0 0 3px rgba(67,97,238,.15);
}
/* date picker icon color fix on dark theme */
input[type="date"]::-webkit-calendar-picker-indicator {
  filter: invert(0.7);
  cursor: pointer;
}

/* ─── Chart cards ───────────────────────────────────────── */
.chart-card {
  background: var(--bg2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}
.chart-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  padding: 16px 18px 12px;
  border-bottom: 1px solid var(--border);
}
.chart-title  { font-size: .9rem; font-weight: 600; margin-bottom: 2px; }
.chart-subtitle { font-size: .75rem; color: var(--text-muted); margin: 0; }
.chart-badge {
  font-size: .68rem; font-weight: 600;
  background: rgba(67,97,238,.15); color: var(--primary);
  border: 1px solid rgba(67,97,238,.3);
  border-radius: 20px; padding: 2px 9px;
  white-space: nowrap; flex-shrink: 0;
}
.chart-body { padding: 14px 18px; flex: 1; min-height: 0; position: relative; }
.chart-body canvas { display: block; width: 100% !important; }
.chart-body-lg { height: 380px; }
.chart-body-xl { height: 520px; }
.chart-stats {
  padding: 12px 18px;
  border-top: 1px solid var(--border);
  display: flex; flex-wrap: wrap; gap: 12px;
}
.chart-stat-item { font-size: .78rem; color: var(--text-muted); }
.chart-stat-item strong { color: var(--text); display: block; font-size: .95rem; }

/* ─── Stat cards (admin) ────────────────────────────────── */
.stat-card {
  background: var(--bg2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 18px;
  display: flex; align-items: center; gap: 14px;
}
.stat-icon {
  width: 44px; height: 44px; border-radius: 10px;
  display: flex; align-items: center; justify-content: center;
  font-size: 1.2rem; flex-shrink: 0;
}
.stat-value { font-size: 1.6rem; font-weight: 700; line-height: 1; }
.stat-label { font-size: .75rem; color: var(--text-muted); margin-top: 3px; }

/* ─── Tables ────────────────────────────────────────────── */
.table { color: var(--text); border-color: var(--border); }
.table > :not(caption) > * > * { background: transparent; border-color: var(--border); padding: .65rem .85rem; }
.table thead th { font-size: .75rem; text-transform: uppercase; letter-spacing: .05em; color: var(--text-muted); font-weight: 600; }
.table-hover tbody tr:hover > * { background: var(--bg3) !important; }
.card { background: var(--bg2); border-color: var(--border); border-radius: var(--radius); }
.card-header { background: var(--bg3); border-color: var(--border); padding: .85rem 1.1rem; font-size: .875rem; }

/* ─── Image gallery ─────────────────────────────────────── */
.img-pair {
  display: flex; flex-direction: column; gap: 10px;
  background: var(--bg3); border: 1px solid var(--border);
  border-radius: 10px; padding: 12px; font-size: .8rem;
}
.img-pair-imgs { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.img-pair-imgs img {
  width: 100%; aspect-ratio: 3/2; object-fit: cover;
  border-radius: 8px; border: 1px solid var(--border);
  background: var(--bg);
  cursor: zoom-in; transition: opacity .2s;
}
.img-pair-imgs img:hover { opacity: .85; }
.img-label { text-align: center; color: var(--text-muted); font-size: .7rem; margin-top: 2px; }
.img-meta { color: var(--text-muted); }
.img-meta strong { color: var(--text); }
.expired-badge { color: var(--warning); font-size: .7rem; }

.gallery-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(480px, 1fr));
  gap: 16px;
}

/* ─── Flash messages ────────────────────────────────────── */
.flash-wrap { position: sticky; top: 72px; z-index: 900; }

/* ─── Dropdown ──────────────────────────────────────────── */
.dropdown-menu {
  background: var(--bg2) !important;
  border-color: var(--border) !important;
  box-shadow: var(--shadow);
}
.dropdown-item { color: var(--text) !important; font-size: .875rem; }
.dropdown-item:hover { background: var(--bg3) !important; }
.dropdown-header { font-size: .75rem; color: var(--text-muted) !important; }
.dropdown-divider { border-color: var(--border) !important; }

/* ─── Buttons ───────────────────────────────────────────── */
.btn-primary { background: var(--primary); border-color: var(--primary); }
.btn-primary:hover { background: #3451d1; border-color: #3451d1; }

/* ─── Modals ────────────────────────────────────────────── */
.modal-content { background: var(--bg2); border-color: var(--border); }
.modal-header { border-color: var(--border); }
.modal-footer { border-color: var(--border); }

/* ─── Alerts ────────────────────────────────────────────── */
.alert-success { background: rgba(76,201,160,.12) !important; border-color: rgba(76,201,160,.3) !important; color: #4cc9a0 !important; }
.alert-danger   { background: rgba(247,37,133,.12) !important; border-color: rgba(247,37,133,.3) !important; color: #f72585 !important; }
.alert-warning  { background: rgba(248,150,30,.12) !important; border-color: rgba(248,150,30,.3) !important; color: #f8961e !important; }
.alert-info     { background: rgba(76,201,240,.12) !important; border-color: rgba(76,201,240,.3) !important; color: #4cc9f0 !important; }

/* ─── Color utilities ───────────────────────────────────── */
.text-purple { color: var(--purple) !important; }
.text-pink   { color: var(--pink) !important; }

/* ─── Machine badges ────────────────────────────────────── */
/* Bootstrap's bg-opacity-20/text-primary utilities resolve to a low-contrast
   pairing under data-bs-theme="dark" against this app's near-black custom
   backgrounds, so the badge text was effectively invisible. Explicit colors
   here guarantee readable contrast regardless of Bootstrap's color-mode vars. */
.machine-badge {
  background: rgba(67,97,238,.18);
  color: #8fa8ff;
  border: 1px solid rgba(67,97,238,.4);
  font-weight: 600;
}

/* ─── Spinner overlay ───────────────────────────────────── */
.chart-loading {
  position: absolute; inset: 0;
  display: flex; align-items: center; justify-content: center;
  background: rgba(26,29,46,.7); border-radius: 8px;
  font-size: .8rem; color: var(--text-muted); gap: 8px;
  pointer-events: none;
}

/* ─── Scrollbar ─────────────────────────────────────────── */
::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: var(--bg); }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: #404466; }

/* ─── Bootstrap tabs (dark theme override) ──────────────── */
.nav-tabs {
  border-bottom: 1px solid var(--border);
}
.nav-tabs .nav-link {
  color: var(--text-muted) !important;
  border: none;
  border-bottom: 2px solid transparent;
  border-radius: 0;
  padding: .55rem 1rem;
  font-size: .85rem;
  font-weight: 500;
  transition: color .15s, border-color .15s;
}
.nav-tabs .nav-link:hover {
  color: var(--text) !important;
  border-bottom-color: var(--border);
}
.nav-tabs .nav-link.active {
  color: var(--primary) !important;
  background: transparent;
  border-bottom-color: var(--primary);
}
.nav-tabs .nav-link.active::after { display: none; }
.tab-content { background: transparent; }

/* ─── Responsive ────────────────────────────────────────── */
@media (max-width: 576px) {
  .auth-card { padding: 24px 18px; }
  .kpi-value { font-size: 1.25rem; }
  .chart-body-lg { height: 280px; }
  .chart-body-xl { height: 380px; }
  .gallery-grid { grid-template-columns: 1fr; }
}
