/* === Tokens (ported from opensteer-cloud theme) ======================== */
:root {
  color-scheme: dark;

  --bg: #000000;
  --surface: #0d0d0d;
  --surface-2: #161616;
  --surface-3: #1f1f1f;

  --border: rgba(255, 255, 255, 0.08);
  --border-subtle: rgba(255, 255, 255, 0.04);
  --border-strong: rgba(255, 255, 255, 0.14);

  --fg: #ffffff;
  --fg-muted: #a0a0a0;
  --fg-faint: #707070;

  --accent: #ffffff;
  --accent-fg: #000000;

  --danger: #ef4444;
  --danger-soft: rgba(239, 68, 68, 0.16);
  --warn: #f59e0b;
  --warn-soft: rgba(245, 158, 11, 0.16);
  --ok: #22c55e;
  --ok-soft: rgba(34, 197, 94, 0.16);

  --ring: rgba(255, 255, 255, 0.4);

  --radius-sm: 8px;
  --radius-md: 12px;
  --radius-lg: 16px;
  --radius-pill: 999px;

  --shadow-card: 0 8px 28px rgba(0, 0, 0, 0.5);

  --header-h: calc(env(safe-area-inset-top) + 60px);
  --bottomnav-h: calc(env(safe-area-inset-bottom) + 64px);

  --font-body: "Inter", ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont,
    "Segoe UI", Roboto, sans-serif;
}

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

html,
body {
  margin: 0;
  padding: 0;
}

html {
  -webkit-text-size-adjust: 100%;
}

body {
  min-height: 100dvh;
  background: var(--bg);
  color: var(--fg);
  font: 15px/1.5 var(--font-body);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  -webkit-tap-highlight-color: transparent;
  overscroll-behavior-y: contain;
}

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

[hidden] {
  display: none !important;
}

::-webkit-scrollbar {
  width: 6px;
  height: 6px;
}
::-webkit-scrollbar-track {
  background: transparent;
}
::-webkit-scrollbar-thumb {
  background: var(--border-strong);
  border-radius: 3px;
}
::-webkit-scrollbar-thumb:hover {
  background: rgba(255, 255, 255, 0.22);
}

/* === Background atmosphere ============================================== */
.bg-noise {
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 0;
  opacity: 0.04;
  mix-blend-mode: overlay;
  background-image: url("data:image/svg+xml,%3Csvg viewBox='0 0 200 200' xmlns='http://www.w3.org/2000/svg'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.65' numOctaves='3' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)'/%3E%3C/svg%3E");
}

.bg-glow {
  position: fixed;
  top: -240px;
  left: 50%;
  transform: translateX(-50%);
  width: 720px;
  height: 480px;
  pointer-events: none;
  z-index: 0;
  background: radial-gradient(
    ellipse at center,
    rgba(255, 255, 255, 0.07) 0%,
    transparent 60%
  );
  filter: blur(40px);
}

/* === Appbar ============================================================= */
.appbar {
  position: sticky;
  top: 0;
  z-index: 30;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: calc(env(safe-area-inset-top) + 12px) 16px 12px;
  background: color-mix(in srgb, var(--bg) 85%, transparent);
  backdrop-filter: saturate(160%) blur(14px);
  -webkit-backdrop-filter: saturate(160%) blur(14px);
  border-bottom: 1px solid var(--border);
}

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

.appbar__logo {
  display: grid;
  place-items: center;
  width: 36px;
  height: 36px;
  border-radius: 10px;
  background: linear-gradient(180deg, rgba(255, 255, 255, 0.1), rgba(255, 255, 255, 0.02));
  border: 1px solid var(--border);
  color: var(--fg);
  flex-shrink: 0;
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.12);
}

.appbar__title {
  display: flex;
  flex-direction: column;
  min-width: 0;
}

.brand {
  font-size: 16px;
  font-weight: 700;
  letter-spacing: -0.01em;
  line-height: 1.2;
}

/* Status pill */
.status {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 12px;
  color: var(--fg-muted);
  line-height: 1.2;
  margin-top: 2px;
}

.status__dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--fg-faint);
  flex-shrink: 0;
  transition: background 0.18s ease;
}

