:root {
  --bg: #0d0f10;
  --bg-elevated: #17191b;
  --bg-card: #1c1f21;
  --border: #2a2d30;
  --text: #f5f5f5;
  --text-muted: #9aa0a6;
  --accent: #39ff8a;
  --accent-dark: #17c463;
  --accent-soft: rgba(57, 255, 138, 0.12);
  --danger: #ff4d5e;
  --warning: #ffb020;
  --radius-lg: 22px;
  --radius-md: 14px;
  --radius-sm: 8px;
  --shadow: 0 10px 30px rgba(0, 0, 0, 0.35);
  --font: 'Inter', 'Segoe UI', system-ui, -apple-system, sans-serif;
}

[data-theme="light"] {
  --bg: #f2f4f5;
  --bg-elevated: #ffffff;
  --bg-card: #ffffff;
  --border: #e2e5e8;
  --text: #14171a;
  --text-muted: #5b6167;
  --accent: #17c463;
  --accent-dark: #0fa551;
  --accent-soft: rgba(23, 196, 99, 0.12);
  --shadow: 0 10px 30px rgba(0, 0, 0, 0.08);
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  -webkit-tap-highlight-color: transparent;
  overscroll-behavior: none;
}

body {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

button, input, select, textarea {
  font-family: inherit;
}

a { color: inherit; text-decoration: none; }

::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 10px; }
::-webkit-scrollbar-track { background: transparent; }

/* ---------- Header ---------- */
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 18px 28px;
  background: var(--bg-elevated);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 20;
}

.brand {
  display: flex;
  align-items: center;
  gap: 14px;
}

.brand img {
  height: 46px;
  width: auto;
  border-radius: 10px;
  object-fit: contain;
  background: #fff;
  padding: 4px;
}

.brand-fallback {
  height: 46px;
  min-width: 46px;
  border-radius: 10px;
  background: var(--accent);
  color: #05170c;
  font-weight: 800;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 18px;
  letter-spacing: 1px;
}

.brand-name {
  font-size: 20px;
  font-weight: 800;
  letter-spacing: 0.3px;
}

.brand-sub {
  font-size: 12px;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 1.5px;
}

.topbar-actions { display: flex; align-items: center; gap: 10px; }

.icon-btn {
  border: 1px solid var(--border);
  background: var(--bg-card);
  color: var(--text);
  width: 48px;
  height: 48px;
  border-radius: 14px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  font-size: 20px;
  transition: transform 0.15s ease, border-color 0.15s ease;
}
.icon-btn:active { transform: scale(0.93); }
.icon-btn:hover { border-color: var(--accent); }

/* ---------- Tela inicial ---------- */
.home-wrap {
  flex: 1;
  padding: 22px 28px 40px;
  max-width: 1400px;
  margin: 0 auto;
  width: 100%;
}

.home-title {
  text-align: center;
  margin: 18px 0 8px;
  font-size: clamp(24px, 3.4vw, 40px);
  font-weight: 800;
}

.home-subtitle {
  text-align: center;
  color: var(--text-muted);
  font-size: clamp(14px, 1.6vw, 18px);
  margin-bottom: 28px;
}

.toolbar {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  align-items: center;
  justify-content: center;
  margin-bottom: 26px;
}

.search-box {
  display: flex;
  align-items: center;
  gap: 10px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 14px 22px;
  min-width: 320px;
  max-width: 520px;
  flex: 1;
}
.search-box input {
  flex: 1;
  background: transparent;
  border: none;
  outline: none;
  color: var(--text);
  font-size: 18px;
}
.search-box .search-icon { font-size: 20px; color: var(--text-muted); }

.filter-chips {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  justify-content: center;
}
.chip {
  padding: 10px 18px;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: var(--bg-card);
  color: var(--text-muted);
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.15s ease;
  white-space: nowrap;
}
.chip.active, .chip:active {
  background: var(--accent-soft);
  border-color: var(--accent);
  color: var(--accent);
}

.machine-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(210px, 1fr));
  gap: 20px;
}

.machine-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 22px 18px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
  cursor: pointer;
  min-height: 170px;
  justify-content: center;
  transition: transform 0.12s ease, border-color 0.12s ease, box-shadow 0.12s ease;
  text-align: center;
}
.machine-card:active { transform: scale(0.96); }
.machine-card:hover {
  border-color: var(--accent);
  box-shadow: var(--shadow);
}

.machine-number {
  font-size: 40px;
  font-weight: 900;
  color: var(--accent);
  line-height: 1;
}
.machine-number small { font-size: 15px; display: block; color: var(--text-muted); font-weight: 700; letter-spacing: 1px; }

.machine-name {
  font-size: 16px;
  font-weight: 700;
}
.machine-cat {
  font-size: 12px;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 1px;
}

