/* Controle remoto do TowerCTL: mobile first, tema escuro (cores do app). */

:root {
  --bg: #0e0f13;
  --panel: #121318;
  --surface: #1b1d25;
  --surface-2: #1f2129;
  --border: #23252e;
  --text: #e4e4e7;
  --muted: #9a9ba6;
  --accent: #a78bfa;
  --accent-ink: #160f2b;
  --needs: #fbbf24;
  --ok: #4ade80;
  --bad: #f87171;
  --info: #60a5fa;
  --radius: 14px;
  --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-t: env(safe-area-inset-top, 0px);
  color-scheme: dark;
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 16px/1.45 system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
  -webkit-text-size-adjust: 100%;
  -webkit-tap-highlight-color: transparent;
}

button,
input,
textarea {
  font: inherit;
  color: inherit;
}

a {
  color: var(--accent);
}

h1,
h2,
p {
  margin: 0;
}

/* ---------- topo ---------- */

.top {
  position: sticky;
  top: 0;
  z-index: 5;
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--border);
  padding-top: var(--safe-t);
}

.top-row {
  display: flex;
  align-items: center;
  gap: 10px;
  min-height: 56px;
  padding: 6px 14px;
}

.top-title {
  min-width: 0;
}

.top-title h1 {
  font-size: 18px;
  font-weight: 650;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.top-sub {
  color: var(--muted);
  font-size: 13px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.back {
  flex: none;
  width: 40px;
  height: 40px;
  margin-left: -8px;
  border: 0;
  border-radius: 10px;
  background: transparent;
  font-size: 30px;
  line-height: 1;
  cursor: pointer;
}

.back:active {
  background: var(--surface);
}

.brand-mark,
.logo {
  flex: none;
  width: 28px;
  height: 28px;
  border-radius: 8px;
  background: url('/icons/icon-192.png') center / cover;
}

.banner {
  padding: 6px 14px;
  background: #2a2412;
  color: var(--needs);
  font-size: 13px;
}

/* ---------- páginas ---------- */

.page {
  padding: 14px 14px calc(28px + var(--safe-b));
  max-width: 720px;
  margin: 0 auto;
}

.center {
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 14px;
  padding: 24px;
  text-align: center;
  max-width: 440px;
  margin: 0 auto;
}

.center .logo {
  width: 72px;
  height: 72px;
  border-radius: 20px;
}

.hero {
  font-size: 24px;
  font-weight: 700;
}

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

.note {
  color: var(--muted);
  font-size: 14px;
}

.error {
  color: var(--bad);
}

.section {
  margin-bottom: 22px;
}

.section-title {
  font-size: 13px;
  font-weight: 650;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--muted);
  margin: 4px 4px 8px;
}

.section-title.needs {
  color: var(--needs);
}

.card {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  margin-bottom: 16px;
  display: grid;
  gap: 12px;
}

.card h2 {
  font-size: 16px;
}

.card.warn {
  border-color: #3b3220;
  color: var(--needs);
  font-size: 14px;
}

.empty {
  padding: 28px 16px;
  text-align: center;
  color: var(--muted);
  display: grid;
  gap: 8px;
}

.foot {
  text-align: center;
  font-size: 14px;
}

.actions {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  margin-top: 18px;
}

/* ---------- listas ---------- */

.list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: grid;
  gap: 8px;
}

.row {
  width: 100%;
  display: flex;
  align-items: flex-start;
  gap: 12px;
  padding: 14px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--panel);
  text-align: left;
  cursor: pointer;
}

.row:active {
  background: var(--surface);
}

.row-main {
  flex: 1;
  min-width: 0;
}

.row-title {
  display: flex;
  align-items: center;
  gap: 8px;
  font-weight: 600;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.row-sub {
  color: var(--muted);
  font-size: 13px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.row-snippet {
  margin-top: 6px;
  color: #c4c4cc;
  font-size: 14px;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
  white-space: pre-line;
}

.row-side {
  flex: none;
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 6px;
}

.row-time {
  color: var(--muted);
  font-size: 12px;
}

.dot {
  flex: none;
  width: 9px;
  height: 9px;
  border-radius: 50%;
  background: #4b4d57;
}

.dot-on {
  background: var(--ok);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--ok) 20%, transparent);
}

.chip {
  display: inline-block;
  padding: 2px 9px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 600;
  white-space: nowrap;
  background: var(--surface-2);
  color: var(--muted);
}

.chip-needs {
  background: color-mix(in srgb, var(--needs) 18%, transparent);
  color: var(--needs);
}

.chip-working {
  background: color-mix(in srgb, var(--info) 16%, transparent);
  color: var(--info);
}

.chip-waiting {
  background: color-mix(in srgb, var(--accent) 16%, transparent);
  color: var(--accent);
}

.chip-done {
  background: color-mix(in srgb, var(--ok) 15%, transparent);
  color: var(--ok);
}

.chip-error {
  background: color-mix(in srgb, var(--bad) 16%, transparent);
  color: var(--bad);
}

