:root {
  --sidebar-bg: #211f5f;
  --sidebar-bg-2: #2b2970;
  --sidebar-text: #eef0ff;
  --sidebar-muted: #bfc3ea;
  --surface: #ffffff;
  --surface-alt: #f5f6fb;
  --text: #1e2330;
  --muted: #6f7483;
  --border: #d8dbe7;
  --accent: #2a7d38;
  --focus: #4d7cff;
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  padding: 0;
  height: 100%;
  overflow: hidden;
  font-family: "Segoe UI", Tahoma, sans-serif;
  color: var(--text);
  background: var(--surface-alt);
}

.app-shell {
  height: 100%;
  display: grid;
  grid-template-columns: 280px 1fr;
}

.sidebar {
  background: linear-gradient(180deg, var(--sidebar-bg), var(--sidebar-bg-2));
  color: var(--sidebar-text);
  padding: 20px 14px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  height: 100%;
  overflow-y: auto;
}

.brand {
  padding: 8px 8px 14px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.16);
}

.brand-logo {
  display: block;
  width: 100%;
  max-width: 210px;
  height: auto;
  margin-bottom: 8px;
}

.brand-subtitle {
  font-size: 13px;
  color: var(--sidebar-muted);
}

.brand-title {
  font-size: 16px;
  font-weight: 700;
  color: var(--sidebar-text);
  margin-bottom: 2px;
}

.sidebar-search {
  width: 100%;
}

.nav-section {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.nav-item {
  width: 100%;
  text-align: left;
  background: transparent;
  border: 1px solid transparent;
  color: var(--sidebar-text);
  border-radius: 8px;
  padding: 8px;
  cursor: pointer;
  margin: 2px 0;
}

.nav-item:hover {
  border-color: rgba(255, 255, 255, 0.35);
  background: rgba(255, 255, 255, 0.08);
}

.nav-item.active {
  border-color: rgba(255, 255, 255, 0.6);
  background: rgba(255, 255, 255, 0.16);
}

.main {
  padding: 20px 26px;
  height: 100%;
  overflow-y: auto;
}

.main-header h1 {
  margin: 0;
  font-size: 28px;
}

.main-header p {
  margin-top: 6px;
  color: var(--muted);
}

.schema-link {
  color: #1f2f87;
  text-decoration: underline;
  text-underline-offset: 2px;
}

.schema-link:hover {
  color: #1530b2;
}

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  box-shadow: 0 4px 12px rgba(20, 28, 62, 0.07);
}

.mode-card {
  margin-top: 16px;
  padding: 12px;
}

.selector-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}

.selector-field {
  margin-bottom: 0;
}

