:root {
  --bg-app: #f8fafc;
  --bg-surface: #ffffff;
  --bg-muted: #f1f5f9;
  --bg-code: #0f172a;
  --border: #e2e8f0;
  --border-strong: #cbd5e1;
  --ink: #0f172a;
  --ink-2: #475569;
  --muted: #64748b;
  --accent: #2563eb;
  --accent-hover: #1d4ed8;
  --accent-soft: #eff6ff;
  --ok: #16a34a;
  --warn: #d97706;
  --err: #dc2626;
  --font-display: 'Plus Jakarta Sans', -apple-system, BlinkMacSystemFont, sans-serif;
  --font-body: 'DM Sans', -apple-system, BlinkMacSystemFont, sans-serif;
  --font-mono: 'JetBrains Mono', ui-monospace, SFMono-Regular, Menlo, monospace;
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  padding: 0;
  height: 100%;
  background: var(--bg-app);
  color: var(--ink);
  font-family: var(--font-body);
  font-size: 14.5px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

h1,
h2,
h3 {
  font-family: var(--font-display);
  margin: 0;
  letter-spacing: -0.015em;
}

code,
.mono {
  font-family: var(--font-mono);
  font-size: 12.5px;
}

.tabular {
  font-variant-numeric: tabular-nums;
}

.truncate {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  border: 0;
}

/* Auth Shell */
.auth-shell {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
}

.auth-card {
  width: 100%;
  max-width: 430px;
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 32px;
}

.auth-brand {
  display: flex;
  align-items: baseline;
  gap: 10px;
  margin-bottom: 18px;
}

.brand-wordmark {
  font-family: var(--font-display);
  font-size: 17px;
  font-weight: 700;
  color: var(--ink);
  white-space: nowrap;
  flex-shrink: 0;
}

.auth-subtitle {
  font-size: 12.5px;
  color: var(--muted);
}

.auth-card h1 {
  font-size: 22px;
  margin-bottom: 8px;
}

.auth-copy {
  margin: 0 0 22px 0;
  color: var(--ink-2);
  font-size: 14px;
}

.auth-form {
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.auth-error {
  padding: 10px 12px;
  background: #fef2f2;
  border: 1px solid #fecaca;
  color: var(--err);
  border-radius: 7px;
  font-size: 13px;
}

.auth-divider {
  display: flex;
  align-items: center;
  gap: 12px;
  margin: 18px 0;
  color: var(--muted);
  font-size: 12.5px;
}

.auth-divider::before,
.auth-divider::after {
  content: '';
  flex: 1;
  height: 1px;
  background: var(--border);
}

.google-slot {
  display: flex;
  justify-content: center;
}

.field {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.field label {
  font-size: 13px;
  font-weight: 500;
}

.field input,
.field select,
.project-select,
.model-select,
.voice-lang {
  height: 38px;
  padding: 0 11px;
  border: 1px solid var(--border-strong);
  border-radius: 7px;
  background: var(--bg-surface);
  color: var(--ink);
  font-family: inherit;
  font-size: 13.5px;
}

.field input:focus,
.project-select:focus,
.model-select:focus,
.voice-lang:focus,
textarea:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.12);
}

/* Studio Shell */
.studio-shell {
  display: flex;
  flex-direction: column;
  height: 100vh;
  overflow: hidden;
}

.studio-topbar {
  min-height: 54px;
  height: auto;
  background: var(--bg-surface);
  border-bottom: 1px solid var(--border);
  padding: 8px 16px;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 10px 14px;
  flex-shrink: 0;
}

.topbar-zone-left,
.topbar-zone-center,
.topbar-zone-right {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 8px;
  min-width: 0;
}

.project-select {
  max-width: 150px;
}

.model-select {
  max-width: 215px;
}

#google-oauth-btn.btn-oauth-linked {
  max-width: 210px;
  overflow: hidden;
  text-overflow: ellipsis;
  display: inline-block;
  line-height: 30px;
}

.tier-status {
  font-size: 12.5px;
  font-weight: 600;
  color: var(--ink-2);
  white-space: nowrap;
}

.tier-status.is-ok {
  color: var(--ok);
}

.tier-status.is-paid {
  color: var(--accent);
}

.tier-status.is-buy {
  color: var(--err);
}

