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

:root {
  --primary: #3b82f6;
  --success: #22c55e;
  --danger: #ef4444;
  --gray-50: #f9fafb;
  --gray-100: #f3f4f6;
  --gray-200: #e5e7eb;
  --gray-300: #d1d5db;
  --gray-400: #9ca3af;
  --gray-500: #6b7280;
  --gray-600: #4b5563;
  --gray-700: #374151;
  --gray-800: #1f2937;
  --radius: 8px;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  background: var(--gray-100);
  color: var(--gray-800);
  line-height: 1.5;
}

.container {
  max-width: 800px;
  margin: 0 auto;
  padding: 20px;
}

section {
  background: white;
  border-radius: var(--radius);
  padding: 20px;
  margin-bottom: 16px;
  box-shadow: 0 1px 3px rgba(0,0,0,0.1);
}

/* Current Price */
.current-price-section {
  text-align: center;
  padding: 24px;
}

.price-label {
  font-size: 0.875rem;
  color: var(--gray-500);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  margin-bottom: 8px;
}

.price-display {
  display: flex;
  align-items: baseline;
  justify-content: center;
  gap: 4px;
}

.price-value {
  font-size: 3rem;
  font-weight: 700;
  color: var(--gray-800);
}

.price-unit {
  font-size: 1.25rem;
  color: var(--gray-500);
}

.price-total {
  margin-top: 8px;
  font-size: 0.875rem;
  color: var(--gray-600);
}

.pkg-tooltip {
  position: relative;
  border-bottom: 1px dotted var(--gray-400);
  cursor: help;
}

.pkg-tooltip::before,
.pkg-tooltip::after {
  position: absolute;
  opacity: 0;
  visibility: hidden;
  transition: opacity 0.2s, visibility 0.2s;
  pointer-events: none;
}

.pkg-tooltip::before {
  content: attr(data-tooltip);
  bottom: 100%;
  left: 50%;
  transform: translateX(-50%);
  margin-bottom: 8px;
  background: var(--gray-800);
  color: white;
  padding: 8px 12px;
  border-radius: 6px;
  font-size: 0.75rem;
  white-space: nowrap;
  box-shadow: 0 4px 12px rgba(0,0,0,0.3);
  z-index: 1000;
}

.pkg-tooltip::after {
  content: '';
  bottom: 100%;
  left: 50%;
  transform: translateX(-50%);
  margin-bottom: 2px;
  border: 6px solid transparent;
  border-top-color: var(--gray-800);
}

.pkg-tooltip:hover::before,
.pkg-tooltip:hover::after {
  opacity: 1;
  visibility: visible;
}

/* Duration Buttons */
.duration-buttons-wrapper {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 8px;
  min-width: 150px;
}

.duration-buttons-label {
  font-size: 0.85rem;
  color: var(--gray-600);
}

.duration-buttons-row {
  display: flex;
  gap: 8px;
  align-items: center;
  flex-wrap: wrap;
}

.duration-buttons {
  display: flex;
  background: var(--gray-100);
  border-radius: var(--radius);
  padding: 3px;
  gap: 2px;
}

.duration-btn {
  padding: 6px 10px;
  border: none;
  background: transparent;
  border-radius: 6px;
  cursor: pointer;
  font-size: 0.8rem;
  color: var(--gray-600);
  transition: all 0.15s;
}

.duration-btn:hover {
  background: var(--gray-200);
}

.duration-btn.active {
  background: var(--success);
  color: white;
  box-shadow: 0 1px 2px rgba(0,0,0,0.1);
}

.duration-custom {
  display: flex;
  align-items: center;
  gap: 2px;
}

.duration-custom input {
  width: 50px;
  padding: 6px 4px;
  border: 1px solid var(--gray-300);
  border-radius: 0;
  font-size: 0.8rem;
  text-align: center;
}

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

.duration-adjust-btn {
  width: 28px;
  height: 30px;
  border: 1px solid var(--gray-300);
  background: var(--gray-100);
  cursor: pointer;
  font-size: 1rem;
  font-weight: bold;
  color: var(--gray-600);
  display: flex;
  align-items: center;
  justify-content: center;
}

