:root {
  --navy: #16295e;
  --navy-dark: #0f1d45;
  --blue: #1d5bd8;
  --blue-dark: #1747ab;
  --blue-soft: #eaf0fc;
  --bg: #f4f6fb;
  --card: #ffffff;
  --border: #e3e8f2;
  --text: #1c2333;
  --muted: #64748b;
  --success: #16a34a;
  --success-soft: #e8f7ee;
  --warning: #d97706;
  --warning-soft: #fdf3e3;
  --danger: #dc2626;
  --danger-soft: #fdecec;
  --radius: 14px;
  --shadow: 0 1px 3px rgba(22, 41, 94, 0.08), 0 8px 24px rgba(22, 41, 94, 0.06);
}

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

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Inter', Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
}

header {
  background: var(--card);
  border-bottom: 1px solid var(--border);
  padding: 10px 28px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 12px;
  position: sticky;
  top: 0;
  z-index: 10;
  box-shadow: 0 1px 3px rgba(22, 41, 94, 0.06);
}

.brand { display: flex; align-items: center; gap: 10px; text-decoration: none; }
.brand img { height: 52px; width: auto; display: block; }

nav { display: flex; gap: 6px; flex-wrap: wrap; }

nav a {
  color: var(--muted);
  text-decoration: none;
  padding: 9px 16px;
  border-radius: 10px;
  font-size: 14px;
  font-weight: 600;
  transition: all .15s ease;
}

nav a:hover { background: var(--blue-soft); color: var(--blue); }
nav a.active { background: var(--navy); color: #fff; }

main { max-width: 1100px; margin: 0 auto; padding: 28px 24px; }

.grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(300px, 1fr)); gap: 22px; }

.card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 24px;
  box-shadow: var(--shadow);
}

.card h2 {
  font-size: 15px;
  margin-bottom: 16px;
  color: var(--navy);
  text-transform: uppercase;
  letter-spacing: .06em;
  font-weight: 700;
}

.status-badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 6px 14px;
  border-radius: 999px;
  font-size: 13px;
  font-weight: 600;
}

.status-connected { background: var(--success-soft); color: var(--success); }
.status-waiting { background: var(--warning-soft); color: var(--warning); }
.status-error, .status-disabled { background: var(--danger-soft); color: var(--danger); }
.status-starting { background: var(--blue-soft); color: var(--blue); }

.qr-box { text-align: center; margin-top: 14px; }
.qr-box img {
  width: 240px; height: 240px;
  border-radius: 12px;
  background: #fff;
  padding: 8px;
  border: 1px solid var(--border);
}

label {
  display: block;
  font-size: 13px;
  font-weight: 600;
  color: var(--navy);
  margin: 14px 0 6px;
}

input {
  width: 100%;
  padding: 11px 14px;
  background: var(--card);
  border: 1.5px solid var(--border);
  border-radius: 10px;
  color: var(--text);
  font-size: 15px;
  transition: border-color .15s ease, box-shadow .15s ease;
}

input:focus {
  outline: none;
  border-color: var(--blue);
  box-shadow: 0 0 0 3px rgba(29, 91, 216, 0.12);
}

