/* ============================================================
   9M2PJU Ham Radio Dashboard — Professional Dark Theme
   Design tokens → Base → Layout → Components → Responsive
   ============================================================ */

/* ===== Design Tokens ===== */
:root {
  /* Layout */
  --main-layout: auto auto auto auto;
  --main-width: 24.9vw;
  --main-height: 31vh;

  /* Surface colors (deep slate palette) */
  --bg-base:      #0d1117;
  --bg-surface:   #161b22;
  --bg-elevated:  #1c2128;
  --bg-hover:     #22262e;

  /* Borders */
  --border:        #30363d;
  --border-subtle: #21262d;
  --border-active: #58a6ff;

  /* Text */
  --text-primary:   #e6edf3;
  --text-secondary: #8b949e;
  --text-muted:     #6e7681;

  /* Accent (radio/tech cyan-blue) */
  --accent:         #2da9e5;
  --accent-hover:   #4db9ef;
  --accent-subtle:  rgba(45, 169, 229, 0.12);

  /* Status colors */
  --success:        #3fb950;
  --warning:        #d29922;
  --danger:         #f85149;
  --success-bg:     rgba(63, 185, 80, 0.15);
  --warning-bg:     rgba(210, 153, 34, 0.15);
  --danger-bg:      rgba(248, 81, 73, 0.15);

  /* Radii */
  --radius-sm: 6px;
  --radius:    8px;
  --radius-lg: 12px;

  /* Shadows */
  --shadow-sm:  0 1px 3px rgba(0,0,0,0.3);
  --shadow:     0 4px 12px rgba(0,0,0,0.4);
  --shadow-lg:  0 8px 24px rgba(0,0,0,0.5);

  /* Transitions */
  --transition: 0.2s ease;

  /* Fonts */
  --font-mono:    "Victor Mono", "SF Mono", monospace;
  --font-sans:    "Roboto Condensed", system-ui, sans-serif;
  --font-display: "Bebas Neue", sans-serif;
}

/* ===== Base ===== */
body, html {
  background: var(--bg-base);
  font-size: 100%;
  max-width: 100%;
  overflow-x: hidden;
  height: 100%;
  margin: 0;
  justify-content: center;
  align-items: center;
  color: var(--text-primary);
  font-family: var(--font-sans);
}

.iframe-container {
  background-color: var(--bg-base);
  border: 0;
  position: fixed;
  height: 100%;
  width: 100%;
  z-index: -2;
  justify-content: center;
  align-items: center;
}

.img-zoom {
  background-color: var(--bg-base);
  left: 0;
  border: 0;
  height: 100%;
  width: 100%;
  position: fixed;
  overflow: hidden;
  bottom: 0;
  z-index: -2;
}

.full-screen {
  background-color: var(--bg-base);
  border: 0;
  height: 100%;
  width: 98%;
  margin-bottom: 0;
  margin-left: 1%;
  justify-content: center;
  align-items: center;
  -ms-zoom: 1;
  -moz-transform: scale(1);
  -moz-transform-origin: 0 0;
  -o-transform: scale(1);
  -o-transform-origin: 0 0;
  -webkit-transform: scale(1);
  -webkit-transform-origin: 0 0;
}

.default-frame {
  margin: 0;
  left: 0;
  border: 0;
  height: 100%;
  width: 100%;
  position: fixed;
  overflow: hidden;
  bottom: 0;
}

.hidden {
  display: none;
}

/* ===== Click Overlay (for video/iframe tiles) ===== */
.click-overlay {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background-color: transparent;
  z-index: 1;
  cursor: pointer;
}

/* ===== Menu Link Type Icons ===== */
.menu-link.menu-core::before {
  content: '\2605';
  margin-right: 2px;
  opacity: 0.8;
}
.menu-link.menu-config::before {
  content: '\2699';
  margin-right: 2px;
  opacity: 0.8;
  display: inline-block;
  transform: scale(0.8);
  transform-origin: center;
}
.menu-link.menu-user::before {
  content: '';
  margin-right: 0;
}

/* ===== Top Bar ===== */
.top-bar {
  display: grid;
  grid-template-columns: 2fr 1fr 2fr;
  background: linear-gradient(180deg, var(--bg-elevated) 0%, var(--bg-surface) 100%);
  color: var(--text-primary);
  padding: 8px 12px;
  border-bottom: 1px solid var(--border);
  overflow: hidden;
  position: relative;
  width: auto;
  gap: 8px;
}

