:root {
  color-scheme: light;
  --bg: #eef2f4;
  --ink: #12161d;
  --muted: #66717f;
  --line: #d8e0e5;
  --surface: #ffffff;
  --surface-soft: #f6f8f9;
  --accent: #0f8f7a;
  --accent-strong: #0b6f61;
  --blue: #2d68d8;
  --red: #c24343;
  --shadow: 0 24px 70px rgba(34, 48, 64, 0.13);
  font-family: Inter, "Noto Sans SC", system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  min-height: 100vh;
  color: var(--ink);
  background:
    linear-gradient(135deg, rgba(15, 143, 122, 0.08), transparent 34%),
    linear-gradient(315deg, rgba(45, 104, 216, 0.08), transparent 36%),
    var(--bg);
}

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

button, select, input, textarea {
  border: 1px solid var(--line);
}

button {
  cursor: pointer;
}

button:focus:not(:focus-visible),
a:focus:not(:focus-visible),
input:focus:not(:focus-visible),
textarea:focus:not(:focus-visible),
select:focus:not(:focus-visible) {
  outline: none;
}

button:focus-visible,
a:focus-visible,
input:focus-visible,
textarea:focus-visible,
select:focus-visible {
  outline: 3px solid rgba(15, 143, 122, 0.24);
  outline-offset: 2px;
}

button:hover,
.icon-button:hover,
.package-card:hover,
.profile-entry:hover {
  border-color: rgba(15, 143, 122, 0.38);
  transform: translateY(-1px);
}

button,
.icon-button,
.package-card,
.profile-entry,
.result-card {
  transition: border-color 160ms ease, box-shadow 160ms ease, transform 160ms ease, background 160ms ease;
}

.link-button {
  padding: 0;
  color: var(--accent);
  border: 0;
  background: transparent;
  font-size: 12px;
  font-weight: 800;
}

.app-shell {
  display: grid;
  grid-template-columns: 276px minmax(0, 1fr);
  min-height: 100vh;
}

.sidebar {
  display: flex;
  flex-direction: column;
  gap: 28px;
  padding: 28px 20px;
  border-right: 1px solid rgba(18, 22, 29, 0.08);
  background: rgba(255, 255, 255, 0.74);
  backdrop-filter: blur(18px);
}

.brand {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 8px;
}

.brand-mark {
  display: grid;
  place-items: center;
  width: 46px;
  height: 46px;
  border-radius: 8px;
  background: transparent;
  overflow: visible;
}

.brand-mark img {
  width: 100%;
  height: 100%;
  object-fit: contain;
}

.brand h1, .topbar h2, .rail-header h3 {
  margin: 0;
}

.brand h1 {
  font-size: 19px;
  letter-spacing: 0;
}

.brand span, .eyebrow, .result-meta {
  color: var(--muted);
  font-size: 12px;
}

.module-nav {
  display: grid;
  gap: 8px;
}

.account-panel {
  margin-top: auto;
}

.account-card {
  display: grid;
  gap: 12px;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.74);
}

.account-card.signed-in {
  gap: 0;
  padding: 6px;
  border-color: transparent;
  background: transparent;
}

.account-head[hidden],
.guest-actions[hidden],
.profile-entry[hidden],
.account-card.signed-in .account-head,
.account-card.signed-in .guest-actions {
  display: none !important;
}

.profile-entry {
  display: grid;
  grid-template-columns: 42px minmax(0, 1fr);
  align-items: center;
  gap: 10px;
  width: 100%;
  padding: 8px;
  text-align: left;
  border-radius: 8px;
  background: var(--surface);
}

.account-card.signed-in .profile-entry {
  padding: 6px;
  border-color: transparent;
  background: rgba(255, 255, 255, 0.72);
}

.profile-entry span:last-child {
  display: grid;
  gap: 2px;
  min-width: 0;
}

.profile-entry strong,
.profile-entry small {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.avatar {
  display: inline-grid;
  place-items: center;
  width: 42px;
  height: 42px;
  overflow: hidden;
  color: white;
  border: 0;
  border-radius: 50%;
  background: #12161d;
  font-weight: 900;
}

.avatar img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.modal-backdrop {
  position: fixed;
  inset: 0;
  z-index: 45;
  display: grid;
  place-items: center;
  padding: 24px;
  background: rgba(18, 22, 29, 0.58);
  backdrop-filter: blur(10px);
}

.modal-backdrop[hidden] {
  display: none;
}

.modal-card {
  position: relative;
  display: grid;
  gap: 16px;
  width: min(560px, 100%);
  max-height: calc(100vh - 48px);
  padding: 22px;
  overflow: auto;
  border-radius: 8px;
  background: var(--surface);
  box-shadow: var(--shadow);
}

.modal-card h3,
.modal-card p {
  margin: 0;
}

.modal-close {
  position: absolute;
  top: 14px;
  right: 14px;
}

.profile-header {
  display: flex;
  align-items: center;
  gap: 14px;
  padding-right: 48px;
}

#profile-public-id {
  margin-top: 4px;
  color: var(--accent-strong);
  font-size: 12px;
  font-weight: 800;
}

