@import url('https://fonts.googleapis.com/css2?family=Manrope:wght@400;500;600;700&family=IBM+Plex+Sans:wght@400;500;600&display=swap');

:root,
[data-theme="dark"] {
  --bg: #0b1220;
  --bg-accent: #152033;
  --surface: #121a2b;
  --surface-2: #182338;
  --text: #e8eef7;
  --muted: #9aa8bc;
  --accent: #3aa887;
  --accent-strong: #2f9a78;
  --accent-soft: rgba(58, 168, 135, 0.18);
  --danger: #e25b52;
  --danger-soft: rgba(226, 91, 82, 0.16);
  --online: #3aa887;
  --offline: #8a96a6;
  --border: #273449;
  --shadow: 0 12px 32px rgba(0, 0, 0, 0.35);
  --radius: 14px;
  --topbar-bg: rgba(11, 18, 32, 0.86);
  --topbar-border: rgba(39, 52, 73, 0.95);
  --input-bg: #0f1726;
  --btn-secondary: #2a3a52;
  --banner-bg: rgba(56, 132, 214, 0.14);
  --banner-border: rgba(56, 132, 214, 0.35);
  --banner-text: #9ec5ef;
  --thumb-bg: linear-gradient(135deg, #152033, #1a2740);
  --hist-bg: #182338;
  --hist-sticky: linear-gradient(180deg, #121a2b 70%, transparent);
  --kpi-bg: #182338;
  --track-bg: #1b2740;
  --hour-bar-bg: #152033;
  --status-offline-bg: #1b2740;
  --status-offline-fg: #9aa8bc;
  --tag-neutral-bg: #1b2740;
  --tag-neutral-fg: #9aa8bc;
  --glow-a: rgba(58, 168, 135, 0.14);
  --glow-b: rgba(56, 132, 214, 0.12);
  --card-hover: #3d5573;
}

[data-theme="light"] {
  --bg: #eef2f6;
  --bg-accent: #e3ebf4;
  --surface: #ffffff;
  --surface-2: #f7fafc;
  --text: #152033;
  --muted: #5b6b7f;
  --accent: #0f6e56;
  --accent-strong: #0d5f4a;
  --accent-soft: #d8f3ea;
  --danger: #c4362b;
  --danger-soft: #fde8e6;
  --online: #0f6e56;
  --offline: #8a96a6;
  --border: #d5dee8;
  --shadow: 0 10px 30px rgba(21, 32, 51, 0.06);
  --topbar-bg: rgba(255, 255, 255, 0.82);
  --topbar-border: rgba(213, 222, 232, 0.9);
  --input-bg: #ffffff;
  --btn-secondary: #203247;
  --banner-bg: #e8f3ff;
  --banner-border: #bdd7f2;
  --banner-text: #1d4f7a;
  --thumb-bg: linear-gradient(135deg, #edf2f7, #e7eef6);
  --hist-bg: #f4f7fb;
  --hist-sticky: linear-gradient(180deg, #ffffff 70%, transparent);
  --kpi-bg: #f7fafc;
  --track-bg: #eef2f6;
  --hour-bar-bg: #eef2f6;
  --status-offline-bg: #eef2f6;
  --status-offline-fg: #6b7788;
  --tag-neutral-bg: #eef2f6;
  --tag-neutral-fg: #5b6b7f;
  --glow-a: #dceaf7;
  --glow-b: #d9f0e8;
  --card-hover: #9eb4c9;
}

* { box-sizing: border-box; }
html, body { min-height: 100%; }
body {
  margin: 0;
  font-family: "Manrope", "IBM Plex Sans", sans-serif;
  color: var(--text);
  background:
    radial-gradient(1200px 500px at 10% -10%, var(--glow-a) 0%, transparent 55%),
    radial-gradient(900px 420px at 100% 0%, var(--glow-b) 0%, transparent 50%),
    var(--bg);
  color-scheme: dark;
}
html[data-theme="light"] { color-scheme: light; }
html[data-theme="dark"] { color-scheme: dark; }

a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }

.topbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 0.85rem 1.5rem;
  border-bottom: 1px solid var(--topbar-border);
  background: var(--topbar-bg);
  backdrop-filter: blur(10px);
  position: sticky;
  top: 0;
  z-index: 20;
}
.brand {
  font-weight: 700;
  letter-spacing: -0.02em;
  color: var(--text);
  font-size: 1.1rem;
}
.topbar nav {
  display: flex;
  gap: 0.35rem;
  align-items: center;
}
.topbar nav > a {
  color: var(--muted);
  padding: 0.45rem 0.75rem;
  border-radius: 999px;
  font-weight: 600;
  font-size: 0.92rem;
}
.topbar nav > a:hover {
  background: var(--bg-accent);
  color: var(--text);
  text-decoration: none;
}
.theme-toggle {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  margin-left: 0.25rem;
  padding: 0.4rem 0.7rem;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--muted);
  font-weight: 600;
  font-size: 0.85rem;
  cursor: pointer;
}
.theme-toggle:hover {
  color: var(--text);
  filter: none;
  background: var(--bg-accent);
}
.theme-toggle .theme-icon { font-size: 0.95rem; line-height: 1; }

.container {
  padding: 1.5rem clamp(1rem, 3vw, 2rem) 2.5rem;
  max-width: 1280px;
  margin: 0 auto;
}

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.25rem;
  box-shadow: var(--shadow);
}
.login-card {
  max-width: 400px;
  margin: 5rem auto;
}
.login-card h1 {
  margin: 0 0 1rem;
  letter-spacing: -0.03em;
}

