/* sceracnet-web-terminal — PWA shell styles.
 *
 * Dark terminal aesthetic, responsive, safe-area aware. This file is served as
 * /assets/styles.css by the component's static asset table.
 */

:root {
  color-scheme: dark;
  --bg: #0b0e14;
  --bg-elevated: #11151c;
  --bg-inset: #080a0f;
  --panel: #151a22;
  --panel-hover: #1c222c;
  --border: #263040;
  --border-strong: #344156;
  --text: #c9d1d9;
  --text-strong: #f0f3f6;
  --muted: #8b949e;
  --accent: #4493f8;
  --accent-strong: #58a6ff;
  --green: #3fb950;
  --yellow: #d29922;
  --red: #f85149;
  --purple: #bc8cff;
  --shadow: 0 18px 48px rgb(0 0 0 / 45%);
  --radius: 8px;
  --radius-sm: 5px;
  --topbar-h: 3rem;
  --mono: ui-monospace, "JetBrains Mono", "SFMono-Regular", Menlo, Consolas,
    "Liberation Mono", monospace;
  --sans: system-ui, -apple-system, "Segoe UI", "Noto Sans SC", "PingFang SC",
    "Microsoft YaHei", sans-serif;
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

html,
body {
  height: 100%;
}

html {
  background: var(--bg);
}

body {
  margin: 0;
  min-height: 100%;
  background: radial-gradient(circle at 50% -20%, #162030 0, var(--bg) 55%);
  color: var(--text);
  font: 13px/1.5 var(--mono);
  overflow: hidden;
  -webkit-tap-highlight-color: transparent;
  text-rendering: optimizeLegibility;
}

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

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

[hidden] {
  display: none !important;
}

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

.skip-link {
  position: fixed;
  z-index: 100;
  top: -100px;
  left: 12px;
  padding: 8px 12px;
  border-radius: var(--radius-sm);
  background: var(--accent);
  color: #fff;
  text-decoration: none;
}

.skip-link:focus {
  top: 12px;
}

/* ---------------------------------------------------------------- buttons */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  min-height: 2rem;
  padding: 4px 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--panel);
  color: var(--text);
  font-size: 12px;
  font-weight: 500;
  line-height: 1.2;
  white-space: nowrap;
  text-decoration: none;
  cursor: pointer;
  transition: background-color 120ms ease, border-color 120ms ease,
    color 120ms ease, opacity 120ms ease;
}

.btn:hover:not(:disabled) {
  border-color: var(--border-strong);
  background: var(--panel-hover);
  color: var(--text-strong);
}

.btn:active:not(:disabled) {
  transform: translateY(1px);
}

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

.btn--primary {
  border-color: #2f81f7;
  background: #1f6feb;
  color: #fff;
}

.btn--primary:hover:not(:disabled) {
  border-color: #58a6ff;
  background: #2f81f7;
  color: #fff;
}

.btn--accent {
  border-color: #9e6a03;
  background: #3a2b05;
  color: #f2cc60;
}

.btn--accent:hover:not(:disabled) {
  border-color: var(--yellow);
  background: #4a3708;
}

.btn--ghost {
  background: transparent;
}

.btn--wide {
  width: 100%;
}

.btn--tiny {
  min-height: 1.6rem;
  padding: 2px 8px;
  font-size: 11px;
}

/* ------------------------------------------------------------------- boot */

.boot-view {
  position: fixed;
  inset: 0;
  z-index: 50;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 12px;
  color: var(--muted);
  background: var(--bg);
}

.spinner {
  width: 16px;
  height: 16px;
  border: 2px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 900ms linear infinite;
}

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

/* ------------------------------------------------------------------ login */

.login-view {
  display: flex;
  align-items: flex-start;
  justify-content: center;
  height: 100dvh;
  min-height: 100dvh;
  padding: calc(24px + env(safe-area-inset-top))
    calc(16px + env(safe-area-inset-right))
    calc(24px + env(safe-area-inset-bottom))
    calc(16px + env(safe-area-inset-left));
  overflow-y: auto;
}

