/* Custom Properties */
:root {
  --bg-light: #f0f0f0;
  --bg-dark: #1a1a1a;
  --text-light: #333;
  --text-dark: #fff;
  --header-bg-light: #cdcdcd;
  --header-bg-dark: #333;
  --border-light: #ccc;
  --border-dark: #555;
  --shadow-light: 0 0 10px rgba(0, 0, 0, 0.1);
  --shadow-dark: 0 0 10px rgba(0, 0, 0, 0.5);
  --primary-blue: #2196F3;
  --accent-green: #4CAF50;
  --accent-orange: #d17b00;
  --select-arrow-light: url('data:image/svg+xml;utf8,<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="black"><path d="M7 10l5 5 5-5H7z"/></svg>');
  --select-arrow-dark: url('data:image/svg+xml;utf8,<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="white"><path d="M7 10l5 5 5-5H7z"/></svg>');
}

/* Global Styles */
* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

body {
  font-family: Arial, sans-serif;
  background: var(--bg-light);
  color: var(--text-light);
  display: flex;
  flex-direction: column;
  align-items: center;
  min-height: 100vh;
  overflow-x: hidden;
  width: 100vw;
  margin: 0;
  padding: 0;
  transition: background 0.3s, color 0.3s;
  position: relative;
}

.dark-mode {
  background: var(--bg-dark);
  color: var(--text-dark);
}

/* Header */
.header {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 5px;
  background: var(--header-bg-light);
  z-index: 1000;
  height: 50px;
  box-shadow: var(--shadow-light);
}

.dark-mode .header {
  background: var(--header-bg-dark);
}



.header-logo-link {
  display: flex;
  align-items: center;
  text-decoration: none;
  color: inherit;
  margin-left: 5px;
}

.header-logo {
  height: 30px;
  width: auto;
  object-fit: contain;
  margin-right: 5px;
}

.header-title {
  font-size: 24px;
  font-weight: bold;
}

.dark-mode .header-title {
  color: var(--text-dark);
}

/* Navigation Menu */
.nav-menu {
  display: flex;
  align-items: center;
  gap: 8px;
}

.nav-menu a {
  color: var(--text-light);
  text-decoration: none;
  font-size: 1em;
  padding: 6px 10px;
  border-radius: 4px;
  transition: background 0.3s;
}

.dark-mode .nav-menu a {
  color: var(--text-dark);
}

.nav-menu a:hover {
  background: #ddd;
}

/* Dropdown Menu */
.nav-container {
  display: flex;
  align-items: center;
  margin-left: auto;
}

.menu {
  color: var(--text-light);
  padding: 6px 12px;
  border-radius: 5px;
  cursor: pointer;
  font-size: 1.5em;
  margin-right: 5px;
}

.dark-mode .menu {
  color: var(--text-dark);
}

.menu-content {
  position: fixed;
  top: 50px;
  right: 10px;
  background: var(--header-bg-dark);
  color: var(--text-dark);
  border-radius: 5px;
  padding: 10px;
  z-index: 1000;
  display: none;
  max-width: calc(100% - 20px);
}

.menu-content.show {
  display: block;
}

.menu-content a {
  display: block;
  padding: 10px;
  color: var(--text-dark);
  text-decoration: none;
  font-size: 1em;
}

.menu-content a:hover {
  background: #555;
}

.menu-content select,
#currencySelect,
#timezoneSelect,
#timeFormatSelect {
  width: 100%;
  max-width: 200px;
  padding: 8px;
  margin: 5px auto;
  border-radius: 4px;
  border: 1px solid var(--border-dark);
  background: #444 var(--select-arrow-dark) no-repeat right 10px center/16px;
  color: var(--text-dark);
  font-size: 0.9em;
  cursor: pointer;
  appearance: none;
}

.menu-content select:focus,
#currencySelect:focus,
#timezoneSelect:focus,
#timeFormatSelect:focus {
  outline: none;
  border-color: #777;
}

#currencySelectContainer {
  width: 100%;
  text-align: center;
}

.menu-divider {
  border: none;
  border-top: 1px solid var(--border-dark);
  margin: 5px 0;
}

/* Toggle Switches */
.theme-toggle,
.fiat-toggle {
  padding: 10px;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
}

.fiat-toggle {
  margin: 0 auto;
  width: fit-content;
}

.switch {
  position: relative;
  display: inline-block;
  width: 36px;
  height: 20px;
}

.switch input {
  opacity: 0;
  width: 0;
  height: 0;
}

.slider {
  position: absolute;
  cursor: pointer;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: var(--border-light);
  transition: background 0.4s;
  border-radius: 10px;
}

.dark-mode .slider {
  background: var(--border-dark);
}

.slider:before {
  content: "";
  position: absolute;
  height: 16px;
  width: 16px;
  left: 2px;
  bottom: 2px;
  background: var(--text-dark);
  transition: transform 0.4s;
  border-radius: 50%;
}

input:checked + .slider {
  background: var(--accent-green);
}

.dark-mode input:checked + .slider {
  background: #2196F3;
}

input:checked + .slider:before {
  transform: translateX(16px);
}

.theme-toggle .icon,
.fiat-toggle .icon {
  font-size: 18px;
  transition: opacity 0.4s, color 0.4s;
}

.theme-toggle .sun {
  color: #f1c40f;
  opacity: 1;
}

.theme-toggle .moon {
  color: #95a5a6;
  opacity: 0.5;
}

.dark-mode .theme-toggle .sun {
  color: #7f8c8d;
}

.dark-mode .theme-toggle .moon {
  color: #3498db;
}

input:checked ~ .moon {
  color: #3498db;
  opacity: 1;
}

input:checked ~ .sun,
input:not(:checked) ~ .moon {
  opacity: 0.5;
}

input:not(:checked) ~ .sun {
  color: #f1c40f;
  opacity: 1;
}

.fiat-toggle .dollar {
  color: #2ecc71;
  opacity: 0.5;
}

.fiat-toggle .sats {
  color: #f39c12;
  opacity: 1;
}

input:checked ~ .dollar {
  opacity: 1;
}

input:checked ~ .sats,
input:not(:checked) ~ .dollar {
  opacity: 0.5;
}

/* Values Container */
.values-container {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 15px;
  margin: 70px 0 20px;
  width: 100%;
  padding: 0 10px;
}

.value-box {
  width: 100%;
  max-width: 300px;
  height: 160px;
  padding: 10px;
  border-radius: 8px;
  color: var(--text-dark);
  text-align: center;
  display: flex;
  flex-direction: column;
  justify-content: flex-start;
  position: relative;
  transition: height 0.3s ease;
}

.value-box.fiat-enabled {
  height: 180px;
}

.prize-box,
.payment-box,
.selected-day-sats-box {
  background: var(--accent-orange);
}

.hashrate-box,
.last-24h-sats-box {
  background: var(--primary-blue);
}

.next-payment-box,
.lowest-hashrate-box {
  background: #FF5722;
}

.total-sats-box {
  background: #a028ee;
}

.highest-hashrate-box {
  background: #27ae60;
}

.average-hashrate-box {
  background: #9c27b0;
}

.label {
  font-size: 1.2em;
  font-weight: bold;
  margin-bottom: 4px;
  line-height: 1.2;
}

