/* style.css — HamCon Web App */

:root {
  /* Color vars set by js/themes.js */
  --font-mono: 'SF Mono', 'Cascadia Code', 'Fira Code', 'Consolas', monospace;
  --font-sans: -apple-system, BlinkMacSystemFont, 'Segoe UI', system-ui, sans-serif;
}

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

html, body {
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-sans);
  font-size: 14px;
  line-height: 1.4;
}

/* ── Layout ── */

.app {
  display: flex;
  flex-direction: column;
  height: 100vh;
  overflow: hidden;
}

/* ── Header / Toolbar ── */

.toolbar {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 16px;
  background: var(--bg-surface);
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}

.toolbar h1 {
  font-size: 16px;
  font-weight: 600;
  color: var(--text-bright);
  white-space: nowrap;
}

.toolbar h1 span {
  color: var(--accent);
  font-weight: 400;
}

.toolbar-spacer { flex: 1; }

.toolbar-group {
  display: flex;
  align-items: center;
  gap: 6px;
}

.toolbar-divider {
  width: 1px;
  height: 24px;
  background: var(--border);
  margin: 0 4px;
}

/* ── Theme dropdown ── */

.theme-select {
  padding: 3px 22px 3px 8px;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: 4px;
  color: var(--text-dim);
  font-family: var(--font-sans);
  font-size: 12px;
  cursor: pointer;
  outline: none;
  -webkit-appearance: none;
  appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg width='8' height='5' viewBox='0 0 8 5' fill='none' xmlns='http://www.w3.org/2000/svg'%3E%3Cpath d='M1 1L4 4L7 1' stroke='%238892a4' stroke-width='1.2'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 6px center;
}

.theme-select:hover {
  border-color: var(--accent-dim);
}

.theme-select:focus {
  border-color: var(--border-focus);
}

/* ── Radio model dropdown (in h1) ── */

.radio-select {
  padding: 2px 24px 2px 8px;
  background: transparent;
  border: 1px solid transparent;
  border-radius: 4px;
  color: var(--accent);
  font-family: var(--font-sans);
  font-size: 16px;
  font-weight: 400;
  cursor: pointer;
  outline: none;
  -webkit-appearance: none;
  appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg width='8' height='5' viewBox='0 0 8 5' fill='none' xmlns='http://www.w3.org/2000/svg'%3E%3Cpath d='M1 1L4 4L7 1' stroke='%238892a4' stroke-width='1.2'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 6px center;
}

.radio-select:hover {
  border-color: var(--accent-dim);
}

.radio-select:focus {
  border-color: var(--border-focus);
}

/* ── Buttons ── */

button {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 6px 12px;
  border: 1px solid var(--border);
  border-radius: 4px;
  background: var(--bg-elevated);
  color: var(--text);
  font-family: var(--font-sans);
  font-size: 13px;
  cursor: pointer;
  white-space: nowrap;
  transition: background 0.15s, border-color 0.15s;
}

button:hover {
  background: var(--bg-input);
  border-color: var(--accent-dim);
}

button:active {
  background: var(--bg);
}

button:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

button.primary {
  background: var(--accent-dim);
  border-color: var(--accent);
  color: var(--text-bright);
}

button.primary:hover {
  background: var(--accent);
  color: var(--bg);
}

button.danger {
  border-color: var(--error);
  color: var(--error);
}

button.danger:hover {
  background: var(--error);
  color: var(--text-bright);
}

button.small {
  padding: 3px 8px;
  font-size: 12px;
}

/* ── Status bar ── */

.status-bar {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 6px 16px;
  background: var(--bg-surface);
  border-top: 1px solid var(--border);
  font-size: 12px;
  color: var(--text-dim);
  flex-shrink: 0;
}

.status-indicator {
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

.status-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--text-dim);
}

.status-dot.connected { background: var(--success); }
.status-dot.connecting { background: var(--warning); animation: pulse 1s ease-in-out infinite; }
.status-dot.error { background: var(--error); }

@keyframes pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.4; }
}

.status-spacer { flex: 1; }

/* ── Progress bar ── */

.progress-bar {
  height: 3px;
  background: var(--border);
  width: 100%;
  flex-shrink: 0;
  display: none;
}

.progress-bar.active { display: block; }

.progress-bar .progress-fill {
  height: 100%;
  background: var(--accent);
  width: 0%;
  transition: width 0.2s;
}

/* ── Content Area (table + controls panel) ── */

.content-area {
  display: flex;
  flex: 1;
  min-height: 0;
  overflow: hidden;
}

/* ── Channel Table ── */

