/* ═══════════════════════════════════════════════════════════
   COCHLEA CAP WEB PORTAL — style.css
   ═══════════════════════════════════════════════════════════ */

/* ── Reset & Base ─────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --primary:       #0A5C45;
  --primary-light: #0D7A5B;
  --primary-dark:  #084A38;
  --accent:        #E8A84A;
  --danger:        #E85C5C;
  --danger-light:  #FDECEA;
  --success:       #4AE8A8;
  --bg:            #F7F9F8;
  --card-bg:       #FFFFFF;
  --card-border:   #D4E4DC;
  --text-primary:  #1A2E26;
  --text-muted:    #7A9088;
  --shadow-sm:     0 2px 8px rgba(10,92,69,0.06);
  --shadow-md:     0 8px 28px rgba(10,92,69,0.10);
  --shadow-lg:     0 16px 48px rgba(10,92,69,0.14);
  --radius-sm:     12px;
  --radius-md:     18px;
  --radius-lg:     24px;
  --radius-xl:     32px;
  --nav-h:         70px;
}

html { font-size: 16px; scroll-behavior: smooth; }

body {
  font-family: 'Plus Jakarta Sans', sans-serif;
  background: var(--bg);
  color: var(--text-primary);
  min-height: 100vh;
  -webkit-font-smoothing: antialiased;
}

.hidden { display: none !important; }

/* ═══════════════════════════════════════════════════════════
   AUTH PAGE
   ═══════════════════════════════════════════════════════════ */
.auth-page {
  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%);
  overflow: hidden;
  position: relative;
}

