/* Layout e componentes do CronoBase. */

* {
  box-sizing: border-box;
}

/* O UA [hidden] deste Edge não usa !important — autor .screen{display:flex}
   vencia e mantinha telas/banner/toast empilhados (bodyScroll + scrollbar). */
[hidden] {
  display: none !important;
}

html,
body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  min-height: 100dvh;
}

body {
  padding-left: env(safe-area-inset-left);
  padding-right: env(safe-area-inset-right);
}

button,
select,
input {
  min-height: var(--touch);
  font: inherit;
}

.clock {
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-variant-numeric: tabular-nums;
}

.muted {
  color: var(--muted);
}

.hint {
  font-size: 0.85rem;
  color: var(--muted);
  margin: 0.75rem 0 0;
}

.screen {
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
}

/* ---------------- Topbar ---------------- */
.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  padding: 0.6rem 1rem;
  padding-top: calc(0.6rem + env(safe-area-inset-top));
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}

.brand {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  min-width: 0;
}

.brand-mark {
  width: 28px;
  height: 28px;
  border-radius: 6px;
}

.brand-name {
  font-size: 1.05rem;
  font-weight: 700;
  color: var(--blue);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.topbar-actions {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.theme-field {
  display: flex;
  align-items: center;
  gap: 0.4rem;
}

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

/* ---------------- Botões e campos ---------------- */
.btn {
  border: 1px solid transparent;
  border-radius: var(--radius-btn);
  padding: 0.5rem 1rem;
  font-size: 0.95rem;
  font-weight: 600;
  cursor: pointer;
  background: var(--surface-2);
  color: var(--text);
  transition: background-color 0.15s ease, border-color 0.15s ease;
  min-width: var(--touch);
}

.btn:focus-visible,
.input:focus-visible,
.select:focus-visible {
  outline: 2px solid var(--blue-400);
  outline-offset: 2px;
}

.btn:disabled {
  opacity: 0.55;
  cursor: not-allowed;
}

.btn-primary {
  background: var(--blue);
  color: #fff;
}

.btn-primary:hover:not(:disabled) {
  background: var(--blue-hover);
}

.btn-secondary {
  background: var(--surface);
  border-color: var(--border);
}

.btn-secondary:hover:not(:disabled) {
  background: var(--surface-2);
}

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

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

.btn-ghost {
  background: transparent;
  color: var(--muted);
  border-color: transparent;
}

.btn-ghost:hover:not(:disabled) {
  background: var(--surface-2);
  color: var(--text);
}

.btn-square {
  width: var(--touch);
  padding: 0.4rem;
}

.btn-sm {
  min-height: 34px;
  padding: 0.25rem 0.6rem;
  font-size: 0.85rem;
}

.btn-big {
  min-height: calc(var(--touch) + 8px);
  font-size: 1.05rem;
}

.btn-xl {
  min-height: calc(var(--touch) + 12px);
  font-size: 1.05rem;
  flex: 1 1 0;
}

.input,
.select {
  width: 100%;
  padding: 0.5rem 0.7rem;
  border: 1px solid var(--border);
  border-radius: var(--radius-btn);
  background: var(--surface);
  color: var(--text);
  font-size: 0.95rem;
}

.select-sm {
  width: auto;
  min-width: 8.5rem;
}

.field {
  display: flex;
  flex-direction: column;
  gap: 0.3rem;
  margin-bottom: 0.9rem;
}

.field-label {
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--muted);
}

.field-row {
  display: flex;
  flex-wrap: wrap;
  gap: 0.75rem;
  align-items: flex-end;
}

.field-row .field {
  flex: 1 1 0;
  margin-bottom: 0;
}

.field-grow {
  flex: 1 1 auto;
}

.sub-title {
  font-size: 0.8rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--muted);
  margin: 1.1rem 0 0.5rem;
}

/* ---------------- Config ---------------- */
.config-main {
  flex: 1 1 auto;
  width: min(640px, 100%);
  margin: 0 auto;
  padding: 1rem 1rem 6rem;
}

.steps {
  display: flex;
  gap: 0.5rem;
  list-style: none;
  margin: 0 0 1rem;
  padding: 0;
}

.step-pill {
  flex: 1 1 0;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.4rem;
  padding: 0.55rem 0.4rem;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: var(--surface);
  color: var(--muted);
  font-size: 0.85rem;
  font-weight: 600;
}

.step-pill.active {
  background: var(--blue-soft);
  border-color: var(--blue);
  color: var(--blue);
}

.step-num {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 20px;
  height: 20px;
  border-radius: 50%;
  background: var(--blue);
  color: #fff;
  font-size: 0.75rem;
}

.step-pill:not(.active) .step-num {
  background: var(--surface-2);
  color: var(--muted);
}

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