.child {
  position: relative;
  display: grid;
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-sm);
  background: var(--bg-surface);
  color: var(--text-primary);
  padding: 6px 10px;
  font-family: var(--font-mono);
  font-size: clamp(11px, 1.3vw, 15px);
  align-content: center;
}

#topBarLeft {
  text-align: left;
  color: var(--text-secondary);
}
#topBarCenter {
  text-align: center;
  color: var(--accent);
  font-weight: 600;
  letter-spacing: 0.5px;
}
#topBarRight {
  text-align: right;
  color: var(--text-secondary);
}

/* ===== Dashboard Grid ===== */
.dashboard {
  display: grid;
  grid-template-columns: var(--main-layout);
  grid-gap: 6px;
  border: 0;
  margin: 6px;
  overflow: hidden;
  position: relative;
  width: calc(100% - 12px);
  padding-bottom: 32px;
}

.image-container {
  position: relative;
  float: inline-start;
  margin: 0;
  border: 1px solid var(--border-subtle);
  height: var(--main-height);
  width: var(--main-width);
  overflow: hidden;
  display: flex;
  justify-content: center;
  align-items: center;
  border-radius: var(--radius);
  background: var(--bg-surface);
  box-shadow: var(--shadow-sm);
  transition: border-color var(--transition), box-shadow var(--transition);
}
.image-container:hover {
  border-color: var(--border);
  box-shadow: var(--shadow);
}

.iframe-tile {
  position: absolute;
  float: inline-start;
  overflow: hidden;
  border: 0;
  display: flex;
  height: var(--main-height);
  width: var(--main-width);
  margin: 0;
  border-radius: var(--radius);
}

.image-container img {
  height: 100%;
  width: 100%;
  object-fit: cover;
}

.image-title {
  position: absolute;
  top: 8px;
  left: 50%;
  transform: translateX(-50%);
  color: var(--text-primary);
  background: rgba(13, 17, 23, 0.85);
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
  font-size: clamp(9px, 1vw, 13px);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-sm);
  font-family: var(--font-sans);
  font-weight: 400;
  padding: 3px 10px;
  white-space: nowrap;
  max-width: 90%;
  overflow: hidden;
  text-overflow: ellipsis;
  letter-spacing: 0.3px;
}

.image-large {
  display: block;
  position: relative;
  margin-left: auto;
  margin-right: auto;
  max-height: 100%;
  max-width: 100%;
  height: 100%;
  width: auto;
  border-radius: var(--radius-sm);
}

.media {
  height: 100%;
  width: 100%;
  cursor: pointer;
  border-radius: var(--radius);
}

/* ===== Side Menus ===== */
.menu {
  display: grid;
  grid-gap: 4px;
  position: absolute;
  height: auto;
  width: auto;
  margin-top: 10vh;
  left: calc(-5.2vw - 0px);
  z-index: 2;
  transition: var(--transition);
}

.menuR {
  display: grid;
  grid-gap: 4px;
  position: absolute;
  height: auto;
  width: 30px;
  margin-top: 10vh;
  right: -5px;
  z-index: 2;
  transition: var(--transition);
}

#myMenu:hover {
  width: 7vw;
  left: 0;
}
#myMenuR:hover {
  width: 7vw;
  right: 0;
}

#mySidenav a {
  position: relative;
  float: inline-start;
  left: calc(-0.2vw - 10px);
  transition: var(--transition);
  padding: 10px 16px;
  width: 5vw;
  min-width: 90px;
  text-decoration: none;
  font-family: var(--font-display);
  font-size: clamp(11px, 1.2vw, 15px);
  font-weight: 400;
  letter-spacing: 0.5px;
  text-align: right;
  color: var(--text-primary);
  border-radius: 0 var(--radius-sm) var(--radius-sm) 0;
  box-shadow: var(--shadow);
  border: 1px solid var(--border-subtle);
  border-left: 3px solid var(--accent);
}
#mySidenav a:hover {
  left: 0;
  filter: brightness(1.15);
}

