:root {
  --bg: #06101a;
  --panel: rgba(10, 18, 29, 0.88);
  --panel-edge: rgba(255, 255, 255, 0.08);
  --text: #f5f8ff;
  --muted: #98a6be;
  --brand: #ffb347;
  --brand-strong: #ff7d38;
  --cyan: #55d8ff;
  --success: #6ae1b3;
  --radius: 22px;
  --shadow: 0 24px 70px rgba(0, 0, 0, 0.38);
}

* { box-sizing: border-box; }
html, body { min-height: 100%; }
body {
  margin: 0;
  font-family: 'Montserrat', sans-serif;
  color: var(--text);
  background:
    radial-gradient(circle at top left, rgba(85, 216, 255, 0.12), transparent 25%),
    radial-gradient(circle at top right, rgba(255, 179, 71, 0.15), transparent 22%),
    linear-gradient(160deg, #05101a 0%, #081420 50%, #050b13 100%);
}

button, input, select, textarea { font: inherit; }
button { cursor: pointer; }
.hidden { display: none !important; }

.page-shell {
  width: min(1360px, calc(100vw - 16px));
  margin: 0 auto;
  padding: 8px 0 18px;
}

.auth-view {
  min-height: calc(100vh - 72px);
  display: grid;
  place-items: center;
}

.auth-card {
  width: min(520px, 100%);
  background: rgba(10, 19, 31, 0.9);
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: 28px;
  box-shadow: var(--shadow);
  padding: 34px;
}

.auth-brand { margin-bottom: 26px; }
.auth-logo {
  font-family: 'Pacifico', cursive;
  font-size: 40px;
  line-height: 1;
}
.auth-logo span { color: var(--brand); }
.auth-brand p, .auth-subtitle {
  color: var(--muted);
  line-height: 1.65;
}
.auth-form { display: grid; gap: 16px; }
.auth-title { font-size: 24px; font-weight: 800; }

.auth-form label, .form-grid label {
  display: grid;
  gap: 6px;
  font-size: 12px;
  color: var(--muted);
}

input, select, textarea {
  width: 100%;
  border: 1px solid rgba(255, 255, 255, 0.1);
  border-radius: 12px;
  padding: 9px 12px;
  background: rgba(255, 255, 255, 0.04);
  color: var(--text);
  outline: none;
  transition: border-color 0.18s ease, background 0.18s ease;
}
select {
  color-scheme: dark;
}
select option,
select optgroup {
  color: var(--text);
  background: #101925;
}
input:focus, select:focus, textarea:focus {
  border-color: rgba(255, 179, 71, 0.9);
  background: rgba(255, 255, 255, 0.07);
}
textarea { resize: vertical; min-height: 74px; }

.primary-btn, .ghost-btn, .network-chip {
  border-radius: 12px;
  border: 1px solid transparent;
  padding: 10px 14px;
  font-weight: 700;
  transition: transform 0.16s ease, border-color 0.16s ease, background 0.16s ease, color 0.16s ease;
}
.primary-btn:hover, .ghost-btn:hover, .network-chip:hover { transform: translateY(-1px); }
.primary-btn {
  color: #08101b;
  background: linear-gradient(135deg, var(--brand), var(--brand-strong));
}
.ghost-btn {
  color: var(--text);
  background: rgba(255, 255, 255, 0.04);
  border-color: rgba(255, 255, 255, 0.1);
}
.small {
  padding: 8px 11px;
  border-radius: 11px;
  font-size: 12px;
}

.status-line {
  min-height: 16px;
  font-size: 11px;
  line-height: 1.35;
  color: var(--muted);
}

.topbar {
  display: flex;
  justify-content: space-between;
  gap: 14px;
  margin-bottom: 10px;
  padding: 2px;
}
.eyebrow, .panel-kicker, .hero-label {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.18em;
  color: rgba(255, 255, 255, 0.55);
}
.topbar h1 {
  margin: 6px 0 8px;
  font-size: clamp(24px, 2.6vw, 32px);
  line-height: 1.08;
}
.topbar-subtitle {
  max-width: 720px;
  margin: 0;
  color: var(--muted);
  line-height: 1.55;
  font-size: 13px;
}
.topbar-actions {
  min-width: 220px;
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 10px;
}
.badge-row {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 10px;
}
.provider-badge {
  padding: 9px 12px;
  border-radius: 999px;
  font-size: 11px;
  font-weight: 700;
  border: 1px solid rgba(255, 255, 255, 0.1);
  background: rgba(255, 255, 255, 0.04);
}
.provider-badge.ok {
  color: var(--success);
  border-color: rgba(106, 225, 179, 0.35);
}
.provider-badge.warn {
  color: var(--brand);
  border-color: rgba(255, 179, 71, 0.35);
}

.hero-grid {
  display: none;
}
.hero-card, .panel {
  background: var(--panel);
  border: 1px solid var(--panel-edge);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}
.hero-card { padding: 16px 18px; }
.hero-card.compact { display: none; }
.hero-card h2 {
  margin: 6px 0 8px;
  font-size: 22px;
}
.hero-card p {
  margin: 0;
  line-height: 1.55;
  color: var(--muted);
  font-size: 14px;
}
.hero-list {
  margin: 12px 0 0;
  padding-left: 18px;
  color: var(--muted);
  line-height: 1.9;
}

.app-tabs {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-bottom: 8px;
}

.app-tab {
  padding: 8px 12px;
  border-radius: 999px;
  border: 1px solid rgba(255, 255, 255, 0.08);
  background: rgba(255, 255, 255, 0.04);
  color: var(--muted);
  font-weight: 700;
  font-size: 12px;
  white-space: nowrap;
  transition: transform 0.16s ease, border-color 0.16s ease, background 0.16s ease, color 0.16s ease;
}

.app-tab:hover {
  transform: translateY(-1px);
  color: var(--text);
}

.app-tab.active {
  color: #08101b;
  border-color: transparent;
  background: linear-gradient(135deg, var(--brand), var(--brand-strong));
}

.workspace {
  display: grid;
  gap: 10px;
  align-items: start;
}

.workspace.view-card {
  grid-template-columns: minmax(0, 1fr) 360px;
}

.workspace.view-text {
  grid-template-columns: minmax(0, 1fr);
}

.workspace.view-compose {
  grid-template-columns: minmax(0, 1fr) 360px;
}

.workspace-left, .workspace-right { display: grid; gap: 10px; min-width: 0; }
.panel { padding: 10px 12px; overflow: hidden; }
.sticky-panel { position: sticky; top: 10px; }
.builder-subgrid {
  display: grid;
  grid-template-columns: minmax(0, 1.15fr) minmax(0, 0.85fr);
  gap: 10px;
}
.compact-card-panel {
  height: 100%;
}
.builder-subgrid .images-grid {
  grid-template-columns: repeat(2, minmax(0, 1fr));
}

.workspace.view-card .pane-text:not(.pane-card),
.workspace.view-card .pane-compose:not(.pane-card) {
  display: none;
}

.workspace.view-text .pane-card:not(.pane-text),
.workspace.view-text .pane-compose:not(.pane-text) {
  display: none;
}

.workspace.view-text .workspace-right {
  display: none;
}

.workspace.view-compose .pane-card:not(.pane-compose),
.workspace.view-compose .pane-text:not(.pane-compose) {
  display: none;
}

.workspace.view-card .workspace-left {
  gap: 10px;
}

.panel-head {
  display: flex;
  justify-content: space-between;
  gap: 8px;
  align-items: flex-start;
  margin-bottom: 8px;
  flex-wrap: wrap;
}
.panel-actions {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  justify-content: flex-end;
}
.panel-head h3 {
  margin: 2px 0 0;
  font-size: 16px;
  line-height: 1.12;
}

.context-area { min-height: 60px; }
.import-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 8px;
  margin-bottom: 8px;
}
.field-hint {
  margin-top: 4px;
  font-size: 11px;
  line-height: 1.3;
  color: var(--muted);
}
.form-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
}
.form-grid .full { grid-column: 1 / -1; }
.card-form-grid { grid-template-columns: repeat(6, minmax(0, 1fr)); }
.card-form-grid .span-1 { grid-column: span 1; }
.card-form-grid .span-2 { grid-column: span 2; }
.card-form-grid .span-3 { grid-column: span 3; }
.brand-form-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }

.toggle-field {
  display: flex !important;
  flex-direction: row;
  align-items: center;
  gap: 8px;
  color: var(--text);
  font-weight: 600;
}
.toggle-field input {
  width: 18px;
  height: 18px;
  padding: 0;
}
.logo-field input[type='file'] { padding: 10px 12px; }
.logo-preview {
  min-height: 48px;
  display: grid;
  place-items: center;
  border: 1px dashed rgba(255, 255, 255, 0.12);
  border-radius: 14px;
  background: rgba(255, 255, 255, 0.03);
  overflow: hidden;
  color: var(--muted);
  text-align: center;
  padding: 10px;
}
.logo-preview img {
  max-width: 100%;
  max-height: 130px;
  display: block;
}

.logo-library {
  display: grid;
  gap: 8px;
}

.logo-library-empty {
  padding: 10px 12px;
  border-radius: 12px;
  border: 1px dashed rgba(255, 255, 255, 0.08);
  color: var(--muted);
  font-size: 11px;
  line-height: 1.35;
}

.logo-library-item {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 8px;
  align-items: center;
  padding: 8px;
  border-radius: 14px;
  border: 1px solid rgba(255, 255, 255, 0.08);
  background: rgba(255, 255, 255, 0.03);
}

.logo-library-item.active {
  border-color: rgba(255, 179, 71, 0.45);
  background: rgba(255, 179, 71, 0.08);
}

