/* ============================================================
   Axome Replicator - Webapp Styles (v2)
   ============================================================ */

:root {
  --color-bg: #0a0a0b;
  --color-surface: #141417;
  --color-surface-raised: #1c1c21;
  --color-border: #2a2a30;
  --color-text: #e4e4e7;
  --color-text-muted: #71717a;
  --color-primary: #6366f1;
  --color-primary-hover: #818cf8;
  --color-success: #22c55e;
  --color-error: #ef4444;
  --color-warning: #f59e0b;
  --radius: 8px;
  --radius-lg: 12px;
  --font-mono: "SF Mono", "Fira Code", "Cascadia Code", monospace;
  --font-sans: -apple-system, BlinkMacSystemFont, "Segoe UI", system-ui, sans-serif;
  --header-height: 56px;
  --toolbar-height: 44px;
}

* { box-sizing: border-box; margin: 0; padding: 0; }

body {
  font-family: var(--font-sans);
  background: var(--color-bg);
  color: var(--color-text);
  height: 100vh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

/* ---- Header ---- */
.app-header {
  padding: 0 20px;
  border-bottom: 1px solid var(--color-border);
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px 20px;
  flex-shrink: 0;
  background: var(--color-surface);
  min-height: var(--header-height);
  padding-block: 8px;
}

.app-header__brand {
  display: flex;
  align-items: baseline;
  gap: 8px;
  flex-shrink: 0;
}

.app-header__brand h1 {
  font-size: 16px;
  font-weight: 700;
  letter-spacing: -0.02em;
  white-space: nowrap;
}

/* ---- Header Form (inline) ---- */
.header-form {
  flex: 1;
  display: flex;
  align-items: center;
  gap: 8px;
  max-width: 900px;
}

.header-form__input {
  flex: 1;
  height: 36px;
  padding: 0 14px;
  background: var(--color-bg);
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  color: var(--color-text);
  font-size: 13px;
  font-family: var(--font-mono);
  transition: border-color 0.15s;
}

.header-form__input:focus {
  outline: none;
  border-color: var(--color-primary);
}

.header-form__input::placeholder {
  color: var(--color-text-muted);
}

.header-form__input--mobile {
  flex: 0.6;
}

.header-form__select {
  height: 36px;
  padding: 0 12px;
  background: var(--color-bg);
  border: 1px solid var(--color-primary);
  border-radius: var(--radius);
  color: var(--color-text);
  font-size: 13px;
  font-family: var(--font-sans);
  cursor: pointer;
  flex-shrink: 0;
  max-width: 200px;
}

.header-form__select:focus {
  outline: none;
  border-color: var(--color-primary-hover);
}

/* ---- Mode Selector ---- */
.mode-selector {
  display: flex;
  gap: 2px;
  background: var(--color-bg);
  border-radius: var(--radius);
  padding: 2px;
  flex-shrink: 0;
}

.mode-btn {
  padding: 6px 14px;
  border: none;
  border-radius: 6px;
  background: transparent;
  color: var(--color-text-muted);
  font-size: 12px;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.15s;
  white-space: nowrap;
}

.mode-btn:hover {
  color: var(--color-text);
}

.mode-btn--active {
  background: var(--color-primary);
  color: #fff;
}

/* ---- Toggle + Prompt Row ---- */
.btn--icon {
  width: 36px;
  height: 36px;
  padding: 0;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: var(--color-surface-raised);
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  color: var(--color-text-muted);
  cursor: pointer;
  transition: all 0.15s;
  flex-shrink: 0;
  font-size: 18px;
  font-weight: 400;
  line-height: 1;
}

.btn--icon:hover {
  color: var(--color-text);
  border-color: var(--color-text-muted);
}

.btn--icon[aria-expanded="true"] {
  color: var(--color-primary);
  border-color: var(--color-primary);
}

.header-prompt {
  width: 100%;
  padding: 0 0 0 0;
}

.header-prompt__textarea {
  width: 100%;
  padding: 8px 14px;
  background: var(--color-bg);
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  color: var(--color-text);
  font-size: 13px;
  font-family: var(--font-sans);
  resize: vertical;
  min-height: 36px;
  max-height: 120px;
  transition: border-color 0.15s;
  line-height: 1.4;
}

.header-prompt__textarea:focus {
  outline: none;
  border-color: var(--color-primary);
}

.header-prompt__textarea::placeholder {
  color: var(--color-text-muted);
}

/* ---- Toolbar ---- */
.toolbar {
  height: var(--toolbar-height);
  padding: 0 16px;
  border-bottom: 1px solid var(--color-border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-shrink: 0;
  background: var(--color-surface);
}

.toolbar__tabs {
  display: flex;
  gap: 2px;
}

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

.tab {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 6px 14px;
  border: none;
  border-radius: 6px;
  background: transparent;
  color: var(--color-text-muted);
  font-size: 12px;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.15s;
}

.tab:hover {
  color: var(--color-text);
  background: var(--color-surface-raised);
}

.tab.is-active {
  color: var(--color-text);
  background: var(--color-surface-raised);
}

.tab svg {
  flex-shrink: 0;
}

/* ---- Buttons ---- */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  height: 36px;
  padding: 0 16px;
  border: none;
  border-radius: var(--radius);
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.15s;
  white-space: nowrap;
}

.btn--primary {
  background: var(--color-primary);
  color: white;
  flex-shrink: 0;
}

.btn--primary:hover {
  background: var(--color-primary-hover);
}

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

.btn--small {
  padding: 5px 12px;
  font-size: 12px;
  background: var(--color-surface-raised);
  color: var(--color-text-muted);
  border: 1px solid var(--color-border);
}

.btn--small:hover {
  color: var(--color-text);
  border-color: var(--color-text-muted);
}

/* ---- QA Badge ---- */
/* Hidden attribute support (override display properties) */
[hidden] { display: none !important; }

.qa-badge {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 12px;
  padding: 4px 10px;
  border-radius: 6px;
  background: var(--color-surface-raised);
  border: 1px solid var(--color-border);
}

.qa-badge__label {
  color: var(--color-text-muted);
}

.qa-badge__score {
  font-weight: 700;
  font-size: 13px;
}

/* ---- Progress Overlay (Split Layout) ---- */
.progress-overlay {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: flex;
}

.progress-overlay__left {
  width: 380px;
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(10, 10, 11, 0.92);
  backdrop-filter: blur(12px);
}

.progress-overlay__card {
  padding: 32px 40px;
  min-width: 320px;
}

.progress-overlay__right {
  flex: 1;
  background: #0d0d0f;
  border-left: 1px solid var(--color-border);
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 24px 20px;
  gap: 16px;
}

.reels__intro {
  font-size: 12px;
  color: var(--color-text-muted);
  text-align: center;
  font-style: italic;
}

.reels__container {
  width: 100%;
  aspect-ratio: 9 / 16;
  max-height: calc(100vh - 240px);
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: var(--radius-lg);
  overflow: hidden;
  background: #000;
  position: relative;
}

.reels__container iframe {
  width: 100%;
  height: 100%;
  border: none;
}

.reels__spinner {
  width: 32px;
  height: 32px;
  border: 3px solid var(--color-border);
  border-top-color: var(--color-primary);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

.reels__nav {
  display: flex;
  align-items: center;
  gap: 16px;
}

.reels__btn {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  border: 1px solid var(--color-border);
  background: var(--color-surface-raised);
  color: var(--color-text-muted);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.15s;
}

.reels__btn:hover {
  color: var(--color-text);
  border-color: var(--color-text-muted);
}

.reels__counter {
  font-size: 12px;
  color: var(--color-text-muted);
  font-family: var(--font-mono);
  min-width: 48px;
  text-align: center;
}

/* ---- Progress Meta Badges ---- */
.progress__meta {
  display: flex;
  gap: 6px;
  margin-bottom: 14px;
  min-height: 22px;
}

.progress__badge {
  font-size: 10px;
  font-weight: 600;
  padding: 2px 8px;
  border-radius: 4px;
  background: var(--color-surface-raised);
  border: 1px solid var(--color-border);
  color: var(--color-text-muted);
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.progress__badge--accent {
  border-color: var(--color-primary);
  color: var(--color-primary);
}

/* ---- Progress Stages ---- */
.progress__stages {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-bottom: 12px;
}

.progress__stage {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  font-size: 13px;
  color: var(--color-text-muted);
}

.progress__stage-info {
  display: flex;
  flex-direction: column;
  gap: 1px;
}

.progress__agent {
  font-size: 10px;
  color: var(--color-text-muted);
  opacity: 0;
  transition: opacity 0.3s;
}

.progress__stage.is-active .progress__agent {
  opacity: 0.7;
}

.progress__stage.is-active {
  color: var(--color-primary);
}

.progress__stage.is-done {
  color: var(--color-success);
}

.progress__stage.is-error {
  color: var(--color-error);
}

.progress__dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--color-border);
  flex-shrink: 0;
  margin-top: 4px;
}

.progress__stage.is-active .progress__dot {
  background: var(--color-primary);
  animation: pulse 1.5s infinite;
}

.progress__stage.is-done .progress__dot {
  background: var(--color-success);
}

.progress__stage.is-error .progress__dot {
  background: var(--color-error);
}

/* ---- Progress Detail ---- */
.progress__detail {
  font-size: 11px;
  color: var(--color-text-muted);
  font-style: italic;
  margin-bottom: 12px;
  min-height: 16px;
  line-height: 1.4;
  opacity: 0.8;
}

/* ---- QA Results ---- */
.progress__qa {
  display: flex;
  flex-direction: column;
  gap: 4px;
  padding: 8px 10px;
  background: var(--color-surface-raised);
  border: 1px solid var(--color-border);
  border-radius: 6px;
  margin-bottom: 12px;
}

.progress__qa-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 11px;
}