.login-card {
  width: min(100%, 460px);
  margin: auto;
  padding: 30px 28px;
  border: 1px solid var(--border);
  border-radius: 14px;
  background: linear-gradient(180deg, #121822 0%, #0e1218 100%);
  box-shadow: var(--shadow);
}

.login-brand {
  display: flex;
  justify-content: center;
  margin-bottom: 12px;
}

.brand-mark {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 2.4rem;
  height: 2.4rem;
  padding: 0 6px;
  border: 1px solid #28568f;
  border-radius: var(--radius);
  background: #0d213b;
  color: #79c0ff;
  font-family: var(--mono);
  font-size: 18px;
  font-weight: 700;
  line-height: 1;
  letter-spacing: -0.08em;
}

.login-card h1 {
  margin: 0;
  color: var(--text-strong);
  font-family: var(--sans);
  font-size: 22px;
  font-weight: 650;
  letter-spacing: 0.01em;
  text-align: center;
}

.login-subtitle {
  margin: 6px 0 22px;
  color: var(--muted);
  font-size: 12px;
  text-align: center;
}

.notice {
  margin: 0 0 18px;
  padding: 14px 16px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--bg-inset);
}

.notice h2 {
  margin: 0 0 6px;
  font-family: var(--sans);
  font-size: 13px;
  font-weight: 650;
}

.notice p {
  margin: 0 0 8px;
  color: #b3bec9;
  font-family: var(--sans);
  font-size: 12.5px;
  line-height: 1.65;
}

.notice p:last-child {
  margin-bottom: 0;
}

.notice--shared {
  border-color: #68501a;
  background: #211b0b;
}

.notice--shared h2 {
  color: #f2cc60;
}

.notice--shared p {
  color: #d8cfae;
}

.login-status {
  min-height: 1.5em;
  margin: 0 0 12px;
  color: var(--yellow);
  font-family: var(--sans);
  font-size: 12.5px;
  text-align: center;
}

.login-hint {
  margin: 16px 0 0;
  color: var(--muted);
  font-family: var(--sans);
  font-size: 11.5px;
  line-height: 1.6;
  text-align: center;
}

.login-card .btn + .btn,
.login-card .btn + .login-hint {
  margin-top: 8px;
}

/* -------------------------------------------------------------------- app */

.app {
  display: flex;
  flex-direction: column;
  height: 100dvh;
  min-height: 0;
  padding-top: env(safe-area-inset-top);
  padding-left: env(safe-area-inset-left);
  padding-right: env(safe-area-inset-right);
  background: var(--bg);
}

.topbar {
  display: flex;
  flex: 0 0 auto;
  align-items: center;
  gap: 10px;
  min-height: var(--topbar-h);
  padding: 6px 12px;
  border-bottom: 1px solid var(--border);
  background: var(--bg-elevated);
}

.brand {
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
}

.brand .brand-mark {
  min-width: 1.9rem;
  height: 1.9rem;
  border-radius: var(--radius-sm);
  font-size: 14px;
}

.brand-name {
  color: var(--text-strong);
  font-family: var(--sans);
  font-size: 13px;
  font-weight: 650;
  white-space: nowrap;
}

.badge {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 2px 8px;
  border: 1px solid var(--border);
  border-radius: 999px;
  font-size: 11px;
  line-height: 1.5;
  white-space: nowrap;
}

.badge--shared {
  border-color: #7a5b12;
  background: #2d2408;
  color: #f2cc60;
}

.badge--shared::before {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--yellow);
  content: "";
  box-shadow: 0 0 0 2px rgb(210 153 34 / 18%);
}

.host-chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  min-width: 0;
  max-width: 18rem;
  padding: 4px 9px;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: var(--bg-inset);
  color: var(--text);
  font-size: 11px;
  cursor: pointer;
}

.host-chip:hover {
  border-color: var(--border-strong);
  background: var(--panel-hover);
}

.host-chip-label {
  color: var(--muted);
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 0.06em;
}

.host-chip-name {
  overflow: hidden;
  color: var(--text-strong);
  font-family: var(--mono);
  text-overflow: ellipsis;
  white-space: nowrap;
}