.avatar-large {
  width: 70px;
  height: 70px;
  font-size: 24px;
}

.profile-form,
.balance-account {
  display: grid;
  gap: 10px;
}

.profile-form label {
  display: grid;
  gap: 8px;
  font-size: 13px;
  font-weight: 800;
}

.profile-form button,
.balance-account button,
.ledger-entry-button,
.logout-wide {
  min-height: 38px;
  border-radius: 8px;
  background: var(--surface-soft);
  font-weight: 800;
}

.ledger-entry-button {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: center;
  gap: 10px;
  width: 100%;
  padding: 12px;
  text-align: left;
}

.ledger-entry-button span {
  color: var(--ink);
}

.ledger-entry-button strong {
  color: var(--accent-strong);
  font-size: 12px;
  text-align: right;
}

.admin-entry-button {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: center;
  gap: 10px;
  width: 100%;
  min-height: 38px;
  padding: 12px;
  border-radius: 8px;
  background: #12161d;
  color: white;
  text-align: left;
  font-weight: 800;
}

.admin-entry-button[hidden] {
  display: none;
}

.admin-entry-button strong {
  color: rgba(255, 255, 255, 0.72);
  font-size: 12px;
  text-align: right;
}

.recharge-orders button[data-order-id] {
  display: none;
}

.admin-modal-card {
  width: min(820px, calc(100vw - 28px));
}

.admin-section {
  display: grid;
  gap: 10px;
}

.admin-section h4 {
  margin: 0;
  font-size: 14px;
}

.admin-list {
  display: grid;
  gap: 8px;
  max-height: min(34vh, 320px);
  overflow: auto;
  padding-right: 4px;
}

.admin-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto auto;
  align-items: center;
  gap: 12px;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface-soft);
}

.admin-log-row {
  grid-template-columns: minmax(0, 1fr);
}

.admin-user-row {
  grid-template-columns: minmax(0, 1fr) minmax(90px, 120px) minmax(120px, 1fr) auto;
}

.admin-user-search {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 8px;
}

.admin-user-search input,
.admin-user-row input {
  min-height: 36px;
}

.admin-row strong,
.admin-row span {
  display: block;
}

.admin-row strong {
  margin-bottom: 4px;
  color: var(--ink);
  font-size: 13px;
}

.admin-row span {
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
}

.admin-row b {
  color: var(--accent-strong);
  font-size: 12px;
  white-space: nowrap;
}

.admin-row button {
  min-height: 32px;
  padding: 0 12px;
  border-radius: 8px;
  background: #12161d;
  color: white;
  font-weight: 800;
}

.card-generator,
.card-redeem-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr) minmax(0, 1.2fr) auto;
  gap: 8px;
}

.card-redeem-row {
  grid-template-columns: minmax(0, 1fr) auto;
}

.card-generator input,
.card-redeem-row input {
  min-height: 38px;
}

.card-generator button {
  min-height: 38px;
  padding: 0 14px;
  border-radius: 8px;
  background: #12161d;
  color: white;
  font-weight: 800;
}

.card-output {
  min-height: 96px;
  resize: vertical;
  font-family: ui-monospace, SFMono-Regular, Consolas, monospace;
  font-size: 12px;
  line-height: 1.5;
}

.card-redeem-card {
  display: grid;
  gap: 12px;
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface-soft);
}

.card-redeem-card h4,
.card-redeem-card p {
  margin: 0;
}

.card-redeem-card h4 {
  font-size: 15px;
}

.card-redeem-card p {
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
}

.card-buy-link {
  display: inline-grid;
  min-height: 38px;
  width: fit-content;
  align-items: center;
  padding: 0 14px;
  border-radius: 8px;
  background: #12161d;
  color: white;
  font-size: 13px;
  font-weight: 800;
  text-decoration: none;
}

@media (max-width: 720px) {
  .card-generator,
  .card-redeem-row {
    grid-template-columns: 1fr;
  }

  .admin-user-row,
  .admin-user-search {
    grid-template-columns: 1fr;
  }
}

.ledger-modal-card {
  width: min(720px, calc(100vw - 28px));
}

.ledger-modal-head {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: start;
  gap: 16px;
  padding-right: 48px;
}

.ledger-modal-head h3 {
  margin: 0 0 4px;
}

.ledger-modal-head p {
  margin: 0;
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
}

.ledger-modal-head > strong {
  padding: 8px 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  color: var(--accent-strong);
  background: var(--surface-soft);
  white-space: nowrap;
}

.ledger-list {
  display: grid;
  gap: 8px;
  max-height: min(58vh, 560px);
  overflow: auto;
  padding-right: 4px;
}

.ledger-item {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: center;
  gap: 14px;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface-soft);
}

