html,
body {
  width: 100%;
  height: 100%;
}

body {
  padding: 0;
  margin: 0;
  background-color: #222;
  overflow-x: hidden;
}

body.fullscreen-mode,
body.embed-mode {
  overflow: hidden;
}

/* ===== Layout Containers ===== */
#topContainer {
  position: absolute;
  width: 100%;
  background-color: #333;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 10px 0;
  box-sizing: border-box;
  z-index: 10;
}

.controls-row {
  display: flex;
  align-items: center;
  justify-content: center;
  flex-wrap: wrap;
  /* gap: 5px; */
  padding: 0 7px;
}

.controls-row input,
.controls-row select {
  margin: 5px;
  padding: 8px;
  border: none;
  border-radius: 4px;
  font-size: 14px;
}

.controls-row label {
  color: white;
  display: flex;
  align-items: center;
  margin: 5px 10px;
  font-size: 14px;
  white-space: nowrap;
}

.controls-row label input[type="checkbox"] {
  margin-right: 5px;
}

#mainWrapper {
  display: flex;
  position: absolute;
  width: 100%;
  height: calc(100% - 120px);
  top: 120px;
}

#container {
  flex: 1;
  height: 100%;
  min-width: 0;
}

#rightPanel {
  width: 250px;
  min-width: 200px;
  height: 100%;
  background-color: #333;
  padding: 10px;
  box-sizing: border-box;
  overflow-y: auto;
}

#rightPanel h3 {
  color: white;
  margin: 0 0 10px 0;
}

#rightPanel input[type="text"] {
  width: calc(100% - 100px);
  margin: 5px 0;
  padding: 8px;
  border: none;
  border-radius: 4px;
  box-sizing: border-box;
}

/* ===== Mobile Toggle Button ===== */
#mobileMenuToggle {
  display: none;
  position: fixed;
  bottom: 20px;
  right: 20px;
  width: 50px;
  height: 50px;
  border-radius: 50%;
  background-color: #4CAF50;
  color: white;
  border: none;
  font-size: 24px;
  cursor: pointer;
  z-index: 1001;
  box-shadow: 0 2px 10px rgba(0, 0, 0, 0.3);
}

#mobileMenuToggle:hover {
  background-color: #45a049;
}

/* ===== Settings ===== */
#settingsButton {
  position: fixed;
  top: 10px;
  right: 10px;
  z-index: 1000;
  padding: 8px 16px;
  background-color: #4CAF50;
  color: white;
  border: none;
  border-radius: 4px;
  cursor: pointer;
}

#settingsButton:hover {
  background-color: #45a049;
}

/* Icon-only button (used for fullscreen toggle) */
.icon-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
}

#fullscreenButton {
  position: fixed;
  top: 6px;
  left: 6px;
  z-index: 1000;
  width: 26px;
  height: 26px;
  padding: 0;
  background: rgba(76, 175, 80, 0.95);
  color: #ffffff;
  border: 1px solid rgba(255, 255, 255, 0.18);
  border-radius: 7px;
  cursor: pointer;
  box-shadow: 0 2px 10px rgba(0, 0, 0, 0.25);
}

#fullscreenButton:hover {
  background: rgba(69, 160, 73, 0.98);
}

#fullscreenButton:active {
  transform: translateY(1px);
}

#fullscreenButton .icon {
  width: 14px;
  height: 14px;
  display: block;
}

/* Default state: show "enter fullscreen" icon */
#fullscreenButton .icon-exit {
  display: none;
}

/* In fullscreen-mode: show "exit" icon */
body.fullscreen-mode #fullscreenButton .icon-enter {
  display: none;
}

body.fullscreen-mode #fullscreenButton .icon-exit {
  display: block;
}

/* Fullscreen chart mode (hide UI chrome) */
body.fullscreen-mode #topContainer,
body.embed-mode #topContainer {
  display: none;
}

body.fullscreen-mode #rightPanel,
body.embed-mode #rightPanel {
  display: none !important;
}

body.fullscreen-mode #panelOverlay,
body.embed-mode #panelOverlay {
  display: none !important;
}

body.fullscreen-mode #settingsButton,
body.embed-mode #settingsButton {
  display: none;
}

body.fullscreen-mode #mobileMenuToggle,
body.embed-mode #mobileMenuToggle {
  display: none;
}

