/* style.css */
:root {
  --bg: #0e1117;
  --bg2: #161b27;
  --bg3: #1e2537;
  --border: #2a3247;
  --border-light: #344060;
  --text: #e8eaf2;
  --text2: #8b93b0;
  --text3: #525d7a;
  --accent: #4f8ef7;
  --accent-glow: rgba(79,142,247,0.15);
  --ok: #34d399;
  --ok-bg: rgba(52,211,153,0.1);
  --warn: #fbbf24;
  --warn-bg: rgba(251,191,36,0.1);
  --danger: #f87171;
  --danger-bg: rgba(248,113,113,0.1);
  --info: #60a5fa;
  --cold: #93c5fd;
  --cold-bg: rgba(147,197,253,0.1);
  --sidebar-w: 220px;
  --radius: 10px;
  --mono: 'DM Mono', monospace;
  --sans: 'DM Sans', sans-serif;
  --head: 'Syne', sans-serif;
}

* { margin: 0; padding: 0; box-sizing: border-box; }
body { font-family: var(--sans); background: var(--bg); color: var(--text); min-height: 100vh; font-size: 14px; }

.hidden { display: none !important; }

/* ─── LOGIN ─────────────────────────────────────────── */
.login-screen {
  position: fixed; inset: 0;
  display: flex; align-items: center; justify-content: center;
  background: var(--bg);
}
.login-box {
  background: var(--bg2); border: 1px solid var(--border);
  border-radius: 16px; padding: 40px; width: 360px;
  text-align: center;
}
.login-logo { font-size: 48px; margin-bottom: 16px; }
.login-title { font-family: var(--head); font-size: 24px; font-weight: 700; color: var(--text); margin-bottom: 4px; }
.login-sub { color: var(--text2); font-size: 13px; margin-bottom: 28px; }
.login-error { color: var(--danger); font-size: 13px; margin-top: 12px; }

/* ─── LAYOUT ────────────────────────────────────────── */
#app { display: flex; height: 100vh; overflow: hidden; }

.sidebar {
  width: var(--sidebar-w); background: var(--bg2);
  border-right: 1px solid var(--border);
  display: flex; flex-direction: column;
  padding: 0; flex-shrink: 0;
}
.sidebar-brand {
  padding: 24px 20px 20px;
  border-bottom: 1px solid var(--border);
  display: flex; align-items: center; gap: 12px;
}
.brand-icon { font-size: 28px; }
.brand-name { font-family: var(--head); font-size: 15px; font-weight: 700; line-height: 1.2; color: var(--text); }

.sidebar-nav { flex: 1; padding: 12px 10px; display: flex; flex-direction: column; gap: 2px; overflow-y: auto; }
.nav-item {
  display: flex; align-items: center; gap: 10px;
  padding: 9px 12px; border-radius: 8px;
  color: var(--text2); text-decoration: none;
  font-size: 13px; font-weight: 500;
  transition: all 0.15s;
}
.nav-item:hover { background: var(--bg3); color: var(--text); }
.nav-item.active { background: var(--accent-glow); color: var(--accent); }
.nav-icon { font-size: 16px; width: 18px; text-align: center; }

.sidebar-footer {
  padding: 16px; border-top: 1px solid var(--border);
  display: flex; flex-direction: column; gap: 10px;
}
.sync-indicator { display: flex; align-items: center; gap: 8px; font-size: 11px; color: var(--text3); }
.sync-dot { width: 7px; height: 7px; border-radius: 50%; background: var(--text3); flex-shrink: 0; }
.sync-dot.ok { background: var(--ok); box-shadow: 0 0 6px var(--ok); }
.sync-dot.error { background: var(--danger); }
.sync-dot.running { background: var(--accent); animation: pulse 1s infinite; }
@keyframes pulse { 0%,100%{opacity:1} 50%{opacity:.4} }

.btn-logout { background: none; border: 1px solid var(--border); color: var(--text2); padding: 7px 12px; border-radius: 6px; font-size: 12px; cursor: pointer; width: 100%; transition: all 0.15s; }
.btn-logout:hover { border-color: var(--danger); color: var(--danger); }

.main-content { flex: 1; overflow-y: auto; background: var(--bg); }

/* ─── PAGE HEADER ───────────────────────────────────── */
.page { padding: 28px 32px; max-width: 1400px; }
.page-header { margin-bottom: 28px; display: flex; align-items: flex-start; justify-content: space-between; flex-wrap: wrap; gap: 12px; }
.page-title { font-family: var(--head); font-size: 22px; font-weight: 700; color: var(--text); }
.page-subtitle { color: var(--text2); font-size: 13px; margin-top: 4px; }

