/* Clock grid */
#clock-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
  gap: 3rem;
  padding: 2rem;
  width: 100%;
  max-width: 1400px;
  margin: 0 auto;
  justify-content: center;
  align-items: start;
}

/* Clock Card */
.clock-card {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 1.5rem;
  width: 100%;
  container-type: inline-size;
}

/* Controls row. The visible icon is the single centered in-flow child;
   the remove button is absolutely centered on the same spot and cross-
   fades in on hover/focus (see below). */
.clock-controls {
  display: flex;
  justify-content: center;
  align-items: center;
  width: 100%;
  position: relative;
  z-index: 60;
  flex-shrink: 0;
  min-height: 32px;
  margin-bottom: 8px;
  margin-bottom: 4cqi;
}

.home-icon,
.salesforce-icon {
  display: none;
  width: 24px;
  height: 24px;
  color: var(--text-secondary);
  transition: opacity var(--transition-fast);
}

/* Absolutely centered over the icon slot so (a) it never shifts the
   centered icon off-axis, and (b) it occupies the same spot as the icon
   for a clean swap. Hidden until hover/focus. */
.remove-btn {
  position: absolute;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%);
  background: none;
  border: none;
  color: var(--brand-red);
  cursor: pointer;
  opacity: 0;
  transition: opacity var(--transition-fast);
  padding: 0;
  display: flex;
  align-items: center;
  justify-content: center;
}

.remove-btn:focus-visible {
  opacity: 1;
  outline: 2px solid var(--brand-red);
  outline-offset: 2px;
}

.remove-icon {
  width: 24px;
  height: 24px;
  stroke: currentColor;
  stroke-width: 2;
}

.clock-card:hover .remove-btn,
.clock-card:focus-within .remove-btn {
  opacity: 1;
}

/* On the local clock, the home icon and the remove button share the
   centered slot. Fade the home icon out on hover/focus so it cleanly
   morphs into the red X. The Salesforce/MCE cloud is intentionally NOT
   targeted (that clock has no remove button — the cloud always shows). */
.clock-card:hover .home-icon,
.clock-card:focus-within .home-icon {
  opacity: 0;
}

/* Clock container */
.clock-container {
  position: relative;
  width: 100%;
  max-width: 350px;
  aspect-ratio: 1/1;
  display: flex;
  align-items: center;
  justify-content: center;
}

.clock-face {
  position: relative;
  width: 100%;
  height: 100%;
  overflow: hidden;
  border-radius: 50%;
  background-color: var(--clock-face);
  border: 4px solid var(--clock-border);
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.1);
  flex-shrink: 0;
  transition: background-color 0.5s ease;
}

/* Analog / Digital faces */
.analog-face,
.digital-face {
  width: 100%;
  height: 100%;
  position: absolute;
  top: 0;
  left: 0;
  border-radius: 50%;
  background-color: transparent;
}

.digital-face {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 0.3rem;
  padding: 10%;
  box-sizing: border-box;
}

.digital-time {
  font-size: 11cqi;
  font-weight: 700;
  color: var(--text-primary);
  font-variant-numeric: tabular-nums;
  line-height: 1.1;
  text-align: center;
  white-space: nowrap;
  max-width: 100%;
}

.digital-date {
  font-size: 4cqi;
  font-weight: 500;
  color: var(--brand-red);
  text-transform: uppercase;
  letter-spacing: 2px;
}

/* Day/Night overrides */
.clock-card.day .clock-face {
  background-color: #FFFFFF;
  border-color: var(--clock-border);
}

.clock-card.day .digital-time {
  color: #1A1A1A;
}

.clock-card.night .clock-face {
  background-color: #1E1E1E;
  border-color: var(--clock-border);
}

.clock-card.night .digital-time {
  color: #F0F0F0;
}

.clock-card.night .marker::after {
  background-color: #F0F0F0;
}

.clock-card.day .marker::after {
  background-color: #1A1A1A;
}

/* Date display on analog face */
.date-display {
  position: absolute;
  top: 50%;
  /* Anchor from the left so the badge always begins just right of the
     center hub. A right:% anchor let the badge's floor width (min font +
     "MMM DD") reach back over the center on small (160px) clocks. */
  left: 56%;
  transform: translateY(-50%);
  font-weight: 700;
  font-size: 12px;
  font-size: clamp(10px, 4.5cqi, 18px);
  background-color: var(--text-primary);
  color: var(--bg-app);
  padding: 2px 4px;
  padding: clamp(1px, 0.5cqi, 5px) clamp(3px, 1cqi, 8px);
  border-radius: 2px;
  z-index: 5;
  white-space: nowrap;
}

/* Hands */
.hand {
  position: absolute;
  bottom: 50%;
  left: 50%;
  transform-origin: bottom center;
  border-radius: 2px 2px 0 0;
  z-index: 10;
}

.hour-hand {
  width: 6px;
  height: 25%;
  background-color: var(--hand-hour);
}

.minute-hand {
  width: 4px;
  height: 40%;
  background-color: var(--hand-minute);
  z-index: 11;
}