.card-title {
  margin: 0 0 1rem;
  font-size: 1.15rem;
  color: var(--text-strong);
}

.step-panel {
  display: none;
}

.step-panel.active {
  display: block;
}

.config-nav {
  display: flex;
  gap: 0.75rem;
  margin-top: 1rem;
  justify-content: flex-end;
}

.config-footer {
  position: sticky;
  bottom: 0;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
  padding: 0.5rem 1rem;
  padding-bottom: calc(0.5rem + env(safe-area-inset-bottom));
  background: var(--surface);
  border-top: 1px solid var(--border);
  font-size: 0.85rem;
}

.footer-actions {
  display: flex;
  gap: 0.25rem;
}

/* Lista de atletas (config) */
.atleta-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.atleta-item {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  padding: 0.5rem 0.7rem;
  border: 1px solid var(--border);
  border-radius: var(--radius-btn);
  background: var(--surface-2);
}

.atleta-item.selected {
  background: var(--blue-soft);
  border-color: var(--blue);
}

.atleta-toggle {
  flex: 1 1 auto;
  text-align: left;
  background: transparent;
  border: 0;
  color: var(--text);
  font-weight: 600;
  cursor: pointer;
  min-height: var(--touch);
}

.atleta-check {
  font-weight: 700;
  color: var(--blue);
  min-width: 1.4rem;
}

.atleta-remove {
  border: 0;
  background: transparent;
  color: var(--muted);
  font-size: 1.1rem;
  cursor: pointer;
  min-width: var(--touch);
  min-height: var(--touch);
  border-radius: var(--radius-btn);
}

.atleta-remove:hover {
  background: var(--danger-soft);
  color: var(--danger);
}

/* ---------------- Cronômetro ---------------- */
/* Modal <dialog> de borda total, colado no topo da viewport. */
#screen-chrono {
  margin: 0 auto;
  width: 100%;
  max-width: 100%;
  height: 100dvh;
  max-height: 100dvh;
  padding: 0;
  border: none;
  border-radius: 0;
  background: var(--surface);
  color: var(--text);
  overflow: hidden;
}

#screen-chrono:not([open]) {
  display: none;
}

#screen-chrono::backdrop {
  background: rgb(0 0 0 / 0.45);
}

.chrono-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.6rem;
  padding: 0.5rem 0.9rem;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  flex-wrap: wrap;
}

.chrono-title {
  display: flex;
  flex-direction: column;
  min-width: 0;
}

.chrono-name {
  font-weight: 700;
  color: var(--text-strong);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.chrono-config {
  font-size: 0.78rem;
}

.chrono-header-actions {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  flex-wrap: wrap;
}

.gp-badge {
  font-size: 0.72rem;
  font-weight: 700;
  padding: 0.25rem 0.55rem;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: var(--surface-2);
  color: var(--muted);
  max-width: 16rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.gp-badge.gp-on {
  background: var(--success-soft);
  border-color: var(--success);
  color: var(--success);
}

.gp-badge.gp-custom {
  background: var(--warning-soft);
  border-color: var(--warning);
  color: var(--warning);
}

.chrono-displays {
  display: flex;
  gap: 0.6rem;
  padding: 0.6rem 0.9rem 0;
}

.display {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-card);
  padding: 0.45rem 0.7rem;
  display: flex;
  flex-direction: column;
  box-shadow: var(--shadow-card);
}

.display-master {
  flex: 2 1 0;
}

.display-continuous {
  flex: 1 1 0;
  background: var(--surface-2);
}

.display-label {
  font-size: 0.7rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--muted);
}

.display-value {
  font-size: var(--master-size);
  font-weight: 700;
  line-height: 1.1;
  color: var(--text-strong);
}

.display-value-sm {
  font-size: calc(var(--master-size) * 0.55);
}

.display-value.blink {
  animation: timerBlink 0.6s ease;
}

@keyframes timerBlink {
  0%,
  100% {
    opacity: 1;
  }
  50% {
    opacity: 0.35;
  }
}

.state-line {
  padding: 0.45rem 0.9rem 0;
  font-size: 0.9rem;
  font-weight: 600;
  color: var(--muted);
}

.state-line.running {
  color: var(--success);
}

.state-line.resting {
  color: var(--warning);
}

.chrono-controls {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  padding: 0.55rem 0.9rem;
  padding-top: calc(0.55rem + env(safe-area-inset-top));
  border-bottom: 1px solid var(--border);
  flex-wrap: wrap;
}

/* Mobile-first: botões dividem a largura em partes iguais (gap 0.5rem). */
.chrono-controls .btn-xl {
  flex: 1 1 0;
}

#startBtn {
  margin-right: 0;
}

/* ≥641px: 5cm cabe na linha — par Iniciar/Parar centralizado com gap
   fixo de ~5cm entre eles (compensa o gap flex de 0.5rem). */