.warning-bar {
  background: #fffbeb;
  border-bottom: 1px solid #fde68a;
  color: #92400e;
  padding: 8px 20px;
  font-size: 13px;
  flex-shrink: 0;
}

.mobile-switcher {
  display: none;
  border-bottom: 1px solid var(--border);
  background: var(--bg-surface);
  padding: 6px 12px;
  gap: 8px;
}

.mob-tab {
  flex: 1;
  height: 36px;
  border: 1px solid var(--border);
  background: var(--bg-app);
  border-radius: 6px;
  font-weight: 500;
  cursor: pointer;
}

.mob-tab.is-active {
  background: var(--accent);
  border-color: var(--accent);
  color: #ffffff;
}

/* Main Split Workspace */
.studio-workspace {
  flex: 1;
  min-height: 0;
  display: grid;
  grid-template-columns: minmax(360px, 44%) minmax(0, 56%);
}

/* Left Chat Pane */
.chat-pane {
  display: flex;
  flex-direction: column;
  min-height: 0;
  border-right: 1px solid var(--border);
  background: var(--bg-surface);
}

.chat-feed {
  flex: 1;
  overflow-y: auto;
  padding: 20px;
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.chat-empty {
  margin: auto 0;
  text-align: center;
  padding: 32px 20px;
  color: var(--ink-2);
}

.chat-empty h2 {
  font-size: 19px;
  margin-bottom: 8px;
}

.chat-empty p {
  margin: 0 auto;
  max-width: 44ch;
  font-size: 13.5px;
}

.msg-card {
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding: 14px 16px;
  border-radius: 9px;
  border: 1px solid var(--border);
  background: var(--bg-app);
}

.msg-card.is-user {
  background: var(--accent-soft);
  border-color: #bfdbfe;
}

.msg-card.is-error {
  background: #fef2f2;
  border-color: #fecaca;
}

.msg-meta {
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-size: 12px;
  color: var(--muted);
}

.msg-role {
  font-weight: 600;
  color: var(--ink);
}

.msg-body {
  font-size: 14px;
  color: var(--ink);
  white-space: pre-wrap;
  word-break: break-word;
}

.msg-files {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  padding-top: 6px;
  border-top: 1px solid var(--border);
}

.msg-file-btn {
  appearance: none;
  background: var(--bg-surface);
  border: 1px solid var(--border-strong);
  border-radius: 6px;
  padding: 5px 10px;
  font-family: var(--font-mono);
  font-size: 12px;
  color: var(--ink);
  cursor: pointer;
}

.msg-file-btn:hover {
  border-color: var(--accent);
  color: var(--accent);
}

/* Composer */
.composer-box {
  border-top: 1px solid var(--border);
  padding: 14px 16px;
  background: var(--bg-surface);
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.composer-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  flex-wrap: wrap;
}

.voice-controls {
  display: flex;
  align-items: center;
  gap: 8px;
}

.btn-mic {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  height: 34px;
  padding: 0 12px;
  border-radius: 7px;
  border: 1px solid var(--border-strong);
  background: var(--bg-app);
  color: var(--ink);
  font-family: inherit;
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
}

.btn-mic:hover {
  background: var(--bg-muted);
}

.btn-mic.is-recording {
  background: #fef2f2;
  border-color: var(--err);
  color: var(--err);
}

.voice-lang {
  height: 34px;
  font-size: 12.5px;
}

.voice-note {
  font-size: 12px;
  font-weight: 600;
  color: var(--err);
}

.composer-hint {
  font-size: 12px;
  color: var(--muted);
}

.composer-box textarea {
  width: 100%;
  min-height: 76px;
  max-height: 180px;
  resize: vertical;
  padding: 10px 12px;
  border: 1px solid var(--border-strong);
  border-radius: 8px;
  font-family: inherit;
  font-size: 14px;
  line-height: 1.45;
}

.composer-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 10px;
}

.composer-footer-left {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 12px;
}

.composer-sync-toggle {
  font-size: 12.5px;
  color: var(--ink-2);
  align-items: center;
}

.composer-sync-toggle input[type="checkbox"] {
  margin-top: 0;
}

