/* Reset and base styles */
* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

html,
body {
  height: 100%;
  width: 100%;
  background: linear-gradient(135deg, #0f0c29 0%, #1a1a2e 50%, #16213e 100%);
  background-attachment: fixed;
  color: #ffffff;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto,
    "Helvetica Neue", Arial, sans-serif;
  overflow: hidden;
  position: fixed;
  top: 0;
  left: 0;
}

/* Main container */
.app-container {
  display: flex;
  flex-direction: column;
  height: 100vh;
  height: 100dvh; /* mobile browser chrome-safe viewport */
  width: 100vw;
  position: relative;
  animation: fadeIn 0.5s ease-in;
}

@keyframes fadeIn {
  from {
    opacity: 0;
    transform: translateY(20px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

/* Top bar */
.top-bar {
  background: rgba(45, 45, 45, 0.85);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  border-bottom: 1px solid rgba(255, 255, 255, 0.06);
  padding: 6px 14px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-shrink: 0;
  min-height: 46px;
  z-index: 100;
  transition: all 0.3s ease;
}

.dashboard-title {
  font-size: 15px;
  font-weight: 600;
  background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
  flex: 1;
  min-width: 0;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  margin-right: 15px;
  text-shadow: 0 2px 10px rgba(102, 126, 234, 0.3);
  animation: titleGlow 3s ease-in-out infinite;
}

@keyframes titleGlow {
  0%,
  100% {
    filter: brightness(1);
  }
  50% {
    filter: brightness(1.2);
  }
}

.toolbar {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-shrink: 0;
}

.person-toggles {
  display: flex;
  gap: 6px;
  align-items: center;
}

.person-toggle {
  padding: 6px 12px;
  border: 1px solid rgba(255, 255, 255, 0.1);
  border-radius: 8px;
  background: rgba(61, 61, 61, 0.5);
  backdrop-filter: blur(10px);
  color: #ffffff;
  cursor: pointer;
  font-size: 11px;
  transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
  white-space: nowrap;
  min-height: 32px;
  font-weight: 500;
  position: relative;
  overflow: hidden;
}

.person-toggle::before {
  content: "";
  position: absolute;
  top: 0;
  left: -100%;
  width: 100%;
  height: 100%;
  background: linear-gradient(
    90deg,
    transparent,
    rgba(255, 255, 255, 0.2),
    transparent
  );
  transition: left 0.5s;
}

.person-toggle:hover::before {
  left: 100%;
}

.person-toggle.active {
  background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  border-color: transparent;
  color: #ffffff;
  box-shadow: 0 4px 15px rgba(102, 126, 234, 0.4);
  transform: translateY(-2px);
}

.person-toggle:hover {
  background: rgba(77, 77, 77, 0.7);
  border-color: rgba(255, 255, 255, 0.2);
  transform: translateY(-2px);
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
}

.person-toggle.active:hover {
  background: linear-gradient(135deg, #7b8fea 0%, #865bc2 100%);
  box-shadow: 0 6px 20px rgba(102, 126, 234, 0.6);
}

.toolbar button {
  padding: 8px 14px;
  border: 1px solid rgba(255, 255, 255, 0.1);
  border-radius: 8px;
  background: rgba(61, 61, 61, 0.5);
  backdrop-filter: blur(10px);
  color: #ffffff;
  cursor: pointer;
  font-size: 12px;
  font-weight: 500;
  transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
  white-space: nowrap;
  min-height: 36px;
  touch-action: manipulation;
  display: flex;
  align-items: center;
  gap: 6px;
  position: relative;
  overflow: hidden;
}

.toolbar button::after {
  content: "";
  position: absolute;
  inset: 0;
  background: radial-gradient(
    circle at center,
    rgba(255, 255, 255, 0.1),
    transparent
  );
  opacity: 0;
  transition: opacity 0.3s;
}

.toolbar button:hover::after {
  opacity: 1;
}

.toolbar button:hover {
  transform: translateY(-2px);
  box-shadow: 0 4px 12px rgba(88, 101, 242, 0.3);
  border-color: rgba(88, 101, 242, 0.5);
  background: rgba(88, 101, 242, 0.2);
}

.toolbar button:active {
  transform: translateY(0);
  box-shadow: 0 2px 6px rgba(88, 101, 242, 0.2);
}

/* Toolbar separator */
.toolbar-separator {
  color: #555;
  font-size: 18px;
  margin: 0 4px;
  user-select: none;
}

.view-select {
  padding: 8px 12px;
  border: 1px solid #555;
  border-radius: 6px;
  background: #3d3d3d;
  color: #ffffff;
  cursor: pointer;
  font-size: 12px;
  font-weight: 500;
  transition: all 0.2s;
  white-space: nowrap;
  min-height: 36px;
  min-width: 180px;
  appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 12 12'%3E%3Cpath fill='%23ffffff' d='M6 9L1 4h10z'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 8px center;
  padding-right: 32px;
}

.view-select:hover {
  background-color: #4d4d4d;
  border-color: #666;
}

.view-select:focus {
  outline: 2px solid #5865f2;
  outline-offset: 2px;
  border-color: #5865f2;
}

.view-select:disabled {
  opacity: 0.6;
  cursor: not-allowed;
}

.view-select.loading {
  border-color: #66d9ef;
  box-shadow: 0 0 0 2px rgba(102, 217, 239, 0.15);
}

.view-select option {
  background: #2d2d2d;
  color: #ffffff;
  padding: 8px;
}

/* Main content area */
.main-content {
  display: flex;
  flex: 1;
  min-height: 0;
  position: relative;
  background: #1a1a1a;
}

.mobile-panel-backdrop {
  position: fixed;
  inset: 0;
  z-index: 899;
  display: none;
  background: rgba(0, 0, 0, 0.45);
}

.mobile-panel-backdrop.active {
  display: block;
}

/* Legend panel: an overlay drawer on every screen size — the chart owns the
   full width; the drawer is the deep-dive metric list (search, tooltips,
   presets), opened from the Metrics button in the control strip. */
.legend-panel {
  position: fixed;
  top: 0;
  bottom: 0;
  left: 0;
  z-index: 900;
  width: min(84vw, 320px);
  max-height: 100dvh;
  transform: translateX(-105%);
  transition: transform 0.22s ease;
  background: rgba(38, 38, 42, 0.97);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  border-right: 1px solid rgba(255, 255, 255, 0.18);
  display: flex;
  flex-direction: column;
  overflow-y: auto;
  box-shadow: 12px 0 42px rgba(0, 0, 0, 0.55);
}

.legend-panel.mobile-open {
  transform: translateX(0);
}

.legend-header {
  padding: 10px;
  border-bottom: 1px solid #404040;
  background: #2d2d2d;
  position: sticky;
  top: 0;
  z-index: 10;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.legend-title-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.legend-header h3 {
  font-size: 14px;
  font-weight: 600;
  color: #ffffff;
  margin: 0;
}

.metrics-count {
  font-size: 11px;
  color: #888;
  font-weight: 400;
  padding: 2px 6px;
  background: #3d3d3d;
  border-radius: 4px;
}

.legend-search {
  position: relative;
  display: flex;
  align-items: center;
}

.legend-search input {
  width: 100%;
  padding: 6px 28px 6px 8px;
  background: #3d3d3d;
  border: 1px solid #555;
  border-radius: 4px;
  color: #fff;
  font-size: 12px;
  transition: all 0.2s;
}

.legend-search input:focus {
  outline: none;
  border-color: #5865f2;
  background: #454545;
}

.legend-search input::placeholder {
  color: #888;
}

.clear-search-btn {
  position: absolute;
  right: 4px;
  background: none;
  border: none;
  color: #888;
  cursor: pointer;
  padding: 4px 6px;
  font-size: 14px;
  line-height: 1;
  border-radius: 3px;
  transition: all 0.2s;
  display: flex;
  align-items: center;
  justify-content: center;
}

.clear-search-btn:hover {
  color: #fff;
  background: #555;
}

.legend-close-btn {
  width: 28px;
  height: 28px;
  flex: 0 0 28px;
  justify-content: center;
  padding: 0 !important;
}

.legend-content {
  padding: 6px;
}

.legend-item {
  display: flex;
  align-items: center;
  padding: 6px;
  margin: 2px 0;
  border-radius: 6px;
  cursor: pointer;
  transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
  position: relative;
  user-select: none;
  border: 1px solid transparent;
}

.legend-item:hover {
  background: rgba(88, 101, 242, 0.15);
  border-color: rgba(88, 101, 242, 0.3);
  transform: translateX(4px) scale(1.02);
  box-shadow: 0 4px 12px rgba(88, 101, 242, 0.2);
}

.legend-item:focus {
  outline: 2px solid #5865f2;
  outline-offset: -2px;
}

.legend-item:active {
  transform: translateX(1px);
}

/* Enhanced tooltip styles */
.legend-item[title] {
  cursor: help;
}

.legend-item[title]:hover::after {
  content: "i";
  position: absolute;
  right: 8px;
  font-size: 14px;
  opacity: 0.7;
}

.legend-checkbox {
  width: 14px;
  height: 14px;
  border: 2px solid #666;
  border-radius: 3px;
  margin-right: 6px;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.legend-item.checked .legend-checkbox {
  border-color: inherit;
}

.legend-item.checked .legend-checkbox::after {
  content: "x";
  color: white;
  font-size: 12px;
  font-weight: bold;
}

.legend-label {
  font-size: 11.5px;
  line-height: 1.25;
  color: #ffffff;
  flex: 1;
  min-width: 0;
  overflow-wrap: anywhere;
}

.legend-info-btn {
  display: none;
  width: 24px;
  height: 24px;
  flex: 0 0 24px;
  align-items: center;
  justify-content: center;
  border: 1px solid rgba(255, 255, 255, 0.16);
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.06);
  color: #ffffff;
  cursor: pointer;
  font-size: 12px;
  font-weight: 700;
  line-height: 1;
}

/* Chart container */
.chart-container {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-width: 0;
  position: relative;
}

.highlights-panel {
  display: none;
  flex-shrink: 0;
  flex-direction: column;
  gap: 8px;
  overflow: hidden;
  padding: 10px 12px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.08);
  background: #202020;
}

.highlights-panel.has-items {
  display: flex;
}

.highlights-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  min-width: 0;
}

.highlights-heading {
  display: flex;
  flex-direction: column;
  gap: 2px;
  min-width: 120px;
}

.highlights-heading strong {
  font-size: 13px;
  color: #fff;
}

.highlights-heading span {
  font-size: 11px;
  color: #aaa;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.highlight-pills {
  display: flex;
  flex: 1;
  flex-wrap: nowrap;
  gap: 6px;
  min-width: 0;
  overflow-x: auto;
  scrollbar-width: thin;
  padding-bottom: 2px;
}

.highlight-pill {
  flex: 0 0 auto;
  min-width: 108px;
  max-width: 160px;
  padding: 5px 8px;
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-left-width: 3px;
  border-radius: 6px;
  background: #292929;
  color: #d8d8d8;
}

.highlight-pill.high {
  border-left-color: #2ecc71;
}

.highlight-pill.low {
  border-left-color: #e74c3c;
}

.highlight-pill.neutral {
  border-left-color: #9e9e9e;
}

.highlight-pill span,
.highlight-pill strong {
  display: block;
  min-width: 0;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.highlight-pill span {
  display: flex;
  align-items: center;
  gap: 5px;
  font-size: 10px;
  color: #999;
}

.highlight-pill strong {
  margin-top: 2px;
  font-size: 11px;
  font-weight: 650;
  color: #fff;
}

.highlight-dot {
  display: inline-block;
  flex: 0 0 8px;
  width: 8px;
  height: 8px;
  border-radius: 50%;
}

#chart {
  flex: 1;
  min-height: 300px;
  width: 100%;
  background: #1a1a1a;
  touch-action: pan-x pan-y;
  -webkit-user-select: none;
  user-select: none;
}

.forecast-loading {
  position: fixed;
  inset: 0;
  z-index: 9999;
  display: none;
  align-items: center;
  justify-content: center;
  background: #000000;
  cursor: wait;
}

.forecast-loading.active {
  display: flex;
}

.forecast-loading-box {
  min-width: 260px;
  max-width: min(420px, calc(100vw - 48px));
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 18px 20px;
  border: 1px solid rgba(255, 255, 255, 0.18);
  border-radius: 8px;
  background: #0c0c0f;
  box-shadow: 0 0 48px rgba(102, 217, 239, 0.14);
}

.forecast-loading-spinner {
  width: 34px;
  height: 34px;
  flex: 0 0 34px;
  border: 3px solid rgba(255, 255, 255, 0.18);
  border-top-color: #66d9ef;
  border-right-color: #2ecc71;
  border-radius: 50%;
  animation: spin 0.85s linear infinite;
}

.forecast-loading-title {
  font-size: 14px;
  font-weight: 650;
  color: #ffffff;
}

.forecast-loading-detail {
  margin-top: 4px;
  font-size: 12px;
  color: #b8bdc7;
}

.forecast-loading-bar {
  position: absolute;
  left: 0;
  right: 0;
  top: 0;
  height: 3px;
  overflow: hidden;
  background: rgba(255, 255, 255, 0.08);
}

.forecast-loading-bar::before {
  content: "";
  position: absolute;
  top: 0;
  left: -35%;
  width: 35%;
  height: 100%;
  background: linear-gradient(90deg, #66d9ef, #2ecc71);
  animation: loadingBar 1.1s ease-in-out infinite;
}

.metric-info-popover {
  position: fixed;
  inset: 0;
  z-index: 2200;
  display: none;
  align-items: center;
  justify-content: center;
  padding: 18px;
  background: rgba(0, 0, 0, 0.48);
}

.metric-info-popover.open {
  display: flex;
}

.metric-info-box {
  width: min(420px, calc(100vw - 36px));
  border: 1px solid rgba(255, 255, 255, 0.16);
  border-radius: 10px;
  background: #24262c;
  box-shadow: 0 22px 72px rgba(0, 0, 0, 0.72);
  padding: 16px;
}

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

.metric-info-header h2 {
  margin: 0;
  font-size: 16px;
  color: #ffffff;
}

.metric-info-header button {
  width: 32px;
  height: 32px;
  flex: 0 0 32px;
  border: 1px solid rgba(255, 255, 255, 0.16);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.08);
  color: #ffffff;
  cursor: pointer;
}

.metric-info-box p {
  margin: 0;
  color: #d8dde7;
  font-size: 13px;
  line-height: 1.45;
  white-space: pre-line;
}

body.is-waiting {
  cursor: wait;
}

body.is-waiting * {
  cursor: wait !important;
}

/* Loading indicator (boot screen only — #view-select also gets a "loading"
   class during view switches, which must not match this) */
#loading {
  display: flex;
  align-items: center;
  justify-content: center;
  height: 100vh;
  font-size: 16px;
  color: #ffffff;
  padding: 20px;
  text-align: center;
  flex-direction: column;
  gap: 15px;
  background: linear-gradient(135deg, #0f0c29 0%, #1a1a2e 50%, #16213e 100%);
  background-attachment: fixed;
}

.loading-spinner {
  width: 60px;
  height: 60px;
  border: 4px solid rgba(102, 126, 234, 0.2);
  border-top: 4px solid #667eea;
  border-right: 4px solid #764ba2;
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
  box-shadow: 0 0 20px rgba(102, 126, 234, 0.5);
}

.loading-details {
  font-size: 13px;
  color: #888;
  margin-top: 5px;
  font-style: italic;
}

@keyframes spin {
  0% {
    transform: rotate(0deg);
  }
  100% {
    transform: rotate(360deg);
  }
}

@keyframes loadingBar {
  0% {
    left: -35%;
  }
  50% {
    left: 45%;
  }
  100% {
    left: 100%;
  }
}

/* Error message */
.error-message {
  background: #2d1b1b;
  border: 2px solid #5c2e2e;
  border-radius: 8px;
  padding: 24px;
  margin: 20px;
  color: #ff6b6b;
  max-width: 600px;
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.3);
}

.error-message h3 {
  margin-bottom: 12px;
  font-size: 18px;
  color: #ff8888;
}

.error-message p {
  margin-bottom: 16px;
  line-height: 1.5;
}

.reload-button {
  padding: 10px 20px;
  background: #5865f2;
  color: white;
  border: none;
  border-radius: 6px;
  cursor: pointer;
  font-size: 14px;
  font-weight: 600;
  transition: all 0.2s;
}

.reload-button:hover {
  background: #6b7cfb;
  transform: translateY(-1px);
}

/* Status notifications */
.status-notification {
  position: fixed;
  top: 75px;
  right: 20px;
  background: rgba(45, 45, 45, 0.98);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  color: white;
  padding: 14px 20px;
  border-radius: 12px;
  border: 1px solid rgba(102, 126, 234, 0.5);
  font-size: 13px;
  font-weight: 500;
  z-index: 2147483647; /* above the tracker/natal modals so toasts stay visible */
  display: none;
  max-width: 450px;
  max-height: 80vh;
  overflow-y: auto;
  text-align: left;
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.6),
    0 0 0 1px rgba(255, 255, 255, 0.1) inset;
  animation: slideInBounce 0.5s cubic-bezier(0.68, -0.55, 0.265, 1.55);
}

@keyframes slideInBounce {
  0% {
    transform: translateX(400px) scale(0.8);
    opacity: 0;
  }
  60% {
    transform: translateX(-10px) scale(1.05);
    opacity: 1;
  }
  100% {
    transform: translateX(0) scale(1);
  }
}

.status-notification.success {
  background: rgba(45, 45, 45, 0.98);
  border-color: rgba(67, 181, 129, 0.7);
  box-shadow: 0 8px 32px rgba(67, 181, 129, 0.3),
    0 0 0 1px rgba(67, 181, 129, 0.2) inset;
}

.status-notification.error {
  background: rgba(45, 45, 45, 0.98);
  border-color: rgba(240, 62, 62, 0.7);
  box-shadow: 0 8px 32px rgba(240, 62, 62, 0.3),
    0 0 0 1px rgba(240, 62, 62, 0.2) inset;
}

.status-notification.warning {
  background: rgba(45, 45, 45, 0.98);
  border-color: rgba(243, 156, 18, 0.7);
  box-shadow: 0 8px 32px rgba(243, 156, 18, 0.3),
    0 0 0 1px rgba(243, 156, 18, 0.2) inset;
}

/* Tracker entry panel */
.tracker-entry-panel {
  position: fixed;
  inset: 0;
  z-index: 2147483647;
  display: none;
  align-items: center;
  justify-content: center;
  width: 100vw;
  /* dvh (not vh) so the panel tracks the *visible* viewport — vh is the tall
     chrome-hidden height, which lets the phone's nav/URL bar cover the bottom
     of the form. Extra bottom padding clears the home-indicator/gesture bar. */
  height: 100dvh;
  box-sizing: border-box;
  padding: 28px;
  padding-bottom: calc(28px + env(safe-area-inset-bottom, 0px));
  overflow: auto;
  border: 0;
  border-radius: 0;
  background: rgba(7, 9, 13, 0.82);
  color: #ffffff;
  box-shadow: none;
  backdrop-filter: blur(7px);
}

.tracker-entry-panel.open {
  display: flex !important;
  visibility: visible !important;
  opacity: 1 !important;
  pointer-events: auto;
}

.tracker-entry-form {
  display: flex;
  box-sizing: border-box;
  width: min(540px, calc(100vw - 32px));
  max-height: calc(100dvh - 56px - env(safe-area-inset-bottom, 0px));
  flex-direction: column;
  gap: 18px;
  overflow-y: auto;
  border: 1px solid rgba(255, 255, 255, 0.16);
  border-radius: 14px;
  background: #24262c;
  box-shadow: 0 28px 84px rgba(0, 0, 0, 0.78);
  padding: 24px;
}

.tracker-entry-header,
.tracker-date-row,
.tracker-checkbox-row {
  display: flex;
  align-items: center;
  gap: 10px;
}

.tracker-entry-header {
  justify-content: space-between;
  gap: 18px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.1);
  padding-bottom: 16px;
}

.tracker-entry-header h2 {
  margin: 0;
  color: #f4f7fb;
  font-size: 22px;
  font-weight: 750;
  line-height: 1.2;
}

.tracker-entry-header p,
.tracker-entry-cycle-day {
  margin: 4px 0 0;
  color: #aab1bf;
  font-size: 12px;
  line-height: 1.35;
}

.tracker-entry-icon-btn {
  width: 40px;
  height: 40px;
  flex: 0 0 40px;
  border: 1px solid rgba(255, 255, 255, 0.14);
  border-radius: 10px;
  background: rgba(255, 255, 255, 0.07);
  color: #ffffff;
  cursor: pointer;
  font-size: 15px;
  font-weight: 700;
  line-height: 1;
}

.tracker-entry-icon-btn:hover:not(:disabled) {
  border-color: rgba(102, 217, 239, 0.45);
  background: rgba(102, 217, 239, 0.14);
}

.tracker-entry-icon-btn:disabled {
  opacity: 0.35;
  cursor: not-allowed;
}

.tracker-date-display,
.tracker-field {
  display: flex;
  min-width: 0;
  flex: 1;
  flex-direction: column;
  gap: 8px;
}

.tracker-date-display label,
.tracker-field span,
.tracker-checkbox-row span {
  color: #d8dde7;
  font-size: 13px;
  font-weight: 600;
}

.tracker-date-row {
  align-items: flex-end;
}

.tracker-date-display input,
.tracker-field textarea {
  box-sizing: border-box;
  width: 100%;
  border: 1px solid rgba(255, 255, 255, 0.16);
  border-radius: 10px;
  background: #17191f;
  color: #ffffff;
  font: inherit;
  outline: none;
  transition: border-color 0.2s, box-shadow 0.2s, background 0.2s;
}

.tracker-date-display input:focus,
.tracker-field textarea:focus {
  border-color: rgba(102, 217, 239, 0.64);
  background: #151820;
  box-shadow: 0 0 0 3px rgba(102, 217, 239, 0.12);
}

.tracker-date-display input {
  min-height: 42px;
  padding: 9px 12px;
}

.tracker-field textarea {
  resize: vertical;
  min-height: 132px;
  padding: 12px;
  line-height: 1.45;
}

.tracker-score-field {
  border: 1px solid rgba(255, 255, 255, 0.1);
  border-radius: 12px;
  background: rgba(255, 255, 255, 0.04);
  padding: 14px;
}

.tracker-score-label {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.tracker-score-label strong {
  min-width: 46px;
  border: 1px solid rgba(102, 217, 239, 0.35);
  border-radius: 999px;
  background: rgba(102, 217, 239, 0.12);
  color: #d9f9ff;
  font-size: 13px;
  line-height: 1;
  padding: 7px 10px;
  text-align: center;
}

.tracker-field input[type="range"] {
  width: 100%;
  accent-color: #66d9ef;
  cursor: pointer;
}

.tracker-checkbox-row {
  width: 100%;
  box-sizing: border-box;
  justify-content: flex-start;
  border: 1px solid rgba(233, 30, 99, 0.2);
  border-radius: 12px;
  background: rgba(233, 30, 99, 0.08);
  padding: 12px 14px;
  cursor: pointer;
}

.tracker-checkbox-row input {
  width: 18px;
  height: 18px;
  accent-color: #e91e63;
}

.tracker-entry-cycle-day {
  border: 1px solid rgba(255, 255, 255, 0.1);
  border-radius: 10px;
  background: rgba(255, 255, 255, 0.04);
  padding: 10px 12px;
}

.tracker-entry-submit {
  min-height: 46px;
  border: 1px solid rgba(102, 217, 239, 0.55);
  border-radius: 10px;
  background: #276f82;
  color: #ffffff;
  cursor: pointer;
  font-size: 14px;
  font-weight: 700;
  letter-spacing: 0;
}

.tracker-entry-submit:hover:not(:disabled) {
  background: #2f8298;
}

.tracker-entry-submit:disabled {
  opacity: 0.6;
  cursor: wait;
}

@media (max-width: 560px) {
  .tracker-entry-panel {
    align-items: flex-start;
    padding: 14px;
    padding-bottom: calc(14px + env(safe-area-inset-bottom, 0px));
  }

  .tracker-entry-form {
    width: 100%;
    max-height: calc(100dvh - 28px - env(safe-area-inset-bottom, 0px));
    padding: 16px;
    /* Extra room under the last control so the Save button never sits flush
       against (or behind) the phone's bottom bar. */
    padding-bottom: calc(16px + env(safe-area-inset-bottom, 0px));
  }
}

/* Mobile styles */
@media (max-width: 768px) {
  .main-content {
    display: block;
  }

  .top-bar {
    padding: 5px 8px;
    min-height: 42px;
    gap: 6px;
  }

  .dashboard-title {
    font-size: 12px;
    margin-right: 8px;
  }

  .toolbar-primary {
    gap: 4px;
  }

  .toolbar button {
    padding: 5px 8px;
    font-size: 11px;
    min-height: 30px;
    border-radius: 6px;
  }

  .toolbar input {
    width: 120px;
    padding: 6px 8px;
    font-size: 12px;
    min-height: 32px;
  }

  .view-select {
    flex: 1 1 132px;
    min-width: 132px;
    font-size: 11px;
    padding: 5px 26px 5px 8px;
    min-height: 30px;
    background-position: right 6px center;
  }

  .status-notification {
    top: 65px;
    right: 10px;
    left: 10px;
    max-width: none;
    font-size: 12px;
  }

  .person-toggles {
    flex-wrap: nowrap;
    gap: 4px;
  }

  .person-toggle {
    width: 30px;
    min-width: 30px;
    justify-content: center;
    padding: 4px 0;
    font-size: 10px;
    min-height: 30px;
  }

  .legend-header {
    padding: 8px;
  }

  .legend-content {
    padding: 4px;
  }

  .legend-item {
    padding: 6px;
    margin: 2px 0;
  }

  .legend-info-btn {
    display: inline-flex;
  }

  #chart {
    height: 100%;
    min-height: 320px;
  }

  .highlights-panel {
    padding: 6px 8px;
    gap: 4px;
  }

  .highlights-heading span {
    display: none;
  }

  .highlights-top {
    align-items: stretch;
    flex-direction: column;
    gap: 6px;
  }

  .chart-container {
    height: 100%;
  }

  .toolbar-separator {
    display: none;
  }

  .legend-search input {
    font-size: 11px;
    padding: 5px 24px 5px 6px;
  }

  .metrics-count {
    font-size: 10px;
    padding: 2px 4px;
  }

}

@media (max-width: 480px) {
  .dashboard-title {
    font-size: 12px;
  }

  .toolbar button {
    padding: 5px 7px;
    font-size: 10px;
    min-height: 28px;
  }

  .toolbar input {
    width: 100px;
    font-size: 11px;
  }

  .view-select {
    flex-basis: 116px;
    min-width: 116px;
    font-size: 10px;
    padding: 5px 24px 5px 8px;
    min-height: 28px;
  }

  .legend-panel {
    width: min(88vw, 300px);
  }

  .legend-header h3 {
    font-size: 12px;
  }

  .legend-item {
    padding: 6px;
  }

  .legend-label {
    font-size: 11px;
  }

  .toolbar {
    gap: 4px;
  }

  .chart-container {
    height: 100%;
  }
}

/* Custom Scrollbar Styling */
::-webkit-scrollbar {
  width: 8px;
  height: 8px;
}

::-webkit-scrollbar-track {
  background: rgba(0, 0, 0, 0.2);
  border-radius: 4px;
}

::-webkit-scrollbar-thumb {
  background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  border-radius: 4px;
  transition: all 0.3s;
}

::-webkit-scrollbar-thumb:hover {
  background: linear-gradient(135deg, #7b8fea 0%, #865bc2 100%);
  box-shadow: 0 0 6px rgba(102, 126, 234, 0.6);
}

/* Enhanced Chart Container */
.chart-container {
  position: relative;
}

.chart-container::before {
  content: "";
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  height: 1px;
  background: linear-gradient(
    90deg,
    transparent,
    rgba(102, 126, 234, 0.5),
    transparent
  );
  animation: shimmer 3s ease-in-out infinite;
}

@keyframes shimmer {
  0%,
  100% {
    opacity: 0.3;
  }
  50% {
    opacity: 1;
  }
}

/* Enhanced Legend Header */
.legend-header {
  background: linear-gradient(
    180deg,
    rgba(45, 45, 45, 0.95) 0%,
    rgba(45, 45, 45, 0.85) 100%
  );
}

/* Enhanced Metrics Count Badge */
.metrics-count {
  background: linear-gradient(
    135deg,
    rgba(102, 126, 234, 0.3),
    rgba(118, 75, 162, 0.3)
  );
  border: 1px solid rgba(102, 126, 234, 0.5);
}

/* Enhanced View Select — background-color (not the `background` shorthand)
   so the custom SVG caret set earlier is not wiped out. */
.view-select {
  background-color: rgba(61, 61, 61, 0.5);
  backdrop-filter: blur(10px);
  border: 1px solid rgba(255, 255, 255, 0.1);
  transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

.view-select:hover {
  background-color: rgba(88, 101, 242, 0.2);
  border-color: rgba(88, 101, 242, 0.5);
  box-shadow: 0 4px 12px rgba(88, 101, 242, 0.3);
}

/* Enhanced Input Fields */
.legend-search input {
  background: rgba(61, 61, 61, 0.5);
  backdrop-filter: blur(10px);
  border: 1px solid rgba(255, 255, 255, 0.1);
  transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

.legend-search input:focus {
  background: rgba(88, 101, 242, 0.15);
  border-color: rgba(102, 126, 234, 0.5);
  box-shadow: 0 0 0 3px rgba(102, 126, 234, 0.1);
}

/* Enhanced focus states for accessibility */
button:focus-visible,
.person-toggle:focus-visible,
.legend-item:focus-visible {
  outline: 2px solid #667eea;
  outline-offset: 2px;
}

/* Smooth transitions for all interactive elements */
button,
.person-toggle,
.legend-item,
input,
select {
  transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

/* Fix iOS safari viewport issues */
@supports (-webkit-touch-callout: none) {
  body {
    height: -webkit-fill-available;
  }

  .app-container {
    height: -webkit-fill-available;
  }
}

/* =====================================
   Overlay toggle on-state + dasha ribbon
   ===================================== */
.toolbar button.active {
  background: rgba(88, 101, 242, 0.28);
  border-color: rgba(88, 101, 242, 0.7);
  color: #dfe3ff;
}

.dasha-ribbon {
  flex-shrink: 0;
  width: 100%;
  height: 0;
  background: #161616;
  border-top: 1px solid rgba(255, 255, 255, 0.08);
}

.dasha-caption {
  display: none;
  flex-shrink: 0;
  padding: 2px 12px 4px;
  font-size: 11px;
  line-height: 1.5;
  color: #9aa3b2;
  background: #161616;
}
.dasha-caption > summary {
  cursor: pointer;
  padding: 3px 0;
  color: #8b93a3;
  list-style: none;
  user-select: none;
}
.dasha-caption > summary::-webkit-details-marker {
  display: none;
}
.dasha-caption > summary::before {
  content: "▸ ";
  opacity: 0.7;
}
.dasha-caption[open] > summary::before {
  content: "▾ ";
}
.dasha-caption-body {
  padding-bottom: 4px;
}
.dasha-caption b {
  color: #c7cedb;
}
.dasha-key {
  font-weight: 600;
  white-space: nowrap;
}
.dasha-key-benefic {
  color: #3fb950;
}
.dasha-key-malefic {
  color: #e0533d;
}

/* =====================================
   Natal (birth chart) panel
   ===================================== */
.natal-panel {
  display: none;
  position: fixed;
  inset: 0;
  z-index: 2147483646;
  background: rgba(7, 9, 13, 0.82);
  padding: 24px;
  align-items: center;
  justify-content: center;
}
.natal-panel.open {
  display: flex;
}
.natal-box {
  display: flex;
  flex-direction: column;
  width: min(960px, calc(100vw - 32px));
  max-height: calc(100vh - 48px);
  overflow: hidden;
  background: #1f2127;
  border: 1px solid rgba(255, 255, 255, 0.16);
  border-radius: 14px;
  box-shadow: 0 28px 84px rgba(0, 0, 0, 0.78);
}
.natal-header {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 16px 20px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.1);
}
.natal-header h2 {
  margin: 0;
  font-size: 18px;
  color: #fff;
}
.natal-person-tabs {
  display: flex;
  gap: 6px;
  flex: 1;
}
.natal-tab {
  padding: 6px 14px;
  border: 1px solid rgba(255, 255, 255, 0.12);
  border-radius: 8px;
  background: rgba(61, 61, 61, 0.5);
  color: #ddd;
  cursor: pointer;
  font-size: 12px;
}
.natal-tab.active {
  background: rgba(88, 101, 242, 0.3);
  border-color: rgba(88, 101, 242, 0.7);
  color: #fff;
}
.natal-close {
  border: 1px solid rgba(255, 255, 255, 0.12);
  border-radius: 8px;
  background: rgba(61, 61, 61, 0.5);
  color: #fff;
  cursor: pointer;
  width: 32px;
  height: 32px;
  font-size: 16px;
  flex: 0 0 auto;
}
.natal-body {
  padding: 20px;
  overflow: auto;
}
.natal-loading {
  color: #aaa;
  text-align: center;
  padding: 40px;
}
.natal-charts {
  display: flex;
  gap: 18px;
  flex-wrap: wrap;
  justify-content: center;
}

.natal-guide {
  margin: 0 0 18px;
  border: 1px solid rgba(255, 255, 255, 0.12);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.03);
}
.natal-guide > summary {
  cursor: pointer;
  padding: 10px 14px;
  font-size: 13px;
  font-weight: 600;
  color: #c7cedb;
  list-style: none;
}
.natal-guide > summary::-webkit-details-marker {
  display: none;
}
.natal-guide > summary::before {
  content: "ⓘ ";
  opacity: 0.7;
}
.natal-guide[open] > summary {
  border-bottom: 1px solid rgba(255, 255, 255, 0.1);
}
.natal-guide-body {
  padding: 12px 16px 4px;
  font-size: 12.5px;
  line-height: 1.6;
  color: #b6bdca;
}
.natal-guide-body p {
  margin: 0 0 10px;
}
.natal-guide-body ul {
  margin: 0 0 12px;
  padding-left: 20px;
}
.natal-guide-body li {
  margin-bottom: 4px;
}
.natal-guide-body b {
  color: #dfe4ec;
}
.natal-guide-grahas {
  columns: 2;
  column-gap: 24px;
}
@media (max-width: 768px) {
  .natal-guide-grahas {
    columns: 1;
  }
}

.south-indian {
  display: grid;
  grid-template-columns: repeat(4, 86px);
  grid-template-rows: repeat(4, 86px);
  gap: 2px;
  background: rgba(255, 255, 255, 0.12);
  border: 1px solid rgba(255, 255, 255, 0.18);
  padding: 2px;
  border-radius: 6px;
}
.sic-cell {
  background: #15171c;
  padding: 4px 5px;
  display: flex;
  flex-direction: column;
  gap: 3px;
  overflow: hidden;
}
.sic-asc {
  background: #1d2535;
  box-shadow: inset 0 0 0 1px rgba(120, 150, 255, 0.55);
}
.sic-center {
  background: #11141a;
  display: flex;
  align-items: center;
  justify-content: center;
  text-align: center;
  color: #8a93a6;
  font-size: 13px;
  font-weight: 600;
  line-height: 1.3;
}
.sic-sign {
  font-size: 9px;
  letter-spacing: 0.4px;
  color: #6e7686;
  text-transform: uppercase;
}
.sic-grahas {
  display: flex;
  flex-wrap: wrap;
  gap: 2px 5px;
  font-size: 12px;
  font-weight: 600;
}
.sic-graha sup {
  font-size: 7px;
  opacity: 0.8;
}

.natal-meta {
  margin-top: 20px;
}
.natal-summary {
  display: flex;
  flex-wrap: wrap;
  gap: 8px 28px;
  color: #d6d9e0;
  font-size: 13px;
  margin-bottom: 14px;
}
.natal-k {
  color: #7f879a;
  margin-right: 6px;
  text-transform: uppercase;
  font-size: 10px;
  letter-spacing: 0.5px;
}
.natal-sub {
  color: #7f879a;
  font-size: 11px;
}
.natal-tables {
  display: flex;
  gap: 24px;
  flex-wrap: wrap;
}
.natal-table-wrap {
  flex: 1;
  min-width: 240px;
}
.natal-table-wrap h4 {
  margin: 0 0 8px;
  color: #aab;
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}
.natal-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 12px;
  color: #cfd3db;
}
.natal-table th {
  text-align: left;
  color: #7f879a;
  font-weight: 600;
  padding: 4px 8px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.1);
}
.natal-table td {
  padding: 4px 8px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.05);
}
.natal-dasha-current {
  background: rgba(88, 101, 242, 0.16);
}
.natal-dot {
  display: inline-block;
  width: 9px;
  height: 9px;
  border-radius: 50%;
  margin-right: 7px;
  vertical-align: middle;
}

