/*
 * Mobile-first styles for the phone client. All styling lives here because the
 * response CSP only allows same-origin style sheets (`style-src 'self'`).
 */

:root {
  color-scheme: light dark;

  --bg: #f2f5fb;
  --surface: #ffffff;
  --surface-2: #e9eef8;
  --text: #15203a;
  --muted: #5a6478;
  --border: #d3dbea;
  --accent: #2f6fed;
  --accent-strong: #1f55c4;
  --accent-text: #ffffff;
  --danger: #b3261e;
  --danger-bg: #fdecea;
  --danger-border: #efb4ae;
  --online-bg: #e3f6ea;
  --online-border: #9bd7b2;
  --online-text: #145c36;
  --offline-bg: #fff3d6;
  --offline-border: #e2ba55;
  --offline-text: #6b4d00;
  --expired-bg: #fdecea;
  --expired-border: #e6a29c;
  --expired-text: #8a1c16;
  --warning-bg: #fff4d6;
  --warning-border: #e3b341;
  --warning-text: #5f4400;
  --focus: #1a73e8;

  --radius: 12px;
  --gap: 16px;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0b1220;
    --surface: #141d2f;
    --surface-2: #1d2a42;
    --text: #e6ecf8;
    --muted: #9ba9c2;
    --border: #2c3b57;
    --accent: #6f9dff;
    --accent-strong: #8fb3ff;
    --accent-text: #0b1220;
    --danger: #ff8a80;
    --danger-bg: #3a1715;
    --danger-border: #7a2f28;
    --online-bg: #10301f;
    --online-border: #2c6c48;
    --online-text: #a8e7c2;
    --offline-bg: #362b10;
    --offline-border: #7a6224;
    --offline-text: #f0d894;
    --expired-bg: #3a1715;
    --expired-border: #7a2f28;
    --expired-text: #ffb4ad;
    --warning-bg: #362b10;
    --warning-border: #7a6224;
    --warning-text: #f0d894;
    --focus: #8fb3ff;
  }
}

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

[hidden] {
  display: none !important;
}

html,
body {
  margin: 0;
  padding: 0;
  overflow-x: hidden;
}

body {
  min-height: 100vh;
  min-height: 100dvh;
  background: var(--bg);
  color: var(--text);
  font-family:
    system-ui,
    -apple-system,
    "Segoe UI",
    Roboto,
    "Noto Sans",
    "HarmonyOS Sans",
    sans-serif;
  font-size: 16px;
  line-height: 1.45;
  -webkit-text-size-adjust: 100%;
}

.app {
  width: 100%;
  max-width: 640px;
  margin: 0 auto;
  padding: var(--gap);
  padding-bottom: calc(var(--gap) + env(safe-area-inset-bottom, 0px));
}

h1,
h2,
h3 {
  margin: 0;
  line-height: 1.25;
}

h1 {
  font-size: 1.45rem;
}

h2 {
  font-size: 1.15rem;
  margin-bottom: 4px;
}

h3 {
  font-size: 1rem;
}

p {
  margin: 0 0 8px;
}

.page-header {
  margin-bottom: var(--gap);
}

.page-header p {
  margin: 4px 0 0;
}

.row {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
}

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

.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  margin: -1px;
  padding: 0;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
  border: 0;
}

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: var(--gap);
}

/* ------------------------------------------------------------------ forms */

label {
  display: block;
  margin: 14px 0 6px;
  font-weight: 600;
}

input,
textarea {
  display: block;
  width: 100%;
  min-height: 44px;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--surface);
  color: var(--text);
  font: inherit;
  font-size: 16px;
}

textarea {
  min-height: 64px;
  resize: vertical;
}

input:focus-visible,
textarea:focus-visible,
button:focus-visible,
a:focus-visible,
code:focus-visible {
  outline: 3px solid var(--focus);
  outline-offset: 2px;
}

.auth-form {
  display: block;
}

.auth-form .button {
  width: 100%;
  margin-top: 12px;
}

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

.button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 44px;
  min-width: 44px;
  padding: 10px 16px;
  border: 1px solid transparent;
  border-radius: 10px;
  font: inherit;
  font-weight: 600;
  line-height: 1.2;
  text-align: center;
  cursor: pointer;
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
}

.button:disabled {
  opacity: 0.55;
  cursor: not-allowed;
}

.button.primary {
  background: var(--accent);
  color: var(--accent-text);
}

.button.subtle {
  background: var(--surface-2);
  border-color: var(--border);
  color: var(--text);
}

.button.danger {
  background: transparent;
  border-color: var(--danger-border);
  color: var(--danger);
}

.button.link {
  background: none;
  border: none;
  color: var(--accent-strong);
  text-decoration: underline;
  padding: 10px 8px;
}

@media (hover: hover) {
  .button.primary:hover:not(:disabled) {
    background: var(--accent-strong);
  }

  .button.subtle:hover:not(:disabled) {
    background: var(--border);
  }

  .button.danger:hover:not(:disabled) {
    background: var(--danger-bg);
  }
}

/* ----------------------------------------------------------------- errors */

.error {
  margin: 10px 0;
  padding: 10px 12px;
  border: 1px solid var(--danger-border);
  border-radius: 10px;
  background: var(--danger-bg);
  color: var(--danger);
  font-weight: 600;
  overflow-wrap: anywhere;
}

