:root {
  --bg: #0d1017;
  --panel: #151a24;
  --panel-2: #1c2230;
  --line: #2a3242;
  --text: #e8ecf3;
  --muted: #8b95a7;
  --accent: #3d8bff;
  --accent-2: #2f6fd0;
  --danger: #ff5c5c;
  --ok: #3ddc84;
  --radius: 10px;
  color-scheme: dark;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}

h2 { margin: 0 0 14px; font-size: 17px; }
.hint { color: var(--muted); font-size: 13px; font-weight: normal; }
.empty { color: var(--muted); text-align: center; padding: 24px 0; margin: 0; }
.error { color: var(--danger); margin: 0; }

.brand { display: flex; align-items: center; gap: 8px; font-weight: 700; font-size: 18px; }
.brand small { color: var(--muted); font-weight: 500; font-size: 13px; }
.logo {
  display: inline-grid; place-items: center; width: 28px; height: 28px; border-radius: 7px;
  background: var(--accent); color: #fff; font-size: 13px;
}

.card { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 20px; }

label { display: grid; gap: 6px; margin-bottom: 14px; font-weight: 600; font-size: 14px; }
input, select, textarea {
  width: 100%; padding: 10px 12px; border-radius: 8px; border: 1px solid var(--line);
  background: var(--panel-2); color: var(--text); font: inherit; font-weight: normal;
}
textarea { font: 13px/1.5 ui-monospace, "Cascadia Code", Consolas, monospace; resize: vertical; }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--accent); outline-offset: -1px; }

