/* Doorly Admin Panel — Theme variables */

/* ── Dark theme (default) ── */
:root {
  --bg:       #0f1117;
  --surface:  #1a1d27;
  --border:   #2a2d3e;
  --accent:   #4f8ef7;
  --accent2:  #22c55e;
  --danger:   #ef4444;
  --warn:     #f59e0b;
  --text:     #e2e8f0;
  --muted:    #64748b;
  --radius:   8px;

  /* badge tokens */
  --badge-green-bg:  #14532d; --badge-green-fg:  #86efac;
  --badge-blue-bg:   #1e3a5f; --badge-blue-fg:   #93c5fd;
  --badge-yellow-bg: #451a03; --badge-yellow-fg: #fcd34d;
  --badge-red-bg:    #450a0a; --badge-red-fg:    #fca5a5;

  /* alert tokens */
  --alert-ok-bg:   #052e16; --alert-ok-b:   #166534; --alert-ok-fg:   #86efac;
  --alert-err-bg:  #450a0a; --alert-err-b:  #7f1d1d; --alert-err-fg:  #fca5a5;
  --alert-warn-bg: #451a03; --alert-warn-b: #92400e; --alert-warn-fg: #fcd34d;

  /* row hover */
  --row-hover: rgba(255,255,255,.02);
}

/* ── Light theme ── */
[data-theme="light"] {
  --bg:      #f1f5f9;
  --surface: #ffffff;
  --border:  #e2e8f0;
  --text:    #0f172a;
  --muted:   #64748b;
  /* accent, accent2, danger, warn unchanged */

  --badge-green-bg:  #dcfce7; --badge-green-fg:  #15803d;
  --badge-blue-bg:   #dbeafe; --badge-blue-fg:   #1d4ed8;
  --badge-yellow-bg: #fef3c7; --badge-yellow-fg: #b45309;
  --badge-red-bg:    #fee2e2; --badge-red-fg:    #b91c1c;

  --alert-ok-bg:   #f0fdf4; --alert-ok-b:   #86efac; --alert-ok-fg:   #15803d;
  --alert-err-bg:  #fef2f2; --alert-err-b:  #fca5a5; --alert-err-fg:  #b91c1c;
  --alert-warn-bg: #fffbeb; --alert-warn-b: #fcd34d; --alert-warn-fg: #b45309;

  --row-hover: rgba(0,0,0,.03);
}

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

body {
  background: var(--bg);
  color: var(--text);
  font-family: 'Segoe UI', system-ui, sans-serif;
  font-size: 14px;
  min-height: 100vh;
}

/* ── Sidebar ── */
nav {
  position: fixed;
  top: 0; left: 0;
  width: 220px;
  height: 100vh;
  background: var(--surface);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  z-index: 200;
  overflow-y: auto;
  overflow-x: hidden;
  transition: transform .25s cubic-bezier(.4,0,.2,1);
}

