* { box-sizing: border-box; }
html, body {
  margin: 0; padding: 0;
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  background: #f8f9fa; color: #212529; height: 100%;
}
body { min-height: 100vh; }

.login-box {
  max-width: 360px; margin: 80px auto; padding: 32px;
  background: white; border-radius: 12px;
  box-shadow: 0 2px 12px rgba(0,0,0,0.08);
}
.login-box h1 { margin-top: 0; }
.login-box input {
  width: 100%; padding: 12px; font-size: 16px;
  border: 1px solid #ced4da; border-radius: 6px; margin-bottom: 12px;
}
.login-box button {
  width: 100%; padding: 12px; font-size: 16px;
  background: #ff6f00; color: white; border: none; border-radius: 6px; cursor: pointer;
}
.login-box button:hover { background: #e85f00; }
.login-error { color: #dc3545; margin-top: 8px; min-height: 20px; }

.admin-container { max-width: 1400px; margin: 0 auto; padding: 16px; }
.admin-header {
  display: flex; justify-content: space-between; align-items: center;
  margin-bottom: 16px; padding-bottom: 12px; border-bottom: 2px solid #e9ecef;
}
.admin-header h1 { margin: 0; font-size: 24px; }

.tabs {
  display: flex; gap: 4px; margin-bottom: 16px; border-bottom: 2px solid #e9ecef;
}
.tab {
  padding: 10px 20px; background: none; border: none; cursor: pointer;
  font-size: 15px; border-bottom: 3px solid transparent; margin-bottom: -2px;
}
.tab.active { border-bottom-color: #ff6f00; font-weight: 600; }

.tab-content { display: none; }
.tab-content.active { display: block; }

.card {
  background: white; border-radius: 8px; padding: 20px; margin-bottom: 16px;
  box-shadow: 0 1px 4px rgba(0,0,0,0.06);
}
.card h2 { margin-top: 0; }

table { width: 100%; border-collapse: collapse; }
th, td { padding: 8px 12px; text-align: left; border-bottom: 1px solid #e9ecef; }
th { background: #f1f3f5; font-weight: 600; }

button.btn {
  padding: 8px 16px; font-size: 14px;
  border: 1px solid #ced4da; background: white; border-radius: 6px; cursor: pointer;
}
button.btn:hover { background: #f1f3f5; }
button.btn-primary { background: #ff6f00; color: white; border-color: #ff6f00; }
button.btn-primary:hover { background: #e85f00; }
button.btn-danger { background: #dc3545; color: white; border-color: #dc3545; }
button.btn-danger:hover { background: #c82333; }
button.btn-success { background: #28a745; color: white; border-color: #28a745; }
button.btn-sm { padding: 4px 10px; font-size: 13px; }

input, select, textarea {
  padding: 8px; font-size: 14px;
  border: 1px solid #ced4da; border-radius: 6px;
}

.row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.row > * { flex: 0 0 auto; }
.row.gap-lg { gap: 16px; }

.current-indicator {
  display: inline-block; padding: 2px 8px;
  background: #ff6f00; color: white; border-radius: 4px;
  font-size: 12px; margin-left: 8px;
}

.connection-status { font-size: 12px; padding: 4px 10px; border-radius: 4px; }
.connection-status.connected { background: #d4edda; color: #155724; }
.connection-status.disconnected { background: #f8d7da; color: #721c24; }

.team-list { list-style: none; padding: 0; margin: 0; }
.team-item {
  padding: 12px 16px; background: #f8f9fa; border: 1px solid #dee2e6;
  border-radius: 6px; margin-bottom: 6px; cursor: move;
  display: flex; justify-content: space-between; align-items: center;
}
.team-item.completed { opacity: 0.5; text-decoration: line-through; }
.team-item.completed button { opacity: 1; text-decoration: none; }
.team-item.current { background: #fff3cd; border-color: #ff6f00; font-weight: 600; }
.team-item .drag-handle { color: #adb5bd; margin-right: 12px; }

.group-actions #nextTeamBtn {
  font-size: 18px;
  padding: 14px 28px;
}

.score-entry-card {
  border: 1px solid #e9ecef;
  background: #f8f9fa;
  border-radius: 8px;
  padding: 14px;
  margin-bottom: 16px;
}
.score-entry-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 12px;
}
.score-entry-label,
.score-entry-round {
  color: #6c757d;
  font-size: 13px;
}
.score-entry-team {
  font-weight: 800;
  font-size: 20px;
  line-height: 1.2;
  overflow-wrap: anywhere;
}
.score-entry-grid {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
  gap: 12px;
  margin-bottom: 12px;
}
.score-entry-grid label {
  display: grid;
  gap: 6px;
  color: #495057;
  font-size: 13px;
  font-weight: 600;
}
.score-entry-grid input {
  width: 100%;
  font-size: 22px;
  font-weight: 700;
  padding: 10px;
}
.score-timer-actions {
  gap: 8px;
}

.screen-body {
  background: #f8f9fa; height: 100vh; width: 100vw; margin: 0; padding: 0; overflow: hidden;
}
.screen-container { width: 100%; height: 100%; display: flex; flex-direction: column; }
.screen-iframe-overlay {
  position: fixed; top: 0; left: 0; right: 0; bottom: 0;
  z-index: 1000; background: white;
}
.screen-iframe-overlay iframe { width: 100%; height: 100%; border: 0; }
.screen-image-overlay {
  position: fixed;
  inset: 0;
  z-index: 1000;
  background: white;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: clamp(24px, 5vw, 80px);
}
.screen-image-overlay img {
  display: block;
  max-width: 100%;
  max-height: 100%;
  object-fit: contain;
}

.global-screen {
  display: grid; grid-template-columns: 2fr 1fr; gap: 24px;
  padding: 32px; height: 100vh; overflow: hidden;
}
.global-main {
  display: flex; flex-direction: column; align-items: center; justify-content: center;
}
.global-current-title {
  font-size: clamp(36px, 5vw, 72px); margin-bottom: 24px;
  text-align: center; font-weight: 600; color: #212529;
}
.global-sidebar {
  min-height: 0;
  overflow: hidden;
  display: flex;
  flex-direction: column;
}
.global-sidebar h3 {
  flex: 0 0 auto;
  margin: 0 0 24px;
  font-size: clamp(22px, 2.2vw, 32px);
  color: #6c757d;
}
.upcoming-list {
  flex: 1 1 auto;
  min-height: 0;
  list-style: none;
  padding: 0;
  margin: 0;
  overflow: hidden;
}
.upcoming-item {
  padding: 14px 16px; margin-bottom: 8px;
  background: white; border-radius: 8px; font-size: clamp(16px, 1.45vw, 22px);
  line-height: 1.25;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.upcoming-item .upcoming-time { color: #6c757d; font-size: 14px; margin-right: 8px; }

.circular-progress {
  position: relative; display: flex; align-items: center; justify-content: center;
}
.circular-progress svg { transform: rotate(-90deg); }
.circular-progress .time-display {
  position: absolute; font-weight: 700; text-align: center;
}
.circular-progress.large .time-display { font-size: clamp(48px, 7vw, 120px); }
.circular-progress.small .time-display { font-size: 32px; }

.group-screen {
  display: flex; flex-direction: column; height: 100vh;
  padding: 24px 32px; gap: 20px;
  background: linear-gradient(180deg, #f8f9fa 0%, #eef1f4 100%);
}
.group-header {
  display: flex; justify-content: space-between; align-items: center;
  flex: 0 0 auto;
}
.group-header h1 {
  margin: 0;
  font-size: clamp(28px, 3vw, 44px);
  font-weight: 800;
  background: linear-gradient(90deg, #1a1a2e 0%, #16213e 100%);
  -webkit-background-clip: text;
  background-clip: text;
  -webkit-text-fill-color: transparent;
  letter-spacing: -0.02em;
}
.group-header .round-badge {
  color: white;
  -webkit-text-fill-color: white;
  display: inline-block;
  background: linear-gradient(135deg, #ff6f00 0%, #ff9100 100%);
  padding: 6px 18px;
  border-radius: 999px;
  font-size: clamp(18px, 2vw, 28px);
  font-weight: 700;
  margin-left: 12px;
  vertical-align: middle;
  box-shadow: 0 2px 8px rgba(255, 111, 0, 0.3);
}
.group-mini-timer { display: flex; align-items: center; gap: 16px; }

.group-tables {
  flex: 1 1 0;
  display: grid; grid-template-columns: 1fr 1fr; gap: 24px;
  min-height: 0;
}
.table-section {
  display: flex; flex-direction: column;
  background: white; border-radius: 20px;
  padding: 24px;
  box-shadow: 0 4px 24px rgba(0, 0, 0, 0.06);
  overflow: hidden;
  position: relative;
  border-top: 5px solid;
}
.table-section.table-1 { border-top-color: #ff6f00; }
.table-section.table-2 { border-top-color: #2196f3; }
.table-section h2 {
  margin: 0 0 20px;
  font-size: clamp(20px, 2vw, 32px);
  text-align: center;
  color: #495057;
  font-weight: 700;
  letter-spacing: 0.02em;
}
.table-teams {
  flex: 1 1 0;
  display: flex; flex-direction: column;
  gap: 10px;
  min-height: 0;
  overflow: hidden; /* nekad scroll */
  justify-content: flex-start;
  padding: 4px; /* atstāj vietu glow efektam */
}
.screen-team {
  flex: 0 1 auto;
  padding: 14px 22px;
  border-radius: 12px;
  font-size: clamp(18px, 2vw, 28px);
  font-weight: 600;
  background: #f1f3f5;
  color: #495057;
  transition: background 0.4s ease, color 0.4s ease, font-size 0.4s ease, padding 0.4s ease;
  /* Pārliecinās ka nepārkāpj */
  max-width: 100%;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  box-sizing: border-box;
}
.screen-team.completed {
  opacity: 0.45;
  background: #e9ecef;
  text-decoration: line-through;
  font-size: clamp(15px, 1.5vw, 22px);
  padding: 10px 22px;
}
.screen-team.current {
  background: linear-gradient(135deg, #ff6f00 0%, #ff9100 100%);
  color: white;
  font-weight: 800;
  font-size: clamp(24px, 3vw, 44px);
  padding: 24px 32px;
  border-radius: 16px;
  /* Animēts box-shadow glow - bez transform, lai neizlec ārā */
  animation: pulseGlow 1.8s ease-in-out infinite;
  letter-spacing: -0.01em;
  text-overflow: ellipsis;
  overflow: hidden;
}
.table-section.table-2 .screen-team.current {
  background: linear-gradient(135deg, #1976d2 0%, #2196f3 100%);
  animation-name: pulseGlowBlue;
}
@keyframes pulseGlow {
  0%, 100% {
    box-shadow: 0 6px 20px rgba(255, 111, 0, 0.35),
                0 0 0 0 rgba(255, 111, 0, 0.4),
                inset 0 -3px 0 rgba(0,0,0,0.1);
  }
  50% {
    box-shadow: 0 8px 28px rgba(255, 111, 0, 0.5),
                0 0 0 6px rgba(255, 111, 0, 0.15),
                inset 0 -3px 0 rgba(0,0,0,0.1);
  }
}
@keyframes pulseGlowBlue {
  0%, 100% {
    box-shadow: 0 6px 20px rgba(33, 150, 243, 0.35),
                0 0 0 0 rgba(33, 150, 243, 0.4),
                inset 0 -3px 0 rgba(0,0,0,0.1);
  }
  50% {
    box-shadow: 0 8px 28px rgba(33, 150, 243, 0.5),
                0 0 0 6px rgba(33, 150, 243, 0.15),
                inset 0 -3px 0 rgba(0,0,0,0.1);
  }
}

.group-screen-info {
  flex: 1; display: flex; align-items: center; justify-content: center;
}

.results-screen {
  padding: 32px;
  height: 100vh;
  overflow-y: auto;
}
.results-screen.fit-results {
  padding: var(--results-pad, 32px);
  overflow: hidden;
  display: flex;
  flex-direction: column;
  gap: var(--results-title-margin, 24px);
}
.results-screen h1 {
  font-size: 48px;
  margin: 0 0 24px;
  text-align: center;
}
.results-screen.fit-results h1 {
  flex: 0 0 auto;
  font-size: var(--results-title, 48px);
  line-height: 1.1;
  margin: 0;
}
.results-table {
  width: 100%; font-size: clamp(16px, 1.5vw, 24px);
  background: white; border-radius: 12px; overflow: hidden;
  box-shadow: 0 2px 8px rgba(0,0,0,0.08);
}
.fit-results .results-table {
  flex: 1 1 auto;
  min-height: 0;
  table-layout: fixed;
  font-size: var(--results-font, 22px);
}
.results-table th, .results-table td { padding: 14px; }
.fit-results .results-table th,
.fit-results .results-table td {
  padding: var(--results-cell-y, 12px) var(--results-cell-x, 12px);
  line-height: 1.12;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.results-table .place { font-weight: 700; width: 60px; text-align: center; }
.fit-results .results-table .place { width: 5ch; }
.score-time {
  color: #868e96;
  font-size: 0.72em;
  white-space: nowrap;
}
.score-points { font-weight: 700; }
.badge {
  display: inline-block; padding: 4px 12px; border-radius: 999px;
  color: white; font-size: 12px; font-weight: 600;
}
.fit-results .badge {
  padding: var(--results-badge-y, 4px) var(--results-badge-x, 12px);
  font-size: var(--results-badge-font, 12px);
}
.badge-bronze { background: #cd7f32; }
.badge-silver { background: #b0b0b0; }
.badge-gold { background: #ffc800; color: #5d4500; }

.global-results-grid {
  display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 24px; padding: 0 32px 32px;
  height: calc(100vh - 96px);
  overflow: hidden;
}
.global-results-card {
  background: white; border-radius: 12px; padding: 24px;
  box-shadow: 0 2px 8px rgba(0,0,0,0.08);
  min-height: 0;
  overflow: hidden;
}
.global-results-card h2 { margin-top: 0; text-align: center; }
.compact-results-table {
  font-size: clamp(14px, 1.1vw, 18px);
}
.compact-results-table th,
.compact-results-table td {
  padding: 9px 10px;
}

@media (max-width: 900px) {
  .global-screen { grid-template-columns: 1fr; }
  .group-tables { grid-template-columns: 1fr; }
  .global-results-grid { grid-template-columns: 1fr; }
}

@media (max-width: 640px) {
  body.group-admin-page {
    overflow-x: hidden;
  }

  .group-admin-page .admin-container {
    width: 100%;
    max-width: none;
    padding: 10px;
  }

  .group-admin-page .admin-header {
    gap: 10px;
    align-items: flex-start;
  }

  .group-admin-page .admin-header h1 {
    min-width: 0;
    font-size: 20px;
    line-height: 1.15;
    overflow-wrap: anywhere;
  }

  .group-admin-page .connection-status {
    flex: 0 0 auto;
    margin-top: 2px;
  }

  .group-admin-page .card {
    padding: 14px;
    border-radius: 8px;
  }

  .group-admin-page .row,
  .group-admin-page .row.gap-lg {
    width: 100%;
    gap: 10px;
  }

  .group-status-card .row {
    display: grid;
    grid-template-columns: 1fr;
    align-items: start;
  }

  .group-status-card .row > div,
  #currentItem {
    min-width: 0;
    overflow-wrap: anywhere;
  }

  .group-admin-page .tabs {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 0;
  }

  .group-admin-page .tab {
    width: 100%;
    padding: 12px 8px;
    font-size: 15px;
  }

  .group-actions {
    display: grid;
    grid-template-columns: 1fr;
  }

  .score-entry-card {
    padding: 12px;
  }

  .score-entry-header {
    display: grid;
    grid-template-columns: 1fr;
  }

  .score-entry-grid {
    grid-template-columns: 1fr 1fr;
  }

  .score-timer-actions {
    display: grid;
    grid-template-columns: 1fr 1fr;
    width: 100%;
  }

  .score-timer-actions .btn {
    width: 100%;
    min-height: 44px;
    padding: 10px;
  }

  #saveScoreBtn {
    grid-column: 1 / -1;
  }

  .group-actions .btn,
  .group-actions #nextTeamBtn {
    width: 100%;
    min-height: 48px;
    padding: 12px 14px;
    font-size: 16px;
    white-space: normal;
  }

  .group-control-card p {
    margin: 0 0 12px;
    line-height: 1.35;
  }

  .team-item {
    width: 100%;
    min-width: 0;
    align-items: flex-start;
    gap: 10px;
    padding: 12px;
  }

  .team-item > span:first-child {
    min-width: 0;
    flex: 1 1 auto;
    overflow-wrap: anywhere;
  }

  .team-item > span:last-child {
    flex: 0 0 auto;
    max-width: 42%;
    justify-content: flex-end;
    flex-wrap: wrap;
    text-align: right;
  }

  .team-item .drag-handle {
    margin-right: 8px;
  }

  .team-item .btn-sm {
    padding: 6px 9px;
  }
}