label { display: block; margin-bottom: 1rem; font-weight: 600; color: var(--muted); font-size: 0.9rem; }
input, button, textarea, select {
  font: inherit;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: var(--input-bg);
  color: var(--text);
  padding: 0.65rem 0.85rem;
}
input { width: 100%; margin-top: 0.35rem; }
button, .file-btn {
  cursor: pointer;
  background: var(--accent);
  border-color: transparent;
  color: #fff;
  font-weight: 600;
  transition: transform 0.12s ease, filter 0.12s ease;
}
button:hover, .file-btn:hover { filter: brightness(1.05); }
button:active, .file-btn:active { transform: translateY(1px); }
button.danger { background: var(--danger); }
button.secondary, .file-btn {
  background: var(--btn-secondary);
}
button.linkish {
  background: transparent;
  border: none;
  color: var(--muted);
  padding: 0.45rem 0.75rem;
  font-weight: 600;
}
button.linkish:hover { color: var(--text); filter: none; }

.toolbar {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 1rem;
  margin-bottom: 1.15rem;
}
.toolbar h1 {
  margin: 0;
  font-size: clamp(1.55rem, 2.4vw, 2rem);
  letter-spacing: -0.03em;
}
.toolbar .muted { margin: 0.35rem 0 0; }
.actions {
  display: flex;
  gap: 0.5rem;
  flex-wrap: wrap;
  justify-content: flex-end;
}
.file-btn {
  display: inline-flex;
  align-items: center;
  border-radius: 10px;
  padding: 0.65rem 0.85rem;
}

.device-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: 1rem;
}
.device-card {
  display: flex;
  flex-direction: column;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  color: inherit;
  box-shadow: var(--shadow);
  transition: border-color 0.15s ease, transform 0.15s ease;
}
.device-card:hover {
  border-color: var(--card-hover);
  transform: translateY(-2px);
  text-decoration: none;
}
.device-card .thumb {
  aspect-ratio: 16/10;
  background: var(--thumb-bg);
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
}
.device-card .thumb img {
  width: 100%;
  height: 100%;
  object-fit: contain;
  display: block;
  background: #0b1220;
}
.device-card .meta {
  padding: 0.9rem 1rem 1rem;
  display: grid;
  gap: 0.25rem;
}
.device-card .meta strong {
  font-size: 1.05rem;
  letter-spacing: -0.02em;
}
.device-card .meta-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 0.5rem;
  margin-top: 0.35rem;
}
.device-card .card-actions {
  display: flex;
  gap: 0.4rem;
  padding: 0 1rem 1rem;
}
.device-card .card-actions a,
.device-card .card-actions button {
  flex: 1;
  text-align: center;
  font-size: 0.88rem;
  padding: 0.5rem 0.6rem;
  text-decoration: none;
}
.device-card .card-actions a.secondary {
  background: var(--btn-secondary);
  color: #fff;
  border-radius: 10px;
  font-weight: 600;
}

.status {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  font-size: 0.82rem;
  font-weight: 700;
  padding: 0.2rem 0.55rem;
  border-radius: 999px;
}
.status::before {
  content: "";
  width: 0.45rem;
  height: 0.45rem;
  border-radius: 50%;
  background: currentColor;
}
.status.online {
  color: var(--online);
  background: var(--accent-soft);
}
.status.offline {
  color: var(--status-offline-fg);
  background: var(--status-offline-bg);
}
.muted { color: var(--muted); }
.error { color: var(--danger); }
.banner {
  background: var(--banner-bg);
  border: 1px solid var(--banner-border);
  color: var(--banner-text);
  padding: 0.85rem 1rem;
  border-radius: 12px;
  margin-bottom: 1rem;
  font-weight: 600;
}
.hidden { display: none !important; }
.placeholder {
  color: var(--muted);
  display: flex;
  align-items: center;
  justify-content: center;
  width: 100%;
  height: 100%;
  min-height: 140px;
  font-weight: 600;
}
.inline { display: inline; }