@media (max-width: 640px) {
  .south-indian {
    grid-template-columns: repeat(4, 70px);
    grid-template-rows: repeat(4, 70px);
  }
}

/* =====================================
   AI day review panel + accuracy rating
   ===================================== */
.ai-review-box {
  width: min(760px, calc(100vw - 32px));
}
.ai-review-date-nav {
  flex: 1;
  display: flex;
  align-items: center;
  gap: 10px;
}
.ai-review-date {
  color: #d6dbe4;
  font-size: 13px;
  min-width: 86px;
  text-align: center;
}
.ai-review-date-nav .tracker-entry-icon-btn:disabled {
  opacity: 0.35;
  cursor: default;
}
/* Regenerate icon button, sits just left of the close button in the header */
.ai-review-generate-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 32px;
  height: 32px;
  flex: 0 0 auto;
  border: 1px solid rgba(88, 101, 242, 0.7);
  border-radius: 8px;
  background: rgba(88, 101, 242, 0.3);
  color: #fff;
  cursor: pointer;
}
.ai-review-generate-icon:hover {
  background: rgba(88, 101, 242, 0.5);
}
.ai-review-generate-icon:disabled {
  opacity: 0.55;
  cursor: wait;
}

.ai-review-delete-icon {
  color: #e98383;
}

