.row-spacer {
  flex: 1;
}

#topbar {
  height: 60px;
  flex-shrink: 0;
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 0 14px;
  background: var(--rg-bg-glass);
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
  position: relative;
  z-index: 30;
}

#app {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-height: 0;
}

.view {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-height: 0;
}

#messages {
  flex: 1 1 0%;
  min-height: 0;
  overflow-y: auto;
  overflow-x: hidden;
  -webkit-overflow-scrolling: touch;
  overscroll-behavior: contain;
  padding: 16px 14px calc(var(--composer-pad-bottom, 152px) + env(safe-area-inset-bottom, 0px));
  display: flex;
  flex-direction: column;
  gap: 12px;
  mask-image: linear-gradient(to bottom, transparent, black 28px);
  -webkit-mask-image: linear-gradient(to bottom, transparent, black 28px);
}

#messages,
#sidebar,
.settings-page,
#view-collection {
  scrollbar-width: thin;
  scrollbar-color: var(--rg-line) transparent;
}

#messages::-webkit-scrollbar,
#sidebar::-webkit-scrollbar,
.settings-page::-webkit-scrollbar,
#view-collection::-webkit-scrollbar {
  width: 4px;
}

#messages::-webkit-scrollbar-thumb,
#sidebar::-webkit-scrollbar-thumb,
.settings-page::-webkit-scrollbar-thumb,
#view-collection::-webkit-scrollbar-thumb {
  background: var(--rg-line);
  border-radius: 2px;
}

#view-chat {
  position: relative;
  flex: 1 1 0%;
  height: 100%;
  max-height: var(--vvh, 100%);
  min-height: 0;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

#composer {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 20;
  pointer-events: none;
  padding: 0 12px calc(14px + env(safe-area-inset-bottom, 0px));
  background: transparent;
  box-shadow: none;
  border: none;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

#composer > * {
  pointer-events: auto;
}

body.keyboard-open #composer {
  padding: 0 12px 12px;
  background: transparent;
  box-shadow: none;
  border: none;
}

body.keyboard-open #messages {
  padding-bottom: calc(var(--composer-pad-bottom, 148px) + env(safe-area-inset-bottom, 0px));
}

#composer-card {
  background: var(--rg-bg-glass);
  backdrop-filter: blur(18px) saturate(180%);
  -webkit-backdrop-filter: blur(18px) saturate(180%);
  border: 1px solid rgba(15, 23, 42, 0.08);
  border-radius: 26px;
  padding: 14px 14px 10px;
  box-shadow: 0 8px 28px -6px rgba(15, 23, 42, 0.08), 0 2px 6px rgba(15, 23, 42, 0.03);
  transition: background 0.28s ease, border-color 0.2s, box-shadow 0.2s;
}

#composer-card:has(#chat-input:focus) {
  border-color: var(--rg-line);
  box-shadow: var(--rg-shadow);
  outline: none;
}

#chat-input:focus,
#chat-input:focus-visible,
#composer button:focus,
#composer button:focus-visible,
#top-download-bar button:focus,
#top-download-bar button:focus-visible {
  outline: none;
  box-shadow: none;
}

.weight-card {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin: 0 4px 12px;
  padding-bottom: 12px;
  border-bottom: 1px solid var(--rg-line);
}

.weight-card[hidden] {
  display: none;
}

#top-download-bar[hidden] {
  display: none;
}

body.auth-gate #top-download-bar {
  display: none;
}

#top-download-bar {
  flex: 0 0 auto;
  width: 100%;
}

#top-download-bar .weight-card {
  margin: 0;
  padding: 8px 12px;
  border: 1px solid var(--rg-line);
  border-bottom: 1px solid var(--rg-line);
  border-radius: 12px;
  background: var(--rg-bg);
  max-height: 67px;
}

#top-download-bar .weight-card:not(:has(#weight-status[data-busy="1"])) {
  display: flex;
  flex-direction: row;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  height: 44px;
  max-height: 44px;
  padding: 0 6px 0 14px;
  border-radius: 999px;
  overflow: hidden;
}

#top-download-bar .weight-card:not(:has(#weight-status[data-busy="1"])) .weight-bar {
  display: none;
}

