:root {
  --mint-50: #effaf6;
  --mint-100: #d7f2e9;
  --mint-300: #7fe1c9;
  --mint-500: #28c5a5;
  --mint-600: #17a98d;
  --teal-700: #0f7b6a;
  --teal-900: #172f2a;
  --lime-100: #dff2cf;
  --yellow-100: #fff1bd;
  --yellow-700: #8d6800;
  --canvas: #dfecea;
  --surface: #f7fbf9;
  --panel: rgba(255, 255, 255, 0.9);
  --line: #dbe8e3;
  --muted: #728681;
  --text: #213b36;
  --card-shadow: 0 10px 28px rgba(28, 63, 55, 0.07);
  --card-shadow-hover: 0 22px 52px rgba(28, 63, 55, 0.14);
  --radius-sm: 8px;
  --radius-md: 14px;
  --radius-lg: 30px;
  --font: "Inter", system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  --mono: "JetBrains Mono", "SFMono-Regular", Consolas, monospace;
}

* { box-sizing: border-box; }

body {
  min-width: 320px;
  margin: 0;
  color: var(--text);
  font-family: var(--font);
  font-size: 14px;
  line-height: 1.5;
  background:
    linear-gradient(90deg, rgba(15, 123, 106, 0.08) 1px, transparent 1px),
    linear-gradient(rgba(15, 123, 106, 0.06) 1px, transparent 1px),
    linear-gradient(135deg, #edf7f2, var(--canvas));
  background-size: 34px 34px, 34px 34px, auto;
}

button, input, select, textarea { font: inherit; }
button { cursor: pointer; }
a { color: inherit; text-decoration: none; }
h1, h2, h3, p { margin: 0; }
h1 { font-size: clamp(30px, 4vw, 44px); line-height: 1; letter-spacing: 0; }
h2 { font-size: 24px; line-height: 1.05; letter-spacing: 0; }
h3 { font-size: 15px; line-height: 1.25; letter-spacing: 0; }
svg {
  width: 18px;
  height: 18px;
  fill: none;
  stroke: currentColor;
  stroke-linecap: round;
  stroke-linejoin: round;
  stroke-width: 1.9;
}

.sidebar-toggle {
  position: fixed;
  width: 1px;
  height: 1px;
  opacity: 0;
  pointer-events: none;
}

.app-shell {
  display: grid;
  grid-template-columns: 248px minmax(0, 1fr);
  align-items: start;
  width: min(1280px, calc(100% - 48px));
  min-height: calc(100vh - 48px);
  margin: 24px auto;
  border: 1px solid rgba(255, 255, 255, 0.74);
  border-radius: var(--radius-lg);
  background: rgba(246, 250, 248, 0.86);
  box-shadow: 0 22px 70px rgba(28, 63, 55, 0.09);
  backdrop-filter: blur(18px);
}

.sidebar {
  position: sticky;
  top: 24px;
  display: flex;
  flex-direction: column;
  gap: 26px;
  height: calc(100vh - 48px);
  padding: 28px 18px;
  border-right: 1px solid rgba(219, 232, 227, 0.78);
  border-radius: 30px 0 0 30px;
  background: rgba(239, 250, 246, 0.74);
}

.brand, .nav-item, .system-card, .badge, .button-row, .topbar, .topbar-actions, .panel-title, .result-actions {
  display: flex;
  align-items: center;
}

.brand {
  gap: 10px;
  padding: 0 8px;
  color: var(--teal-700);
  font-weight: 800;
}

.brand-mark, .avatar, .ai-mark {
  display: grid;
  place-items: center;
  color: #fff;
  font-weight: 800;
  background: linear-gradient(145deg, var(--mint-500), var(--teal-700));
}

.brand-mark { width: 28px; height: 28px; border-radius: var(--radius-sm); }
.avatar { width: 32px; height: 32px; border-radius: 50%; font-size: 11px; }
.ai-mark { width: 42px; height: 42px; border-radius: 12px; font-family: var(--mono); }

.collapse-btn {
  position: absolute;
  top: 50%;
  right: 14px;
  display: grid;
  width: 34px;
  height: 34px;
  place-items: center;
  border: 1px solid var(--line);
  border-radius: 999px;
  color: var(--teal-700);
  background: rgba(255, 255, 255, 0.94);
  box-shadow: 0 10px 24px rgba(28, 63, 55, 0.08);
  transform: translateY(-50%);
  z-index: 3;
}

.menu-icon { display: none; }

.nav-list {
  display: grid;
  gap: 7px;
}

.nav-item {
  gap: 10px;
  min-height: 40px;
  padding: 0 12px;
  border: 1px solid transparent;
  border-radius: var(--radius-sm);
  color: #5e766f;
  font-size: 13px;
  font-weight: 700;
}

.nav-item:hover { color: var(--teal-700); border-color: var(--line); background: var(--panel); }
.nav-item.active { color: #fff; background: var(--mint-500); }

.system-card {
  gap: 10px;
  width: 100%;
  margin-top: auto;
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: var(--radius-md);
  background: var(--panel);
}
.system-card strong { display: block; font-size: 12px; }
.system-card p { color: var(--muted); font-size: 11px; font-weight: 700; }

.status-dot, .badge i {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--mint-500);
  box-shadow: 0 0 0 4px rgba(40, 197, 165, 0.14);
}

.page {
  min-width: 0;
  padding: 28px;
}

.topbar {
  justify-content: space-between;
  gap: 22px;
  margin-bottom: 24px;
}

.topbar-actions {
  gap: 10px;
  flex-wrap: wrap;
  justify-content: flex-end;
}

.eyebrow {
  color: var(--mint-600);
  font-size: 12px;
  font-weight: 800;
  letter-spacing: 0;
  text-transform: uppercase;
}

.user-pill {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  min-height: 40px;
  padding: 4px 10px 4px 4px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--panel);
  font-size: 12px;
  font-weight: 700;
}