body.fullscreen-mode #settingsOverlay,
body.embed-mode #settingsOverlay {
  display: none !important;
}

body.fullscreen-mode #mainWrapper,
body.embed-mode #mainWrapper {
  top: 0 !important;
  width: 100% !important;
  height: 100vh !important;
  height: 100dvh !important;
  position: fixed;
}

body.embed-mode #fullscreenButton {
  display: none !important;
}

#settingsOverlay {
  display: none;
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(0, 0, 0, 0.5);
  z-index: 999;
}

#settingsContent {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  background: white;
  padding: 20px;
  border-radius: 10px;
  box-shadow: 0 4px 8px rgba(0, 0, 0, 0.2);
  max-width: 90vw;
  max-height: 90vh;
  overflow-y: auto;
}

.settingsRow {
  margin-bottom: 10px;
  display: flex;
  flex-wrap: wrap;
  gap: 5px;
  align-items: center;
}

.settingsRow input,
.settingsRow select {
  padding: 5px;
  border-radius: 4px;
  border: 1px solid #ccc;
}

#saveSettingsButton {
  background-color: #4CAF50;
  color: white;
  padding: 10px 20px;
  border: none;
  border-radius: 5px;
  cursor: pointer;
  width: 100%;
  margin-top: 10px;
}

#saveSettingsButton:hover {
  background-color: #45a049;
}

/* ===== Buttons ===== */
.btn {
  background-color: #4CAF50;
  border: none;
  color: white;
  padding: 10px 20px;
  text-align: center;
  text-decoration: none;
  display: inline-block;
  font-size: 16px;
  margin: 4px 2px;
  cursor: pointer;
  border-radius: 5px;
}

.btn:hover {
  background-color: #45a049;
}

/* ===== Watchlist ===== */
.watchlist {
  max-height: 400px;
  overflow-y: auto;
  padding: 0;
  margin: 0;
  list-style-type: none;
}

.watchlist li {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 8px 5px;
  border-bottom: 1px solid #555;
  color: white;
  cursor: pointer;
}

.watchlist li:hover {
  background-color: #575757;
}

.watchlist button {
  background-color: #f48b36;
  border: none;
  color: white;
  padding: 5px 10px;
  text-align: center;
  text-decoration: none;
  display: inline-block;
  font-size: 14px;
  margin: 0 2px;
  cursor: pointer;
  border-radius: 5px;
}

.watchlist button:hover {
  background-color: #df6a1c;
}

/* ===== Tools List ===== */
.tools-list {
  list-style-type: none;
  padding: 0;
  color: white;
}

.tools-list li {
  padding: 8px 5px;
  cursor: pointer;
  border-bottom: 1px solid #555;
}

.tools-list li:hover {
  background-color: #575757;
}

/* ===== RESPONSIVE: Tablets (768px and below) ===== */
@media screen and (max-width: 768px) {
  #topContainer {
    padding: 8px 5px;
  }

  .controls-row {
    gap: 3px;
  }

  .controls-row input,
  .controls-row select {
    padding: 6px;
    font-size: 13px;
    margin: 3px;
  }

  .controls-row label {
    font-size: 12px;
    margin: 3px 5px;
  }

  #mainWrapper {
    height: calc(100% - 110px);
    top: 110px;
  }

  #rightPanel {
    position: fixed;
    right: -260px;
    top: 0;
    height: 100%;
    width: 250px;
    z-index: 100;
    transition: right 0.3s ease;
    padding-top: 120px;
  }

  #rightPanel.open {
    right: 0;
  }

  #container {
    width: 100%;
  }

  #mobileMenuToggle {
    display: block;
  }

  #settingsButton {
    top: auto;
    bottom: 80px;
    right: 20px;
    padding: 6px 12px;
    font-size: 14px;
  }

  /* Keep fullscreen button top-left on mobile too (it is small/icon-only). */

  .btn {
    padding: 8px 16px;
    font-size: 14px;
  }
}