/* ─── CARDS ─────────────────────────────────────────── */
.card {
  background: var(--bg2); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 20px;
}
.card-title { font-family: var(--head); font-size: 13px; font-weight: 600; color: var(--text2); text-transform: uppercase; letter-spacing: 0.8px; margin-bottom: 16px; }

/* ─── FRIDGE CARDS ──────────────────────────────────── */
.fridge-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); gap: 16px; margin-bottom: 28px; }

.fridge-card {
  background: var(--bg2); border: 1px solid var(--border);
  border-radius: 12px; padding: 20px;
  position: relative; overflow: hidden;
  transition: border-color 0.2s, transform 0.15s;
}
.fridge-card:hover { transform: translateY(-2px); border-color: var(--border-light); }
.fridge-card::before {
  content: ''; position: absolute; top: 0; left: 0; right: 0; height: 3px;
  background: var(--ok); border-radius: 12px 12px 0 0;
}
.fridge-card.warn::before { background: var(--warn); }
.fridge-card.danger::before { background: var(--danger); }
.fridge-card.offline::before { background: var(--text3); }
.fridge-card.cold::before { background: var(--cold); }

.fridge-card-header { display: flex; justify-content: space-between; align-items: flex-start; margin-bottom: 16px; }
.fridge-name { font-family: var(--head); font-size: 15px; font-weight: 700; color: var(--text); }
.fridge-type { font-size: 11px; color: var(--text3); margin-top: 3px; }
.status-badge {
  padding: 3px 10px; border-radius: 20px; font-size: 11px; font-weight: 600;
  font-family: var(--mono); white-space: nowrap;
}
.status-badge.ok { background: var(--ok-bg); color: var(--ok); }
.status-badge.warn { background: var(--warn-bg); color: var(--warn); }
.status-badge.danger { background: var(--danger-bg); color: var(--danger); }
.status-badge.offline { background: rgba(255,255,255,0.05); color: var(--text3); }

.fridge-temp {
  font-family: var(--mono); font-size: 44px; font-weight: 500;
  line-height: 1; margin-bottom: 8px;
  color: var(--text);
}
.fridge-temp.ok { color: var(--ok); }
.fridge-temp.danger { color: var(--danger); }
.fridge-temp.warn { color: var(--warn); }
.fridge-temp.cold { color: var(--cold); }
.fridge-temp.offline { color: var(--text3); }

.fridge-range { font-size: 12px; color: var(--text3); margin-bottom: 12px; font-family: var(--mono); }
.fridge-meta { font-size: 11px; color: var(--text3); margin-top: 8px; }

.mini-chart { height: 48px; margin-top: 8px; }

/* ─── FORMS ─────────────────────────────────────────── */
.form-group { margin-bottom: 16px; }
.form-label { display: block; font-size: 12px; color: var(--text2); margin-bottom: 6px; font-weight: 500; text-transform: uppercase; letter-spacing: 0.4px; }
.input, .select {
  width: 100%; background: var(--bg3); border: 1px solid var(--border);
  border-radius: 8px; padding: 9px 12px; color: var(--text); font-size: 14px;
  font-family: var(--sans); transition: border-color 0.15s;
  outline: none;
}
.input:focus, .select:focus { border-color: var(--accent); }
.input::placeholder { color: var(--text3); }
.select option { background: var(--bg2); }

.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.form-grid-3 { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 12px; }

