/* ============================================================
   TOOLSPOT — SLEEP CALCULATOR & ANALYZER STYLES
   ============================================================ */

:root {
  --tool-emerald: #10b981;
  --tool-emerald-soft: rgba(16, 185, 129, 0.15);
  --tool-emerald-glow: rgba(16, 185, 129, 0.25);
}

body.light {
  --tool-emerald: #059669;
  --tool-emerald-soft: rgba(5, 150, 105, 0.08);
  --tool-emerald-glow: rgba(5, 150, 105, 0.15);
}

/* ── Page Layout ── */
.container {
  max-width: 1200px;
  margin: 0 auto;
  padding: 0 24px 100px;
  position: relative;
  z-index: 1;
}

/* ── Interactive sliding toggles ── */
.mode-toggle {
  position: relative;
  display: flex !important;
  background: rgba(255, 255, 255, 0.02);
  border: 1px solid rgba(255, 255, 255, 0.05);
  border-radius: 12px;
  padding: 4px;
  gap: 4px;
  z-index: 1;
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  transition: all 0.3s ease;
  margin-bottom: 24px;
  width: 100%;
}

.mode-toggle::before {
  content: '';
  position: absolute;
  top: 4px;
  bottom: 4px;
  left: 4px;
  width: calc(33.333% - 6px);
  background: linear-gradient(135deg, rgba(16, 185, 129, 0.15) 0%, rgba(16, 185, 129, 0.06) 100%);
  border: 1px solid rgba(16, 185, 129, 0.3);
  border-radius: 8px;
  transition: transform 0.28s cubic-bezier(0.25, 1, 0.5, 1), background 0.28s, border-color 0.28s;
  z-index: 0;
  box-shadow: 0 4px 15px rgba(16, 185, 129, 0.12), inset 0 1px 1px rgba(255, 255, 255, 0.15);
}

.mode-toggle.active-wake::before {
  transform: translateX(0);
}

.mode-toggle.active-bed::before {
  transform: translateX(calc(100% + 4px));
}

.mode-toggle.active-now::before {
  transform: translateX(calc(200% + 8px));
}

.mode-btn {
  position: relative;
  z-index: 2;
  flex: 1;
  background: transparent !important;
  border: none;
  padding: 10px 16px;
  font-size: 13px;
  font-weight: 700;
  color: var(--text-2);
  cursor: pointer;
  border-radius: 8px;
  box-shadow: none !important;
  transition: color 0.28s cubic-bezier(0.25, 1, 0.5, 1), transform 0.2s cubic-bezier(0.25, 0.8, 0.25, 1);
  text-align: center;
}

.mode-btn:hover {
  color: var(--text);
}

.mode-btn.active {
  color: #34d399 !important;
  text-shadow: 0 0 10px rgba(16, 185, 129, 0.4);
  background: transparent !important;
  box-shadow: none !important;
}

.mode-btn:active {
  transform: scale(0.97);
}

body.light .mode-toggle {
  background: rgba(0, 0, 0, 0.02);
  border-color: rgba(0, 0, 0, 0.05);
}

body.light .mode-toggle::before {
  background: linear-gradient(135deg, rgba(5, 150, 105, 0.12) 0%, rgba(5, 150, 105, 0.04) 100%) !important;
  border-color: rgba(5, 150, 105, 0.25) !important;
  box-shadow: 0 4px 12px rgba(5, 150, 105, 0.06), inset 0 1px 1px rgba(255, 255, 255, 0.5) !important;
}

body.light .mode-btn {
  color: #556b82 !important;
}

body.light .mode-btn:hover {
  color: #0f172a !important;
}

body.light .mode-btn.active {
  color: #059669 !important;
  text-shadow: none !important;
}

/* ── Sleep Timeline Cards Grid ── */
.timeline-grid {
  display: flex;
  flex-direction: column;
  gap: 12px;
  margin-top: 16px;
}