.mode-buttons {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.mode-btn {
  background: #f2f4fb;
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: 8px;
  padding: 8px 12px;
  cursor: pointer;
  font-weight: 600;
}

.mode-btn.active {
  border-color: #2944b8;
  background: #e6ecff;
}

.mode-btn.compare {
  margin-left: auto;
}

.work-area {
  margin-top: 16px;
  padding: 16px;
  min-height: calc(100vh - 230px);
}

.placeholder {
  color: var(--muted);
}

.grid-two {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 14px;
}

.field {
  margin-bottom: 10px;
}

.label {
  display: block;
  margin-bottom: 4px;
  font-size: 13px;
  color: var(--muted);
}

.input,
.textarea,
.select {
  width: 100%;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 8px 10px;
  font-size: 14px;
  background: #fff;
}

.textarea {
  min-height: 190px;
  resize: vertical;
  font-family: Consolas, "Courier New", monospace;
}

.textarea-compact {
  min-height: 0;
  height: 3.2em;
}

.input:focus,
.textarea:focus,
.select:focus {
  outline: 2px solid var(--focus);
  outline-offset: 1px;
}

.button-row {
  display: flex;
  gap: 8px;
  align-items: center;
}

.button {
  background: #1f2f87;
  border: 1px solid #1f2f87;
  color: #fff;
  border-radius: 8px;
  padding: 8px 12px;
  cursor: pointer;
}

.button.secondary {
  background: #f2f4fb;
  color: var(--text);
  border-color: var(--border);
}

.button:disabled {
  background: #c9ccd6;
  border-color: #bcc0cc;
  color: #6f7483;
  cursor: not-allowed;
}

.result-ok {
  color: var(--accent);
  font-weight: 700;
}

.result-error {
  color: #b3261e;
  font-weight: 700;
}

.hint {
  color: var(--muted);
  font-size: 13px;
}

.data-table {
  width: 100%;
  border-collapse: collapse;
  border: 1px solid var(--border);
  border-radius: 8px;
  overflow: hidden;
  font-size: 13px;
}

.csv-dropzone {
  border: 2px dashed var(--border);
  border-radius: 8px;
  padding: 12px;
  background: #fafbff;
  color: var(--muted);
  text-align: center;
  margin-bottom: 8px;
}

.csv-dropzone.active {
  border-color: var(--focus);
  background: #eef3ff;
}

.csv-table .csv-col-parsed {
  min-width: 280px;
}

.csv-payload-hex-col {
  min-width: 180px;
}

.csv-payload-hex-cell {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 6px;
}

.csv-payload-hex-text {
  min-width: 0;
}

.sigfox-msg-icon {
  display: inline-flex;
  flex-shrink: 0;
  width: 1em;
  height: 1em;
  line-height: 1;
}

.sigfox-msg-icon-svg {
  width: 1em;
  height: 1em;
  display: block;
}

.sigfox-msg-icon-uplink .sigfox-msg-icon-bg {
  fill: #3dbd6a;
}

.sigfox-msg-icon-oob .sigfox-msg-icon-bg {
  fill: #2b2b2b;
}

.seq-na {
  color: var(--muted);
}

.seq-gap {
  color: #b3261e;
  font-weight: 600;
}

.seq-rollover {
  color: #137333;
  font-weight: 600;
}

.csv-row-error td {
  background: #fff3f2;
}

.warn-mark {
  display: inline-block;
  margin-left: 4px;
  color: #b3261e;
  font-weight: 700;
  cursor: help;
}

.csv-parse-button {
  min-width: 110px;
  white-space: nowrap;
}

.csv-sort-toggle {
  border: 0;
  background: transparent;
  color: inherit;
  font: inherit;
  font-weight: 700;
  padding: 0;
  cursor: pointer;
  white-space: nowrap;
}

.csv-graph-panel {
  position: relative;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: #fff;
  margin-bottom: 12px;
  padding: 8px 10px 4px 10px;
}

.csv-graph-toolbar {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 4px;
}

.csv-graph-field-select {
  font-size: 13px;
  padding: 3px 8px;
  border: 1px solid var(--border);
  border-radius: 4px;
  background: #fafbff;
  min-width: 180px;
}

.csv-graph-canvas {
  width: 100%;
  height: 210px;
  display: block;
}

.csv-graph-tooltip {
  position: absolute;
  z-index: 5;
  pointer-events: none;
  display: none;
  max-width: 280px;
  padding: 6px 10px;
  font-size: 12px;
  line-height: 1.35;
  color: var(--text);
  background: #fff;
  border: 1px solid var(--border);
  border-radius: 6px;
  box-shadow: 0 4px 12px rgba(20, 28, 62, 0.12);
}

.csv-graph-tooltip.visible {
  display: block;
}

.data-table th,
.data-table td {
  border-bottom: 1px solid var(--border);
  border-right: 1px solid var(--border);
  padding: 6px 8px;
  text-align: left;
  vertical-align: top;
}

.data-table th:last-child,
.data-table td:last-child {
  border-right: none;
}

.data-table thead th {
  background: #f2f4fb;
  font-weight: 700;
}

.data-table tbody tr:last-child td {
  border-bottom: none;
}

.compare-table code {
  white-space: pre-wrap;
  word-break: break-word;
}

.diff-row.changed td {
  background: #fff4d9;
}

.diff-row.equal td {
  background: #eef8ef;
  color: #6f7483;
}

.diff-row.missing-left td:nth-child(3),
.diff-row.missing-right td:nth-child(2) {
  background: #ffe8e8;
}

.group-sep td {
  padding: 6px 0;
  border: none;
  background: transparent;
}

.diff-scope {
  font-weight: 700;
  width: 260px;
}

#field-editors {
  max-height: calc(100vh - 360px);
  min-height: 320px;
  overflow: auto;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 8px;
  background: #fafbff;
}