.ledger-item strong,
.ledger-item span {
  display: block;
}

.ledger-item strong {
  margin-bottom: 4px;
  color: var(--ink);
  font-size: 13px;
}

.ledger-item span {
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
}

.ledger-item b {
  color: #b42318;
  font-size: 13px;
  white-space: nowrap;
}

.ledger-item.income b {
  color: var(--accent-strong);
}

.ledger-empty {
  padding: 18px;
  border: 1px dashed var(--line);
  border-radius: 8px;
  color: var(--muted);
  text-align: center;
  font-size: 13px;
  font-weight: 800;
}

.usage-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 10px;
}

.usage-grid div,
.balance-account {
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface-soft);
}

.usage-grid span,
.balance-account span {
  display: block;
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
}

.usage-grid strong,
.balance-account strong {
  display: block;
  margin-top: 4px;
  font-size: 20px;
}

.profile-ledger {
  max-height: 180px;
}

.recharge-channel,
.package-grid {
  display: grid;
  gap: 10px;
}

.recharge-channel {
  grid-template-columns: 1fr 1fr;
}

.recharge-channel button,
.package-card,
.order-row button {
  min-height: 38px;
  border-radius: 8px;
  background: var(--surface-soft);
  font-weight: 800;
}

.recharge-channel button.active {
  color: white;
  border-color: #12161d;
  background: #12161d;
}

.package-grid {
  grid-template-columns: repeat(2, minmax(0, 1fr));
}

.package-card {
  display: grid;
  gap: 4px;
  padding: 12px;
  text-align: left;
  color: inherit;
  text-decoration: none;
}

.package-card.selected {
  border-color: var(--accent-strong);
  background: rgba(15, 143, 122, 0.08);
}

.package-card:not(.disabled):hover {
  border-color: var(--accent-strong);
  background: rgba(15, 143, 122, 0.08);
}

.package-card.disabled {
  cursor: not-allowed;
  opacity: 0.5;
}

.payment-confirm-card {
  display: grid;
  gap: 12px;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface-soft);
}

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

.payment-confirm-card h4,
.payment-confirm-card p {
  margin: 0;
}

.payment-confirm-card h4 {
  font-size: 15px;
}

.payment-confirm-card p {
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
  line-height: 1.55;
}

.payment-note-field,
.payment-proof-field,
.payment-paid-check {
  display: grid;
  gap: 8px;
  font-size: 12px;
  font-weight: 800;
}

.payment-note-field input,
.payment-proof-field input {
  height: 36px;
}

.payment-proof-field small {
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
}

.payment-paid-check {
  grid-template-columns: auto minmax(0, 1fr);
  align-items: center;
}

.payment-paid-check input {
  width: 16px;
  height: 16px;
}

.action-button:disabled {
  cursor: not-allowed;
  opacity: 0.48;
}

.payment-proof-link {
  color: var(--brand);
  font-size: 12px;
  font-weight: 800;
  text-decoration: none;
}

.payment-confirm-card img {
  width: min(260px, 100%);
  aspect-ratio: 1 / 1;
  justify-self: center;
  object-fit: cover;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: white;
}

.package-card strong {
  font-size: 18px;
}

.package-card span,
.package-card small,
.modal-note,
.recharge-orders {
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
}

.recharge-orders {
  display: grid;
  gap: 8px;
}

.pricing-card {
  display: grid;
  gap: 10px;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface-soft);
}

.pricing-head,
.pricing-row {
  display: grid;
  grid-template-columns: minmax(76px, 0.8fr) minmax(120px, 1.4fr) minmax(94px, auto);
  align-items: center;
  gap: 10px;
}

.pricing-head {
  grid-template-columns: minmax(0, 1fr) auto;
}

.pricing-head h3 {
  margin: 0;
  font-size: 15px;
}

.pricing-head span,
.pricing-note,
.pricing-row span {
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
}

.pricing-table {
  display: grid;
  gap: 0;
  overflow: hidden;
  border: 1px solid rgba(18, 22, 29, 0.08);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.74);
}

.pricing-row {
  min-height: 36px;
  padding: 8px 10px;
  border-top: 1px solid rgba(18, 22, 29, 0.08);
}

.pricing-row:first-child {
  border-top: 0;
}

.pricing-row-head {
  background: rgba(18, 22, 29, 0.04);
}

.pricing-row strong {
  justify-self: end;
  color: var(--accent-strong);
  font-size: 12px;
  text-align: right;
}

.pricing-note {
  margin: 0;
  line-height: 1.55;
}

.recharge-pricing-card {
  margin-top: 10px;
}

.order-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: center;
  gap: 8px;
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface-soft);
}

.order-row button {
  grid-column: 1 / -1;
}