.next-payment-box .label {
  text-align: center;
  width: 100%;
  margin-bottom: 0;
}

.date {
  font-size: 0.9em;
  font-weight: normal;
}

.value {
  font-size: 1.5em;
  margin: 8px 0 4px;
  line-height: 1.2;
}

.payment-box .value,
.next-payment-box .value {
  margin-top: 10px;
}

.usd-value,
.fiat-value {
  font-size: 0.9em;
  color: var(--text-dark);
  margin-top: 5px;
  font-style: italic;
  font-family: 'Lato', Arial, sans-serif;
}

.fiat-value {
  color: var(--text-light);
}

.dark-mode .usd-value,
.dark-mode .fiat-value,
.dark-mode .payment-time {
  color: var(--text-dark);
}

.fiat-value.show {
  display: block;
}

.fiat-separator {
  margin: 0 5px;
  color: #666;
}

.dark-mode .fiat-separator {
  color: #d4d4d4;
}

.payment-time {
  font-size: 1em;
  line-height: 1.2;
  margin-top: 15px;
  text-shadow: 0 0 2px rgba(0, 0, 0, 0.5);
}

.next-payment-box .tooltip {
  position: absolute;
  top: 10px;
  right: 10px;
  z-index: 101;
}

/* Calculator Section */
.calculator-section {
  max-width: 1200px;
  margin: 70px auto 60px;
  padding: 20px;
  text-align: center;
}

/* Two-Column Card Layout */
.card-columns {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 15px;
  padding: 0 15px;
  width: 100%;
  margin-top: 60px;
}

.column-left,
.column-right {
  display: grid;
  grid-template-rows: repeat(4, auto);
  gap: 10px;
}

.card {
  background: #fff;
  border-radius: 10px;
  box-shadow: var(--shadow-light);
  padding: 20px;
  transition: transform 0.2s;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  position: relative;
}

.card:hover {
  transform: translateY(-5px);
}

.dark-mode .card {
  background: #2a2a2a;
  box-shadow: var(--shadow-dark);
}

.card-label {
  font-size: 1.1em;
  font-weight: bold;
  color: var(--primary-blue);
  margin-bottom: 10px;
}

.dark-mode .card-label {
  color: #64b5f6;
}

.card-value {
  font-size: 1.5em;
  color: var(--text-light);
}

.dark-mode .card-value {
  color: var(--text-dark);
}

.input-card {
  text-align: center;
  display: flex;
  flex-direction: column;
  align-items: center;
}

.input-card input[type="number"],
.input-card input[type="text"] {
  width: 100%;
  max-width: 200px;
  padding: 8px;
  border: none;
  border-radius: 5px;
  font-size: 1em;
  text-align: center;
  background: #e8e8e8;
  color: var(--text-light);
  margin: 0 auto 10px;
}

.dark-mode .input-card input[type="number"],
.dark-mode .input-card input[type="text"] {
  background: var(--header-bg-dark);
  color: var(--text-dark);
  border-color: var(--border-dark);
}

.input-card input:focus {
  outline: none;
}

.warning {
  color: #e74c3c;
  font-size: 0.9em;
  min-height: 1.2em;
  text-align: center;
}

/* Dashboard */
.dashboard {
  display: flex;
  flex-direction: column;
  width: 100%;
  max-width: 1200px;
  margin: 20px 0 60px;
  gap: 15px;
  padding: 0 10px;
}

/* Graphs */
.graph-container {
  background: #fff;
  padding: 15px 15px 40px;
  border-radius: 8px;
  box-shadow: var(--shadow-light);
  margin-top: 15px;
  width: 100%;
  height: 600px;
  position: relative;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  padding-top: 60px;
  transition: opacity 0.3s ease;
}

.dark-mode .graph-container {
  background: #2a2a2a;
  box-shadow: var(--shadow-dark);
}

.graph-container.fading {
  opacity: 0;
}

.graph-container .plotly {
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  top: 60px;
  width: 100% !important;
  height: calc(100% - 60px) !important;
}

#ppGraph,
#hrGraph,
#crGraph,
#priceGraph,
#supplyGraph {
  width: 100% !important;
  height: 100% !important;
}

.graph-filter {
  position: absolute;
  top: 10px;
  right: 15px;
  display: flex;
  align-items: center;
  gap: 10px;
  z-index: 10;
}

.graph-filter select,
#ppRangeFilter,
#hrRangeFilter,
#crRangeFilter {
  padding: 5px 30px 5px 5px;
  font-size: 0.9em;
  border-radius: 4px;
  border: 1px solid var(--border-light);
  background: #fff var(--select-arrow-light) no-repeat right 10px center/16px;
  cursor: pointer;
  appearance: none;
}

.dark-mode .graph-filter select,
.dark-mode #ppRangeFilter,
.dark-mode #hrRangeFilter,
.dark-mode #crRangeFilter {
  background: var(--header-bg-dark) var(--select-arrow-dark) no-repeat right 10px center/16px;
  color: var(--text-dark);
  border-color: var(--border-dark);
}

.custom-range {
  display: none;
  flex-direction: row;
  gap: 10px;
  align-items: center;
  justify-content: flex-end;
}

.custom-range.show,
.custom-range.visible {
  display: flex;
}

#zoomToDate {
  max-width: 200px;
  padding: 5px;
  font-size: 0.9em;
  border-radius: 4px;
  border: 1px solid var(--border-light);
  background: var(--bg-light);
  color: var(--text-light);
  cursor: pointer;
  transition: background 0.2s;
}

.dark-mode #zoomToDate {
  background: #444;
  color: var(--text-dark);
}

#zoomToDate:hover {
  background: #e0e0e0;
}

.dark-mode #zoomToDate:hover {
  background: #555;
}

.zoom-indicator {
  font-size: 0.8em;
  color: #555;
  text-align: center;
  margin-bottom: 28px;
  display: none;
  position: absolute;
  bottom: 0;
  width: 100%;
  z-index: 10;
}

.dark-mode .zoom-indicator {
  color: #aaa;
}

.zoom-indicator.visible {
  display: block;
}

/* Tables */
.table-container {
  background: #fff;
  padding: 15px;
  border-radius: 8px;
  box-shadow: var(--shadow-light);
  margin-top: 15px;
  width: 100%;
  overflow-x: auto;
  position: relative;
}

.dark-mode .table-container {
  background: #2a2a2a;
  box-shadow: var(--shadow-dark);
}

.table-content {
  display: flex;
  flex-direction: column;
  gap: 15px;
  margin: 80px 0 60px;
}

.table-stats-container {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 15px;
}

table {
  width: 100%;
  border-collapse: collapse;
  min-width: 300px;
}

th,
td {
  border: 1px solid var(--border-light);
  padding: 8px;
  text-align: center;
  font-size: 0.85em;
  min-width: 80px;
}

.dark-mode th,
.dark-mode td {
  border-color: var(--border-dark);
  color: var(--text-dark);
}

#historyTable tr.data-row:nth-child(odd),
tr.data-row:nth-child(odd) {
  background: #f5f5f5;
}

#historyTable tr.data-row:nth-child(even),
tr.data-row:nth-child(even) {
  background: #fff;
}

