:root {
  --bg: #f5f6f8;
  --surface: #ffffff;
  --sidebar-bg: #ffffff;
  --border: #e1e4e8;
  --text: #1f2328;
  --text-muted: #6b7280;
  --primary: #2f6feb;
  --primary-hover: #2557c7;
  --primary-wash: rgba(47, 111, 235, 0.1);
  --danger: #d64545;
  --danger-hover: #b53838;
  --success: #1e8e5a;
  --status-good: #0ca30c;
  --status-warning: #b8790f;
  --status-critical: #d03b3b;
  --radius: 8px;
  --shadow: 0 1px 2px rgba(0, 0, 0, 0.06), 0 1px 6px rgba(0, 0, 0, 0.04);
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #14161a;
    --surface: #1d2026;
    --sidebar-bg: #191b20;
    --border: #2c3038;
    --text: #e8eaed;
    --text-muted: #9aa0a6;
    --primary: #5b8def;
    --primary-hover: #82a9f2;
    --primary-wash: rgba(91, 141, 239, 0.15);
    --danger: #e56a6a;
    --danger-hover: #ee8a8a;
    --success: #4fbd85;
    --status-good: #4fbd85;
    --status-warning: #f0b84a;
    --status-critical: #e88686;
    --shadow: 0 1px 2px rgba(0, 0, 0, 0.3), 0 1px 8px rgba(0, 0, 0, 0.25);
  }
}
:root[data-theme="dark"] {
  --bg: #14161a;
  --surface: #1d2026;
  --sidebar-bg: #191b20;
  --border: #2c3038;
  --text: #e8eaed;
  --text-muted: #9aa0a6;
  --primary: #5b8def;
  --primary-hover: #82a9f2;
  --primary-wash: rgba(91, 141, 239, 0.15);
  --danger: #e56a6a;
  --danger-hover: #ee8a8a;
  --success: #4fbd85;
  --status-good: #4fbd85;
  --status-warning: #f0b84a;
  --status-critical: #e88686;
  --shadow: 0 1px 2px rgba(0, 0, 0, 0.3), 0 1px 8px rgba(0, 0, 0, 0.25);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
}

.app {
  display: flex;
  min-height: 100vh;
}

.sidebar {
  width: 220px;
  flex: 0 0 220px;
  background: var(--sidebar-bg);
  border-right: 1px solid var(--border);
  padding: 20px 12px;
  position: sticky;
  top: 0;
  height: 100vh;
  overflow-y: auto;
}

.brand {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 4px 10px 20px;
}

.brand-mark {
  font-size: 1.2rem;
}

.brand-name {
  font-weight: 700;
  font-size: 1rem;
}

.side-nav {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.nav-btn {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  text-align: left;
  background: none;
  border: none;
  border-radius: 6px;
  padding: 10px 12px;
  font-size: 0.9rem;
  color: var(--text-muted);
  cursor: pointer;
}

.nav-icon {
  width: 18px;
  text-align: center;
  font-size: 0.95rem;
}

.nav-btn:hover {
  background: rgba(127, 127, 127, 0.08);
  color: var(--text);
}

.nav-btn.active {
  background: var(--primary-wash);
  color: var(--primary);
  font-weight: 600;
}

.content {
  flex: 1;
  min-width: 0;
  padding: 28px 32px 60px;
  max-width: 1000px;
}

.view-title {
  margin: 0;
  font-size: 1.4rem;
}

.view-subtitle {
  margin: 4px 0 20px;
  color: var(--text-muted);
  font-size: 0.9rem;
}

.view-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 16px;
}

.view-header .view-title {
  margin: 0;
}

.filter-bar {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  margin-bottom: 16px;
}

.dropdown-select {
  position: relative;
}

