@import url("https://fonts.googleapis.com/css2?family=JetBrains+Mono:wght@400;600&family=Outfit:wght@400;500;600;700&display=swap");

:root {
  color-scheme: dark;
  --bg: #08111f;
  --panel: #0f1a2b;
  --panel-strong: #12223a;
  --border: #1a2e4a;
  --text: #e4efff;
  --muted: #93a6c6;
  --accent: #3a7cff;
  --accent-2: #57b3ff;
  --green: #30ff30;
  --danger: #ff6b6b;
  --shadow: 0 24px 60px rgba(4, 10, 22, 0.55);
  font-family: "Outfit", "Space Grotesk", "Sora", "Manrope", sans-serif;
}

.tool-scope input,
.tool-scope select,
.tool-scope textarea {
  font-family: inherit;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  background: radial-gradient(circle at top, rgba(87, 179, 255, 0.2), transparent 52%),
    radial-gradient(circle at 15% 25%, rgba(58, 124, 255, 0.18), transparent 48%),
    var(--bg);
  color: var(--text);
  min-height: 100vh;
  padding: 48px 24px 80px;
}

body.mirror-page {
  min-width: 0;
}

.app {
  max-width: 1100px;
  margin: 0 auto;
  display: flex;
  flex-direction: column;
  gap: 32px;
}

.page {
  display: none;
}

.page.active {
  display: flex;
  flex-direction: column;
  gap: 32px;
}

.hero {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(260px, 1fr));
  gap: 24px;
  align-items: start;
}

.eyebrow {
  text-transform: uppercase;
  letter-spacing: 0.24em;
  font-size: 0.72rem;
  color: var(--muted);
  margin: 0 0 12px;
}

h1 {
  margin: 0 0 12px;
  font-size: clamp(2rem, 2vw + 1.6rem, 3rem);
  line-height: 1.1;
}

.subtitle {
  margin: 0;
  color: var(--muted);
  max-width: 520px;
}

.hero-links {
  margin-top: 16px;
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
}

.chip-link {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 8px 14px;
  border-radius: 12px;
  border: 1px solid var(--border);
  color: var(--text);
  text-decoration: none;
  background: rgba(18, 34, 58, 0.6);
}

.chip-link:hover {
  border-color: var(--accent-2);
}
.status-card {
  background: linear-gradient(140deg, rgba(21, 30, 43, 0.95), rgba(14, 20, 30, 0.95));
  border: 1px solid var(--border);
  padding: 20px;
  border-radius: 14px;
  box-shadow: var(--shadow);
  display: flex;
  flex-direction: column;
  gap: 12px;
  position: relative;
}

.status-top {
  display: flex;
  align-items: center;
  gap: 12px;
  font-weight: 600;
}

.status-dot {
  width: 12px;
  height: 12px;
  border-radius: 999px;
  background: var(--danger);
  box-shadow: 0 0 12px rgba(255, 107, 107, 0.6);
}

.status-dot[data-status="connected"] {
  background: var(--green);
  box-shadow: 0 0 12px rgba(60, 145, 207, 0.6);
}

.muted {
  color: var(--muted);
  margin: 0;
}

.status-actions {
  display: flex;
  flex-wrap: nowrap;
  gap: 12px;
  align-items: end;
}

.status-actions .field-group {
  min-width: 120px;
}

.status-split {
  display: grid;
  grid-template-columns: minmax(0, 2fr) minmax(0, 1fr);
  gap: 20px;
  align-items: start;
}

.status-main {
  display: grid;
  gap: 12px;
}

.status-side {
  display: grid;
  gap: 12px;
}

.status-meta {
  display: grid;
  gap: 16px;
}

.status-meta > div {
  display: grid;
  gap: 4px;
}

.status-inline {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  padding: 10px 14px;
  border-radius: 12px;
  border: 1px solid var(--border);
  background: rgba(18, 34, 58, 0.6);
  flex-wrap: wrap;
}

.status-divider {
  color: var(--muted);
}