.generator-grid {
  display: grid;
  grid-template-columns: minmax(0, 0.92fr) minmax(360px, 1.08fr);
  gap: 14px;
  min-width: 0;
}

.panel {
  min-width: 0;
  border: 1px solid rgba(219, 232, 227, 0.9);
  border-radius: var(--radius-md);
  background:
    radial-gradient(circle at var(--card-glow-x, 50%) var(--card-glow-y, 0%), rgba(127, 225, 201, 0.14), transparent 42%),
    var(--panel);
  backdrop-filter: blur(14px);
  box-shadow: var(--card-shadow);
  padding: 16px;
  transform: perspective(900px) translate3d(0, 0, 0);
  transition: border-color 180ms ease, box-shadow 220ms ease, transform 220ms ease;
}
.panel:hover {
  border-color: rgba(40, 197, 165, 0.62);
  box-shadow: var(--card-shadow-hover);
  transform: perspective(900px) translate3d(0, -4px, 12px);
}

.panel-title {
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 14px;
}

.form-card, .field {
  display: grid;
  gap: 14px;
}

.field { gap: 7px; }
.field span {
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
}

.field textarea {
  width: 100%;
  min-height: 228px;
  resize: vertical;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  outline: 0;
  padding: 12px;
  color: var(--text);
  background: var(--surface);
}
.field textarea:focus {
  border-color: var(--mint-500);
  box-shadow: 0 0 0 3px rgba(40, 197, 165, 0.15);
}

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

.ratio-card {
  display: grid;
  gap: 3px;
  min-height: 72px;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  background: #fff;
  cursor: pointer;
}
.ratio-card input { position: absolute; opacity: 0; }
.ratio-card strong { font-family: var(--mono); font-size: 15px; }
.ratio-card span { color: var(--muted); font-size: 11px; font-weight: 800; }
.ratio-card.selected {
  color: #fff;
  border-color: transparent;
  background: linear-gradient(145deg, var(--mint-500), var(--teal-700));
}
.ratio-card.selected span { color: rgba(255,255,255,0.82); }