/* Logo block */
.sidebar-logo {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 16px 14px;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
  text-decoration: none;
}
.nav-logo-img {
  width: 36px; height: 36px;
  border-radius: 8px;
  box-shadow: 0 4px 14px rgba(79,142,247,.35);
  flex-shrink: 0;
  display: block;
}
.nav-logo-fallback {
  width: 36px; height: 36px;
  background: linear-gradient(135deg, var(--accent) 0%, #1d4ed8 100%);
  border-radius: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 18px;
  flex-shrink: 0;
}
.nav-logo-text { display: flex; flex-direction: column; gap: 3px; min-width: 0; }
.nav-logo-name {
  font-size: 16px; font-weight: 700; letter-spacing: 1px;
  background: linear-gradient(135deg, var(--accent) 0%, #1d4ed8 100%);
  -webkit-background-clip: text; -webkit-text-fill-color: transparent; background-clip: text;
  line-height: 1; white-space: nowrap;
}
.nav-logo-sub {
  font-size: 9px; color: var(--muted); font-weight: 500;
  text-transform: uppercase; letter-spacing: 1px; line-height: 1;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}

/* Section group labels */
.nav-section-label {
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 1.5px;
  text-transform: uppercase;
  color: var(--muted);
  padding: 16px 14px 5px;
  flex-shrink: 0;
}

/* Links area */
.nav-links {
  display: flex;
  flex-direction: column;
  padding: 4px 8px;
  gap: 1px;
  flex: 1;
}

nav a {
  display: flex;
  align-items: center;
  gap: 9px;
  color: var(--muted);
  text-decoration: none;
  padding: 8px 10px;
  border-radius: var(--radius);
  transition: all .15s;
  font-size: 13px;
  white-space: nowrap;
}
nav a:hover { color: var(--text); background: var(--border); }
nav a.active { color: var(--accent); background: rgba(79,142,247,.1); }
nav a [data-lucide] { width: 15px; height: 15px; flex-shrink: 0; }

/* Footer: health chips + actions */
.sidebar-footer {
  padding: 12px 10px;
  border-top: 1px solid var(--border);
  flex-shrink: 0;
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.health-chips {
  display: flex;
  align-items: center;
  gap: 5px;
  flex-wrap: wrap;
}
.sidebar-actions {
  display: flex;
  align-items: center;
  gap: 6px;
}

/* Theme toggle */
.theme-toggle {
  background: transparent;
  border: 1px solid var(--border);
  color: var(--muted);
  border-radius: var(--radius);
  padding: 5px 8px;
  cursor: pointer;
  line-height: 1;
  display: flex;
  align-items: center;
  transition: all .15s;
  flex-shrink: 0;
}
.theme-toggle:hover { border-color: var(--accent); color: var(--accent); }

/* Logout button */
nav .logout-btn {
  flex: 1;
  background: transparent;
  border: 1px solid var(--border);
  color: var(--muted);
  padding: 5px 8px;
  border-radius: var(--radius);
  cursor: pointer;
  font-size: 12px;
  transition: all .15s;
  display: flex;
  align-items: center;
  gap: 5px;
  justify-content: center;
  white-space: nowrap;
}
nav .logout-btn:hover { border-color: var(--danger); color: var(--danger); }

/* Hamburger — fixed, only visible on mobile */
.nav-hamburger {
  display: none;
  position: fixed;
  top: 12px; left: 12px;
  z-index: 300;
  background: var(--surface);
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: var(--radius);
  padding: 7px 9px;
  cursor: pointer;
  line-height: 1;
  box-shadow: 0 2px 8px rgba(0,0,0,.25);
}

/* Overlay — covers content when sidebar is open on mobile */
.sidebar-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,.5);
  z-index: 150;
  backdrop-filter: blur(1px);
}
.sidebar-overlay.open { display: block; }

/* ── Layout ── */
.container {
  margin-left: 220px;
  max-width: calc(220px + 960px);
  padding: 24px 28px;
}

h1 { font-size: 20px; margin-bottom: 20px; color: var(--text); }
h2 { font-size: 15px; margin-bottom: 12px; color: var(--text); }

/* ── Cards ── */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  margin-bottom: 16px;
}

/* ── Forms ── */
label { display: block; color: var(--muted); font-size: 12px; margin-bottom: 4px; }

input[type=text], input[type=password], input[type=number], select, textarea {
  width: 100%;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 6px;
  color: var(--text);
  padding: 8px 10px;
  font-size: 13px;
  outline: none;
  transition: border-color .15s;
}
input:focus, select:focus, textarea:focus { border-color: var(--accent); }
textarea { font-family: 'Cascadia Code', 'Consolas', monospace; resize: vertical; }

.field { margin-bottom: 14px; }