button { font: inherit; cursor: pointer; border-radius: 8px; border: 1px solid transparent; padding: 9px 16px; }
button.primary { background: var(--accent); color: #fff; font-weight: 600; }
button.primary:hover { background: var(--accent-2); }
button.ghost { background: transparent; color: var(--text); border-color: var(--line); }
button.ghost:hover { background: var(--panel-2); }
button.danger { background: transparent; color: var(--danger); border-color: #4a2a2a; }
button.link { background: none; border: none; color: var(--accent); padding: 0 4px; }
button.small { padding: 4px 10px; font-size: 13px; }
.row { display: flex; gap: 8px; }

/* Login */
.login { min-height: 100vh; display: grid; place-items: center; padding: 16px; }
.login-card { width: min(380px, 100%); display: grid; gap: 16px; }
.login-card label { margin: 0; }

/* Top bar */
.topbar {
  display: flex; align-items: center; gap: 24px; padding: 12px 24px;
  border-bottom: 1px solid var(--line); background: var(--panel); position: sticky; top: 0; z-index: 2;
  flex-wrap: wrap;
}
.tabs { display: flex; gap: 4px; flex: 1; flex-wrap: wrap; }
.tabs button { background: none; color: var(--muted); }
.tabs button.active { background: var(--panel-2); color: var(--text); }
.topbar-right { display: flex; align-items: center; gap: 16px; }
.online { display: flex; align-items: center; gap: 6px; color: var(--muted); }
.online b { color: var(--text); }
.dot { width: 8px; height: 8px; border-radius: 50%; background: var(--ok); }

.tab { padding: 24px; max-width: 1280px; margin: 0 auto; }
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 24px; align-items: start; }
@media (max-width: 900px) {
  .grid-2 { grid-template-columns: 1fr; }
  .tab { padding: 16px; }
  .topbar { padding: 12px 16px; gap: 12px; }
}

.send-to { border: 0; padding: 0; margin: 0 0 14px; display: flex; gap: 20px; align-items: center; flex-wrap: wrap; }
.send-to legend { font-weight: 600; font-size: 14px; padding: 0; margin-bottom: 6px; float: left; width: 100%; }
label.radio { display: flex; flex-direction: row; align-items: center; gap: 8px; margin: 0; font-weight: 500; cursor: pointer; }
label.radio input { width: auto; }
#target-status { min-height: 1em; }
.suggest {
  list-style: none; margin: 0; padding: 4px; font-weight: normal;
  background: var(--panel-2); border: 1px solid var(--line); border-radius: var(--radius);
  max-height: 280px; overflow-y: auto;
}
.suggest li { display: flex; justify-content: space-between; gap: 12px; padding: 10px 12px; border-radius: 6px; cursor: pointer; }
.suggest li .hint { white-space: nowrap; }
.suggest li:hover, .suggest li.active { background: var(--accent-2); }
.suggest li:hover .hint, .suggest li.active .hint { color: var(--text); }
.suggest li.suggest-empty { color: var(--muted); cursor: default; }
.suggest li.suggest-empty:hover { background: none; }

.settings-card { max-width: 760px; }
.switch-row {
  display: flex; flex-direction: row; align-items: flex-start; justify-content: space-between; gap: 24px;
  font-weight: normal; margin: 0;
}
.switch-row > span { display: grid; gap: 4px; }
.switch-row em { color: var(--text); font-style: normal; }
input[role="switch"] {
  appearance: none; flex: none; width: 46px; height: 26px; padding: 0; border-radius: 99px;
  background: var(--line); position: relative; cursor: pointer; transition: background .15s;
}
input[role="switch"]::after {
  content: ""; position: absolute; top: 3px; left: 3px; width: 20px; height: 20px; border-radius: 50%;
  background: #fff; transition: transform .15s;
}
input[role="switch"]:checked { background: var(--accent); }
input[role="switch"]:checked::after { transform: translateX(20px); }

.label-row { display: flex; justify-content: space-between; align-items: baseline; font-weight: 600; font-size: 14px; margin-bottom: 6px; flex-wrap: wrap; }
.templates { color: var(--muted); font-weight: normal; font-size: 13px; }

/* TV preview: mirrors the app's popup (60% width, dark card, OK button). */
.tv {
  position: relative; aspect-ratio: 16 / 9; border-radius: 8px; overflow: hidden;
  border: 6px solid #05070a; background: #000;
}
.tv-video {
  position: absolute; inset: 0;
  background: linear-gradient(135deg, #1b3b5f 0%, #3a1f4d 50%, #0f2a2a 100%);
  filter: saturate(0.7) brightness(0.6);
}
.tv-popup {
  position: absolute; left: 20%; right: 20%; top: 10%; bottom: 10%;
  background: #151a24; border-radius: 10px; display: flex; flex-direction: column;
  box-shadow: 0 10px 40px #000a; overflow: hidden;
}
/* .tv-content reserves the scaled space; the iframe is real TV size, scaled by admin.js. */
.tv-content { flex: none; width: 100%; }
.tv-popup iframe {
  position: absolute; top: 0; left: 0; border: 0; background: transparent;
  transform-origin: top left;
}
.tv-ok {
  margin-top: auto;
  align-self: center; margin-bottom: 4%; padding: 3px 26px; border-radius: 5px;
  background: #fff; color: #000; font-weight: 700; font-size: 11px;
}

/* Tables */
.table { width: 100%; border-collapse: collapse; font-size: 14px; }
.table th { text-align: left; color: var(--muted); font-weight: 600; padding: 8px; border-bottom: 1px solid var(--line); }
.table td { padding: 10px 8px; border-bottom: 1px solid var(--line); vertical-align: middle; }
.card { overflow-x: auto; }
.badge { display: inline-block; padding: 1px 8px; border-radius: 99px; font-size: 12px; font-weight: 600; }
.badge.live { background: #163d2a; color: var(--ok); }
.badge.expired { background: #2a2f3a; color: var(--muted); }
.badge.revoked { background: #3d1c1c; color: var(--danger); }

/* DNS list */
.dns-list { list-style: none; margin: 0; padding: 0; display: grid; gap: 8px; }
.dns-list li {
  display: flex; align-items: center; gap: 12px; padding: 10px 12px;
  background: var(--panel-2); border: 1px solid var(--line); border-radius: 8px;
}
.dns-list .dns-info { flex: 1; min-width: 0; }
.dns-list .dns-name { font-weight: 600; }
.dns-list .dns-url { color: var(--muted); font-size: 13px; overflow-wrap: anywhere; }
.dns-list .order { display: flex; flex-direction: column; }
.dns-list .order button { padding: 0 6px; background: none; color: var(--muted); line-height: 1.2; }

/* Weekly messages */
.weekly-list .weekly-when { color: var(--muted); font-size: 13px; }
.weekly-list li.off .dns-name, .weekly-list li.off .weekly-when { opacity: .55; }
.weekly-days { gap: 14px; }
.weekly-at > label { flex: 1; }

.toast {
  position: fixed; bottom: 24px; left: 50%; transform: translateX(-50%);
  background: var(--panel-2); border: 1px solid var(--line); padding: 10px 18px; border-radius: 8px;
  box-shadow: 0 8px 30px #0008; z-index: 10;
}

/* Updates */
label.check-row { display: flex; flex-direction: row; align-items: flex-start; gap: 10px; font-weight: normal; }
label.check-row input { width: auto; margin-top: 4px; }
label.check-row > span { display: grid; gap: 2px; }
code { background: var(--panel-2); border: 1px solid var(--line); border-radius: 6px; padding: 3px 8px; font-size: 13px; overflow-wrap: anywhere; }
.badge.required { background: #3d2e12; color: var(--warn, #ffb347); }
.badge.optional { background: #2a2f3a; color: var(--muted); }

.logo-img { width: 34px; height: 34px; object-fit: contain; }
.login-card .logo-img { width: 56px; height: 56px; }

.badge.scheduled { background: #16304f; color: #7fb6ff; }
.badge.online { background: #163d2a; color: var(--ok); }
.device-name { font-weight: 600; }
.device-model { color: var(--muted); font-size: 12px; }
.actions { white-space: nowrap; }

/* ---------- Phones: one-row swipeable menu, tables become stacked cards ---------- */
@media (max-width: 700px) {
  .topbar { display: grid; grid-template-columns: 1fr auto; gap: 10px; padding: 10px 16px; }
  .topbar .brand { font-size: 16px; }
  .topbar-right { gap: 10px; }
  .topbar-right .ghost { padding: 6px 12px; }
  .tabs {
    grid-column: 1 / -1; grid-row: 2; flex-wrap: nowrap; overflow-x: auto; scrollbar-width: none;
    margin: 0 -16px; padding: 0 16px;
  }
  .tabs::-webkit-scrollbar { display: none; }
  .tabs button { flex: none; padding: 8px 12px; }

  .card { padding: 16px; }
  .table thead { display: none; }
  .table, .table tbody, .table tr, .table td { display: block; width: 100%; }
  .table tr { padding: 12px 0; border-bottom: 1px solid var(--line); }
  .table td { border: 0; padding: 3px 0; display: flex; gap: 12px; justify-content: space-between; align-items: center; }
  .table td::before { content: attr(data-label); color: var(--muted); font-size: 13px; font-weight: 600; flex: none; }
  .table td[data-label=""]::before { content: none; }
  .table td.actions { justify-content: flex-start; flex-wrap: wrap; gap: 8px; padding-top: 8px; white-space: normal; }
  .table td > div { text-align: right; }
}