.host-chip-caret {
  color: var(--muted);
  font-size: 10px;
}

.topbar-status {
  display: flex;
  align-items: center;
  gap: 6px;
  min-width: 0;
}

.status {
  color: var(--muted);
  font-size: 11.5px;
  white-space: nowrap;
}

.status[data-state="live"] {
  color: var(--green);
}

.status[data-state="busy"],
.status[data-state="warn"] {
  color: var(--yellow);
}

.status[data-state="down"] {
  color: var(--red);
}

.status[data-state="offline"] {
  color: var(--yellow);
}

.status[data-state="live"]::before {
  display: inline-block;
  width: 6px;
  height: 6px;
  margin-right: 5px;
  border-radius: 50%;
  background: currentColor;
  content: "";
  vertical-align: 1px;
}

.chip {
  padding: 1px 6px;
  border-radius: 999px;
  font-size: 10.5px;
  white-space: nowrap;
}

.chip--offline {
  border: 1px solid #7a5b12;
  background: #2d2408;
  color: #f2cc60;
}

.topbar-user {
  display: flex;
  align-items: baseline;
  gap: 6px;
  min-width: 0;
  margin-left: auto;
  color: var(--muted);
  font-size: 11.5px;
}

.user-label {
  flex: 0 0 auto;
  color: var(--muted);
}

.user-name {
  max-width: 14rem;
  overflow: hidden;
  color: var(--text);
  text-overflow: ellipsis;
  white-space: nowrap;
}

.topbar-actions {
  display: flex;
  flex: 0 0 auto;
  align-items: center;
  gap: 6px;
}