.ai-review-delete-icon:hover:not(:disabled) {
  background: rgba(233, 83, 83, 0.14);
}
.ai-review-generate-icon.spinning svg {
  animation: ai-spin 0.9s linear infinite;
}
@keyframes ai-spin {
  to {
    transform: rotate(360deg);
  }
}
/* Version pills (v1 / v2 / v3 ...) in the header */
.ai-review-versions {
  display: flex;
  gap: 4px;
  flex-wrap: wrap;
}
.ai-review-version {
  min-width: 30px;
  padding: 4px 8px;
  border: 1px solid rgba(255, 255, 255, 0.12);
  border-radius: 7px;
  background: rgba(61, 61, 61, 0.5);
  color: #c7cedb;
  cursor: pointer;
  font-size: 11.5px;
}
.ai-review-version.active {
  background: rgba(88, 101, 242, 0.3);
  border-color: rgba(88, 101, 242, 0.7);
  color: #fff;
}
/* Running "AI spend $x.xx" chip in the review top bar; breakdown on hover. */
.ai-cost-total {
  margin-left: auto;
  font-size: 11px;
  color: #9aa3b5;
  white-space: nowrap;
  cursor: help;
  flex: 0 0 auto;
}
/* Chart / Raw tab strip above the body */
.ai-review-topbar {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 12px;
  min-height: 20px;
}
.ai-review-tabs {
  display: flex;
  gap: 6px;
}
.ai-review-tabs[hidden] {
  display: none;
}
.ai-review-tab {
  padding: 6px 16px;
  border: 1px solid rgba(255, 255, 255, 0.12);
  border-radius: 8px;
  background: rgba(61, 61, 61, 0.5);
  color: #ddd;
  cursor: pointer;
  font-size: 12px;
}
.ai-review-tab.active {
  background: rgba(88, 101, 242, 0.3);
  border-color: rgba(88, 101, 242, 0.7);
  color: #fff;
}
.ai-review-status {
  color: #9aa3b2;
  font-size: 12px;
}
.ai-review-status.error {
  color: #e0533d;
}
.ai-review-body {
  color: #d6dbe4;
  font-size: 13.5px;
  line-height: 1.55;
}
/* Raw tab: the markdown reading in a bordered card */
.ai-review-raw {
  border: 1px solid rgba(255, 255, 255, 0.1);
  border-radius: 10px;
  background: rgba(255, 255, 255, 0.03);
  padding: 16px 18px;
}
.ai-review-raw h3 {
  margin: 16px 0 6px;
  color: #fff;
  font-size: 16px;
}
.ai-review-raw h3:first-child {
  margin-top: 0;
}
.ai-review-body h4 {
  margin: 14px 0 6px;
  color: #fff;
  font-size: 15px;
}
.ai-review-body h4:first-child {
  margin-top: 0;
}
.ai-review-body h5 {
  margin: 10px 0 4px;
  color: #c7cedb;
  font-size: 13.5px;
}
.ai-review-body p {
  margin: 6px 0;
}
.ai-review-body ul {
  margin: 6px 0;
  padding-left: 18px;
}
.ai-review-body li {
  margin: 3px 0;
}
.ai-review-body ul {
  margin: 6px 0;
  padding-left: 20px;
}
.ai-review-stamp {
  margin-top: 12px;
  color: #767f8d;
  font-size: 11px;
}
/* ---- Chart tab: interactive family Venn ---- */
.ai-venn-wrap {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 14px;
}
.ai-venn {
  width: 100%;
  max-width: 460px;
  height: auto;
  touch-action: none;
  user-select: none;
}
/* Only the top hit rect intercepts pointer events; region is computed by math. */
.ai-venn > *:not(.ai-venn-hit) {
  pointer-events: none;
}
.ai-venn-hit {
  pointer-events: all;
  cursor: pointer;
}
.ai-venn-circle {
  fill: transparent;
  stroke-width: 2.5;
  transition: stroke-width 0.12s ease, opacity 0.12s ease;
  opacity: 0.55;
}
.ai-venn-circle.lit {
  opacity: 1;
  stroke-width: 4;
}
.ai-venn-label {
  fill: #fff;
  font-size: 13px;
  font-weight: 700;
  text-anchor: middle;
  pointer-events: none;
  stroke: rgba(0, 0, 0, 0.65);
  stroke-width: 3px;
  paint-order: stroke;
  stroke-linejoin: round;
}
.ai-venn-hi {
  opacity: 0;
  transition: opacity 0.12s ease;
  pointer-events: none;
}
.ai-venn-hi.on {
  opacity: 1;
}
.ai-venn-caption {
  width: 100%;
  max-width: 560px;
  border: 1px solid rgba(255, 255, 255, 0.1);
  border-radius: 10px;
  background: rgba(255, 255, 255, 0.03);
  padding: 14px 16px;
  min-height: 92px;
}
.ai-venn-caption-title {
  margin: 0 0 6px;
  color: #fff;
  font-size: 15px;
  font-weight: 600;
}
.ai-venn-caption-text {
  margin: 0;
  color: #d6dbe4;
  font-size: 13.5px;
  line-height: 1.55;
}
.ai-venn-caption-text p {
  margin: 0 0 8px;
}
.ai-venn-caption-text p:last-child {
  margin-bottom: 0;
}
/* Markdown readings: headings + bullets inside the caption box */
.ai-venn-caption-text h3,
.ai-venn-caption-text h4,
.ai-venn-caption-text h5 {
  margin: 10px 0 4px;
  color: #fff;
  font-size: 13.5px;
  font-weight: 600;
}
.ai-venn-caption-text h3:first-child,
.ai-venn-caption-text h4:first-child,
.ai-venn-caption-text h5:first-child {
  margin-top: 0;
}
.ai-venn-caption-text ul {
  margin: 4px 0 8px;
  padding-left: 18px;
}
.ai-venn-caption-text li {
  margin: 2px 0;
}
/* Desktop hover mode: the cursor tooltip replaces the caption box. */
.ai-venn-wrap.hover-mode .ai-venn-caption {
  display: none;
}
.ai-venn-tip {
  position: fixed;
  z-index: 2147483647;
  max-width: 300px;
  padding: 10px 12px;
  border: 1px solid rgba(255, 255, 255, 0.16);
  border-radius: 8px;
  background: #2a2d36;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.55);
  pointer-events: none;
}
.ai-venn-tip-title {
  margin-bottom: 4px;
  color: #fff;
  font-size: 13px;
  font-weight: 600;
}
.ai-venn-tip-text p {
  margin: 0 0 7px;
  color: #d6dbe4;
  font-size: 12.5px;
  line-height: 1.5;
}
.ai-venn-tip-text p:last-child {
  margin-bottom: 0;
}
/* Markdown readings: headings + bullets inside the cursor tooltip */
.ai-venn-tip-text h3,
.ai-venn-tip-text h4,
.ai-venn-tip-text h5 {
  margin: 8px 0 3px;
  color: #fff;
  font-size: 12.5px;
  font-weight: 600;
}
.ai-venn-tip-text h3:first-child,
.ai-venn-tip-text h4:first-child,
.ai-venn-tip-text h5:first-child {
  margin-top: 0;
}
.ai-venn-tip-text ul {
  margin: 3px 0 7px;
  padding-left: 16px;
}
.ai-venn-tip-text li {
  margin: 2px 0;
  color: #d6dbe4;
  font-size: 12.5px;
  line-height: 1.5;
}
/* ---- Talk tab: neomorphic chat ---- */
.ai-talk {
  box-sizing: border-box;
  display: flex;
  flex-direction: column;
  gap: 14px;
  height: min(58vh, 520px);
  padding: 16px;
  border-radius: 18px;
  background: #1b1d23;
  /* recessed: dark inner shadow top-left, faint light bottom-right */
  box-shadow:
    inset 3px 3px 8px rgba(0, 0, 0, 0.6),
    inset -3px -3px 8px rgba(255, 255, 255, 0.028);
}
.ai-talk-log {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 12px;
  padding: 2px 8px 2px 2px;
}
.ai-talk-empty {
  margin: auto;
  max-width: 260px;
  color: #868f9f;
  font-size: 13px;
  text-align: center;
  padding: 20px;
}
.ai-talk-msg {
  display: flex;
  max-width: 82%;
}
.ai-talk-msg.user {
  align-self: flex-end;
  justify-content: flex-end;
}
.ai-talk-msg.assistant {
  align-self: flex-start;
}
.ai-talk-bubble {
  padding: 10px 14px;
  border-radius: 16px;
  font-size: 13.5px;
  line-height: 1.5;
  white-space: pre-wrap;
  word-break: break-word;
  /* raised: extruded off the recessed panel */
  box-shadow:
    3px 3px 8px rgba(0, 0, 0, 0.4),
    -2px -2px 6px rgba(255, 255, 255, 0.03);
}
.ai-talk-msg.user .ai-talk-bubble {
  background: linear-gradient(145deg, #5c68f0, #4a53cf);
  color: #fff;
  border-bottom-right-radius: 5px;
}
.ai-talk-msg.assistant .ai-talk-bubble {
  background: #24262e;
  color: #e6e9ef;
  border-bottom-left-radius: 5px;
}
/* Tracker confirmations logged from chat: quieter, informational bubble */
.ai-talk-msg.tracker .ai-talk-bubble {
  background: rgba(59, 165, 93, 0.14);
  border: 1px solid rgba(59, 165, 93, 0.4);
  color: #b9e2c6;
  font-size: 12.5px;
}
.ai-talk-bubble.streaming::after {
  content: "▍";
  opacity: 0.6;
  animation: ai-talk-blink 1s steps(2) infinite;
}
@keyframes ai-talk-blink {
  50% {
    opacity: 0;
  }
}
/* Input dock: a raised pill holding a one-line field + round send button */
.ai-talk-form {
  box-sizing: border-box;
  display: flex;
  align-items: center;
  gap: 8px;
  flex: 0 0 auto;
  padding: 6px 6px 6px 16px;
  border-radius: 24px;
  background: #1f2229;
  box-shadow:
    4px 4px 10px rgba(0, 0, 0, 0.5),
    -3px -3px 9px rgba(255, 255, 255, 0.035);
}
.ai-talk-input {
  flex: 1;
  min-width: 0;
  resize: none;
  max-height: 92px;
  padding: 8px 0;
  border: 0;
  background: transparent;
  color: #e6e9ef;
  font: inherit;
  font-size: 13.5px;
  line-height: 1.4;
  outline: none;
}
.ai-talk-input::placeholder {
  color: #7b8494;
}
.ai-talk-input:disabled {
  opacity: 0.55;
}
.ai-talk-send {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex: 0 0 auto;
  width: 38px;
  height: 38px;
  padding: 0;
  border: 0;
  border-radius: 50%;
  background: linear-gradient(145deg, #6570f6, #4a53cf);
  color: #fff;
  cursor: pointer;
  box-shadow:
    3px 3px 7px rgba(0, 0, 0, 0.5),
    -2px -2px 6px rgba(255, 255, 255, 0.05);
  transition: filter 0.15s ease, box-shadow 0.12s ease;
}
.ai-talk-send:hover {
  filter: brightness(1.12);
}
.ai-talk-send:active {
  box-shadow: inset 2px 2px 6px rgba(0, 0, 0, 0.55);
}
.ai-talk-send:disabled {
  opacity: 0.5;
  cursor: default;
  box-shadow: none;
}
/* Natal panel: rectification checklist */
.natal-rectification {
  margin: 18px 0;
  border: 1px solid rgba(255, 255, 255, 0.12);
  border-radius: 10px;
  background: rgba(255, 255, 255, 0.03);
  padding: 14px 16px;
}
.natal-rectification h4 {
  margin: 0 0 6px;
  color: #fff;
  font-size: 14px;
}
.natal-rectification h4 + .natal-rect-hint {
  margin-top: 0;
}
.natal-rect-hint {
  color: #9aa3b2;
  font-size: 12px;
  margin: 4px 0 10px;
}
.natal-rect-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
  gap: 8px 18px;
  color: #d6dbe4;
  font-size: 12.5px;
  margin-bottom: 14px;
}
.natal-rect-grid .natal-k {
  display: block;
  color: #8b93a3;
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}
.natal-rect-eyes {
  margin: 2px 0 0;
  padding-left: 16px;
}
.natal-rect-flags {
  grid-column: 1 / -1;
  color: #f1c40f;
  font-size: 12.5px;
}

/* AI-generated life profile on the birth-chart panel */
.natal-ai-profile {
  margin: 18px 0;
  border: 1px solid rgba(88, 101, 242, 0.35);
  border-radius: 10px;
  background: rgba(88, 101, 242, 0.06);
  padding: 14px 16px;
}
.natal-ai-profile h4 {
  margin: 0 0 6px;
  color: #fff;
  font-size: 14px;
}
.natal-ai-body {
  color: #d6dbe4;
  font-size: 13.5px;
  line-height: 1.55;
}
.natal-ai-body h4 {
  margin: 14px 0 6px;
  color: #fff;
  font-size: 14.5px;
}
.natal-ai-body h5 {
  margin: 10px 0 4px;
  color: #c7cedb;
  font-size: 13px;
}
.natal-ai-body p {
  margin: 6px 0;
}
.natal-ai-body ul {
  margin: 6px 0;
  padding-left: 18px;
}
.natal-ai-body li {
  margin: 3px 0;
}
.natal-ai-stamp {
  margin-top: 12px;
  color: #767f8d;
  font-size: 11px;
}

/* =====================================
   Chart-first layout: control strip + metric chips
   ===================================== */
.toolbar-primary {
  gap: 8px;
}

/* Icon-only top-bar buttons (Charts / AI Read / Track): square, label lives
   in title + aria-label. */
.toolbar-primary .icon-btn {
  width: 38px;
  min-width: 38px;
  padding: 0;
  justify-content: center;
}
.toolbar-primary .icon-btn svg {
  display: block;
  pointer-events: none;
}

/* Bands / Windows: compact single-letter toggles, yellow when active. */
#bands-toggle,
#windows-toggle {
  min-width: 34px;
  justify-content: center;
  font-weight: 700;
  letter-spacing: 0.02em;
}
#bands-toggle.active,
#windows-toggle.active {
  background: linear-gradient(135deg, #f1c40f 0%, #d4a017 100%);
  border-color: transparent;
  color: #1c1c1c;
  box-shadow: 0 4px 15px rgba(241, 196, 15, 0.35);
}
#bands-toggle.active:hover,
#windows-toggle.active:hover {
  background: linear-gradient(135deg, #f4d03f 0%, #dbaa1c 100%);
  color: #1c1c1c;
  box-shadow: 0 6px 20px rgba(241, 196, 15, 0.5);
}