.msg-stage-banner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 8px;
  padding: 8px 10px;
  border-radius: 6px;
  background: #f0fdf4;
  border: 1px solid #bbf7d0;
  color: #166534;
  font-size: 12.5px;
}

.msg-stage-banner a {
  color: #15803d;
  font-weight: 600;
  text-decoration: underline;
}

/* Right Workbench Pane */
.workbench-pane {
  display: grid;
  grid-template-columns: 230px minmax(0, 1fr);
  min-height: 0;
  background: var(--bg-app);
}

.explorer-sidebar {
  border-right: 1px solid var(--border);
  background: var(--bg-surface);
  display: flex;
  flex-direction: column;
  min-height: 0;
}

.explorer-header {
  height: 46px;
  padding: 0 14px;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-size: 13px;
  font-weight: 600;
}

.file-count {
  font-size: 12px;
  color: var(--muted);
  font-weight: 400;
}

.explorer-list {
  flex: 1;
  overflow-y: auto;
  padding: 8px;
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.explorer-empty {
  padding: 20px 10px;
  font-size: 13px;
  color: var(--muted);
  text-align: center;
}

.file-item {
  appearance: none;
  width: 100%;
  text-align: left;
  background: transparent;
  border: 0;
  border-radius: 6px;
  padding: 8px 10px;
  font-family: var(--font-mono);
  font-size: 12.5px;
  color: var(--ink-2);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.file-item:hover {
  background: var(--bg-muted);
  color: var(--ink);
}

.file-item.is-active {
  background: var(--accent-soft);
  color: var(--accent);
  font-weight: 500;
}

.file-size {
  font-size: 11px;
  color: var(--muted);
  flex-shrink: 0;
}

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

.editor-header {
  height: 46px;
  background: var(--bg-surface);
  border-bottom: 1px solid var(--border);
  padding: 0 14px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.editor-tabs {
  display: inline-flex;
  gap: 4px;
  padding: 3px;
  background: var(--bg-muted);
  border-radius: 6px;
}

.editor-tab {
  appearance: none;
  border: 0;
  background: transparent;
  padding: 4px 12px;
  border-radius: 4px;
  font-size: 12.5px;
  font-weight: 500;
  color: var(--ink-2);
  cursor: pointer;
}

.editor-tab.is-active {
  background: var(--bg-surface);
  color: var(--ink);
}

.editor-meta {
  flex: 1;
  min-width: 0;
  text-align: center;
  color: var(--ink-2);
}

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

.editor-body {
  flex: 1;
  min-height: 0;
  position: relative;
}

.tab-panel {
  display: none;
  height: 100%;
}

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

.code-empty {
  margin: auto;
  padding: 24px;
  color: var(--muted);
  text-align: center;
  font-size: 13.5px;
}

.code-view-wrap {
  display: flex;
  flex: 1;
  min-height: 0;
  overflow: auto;
  background: var(--bg-code);
  color: #e2e8f0;
  font-family: var(--font-mono);
  font-size: 13px;
  line-height: 1.6;
}

.code-view-wrap[hidden] {
  display: none;
}

.code-gutter {
  padding: 16px 12px;
  text-align: right;
  color: #64748b;
  user-select: none;
  border-right: 1px solid #1e293b;
  white-space: pre;
}

.code-content {
  margin: 0;
  padding: 16px 18px;
  flex: 1;
  white-space: pre;
  overflow-x: visible;
}

.preview-frame {
  width: 100%;
  height: 100%;
  border: 0;
  background: #ffffff;
}

/* Buttons & Modal */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  height: 38px;
  padding: 0 16px;
  border-radius: 7px;
  font-family: inherit;
  font-size: 13.5px;
  font-weight: 500;
  cursor: pointer;
  white-space: nowrap;
  flex-shrink: 0;
  border: 1px solid transparent;
  transition: background-color 0.15s ease, border-color 0.15s ease;
}

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

.btn-sm {
  height: 32px;
  padding: 0 12px;
  font-size: 12.5px;
}

.btn-full {
  width: 100%;
}

.btn-primary {
  background: var(--accent);
  color: #ffffff;
}

.btn-primary:hover:not(:disabled) {
  background: var(--accent-hover);
}

.btn-secondary {
  background: var(--bg-surface);
  color: var(--ink);
  border-color: var(--border-strong);
}

.btn-secondary:hover:not(:disabled) {
  background: var(--bg-muted);
}

.btn-ghost {
  background: transparent;
  color: var(--ink-2);
}

.btn-ghost:hover:not(:disabled) {
  background: var(--bg-muted);
  color: var(--ink);
}

.btn-danger {
  background: var(--err);
  color: #ffffff;
}

.btn-danger:hover:not(:disabled) {
  background: #b91c1c;
}

.btn-danger-ghost {
  background: transparent;
  color: var(--err);
  border-color: #fecaca;
}

.btn-danger-ghost:hover:not(:disabled) {
  background: #fef2f2;
  border-color: #fca5a5;
}

.btn-cloud-synced {
  background: #eff6ff;
  border-color: #bfdbfe;
  color: #1d4ed8;
  max-width: 190px;
  overflow: hidden;
  text-overflow: ellipsis;
  display: inline-block;
  line-height: 30px;
}

.checkbox-row {
  display: flex;
  align-items: flex-start;
  gap: 8px;
  font-size: 13px;
  color: var(--ink-2);
  cursor: pointer;
}

.checkbox-row input[type="checkbox"] {
  margin-top: 3px;
  flex-shrink: 0;
}

.checkbox-row[hidden] {
  display: none;
}

.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, 0.45);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  z-index: 60;
}

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