.dark-mode #historyTable tr.data-row:nth-child(odd),
.dark-mode tr.data-row:nth-child(odd) {
  background: #333;
}

.dark-mode #historyTable tr.data-row:nth-child(even),
.dark-mode tr.data-row:nth-child(even) {
  background: #2a2a2a;
}

#historyTable tr.reward-row:nth-child(odd),
.payment-entry {
  background: #FF9800;
  color: var(--text-light);
  font-weight: 700;
}

#historyTable tr.reward-row:nth-child(even) {
  background: #ffcc80;
  color: var(--text-light);
  font-weight: 700;
}

.dark-mode #historyTable tr.reward-row:nth-child(odd),
.dark-mode .payment-entry {
  background: var(--accent-orange);
  color: var(--text-dark);
}

.dark-mode #historyTable tr.reward-row:nth-child(even) {
  background: #b56500;
  color: var(--text-dark);
}

.payment-only tr.payment-entry:nth-child(odd) {
  background: #f7931a;
  color: var(--text-light);
}

.payment-only tr.payment-entry:nth-child(even) {
  background: #ffcc80;
  color: var(--text-light);
}

.dark-mode .payment-only tr.payment-entry:nth-child(odd) {
  background: var(--accent-orange);
}

.dark-mode .payment-only tr.payment-entry:nth-child(even) {
  background: #b56500;
}

.table-filter {
  position: absolute;
  top: 10px;
  right: 15px;
  display: flex;
  align-items: center;
  gap: 10px;
  z-index: 10;
}

.table-filter select,
#dataFilter {
  padding: 5px 30px 5px 5px;
  font-size: 0.9em;
  border-radius: 4px;
  border: 1px solid var(--border-light);
  background: #fff var(--select-arrow-light) no-repeat right 10px center/16px;
  cursor: pointer;
  appearance: none;
}

.dark-mode .table-filter select,
.dark-mode #dataFilter {
  background: var(--header-bg-dark) var(--select-arrow-dark) no-repeat right 10px center/16px;
  color: var(--text-dark);
  border-color: var(--border-dark);
}

.table-filter .sortable {
    width: 180px !important;
}

/* Headings */
.graph-container h2,
.heading-container h2 {
  position: absolute;
  top: 15px;
  left: 15px;
  margin: 0;
  font-size: 1em;
  color: var(--text-light);
}

.dark-mode .graph-container h2,
.dark-mode .heading-container h2 {
  color: var(--text-dark);
}

.graph-container h3,
.heading-container h3 {
  position: absolute;
  top: 15px;
  left: 15px;
  margin: 0;
  font-size: 1em;
  color: var(--text-light);
}

.dark-mode .graph-container h3,
.dark-mode .heading-container h3 {
  color: var(--text-dark);
}

/* Tooltips */
.tooltip {
  position: relative;
  display: inline-block;
}

.tooltip .tooltiptext {
  visibility: hidden;
  width: 200px;
  background: var(--header-bg-dark);
  color: var(--text-dark);
  text-align: left;
  border-radius: 8px;
  padding: 12px;
  position: absolute;
  top: calc(100% + 10px);
  left: 50%;
  transform: translateX(-50%);
  opacity: 0;
  transition: opacity 0.2s ease;
  font-size: 14px;
  line-height: 1.5;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
  z-index: 9999;
  white-space: normal;
  word-wrap: break-word;
  font-weight: bold;
}

/* Calculator-specific tooltip */
.joules-consumption .tooltip .tooltiptext {
  width: 500px;
  font-weight: normal;
}

/* Detail page-specific tooltip */
.next-payment-box .tooltip .tooltiptext {
  width: 200px;
}

/* Formula card tooltips */
.clickable-card .tooltip {
  position: absolute;
  top: 10px;
  right: 10px;
  z-index: 1000;
}

.clickable-card .tooltip .tooltiptext {
  width: 200px;
  left: 50%;
  transform: translateX(-50%);
  font-size: 0.8em;
  text-align: center;
}

.clickable-card .tooltip .info-icon {
  width: 16px;
  height: 16px;
  opacity: 0.7;
  transition: opacity 0.2s ease;
}

.clickable-card .tooltip .info-icon:hover {
  opacity: 1;
}

.dark-mode .clickable-card .tooltip .info-icon {
  filter: brightness(0) invert(1);
}

.tooltip .tooltiptext::before {
  content: '';
  position: absolute;
  top: -6px;
  left: 50%;
  transform: translateX(-50%);
  border-width: 0 6px 6px 6px;
  border-style: solid;
  border-color: transparent transparent var(--header-bg-dark) transparent;
}

.tooltip:hover .tooltiptext {
  visibility: visible;
  opacity: 1;
}

.info-icon {
  cursor: pointer;
  width: 14px;
  height: 14px;
  vertical-align: middle;
}

/* Flatpickr Styles */
.flatpickr-input,
#dateFilter {
  width: 130px;
  padding: 5px 5px 5px 32px;
  font-size: 0.9em;
  border-radius: 4px;
  border: 1px solid var(--border-light);
  background: #fff url('img/calendar-dark.png') no-repeat 5px center/16px;
  cursor: pointer;
}

.dark-mode .flatpickr-input,
.dark-mode #dateFilter {
  background: var(--header-bg-dark) url('img/calendar-white.png') no-repeat 5px center/16px;
  color: var(--text-dark);
  border-color: var(--border-dark);
}

.flatpickr-input[readonly] {
  background: #fff;
}

.dark-mode .flatpickr-input[readonly] {
  background: var(--header-bg-dark);
}

.flatpickr-calendar {
  font-family: Arial, sans-serif;
  border-radius: 8px;
  box-shadow: var(--shadow-light);
  background: #fff;
}

.dark-mode .flatpickr-calendar {
  background: #30323b;
  box-shadow: var(--shadow-dark);
}

.flatpickr-day.selected,
.flatpickr-day.startRange,
.flatpickr-day.endRange {
  background: var(--primary-blue);
  border-color: var(--primary-blue);
  color: var(--text-dark);
}

.flatpickr-day.inRange {
  background: rgba(33, 150, 243, 0.2);
  border: none;
}

.flatpickr-day:hover {
  background: rgba(33, 150, 243, 0.1);
}

.dark-mode .flatpickr-day {
  color: rgba(255, 255, 255, 0.95);
}

.dark-mode .flatpickr-day.inRange,
.dark-mode .flatpickr-day:hover,
.dark-mode .flatpickr-day:focus {
  background: #646c8c;
  border-color: #646c8c;
}

.dark-mode .flatpickr-day.today {
  border-color: #eee;
}

.dark-mode .flatpickr-day.today:hover,
.dark-mode .flatpickr-day.today:focus {
  background: #eee;
  color: #3f4458;
}

.dark-mode .flatpickr-day.selected,
.dark-mode .flatpickr-day.startRange,
.dark-mode .flatpickr-day.endRange {
  background: #80cbc4;
  border-color: #80cbc4;
}

.dark-mode .flatpickr-day.inRange {
  box-shadow: -5px 0 0 #646c8c, 5px 0 0 #646c8c;
}