.dropdown-select-btn {
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 170px;
  max-width: 220px;
  text-align: left;
  cursor: pointer;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.dropdown-select-btn::after {
  content: "▾";
  margin-left: auto;
  font-size: 0.7rem;
  color: var(--text-muted);
  flex: 0 0 auto;
}

.dropdown-select-menu {
  position: absolute;
  top: calc(100% + 4px);
  left: 0;
  z-index: 20;
  min-width: 200px;
  max-height: 220px;
  overflow-y: auto;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 6px;
  box-shadow: var(--shadow);
  padding: 6px;
}

.dropdown-select-option {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 8px;
  font-size: 0.88rem;
  border-radius: 4px;
  cursor: pointer;
  white-space: nowrap;
}

.dropdown-select-option:hover {
  background: rgba(127, 127, 127, 0.08);
}

.dropdown-select-option input {
  cursor: pointer;
}

.dropdown-select-divider {
  height: 1px;
  background: var(--border);
  margin: 6px 2px;
}

.filter-search {
  flex: 1 1 260px;
  max-width: 320px;
  padding: 8px 12px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--surface);
  color: var(--text);
  font-size: 0.88rem;
}

.filter-status {
  padding: 8px 12px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--surface);
  color: var(--text);
  font-size: 0.88rem;
}

.filter-search:focus,
.filter-status:focus {
  outline: 2px solid var(--primary);
  outline-offset: -1px;
}

.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(11, 11, 11, 0.45);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  z-index: 100;
}

.modal-overlay[hidden] {
  display: none;
}

#form-modal {
  z-index: 110;
}

.modal {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: 0 8px 30px rgba(0, 0, 0, 0.25);
  width: 100%;
  max-width: 520px;
  max-height: 90vh;
  overflow-y: auto;
  padding: 20px 24px 24px;
}

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 16px;
}

.modal-title {
  margin: 0;
  font-size: 1.05rem;
}

.modal-close {
  background: none;
  border: none;
  font-size: 1.3rem;
  line-height: 1;
  color: var(--text-muted);
  cursor: pointer;
  padding: 4px 8px;
  border-radius: 6px;
}

.modal-close:hover {
  color: var(--text);
  background: rgba(127, 127, 127, 0.1);
}

.modal .form {
  align-items: stretch;
}

.modal .field {
  flex: 1 1 100%;
}

.modal .form-actions {
  flex: 1 1 100%;
  justify-content: flex-end;
  margin-top: 4px;
}

.modal-wide {
  max-width: 760px;
}

.detail-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
  gap: 12px 20px;
  margin: 0 0 22px;
}

.detail-grid div {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.detail-label {
  font-size: 0.75rem;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.03em;
}

.detail-value {
  font-size: 0.92rem;
}

.view-section-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin: 4px 0 12px;
}

/* separa visualmente uma seção (ex: Avaliações) da tabela da seção anterior
   (ex: Cursos) na ficha do piloto, apenas com espaço */
.table-wrap + .view-section-header {
  margin-top: 32px;
}

.view-section-header h3 {
  margin: 0;
  font-size: 1rem;
}

tbody tr.row-clickable {
  cursor: pointer;
}

.panel {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 20px;
}

.form {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  align-items: end;
}

.field {
  display: flex;
  flex-direction: column;
  gap: 4px;
  flex: 1 1 160px;
  min-width: 140px;
}

.field label {
  font-size: 0.78rem;
  color: var(--text-muted);
}

.field-hint {
  font-size: 0.76rem;
  color: var(--text-muted);
}

.cert-link {
  color: var(--primary);
  text-decoration: none;
}

.cert-link:hover {
  text-decoration: underline;
}

.field input,
.field select {
  padding: 8px 10px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--bg);
  color: var(--text);
  font-size: 0.9rem;
}

.field input:focus,
.field select:focus {
  outline: 2px solid var(--primary);
  outline-offset: -1px;
}

.form-actions {
  display: flex;
  gap: 8px;
}

.field-wide {
  flex-basis: 100%;
}

.dual-list {
  display: flex;
  gap: 12px;
}

.dual-list-col {
  display: flex;
  flex-direction: column;
  gap: 6px;
  flex: 1 1 50%;
  min-width: 0;
}

.dual-list-header {
  font-size: 0.78rem;
  color: var(--text-muted);
}