.account-head,
.account-session,
.auth-actions,
.guest-actions {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.account-head span,
.account-session span,
.credit-ledger {
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
}

.account-head strong,
.account-session strong {
  font-size: 13px;
}

.auth-form {
  display: grid;
  gap: 8px;
}

.auth-form input {
  width: 100%;
  height: 36px;
  border-radius: 8px;
  background: var(--surface);
}

.form-error {
  margin: 0;
  color: #c2410c;
  font-size: 12px;
  font-weight: 800;
}

.auth-actions button,
.guest-actions button,
.account-session button {
  min-height: 34px;
  padding: 0 12px;
  border-radius: 8px;
  background: var(--surface);
  font-size: 12px;
  font-weight: 800;
}

.auth-actions button[type="submit"] {
  color: white;
  border-color: #12161d;
  background: #12161d;
}

.guest-actions button:first-child {
  color: white;
  border-color: #12161d;
  background: #12161d;
}

.guest-actions button {
  flex: 1;
}

.credit-ledger {
  display: grid;
  gap: 6px;
  max-height: 130px;
  overflow: auto;
}

.ledger-row {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 6px;
  padding-top: 6px;
  border-top: 1px solid rgba(18, 22, 29, 0.08);
}

.ledger-row strong {
  color: var(--accent-strong);
}

.nav-item {
  display: flex;
  align-items: center;
  gap: 12px;
  width: 100%;
  min-height: 46px;
  padding: 0 14px;
  color: #344150;
  border-color: transparent;
  border-radius: 8px;
  background: transparent;
  font-weight: 650;
}

.nav-item svg, .icon-button svg, .action-button svg {
  width: 18px;
  height: 18px;
}

.nav-item.active {
  color: white;
  background: #12161d;
  box-shadow: 0 14px 30px rgba(18, 22, 29, 0.18);
}

.workspace {
  display: flex;
  flex-direction: column;
  min-width: 0;
  height: 100vh;
  padding: 26px;
  overflow: hidden;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  min-height: 72px;
  gap: 18px;
}

.eyebrow {
  margin: 0 0 7px;
  font-weight: 700;
  text-transform: uppercase;
}

.topbar h2 {
  font-size: 30px;
  letter-spacing: 0;
}

.status-cluster {
  display: inline-flex;
  align-items: center;
  gap: 9px;
  height: 38px;
  padding: 0 13px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.68);
  color: var(--muted);
  font-size: 13px;
}

.status-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: #d29d2d;
}

.status-dot.ready { background: var(--accent); }
.status-dot.error { background: var(--red); }

.panel-grid {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 360px;
  gap: 22px;
  flex: 1;
  min-height: 0;
  overflow: hidden;
}

.panel-grid.chat-only {
  grid-template-columns: minmax(0, 1fr) 360px;
}

.panel-grid.chat-only .result-rail {
  display: flex;
}

.creator-surface, .result-rail {
  height: 100%;
  min-height: 0;
  border: 1px solid rgba(18, 22, 29, 0.08);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.86);
  box-shadow: var(--shadow);
  overflow: hidden;
}

.panel {
  display: none;
  height: 100%;
  min-height: 0;
  padding: 22px;
}

.panel.active {
  display: flex;
  flex-direction: column;
}

.chat-history-bar {
  flex: 0 0 auto;
  display: none;
  grid-template-columns: minmax(150px, 1fr) 40px 40px minmax(150px, 1fr) 40px 40px;
  align-items: end;
  gap: 8px;
  margin-bottom: 14px;
}

.chat-history-bar label {
  display: grid;
  gap: 6px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
}

.chat-window {
  flex: 1;
  min-height: 0;
  overflow: auto;
  padding: 2px 4px 18px;
}

.message {
  display: grid;
  gap: 6px;
  max-width: 82%;
  margin: 0 0 16px;
}

.message.user {
  margin-left: auto;
}

.message .bubble {
  padding: 14px 16px;
  border-radius: 8px;
  white-space: normal;
  line-height: 1.65;
}

.message-text {
  white-space: pre-wrap;
}

.message-attachment {
  display: block;
  width: min(280px, 100%);
  max-height: 220px;
  object-fit: cover;
  border-radius: 8px;
  margin-bottom: 10px;
  border: 1px solid rgba(255, 255, 255, 0.24);
}

.message.assistant .message-attachment {
  border-color: var(--line);
}

.message-image-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(108px, 1fr));
  gap: 8px;
  width: min(520px, 100%);
  margin-bottom: 10px;
}

.message-image-grid figure {
  position: relative;
  margin: 0;
}

.message-image-grid figure span {
  position: absolute;
  top: 6px;
  left: 6px;
  z-index: 1;
  display: inline-grid;
  place-items: center;
  width: 22px;
  height: 22px;
  color: white;
  border-radius: 999px;
  background: rgba(18, 22, 29, 0.78);
  font-size: 12px;
  font-weight: 900;
}

.message-image-grid .message-attachment {
  width: 100%;
  height: 108px;
  margin-bottom: 0;
}

