:root {
  color-scheme: light dark;
  --bg: #0f1115;
  --surface: #171a21;
  --surface-2: #1f232c;
  --border: #2a2f3a;
  --text: #e6e8eb;
  --text-dim: #9aa1ac;
  --accent: #5b8def;
  --danger: #e6553f;
  --success: #3fbf6f;
  --warn: #e6b83f;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
}

.app-shell { display: flex; min-height: 100vh; }

.sidebar {
  width: 220px;
  flex-shrink: 0;
  display: flex;
  flex-direction: column;
  background: var(--surface);
  border-right: 1px solid var(--border);
}

.sidebar .brand { font-weight: 700; padding: 1.25rem 1.25rem 0.5rem; }

.sidebar-nav { display: flex; flex-direction: column; gap: 0.15rem; flex: 1; padding: 0.75rem 0.6rem; }
.sidebar-nav a {
  display: flex;
  align-items: center;
  gap: 0.7rem;
  padding: 0.55rem 0.65rem;
  border-radius: 6px;
  color: var(--text-dim);
  text-decoration: none;
  font-size: 0.92rem;
}
.sidebar-nav a svg { width: 18px; height: 18px; flex-shrink: 0; }
.sidebar-nav a:hover { color: var(--text); background: var(--surface-2); }
.sidebar-nav a.active { color: var(--text); background: var(--surface-2); }

.sidebar-bottom {
  border-top: 1px solid var(--border);
  padding: 0.9rem 1rem;
  display: flex;
  flex-direction: column;
  gap: 0.6rem;
}
.sidebar-user {
  color: var(--text-dim);
  font-size: 0.8rem;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.sidebar-actions { display: flex; gap: 0.5rem; }
.sidebar-actions form { margin: 0; }

.icon-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 34px;
  height: 34px;
  border-radius: 6px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  color: var(--text-dim);
  cursor: pointer;
  text-decoration: none;
  padding: 0;
}
.icon-btn svg { width: 17px; height: 17px; }
.icon-btn:hover { color: var(--text); border-color: var(--accent); filter: none; }

.container { max-width: 960px; margin: 0 auto; padding: 2rem 1.5rem; }
.app-shell .container { flex: 1; min-width: 0; margin: 0; }

h1 { margin-top: 0; }

.auth-card {
  max-width: 380px;
  margin: 4rem auto;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 2rem;
}

form label { display: block; margin-bottom: 1rem; font-size: 0.9rem; color: var(--text-dim); }

input, select, button {
  font: inherit;
  color: var(--text);
}

input, select {
  width: 100%;
  margin-top: 0.35rem;
  padding: 0.55rem 0.65rem;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 6px;
}

button {
  cursor: pointer;
  background: var(--accent);
  border: none;
  border-radius: 6px;
  padding: 0.55rem 1rem;
  color: white;
  font-weight: 600;
}

button:hover { filter: brightness(1.1); }

.inline-form {
  display: flex;
  gap: 0.5rem;
  flex-wrap: wrap;
  margin-bottom: 1.5rem;
  align-items: center;
}
.inline-form input, .inline-form select { width: auto; margin-top: 0; }

table { width: 100%; border-collapse: collapse; margin-top: 1rem; }
th, td { text-align: left; padding: 0.6rem 0.5rem; border-bottom: 1px solid var(--border); }
th { color: var(--text-dim); font-size: 0.8rem; text-transform: uppercase; letter-spacing: 0.03em; }

a { color: var(--accent); }

.meta { color: var(--text-dim); }
.empty { color: var(--text-dim); font-style: italic; }
.error { color: var(--danger); }

.stat-row { display: flex; gap: 1rem; margin-bottom: 2rem; }
.stat-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 1.25rem 1.5rem;
  display: flex;
  flex-direction: column;
}
.stat-value { font-size: 1.8rem; font-weight: 700; }
.stat-label { color: var(--text-dim); font-size: 0.85rem; }