#mySidenavR a {
  position: relative;
  float: inline-start;
  right: calc(-0.2vw - 10px);
  transition: var(--transition);
  padding: 10px 16px;
  width: 7vw;
  min-width: 90px;
  text-decoration: none;
  font-family: var(--font-display);
  font-size: clamp(11px, 1.2vw, 15px);
  font-weight: 400;
  letter-spacing: 0.5px;
  text-align: left;
  color: var(--text-primary);
  border-radius: var(--radius-sm) 0 0 var(--radius-sm);
  box-shadow: var(--shadow);
  border: 1px solid var(--border-subtle);
  border-right: 3px solid var(--accent);
}
#mySidenavR a:hover {
  right: 0;
  width: 7vw;
  filter: brightness(1.15);
}

/* ===== Overlay (Sources) ===== */
.overlay {
  display: none;
  position: fixed;
  top: 0;
  left: 0;
  height: 100%;
  width: 100%;
  background: rgba(0, 0, 0, 0.75);
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
  color: var(--text-primary);
  padding: 50px;
  box-sizing: border-box;
  z-index: 3;
  font-family: var(--font-sans);
}

.overlay-content {
  background: var(--bg-surface);
  border: 1px solid var(--border);
  padding: 24px;
  border-radius: var(--radius-lg);
  max-height: 80vh;
  overflow-y: auto;
  box-shadow: var(--shadow-lg);
}

.close-btn {
  cursor: pointer;
  color: var(--text-secondary);
  float: right;
  font-size: 22px;
  transition: color var(--transition);
}
.close-btn:hover {
  color: var(--text-primary);
}

.overlay-link {
  color: var(--accent);
  text-decoration: none;
  transition: color var(--transition);
}
.overlay-link:hover {
  color: var(--accent-hover);
}

/* ===== Settings Page ===== */
.settings-Page {
  display: none;
  font-family: var(--font-sans);
  margin-top: 37px;
  background: var(--bg-base);
  color: var(--text-primary);
  height: 98%;
  width: 98%;
  margin-left: 1%;
  overflow-y: auto;
  padding: 20px;
  box-sizing: border-box;
}

.fixed-section {
  display: none;
  text-align: center;
  position: fixed;
  top: 0;
  left: 1%;
  width: 98%;
  background: var(--bg-elevated);
  border-bottom: 1px solid var(--border);
  padding: 10px 7px;
  box-shadow: var(--shadow);
  z-index: -3;
}

.section {
  margin-bottom: 24px;
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

label {
  margin: 2px;
  font-weight: 600;
  color: var(--text-primary);
}

input[type="text"] {
  width: 90%;
  padding: 6px 10px;
  margin-right: 5px;
  margin-bottom: 6px;
  background: var(--bg-base);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text-primary);
  font-family: var(--font-sans);
  font-size: 14px;
  box-sizing: border-box;
}
input[type="text"]:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-subtle);
}

input[type="number"] {
  width: 80px;
  padding: 6px 10px;
  margin-bottom: 10px;
  background: var(--bg-base);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text-primary);
  font-family: var(--font-sans);
  font-size: 14px;
  box-sizing: border-box;
}
input[type="number"]:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-subtle);
}

input[type="color"] {
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--bg-base);
  cursor: pointer;
}

table {
  width: 100%;
  border-collapse: collapse;
  margin-bottom: 12px;
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-sm);
  overflow: hidden;
}
table th,
table td {
  border: 1px solid var(--border-subtle);
  padding: 8px 10px;
  align-content: start;
  color: var(--text-primary);
}
table th {
  background: var(--bg-elevated);
  font-weight: 600;
  text-transform: uppercase;
  font-size: 12px;
  letter-spacing: 0.5px;
  color: var(--text-secondary);
}
table td input {
  background: var(--bg-base);
  border: 1px solid var(--border);
  border-radius: 4px;
  color: var(--text-primary);
  padding: 4px 8px;
  font-size: 13px;
}

/* ===== Buttons ===== */
button {
  padding: 8px 16px;
  margin: 0 0 8px 0;
  cursor: pointer;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  box-sizing: border-box;
  color: var(--text-primary);
  font-family: var(--font-sans);
  font-size: 13px;
  font-weight: 500;
  outline: 0;
  overflow: hidden;
  text-align: center;
  text-decoration: none;
  text-overflow: ellipsis;
  user-select: none;
  -webkit-user-select: none;
  touch-action: manipulation;
  white-space: nowrap;
  transition: background var(--transition), border-color var(--transition);
}
button:hover {
  background: var(--bg-hover);
  border-color: var(--text-muted);
}
button:active {
  background: var(--bg-surface);
}
button:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-subtle);
}