.status--ok .status__dot {
  background: var(--ok);
  box-shadow: 0 0 8px color-mix(in srgb, var(--ok) 60%, transparent);
  animation: pulse-dot 2s ease-in-out infinite;
}
.status--loading .status__dot {
  background: var(--warn);
  animation: pulse-dot 1s ease-in-out infinite;
}
.status--danger .status__dot {
  background: var(--danger);
}
.status--offline .status__dot {
  background: var(--fg-faint);
}

@keyframes pulse-dot {
  0%, 100% {
    opacity: 1;
    transform: scale(1);
  }
  50% {
    opacity: 0.55;
    transform: scale(0.85);
  }
}

/* === Buttons ============================================================ */
.btn {
  -webkit-appearance: none;
  appearance: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  border: 1px solid var(--border);
  background: transparent;
  color: var(--fg);
  border-radius: var(--radius-md);
  font-weight: 600;
  font-size: 14px;
  padding: 10px 14px;
  min-height: 44px;
  cursor: pointer;
  transition: background 0.18s ease, border-color 0.18s ease, transform 0.06s ease,
    color 0.18s ease;
  user-select: none;
  -webkit-user-select: none;
  text-decoration: none;
}

.btn:hover {
  background: var(--surface-2);
}
.btn:active {
  transform: scale(0.985);
}
.btn:focus-visible {
  outline: none;
  box-shadow: 0 0 0 2px var(--bg), 0 0 0 4px var(--ring);
}
.btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.btn--primary {
  background: var(--accent);
  color: var(--accent-fg);
  border-color: var(--accent);
}
.btn--primary:hover {
  background: color-mix(in srgb, var(--accent) 90%, transparent);
}

.btn--secondary {
  background: var(--surface-2);
  border-color: var(--border-strong);
}

.btn--ghost {
  background: transparent;
  border-color: transparent;
}
.btn--ghost:hover {
  background: var(--surface-2);
}

.btn--danger {
  color: var(--danger);
}
.btn--danger:hover {
  background: var(--danger-soft);
}

.btn--lg {
  min-height: 50px;
  padding: 12px 18px;
  font-size: 15px;
}

.btn--chip {
  min-height: 38px;
  padding: 8px 14px;
  background: var(--surface-2);
  border-color: var(--border);
  border-radius: var(--radius-pill);
  font-weight: 500;
}

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

.iconButton {
  width: 40px;
  height: 40px;
  min-height: auto;
  padding: 0;
  display: grid;
  place-items: center;
  background: transparent;
  border: 1px solid var(--border);
  border-radius: 10px;
  color: var(--fg);
  cursor: pointer;
  transition: background 0.18s ease, transform 0.06s ease;
  flex-shrink: 0;
}
.iconButton:hover {
  background: var(--surface-2);
}
.iconButton:active {
  transform: scale(0.96);
}
.iconButton:focus-visible {
  outline: none;
  box-shadow: 0 0 0 2px var(--bg), 0 0 0 4px var(--ring);
}

/* === Inputs ============================================================= */
.input {
  width: 100%;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  color: var(--fg);
  padding: 12px 14px;
  font-size: 16px; /* 16px prevents iOS zoom on focus */
  line-height: 1.4;
  transition: border-color 0.18s ease, background 0.18s ease, box-shadow 0.18s ease;
  outline: none;
}
.input::placeholder {
  color: var(--fg-faint);
}
.input:focus {
  border-color: var(--border-strong);
  background: var(--surface-2);
  box-shadow: 0 0 0 3px rgba(255, 255, 255, 0.06);
}
.input--textarea {
  resize: vertical;
  min-height: 80px;
}

.field {
  display: grid;
  gap: 6px;
}
.field__label {
  font-size: 11px;
  font-weight: 600;
  color: var(--fg-muted);
  letter-spacing: 0.06em;
  text-transform: uppercase;
}

/* === Layout ============================================================= */
main {
  position: relative;
  z-index: 1;
  width: min(720px, 100%);
  margin: 0 auto;
  padding: 16px 16px calc(var(--bottomnav-h) + 16px);
}

.view {
  width: 100%;
}

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

.stack {
  display: grid;
  gap: 12px;
}

/* === Pair view ========================================================== */
.authView {
  min-height: calc(100dvh - var(--header-h) - 80px);
  display: grid;
  place-items: center;
  padding: 24px 0;
}