.duration-adjust-btn:first-child {
  border-radius: var(--radius) 0 0 var(--radius);
}

.duration-adjust-btn:last-child {
  border-radius: 0 var(--radius) var(--radius) 0;
}

.duration-adjust-btn:hover {
  background: var(--gray-200);
}

.duration-adjust-btn:active {
  background: var(--gray-300);
}

.toggle-label-text {
  font-size: 0.85rem;
  color: var(--gray-600);
  margin-bottom: 6px;
}

/* Package selector */
.package-select .setting-input-group {
  display: flex;
  gap: 8px;
  align-items: center;
}

#networkPackage {
  padding: 8px 10px;
  border-radius: var(--radius);
  border: 2px solid var(--gray-200);
  background: white;
  font-weight: 600;
}

/* Compact package selector in chart header */
#networkPackageTop {
  padding: 6px 10px;
  border: 2px solid var(--gray-200);
  background: white;
  border-radius: 8px;
  font-size: 0.85rem;
  color: var(--gray-600);
  cursor: pointer;
  transition: all 0.15s;
  font-weight: 500;
  max-width: 120px;
  appearance: none;
  -webkit-appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 24 24' fill='none' stroke='%236b7280' stroke-width='2'%3E%3Cpath d='M6 9l6 6 6-6'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 8px center;
  padding-right: 26px;
}

#networkPackageTop:hover {
  border-color: var(--primary);
  color: var(--primary);
}

#networkPackageTop:focus {
  outline: none;
  border-color: var(--primary);
}

.package-info {
  font-size: 0.85rem;
  color: var(--gray-700);
}

/* Mode section (below chart) */
.mode-section {
  padding: 16px 20px;
}

.mode-row {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 16px;
}

/* Toggles on the right side */
.toggles-right {
  display: flex;
  gap: 16px;
  flex-shrink: 0;
}

/* Allow wrapping so compact groups don't overlap adjacent items */
.toggles-right {
  flex-wrap: wrap;
  align-items: flex-start;
}

.toggle-group {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 4px;
}

.toggle-label {
  font-size: 0.7rem;
  color: var(--gray-500);
}

.toggle-buttons {
  display: flex;
  background: var(--gray-100);
  border-radius: var(--radius);
  padding: 3px;
  gap: 2px;
}

.toggle-btn {
  padding: 6px 12px;
  border: none;
  background: transparent;
  border-radius: calc(var(--radius) - 2px);
  font-size: 0.75rem;
  font-weight: 600;
  color: var(--gray-500);
  cursor: pointer;
  transition: all 0.2s;
}

.toggle-btn:hover {
  color: var(--gray-700);
}

.toggle-btn.active {
  background: var(--success);
  color: white;
  box-shadow: 0 1px 2px rgba(0,0,0,0.1);
}

/* Vertical compact grouping for stacked toggle buttons */
.toggle-vertical {
  display: flex;
  flex-direction: column;
  gap: 6px;
  align-items: center;
}

.toggle-vertical .toggle-buttons {
  width: 160px;
  justify-content: center;
}

/* Compact wrapper for vertical toggle groups */
.compact-toggle-block {
  display: inline-flex;
  flex-direction: column;
  gap: 6px;
  min-width: 160px;
}

/* Resolution (Period) toggle group - small styling */
.toggle-group #resolutionButtons {
  width: auto;
}

.toggle-group #resolutionButtons .toggle-btn {
  padding: 6px 10px;
  font-size: 0.75rem;
}

/* Price direction specific active styling */
.toggle-buttons#priceDirectionButtons .toggle-btn.active[data-price="expensive"] {
  background: var(--danger);
  color: white;
  box-shadow: 0 1px 2px rgba(0,0,0,0.08);
}

/* Countdown red styling for expensive selection */
.countdown-card.expensive {
  background: rgba(239, 68, 68, 0.12);
  border: 1px solid rgba(239, 68, 68, 0.25);
}
.countdown-card.expensive .info-value {
  color: var(--danger);
}