.warning {
  margin: 10px 0;
  padding: 10px 12px;
  border: 1px solid var(--warning-border);
  border-radius: 10px;
  background: var(--warning-bg);
  color: var(--warning-text);
  font-size: 0.94rem;
}

/* ---------------------------------------------------------------- devices */

.toolbar {
  display: flex;
  gap: 8px;
  margin-bottom: 12px;
}

.toolbar .button {
  flex: 1;
}

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

.device-row {
  display: flex;
  flex-direction: column;
  gap: 12px;
  padding: 14px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
}

.device-block {
  min-width: 0;
}

.device-name-row {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

.device-name {
  font-weight: 700;
  overflow-wrap: anywhere;
}

.device-status {
  color: var(--muted);
  font-size: 0.82rem;
}

.dot {
  width: 10px;
  height: 10px;
  flex: none;
  border-radius: 50%;
  background: var(--muted);
}

.dot.online {
  background: #22a45d;
  box-shadow: 0 0 0 3px rgb(34 164 93 / 22%);
}

.dot.offline {
  background: var(--muted);
}

.device-meta {
  margin-top: 4px;
  color: var(--muted);
  font-size: 0.9rem;
  overflow-wrap: anywhere;
}

.device-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.device-actions .button {
  flex: 1 1 auto;
}

/* ------------------------------------------------------------ device view */

.device-heading {
  min-width: 0;
}

.back-link {
  display: inline-flex;
  align-items: center;
  min-height: 44px;
  margin-bottom: 2px;
  color: var(--accent-strong);
  font-weight: 600;
  text-decoration: none;
}

.back-link:hover {
  text-decoration: underline;
}

.banner {
  margin: 0 0 10px;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: 10px;
  font-weight: 600;
  overflow-wrap: anywhere;
}

.banner-connecting {
  background: var(--surface-2);
  border-color: var(--border);
  color: var(--muted);
}

.banner-online {
  background: var(--online-bg);
  border-color: var(--online-border);
  color: var(--online-text);
}

.banner-offline {
  background: var(--offline-bg);
  border-color: var(--offline-border);
  color: var(--offline-text);
}

.banner-expired {
  background: var(--expired-bg);
  border-color: var(--expired-border);
  color: var(--expired-text);
}

.status-line {
  margin: 0 0 8px;
  color: var(--muted);
  font-size: 0.94rem;
  overflow-wrap: anywhere;
}

.log {
  min-height: 160px;
  max-height: 45vh;
  max-height: 45dvh;
  overflow-x: hidden;
  overflow-y: auto;
  padding: 12px;
  border: 1px solid #24324c;
  border-radius: var(--radius);
  background: #0e1524;
  color: #d8e3f5;
  font-family:
    ui-monospace,
    SFMono-Regular,
    Menlo,
    Consolas,
    "Liberation Mono",
    monospace;
  font-size: 0.9rem;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  word-break: break-word;
  overscroll-behavior: contain;
}

.log-error {
  margin: 6px 0;
  color: #ffb4b4;
  font-weight: 600;
}

.log-json {
  margin: 6px 0;
  color: #a9c7ff;
  font: inherit;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}

.approvals {
  display: grid;
  gap: 10px;
  margin: 12px 0;
}

.approval-card {
  padding: 12px;
  border: 1px solid var(--warning-border);
  border-radius: var(--radius);
  background: var(--warning-bg);
  color: var(--text);
}

.approval-title {
  margin-bottom: 6px;
  overflow-wrap: anywhere;
}

.approval-detail {
  margin-bottom: 10px;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}

.approval-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.approval-actions .button {
  flex: 1 1 120px;
}

.approval-result {
  margin: 8px 0 0;
  color: var(--muted);
  font-weight: 600;
}

.composer {
  display: grid;
  gap: 8px;
  margin-top: 12px;
}

.composer-actions {
  display: flex;
  gap: 8px;
}

.composer-actions .button {
  flex: 1;
}

/* ------------------------------------------------------------------ modal */

.modal {
  position: fixed;
  inset: 0;
  z-index: 50;
  display: flex;
  align-items: flex-end;
  justify-content: center;
  padding: 16px;
  background: rgb(6 10 20 / 65%);
}

.modal-card {
  width: 100%;
  max-width: 480px;
  max-height: calc(100vh - 32px);
  max-height: calc(100dvh - 32px);
  overflow-y: auto;
  border-radius: 16px;
}

.modal-actions {
  display: flex;
  gap: 8px;
  margin-top: 16px;
}

.modal-actions .button {
  flex: 1;
}

.token-row {
  display: grid;
  gap: 8px;
  margin: 10px 0;
}

.token {
  display: block;
  padding: 12px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--surface-2);
  font-family:
    ui-monospace,
    SFMono-Regular,
    Menlo,
    Consolas,
    monospace;
  font-size: 0.95rem;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  user-select: all;
}

@media (min-width: 600px) {
  .modal {
    align-items: center;
  }

  .token-row {
    grid-template-columns: minmax(0, 1fr) auto;
    align-items: start;
  }

  .device-row {
    flex-direction: row;
    align-items: center;
    justify-content: space-between;
  }

  .device-actions .button {
    flex: 0 0 auto;
  }
}