.logo-library-select {
  display: grid;
  grid-template-columns: 58px minmax(0, 1fr);
  gap: 10px;
  align-items: center;
  text-align: left;
  width: 100%;
  padding: 0;
  border: 0;
  background: transparent;
  color: inherit;
}

.logo-library-thumb {
  display: grid;
  place-items: center;
  min-height: 48px;
  border-radius: 12px;
  padding: 6px;
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid rgba(255, 255, 255, 0.08);
}

.logo-library-thumb img {
  max-width: 100%;
  max-height: 44px;
  display: block;
}

.logo-library-meta strong,
.logo-library-meta span {
  display: block;
}

.logo-library-meta strong {
  font-size: 12px;
  color: var(--text);
}

.logo-library-meta span {
  margin-top: 3px;
  font-size: 11px;
  line-height: 1.3;
  color: var(--muted);
}

.inline-search { margin-bottom: 8px; }
.images-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 8px;
}
.image-option {
  border-radius: 16px;
  overflow: hidden;
  border: 2px solid transparent;
  background: rgba(255, 255, 255, 0.03);
  transition: transform 0.16s ease, border-color 0.16s ease;
}
.image-option:hover { transform: translateY(-2px); }
.image-option.active { border-color: var(--brand); }
.image-option img {
  width: 100%;
  aspect-ratio: 16 / 10;
  object-fit: cover;
  display: block;
}
.image-caption {
  padding: 6px 8px 8px;
  font-size: 11px;
  line-height: 1.3;
  color: var(--muted);
}

