/* ============================================
   OPERATOR.CSS — Panel Operator Styles
   Everything fits in one viewport (100dvh).
   ============================================ */

html,
body {
  height: 100%;
  overflow: hidden;
}

/* ── Page Shell ── */
.op-page {
  height: 100vh;
  height: 100dvh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

/* ── Header ── */
.op-header {
  background: var(--header-bg);
  border-bottom: 1px solid var(--header-border);
  padding: 6px 12px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  z-index: 100;
  flex-shrink: 0;
}

.op-header-left {
  display: flex;
  align-items: center;
  gap: 8px;
}

.op-header-logo {
  display: flex;
  align-items: center;
  color: var(--accent);
}

.op-header-logo svg {
  width: 22px;
  height: 22px;
}

.op-header-title {
  font-size: 1.25rem;
  font-weight: 700;
  line-height: 1.1;
}

.op-header-sub {
  font-size: 1rem;
  color: #6b7280;
  font-weight: 500;
  display: flex;
  align-items: center;
  gap: 6px;
  flex-wrap: wrap;
}

.op-header-sep {
  color: var(--text-muted);
  opacity: .5;
  font-size: .7rem;
}

.op-header-sets {
  font-weight: 800;
  color: var(--accent);
}

.op-header-right {
  display: flex;
  gap: 2px;
}

.op-header-right .btn-icon {
  width: 32px;
  height: 32px;
  border-radius: var(--radius-sm);
}

/* ── Status Banner ── */
.op-banner {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  z-index: 150;
  padding: 10px 16px;
  text-align: center;
  font-weight: 800;
  font-size: .82rem;
  letter-spacing: .03em;
  text-transform: uppercase;
  animation: slideDown .35s var(--ease);
}

.op-banner.set-point {
  background: #d97706;
  color: #000;
}

.op-banner.match-point {
  background: #dc2626;
  color: #fff;
  animation: slideDown .35s var(--ease), glowPulse 1.5s ease infinite;
}

.op-banner.match-won {
  background: #16a34a;
  color: #fff;
}


/* ── Main Area ── */
.op-main {
  flex: 1;
  min-height: 0;
  /* critical for nested flex overflow */
  padding: 3px;
  display: flex;
  flex-direction: column;
  gap: 3px;
  width: 100%;
}

.op-panels {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 3px;
  flex: 1;
  min-height: 0;
  /* allow panels to shrink */
}

/* ── Team Panel ── */
.op-panel {
  background: var(--card-bg);
  border: 1.5px solid var(--card-border);
  border-radius: var(--radius-lg);
  padding: 6px 8px 8px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0;
  box-shadow: var(--card-shadow);
  transition: all var(--speed) var(--ease);
  position: relative;
  overflow: hidden;
  min-height: 0;
  /* allow flex shrink */
}

.op-panel::before {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  height: 4px;
  background: var(--panel-color);
}

.op-panel-header {
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-shrink: 0;
}

.op-panel-name {
  font-size: 1.5rem;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: .04em;
  color: var(--text-primary);
}

.op-panel-serve {
  font-size: 1.1rem;
  font-weight: 700;
  color: var(--serve-color);
  display: flex;
  align-items: center;
  gap: 4px;
}

.op-panel-serve svg {
  width: 16px;
  height: 16px;
}

/* ── Score — fills all remaining space ── */
.op-panel-score {
  font-family: var(--font-score);
  font-size: clamp(6rem, 48dvh, 30rem);
  font-weight: 400;
  line-height: .85;
  letter-spacing: .04em;
  flex: 1 1 0;
  min-height: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 100%;
  overflow: hidden;
}

/* ── Add Point Button — massive touch target ── */
.btn-add-big {
  width: 100%;
  padding: 2.5dvh 1rem;
  min-height: 4rem;
  font-size: 1.4rem;
  font-weight: 800;
  border: none;
  border-radius: var(--radius-md);
  cursor: pointer;
  transition: all var(--speed) var(--ease);
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  font-family: var(--font-ui);
  user-select: none;
  -webkit-tap-highlight-color: transparent;
  position: relative;
  overflow: hidden;
  letter-spacing: .02em;
  flex-shrink: 0;
  margin-top: 4px;
}

.btn-add-big::after {
  content: '';
  position: absolute;
  inset: 0;
  background: radial-gradient(circle at 50% 50%, rgba(255, 255, 255, .2) 0%, transparent 60%);
  opacity: 0;
  transition: opacity .3s ease;
}

.btn-add-big:active::after {
  opacity: 1;
  transition: 0s;
}

.btn-add-big:active {
  transform: scale(.97);
}

.btn-add-big svg {
  width: 24px;
  height: 24px;
}

.btn-add-big:disabled {
  opacity: .3;
  cursor: not-allowed;
  transform: none;
}

/* ── Panel Actions (TO, VC, SUB, -1) — large touch targets ── */
.op-panel-actions {
  display: flex;
  gap: 3px;
  width: 100%;
  flex-shrink: 0;
  margin-top: 3px;
}

.op-panel-actions .btn {
  flex: 1;
  padding: clamp(0.6rem, 2dvh, 1.5rem) 0.8rem;
  font-size: 1rem;
  font-weight: 600;
  gap: 5px;
  background: var(--btn-secondary-bg, rgba(255, 255, 255, .06));
  border-color: var(--border-color);
  transition: background .15s ease, transform .1s ease;
}

.op-panel-actions .btn:active {
  background: rgba(255, 255, 255, .15);
  transform: scale(.96);
}

.op-panel-actions .btn svg {
  width: 18px;
  height: 18px;
}

.op-to-badge {
  font-size: .85rem;
  opacity: .8;
  font-weight: 700;
}

/* ── Subtract button (red tint) ── */
.btn-sub {
  color: #dc2626 !important;
}

.btn-sub svg {
  color: #dc2626;
}

/* ── Unified Bottom Bar ── */
.op-bottom-bar {
  display: grid;
  grid-template-columns: auto 1fr auto;
  gap: 1rem;
  padding: 0.6rem 1rem;
  align-items: center;
  background: var(--card-bg);
  border-top: 1px solid var(--card-border);
  flex-shrink: 0;
}

/* Timer (left) */
.op-bottom-timer {
  display: flex;
  align-items: center;
  gap: 8px;
}

.op-timer-display {
  font-family: var(--font-ui);
  font-size: 2rem;
  font-weight: 800;
  letter-spacing: .06em;
  color: var(--text-primary);
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

.op-timer-controls {
  display: flex;
  gap: 4px;
}

.op-timer-controls .btn {
  padding: 6px 10px;
  font-size: .85rem;
  gap: 3px;
  min-height: 2.5rem;
}

/* Center buttons (Servis + Undo) */
.op-bottom-center {
  display: flex;
  gap: 6px;
  justify-content: center;
}

.btn-solid {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 0.7rem 1.2rem;
  min-height: 3rem;
  font-size: 1.05rem;
  font-weight: 700;
  font-family: var(--font-ui);
  background: var(--input-bg, rgba(0, 0, 0, .06));
  border: 1.5px solid var(--border-color);
  border-radius: var(--radius-md);
  color: var(--text-primary);
  cursor: pointer;
  transition: all .15s ease;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
}

.btn-solid:hover {
  background: var(--bg-hover);
  border-color: var(--accent);
}

.btn-solid:active {
  transform: scale(.96);
}

.btn-solid:disabled {
  opacity: .35;
  cursor: not-allowed;
  transform: none;
}

.btn-solid svg {
  width: 16px;
  height: 16px;
}

/* Reset button (right) — outlined red warning */
.op-bottom-right {
  display: flex;
  justify-content: flex-end;
}

.btn-reset-outline {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 0.7rem 1.2rem;
  min-height: 3rem;
  font-size: .85rem;
  font-weight: 700;
  font-family: var(--font-ui);
  background: transparent;
  border: 1.5px solid #dc2626;
  border-radius: var(--radius-md);
  color: #dc2626;
  cursor: pointer;
  transition: all .15s ease;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
  white-space: nowrap;
}

.btn-reset-outline:hover {
  background: rgba(220, 38, 38, .08);
}

.btn-reset-outline:active {
  background: rgba(220, 38, 38, .15);
  transform: scale(.96);
}

.btn-reset-outline svg {
  width: 16px;
  height: 16px;
}

/* ── Settings Overlay ── */
.settings-overlay {
  position: fixed;
  inset: 0;
  background: var(--overlay-bg);
  z-index: 200;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
  animation: fadeIn .15s ease;
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
}

.settings-panel {
  background: var(--card-bg);
  border: 1px solid var(--card-border);
  border-radius: var(--radius-xl);
  padding: 24px;
  width: 100%;
  max-width: 460px;
  max-height: 90vh;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 16px;
  animation: fadeInScale .25s var(--ease);
  box-shadow: 0 20px 60px rgba(0, 0, 0, .3);
}

.settings-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.settings-head h3 {
  font-size: 1rem;
}

.sett-section {
  padding-top: 14px;
  border-top: 1px solid var(--border-color);
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.sett-section-label {
  font-size: .65rem;
  font-weight: 800;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: .1em;
}

.sett-team-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}

.sett-team-card {
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding: 12px;
  border: 1.5px solid var(--border-color);
  background: var(--input-bg);
  transition: border-color var(--speed) var(--ease);
}

.sett-team-card:hover {
  border-color: var(--accent);
}

.sett-team-label {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: .68rem;
  font-weight: 800;
  text-transform: uppercase;
  color: var(--text-secondary);
}

.sett-team-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  flex-shrink: 0;
}

.sett-color-row {
  display: flex;
  gap: 6px;
  align-items: stretch;
}

.sett-color-row .input {
  flex: 1;
  font-weight: 600;
  font-size: .78rem;
  padding: 8px 10px;
}

.sett-logo-row {
  display: flex;
  align-items: center;
  gap: 6px;
}

.sett-logo-preview {
  width: 32px;
  height: 32px;
  object-fit: contain;
  border: 1px solid var(--border-color);
  background: var(--input-bg);
  padding: 2px;
  flex-shrink: 0;
}

.sett-logo-preview.hidden {
  display: none;
}

.sett-logo-btn {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  cursor: pointer;
  font-size: .65rem;
  font-weight: 600;
  padding: 6px 8px;
  color: var(--text-secondary);
  background: transparent;
  border: 1px dashed var(--border-color);
  transition: all var(--speed) var(--ease);
  flex: 1;
  justify-content: center;
}

.sett-logo-btn:hover {
  border-color: var(--accent);
  color: var(--accent);
}

.sett-logo-btn input {
  display: none;
}

.sett-logo-btn svg {
  width: 12px;
  height: 12px;
}

.sett-logo-clear {
  display: none;
  align-items: center;
  justify-content: center;
  width: 24px;
  height: 24px;
  padding: 0;
  background: transparent;
  border: 1px solid var(--border-color);
  color: var(--text-muted);
  cursor: pointer;
  flex-shrink: 0;
}

.sett-logo-clear:hover {
  border-color: #ef4444;
  color: #ef4444;
}

.sett-logo-clear.visible {
  display: inline-flex;
}

.sett-logo-clear svg {
  width: 12px;
  height: 12px;
}

.sett-format-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}