.radio-group {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 8px;
}
.radio-group label {
  margin-right: 12px;
  padding-top: 5px;
  font-weight: 400;
  color: var(--text-secondary);
}

/* ===== RSS Ticker ===== */
.rss-ticker {
  position: fixed;
  bottom: 0;
  width: 100%;
  background: rgba(13, 17, 23, 0.92);
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
  border-top: 1px solid var(--border);
  overflow: hidden;
  white-space: nowrap;
  box-sizing: border-box;
  padding: 5px 0;
  font-family: var(--font-mono);
  font-size: clamp(10px, 1.3vh, 13px);
  font-weight: 500;
  color: var(--text-secondary);
}

.rss-ticker-content {
  display: inline-block;
  padding-left: 100%;
  animation: ticker var(--ticker-duration, 90s) linear infinite;
  animation-play-state: running;
}

.rss-ticker-content a {
  text-decoration: none;
  color: var(--accent);
  transition: color var(--transition);
}
.rss-ticker-content a:hover {
  color: var(--accent-hover);
}

@keyframes ticker {
  0%   { transform: translateX(0%); }
  100% { transform: translateX(-100%); }
}

/* ===== Hamburger Menu Toggle (mobile) ===== */
.menu-toggle {
  display: none;
  position: fixed;
  top: 50%;
  transform: translateY(-50%);
  z-index: 5;
  width: 36px;
  height: 46px;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text-primary);
  font-size: 20px;
  line-height: 1;
  cursor: pointer;
  touch-action: manipulation;
  user-select: none;
  -webkit-user-select: none;
  padding: 0;
  transition: background var(--transition);
}
.menu-toggle.left  { left: 4px; }
.menu-toggle.right { right: 4px; }
.menu-toggle:active { background: var(--bg-hover); }

/* ===== Toast Notifications ===== */
#toast-container {
  position: fixed;
  top: 16px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 100;
  display: flex;
  flex-direction: column;
  gap: 8px;
  align-items: center;
  pointer-events: none;
  max-width: 92vw;
}
.toast {
  background: var(--bg-elevated);
  color: var(--text-primary);
  border: 1px solid var(--border);
  border-left: 4px solid var(--accent);
  border-radius: var(--radius-sm);
  padding: 12px 20px;
  font-family: var(--font-sans);
  font-size: 14px;
  box-shadow: var(--shadow-lg);
  opacity: 0;
  transform: translateY(-10px);
  transition: opacity 0.25s ease, transform 0.25s ease;
  max-width: 80vw;
  white-space: pre-wrap;
  text-align: center;
}
.toast.show    { opacity: 1; transform: translateY(0); }
.toast.error   { border-left-color: var(--danger); }
.toast.success { border-left-color: var(--success); }

/* ===== Tile Loading Spinner ===== */
.tile-spinner {
  position: absolute;
  top: 50%; left: 50%;
  width: 28px; height: 28px;
  margin: -14px 0 0 -14px;
  border: 3px solid var(--border-subtle);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.9s linear infinite;
  pointer-events: none;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ===== Tile Error Placeholder ===== */
.tile-error {
  position: absolute;
  top: 0; left: 0;
  width: 100%; height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  text-align: center;
  color: var(--warning);
  font-family: var(--font-sans);
  font-size: clamp(11px, 1.2vw, 14px);
  padding: 12px;
  box-sizing: border-box;
  background: var(--bg-surface);
  pointer-events: none;
}

/* ===== Settings: Scrollable Tables ===== */
.table-scroll {
  width: 100%;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  border-radius: var(--radius-sm);
}
.table-scroll table { min-width: 520px; }

/* ===== Solar Conditions Widget ===== */
.solar-widget {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px 16px;
  padding: 6px 14px;
  background: var(--bg-surface);
  border-bottom: 1px solid var(--border);
  font-family: var(--font-sans);
  font-size: clamp(11px, 1.2vw, 14px);
  color: var(--text-secondary);
}
.solar-widget[hidden] { display: none; }
.solar-status {
  font-weight: 700;
  padding: 3px 10px;
  border-radius: var(--radius-sm);
  white-space: nowrap;
  font-size: inherit;
  letter-spacing: 0.3px;
}
.solar-status.good  { background: var(--success-bg); color: var(--success); border: 1px solid rgba(63,185,80,0.3); }
.solar-status.fair  { background: var(--warning-bg); color: var(--warning); border: 1px solid rgba(210,153,34,0.3); }
.solar-status.poor  { background: var(--danger-bg);  color: var(--danger);  border: 1px solid rgba(248,81,73,0.3); }
.solar-detail {
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  min-width: 0;
}
.solar-detail b { color: var(--text-primary); font-weight: 600; }

/* ===== Fullscreen Image Close Button ===== */
.img-zoom-close {
  position: fixed;
  top: 16px;
  right: 16px;
  z-index: 4;
  width: 42px;
  height: 42px;
  border-radius: 50%;
  background: rgba(28, 33, 40, 0.9);
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
  color: var(--text-primary);
  border: 1px solid var(--border);
  font-size: 20px;
  cursor: pointer;
  display: none;
  align-items: center;
  justify-content: center;
  touch-action: manipulation;
  transition: background var(--transition);
}
.img-zoom-close:hover { background: var(--bg-hover); }
.img-zoom-close.show { display: flex; }

/* ===== Tile Status Badge ===== */
.tile-badge {
  position: absolute;
  top: 8px;
  right: 8px;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--warning);
  z-index: 2;
  pointer-events: none;
  box-shadow: 0 0 6px rgba(0,0,0,0.6);
  transition: background var(--transition);
}
.tile-badge.loaded { background: var(--success); }
.tile-badge.error  { background: var(--danger); }

