:root {
  --bg-primary: #0f172a;
  --bg-secondary: #1e293b;
  --bg-card: #1e293b;
  --bg-card-hover: #273549;
  --border-color: #334155;
  --text-primary: #f8fafc;
  --text-secondary: #94a3b8;
  --text-muted: #64748b;
  
  --accent-primary: #6366f1;
  --accent-hover: #4f46e5;
  --accent-glow: rgba(99, 102, 241, 0.3);

  --status-waiting: #3b82f6;
  --status-waiting-bg: rgba(59, 130, 246, 0.15);
  
  --status-ready: #10b981;
  --status-ready-bg: rgba(16, 185, 129, 0.2);
  
  --status-ended: #64748b;
  --status-ended-bg: rgba(100, 116, 139, 0.2);
  
  --status-danger: #ef4444;
  --status-danger-bg: rgba(239, 68, 68, 0.2);

  --font-family: system-ui, -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, sans-serif;
}

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

body {
  font-family: var(--font-family);
  background: var(--bg-primary);
  color: var(--text-primary);
  line-height: 1.5;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

/* Header */
.app-header {
  background: var(--bg-secondary);
  border-bottom: 1px solid var(--border-color);
  padding: 1rem 1.5rem;
  position: sticky;
  top: 0;
  z-index: 100;
  backdrop-filter: blur(8px);
}

.header-container {
  max-width: 1200px;
  margin: 0 auto;
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 1.25rem;
}

.logo-section {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  flex-wrap: wrap;
  min-width: 0;
}

.site-logo {
  display: block;
  width: 278px;
  max-width: 100%;
  height: auto;
}

.logo-title h1 {
  font-size: 1.25rem;
  font-weight: 700;
  letter-spacing: -0.02em;
}

.logo-title p {
  font-size: 0.75rem;
  color: var(--text-secondary);
}

/* Header Controls */
.header-actions {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  flex-wrap: wrap;
  width: 100%;
  padding-top: 1rem;
  border-top: 1px solid var(--border-color);
}

.header-actions .developer-contact {
  margin-left: auto;
}

.status-pill {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  background: #0f172a;
  padding: 0.4rem 0.8rem;
  border-radius: 9999px;
  font-size: 0.8rem;
  color: var(--text-secondary);
  border: 1px solid var(--border-color);
}

.pulse-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: #10b981;
  box-shadow: 0 0 8px #10b981;
  animation: pulse-dot 1.8s infinite;
}

@keyframes pulse-dot {
  0% { transform: scale(0.95); opacity: 0.8; }
  50% { transform: scale(1.3); opacity: 1; box-shadow: 0 0 12px #10b981; }
  100% { transform: scale(0.95); opacity: 0.8; }
}

.pulse-dot.paused {
  background: #f59e0b;
  box-shadow: 0 0 8px #f59e0b;
  animation: none;
}

/* Audio control bar */
.audio-controls {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  background: #0f172a;
  padding: 0.35rem 0.75rem;
  border-radius: 8px;
  border: 1px solid var(--border-color);
  font-size: 0.85rem;
}

.volume-slider {
  width: 70px;
  accent-color: var(--accent-primary);
  cursor: pointer;
}

/* Main Container */
.main-content {
  max-width: 1200px;
  margin: 1.5rem auto;
  padding: 0 1.5rem;
  width: 100%;
  flex: 1;
}

/* Input Card */
.card {
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: 12px;
  padding: 1.25rem;
  margin-bottom: 1.5rem;
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.2);
}

