/* ============================================================
   SiteForge Editor — UI stylesheet
   Rewritten to match the current index.html / app.js exactly.
   Design tokens preserved from the original visual language.
   ============================================================ */

:root {
  --blue:       #0071e3;
  --blue-dark:  #005bb5;
  --green:      #34c759;
  --red:        #ff3b30;
  --yellow:     #ffd60a;
  --bg:         #f5f5f7;
  --surface:    #ffffff;
  --border:     #e2e2e5;
  --text:       #1d1d1f;
  --text-muted: #86868b;
  --radius:     10px;
  --sidebar-w:  320px;
}

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

html, body { height: 100%; overflow: hidden; }

body {
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  font-size: 14px;
  line-height: 1.5;
  color: var(--text);
  background: var(--bg);
}

a { color: var(--blue); text-decoration: none; }
.hidden { display: none !important; }

/* ── Screens ──────────────────────────────────────────────────── */
.screen { display: none; height: 100%; overflow: hidden; }
.screen--active { display: flex; flex-direction: column; }

/* ── Buttons ──────────────────────────────────────────────────── */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  padding: 10px 20px; border-radius: 8px; font-family: inherit; font-size: 14px;
  font-weight: 600; border: none; cursor: pointer; transition: all 0.15s;
  text-decoration: none; white-space: nowrap;
}
.btn:disabled { opacity: 0.5; cursor: not-allowed; }
.btn--primary { background: var(--blue); color: #fff; }
.btn--primary:hover:not(:disabled) { background: var(--blue-dark); }
.btn--outline { background: transparent; color: var(--blue); border: 1px solid var(--blue); }
.btn--outline:hover:not(:disabled) { background: var(--blue); color: #fff; }
.btn--ghost { background: transparent; color: var(--text); border: 1px solid var(--border); }
.btn--ghost:hover:not(:disabled) { background: var(--bg); }
.btn--text { background: none; border: none; color: var(--blue); padding: 4px 0; font-size: 13px; }
.btn--sm { padding: 7px 14px; font-size: 13px; }
.btn--lg { padding: 13px 22px; font-size: 15px; }
.btn--full { width: 100%; }
.btn--icon { padding: 8px; }

/* ── Forms ────────────────────────────────────────────────────── */
.form-group { display: flex; flex-direction: column; gap: 6px; margin-bottom: 12px; }
.form-group label { font-size: 13px; font-weight: 600; }
.form-input {
  width: 100%; padding: 10px 12px; border: 1px solid var(--border); border-radius: 8px;
  font-family: inherit; font-size: 14px; color: var(--text); background: var(--bg);
  transition: border-color 0.15s;
}
.form-input:focus { outline: none; border-color: var(--blue); background: #fff; }
.form-input--lg { padding: 13px 16px; font-size: 16px; }
textarea.form-input { resize: vertical; min-height: 80px; }

/* ── Alerts ───────────────────────────────────────────────────── */
.alert { padding: 12px 14px; border-radius: 8px; font-size: 13px; margin-top: 12px; }
.alert--error   { background: #fff2f2; color: var(--red);   border: 1px solid #ffd0cf; }
.alert--success { background: #f2fff5; color: var(--green); border: 1px solid #c8f0d1; }

/* ── Auth screen ──────────────────────────────────────────────── */
#auth-screen {
  background: linear-gradient(135deg, #667eea 0%, #0071e3 100%);
}
.auth-wrap {
  flex: 1; display: flex; align-items: center; justify-content: center; padding: 24px;
}
.auth-card {
  background: #fff; border-radius: 20px; padding: 40px; width: 100%; max-width: 400px;
  box-shadow: 0 24px 64px rgba(0,0,0,0.18);
}
.auth-logo { display: flex; align-items: center; gap: 10px; margin-bottom: 28px; font-size: 22px; font-weight: 700; }
.auth-card h1 { font-size: 26px; font-weight: 700; margin-bottom: 6px; }
.auth-sub { color: var(--text-muted); margin-bottom: 24px; }
.auth-hint { text-align: center; font-size: 12px; color: var(--text-muted); margin-top: 12px; }
.auth-cancel { display: block; width: 100%; text-align: center; margin-top: 16px; }

/* ── Top bar (dashboard) ──────────────────────────────────────── */
.topbar {
  display: flex; align-items: center; justify-content: space-between;
  padding: 0 20px; height: 52px; background: rgba(255,255,255,0.85);
  backdrop-filter: blur(10px); -webkit-backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--border); flex-shrink: 0; position: sticky; top: 0; z-index: 10;
}
.topbar__logo { display: flex; align-items: center; gap: 8px; font-weight: 700; font-size: 16px; }
.topbar__actions { display: flex; gap: 8px; }

/* ── Dashboard ────────────────────────────────────────────────── */
#dashboard-screen.screen--active { display: flex; }
.dashboard { flex: 1; overflow-y: auto; padding: 24px 20px; }

.empty-state {
  display: flex; flex-direction: column; align-items: center; gap: 12px;
  padding: 80px 24px; text-align: center;
}
.empty-state h2 { font-size: 22px; font-weight: 600; }
.empty-state p  { color: var(--text-muted); }

.sites-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 16px; }

.site-card {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  overflow: hidden; cursor: pointer; transition: box-shadow 0.15s, transform 0.15s;
}
.site-card:hover { box-shadow: 0 8px 24px rgba(0,0,0,0.08); transform: translateY(-2px); }
.site-card__thumb { height: 140px; position: relative; }
.site-card__badge {
  position: absolute; top: 8px; right: 8px; font-size: 11px; font-weight: 600;
  padding: 3px 10px; border-radius: 20px; background: rgba(0,0,0,0.6); color: #fff;
}
.site-card__badge--active { background: var(--green); }
.site-card__badge--draft  { background: var(--text-muted); }
.site-card__body { padding: 14px 16px; }
.site-card__name { font-weight: 600; font-size: 15px; margin-bottom: 4px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.site-card__url  { font-size: 12px; color: var(--text-muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.site-card__actions { display: flex; gap: 8px; padding: 0 16px 14px; }

/* ── Offline banner ───────────────────────────────────────────── */
.offline-banner {
  position: fixed; top: 0; left: 0; right: 0; background: var(--yellow); color: #333;
  text-align: center; padding: 6px; font-size: 13px; font-weight: 600; z-index: 200;
}

/* ── Template chooser (DEFAULT HOME) ─────────────────────────── */
#template-screen.screen--active { display: flex; }

.tpl-header {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 16px 20px; background: var(--surface); border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}
.tpl-header__brand { display: flex; align-items: center; gap: 12px; }
.tpl-header__brand h2 { font-size: 18px; font-weight: 700; line-height: 1.3; }
.tpl-header__brand p  { font-size: 12px; color: var(--text-muted); }

.tpl-search-wrap { padding: 12px 16px 0; background: var(--surface); }
.tpl-search { border-radius: 20px !important; font-size: 14px; }

.cat-bar {
  display: flex; gap: 8px; padding: 12px 16px; overflow-x: auto;
  background: var(--surface); border-bottom: 1px solid var(--border); flex-shrink: 0;
}
.cat-bar::-webkit-scrollbar { display: none; }

.chip {
  display: inline-block; padding: 6px 14px; border-radius: 20px; font-size: 13px; font-weight: 500;
  border: 1px solid var(--border); background: transparent; color: var(--text); cursor: pointer;
  white-space: nowrap; transition: all 0.1s; flex-shrink: 0;
}
.chip--active { background: var(--blue); color: #fff; border-color: var(--blue); }

.tpl-grid {
  flex: 1; display: grid; grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
  gap: 16px; padding: 20px; overflow-y: auto; align-content: start;
}

.tpl-card {
  position: relative; border: 2px solid var(--border); border-radius: var(--radius);
  overflow: hidden; cursor: pointer; background: var(--surface);
  transition: border-color 0.15s, box-shadow 0.15s;
}
.tpl-card:hover { border-color: var(--blue); box-shadow: 0 4px 12px rgba(0,113,227,0.15); }
.tpl-card--selected { border-color: var(--blue); box-shadow: 0 0 0 2px var(--blue); }

.tpl-card__thumb { height: 100px; position: relative; overflow: hidden; }
.tpl-card__accent { position: absolute; top: 0; left: 0; right: 0; height: 3px; }
.tpl-card__emoji {
  position: absolute; top: 50%; left: 50%; transform: translate(-50%, -60%);
  font-size: 28px; line-height: 1;
}
.tpl-card__bars { position: absolute; bottom: 8px; left: 10px; right: 10px; display: flex; flex-direction: column; gap: 4px; }
.tpl-bar { height: 5px; border-radius: 3px; }

.tpl-card__body { padding: 10px 12px; }
.tpl-card__ind  { font-weight: 700; font-size: 13px; margin-bottom: 2px; }
.tpl-card__ds   { font-size: 11px; color: var(--text-muted); }

.tpl-empty { grid-column: 1 / -1; text-align: center; padding: 48px 24px; color: var(--text-muted); font-size: 15px; }

/* Skeleton loading state (Phase 2 idle-batch placeholders) */
.tpl-skeleton { pointer-events: none; opacity: 0.6; }
.skel-bg {
  background: linear-gradient(90deg, #e2e2e5 25%, #f0f0f3 50%, #e2e2e5 75%);
  background-size: 200% 100%; animation: shimmer 1.4s infinite; height: 100px;
}
.skel-line {
  height: 10px; border-radius: 4px; margin-bottom: 6px; width: 60%;
  background: linear-gradient(90deg, #e2e2e5 25%, #f0f0f3 50%, #e2e2e5 75%);
  background-size: 200% 100%; animation: shimmer 1.4s infinite;
}
.skel-line--wide { width: 80%; }
@keyframes shimmer { to { background-position: -200% 0; } }

/* ── Name modal ───────────────────────────────────────────────── */
.modal-overlay {
  position: fixed; inset: 0; background: rgba(0,0,0,0.45);
  display: flex; align-items: center; justify-content: center; z-index: 500; padding: 20px;
}
.modal-card {
  background: var(--surface); border-radius: var(--radius); padding: 28px;
  width: 100%; max-width: 380px; box-shadow: 0 24px 64px rgba(0,0,0,0.25);
}
.modal-card h3 { font-size: 17px; font-weight: 700; margin-bottom: 16px; }
.modal-hint { font-size: 12px; color: var(--text-muted); margin: 10px 0 4px; line-height: 1.5; }
.modal-actions { display: flex; gap: 10px; justify-content: flex-end; margin-top: 20px; }

/* ── Editor ───────────────────────────────────────────────────── */
#editor-screen.screen--active { display: block; }

.editor-layout { display: grid; grid-template-columns: var(--sidebar-w) 1fr; height: 100%; }

.editor-sidebar {
  display: flex; flex-direction: column; background: var(--surface);
  border-right: 1px solid var(--border); height: 100%; overflow: hidden;
}

.editor-sidebar__head {
  display: flex; align-items: center; gap: 10px; padding: 14px 16px;
  border-bottom: 1px solid var(--border); flex-shrink: 0;
}
.editor-sidebar__name { font-weight: 700; font-size: 15px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

.editor-tabs { display: flex; border-bottom: 1px solid var(--border); flex-shrink: 0; }
.etab {
  flex: 1; padding: 10px 4px; font-size: 13px; font-weight: 500; border: none; background: none;
  cursor: pointer; color: var(--text-muted); border-bottom: 2px solid transparent; transition: all 0.15s;
}
.etab--active { color: var(--blue); border-bottom-color: var(--blue); }

.epanel { display: none; flex: 1; overflow-y: auto; padding: 16px; }
.epanel--active { display: block; }

.editor-sidebar__foot { padding: 12px 16px; border-top: 1px solid var(--border); flex-shrink: 0; }
.save-status { font-size: 12px; color: var(--text-muted); margin-top: 8px; min-height: 18px; text-align: center; }

/* Content fields */
.content-fields { display: flex; flex-direction: column; gap: 16px; }
.field-group { display: flex; flex-direction: column; gap: 6px; }
.field-group label { font-size: 12px; font-weight: 600; text-transform: uppercase; letter-spacing: 0.05em; color: var(--text-muted); }

/* Design panel */
.design-section h4 { font-size: 13px; font-weight: 600; text-transform: uppercase; letter-spacing: 0.05em; color: var(--text-muted); margin-bottom: 10px; }
.design-section { margin-bottom: 24px; }
.color-presets { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; }
.color-preset { height: 40px; border-radius: 8px; cursor: pointer; border: 2px solid transparent; transition: border-color 0.15s; }
.color-preset--active { border-color: var(--text); }

/* App panel — native app config (premium add-on) */
.app-panel__status { padding: 16px; background: var(--bg); border-radius: 8px; text-align: center; margin-bottom: 16px; }
.app-panel__status h4 { font-size: 15px; font-weight: 600; margin-bottom: 6px; }
.app-panel__status p { font-size: 13px; color: var(--text-muted); margin-bottom: 12px; line-height: 1.5; }
.app-panel__config { display: flex; flex-direction: column; gap: 4px; }
.form-input--color { height: 40px; padding: 4px 8px; cursor: pointer; }

/* Publish panel */
.publish-panel { display: flex; flex-direction: column; gap: 16px; }
.pub-status { padding: 12px; border-radius: 8px; background: var(--bg); font-size: 13px; }
.pub-info strong { margin-right: 6px; }
.pub-hint { font-size: 12px; color: var(--text-muted); margin-top: 8px; line-height: 1.5; }
.pub-domain { border-top: 1px solid var(--border); padding-top: 16px; }
.pub-domain h4 { font-size: 14px; font-weight: 600; margin-bottom: 4px; }
.pub-note { font-size: 12px; color: var(--text-muted); margin-bottom: 10px; }

/* ── Preview pane ─────────────────────────────────────────────── */
.preview-pane { display: flex; flex-direction: column; background: #1a1a1a; overflow: hidden; }

.preview-toolbar {
  display: flex; align-items: center; justify-content: space-between;
  padding: 8px 12px; background: #2a2a2a; border-bottom: 1px solid #333; flex-shrink: 0;
}

.page-tabs { display: flex; gap: 6px; overflow-x: auto; }
.ptab {
  padding: 5px 12px; border-radius: 6px; font-size: 12px; font-weight: 500;
  border: 1px solid #444; background: transparent; color: #aaa; cursor: pointer;
  white-space: nowrap; transition: all 0.1s;
}
.ptab--active { background: var(--blue); color: #fff; border-color: var(--blue); }

.viewport-btns { display: flex; gap: 4px; }
.vbtn {
  padding: 6px; border-radius: 6px; border: 1px solid #444; background: transparent;
  color: #aaa; cursor: pointer; display: flex; align-items: center; transition: all 0.1s;
}
.vbtn--active { background: #444; color: #fff; }

.preview-frame-wrap {
  flex: 1; display: flex; justify-content: center; align-items: center; overflow: auto; padding: 16px;
}
.preview-frame-wrap.desktop { padding: 0; align-items: stretch; }

#preview-frame {
  border: none; background: #fff; border-radius: 8px;
  box-shadow: 0 8px 32px rgba(0,0,0,0.4);
  width: 390px; height: 844px;
  transition: width 0.2s, height 0.2s, border-radius 0.2s;
}
#preview-frame.desktop { width: 100%; height: 100%; border-radius: 0; box-shadow: none; }

/* ── Badges (used in dashboard + publish panel) ──────────────── */
.badge { display: inline-flex; align-items: center; gap: 4px; padding: 3px 10px; border-radius: 20px; font-size: 11px; font-weight: 600; }
.badge--green  { background: #e4f7ec; color: #1a7f40; }
.badge--blue   { background: #e3f0ff; color: #0055cc; }
.badge--orange { background: #fff4e8; color: #c05c00; }
.badge--red    { background: #ffe8e7; color: #cc2200; }
.badge--gray   { background: var(--bg); color: var(--text-muted); }

/* ── Loading overlay ──────────────────────────────────────────── */
.loading-overlay {
  position: fixed; inset: 0; background: rgba(0,0,0,0.5);
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  z-index: 9999; gap: 16px;
}
.loading-overlay p { color: #fff; font-size: 15px; }
.spinner {
  width: 36px; height: 36px; border: 3px solid rgba(255,255,255,0.3);
  border-top-color: #fff; border-radius: 50%; animation: spin 0.7s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ── Toast ────────────────────────────────────────────────────── */
.toast {
  position: fixed; bottom: 24px; left: 50%; transform: translateX(-50%);
  background: #1d1d1f; color: #fff; padding: 12px 20px; border-radius: 10px;
  font-size: 14px; font-weight: 500; box-shadow: 0 4px 16px rgba(0,0,0,0.3);
  z-index: 10000; transition: opacity 0.3s; max-width: 90vw; text-align: center;
}
.toast--success { background: var(--green); }
.toast--error   { background: var(--red); }

/* ── Responsive ───────────────────────────────────────────────── */
@media (max-width: 768px) {
  :root { --sidebar-w: 100%; }
  .editor-layout { grid-template-columns: 1fr; }
  .preview-pane { display: none; }
  .sites-grid { grid-template-columns: 1fr; }
  .tpl-grid { grid-template-columns: repeat(2, 1fr); }
  .tpl-header { flex-wrap: wrap; }
}
