:root {
  /* iOS system (light) */
  --ios-blue: #007aff;
  --ios-blue-pressed: #0056b3;
  --ios-label: #000000;
  --ios-secondary-label: rgba(60, 60, 67, 0.6);
  --ios-tertiary-label: rgba(60, 60, 67, 0.3);
  --ios-separator: rgba(60, 60, 67, 0.29);
  --ios-separator-opaque: #c6c6c8;
  --ios-grouped-bg: #f2f2f7;
  --ios-cell-bg: #ffffff;
  --ios-nav-bg: rgba(249, 249, 249, 0.94);
  --ios-bubble-mine: #007aff;
  --ios-bubble-mine-text: #ffffff;
  --ios-bubble-theirs: #e9e9eb;
  --ios-bubble-theirs-text: #000000;
  --ios-danger: #ff3b30;
  --ios-radius-group: 10px;
  --ios-radius-bubble: 17px;
  --font-sf: -apple-system, BlinkMacSystemFont, 'SF Pro Text', 'SF Pro Display', 'Helvetica Neue', sans-serif;
  --device-outer-radius: 54px;
  --device-inner-radius: 44px;
  --tab-bar-h: 49px;
}

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

html,
body {
  height: 100%;
  margin: 0;
  overflow-x: hidden;
  overflow-y: auto;
  font-family: var(--font-sf);
  font-size: 17px;
  -webkit-font-smoothing: antialiased;
  background: radial-gradient(120% 80% at 50% 20%, #5b5b66 0%, #2d2d32 42%, #1a1a1e 100%);
  color: var(--ios-label);
  min-height: 100dvh;
}

/* —— Phone chrome (desktop / dev preview) —— */
.device-shell {
  min-height: 100dvh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: max(16px, env(safe-area-inset-top)) 16px max(16px, env(safe-area-inset-bottom));
}

.device-frame {
  position: relative;
  flex-shrink: 0;
  width: min(393px, calc(100vw - 32px));
  height: min(852px, calc(100dvh - 32px));
  padding: 11px;
  border-radius: var(--device-outer-radius);
  background: linear-gradient(160deg, #3a3a3e 0%, #1c1c1f 40%, #0d0d0f 100%);
  box-shadow:
    0 0 0 1px rgba(255, 255, 255, 0.06) inset,
    0 0 0 0.5px rgba(0, 0, 0, 0.8),
    0 32px 64px rgba(0, 0, 0, 0.55),
    0 12px 24px rgba(0, 0, 0, 0.35);
}

.device-screen {
  display: flex;
  flex-direction: column;
  width: 100%;
  height: 100%;
  border-radius: var(--device-inner-radius);
  overflow: hidden;
  background: #ffffff;
}

.device-status {
  position: relative;
  flex-shrink: 0;
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  min-height: 54px;
  padding: 12px 24px 10px;
  background: #ffffff;
  color: var(--ios-label);
}

.device-time {
  font-size: 17px;
  font-weight: 600;
  letter-spacing: -0.3px;
  font-variant-numeric: tabular-nums;
}

.device-island-wrap {
  position: absolute;
  left: 50%;
  top: 11px;
  transform: translateX(-50%);
  pointer-events: none;
}

.device-island {
  width: 120px;
  height: 34px;
  border-radius: 20px;
  background: #000000;
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.25);
}

.device-signal-cluster {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 5px;
  color: var(--ios-label);
}

.device-sig,
.device-wifi,
.device-battery {
  display: block;
  flex-shrink: 0;
  opacity: 0.92;
}

.device-content {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
  background: var(--ios-grouped-bg);
}

.device-home-bar {
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 28px;
  padding-bottom: 10px;
  background: #ffffff;
}

.device-home-pill {
  width: 134px;
  height: 5px;
  border-radius: 100px;
  background: #000000;
  opacity: 0.9;
}

.device-content .app {
  flex: 1;
  min-height: 0;
  width: 100%;
  max-width: none;
  margin: 0;
  height: auto;
  max-height: none;
  box-shadow: none;
  border-radius: 0;
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  border: 0;
}

.app {
  display: flex;
  flex-direction: column;
  width: 100%;
  max-width: 430px;
  margin: 0 auto;
  height: 100%;
  max-height: 100dvh;
  min-height: 0;
  overflow: hidden;
  background: var(--ios-grouped-bg);
  box-shadow: 0 0 0 0.5px var(--ios-separator-opaque);
}

.screen {
  display: none;
  flex-direction: column;
  flex: 1;
  min-height: 0;
  overflow: hidden;
}

.screen.is-active {
  display: flex;
}

/* —— Root (tabs) —— */
.screen-root {
  background: var(--ios-grouped-bg);
}

.panel {
  display: none;
  flex-direction: column;
  flex: 1;
  min-height: 0;
  overflow: hidden;
}

.panel.is-active {
  display: flex;
}

.ios-screen-head {
  flex-shrink: 0;
  padding: 0.35rem 1rem 0.35rem;
  background: var(--ios-grouped-bg);
}

.ios-large-title {
  margin: 0;
  font-size: 34px;
  font-weight: 700;
  letter-spacing: 0.37px;
  line-height: 1.05;
  color: var(--ios-label);
}

.ios-list-scroll {
  flex: 1;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  padding: 0 0 0.5rem;
}

.ios-thread-list {
  padding: 0 1rem;
}

.ios-group-list {
  background: var(--ios-cell-bg);
  border-radius: var(--ios-radius-group);
  overflow: hidden;
  box-shadow: 0 0 0 0.5px var(--ios-separator-opaque);
}

.ios-group-list .thread-item:first-child,
.ios-group-list .thread-item:last-child {
  border-radius: 0;
}

.ios-section-label {
  margin: 1.35rem 1rem 0.35rem;
  font-size: 13px;
  font-weight: 400;
  color: var(--ios-secondary-label);
  text-transform: uppercase;
  letter-spacing: -0.08px;
}

.ios-section-label:first-of-type {
  margin-top: 0.75rem;
}

.ios-group {
  margin: 0 1rem;
  background: var(--ios-cell-bg);
  border-radius: var(--ios-radius-group);
  overflow: hidden;
  box-shadow: 0 0 0 0.5px var(--ios-separator-opaque);
}

.ios-group-form {
  margin: 0;
}

.ios-settings-scroll {
  flex: 1;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  padding-bottom: calc(0.5rem + env(safe-area-inset-bottom, 0px));
}

.ios-settings-lead {
  margin: 0.5rem 1rem 0;
}

.ios-footnote {
  font-size: 13px;
  line-height: 1.35;
  color: var(--ios-secondary-label);
}

.ios-row {
  display: flex;
  align-items: center;
  min-height: 44px;
  padding: 0 1rem;
  border: 0;
  width: 100%;
  text-align: left;
  font: inherit;
  background: var(--ios-cell-bg);
  color: inherit;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}

.ios-row + .ios-row {
  box-shadow: inset 0 0.5px 0 var(--ios-separator);
}

.ios-row:active {
  background: #e5e5ea;
}

.ios-row--field {
  cursor: default;
}

.ios-row--field:active {
  background: var(--ios-cell-bg);
}

.ios-row--stack {
  flex-direction: column;
  align-items: stretch;
  padding-top: 0.5rem;
  padding-bottom: 0.5rem;
}

.ios-row--action {
  justify-content: center;
  min-height: 48px;
}

.ios-field {
  width: 100%;
  border: none;
  margin: 0;
  padding: 0.35rem 0;
  font-size: 17px;
  font-family: inherit;
  color: var(--ios-label);
  background: transparent;
  outline: none;
}

.ios-field::placeholder {
  color: var(--ios-tertiary-label);
}

.ios-link-btn {
  border: none;
  background: none;
  padding: 0.75rem 1rem;
  font-size: 17px;
  font-family: inherit;
  color: var(--ios-blue);
  cursor: pointer;
}

.ios-link-btn--strong {
  font-weight: 600;
}

.ios-status {
  margin: 0;
  padding: 0.65rem 0;
  font-size: 13px;
  line-height: 1.4;
  color: var(--ios-secondary-label);
  word-break: break-word;
}

.ios-status.warn {
  color: var(--ios-danger);
}

code {
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 12px;
  background: rgba(60, 60, 67, 0.08);
  padding: 0.1em 0.3em;
  border-radius: 4px;
}

/* Thread row (iOS Messages cell) */
.thread-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 12px;
  min-height: 76px;
  border: none;
  width: 100%;
  text-align: left;
  font: inherit;
  background: var(--ios-cell-bg);
  color: inherit;
  cursor: pointer;
  border-radius: 0;
  -webkit-tap-highlight-color: transparent;
}