.auth-card {
  width: 100%;
  max-width: 380px;
  display: grid;
  gap: 16px;
  padding: 28px 24px;
  background: linear-gradient(
    180deg,
    rgba(255, 255, 255, 0.04),
    rgba(255, 255, 255, 0.01)
  );
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-card), inset 0 1px 0 rgba(255, 255, 255, 0.05);
  animation: fade-up 0.5s cubic-bezier(0.16, 1, 0.3, 1);
}

.auth-card__icon {
  width: 48px;
  height: 48px;
  display: grid;
  place-items: center;
  margin: 0 auto;
  border-radius: 14px;
  background: linear-gradient(180deg, rgba(255, 255, 255, 0.1), rgba(255, 255, 255, 0.02));
  border: 1px solid var(--border);
  color: var(--fg);
}

.auth-card h1 {
  margin: 0;
  font-size: 22px;
  font-weight: 700;
  letter-spacing: -0.01em;
  text-align: center;
}

.auth-card__sub {
  margin: 0;
  text-align: center;
  font-size: 14px;
  color: var(--fg-muted);
  line-height: 1.5;
}

.auth-card .stack {
  gap: 14px;
  margin-top: 6px;
}

@keyframes fade-up {
  from {
    opacity: 0;
    transform: translateY(8px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

/* === Panel ============================================================== */
.panel {
  display: flex;
  flex-direction: column;
  gap: 14px;
  animation: fade-up 0.32s cubic-bezier(0.16, 1, 0.3, 1);
}

.panel__header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 4px 4px 0;
}

.panel__title {
  margin: 0;
  font-size: 22px;
  font-weight: 700;
  letter-spacing: -0.015em;
}

/* Badge */
.badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  height: 22px;
  min-width: 22px;
  padding: 0 7px;
  border-radius: var(--radius-pill);
  font-size: 12px;
  font-weight: 700;
  background: var(--surface-2);
  border: 1px solid var(--border);
  color: var(--fg);
  line-height: 1;
}
.badge--accent {
  background: var(--accent);
  color: var(--accent-fg);
  border-color: var(--accent);
}
.badge--dot {
  background: var(--danger);
  border-color: var(--danger);
  color: var(--fg);
  height: 18px;
  min-width: 18px;
  padding: 0 5px;
  font-size: 10px;
}

/* === List & Request card ================================================ */
.list {
  display: grid;
  gap: 12px;
}

.request {
  position: relative;
  display: grid;
  gap: 12px;
  padding: 16px;
  background: linear-gradient(
    180deg,
    rgba(255, 255, 255, 0.04),
    rgba(255, 255, 255, 0.012)
  );
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-card), inset 0 1px 0 rgba(255, 255, 255, 0.04);
  animation: fade-up 0.28s cubic-bezier(0.16, 1, 0.3, 1);
}

.request__header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  flex-wrap: wrap;
}

.request__status {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  height: 22px;
  padding: 0 9px;
  border-radius: var(--radius-pill);
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  background: var(--warn-soft);
  color: var(--warn);
  border: 1px solid color-mix(in srgb, var(--warn) 30%, transparent);
}
.request__status[data-status="answered"],
.request__status[data-status="responded"],
.request__status[data-status="completed"] {
  background: var(--ok-soft);
  color: var(--ok);
  border-color: color-mix(in srgb, var(--ok) 30%, transparent);
}
.request__status[data-status="cancelled"],
.request__status[data-status="expired"],
.request__status[data-status="canceled"] {
  background: var(--surface-2);
  color: var(--fg-muted);
  border-color: var(--border);
}
.request__status[data-status="error"],
.request__status[data-status="failed"] {
  background: var(--danger-soft);
  color: var(--danger);
  border-color: color-mix(in srgb, var(--danger) 30%, transparent);
}

.requestMeta {
  font-size: 12px;
  color: var(--fg-muted);
  font-variant-numeric: tabular-nums;
}

.requestMessage {
  margin: 0;
  font-size: 15px;
  line-height: 1.55;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  color: var(--fg);
}

.replyForm {
  display: grid;
  gap: 10px;
}

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

.replyActions .quick {
  flex: 0 0 auto;
}
.replyActions button[type="submit"] {
  flex: 1 1 auto;
  min-width: 96px;
}