.progress__qa-label {
  color: var(--color-text-muted);
}

.progress__qa-value {
  font-weight: 700;
  font-family: var(--font-mono);
  font-size: 12px;
}

.btn--cancel {
  margin-top: 12px;
  padding: 6px 20px;
  background: transparent;
  color: var(--color-text-muted);
  border: 1px solid var(--color-border);
  font-size: 12px;
  border-radius: var(--radius);
  cursor: pointer;
  transition: all 0.15s;
}

.btn--cancel:hover {
  color: var(--color-error);
  border-color: var(--color-error);
}

.progress__bar {
  height: 3px;
  background: var(--color-border);
  border-radius: 2px;
  overflow: hidden;
}

.progress__fill {
  height: 100%;
  background: var(--color-primary);
  border-radius: 2px;
  transition: width 0.5s ease;
}

/* ---- Main Content ---- */
.main-content {
  flex: 1;
  display: flex;
  min-height: 0;
  position: relative;
}

.main-panel {
  overflow: hidden;
  display: flex;
  flex-direction: column;
}

.main-panel--code {
  flex: 1;
  min-width: 0;
  border-right: 1px solid var(--color-border);
}

.main-panel--preview {
  flex: 1;
  min-width: 0;
}

/* View modes */
body[data-view="code"] .main-panel--preview { display: none; }
body[data-view="code"] .main-panel--instructions { display: none; }
body[data-view="code"] .main-panel--code { flex: 1; border-right: none; }
body[data-view="code"] .resize-handle { display: none; }