.dark-mode .flatpickr-current-month {
  font-size: 135%;
  line-height: inherit;
  font-weight: 300;
  color: #fff;
  position: absolute;
  width: 75%;
  left: 12.5%;
  padding: 7.48px 0 0 0;
  line-height: 1;
  height: 34px;
  display: inline-block;
  text-align: center;
  transform: translate3d(0px, 0px, 0px);
}

.flatpickr-current-month .flatpickr-monthDropdown-months {
  background: #d9d9d9;
}

.dark-mode .flatpickr-current-month .flatpickr-monthDropdown-months {
  appearance: menulist;
  background: #3f4458;
  border: none;
  border-radius: 0;
  box-sizing: border-box;
  color: #fff;
  cursor: pointer;
  font-size: inherit;
  font-family: inherit;
  font-weight: 300;
  height: auto;
  line-height: inherit;
  margin: -1px 0 0 0;
  outline: none;
  padding: 0 0 0 0.5ch;
  position: relative;
  vertical-align: initial;
  width: auto;
}

.dark-mode span.flatpickr-weekday {
  cursor: default;
  font-size: 90%;
  background: #3f4458;
  color: #fff;
  line-height: 1;
  margin: 0;
  text-align: center;
  display: block;
  flex: 1;
  font-weight: bolder;
}

.dark-mode .flatpickr-months .flatpickr-prev-month,
.dark-mode .flatpickr-months .flatpickr-next-month {
  user-select: none;
  text-decoration: none;
  cursor: pointer;
  position: absolute;
  top: 0;
  height: 34px;
  padding: 10px;
  z-index: 3;
  color: #fff;
  fill: #fff;
}

.dark-mode .flatpickr-current-month input.cur-year {
  background: transparent;
  box-sizing: border-box;
  color: #fff;
  cursor: text;
  padding: 0 0 0 0.5ch;
  margin: 0;
  display: inline-block;
  font-size: inherit;
  font-family: inherit;
  font-weight: 300;
  line-height: inherit;
  height: auto;
  border: 0;
  border-radius: 0;
  vertical-align: initial;
  -webkit-appearance: textfield;
  -moz-appearance: textfield;
  appearance: textfield;
}

/* Footer */
.footer {
  background: var(--header-bg-light);
  padding: 20px;
  border-top: 1px solid #999;
  font-size: 14px;
  color: var(--text-light);
  width: 100vw;
  margin-top: auto;
  margin-bottom: 0;
  left: 0;
  right: 0;
  position: relative;
  box-shadow: 0 -2px 5px rgba(0, 0, 0, 0.1);
}

.dark-mode .footer {
  background: var(--header-bg-dark);
  border-top: 1px solid var(--border-dark);
  color: var(--text-dark);
}

.footer-container {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  max-width: 1200px;
  margin: 0 auto;
  gap: 20px;
}

.footer-item {
  flex: 1;
  min-width: 200px;
  text-align: center;
}

.footer-item a {
  text-decoration: none;
  color: var(--text-light);
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
}

.dark-mode .footer-item a {
  color: var(--text-dark);
}

.footer-item a:hover {
  text-decoration: underline;
}

.footer-logo {
  height: 30px;
  width: 30px;
  object-fit: contain;
  margin-right: 5px;
}

.footer-item a .external-icon {
  width: 20px;
  height: 20px;
  margin-left: 5px;
  vertical-align: middle;
}

.footer-bottom {
  text-align: center;
  margin-top: 20px;
  font-size: 12px;
  color: #666;
}

.dark-mode .footer-bottom {
  color: #aaa;
}

.dark-mode .footer-item img[src*="web.png"],
.dark-mode .footer-item img[src*="external-link.png"] {
  filter: brightness(0) invert(0.9);
}

.footer-heading {
  color: var(--primary-blue);
}

.dark-mode .footer-heading {
 color: #81c5fc
}

/* Animations */
@keyframes fpFadeInDown {
  from {
    opacity: 0;
    transform: translate3d(0, -20px, 0);
  }
  to {
    opacity: 1;
    transform: translate3d(0, 0, 0);
  }
}

/* Media Queries - Desktop (min-width: 768px) */
@media (min-width: 768px) {
  .values-container {
    flex-direction: row;
    flex-wrap: wrap;
    justify-content: center;
  }

  .value-box {
    width: 200px;
    max-width: none;
    height: 160px;
  }

  .value-box.fiat-enabled {
    height: 180px;
  }

  .dashboard {
    padding: 0;
  }

  .graph-container {
    height: 800px;
    padding-top: 70px;
    padding-bottom: 50px;
  }

  .graph-container .plotly {
    top: 70px;
    height: calc(100% - 70px) !important;
  }

  .table-content {
    display: grid;
    grid-template-columns: 1fr 250px;
    gap: 20px;
    align-items: start;
    margin: 60px 0;
  }

  .table-filter select,
  #dataFilter,
  .flatpickr-input,
  #dateFilter {
    width: 130px;
  }

  .label {
    font-size: 1.4em;
    margin-bottom: 6px;
  }

  .date {
    font-size: 0.7em;
  }

  .value {
    font-size: 1.3em;
    margin: 10px 0 6px;
  }

  .usd-value,
  .fiat-value {
    font-size: 0.9em;
    margin-top: 6px;
  }

  .payment-time {
    font-size: 1.1em;
    margin-top: 12px;
  }

  th,
  td {
    padding: 10px;
    font-size: 1em;
  }

  .graph-container h2,
  .heading-container h2 {
    font-size: 1.2em;
  }

  .info-icon {
    width: 16px;
    height: 16px;
  }

  .tooltip .tooltiptext {
    width: 500px;
    font-size: 0.9em;
    padding: 12px;
  }
}

