:root {
  --bg: #0f1419;
  --panel: #1a2332;
  --accent: #3b82f6;
  --text: #e7ecf3;
  --muted: #94a3b8;
  --danger: #f87171;
  --border: #2d3a4f;
  --touch-min: 48px;
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --safe-top: env(safe-area-inset-top, 0px);
}

* { box-sizing: border-box; }

html {
  -webkit-text-size-adjust: 100%;
}

body {
  margin: 0;
  font-family: system-ui, -apple-system, Segoe UI, Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  min-height: 100dvh;
  padding-bottom: var(--safe-bottom);
}

.muted { color: var(--muted); font-size: 0.9rem; }
.error { color: var(--danger); }

.top-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  align-items: center;
}

.top {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 0.75rem;
  padding: calc(0.75rem + var(--safe-top)) 1rem 0.75rem;
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 20;
  background: rgba(15, 20, 25, 0.92);
  backdrop-filter: blur(8px);
}

.top h1 {
  margin: 0;
  font-size: 1.35rem;
  line-height: 1.2;
}

.top .muted {
  margin: 0.25rem 0 0;
  font-size: 0.8rem;
  line-height: 1.35;
}

.layout {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(min(100%, 320px), 1fr));
  gap: 1rem;
  padding: 1rem;
  padding-bottom: calc(1rem + var(--safe-bottom));
}

.panel {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 1rem;
}

.panel h2 {
  margin: 0 0 0.75rem;
  font-size: 1.1rem;
}

.receiver-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(min(100%, 158px), 1fr));
  gap: 0.75rem;
}

.receiver-card {
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 0.75rem;
  cursor: pointer;
  transition: border-color 0.15s;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
}

.receiver-card.active-select {
  border-color: var(--accent);
  box-shadow: 0 0 0 1px var(--accent);
}

.receiver-card.inactive { opacity: 0.5; }
.receiver-card h3 { margin: 0 0 0.25rem; font-size: 1rem; word-break: break-word; }

.receiver-card .tag {
  display: inline-block;
  font-size: 0.75rem;
  text-transform: uppercase;
  background: #1e3a5f;
  padding: 0.15rem 0.45rem;
  border-radius: 4px;
  margin: 0 0 0.5rem;
}

.receiver-card input[type="text"] { font-size: 16px; }
.receiver-card input[type="checkbox"] {
  width: 1.25rem;
  height: 1.25rem;
  vertical-align: middle;
  margin-right: 0.35rem;
}

.channel-btns { margin: 0.75rem 0; }

.remote-pad {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 0.5rem;
  width: 100%;
  max-width: 360px;
  margin: 0 auto;
}

.remote-pad button {
  min-height: var(--touch-min);
  font-size: 1rem;
  font-weight: 500;
}

.btn,
button {
  background: var(--accent);
  color: #fff;
  border: none;
  border-radius: 10px;
  padding: 0.65rem 1rem;
  min-height: var(--touch-min);
  cursor: pointer;
  font-size: 1rem;
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
}

.btn.ghost,
button.ghost {
  background: transparent;
  border: 1px solid var(--border);
  color: var(--text);
}

.btn.primary { font-weight: 600; }

.btn:disabled,
button:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

.row {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  margin-bottom: 0.75rem;
  align-items: stretch;
}

.row input { flex: 1 1 140px; }
.row .btn { flex: 0 1 auto; }

input,
select {
  width: 100%;
  padding: 0.65rem 0.75rem;
  min-height: var(--touch-min);
  border-radius: 10px;
  border: 1px solid var(--border);
  background: #0b1018;
  color: var(--text);
  margin-top: 0.25rem;
  font-size: 16px;
}

label {
  display: block;
  margin-bottom: 0.75rem;
  font-size: 0.9rem;
}

.learn-prompt { font-size: 1.05rem; font-weight: 600; line-height: 1.4; }

.learn-wizard .btn {
  width: 100%;
  margin-bottom: 0.5rem;
}

.learn-progress {
  list-style: none;
  padding: 0;
  font-size: 0.85rem;
  columns: 2;
  gap: 0.5rem;
}

