/* ─── Variables — ScienceDirect Swapped (Blue primary, Orange secondary) ─────── */
:root {
  --bg:         #f5f5f5;
  --surface:    #ffffff;
  --border:     #e8e8e8;
  --accent:     #007398;   /* teal blue — primary */
  --accent2:    #FF6600;   /* orange — secondary */
  --danger:     #cc3300;
  --success:    #2e7d32;
  --text:       #333333;
  --muted:      #999999;
  --sidebar-w:  190px;
  --radius:     2px;
  font-family:  'Helvetica Neue', Arial, sans-serif;
}

/* ─── Reset ──────────────────────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
body { background: var(--bg); color: var(--text); font-size: 14px; min-height: 100vh; }

/* ─── Auth gate ──────────────────────────────────────────────────────────────── */
#auth-gate {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  background: linear-gradient(160deg, #004d63 0%, #007398 60%, #005f7a 100%);
}
.auth-logo {
  text-align: center;
  margin-bottom: 28px;
  display: flex;
  justify-content: center;
}
.auth-box {
  background: #ffffff;
  border: none;
  border-radius: 2px;
  border-top: 4px solid #007398;
  padding: 40px;
  width: 400px;
  box-shadow: 0 2px 16px rgba(0,0,0,0.15);
}

/* ─── App shell ──────────────────────────────────────────────────────────────── */
#app {
  display: flex;
  min-height: 100vh;
  border-top: 8px solid #007398;
}

/* ─── Sidebar ────────────────────────────────────────────────────────────────── */
#sidebar {
  width: var(--sidebar-w);
  min-width: var(--sidebar-w);
  background: #0d1f3c;
  border-right: none;
  display: flex;
  flex-direction: column;
  padding: 0 0 24px 0;
  position: sticky;
  top: 0;
  height: calc(100vh - 8px);
  overflow-y: auto;
}
.logo {
  padding: 16px 14px 14px;
  border-bottom: 1px solid rgba(255,255,255,0.1);
  background: #0d1f3c;
  display: flex;
  align-items: center;
}
#sidebar ul { list-style: none; padding: 10px 0; flex: 1; }
#sidebar ul li a {
  display: block;
  padding: 10px 16px;
  color: #8ba3c0;
  text-decoration: none;
  border-left: 3px solid transparent;
  font-size: 13px;
  transition: all 0.12s;
}
#sidebar ul li a:hover {
  color: #ffffff;
  background: rgba(0,115,152,0.15);
}
#sidebar ul li a.active {
  color: #ffffff;
  border-left-color: #007398;
  background: rgba(0,115,152,0.2);
  font-weight: 700;
}
.logout-link {
  display: block;
  padding: 10px 16px;
  color: #556680;
  text-decoration: none;
  font-size: 12px;
  transition: color 0.12s;
  border-left: 3px solid transparent;
}
.logout-link:hover { color: var(--danger); }
.account-badge {
  padding: 10px 16px;
  color: #556680;
  font-size: 11px;
  border-top: 1px solid rgba(255,255,255,0.08);
  margin-top: 8px;
  line-height: 1.6;
  word-break: break-all;
}
.account-badge strong { color: #ffffff; font-size: 12px; }

/* ─── Main area ──────────────────────────────────────────────────────────────── */
#main {
  flex: 1;
  padding: 28px 36px;
  min-height: 100%;
  overflow-y: auto;
  background: #f5f5f5;
}

/* ─── Pages ──────────────────────────────────────────────────────────────────── */
.page { display: none; }
.page.active { display: block; }