.second-hand {
  width: 2px;
  height: 45%;
  background-color: var(--hand-second);
  z-index: 12;
}

.second-hand::after {
  content: '';
  position: absolute;
  bottom: -15px;
  left: 50%;
  transform: translateX(-50%);
  width: 8px;
  height: 8px;
  background-color: var(--hand-second);
  border-radius: 50%;
}

.center-dot {
  position: absolute;
  top: 50%;
  left: 50%;
  width: 12px;
  height: 12px;
  background-color: var(--text-primary);
  border-radius: 50%;
  transform: translate(-50%, -50%);
  z-index: 20;
  transition: background-color 0.5s ease;
}

.clock-card.night .center-dot {
  background-color: #F0F0F0;
}

.clock-card.day .center-dot {
  background-color: #1A1A1A;
}

/* Markers */
.marker {
  position: absolute;
  bottom: 50%;
  left: 50%;
  width: 2px;
  height: 50%;
  transform-origin: bottom center;
  margin-left: -1px;
  z-index: 1;
}

.marker::after {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 12%;
  background-color: var(--marker-color);
  display: block;
}

.hour-1  { transform: rotate(30deg); }
.hour-2  { transform: rotate(60deg); }
.hour-3  { transform: rotate(90deg); }
.hour-4  { transform: rotate(120deg); }
.hour-5  { transform: rotate(150deg); }
.hour-6  { transform: rotate(180deg); }
.hour-7  { transform: rotate(210deg); }
.hour-8  { transform: rotate(240deg); }
.hour-9  { transform: rotate(270deg); }
.hour-10 { transform: rotate(300deg); }
.hour-11 { transform: rotate(330deg); }
.hour-12 { transform: rotate(0deg); }

.hour-12::after,
.hour-3::after,
.hour-6::after,
.hour-9::after {
  height: 25%;
}

/* Digital readout below analog clock */
.digital-readout {
  font-size: 1.3rem;
  font-weight: 600;
  color: var(--text-primary);
  font-variant-numeric: tabular-nums;
  text-align: center;
  letter-spacing: 1.5px;
  line-height: 1;
  margin-top: 5cqi;
}

.digital-readout__blink {
  animation: blink-colon 1s step-end infinite;
}

.digital-readout__ampm {
  font-size: 0.75em;
  font-weight: 500;
  letter-spacing: 0.5px;
}

@keyframes blink-colon {
  0%, 50% { opacity: 1; }
  51%, 100% { opacity: 0; }
}

/* Timezone display */
.timezone-display {
  font-weight: 300;
  font-size: 1.1rem;
  letter-spacing: 1px;
  color: var(--text-primary);
  text-transform: uppercase;
  text-align: center;
  display: flex;
  flex-direction: column;
  gap: 0.3rem;
  width: 100%;
  align-items: center;
  margin-top: 8px;
  margin-top: 4cqi;
}

.timezone-name-row {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
}

.timezone-short {
  font-size: 0.65rem;
  font-weight: 700;
  color: var(--text-muted);
  background: var(--bg-app);
  border: 1px solid var(--border-color);
  border-radius: 3px;
  padding: 0 4px;
  line-height: 1.5;
  letter-spacing: 0.3px;
  flex-shrink: 0;
}

.timezone-name-text {
  cursor: default;
}

.timezone-rename-input {
  background: var(--bg-app);
  color: var(--text-primary);
  border: 1px solid var(--color-primary);
  border-radius: 3px;
  padding: 2px 6px;
  font-family: var(--font-family);
  font-size: inherit;
  font-weight: inherit;
  text-align: center;
  outline: none;
}

.timezone-details {
  font-size: 0.85rem;
  font-weight: 500;
  opacity: 0.7;
}

/* Time Probe */
.probe-btn {
  background: none;
  border: 1px solid var(--border-color);
  color: var(--text-secondary);
  cursor: pointer;
  border-radius: var(--border-radius-sm);
  width: 28px;
  height: 28px;
  display: flex;
  align-items: center;
  justify-content: center;
  opacity: 0;
  transition: opacity var(--transition-fast), background var(--transition-fast);
  margin-top: var(--spacing-sm);
}

.clock-card:hover .probe-btn,
.clock-card:focus-within .probe-btn,
.clock-card.probe-active .probe-btn {
  opacity: 1;
}

.probe-btn:hover {
  background: var(--sidebar-item-hover);
  color: var(--text-primary);
}

.clock-card.probe-active {
  box-shadow: inset 0 0 0 3px var(--brand-blue);
  border-radius: var(--border-radius-md);
}

.clock-card.probe-active .probe-btn {
  border-color: var(--brand-blue);
  color: var(--brand-blue);
}

.probe-picker {
  position: absolute;
  bottom: 0;
  left: 50%;
  transform: translateX(-50%);
  z-index: 500;
  background-color: var(--bg-surface);
  border: 1px solid var(--border-color);
  border-radius: var(--border-radius-md);
  box-shadow: var(--shadow-md);
  padding: var(--spacing-sm);
  width: 220px;
}