.learn-progress li.done { color: #4ade80; }
.learn-progress li.current { color: var(--accent, #60a5fa); font-weight: 600; }
.learn-hint { font-size: 0.9rem; margin: 0.5rem 0 1rem; }

dialog.learn-modal {
  max-width: min(520px, 96vw);
  width: min(520px, 96vw);
  padding: 1.25rem 1.5rem 1.5rem;
  text-align: center;
}

.learn-modal-step {
  font-size: 0.95rem;
  margin: 0 0 0.25rem;
}

.learn-modal-key {
  font-size: clamp(5rem, 28vw, 9rem);
  font-weight: 800;
  line-height: 1;
  margin: 0.35rem 0 0.5rem;
  letter-spacing: -0.02em;
  color: var(--accent, #60a5fa);
  user-select: none;
}

.learn-modal-key.is-text {
  font-size: clamp(2rem, 10vw, 3.25rem);
  line-height: 1.15;
}

.learn-modal-sub {
  font-size: 1.05rem;
  font-weight: 600;
  margin: 0 0 0.5rem;
  line-height: 1.35;
}

.learn-modal-actions {
  justify-content: center;
  gap: 0.75rem;
  margin-top: 1rem;
}

.learn-modal-actions .btn {
  flex: 1;
  min-height: var(--touch-min, 44px);
}

dialog.learn-modal .learn-progress {
  margin-top: 0.75rem;
  text-align: left;
  max-height: 8rem;
  overflow: auto;
}

.channel-list {
  list-style: none;
  padding: 0;
  margin: 0.75rem 0;
  max-height: min(55vh, 420px);
  overflow: auto;
  -webkit-overflow-scrolling: touch;
}

.channel-list li button {
  width: 100%;
  text-align: left;
  background: #111827;
  margin-bottom: 0.35rem;
  min-height: var(--touch-min);
  padding: 0.75rem;
}

dialog {
  background: var(--panel);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 1rem;
  padding-bottom: calc(1rem + var(--safe-bottom));
  max-width: 420px;
  width: min(420px, 94vw);
  margin: auto;
}

dialog::backdrop {
  background: rgba(0, 0, 0, 0.65);
}

dialog form {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

dialog h3 { margin: 0 0 0.25rem; }

.auth-page {
  display: grid;
  place-items: center;
  min-height: 100vh;
  min-height: 100dvh;
  padding: 1rem;
}

.auth-card { width: min(360px, 100%); }

.auth-card button[type="submit"] {
  width: 100%;
  margin-top: 0.5rem;
}

.card {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 1.5rem;
}

.home-main {
  padding: 0.75rem;
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
  margin: 0 auto;
  max-width: 960px;
  width: 100%;
}

.home-main.home-layout {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}

.receiver-menu {
  padding: 0.5rem;
  margin: 0;
}

.receiver-menu-rows {
  display: flex;
  flex-direction: column;
  gap: 0.45rem;
}

.receiver-menu-row {
  display: flex;
  flex-direction: row;
  flex-wrap: wrap;
  gap: 0.4rem;
}

.receiver-menu-item {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 0.15rem;
  flex: 1 1 calc(20% - 0.4rem);
  min-width: 5.5rem;
  max-width: 100%;
  text-align: left;
  padding: 0.55rem 0.65rem;
  border: 1px solid transparent;
  border-radius: 10px;
  background: transparent;
  color: var(--text);
  cursor: pointer;
  font: inherit;
}

.receiver-menu-item:hover {
  background: #111827;
  border-color: var(--border);
}

.receiver-menu-item.active {
  background: rgba(34, 197, 94, 0.12);
  border-color: #22c55e;
}

.receiver-menu-item.active .receiver-menu-name {
  color: #4ade80;
}

.receiver-menu-item.inactive {
  opacity: 0.45;
  cursor: not-allowed;
}

.receiver-menu-name {
  font-weight: 600;
  font-size: 1rem;
  line-height: 1.25;
}

.receiver-menu-meta {
  font-size: 0.8rem;
}

.receiver-panel {
  display: flex;
  flex-direction: column;
  min-height: 0;
  min-width: 0;
}

.receiver-panel-head {
  margin: 0 0 0.75rem;
}

.receiver-panel-title {
  margin: 0;
  font-size: 1.25rem;
  font-weight: 600;
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  gap: 0.35rem 0.65rem;
  line-height: 1.3;
}

.receiver-panel-name {
  font-weight: 600;
}

.receiver-panel-meta {
  font-size: 0.85rem;
  font-weight: 400;
}

.remote-section {
  margin-top: 1rem;
  padding-top: 0.75rem;
  border-top: 1px solid var(--border);
}

.remote-section-title {
  margin: 0 0 0.5rem;
  font-size: 0.9rem;
  font-weight: 600;
  color: var(--muted);
}

.channel-list-vertical {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.3rem 0.4rem;
  align-content: start;
}

.ch-btn-row {
  display: block;
  width: 100%;
  text-align: left;
  background: #111827;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 0.55rem 0.65rem;
  min-height: 44px;
  color: var(--text);
  cursor: pointer;
}

.ch-btn-row:hover { border-color: #3b556f; }
.ch-btn-row:active { border-color: var(--accent); background: #1a2740; }

.ch-btn-row.last-pressed {
  border-color: #eab308;
  background: rgba(234, 179, 8, 0.22);
  box-shadow: 0 0 0 1px rgba(234, 179, 8, 0.45);
}

.ch-btn-row.last-pressed .ch-name {
  color: #fde047;
  font-weight: 600;
}

.toast {
  position: fixed;
  left: 50%;
  transform: translate(-50%, -8px);
  z-index: 1000;
  max-width: min(92vw, 36rem);
  padding: 0.7rem 1.1rem;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: #1f2937;
  color: #f9fafb;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.4);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s, transform 0.2s;
}

.icon-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: var(--touch-min);
  padding: 0.5rem;
}

.icon-btn.has-dot { position: relative; }
.icon-btn.has-dot::after {
  content: '';
  position: absolute;
  top: 6px;
  right: 6px;
  width: 9px;
  height: 9px;
  border-radius: 50%;
  background: #22c55e;
}

.icon {
  width: 1.4rem;
  height: 1.4rem;
  fill: none;
  stroke: currentColor;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.toast[popover] {
  right: auto;
  bottom: auto;
  margin: 0;
  overflow: visible;
}

.toast-show {
  opacity: 1;
  transform: translate(-50%, 0);
}

.toast-error {
  border-color: #ef4444;
  background: #3f1d1d;
}

.toast-success {
  border-color: #22c55e;
  background: #14301f;
}

.send-locked .ch-btn:not(.sending),
.send-locked .remote-key {
  opacity: 0.45;
  cursor: wait;
}

.ch-btn-row.sending {
  border-color: #eab308;
  animation: ch-sending 0.8s ease-in-out infinite alternate;
}

@keyframes ch-sending {
  from { background: rgba(234, 179, 8, 0.08); }
  to { background: rgba(234, 179, 8, 0.32); }
}

.remote-key.last-pressed {
  border-color: #22c55e;
  background: rgba(34, 197, 94, 0.18);
  color: #4ade80;
  font-weight: 600;
}
.ch-name {
  font-size: 0.95rem;
  line-height: 1.3;
  min-width: 0;
}

.ch-freq {
  display: none;
}

@media (min-width: 640px) {
  body.page-home .home-main.home-layout {
    padding: 1rem;
  }

  body.page-home .channel-list-vertical {
    grid-template-columns: 1fr 1fr;
    gap: 0.45rem 0.55rem;
  }

  body.page-home .ch-btn-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.5rem;
  }

  body.page-home .ch-freq {
    display: block;
    flex-shrink: 0;
    font-size: 0.68rem;
    line-height: 1.2;
    color: var(--muted);
    letter-spacing: 0.02em;
  }

  body.page-home .ch-btn-row.last-pressed .ch-freq {
    color: #ca8a04;
  }
}

@media (max-width: 639px) {
  body.page-home .receiver-menu-row {
    flex-wrap: nowrap;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    padding-bottom: 0.25rem;
  }

  body.page-home .receiver-menu-item {
    flex: 0 0 auto;
    min-width: 7.5rem;
  }
}

.remote-details { margin-top: 0.75rem; }
.remote-details summary {
  cursor: pointer;
  padding: 0.5rem 0;
  font-size: 0.9rem;
  color: var(--muted);
}

.remote-pad.compact {
  max-width: none;
  margin-top: 0.5rem;
}

.empty { text-align: center; padding: 2rem 1rem; }

.settings-rec {
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 0.75rem;
  margin-bottom: 0.75rem;
}

.ch-table { width: 100%; border-collapse: collapse; font-size: 0.9rem; }
.ch-table th, .ch-table td { padding: 0.35rem; vertical-align: middle; }
.ch-table input { margin: 0; min-height: 40px; }
.btn-sm { min-height: 40px; padding: 0.35rem 0.6rem; font-size: 0.85rem; }

.settings-layout { max-width: 960px; margin: 0 auto; }

.settings-menu {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  padding: 0.75rem 1rem;
  border-bottom: 1px solid var(--border);
  background: rgba(15, 20, 25, 0.95);
  position: sticky;
  top: 0;
  z-index: 15;
}

.settings-menu-item {
  min-height: 44px;
  padding: 0.5rem 1rem;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: #111827;
  color: var(--text);
  cursor: pointer;
  font-size: 0.95rem;
}

.settings-menu-item.active {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
}

.settings-view.hidden {
  display: none;
}

.settings-page {
  max-width: 720px;
  margin: 0 auto;
  padding: 1rem;
}

.provider-tabs {
  display: flex;
  flex-wrap: wrap;
  gap: 0.35rem;
  margin-bottom: 1rem;
}

.panel-inset {
  background: #111827;
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 0.85rem;
  margin-bottom: 1rem;
}

.panel-inset h3 {
  margin: 0 0 0.65rem;
  font-size: 1rem;
}

.provider-create-inline {
  margin-top: 1rem;
}

.learn-timing {
  margin-top: 1.25rem;
}

.learn-timing input[type="number"] {
  width: 8rem;
}

.profile-card-head {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem 1rem;
  align-items: baseline;
  margin-bottom: 0.6rem;
}

.provider-create-inline summary {
  cursor: pointer;
  font-weight: 600;
  font-size: 0.95rem;
  margin-bottom: 0.5rem;
}

.provider-create-inline[open] summary {
  margin-bottom: 0.65rem;
}

.port-tabs {
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
  margin-bottom: 1rem;
}

.port-tabs-row {
  display: flex;
  flex-direction: row;
  flex-wrap: wrap;
  gap: 0.35rem;
}

.port-tabs-row .port-tab {
  flex: 1 1 calc(20% - 0.35rem);
  min-width: 4.5rem;
}

.port-tab {
  min-height: 40px;
  padding: 0.4rem 0.65rem;
  font-size: 0.85rem;
  background: #111827;
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: 8px;
  cursor: pointer;
}

.port-tab.active {
  border-color: var(--accent);
  background: #1e3a5f;
}

.port-tab.off {
  opacity: 0.65;
}

.receiver-editor .rec-editor-title {
  margin: 0 0 0.5rem;
  font-size: 1.15rem;
}

.receiver-editor .check-row {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.receiver-editor .check-row input {
  width: auto;
  min-height: auto;
  margin: 0;
}

.provider-hint {
  font-size: 0.9rem;
  line-height: 1.45;
  margin: 0 0 0.75rem;
}

#remote-panel {
  scroll-margin-top: 5rem;
}

/* ——— Mobile ——— */
@media (max-width: 768px) {
  .layout {
    grid-template-columns: 1fr;
    gap: 0.75rem;
    padding: 0.75rem;
  }

  .top .btn.ghost {
    flex-shrink: 0;
    padding-left: 0.75rem;
    padding-right: 0.75rem;
  }

  #remote-panel:not([hidden]) {
    order: 2;
    position: sticky;
    bottom: var(--safe-bottom);
    z-index: 15;
    box-shadow: 0 -8px 24px rgba(0, 0, 0, 0.45);
  }

  #settings-panel {
    order: 3;
  }

  .remote-pad {
    max-width: none;
    gap: 0.4rem;
  }

  .remote-pad button {
    min-height: 52px;
  }

  #btn-channels {
    width: 100%;
  }

  .learn-progress {
    columns: 1;
  }

  dialog {
    width: 100%;
    max-width: none;
    height: auto;
    max-height: min(92dvh, 100%);
    margin: auto 0 0;
    border-radius: 16px 16px 0 0;
    align-self: end;
  }

  dialog[open] {
    display: flex;
    flex-direction: column;
  }

  dialog.learn-modal {
    width: 100%;
    max-width: none;
    margin: auto 0 0;
    border-radius: 20px 20px 0 0;
    padding-top: 1.5rem;
  }

  .learn-modal-key {
    font-size: clamp(6rem, 34vw, 10rem);
  }

  .channel-list {
    max-height: min(50dvh, 360px);
  }
}

@media (max-width: 380px) {
  .receiver-grid {
    grid-template-columns: 1fr;
  }

  .top h1 { font-size: 1.2rem; }
}

@media (pointer: coarse) {
  .receiver-card label.small {
    padding: 0.25rem 0;
  }
}


.device-number {
  font-family: ui-monospace, Consolas, monospace;
  font-size: 1.8rem;
  font-weight: 700;
  letter-spacing: 0.05em;
  margin: 0.25rem 0 0.75rem;
}
.activate-card { text-align: center; }
.update-banner {
  display: flex; align-items: center; justify-content: space-between; gap: 0.8rem; flex-wrap: wrap;
  margin-top: 1rem; padding: 0.7rem 0.9rem;
  border: 1px solid #22c55e; border-radius: 10px; background: #14301f;
}
.update-banner[hidden], .update-banner [hidden] { display: none; }
.update-banner p { margin: 0.2rem 0 0; }
.update-banner p:empty { display: none; }

#view-update .device-info { margin-bottom: 0.9rem; }
#update-hint { margin: 0 0 1rem; }
.update-progress { margin: 0 0 1rem; }
.update-progress[hidden] { display: none; }
.update-progress-bar { height: 0.7rem; border-radius: 999px; background: var(--bg); border: 1px solid var(--border); overflow: hidden; }
.update-progress-fill { height: 100%; width: 0; background: linear-gradient(90deg, #3b82f6, #22c55e); transition: width 0.3s; }
.update-progress-fill.indeterminate { width: 35%; animation: update-indeterminate 1.2s ease-in-out infinite; }
@keyframes update-indeterminate { from { margin-left: -35%; } to { margin-left: 100%; } }
.update-progress-text { display: flex; justify-content: space-between; margin-top: 0.35rem; font-size: 0.85rem; color: var(--muted); }
.update-rollback { margin-top: 1.2rem; padding-top: 1rem; border-top: 1px solid var(--border); }
.update-rollback h3 { margin: 0 0 0.3rem; font-size: 1rem; }
.update-rollback[hidden], .update-rollback [hidden] { display: none; }
.inline-confirm { margin-top: 0.6rem; padding: 0.7rem 0.9rem; border: 1px solid #b45309; border-radius: 10px; background: rgba(180, 83, 9, 0.15); }
.inline-confirm p { margin: 0 0 0.6rem; }
.inline-confirm .row { margin: 0; gap: 0.5rem; }
.btn.danger { background: #dc2626; border-color: #dc2626; color: #fff; }
.btn.danger:hover { background: #b91c1c; }
.activation-request { text-align: left; margin-top: 1rem; }
.activation-request h2 { margin: 0 0 0.5rem; font-size: 1.1rem; }
.activation-form { display: flex; flex-direction: column; gap: 0.6rem; }
.activation-form label { display: flex; flex-direction: column; gap: 0.25rem; }
.activation-form p { margin: 0; }
.activation-request[hidden], .activation-request [hidden] { display: none; }
.device-info { display: grid; grid-template-columns: max-content 1fr; gap: 0.35rem 1rem; margin: 0; }
.device-info dt { color: var(--muted); }
.device-info dd { margin: 0; }

.renew-notice { color: #fbbf24; font-weight: 600; font-size: 0.95rem; }

/* Διαφήμιση από το cloud (και ο editor του cloud) */
.announcement { margin-top: 1rem; overflow-wrap: anywhere; line-height: 1.5; }
.announcement[hidden] { display: none; }
.announcement > :first-child, .rich > :first-child { margin-top: 0; }
.announcement > :last-child, .rich > :last-child { margin-bottom: 0; }
.announcement h2, .rich h2 { font-size: 1.6rem; margin: 0.6rem 0; color: inherit; }
.announcement h3, .rich h3 { font-size: 1.25rem; margin: 0.5rem 0; color: inherit; }
.announcement p, .rich p { margin: 0.4rem 0; }
.announcement img, .rich img { max-width: 100%; height: auto; border-radius: 8px; }
.announcement a, .rich a { color: var(--accent, #4ea1ff); }
.announcement blockquote, .rich blockquote { margin: 0.5rem 0; padding-left: 0.8rem; border-left: 3px solid var(--muted); }

.auth-back { display: flex; justify-content: center; width: 100%; margin-top: 0.5rem; }

.backup-list { list-style: none; margin: 0.5rem 0 1rem; padding: 0; }
.backup-list li { display: flex; align-items: center; justify-content: space-between; gap: 0.75rem; padding: 0.5rem 0; border-bottom: 1px solid var(--border, #2a3242); }

.cloud-providers { display: flex; flex-direction: column; gap: 0.5rem; margin: 0.75rem 0; max-height: 50vh; overflow: auto; }
.cloud-provider { display: flex; gap: 0.6rem; align-items: flex-start; padding: 0.5rem; border: 1px solid var(--border, #2a3242); border-radius: 10px; cursor: pointer; }
.cloud-provider input { width: auto; min-height: 0; margin-top: 0.2rem; }
.provider-own input { flex: 1; min-width: 10rem; }