/* ---------- botões ---------- */

.btn {
  min-height: 44px;
  padding: 10px 16px;
  border-radius: 12px;
  border: 1px solid var(--border);
  background: var(--surface);
  font-weight: 600;
  cursor: pointer;
}

.btn:active {
  filter: brightness(1.2);
}

.btn:disabled {
  opacity: 0.45;
  cursor: default;
}

.btn-primary {
  background: var(--accent);
  border-color: var(--accent);
  color: var(--accent-ink);
}

.btn-big {
  width: 100%;
  min-height: 52px;
  font-size: 17px;
}

.btn-yes {
  border-color: color-mix(in srgb, var(--ok) 45%, var(--border));
  color: var(--ok);
}

.btn-no {
  border-color: color-mix(in srgb, var(--bad) 45%, var(--border));
  color: var(--bad);
}

.btn-danger-quiet {
  color: var(--bad);
  background: transparent;
}

.link {
  border: 0;
  background: none;
  color: var(--accent);
  padding: 4px;
  cursor: pointer;
  font-size: 14px;
}

:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

/* ---------- conversa ---------- */

.pane-view {
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
}

.chat {
  flex: 1;
  width: 100%;
  padding-bottom: 16px;
}

.pane-status {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 12px;
}

.pane-status .link {
  margin-left: auto;
}

.msgs {
  list-style: none;
  margin: 0;
  padding: 0;
  display: grid;
  gap: 10px;
}

.msg {
  max-width: 92%;
  padding: 10px 13px;
  border-radius: 14px;
  background: var(--panel);
  border: 1px solid var(--border);
}

.msg-text {
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  font-size: 15px;
}

.msg-time {
  color: var(--muted);
  font-size: 11px;
  margin-top: 4px;
}

.msg-me {
  justify-self: end;
  background: color-mix(in srgb, var(--accent) 22%, var(--panel));
  border-color: color-mix(in srgb, var(--accent) 35%, var(--border));
}

.msg-sys {
  justify-self: center;
  background: transparent;
  border: 0;
  color: var(--muted);
  font-size: 13px;
  padding: 2px 8px;
}

.msg-sys .msg-time {
  display: none;
}

.log {
  margin: 0 0 14px;
  padding: 12px;
  max-height: 55vh;
  overflow: auto;
  background: #08090c;
  border: 1px solid var(--border);
  border-radius: 12px;
  font: 12px/1.4 ui-monospace, 'Cascadia Mono', Menlo, Consolas, monospace;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}

.composer {
  position: sticky;
  bottom: 0;
  background: var(--panel);
  border-top: 1px solid var(--border);
  padding: 10px 12px calc(10px + var(--safe-b));
  display: grid;
  gap: 8px;
}

.keys {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 8px;
}

.keys .btn {
  padding: 8px 4px;
}

.more-keys summary {
  color: var(--muted);
  font-size: 13px;
  cursor: pointer;
  padding: 2px 0;
}

.more-keys .keys {
  grid-template-columns: repeat(6, 1fr);
  margin-top: 8px;
}

.reply {
  display: flex;
  gap: 8px;
  align-items: flex-end;
}

.reply textarea {
  flex: 1;
  min-height: 44px;
  max-height: 160px;
  resize: vertical;
  padding: 10px 12px;
  border-radius: 12px;
  border: 1px solid var(--border);
  background: var(--bg);
  font-size: 16px;
}

/* ---------- pareamento ---------- */

.pair {
  text-align: center;
  justify-items: center;
  padding: 24px 18px;
}

.pair .big {
  font-size: 20px;
  font-weight: 650;
}

.field {
  display: grid;
  gap: 6px;
  width: 100%;
  text-align: left;
  font-size: 14px;
  color: var(--muted);
}

.field input {
  min-height: 48px;
  padding: 10px 12px;
  border-radius: 12px;
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--text);
  font-size: 16px;
}

.spinner {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  border: 3px solid var(--surface-2);
  border-top-color: var(--accent);
  animation: spin 0.9s linear infinite;
}

@keyframes spin {
  to {
    transform: rotate(360deg);
  }
}

@media (prefers-reduced-motion: reduce) {
  .spinner {
    animation-duration: 3s;
  }
}

/* ---------- aviso ---------- */

.toast {
  position: fixed;
  left: 50%;
  bottom: calc(18px + var(--safe-b));
  transform: translateX(-50%);
  z-index: 20;
  max-width: calc(100% - 28px);
  padding: 11px 16px;
  border-radius: 12px;
  background: #2b2d38;
  border: 1px solid #3a3c48;
  box-shadow: 0 8px 28px rgb(0 0 0 / 45%);
  font-size: 14px;
}

.pane-view ~ .toast {
  bottom: calc(190px + var(--safe-b));
}

@media (min-width: 720px) {
  .composer {
    max-width: 720px;
    width: 100%;
    margin: 0 auto;
    border: 1px solid var(--border);
    border-bottom: 0;
    border-radius: var(--radius) var(--radius) 0 0;
  }
}