/* Media Queries - Mobile (max-width: 767px) */
@media (max-width: 767px) {
  .values-container {
    margin-top: 100px; /* Increased to account for header + glued timer */
  }

  .value-box {
    height: 145px;
  }

  .value-box.fiat-enabled {
    height: 165px;
  }

  .table-content {
    margin: 80px 0 20px;
  }

  .menu-content {
    right: 5px;
    max-width: calc(100% - 10px);
  }

  .tooltip .tooltiptext {
    width: 120px;
    font-size: 0.7em;
    right: 100%;
    top: 50%;
    transform: translateY(-50%);
    margin-right: 5px;
  }

  .nav-menu {
    gap: 6px;
  }

  .nav-menu a {
    padding: 4px 8px;
    white-space: nowrap;
  }

  .header-title {
    font-size: 16px;
  }

  .header-logo {
    height: 25px;
  }

  .header {
    padding: 8px 3px;
    height: auto;
    min-height: 50px;
    flex-wrap: wrap;
    align-items: center;
  }

  /* Move hamburger menu to same level as header title */
  .nav-container {
    gap: 4px;
    flex-wrap: wrap;
    justify-content: flex-end;
    align-items: center;
  }

  .menu {
    margin-right: 0;
    padding: 4px 8px;
    font-size: 1.3em;
  }

  .graph-filter {
    right: 10px;
    justify-content: flex-end;
  }

  .table-filter {
    position: absolute;
    top: 45px;
    left: 15px;
    flex-wrap: nowrap;
    z-index: 10;
  }

  .graph-filter select,
  #ppRangeFilter,
  #hrRangeFilter,
  #crRangeFilter,
  #zoomToDate,
  .flatpickr-input,
  #dateFilter {
    min-width: 120px;
    max-width: 150px;
    font-size: 0.8em;
    padding: 4px;
  }

  .table-filter select,
  #dataFilter {
    width: 120px;
    padding: 4px 25px 4px 4px;
  }

  .flatpickr-input,
  #dateFilter {
    padding-left: 28px;
  }

  .graph-container {
    border-radius: 10px;
    box-shadow: var(--shadow-dark);
  }

  .graph-container h2 {
    font-size: 0.9em;
    top: 15px;
    left: 15px;
    z-index: 11;
  }

  .footer-container {
    flex-direction: column;
    align-items: center;
  }

  body.popup-open .footer {
    height: 500px;
  }

  .card-columns {
    grid-template-columns: 1fr;
    gap: 10px;
  }

  .calculator-section {
    margin-top: 100px;
    padding: 10px;
  }

  .tooltip .tooltiptext {
    width: 120px;
    font-size: 0.7em;
    white-space: normal;
    right: 100%;
    left: auto;
    top: 50%;
    transform: translateY(-50%);
    margin-right: 5px;
  }

  /* Calculator-specific tooltip on mobile */
  .joules-consumption .tooltip .tooltiptext {
    width: 200px;
    left: 50%;
    right: auto;
    top: 100%;
    transform: translateX(-50%);
    margin-top: 10px;
    margin-right: 0;
  }

  .tooltip:hover .tooltiptext {
  visibility: visible;
  opacity: 1;
}
}

/* Input Container */
.input-container {
  position: relative;
  display: flex;
  align-items: center;
}

.reset-icon {
  width: 20px;
  height: 20px;
  margin-left: 10px;
  margin-bottom: 10px;
  cursor: pointer;
  transition: opacity 0.3s;
}

.reset-icon:hover {
  opacity: 0.7;
}

/* --- Calculator Layout with Side Panel --- */
.calculator-layout {
  display: flex;
  flex-direction: row;
  justify-content: center;
  align-items: stretch;
  width: 100%;
  max-width: 1600px;
  margin: 70px auto 20px;
  gap: 150px;
}

.side-panel {
  display: flex;
  flex-direction: column;
  justify-content: flex-start;
  align-items: stretch;
  min-width: 280px;
  max-width: 350px;
  flex: 0 0 350px;
  /* Match height to calculator-section */
}

.side-panel .card {
  margin-top: 40px;
  height: 90%;
  min-height: 90%;
  display: flex;
  flex-direction: column;
  justify-content: flex-start;
}

/* Left placeholder to maintain layout balance */
.left-placeholder {
  visibility: hidden;
  pointer-events: none;
}

/* Ensure calculator-section stays centered */
.calculator-section {
  margin: 0 auto 20px;
  flex: 0 0 600px;
  max-width: 600px;
  width: 600px;
}

@media (max-width: 1200px) {
  .calculator-layout {
    gap: 40px;
  }
  .side-panel {
    min-width: 180px;
    flex-basis: 180px;
  }
}

@media (max-width: 900px) {
  .calculator-layout {
    flex-direction: column;
    align-items: center;
    gap: 20px;
  }
  .side-panel {
    width: 100%;
    max-width: 100%;
    min-width: 0;
    flex-basis: auto;
  }
  .side-panel .card {
    min-height: unset;
    height: auto;
  }
  .calculator-section {
    margin: 0 auto 20px;
  }
}

@media (max-width: 768px) {
  .card-columns {
    padding: 0 10px;
    gap: 10px;
    margin-top: 70px;
    grid-template-columns: 1fr
  }
  
  .card {
    padding: 15px;
    height: 120px;
  }
  
  .card-label {
    font-size: 1em;
    margin-bottom: 8px;
  }
  
  .card-value {
    font-size: 1.3em;
  }
  
  .input-card input[type="number"],
  .input-card input[type="text"] {
    max-width: 150px;
    padding: 6px;
    font-size: 0.9em;
  }
  
  .calculator-layout {
    margin: 60px auto 15px;
    gap: 15px;
  }
  
  .calculator-section {
    margin: 0 auto 15px;
    width: 100%;
    max-width: 100%;
    flex: 0 0 auto;
  }
  
  .side-panel {
    padding: 0 10px;
    margin-bottom: 45px;
  }
  
  .side-panel .card {
    margin-top: 20px;
  }

  .hashrate-input-container {
    padding-bottom: 30px;
  }
}

@media (max-width: 480px) {
  .card-columns {
    padding: 0 8px;
    gap: 8px;
  }
  
  .card {
    padding: 12px;
    min-width: 0; /* Allow cards to shrink */
  }
  
  .card-label {
    font-size: 1em;
    margin-bottom: 6px;
  }
  
  .card-value {
    font-size: 1.4em;
    word-break: break-word; /* Prevent long numbers from overflowing */
  }
  
  .input-card input[type="number"],
  .input-card input[type="text"] {
    max-width: 120px;
    padding: 5px;
    font-size: 1em;
  }
  
  .calculator-layout {
    margin: 0 auto 10px;
    gap: 10px;
  }
  
  .calculator-section {
    margin: 0 auto 10px;
  }
  
  .side-panel {
    padding: 0 8px;
  }
  
  .side-panel .card {
    margin-top: 15px;
  }
}

/* Extra small screens */
@media (max-width: 360px) {
  .card-columns {
    padding: 0 5px;
    gap: 5px;
  }
  
  .card {
    padding: 10px;
  }
  
  .card-label {
    font-size: 0.85em;
  }
  
  .card-value {
    font-size: 1.1em;
  }
  
  .input-card input[type="number"],
  .input-card input[type="text"] {
    max-width: 100px;
    padding: 4px;
    font-size: 0.8em;
  }
}

/* --- Average Hashrate Toggle & Note --- */
.avg-hashrate-toggle {
  margin-top: 0px;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 0;
  flex-wrap: nowrap;
  white-space: nowrap;
  min-height: 36px;
}

#avgPeriodSelect {
  padding: 5px 25px 5px 5px;
  font-size: 0.9em;
  border-radius: 4px;
  border: 1px solid var(--border-light);
  background: #fff var(--select-arrow-light) no-repeat right 5px center/16px;
  cursor: pointer;
  appearance: none;
  margin-left: 10px;
  width: auto;
  min-width: 90px;
}

.dark-mode #avgPeriodSelect {
  background: var(--header-bg-dark) var(--select-arrow-dark) no-repeat right 10px center/16px;
  color: var(--text-dark);
  border-color: var(--border-dark);
}

#avgHashrateNote {
  font-size: 0.95em;
  color: #888;
  margin-top: 8px;
  display: none;
  font-style: italic;
  transition: color 0.3s;
}

.dark-mode #avgHashrateNote {
  color: #bbb;
}

#avgHashrateValue {
  font-weight: bold;
  color: var(--primary-blue);
  margin-left: 4px;
}

.dark-mode #avgHashrateValue {
  color: #64b5f6;
}

/* --- Joules Consumption Styles --- */
.joules-consumption {
  margin-top: 0px;
  position: relative;
}