.panel-grid {
  display: grid;
  gap: 24px;
  grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
}

.panel {
  background: var(--panel);
  border: 1px solid var(--border);
  padding: 24px;
  border-radius: 14px;
  box-shadow: var(--shadow);
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.firmware-panel {
  border-color: rgba(87, 179, 255, 0.45);
  background: linear-gradient(160deg, rgba(20, 35, 60, 0.95), rgba(12, 24, 42, 0.95));
  box-shadow: 0 18px 40px rgba(6, 16, 32, 0.45);
}

.firmware-panel h2 {
  color: #9ed4ff;
}

.panel h2 {
  margin: 0;
  font-size: 1.2rem;
}

.page-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 20px;
  flex-wrap: wrap;
}

.page#channels {
  width: 100%;
}

.page#channels .channel-panel {
  width: min(96vw, 1600px);
  align-self: center;
}

.page-head .subtitle {
  max-width: 640px;
}

.settings-panel {
  gap: 16px;
}

.settings-panel.is-locked .settings-grid {
  opacity: 0.6;
  pointer-events: none;
}

.settings-grid {
  display: grid;
  gap: 16px;
}

.settings-zone {
  background: linear-gradient(160deg, rgba(18, 34, 58, 0.9), rgba(12, 24, 42, 0.95));
  border: 1px solid var(--border);
  padding: 16px;
  border-radius: 14px;
  display: grid;
  gap: 12px;
}

.settings-zone h3 {
  margin: 0;
  font-size: 0.95rem;
  color: var(--text);
}

.settings-fields {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 12px 16px;
}

.settings-field {
  display: grid;
  gap: 6px;
  color: var(--muted);
  font-size: 0.85rem;
}

.settings-field select,
.settings-field input {
  width: 100%;
  background: #0f1b2c;
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: 8px;
  padding: 6px 8px;
  font-size: 0.85rem;
  font-family: inherit;
}
.channel-panel {
  gap: 12px;
  width: 100%;
  align-self: stretch;
}

.channel-actions {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
}

.channel-actions .action-group {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

.channel-search {
  flex-direction: column;
  align-items: flex-start;
  gap: 0;
}

.channel-search input {
  min-width: 220px;
  background: var(--panel-strong);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 6px 10px;
  border-radius: 8px;
  font-family: inherit;
}

.channel-search .muted {
  font-size: 0.8rem;
  margin-top: 40px;
  position: absolute;
}

.search-field {
  position: relative;
  display: inline-block;
}

.search-field input {
  padding-right: 32px;
  width: 260px;
}

.search-field .search-clear {
  position: absolute;
  right: 8px;
  width: 18px;
  height: 18px;
  top: 50%;
  transform: translateY(-50%);
}

.channel-status {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  color: var(--muted);
  font-size: 0.8rem;
}

.status-error {
  color: #ff9b9b;
}

.status-error[hidden],
.status-error-popup[hidden] {
  display: none;
}

.status-error-popup {
  color: #2b0b0b;
  background: rgba(255, 205, 205, 0.95);
  border: 1px solid rgba(255, 140, 140, 0.85);
  padding: 6px 8px;
  border-radius: 8px;
  position: absolute;
  right: 18px;
  bottom: 18px;
  max-width: min(320px, 80%);
  z-index: 2;
  box-shadow: 0 16px 30px rgba(6, 12, 20, 0.45);
  display: flex;
  align-items: flex-start;
  gap: 8px;
}

.status-error-text {
  flex: 1;
}

.status-error-close {
  background: transparent;
  color: inherit;
  font-weight: 700;
  font-size: 0.85rem;
  line-height: 1;
  padding: 2px 4px;
  cursor: pointer;
}

.status-error-close:focus {
  outline: 1px solid rgba(43, 11, 11, 0.6);
  outline-offset: 2px;
}

.status-error-close:hover {
  opacity: 0.75;
}

.table-wrap {
  border: 1px solid var(--border);
  border-radius: 10px;
  overflow-x: auto;
  overflow-y: auto;
  max-height: 520px;
  width: 100%;
  min-width: 0;
}

.channel-table {
  table-layout: fixed;
}

.channel-table thead th {
  position: sticky;
  top: 0;
  background: var(--panel);
  z-index: 1;
}

.channel-table {
  width: 100%;
  border-collapse: collapse;
  min-width: 1400px;
  font-size: 0.8rem;
}

.channel-table th:nth-child(2),
.channel-table td:nth-child(2) {
  width: 110px;
}

.channel-table th:nth-child(3),
.channel-table td:nth-child(3) {
  width: 130px;
}

.channel-table th:nth-child(6),
.channel-table td:nth-child(6) {
  width: 130px;
}

.channel-table th:nth-child(5),
.channel-table td:nth-child(5) {
  width: 120px;
}

.channel-table .row-actions {
  display: flex;
  gap: 6px;
  align-items: center;
  justify-content: center;
  /*width: 60px;*/
  min-height: 33px;
}

.action-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  color: var(--muted);
  cursor: pointer;
  position: relative;
}