.table-container {
  flex: 1;
  overflow: auto;
  position: relative;
  min-width: 0;
}

.table-container::-webkit-scrollbar {
  width: 10px;
  height: 10px;
}

.table-container::-webkit-scrollbar-track {
  background: var(--scrollbar-track);
}

.table-container::-webkit-scrollbar-thumb {
  background: var(--scrollbar-thumb);
  border-radius: 4px;
}

table.channel-table {
  width: 100%;
  border-collapse: collapse;
  table-layout: fixed;
  font-size: 13px;
}

table.channel-table thead {
  position: sticky;
  top: 0;
  z-index: 10;
}

table.channel-table th {
  background: var(--bg-elevated);
  color: var(--text-dim);
  font-weight: 600;
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  padding: 8px 8px;
  text-align: left;
  border-bottom: 2px solid var(--border);
  white-space: nowrap;
  user-select: none;
  cursor: default;
}

table.channel-table th.col-num { width: 50px; text-align: center; }
table.channel-table th.col-name { width: 100px; }
table.channel-table th.col-freq { width: 110px; }
table.channel-table th.col-tone { width: 80px; }
table.channel-table th.col-tone-val { width: 90px; }
table.channel-table th.col-power { width: 70px; }
table.channel-table th.col-bw { width: 80px; }
table.channel-table th.col-scan { width: 55px; text-align: center; }
table.channel-table th.col-location { width: 150px; }
table.channel-table th.col-notes { width: 150px; }
table.channel-table th.col-actions { width: 70px; text-align: center; }

table.channel-table td {
  padding: 2px 4px;
  border-bottom: 1px solid var(--border);
  vertical-align: middle;
}

table.channel-table tr:nth-child(even) td {
  background: var(--row-alt);
}

table.channel-table tr:hover td {
  background: var(--row-hover);
}

table.channel-table tr.empty td {
  opacity: 0.35;
}

table.channel-table tr.selected td {
  background: rgba(79, 195, 247, 0.12);
}

.ch-num {
  text-align: center;
  font-family: var(--font-mono);
  font-size: 12px;
  color: var(--text-dim);
}

/* ── Inline editing ── */

table.channel-table input,
table.channel-table select {
  width: 100%;
  padding: 4px 6px;
  background: transparent;
  border: 1px solid transparent;
  border-radius: 3px;
  color: var(--text);
  font-family: var(--font-mono);
  font-size: 13px;
  outline: none;
}

table.channel-table input:focus,
table.channel-table select:focus {
  background: var(--bg-input);
  border-color: var(--border-focus);
}

table.channel-table input:hover,
table.channel-table select:hover {
  border-color: var(--border);
}

table.channel-table input[type="checkbox"] {
  width: auto;
  cursor: pointer;
  accent-color: var(--accent);
}

table.channel-table select {
  cursor: pointer;
  -webkit-appearance: none;
  appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg width='8' height='5' viewBox='0 0 8 5' fill='none' xmlns='http://www.w3.org/2000/svg'%3E%3Cpath d='M1 1L4 4L7 1' stroke='%238892a4' stroke-width='1.2'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 6px center;
  padding-right: 20px;
}

/* ── Sub-toolbar (filter/actions) ── */

.sub-toolbar {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 6px 16px;
  background: var(--bg);
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}

.sub-toolbar input[type="search"] {
  padding: 5px 10px;
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: 4px;
  color: var(--text);
  font-size: 13px;
  width: 200px;
  outline: none;
}

.sub-toolbar input[type="search"]:focus {
  border-color: var(--border-focus);
}

.sub-toolbar label {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  font-size: 12px;
  color: var(--text-dim);
  cursor: pointer;
}

/* ── Modal / Dialog ── */

.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.6);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
  backdrop-filter: blur(2px);
}

.modal {
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 24px;
  max-width: 500px;
  width: 90%;
  max-height: 80vh;
  overflow-y: auto;
}

.modal h2 {
  font-size: 16px;
  margin-bottom: 12px;
  color: var(--text-bright);
}

.modal p {
  margin-bottom: 12px;
  color: var(--text-dim);
  font-size: 13px;
}

.modal .modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  margin-top: 16px;
}

/* ── Toast notifications ── */