input::placeholder { color: #a6b0c3; }

button {
  margin-top: 18px;
  padding: 13px 22px;
  background: var(--blue);
  color: #fff;
  border: none;
  border-radius: 10px;
  font-size: 15px;
  font-weight: 700;
  cursor: pointer;
  width: 100%;
  transition: background .15s ease, transform .05s ease;
}

button:hover { background: var(--blue-dark); }
button:active { transform: scale(.99); }
button:disabled { opacity: .45; cursor: not-allowed; }

button.secondary {
  background: var(--card);
  border: 1.5px solid var(--border);
  color: var(--navy);
}
button.secondary:hover { background: var(--blue-soft); }

button.danger {
  background: var(--danger);
  width: auto;
  padding: 7px 14px;
  margin: 0;
  font-size: 13px;
}

.video-wrap {
  position: relative;
  width: 100%;
  border-radius: 12px;
  overflow: hidden;
  background: #0f1d45;
  border: 1px solid var(--border);
}
.video-wrap video { width: 100%; display: block; }
.video-wrap canvas { position: absolute; top: 0; left: 0; width: 100%; height: 100%; }

.msg {
  margin-top: 14px;
  padding: 11px 15px;
  border-radius: 10px;
  font-size: 14px;
  font-weight: 500;
  display: none;
}
.msg.show { display: block; }
.msg.success { background: var(--success-soft); color: var(--success); }
.msg.error { background: var(--danger-soft); color: var(--danger); }
.msg.info { background: var(--blue-soft); color: var(--blue); }

table { width: 100%; border-collapse: collapse; font-size: 14px; }
th, td { text-align: left; padding: 12px 10px; border-bottom: 1px solid var(--border); }
th {
  color: var(--muted);
  font-weight: 600;
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: .05em;
}
tbody tr:hover { background: var(--bg); }

.log-list { list-style: none; max-height: 420px; overflow-y: auto; }
.log-list li { padding: 12px 0; border-bottom: 1px solid var(--border); font-size: 14px; }
.log-list li:last-child { border-bottom: none; }
.log-list .time { color: var(--muted); font-size: 12px; }

.big-number { font-size: 44px; font-weight: 800; color: var(--navy); }
.hint { color: var(--muted); font-size: 13px; margin-top: 8px; line-height: 1.5; }

.captures { display: flex; gap: 8px; margin-top: 14px; flex-wrap: wrap; }
.captures .shot {
  width: 64px; height: 64px;
  border-radius: 10px;
  border: 2px solid var(--success);
  object-fit: cover;
}

.mode-toggle { display: flex; gap: 10px; margin-bottom: 14px; }
.mode-toggle a {
  flex: 1;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 11px;
  border-radius: 10px;
  text-decoration: none;
  color: #fff;
  font-weight: 700;
  font-size: 14px;
  opacity: .35;
  transition: opacity .15s ease;
}
.mode-toggle a:hover { opacity: .75; }
.mode-toggle a.entrada { background: var(--success); }
.mode-toggle a.saida { background: var(--danger); }
.mode-toggle a.on { opacity: 1; box-shadow: var(--shadow); }

.link-code {
  font-family: 'SF Mono', Menlo, monospace;
  font-size: 34px;
  font-weight: 700;
  letter-spacing: 5px;
  margin-top: 12px;
  color: var(--blue);
}

.icon {
  width: 16px;
  height: 16px;
  fill: none;
  stroke: currentColor;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
  vertical-align: -3px;
  flex-shrink: 0;
}

nav a { display: inline-flex; align-items: center; gap: 7px; }

.status-badge::before {
  content: '';
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: currentColor;
  flex-shrink: 0;
}

.log-list li { display: flex; gap: 10px; align-items: flex-start; }
.log-list li .icon { margin-top: 2px; color: var(--muted); }
.log-list li .icon-in { color: var(--success); }
.log-list li .icon-out { color: var(--blue); }
.log-list li .icon-err { color: var(--danger); }

button { display: inline-flex; align-items: center; justify-content: center; gap: 8px; }
button .icon { width: 17px; height: 17px; }

.stat-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(190px, 1fr));
  gap: 16px;
}

.stat-tile {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 18px 20px;
  box-shadow: var(--shadow);
  display: flex;
  align-items: center;
  gap: 14px;
}

.stat-icon {
  width: 42px;
  height: 42px;
  border-radius: 12px;
  background: var(--blue-soft);
  color: var(--blue);
  display: flex;
  align-items: center;
  justify-content: center;
}
.stat-icon .icon { width: 20px; height: 20px; }
.stat-icon-in { background: var(--success-soft); color: var(--success); }
.stat-icon-out { background: var(--blue-soft); color: var(--blue); }

.stat-value { font-size: 28px; font-weight: 800; color: var(--navy); line-height: 1.1; }
.stat-label { font-size: 12px; color: var(--muted); font-weight: 600; }

.chart-legend {
  display: flex;
  gap: 18px;
  font-size: 13px;
  color: var(--muted);
  font-weight: 600;
  margin-bottom: 12px;
}
.chart-legend span { display: inline-flex; align-items: center; gap: 6px; }
.swatch { width: 11px; height: 11px; border-radius: 3px; display: inline-block; }
.swatch-entrada { background: #16a34a; }
.swatch-saida { background: #1d5bd8; }

.chart {
  display: flex;
  align-items: flex-end;
  gap: 8px;
  min-height: 170px;
  border-bottom: 1px solid var(--border);
  padding: 0 10px 2px 0;
  overflow-x: auto;
}

.bar-group { display: flex; flex-direction: column; align-items: center; gap: 6px; flex: 1; min-width: 30px; }
.bars { display: flex; align-items: flex-end; gap: 2px; height: 145px; }
.bar-wrap { display: flex; flex-direction: column; align-items: center; justify-content: flex-end; }
.bar {
  width: 11px;
  border-radius: 4px 4px 0 0;
  transition: opacity .15s ease;
}
.bar-wrap:hover .bar { opacity: .75; }
.bar-entrada { background: #16a34a; }
.bar-saida { background: #1d5bd8; }
.bar-label { font-size: 11px; font-weight: 700; color: var(--text); margin-bottom: 3px; }
.bar-x { font-size: 11px; color: var(--muted); font-weight: 600; }

@media (max-width: 700px) {
  main { padding: 14px; }
  header { padding: 10px 14px; }
  .brand img { height: 42px; }
  nav a { padding: 8px 10px; font-size: 13px; }
}