body[data-view="preview"] .main-panel--code { display: none; }
body[data-view="preview"] .main-panel--instructions { display: none; }
body[data-view="preview"] .main-panel--preview { flex: 1; }
body[data-view="preview"] .resize-handle { display: none; }

body[data-view="split"] .main-panel--code { flex: 1; }
body[data-view="split"] .main-panel--preview { flex: 1; }
body[data-view="split"] .main-panel--instructions { display: none; }

body[data-view="instructions"] .main-panel--code { display: none; }
body[data-view="instructions"] .main-panel--preview { display: none; }
body[data-view="instructions"] .resize-handle { display: none; }
body[data-view="instructions"] .main-panel--instructions { display: block; flex: 1; }

/* ---- Editor ---- */
.editor {
  flex: 1;
  min-height: 0;
}

/* ---- Live Preview ---- */
.live-preview {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-height: 0;
  position: relative;
}

.live-preview__empty {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 16px;
  color: var(--color-text-muted);
}

.live-preview__empty-icon {
  opacity: 0.3;
}

.live-preview__empty p {
  font-size: 13px;
}

.live-preview iframe,
.live-preview__iframe {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  border: none;
  background: white;
}

/* ---- Resize Handle ---- */
.resize-handle {
  width: 5px;
  cursor: col-resize;
  background: var(--color-border);
  position: relative;
  flex-shrink: 0;
  z-index: 10;
  transition: background 0.15s;
}