.toast-container {
  position: fixed;
  top: 16px;
  right: 16px;
  z-index: 200;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.toast {
  padding: 10px 16px;
  border-radius: 6px;
  font-size: 13px;
  color: var(--text-bright);
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  animation: slideIn 0.2s ease-out;
  max-width: 360px;
}

.toast.success { border-left: 3px solid var(--success); }
.toast.error { border-left: 3px solid var(--error); }
.toast.warning { border-left: 3px solid var(--warning); }
.toast.info { border-left: 3px solid var(--accent); }

@keyframes slideIn {
  from { transform: translateX(100%); opacity: 0; }
  to { transform: translateX(0); opacity: 1; }
}

/* ── Browser not supported banner ── */

.unsupported-banner {
  padding: 16px 24px;
  background: var(--error);
  color: var(--text-bright);
  text-align: center;
  font-size: 14px;
}

.unsupported-banner a {
  color: var(--text-bright);
  text-decoration: underline;
}

/* ── MXT575 Column + Tooltip ── */

table.channel-table th.col-mxt575 {
  width: 80px;
  text-align: center;
}

.col-mxt575-cell {
  text-align: center;
  font-family: var(--font-mono);
  font-size: 12px;
  color: var(--text-dim);
}

/* Tooltip on tone value cells */
.midland-tooltip {
  position: relative;
}

.midland-tooltip::after {
  content: attr(data-midland);
  position: absolute;
  bottom: 100%;
  left: 50%;
  transform: translateX(-50%);
  padding: 3px 8px;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: 4px;
  font-family: var(--font-mono);
  font-size: 11px;
  color: var(--text-bright);
  white-space: nowrap;
  pointer-events: none;
  opacity: 0;
  transition: opacity 0.15s;
  z-index: 20;
}

.midland-tooltip:hover::after {
  opacity: 1;
}

@media print {
  .midland-tooltip::after { display: none; }
}

/* ── Repeater Search Modal ── */

.modal.modal-wide {
  max-width: 860px;
  width: 95%;
  max-height: 85vh;
  overflow: hidden;
  display: flex;
  flex-direction: column;
}

.modal.modal-wide h2 {
  flex-shrink: 0;
}

.repeater-search-bar {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 12px;
  flex-shrink: 0;
}

.repeater-search-bar select {
  flex: 1;
  padding: 6px 10px;
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: 4px;
  color: var(--text);
  font-family: var(--font-sans);
  font-size: 13px;
  outline: none;
}

.repeater-search-bar select:focus {
  border-color: var(--border-focus);
}

.repeater-filter-bar {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 8px;
  flex-shrink: 0;
}

.repeater-filter-bar input[type="search"] {
  padding: 4px 8px;
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: 4px;
  color: var(--text);
  font-size: 12px;
  width: 180px;
  outline: none;
}

.repeater-filter-bar input[type="search"]:focus {
  border-color: var(--border-focus);
}

.repeater-filter-bar label {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  font-size: 12px;
  color: var(--text-dim);
  cursor: pointer;
  white-space: nowrap;
}

.repeater-results {
  flex: 1;
  overflow-y: auto;
  min-height: 0;
  border: 1px solid var(--border);
  border-radius: 4px;
}

.repeater-results table {
  width: 100%;
  border-collapse: collapse;
  font-size: 12px;
}

.repeater-results thead {
  position: sticky;
  top: 0;
  z-index: 1;
}

.repeater-results th {
  background: var(--bg-elevated);
  color: var(--text-dim);
  font-weight: 600;
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.4px;
  padding: 6px 8px;
  text-align: left;
  border-bottom: 2px solid var(--border);
  white-space: nowrap;
  user-select: none;
}

.repeater-results th:first-child {
  width: 36px;
  text-align: center;
}

.repeater-results td {
  padding: 4px 8px;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 140px;
}

.repeater-results td:first-child {
  text-align: center;
}

.repeater-results tbody tr:nth-child(even) td {
  background: var(--row-alt);
}

.repeater-results tbody tr:hover td {
  background: var(--row-hover);
}

.repeater-results tbody tr.repeater-closed td {
  opacity: 0.4;
}

.repeater-results input[type="checkbox"] {
  cursor: pointer;
  accent-color: var(--accent);
}

.repeater-count {
  font-size: 12px;
  color: var(--text-dim);
  margin-left: auto;
  white-space: nowrap;
}

.repeater-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-top: 12px;
  flex-shrink: 0;
}

.repeater-footer .attribution {
  font-size: 11px;
  color: var(--text-dim);
}

.repeater-footer .attribution a {
  color: var(--accent);
  text-decoration: none;
}

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

.repeater-footer .modal-actions {
  margin-top: 0;
}

.repeater-status {
  text-align: center;
  padding: 32px 16px;
  color: var(--text-dim);
  font-size: 13px;
}

/* ── Controls Panel (right side) ── */