.control-strip {
  flex-shrink: 0;
  display: flex;
  align-items: center;
  gap: 6px;
  flex-wrap: nowrap;
  overflow-x: auto;
  scrollbar-width: thin;
  padding: 5px 12px;
  background: rgba(38, 38, 42, 0.9);
  border-bottom: 1px solid rgba(255, 255, 255, 0.08);
  z-index: 90;
}
.control-strip button {
  flex: 0 0 auto;
  white-space: nowrap;
}
.control-strip .person-toggles {
  flex: 0 0 auto;
}
@media (min-width: 769px) {
  .control-strip {
    flex-wrap: wrap;
    overflow-x: visible;
  }
}

/* Metric quick-chips: one-tap toggles above the chart. */
.metric-chips {
  flex-shrink: 0;
  display: flex;
  align-items: center;
  gap: 6px;
  flex-wrap: nowrap;
  overflow-x: auto;
  scrollbar-width: thin;
  padding: 6px 12px;
  background: #1e1e1e;
  border-bottom: 1px solid rgba(255, 255, 255, 0.06);
}
.metric-chip {
  flex: 0 0 auto;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 4px 10px;
  border: 1px solid rgba(255, 255, 255, 0.1);
  border-radius: 999px;
  background: rgba(61, 61, 61, 0.35);
  color: #8b93a3;
  font-size: 11px;
  cursor: pointer;
  white-space: nowrap;
  transition: all 0.15s ease;
}
.metric-chip .metric-chip-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  opacity: 0.35;
  flex: 0 0 8px;
}
.metric-chip.active {
  background: rgba(88, 101, 242, 0.12);
  color: #fff;
}
.metric-chip.active .metric-chip-dot {
  opacity: 1;
}
.metric-chip:hover {
  color: #fff;
}
@media (max-width: 768px) {
  .metric-chips {
    padding: 5px 8px;
  }
  .metric-chip {
    font-size: 10px;
    padding: 4px 8px;
    min-height: 26px;
  }
}

