/* Brand colours from branding/CI-GUIDELINES.md ("Fan Deck"). Violet marks controls;
   status colours (green live, amber can't switch, red failed) stay separate and are
   never brand colours. --accent is the lighter violet so text keeps ~5:1 contrast. */
:root {
  --ps-navy: #06172D;
  --ps-slate: #607AAB;
  --ps-blue: #0CAAF0;
  --ps-violet: #7840F3;
  --accent: #A36BFF;
  --accent-strong: #8148F7;
  --accent-dim: #2a1a4d;
}

* { box-sizing: border-box; margin: 0; padding: 0; }
[hidden] { display: none !important; }

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  background: #141414;
  color: #fff;
  min-height: 100vh;
  padding: 1.25rem;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
}

.app-logo { height: 1.4em; width: auto; }

.safe-area-top {
  height: env(safe-area-inset-top, 0px);
  flex-shrink: 0;
  width: 100%;
}

.app-title {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  font-size: 0.75rem;
  font-weight: 700;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: #777;
  margin-bottom: 1rem;
}

#status-bar {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.4rem;
  margin-bottom: 1rem;
}

.status {
  display: flex;
  justify-content: center;
}

.logout-pill {
  background: #2e0a0a;
  border: none;
  border-radius: 999px;
  padding: 0 0.6rem;
  height: 1.5rem;
  color: #c0392b;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  -webkit-tap-highlight-color: transparent;
  transition: background 0.15s, color 0.15s;
}
.logout-pill:hover  { background: #3e1010; color: #e74c3c; }
.logout-pill:active { background: #500; color: #ff6b6b; }

.status-pill {
  font-size: 0.7rem;
  font-weight: 600;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  padding: 0 0.75rem;
  height: 1.5rem;
  border-radius: 999px;
  background: #2a2a2a;
  color: #555;
  display: inline-flex;
  align-items: center;
}

.status.live  .status-pill { background: #0a2e18; color: #00c850; }
.status.error .status-pill { background: #2e0a0a; color: #f44336; }
.status.warn  .status-pill { background: #2e1f00; color: #ffaa00; }

.content {
  width: 100%;
  max-width: 480px;
}

@media (min-width: 520px) {
  .content { max-width: 640px; }
}

.grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 1rem;
}

.empty-state {
  grid-column: 1 / -1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  padding: 3rem 0;
  color: #555;
  font-size: 0.8rem;
  font-weight: 700;
  letter-spacing: 0.1em;
  text-transform: uppercase;
}

@media (min-width: 520px) {
  .grid { grid-template-columns: repeat(4, 1fr); }
}

.card {
  background: #1e1e1e;
  border-radius: 14px;
  padding: 1.5rem 0.75rem 0;
  cursor: pointer;
  border: 3px solid transparent;
  position: relative;
  overflow: hidden;
  min-height: 130px;
  display: flex;
  flex-direction: column;
  align-items: center;
  transition: opacity 0.1s;
  -webkit-tap-highlight-color: transparent;
  user-select: none;
  touch-action: manipulation;
}

.card.active      { border-color: #00c850; }
.card.unreachable { border-color: #f5a623; }
.card.failed      { border-color: #f44336; }
.card-failed      { color: #f44336; }

.card-warning {
  font-size: 0.6rem;
  color: #f5a623;
  text-align: center;
  margin-bottom: 0.5rem;
  letter-spacing: 0.03em;
}
.card:active { opacity: 0.6; }

.card.placeholder {
  opacity: 0.35;
  cursor: default;
  pointer-events: none;
}

.card-thumb {
  display: none;
  width: calc(100% + 1.5rem);
  margin: -1.5rem -0.75rem 0.75rem;
  aspect-ratio: 16 / 9;
  object-fit: cover;
}

.card-number {
  font-size: 3.5rem;
  font-weight: 700;
  line-height: 1;
}

.card-name {
  font-size: 0.65rem;
  color: #999;
  text-align: center;
  margin-top: 0.4rem;
  margin-bottom: 1.25rem;
  word-break: break-word;
  padding: 0 0.25rem;
}

.color-bar {
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  height: 7px;
}

.nav {
  display: flex;
  gap: 1rem;
  margin-top: 1.25rem;
}

@media (max-width: 519px) {
  body {
    justify-content: flex-start;
    padding-bottom: 5.5rem;
  }
  .nav {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    margin-top: 0;
    padding: 0.65rem 1.25rem;
    padding-bottom: max(0.65rem, env(safe-area-inset-bottom));
    background: #141414;
    border-top: 1px solid #222;
    z-index: 50;
  }
}

.nav-btn {
  flex: 1;
  padding: 0.9rem 2rem;
  background: #1e1e1e;
  color: #fff;
  border: 2px solid #333;
  border-radius: 12px;
  font-size: 1rem;
  font-weight: 600;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  user-select: none;
  touch-action: manipulation;
  transition: opacity 0.1s;
}

.nav-btn:active { opacity: 0.6; }

.color-bar.active   { background: #00c850; }
.color-bar.loaded   { background: #505050; }
.color-bar.conflict { background: #f44336; }

.settings-toggle {
  flex: 0 0 3.2rem;
  padding: 0.9rem 0;
  font-size: 1.3rem;
  display: flex;
  align-items: center;
  justify-content: center;
}

.settings-toggle.active {
  border-color: var(--accent);
  color: var(--accent);
}

.settings-panel {
  margin-top: 1rem;
  background: #1e1e1e;
  border-radius: 14px;
  padding: 1.25rem;
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

.settings-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
}

.settings-label {
  font-size: 0.9rem;
  color: #ccc;
  flex-shrink: 0;
  display: flex;
  align-items: center;
  gap: 0.35rem;
}

.help-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 0.9rem;
  height: 0.9rem;
  color: #888;
  cursor: help;
  flex-shrink: 0;
  user-select: none;
  transition: color 0.15s;
}

.help-icon:hover { color: #aaa; }

.help-icon svg {
  width: 100%;
  height: 100%;
}

.number-input {
  display: flex;
  align-items: center;
  background: #2a2a2a;
  border: 1px solid #444;
  border-radius: 8px;
  overflow: hidden;
}

.number-input input[type=number]::-webkit-inner-spin-button,
.number-input input[type=number]::-webkit-outer-spin-button { -webkit-appearance: none; }
.number-input input[type=number] { -moz-appearance: textfield; }

.num-btn {
  padding: 0.4rem 0.65rem;
  background: transparent;
  border: none;
  color: #777;
  font-size: 1.1rem;
  line-height: 1;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  user-select: none;
  transition: color 0.15s, background 0.15s;
}

.num-btn:active { background: #333; color: #fff; }

.settings-input {
  width: 3.5rem;
  background: transparent;
  border: none;
  color: #fff;
  padding: 0.4rem 0.25rem;
  font-size: 0.9rem;
  text-align: center;
}

.settings-row.vertical {
  flex-direction: column;
  align-items: flex-start;
  gap: 0.5rem;
}

.settings-segmented {
  display: flex;
  width: 100%;
  background: #2a2a2a;
  border-radius: 8px;
  padding: 3px;
  gap: 2px;
}

.seg-btn {
  flex: 1;
  padding: 0.4rem 0.5rem;
  background: transparent;
  border: none;
  border-radius: 6px;
  color: #666;
  font-size: 0.75rem;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.15s, color 0.15s;
  -webkit-tap-highlight-color: transparent;
}

.seg-btn.active {
  background: #1e1e1e;
  color: var(--accent);
}

.toggle-switch {
  position: relative;
  display: inline-block;
  cursor: pointer;
  flex-shrink: 0;
}

.toggle-switch input {
  opacity: 0;
  width: 0;
  height: 0;
  position: absolute;
}

.toggle-track {
  display: block;
  width: 2.75rem;
  height: 1.5rem;
  background: #333;
  border-radius: 999px;
  transition: background 0.2s;
  position: relative;
}

.toggle-thumb {
  position: absolute;
  top: 3px;
  left: 3px;
  width: 1.125rem;
  height: 1.125rem;
  background: #888;
  border-radius: 50%;
  transition: transform 0.2s, background 0.2s;
}

.toggle-switch input:checked + .toggle-track {
  background: var(--accent-dim);
}

.toggle-switch input:checked + .toggle-track .toggle-thumb {
  background: var(--accent-strong);
  transform: translateX(1.25rem);
}

.settings-save {
  border-color: var(--accent);
  color: var(--accent);
  flex: unset;
  align-self: flex-end;
  padding: 0.6rem 1.5rem;
  font-size: 0.85rem;
}

.auth-overlay {
  position: fixed;
  inset: 0;
  background: #141414;
  z-index: 100;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 1.5rem;
  padding: 1.25rem;
  padding-top: max(1.25rem, env(safe-area-inset-top, 0px));
}

.auth-box {
  display: flex;
  flex-direction: column;
  align-items: stretch;
  gap: 0.75rem;
  width: 100%;
  max-width: 280px;
}

.auth-input {
  width: 100%;
  background: #1e1e1e;
  border: 2px solid #333;
  border-radius: 12px;
  color: #fff;
  padding: 0.9rem 1rem;
  font-size: 1rem;
  text-align: center;
  outline: none;
  font-family: inherit;
}

.auth-input:focus { border-color: var(--accent); }

.auth-error-text {
  text-align: center;
  font-size: 0.75rem;
  color: #f44336;
  font-weight: 600;
  letter-spacing: 0.05em;
  text-transform: uppercase;
}

@keyframes auth-shake {
  0%, 100% { transform: translateX(0); }
  20%, 60% { transform: translateX(-6px); }
  40%, 80% { transform: translateX(6px); }
}

.auth-shake { animation: auth-shake 0.35s ease-in-out; }

.settings-secret-row {
  display: flex;
  gap: 0.5rem;
  width: 100%;
}

.settings-secret-input {
  flex: 1;
  width: auto;
  text-align: left;
}

.settings-generate {
  flex: 0;
  padding: 0.5rem 0.75rem;
  font-size: 0.75rem;
  white-space: nowrap;
}

.settings-textarea {
  width: 100%;
  box-sizing: border-box;
  background: #2a2a2a;
  border: none;
  border-radius: 6px;
  color: #fff;
  padding: 0.4rem 0.5rem;
  font-size: 0.85rem;
  font-family: monospace;
  resize: vertical;
  min-height: 4.5rem;
}

.comp-section-label {
  font-size: 0.75rem;
  font-weight: 700;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: #999;
  margin-top: 1rem;
  padding-top: 0.75rem;
  border-top: 1px solid #2a2a2a;
}

.comp-section-label:first-child {
  margin-top: 0;
  padding-top: 0;
  border-top: none;
}

.comp-slot-label {
  font-size: 0.8rem;
  font-weight: 700;
  color: #bbb;
  margin-top: 0.9rem;
  letter-spacing: 0.04em;
}

.comp-copy-row {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.comp-action-label {
  font-size: 0.8rem;
  color: #aaa;
  width: 3.25rem;
  flex-shrink: 0;
}

.comp-value {
  flex: 1;
  font-family: ui-monospace, "SF Mono", "Cascadia Mono", monospace;
  font-size: 0.8rem;
  color: #e0e0e0;
  background: #2a2a2a;
  border-radius: 6px;
  padding: 0.35rem 0.5rem;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  min-width: 0;
}

.comp-hint {
  font-size: 0.8rem;
  color: #aaa;
  line-height: 1.4;
}

.grid.offline .card { opacity: 0.35; pointer-events: none; }

.auth-prompt {
  text-align: center;
  font-size: 0.85rem;
  color: #aaa;
}

.auth-error-text { line-height: 1.4; }

/* OSC-only rows (port, listeners, no-password note): spaced like the panel itself. */
#osc-settings-rows { display: flex; flex-direction: column; gap: 1rem; }

.settings-note {
  font-size: 0.8rem;
  color: #ffaa00;
  line-height: 1.4;
  margin-top: -0.5rem;
}

/* Full-window views opened from the menu bar (?view=…) */
body.view-connect #status-bar,
body.view-connect .content:not(#connect-view),
body.view-settings #status-bar,
body.view-settings #grid,
body.view-settings .nav,
body.view-settings #companion-panel,
body.view-settings #setup-banner,
body.view-check #status-bar,
body.view-check .content:not(#check-view) { display: none !important; }

body.view-settings .settings-panel { margin-top: 0; }

/* App windows: content starts at the top, so nothing jumps when a warning or
   extra rows change the height (window sizes in broker/menubar.py leave room for them). */
body.view-connect,
body.view-settings,
body.view-check { justify-content: flex-start; }

.connect-view { max-width: 420px; }

.connect-panel { margin-top: 0; align-items: stretch; }

.connect-qr {
  align-self: center;
  width: 100%;
  max-width: 260px;
  aspect-ratio: 1;
  background: #fff;
  border-radius: 12px;
  padding: 0.75rem;
}

.connect-phrase {
  font-family: ui-monospace, "SF Mono", "Cascadia Mono", monospace;
  font-size: 1.5rem;
  font-weight: 600;
  text-align: center;
  word-break: break-word;
  color: #fff;
  user-select: all;
}

/* Destructive, so not styled as the primary (accent) action. */
.connect-rotate { align-self: center; border-color: #444; color: #fff; }

.connect-phrase-row {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.75rem;
}

.setup-banner {
  background: #2e1f00;
  color: #ffaa00;
  border-radius: 12px;
  padding: 0.75rem 1rem;
  font-size: 0.8rem;
  line-height: 1.4;
  margin-bottom: 1rem;
}

.check-actions { display: flex; gap: 0.5rem; flex-wrap: wrap; }

.check-confirm {
  background: #2e1f00;
  color: #ffaa00;
  border-radius: 10px;
  padding: 0.75rem;
  font-size: 0.9rem;
  line-height: 1.4;
  display: flex;
  flex-direction: column;
  gap: 0.6rem;
}

.check-continue { border-color: #ffaa00; color: #ffaa00; }

.check-summary { font-size: 0.95rem; font-weight: 600; }
.check-summary.good { color: #00c850; }
.check-summary.bad  { color: #f44336; }

.check-results { display: flex; flex-direction: column; gap: 0.4rem; }

.check-row {
  display: flex;
  justify-content: space-between;
  gap: 0.75rem;
  background: #2a2a2a;
  border-radius: 8px;
  padding: 0.5rem 0.75rem;
  font-size: 0.9rem;
}
.check-row .check-status { color: #00c850; text-align: right; }
.check-row.bad .check-status { color: #f5a623; }
.check-name { overflow-wrap: anywhere; }

.relay-status { font-size: 0.8rem; color: #aaa; line-height: 1.4; }
.relay-status.good { color: #00c850; }
.relay-status.bad  { color: #f5a623; }