/* ===== Responsive: Tablet (<= 1024px) ===== */
@media (max-width: 1024px) {
  :root {
    --main-width: 49.5vw !important;
  }
  .dashboard {
    grid-template-columns: auto auto !important;
  }
  .default-frame {
    position: relative !important;
    height: auto !important;
    overflow-y: auto !important;
    overflow-x: hidden !important;
    bottom: auto !important;
  }
  .menu-toggle { display: block; }
  #myMenu, #myMenuR { transition: none; }
  #myMenu   { left: -260px; }
  #myMenuR  { right: -260px; }
  #myMenu.open   { left: 4px; }
  #myMenuR.open  { right: 4px; }
  #myMenu:hover, #myMenuR:hover { width: auto; }
  #mySidenav a, #mySidenavR a {
    left: 0 !important; right: 0 !important;
    width: auto !important; min-width: 120px;
  }
}

/* ===== Responsive: Phone (<= 640px) ===== */
@media (max-width: 640px) {
  :root {
    --main-width: 100vw !important;
    --main-height: 30vh !important;
  }
  .default-frame {
    position: relative !important;
    height: auto !important;
    overflow-y: auto !important;
    overflow-x: hidden !important;
    bottom: auto !important;
  }
  .dashboard {
    grid-template-columns: auto !important;
    width: 100% !important;
    margin: 0 !important;
    grid-gap: 4px !important;
  }
  .image-container, .iframe-tile {
    width: 100% !important;
    border-radius: 0 !important;
    border-left: 0 !important;
    border-right: 0 !important;
  }
  .top-bar {
    grid-template-columns: 1fr 1fr;
    padding: 6px 8px !important;
    gap: 4px;
  }
  .top-bar .child {
    font-size: 11px !important;
    padding: 4px 6px !important;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }
  #topBarCenter {
    grid-column: 1 / -1;
    order: -1;
    text-align: center !important;
  }
  #topBarLeft  { text-align: left !important; }
  #topBarRight { text-align: right !important; }
  .image-title { font-size: 12px; }
  .menu-toggle { width: 32px; height: 42px; font-size: 18px; }
  .settings-Page {
    width: 100% !important;
    margin-left: 0 !important;
    padding: 12px !important;
  }
  .fixed-section {
    position: relative !important;
    width: 100% !important;
    left: 0 !important;
    display: block !important;
    padding: 8px 4px;
  }
  .fixed-section button {
    display: block;
    width: 100%;
    margin: 4px 0;
    height: auto;
    padding: 12px;
  }
  .overlay { padding: 10px; }
  .overlay-content { padding: 16px; max-height: 90vh; }
  .solar-widget {
    font-size: 11px !important;
    padding: 4px 10px !important;
  }
  .solar-detail {
    min-width: 0;
    flex: 1 1 100%;
    white-space: normal !important;
    line-height: 1.4;
  }
}

/* ===== Desktop: hide hamburger on fine pointers ===== */
@media (pointer: fine) and (min-width: 1025px) {
  .menu-toggle { display: none; }
}