/* --- Sidebar footer (Sigfox Auth button) --- */

.sidebar-footer {
  margin-top: auto;
  padding-top: 10px;
  border-top: 1px solid rgba(255, 255, 255, 0.12);
}

.tz-toggle {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 4px 8px 10px;
}

.tz-toggle-label {
  font-size: 12px;
  color: var(--sidebar-muted);
}

.tz-toggle-buttons {
  display: inline-flex;
  border: 1px solid rgba(255, 255, 255, 0.18);
  border-radius: 8px;
  overflow: hidden;
}

.tz-btn {
  background: transparent;
  border: none;
  color: var(--sidebar-muted);
  padding: 4px 10px;
  cursor: pointer;
  font-size: 12px;
  line-height: 1.4;
}

.tz-btn + .tz-btn {
  border-left: 1px solid rgba(255, 255, 255, 0.18);
}

.tz-btn:hover {
  background: rgba(255, 255, 255, 0.07);
  color: var(--sidebar-text);
}

.tz-btn.active {
  background: rgba(255, 255, 255, 0.16);
  color: var(--sidebar-text);
  font-weight: 600;
}

.sfx-auth-btn {
  width: 100%;
  text-align: left;
  background: transparent;
  border: 1px solid transparent;
  color: var(--sidebar-muted);
  border-radius: 8px;
  padding: 7px 8px;
  cursor: pointer;
  font-size: 13px;
  display: flex;
  align-items: center;
  gap: 6px;
}

.sfx-auth-btn:hover {
  border-color: rgba(255, 255, 255, 0.3);
  background: rgba(255, 255, 255, 0.07);
  color: var(--sidebar-text);
}

.sfx-auth-icon {
  font-size: 13px;
  opacity: 0.7;
}

.sfx-auth-indicator {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: transparent;
  border: 1px solid rgba(255, 255, 255, 0.25);
  margin-left: auto;
  flex-shrink: 0;
  transition: background 0.2s;
}

.sfx-auth-indicator.saved {
  background: #4caf7d;
  border-color: #4caf7d;
}

/* --- Modal dialog --- */

.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.45);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
}

.modal-box {
  background: #fff;
  border-radius: 12px;
  box-shadow: 0 8px 40px rgba(0, 0, 0, 0.22);
  padding: 24px 28px 22px;
  width: 100%;
  max-width: 420px;
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.modal-box-wide {
  max-width: 520px;
}

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.modal-title {
  font-size: 15px;
  font-weight: 700;
  color: var(--text);
}

.modal-close {
  background: none;
  border: none;
  font-size: 20px;
  color: var(--muted);
  cursor: pointer;
  padding: 2px 6px;
  border-radius: 4px;
  line-height: 1;
}

.modal-close:hover {
  background: #f0f2fb;
  color: var(--text);
}

.modal-desc {
  font-size: 12px;
  color: var(--muted);
  margin: 0;
  line-height: 1.5;
}

.modal-box .field {
  margin: 0;
}

/* --- Source toggle (Upload CSV / Fetch from Sigfox) --- */

.source-toggle {
  display: flex;
  gap: 0;
  margin-bottom: 14px;
  border: 1px solid var(--border);
  border-radius: 8px;
  overflow: hidden;
  width: fit-content;
}

.source-tab {
  background: #f2f4fb;
  border: none;
  color: var(--muted);
  padding: 7px 18px;
  cursor: pointer;
  font-size: 13px;
  font-weight: 500;
  transition: background 0.12s, color 0.12s;
  line-height: 1.4;
}

.source-tab:not(:last-child) {
  border-right: 1px solid var(--border);
}

.source-tab.active {
  background: #1f2f87;
  color: #fff;
}

.source-tab:not(.active):hover {
  background: #e4e8f7;
  color: #1f2f87;
}

/* --- Sigfox form --- */

.sigfox-form {
  display: flex;
  gap: 12px;
  flex-wrap: wrap;
  align-items: flex-end;
  margin-bottom: 10px;
}

.sigfox-form .field {
  margin: 0;
  flex: 1;
  min-width: 140px;
}

.sigfox-creds {
  display: flex;
  gap: 12px;
  flex: 2;
  min-width: 260px;
}

.sigfox-creds .field {
  flex: 1;
}

.sigfox-fetch-row {
  flex-wrap: wrap;
  align-items: center;
}

.sigfox-device-field {
  position: relative;
  display: inline-flex;
  align-items: center;
}

.sigfox-input-device {
  max-width: 180px;
  padding-right: 34px;
}

.sigfox-fav-star {
  position: absolute;
  right: 4px;
  top: 50%;
  transform: translateY(-50%);
  border: 0;
  background: transparent;
  color: #8a93b2;
  font-size: 18px;
  line-height: 1;
  padding: 2px 4px;
  cursor: pointer;
  border-radius: 4px;
}

.sigfox-fav-star:hover:not(:disabled) {
  color: #e6a800;
  background: #fff8e6;
}

.sigfox-fav-star.is-favourite {
  color: #e6a800;
}

.sigfox-fav-star:disabled {
  opacity: 0.35;
  cursor: default;
}

.sfx-favourites-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
  max-height: 320px;
  overflow-y: auto;
}