.card-title {
  font-size: 1.05rem;
  font-weight: 600;
  margin-bottom: 0.75rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.input-group {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}

.textarea-links {
  width: 100%;
  min-height: 80px;
  background: #0f172a;
  border: 1px solid var(--border-color);
  border-radius: 8px;
  padding: 0.75rem;
  color: var(--text-primary);
  font-family: monospace;
  font-size: 0.85rem;
  resize: vertical;
  outline: none;
  transition: border-color 0.2s;
}

.textarea-links:focus {
  border-color: var(--accent-primary);
  box-shadow: 0 0 0 2px var(--accent-glow);
}

.input-actions {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 0.75rem;
}

.btn {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  padding: 0.55rem 1.1rem;
  border-radius: 8px;
  font-weight: 600;
  font-size: 0.875rem;
  cursor: pointer;
  border: none;
  transition: all 0.2s ease;
  user-select: none;
  text-decoration: none;
}

a.btn, .card-actions a {
  text-decoration: none !important;
}

.btn-primary {
  background: var(--accent-primary);
  color: #fff;
  box-shadow: 0 2px 8px var(--accent-glow);
}

.btn-primary:hover {
  background: var(--accent-hover);
  transform: translateY(-1px);
}

.btn-secondary {
  background: #334155;
  color: var(--text-primary);
}

.btn-secondary:hover {
  background: #475569;
}

.btn-outline {
  background: transparent;
  border: 1px solid var(--border-color);
  color: var(--text-secondary);
}

.btn-outline:hover {
  background: #334155;
  color: var(--text-primary);
}

.btn-danger {
  background: var(--status-danger);
  color: #fff;
}

.btn-danger:hover {
  background: #dc2626;
}

.btn-success {
  background: var(--status-ready);
  color: #fff;
}

.btn-success:hover {
  background: #059669;
}

.btn-sm {
  padding: 0.35rem 0.75rem;
  font-size: 0.8rem;
}

/* Polling & Stats Bar */
.control-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 1rem;
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: 10px;
  padding: 0.75rem 1.25rem;
  margin-bottom: 1.5rem;
  font-size: 0.85rem;
}

.control-bar-left {
  display: flex;
  align-items: center;
  gap: 1.25rem;
  flex-wrap: wrap;
}

.control-item {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  color: var(--text-secondary);
}

.control-select {
  background: #0f172a;
  border: 1px solid var(--border-color);
  color: var(--text-primary);
  padding: 0.3rem 0.6rem;
  border-radius: 6px;
  font-size: 0.85rem;
  outline: none;
}

/* Table of Hearings */
.audiences-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(min(100%, 360px), 1fr));
  gap: 1.25rem;
}

.audience-card {
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: 12px;
  padding: 1.25rem;
  position: relative;
  transition: all 0.25s ease;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
}

.audience-card:hover {
  border-color: #475569;
  background: var(--bg-card-hover);
}