.detail-grid {
  display: grid;
  grid-template-columns: 1.45fr 1fr;
  gap: 1rem;
}
@media (max-width: 980px) {
  .detail-grid { grid-template-columns: 1fr; }
  .toolbar { flex-direction: column; }
  .actions { justify-content: flex-start; }
}

.live-frame {
  background: #101826;
  border-radius: 12px;
  min-height: 280px;
  max-height: 420px;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: auto;
  margin-bottom: 1rem;
}
.live-frame img {
  max-width: 100%;
  max-height: 400px;
  width: auto;
  height: auto;
  object-fit: contain;
  display: none;
}

.history {
  display: flex;
  flex-direction: column;
  gap: 0.85rem;
  max-height: 420px;
  overflow-y: auto;
  overflow-x: hidden;
  padding-right: 0.35rem;
}
.hist-group { display: grid; gap: 0.45rem; }
.hist-group-title {
  position: sticky;
  top: 0;
  z-index: 1;
  margin: 0;
  padding: 0.25rem 0.4rem;
  font-size: 0.85rem;
  font-weight: 700;
  color: var(--muted);
  background: var(--hist-sticky);
}
.hist-group-items {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(112px, 1fr));
  gap: 0.45rem;
}
.hist-item {
  background: var(--hist-bg);
  border: 1px solid var(--border);
  padding: 0.3rem;
  display: grid;
  gap: 0.25rem;
  width: 100%;
  cursor: pointer;
  border-radius: 10px;
}
.hist-item.active { border-color: var(--accent); box-shadow: 0 0 0 2px var(--accent-soft); }
.hist-item img {
  width: 100%;
  aspect-ratio: 16 / 10;
  height: auto;
  object-fit: contain;
  background: #101826;
  display: block;
  border-radius: 6px;
}
.hist-item span {
  font-size: 0.75rem;
  color: var(--muted);
  text-align: center;
  font-weight: 600;
}

table {
  width: 100%;
  border-collapse: collapse;
}
th, td {
  text-align: left;
  padding: 0.55rem 0.4rem;
  border-bottom: 1px solid var(--border);
  vertical-align: top;
}
th { color: var(--muted); font-size: 0.82rem; font-weight: 700; }