.sfx-favourites-empty {
  margin: 0;
  text-align: center;
  padding: 8px 0 4px;
}

.sfx-fav-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: #fafbff;
}

.sfx-fav-item-main {
  display: flex;
  flex-direction: column;
  gap: 2px;
  min-width: 0;
}

.sfx-fav-item-id {
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 13px;
  font-weight: 700;
}

.sfx-fav-item-desc {
  font-size: 12px;
  color: var(--muted);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.sfx-fav-item-actions {
  display: flex;
  gap: 6px;
  flex-shrink: 0;
}

.sfx-fav-item-actions .button {
  padding: 4px 10px;
  font-size: 12px;
}

.sigfox-device-info-panel {
  position: relative;
  font-size: 11px;
  line-height: 1.4;
  color: var(--muted);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 8px 12px 34px;
  margin-bottom: 10px;
  background: #fafbff;
}

.sigfox-device-info-head {
  font-size: 12px;
  font-weight: 700;
  color: var(--text);
  margin-bottom: 6px;
}

.sigfox-device-info-grid {
  display: flex;
  flex-wrap: wrap;
  gap: 5px 18px;
  align-items: flex-start;
}

.sigfox-device-info-item {
  white-space: nowrap;
  flex: 0 0 auto;
}

.sigfox-device-info-label {
  font-weight: 600;
  color: var(--text);
}

.sigfox-device-info-label::after {
  content: ": ";
}

.sigfox-device-info-value {
  white-space: nowrap;
}

.sigfox-resolved-value {
  cursor: help;
}

.sigfox-device-info-resolve-btn {
  position: absolute;
  right: 10px;
  bottom: 8px;
  padding: 3px 10px;
  font-size: 11px;
  line-height: 1.3;
}

.sfx-panel-auth-row {
  margin-bottom: 10px;
  font-size: 13px;
}

.sfx-status-ok {
  color: #2a7d38;
  font-weight: 600;
}

.sfx-status-err {
  color: #c0392b;
  font-weight: 600;
}

.sfx-inline-link {
  background: none;
  border: none;
  color: #c0392b;
  text-decoration: underline;
  cursor: pointer;
  font-size: 13px;
  font-weight: 600;
  padding: 0;
}

.sfx-inline-link:hover {
  color: #922b21;
}

@media (max-width: 1080px) {
  html,
  body {
    height: auto;
    overflow: auto;
  }

  .app-shell {
    height: auto;
    grid-template-columns: 1fr;
  }

  .sidebar {
    height: auto;
    overflow-y: visible;
  }

  .main {
    height: auto;
    overflow-y: visible;
  }

  .mode-btn.compare {
    margin-left: 0;
  }

  .grid-two {
    grid-template-columns: 1fr;
  }

  .selector-row {
    grid-template-columns: 1fr;
  }

  .work-area {
    min-height: auto;
  }

  #field-editors {
    max-height: none;
    min-height: 220px;
  }
}