.message-document {
  display: grid;
  grid-template-columns: 22px minmax(0, 1fr) auto;
  align-items: center;
  gap: 8px;
  margin-bottom: 10px;
  padding: 10px;
  color: inherit;
  border: 1px solid rgba(255, 255, 255, 0.18);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.1);
}

.message.assistant .message-document {
  border-color: var(--line);
  background: var(--surface);
}

.message-document svg {
  width: 18px;
  height: 18px;
}

.message-document span {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-weight: 800;
}

.message-document small {
  color: inherit;
  opacity: 0.72;
}

.message.assistant .bubble {
  background: var(--surface-soft);
  border: 1px solid var(--line);
}

.message.user .bubble {
  color: white;
  background: #12161d;
}

.message small {
  color: var(--muted);
  font-size: 12px;
}

.message.user small { text-align: right; }

.composer {
  flex: 0 0 auto;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  overflow: hidden;
}

textarea, input, select {
  width: 100%;
  color: var(--ink);
  border-radius: 8px;
  background: #fbfcfd;
  outline: none;
}

textarea:focus, input:focus, select:focus {
  border-color: rgba(15, 143, 122, 0.6);
  box-shadow: 0 0 0 3px rgba(15, 143, 122, 0.12);
}

.composer textarea {
  display: block;
  min-height: 96px;
  padding: 16px;
  border: 0;
  resize: vertical;
  background: transparent;
}

.attachment-preview {
  padding: 0 12px 12px;
}

.reference-block .attachment-preview {
  max-height: 236px;
  overflow-y: auto;
  padding: 8px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.7);
}

.reference-preview-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 8px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
}

.reference-preview-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
  gap: 8px;
}

.attachment-chip {
  display: inline-grid;
  grid-template-columns: 58px minmax(0, 1fr) 32px;
  align-items: center;
  gap: 10px;
  max-width: min(440px, 100%);
  padding: 8px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface-soft);
}

.attachment-chip img {
  width: 58px;
  height: 46px;
  object-fit: cover;
  border-radius: 6px;
  background: #101317;
}

.attachment-chip span {
  min-width: 0;
  overflow: hidden;
  color: #344150;
  font-size: 13px;
  font-weight: 700;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.attachment-chip span small {
  display: block;
  margin-top: 2px;
  color: var(--muted);
  font-size: 11px;
  font-weight: 700;
}

.upload-progress {
  display: block;
  width: 100%;
  height: 6px;
  margin-top: 7px;
  overflow: hidden;
  border-radius: 999px;
  background: rgba(18, 22, 29, 0.08);
}

.upload-progress span {
  display: block;
  min-width: 0;
  height: 100%;
  overflow: visible;
  border-radius: inherit;
  background: linear-gradient(90deg, var(--accent), var(--blue));
  transition: width 180ms ease;
  text-overflow: clip;
  white-space: normal;
}

.document-chip {
  grid-template-columns: 42px minmax(0, 1fr) 32px;
}

.document-icon {
  display: inline-grid;
  place-items: center;
  width: 42px;
  height: 42px;
  color: var(--accent-strong);
  border-radius: 8px;
  background: rgba(15, 143, 122, 0.1);
}

.document-icon svg {
  width: 19px;
  height: 19px;
}

.reference-chip {
  grid-template-columns: 28px 58px minmax(0, 1fr) 32px;
  max-width: 100%;
}

.attachment-chip .reference-index {
  display: inline-grid;
  place-items: center;
  width: 24px;
  height: 24px;
  color: white;
  border-radius: 999px;
  background: #12161d;
  font-size: 12px;
  font-weight: 900;
}

.attachment-remove {
  width: 32px;
  height: 32px;
  border-radius: 8px;
}

.composer-actions {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  padding: 12px;
  border-top: 1px solid var(--line);
}

.attachment-actions {
  display: flex;
  align-items: center;
  gap: 8px;
}

.inline-controls, .control-grid {
  display: flex;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
}

.inline-controls label, .control-grid label {
  display: grid;
  gap: 7px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
}

.inline-controls input[type="range"] {
  width: 138px;
  accent-color: var(--accent);
}

select, input {
  height: 40px;
  padding: 0 12px;
}

.icon-button {
  display: inline-grid;
  place-items: center;
  flex: 0 0 auto;
  width: 40px;
  height: 40px;
  color: #344150;
  border-radius: 8px;
  border: 1px solid var(--line);
  background: var(--surface);
  text-decoration: none;
}

.icon-button.primary, .action-button {
  color: white;
  border-color: #12161d;
  background: #12161d;
}

.creation-form {
  display: flex;
  flex-direction: column;
  gap: 20px;
  max-width: 820px;
}

.field-block {
  display: grid;
  gap: 10px;
}

.field-block label {
  font-size: 14px;
  font-weight: 800;
}

.field-block textarea {
  min-height: 210px;
  padding: 16px;
  resize: vertical;
}

.reference-block {
  display: grid;
  grid-template-columns: auto 40px minmax(0, 1fr);
  align-items: center;
  gap: 12px;
  padding: 12px;
  border: 1px solid rgba(18, 22, 29, 0.08);
  border-radius: 8px;
  background: rgba(246, 248, 249, 0.78);
}

.reference-block > span {
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
}

.reference-actions {
  display: flex;
  align-items: center;
}

.control-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(160px, 1fr));
}

