* {
  box-sizing: border-box;
}

:root {
  color-scheme: dark;
  --bg: #08090b;
  --panel: #111318;
  --panel-soft: #171a21;
  --panel-strong: #1d212b;
  --line: #2b3140;
  --text: #f5f7fb;
  --muted: #a8b0c2;
  --soft: #768197;
  --accent: #38bdf8;
  --accent-strong: #0ea5e9;
  --success: #22c55e;
  --danger: #ef4444;
  --warning: #f59e0b;
  --radius: 18px;
  --shadow: 0 22px 70px rgba(0, 0, 0, 0.35);
}

html,
body {
  margin: 0;
  min-height: 100%;
  background:
    radial-gradient(circle at 20% 0%, rgba(56, 189, 248, 0.14), transparent 35%),
    radial-gradient(circle at 100% 20%, rgba(14, 165, 233, 0.1), transparent 30%),
    var(--bg);
  color: var(--text);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

button,
textarea,
input {
  font: inherit;
}

button {
  cursor: pointer;
}

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

.sidebar,
.workspace {
  min-width: 0;
}

.sidebar {
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.brand {
  display: flex;
  gap: 14px;
  align-items: center;
  padding: 18px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: linear-gradient(145deg, rgba(17, 19, 24, 0.94), rgba(29, 33, 43, 0.78));
  box-shadow: var(--shadow);
}

.brand-mark {
  width: 50px;
  height: 50px;
  border-radius: 16px;
  display: grid;
  place-items: center;
  background: linear-gradient(135deg, var(--accent), #1d4ed8);
  color: #00111c;
  font-weight: 900;
  letter-spacing: -0.04em;
}

.brand h1,
.topbar h2 {
  margin: 0;
  font-size: 20px;
  line-height: 1.1;
}

.brand p,
.topbar p {
  margin: 6px 0 0;
  color: var(--muted);
  font-size: 13px;
}

.panel {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: rgba(17, 19, 24, 0.92);
  box-shadow: var(--shadow);
  overflow: hidden;
}

.panel-title {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  min-height: 48px;
  padding: 12px 14px;
  border-bottom: 1px solid var(--line);
  font-weight: 800;
  color: #fff;
}

.panel-title.compact {
  min-height: auto;
  padding: 10px 0 8px;
  border: 0;
  font-size: 13px;
  color: var(--muted);
}

.status-pill {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  border: 1px solid var(--line);
  border-radius: 999px;
  color: var(--muted);
  background: rgba(255, 255, 255, 0.035);
  padding: 5px 9px;
  font-size: 12px;
  font-weight: 700;
}

.status-pill.online {
  border-color: rgba(34, 197, 94, 0.4);
  color: #bbf7d0;
}

.status-pill.offline {
  border-color: rgba(245, 158, 11, 0.35);
  color: #fde68a;
}

.chat-panel {
  flex: 1;
  min-height: 520px;
  display: flex;
  flex-direction: column;
}

.messages {
  flex: 1;
  overflow: auto;
  padding: 14px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.message {
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 10px;
  background: rgba(255, 255, 255, 0.035);
}

.message.user {
  border-color: rgba(56, 189, 248, 0.26);
  background: rgba(56, 189, 248, 0.08);
}

.message.ai {
  border-color: rgba(34, 197, 94, 0.22);
  background: rgba(34, 197, 94, 0.06);
}

.message.error {
  border-color: rgba(239, 68, 68, 0.3);
  background: rgba(239, 68, 68, 0.08);
}

.message-role {
  color: var(--accent);
  font-size: 12px;
  font-weight: 900;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  margin-bottom: 6px;
}

.message-text {
  white-space: pre-wrap;
  color: var(--text);
  font-size: 13px;
  line-height: 1.45;
}

.prompt-box {
  border-top: 1px solid var(--line);
  padding: 12px;
  background: rgba(255, 255, 255, 0.02);
}

.prompt-box textarea,
#codeEditor {
  width: 100%;
  resize: vertical;
  color: var(--text);
  background: #07080b;
  border: 1px solid var(--line);
  border-radius: 14px;
  outline: none;
  padding: 12px;
}

.prompt-box textarea:focus,
#codeEditor:focus {
  border-color: rgba(56, 189, 248, 0.6);
  box-shadow: 0 0 0 3px rgba(56, 189, 248, 0.1);
}

.prompt-actions,
.topbar-actions,
.editor-actions,
.preview-controls {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

.prompt-actions {
  margin-top: 10px;
}

.primary-btn,
.ghost-btn {
  border: 1px solid transparent;
  border-radius: 12px;
  min-height: 38px;
  padding: 0 12px;
  color: #fff;
  font-weight: 800;
}

.primary-btn {
  background: linear-gradient(135deg, var(--accent), #2563eb);
  color: #00111c;
}

.primary-btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.ghost-btn {
  background: rgba(255, 255, 255, 0.04);
  border-color: var(--line);
  color: var(--text);
}

.ghost-btn:hover,
.ghost-btn.active {
  border-color: rgba(56, 189, 248, 0.55);
  background: rgba(56, 189, 248, 0.11);
}

.ghost-btn.small {
  min-height: 30px;
  padding: 0 9px;
  font-size: 12px;
}

.rules-panel {
  padding-bottom: 8px;
}

.rules-panel ul {
  margin: 0;
  padding: 10px 22px 14px 32px;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.7;
}

.workspace {
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.topbar {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: rgba(17, 19, 24, 0.82);
  padding: 16px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  box-shadow: var(--shadow);
}

.work-grid {
  display: grid;
  grid-template-columns: minmax(410px, 0.9fr) minmax(420px, 1.15fr);
  gap: 14px;
  min-height: calc(100vh - 118px);
}

.file-layout {
  display: grid;
  grid-template-columns: 150px minmax(0, 1fr);
  min-height: 450px;
}

.file-list {
  border-right: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.025);
  padding: 10px;
}

.file-btn {
  display: block;
  width: 100%;
  margin-bottom: 8px;
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 10px;
  text-align: left;
  color: var(--muted);
  background: rgba(0, 0, 0, 0.18);
  font-size: 13px;
  font-weight: 800;
}

.file-btn.active {
  color: #fff;
  border-color: rgba(56, 189, 248, 0.55);
  background: rgba(56, 189, 248, 0.12);
}

.editor-area {
  display: flex;
  flex-direction: column;
  min-width: 0;
}

.editor-toolbar {
  min-height: 48px;
  border-bottom: 1px solid var(--line);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 10px;
  color: var(--muted);
  font-size: 13px;
  font-weight: 800;
}

#codeEditor {
  flex: 1;
  min-height: 410px;
  border: 0;
  border-radius: 0;
  font-family: "JetBrains Mono", "Fira Code", Consolas, monospace;
  font-size: 13px;
  line-height: 1.5;
  resize: none;
  white-space: pre;
}

.history {
  padding: 0 12px 12px;
  border-top: 1px solid var(--line);
}

.history-list {
  display: flex;
  flex-wrap: wrap;
  gap: 7px;
  max-height: 112px;
  overflow: auto;
}

.history-item {
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 6px 9px;
  background: rgba(255, 255, 255, 0.035);
  color: var(--muted);
  font-size: 12px;
}

.preview-panel {
  display: flex;
  flex-direction: column;
  min-height: 0;
}

.preview-wrap {
  flex: 1;
  min-height: 540px;
  padding: 12px;
  display: grid;
  gap: 12px;
  background: #0c0e13;
}

.preview-wrap.split {
  grid-template-columns: minmax(0, 1fr) 380px;
}

.preview-wrap.desktop {
  grid-template-columns: 1fr;
}

.preview-wrap.desktop .mobile-frame {
  display: none;
}

.preview-wrap.mobile {
  grid-template-columns: 1fr;
  place-items: center;
}

.preview-wrap.mobile .desktop-frame {
  display: none;
}

.desktop-frame,
.mobile-frame {
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.frame-label {
  color: var(--muted);
  font-size: 12px;
  font-weight: 900;
  text-transform: uppercase;
  letter-spacing: 0.08em;
}

iframe {
  width: 100%;
  height: 100%;
  min-height: 500px;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: #fff;
}

.phone-shell {
  width: 100%;
  max-width: 360px;
  height: 100%;
  min-height: 540px;
  margin: 0 auto;
  padding: 14px;
  border: 1px solid #32394b;
  border-radius: 38px;
  background: linear-gradient(145deg, #020305, #171a22);
  box-shadow: inset 0 0 0 2px rgba(255,255,255,0.04), 0 30px 80px rgba(0,0,0,0.45);
}

.phone-speaker {
  width: 82px;
  height: 6px;
  border-radius: 999px;
  background: #303747;
  margin: 0 auto 12px;
}

.phone-shell iframe {
  border-radius: 26px;
  min-height: 492px;
}

@media (max-width: 1180px) {
  .app-shell {
    grid-template-columns: 1fr;
  }

  .chat-panel {
    min-height: 460px;
  }

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

@media (max-width: 720px) {
  .app-shell {
    padding: 8px;
  }

  .topbar {
    align-items: stretch;
    flex-direction: column;
  }

  .file-layout {
    grid-template-columns: 1fr;
  }

  .file-list {
    border-right: 0;
    border-bottom: 1px solid var(--line);
    display: flex;
    gap: 8px;
    overflow: auto;
  }

  .file-btn {
    min-width: 120px;
    margin: 0;
  }

  .preview-wrap.split {
    grid-template-columns: 1fr;
  }
}