#top-download-bar .weight-card:not(:has(#weight-status[data-busy="1"])) #weight-status {
  flex: 1 1 auto;
  min-width: 0;
  margin: 0;
  font-size: 12.5px;
  font-weight: 500;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

#top-download-bar .weight-card:not(:has(#weight-status[data-busy="1"])) .weight-actions {
  flex: 0 0 auto;
  flex-wrap: nowrap;
}

#top-download-bar .weight-card:not(:has(#weight-status[data-busy="1"])) #btn-weight {
  padding: 6px 12px;
  font-size: 12px;
  font-weight: 600;
  white-space: nowrap;
}

#top-download-bar .dl-ico {
  display: none;
}

#top-download-bar .weight-card:has(#weight-status[data-busy="1"]) {
  display: flex;
  flex-direction: row;
  align-items: center;
  gap: 8px;
  height: 36px;
  max-height: 36px;
  padding: 0 8px 0 12px;
  border-radius: 999px;
  overflow: hidden;
}

#top-download-bar .weight-card:has(#weight-status[data-busy="1"]) #btn-weight {
  display: none;
}

#top-download-bar .weight-card:has(#weight-status[data-busy="1"]) .dl-ico {
  display: inline-flex;
  order: 0;
  flex: 0 0 auto;
}

#top-download-bar .weight-card:has(#weight-status[data-busy="1"]) #weight-status {
  order: 1;
  flex: 0 1 auto;
  font-family: inherit;
  font-variant-numeric: tabular-nums;
  font-size: 11.5px;
  font-weight: 650;
  letter-spacing: -0.01em;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

#top-download-bar .weight-card:has(#weight-status[data-busy="1"]) .weight-bar {
  order: 2;
  flex: 1 1 24px;
  height: 3px;
  min-width: 20px;
}

#top-download-bar .weight-card:has(#weight-status[data-busy="1"]) .weight-bar::after {
  display: none;
}

#top-download-bar .weight-card:has(#weight-status[data-busy="1"]) .weight-actions {
  order: 3;
  flex: 0 0 auto;
  gap: 6px;
}

#top-download-bar .weight-card:has(#weight-status[data-busy="1"]) .weight-actions button {
  padding: 4px 10px;
  font-size: 12px;
}

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

.weight-actions button {
  border: 1px solid var(--rg-line);
  background: transparent;
  color: var(--rg-text);
  border-radius: 999px;
  padding: 8px 14px;
  font: inherit;
  font-size: 13px;
  cursor: pointer;
}

.weight-actions button:disabled {
  opacity: 0.6;
  cursor: default;
}

.weight-actions button[hidden] {
  display: none;
}

.weight-bar {
  position: relative;
  height: 4px;
  background: var(--rg-line);
  border-radius: 999px;
  overflow: hidden;
}

.weight-bar::after {
  content: '';
  position: absolute;
  left: 22%;
  top: 0;
  bottom: 0;
  width: 2px;
  background: var(--rg-text);
  opacity: 0.7;
}

#weight-fill {
  display: block;
  height: 100%;
  width: 0;
  background: var(--rg-text);
}

#weight-status {
  margin: 0;
  font-size: 12px;
  line-height: 1.4;
  color: var(--rg-muted);
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}

#chat-input {
  width: 100%;
  min-height: 28px;
  background: transparent;
  border: none;
  outline: none;
  color: var(--rg-text);
  font-size: 17px;
  line-height: 1.45;
  padding: 2px 4px;
  resize: none;
  max-height: 120px;
  overflow-y: hidden;
  scrollbar-width: none;
  -ms-overflow-style: none;
  -webkit-appearance: none;
  appearance: none;
  -webkit-user-select: text;
  user-select: text;
}

#chat-input::-webkit-scrollbar,
#chat-input::-webkit-resizer,
#composer-card::-webkit-resizer,
textarea::-webkit-resizer {
  display: none;
  width: 0;
  height: 0;
  background: transparent;
}

#chat-input::placeholder {
  color: var(--rg-muted);
}

.card-row {
  display: flex;
  align-items: center;
  gap: 4px;
  margin-top: 8px;
}

.model-badge {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.3px;
  color: var(--rg-muted);
  padding: 0 4px;
}

@media (horizontal-viewport-segments: 2) {
  #view-chat {
    display: grid;
    grid-template-columns: 1fr 1fr;
  }
}