.joules-consumption .card-label {
  display: block;
  margin-bottom: 15px;
  font-weight: bold;
  color: var(--text-light);
}

.dark-mode .joules-consumption .card-label {
  color: var(--text-dark);
}

.menu-divider-settings {
  border: none;
  border-top: 1px solid var(--border-dark);
  margin: 5px 0 15px 0;
}

.info-icon {
  width: 16px;
  height: 16px;
  vertical-align: middle;
  margin-left: 5px;
  opacity: 0.8;
  transition: opacity 0.2s;
  filter: invert(1);
}

.dark-mode .info-icon {
  filter: none;
}

.info-icon:hover {
  opacity: 1;
}

/* Position the info icon in the top-right for these boxes */
.avg-joules-box .info-icon,
#dailyPLBox .info-icon {
  position: absolute;
  top: 8px;
  right: 8px;
}

.joules-boxes {
  display: flex;
  gap: 10px;
  justify-content: space-between;
  margin: 15px 0 10px;
}

.joules-boxes:last-child {
  margin-bottom: 0;
}

.joules-box {
  width: 130px;
  height: 130px;
  border: 1px solid var(--border-light);
  border-radius: 12px;
  padding: 15px;
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  background: #fff;
  transition: all 0.3s ease;
  box-shadow: var(--shadow-light);
}

.dark-mode .joules-box {
  background: var(--bg-dark);
  border-color: var(--border-dark);
  box-shadow: var(--shadow-dark);
}

.joules-box:hover {
  transform: translateY(-2px);
  border-color: var(--primary-blue);
}

.box-label {
  font-size: 14px;
  font-weight: bold;
  color: var(--primary-blue);
  margin-bottom: 10px;
  text-align: center;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.dark-mode .box-label {
  color: var(--primary-blue);
}

.joules-box input[type="number"] {
  width: 80px;
  height: 40px;
  padding: 8px;
  border: 1px solid var(--border-light);
  border-radius: 8px;
  background: var(--bg-light);
  color: var(--text-light);
  font-size: 16px;
  font-weight: bold;
  text-align: center;
  transition: all 0.3s ease;
  -webkit-appearance: textfield;
  -moz-appearance: textfield;
  appearance: textfield;
}

.joules-box input[type="number"]::-webkit-outer-spin-button,
.joules-box input[type="number"]::-webkit-inner-spin-button {
  -webkit-appearance: none;
  margin: 0;
}

.dark-mode .joules-box input[type="number"] {
  background: #4f4f4f;
  border-color: var(--border-dark);
  color: var(--text-dark);
}

.joules-box input[type="number"]:focus {
  outline: none;
  border-color: var(--primary-blue);
  box-shadow: 0 0 0 2px rgba(33, 150, 243, 0.1);
}

.box-value {
  font-size: 24px;
  font-weight: bold;
  color: var(--text-light);
  text-align: center;
}

.dark-mode .box-value {
  color: var(--text-dark);
}

/* Profit/Loss color overrides */
.joules-box .box-value[style*="color: #4CAF50"] {
  color: #4CAF50 !important;
}

.dark-mode .joules-box .box-value[style*="color: #4CAF50"] {
  color: #4CAF50 !important;
}

.joules-box .box-value[style*="color: #f44336"] {
  color: #f44336 !important;
}

.dark-mode .joules-box .box-value[style*="color: #f44336"] {
  color: #f44336 !important;
}

/* Clickable Box Styling */
.clickable-box {
  cursor: pointer;
  transition: transform 0.2s ease, box-shadow 0.2s ease;
}

.clickable-box:hover {
  transform: translateY(-2px);
  box-shadow: 0 4px 8px rgba(0, 0, 0, 0.15);
}

.dark-mode .clickable-box:hover {
  box-shadow: 0 4px 8px rgba(0, 0, 0, 0.3);
}

/* P/L Breakdown Popup */
.joules-box {
  position: relative;
}

.pl-breakdown-popup {
  display: none;
  position: absolute;
  top: 100%;
  left: 50%;
  transform: translateX(-50%);
  margin-top: 8px;
  background: var(--bg-light);
  border: 1px solid var(--border-light);
  border-radius: 8px;
  padding: 12px;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
  z-index: 100;
  min-width: 200px;
  font-size: 14px;
}

.dark-mode .pl-breakdown-popup {
  background: var(--bg-dark);
  border-color: var(--border-dark);
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
}

.pl-breakdown-popup .breakdown-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 4px 0;
  margin: 0;
}

.pl-breakdown-popup .breakdown-item span:first-child {
  color: var(--text-light);
  font-weight: 500;
}

.dark-mode .pl-breakdown-popup .breakdown-item span:first-child {
  color: var(--text-dark);
}

.pl-breakdown-popup .breakdown-item span:last-child {
  font-weight: bold;
  color: var(--text-light);
}

.dark-mode .pl-breakdown-popup .breakdown-item span:last-child {
  color: var(--text-dark);
}

.pl-breakdown-popup .breakdown-item.total span:last-child {
  color: var(--primary-blue);
  font-weight: 600;
}

.pl-breakdown-popup .breakdown-item.profit span:last-child {
  font-weight: 700;
  font-size: 15px;
}

.pl-breakdown-popup .breakdown-separator {
  height: 1px;
  background: var(--border-light);
  margin: 6px 0;
}

.dark-mode .pl-breakdown-popup .breakdown-separator {
  background: var(--border-dark);
}

/* Arrow pointing up to the box */
.pl-breakdown-popup::before {
  content: '';
  position: absolute;
  top: -6px;
  left: 50%;
  transform: translateX(-50%);
  width: 0;
  height: 0;
  border-left: 6px solid transparent;
  border-right: 6px solid transparent;
  border-bottom: 6px solid var(--border-light);
}

.pl-breakdown-popup::after {
  content: '';
  position: absolute;
  top: -5px;
  left: 50%;
  transform: translateX(-50%);
  width: 0;
  height: 0;
  border-left: 5px solid transparent;
  border-right: 5px solid transparent;
  border-bottom: 5px solid var(--bg-light);
}

.dark-mode .pl-breakdown-popup::before {
  border-bottom-color: var(--border-dark);
}

.dark-mode .pl-breakdown-popup::after {
  border-bottom-color: var(--bg-dark);
}

/* Avg Joules Popup */
.avg-joules-popup {
  display: none;
  position: absolute;
  top: 100%;
  left: 50%;
  right: auto;
  transform: translateX(-50%);
  margin-top: 10px;
  margin-right: 0;
  background: var(--bg-light);
  border: 1px solid var(--border-light);
  border-radius: 8px;
  padding: 12px;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
  z-index: 99999;
  min-width: 420px;
  max-width: 90vw;
  width: auto;
  font-size: 14px;
  color: var(--text-light);
}

/* Ensure the Avg Joules box can rise above other cards when popup is open */
.avg-joules-box {
  position: relative;
  z-index: 1;
}

.avg-joules-box.popup-open {
  z-index: 99998;
}

.dark-mode .avg-joules-popup {
  background: var(--bg-dark);
  border-color: var(--border-dark);
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
  color: var(--text-dark);
}