h2 {
  font-size: 22px;
  font-weight: 700;
  margin-bottom: 20px;
  color: #333333;
  padding-bottom: 8px;
  border-bottom: 3px solid #007398;
  display: inline-block;
}
h3 { font-size: 15px; margin: 20px 0 12px; color: #333333; font-weight: 700; }

.loading { color: var(--muted); padding: 12px 0; font-size: 13px; }

/* ─── Tabs ────────────────────────────────────────────────────────────────────── */
.tabs { display: flex; gap: 0; margin-bottom: 24px; border-bottom: 2px solid #e8e8e8; }
.tab {
  flex: 1;
  padding: 10px;
  background: transparent;
  border: none;
  border-bottom: 3px solid transparent;
  margin-bottom: -2px;
  color: #999999;
  cursor: pointer;
  transition: all 0.12s;
  font-family: inherit;
  font-size: 14px;
  font-weight: 600;
}
.tab.active { color: #007398; border-bottom-color: #007398; }
.tab:hover  { color: #007398; }

/* ─── Forms ──────────────────────────────────────────────────────────────────── */
.auth-form, #assign-form, #register-sensor-form {
  display: flex;
  flex-direction: column;
  gap: 16px;
}
label {
  display: flex;
  flex-direction: column;
  gap: 5px;
  color: #555555;
  font-size: 12px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}
input, select {
  background: #ffffff;
  border: 1px solid #cccccc;
  border-radius: var(--radius);
  color: var(--text);
  padding: 9px 12px;
  font-family: inherit;
  font-size: 14px;
  transition: border-color 0.12s, box-shadow 0.12s;
}
input:focus, select:focus {
  outline: none;
  border-color: #007398;
  box-shadow: 0 0 0 3px rgba(0,115,152,0.12);
}
button {
  padding: 10px 22px;
  background: #007398;
  color: #ffffff;
  border: none;
  border-radius: var(--radius);
  font-family: inherit;
  font-weight: 700;
  font-size: 13px;
  cursor: pointer;
  transition: background 0.12s;
}
button:hover { background: #005f7a; }
.error   { color: var(--danger); font-size: 12px; }
.success { color: var(--success); font-size: 12px; }
.hint    { color: var(--muted); font-size: 13px; margin-bottom: 16px; }
hr { border: none; border-top: 1px solid var(--border); margin: 24px 0; }

/* ─── Stat cards ─────────────────────────────────────────────────────────────── */
.stat-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(190px, 1fr));
  gap: 16px;
  margin-bottom: 28px;
}
.stat-card {
  background: #ffffff;
  border: 1px solid #e8e8e8;
  border-radius: var(--radius);
  padding: 18px;
  border-top: 4px solid #007398;
}
.stat-card .vendor { font-size: 10px; color: #aaaaaa; margin-bottom: 4px; letter-spacing: 1px; text-transform: uppercase; }
.stat-card .alias  { font-size: 13px; font-weight: 700; margin-bottom: 10px; color: #333333; }
.stat-card .val    { font-size: 28px; font-weight: 700; color: #007398; }
.stat-card .sub    { font-size: 10px; color: #aaaaaa; margin-top: 6px; }
.stat-card.no-data { border-top-color: #dddddd; }
.stat-card.no-data .val { color: #cccccc; font-size: 13px; }
.stat-card:nth-child(even) { border-top-color: #FF6600; }
.stat-card:nth-child(even) .val { color: #FF6600; }

/* ─── Section title ──────────────────────────────────────────────────────────── */
.section-title {
  font-size: 10px;
  color: #aaaaaa;
  text-transform: uppercase;
  letter-spacing: 1.5px;
  margin-bottom: 12px;
}

/* ─── Charts ─────────────────────────────────────────────────────────────────── */
canvas {
  background: #ffffff;
  border: 1px solid #e8e8e8;
  border-radius: var(--radius);
  padding: 16px;
  max-width: 100%;
}

/* ─── Plot controls ──────────────────────────────────────────────────────────── */
.plot-controls {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  margin-bottom: 14px;
  align-items: flex-end;
  background: #ffffff;
  border: 1px solid #e8e8e8;
  padding: 10px 14px;
  border-radius: var(--radius);
}
.plot-controls select,
.plot-controls input { flex: 1; min-width: 110px; }
.plot-controls button { flex: 0 0 70px; }

.plot-stats-row {
  display: flex;
  gap: 12px;
  margin-top: 14px;
  flex-wrap: wrap;
}
.plot-stat {
  background: #ffffff;
  border: 1px solid #e8e8e8;
  border-radius: var(--radius);
  padding: 10px 18px;
  flex: 1;
  min-width: 110px;
  text-align: center;
}
.plot-stat .label  { font-size: 10px; color: #aaaaaa; text-transform: uppercase; letter-spacing: 0.5px; }
.plot-stat .number { font-size: 20px; font-weight: 700; color: #007398; }

/* ─── Sensors table ──────────────────────────────────────────────────────────── */
table {
  width: 100%;
  border-collapse: collapse;
  background: #ffffff;
  border: 1px solid #e8e8e8;
  border-radius: var(--radius);
  overflow: hidden;
}
th {
  background: #007398;
  padding: 10px 16px;
  text-align: left;
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.8px;
  color: #ffffff !important;
  font-weight: 600;
}
td {
  padding: 11px 16px;
  border-top: 1px solid #f0f0f0;
  color: #333333;
  font-size: 13px;
}
tr:hover td { background: #fafafa; }
.badge {
  display: inline-block;
  padding: 2px 8px;
  background: #e6f3f7;
  color: #007398;
  border-radius: 2px;
  font-size: 11px;
  font-weight: 600;
}

.btn-sm {
  padding: 4px 12px;
  font-size: 11px;
  background: transparent;
  border: 1px solid #cccccc;
  color: #666666;
  border-radius: 2px;
  cursor: pointer;
}
.btn-sm:hover { background: #f5f5f5; }

/* ─── Admin panel ────────────────────────────────────────────────────────────── */
.admin-section {
  background: #ffffff;
  border: 1px solid #e8e8e8;
  border-radius: var(--radius);
  padding: 24px;
  margin-bottom: 24px;
}
.admin-section h3 { margin-top: 0; color: #007398; border-bottom: 2px solid #f0f0f0; padding-bottom: 10px; }

.form-row {
  display: flex;
  gap: 12px;
  flex-wrap: wrap;
  align-items: flex-end;
}
.form-row label { flex: 1; min-width: 150px; }
.form-row button { flex: 0 0 auto; align-self: flex-end; }

.checkbox-label {
  flex-direction: row !important;
  align-items: center;
  gap: 8px;
  color: #555555 !important;
  font-size: 13px !important;
  text-transform: none !important;
  letter-spacing: 0 !important;
  cursor: pointer;
}
.checkbox-label input[type="checkbox"] {
  width: 15px; height: 15px;
  accent-color: #007398;
  padding: 0;
  border: none;
}

.status-active   { color: var(--success); font-weight: 600; }
.status-inactive { color: var(--danger);  font-weight: 600; }

.tag-admin {
  display: inline-block;
  padding: 2px 8px;
  background: #e6f3f7;
  color: #007398;
  border-radius: 2px;
  font-size: 11px;
  font-weight: 600;
}
.tag-user {
  display: inline-block;
  padding: 2px 8px;
  background: #f5f5f5;
  color: #aaaaaa;
  border-radius: 2px;
  font-size: 11px;
}

.btn-activate   { border-color: #007398 !important; color: #007398 !important; }
.btn-deactivate { border-color: var(--danger) !important; color: var(--danger) !important; }
.btn-activate:hover   { background: #e6f3f7 !important; }
.btn-deactivate:hover { background: #fef0ed !important; }

/* Admin nav — orange accent */
#admin-nav-item a { color: #FF8833 !important; }
#admin-nav-item a:hover,
#admin-nav-item a.active {
  border-left-color: #FF6600 !important;
  background: rgba(255,102,0,0.15) !important;
  color: #FF8833 !important;
}

/* ─── Custom date picker ─────────────────────────────────────────────────────── */
.date-picker {
  display: flex;
  align-items: center;
  gap: 4px;
  background: #ffffff;
  border: 1px solid #cccccc;
  border-radius: var(--radius);
  padding: 4px 8px;
  flex: 1;
  min-width: 200px;
}
.date-picker:focus-within {
  border-color: #007398;
  box-shadow: 0 0 0 3px rgba(0,115,152,0.12);
}
.date-label {
  font-size: 11px;
  color: #999999;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  white-space: nowrap;
  margin-right: 4px;
}
.date-picker select {
  border: none;
  background: transparent;
  padding: 4px 2px;
  font-size: 13px;
  color: #333333;
  box-shadow: none;
  min-width: unset;
  flex: unset;
}
.date-picker select:focus {
  outline: none;
  border: none;
  box-shadow: none;
}

/* ─── Zoomable chart cursor ──────────────────────────────────────────────────── */
#plot-chart { cursor: grab; }
#plot-chart:active { cursor: grabbing; }

/* ════════════════════════════════════════════════════════════
   RESPONSIVE / MOBILE  (max-width: 768px)
════════════════════════════════════════════════════════════ */

/* ─── Hamburger button ───────────────────────────────────────────────────────── */
#hamburger {
  display: none;
  position: fixed;
  top: 12px;
  left: 12px;
  z-index: 1000;
  background: #0d1f3c;
  border: none;
  border-radius: 4px;
  padding: 8px 10px;
  cursor: pointer;
  flex-direction: column;
  gap: 5px;
  box-shadow: 0 2px 8px rgba(0,0,0,0.3);
}
#hamburger span {
  display: block;
  width: 22px;
  height: 2px;
  background: #ffffff;
  border-radius: 2px;
  transition: all 0.2s;
}
#hamburger.open span:nth-child(1) { transform: translateY(7px) rotate(45deg); }
#hamburger.open span:nth-child(2) { opacity: 0; }
#hamburger.open span:nth-child(3) { transform: translateY(-7px) rotate(-45deg); }

/* ─── Overlay behind open sidebar ───────────────────────────────────────────── */
#sidebar-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.5);
  z-index: 900;
}
#sidebar-overlay.visible { display: block; }

@media (max-width: 768px) {

  /* Show hamburger */
  #hamburger { display: flex; }

  /* Auth box full width on mobile */
  .auth-box {
    width: 94vw;
    padding: 28px 20px;
    margin: 0 3vw;
  }
  .auth-logo svg { width: 220px; height: auto; }

  /* App shell stacks vertically */
  #app {
    flex-direction: column;
    border-top: 4px solid #007398;
  }

  /* Sidebar slides in from left as drawer */
  #sidebar {
    position: fixed;
    top: 0;
    left: 0;
    height: 100vh;
    width: 240px;
    z-index: 950;
    transform: translateX(-100%);
    transition: transform 0.25s ease;
    box-shadow: 4px 0 16px rgba(0,0,0,0.3);
  }
  #sidebar.open {
    transform: translateX(0);
  }

  /* Main content full width, top padding for hamburger */
  #main {
    padding: 60px 16px 24px;
    width: 100%;
  }

  /* Page heading smaller */
  h2 { font-size: 18px; margin-bottom: 16px; }

  /* Stat cards single column */
  .stat-grid {
    grid-template-columns: 1fr 1fr;
    gap: 10px;
    margin-bottom: 20px;
  }
  .stat-card .val { font-size: 22px; }

  /* Plot controls stack vertically */
  .plot-controls {
    flex-direction: column;
    gap: 8px;
    padding: 12px;
  }
  .plot-controls select,
  .plot-controls button,
  .plot-controls .date-picker { width: 100%; flex: unset; }

  /* Date pickers stack */
  .date-picker { min-width: unset; }

  /* Chart height smaller on mobile */
  #plot-chart { height: 220px !important; }
  canvas { padding: 8px; }

  /* Plot stats wrap to 2 per row */
  .plot-stats-row { gap: 8px; }
  .plot-stat { min-width: calc(50% - 4px); padding: 8px 12px; }
  .plot-stat .number { font-size: 16px; }

  /* Tables scroll horizontally */
  table { display: block; overflow-x: auto; white-space: nowrap; }

  /* Admin form rows stack */
  .form-row { flex-direction: column; }
  .form-row label { min-width: unset; width: 100%; }

  /* Section title smaller */
  .section-title { font-size: 9px; }

  /* Overview chart height */
  #overview-chart { height: 180px !important; }

  /* Reset zoom button */
  #reset-zoom-btn { width: 100%; margin-top: 8px; }
}

@media (max-width: 400px) {
  .stat-grid { grid-template-columns: 1fr; }
  .plot-stat { min-width: 100%; }
}