.empty-state {
  text-align: center;
  padding: 60px 20px;
  color: var(--text-muted);
  font-size: 18px;
}

/* ---------- Tela da máquina ---------- */
.back-btn {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 12px 20px;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: var(--bg-card);
  font-weight: 700;
  cursor: pointer;
  font-size: 15px;
}
.back-btn:active { transform: scale(0.96); }

.machine-header {
  display: flex;
  gap: 20px;
  align-items: center;
  margin: 24px 0 8px;
  flex-wrap: wrap;
}
.machine-header .badge {
  background: var(--accent);
  color: #05170c;
  font-weight: 900;
  font-size: 22px;
  border-radius: 16px;
  padding: 10px 18px;
  min-width: 64px;
  text-align: center;
}
.machine-header img.thumb {
  width: 84px;
  height: 84px;
  object-fit: cover;
  border-radius: 16px;
  border: 1px solid var(--border);
}
.machine-header h1 { margin: 0; font-size: clamp(22px, 3vw, 32px); }
.machine-header .cat-tag {
  display: inline-block;
  margin-top: 6px;
  font-size: 12px;
  color: var(--accent);
  text-transform: uppercase;
  letter-spacing: 1.5px;
  font-weight: 700;
}

.machine-desc {
  color: var(--text-muted);
  font-size: 16px;
  line-height: 1.5;
  max-width: 900px;
  margin: 14px 0;
}
.machine-warning {
  display: flex;
  gap: 10px;
  align-items: flex-start;
  background: rgba(255, 176, 32, 0.1);
  border: 1px solid rgba(255, 176, 32, 0.35);
  color: #ffcf7a;
  padding: 14px 16px;
  border-radius: var(--radius-md);
  font-size: 14px;
  margin-bottom: 20px;
  max-width: 900px;
}

.content-grid {
  display: grid;
  grid-template-columns: minmax(0, 2fr) minmax(260px, 1fr);
  gap: 26px;
  margin-top: 10px;
}
@media (max-width: 900px) {
  .content-grid { grid-template-columns: 1fr; }
}

.player-wrap {
  background: #000;
  border-radius: var(--radius-lg);
  overflow: hidden;
  aspect-ratio: 16/9;
  border: 1px solid var(--border);
}
.player-wrap iframe, .player-wrap video {
  width: 100%;
  height: 100%;
  border: none;
  display: block;
}

.video-list {
  display: flex;
  flex-direction: column;
  gap: 12px;
}
.video-item {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 16px;
  border-radius: var(--radius-md);
  background: var(--bg-card);
  border: 1px solid var(--border);
  cursor: pointer;
  transition: border-color 0.15s ease, background 0.15s ease;
}
.video-item:active { transform: scale(0.98); }
.video-item.active {
  border-color: var(--accent);
  background: var(--accent-soft);
}
.video-item .play-ico {
  width: 42px;
  height: 42px;
  border-radius: 50%;
  background: var(--accent);
  color: #05170c;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 16px;
  flex-shrink: 0;
}
.video-item .video-title { font-weight: 700; font-size: 15px; }
.video-item .video-sub { font-size: 12px; color: var(--text-muted); margin-top: 2px; }

.qr-box {
  margin-top: 22px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 18px;
  display: flex;
  gap: 16px;
  align-items: center;
}
.qr-box img { width: 90px; height: 90px; border-radius: 8px; background: #fff; padding: 6px; }
.qr-box .qr-text { font-size: 13px; color: var(--text-muted); }

/* ---------- Idle overlay ---------- */
.idle-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.85);
  display: none;
  align-items: center;
  justify-content: center;
  z-index: 100;
  flex-direction: column;
  gap: 14px;
  color: #fff;
  text-align: center;
  padding: 20px;
}
.idle-overlay.show { display: flex; }
.idle-overlay .count { font-size: 64px; font-weight: 900; color: var(--accent); }

/* ---------- Admin ---------- */
.admin-shell { display: flex; min-height: 100vh; }
.admin-sidebar {
  width: 240px;
  background: var(--bg-elevated);
  border-right: 1px solid var(--border);
  padding: 22px 16px;
  display: flex;
  flex-direction: column;
  gap: 6px;
  flex-shrink: 0;
}
.admin-sidebar .logo-row { display:flex; align-items:center; gap:10px; padding: 4px 8px 20px; }
.admin-sidebar a {
  padding: 12px 14px;
  border-radius: 10px;
  color: var(--text-muted);
  font-weight: 600;
  font-size: 14px;
  display: flex;
  align-items: center;
  gap: 10px;
}
.admin-sidebar a.active, .admin-sidebar a:hover { background: var(--accent-soft); color: var(--accent); }
.admin-main { flex: 1; padding: 30px 34px; max-width: 1200px; }