.info-sub {
  margin-top: 6px;
  font-size: 0.8rem;
  color: var(--gray-600);
}

/* Small note for inputs */
/* Removed special excl-VAT note for security fee — fee is included in VAT calculation like others */

/* Chart */
.chart-section {
  padding: 20px;
  position: relative;
}

.chart-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 12px;
  padding: 0 10px 0 50px;
}

.chart-header-buttons {
  display: flex;
  gap: 6px;
  align-items: center;
}

/* small spacing for the new chart header toggle */
.chart-toggle {
  padding: 6px 8px;
}

.package-select-label {
  font-size: 0.8rem;
  color: var(--gray-600);
  margin-right: 2px;
}

.chart-toggle.active {
  background: var(--success);
  color: white;
}

.chart-date {
  font-size: 0.875rem;
  font-weight: 600;
  color: var(--gray-700);
}

.chart-toggle {
  padding: 6px 10px;
  border: 2px solid var(--gray-200);
  background: white;
  border-radius: 8px;
  font-size: 0.85rem;
  color: var(--gray-600);
  cursor: pointer;
  transition: all 0.15s;
}

.chart-toggle:hover {
  border-color: var(--primary);
  color: var(--primary);
}

/* Expanded chart view: widen only the chart section to full viewport width (keep original height) */
body.chart-expanded .chart-section {
  width: 100vw;
  margin-left: calc(50% - 50vw);
  z-index: 2000;
  box-shadow: 0 8px 24px rgba(0,0,0,0.08);
}

body.chart-expanded .chart-wrapper {
  max-width: 100vw;
}

.chart-unit {
  font-size: 0.75rem;
  color: var(--gray-500);
  font-weight: 500;
}

.chart-wrapper {
  position: relative;
}

.chart-container {
  display: flex;
  gap: 0;
}

.chart-y-axis {
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  padding: 0 6px 18px 0;
  font-size: 0.7rem;
  color: var(--gray-800);
  text-align: right;
  min-width: 32px;
  font-weight: 500;
}

.chart-y-axis span {
  transform: translateY(-50%);
}

.chart-y-axis span:first-child {
  transform: translateY(0);
}

.chart-y-axis span:last-child {
  transform: translateY(-100%);
}

.chart-area {
  flex: 1;
  position: relative;
  border-left: 1px solid var(--gray-300);
  border-bottom: 1px solid var(--gray-300);
  overflow: hidden;
}

.chart-zero-line {
  position: absolute;
  left: 0;
  right: 0;
  height: 1px;
  background: var(--gray-400);
  z-index: 5;
}

.chart {
  position: relative;
  height: 250px;
  padding: 10px 0 0 0;
}

.chart-canvas {
  width: 100%;
  height: 100%;
  display: block;
}

.chart-x-axis {
  display: flex;
  justify-content: space-between;
  font-size: 0.7rem;
  color: var(--gray-800);
  padding: 2px 5px 0 5px;
  font-weight: 500;
}

.chart-x-label {
  text-align: center;
  line-height: 1;
}

.chart-tooltip {
  position: absolute;
  background: var(--gray-800);
  color: white;
  padding: 8px 12px;
  border-radius: 6px;
  font-size: 0.75rem;
  white-space: nowrap;
  z-index: 1000;
  transform: translateX(-50%);
  box-shadow: 0 4px 12px rgba(0,0,0,0.3);
  pointer-events: none;
}

.chart-tooltip::after {
  content: '';
  position: absolute;
  top: 100%;
  left: 50%;
  transform: translateX(-50%);
  border: 6px solid transparent;
  border-top-color: var(--gray-800);
}

.chart-tooltip.tooltip-below {
  transform: translateX(-50%);
}

.chart-tooltip.tooltip-below::after {
  top: auto;
  bottom: 100%;
  border-top-color: transparent;
  border-bottom-color: var(--gray-800);
}


.chart-legend {
  display: flex;
  justify-content: center;
  gap: 16px;
  margin-top: 16px;
  flex-wrap: wrap;
}