.avg-joules-popup::before {
  content: '';
  position: absolute;
  top: -6px;
  right: auto;
  left: 50%;
  transform: translateX(-50%);
  width: 0;
  height: 0;
  border-left: 6px solid transparent;
  border-right: 6px solid transparent;
  border-bottom: 6px solid var(--border-light);
}

.avg-joules-popup::after {
  content: '';
  position: absolute;
  top: -5px;
  right: auto;
  left: 50%;
  transform: translateX(-50%);
  width: 0;
  height: 0;
  border-left: 5px solid transparent;
  border-right: 5px solid transparent;
  border-bottom: 5px solid var(--bg-light);
}

.dark-mode .avg-joules-popup::before {
  border-left-color: var(--border-dark);
}

.dark-mode .avg-joules-popup::after {
  border-left-color: var(--bg-dark);
}

.avg-joules-header {
  color: var(--primary-blue);
  font-weight: bold;
  margin-bottom: 6px;
}

.avg-joules-sub {
  font-size: 12px;
  color: #777;
  margin-bottom: 8px;
}

.dark-mode .avg-joules-sub {
  color: #bbb;
}

.avg-joules-metrics {
  display: grid;
  grid-template-columns: 1fr;
  gap: 4px;
  margin-bottom: 10px;
}

/* Improve visibility of metrics in light theme */
.avg-joules-metrics > div {
  background: #fff;
  border: 1px solid var(--border-light);
  border-radius: 6px;
  padding: 6px 8px;
}

.dark-mode .avg-joules-metrics > div {
  background: #1f1f1f;
  border-color: var(--border-dark);
}

.avg-joules-lists {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}

.avg-joules-toggle {
  position: absolute;
  top: 8px;
  right: 12px;
  color: var(--primary-blue);
  cursor: pointer;
  font-weight: 600;
  user-select: none;
}

.avg-joules-toggle:hover {
  text-decoration: underline;
}

.avg-joules-list .list-title {
  font-weight: 600;
  margin-bottom: 6px;
  color: var(--text-light);
}

.dark-mode .avg-joules-list .list-title {
  color: var(--text-dark);
}

.avg-row {
  display: grid;
  grid-template-columns: 80px 110px 135px;
  gap: 4px;
  padding: 4px 0;
  border-bottom: 1px solid var(--border-light);
}

/* Treat first row as header for each list */
.avg-joules-list .avg-row:first-child {
  font-weight: 700;
  background: #f7f7f7;
  border-bottom-color: var(--border-light);
}

.dark-mode .avg-joules-list .avg-row:first-child {
  background: #2a2a2a;
  border-bottom-color: var(--border-dark);
}

.avg-row:last-child {
  border-bottom: none;
}

.dark-mode .avg-row {
  border-bottom-color: var(--border-dark);
}

/* Ensure row text is readable in dark mode */
.dark-mode .avg-row span {
  color: var(--text-dark);
}

.avg-row span {
  text-align: right;
  white-space: nowrap;
  font-variant-numeric: tabular-nums;
}

/* Add breathing room after the last column (right edge) */
.avg-joules-list .avg-row span:last-child {
  padding-right: 10px;
}

/* Clickable Cards */
.clickable-card {
  cursor: pointer;
  transition: transform 0.2s ease, box-shadow 0.2s ease;
  position: relative;
  z-index: 1;
}

.clickable-card.popup-open {
  z-index: 99998;
}

.clickable-card:hover {
  transform: translateY(-2px);
  box-shadow: 0 6px 20px rgba(0, 0, 0, 0.15);
}

.dark-mode .clickable-card:hover {
  box-shadow: 0 6px 20px rgba(0, 0, 0, 0.4);
}

/* Prevent layout shift on settings card and Joules boxes while interacting with popups */
.side-panel .card:hover {
  transform: none;
}

.avg-joules-box:hover,
#dailyPLBox:hover {
  transform: none;
}

.avg-joules-box.popup-open:hover {
  transform: none;
}

/* Formula Popup Styling */
.formula-popup {
  display: none;
  position: absolute;
  top: 100%;
  left: 50%;
  transform: translateX(-50%);
  margin-top: 8px;
  background: var(--bg-light);
  border: 1px solid var(--border-light);
  border-radius: 8px;
  padding: 16px;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
  z-index: 99999;
  min-width: 280px;
  font-size: 14px;
  pointer-events: auto;
}

.dark-mode .formula-popup {
  background: var(--bg-dark);
  border-color: var(--border-dark);
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
}

.formula-content h5 {
  color: var(--primary-blue);
  margin: 0 0 12px 0;
  font-size: 1.1em;
  font-weight: bold;
}

.dark-mode .formula-content h5 {
  color: #64b5f6;
}

.formula-content .formula-box {
  background: #f8f9fa;
  border: 1px solid var(--border-light);
  border-radius: 6px;
  padding: 12px;
  margin: 8px 0;
  font-family: 'Courier New', monospace;
}

.dark-mode .formula-content .formula-box {
  background: #1e1e1e;
  border-color: var(--border-dark);
}

.formula-content .formula-box code {
  font-size: 0.9em;
  color: var(--primary-blue);
  font-weight: bold;
  background: none;
  padding: 0;
}

.dark-mode .formula-content .formula-box code {
  color: #64b5f6;
}



/* Formula calculation styling */
.formula-calculation {
  background: #f0f8ff;
  border: 1px solid #cce7ff;
  border-radius: 6px;
  padding: 12px;
  margin: 12px 0;
  font-size: 0.9em;
}

.dark-mode .formula-calculation {
  background: #1a1a2e;
  border-color: #2d3748;
}

.formula-calculation p {
  margin: 4px 0;
  line-height: 1.4;
}

.formula-calculation strong {
  color: var(--primary-blue);
}

.dark-mode .formula-calculation strong {
  color: #64b5f6;
}

/* Arrow pointing up to the card */
.formula-popup::before {
  content: '';
  position: absolute;
  top: var(--arrow-top, -6px);
  left: 50%;
  transform: translateX(-50%);
  width: 0;
  height: 0;
  border-left: 6px solid transparent;
  border-right: 6px solid transparent;
  border-bottom: 6px solid var(--border-light);
}

.formula-popup::after {
  content: '';
  position: absolute;
  top: var(--arrow-top, -5px);
  left: 50%;
  transform: translateX(-50%);
  width: 0;
  height: 0;
  border-left: 5px solid transparent;
  border-right: 5px solid transparent;
  border-bottom: 5px solid var(--bg-light);
}

.dark-mode .formula-popup::before {
  border-bottom-color: var(--border-dark);
}

.dark-mode .formula-popup::after {
  border-bottom-color: var(--bg-dark);
}

/* Arrow pointing down when popup is above the card */
.formula-popup.above::before {
  top: auto;
  bottom: -6px;
  border-bottom: none;
  border-top: 6px solid var(--border-light);
}

.formula-popup.above::after {
  top: auto;
  bottom: -5px;
  border-bottom: none;
  border-top: 5px solid var(--bg-light);
}

.dark-mode .formula-popup.above::before {
  border-top-color: var(--border-dark);
}

.dark-mode .formula-popup.above::after {
  border-top-color: var(--bg-dark);
}