.thread-item + .thread-item {
  box-shadow: inset 0 0.5px 0 var(--ios-separator);
}

.thread-item:active {
  background: #e5e5ea;
}

.thread-item.active {
  background: #ebebf0;
}

.thread-item.thread-waiting .ios-avatar {
  opacity: 0.85;
}

.ios-avatar {
  flex-shrink: 0;
  width: 52px;
  height: 52px;
  border-radius: 50%;
  background: linear-gradient(145deg, #aeaeb2, #8e8e93);
  color: #fff;
  font-size: 15px;
  font-weight: 600;
  display: flex;
  align-items: center;
  justify-content: center;
  letter-spacing: -0.02em;
}

.ios-row-body {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.ios-row-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
}

.thread-item .num {
  font-size: 17px;
  font-weight: 600;
  color: var(--ios-label);
}

.ios-row-time {
  flex-shrink: 0;
  font-size: 15px;
  color: var(--ios-secondary-label);
}

.thread-item .preview {
  font-size: 15px;
  color: var(--ios-secondary-label);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.thread-item-top {
  display: contents;
}

.thread-busy-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--ios-blue);
  flex-shrink: 0;
  margin-left: 4px;
}

.ios-row-chevron {
  flex-shrink: 0;
  color: var(--ios-tertiary-label);
  font-size: 20px;
  font-weight: 300;
  line-height: 1;
}