.shared-banner {
  display: flex;
  flex: 0 0 auto;
  align-items: baseline;
  gap: 10px;
  padding: 7px 12px;
  border-bottom: 1px solid #5c4714;
  background: linear-gradient(90deg, #2b2309 0%, #211b0b 62%, #15150f 100%);
  color: #e6d8a8;
  font-family: var(--sans);
  font-size: 11.5px;
  line-height: 1.45;
}

.shared-banner strong {
  flex: 0 0 auto;
  color: #f2cc60;
  font-size: 11.5px;
  letter-spacing: 0.04em;
}

.offline-banner,
.error-banner {
  display: flex;
  flex: 0 0 auto;
  align-items: center;
  gap: 10px;
  padding: 7px 12px;
  font-family: var(--sans);
  font-size: 12px;
  line-height: 1.45;
}

.offline-banner {
  border-bottom: 1px solid #5c4714;
  background: #211b0b;
  color: #f2cc60;
}

.error-banner {
  border-bottom: 1px solid #6e2a26;
  background: #2a1110;
  color: #ffb3ad;
}

.error-text {
  flex: 1 1 auto;
  min-width: 0;
  overflow-wrap: anywhere;
}

.error-banner .btn {
  flex: 0 0 auto;
}

.layout {
  display: flex;
  flex: 1 1 auto;
  min-height: 0;
  min-width: 0;
}

.sidebar {
  display: flex;
  flex: 0 0 264px;
  flex-direction: column;
  min-height: 0;
  border-right: 1px solid var(--border);
  background: var(--bg-elevated);
}

.sidebar-head {
  display: flex;
  flex: 0 0 auto;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 10px 10px 6px 12px;
}

.sidebar-head h2 {
  margin: 0;
  color: var(--text-strong);
  font-family: var(--sans);
  font-size: 12px;
  font-weight: 650;
  letter-spacing: 0.06em;
}

.sidebar-note {
  flex: 0 0 auto;
  margin: 0;
  padding: 0 12px 8px;
  color: var(--muted);
  font-family: var(--sans);
  font-size: 10.5px;
  line-height: 1.45;
}

.session-list {
  flex: 1 1 auto;
  min-height: 0;
  margin: 0;
  padding: 0 6px 6px;
  overflow-y: auto;
  overscroll-behavior: contain;
  list-style: none;
}

.session-item {
  display: flex;
  align-items: stretch;
  gap: 2px;
  margin-bottom: 2px;
  border: 1px solid transparent;
  border-radius: var(--radius-sm);
}

.session-item:hover {
  background: var(--panel-hover);
}

.session-item.is-active {
  border-color: #28568f;
  background: #0d213b;
}

.session-main {
  display: flex;
  flex: 1 1 auto;
  flex-direction: column;
  gap: 2px;
  min-width: 0;
  padding: 7px 8px;
  border: 0;
  border-radius: var(--radius-sm);
  background: transparent;
  text-align: left;
  cursor: pointer;
}

.session-title {
  display: flex;
  align-items: center;
  gap: 6px;
  min-width: 0;
  color: var(--text);
  font-size: 12px;
  font-weight: 600;
}

.session-title-text {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.session-dot {
  flex: 0 0 auto;
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--green);
}

.session-dot.is-exited {
  background: var(--muted);
}

.session-meta {
  overflow: hidden;
  color: var(--muted);
  font-size: 10.5px;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.session-close {
  flex: 0 0 auto;
  width: 2rem;
  border: 0;
  border-radius: var(--radius-sm);
  background: transparent;
  color: var(--muted);
  font-size: 14px;
  cursor: pointer;
}

.session-close:hover {
  background: #3a1717;
  color: var(--red);
}

.sidebar-empty {
  margin: 8px 12px;
  color: var(--muted);
  font-family: var(--sans);
  font-size: 11.5px;
}

.sidebar-foot {
  display: flex;
  flex: 0 0 auto;
  gap: 6px;
  padding: 8px 10px calc(8px + env(safe-area-inset-bottom));
  border-top: 1px solid var(--border);
}

/* --------------------------------------------------------------- terminal */

.terminal-pane {
  position: relative;
  flex: 1 1 auto;
  min-width: 0;
  min-height: 0;
  background: var(--bg);
}

.terminal {
  position: absolute;
  inset: 0;
  padding: 8px 6px 8px 10px;
  overflow: hidden;
}

.terminal .xterm {
  height: 100%;
}

.terminal .xterm-viewport {
  overflow-y: scroll;
  scrollbar-color: #303a49 transparent;
  scrollbar-width: thin;
}

.terminal .xterm-viewport::-webkit-scrollbar {
  width: 10px;
}

.terminal .xterm-viewport::-webkit-scrollbar-thumb {
  border: 2px solid var(--bg);
  border-radius: 999px;
  background: #303a49;
}

.empty-state {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 10px;
  padding: 24px;
  text-align: center;
}

.empty-state h2 {
  margin: 0;
  color: var(--text-strong);
  font-family: var(--sans);
  font-size: 18px;
  font-weight: 650;
}

.empty-state p {
  max-width: 46ch;
  margin: 0 0 6px;
  color: var(--muted);
  font-family: var(--sans);
  font-size: 12.5px;
  line-height: 1.7;
}

/* ------------------------------------------------------------- mobile keys */

.mobile-keys {
  display: none;
  flex: 0 0 auto;
  border-top: 1px solid var(--border);
  background: var(--bg-elevated);
  padding-bottom: env(safe-area-inset-bottom);
}

.mobile-keys-scroll {
  display: flex;
  gap: 5px;
  padding: 6px;
  overflow-x: auto;
  overscroll-behavior-x: contain;
  scrollbar-width: none;
}

.mobile-keys-scroll::-webkit-scrollbar {
  display: none;
}

.key {
  flex: 0 0 auto;
  min-width: 2.5rem;
  min-height: 2.25rem;
  padding: 0 9px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--panel);
  color: var(--text);
  font-size: 12px;
  cursor: pointer;
  touch-action: manipulation;
  user-select: none;
}

.key:active,
.key[aria-pressed="true"] {
  border-color: var(--accent);
  background: #0d213b;
  color: #79c0ff;
}

.is-offline .mobile-keys {
  opacity: 0.45;
}

.is-offline .terminal {
  opacity: 0.65;
}

/* ------------------------------------------------------------- host dialog */

.host-dialog {
  width: min(92vw, 440px);
  padding: 0;
  border: 1px solid var(--border-strong);
  border-radius: 12px;
  background: var(--bg-elevated);
  color: var(--text);
  box-shadow: var(--shadow);
}

.host-dialog::backdrop {
  background: rgb(0 0 0 / 62%);
}

.host-dialog form {
  display: flex;
  flex-direction: column;
  gap: 12px;
  padding: 20px;
}

.host-dialog h2 {
  margin: 0;
  color: var(--text-strong);
  font-family: var(--sans);
  font-size: 17px;
}

.host-help {
  margin: 0;
  color: var(--muted);
  font-family: var(--sans);
  font-size: 12px;
  line-height: 1.55;
}

.host-help code {
  color: var(--text);
}

.host-field {
  display: flex;
  flex-direction: column;
  gap: 5px;
  color: var(--muted);
  font-size: 11px;
}

.host-field input {
  width: 100%;
  min-height: 2.2rem;
  padding: 6px 9px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--bg-inset);
  color: var(--text-strong);
  font-family: var(--mono);
}