.network-toolbar {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 12px;
}
.network-chip {
  background: rgba(255, 255, 255, 0.04);
  color: var(--muted);
  border-color: rgba(255, 255, 255, 0.08);
}
.network-chip.active {
  color: #08101b;
  background: linear-gradient(135deg, var(--cyan), #7de8ff);
  border-color: transparent;
}

.copy-panels {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
}
.copy-card {
  border-radius: 16px;
  border: 1px solid rgba(255, 255, 255, 0.08);
  padding: 12px;
  background: rgba(255, 255, 255, 0.03);
}
.copy-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 8px;
  font-weight: 700;
}

.format-switcher {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-bottom: 8px;
}
.format-btn {
  padding: 7px 10px;
  border-radius: 999px;
  border: 1px solid rgba(255, 255, 255, 0.08);
  background: rgba(255, 255, 255, 0.04);
  color: var(--muted);
  font-weight: 700;
  font-size: 12px;
}
.format-btn.active {
  background: linear-gradient(135deg, rgba(255, 179, 71, 0.24), rgba(85, 216, 255, 0.18));
  border-color: rgba(255, 179, 71, 0.45);
  color: var(--text);
}

.preview-frame {
  padding: 8px;
  border-radius: 16px;
  background: linear-gradient(180deg, rgba(255, 255, 255, 0.04), rgba(255, 255, 255, 0.02));
  border: 1px solid rgba(255, 255, 255, 0.08);
}
#cardCanvas {
  width: 100%;
  max-height: min(56vh, 430px);
  height: auto;
  border-radius: 16px;
  display: block;
  background: #111827;
}
.preview-actions {
  display: grid;
  gap: 6px;
  margin-top: 8px;
}

.history-list {
  display: grid;
  gap: 10px;
}
.history-item {
  padding: 12px;
  border-radius: 16px;
  border: 1px solid rgba(255, 255, 255, 0.08);
  background: rgba(255, 255, 255, 0.03);
}
.history-item h4 {
  margin: 0 0 8px;
  font-size: 16px;
}
.history-item p {
  margin: 0 0 12px;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.65;
}
.history-actions { display: flex; gap: 10px; }
.utility-panel .history-list {
  max-height: 220px;
  overflow: auto;
  padding-right: 4px;
}

.toast {
  position: fixed;
  left: 50%;
  bottom: 28px;
  transform: translateX(-50%) translateY(120%);
  padding: 13px 18px;
  border-radius: 999px;
  background: rgba(6, 16, 26, 0.96);
  border: 1px solid rgba(255, 255, 255, 0.08);
  color: var(--text);
  font-size: 13px;
  font-weight: 700;
  transition: transform 0.25s ease;
  z-index: 9999;
}
.toast.show { transform: translateX(-50%) translateY(0); }

@media (max-width: 1180px) {
  .workspace,
  .workspace.view-card,
  .workspace.view-compose,
  .workspace.view-text {
    grid-template-columns: 1fr;
  }
  .sticky-panel { position: static; }
  .topbar { flex-direction: column; }
  .topbar-actions { align-items: flex-start; }
  .badge-row { justify-content: flex-start; }
  .builder-subgrid { grid-template-columns: 1fr; }
  .panel-actions { width: 100%; justify-content: flex-start; }
  .card-form-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .card-form-grid .span-1,
  .card-form-grid .span-2,
  .card-form-grid .span-3 { grid-column: span 2; }
  .images-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}

@media (max-width: 720px) {
  .page-shell {
    width: min(100vw - 16px, 100%);
    padding-top: 8px;
  }
  .auth-card, .hero-card, .panel { padding: 16px; }
  .form-grid { grid-template-columns: 1fr; }
  .card-form-grid, .brand-form-grid { grid-template-columns: 1fr; }
  .card-form-grid .span-1,
  .card-form-grid .span-2,
  .card-form-grid .span-3 { grid-column: auto; }
  .import-row { grid-template-columns: 1fr; }
  .images-grid { grid-template-columns: 1fr; }
  .copy-panels { grid-template-columns: 1fr; }
  .app-tabs { gap: 8px; }
  .app-tab { width: 100%; }
}