.sett-format-opt {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 12px 10px;
  background: var(--input-bg);
  border: 2px solid var(--border-color);
  cursor: pointer;
  transition: all var(--speed) var(--ease);
  font-family: var(--font-ui);
  font-size: .8rem;
  font-weight: 700;
  color: var(--text-secondary);
}

.sett-format-opt:hover {
  border-color: var(--accent);
  color: var(--text-primary);
}

.sett-format-opt.active {
  border-color: var(--accent);
  background: var(--accent);
  color: var(--accent-text, #fff);
  box-shadow: 0 4px 14px var(--accent-glow, rgba(0, 0, 0, .15));
}

.sett-format-opt.locked {
  pointer-events: none;
  opacity: .5;
}

.sett-format-opt input {
  position: absolute;
  opacity: 0;
  pointer-events: none;
}

.sett-format-opt svg {
  width: 16px;
  height: 16px;
}

.btn-save-settings {
  padding: 14px;
  font-size: .9rem;
  font-weight: 800;
  border-radius: var(--radius-md);
  letter-spacing: .01em;
  margin-top: 4px;
}

/* ── Confirm Modal ── */
.confirm-overlay {
  position: fixed;
  inset: 0;
  background: var(--overlay-bg, rgba(0, 0, 0, .6));
  z-index: 300;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  animation: fadeIn .15s ease;
}

.confirm-dialog {
  background: var(--card-bg);
  border: 1px solid var(--card-border);
  border-radius: var(--radius-xl);
  padding: 28px 24px 20px;
  width: 100%;
  max-width: 360px;
  display: flex;
  flex-direction: column;
  gap: 20px;
  animation: fadeInScale .25s var(--ease);
  box-shadow: 0 20px 60px rgba(0, 0, 0, .35);
  text-align: center;
}

.confirm-icon {
  width: 52px;
  height: 52px;
  border-radius: 50%;
  background: rgba(239, 68, 68, .12);
  display: flex;
  align-items: center;
  justify-content: center;
  margin: 0 auto;
  color: #ef4444;
}

.confirm-icon svg {
  width: 26px;
  height: 26px;
}

.confirm-title {
  font-size: 1.05rem;
  font-weight: 800;
  color: var(--text-primary);
  line-height: 1.3;
}

.confirm-message {
  font-size: .82rem;
  color: var(--text-secondary);
  line-height: 1.5;
}

.confirm-actions {
  display: flex;
  gap: 10px;
  margin-top: 4px;
}

.confirm-actions .btn {
  flex: 1;
  padding: 13px 16px;
  font-size: .82rem;
}

/* ══════════════════════════════════════════════
   RESPONSIVE MEDIA QUERIES
   ══════════════════════════════════════════════ */

/* ── Portrait Tablet & Small Laptops (≤ 768px) ── */
@media (max-width: 768px) {

  /* Header */
  .op-header {
    padding: 5px 10px;
  }

  .op-header-title {
    font-size: 1.05rem;
  }

  .op-header-sub {
    font-size: .85rem;
  }

  .op-header-right .btn-icon {
    width: 30px;
    height: 30px;
  }

  /* Stack panels vertically */
  .op-panels {
    grid-template-columns: 1fr;
  }

  /* Score: smaller clamp for portrait */
  .op-panel-score {
    font-size: clamp(3rem, 15vh, 8rem);
  }

  /* Tambah Poin: smaller */
  .btn-add-big {
    padding: 0.6rem 0.8rem;
    min-height: 3rem;
    font-size: 1rem;
  }

  /* CRITICAL: Merge 2 action rows into 1×4 grid via display:contents */
  .op-panel-actions {
    display: contents;
  }

  /* Create a 4-column grid on the panel itself for the loose buttons */
  .op-panel {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 3px;
    align-items: stretch;
  }

  /* Span full-width elements across all 4 columns */
  .op-panel-header,
  .op-panel-score,
  .btn-add-big {
    grid-column: 1 / -1;
  }

  /* Ensure panel header stays flex for internal layout */
  .op-panel-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
  }

  /* Ensure score centers within its full-width cell */
  .op-panel-score {
    display: flex;
    align-items: center;
    justify-content: center;
  }

  /* Action buttons: tight padding in their 4-col grid cells */
  .op-panel-actions .btn {
    padding: 0.5rem;
    font-size: .78rem;
    min-height: 2.5rem;
  }

  /* Bottom bar: 2-row grid to prevent horizontal overflow */
  .op-bottom-bar {
    grid-template-columns: 1fr 1fr;
    grid-template-areas:
      "timer  reset"
      "controls controls";
    gap: 0.5rem;
    padding: 0.5rem;
  }

  .op-bottom-timer {
    grid-area: timer;
  }

  .op-bottom-right {
    grid-area: reset;
    justify-content: flex-end;
  }

  .op-bottom-center {
    grid-area: controls;
    justify-content: center;
  }

  .btn-solid {
    font-size: .82rem;
    padding: 0.5rem 0.8rem;
    min-height: 2.5rem;
  }

  .btn-reset-outline {
    font-size: .82rem;
    padding: 0.5rem 0.8rem;
    min-height: 2.5rem;
  }

  .op-timer-display {
    font-size: 1.2rem;
  }

  /* Settings & Confirm */
  .confirm-dialog {
    padding: 20px 16px 14px;
  }

  .settings-panel {
    padding: 18px;
    gap: 14px;
  }

  .sett-team-grid {
    grid-template-columns: 1fr;
  }
}