.resize-handle:hover,
.resize-handle.is-dragging {
  background: var(--color-primary);
}

/* ---- Tab Badge ---- */
.tab__badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 18px;
  height: 18px;
  padding: 0 5px;
  border-radius: 9px;
  background: var(--color-primary);
  color: white;
  font-size: 10px;
  font-weight: 700;
  line-height: 1;
}

/* ---- Instructions Panel ---- */
.main-panel--instructions {
  overflow-y: auto;
}

.instructions {
  padding: 24px 32px;
  max-width: 720px;
  margin: 0 auto;
}

.instructions__empty {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 200px;
  color: var(--color-text-muted);
  font-size: 13px;
}

.instructions__title {
  font-size: 18px;
  font-weight: 700;
  margin-bottom: 20px;
}

.instructions__section {
  margin-bottom: 24px;
}

.instructions__section-title {
  font-size: 13px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--color-text-muted);
  margin-bottom: 10px;
}

.instructions__file-tree {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  padding: 14px 18px;
  font-family: var(--font-mono);
  font-size: 12px;
  line-height: 1.8;
  color: var(--color-text);
}

.instructions__file-tree .file--section { color: var(--color-primary); }
.instructions__file-tree .file--snippet { color: var(--color-success); }
.instructions__file-tree .file--asset { color: var(--color-warning); }

.instructions__steps {
  list-style: none;
  counter-reset: step;
}

.instructions__steps li {
  counter-increment: step;
  position: relative;
  padding-left: 28px;
  margin-bottom: 10px;
  font-size: 13px;
  line-height: 1.5;
}

.instructions__steps li::before {
  content: counter(step);
  position: absolute;
  left: 0;
  top: 1px;
  width: 20px;
  height: 20px;
  border-radius: 50%;
  background: var(--color-surface-raised);
  border: 1px solid var(--color-border);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 11px;
  font-weight: 600;
  color: var(--color-text-muted);
}

.instructions__notes {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  padding: 14px 18px;
  font-size: 13px;
  line-height: 1.6;
  color: var(--color-text);
  white-space: pre-wrap;
}

/* ---- Cost Display (Progress Overlay) ---- */
.progress__cost {
  display: flex;
  align-items: center;
  gap: 4px;
  margin-bottom: 12px;
  font-size: 12px;
  font-family: var(--font-mono);
}

.progress__cost-icon {
  color: var(--color-text-muted);
  font-weight: 600;
}

.progress__cost-value {
  color: var(--color-text);
  font-weight: 700;
  font-size: 14px;
}

/* ---- Cost Badge (Toolbar) ---- */
.cost-badge {
  display: flex;
  align-items: center;
  gap: 5px;
  font-size: 12px;
  padding: 4px 10px;
  border-radius: 6px;
  background: var(--color-surface-raised);
  border: 1px solid var(--color-border);
}

.cost-badge__label {
  color: var(--color-text-muted);
}

.cost-badge__value {
  font-weight: 700;
  font-size: 13px;
  font-family: var(--font-mono);
  color: var(--color-text);
}

/* ---- Animations ---- */
@keyframes pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.4; }
}