.tool-switch {
  display: inline-grid;
  grid-template-columns: repeat(2, minmax(110px, 1fr));
  width: min(340px, 100%);
  padding: 4px;
  gap: 4px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface-soft);
}

.tool-switch button {
  min-height: 36px;
  border: 0;
  border-radius: 6px;
  color: var(--muted);
  background: transparent;
  font-weight: 800;
}

.tool-switch button.active {
  color: #12161d;
  background: var(--surface);
  box-shadow: 0 8px 18px rgba(34, 48, 64, 0.08);
}

[data-music-section][hidden] {
  display: none;
}

.video-extra-grid {
  grid-template-columns: minmax(260px, 1fr) minmax(150px, auto) minmax(150px, auto);
}

.single-reference-grid {
  grid-template-columns: minmax(180px, 320px);
}

.checkbox-line {
  grid-template-columns: 18px auto;
  align-items: center;
  height: 40px;
  padding-top: 18px;
}

.checkbox-line input {
  width: 18px;
  height: 18px;
  accent-color: var(--accent);
}

.inline-field-action {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 40px;
  gap: 8px;
  align-items: center;
}

.range-field {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 52px;
  gap: 10px;
  align-items: center;
  min-height: 40px;
}

.range-field input[type="range"] {
  width: 100%;
  accent-color: var(--accent);
}

.range-field output {
  color: #26313d;
  font-size: 12px;
  font-weight: 900;
  text-align: right;
}

.action-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  min-height: 48px;
  width: min(220px, 100%);
  border-radius: 8px;
  font-weight: 800;
}

.result-rail {
  display: flex;
  flex-direction: column;
  min-width: 0;
  min-height: 0;
  background: rgba(250, 252, 253, 0.9);
}

.rail-header {
  flex: 0 0 auto;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  padding: 20px;
  border-bottom: 1px solid var(--line);
}

.result-list {
  display: grid;
  gap: 12px;
  align-content: start;
  flex: 1;
  min-height: 0;
  padding: 16px;
  overflow: auto;
}

.empty-state {
  display: grid;
  place-items: center;
  align-content: center;
  gap: 8px;
  min-height: 260px;
  padding: 24px;
  color: var(--muted);
  text-align: center;
  border: 1px dashed var(--line);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.62);
}

.empty-state svg {
  width: 28px;
  height: 28px;
  color: var(--accent);
}

.empty-state strong {
  color: var(--ink);
  font-size: 14px;
}

.empty-state span {
  max-width: 220px;
  font-size: 12px;
  line-height: 1.55;
}

.result-summary {
  position: sticky;
  top: -16px;
  z-index: 1;
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 6px;
  padding: 8px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(250, 252, 253, 0.94);
  backdrop-filter: blur(10px);
}

.result-summary span {
  display: grid;
  place-items: center;
  min-height: 28px;
  padding: 0 6px;
  color: var(--muted);
  border-radius: 6px;
  background: var(--surface);
  font-size: 12px;
  font-weight: 800;
  white-space: nowrap;
}

.result-card {
  display: grid;
  gap: 12px;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
}

.result-card:hover {
  border-color: rgba(15, 143, 122, 0.28);
  box-shadow: 0 16px 36px rgba(34, 48, 64, 0.1);
}

.result-card.status-queued,
.result-card.status-submitting,
.result-card.status-processing {
  border-color: rgba(45, 104, 216, 0.32);
  background: linear-gradient(0deg, rgba(45, 104, 216, 0.05), rgba(45, 104, 216, 0.05)), var(--surface);
}

.result-card.status-failed {
  border-color: rgba(194, 65, 12, 0.34);
  background: linear-gradient(0deg, rgba(194, 65, 12, 0.06), rgba(194, 65, 12, 0.06)), var(--surface);
}

.result-meta {
  display: flex;
  justify-content: space-between;
  gap: 10px;
}

.result-type {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  color: var(--accent-strong);
  font-weight: 800;
}

.result-status-dot {
  width: 7px;
  height: 7px;
  border-radius: 999px;
  background: var(--accent);
}

.status-queued .result-status-dot,
.status-submitting .result-status-dot,
.status-processing .result-status-dot {
  background: var(--blue);
  box-shadow: 0 0 0 4px rgba(45, 104, 216, 0.12);
}

.status-failed .result-status-dot {
  background: var(--red);
  box-shadow: 0 0 0 4px rgba(194, 67, 67, 0.12);
}

.result-preview {
  display: grid;
  min-height: 84px;
  color: #2b3440;
  line-height: 1.55;
  overflow-wrap: anywhere;
}