.action-icon svg {
  width: 16px;
  height: 16px;
  stroke: currentColor;
  transition: transform 0.15s ease, color 0.15s ease;
}

.action-icon:hover {
  color: var(--text);
}

.action-icon:hover svg {
  transform: scale(1.1);
}

.action-tooltip {
  position: fixed;
  transform: translate(-50%, -100%);
  background: rgba(8, 17, 31, 0.95);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 4px 8px;
  border-radius: 8px;
  font-size: 0.72rem;
  white-space: nowrap;
  z-index: 10;
  pointer-events: none;
}

.action-icon[data-disabled="true"] {
  opacity: 0.4;
  cursor: not-allowed;
  pointer-events: none;
}

.channel-table th,
.channel-table td {
  border-bottom: 1px solid var(--border);
  border-right: 1px solid var(--border);
  padding: 4px 6px;
  text-align: center;
  background: rgba(12, 20, 36, 0.6);
}

.channel-table th {
  position: sticky;
  top: 0;
  z-index: 1;
  background: #0b1628;
  font-weight: 600;
}

.channel-table tr:nth-child(even) td {
  background: rgba(9, 16, 28, 0.7);
}

.channel-table tbody tr:hover td {
  background: rgba(58, 124, 255, 0.2);
}

.channel-table tbody tr.row-match td {
  background: rgba(58, 124, 255, 0.35);
}

.channel-table input,
.channel-table select {
  width: 100%;
  min-width: 64px;
  background: #0f1b2c;
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: 7px;
  padding: 3px 5px;
  font-size: 0.8rem;
  line-height: 1.2;

  font-family: inherit;}

.channel-table input[type="checkbox"] {
  width: 16px;
  height: 16px;
  min-width: 16px;
  accent-color: var(--accent);
}

.pagination {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  font-size: 0.8rem;
  color: var(--muted);
}

.pagination .page-actions {
  display: flex;
  gap: 8px;
}

.page-links {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
}

.page-link {
  min-width: 28px;
  height: 31px;
  border-radius: 8px;
  font-family: inherit;
  border: 1px solid var(--border);
  background: #0b1628;
  color: var(--text);
  font-size: 0.8rem;
  cursor: pointer;
  padding: 0 8px;
}

.page-link.active {
  border-color: var(--accent);
  color: var(--muted);
}

.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(6, 12, 20, 0.7);
  display: none;
  align-items: center;
  justify-content: center;
  z-index: 100;
  padding: 24px;
}

.modal-overlay.active {
  display: flex;
}

.modal-card {
  width: min(420px, 100%);
  background: #0f1a2b;
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 20px;
  box-shadow: var(--shadow);
  display: grid;
  gap: 12px;
}

.modal-card h2 {
  margin: 0;
  font-size: 1.1rem;
}

.field-group,
.field-row {
  display: flex;
  flex-direction: column;
  gap: 8px;
}


.tool-scope label {
  font-size: 0.9rem;
  color: var(--muted);
}