@media (min-width: 641px) {
  .chrono-controls .btn-xl {
    flex: 0 1 auto;
  }

  #startBtn {
    margin-right: calc(5cm - 0.5rem);
  }
}

/* Lista de raias */
.raia-list {
  list-style: none;
  margin: 0;
  padding: 0 0.9rem;
  flex: 1 1 auto;
  min-height: 0;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.raia {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  background: var(--surface);
  border: 2px solid var(--border);
  border-radius: var(--radius-card);
  padding: 0.5rem 0.6rem;
  box-shadow: var(--shadow-card);
  cursor: pointer;
  transition: border-color 0.15s ease, background-color 0.15s ease;
}

.raia.selected {
  border-color: var(--blue);
  background: var(--blue-soft);
  box-shadow: var(--selected-ring);
}

.raia.selected::after {
  content: "✓ selecionado";
  font-size: 0.68rem;
  font-weight: 800;
  color: var(--blue);
  white-space: nowrap;
}

.raia.resting {
  background: var(--blue-soft);
  border-color: var(--blue-400);
}

.raia.rest-alert {
  background: var(--danger-soft);
  border-color: var(--danger);
  animation: restPulse 1s ease-in-out infinite;
}

@keyframes restPulse {
  0%,
  100% {
    border-color: var(--danger);
  }
  50% {
    border-color: color-mix(in srgb, var(--danger) 35%, var(--surface));
  }
}

.raia.done {
  border-color: var(--success);
}

.raia.dragging {
  opacity: 0.6;
}

.raia.drop-target {
  border-color: var(--blue);
  border-style: dashed;
}

.raia-handle {
  border: 0;
  background: transparent;
  color: var(--muted);
  font-size: 1.15rem;
  cursor: grab;
  touch-action: none;
  min-width: 34px;
  min-height: var(--touch);
  border-radius: var(--radius-btn);
}

.raia-handle:active {
  cursor: grabbing;
}

.raia-lane {
  font-weight: 800;
  font-size: 0.95rem;
  color: var(--blue);
  min-width: 1.6rem;
  text-align: center;
}

.raia-main {
  flex: 1 1 auto;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 0.1rem;
}

.raia-name {
  font-weight: 700;
  color: var(--text-strong);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.raia-meta {
  font-size: 0.78rem;
  color: var(--muted);
}

.raia-temps {
  font-size: 0.8rem;
  display: flex;
  flex-wrap: wrap;
  gap: 0.3rem;
}

.raia-temp-chip {
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 0.05rem 0.45rem;
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-variant-numeric: tabular-nums;
}

.raia-right {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 0.15rem;
  min-width: 7.5rem;
}

.raia-clock {
  font-size: var(--clock-size);
  font-weight: 700;
  line-height: 1.05;
  color: var(--text-strong);
}

.raia-clock.rest-count {
  background: var(--danger);
  color: #fff;
  border-radius: 8px;
  padding: 0 0.4rem;
  font-size: calc(var(--clock-size) * 0.85);
}

.raia-tag {
  font-size: 0.72rem;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--muted);
  background: var(--surface-2);
  border-radius: 999px;
  padding: 0.1rem 0.5rem;
  border: 1px solid var(--border);
}

.raia-tag.tag-rest {
  background: var(--warning-soft);
  color: var(--warning);
  border-color: var(--warning);
}

.raia-tag.tag-alert {
  background: var(--danger);
  color: #fff;
  border-color: var(--danger);
}

.raia-tag.tag-done {
  background: var(--success-soft);
  color: var(--success);
  border-color: var(--success);
}

.chrono-hint {
  text-align: center;
  font-size: 0.75rem;
  padding: 0.4rem 0.9rem;
  margin: 0;
  padding-bottom: calc(0.4rem + env(safe-area-inset-bottom));
}

/* ---------------- Resumo ---------------- */
.summary-main {
  flex: 1 1 auto;
  width: min(720px, 100%);
  margin: 0 auto;
  padding: 1rem 1rem 2rem;
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

.summary-list {
  list-style: none;
  margin: 0.75rem 0 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}

.summary-item {
  border: 1px solid var(--border);
  border-radius: var(--radius-btn);
  padding: 0.6rem 0.75rem;
  background: var(--surface-2);
}

.summary-item-head {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  gap: 0.5rem;
  font-weight: 700;
  color: var(--text-strong);
}

.summary-item-times {
  margin-top: 0.35rem;
  display: flex;
  flex-wrap: wrap;
  gap: 0.35rem;
}

.summary-empty {
  color: var(--muted);
  font-size: 0.9rem;
}

.summary-actions {
  display: flex;
  gap: 0.6rem;
  flex-wrap: wrap;
  justify-content: flex-end;
}

/* ---------------- Diálogos ---------------- */
.dialog {
  border: 1px solid var(--border);
  border-radius: var(--radius-card);
  background: var(--surface);
  color: var(--text);
  padding: 0;
  width: min(560px, calc(100vw - 2rem));
  max-height: 85dvh;
}

.dialog::backdrop {
  background: rgb(0 0 0 / 0.45);
}

.dialog-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
  padding: 0.9rem 1rem;
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  background: var(--surface);
}

.dialog-title {
  margin: 0;
  font-size: 1.05rem;
  color: var(--text-strong);
}

.dialog-body {
  padding: 1rem;
  overflow-y: auto;
}

.dialog-actions {
  display: flex;
  justify-content: flex-end;
  gap: 0.6rem;
  margin-top: 1rem;
}

.confirm-message {
  color: var(--muted);
  line-height: 1.5;
}

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

.gp-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.85rem;
}