.dual-list-box {
  display: flex;
  flex-direction: column;
  gap: 4px;
  height: 160px;
  overflow-y: auto;
  padding: 6px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--bg);
}

.dual-list-item {
  display: block;
  width: 100%;
  text-align: left;
  padding: 6px 8px;
  border: 1px solid transparent;
  border-radius: 6px;
  background: transparent;
  color: var(--text);
  font-size: 0.85rem;
  cursor: pointer;
}

.dual-list-item:hover {
  background: var(--primary-wash);
  border-color: var(--border);
}

.dual-list-item-selected {
  background: var(--primary-wash);
  color: var(--primary);
}

.dual-list-empty {
  color: var(--text-muted);
  font-size: 0.82rem;
  padding: 6px 8px;
}

button.primary,
button.secondary,
button.danger {
  cursor: pointer;
  border: none;
  border-radius: 6px;
  padding: 9px 16px;
  font-size: 0.9rem;
  font-weight: 500;
}

button.primary {
  background: var(--primary);
  color: white;
}
button.primary:hover {
  background: var(--primary-hover);
}

button.secondary {
  background: transparent;
  color: var(--text-muted);
  border: 1px solid var(--border);
}
button.secondary:hover {
  color: var(--text);
}

button.danger {
  background: transparent;
  color: var(--danger);
  border: 1px solid var(--border);
  padding: 5px 10px;
  font-size: 0.8rem;
}
button.danger:hover {
  background: var(--danger);
  color: white;
}

button.link {
  background: transparent;
  border: 1px solid var(--border);
  color: var(--text-muted);
  padding: 5px 10px;
  font-size: 0.8rem;
  border-radius: 6px;
  cursor: pointer;
  margin-right: 6px;
}
button.link:hover {
  color: var(--text);
}

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

.section-title {
  margin: 28px 0 12px;
  font-size: 1.05rem;
}

.expiry-badge {
  display: inline-block;
  padding: 3px 9px;
  border-radius: 999px;
  font-size: 0.75rem;
  font-weight: 600;
}

.expiry-badge.ok { background: rgba(12, 163, 12, 0.15); color: var(--status-good); }
.expiry-badge.warning { background: rgba(184, 121, 15, 0.15); color: var(--status-warning); }
.expiry-badge.critical { background: rgba(208, 59, 59, 0.15); color: var(--status-critical); }

.stat-tile {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 18px 20px;
}

.stat-label {
  color: var(--text-muted);
  font-size: 0.82rem;
}

.stat-value {
  font-size: 2rem;
  font-weight: 600;
  margin: 4px 0 12px;
  font-variant-numeric: proportional-nums;
}

.stat-breakdown {
  display: flex;
  flex-wrap: wrap;
  gap: 6px 14px;
}

.stat-breakdown-item {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 0.8rem;
  color: var(--text-muted);
}

.stat-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  flex: 0 0 auto;
}

.stat-dot.good { background: var(--status-good); }
.stat-dot.warning { background: var(--status-warning); }
.stat-dot.critical { background: var(--status-critical); }
.stat-dot.neutral { background: var(--text-muted); }

.stat-empty {
  color: var(--text-muted);
  font-size: 0.8rem;
}

.table-wrap {
  overflow-x: auto;
}

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.88rem;
}

th, td {
  text-align: left;
  padding: 10px 12px;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}

th {
  color: var(--text-muted);
  font-weight: 600;
  font-size: 0.78rem;
  text-transform: uppercase;
  letter-spacing: 0.03em;
}

tbody tr:hover {
  background: rgba(127, 127, 127, 0.06);
}

.badge {
  display: inline-block;
  padding: 3px 9px;
  border-radius: 999px;
  font-size: 0.75rem;
  font-weight: 600;
}

.badge.ok { background: rgba(30, 142, 90, 0.15); color: var(--success); }
.badge.warn { background: rgba(214, 69, 69, 0.15); color: var(--danger); }
.badge.neutral { background: rgba(127,127,127,0.15); color: var(--text-muted); }

.empty-msg {
  text-align: center;
  color: var(--text-muted);
  padding: 24px 0;
}