.tool-scope select,
.tool-scope input[type="file"] {
  background: var(--panel-strong);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 6px 12px;
  border-radius: 8px;
  font-family: inherit;
}

.tool-scope input[type="file"] {
  width: 100%;
  padding: 6px 10px;
  border-radius: 10px;
  background: linear-gradient(150deg, rgba(18, 34, 58, 0.9), rgba(12, 24, 42, 0.95));
}

.tool-scope input[type="file"]::file-selector-button {
  margin-right: 10px;
  border: 1px solid var(--border);
  background: linear-gradient(140deg, var(--accent), #2aa7c8);
  color: #041015;
  padding: 6px 12px;
  border-radius: 8px;
  font-weight: 600;
  cursor: pointer;
}

.tool-scope input[type="file"]::-webkit-file-upload-button {
  margin-right: 10px;
  border: 1px solid var(--border);
  background: linear-gradient(140deg, var(--accent), #2aa7c8);
  color: #041015;
  padding: 6px 12px;
  border-radius: 8px;
  font-weight: 600;
  cursor: pointer;
}

.tool-scope .channel-table td select {
  background: var(--panel-strong);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 2px 0px;
  border-radius: 4px;
  font-family: inherit;
}

.tool-scope button {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 8px 12px;
  border-radius: 8px;
  border: none;
  background: var(--accent);
  color: #06120c;
  font-weight: 600;
  cursor: pointer;
  transition: transform 0.2s ease, box-shadow 0.2s ease, opacity 0.2s ease;
}

.tool-scope button:hover:not(:disabled) {
  transform: translateY(-1px);
  box-shadow: 0 10px 24px rgba(60, 145, 207, 0.3);
}

.tool-scope button:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.is-disabled {
  opacity: 0.5;
  cursor: not-allowed;
  pointer-events: none;
}

.primary {
  background: linear-gradient(140deg, var(--accent), #2aa7c8);
  color: #041015;
}

.ghost {
  background: transparent;
  border: 1px solid var(--border);
  color: var(--text);
}

.ghost:hover:not(:disabled) {
  box-shadow: none;
  border-color: var(--accent-2);
}

.ghost.small {
  padding: 8px 12px;
  font-size: 0.85rem;
}

.btn-icon {
  display: inline-flex;
  align-items: center;
}

.btn-icon svg {
  width: 16px;
  height: 16px;
  stroke: currentColor;
}

.ghost.small .btn-icon svg {
  width: 14px;
  height: 14px;
}

.toggle {
  display: flex;
  align-items: center;
  gap: 12px;
  font-size: 0.95rem;
  color: var(--text);
}

.tool-scope .toggle input {
  accent-color: var(--accent);
  width: 18px;
  height: 18px;
}

.hint {
  color: var(--muted);
  font-size: 0.85rem;
  margin: 0;
}

.progress {
  display: none;
  gap: 8px;
}

.progress.active {
  display: grid;
}

.progress-label {
  display: flex;
  justify-content: space-between;
  font-size: 0.85rem;
  color: var(--muted);
}

.progress-bar {
  height: 8px;
  border-radius: 8px;
  font-family: inherit;
  background: #0b1424;
  border: 1px solid var(--border);
  overflow: hidden;
}

.progress-fill {
  height: 100%;
  width: 0%;
  border-radius: 8px;
  font-family: inherit;
  background: linear-gradient(90deg, var(--accent), var(--accent-2));
  transition: width 0.2s ease;
}

.log-panel {
  min-height: 180px;
}

.log-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.log-output {
  font-family: "JetBrains Mono", "Fira Code", monospace;
  background: #0a0f16;
  border: 1px solid var(--border);
  padding: 16px;
  border-radius: 10px;
  min-height: 120px;
  max-height: 260px;
  overflow-y: auto;
  font-size: 0.85rem;
  line-height: 1.5;
}

.sms-log {
  display: flex;
  flex-direction: column;
  min-height: 300px;
  max-height: 300px;
  gap: 8px;
}

.sms-entry {
  display: flex;
  align-items: baseline;
  gap: 10px;
  padding: 8px 10px;
  border-radius: 8px;
  border: 1px solid transparent;
  background: rgba(12, 20, 36, 0.6);
}

.sms-entry[data-direction="in"] {
  border-color: rgba(88, 194, 134, 0.35);
  background: rgba(88, 194, 134, 0.14);
  color: #d8ffe7;
}

.sms-entry[data-direction="out"] {
  border-color: var(--border);
  background: rgba(12, 20, 36, 0.6);
}

.sms-entry.sms-ack {
  border-color: rgba(88, 194, 134, 0.35);
}

.sms-entry[data-tone="system"] {
  border-color: rgba(148, 168, 205, 0.2);
  background: rgba(9, 16, 28, 0.7);
  color: var(--muted);
}

.sms-label {
  font-weight: 600;
  color: var(--muted);
  min-width: 48px;
}

.sms-text {
  white-space: pre-wrap;
  word-break: break-word;
}

.sms-meta {
  margin-left: auto;
  font-size: 0.75rem;
  font-weight: 600;
  color: #7ee4a9;
  padding: 2px 6px;
  border-radius: 999px;
  border: 1px solid rgba(88, 194, 134, 0.4);
  background: rgba(88, 194, 134, 0.16);
}

.sms-compose {
  display: flex;
  gap: 12px;
  align-items: center;
  flex-wrap: wrap;
}

.sms-compose input[type="text"] {
  flex: 1;
  min-width: 220px;
  background: var(--panel-strong);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 10px 12px;
  border-radius: 8px;
  font-size: 0.9rem;
  font-family: inherit;
}

.sms-compose input[type="text"]::placeholder {
  color: var(--muted);
}

.log-output [data-tone="error"] {
  color: #ff9b9b;
  background: rgba(255, 107, 107, 0.12);
  border: 1px solid rgba(255, 107, 107, 0.35);
  padding: 6px 8px;
  border-radius: 8px;
  margin-bottom: 6px;
  display: inline-block;
}

.footer {
  display: flex;
  justify-content: center;
  align-items: center;
  flex-wrap: wrap;
  gap: 10px 16px;
  color: var(--muted);
  font-size: 0.85rem;
  padding-top: 8px;
}

.footer-note a {
  color: var(--accent-2);
  text-decoration: none;
}

.footer-note a:hover {
  text-decoration: underline;
}

.mirror-status {
  display: grid;
  grid-template-columns: minmax(0, 2fr) minmax(0, 1fr);
  gap: 20px;
  align-items: start;
}

.mirror-actions {
  display: flex;
  flex-wrap: nowrap;
  justify-content: center;
  gap: 12px;
  grid-area: mirror-actions;
}

.mirror-select {
  display: flex;
  justify-content: center;
  width: 100%;
  grid-area: mirror-select;
}

.mirror-host {
  width: 100%;
  display: grid;
  grid-template-columns: auto minmax(180px, 1fr);
  grid-template-areas:
    "mirror-actions mirror-select"
    "mirror-lcd mirror-lcd";
  gap: 16px;
  align-items: center;
  justify-items: center;
}

.lcd-shell {
  grid-area: mirror-lcd;
  width: min(100%, 760px);
  padding: 12px;
  border-radius: 12px;
  border: 1px solid var(--border);
  box-shadow: inset 0 0 40px rgba(0, 0, 0, 0.5);
}

.lcd-shell canvas {
  width: 100%;
  height: auto;
  display: block;
}

.lcd-amber {
  background: linear-gradient(160deg, #ffb45e, #e07f2a);
}

.lcd-white {
  background: linear-gradient(160deg, #f3f7ff, #cfdcff);
}

@media (max-width: 900px) {
  .mirror-status {
    grid-template-columns: 1fr;
  }

  .status-split {
    grid-template-columns: 1fr;
  }

  .mirror-actions {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 720px) {
  body {
    padding: 32px 18px 60px;
  }

  .status-actions {
    flex-direction: column;
  }
}