.login-shell {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
}
.login-card {
  width: 100%;
  max-width: 380px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 34px;
  box-shadow: var(--shadow);
}
.login-card h1 { font-size: 22px; margin: 4px 0 4px; }
.login-card p { color: var(--text-muted); font-size: 14px; margin-bottom: 22px; }

.field { margin-bottom: 16px; display: flex; flex-direction: column; gap: 6px; }
.field label { font-size: 13px; font-weight: 700; color: var(--text-muted); }
.field input, .field select, .field textarea {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 12px 14px;
  color: var(--text);
  font-size: 15px;
  outline: none;
}
.field input:focus, .field select:focus, .field textarea:focus { border-color: var(--accent); }
.field textarea { resize: vertical; min-height: 70px; }

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 13px 22px;
  border-radius: var(--radius-sm);
  border: none;
  font-weight: 700;
  font-size: 15px;
  cursor: pointer;
  transition: transform 0.1s ease, opacity 0.15s ease;
}
.btn:active { transform: scale(0.97); }
.btn-primary { background: var(--accent); color: #05170c; }
.btn-secondary { background: var(--bg-card); color: var(--text); border: 1px solid var(--border); }
.btn-danger { background: var(--danger); color: #fff; }
.btn-block { width: 100%; }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }

.error-msg {
  background: rgba(255, 77, 94, 0.12);
  border: 1px solid rgba(255, 77, 94, 0.4);
  color: #ff8b96;
  padding: 10px 14px;
  border-radius: var(--radius-sm);
  font-size: 13px;
  margin-bottom: 14px;
  display: none;
}
.error-msg.show { display: block; }

.success-msg {
  background: var(--accent-soft);
  border: 1px solid var(--accent);
  color: var(--accent);
  padding: 10px 14px;
  border-radius: var(--radius-sm);
  font-size: 13px;
  margin-bottom: 14px;
  display: none;
}
.success-msg.show { display: block; }

.page-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 14px;
  margin-bottom: 22px;
}
.page-head h1 { margin: 0; font-size: 24px; }
.page-head p { margin: 4px 0 0; color: var(--text-muted); font-size: 14px; }

.stat-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 16px;
  margin-bottom: 26px;
}
.stat-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 20px;
}
.stat-card .stat-value { font-size: 30px; font-weight: 800; color: var(--accent); }
.stat-card .stat-label { color: var(--text-muted); font-size: 13px; margin-top: 4px; }

table.data-table {
  width: 100%;
  border-collapse: collapse;
  background: var(--bg-card);
  border-radius: var(--radius-md);
  overflow: hidden;
  border: 1px solid var(--border);
}
table.data-table th, table.data-table td {
  padding: 13px 16px;
  text-align: left;
  font-size: 14px;
  border-bottom: 1px solid var(--border);
}
table.data-table th { color: var(--text-muted); font-weight: 700; font-size: 12px; text-transform: uppercase; letter-spacing: 0.5px; }
table.data-table tr:last-child td { border-bottom: none; }
table.data-table tr:hover td { background: rgba(255,255,255,0.02); }

.row-actions { display: flex; gap: 8px; }
.row-actions button {
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--text);
  padding: 7px 12px;
  border-radius: 8px;
  cursor: pointer;
  font-size: 12px;
  font-weight: 700;
}
.row-actions button.danger { color: var(--danger); border-color: rgba(255,77,94,0.4); }

.badge-pill {
  display: inline-block;
  padding: 4px 10px;
  border-radius: 999px;
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
}
.badge-on { background: var(--accent-soft); color: var(--accent); }
.badge-off { background: rgba(255,77,94,0.12); color: var(--danger); }

.modal-overlay {
  position: fixed; inset: 0; background: rgba(0,0,0,0.6);
  display: none; align-items: center; justify-content: center; z-index: 200; padding: 20px;
}
.modal-overlay.show { display: flex; }
.modal-box {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 28px;
  width: 100%;
  max-width: 520px;
  max-height: 90vh;
  overflow-y: auto;
}
.modal-box h2 { margin-top: 0; font-size: 19px; }
.modal-actions { display: flex; justify-content: flex-end; gap: 10px; margin-top: 20px; }

.two-col { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
@media (max-width: 520px) { .two-col { grid-template-columns: 1fr; } }

.section-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 22px;
  margin-bottom: 20px;
}
.section-card h3 { margin-top: 0; font-size: 16px; }

.fullscreen-fab {
  position: fixed;
  bottom: 20px;
  right: 20px;
  z-index: 30;
}

@media (max-width: 640px) {
  .topbar { padding: 14px 16px; }
  .home-wrap { padding: 16px; }
  .admin-shell { flex-direction: column; }
  .admin-sidebar { width: 100%; flex-direction: row; overflow-x: auto; }
  .admin-main { padding: 20px; }
}