.empty-msg.error {
  color: var(--danger);
}

th.sortable {
  cursor: pointer;
  user-select: none;
}

th.sortable:hover {
  color: var(--text);
}

.sarpas-status-bar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  padding: 2px 2px 10px;
  font-size: 0.78rem;
}

.sarpas-last-updated {
  color: var(--text-muted);
}

.sarpas-refresh-warning {
  color: var(--danger);
}

.logout-btn {
  margin-top: auto;
}

.auth-screen {
  position: fixed;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--bg);
  padding: 20px;
  z-index: 200;
}

.auth-screen[hidden] {
  display: none;
}

.auth-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: 0 8px 30px rgba(0, 0, 0, 0.25);
  width: 100%;
  max-width: 360px;
  padding: 24px 24px 28px;
}

.auth-card .brand {
  justify-content: center;
  padding: 0 0 20px;
}

.auth-error {
  color: var(--danger);
  font-size: 0.85rem;
  margin: 0 0 12px;
}

.link-box {
  display: flex;
  gap: 8px;
}

.link-box input {
  flex: 1;
}

.checkbox-row {
  display: flex;
  flex-wrap: wrap;
  gap: 14px;
}

.checkbox-item {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 0.88rem;
  font-weight: 400;
  cursor: pointer;
}

.subtab-bar {
  display: flex;
  gap: 4px;
  border-bottom: 1px solid var(--border);
  margin-bottom: 20px;
}

.subtab-btn {
  background: none;
  border: none;
  border-bottom: 2px solid transparent;
  padding: 10px 14px;
  font-size: 0.88rem;
  color: var(--text-muted);
  cursor: pointer;
}

.subtab-btn:hover {
  color: var(--text);
}

.subtab-btn.active {
  color: var(--primary);
  border-bottom-color: var(--primary);
  font-weight: 600;
}

.subpanel[hidden] {
  display: none;
}

.canal-card {
  margin-bottom: 16px;
}

.canal-card-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 10px;
}

.canal-card-title {
  font-weight: 600;
}

.canal-card-subtitle {
  color: var(--text-muted);
  font-size: 0.82rem;
  margin-top: 2px;
}

.chip-row {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin: 6px 0 12px;
}

.chip {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 3px 10px;
  border-radius: 999px;
  font-size: 0.75rem;
  background: rgba(127, 127, 127, 0.12);
  color: var(--text-muted);
}

.chip.live {
  background: rgba(30, 142, 90, 0.15);
  color: var(--success);
}

.chip.live::before {
  content: "●";
  font-size: 0.6rem;
}

.channel-card {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  cursor: pointer;
  margin-bottom: 10px;
}

.channel-card:hover {
  border-color: var(--primary);
}

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

.video-tile {
  position: relative;
  background: #000;
  border-radius: var(--radius);
  overflow: hidden;
  aspect-ratio: 16 / 9;
}

.video-tile video {
  width: 100%;
  height: 100%;
  object-fit: contain;
  background: #000;
}

.video-tile-label {
  position: absolute;
  top: 8px;
  left: 8px;
  padding: 3px 9px;
  border-radius: 999px;
  font-size: 0.75rem;
  background: rgba(0, 0, 0, 0.6);
  color: #fff;
}

.video-tile-offline {
  display: flex;
  align-items: center;
  justify-content: center;
  height: 100%;
  color: var(--text-muted);
  font-size: 0.85rem;
  background: rgba(127, 127, 127, 0.08);
}

.rtmp-url {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-top: 6px;
  font-size: 0.78rem;
  color: var(--text-muted);
}

.rtmp-url code {
  background: rgba(127, 127, 127, 0.12);
  padding: 2px 6px;
  border-radius: 4px;
}

.toast {
  position: fixed;
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%);
  background: var(--text);
  color: var(--bg);
  padding: 10px 18px;
  border-radius: 6px;
  font-size: 0.85rem;
  box-shadow: var(--shadow);
}

.toast.error {
  background: var(--danger);
  color: white;
}