.history-response {
  font-size: 14px;
  color: var(--fg);
  background: var(--surface);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-md);
  padding: 10px 12px;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}
.history-response--muted {
  color: var(--fg-faint);
  font-style: italic;
}

/* === Empty state ======================================================== */
.empty {
  display: grid;
  place-items: center;
  gap: 6px;
  padding: 48px 16px;
  text-align: center;
  color: var(--fg-muted);
  border: 1px dashed var(--border);
  border-radius: var(--radius-lg);
  background: rgba(255, 255, 255, 0.012);
}

.empty__icon {
  width: 44px;
  height: 44px;
  display: grid;
  place-items: center;
  border-radius: 12px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  color: var(--fg-muted);
  margin-bottom: 4px;
}

.empty__title {
  margin: 0;
  font-size: 15px;
  font-weight: 600;
  color: var(--fg);
}
.empty__sub {
  margin: 0;
  font-size: 13px;
}

/* === Settings =========================================================== */
.settings__group {
  display: flex;
  flex-direction: column;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  overflow: hidden;
  box-shadow: var(--shadow-card);
}

.settings__row {
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 16px;
  border-bottom: 1px solid var(--border-subtle);
}
.settings__row:last-child {
  border-bottom: 0;
}

.settings__row > div:first-child {
  flex: 1;
  min-width: 0;
}
.settings__row-title {
  font-size: 15px;
  font-weight: 600;
}
.settings__row-sub {
  font-size: 13px;
  margin-top: 2px;
  line-height: 1.45;
}
.settings__status {
  margin: 4px 4px 0;
  font-size: 13px;
  min-height: 1.2em;
  color: var(--fg-muted);
}

/* === Tabs (bottom nav on mobile, top pill bar on desktop) =============== */
.tabs {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  z-index: 30;
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 4px;
  padding: 6px 8px calc(env(safe-area-inset-bottom) + 8px);
  background: color-mix(in srgb, var(--bg) 85%, transparent);
  backdrop-filter: saturate(160%) blur(18px);
  -webkit-backdrop-filter: saturate(160%) blur(18px);
  border-top: 1px solid var(--border);
}

.tab {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 3px;
  padding: 8px 4px;
  background: transparent;
  border: 0;
  color: var(--fg-faint);
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.02em;
  cursor: pointer;
  transition: color 0.18s ease, background 0.18s ease;
  border-radius: var(--radius-md);
  min-height: 52px;
}

.tab__icon {
  position: relative;
  display: grid;
  place-items: center;
}

.tab svg {
  width: 22px;
  height: 22px;
}

.tab__badge {
  position: absolute;
  top: -4px;
  right: -8px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  height: 16px;
  min-width: 16px;
  padding: 0 4px;
  border-radius: var(--radius-pill);
  background: var(--danger);
  color: #fff;
  font-size: 10px;
  font-weight: 700;
  line-height: 1;
  border: 2px solid var(--bg);
}

.tab.active {
  color: var(--fg);
  background: var(--surface-2);
}

.tab:focus-visible {
  outline: none;
  color: var(--fg);
  box-shadow: 0 0 0 2px var(--ring) inset;
}

@media (min-width: 720px) {
  .tabs {
    position: sticky;
    top: var(--header-h);
    bottom: auto;
    margin: 0 auto 16px;
    width: max-content;
    padding: 4px;
    grid-template-columns: repeat(3, auto);
    gap: 2px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-pill);
    backdrop-filter: none;
    -webkit-backdrop-filter: none;
    box-shadow: var(--shadow-card);
  }
  .tab {
    flex-direction: row;
    padding: 8px 16px;
    border-radius: var(--radius-pill);
    font-size: 13px;
    min-height: 38px;
  }
  .tab svg {
    width: 16px;
    height: 16px;
  }
  .tab__badge {
    position: static;
    border: 0;
    margin-left: 4px;
  }
  .tab.active {
    background: var(--accent);
    color: var(--accent-fg);
  }
  main {
    padding-bottom: 32px;
  }
}

/* === Reduced motion ===================================================== */
@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.001ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.001ms !important;
  }
}

/* === Tiny phones ======================================================== */
@media (max-width: 360px) {
  .replyActions {
    flex-direction: column;
  }
  .replyActions .quick,
  .replyActions button[type="submit"] {
    width: 100%;
  }
}