.button-row, .result-actions {
  gap: 8px;
  flex-wrap: wrap;
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 42px;
  padding: 0 16px;
  border: 1px solid transparent;
  border-radius: var(--radius-sm);
  font-weight: 800;
  transition: border-color 160ms ease, background 160ms ease, color 160ms ease, transform 160ms ease;
}
.btn:hover { transform: translateY(-2px); }
.btn-primary { color: #fff; background: var(--mint-500); }
.btn-primary:hover { background: var(--mint-600); }
.btn-secondary { color: var(--teal-700); border-color: var(--mint-100); background: var(--mint-50); }
.btn-secondary:hover { border-color: var(--mint-300); background: #fff; }
.btn-ghost { color: var(--muted); border-color: var(--line); background: #fff; }
.btn-ghost:hover { color: var(--teal-700); border-color: var(--mint-300); }
.btn.disabled {
  opacity: 0.45;
  pointer-events: none;
}
.generate-btn { min-width: 190px; }

.badge {
  gap: 7px;
  min-height: 26px;
  padding: 0 9px;
  border-radius: 999px;
  font-size: 11px;
  font-weight: 800;
  white-space: nowrap;
}
#statusBadge {
  justify-content: flex-start;
  max-width: 100%;
  height: auto;
  min-height: 26px;
  padding-block: 5px;
  white-space: normal;
  overflow-wrap: anywhere;
}
.badge-success { color: var(--teal-700); background: var(--mint-100); }
.badge-warning { color: var(--yellow-700); background: var(--yellow-100); }
.badge-soft { color: var(--teal-700); background: var(--lime-100); }
.badge-dark { color: #fff; background: var(--teal-900); }
.badge-warning i {
  background: #d89b00;
  box-shadow: 0 0 0 4px rgba(216, 155, 0, 0.13);
}

.result-panel {
  display: grid;
  gap: 14px;
  align-content: start;
}

.preview-frame {
  display: grid;
  place-items: center;
  width: 100%;
  min-height: 520px;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  background:
    linear-gradient(45deg, rgba(15, 123, 106, 0.06) 25%, transparent 25%),
    linear-gradient(-45deg, rgba(15, 123, 106, 0.06) 25%, transparent 25%),
    var(--surface);
  background-size: 24px 24px;
}

.empty-state {
  display: grid;
  justify-items: center;
  gap: 10px;
  max-width: 320px;
  padding: 22px;
  text-align: center;
}
.empty-state p { color: var(--muted); font-size: 12px; font-weight: 700; }

#resultImage {
  display: block;
  width: 100%;
  height: 100%;
  max-height: 620px;
  object-fit: contain;
}

.meta-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 10px;
}
.meta-grid div {
  display: grid;
  gap: 4px;
  min-height: 70px;
  padding: 12px;
  border-radius: var(--radius-sm);
  background: var(--mint-50);
}
.meta-grid span {
  color: var(--muted);
  font-size: 11px;
  font-weight: 800;
}
.meta-grid strong {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-family: var(--mono);
  font-size: 12px;
}

.is-loading .generate-btn {
  opacity: 0.8;
  pointer-events: none;
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { transition: none !important; }
  .panel, .panel:hover, .btn:hover { transform: none !important; }
}

@media (max-width: 1180px) {
  .app-shell { grid-template-columns: 1fr; }
  .sidebar {
    position: static;
    height: auto;
    border-right: 0;
    border-bottom: 1px solid var(--line);
    border-radius: 30px 30px 0 0;
  }
  .collapse-btn, .system-card { display: none; }
  .nav-list { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .generator-grid { grid-template-columns: 1fr; }
  .preview-frame { min-height: 440px; }
}

@media (max-width: 760px) {
  .app-shell {
    width: 100%;
    min-height: 100vh;
    margin: 0;
    border-radius: 0;
  }
  .page, .sidebar { padding: 18px; }
  .sidebar {
    position: sticky;
    top: 0;
    z-index: 10;
    border-radius: 0;
    gap: 0;
    background: rgba(239, 250, 246, 0.96);
  }
  .collapse-btn {
    position: fixed;
    top: 14px;
    right: 14px;
    display: grid;
    width: 48px;
    height: 48px;
    border-radius: 10px;
    transform: none;
  }
  .collapse-icon { display: none; }
  .menu-icon { display: block; }
  .brand { min-height: 48px; padding-right: 58px; }
  .nav-list {
    position: fixed;
    top: 72px;
    right: 14px;
    left: 14px;
    z-index: 29;
    grid-template-columns: 1fr;
    max-height: min(62vh, 430px);
    overflow-y: auto;
    padding: 12px;
    border: 1px solid var(--line);
    border-radius: var(--radius-md);
    background: rgba(239, 250, 246, 0.98);
    box-shadow: 0 18px 46px rgba(28, 63, 55, 0.12);
    opacity: 0;
    transform: translateY(-8px);
    pointer-events: none;
  }
  .sidebar-toggle:checked ~ .app-shell .nav-list {
    opacity: 1;
    transform: translateY(0);
    pointer-events: auto;
  }
  .topbar { align-items: flex-start; flex-direction: column; }
  .topbar-actions { width: 100%; justify-content: flex-start; }
  .generator-grid { grid-template-columns: minmax(0, 1fr); }
  .ratio-grid, .meta-grid { grid-template-columns: 1fr; }
  .preview-frame { min-height: 340px; }
  .result-actions .btn, .button-row .btn { width: 100%; }
}