.legend-item {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 0.75rem;
  color: var(--gray-600);
}

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

.legend-color.future {
  background: #1e40af;
  width: 20px;
  height: 3px;
  border-radius: 2px;
}

.legend-color.best {
  background: var(--success);
  width: 20px;
  height: 3px;
  border-radius: 2px;
}

.legend-color.current-line {
  background: repeating-linear-gradient(
    to right,
    var(--danger) 0px,
    var(--danger) 3px,
    transparent 3px,
    transparent 6px
  );
  width: 20px;
  height: 2px;
}

/* Info Cards */
.best-time-section {
  padding: 16px;
}

.info-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 12px;
}

@media (min-width: 500px) {
  .info-grid {
    grid-template-columns: repeat(5, 1fr);
  }
}

.info-card {
  text-align: center;
  padding: 12px;
  background: var(--gray-50);
  border-radius: var(--radius);
}

.info-label {
  font-size: 0.75rem;
  color: var(--gray-500);
  margin-bottom: 4px;
}

.info-value {
  font-size: 1rem;
  font-weight: 600;
  color: var(--gray-800);
}

.countdown-card {
  background: rgba(34, 197, 94, 0.15);
  border: 1px solid rgba(34, 197, 94, 0.3);
}

.countdown-card .info-value {
  color: var(--success);
}

/* Calculator */
.calculator-section summary {
  cursor: pointer;
  font-weight: 600;
  color: var(--gray-700);
  padding: 4px 0;
}

.calculator-row {
  display: flex;
  flex-wrap: wrap;
  gap: 16px;
  align-items: flex-start;
}

.calculator-input {
  flex: 0 0 auto;
}

.calc-input-label {
  font-size: 0.85rem;
  color: var(--gray-600);
  margin-bottom: 6px;
}

.calc-input-group {
  display: flex;
  align-items: center;
  gap: 2px;
}

.calc-input-group input {
  width: 50px;
  padding: 6px 4px;
  border: 1px solid var(--gray-300);
  border-radius: 0;
  font-size: 0.8rem;
  text-align: center;
}

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

.calc-input-group .input-unit {
  padding: 6px 8px;
  background: transparent;
  border: none;
  color: var(--gray-500);
  font-size: 0.8rem;
  font-size: 0.875rem;
}

.calculator-results {
  flex: 1;
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
}

.calc-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 12px;
}

.calc-card {
  text-align: center;
  padding: 12px 8px;
  background: var(--gray-50);
  border-radius: var(--radius);
}

.calc-card.optimal {
  background: #dcfce7;
}

.calc-card.savings {
  background: #fef3c7;
}

.calc-card.savings.hidden {
  display: none;
}

.calc-card .calc-label {
  font-size: 0.7rem;
  color: var(--gray-500);
  margin-bottom: 4px;
}

.calc-card .calc-value {
  font-size: 1rem;
  font-weight: 700;
  color: var(--gray-800);
}

.calc-card.optimal .calc-value {
  color: var(--success);
}

.calc-card.savings .calc-value {
  color: #92400e;
}

.calc-card .calc-input-group {
  justify-content: center;
}

/* Chart Settings Section */
.chart-settings-section {
  background: white;
}

.chart-settings-section summary {
  cursor: pointer;
  font-weight: 600;
  color: var(--gray-700);
  padding: 4px 0;
}

.chart-settings-content {
  padding-top: 16px;
}

.toggle-setting {
  margin-bottom: 12px;
}

.toggle-label {
  display: flex;
  align-items: center;
  gap: 10px;
  cursor: pointer;
  font-size: 0.9rem;
  color: var(--gray-700);
}

.toggle-label input[type="checkbox"] {
  width: 18px;
  height: 18px;
  cursor: pointer;
  accent-color: var(--primary);
}

.toggle-text {
  font-weight: 500;
}

.toggle-note {
  font-size: 0.8rem;
  color: var(--gray-500);
  margin-top: 6px;
  margin-left: 28px;
}