/* =====================================
   Mobile overrides for late-file components (icon buttons, autofit
   placement, rating stars). Kept at the end so they win over the base
   rules above.
   ===================================== */
@media (max-width: 768px) {
  .toolbar-primary .icon-btn {
    width: 32px;
    min-width: 32px;
    padding: 0;
  }

  /* Keep the Y-axis mode (Fixed / Auto-fit) at the end of the control strip
     on phones so it reads as its own thing, apart from the overlay toggles. */
  #autofit-toggle {
    order: 99;
    margin-left: auto;
  }

}

@media (max-width: 480px) {
  .toolbar-primary .icon-btn {
    width: 30px;
    min-width: 30px;
    padding: 0;
  }
}

/* =====================================
   Mobile: keep the birth-chart / AI-review modal close button reachable.
   The header is a horizontal flex row; with person + birth-time tabs it can
   exceed the modal width and (because .natal-box clips overflow) push the
   trailing close button off-screen. Pin the close button to the top-right of
   the box and let the header wrap beneath it.
   ===================================== */
@media (max-width: 768px) {
  .natal-header {
    position: relative;
    flex-wrap: wrap;
    padding-right: 52px;
    row-gap: 8px;
  }
  .natal-header h2 {
    font-size: 16px;
  }
  .natal-close {
    position: absolute;
    top: 12px;
    right: 12px;
    width: 36px;
    height: 36px;
    z-index: 2;
  }
  .natal-person-tabs {
    flex-wrap: wrap;
  }
  .ai-review-date-nav {
    flex-wrap: wrap;
  }
}

/* "No metrics found" placeholder in the legend search results */
.no-results {
  padding: 14px 10px;
  color: #9aa3b2;
  font-size: 12px;
  text-align: center;
}

/* Tracker form while a load/save request is in flight */
.tracker-entry-form.busy {
  opacity: 0.65;
  pointer-events: none;
}

/* Legend quick-action buttons (were inline styles in index.html) */
.legend-actions {
  display: flex;
  gap: 6px;
  margin-top: 8px;
}

.legend-actions button {
  flex: 1;
  padding: 6px;
  font-size: 11px;
  border: 1px solid rgba(255, 255, 255, 0.1);
  background: rgba(61, 61, 61, 0.5);
  color: white;
  border-radius: 6px;
  cursor: pointer;
}

.legend-actions #quick-mood {
  background: rgba(102, 126, 234, 0.3);
}

/* Tracker panel: per-person Mood/Health slider groups */
.tracker-person-section {
  border-top: 1px solid rgba(255, 255, 255, 0.1);
  padding-top: 10px;
  margin-top: 4px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.tracker-person-title {
  margin: 0;
  font-size: 13px;
  font-weight: 600;
  color: #9aa3b2;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}