/* ─── BUTTONS ───────────────────────────────────────── */
.btn {
  padding: 9px 18px; border-radius: 8px; font-size: 13px; font-weight: 500;
  cursor: pointer; border: none; transition: all 0.15s; font-family: var(--sans);
  display: inline-flex; align-items: center; gap: 6px;
}
.btn:disabled { opacity: 0.4; cursor: not-allowed; }
.btn-primary { background: var(--accent); color: white; }
.btn-primary:hover:not(:disabled) { background: #6ba0f9; }
.btn-secondary { background: var(--bg3); color: var(--text); border: 1px solid var(--border); }
.btn-secondary:hover { border-color: var(--border-light); background: var(--border); }
.btn-danger { background: var(--danger-bg); color: var(--danger); border: 1px solid rgba(248,113,113,0.2); }
.btn-danger:hover { background: rgba(248,113,113,0.2); }
.btn-full { width: 100%; justify-content: center; }
.btn-sm { padding: 5px 12px; font-size: 12px; }

/* ─── TABLES ────────────────────────────────────────── */
.table-wrap { overflow-x: auto; border-radius: var(--radius); border: 1px solid var(--border); }
table { width: 100%; border-collapse: collapse; }
thead th {
  background: var(--bg3); color: var(--text2); font-size: 11px; font-weight: 600;
  text-transform: uppercase; letter-spacing: 0.6px; padding: 10px 14px; text-align: left;
  border-bottom: 1px solid var(--border);
}
tbody td { padding: 10px 14px; border-bottom: 1px solid var(--border); font-size: 13px; vertical-align: middle; }
tbody tr:last-child td { border-bottom: none; }
tbody tr:hover td { background: var(--bg3); }
.td-mono { font-family: var(--mono); font-size: 12px; }

/* ─── TOGGLE ────────────────────────────────────────── */
.toggle { display: flex; align-items: center; gap: 10px; cursor: pointer; }
.toggle-track { width: 36px; height: 20px; background: var(--bg3); border-radius: 10px; position: relative; border: 1px solid var(--border); transition: background 0.2s; flex-shrink: 0; }
.toggle-thumb { position: absolute; top: 2px; left: 2px; width: 14px; height: 14px; border-radius: 50%; background: var(--text3); transition: all 0.2s; }
input[type=checkbox].toggle-input { position: absolute; opacity: 0; width: 0; height: 0; }
input[type=checkbox].toggle-input:checked + .toggle-track { background: var(--accent); border-color: var(--accent); }
input[type=checkbox].toggle-input:checked + .toggle-track .toggle-thumb { left: 18px; background: white; }

/* ─── ALERTS LOG ────────────────────────────────────── */
.alert-item { display: flex; gap: 12px; padding: 12px 0; border-bottom: 1px solid var(--border); align-items: flex-start; }
.alert-item:last-child { border-bottom: none; }
.alert-icon { width: 32px; height: 32px; border-radius: 8px; display: flex; align-items: center; justify-content: center; font-size: 16px; flex-shrink: 0; }
.alert-icon.danger { background: var(--danger-bg); }
.alert-icon.ok { background: var(--ok-bg); }
.alert-icon.offline { background: rgba(255,255,255,0.05); }
.alert-body { flex: 1; }
.alert-device { font-size: 13px; font-weight: 600; color: var(--text); }
.alert-time { font-size: 11px; color: var(--text3); margin-top: 2px; font-family: var(--mono); }

/* ─── SETUP BANNER ──────────────────────────────────── */
.setup-banner {
  background: linear-gradient(135deg, rgba(79,142,247,0.1), rgba(79,142,247,0.03));
  border: 1px solid rgba(79,142,247,0.3); border-radius: var(--radius);
  padding: 24px; margin-bottom: 24px; display: flex; gap: 16px; align-items: flex-start;
}
.setup-banner-icon { font-size: 32px; }
.setup-banner-title { font-family: var(--head); font-size: 16px; font-weight: 700; margin-bottom: 6px; color: var(--accent); }
.setup-banner-text { color: var(--text2); font-size: 13px; line-height: 1.6; }

/* ─── MODAL ─────────────────────────────────────────── */
.modal-overlay {
  position: fixed; inset: 0; background: rgba(0,0,0,0.7);
  display: flex; align-items: center; justify-content: center; z-index: 1000;
  backdrop-filter: blur(4px);
}
.modal {
  background: var(--bg2); border: 1px solid var(--border);
  border-radius: 14px; padding: 28px; width: 520px; max-width: 95vw;
  max-height: 90vh; overflow-y: auto;
}
.modal-title { font-family: var(--head); font-size: 18px; font-weight: 700; margin-bottom: 20px; }
.modal-footer { display: flex; gap: 10px; justify-content: flex-end; margin-top: 24px; }

/* ─── CHART AREA ────────────────────────────────────── */
.chart-container { position: relative; height: 260px; }

/* ─── MISC ──────────────────────────────────────────── */
.section-title { font-family: var(--head); font-size: 15px; font-weight: 700; margin-bottom: 16px; display: flex; align-items: center; gap: 10px; }
.empty-state { text-align: center; padding: 48px; color: var(--text3); }
.empty-icon { font-size: 40px; margin-bottom: 12px; }
.empty-text { font-size: 14px; }
.chip { display: inline-flex; align-items: center; gap: 4px; padding: 2px 8px; border-radius: 20px; font-size: 11px; font-weight: 500; }
.chip.ok { background: var(--ok-bg); color: var(--ok); }
.chip.danger { background: var(--danger-bg); color: var(--danger); }
.chip.warn { background: var(--warn-bg); color: var(--warn); }
.chip.offline { background: rgba(255,255,255,0.05); color: var(--text3); }
.divider { border: none; border-top: 1px solid var(--border); margin: 20px 0; }
.text-sm { font-size: 12px; color: var(--text2); }
.text-mono { font-family: var(--mono); }
.gap-8 { display: flex; gap: 8px; flex-wrap: wrap; }
.mt-16 { margin-top: 16px; }
.notification { position: fixed; bottom: 24px; right: 24px; background: var(--bg2); border: 1px solid var(--border); border-radius: 10px; padding: 14px 18px; font-size: 13px; z-index: 9999; max-width: 320px; box-shadow: 0 8px 32px rgba(0,0,0,0.4); animation: slideIn 0.3s ease; }
.notification.success { border-left: 3px solid var(--ok); }
.notification.error { border-left: 3px solid var(--danger); }
@keyframes slideIn { from { transform: translateX(100%); opacity: 0; } to { transform: translateX(0); opacity: 1; } }

/* ─── REPORT SELECTOR ───────────────────────────────── */
.report-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); gap: 12px; }
.report-card { background: var(--bg2); border: 1px solid var(--border); border-radius: 10px; padding: 16px; display: flex; justify-content: space-between; align-items: center; transition: border-color 0.15s; }
.report-card:hover { border-color: var(--border-light); }
.report-card-name { font-weight: 600; font-size: 14px; color: var(--text); }
.report-card-sub { font-size: 11px; color: var(--text3); margin-top: 3px; }

