:root {
  --bg: #04111f;
  --panel: #071a2d;
  --panel-2: #0a223c;
  --card: #0b2745;
  --line: rgba(255, 255, 255, 0.08);
  --text: #f7fbff;
  --muted: #8ea7be;
  --accent: #ff8a16;
  --accent-2: #0c6fff;
  --success: #1ed08d;
  --danger: #ff6c6c;
  --shadow: 0 20px 50px rgba(0, 0, 0, 0.35);
  --radius: 18px;
}
* {
  box-sizing: border-box;
}
html,
body {
  height: 100%;
}
body {
  margin: 0;
  background:
    radial-gradient(
      circle at top right,
      rgba(31, 91, 180, 0.16),
      transparent 28%
    ),
    linear-gradient(180deg, #03111f 0%, #07172a 100%);
  color: var(--text);
  font-family:
    Inter,
    ui-sans-serif,
    system-ui,
    -apple-system,
    Segoe UI,
    Roboto,
    Arial,
    sans-serif;
  overflow: hidden;
}
a {
  color: inherit;
  text-decoration: none;
}
button,
input,
textarea,
select {
  font: inherit;
}
.layout {
  display: grid;
  grid-template-columns: 250px minmax(0, 1fr);
  height: 100vh;
}
.sidebar {
  border-right: 1px solid var(--line);
  background: rgba(2, 12, 24, 0.72);
  backdrop-filter: blur(12px);
  display: flex;
  flex-direction: column;
  padding: 18px 14px;
  gap: 14px;
  overflow-y: auto;
  overscroll-behavior: contain;
}
.brand {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 6px 4px 18px;
}
.brand img {
  width: 100%;
  height: 78px;
  max-width: 220px;
  max-height: 78px;
  object-fit: cover;
  background: transparent;
  border-radius: 10px;
}
.nav {
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.nav-btn,
.new-chat-btn {
  width: 100%;
  display: flex;
  align-items: center;
  gap: 12px;
  border: 1px solid transparent;
  background: transparent;
  color: #dce8f5;
  border-radius: 14px;
  padding: 12px 14px;
  cursor: pointer;
  text-align: left;
  font-weight: 700;
}
.nav-btn:hover,
.new-chat-btn:hover {
  background: rgba(255, 255, 255, 0.04);
}
.nav-btn.active {
  background: linear-gradient(180deg, #0e2f53, #0a2440);
  border-color: rgba(255, 255, 255, 0.08);
  box-shadow: var(--shadow);
}
.new-chat-btn {
  background: linear-gradient(90deg, var(--accent), #ffaf3f);
  color: #fff;
  justify-content: center;
}
.chat-history-panel {
  display: flex;
  flex-direction: column;
  min-height: 88px;
  max-height: 38vh;
  flex: 0 0 auto;
  border-top: 1px solid var(--line);
  padding-top: 12px;
}
.chat-history-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 8px 7px;
  color: #fff;
  font-size: 12px;
  font-weight: 800;
}
.chat-history-list {
  display: flex;
  flex-direction: column;
  gap: 3px;
  overflow-y: auto;
  padding: 0 2px 4px;
  scrollbar-width: thin;
  min-height: 44px;
  max-height: 260px;
  flex: 0 0 auto;
}
.chat-group-label {
  padding: 8px 8px 4px;
  color: var(--muted);
  font-size: 10px;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: 0.06em;
}
.chat-history-item {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 28px;
  align-items: center;
  gap: 4px;
  border-radius: 10px;
  padding: 2px 3px 2px 8px;
  color: #cfe0ef;
  cursor: pointer;
  border: 1px solid transparent;
}
.chat-history-item:hover {
  background: rgba(255, 255, 255, 0.045);
}
.chat-history-item.active {
  background: #0b2948;
  border-color: rgba(80, 145, 230, 0.3);
  color: #fff;
}
.chat-history-title {
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  font-size: 11px;
  padding: 7px 0;
}
.chat-more {
  border: 0;
  background: transparent;
  color: #8ea7be;
  cursor: pointer;
  border-radius: 7px;
  height: 28px;
}
.chat-more:hover {
  background: rgba(255, 255, 255, 0.08);
  color: #fff;
}
.chat-empty {
  padding: 10px 8px;
  color: var(--muted);
  font-size: 11px;
  line-height: 1.45;
}
.side-section {
  border-top: 1px solid var(--line);
  padding-top: 14px;
  margin-top: 4px;
}
.mini {
  font-size: 12px;
  color: var(--muted);
  line-height: 1.55;
  padding: 0 10px;
}
.main {
  display: flex;
  flex-direction: column;
  min-width: 0;
  min-height: 0;
  height: 100vh;
  overflow: hidden;
}
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 20px;
  border-bottom: 1px solid var(--line);
  background: rgba(2, 12, 24, 0.45);
  backdrop-filter: blur(12px);
  gap: 16px;
}
.top-left h1 {
  margin: 0;
  font-size: 22px;
}
.top-left p {
  margin: 4px 0 0;
  color: var(--muted);
  font-size: 13px;
}
.top-right {
  display: flex;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
  justify-content: flex-end;
}
.chip {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 14px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid var(--line);
}
.coin {
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: linear-gradient(180deg, #ffc14f, #ff9f16);
  box-shadow: 0 0 0 3px rgba(255, 173, 55, 0.15);
}
.plus {
  display: inline-grid;
  place-items: center;
  width: 24px;
  height: 24px;
  border-radius: 50%;
  background: linear-gradient(180deg, #1a86ff, #0c6fff);
  font-weight: 900;
  cursor: pointer;
}
.userbox {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 10px;
  border-radius: 14px;
  background: rgba(255, 255, 255, 0.04);
  border: 1px solid var(--line);
  cursor: pointer;
  transition: 0.18s;
}
.userbox:hover {
  background: rgba(255, 255, 255, 0.08);
  border-color: rgba(62, 131, 255, 0.35);
}
.avatar {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  background: linear-gradient(180deg, #1d60b8, #163a67);
  display: grid;
  place-items: center;
  font-weight: 900;
}
.user-meta {
  display: flex;
  flex-direction: column;
  min-width: 0;
}
.user-meta strong {
  font-size: 14px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.user-meta span {
  font-size: 11px;
  color: var(--muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 200px;
}
.logout-btn {
  width: 38px;
  height: 38px;
  border-radius: 12px;
  border: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.04);
  color: #fff;
  cursor: pointer;
}
.workspace {
  flex: 1 1 auto;
  display: grid;
  grid-template-columns: minmax(0, 1fr) 360px;
  gap: 0;
  min-height: 0;
  height: 0;
  overflow: hidden;
}
.page {
  display: none;
  min-height: 0;
  height: 100%;
  max-height: 100%;
  overflow: hidden;
}
.page.active {
  display: flex;
  flex-direction: column;
  flex: 1;
  min-height: 0;
  height: 100%;
}
.chat-page {
  min-width: 0;
  min-height: 0;
  border-right: 1px solid var(--line);
  height: 100%;
  max-height: 100%;
  overflow: hidden;
}
.chat-stream {
  flex: 1 1 0;
  min-height: 0;
  height: 0;
  overflow-y: scroll;
  overflow-x: hidden;
  padding: 18px 18px 26px;
  display: flex;
  flex-direction: column;
  gap: 14px;
  overscroll-behavior: contain;
  scrollbar-gutter: stable;
}

.chat-stream::-webkit-scrollbar {
  width: 10px;
}
.chat-stream::-webkit-scrollbar-track {
  background: rgba(255, 255, 255, 0.025);
  border-radius: 999px;
}
.chat-stream::-webkit-scrollbar-thumb {
  background: rgba(142, 167, 190, 0.42);
  border-radius: 999px;
  border: 2px solid transparent;
  background-clip: padding-box;
}
.chat-stream::-webkit-scrollbar-thumb:hover {
  background: rgba(142, 167, 190, 0.68);
  background-clip: padding-box;
}
.empty-state {
  margin: auto;
  max-width: 720px;
  background: linear-gradient(
    180deg,
    rgba(11, 39, 69, 0.9),
    rgba(7, 24, 43, 0.96)
  );
  border: 1px solid var(--line);
  border-radius: 26px;
  padding: 34px;
  box-shadow: var(--shadow);
}
.empty-state h2 {
  font-size: 40px;
  line-height: 1.06;
  margin: 0 0 10px;
}
.empty-state p {
  margin: 0;
  color: #c3d6e7;
  font-size: 16px;
  line-height: 1.65;
}
.empty-state .quick {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  margin-top: 20px;
}
.quick button {
  border: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.03);
  color: #fff;
  padding: 10px 14px;
  border-radius: 999px;
  cursor: pointer;
}
.msg {
  display: flex;
  gap: 12px;
  max-width: 100%;
}
.msg.user {
  justify-content: flex-end;
}
.msg-avatar {
  flex: 0 0 36px;
  width: 36px;
  height: 36px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  background: linear-gradient(180deg, #1f6bd0, #163760);
  font-size: 13px;
  font-weight: 900;
}
.msg.user .msg-avatar {
  order: 2;
  background: linear-gradient(180deg, #ff9e32, #e56d00);
}
.bubble-wrap {
  max-width: min(780px, 86%);
}
.bubble {
  background: linear-gradient(180deg, #0b2745, #091f38);
  border: 1px solid var(--line);
  border-radius: 18px;
  padding: 14px 16px;
  line-height: 1.62;
  color: #edf5fc;
  box-shadow: 0 16px 40px rgba(0, 0, 0, 0.18);
  white-space: pre-wrap;
  word-break: break-word;
}
.msg.user .bubble {
  background: linear-gradient(180deg, #0f3763, #0a2849);
}
.msg-meta {
  margin-top: 8px;
  color: var(--muted);
  font-size: 12px;
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
}
.assistant-images {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 12px;
  margin-top: 12px;
}
.assistant-images .img-card {
  background: rgba(255, 255, 255, 0.03);
  border: 1px solid var(--line);
  border-radius: 16px;
  padding: 10px;
}
.assistant-images img {
  width: 100%;
  max-height: 440px;
  height: auto;
  display: block;
  border-radius: 12px;
  object-fit: contain;
  background: #061321;
}
.img-actions {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  margin-top: 9px;
}
.img-actions button,
.img-actions a {
  flex: 1 1 auto;
  display: inline-flex;
  justify-content: center;
  align-items: center;
  min-height: 34px;
  border-radius: 10px;
  border: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.04);
  color: #fff;
  cursor: pointer;
  padding: 0 10px;
  font-size: 12px;
}
.composer {
  flex: 0 0 auto;
  padding: 14px 18px 18px;
  border-top: 1px solid var(--line);
  background: rgba(4, 17, 31, 0.98);
  backdrop-filter: blur(12px);
  position: sticky;
  bottom: 0;
  z-index: 30;
  box-shadow: 0 -16px 35px rgba(0, 0, 0, 0.22);
}
.attachment-list {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  margin-bottom: 12px;
  align-items: center;
}
.attachment-list.empty {
  display: none;
}
.attachment-summary {
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  color: var(--muted);
  font-size: 11px;
  padding: 0 2px;
}
.attachment-summary strong {
  color: #e8f3ff;
  font-size: 12px;
}
.attachment-summary .attach-state {
  display: inline-flex;
  align-items: center;
  gap: 6px;
}
.attachment-summary .attach-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: #7f9ab4;
}
.attachment-list.uploading .attach-dot,
.attachment-list.analyzing .attach-dot {
  background: #ff9d28;
  box-shadow: 0 0 0 4px rgba(255, 157, 40, 0.1);
}
.attachment-list.error .attach-dot {
  background: #ff6c6c;
}
.attachment {
  display: flex;
  align-items: center;
  gap: 8px;
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid var(--line);
  border-radius: 13px;
  padding: 7px 8px;
  max-width: 260px;
  min-width: 170px;
}
.attachment-preview-link {
  display: block;
  flex: 0 0 auto;
  border-radius: 9px;
  overflow: hidden;
}
.attachment-thumb {
  width: 46px;
  height: 46px;
  object-fit: cover;
  border-radius: 9px;
  background: #061321;
  border: 1px solid var(--line);
  display: block;
}
.attachment-info {
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 3px;
  flex: 1;
}
.attachment-info strong {
  font-size: 12px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.attachment-meta {
  font-size: 10px;
  color: var(--muted);
  white-space: nowrap;
}
.attachment button {
  border: 0;
  background: rgba(255, 108, 108, 0.08);
  border-radius: 9px;
  color: #ff9a9a;
  cursor: pointer;
  width: 30px;
  height: 30px;
  display: grid;
  place-items: center;
  flex: 0 0 auto;
}
.attachment-count {
  font-size: 11px;
  color: var(--muted);
  padding: 0 2px;
  white-space: nowrap;
}
.user-attachments {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
  margin-top: 10px;
  max-width: 460px;
}
.user-attachments a {
  display: block;
  border-radius: 12px;
  overflow: hidden;
  border: 1px solid var(--line);
  background: #061321;
}
.user-attachments img {
  display: block;
  width: 100%;
  height: 150px;
  object-fit: cover;
}
@media (max-width: 640px) {
  .user-attachments img {
    height: 120px;
  }
  .attachment {
    max-width: 240px;
    min-width: 210px;
  }
  .attachment-summary {
    font-size: 10px;
  }
  .attachment-thumb {
    width: 44px;
    height: 44px;
  }
}
.composer-box {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 110px;
  gap: 12px;
  align-items: end;
}
.textarea-wrap {
  background: linear-gradient(180deg, #081a30, #061425);
  border: 1px solid var(--line);
  border-radius: 18px;
  padding: 10px 12px;
}
textarea {
  width: 100%;
  resize: none;
  background: transparent;
  border: 0;
  outline: 0;
  color: #fff;
  min-height: 92px;
  max-height: 210px;
}
.composer-actions {
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.primary-btn,
.secondary-btn,
.ghost-btn {
  min-height: 48px;
  border-radius: 14px;
  border: 0;
  font-weight: 800;
  cursor: pointer;
  padding: 0 14px;
}
.primary-btn {
  background: linear-gradient(90deg, var(--accent), #ffad3c);
  color: #fff;
}
.secondary-btn {
  background: linear-gradient(90deg, #1a86ff, #6b5cff);
  color: #fff;
}
.ghost-btn {
  background: rgba(255, 255, 255, 0.04);
  border: 1px solid var(--line);
  color: #fff;
}
.composer-footer {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  margin-top: 12px;
  flex-wrap: wrap;
}
.left-tools {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}
.right-tools {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
  color: var(--muted);
  font-size: 12px;
}
.file-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 40px;
  padding: 0 14px;
  border-radius: 12px;
  border: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.04);
  cursor: pointer;
}
#fileInput {
  display: none;
}
details.settings {
  margin-top: 12px;
  border: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.025);
  border-radius: 16px;
  overflow: hidden;
}
details.settings summary {
  list-style: none;
  cursor: pointer;
  padding: 14px 16px;
  font-weight: 800;
  display: flex;
  justify-content: space-between;
  align-items: center;
}
details.settings summary::-webkit-details-marker {
  display: none;
}
.settings-grid {
  padding: 0 16px 16px;
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
}
.field {
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.field label {
  font-size: 12px;
  color: var(--muted);
}
.field select,
.field input {
  height: 42px;
  border-radius: 12px;
  border: 1px solid var(--line);
  background: #07182b;
  color: #fff;
  padding: 0 12px;
  outline: none;
}
.sidepanel {
  padding: 18px;
  min-height: 0;
  overflow: auto;
  display: flex;
  flex-direction: column;
  gap: 16px;
  background: rgba(4, 17, 31, 0.55);
}
.panel-card {
  background: linear-gradient(180deg, #0a2139, #07182b);
  border: 1px solid var(--line);
  border-radius: 18px;
  padding: 16px;
  box-shadow: var(--shadow);
}
.panel-card h3 {
  margin: 0 0 12px;
  font-size: 16px;
}
.panel-card p {
  margin: 0;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.6;
}
.status-pill {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 8px 12px;
  border-radius: 999px;
  background: rgba(30, 208, 141, 0.12);
  border: 1px solid rgba(30, 208, 141, 0.24);
  color: #a8f0ce;
  font-size: 12px;
  font-weight: 700;
}
.status-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--success);
}
.creation-toolbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  padding: 18px 18px 0;
}
.creation-toolbar h2 {
  margin: 0;
}
.danger-btn {
  min-height: 38px;
  border-radius: 11px;
  border: 1px solid rgba(255, 108, 108, 0.28);
  background: rgba(255, 108, 108, 0.08);
  color: #ffb1b1;
  padding: 0 13px;
  font-weight: 800;
  cursor: pointer;
}
.creation-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  gap: 14px;
  padding: 18px;
  overflow: auto;
  min-height: 0;
}
.creation-card {
  background: linear-gradient(180deg, #0a2139, #07182b);
  border: 1px solid var(--line);
  border-radius: 18px;
  padding: 12px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.creation-card img {
  width: 100%;
  aspect-ratio: 1/1;
  object-fit: cover;
  border-radius: 14px;
  background: #081827;
}
.creation-title {
  font-weight: 800;
  font-size: 14px;
}
.creation-meta {
  font-size: 12px;
  color: var(--muted);
  line-height: 1.5;
}
.credits-page,
.templates-page {
  padding: 18px;
  overflow: auto;
  min-height: 0;
}
.template-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 18px;
}
.template-head h2 {
  margin: 0;
  font-size: 30px;
  letter-spacing: -0.4px;
}
.template-head p {
  margin: 6px 0 0;
  color: var(--muted);
  max-width: 760px;
  line-height: 1.6;
}
.template-search {
  width: min(360px, 100%);
  height: 44px;
  border-radius: 12px;
  border: 1px solid var(--line);
  background: #07182b;
  color: #fff;
  padding: 0 14px;
  outline: none;
}
.template-cats {
  display: flex;
  gap: 9px;
  flex-wrap: wrap;
  margin-bottom: 18px;
  position: sticky;
  top: -18px;
  z-index: 4;
  padding: 10px 0;
  background: linear-gradient(180deg, #04111f 75%, rgba(4, 17, 31, 0));
}
.template-cat {
  border: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.035);
  color: #dce8f5;
  padding: 8px 13px;
  border-radius: 999px;
  cursor: pointer;
  font-weight: 700;
  font-size: 12px;
}
.template-cat.active {
  background: linear-gradient(90deg, #0c6fff, #6b5cff);
  border-color: transparent;
}
.template-section {
  margin: 0 0 24px;
}
.template-section-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin: 0 0 12px;
}
.template-section-head h3 {
  margin: 0;
  font-size: 18px;
}
.template-section-head span {
  color: var(--muted);
  font-size: 11px;
}
.template-strip {
  display: grid;
  grid-auto-flow: column;
  grid-auto-columns: minmax(260px, 290px);
  gap: 14px;
  overflow-x: auto;
  padding: 2px 2px 10px;
  scroll-snap-type: x proximity;
}
.template-strip .template-card {
  scroll-snap-align: start;
}
.template-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: 18px;
  padding-bottom: 28px;
}
.template-card {
  border: 1px solid var(--line);
  background: linear-gradient(180deg, #0a2139, #07182b);
  border-radius: 18px;
  overflow: hidden;
  cursor: pointer;
  transition: 0.2s ease;
  box-shadow: 0 12px 30px rgba(0, 0, 0, 0.14);
}
.template-card:hover {
  transform: translateY(-4px);
  border-color: rgba(95, 154, 255, 0.55);
  box-shadow: 0 18px 46px rgba(0, 0, 0, 0.28);
}
.template-preview {
  height: 240px;
  position: relative;
  overflow: hidden;
  background: radial-gradient(circle at 50% 42%, #122b45, #06182b 70%);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 4px;
}
.template-preview[data-ratio="wide"] {
  height: 220px;
}
.template-preview[data-ratio="portrait"] {
  height: 270px;
}
.template-preview[data-ratio="square"] {
  height: 250px;
}
.template-preview:after {
  content: "";
  position: absolute;
  inset: 0;
  background: linear-gradient(
    180deg,
    rgba(0, 0, 0, 0) 78%,
    rgba(0, 0, 0, 0.14) 100%
  );
  pointer-events: none;
}
.template-preview img {
  width: 100%;
  height: 100%;
  object-fit: contain;
  display: block;
  border-radius: 11px;
  background: transparent;
}
.template-preview.fallback {
  background: #0a223c center/cover no-repeat;
  padding: 0;
}
.template-real-badge {
  position: absolute;
  left: 10px;
  top: 10px;
  z-index: 2;
  padding: 4px 7px;
  border-radius: 999px;
  background: rgba(3, 14, 28, 0.74);
  border: 1px solid rgba(255, 255, 255, 0.14);
  color: #e8f3ff;
  font-size: 9px;
  font-weight: 800;
  letter-spacing: 0.2px;
  backdrop-filter: blur(8px);
}
.template-real-badge:empty {
  display: none;
}
.template-hover {
  position: absolute;
  inset: 0;
  z-index: 3;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(4, 17, 31, 0.18);
  opacity: 0;
  transition: 0.18s ease;
}
.template-card:hover .template-hover {
  opacity: 1;
  background: rgba(4, 17, 31, 0.42);
}
.template-use {
  border: 1px solid rgba(255, 255, 255, 0.2);
  background: #fff;
  color: #0a1727;
  height: 40px;
  padding: 0 18px;
  border-radius: 999px;
  font-weight: 900;
  cursor: pointer;
  box-shadow: 0 10px 26px rgba(0, 0, 0, 0.28);
}
.template-body {
  padding: 12px 14px 14px;
}
.template-body b {
  display: block;
  font-size: 14px;
}
.template-body span {
  display: block;
  color: var(--muted);
  font-size: 11px;
  margin-top: 5px;
}
.template-badge {
  display: inline-block !important;
  width: auto;
  margin-top: 9px !important;
  padding: 4px 8px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.06);
  font-size: 10px !important;
  color: #cfe0ef !important;
}
.workspace.template-focus {
  grid-template-columns: minmax(0, 1fr) !important;
}
.workspace.template-focus .sidepanel {
  display: none !important;
}
.workspace.template-focus .templates-page {
  padding-right: 22px;
}
@media (max-width: 760px) {
  .template-head {
    flex-direction: column;
  }
  .template-search {
    width: 100%;
  }
  .template-grid {
    grid-template-columns: 1fr;
    gap: 12px;
  }
  .template-strip {
    grid-auto-columns: 82vw;
  }
  .template-preview,
  .template-preview[data-ratio="wide"],
  .template-preview[data-ratio="portrait"],
  .template-preview[data-ratio="square"] {
    height: 250px;
  }
  .template-cats {
    top: -18px;
  }
}
.topup-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 12px;
  margin-top: 18px;
}
.topup-card {
  border: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.035);
  border-radius: 16px;
  padding: 16px;
}
.topup-card strong {
  display: block;
  font-size: 24px;
}
.topup-card span {
  display: block;
  color: var(--muted);
  font-size: 12px;
  margin: 6px 0 12px;
}
.topup-card button {
  width: 100%;
  height: 40px;
  border: 0;
  border-radius: 11px;
  background: linear-gradient(90deg, #0c6fff, #6b5cff);
  color: white;
  font-weight: 800;
  cursor: pointer;
}
@media (max-width: 760px) {
  .topup-grid {
    grid-template-columns: 1fr;
  }
}
.big-card {
  max-width: 880px;
  background: linear-gradient(180deg, #0a2139, #07182b);
  border: 1px solid var(--line);
  border-radius: 24px;
  padding: 22px;
  box-shadow: var(--shadow);
}
.ledger {
  margin-top: 14px;
  border-top: 1px solid var(--line);
}
.ledger-row {
  display: grid;
  grid-template-columns: 110px 110px 1fr 120px;
  gap: 12px;
  padding: 12px 0;
  border-bottom: 1px solid rgba(255, 255, 255, 0.05);
  font-size: 13px;
}
.ledger-row strong {
  color: #fff;
}
.positive {
  color: #85f0b7;
}
.negative {
  color: #ff9e9e;
}
.toast {
  position: fixed;
  right: 22px;
  bottom: 20px;
  background: #081b32;
  border: 1px solid var(--line);
  color: #fff;
  padding: 12px 16px;
  border-radius: 14px;
  box-shadow: var(--shadow);
  opacity: 0;
  transform: translateY(10px);
  transition: 0.2s;
  z-index: 1000;
}
.toast.show {
  opacity: 1;
  transform: translateY(0);
}
.loading {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  color: var(--muted);
  font-size: 13px;
}
.spinner {
  width: 14px;
  height: 14px;
  border: 2px solid rgba(255, 255, 255, 0.15);
  border-top-color: #fff;
  border-radius: 50%;
  animation: spin 1s linear infinite;
}
@keyframes spin {
  to {
    transform: rotate(360deg);
  }
}
.btn-spinner {
  display: inline-block;
  width: 18px;
  height: 18px;
  border: 2.5px solid rgba(255, 255, 255, 0.28);
  border-top-color: #fff;
  border-radius: 50%;
  animation: spin 0.75s linear infinite;
  vertical-align: middle;
}
.secondary-btn.is-busy,
.primary-btn.is-busy {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  opacity: 0.95;
  cursor: wait;
}
.auth-gate {
  position: fixed;
  inset: 0;
  z-index: 999;
  background:
    radial-gradient(circle at 75% 15%, rgba(24, 95, 180, 0.2), transparent 35%),
    rgba(1, 10, 19, 0.94);
  backdrop-filter: blur(16px);
  display: none;
  align-items: center;
  justify-content: center;
  padding: 20px;
}
.auth-gate.show {
  display: flex;
}
.auth-card {
  width: min(440px, 96vw);
  border: 1px solid rgba(255, 255, 255, 0.11);
  background: linear-gradient(180deg, #0a2747, #05182c);
  border-radius: 24px;
  padding: 24px;
  box-shadow: 0 34px 100px rgba(0, 0, 0, 0.55);
}
.auth-brand {
  display: flex;
  align-items: center;
  gap: 13px;
  margin-bottom: 18px;
}
.auth-brand img {
  display: block;
  width: 176px;
  height: 176px;
  max-width: 100%;
  object-fit: contain;
  border-radius: 14px;
  background: transparent;
}
.auth-brand {
  justify-content: center;
}
.auth-card h2 {
  margin: 0 0 5px;
  font-size: 25px;
}
.auth-sub {
  color: #93a9bd;
  font-size: 12px;
  margin-bottom: 17px;
}
.auth-tabs {
  display: grid;
  grid-template-columns: 1fr 1fr;
  background: #04172b;
  border-radius: 11px;
  padding: 4px;
  margin-bottom: 15px;
}
.auth-tab {
  border: 0;
  background: transparent;
  color: #8fa5ba;
  height: 38px;
  border-radius: 8px;
  font-weight: 800;
  cursor: pointer;
}
.auth-tab.active {
  background: #0b6cf4;
  color: white;
}
.auth-field {
  margin: 10px 0;
}
.auth-field label {
  display: block;
  font-size: 10px;
  color: #91a7bb;
  margin: 0 0 5px;
}
.auth-field input {
  width: 100%;
  height: 44px;
  border-radius: 10px;
  border: 1px solid rgba(255, 255, 255, 0.11);
  background: #04172b;
  color: #fff;
  padding: 0 12px;
  outline: none;
}
.auth-field input:focus {
  border-color: #2b83ff;
}
.auth-submit {
  width: 100%;
  height: 48px;
  border: 0;
  border-radius: 11px;
  background: linear-gradient(90deg, #ff7a00, #ff9f2c);
  font-weight: 900;
  color: white;
  margin-top: 8px;
  cursor: pointer;
}
.auth-note {
  font-size: 10px;
  color: #7f97ad;
  line-height: 1.5;
  margin-top: 12px;
}
.auth-error {
  min-height: 18px;
  color: #ff8c8c;
  font-size: 11px;
  margin-top: 7px;
}
.profile-gate {
  position: fixed;
  inset: 0;
  z-index: 998;
  background: rgba(1, 9, 18, 0.72);
  backdrop-filter: blur(10px);
  display: none;
  align-items: center;
  justify-content: center;
  padding: 20px;
}
.profile-gate.show {
  display: flex;
}
.profile-card {
  width: min(520px, 96vw);
  border: 1px solid rgba(255, 255, 255, 0.11);
  background: linear-gradient(180deg, #0a2747, #05182c);
  border-radius: 22px;
  padding: 22px;
  box-shadow: 0 34px 100px rgba(0, 0, 0, 0.55);
}
.profile-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 14px;
}
.profile-head h2 {
  margin: 0;
  font-size: 24px;
}
.profile-close {
  width: 38px;
  height: 38px;
  border-radius: 10px;
  border: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.04);
  color: #fff;
  cursor: pointer;
}
.profile-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}
.profile-grid .auth-field {
  margin: 0;
}
.profile-grid .full {
  grid-column: 1/-1;
}
.profile-actions {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  margin-top: 16px;
}
.profile-save {
  min-width: 140px;
  height: 46px;
  border: 0;
  border-radius: 12px;
  background: linear-gradient(90deg, #0c6fff, #6b5cff);
  color: #fff;
  font-weight: 900;
  cursor: pointer;
}
@media (max-width: 620px) {
  .profile-grid {
    grid-template-columns: 1fr;
  }
  .profile-grid .full {
    grid-column: auto;
  }
}
.mobile-top {
  display: none;
}
@media (max-width: 1280px) {
  .workspace {
    grid-template-columns: minmax(0, 1fr) 320px;
  }
  .bubble-wrap {
    max-width: 90%;
  }
}

.project-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 16px;
  padding-top: 14px;
}
.project-card {
  border: 1px solid var(--line);
  background: linear-gradient(180deg, #0c2643, #07192c);
  border-radius: 18px;
  padding: 18px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  min-height: 180px;
}
.project-card h3 {
  margin: 0;
  font-size: 19px;
}
.project-card p {
  margin: 0;
  color: var(--muted);
  line-height: 1.45;
  min-height: 42px;
}
.project-meta {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  color: var(--muted);
  font-size: 12px;
}
.project-actions {
  display: flex;
  gap: 8px;
  margin-top: auto;
  flex-wrap: wrap;
}
.project-actions button {
  flex: 1;
  min-width: 84px;
}
.project-actions .danger-project {
  color: #ffb3b3;
  border-color: rgba(255, 95, 95, 0.35);
  background: rgba(110, 20, 20, 0.22);
}
.share-modal-card {
  width: min(560px, 92vw);
  background: #0a1d33;
  border: 1px solid rgba(255, 255, 255, 0.12);
  border-radius: 22px;
  padding: 20px;
  box-shadow: 0 28px 80px rgba(0, 0, 0, 0.45);
}
.share-modal-card h3 {
  margin: 0 0 6px;
  font-size: 22px;
}
.share-modal-card p {
  margin: 0 0 16px;
  color: var(--muted);
  line-height: 1.5;
}
.share-row {
  display: flex;
  gap: 10px;
  align-items: center;
  margin: 12px 0;
}
.share-row select,
.share-row input {
  flex: 1;
  background: #06172a;
  color: #fff;
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 12px;
}
.share-actions {
  display: flex;
  gap: 10px;
  justify-content: flex-end;
  margin-top: 16px;
  flex-wrap: wrap;
}
.lang-select {
  background: linear-gradient(135deg, #ff7a00, #ffad32) !important;
  color: #071421 !important;
  border: 1px solid #ffad32 !important;
  font-weight: 900 !important;
  box-shadow: 0 8px 22px rgba(255, 122, 0, 0.18);
}
.lang-select option {
  background: #fff;
  color: #111;
}
.project-toolbar {
  display: flex;
  gap: 10px;
  align-items: center;
  flex-wrap: wrap;
  margin: 10px 0 14px;
}
.recover-btn,
.trash-btn {
  border: 1px solid var(--line);
  background: #0b223c;
  color: #fff;
  border-radius: 12px;
  padding: 10px 14px;
  font-weight: 800;
  cursor: pointer;
}
.recover-btn:hover,
.trash-btn:hover {
  border-color: #ff9826;
}
.trash-panel {
  display: none;
  background: #091d33;
  border: 1px solid var(--line);
  border-radius: 18px;
  padding: 14px;
  margin: 10px 0 18px;
}
.trash-panel.show {
  display: block;
}
.trash-item {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  align-items: center;
  padding: 12px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.07);
}
.trash-item:last-child {
  border-bottom: 0;
}
.trash-actions {
  display: flex;
  gap: 8px;
}
.trash-actions button {
  padding: 8px 11px;
  border-radius: 10px;
  border: 1px solid var(--line);
  background: #0d2a49;
  color: #fff;
  font-weight: 800;
}
.project-context-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 14px;
  margin: 16px 0;
}
.project-context-card {
  background: #091d33;
  border: 1px solid var(--line);
  border-radius: 18px;
  padding: 16px;
}
.project-context-card h4 {
  margin: 0 0 8px;
  font-size: 17px;
}
.project-instructions {
  width: 100%;
  min-height: 120px;
  resize: vertical;
  background: #041425;
  color: #fff;
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 12px;
  font: inherit;
  box-sizing: border-box;
}
.project-context-actions {
  display: flex;
  gap: 8px;
  justify-content: flex-end;
  margin-top: 10px;
}
.project-files-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-top: 10px;
  max-height: 260px;
  overflow: auto;
}
.project-file-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 10px 11px;
  background: #071a2e;
  border: 1px solid rgba(255, 255, 255, 0.07);
  border-radius: 12px;
}
.project-file-main {
  min-width: 0;
}
.project-file-name {
  font-weight: 800;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.project-file-meta {
  font-size: 12px;
  color: var(--muted);
  margin-top: 3px;
}
.project-file-actions {
  display: flex;
  gap: 6px;
  flex-shrink: 0;
}
.project-file-actions button {
  border: 1px solid var(--line);
  background: #0d2a49;
  color: #fff;
  border-radius: 9px;
  padding: 7px 9px;
  font-weight: 800;
}
.project-file-actions .danger {
  color: #ffb1b1;
}
@media (max-width: 980px) {
  .project-context-grid {
    grid-template-columns: 1fr;
  }
  .project-context-card {
    padding: 13px;
  }
  .project-file-row {
    align-items: flex-start;
  }
  .project-file-actions {
    flex-direction: column;
  }
}
@media (max-width: 980px) {
  .project-toolbar {
    display: grid;
    grid-template-columns: 1fr 1fr;
  }
  .trash-item {
    align-items: flex-start;
  }
  .trash-actions {
    flex-direction: column;
  }
}
@media (max-width: 980px) {
  .project-actions {
    display: grid;
    grid-template-columns: 1fr 1fr;
  }
  .project-actions button {
    min-width: 0;
  }
  .share-row {
    flex-direction: column;
    align-items: stretch;
  }
  .share-actions > * {
    flex: 1;
  }
}
.project-active-bar {
  margin: 10px 0 6px;
  padding: 12px 14px;
  border: 1px solid rgba(69, 150, 255, 0.35);
  background: #0a2440;
  border-radius: 14px;
}
.project-chip {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 6px 10px;
  border-radius: 999px;
  background: #0d3157;
  border: 1px solid rgba(255, 255, 255, 0.12);
  font-size: 12px;
  font-weight: 800;
}
.project-detail {
  display: none;
  margin-top: 14px;
  border: 1px solid var(--line);
  background: linear-gradient(180deg, #0b223d, #07192c);
  border-radius: 20px;
  padding: 18px;
}
.project-detail.show {
  display: block;
}
.project-detail-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 14px;
}
.project-detail-head h3 {
  margin: 0;
  font-size: 22px;
}
.project-detail-head p {
  margin: 4px 0 0;
  color: var(--muted);
  font-size: 12px;
}
.project-chat-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.project-chat-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 12px 14px;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: #081c31;
  cursor: pointer;
}
.project-chat-row:hover {
  background: #0b2948;
  border-color: rgba(80, 145, 230, 0.35);
}
.project-chat-main {
  min-width: 0;
}
.project-chat-title {
  font-weight: 800;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.project-chat-meta {
  font-size: 11px;
  color: var(--muted);
  margin-top: 3px;
}
.project-chat-open {
  flex: 0 0 auto;
  border: 1px solid var(--line);
  background: #0d3157;
  color: #fff;
  border-radius: 10px;
  padding: 8px 12px;
  font-weight: 800;
  cursor: pointer;
}
.project-empty {
  padding: 18px;
  border: 1px dashed var(--line);
  border-radius: 14px;
  color: var(--muted);
  text-align: center;
}
@media (max-width: 980px) {
  .project-grid {
    grid-template-columns: 1fr;
  }
  .projects-page {
    padding: 14px !important;
  }
  .project-card {
    min-height: 150px;
  }
  .project-detail {
    padding: 14px;
  }
  .project-detail-head {
    flex-direction: column;
  }
  .project-detail-head .primary-btn {
    width: 100%;
  }
  .project-chat-row {
    padding: 12px;
  }
  .project-chat-open {
    padding: 8px 10px;
  }
}

@media (max-width: 980px) {
  .layout {
    grid-template-columns: 1fr;
  }
  .sidebar {
    display: none;
    position: fixed;
    inset: 0 auto 0 0;
    width: 280px;
    z-index: 70;
  }
  .sidebar.show {
    display: flex;
  }
  .workspace {
    grid-template-columns: 1fr;
  }
  .sidepanel {
    display: none;
  }
  .mobile-top {
    display: flex;
    align-items: center;
    gap: 10px;
  }
  .top-left h1 {
    font-size: 18px;
  }
  .top-left p {
    font-size: 12px;
  }
  .empty-state h2 {
    font-size: 30px;
  }
  .composer-box {
    grid-template-columns: 1fr;
  }
  .composer-actions {
    flex-direction: row;
  }
  .bubble-wrap {
    max-width: 100%;
  }
  .msg {
    gap: 8px;
  }
  .settings-grid {
    grid-template-columns: 1fr;
  }
  .creation-grid {
    grid-template-columns: 1fr 1fr;
  }
}
@media (max-width: 640px) {
  .topbar {
    padding: 12px;
  }
  .chat-stream {
    padding: 12px;
  }
  .composer {
    padding: 12px;
  }
  .creation-grid {
    grid-template-columns: 1fr;
  }
  .assistant-images {
    grid-template-columns: 1fr;
  }
  .userbox {
    max-width: 180px;
  }
  .user-meta span {
    max-width: 120px;
  }
}

/* V4.3.6 — Equal Height Template Cards */
.templates-page {
  max-width: none;
  width: 100%;
  box-sizing: border-box;
}
.template-strip {
  grid-auto-columns: minmax(230px, 260px);
  gap: 14px;
  padding-right: 8px;
}
.template-grid {
  grid-template-columns: repeat(auto-fill, minmax(230px, 1fr));
  gap: 14px;
}
.template-preview {
  height: auto !important;
  min-height: 0;
  aspect-ratio: 4/3;
  padding: 6px;
  background: #eef3f8;
}
.template-preview[data-ratio="wide"] {
  aspect-ratio: 16/10;
}
.template-preview[data-ratio="portrait"] {
  aspect-ratio: 4/5;
}
.template-preview[data-ratio="square"] {
  aspect-ratio: 1/1;
}
.template-preview img {
  width: 100%;
  height: 100%;
  object-fit: contain;
  border-radius: 10px;
}
.template-body {
  padding: 11px 12px 13px;
}
.template-section {
  margin-bottom: 20px;
}

@media (max-width: 980px) {
  .templates-page {
    padding: 14px 12px 20px !important;
  }
  .template-head {
    margin-bottom: 10px;
  }
  .template-head h2 {
    font-size: 24px;
  }
  .template-head p {
    font-size: 12px;
    line-height: 1.45;
  }
  .template-cats {
    gap: 7px;
    margin-bottom: 12px;
    padding: 8px 0;
    overflow-x: auto;
    flex-wrap: nowrap;
    scrollbar-width: none;
  }
  .template-cats::-webkit-scrollbar {
    display: none;
  }
  .template-cat {
    white-space: nowrap;
    padding: 8px 12px;
  }
  .template-section-head {
    margin-bottom: 9px;
  }
  .template-section-head h3 {
    font-size: 17px;
  }
  .template-section-head span {
    font-size: 11px;
  }
  .template-strip {
    grid-auto-columns: min(280px, 76vw);
    gap: 10px;
    padding-bottom: 8px;
    scroll-padding-left: 2px;
  }
  .template-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 10px;
  }
  .template-card {
    border-radius: 14px;
  }
  .template-preview {
    padding: 4px;
    aspect-ratio: 4/5;
  }
  .template-preview[data-ratio="wide"] {
    aspect-ratio: 16/10;
  }
  .template-preview[data-ratio="portrait"] {
    aspect-ratio: 4/5;
  }
  .template-preview[data-ratio="square"] {
    aspect-ratio: 1/1;
  }
  .template-real-badge {
    left: 7px;
    top: 7px;
    font-size: 8px;
    padding: 3px 6px;
  }
  .template-body {
    padding: 9px 10px 11px;
  }
  .template-body b {
    font-size: 12px;
    line-height: 1.25;
  }
  .template-body span {
    font-size: 10px;
    margin-top: 4px;
  }
  .template-badge {
    font-size: 9px !important;
    padding: 3px 6px;
    margin-top: 7px !important;
  }
  .template-hover {
    display: none;
  }
}

@media (max-width: 640px) {
  .topbar {
    padding: 10px 12px !important;
    gap: 8px;
    align-items: flex-start;
  }
  .top-left h1 {
    font-size: 18px !important;
    line-height: 1.15;
  }
  .top-left p {
    font-size: 10px !important;
    line-height: 1.35;
    max-width: 360px;
  }
  .top-actions {
    gap: 7px;
    flex-wrap: wrap;
    justify-content: flex-end;
  }
  .credits-pill {
    min-height: 40px;
  }
  .userbox {
    max-width: 170px;
  }
  .templates-page {
    padding: 10px 8px 18px !important;
  }
  .template-head {
    gap: 8px;
  }
  .template-head h2 {
    font-size: 22px;
  }
  .template-head p {
    display: none;
  }
  .template-search {
    height: 40px;
  }
  .template-cats {
    margin-left: -2px;
    margin-right: -2px;
  }
  .template-strip {
    grid-auto-columns: min(300px, 78vw);
    gap: 9px;
  }
  .template-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 8px;
  }
  .template-card {
    border-radius: 12px;
  }
  .template-preview {
    padding: 3px;
  }
  .template-body {
    padding: 8px 9px 10px;
  }
  .template-body b {
    font-size: 11px;
  }
  .template-body span {
    font-size: 9px;
  }
  .template-badge {
    display: none !important;
  }
  .template-section {
    margin-bottom: 16px;
  }
}

@media (max-width: 380px) {
  .template-grid {
    grid-template-columns: 1fr 1fr;
    gap: 6px;
  }
  .template-strip {
    grid-auto-columns: 82vw;
  }
  .template-body b {
    font-size: 10px;
  }
}

/* V4.4.2 — Native-ratio Template Cards */
.template-card {
  display: flex;
  flex-direction: column;
  height: 100%;
}
.template-preview {
  height: auto !important;
  min-height: 0 !important;
  max-height: none !important;
  flex: 0 0 auto !important;
  background: #081b30;
  padding: 4px;
}
.template-preview[data-ratio="wide"] {
  aspect-ratio: 16/10 !important;
}
.template-preview[data-ratio="portrait"] {
  aspect-ratio: 4/5 !important;
}
.template-preview[data-ratio="square"] {
  aspect-ratio: 1/1 !important;
}
.template-preview img {
  width: 100%;
  height: 100%;
  object-fit: contain;
  display: block;
  border-radius: 10px;
  background: #081b30;
}
.template-body {
  min-height: 92px;
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  box-sizing: border-box;
}
.template-body b {
  min-height: 30px;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}
.template-body > span:not(.template-badge) {
  min-height: 16px;
  display: -webkit-box;
  -webkit-line-clamp: 1;
  -webkit-box-orient: vertical;
  overflow: hidden;
}
.template-badge {
  margin-top: auto !important;
}
.template-strip {
  align-items: start;
}
.template-grid {
  align-items: start;
}
@media (max-width: 980px) {
  .template-strip {
    grid-auto-columns: min(320px, 82vw);
  }
  .template-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 10px;
  }
}
@media (max-width: 640px) {
  .template-strip {
    grid-auto-columns: min(330px, 84vw);
  }
  .template-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 8px;
  }
}

@media (max-width: 979px) {
  .sidebar {
    overflow-y: auto !important;
    max-height: 100dvh;
    padding-bottom: 28px;
  }
  .chat-history-panel {
    min-height: 96px !important;
    max-height: none !important;
    flex: 0 0 auto !important;
  }
  .chat-history-list {
    min-height: 48px !important;
    max-height: 220px !important;
    overflow-y: auto !important;
    flex: 0 0 auto !important;
  }
  .chat-history-item {
    min-height: 42px !important;
    display: grid !important;
  }
  .chat-history-title {
    font-size: 13px !important;
    padding: 9px 0 !important;
  }
  .chat-group-label {
    font-size: 10px !important;
    padding-top: 8px !important;
  }
}

/* V4.5 — Mobile Chat-first Experience */

.chat-history-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}
.chat-history-actions {
  display: flex;
  align-items: center;
  gap: 6px;
}
.chat-clear-all {
  border: 0;
  background: transparent;
  color: #ff9e9e;
  font-size: 12px;
  font-weight: 700;
  padding: 6px 8px;
  border-radius: 8px;
  cursor: pointer;
}
.chat-clear-all:hover {
  background: rgba(255, 100, 100, 0.1);
}
.chat-item-actions {
  display: flex;
  align-items: center;
  gap: 2px;
  flex: 0 0 auto;
}
.chat-delete {
  border: 0;
  background: transparent;
  color: #ff9e9e;
  font-size: 15px;
  line-height: 1;
  padding: 7px;
  border-radius: 8px;
  cursor: pointer;
}
.chat-delete:hover {
  background: rgba(255, 100, 100, 0.12);
}

.mobile-menu-close,
.mobile-menu-account {
  display: none;
}
@media (max-width: 980px) {
  html,
  body {
    height: 100%;
    overflow: hidden;
  }
  .layout {
    display: block;
    height: 100dvh;
    min-height: 100dvh;
  }
  .main {
    height: 100dvh;
    min-height: 100dvh;
    overflow: hidden;
  }
  .workspace {
    display: block;
    height: calc(100dvh - 58px);
    min-height: 0;
    overflow: hidden;
  }
  .page.chat-page.active {
    height: 100%;
    min-height: 0;
    display: flex;
    flex-direction: column;
    overflow: hidden;
  }
  .chat-stream {
    flex: 1 1 auto;
    min-height: 0;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    padding: 14px 12px 120px !important;
  }
  .composer {
    position: fixed !important;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 55;
    padding: 8px 10px calc(8px + env(safe-area-inset-bottom)) !important;
    background: rgba(3, 15, 27, 0.97);
    border-top: 1px solid rgba(255, 255, 255, 0.08);
    box-shadow: 0 -10px 28px rgba(0, 0, 0, 0.26);
  }
  .composer-box {
    display: grid !important;
    grid-template-columns: 42px minmax(0, 1fr) 46px !important;
    gap: 8px !important;
    align-items: end;
  }
  .textarea-wrap {
    grid-column: 2;
    padding: 7px 10px !important;
    border-radius: 18px !important;
  }
  #messageInput {
    min-height: 38px !important;
    max-height: 120px !important;
    height: 38px;
    font-size: 15px;
    line-height: 1.35;
    padding: 8px 0 !important;
  }
  .composer-actions {
    display: contents !important;
  }
  #generateBtn {
    display: none !important;
  }
  .composer-footer {
    position: absolute;
    left: 10px;
    bottom: calc(10px + env(safe-area-inset-bottom));
    margin: 0 !important;
    display: block !important;
    pointer-events: none;
  }
  .left-tools {
    display: block !important;
  }
  .left-tools .file-btn {
    pointer-events: auto;
    width: 42px;
    height: 42px;
    min-height: 42px;
    border-radius: 50%;
    display: flex !important;
    align-items: center;
    justify-content: center;
    font-size: 0;
    padding: 0 !important;
    background: #0b2139;
    border: 1px solid rgba(255, 255, 255, 0.12);
  }
  .left-tools .file-btn:after {
    content: "＋";
    font-size: 24px;
    color: white;
    line-height: 1;
  }
  #clearRefsBtn,
  #examplePromptBtn,
  .right-tools,
  .settings {
    display: none !important;
  }
  .attachment-list {
    margin: 0 46px 6px 50px;
    max-height: 68px;
    overflow-x: auto;
    overflow-y: hidden;
    display: flex;
    flex-wrap: nowrap;
  }

  .topbar {
    height: 58px;
    min-height: 58px;
    padding: 8px 10px !important;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
    background: #03111f;
    border-bottom: 1px solid rgba(255, 255, 255, 0.07);
    position: relative;
    z-index: 50;
  }
  .top-left {
    display: flex;
    align-items: center;
    gap: 8px;
    min-width: 0;
  }
  .mobile-top {
    display: flex !important;
  }
  #menuBtn {
    width: 40px;
    height: 40px;
    min-height: 40px !important;
    padding: 0 !important;
    border-radius: 12px !important;
    font-size: 20px;
  }
  .top-left h1 {
    display: block !important;
    font-size: 16px !important;
    white-space: nowrap;
    margin: 0;
  }
  .top-left p {
    display: none !important;
  }
  .top-right {
    display: flex;
    align-items: center;
    gap: 6px;
    margin-left: auto;
  }
  .lang-select {
    height: 36px;
    min-width: 54px;
    padding: 0 6px;
    font-size: 13px;
  }
  .chip {
    height: 36px;
    min-height: 36px;
    padding: 0 8px !important;
    gap: 5px;
  }
  .chip .coin {
    width: 20px;
    height: 20px;
  }
  .chip .plus {
    width: 24px;
    height: 24px;
    font-size: 18px;
  }
  #creditBalance {
    font-size: 13px;
    white-space: nowrap;
  }
  .userbox,
  #logoutBtn {
    display: none !important;
  }

  .sidebar {
    display: none !important;
    position: fixed !important;
    inset: 0 !important;
    width: 100vw !important;
    max-width: none !important;
    height: 100dvh !important;
    max-height: 100dvh !important;
    z-index: 100 !important;
    padding: 18px 16px calc(24px + env(safe-area-inset-bottom)) !important;
    background: #03111f !important;
    overflow-y: auto !important;
    gap: 12px !important;
  }
  .sidebar.show {
    display: flex !important;
  }
  .mobile-menu-close {
    display: flex;
    position: absolute;
    top: 14px;
    right: 14px;
    width: 42px;
    height: 42px;
    border-radius: 12px;
    border: 1px solid rgba(255, 255, 255, 0.12);
    background: #0b2139;
    color: white;
    align-items: center;
    justify-content: center;
    font-size: 22px;
    z-index: 3;
  }
  .brand {
    min-height: 64px;
    padding-right: 56px;
    display: flex;
    align-items: center;
  }
  .brand img {
    max-width: 190px !important;
    height: 68px !important;
    max-height: 68px !important;
    object-fit: cover;
  }
  .new-chat-btn {
    height: 50px !important;
    font-size: 17px !important;
    border-radius: 14px !important;
    margin-top: 2px;
  }
  .nav {
    gap: 7px !important;
  }
  .nav-btn {
    min-height: 48px !important;
    border-radius: 13px !important;
    font-size: 16px !important;
    padding: 0 14px !important;
    text-align: left;
  }
  .mobile-menu-account {
    display: flex;
    align-items: center;
    gap: 11px;
    padding: 12px 14px;
    border: 1px solid rgba(255, 255, 255, 0.1);
    border-radius: 14px;
    background: #081b30;
    margin-top: 2px;
    cursor: pointer;
  }
  .mobile-menu-account .avatar {
    width: 42px;
    height: 42px;
    flex: 0 0 42px;
  }
  .mobile-menu-account .user-meta {
    min-width: 0;
  }
  .mobile-menu-account .user-meta strong,
  .mobile-menu-account .user-meta span {
    display: block;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }
  .chat-history-panel {
    border-top: 1px solid rgba(255, 255, 255, 0.09);
    padding-top: 12px;
    margin-top: 2px;
    min-height: auto !important;
  }
  .chat-history-head {
    font-size: 14px !important;
    padding: 0 4px 8px !important;
  }
  .chat-history-list {
    max-height: none !important;
    min-height: 0 !important;
    overflow: visible !important;
  }
  .chat-history-item {
    min-height: 46px !important;
    border-radius: 12px !important;
    padding: 0 8px !important;
  }
  .chat-history-title {
    font-size: 14px !important;
  }
  .side-section {
    display: none !important;
  }

  .empty-state {
    padding: 18vh 18px 120px !important;
    max-width: 100% !important;
    margin: 0 auto;
    text-align: center;
  }
  .empty-state h2 {
    font-size: 27px !important;
    line-height: 1.1;
    margin-bottom: 10px;
  }
  .empty-state p {
    font-size: 14px;
    line-height: 1.45;
    max-width: 420px;
    margin: 0 auto 16px;
  }
  .empty-state .quick {
    display: none !important;
  }
  .bubble-wrap {
    max-width: 92% !important;
  }
  .assistant-images {
    grid-template-columns: 1fr !important;
  }
  .msg {
    padding: 7px 0 !important;
  }
  .msg .avatar {
    width: 30px;
    height: 30px;
    flex: 0 0 30px;
  }
  .bubble {
    font-size: 15px;
    line-height: 1.45;
    border-radius: 16px !important;
  }

  .page:not(.chat-page) {
    height: calc(100dvh - 58px);
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    padding-bottom: 30px;
  }
  .creation-grid {
    grid-template-columns: 1fr !important;
  }
  .templates-page {
    padding-bottom: 30px !important;
  }
}
@media (max-width: 420px) {
  .top-left h1 {
    font-size: 15px !important;
  }
  .lang-select {
    display: none !important;
  }
  #creditBalance {
    font-size: 12px;
  }
  .chip {
    padding: 0 6px !important;
  }
  .empty-state {
    padding-top: 15vh !important;
  }
}