.result-preview img, .result-preview video {
  width: 100%;
  border-radius: 8px;
  background: #101317;
}

.result-preview img {
  cursor: zoom-in;
}

.result-preview audio {
  width: 100%;
}

.audio-preview {
  display: grid;
  gap: 10px;
}

.audio-preview img {
  width: 100%;
  aspect-ratio: 16 / 9;
  object-fit: cover;
  cursor: default;
}

.audio-asset-switcher {
  display: grid;
  grid-template-columns: 40px minmax(0, 1fr) 40px;
  align-items: center;
  gap: 8px;
  padding: 8px;
  border: 1px solid rgba(18, 22, 29, 0.08);
  border-radius: 8px;
  background: var(--surface-soft);
}

.audio-asset-info {
  display: grid;
  min-width: 0;
  gap: 2px;
  text-align: center;
}

.audio-asset-info strong,
.audio-asset-info em,
.audio-asset-info span {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.audio-asset-info strong {
  color: #26313d;
  font-size: 13px;
}

.audio-asset-info span {
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
}

.audio-asset-info em {
  color: var(--muted);
  font-size: 12px;
  font-style: normal;
}

.audio-asset-meta {
  padding: 8px 10px;
  border-radius: 8px;
  color: var(--muted);
  background: var(--surface-soft);
  font-size: 12px;
  font-weight: 800;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.result-preview pre {
  max-height: 240px;
  overflow: auto;
  margin: 0;
  padding: 12px;
  border-radius: 8px;
  background: #f2f5f7;
  white-space: pre-wrap;
  font-size: 12px;
}

.result-detail {
  display: grid;
  gap: 6px;
  padding: 10px;
  color: var(--muted);
  border: 1px solid rgba(18, 22, 29, 0.08);
  border-radius: 8px;
  background: var(--surface-soft);
  font-size: 12px;
  line-height: 1.45;
}

.result-detail span {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.result-detail strong {
  color: #344150;
}

.result-actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
}

.chat-history-list {
  display: grid;
  gap: 10px;
}

.chat-history-card {
  display: grid;
  gap: 8px;
  padding: 12px;
  text-align: left;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
}

.chat-history-card.active {
  border-color: rgba(15, 143, 122, 0.46);
  background: linear-gradient(0deg, rgba(15, 143, 122, 0.07), rgba(15, 143, 122, 0.07)), var(--surface);
}

.chat-history-main {
  display: grid;
  gap: 4px;
  min-width: 0;
  padding: 0;
  text-align: left;
  border: 0;
  background: transparent;
}

.chat-history-main strong,
.chat-history-main span {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.chat-history-main strong {
  color: var(--ink);
  font-size: 13px;
}

.chat-history-main span,
.chat-history-card time {
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
}

.chat-history-actions {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
}

.chat-history-actions div {
  display: flex;
  gap: 6px;
}

.chat-history-actions .icon-button {
  width: 34px;
  height: 34px;
}

.image-lightbox {
  position: fixed;
  inset: 0;
  z-index: 50;
  display: grid;
  place-items: center;
  padding: 72px 24px 24px;
  background: rgba(18, 22, 29, 0.86);
  backdrop-filter: blur(10px);
}

.image-lightbox[hidden] {
  display: none;
}

.lightbox-content {
  display: grid;
  grid-template-columns: minmax(0, auto) 260px;
  align-items: center;
  gap: 16px;
  max-width: min(1420px, 96vw);
  width: fit-content;
}

.image-lightbox img {
  max-width: min(1040px, calc(96vw - 300px));
  max-height: 84vh;
  object-fit: contain;
  border-radius: 8px;
  box-shadow: 0 24px 80px rgba(0, 0, 0, 0.38);
}

.lightbox-info {
  align-self: stretch;
  display: flex;
  flex-direction: column;
  justify-content: center;
  min-width: 0;
  max-height: 84vh;
  padding: 16px;
  overflow: auto;
  color: white;
  border: 1px solid rgba(255, 255, 255, 0.14);
  border-radius: 8px;
  background: rgba(18, 22, 29, 0.74);
  box-shadow: 0 24px 80px rgba(0, 0, 0, 0.24);
}

.lightbox-info h3 {
  margin: 0 0 14px;
  font-size: 15px;
}

.lightbox-info dl {
  display: grid;
  gap: 10px;
  margin: 0;
}

.lightbox-info dl div {
  display: grid;
  gap: 4px;
  padding-bottom: 10px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.1);
}

.lightbox-info dl div:last-child {
  padding-bottom: 0;
  border-bottom: 0;
}

.lightbox-info dt {
  color: rgba(255, 255, 255, 0.56);
  font-size: 12px;
  font-weight: 800;
}

.lightbox-info dd {
  margin: 0;
  overflow-wrap: anywhere;
  font-size: 13px;
  font-weight: 800;
}

.lightbox-close,
.lightbox-download {
  position: fixed;
  top: 22px;
  color: white;
  border-color: rgba(255, 255, 255, 0.18);
  background: rgba(255, 255, 255, 0.14);
}

.lightbox-close {
  right: 22px;
}

.lightbox-download {
  right: 72px;
}

.loading {
  opacity: 0.72;
  pointer-events: none;
}

@media (max-width: 1120px) {
  .app-shell {
    grid-template-columns: 88px minmax(0, 1fr);
  }

  .brand div:not(.brand-mark), .nav-item span {
    display: none;
  }

  .brand { justify-content: center; }
  .nav-item { justify-content: center; padding: 0; }
  .workspace { overflow: auto; }
  .panel-grid { grid-template-columns: 1fr; overflow: visible; }
  .panel-grid.chat-only { grid-template-columns: 1fr; }
  .creator-surface { height: calc(100vh - 124px); min-height: 520px; }
  .result-rail { height: 520px; max-height: 520px; }
}

@media (max-width: 720px) {
  .app-shell {
    display: block;
    min-height: 100vh;
  }

  .sidebar {
    position: sticky;
    top: 0;
    z-index: 5;
    flex-direction: row;
    align-items: center;
    gap: 10px;
    padding: 10px;
    overflow-x: auto;
  }

  .brand {
    flex: 0 0 auto;
    padding: 0;
  }

  .brand-mark {
    width: 40px;
    height: 40px;
  }

  .module-nav {
    flex: 1;
    min-width: 0;
    grid-auto-flow: column;
    grid-auto-columns: minmax(44px, 1fr);
    overflow-x: auto;
  }

  .nav-item {
    flex-direction: column;
    gap: 2px;
    min-height: 40px;
    font-size: 11px;
  }

  .nav-item span {
    display: block;
    max-width: 42px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }

  .account-panel {
    flex: 0 0 auto;
    width: auto;
    min-width: 108px;
    margin-top: 0;
  }

  .account-card,
  .account-card.signed-in {
    padding: 0;
    border: 0;
    background: transparent;
  }

  .guest-actions {
    display: grid;
    grid-template-columns: repeat(2, minmax(48px, 1fr));
    gap: 6px;
  }

  .guest-actions button {
    min-height: 34px;
    padding: 0 8px;
    font-size: 12px;
    white-space: nowrap;
  }

  .profile-entry,
  .account-card.signed-in .profile-entry {
    grid-template-columns: 40px;
    gap: 0;
    padding: 0;
    background: transparent;
  }

  .profile-entry span:last-child {
    display: none;
  }

  .workspace {
    height: auto;
    min-height: calc(100dvh - 60px);
    padding: 12px;
    overflow: visible;
  }

  .topbar {
    align-items: flex-start;
    flex-direction: column;
    min-height: auto;
    margin-bottom: 16px;
  }

  .topbar h2 {
    font-size: 24px;
  }

  .panel {
    padding: 14px;
  }

  .panel-grid {
    gap: 12px;
    min-height: auto;
  }

  .creator-surface {
    height: auto;
    min-height: calc(100dvh - 138px);
    overflow: visible;
  }

  .result-rail {
    height: auto;
    max-height: none;
  }

  .panel-grid.chat-only .result-rail {
    margin-top: 12px;
    max-height: 380px;
  }

  #chat-panel {
    min-height: calc(100dvh - 138px);
  }

  .chat-history-bar {
    grid-template-columns: minmax(0, 1fr) 38px 38px;
    gap: 6px;
    margin-bottom: 10px;
  }

  .chat-history-bar label,
  .chat-history-bar select {
    min-width: 0;
  }

  .chat-history-bar .icon-button {
    width: 38px;
    height: 38px;
  }

  .chat-window {
    min-height: 300px;
    padding-bottom: 12px;
  }

  .control-grid {
    grid-template-columns: 1fr;
  }

  .reference-block {
    grid-template-columns: 1fr 40px;
  }

  .reference-block .attachment-preview {
    grid-column: 1 / -1;
  }

  .composer-actions {
    display: grid;
    grid-template-columns: 1fr;
    align-items: stretch;
    gap: 10px;
  }

  .attachment-actions {
    justify-content: space-between;
  }

  .composer textarea {
    min-height: 86px;
    max-height: 34dvh;
  }

  .rail-header {
    padding: 14px;
  }

  .result-list {
    padding: 12px;
  }

  .message {
    max-width: 100%;
  }

  .usage-grid {
    grid-template-columns: 1fr 1fr;
  }

  .result-summary {
    position: static;
    grid-template-columns: 1fr 1fr;
  }

  .result-detail span {
    white-space: normal;
  }

  .image-lightbox {
    padding: 72px 14px 14px;
    overflow: auto;
    place-items: start center;
  }

  .lightbox-content {
    grid-template-columns: 1fr;
    width: 100%;
  }

  .image-lightbox img {
    width: 100%;
    max-width: 100%;
    max-height: 62vh;
  }

  .lightbox-info {
    width: 100%;
    max-height: none;
  }
}