.gp-table th,
.gp-table td {
  border-bottom: 1px solid var(--border);
  padding: 0.45rem 0.5rem;
  text-align: left;
  vertical-align: top;
}

.gp-table th {
  font-size: 0.72rem;
  text-transform: uppercase;
  color: var(--muted);
}

.gp-table td:first-child {
  font-weight: 700;
  white-space: nowrap;
}

.help-list {
  margin: 0.4rem 0 0;
  padding-left: 1.1rem;
  line-height: 1.5;
  font-size: 0.9rem;
}

code {
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 0 0.25rem;
  font-size: 0.85em;
}

/* ---------------- Toast / banners ---------------- */
.toast {
  position: fixed;
  left: 50%;
  bottom: calc(1.2rem + env(safe-area-inset-bottom));
  transform: translateX(-50%);
  background: var(--text-strong);
  color: var(--bg);
  padding: 0.6rem 1rem;
  border-radius: var(--radius-btn);
  font-size: 0.9rem;
  font-weight: 600;
  z-index: 60;
  max-width: min(92vw, 26rem);
  text-align: center;
}

[data-theme="pool"] .toast {
  background: #000;
  color: #fff;
  border: 2px solid #000;
}

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

.toast.toast-success {
  background: var(--success);
  color: #fff;
}

.update-banner {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  z-index: 70;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.75rem;
  flex-wrap: wrap;
  background: var(--warning-soft);
  color: var(--warning);
  border-bottom: 2px solid var(--warning);
  padding: 0.5rem 0.75rem;
  font-weight: 700;
  font-size: 0.9rem;
}

/* ---------------- Tema "beira de piscina": operacional ---------------- */
[data-theme="pool"] .card,
[data-theme="pool"] .raia,
[data-theme="pool"] .display {
  border-width: 2px;
  box-shadow: none;
}

[data-theme="pool"] .btn {
  font-weight: 800;
}

[data-theme="pool"] .btn-primary {
  border: 2px solid var(--blue-hover);
}

[data-theme="pool"] .btn-secondary {
  border: 2px solid var(--border);
}

[data-theme="pool"] .btn-danger {
  border: 2px solid #7f1d1d;
}

[data-theme="pool"] .btn-success {
  border: 2px solid #14532d;
}

[data-theme="pool"] .muted,
[data-theme="pool"] .chrono-config,
[data-theme="pool"] .field-label,
[data-theme="pool"] .display-label {
  color: #1f2937;
  font-weight: 700;
}

[data-theme="pool"] .raia-clock {
  font-size: calc(var(--clock-size) * 1.05);
}

[data-theme="pool"] .btn-xl {
  font-size: 1.15rem;
}

[data-theme="pool"] .raia.rest-alert,
[data-theme="pool"] .raia.selected {
  animation: none;
}

/* ---------------- Modo paisagem ---------------- */
@media (orientation: landscape) and (max-height: 560px) {
  #screen-chrono {
    display: grid;
    grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
    grid-template-areas:
      "header header"
      "displays displays"
      "state state"
      "controls controls"
      "list hint";
    grid-template-rows: auto auto auto auto minmax(0, 1fr) auto;
    overflow: hidden;
  }

  .chrono-header {
    grid-area: header;
  }

  .chrono-displays {
    grid-area: displays;
  }

  .state-line {
    grid-area: state;
  }

  .chrono-controls {
    grid-area: controls;
  }

  .raia-list {
    grid-area: list;
  }

  .chrono-hint {
    grid-area: hint;
    align-self: end;
  }

  .btn-xl {
    min-height: 44px;
    padding: 0.35rem 0.6rem;
  }
}

/* Cronômetro em telas baixas: mantém controles fixos acima da lista */
@media (max-height: 640px) and (orientation: portrait) {
  :root {
    --master-size: 2.6rem;
    --clock-size: 1.7rem;
  }
}
