/* Pill Runs feature styles (scaffold) */
/* Root card and IDs inherit from global .card; specific styles below */

/* Location buttons grid and states */
.location-buttons { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; margin: 10px 0; }
.location-btn { padding: 8px 10px; background: var(--card-bg); border: 1px solid var(--border-color); border-radius: 6px; cursor: pointer; transition: all var(--transition-normal); text-align: center; font-size: 0.9rem; position: relative; overflow: hidden; flex: 1; color: var(--text); }
.location-btn::after { content: ''; position: absolute; bottom: 0; left: 0; width: 100%; height: 2px; background: var(--accent); transform: scaleX(0); transition: transform var(--transition-normal); }
.location-btn.active { background: var(--accent-light); color: var(--accent); border-color: var(--accent); box-shadow: 0 0 0 1px var(--accent), 0 2px 6px rgba(39, 174, 96, 0.1); font-weight: 600; transform: translateY(-1px); }
.location-btn.active::after { transform: scaleX(1); }
.location-btn:hover:not(.active) { border-color: var(--accent); transform: translateY(-1px); }
.location-btn:hover::after { transform: scaleX(0.5); }
.location-btn.disabled{opacity:.45;cursor:not-allowed;pointer-events:none}

/* History Item Styles */
.history-item { background: rgba(255, 255, 255, 0.03); padding: 10px 15px; margin-bottom: 8px; border-radius: 6px; border-left: 3px solid var(--accent); display: flex; justify-content: flex-start; align-items: center; gap: 8px; transition: background-color 0.2s ease; }
.history-item:hover { background: rgba(255, 255, 255, 0.05); }
.history-item .location { font-weight: 600; color: var(--accent); min-width: 72px; max-width: 32%; overflow: hidden; white-space: nowrap; text-overflow: ellipsis; }
.history-item .time { color: var(--text-secondary); font-size: 0.9em; flex: 1 1 auto; min-width: 0; overflow: hidden; white-space: nowrap; text-overflow: ellipsis; }
.history-item .time-ago { color: var(--text-secondary); font-size: 0.85em; font-style: italic; white-space: nowrap; }
.empty-history { color: var(--text-secondary); text-align: center; padding: 20px; font-style: italic; }