.modal-card {
  width: 100%;
  max-width: 460px;
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 24px;
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.modal-copy {
  margin: 0;
  color: var(--ink-2);
  font-size: 13.5px;
}

.modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
}

.modal-card-wide {
  max-width: 560px;
}

.modal-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.modal-actions-spread {
  justify-content: space-between;
  align-items: center;
  flex-wrap: wrap;
}

.modal-actions-group {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-left: auto;
}

.field-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}

.oauth-status-box {
  padding: 10px 12px;
  border-radius: 7px;
  border: 1px solid var(--border);
  background: var(--bg-app);
  font-size: 13px;
  color: var(--ink-2);
}

.oauth-status-box.is-connected {
  background: #f0fdf4;
  border-color: #bbf7d0;
  color: #166534;
}

.oauth-status-box.is-expired {
  background: #fffbeb;
  border-color: #fde68a;
  color: #92400e;
}

.oauth-info-box {
  display: flex;
  flex-direction: column;
  gap: 6px;
  padding: 10px 12px;
  border-radius: 7px;
  background: var(--bg-muted);
  font-size: 12px;
}

.oauth-info-row {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.oauth-info-row span {
  color: var(--muted);
  font-weight: 500;
}

.oauth-info-row code {
  word-break: break-all;
  color: var(--ink);
}

.inline-link-btn {
  appearance: none;
  border: 0;
  background: transparent;
  padding: 0;
  color: var(--accent);
  font-family: inherit;
  font-size: inherit;
  font-weight: 600;
  text-decoration: underline;
  cursor: pointer;
}

.btn-oauth-linked {
  border-color: #86efac;
  background: #f0fdf4;
  color: #166534;
}

.btn-oauth-linked:hover:not(:disabled) {
  background: #dcfce7;
}

.btn-oauth-warn {
  border-color: #fcd34d;
  background: #fffbeb;
  color: #92400e;
}

.btn-oauth-warn:hover:not(:disabled) {
  background: #fef3c7;
}

.toast-region {
  position: fixed;
  right: 20px;
  bottom: 20px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  z-index: 80;
}

.toast {
  background: #0f172a;
  color: #ffffff;
  padding: 11px 15px;
  border-radius: 7px;
  font-size: 13px;
  max-width: 360px;
}

.toast.is-error {
  background: var(--err);
}

@media (max-width: 1080px) {
  .studio-topbar {
    flex-wrap: wrap;
    height: auto;
    padding: 10px 14px;
  }

  .mobile-switcher {
    display: flex;
  }

  .studio-workspace {
    grid-template-columns: 1fr;
  }

  .chat-pane,
  .workbench-pane {
    display: none;
  }

  .chat-pane.is-active {
    display: flex;
  }

  .workbench-pane.is-active {
    display: grid;
    grid-template-columns: 1fr;
  }

  .explorer-sidebar {
    max-height: 180px;
    border-right: 0;
    border-bottom: 1px solid var(--border);
  }
}