/* ── Small Phones (≤ 600px) ── */
@media (max-width: 600px) {
  .op-header {
    padding: 4px 8px;
  }

  .op-header-title {
    font-size: .95rem;
  }

  .op-header-sub {
    font-size: .72rem;
  }

  /* Tighter score */
  .op-panel {
    padding: 4px 5px 5px;
  }

  .op-panel-score {
    font-size: clamp(2.5rem, 12vh, 6rem);
  }

  .op-panel-name {
    font-size: .9rem;
  }

  .op-panel-serve {
    font-size: .75rem;
  }

  /* Smaller add button */
  .btn-add-big {
    padding: 0.4rem 0.6rem;
    min-height: 2.5rem;
    font-size: .9rem;
  }

  /* Tighter action buttons */
  .op-panel-actions .btn {
    padding: 0.4rem 0.3rem;
    font-size: .7rem;
    gap: 2px;
  }

  .op-panel-actions .btn svg {
    width: 12px;
    height: 12px;
  }

  .op-to-badge {
    font-size: .62rem;
  }

  /* Bottom bar */
  .op-timer-display {
    font-size: 1rem;
  }

  .btn-solid {
    font-size: .75rem;
    padding: 0.4rem 0.6rem;
    min-height: 2.25rem;
  }

  .btn-reset-outline {
    font-size: .75rem;
    padding: 0.4rem 0.6rem;
    min-height: 2.25rem;
  }
}