.host-field input:focus {
  border-color: var(--accent);
  outline: none;
}

.host-error {
  margin: 0;
  color: var(--red);
  font-family: var(--sans);
  font-size: 12px;
}

.host-suggestions {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.host-suggestions-label {
  color: var(--muted);
  font-size: 10.5px;
  text-transform: uppercase;
  letter-spacing: 0.06em;
}

.host-suggestion-list {
  display: flex;
  flex-wrap: wrap;
  gap: 5px;
}

.host-suggestion {
  max-width: 100%;
  overflow: hidden;
  text-overflow: ellipsis;
}

.host-actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  margin-top: 2px;
}

.noscript {
  position: fixed;
  inset: auto 12px 12px;
  padding: 10px 12px;
  border: 1px solid #6e2a26;
  border-radius: var(--radius);
  background: #2a1110;
  color: #ffb3ad;
  font-family: var(--sans);
}

/* --------------------------------------------------------------- responsive */

@media (max-width: 900px) {
  .topbar {
    flex-wrap: wrap;
    gap: 6px 8px;
    padding: 6px 8px;
  }

  .brand-name {
    display: none;
  }

  .topbar-user {
    order: 4;
    max-width: 40%;
    margin-left: 0;
  }

  .topbar-actions {
    order: 3;
    margin-left: auto;
  }

  .topbar-status {
    order: 2;
  }

  .shared-banner {
    padding: 6px 8px;
    font-size: 11px;
  }

  .shared-banner span {
    display: -webkit-box;
    overflow: hidden;
    -webkit-box-orient: vertical;
    -webkit-line-clamp: 2;
  }

  .layout {
    flex-direction: column;
  }

  .sidebar {
    flex: 0 0 auto;
    max-height: 148px;
    border-right: 0;
    border-bottom: 1px solid var(--border);
  }

  .sidebar-head {
    padding: 6px 8px 3px;
  }

  .sidebar-note,
  .sidebar-empty {
    display: none;
  }

  .session-list {
    display: flex;
    flex: 0 0 auto;
    gap: 5px;
    padding: 0 8px 5px;
    overflow-x: auto;
    overflow-y: hidden;
  }

  .session-item {
    flex: 0 0 auto;
    width: 190px;
    margin-bottom: 0;
  }

  .sidebar-foot {
    display: none;
  }

  .terminal {
    padding: 4px 2px 4px 6px;
  }

  .mobile-keys {
    display: block;
  }

  .empty-state {
    padding: 16px;
  }
}

@media (max-width: 460px) {
  .user-label {
    display: none;
  }

  .user-name {
    max-width: 6.5rem;
  }

  .topbar-actions .btn {
    padding-right: 8px;
    padding-left: 8px;
  }

  .badge--shared {
    font-size: 10px;
  }

  .shared-banner strong {
    display: none;
  }

  .login-card {
    padding: 24px 18px;
  }
}

@media (max-height: 540px) and (max-width: 900px) {
  .sidebar {
    max-height: 96px;
  }

  .shared-banner {
    display: none;
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    scroll-behavior: auto !important;
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }

  .spinner {
    animation: none;
    border-top-color: var(--accent);
  }
}