/* ─── RESPONSIVE ────────────────────────────────────── */
@media (max-width: 768px) {
  .sidebar { width: 60px; }
  .brand-name, .nav-item span:not(.nav-icon), .sidebar-footer .sync-indicator span, .btn-logout { display: none; }
  .sidebar-brand { justify-content: center; padding: 16px; }
  .nav-item { justify-content: center; padding: 12px 0; }
  .main-content .page { padding: 16px; }
  .form-grid, .form-grid-3 { grid-template-columns: 1fr; }
}

/* ─── FIX MINI CHART HEIGHT ─────────────────────────────── */
.mini-chart-wrap {
  position: relative;
  height: 52px;
  width: 100%;
  margin: 10px 0 6px;
  flex-shrink: 0;
}
.mini-chart-wrap canvas {
  position: absolute;
  top: 0; left: 0;
  width: 100% !important;
  height: 52px !important;
}

/* ─── FRIDGE CARD FIX ───────────────────────────────────── */
.fridge-card {
  display: flex;
  flex-direction: column;
  height: auto;
  min-height: 0;
}
.fridge-temp {
  font-size: 40px;
  line-height: 1.1;
  margin: 6px 0 4px;
}

/* ─── MOBILE RESPONSIVE ─────────────────────────────────── */
@media (max-width: 600px) {
  :root { --sidebar-w: 0px; }

  #app { flex-direction: column; }

  .sidebar {
    width: 100%;
    height: auto;
    flex-direction: column;
    border-right: none;
    border-bottom: 1px solid var(--border);
  }
  .sidebar-brand { padding: 12px 16px; }
  .brand-name { font-size: 13px; }
  .sidebar-nav {
    flex-direction: row;
    flex-wrap: wrap;
    padding: 6px 8px;
    gap: 4px;
    overflow-x: auto;
  }
  .nav-item {
    padding: 7px 10px;
    font-size: 12px;
    flex-shrink: 0;
  }
  .nav-icon { display: none; }
  .sidebar-footer {
    flex-direction: row;
    align-items: center;
    justify-content: space-between;
    padding: 8px 12px;
    border-top: 1px solid var(--border);
  }
  .main-content { overflow-y: auto; }
  .main-content .page { padding: 12px; }
  .page-header { flex-direction: column; gap: 8px; }
  .fridge-grid { grid-template-columns: 1fr 1fr; gap: 10px; }
  .fridge-temp { font-size: 30px; }
  .fridge-name { font-size: 13px; }
  .form-grid, .form-grid-3 { grid-template-columns: 1fr; }
  .modal { padding: 20px; }
  table { font-size: 12px; }
  thead th, tbody td { padding: 7px 8px; }
}

@media (max-width: 380px) {
  .fridge-grid { grid-template-columns: 1fr; }
}

/* ─── STATUS BADGE COLORS ───────────────────────────────── */
.status-badge.cold { background: var(--cold-bg); color: var(--cold); }
.fridge-card.cold::before { background: var(--cold); }