/* Background orbs */
.auth-bg { position: fixed; inset: 0; pointer-events: none; z-index: 0; }
.auth-orb {
  position: absolute;
  border-radius: 50%;
  filter: blur(80px);
  opacity: 0.18;
}
.auth-orb--1 { width: 500px; height: 500px; background: #4AE8A8; top: -150px; right: -100px; animation: drift 8s ease-in-out infinite alternate; }
.auth-orb--2 { width: 350px; height: 350px; background: #E8A84A; bottom: -80px; left: -80px; animation: drift 10s ease-in-out infinite alternate-reverse; }
.auth-orb--3 { width: 250px; height: 250px; background: #5C7CE8; top: 50%; left: 40%; animation: drift 12s ease-in-out infinite alternate; }

@keyframes drift {
  from { transform: translate(0,0) scale(1); }
  to   { transform: translate(30px, 20px) scale(1.08); }
}

.auth-wrapper {
  position: relative;
  z-index: 1;
  width: 100%;
  max-width: 440px;
  padding: 24px 20px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 32px;
}

/* Branding */
.auth-brand { text-align: center; }
.auth-logo {
  width: 76px; height: 76px;
  background: rgba(255,255,255,0.14);
  border: 2px solid rgba(255,255,255,0.26);
  border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  margin: 0 auto 18px;
  backdrop-filter: blur(8px);
  box-shadow: 0 8px 32px rgba(0,0,0,0.16);
}
.auth-title {
  font-size: 2rem;
  font-weight: 900;
  color: #fff;
  letter-spacing: -0.5px;
  margin-bottom: 6px;
}
.auth-subtitle {
  font-size: 0.875rem;
  color: rgba(255,255,255,0.65);
  font-weight: 500;
}

/* Card */
.auth-card {
  width: 100%;
  background: var(--card-bg);
  border-radius: var(--radius-xl);
  padding: 32px;
  box-shadow: var(--shadow-lg), 0 2px 0 rgba(255,255,255,0.08) inset;
}

/* Tab switcher */
.tab-switcher {
  display: grid;
  grid-template-columns: 1fr 1fr;
  background: var(--bg);
  border-radius: var(--radius-md);
  padding: 4px;
  position: relative;
  margin-bottom: 28px;
}
.tab-btn {
  position: relative;
  z-index: 1;
  border: none;
  background: transparent;
  font-family: inherit;
  font-size: 0.875rem;
  font-weight: 600;
  color: var(--text-muted);
  padding: 10px 16px;
  border-radius: 11px;
  cursor: pointer;
  transition: color 0.25s;
}
.tab-btn.active { color: var(--primary); }
.tab-indicator {
  position: absolute;
  top: 4px; left: 4px;
  width: calc(50% - 4px);
  height: calc(100% - 8px);
  background: var(--card-bg);
  border-radius: 11px;
  box-shadow: var(--shadow-sm);
  transition: transform 0.3s cubic-bezier(.34,1.56,.64,1);
}

/* Error box */
.error-box {
  display: flex;
  align-items: center;
  gap: 10px;
  background: var(--danger-light);
  border: 1px solid rgba(232,92,92,0.2);
  border-radius: var(--radius-sm);
  padding: 12px 14px;
  margin-bottom: 18px;
  font-size: 0.8125rem;
  color: var(--danger);
  font-weight: 500;
}

/* Inputs */
.input-group { margin-bottom: 16px; }
.input-group label {
  display: block;
  font-size: 0.8125rem;
  font-weight: 600;
  color: var(--text-muted);
  margin-bottom: 8px;
}
.input-wrap {
  position: relative;
  display: flex;
  align-items: center;
}
.input-icon {
  position: absolute;
  left: 14px;
  color: var(--primary);
  pointer-events: none;
  width: 18px; height: 18px;
}
.input-wrap input {
  width: 100%;
  background: var(--bg);
  border: 1.5px solid var(--card-border);
  border-radius: var(--radius-sm);
  padding: 13px 14px 13px 42px;
  font-family: inherit;
  font-size: 0.9375rem;
  color: var(--text-primary);
  outline: none;
  transition: border-color 0.2s, box-shadow 0.2s;
}
.input-wrap input:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(10,92,69,0.08);
}
.input-wrap input::placeholder { color: #B0C4BC; }
.pass-toggle {
  position: absolute; right: 12px;
  background: none; border: none; cursor: pointer;
  color: #B0C4BC; display: flex; align-items: center;
  transition: color 0.2s;
}
.pass-toggle:hover { color: var(--primary); }

/* Submit button */
.btn-primary {
  width: 100%;
  height: 52px;
  background: linear-gradient(135deg, var(--primary), var(--primary-light));
  border: none;
  border-radius: var(--radius-md);
  color: #fff;
  font-family: inherit;
  font-size: 1rem;
  font-weight: 800;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  transition: opacity 0.2s, transform 0.15s, box-shadow 0.2s;
  box-shadow: 0 6px 20px rgba(10,92,69,0.28);
  margin-bottom: 18px;
}
.btn-primary:hover { transform: translateY(-1px); box-shadow: 0 10px 28px rgba(10,92,69,0.35); }
.btn-primary:active { transform: translateY(0); }
.btn-primary:disabled { opacity: 0.65; cursor: not-allowed; transform: none; }

/* Spinner */
.spinner {
  width: 20px; height: 20px;
  border: 2.5px solid rgba(255,255,255,0.3);
  border-top-color: #fff;
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

.auth-footer-note {
  text-align: center;
  font-size: 0.75rem;
  color: var(--text-muted);
}

/* ═══════════════════════════════════════════════════════════
   DASHBOARD PAGE
   ═══════════════════════════════════════════════════════════ */
.dashboard-page { display: flex; flex-direction: column; height: 100vh; overflow: hidden; }

/* ── Top nav ─────────────────────────────────────────────── */
.topnav {
  height: var(--nav-h);
  background: linear-gradient(90deg, var(--primary-dark), var(--primary));
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 28px;
  box-shadow: 0 2px 16px rgba(10,92,69,0.22);
  flex-shrink: 0;
  z-index: 100;
}
.topnav__brand { display: flex; align-items: center; gap: 12px; }
.topnav__logo {
  width: 38px; height: 38px;
  background: rgba(255,255,255,0.14);
  border-radius: 10px;
  display: flex; align-items: center; justify-content: center;
}
.topnav__name {
  font-size: 1.0625rem;
  font-weight: 800;
  color: #fff;
  letter-spacing: -0.3px;
}
.live-badge {
  display: flex;
  align-items: center;
  gap: 6px;
  background: rgba(255,255,255,0.14);
  border-radius: 20px;
  padding: 4px 12px;
  font-size: 0.6875rem;
  font-weight: 800;
  color: #fff;
  letter-spacing: 1px;
}
.live-dot {
  width: 7px; height: 7px;
  background: var(--success);
  border-radius: 50%;
  animation: pulse-dot 1.6s ease-in-out infinite;
}
@keyframes pulse-dot {
  0%, 100% { opacity: 1; transform: scale(1); }
  50%       { opacity: 0.5; transform: scale(0.75); }
}

.topnav__right { display: flex; align-items: center; gap: 14px; }
.user-pill {
  display: flex; align-items: center; gap: 10px;
  background: rgba(255,255,255,0.12);
  border-radius: 20px;
  padding: 6px 14px 6px 6px;
}
.user-avatar {
  width: 30px; height: 30px;
  background: rgba(255,255,255,0.2);
  border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  font-size: 0.8125rem;
  font-weight: 700;
  color: #fff;
}
.user-pill span { font-size: 0.875rem; font-weight: 600; color: #fff; }
.btn-logout {
  display: flex; align-items: center; gap: 8px;
  background: rgba(255,255,255,0.1);
  border: 1px solid rgba(255,255,255,0.16);
  border-radius: var(--radius-sm);
  padding: 8px 14px;
  font-family: inherit;
  font-size: 0.8125rem;
  font-weight: 600;
  color: rgba(255,255,255,0.85);
  cursor: pointer;
  transition: background 0.2s;
}
.btn-logout:hover { background: rgba(255,255,255,0.18); }

/* ── Dashboard layout ─────────────────────────────────────── */
.dashboard-layout {
  display: grid;
  grid-template-columns: 340px 1fr;
  flex: 1;
  overflow: hidden;
}

/* ── Sidebar ─────────────────────────────────────────────── */
.sidebar {
  background: var(--bg);
  border-right: 1px solid var(--card-border);
  overflow-y: auto;
  padding: 20px;
  display: flex;
  flex-direction: column;
  gap: 16px;
}
.sidebar::-webkit-scrollbar { width: 4px; }
.sidebar::-webkit-scrollbar-thumb { background: var(--card-border); border-radius: 4px; }

.card {
  background: var(--card-bg);
  border-radius: var(--radius-md);
  border: 1px solid var(--card-border);
  box-shadow: var(--shadow-sm);
  padding: 18px;
}

/* Account card */
.account-card {
  display: flex;
  align-items: center;
  gap: 12px;
}
.account-card__avatar {
  width: 46px; height: 46px;
  background: linear-gradient(135deg, var(--primary), var(--primary-light));
  border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  font-size: 1.125rem;
  font-weight: 700;
  color: #fff;
  flex-shrink: 0;
}
.account-card__info { flex: 1; min-width: 0; }
.account-card__name {
  font-size: 0.9375rem;
  font-weight: 700;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.account-card__email {
  font-size: 0.75rem;
  color: var(--text-muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.status-badge {
  display: flex; align-items: center; gap: 5px;
  font-size: 0.6875rem;
  font-weight: 700;
  padding: 4px 10px;
  border-radius: 20px;
  white-space: nowrap;
}
.status-badge--online { background: rgba(74,232,168,0.12); color: #0A6644; }
.status-dot { width: 6px; height: 6px; background: var(--success); border-radius: 50%; }

/* Devices */
.section-label {
  font-size: 0.6875rem;
  font-weight: 800;
  color: var(--text-muted);
  letter-spacing: 1.2px;
  margin-bottom: 14px;
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.device-section { padding: 16px 18px; }
.device-row {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 0;
}
.device-row + .device-row { border-top: 1px solid var(--card-border); }
.device-icon {
  width: 36px; height: 36px;
  border-radius: 10px;
  display: flex; align-items: center; justify-content: center;
  flex-shrink: 0;
}
.device-icon--green { background: rgba(10,92,69,0.08); color: var(--primary); }
.device-icon--amber { background: rgba(232,168,74,0.1); color: var(--accent); }
.device-info { flex: 1; }
.device-name { display: block; font-size: 0.875rem; font-weight: 700; }
.device-status { font-size: 0.75rem; color: var(--success); font-weight: 600; }
.device-status--warn { color: var(--accent); }
.device-battery { display: flex; align-items: center; gap: 6px; }
.battery-bar { width: 40px; height: 6px; background: var(--card-border); border-radius: 4px; overflow: hidden; }
.battery-fill { height: 100%; background: var(--success); border-radius: 4px; transition: width 0.4s; }
.battery-fill--warn { background: var(--accent); }
.battery-pct { font-size: 0.6875rem; font-weight: 600; color: var(--text-muted); }

/* SOS feed */
.sos-card { padding: 16px 18px; flex: 1; display: flex; flex-direction: column; min-height: 0; }
.sos-count {
  background: var(--danger);
  color: #fff;
  font-size: 0.625rem;
  font-weight: 800;
  width: 18px; height: 18px;
  border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
}
.sos-feed { flex: 1; overflow-y: auto; display: flex; flex-direction: column; gap: 8px; }
.sos-feed::-webkit-scrollbar { width: 3px; }
.sos-empty {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 10px;
  padding: 24px;
  color: var(--text-muted);
  font-size: 0.8125rem;
}
.sos-item {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  padding: 12px;
  background: var(--danger-light);
  border-radius: var(--radius-sm);
  border-left: 3px solid var(--danger);
}
.sos-item--resolved {
  background: rgba(74,232,168,0.08);
  border-left-color: var(--success);
}
.sos-item__icon { flex-shrink: 0; margin-top: 1px; }
.sos-item__info { flex: 1; min-width: 0; }
.sos-item__title { display: block; font-size: 0.8125rem; font-weight: 700; color: var(--danger); }
.sos-item--resolved .sos-item__title { color: #0A6644; }
.sos-item__loc { font-size: 0.6875rem; color: var(--text-muted); }
.sos-item__meta { display: flex; flex-direction: column; align-items: flex-end; gap: 3px; flex-shrink: 0; }
.sos-item__time { font-size: 0.6875rem; color: var(--text-muted); white-space: nowrap; }
.sos-item__status { font-size: 0.625rem; font-weight: 700; color: var(--danger); white-space: nowrap; }
.sos-item--resolved .sos-item__status { color: #0A6644; }

/* ── Map section ─────────────────────────────────────────── */
.map-section {
  display: flex;
  flex-direction: column;
  background: var(--bg);
  overflow: hidden;
}
.map-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 18px 24px 12px;
  background: var(--card-bg);
  border-bottom: 1px solid var(--card-border);
  flex-shrink: 0;
}
.map-title { font-size: 1.125rem; font-weight: 800; }
.map-sub { font-size: 0.8125rem; color: var(--text-muted); margin-top: 2px; }
.map-actions { display: flex; align-items: center; gap: 12px; }
.conn-indicator {
  display: flex;
  align-items: center;
  gap: 7px;
  font-size: 0.8125rem;
  font-weight: 600;
}
.conn-dot { width: 8px; height: 8px; border-radius: 50%; background: var(--success); transition: background 0.3s; }
.btn-recenter {
  display: flex; align-items: center; gap: 7px;
  background: var(--card-bg);
  border: 1.5px solid var(--card-border);
  border-radius: var(--radius-sm);
  padding: 8px 14px;
  font-family: inherit;
  font-size: 0.8125rem;
  font-weight: 600;
  color: var(--primary);
  cursor: pointer;
  transition: background 0.2s, border-color 0.2s;
}
.btn-recenter:hover { background: rgba(10,92,69,0.04); border-color: var(--primary); }

.leaflet-map { flex: 1; min-height: 0; }

/* Leaflet popup override */
.leaflet-popup-content-wrapper {
  border-radius: var(--radius-sm) !important;
  font-family: 'Plus Jakarta Sans', sans-serif !important;
  box-shadow: var(--shadow-md) !important;
}

/* Pulsing device marker */
.pulse-marker { width: 40px; height: 40px; position: relative; }
.pulse-marker__dot {
  position: absolute; top: 50%; left: 50%;
  transform: translate(-50%, -50%);
  width: 16px; height: 16px;
  background: var(--primary);
  border-radius: 50%;
  border: 3px solid #fff;
  box-shadow: 0 2px 8px rgba(10,92,69,0.4);
  z-index: 2;
}
.pulse-marker__ring {
  position: absolute; top: 50%; left: 50%;
  transform: translate(-50%, -50%);
  width: 40px; height: 40px;
  border: 2px solid var(--primary);
  border-radius: 50%;
  animation: ring-pulse 2s ease-out infinite;
  opacity: 0;
}
@keyframes ring-pulse {
  0%   { transform: translate(-50%,-50%) scale(0.4); opacity: 0.8; }
  100% { transform: translate(-50%,-50%) scale(1.2); opacity: 0; }
}

/* SOS marker */
.sos-marker {
  width: 28px; height: 28px;
  background: var(--danger);
  border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  border: 2px solid #fff;
  box-shadow: 0 2px 10px rgba(232,92,92,0.5);
  animation: sos-pulse 1.2s ease-in-out infinite;
}
@keyframes sos-pulse {
  0%, 100% { transform: scale(1); }
  50%       { transform: scale(1.15); }
}

/* Stats bar */
.stats-bar {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  background: var(--card-bg);
  border-top: 1px solid var(--card-border);
  flex-shrink: 0;
}
.stat-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 14px 20px;
}
.stat-item + .stat-item { border-left: 1px solid var(--card-border); }
.stat-label { display: block; font-size: 0.6875rem; color: var(--text-muted); font-weight: 500; }
.stat-value { display: block; font-size: 0.875rem; font-weight: 700; margin-top: 2px; }
.stat-value--danger { color: var(--danger); }

/* ── Responsive ──────────────────────────────────────────── */
@media (max-width: 900px) {
  .dashboard-layout {
    grid-template-columns: 1fr;
    grid-template-rows: auto 1fr;
    overflow-y: auto;
  }
  .sidebar {
    overflow: visible;
    border-right: none;
    border-bottom: 1px solid var(--card-border);
    padding: 16px;
  }
  .sos-card { min-height: 200px; }
  .map-section { min-height: 70vh; }
  .leaflet-map { min-height: 300px; }
  .stats-bar { grid-template-columns: repeat(2, 1fr); }
  .stat-item:nth-child(3) { border-left: none; }
}

@media (max-width: 600px) {
  .topnav { padding: 0 16px; }
  .topnav__name { display: none; }
  .stats-bar { grid-template-columns: 1fr 1fr; }
  .auth-card { padding: 24px 20px; }
}