.ios-group-list .thread-item {
  margin: 0;
}

.ios-empty {
  text-align: center;
  padding: 3rem 1.5rem 2rem;
}

.ios-empty-title {
  margin: 0 0 0.5rem;
  font-size: 20px;
  font-weight: 600;
  color: var(--ios-label);
}

.ios-empty-sub {
  margin: 0;
  font-size: 15px;
  line-height: 1.45;
  color: var(--ios-secondary-label);
}

/* Tab bar */
.tab-bar {
  flex-shrink: 0;
  display: flex;
  align-items: stretch;
  justify-content: space-around;
  min-height: calc(var(--tab-bar-h) + env(safe-area-inset-bottom, 0px));
  padding-bottom: env(safe-area-inset-bottom, 0px);
  background: rgba(249, 249, 249, 0.92);
  backdrop-filter: saturate(180%) blur(20px);
  -webkit-backdrop-filter: saturate(180%) blur(20px);
  border-top: 0.33px solid var(--ios-separator);
}

.tab-item {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  padding: 6px 0 2px;
  border: none;
  background: none;
  font-family: inherit;
  cursor: pointer;
  color: var(--ios-secondary-label);
  -webkit-tap-highlight-color: transparent;
}

.tab-item.is-active {
  color: var(--ios-blue);
}

.tab-icon {
  display: block;
  width: 28px;
  height: 22px;
  margin-bottom: 1px;
}

.tab-label {
  font-size: 10px;
  font-weight: 500;
  letter-spacing: -0.01em;
}

/* —— Chat —— */
.screen-chat {
  background: #ffffff;
}