.probe-header {
  font-size: var(--font-size-xs);
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: var(--color-primary);
  text-align: center;
  margin-bottom: var(--spacing-xs);
}

.probe-input-group {
  display: flex;
  gap: var(--spacing-xs);
  align-items: center;
}

.probe-time-input {
  flex: 1;
  padding: 5px 8px;
  border: 1px solid var(--border-color);
  background: var(--bg-app);
  color: var(--text-primary);
  font-family: var(--font-family);
  font-size: var(--font-size-md);
  font-weight: 600;
  border-radius: var(--border-radius-sm);
  text-align: center;
}

.probe-time-input:focus {
  outline: none;
  border-color: var(--color-primary);
}

.probe-date-input {
  width: 100%;
  padding: 4px 8px;
  margin-top: var(--spacing-xs);
  border: 1px solid var(--border-color);
  background: var(--bg-app);
  color: var(--text-primary);
  font-family: var(--font-family);
  font-size: var(--font-size-sm);
  border-radius: var(--border-radius-sm);
  text-align: center;
}

.probe-date-input:focus {
  outline: none;
  border-color: var(--color-primary);
}

.probe-apply-btn {
  background-color: var(--color-primary);
  color: white;
  border: none;
  padding: 5px 12px;
  font-family: var(--font-family);
  font-size: var(--font-size-xs);
  font-weight: 700;
  cursor: pointer;
  border-radius: var(--border-radius-sm);
  transition: background var(--transition-fast);
}

.probe-apply-btn:hover {
  opacity: 0.88;
}

.probe-close {
  position: absolute;
  top: 2px;
  right: 6px;
  background: none;
  border: none;
  color: var(--text-muted);
  font-size: 1rem;
  cursor: pointer;
  opacity: 0.5;
  transition: opacity var(--transition-fast);
}

.probe-close:hover {
  opacity: 1;
}

.probe-picker.hidden {
  display: none !important;
}

/* Delete Overlay */
.delete-overlay {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background-color: var(--bg-app);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
  border-radius: var(--border-radius-md);
  transition: opacity 0.3s ease;
}

.delete-content {
  text-align: center;
  display: flex;
  flex-direction: column;
  gap: 1.2rem;
  padding: 1.5rem;
}

.delete-question {
  font-size: 1.5rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 2px;
  color: var(--text-primary);
}

.delete-actions {
  display: flex;
  gap: 1.5rem;
  justify-content: center;
}

.delete-actions button {
  background: none;
  border: 1px solid var(--border-color);
  color: var(--text-secondary);
  padding: 8px 20px;
  font-family: var(--font-family);
  font-weight: 600;
  font-size: var(--font-size-md);
  cursor: pointer;
  transition: all var(--transition-fast);
  text-transform: uppercase;
  border-radius: var(--border-radius-sm);
}

.delete-actions .confirm-delete:hover {
  background-color: var(--brand-red);
  border-color: var(--brand-red);
  color: white;
}

.delete-actions .cancel-delete:hover {
  background: var(--sidebar-item-hover);
  color: var(--text-primary);
  border-color: var(--border-color-strong);
}

/* Responsive */
@media (max-width: 768px) {
  #clock-grid {
    grid-template-columns: repeat(2, 1fr);
    gap: 0.75rem;
    padding: 0.5rem;
  }

  .clock-card {
    padding: 0.25rem;
  }

  /* Cap the aspect-ratio owner so width AND height shrink together.
     Capping .clock-face alone left its height tracking the (larger,
     square) .clock-container — producing an egg in the 450–768px band. */
  .clock-container {
    max-width: 160px;
  }

  .clock-face {
    border-width: 3px;
  }

  .clock-face__marker {
    width: 1px;
    height: 6px;
  }

  .clock-face__marker--major {
    width: 2px;
    height: 10px;
  }

  .clock-digital__time {
    font-size: 9cqi;
  }

  .clock-digital__date {
    font-size: 3.5cqi;
    letter-spacing: 1px;
  }

  .clock-tz {
    padding: 2px 6px;
    font-size: 0.7rem;
    letter-spacing: 0.5px;
  }

  .clock-tz__detail {
    font-size: 0.55rem;
  }

  .timezone-display {
    font-size: 0.8rem;
    gap: 0.15rem;
    margin-top: 4px;
  }

  .timezone-name-row {
    flex-direction: column;
    gap: 2px;
  }

  .timezone-short {
    font-size: 0.55rem;
  }

  .timezone-details {
    font-size: 0.6rem;
  }

  .clock-card__delete-overlay .clock-card__delete-text {
    font-size: 0.7rem;
  }

  .clock-card__delete-overlay .clock-card__delete-actions {
    gap: 6px;
  }

  .clock-card__delete-overlay .clock-card__delete-btn {
    padding: 4px 12px;
    font-size: 0.65rem;
  }
}

/* Phone widths: a 2-up grid squashes the cards (digital readouts collide).
   Drop to a single column and let the clock use more of the width. */
@media (max-width: 480px) {
  #clock-grid {
    grid-template-columns: 1fr;
  }

  .clock-container {
    max-width: 220px;
  }
}