.cycle-card {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 20px;
  border-radius: 16px;
  background: rgba(255, 255, 255, 0.02);
  border: 1px solid rgba(255, 255, 255, 0.06);
  transition: all 0.25s cubic-bezier(0.16, 1, 0.3, 1);
  position: relative;
  overflow: hidden;
  gap: 12px;
}

.cycle-card::before {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  bottom: 0;
  width: 4px;
  background: transparent;
  transition: background-color 0.2s;
}

.cycle-card:hover {
  background: rgba(255, 255, 255, 0.04);
  transform: translateY(-2px);
  box-shadow: 0 4px 20px rgba(0, 0, 0, 0.2);
}

/* Recommended highlight */
.cycle-card.recommended {
  background: rgba(16, 185, 129, 0.03);
  border-color: rgba(16, 185, 129, 0.22);
  box-shadow: 0 0 15px rgba(16, 185, 129, 0.05);
}

.cycle-card.recommended::before {
  background: var(--tool-emerald);
}

.cycle-card.recommended:hover {
  background: rgba(16, 185, 129, 0.05);
  border-color: rgba(16, 185, 129, 0.35);
  box-shadow: 0 4px 24px rgba(16, 185, 129, 0.1);
}

/* Sleep Quality Categories */
.cycle-card.quality-optimal::before { background-color: var(--tool-emerald); }
.cycle-card.quality-acceptable::before { background-color: #fbbf24; }
.cycle-card.quality-insufficient::before { background-color: #f97316; }
.cycle-card.quality-severe::before { background-color: #ef4444; }

.cycle-info {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.cycle-num-label {
  font-family: 'Outfit', sans-serif;
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.5px;
  text-transform: uppercase;
  color: var(--text-3);
  display: flex;
  align-items: center;
  gap: 6px;
}

.cycle-badge {
  font-size: 9px;
  font-weight: 700;
  padding: 2px 6px;
  border-radius: 4px;
  text-transform: uppercase;
}

.badge-optimal {
  background: rgba(16, 185, 129, 0.12);
  color: #34d399;
  border: 1px solid rgba(16, 185, 129, 0.2);
}

.badge-acceptable {
  background: rgba(251, 191, 36, 0.12);
  color: #fcd34d;
  border: 1px solid rgba(251, 191, 36, 0.2);
}

.badge-insufficient {
  background: rgba(249, 115, 22, 0.12);
  color: #fdba74;
  border: 1px solid rgba(249, 115, 22, 0.2);
}

.badge-severe {
  background: rgba(239, 68, 68, 0.12);
  color: #fca5a5;
  border: 1px solid rgba(239, 68, 68, 0.2);
}

.cycle-duration {
  font-size: 18px;
  font-weight: 800;
  color: var(--text);
  font-family: 'Outfit', sans-serif;
}

.cycle-duration span {
  font-size: 13px;
  font-weight: 500;
  color: var(--text-2);
  margin-left: 2px;
}

.cycle-time-box {
  text-align: right;
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 2px;
}

.cycle-time {
  font-family: 'Outfit', sans-serif;
  font-size: 20px;
  font-weight: 800;
  color: var(--text);
}

.cycle-desc {
  font-size: 11px;
  color: var(--text-3);
}

/* ── Interactive Time Input Grid ── */
.time-select-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
}

.time-select-grid select {
  font-family: 'Outfit', sans-serif;
  font-size: 15px;
  font-weight: 600;
  background-position: right 8px center !important;
}

/* ── Sleep Cycle Anatomy Segmented Bar ── */
.cycle-anatomy-wrap {
  margin-top: 16px;
}

.cycle-bar-track {
  height: 12px;
  border-radius: 6px;
  display: flex;
  overflow: hidden;
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid rgba(255, 255, 255, 0.08);
}

.cycle-segment {
  height: 100%;
  transition: width 0.3s;
}

.segment-light { background: #3b82f6; }
.segment-deep { background: #8b5cf6; }
.segment-rem { background: #ec4899; }

.cycle-legends {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
  margin-top: 12px;
}

.legend-item {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.legend-header {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 10px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: var(--text-3);
}

.legend-color {
  width: 8px;
  height: 8px;
  border-radius: 2px;
}

.legend-val {
  font-size: 12px;
  font-weight: 700;
  color: var(--text);
}

.legend-desc {
  font-size: 10px;
  color: var(--text-3);
  line-height: 1.3;
}

/* ── Visual Result Hero Card ── */
.result-hero {
  background: linear-gradient(135deg, rgba(16, 185, 129, 0.08) 0%, rgba(139, 92, 246, 0.03) 100%);
  border: 1px solid rgba(16, 185, 129, 0.2);
  border-radius: 18px;
  padding: 22px;
  position: relative;
  overflow: hidden;
  text-align: center;
}

.result-hero::after {
  content: '';
  position: absolute;
  top: -50%;
  left: -50%;
  width: 200%;
  height: 200%;
  background: radial-gradient(circle, rgba(16, 185, 129, 0.05) 0%, transparent 60%);
  pointer-events: none;
}

.result-hero-label {
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 1px;
  text-transform: uppercase;
  color: var(--text-3);
  margin-bottom: 6px;
}

.result-hero-time {
  font-family: 'Outfit', sans-serif;
  font-size: 34px;
  font-weight: 800;
  color: var(--text);
  line-height: 1.1;
  text-shadow: 0 0 20px rgba(16, 185, 129, 0.15);
}

.result-hero-desc {
  font-size: 13px;
  color: var(--text-2);
  margin-top: 8px;
  line-height: 1.4;
}

/* ── Light Mode Styles Overrides ── */
body.light .cycle-card {
  background: rgba(0, 0, 0, 0.015);
  border-color: rgba(0, 0, 0, 0.05);
}

body.light .cycle-card:hover {
  background: rgba(0, 0, 0, 0.03);
  box-shadow: 0 4px 15px rgba(0, 0, 0, 0.06);
}

body.light .cycle-card.recommended {
  background: rgba(16, 185, 129, 0.02);
  border-color: rgba(16, 185, 129, 0.18);
}

body.light .cycle-card.recommended:hover {
  background: rgba(16, 185, 129, 0.04);
}

body.light .result-hero {
  background: linear-gradient(135deg, rgba(16, 185, 129, 0.04) 0%, rgba(139, 92, 246, 0.01) 100%);
  border-color: rgba(16, 185, 129, 0.15);
}

body.light .time-select-grid select {
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 24 24' fill='none' stroke='rgba(0,0,0,0.4)' stroke-width='2.5'%3E%3Cpolyline points='6 9 12 15 18 9'/%3E%3C/svg%3E") !important;
}

body.light .cycle-bar-track {
  background: rgba(0, 0, 0, 0.04);
  border-color: rgba(0, 0, 0, 0.06);
}

body.light .badge-optimal { background: rgba(16, 185, 129, 0.08); color: #047857; border-color: rgba(16, 185, 129, 0.15); }
body.light .badge-acceptable { background: rgba(217, 119, 6, 0.08); color: #b45309; border-color: rgba(217, 119, 6, 0.15); }
body.light .badge-insufficient { background: rgba(249, 115, 22, 0.08); color: #c2410c; border-color: rgba(249, 115, 22, 0.15); }
body.light .badge-severe { background: rgba(220, 38, 38, 0.08); color: #b91c1c; border-color: rgba(220, 38, 38, 0.15); }

/* ── Range Slider ── */
.range-slider {
  -webkit-appearance: none;
  appearance: none;
  width: 100%;
  height: 6px;
  border-radius: 10px;
  outline: none;
  cursor: pointer;
  background: linear-gradient(to right, #10b981 0%, #10b981 var(--fill, 50%), 
    rgba(255, 255, 255, 0.1) var(--fill, 50%), rgba(255, 255, 255, 0.1) 100%) !important;
}

.range-slider::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 20px;
  height: 20px;
  background: #fff !important;
  border: 3px solid #10b981 !important;
  border-radius: 50% !important;
  cursor: pointer;
  box-shadow: 0 0 0 4px rgba(16, 185, 129, 0.15), 0 2px 8px rgba(0, 0, 0, 0.3) !important;
  transition: transform 0.15s cubic-bezier(0.175, 0.885, 0.32, 1.275) !important;
}

.range-slider::-webkit-slider-thumb:hover {
  transform: scale(1.2) !important;
}

.range-slider::-moz-range-thumb {
  width: 20px;
  height: 20px;
  background: #fff !important;
  border: 3px solid #10b981 !important;
  border-radius: 50% !important;
  cursor: pointer;
  box-shadow: 0 0 0 4px rgba(16, 185, 129, 0.15) !important;
}

body.light .range-slider {
  background: linear-gradient(to right, #059669 0%, #059669 var(--fill, 50%), 
    rgba(15, 23, 42, 0.08) var(--fill, 50%), rgba(15, 23, 42, 0.08) 100%) !important;
}

body.light .range-slider::-webkit-slider-thumb {
  border-color: #059669 !important;
  box-shadow: 0 0 0 4px rgba(5, 150, 105, 0.1), 0 2px 6px rgba(0, 0, 0, 0.1) !important;
}

body.light .range-slider::-moz-range-thumb {
  border-color: #059669 !important;
  box-shadow: 0 0 0 4px rgba(5, 150, 105, 0.1) !important;
}

.range-labels {
  display: flex;
  justify-content: space-between;
  margin-top: 10px;
  font-size: 11px;
  font-weight: 600;
  color: var(--text-3);
}

/* ── Print Styles ── */
@media print {
  body {
    background: #fff !important;
    color: #000 !important;
  }
  .page-border {
    border: none !important;
    padding: 0 !important;
  }
  .cycle-card {
    border: 1px solid #ddd !important;
    background: #fff !important;
    color: #000 !important;
    break-inside: avoid;
  }
  .cycle-card.recommended {
    border: 2px solid #065f46 !important;
  }
  .badge-optimal, .badge-acceptable, .badge-insufficient, .badge-severe {
    border: 1px solid #ccc !important;
    color: #000 !important;
    background: none !important;
  }
}

/* ── Form Inputs & Layout Groups ── */
.input-group {
  margin-bottom: 24px;
}

.input-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 12px;
  gap: 12px;
}

.input-header label {
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 1px;
  text-transform: uppercase;
  color: var(--text-3);
  flex: 1;
}

body.light .input-header label {
  color: #64748b;
}

/* ── Value Badges ── */
.value-badge {
  background: var(--tool-emerald-soft);
  color: var(--tool-emerald);
  border: 1px solid var(--tool-emerald-glow);
  padding: 5px 13px;
  border-radius: 20px;
  font-family: 'Outfit', sans-serif;
  font-size: 13px;
  font-weight: 700;
  white-space: nowrap;
  font-variant-numeric: tabular-nums;
  min-width: 80px;
  text-align: center;
}

body.light .value-badge {
  background: rgba(5, 150, 105, 0.08);
  color: #059669;
  border-color: rgba(5, 150, 105, 0.2);
}

/* ── History Panel & Controls ── */
.history-controls {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 16px;
  flex-wrap: wrap;
  gap: 12px;
}

.history-average-card {
  font-size: 13px;
  color: var(--text-2);
}

.history-average-card b {
  color: var(--text);
  font-family: 'Outfit', sans-serif;
}

body.light .history-average-card {
  color: #475569;
}

body.light .history-average-card b {
  color: #0f172a;
}

.history-actions {
  display: flex;
  gap: 8px;
}

/* ── History Table ── */
.table-wrap {
  width: 100%;
  overflow-x: auto;
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: 16px;
  background: rgba(255, 255, 255, 0.02);
  overflow: hidden;
}

body.light .table-wrap {
  border-color: rgba(0, 0, 0, 0.08);
  background: rgba(0, 0, 0, 0.01);
}

.history-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
  text-align: left;
}

.history-table th {
  padding: 12px 16px;
  background: rgba(255, 255, 255, 0.01);
  border-bottom: 1px solid rgba(255, 255, 255, 0.08);
  color: var(--text-3);
  font-size: 10px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.8px;
}

body.light .history-table th {
  background: rgba(0, 0, 0, 0.01);
  border-bottom-color: rgba(0, 0, 0, 0.08);
  color: #64748b;
}

.history-table td {
  padding: 16px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.04);
  color: var(--text-2);
  vertical-align: middle;
}

body.light .history-table td {
  border-bottom-color: rgba(0, 0, 0, 0.04);
  color: #334155;
}

.history-table tbody tr:last-child td {
  border-bottom: none;
}

.history-table tr:hover td {
  background: rgba(255, 255, 255, 0.025);
}

body.light .history-table tr:hover td {
  background: rgba(0, 0, 0, 0.01);
}

.history-table td strong {
  color: var(--text);
  font-family: 'Outfit', sans-serif;
}

body.light .history-table td strong {
  color: #0f172a;
}

.delete-entry-btn {
  background: transparent;
  border: none;
  color: var(--text-3);
  font-size: 14px;
  cursor: pointer;
  padding: 4px 8px;
  border-radius: 4px;
  transition: all 0.2s ease;
}

.delete-entry-btn:hover {
  color: #ef4444;
  background: rgba(239, 68, 68, 0.1);
}

body.light .delete-entry-btn {
  color: #64748b;
}

body.light .delete-entry-btn:hover {
  color: #dc2626;
  background: rgba(220, 38, 38, 0.08);
}

/* ── Tooltips ── */
.tooltip-wrap {
  display: inline-flex;
  width: 16px;
  height: 16px;
  background: rgba(255, 255, 255, 0.08);
  border: 1px solid rgba(255, 255, 255, 0.12);
  border-radius: 50%;
  font-size: 10px;
  font-weight: 700;
  align-items: center;
  justify-content: center;
  cursor: help;
  position: relative;
  color: var(--text-3);
  margin-left: 6px;
  vertical-align: middle;
}

.tooltip-text {
  visibility: hidden;
  width: 220px;
  background: rgba(14, 14, 24, 0.98);
  border: 1px solid rgba(255, 255, 255, 0.12);
  color: var(--text-2);
  text-align: center;
  padding: 8px 12px;
  border-radius: 8px;
  position: absolute;
  z-index: 100;
  bottom: calc(100% + 8px);
  left: 50%;
  transform: translateX(-50%) translateY(4px);
  opacity: 0;
  transition: opacity 0.2s, transform 0.2s;
  font-size: 11px;
  line-height: 1.4;
  pointer-events: none;
  box-shadow: 0 4px 20px rgba(0, 0, 0, 0.4);
  font-weight: normal;
  text-transform: none;
  letter-spacing: normal;
}

.tooltip-wrap:hover .tooltip-text {
  visibility: visible;
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}

body.light .tooltip-wrap {
  background: rgba(0, 0, 0, 0.04);
  border-color: rgba(0, 0, 0, 0.08);
  color: #64748b;
}

body.light .tooltip-text {
  background: #ffffff;
  border-color: rgba(0, 0, 0, 0.08);
  color: #334155;
  box-shadow: 0 4px 15px rgba(0, 0, 0, 0.08);
}

/* ── Responsive Overrides ── */
@media (max-width: 640px) {
  .container {
    padding: 0 16px 80px;
  }
}