.ios-chat-nav {
  flex-shrink: 0;
  display: grid;
  grid-template-columns: minmax(0, auto) 1fr minmax(0, auto);
  align-items: center;
  column-gap: 6px;
  min-height: 44px;
  padding: 6px 8px 6px;
  background: var(--ios-nav-bg);
  backdrop-filter: saturate(180%) blur(20px);
  -webkit-backdrop-filter: saturate(180%) blur(20px);
  border-bottom: 0.33px solid var(--ios-separator);
}

.ios-back-btn {
  display: inline-flex;
  align-items: center;
  gap: 0;
  padding: 4px 8px 4px 2px;
  margin-left: -6px;
  border: none;
  background: none;
  font-family: inherit;
  font-size: 17px;
  color: var(--ios-blue);
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}

.ios-back-chevron {
  font-size: 28px;
  font-weight: 400;
  line-height: 1;
  margin-top: -2px;
  margin-right: -2px;
}

.ios-chat-nav-title {
  font-size: 17px;
  font-weight: 600;
  text-align: center;
  min-width: 0;
  color: var(--ios-label);
}

.peer-label-truncate {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.ios-chat-nav-spacer {
  width: 72px;
  height: 32px;
}

.messages {
  flex: 1;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  padding: 0.75rem 0.65rem 0.5rem;
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
}

.ios-messages {
  background: #ffffff;
}

.bubble-row {
  display: flex;
  max-width: 75%;
}

.bubble-row.out {
  align-self: flex-end;
  justify-content: flex-end;
}

.bubble-row.in {
  align-self: flex-start;
}

.bubble {
  padding: 0.5rem 0.85rem;
  border-radius: var(--ios-radius-bubble);
  line-height: 1.35;
  word-break: break-word;
  font-size: 17px;
}

.bubble.in {
  background: var(--ios-bubble-theirs);
  color: var(--ios-bubble-theirs-text);
  border-bottom-left-radius: 4px;
}

.bubble.out {
  background: var(--ios-bubble-mine);
  color: var(--ios-bubble-mine-text);
  border-bottom-right-radius: 4px;
}

.bubble-meta {
  font-size: 11px;
  opacity: 0.55;
  margin-top: 0.25rem;
  padding: 0 0.2rem;
}

.bubble-row.out .bubble-meta {
  text-align: right;
  color: var(--ios-secondary-label);
}

.bubble-row.in .bubble-meta {
  color: var(--ios-secondary-label);
}

.ios-composer {
  flex-shrink: 0;
  display: flex;
  align-items: flex-end;
  gap: 8px;
  padding: 8px 10px calc(8px + env(safe-area-inset-bottom, 0px));
  background: #f6f6f6;
  border-top: 0.33px solid var(--ios-separator);
}

.ios-composer textarea {
  flex: 1;
  min-height: 36px;
  max-height: 100px;
  resize: none;
  padding: 8px 12px;
  border: none;
  border-radius: 18px;
  background: #ffffff;
  font-family: inherit;
  font-size: 17px;
  line-height: 1.35;
  color: var(--ios-label);
  box-shadow: 0 0 0 0.5px rgba(0, 0, 0, 0.08);
}

.ios-composer textarea:focus {
  outline: none;
  box-shadow: 0 0 0 2px rgba(0, 122, 255, 0.35);
}

.ios-composer textarea:disabled {
  opacity: 0.45;
}

.ios-send {
  flex-shrink: 0;
  align-self: center;
  padding: 8px 4px;
  border: none;
  background: none;
  font-family: inherit;
  font-size: 17px;
  font-weight: 600;
  color: var(--ios-blue);
  cursor: pointer;
  opacity: 1;
}

.ios-send:disabled {
  opacity: 0.35;
  cursor: default;
}

.empty-state {
  margin: auto;
  text-align: center;
  color: var(--ios-secondary-label);
  font-size: 15px;
  padding: 2rem 1.5rem;
  line-height: 1.45;
}

.peer-label {
  font-weight: 600;
  font-size: 17px;
}