/* ── Very Small Phones (≤ 360px) ── */
@media (max-width: 360px) {
  .op-panel-score {
    font-size: clamp(2rem, 10vh, 5rem);
  }

  .btn-add-big {
    min-height: 2rem;
    font-size: .82rem;
  }

  .op-panel-name {
    font-size: .78rem;
  }

  .op-panel-actions .btn {
    font-size: .62rem;
    padding: 0.35rem 0.2rem;
  }

  .op-header-title {
    font-size: .85rem;
  }

  .op-header-sub {
    font-size: .62rem;
  }
}

/* ── Tall Screens (≥ 900px height): cap dvh bloat ── */
@media (min-height: 900px) {
  .op-panel-actions .btn {
    padding: 1rem 0.8rem;
  }

  .btn-add-big {
    padding: 1rem;
  }
}

/* ── Mobile Landscape (short viewport ≤ 500px height) ── */
@media (max-height: 500px) and (orientation: landscape) {
  .op-header { padding: 2px 8px; }
  .op-header-title { font-size: .95rem; }
  .op-header-sub { font-size: .75rem; }
  .op-header-right .btn-icon { width: 28px; height: 28px; }

  .op-main { padding: 2px; gap: 2px; }

  /* FORCE side-by-side */
  .op-panels { grid-template-columns: 1fr 1fr !important; gap: 3px; }

  .op-panel { padding: 3px 6px 4px; gap: 0; }
  .op-panel::before { height: 3px; }
  .op-panel-name { font-size: 1rem; }
  .op-panel-serve { font-size: .8rem; }
  .op-panel-serve svg { width: 12px; height: 12px; }

  /* Score: vh biar proporsional sama tinggi layar di landscape */
  .op-panel-score {
    font-size: clamp(2rem, 15vh, 4rem) !important;
    line-height: .85;
    min-height: 0;
  }

  .btn-add-big { padding: 0.4rem 0.6rem; min-height: 2.4rem; font-size: .95rem; margin-top: 2px; gap: 5px; }
  .btn-add-big svg { width: 18px; height: 18px; }

  .op-panel-actions { margin-top: 2px; gap: 2px; }
  .op-panel-actions .btn { padding: 0.3rem 0.4rem; font-size: .8rem; min-height: 2rem; gap: 3px; }
  .op-panel-actions .btn svg { width: 14px; height: 14px; }
  .op-to-badge { font-size: .65rem; }

  .op-bottom-bar { padding: 0.3rem 0.6rem; gap: 0.5rem; }
  .op-timer-display { font-size: 1.2rem; }
  .op-timer-controls .btn { padding: 3px 8px; font-size: .75rem; min-height: 2rem; }
  .btn-solid { font-size: .85rem; padding: 0.3rem 0.8rem; min-height: 2rem; gap: 4px; }
  .btn-solid svg { width: 14px; height: 14px; }
  .btn-reset-outline { font-size: .85rem; padding: 0.3rem 0.8rem; min-height: 2rem; }
  .btn-reset-outline svg { width: 14px; height: 14px; }
}