/* ===== RESPONSIVE: Mobile Portrait (480px and below) ===== */
@media screen and (max-width: 480px) {
  #topContainer {
    padding: 4px 5px;
  }

  .controls-row {
    width: 100%;
    justify-content: center;
  }

  .controls-row input[type="text"],
  .controls-row input[type="date"],
  .controls-row select {
    width: calc(50% - 10px);
    min-width: 92px;
    padding: 6px;
    font-size: 13px;
    margin: 2px;
  }

  .controls-row input[type="time"] {
    width: 78px;
    padding: 4px 5px;
    font-size: 12px;
    margin: 0 0 0 3px;
  }

  .controls-row label {
    font-size: 10px;
    margin: 1px 3px;
  }

  /* Keep the intraday toggles on one line */
  #topContainer .controls-row:nth-child(2) {
    flex-wrap: nowrap;
    gap: 2px;
  }

  #topContainer .controls-row:nth-child(2) label {
    margin: 0 2px;
  }

  #topContainer .controls-row:nth-child(2) input[type="checkbox"] {
    margin-right: 3px;
    transform: scale(0.9);
    transform-origin: left center;
  }

  .controls-row:last-child {
    margin-top: 5px;
  }

  #mainWrapper {
    height: calc(100% - 130px);
    top: 130px;
  }

  #rightPanel {
    width: 100%;
    right: -100%;
    padding-top: 140px;
  }

  #rightPanel.open {
    right: 0;
  }

  #settingsContent {
    width: 95vw;
    padding: 15px;
  }

  .settingsRow {
    flex-direction: row;
    justify-content: space-between;
  }

  .settingsRow select {
    flex: 1;
    min-width: 80px;
  }

  .settingsRow input[type="number"] {
    width: 50px;
  }

  .settingsRow input[type="color"] {
    width: 40px;
    height: 30px;
    padding: 0;
  }

  .watchlist {
    max-height: 300px;
  }

  #mobileMenuToggle {
    width: 45px;
    height: 45px;
    font-size: 20px;
    bottom: 15px;
    right: 15px;
  }

  #settingsButton {
    bottom: 70px;
    right: 15px;
    padding: 5px 10px;
    font-size: 12px;
  }

  /* Keep fullscreen button top-left on mobile too (it is small/icon-only). */
}

/* ===== RESPONSIVE: Mobile Landscape ===== */
@media screen and (max-height: 500px) and (orientation: landscape) {
  #topContainer {
    padding: 3px 5px;
    flex-direction: row;
    flex-wrap: nowrap;
    justify-content: center;
  }

  .controls-row {
    margin: 0;
    padding: 0 4px;
    flex-wrap: nowrap;
  }

  .controls-row:last-child {
    margin-left: 6px;
  }

  .controls-row input,
  .controls-row select {
    padding: 4px;
    font-size: 12px;
    margin: 2px;
  }

  .controls-row label {
    font-size: 11px;
    margin: 1px 3px;
  }

  /* Compress toggle row in landscape so both control groups fit side-by-side */
  .controls-row label input[type="checkbox"] {
    margin-right: 3px;
    transform: scale(0.9);
    transform-origin: left center;
  }

  #scrollToTimeValue {
    width: 90px;
    padding: 3px 5px;
    font-size: 12px;
    margin: 0 0 0 3px;
  }

  #stockTicker {
    width: 120px;
  }

  #stockDate {
    width: 118px;
  }

  #timeFrame {
    width: 76px;
  }

  .btn {
    padding: 6px 10px;
    font-size: 13px;
    margin: 2px 2px;
  }

  #settingsButton {
    padding: 6px 10px;
    font-size: 13px;
  }

  /* Keep fullscreen button top-left in landscape too. */

  #mainWrapper {
    height: calc(100% - 70px);
    top: 70px;
  }

  #rightPanel {
    /* padding-top: 80px; */
  }

  .watchlist {
    max-height: 150px;
  }

  #settingsContent {
    max-height: 85vh;
  }

  #mobileMenuToggle {
    width: 40px;
    height: 40px;
    font-size: 18px;
    bottom: 10px;
    right: 10px;
  }

  #settingsButton {
    /* bottom: 60px; */
    right: 10px;
  }

  /* Keep fullscreen button top-left in landscape too. */
}

/* ===== Overlay for mobile when panel is open ===== */
#panelOverlay {
  display: none;
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(0, 0, 0, 0.5);
  z-index: 99;
}

@media screen and (max-width: 768px) {
  #panelOverlay.active {
    display: block;
  }
}