/* ── Buttons ── */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 8px 16px;
  border-radius: 6px;
  border: none;
  cursor: pointer;
  font-size: 13px;
  font-weight: 500;
  transition: all .15s;
}
.btn-primary  { background: var(--accent);  color: #fff; }
.btn-primary:hover  { filter: brightness(1.1); }
.btn-success  { background: var(--accent2); color: #fff; }
.btn-success:hover  { filter: brightness(1.1); }
.btn-danger   { background: var(--danger);  color: #fff; }
.btn-danger:hover   { filter: brightness(1.1); }
.btn-outline  { background: transparent; border: 1px solid var(--border); color: var(--text); }
.btn-outline:hover  { border-color: var(--accent); color: var(--accent); }
.btn:disabled { opacity: .5; cursor: not-allowed; }

.btn-row { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 12px; }

/* ── Badges ── */
.badge {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 999px;
  font-size: 11px;
  font-weight: 600;
}
.badge-green  { background: var(--badge-green-bg);  color: var(--badge-green-fg); }
.badge-blue   { background: var(--badge-blue-bg);   color: var(--badge-blue-fg); }
.badge-yellow { background: var(--badge-yellow-bg); color: var(--badge-yellow-fg); }
.badge-red    { background: var(--badge-red-bg);    color: var(--badge-red-fg); }

/* ── Tables ── */
table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: 9px 10px; border-bottom: 1px solid var(--border); }
th { color: var(--muted); font-weight: 500; font-size: 12px; }
tr:last-child td { border-bottom: none; }
tr:hover td { background: var(--row-hover); }

/* table scroll on mobile */
.table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; }

/* ── Alerts ── */
.alert {
  padding: 10px 14px;
  border-radius: 6px;
  font-size: 13px;
  margin-bottom: 12px;
  display: none;
}
.alert.show { display: block; }
.alert-ok   { background: var(--alert-ok-bg);   border: 1px solid var(--alert-ok-b);   color: var(--alert-ok-fg); }
.alert-err  { background: var(--alert-err-bg);  border: 1px solid var(--alert-err-b);  color: var(--alert-err-fg); }
.alert-warn { background: var(--alert-warn-bg); border: 1px solid var(--alert-warn-b); color: var(--alert-warn-fg); }

/* ── Misc ── */
.mono { font-family: 'Cascadia Code', 'Consolas', monospace; font-size: 12px; }
.muted { color: var(--muted); }
.mt-8 { margin-top: 8px; }
.mt-16 { margin-top: 16px; }
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }

/* ── Spinner ── */
.spinner {
  display: inline-block;
  width: 16px; height: 16px;
  border: 2px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin .6s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ── Login page ── */
.login-wrap {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  padding: 20px;
}
.login-box {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 36px 28px;
  width: 100%;
  max-width: 360px;
}
.login-box .logo {
  text-align: center;
  font-size: 22px;
  font-weight: 700;
  color: var(--accent);
  margin-bottom: 4px;
}
.login-box .sub {
  text-align: center;
  color: var(--muted);
  font-size: 12px;
  margin-bottom: 28px;
}

/* ── Device health chips (nav bar) ── */
.health-chips {
  display: flex;
  align-items: center;
  gap: 5px;
  flex-shrink: 0;
}
.health-chip {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 3px 8px;
  border-radius: 999px;
  font-size: 11px;
  font-weight: 600;
  white-space: nowrap;
  border: 1px solid transparent;
  transition: background .2s, border-color .2s;
}
.health-chip .hc-dot {
  width: 6px; height: 6px;
  border-radius: 50%;
  flex-shrink: 0;
}
.health-chip.ok   { background: rgba(34,197,94,.12); border-color: rgba(34,197,94,.3);  color: #86efac; }
.health-chip.ok   .hc-dot { background: #22c55e; box-shadow: 0 0 4px #22c55e; }
.health-chip.warn { background: rgba(245,158,11,.12); border-color: rgba(245,158,11,.3); color: #fcd34d; }
.health-chip.warn .hc-dot { background: #f59e0b; animation: hcPulse .8s infinite; }
.health-chip.err  { background: rgba(239,68,68,.10); border-color: rgba(239,68,68,.25); color: #fca5a5; }
.health-chip.err  .hc-dot { background: #ef4444; }
.health-chip.loading { opacity: .4; background: var(--surface); border-color: var(--border); color: var(--muted); }
.health-chip.off  { background: rgba(100,116,139,.08); border-color: rgba(100,116,139,.2); color: var(--muted); }
.health-chip.off  .hc-dot { background: var(--muted); opacity: .5; }
@keyframes hcPulse { 0%,100%{opacity:1} 50%{opacity:.3} }
/* En móvil: ocultar labels de chips, solo puntos */
@media (max-width: 640px) { .health-chip .hc-label { display: none; } }

/* ── Card title with icon (shared across pages) ── */
.card-title {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 16px;
  padding-bottom: 10px;
  border-bottom: 1px solid var(--border);
}
.card-title h2 { margin: 0; }
.card-title [data-lucide] { color: var(--accent); width: 18px; height: 18px; flex-shrink: 0; }

/* ── Tabs ── */
.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--border); margin-bottom: 16px; flex-wrap: wrap; }
.tab-btn {
  background: transparent;
  border: none;
  border-bottom: 2px solid transparent;
  color: var(--muted);
  padding: 8px 14px;
  cursor: pointer;
  font-size: 13px;
  transition: all .15s;
  margin-bottom: -1px;
}
.tab-btn.active { color: var(--accent); border-bottom-color: var(--accent); }
.tab-pane { display: none; }
.tab-pane.active { display: block; }

/* ── Filter bar ── */
.filter-bar {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  align-items: center;
  margin-bottom: 14px;
}
.filter-bar input[type=text],
.filter-bar select { width: auto; flex: 1; min-width: 120px; }

/* ── Toggle switch ── */
.toggle-wrap { display: flex; align-items: center; gap: 10px; }
.toggle { position: relative; display: inline-block; width: 40px; height: 22px; flex-shrink: 0; }
.toggle input { opacity: 0; width: 0; height: 0; }
.toggle-slider {
  position: absolute; inset: 0;
  background: var(--border);
  border-radius: 22px;
  cursor: pointer;
  transition: .2s;
}
.toggle-slider:before {
  content: '';
  position: absolute;
  width: 16px; height: 16px;
  left: 3px; bottom: 3px;
  background: #fff;
  border-radius: 50%;
  transition: .2s;
}
.toggle input:checked + .toggle-slider { background: var(--accent); }
.toggle input:checked + .toggle-slider:before { transform: translateX(18px); }

/* ── Lucide icons sizing ── */
[data-lucide] { width: 16px; height: 16px; stroke: currentColor; display: inline-block; vertical-align: middle; }

/* ═══════════════════════════════
   RESPONSIVE — mobile-first
   ═══════════════════════════════ */

/* ─── ≤ 768px (mobile + tablet): sidebar → drawer ─── */
@media (max-width: 768px) {
  nav {
    transform: translateX(-100%);
    box-shadow: none;
  }
  nav.open {
    transform: translateX(0);
    box-shadow: 4px 0 24px rgba(0,0,0,.35);
  }
  .nav-hamburger { display: flex !important; align-items: center; }
  .container {
    margin-left: 0;
    padding: 64px 14px 20px;
  }
}

/* ─── ≤ 640px (phones) ─── */
@media (max-width: 640px) {
  body { font-size: 15px; }

  .container { padding: 64px 12px 20px; }
  h1 { font-size: 22px; margin-bottom: 16px; }
  h2 { font-size: 17px; margin-bottom: 12px; }

  .card { padding: 16px 14px; margin-bottom: 14px; }

  .grid-2 { grid-template-columns: 1fr; }

  /* Botones con área táctil mínima de 44px */
  .btn { min-height: 44px; font-size: 14px; padding: 10px 18px; }
  .btn-row { flex-direction: column; gap: 10px; }
  .btn-row .btn { justify-content: center; width: 100%; }

  /* Inputs y selects: altura táctil cómoda */
  input[type=text], input[type=password], input[type=number],
  select, textarea {
    font-size: 15px;
    padding: 11px 12px;
    min-height: 44px;
  }

  /* filter-bar: stack groups, hide separators */
  .filter-bar { flex-direction: column; align-items: stretch; gap: 8px; padding: 12px; }
  .filter-bar label { font-size: 13px; }
  .filter-bar .filter-sep { display: none; }
  .filter-bar .filter-group { width: 100%; }
  .filter-bar .filter-group select,
  .filter-bar .filter-group input[type=text],
  .filter-bar .filter-group input[type=date] { flex: 1; min-width: 0; width: auto; font-size: 15px; min-height: 44px; }
  .filter-bar #resultCount { margin-left: 0; font-size: 13px; }

  /* Pills: más grandes y táctiles */
  .pill { padding: 7px 15px; font-size: 13px; min-height: 36px; display: inline-flex; align-items: center; }
  .level-pills { gap: 6px; flex-wrap: wrap; }

  /* table: allow horizontal scroll (excluye .table-kv que son de solo lectura label-valor) */
  .card > table:not(.mobile-cards):not(.table-kv),
  .table-wrap > table:not(.mobile-cards):not(.table-kv) { min-width: 480px; }
  .card:has(> table:not(.mobile-cards):not(.table-kv)) { padding: 0; overflow: hidden; }
  .card:has(> table:not(.mobile-cards):not(.table-kv)) > table th,
  .card:has(> table:not(.mobile-cards):not(.table-kv)) > table td { padding: 10px 12px; }

  /* ── Table → Card layout ── */
  .mobile-cards thead { display: none; }
  .mobile-cards tbody tr {
    display: block;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 10px 14px;
    margin-bottom: 10px;
    background: var(--surface);
  }
  .mobile-cards tbody tr:last-child { margin-bottom: 0; }
  .mobile-cards tbody td {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    padding: 7px 0;
    border: none !important;
    gap: 10px;
    font-size: 14px;
    white-space: normal;
  }
  .mobile-cards tbody td[data-label]::before {
    content: attr(data-label);
    color: var(--muted);
    font-size: 12px;
    font-weight: 500;
    white-space: nowrap;
    padding-top: 2px;
    min-width: 80px;
    flex-shrink: 0;
  }
  /* Cells with empty data-label (e.g. photo thumb) show as full-width block */
  .mobile-cards tbody td[data-label=""] {
    justify-content: flex-start;
    padding-bottom: 8px;
    margin-bottom: 6px;
    border-bottom: 1px solid var(--border) !important;
  }
  .mobile-cards tbody td[data-label=""]::before { display: none; }
  /* Ensure card table has normal padding in card container */
  .card > table.mobile-cards { min-width: 0; }
  .card:has(> table.mobile-cards) { padding: 16px 14px; overflow: visible; }
  /* Button cells in cards */
  .mobile-cards tbody td .btn { font-size: 13px; padding: 8px 14px; min-height: 40px; }

  /* Badges ligeramente más grandes */
  .badge { font-size: 12px; padding: 3px 10px; }
}

/* ─── 769px – 1024px (tablets landscape) ─── */
@media (min-width: 769px) and (max-width: 1024px) {
  nav { width: 200px; }
  .container { margin-left: 200px; padding: 20px 18px; }

  /* filter-bar: apilar grupos verticalmente para evitar desbordamiento */
  .filter-bar { flex-direction: column; align-items: stretch; }
  .filter-bar .filter-sep { display: none; }
  .filter-bar .filter-group { width: 100%; }
  .filter-bar .filter-group select,
  .filter-bar .filter-group input[type=text],
  .filter-bar .filter-group input[type=date] { flex: 1; min-width: 0; width: auto; }
  .filter-bar #resultCount { margin-left: 0; }
}

/* ── Light mode overrides for page-local hardcoded dark values ── */
[data-theme="light"] .health-chip.ok   { color: #15803d; }
[data-theme="light"] .health-chip.warn { color: #b45309; }
[data-theme="light"] .health-chip.err  { color: #b91c1c; }

/* Log level badges (logs.html) */
[data-theme="light"] .lv-info    { background: #dbeafe; color: #1d4ed8; }
[data-theme="light"] .lv-warning { background: #fef3c7; color: #b45309; }
[data-theme="light"] .lv-error   { background: #fee2e2; color: #b91c1c; }
[data-theme="light"] .lv-debug   { background: #ede9fe; color: #7c3aed; }
[data-theme="light"] .lv-ok      { background: #dcfce7; color: #15803d; }

/* History table borders (logs.html) */
[data-theme="light"] .hist-table td          { border-bottom-color: var(--border); }
[data-theme="light"] .hist-table tr:hover td { background: rgba(0,0,0,.03); }

/* Source badges (photos.html) */
[data-theme="light"] .source-badge.usb { background: #dbeafe; color: #1d4ed8; }
[data-theme="light"] .source-badge.dvr { background: #dcfce7; color: #15803d; }

/* Recent items hover (monitor.html) */
[data-theme="light"] .recent-item:hover { background: rgba(0,0,0,.04); }