.controls-panel {
  width: 200px;
  flex-shrink: 0;
  background: var(--bg-surface);
  border-left: 1px solid var(--border);
  overflow-y: auto;
  padding: 12px;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.panel-section {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.panel-section + .panel-section {
  margin-top: 8px;
}

.panel-section-title {
  font-size: 10px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.6px;
  color: var(--text-dim);
  padding-bottom: 4px;
  border-bottom: 1px solid var(--border);
  margin-bottom: 2px;
}

.panel-btn {
  width: 100%;
  justify-content: center;
  padding: 7px 10px;
  font-size: 12px;
}

/* ── Buy Me a Coffee button ── */

.coffee-btn {
  padding: 4px 10px;
  font-size: 13px;
  border: 1px solid #ffdd00;
  background: linear-gradient(135deg, #ffdd00 0%, #ffc800 100%);
  color: #000;
  border-radius: 4px;
  cursor: pointer;
  transition: all 0.15s;
  text-decoration: none;
  font-weight: 500;
  white-space: nowrap;
}

.coffee-btn:hover {
  background: linear-gradient(135deg, #ffe033 0%, #ffd633 100%);
  transform: translateY(-1px);
  box-shadow: 0 2px 8px rgba(255, 221, 0, 0.3);
}

/* ── Help Icon (column headers) ── */

.help-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 14px;
  height: 14px;
  border-radius: 50%;
  border: 1px solid var(--text-dim);
  font-size: 10px;
  font-weight: 600;
  color: var(--text-dim);
  cursor: help;
  vertical-align: middle;
  margin-left: 4px;
  line-height: 1;
}

/* ── Tooltip popup (positioned via JS, appended to body) ── */

.tooltip-popup {
  position: fixed;
  padding: 6px 10px;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: 4px;
  font-family: var(--font-sans);
  font-size: 12px;
  color: var(--text-bright);
  white-space: normal;
  max-width: 240px;
  width: max-content;
  pointer-events: none;
  z-index: 200;
  line-height: 1.4;
  opacity: 0;
  transition: opacity 0.15s;
}

.tooltip-popup.visible {
  opacity: 1;
}

/* ── Welcome Modal ── */

.welcome-modal {
  max-width: 520px;
  text-align: center;
}

.welcome-modal h2 {
  font-size: 20px;
  margin-bottom: 4px;
}

.welcome-modal .welcome-subtitle {
  color: var(--text-dim);
  font-size: 14px;
  margin-bottom: 20px;
}

.welcome-steps {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
  margin-bottom: 20px;
}

.welcome-step {
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 14px 12px;
  text-align: center;
}

.welcome-step-num {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 28px;
  height: 28px;
  border-radius: 50%;
  background: var(--accent-dim);
  color: var(--text-bright);
  font-weight: 700;
  font-size: 14px;
  margin-bottom: 8px;
}

.welcome-step-title {
  font-weight: 600;
  color: var(--text-bright);
  font-size: 14px;
  margin-bottom: 4px;
}

.welcome-step-desc {
  color: var(--text-dim);
  font-size: 12px;
  line-height: 1.4;
}

.welcome-footer {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
}

.welcome-footer .guide-link {
  color: var(--accent);
  text-decoration: none;
  font-size: 13px;
}

.welcome-footer .guide-link:hover {
  text-decoration: underline;
}

/* ── Guide Link in Toolbar ── */

.guide-link-toolbar {
  font-size: 13px;
  color: var(--text);
  text-decoration: none;
  white-space: nowrap;
  transition: color 0.15s;
}

.guide-link-toolbar:hover {
  color: var(--text-bright);
}

/* ── Print: hide help icons and tooltips ── */

@media print {
  .help-icon { display: none; }
  .tooltip-popup { display: none; }
}

/* ── Responsive ── */

@media (max-width: 768px) {
  .toolbar { flex-wrap: wrap; gap: 8px; }
  .toolbar h1 { font-size: 14px; }
  button { padding: 5px 8px; font-size: 12px; }
  .sub-toolbar { flex-wrap: wrap; }

  .content-area {
    flex-direction: column;
  }

  .controls-panel {
    width: 100%;
    border-left: none;
    border-top: 1px solid var(--border);
    flex-direction: row;
    flex-wrap: wrap;
    gap: 8px;
    padding: 10px 16px;
    overflow-y: visible;
  }

  .panel-section {
    flex-direction: row;
    flex-wrap: wrap;
    gap: 6px;
    align-items: center;
  }

  .panel-section-title {
    width: 100%;
    border-bottom: none;
    padding-bottom: 0;
    margin-bottom: 0;
  }

  .panel-btn {
    width: auto;
    padding: 5px 8px;
  }
}