.stats-toolbar { align-items: flex-end; }
.month-nav {
  display: flex;
  align-items: center;
  gap: 0.75rem;
}
.month-nav button { min-width: 2.2rem; }
.stats-card { margin-bottom: 1rem; overflow: hidden; }
.table-scroll { overflow-x: auto; max-width: 100%; }
.stats-month-table { min-width: 900px; font-size: 0.85rem; }
.stats-month-table th,
.stats-month-table td {
  text-align: center;
  white-space: nowrap;
  padding: 0.4rem 0.3rem;
}
.stats-month-table .sticky-col {
  position: sticky;
  left: 0;
  background: var(--surface);
  text-align: left;
  min-width: 160px;
  z-index: 1;
}
.day-cell { cursor: pointer; min-width: 1.6rem; }
.day-cell.lvl1 { background: rgba(58, 168, 135, 0.18); }
.day-cell.lvl2 { background: rgba(58, 168, 135, 0.32); }
.day-cell.lvl3 { background: rgba(58, 168, 135, 0.55); color: #fff; }
.day-cell.lvl4 { background: rgba(58, 168, 135, 0.78); color: #fff; }
[data-theme="light"] .day-cell.lvl1 { background: rgba(15,110,86,0.12); }
[data-theme="light"] .day-cell.lvl2 { background: rgba(15,110,86,0.25); }
[data-theme="light"] .day-cell.lvl3 { background: rgba(15,110,86,0.45); color: #fff; }
[data-theme="light"] .day-cell.lvl4 { background: rgba(15,110,86,0.7); color: #fff; }
.day-cell:hover { outline: 2px solid var(--accent); }
.hour-scale,
.hour-bars {
  display: grid;
  grid-template-columns: repeat(24, 1fr);
  gap: 2px;
}
.hour-scale {
  margin-bottom: 0.25rem;
  color: var(--muted);
  font-size: 0.7rem;
  text-align: center;
}
.hour-bars {
  height: 72px;
  align-items: end;
  margin-bottom: 0.75rem;
}
.hour-bar {
  background: var(--hour-bar-bg);
  border: 1px solid var(--border);
  border-radius: 3px;
  height: 100%;
  display: flex;
  align-items: flex-end;
  overflow: hidden;
}
.hour-bar i {
  display: block;
  width: 100%;
  background: linear-gradient(180deg, #3aa887, #0f6e56);
  min-height: 0;
}
.stats-reports {
  display: grid;
  grid-template-columns: 1.2fr 1fr;
  gap: 1rem;
  margin-top: 1rem;
}
@media (max-width: 900px) {
  .stats-reports { grid-template-columns: 1fr; }
}
.day-hero {
  display: flex;
  justify-content: space-between;
  gap: 1rem;
  flex-wrap: wrap;
  margin-bottom: 0.85rem;
}
.day-range {
  font-size: 1.05rem;
  margin: 0.25rem 0 0.5rem;
  font-weight: 600;
}
.day-kpis {
  display: flex;
  gap: 0.6rem;
  flex-wrap: wrap;
}
.kpi {
  min-width: 140px;
  padding: 0.7rem 0.85rem;
  border-radius: 12px;
  border: 1px solid var(--border);
  background: var(--kpi-bg);
  display: grid;
  gap: 0.25rem;
}
.kpi span { color: var(--muted); font-size: 0.8rem; font-weight: 600; }
.kpi strong { font-size: 1.15rem; }
.kpi.work { border-color: rgba(58, 168, 135, 0.35); background: var(--accent-soft); }
.kpi.personal { border-color: rgba(226, 91, 82, 0.35); background: var(--danger-soft); }
.split-bar {
  height: 12px;
  border-radius: 999px;
  margin: 0.5rem 0 0.75rem;
  background: var(--track-bg);
}
.absence-box {
  background: var(--danger-soft);
  border: 1px solid rgba(226, 91, 82, 0.3);
  border-radius: 12px;
  padding: 0.75rem 1rem;
  margin-bottom: 1rem;
}
.absence-box ul { margin: 0.35rem 0 0; padding-left: 1.1rem; }
.scrubber { margin-bottom: 1.25rem; }
.scrubber-frame {
  background: #101826;
  border-radius: 12px;
  min-height: 260px;
  max-height: 420px;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: auto;
  margin-bottom: 0.5rem;
}
.scrubber-frame img {
  max-width: 100%;
  max-height: 400px;
  object-fit: contain;
  display: none;
}
.scrubber-meta {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  margin-top: 0.4rem;
}
#scrub-range { width: 100%; }
.prog-bars { display: grid; gap: 0.45rem; margin-bottom: 0.85rem; }
.prog-label {
  display: flex;
  justify-content: space-between;
  font-size: 0.85rem;
  margin-bottom: 0.15rem;
  font-weight: 600;
}
.prog-track {
  height: 8px;
  border-radius: 999px;
  background: var(--track-bg);
  overflow: hidden;
}
.prog-track i { display: block; height: 100%; border-radius: 999px; }
.prog-track i.cat-work { background: var(--accent); }
.prog-track i.cat-personal { background: var(--danger); }
.prog-track i.cat-neutral { background: var(--offline); }
.tag {
  display: inline-block;
  padding: 0.15rem 0.5rem;
  border-radius: 999px;
  font-size: 0.75rem;
  font-weight: 700;
}
.tag.cat-work { background: var(--accent-soft); color: var(--accent); }
.tag.cat-personal { background: var(--danger-soft); color: var(--danger); }
.tag.cat-neutral { background: var(--tag-neutral-bg); color: var(--tag-neutral-fg); }

.empty-state {
  padding: 2.5rem 1.25rem;
  text-align: center;
  background: var(--surface);
  border: 1px dashed var(--border);
  border-radius: var(--radius);
  color: var(--muted);
  font-weight: 600;
}

.modal {
  position: fixed;
  inset: 0;
  z-index: 50;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1rem;
  background: rgba(8, 12, 20, 0.55);
  backdrop-filter: blur(4px);
}
.modal-card {
  width: min(440px, 100%);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 1.25rem 1.35rem 1.35rem;
}
.modal-card h2 {
  margin: 0 0 0.35rem;
  letter-spacing: -0.02em;
}
.modal-card textarea {
  width: 100%;
  margin-top: 0.35rem;
  resize: vertical;
  min-height: 72px;
}