/* Chart legend dual line colors */
.legend-color.spot-line {
  background: #f59e0b;
  width: 20px;
  height: 3px;
  border-radius: 2px;
}

.legend-color.full-line {
  background: #8b5cf6;
  width: 20px;
  height: 3px;
  border-radius: 2px;
}

/* Settings */
.settings-section {
  background: white;
}

.settings-section summary {
  cursor: pointer;
  font-weight: 600;
  color: var(--gray-700);
  padding: 4px 0;
}

.settings-content {
  padding-top: 16px;
}

.settings-note {
  font-size: 0.8rem;
  color: var(--gray-500);
  margin-bottom: 12px;
}

.settings-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 12px;
  margin-bottom: 16px;
}

.setting-item label {
  display: block;
  font-size: 0.8rem;
  color: var(--gray-600);
  margin-bottom: 4px;
}

.setting-input-group {
  display: flex;
}

.setting-input-group input {
  flex: 1;
  min-width: 60px;
  padding: 6px 8px;
  border: 1px solid var(--gray-300);
  border-radius: var(--radius) 0 0 var(--radius);
  font-size: 0.875rem;
  outline: none;
}

.setting-input-group input:focus {
  border-color: var(--primary);
}

.setting-input-group .unit {
  padding: 6px 8px;
  background: var(--gray-100);
  border: 1px solid var(--gray-300);
  border-left: none;
  border-radius: 0 var(--radius) var(--radius) 0;
  color: var(--gray-500);
  font-size: 0.75rem;
  white-space: nowrap;
}

.settings-actions {
  text-align: right;
}

.btn-secondary {
  padding: 8px 14px;
  background: var(--gray-100);
  border: 1px solid var(--gray-300);
  border-radius: var(--radius);
  color: var(--gray-600);
  font-size: 0.875rem;
  cursor: pointer;
}

.btn-secondary:hover {
  background: var(--gray-200);
}

/* Data info / Footer */
.data-info {
  background: transparent;
  box-shadow: none;
  text-align: center;
  font-size: 0.75rem;
  color: var(--gray-500);
  padding: 16px 0 0 0;
  margin-top: 16px;
  border-top: 1px solid var(--gray-200);
}

.data-info p {
  margin-bottom: 4px;
}

.data-info a {
  color: var(--primary);
  text-decoration: none;
}

.data-info a:hover {
  text-decoration: underline;
}

.disclaimer {
  font-style: italic;
}

/* Mobile */
@media (max-width: 600px) {
  .container {
    padding: 10px;
  }

  .price-value {
    font-size: 2.5rem;
  }

  .duration-btn {
    padding: 6px 10px;
    font-size: 0.8rem;
  }

  .chart-section {
    padding: 12px;
  }

  .chart-header {
    padding: 0 5px 0 35px;
    flex-wrap: wrap;
    gap: 4px;
  }

  .package-select-label {
    display: none;
  }

  #networkPackageTop {
    max-width: 90px;
    font-size: 0.75rem;
    padding: 5px 22px 5px 6px;
  }

  .chart-date {
    font-size: 0.75rem;
  }

  .chart {
    height: 200px;
    padding: 8px 3px 0 3px;
  }

  .chart-y-axis {
    min-width: 28px;
    font-size: 0.6rem;
    padding: 0 4px 14px 0;
  }

  .chart-x-axis {
    font-size: 0.6rem;
    padding: 2px 3px 0 3px;
  }

  .info-grid {
    grid-template-columns: repeat(2, 1fr);
    gap: 8px;
  }

  .info-card {
    padding: 10px 6px;
  }

  .info-label {
    font-size: 0.65rem;
  }

  .info-value {
    font-size: 0.875rem;
  }

  .calc-grid {
    grid-template-columns: repeat(2, 1fr);
  }

  .mode-row {
    flex-direction: column;
    align-items: stretch;
    gap: 12px;
  }

  .toggles-right {
    justify-content: flex-start;
  }

  .chart-legend {
    gap: 10px;
    font-size: 0.65rem;
  }

  .legend-item {
    font-size: 0.65rem;
  }
}