.badge {
  display: inline-block;
  padding: 0.15rem 0.55rem;
  border-radius: 999px;
  font-size: 0.75rem;
  font-weight: 600;
  background: var(--surface-2);
  border: 1px solid var(--border);
}
.badge-active, .badge-success { color: var(--success); border-color: var(--success); }
.badge-pending, .badge-provisioning { color: var(--warn); border-color: var(--warn); }
.badge-failed { color: var(--danger); border-color: var(--danger); }

code { background: var(--surface-2); padding: 0.1rem 0.4rem; border-radius: 4px; }

.qr-wrap {
  background: #fff;
  display: inline-block;
  padding: 1rem;
  border-radius: 8px;
  margin: 0.75rem 0;
}
.qr-wrap svg { width: 200px; height: 200px; display: block; }

.block-item {
  border: 1px solid var(--border);
  border-radius: 8px;
  margin-bottom: 0.75rem;
  overflow: hidden;
}
.block-preview { padding: 1rem; background: var(--surface); }
.block-preview-iframe { width: 100%; height: 240px; border: 0; display: block; background: #fff; }
.block-item-editing .block-preview { display: none; }
.block-item form { padding: 1rem; background: var(--surface); }
.block-toolbar {
  display: flex;
  gap: 0.5rem;
  padding: 0.5rem 1rem;
  background: var(--surface-2);
  border-top: 1px solid var(--border);
}
.block-toolbar button { font-size: 0.85rem; padding: 0.35rem 0.75rem; }

.chat-log {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
  margin: 1.5rem 0;
  min-height: 120px;
}
.chat-message {
  max-width: 75%;
  padding: 0.65rem 0.9rem;
  border-radius: 10px;
  border: 1px solid var(--border);
}
.chat-message-user { align-self: flex-end; background: var(--accent); border-color: var(--accent); color: #fff; }
.chat-message-user .chat-role { color: rgba(255,255,255,0.8); }
.chat-message-assistant { align-self: flex-start; background: var(--surface); }
.chat-message-error { align-self: flex-start; background: var(--surface); border-color: var(--danger); color: var(--danger); }
.chat-thinking { display: none; font-style: italic; color: var(--text-dim); padding: 0.6rem 0; }
.chat-thinking.htmx-request { display: block; }
.chat-role { display: block; font-size: 0.75rem; text-transform: uppercase; letter-spacing: 0.03em; color: var(--text-dim); margin-bottom: 0.2rem; }
.chat-content { white-space: pre-wrap; }

.chat-input-form { display: flex; gap: 0.5rem; }
.chat-input-form input { flex: 1; margin-top: 0; }

.container-wide { max-width: none; padding: 0; } /* full-bleed editor */

.builder-topbar {
  display: flex;
  align-items: center;
  gap: 1rem;
  margin-bottom: 1rem;
}
.builder-topbar h1 { margin: 0; font-size: 1.25rem; flex: 1; }
.builder-publish-bar { display: flex; align-items: center; gap: 0.75rem; }

.builder-root {
  height: 100vh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}
.builder-bar {
  flex: none;
  display: flex;
  align-items: center;
  gap: 0.6rem;
  padding: 0.45rem 0.75rem;
  background: linear-gradient(180deg, #2b2e34, #1f2226);
  border-bottom: 1px solid #000;
  box-shadow: 0 1px 4px rgba(0,0,0,.35);
  position: relative;
  z-index: 5;
}
.builder-bar-spacer { flex: 1; }
.builder-shell {
  flex: 1;
  min-height: 0;
  display: grid;
  /* fixed chat track + exactly-one-row: no content-driven renegotiation,
     so publish never resizes the preview and the chat input stays in view */
  grid-template-columns: 380px minmax(0, 1fr);
  grid-template-rows: minmax(0, 1fr);
}
.builder-chat {
  display: flex;
  flex-direction: column;
  min-height: 0;
  overflow: hidden;
}
.builder-chat-head {
  flex: none;
  padding: 0.5rem 0.75rem 0.25rem;
  font-size: 0.75rem;
  font-weight: 700;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--text-dim);
}
.glossy-btn {
  background: linear-gradient(180deg, #fdfdfd, #e7e8eb);
  border: 1px solid #c9ccd2;
  border-radius: 7px;
  color: #23262b;
  font-size: 0.85rem;
  font-weight: 600;
  padding: 0.38rem 0.8rem;
  box-shadow: 0 1px 2px rgba(0,0,0,.2), inset 0 1px 0 rgba(255,255,255,.85);
  cursor: pointer;
  text-decoration: none;
  display: inline-block;
  line-height: 1.3;
}
.glossy-btn:hover { filter: brightness(1.04); }
.glossy-btn.danger {
  background: linear-gradient(180deg, #fdecec, #f3c4c4);
  border-color: #dfa3a3;
  color: #9c3333;
}
.sites-dropdown { position: relative; }
.sites-dropdown summary { list-style: none; cursor: pointer; }
.sites-dropdown summary::-webkit-details-marker { display: none; }
.sites-dropdown[open] .dropdown-menu { display: flex; }
.dropdown-menu {
  display: none;
  position: absolute;
  top: 115%;
  left: 0;
  min-width: 230px;
  background: #fff;
  border: 1px solid var(--border);
  border-radius: 9px;
  box-shadow: 0 10px 28px rgba(0,0,0,.25);
  padding: 0.4rem;
  flex-direction: column;
  z-index: 60;
}
.dropdown-label { font-size: 0.7rem; font-weight: 700; text-transform: uppercase; letter-spacing: 0.05em; color: var(--text-dim); padding: 0.3rem 0.6rem; }
.dropdown-menu a, .dropdown-menu button {
  text-align: left; padding: 0.45rem 0.6rem; border-radius: 6px;
  text-decoration: none; color: var(--text); font-size: 0.9rem;
  background: none; border: none; cursor: pointer; display: block; width: 100%;
}
.dropdown-menu a:hover, .dropdown-menu button:hover { background: #eef0f3; }
.dropdown-menu a.active { font-weight: 700; }
.dropdown-menu button.danger { color: var(--danger); }
.dropdown-menu hr { border: 0; border-top: 1px solid var(--border); margin: 0.3rem 0; }
.plan-badge {
  font-size: 0.76rem; color: #d5d9e0; background: rgba(255,255,255,.09);
  border: 1px solid rgba(255,255,255,.18); padding: 0.28rem 0.65rem;
  border-radius: 999px; white-space: nowrap;
}
.plan-badge.locked { background: #ffdcae; color: #7c4500; border-color: #e3aa5c; font-weight: 700; }
.builder-publish-bar { display: flex; align-items: center; gap: 0.5rem; }

.builder-chat .chat-log { flex: 1; min-height: 0; overflow-y: auto; margin: 0 0 0.75rem 0; }

.builder-preview {
  border: 1px solid var(--border);
  border-radius: 8px;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  min-height: 0;
}

.builder-pages-nav {
  display: flex;
  gap: 0.5rem;
  padding: 0.75rem 1rem;
  background: var(--surface-2);
  border-bottom: 1px solid var(--border);
  overflow-x: auto;
  flex-shrink: 0;
}
.builder-page-link {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  padding: 0.35rem 0.75rem;
  border-radius: 6px;
  border: 1px solid var(--border);
  color: var(--text);
  text-decoration: none;
  white-space: nowrap;
  font-size: 0.85rem;
}
.builder-page-link.active { border-color: var(--accent); background: var(--surface); }

.builder-preview-frame {
  flex: 1;
  min-height: 0;
  overflow: hidden;
  background: #fff;
  color: #111;
  display: flex;
  flex-direction: column;
}
.builder-preview-iframe {
  width: 100%;
  flex: 1;
  min-height: 0;
  border: 0;
  display: block;
  background: #fff;
}

.builder-code-frame {
  display: none;
  flex: 1;
  overflow: auto;
  background: #0d1117;
  padding: 1rem;
}
.builder-code-frame pre { margin: 0; white-space: pre-wrap; word-break: break-word; color: #e6e8eb; font-size: 0.85rem; }

.builder-view-toggle { display: flex; gap: 0.25rem; }
.view-toggle-btn {
  background: transparent;
  border: 1px solid var(--border);
  color: var(--text-dim);
  font-size: 0.8rem;
  padding: 0.35rem 0.75rem;
}
.view-toggle-btn.active { color: var(--text); border-color: var(--accent); background: var(--surface); }

.builder-delete-page-btn { margin-left: auto; font-size: 0.8rem; padding: 0.35rem 0.75rem; flex-shrink: 0; }

.undo-btn {
  background: transparent;
  border: 1px solid var(--border);
  color: inherit;
  font-size: 0.75rem;
  padding: 0.15rem 0.5rem;
  margin-top: 0.4rem;
}

.deploy-error { color: var(--danger); display: block; margin-top: 0.4rem; }

.page-settings-panel { background: var(--surface); border: 1px solid var(--border); border-radius: 8px; padding: 1rem; margin-bottom: 1rem; }
.page-settings-panel h3 { margin: 0 0 0.75rem; }
.page-settings-panel label { display: block; margin-bottom: 0.6rem; font-size: 0.85rem; font-weight: 600; }
.page-settings-panel input, .page-settings-panel textarea { width: 100%; margin-top: 0.25rem; font-weight: 400; }
.page-settings-actions { display: flex; gap: 0.5rem; margin-top: 0.5rem; }
.page-settings-saved { color: var(--success, #2e7d32); }
.builder-settings-btn { margin-left: auto; font-size: 0.8rem; padding: 0.35rem 0.75rem; }

.builder-preview-btn { margin-left: auto; font-size: 0.8rem; padding: 0.35rem 0.75rem; text-decoration: none; }

.sites-bar { display: flex; align-items: center; gap: 0.5rem; flex-wrap: wrap; padding: 0.5rem 1rem; background: var(--surface); border-bottom: 1px solid var(--border); }
.sites-bar-link { padding: 0.3rem 0.8rem; border-radius: 6px; font-size: 0.9rem; text-decoration: none; border: 1px solid var(--border); }
.sites-bar-link.active { background: var(--accent); color: #fff; border-color: var(--accent); }
.sites-bar-new { font-size: 0.85rem; }
.sites-bar-sep { flex: 1; }
.sites-bar-delete { font-size: 0.8rem; padding: 0.3rem 0.7rem; background: transparent; border: 1px solid var(--danger); color: var(--danger); }
.plan-banner { padding: 0.5rem 1rem; background: var(--surface-2, var(--surface)); border-bottom: 1px solid var(--border); font-size: 0.85rem; color: var(--text-dim); }
.plan-banner.plan-locked { background: #fff3e0; color: #b26a00; border-bottom-color: #ffcc80; font-weight: 600; }
.new-site-panel { padding: 1rem; background: var(--surface); border-bottom: 1px solid var(--border); }
.new-site-form label { display: block; font-size: 0.85rem; font-weight: 600; margin-bottom: 0.5rem; }
.new-site-form input { width: 100%; }

.back-workshop { white-space: nowrap; }
.builder-site-name { color: #fff; font-weight: 700; font-size: 0.95rem; }
.builder-live-link { color: #9fe8a9; text-decoration: none; font-size: 1rem; }

.workshop-head { display: flex; align-items: center; justify-content: space-between; gap: 1rem; margin-bottom: 1.25rem; }
.workshop-head h1 { margin: 0; }
.workshop-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(300px, 1fr)); gap: 1rem; }
.workshop-card { background: var(--surface); border: 1px solid var(--border); border-radius: 10px; padding: 1rem; display: flex; flex-direction: column; gap: 0.75rem; box-shadow: 0 1px 3px rgba(0,0,0,.06); }
.workshop-card-top { display: flex; align-items: center; gap: 0.75rem; }
.workshop-avatar { width: 40px; height: 40px; border-radius: 9px; background: linear-gradient(180deg, #fdfdfd, #e7e8eb); border: 1px solid #c9ccd2; display: flex; align-items: center; justify-content: center; font-weight: 800; font-size: 1.1rem; color: #23262b; }
.workshop-card-title h3 { margin: 0 0 0.25rem; }
.workshop-card-meta { display: flex; justify-content: space-between; gap: 0.5rem; font-size: 0.85rem; }
.workshop-card-meta a { color: var(--accent); text-decoration: none; }
.workshop-card-actions { display: flex; gap: 0.5rem; flex-wrap: wrap; border-top: 1px solid var(--border); padding-top: 0.75rem; }
.workshop-card-actions .primary { background: linear-gradient(180deg, #3d7a4d, #2e6b34); border-color: #245328; color: #fff; }
.workshop-empty { text-align: center; padding: 4rem 1rem; border: 2px dashed var(--border); border-radius: 12px; }
.workshop-empty h2 { margin: 0 0 0.5rem; }
.site-settings-anchor { margin-top: 1.5rem; }
.site-settings-panel { background: var(--surface); border: 1px solid var(--border); border-radius: 10px; padding: 1.25rem; margin-top: 1.25rem; max-width: 560px; }
.site-settings-panel h3 { margin: 0 0 0.75rem; }
.site-settings-panel label { display: block; margin-bottom: 0.6rem; font-size: 0.85rem; font-weight: 600; }
.site-settings-panel input, .site-settings-panel textarea { width: 100%; margin-top: 0.25rem; font-weight: 400; }

/* UI-dept hardening: grid items must not blow out tracks; chat text wraps */
.builder-chat, .builder-preview { min-width: 0; }
#builder-chat-log .chat-content { overflow-wrap: anywhere; }

/* ---- button system ---- */
button {
  font: inherit;
  border-radius: 7px;
  border: 1px solid #c9ccd2;
  background: linear-gradient(180deg, #fdfdfd, #e8e9ec);
  padding: 0.45rem 0.9rem;
  cursor: pointer;
  color: #23262b;
}
button:hover { filter: brightness(1.04); }
button:disabled { opacity: 0.55; cursor: not-allowed; }
.btn { display: inline-block; text-decoration: none; border-radius: 7px; padding: 0.45rem 0.9rem; font-weight: 600; border: 1px solid #c9ccd2; background: linear-gradient(180deg, #fdfdfd, #e8e9ec); color: #23262b; cursor: pointer; }
.btn-primary { background: linear-gradient(180deg, #3d7a4d, #2e6b34); border-color: #245328; color: #fff; }
.btn-danger { background: linear-gradient(180deg, #fdecec, #f3c4c4); border-color: #dfa3a3; color: #9c3333; }

/* ---- focus ---- */
:focus-visible { outline: 2px solid var(--accent, #2e6b34); outline-offset: 2px; }

/* ---- micro-interactions ---- */
.htmx-swapping { opacity: 0; transition: opacity 150ms; }
.workshop-card { transition: transform 150ms ease, box-shadow 150ms ease; }
.workshop-card:hover { transform: translateY(-2px); box-shadow: 0 6px 16px rgba(0,0,0,.10); }

/* ---- dashboard ---- */
.dash-stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(140px, 1fr)); gap: 1rem; margin: 1.5rem 0; }
.dash-stat { background: var(--surface); border: 1px solid var(--border); border-radius: 10px; padding: 1.25rem; text-align: center; }
.dash-stat-num { display: block; font-size: 2rem; font-weight: 800; }
.dash-stat-label { font-size: 0.8rem; color: var(--text-dim); text-transform: uppercase; letter-spacing: 0.05em; }
.dash-cta { margin-top: 1rem; }
.dash-cta .meta { margin-top: 0.6rem; }