/* Structured layout regions inside a history row */
.history-left { display: flex; align-items: center; gap: 6px; min-width: 0; flex: 1 1 auto; }
.history-date-badge { background: var(--accent); color: #000; width: 32px; height: 32px; border-radius: 8px; display: flex; flex-direction: column; align-items: center; justify-content: center; font-weight: bold; margin-left: 4px; flex: 0 0 auto; }
.history-date-month { font-size: 11px; line-height: 1; }
.history-date-day { font-size: 14px; }
.history-time-row { display: flex; align-items: center; gap: 6px; white-space: nowrap; min-width: 0; }

/* Note column: fixed width on the right (non-sticky) */
.history-note-col { display: flex; flex-direction: column; align-items: stretch; justify-content: center; gap: 4px; width: 280px; position: relative; padding-left: 0; padding-right: 0; margin-left: 16px; margin-right: 0; background: transparent; z-index: auto; align-self: center; }
.history-note-input { width: 100%; padding: 6px 8px; border-radius: 6px; border: 1px solid var(--border-color); background: var(--card-bg); color: var(--text); font-size: 0.9em; box-sizing: border-box; margin-top: 0 !important; position: static; }
.history-note-input:focus { outline: 2px solid var(--accent); outline-offset: 1px; }
.history-note-status { position: absolute; right: 0; bottom: -2px; margin-top: 0; font-size: 0.8em; color: var(--text-secondary); display: block; min-height: 0; line-height: 14px; visibility: hidden; }

/* History list container */
#historyList { flex: 1 1 auto; max-height: 320px; overflow-y: auto; overflow-x: hidden; padding: 12px; background: rgba(255,255,255,0.02); border-radius: 6px; margin-bottom: 8px; contain: layout paint; min-height: 0; }
/* Let items shrink to container to avoid horizontal scrolling */
#historyList .history-item { min-width: 0; width: 100%; }
/* Visible scrollbar styling for history list (both axes) */
#historyList::-webkit-scrollbar { height: 10px; width: 10px; }
#historyList::-webkit-scrollbar-thumb { background: color-mix(in srgb, var(--accent) 70%, #000 0%); border-radius: 6px; border: 2px solid transparent; background-clip: padding-box; }
#historyList::-webkit-scrollbar-thumb:hover { background: color-mix(in srgb, var(--accent) 85%, #000 0%); }
#historyList::-webkit-scrollbar-track { background: var(--card-hover); border-radius: 6px; }
#historyList { scrollbar-width: thin; scrollbar-color: var(--accent) var(--card-hover); }

/* Date-Time chip and location tag */
.dt-chip { display: inline-flex; align-items: center; gap: 4px; padding: 2px 6px; border: 1px solid var(--border-color); background: var(--card-hover); border-radius: 999px; font-size: 0.8rem; color: var(--text-secondary); white-space: nowrap; flex: 0 0 auto; }
.dt-chip i { font-size: 0.85em; opacity: 0.85; color: var(--accent); }
.dt-text { letter-spacing: .2px; }
.history-location-tag { margin-left: 6px; padding: 2px 5px; border: 1px solid var(--border-color); border-radius: 999px; background: transparent; color: var(--text); max-width: 70%; overflow: hidden; white-space: nowrap; text-overflow: ellipsis; flex: 0 1 auto; }
.history-location-tag.loc-chumash { font-size: 0.85em; letter-spacing: 0.1px; padding: 1px 6px; }

/* Pill Run card variants and status styles */
.pill-run-card { transition: all 0.3s ease; border-radius: 12px; overflow: visible; position: relative; z-index: 1; }
.pill-run-card.ready { box-shadow: none; border: 1px solid var(--border-color); }
.pill-run-card.almost-ready { box-shadow: none; border: 1px solid var(--border-color); }
.pill-run-card.on-cooldown { border: 1px solid var(--border-color); }
.pill-run-card.error { box-shadow: none; border: 1px solid var(--border-color); }
.status-available { color: var(--success); font-weight: 600; }
.status-cooldown { color: var(--warning); font-weight: 600; }
.end-time { font-size: 0.85em; opacity: 0.8; display: block; margin-top: 3px; }

/* Start row + top-right reset icon (Pill Runs) */
.pill-start-row { position: relative; z-index: 5; overflow: visible; }
.pill-start-row .pill-reset-icon {
  position: absolute; top: -36px; right: 0;
  width: 28px; height: 28px; padding: 0;
  display: inline-flex; align-items: center; justify-content: center;
  border-radius: 50%; border: 1px solid var(--border-color);
  background: var(--card-hover); color: var(--text-secondary);
  cursor: pointer; transition: transform .15s ease, color .15s ease, border-color .15s ease, background .15s ease;
  z-index: 2000; pointer-events: auto;
}
.pill-start-row .pill-reset-icon i { font-size: 0.9em; }
.pill-start-row .pill-reset-icon:hover { transform: translateY(-1px); color: var(--accent); border-color: var(--accent); }
:root[data-theme="light"] .pill-start-row .pill-reset-icon { background: var(--button-bg); color: var(--primary); }
:root[data-theme="light"] .pill-start-row .pill-reset-icon:hover { background: var(--primary); color: #fff; border-color: var(--primary); }

/* Prevent focus/hover animations from shifting layout for this card */
#pillRunsCard.card:hover { transform: none !important; }
#pillRunsCard.card:focus-within { overflow: hidden !important; }
/* Same for Run History card */
#runHistoryCard.card:hover { transform: none !important; }
#runHistoryCard.card:focus-within { overflow: hidden !important; }
#runHistoryCard { align-self: start !important; }
#runHistoryCard.card { transition: none !important; height: 100% !important; display: flex; flex-direction: column; max-height: none; }
#pillRunsCard.card { height: 100% !important; }
#runHistoryCard .history-item,
#runHistoryCard .history-note-input,
#runHistoryCard .history-note-status { transition: none !important; }
/* Stabilize footer button spacing */
#runHistoryCard .secondary.mt-auto { margin-top: 8px !important; }

/* Pill-run timer display tweak */
.pill-run-card .timer-display {
  font-family: 'Poppins', monospace;
  background: rgba(255, 119, 0, 0.08);
  padding: 15px;
  border-radius: 10px;
  text-align: center;
  font-weight: 700;
  letter-spacing: 1px;
  font-size: 1.2em;
  box-shadow: 0 2px 10px rgba(0, 0, 0, 0.1);
  transition: all 0.3s ease;
  border: 2px solid transparent;
}

/* History note responsive tweaks */
@media (max-width: 768px) {
  .history-item { flex-wrap: wrap !important; }
  .history-note-col { width: 100% !important; align-items: stretch !important; margin-top: 6px; }
  .history-note-input { width: 100% !important; font-size: 16px !important; }
}
/* Responsive: adjust location button grid and history layout */
@media (max-width: 1024px) {
  .location-buttons { grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 6px; }
}
@media (max-width: 768px) {
  .location-buttons { grid-template-columns: 1fr 1fr; }
}
@media (max-width: 768px) and (orientation: landscape) {
  .location-buttons { grid-template-columns: repeat(3, 1fr); }
}
@media (max-width: 480px) {
  .location-buttons { grid-template-columns: 1fr 1fr; }
  .history-item { display: flex; flex-direction: column; align-items: stretch; gap: 8px; }
  .history-location-tag { max-width: 60vw; overflow: hidden; text-overflow: ellipsis; }
  /* Let history rows fit the viewport width on small phones */
  #historyList { overflow-x: hidden; }
  #historyList .history-item { min-width: 0; width: 100%; }
  .history-date-badge { width: 34px; height: 34px; }
  .history-date-day { font-size: 14px; }
}