/* Responsive adjustments for formula popups */
@media (max-width: 900px) {
  .formula-popup {
    min-width: 250px;
    padding: 12px;
    font-size: 13px;
    /* Ensure popup is always visible on smaller screens */
    max-width: calc(100vw - 40px);
    left: 50%;
    transform: translateX(-50%);
  }
  
  .formula-content h5 {
    font-size: 1em;
    margin: 0 0 10px 0;
  }
  
  .formula-content .formula-box {
    padding: 8px;
  }
  
  .formula-content .formula-box code {
    font-size: 0.8em;
  }
  
  .formula-content .formula-description {
    font-size: 0.8em !important;
  }
}

@media (max-width: 600px) {
  .formula-popup {
    min-width: 220px;
    padding: 10px;
    font-size: 12px;
  }
  
  .formula-content h5 {
    font-size: 0.95em;
    margin: 0 0 8px 0;
  }
  
  .formula-content .formula-box {
    padding: 6px;
  }
  
  .formula-content .formula-box code {
    font-size: 0.75em;
  }
  
  .formula-content .formula-description {
    font-size: 0.75em !important;
  }
  
  /* Mobile tooltip adjustments */
  .clickable-card .tooltip .tooltiptext {
    width: 180px;
    font-size: 0.75em;
  }
  
  .clickable-card .tooltip .info-icon {
    width: 14px;
    height: 14px;
  }
}

@media (max-width: 768px) {
  .card-columns {
    padding: 0;
    gap: 10px;
    margin-top: 70px;
    grid-template-columns: repeat(2, 1fr); /* Change to display two columns on mobile */
  }
  
  .column-left,
  .column-right {
    grid-column: span 1; /* Adjust the column spans for better distribution */
  }

   .joules-boxes {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 10px;
  }
  
  .joules-box {
    width: 100%;
    height: 130px;
    padding: 12px;
  }
  
  .box-label {
    font-size: 13px;
    margin-bottom: 8px;
  }
  
  .box-value {
    font-size: 22px;
  }

  #avgPeriodSelect {
    float: right;
    margin-left: 120px;
    min-width: 80px;
  }

  .formula-popup {
    width: 90%;
    max-width: 320px;
    left: 50%;
    transform: translateX(-50%);
  }
  
  .formula-content {
    padding: 15px;
  }
  
  .formula-box {
    font-size: 1.3em;
    padding: 12px;
  }
  
  .formula-calculation {
    font-size: 1.15em;
  }
}

@media (max-width: 768px) {
  .avg-joules-popup {
    top: 100%;
    left: 100%;
    right: 100%;
    transform: translateX(-50%);
    margin-top: 10px;
    margin-right: 0;
    width: 90vw;
    max-width: 90vw;
  }
  
  .avg-joules-popup::before {
    top: -6px;
    right: auto;
    left: 20%;
    transform: translateX(0);
    border-left: 6px solid transparent;
    border-right: 6px solid transparent;
    border-top: none;
    border-bottom: 6px solid var(--border-light);
  }
  
  .avg-joules-popup::after {
    top: -5px;
    right: auto;
    left: 20%;
    transform: translateX(0);
    border-left: 5px solid transparent;
    border-right: 5px solid transparent;
    border-top: none;
    border-bottom: 5px solid var(--bg-light);
  }
  
  .dark-mode .avg-joules-popup::before {
    border-bottom-color: var(--border-dark);
    border-left-color: transparent;
  }
  
  .dark-mode .avg-joules-popup::after {
    border-bottom-color: var(--bg-dark);
    border-left-color: transparent;
  }

  .avg-joules-lists {
    display: grid;
    grid-template-columns: 1fr;
    gap: 15px;
  }
}

.input-card.modified {
  border: 2px solid var(--primary-blue);
  background: rgba(33, 150, 243, 0.1);
  box-shadow: 0 0 10px rgba(33, 150, 243, 0.3);
}

.dark-mode .input-card.modified {
  border: 2px solid #64b5f6;
  background: rgba(100, 181, 246, 0.1);
  box-shadow: 0 0 10px rgba(100, 181, 246, 0.3);
}

.input-card.modified .card-label {
  color: var(--primary-blue);
  font-weight: bold;
}

.dark-mode .input-card.modified .card-label {
  color: #64b5f6;
}

.avg-joules-box .input-container {
  margin-top: 5px;
  width: 100%;
}

.avg-joules-box input[type="text"] {
  width: 100%;
  padding: 4px 8px;
  font-size: 18px;
  border: 1px solid var(--border-color);
  border-radius: 4px;
  background-color: var(--card-bg);
  color: var(--text-color);
}

@media (max-width: 768px) {
  .avg-joules-box input[type="text"] {
    font-size: 16px;
    padding: 3px 6px;
  }
}

/* Project Cancellation Notification */
.notification-overlay {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background-color: rgba(0, 0, 0, 0.6);
  display: flex;
  justify-content: center;
  align-items: center;
  z-index: 2000;
  backdrop-filter: blur(2px);
}

.notification-box {
  background: var(--bg-light);
  border: 2px solid #ff6b6b;
  border-radius: 12px;
  padding: 30px;
  max-width: 500px;
  width: 90%;
  max-height: 80vh;
  overflow-y: auto;
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.3);
  position: relative;
  text-align: center;
  animation: notificationSlideIn 0.3s ease-out;
}

.dark-mode .notification-box {
  background: var(--bg-dark);
  border-color: #ff8a8a;
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.6);
}

.notification-close {
  position: absolute;
  top: 15px;
  right: 20px;
  background: none;
  border: none;
  font-size: 28px;
  cursor: pointer;
  color: #666;
  padding: 0;
  width: 30px;
  height: 30px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 50%;
  transition: all 0.2s ease;
}

.notification-close:hover {
  background-color: rgba(255, 107, 107, 0.1);
  color: #ff6b6b;
  transform: scale(1.1);
}

.dark-mode .notification-close {
  color: #ccc;
}

.dark-mode .notification-close:hover {
  background-color: rgba(255, 138, 138, 0.2);
  color: #ff8a8a;
}

.notification-icon {
  font-size: 48px;
  margin-bottom: 20px;
  display: block;
}

.notification-title {
  color: #ff6b6b;
  margin-bottom: 20px;
  font-size: 28px;
  font-weight: bold;
}

.dark-mode .notification-title {
  color: #ff8a8a;
}

.notification-message {
  color: var(--text-light);
  line-height: 1.6;
  margin-bottom: 20px;
  font-size: 16px;
}

.dark-mode .notification-message {
  color: var(--text-dark);
}

.notification-date {
  color: #666;
  font-size: 14px;
  font-style: italic;
  margin-top: 15px;
}

.dark-mode .notification-date {
  color: #999;
}

@keyframes notificationSlideIn {
  from {
    opacity: 0;
    transform: scale(0.8) translateY(-20px);
  }
  to {
    opacity: 1;
    transform: scale(1) translateY(0);
  }
}

@media (max-width: 768px) {
  .notification-box {
    padding: 25px 20px;
    margin: 20px;
  }
  
  .notification-title {
    font-size: 24px;
  }
  
  .notification-message {
    font-size: 15px;
  }
  
  .notification-icon {
    font-size: 40px;
  }
}