.shell { padding: 10px 16px 16px; }
.layout { height: min(900px, calc(100dvh - 26px)); }

.app-header {
  flex: 0 0 auto;
  min-height: 58px;
  margin: 0;
  padding: 9px 10px;
  display: flex;
  align-items: center;
  justify-content: flex-start;
  gap: 9px;
  border-bottom: 1px solid rgba(38,55,71,.78);
  background: var(--surface);
}
.profile-button {
  flex: 0 0 auto;
  width: 42px;
  height: 42px;
  padding: 0;
  border-radius: 50%;
  display: grid;
  place-items: center;
  background: linear-gradient(145deg, #5b9df5, #3475d0);
  color: #fff;
  font-weight: 800;
  font-size: 1rem;
  box-shadow: 0 5px 18px rgba(51,144,236,.22);
}
.profile-button:hover { filter: brightness(1.08); }
.app-header-search {
  min-width: 0;
  flex: 1;
  height: 40px;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 0 12px;
  border-radius: 20px;
  background: var(--surface-2);
  color: var(--muted);
}
.app-header-search:focus-within { box-shadow: inset 0 0 0 1px rgba(51,144,236,.58); }
.app-header-search input {
  width: 100%;
  min-width: 0;
  padding: 0;
  border: 0;
  outline: 0;
  background: transparent;
  color: var(--text);
  font-size: .9rem;
}
.app-header-search input::placeholder { color: #788b9e; }

.settings-panel {
  position: fixed;
  inset: 0;
  z-index: 100;
  margin: 0;
  padding: max(18px, env(safe-area-inset-top)) 18px max(18px, env(safe-area-inset-bottom));
  display: flex;
  align-items: flex-start;
  justify-content: center;
  overflow: auto;
  border: 0;
  border-radius: 0;
  background: rgba(4, 10, 16, .72);
  backdrop-filter: blur(8px);
  box-shadow: none;
}
.settings-sheet {
  width: min(520px, 100%);
  max-height: calc(100dvh - max(36px, env(safe-area-inset-top) + env(safe-area-inset-bottom)));
  overflow: auto;
  border: 1px solid var(--border);
  border-radius: 18px;
  background: var(--surface);
  box-shadow: 0 24px 70px rgba(0,0,0,.34);
}
.settings-titlebar {
  position: sticky;
  top: 0;
  z-index: 3;
  min-height: 62px;
  padding: 12px 14px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  border-bottom: 1px solid var(--border);
  background: rgba(23,33,43,.96);
  backdrop-filter: blur(12px);
}
.settings-titlebar h2 { margin: 1px 0 0; font-size: 1.08rem; }
.settings-close { width: 38px; height: 38px; padding: 0; border-radius: 50%; font-size: 1.4rem; line-height: 1; }
.settings-profile {
  display: grid;
  grid-template-columns: 58px minmax(0,1fr);
  gap: 13px;
  align-items: center;
  padding: 18px 16px 14px;
}
.settings-profile-avatar {
  width: 58px;
  height: 58px;
  display: grid;
  place-items: center;
  border-radius: 50%;
  background: linear-gradient(145deg, #5b9df5, #3475d0);
  color: white;
  font-size: 1.2rem;
  font-weight: 800;
}
.settings-profile-copy { min-width: 0; display: grid; gap: 2px; }
.settings-profile-copy strong { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 1rem; }
.settings-profile-copy span { color: #b7c4d1; font-size: .82rem; }
.settings-profile-copy small { color: var(--muted); font-size: .74rem; }
.settings-group {
  margin: 0 10px 10px;
  overflow: hidden;
  border: 1px solid rgba(50,68,87,.8);
  border-radius: 13px;
  background: #111b26;
}
.settings-row {
  min-height: 60px;
  padding: 11px 12px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}
.settings-row + .settings-row { border-top: 1px solid rgba(50,68,87,.6); }
.settings-row > div:first-child { min-width: 0; display: grid; gap: 3px; }
.settings-row strong { font-size: .9rem; }
.settings-row span, .settings-row p { color: var(--muted); font-size: .77rem; line-height: 1.35; }
.settings-row-action { flex: 0 0 auto; padding: .52rem .7rem; }
.settings-actions { flex: 0 0 auto; display: flex; gap: 6px; flex-wrap: wrap; justify-content: flex-end; }
.settings-actions button { padding: .52rem .7rem; }
.settings-hint { margin: -2px 12px 12px; color: var(--muted); font-size: .75rem; line-height: 1.4; }
.connector-grid { display: block; margin: 0; }
.connector-card {
  min-height: 64px;
  padding: 10px 12px;
  border-radius: 0;
  background: transparent;
  border-top: 1px solid rgba(50,68,87,.55);
}
.connector-card:first-child { border-top: 0; }
.connector-actions button { padding: .48rem .64rem; font-size: .76rem; }
.account-section { align-items: center; }
.onboarding-panel { margin: 0 10px 10px; }

@media (max-width: 760px) {
  :root { --mobile-safe-top: env(safe-area-inset-top); }

  @supports (-webkit-touch-callout: none) {
    :root { --mobile-safe-top: max(env(safe-area-inset-top), 44px); }
  }

  .shell { width: 100%; height: 100dvh; padding: 0; }
  .layout { height: 100dvh; min-height: 0; border: 0; border-radius: 0; }

  .conversation-pane .app-header,
  .layout.chat-open .chat-header {
    min-height: calc(58px + var(--mobile-safe-top));
    padding: calc(8px + var(--mobile-safe-top)) 10px 8px;
  }

  .layout.chat-open .chat-header {
    position: relative;
    z-index: 5;
  }

  .layout.chat-open .chat-back {
    display: grid;
    place-items: center;
    width: 44px;
    min-width: 44px;
    height: 44px;
    pointer-events: auto;
    touch-action: manipulation;
  }

  .profile-button { width: 40px; height: 40px; }
  .app-header-search { height: 40px; }
  .count-chip { min-width: 32px; height: 32px; }

  .settings-panel {
    padding: var(--mobile-safe-top) 0 env(safe-area-inset-bottom);
    align-items: stretch;
    background: var(--bg);
    backdrop-filter: none;
  }
  .settings-sheet {
    width: 100%;
    max-height: none;
    min-height: calc(100dvh - var(--mobile-safe-top) - env(safe-area-inset-bottom));
    border: 0;
    border-radius: 0;
    box-shadow: none;
  }
  .settings-titlebar { top: 0; min-height: 58px; }
  .settings-profile { padding-top: 16px; }
  .connector-card { align-items: center; flex-direction: row; }
  .connector-actions { width: auto; justify-content: flex-end; }
  .settings-row { align-items: center; }
  .settings-actions { justify-content: flex-end; }
}

@media (max-width: 430px) {
  .count-chip { display: none; }
  .settings-row-heading { align-items: flex-start; }
  .settings-row-heading > .settings-actions { max-width: 44%; }
  .connector-card { align-items: flex-start; flex-direction: column; }
  .connector-actions { width: 100%; justify-content: flex-start; }
}

@media (max-width: 760px) {
  .settings-panel.settings-panel {
    background:
      radial-gradient(circle at 14% 0%, rgba(57, 119, 164, 0.08), transparent 28%),
      linear-gradient(180deg, #111e28 0%, #0b161e 100%) !important;
  }

  .settings-panel .settings-sheet {
    background: transparent !important;
  }
}