.audience-card.is-ready {
  border: 2px solid #10b981;
  background: linear-gradient(145deg, #132b24, #1e293b);
  box-shadow: 0 0 20px rgba(16, 185, 129, 0.35);
  animation: pulse-ready-card 2s infinite alternate;
}

@keyframes pulse-ready-card {
  0% { box-shadow: 0 0 15px rgba(16, 185, 129, 0.25); border-color: #10b981; }
  100% { box-shadow: 0 0 30px rgba(16, 185, 129, 0.6); border-color: #34d399; }
}

.audience-card.is-ended {
  opacity: 0.7;
}

.card-top {
  display: block;
  margin-bottom: 0.75rem;
  padding-bottom: 0.5rem;
  border-bottom: 1px solid rgba(255, 255, 255, 0.08);
}

.vara-title {
  font-size: 1rem;
  font-weight: 700;
  color: #fff;
  line-height: 1.4;
  word-break: break-word;
}

.badge {
  display: inline-flex;
  align-items: center;
  gap: 0.3rem;
  padding: 0.25rem 0.6rem;
  border-radius: 9999px;
  font-size: 0.75rem;
  font-weight: 600;
  white-space: nowrap;
}

.badge-waiting {
  background: var(--status-waiting-bg);
  color: #60a5fa;
  border: 1px solid rgba(59, 130, 246, 0.3);
}

.badge-scheduled {
  background: rgba(245, 158, 11, 0.15);
  color: #fbbf24;
  border: 1px solid rgba(245, 158, 11, 0.3);
}

.badge-ready {
  background: var(--status-ready-bg);
  color: #34d399;
  border: 1px solid rgba(16, 185, 129, 0.4);
  animation: badge-pulse 1s infinite alternate;
}

@keyframes badge-pulse {
  from { opacity: 0.8; transform: scale(0.98); }
  to { opacity: 1; transform: scale(1.05); }
}

.badge-ended {
  background: var(--status-ended-bg);
  color: #94a3b8;
  border: 1px solid rgba(100, 116, 139, 0.3);
}

.audience-info {
  display: flex;
  flex-direction: column;
  gap: 0.45rem;
  margin-bottom: 1rem;
  font-size: 0.85rem;
}

.info-row {
  display: flex;
  justify-content: space-between;
  color: var(--text-secondary);
  border-bottom: 1px dashed rgba(255, 255, 255, 0.06);
  padding-bottom: 0.25rem;
}

.info-label {
  color: var(--text-muted);
}

.info-value {
  color: var(--text-primary);
  font-weight: 500;
}

.info-processo {
  font-family: monospace;
  font-size: 0.9rem;
  font-weight: 700;
  color: #38bdf8;
}

/* Card Actions */
.card-actions {
  display: flex;
  /* Alinha os botões pela base (bottom) para que fiquem firmes no rodapé */
  align-items: flex-end; 
  justify-content: space-between;
  gap: 0.5rem;
  margin-top: auto; /* Empurra as ações sempre para o fim do card de forma limpa */
  padding-top: 0.75rem;
  border-top: 1px solid var(--border-color);
  width: 100%;
}

.btn-enter {
  flex: 1;
  /* Define uma altura máxima estável para impedir o crescimento vertical */
  height: 38px; 
  /* Impede o texto de quebrar em várias linhas de qualquer forma */
  white-space: nowrap; 
  
  background: linear-gradient(135deg, #10b981, #059669);
  color: #fff;
  font-size: 0.85rem; /* Ajustado levemente para o texto longo caber na horizontal */
  font-weight: 700;
  padding: 0 0.75rem; /* Removido o padding vertical fixo para o height/flex controlar */
  border-radius: 8px;
  text-decoration: none;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.4rem;
  box-shadow: 0 4px 12px rgba(16, 185, 129, 0.3);
  animation: pulse-button 1.5s infinite;
}

@keyframes pulse-button {
  0% { transform: scale(1); }
  50% { transform: scale(1.03); box-shadow: 0 6px 16px rgba(16, 185, 129, 0.5); }
  100% { transform: scale(1); }
}

.btn-enter:hover {
  background: linear-gradient(135deg, #059669, #047857);
}

/* Empty State */
.empty-state {
  text-align: center;
  padding: 3rem 1.5rem;
  background: var(--bg-card);
  border: 2px dashed var(--border-color);
  border-radius: 12px;
  grid-column: 1 / -1;
  color: var(--text-secondary);
}

.empty-icon {
  font-size: 2.5rem;
  margin-bottom: 0.75rem;
}

/* MODAL DE ALARME / OVERLAY */
.alarm-overlay {
  display: none;
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(15, 23, 42, 0.85);
  backdrop-filter: blur(8px);
  z-index: 9999;
  align-items: center;
  justify-content: center;
  padding: 1.5rem;
}

.alarm-overlay.active {
  display: flex;
}

.alarm-modal {
  background: #1e293b;
  border: 3px solid #10b981;
  border-radius: 16px;
  max-width: 580px;
  width: 100%;
  padding: 2rem;
  text-align: center;
  box-shadow: 0 0 50px rgba(16, 185, 129, 0.5);
  animation: modal-flash 1s infinite alternate;
}

@keyframes modal-flash {
  from { border-color: #10b981; box-shadow: 0 0 30px rgba(16, 185, 129, 0.4); }
  to { border-color: #34d399; box-shadow: 0 0 60px rgba(16, 185, 129, 0.8); }
}

.alarm-icon-big {
  font-size: 3.5rem;
  margin-bottom: 0.5rem;
  animation: bell-ring 0.6s infinite alternate;
}

@keyframes bell-ring {
  0% { transform: rotate(-15deg); }
  100% { transform: rotate(15deg); }
}

.alarm-title {
  font-size: 1.6rem;
  font-weight: 800;
  color: #34d399;
  margin-bottom: 0.5rem;
}

.alarm-subtitle {
  font-size: 1.05rem;
  color: var(--text-primary);
  margin-bottom: 1.5rem;
}

.alarm-details-box {
  background: #0f172a;
  border: 1px solid var(--border-color);
  border-radius: 10px;
  padding: 1rem;
  margin-bottom: 1.5rem;
  text-align: left;
  font-size: 0.9rem;
}

.alarm-actions {
  display: flex;
  gap: 1rem;
  justify-content: center;
  flex-wrap: wrap;
}

.alarm-btn-enter {
  flex: 1;
  min-width: 200px;
  background: linear-gradient(135deg, #10b981, #059669);
  color: #fff;
  font-size: 1.1rem;
  font-weight: 800;
  padding: 0.9rem 1.5rem;
  border-radius: 10px;
  text-decoration: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  box-shadow: 0 4px 16px rgba(16, 185, 129, 0.4);
}

.alarm-btn-silence {
  background: #ef4444;
  color: #fff;
  font-size: 1rem;
  font-weight: 700;
  padding: 0.9rem 1.25rem;
  border-radius: 10px;
  border: none;
  cursor: pointer;
}

.alarm-btn-silence:hover {
  background: #dc2626;
}

/* Footer */
.manual-dialog {
  margin: auto;
  width: min(520px, calc(100% - 2rem));
  max-height: calc(100dvh - 2rem);
  overflow-y: auto;
  padding: 1.5rem;
  border: 1px solid var(--border-color);
  border-radius: 12px;
  background: var(--bg-card);
  color: var(--text-primary);
}

.manual-dialog::backdrop {
  background: rgba(0, 0, 0, 0.7);
}

.manual-dialog h2 { font-size: 1.2rem; }
.manual-dialog p { margin-top: 0.75rem; color: var(--text-secondary); font-size: 0.85rem; }
.manual-dialog label { display: block; margin: 1rem 0 0.4rem; }
.manual-dialog input {
  width: 100%;
  min-width: 0;
  padding: 0.75rem;
  border: 1px solid var(--border-color);
  border-radius: 8px;
  background: var(--bg-primary);
  color: var(--text-primary);
  font: inherit;
  color-scheme: dark;
}
.manual-dialog input:focus-visible { outline: 2px solid #a5b4fc; outline-offset: 2px; }
.manual-dialog .manual-error { color: #fca5a5; }
.manual-actions { display: flex; justify-content: flex-end; flex-wrap: wrap; gap: 0.75rem; margin-top: 1.25rem; }
.manual-card-link { overflow-wrap: anywhere; }

.app-footer {
  text-align: center;
  padding: 1.5rem;
  font-size: 0.8rem;
  color: var(--text-secondary);
  border-top: 1px solid var(--border-color);
  margin-top: auto;
}

.footer-content {
  max-width: 1152px;
  margin: 0 auto;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-wrap: wrap;
  gap: 0.5rem 1rem;
}

.footer-socials {
  display: inline-flex;
  gap: 0.85rem;
}

.footer-socials a {
  color: #a5b4fc;
  text-underline-offset: 3px;
}

.footer-socials a:hover {
  color: var(--text-primary);
}

.footer-socials a:focus-visible {
  outline: 2px solid #a5b4fc;
  outline-offset: 4px;
}

.site-notice {
  width: 100%;
  margin-top: 1.5rem;
  padding: 1rem 1.25rem;
  background: var(--bg-secondary);
  border: 1px solid var(--border-color);
  border-radius: 12px;
  text-align: left;
  color: #cbd5e1;
  line-height: 1.7;
  font-size: 0.8rem;
}

.site-notice h2 {
  margin-bottom: 0.5rem;
  font-size: 0.9rem;
  color: #fbbf24;
}

.site-notice p + p {
  margin-top: 0.65rem;
}

.developer-contact {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.65rem;
  min-height: 44px;
  padding: 0.65rem 1.15rem;
  border: 1px solid #818cf8;
  border-radius: 10px;
  background: var(--accent-hover);
  color: #fff;
  font-size: 0.875rem;
  font-weight: 600;
  text-decoration: none;
  transition: background 0.2s, box-shadow 0.2s;
}

.developer-contact:hover {
  background: #4338ca;
  box-shadow: 0 4px 12px var(--accent-glow);
}

.developer-contact:focus-visible {
  outline: 3px solid #a5b4fc;
  outline-offset: 4px;
}

@media (max-width: 600px) {
  .app-header {
    position: static;
  }

  .header-actions > .status-pill,
  .header-actions > .audio-controls,
  .header-actions > .developer-contact {
    width: 100%;
    justify-content: center;
  }

  .header-actions .developer-contact {
    margin-left: 0;
  }
}
