/* =========================================================
   JoyWriter — shared theme tokens & base UI components
   Imported by index.html (designer), api.html, dynamic-url.html, login.html.
   ========================================================= */
:root {
  --bg-app:        #0E1116;
  --bg-panel:      #161A22;
  --bg-panel-alt:  #1B2029;
  --bg-input:      #0E1116;
  --bg-hover:      #232934;
  --border:        #232934;
  --border-strong: #2D343F;
  --text-primary:  #F2F5F9;
  --text-2:        #B6BCC8;
  --text-3:        #6B7280;
  --text-dim:      #4A5160;
  --accent:        #A78BFA;
  --accent-hover:  #C4B5FD;
  --accent-soft:   rgba(167, 139, 250, 0.12);
  --success:       #10B981;
  --error:         #F87171;
  --selected:      #6D28D9;
  --radius:        5px;
  --radius-lg:     7px;
  --shadow-1:      0 10px 30px rgba(0,0,0,0.35);
  --shadow-2:      0 20px 60px rgba(0,0,0,0.5);

  --font-sans: -apple-system, BlinkMacSystemFont, 'Inter', 'Segoe UI', Roboto, sans-serif;
  --font-mono: 'SF Mono', Menlo, 'JetBrains Mono', monospace;
}

* { box-sizing: border-box; margin: 0; padding: 0; }
html, body { height: 100%; }
body {
  font-family: var(--font-sans);
  background: var(--bg-app);
  color: var(--text-primary);
  font-size: 13px;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

/* Scrollbar */
::-webkit-scrollbar { width: 8px; height: 8px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border-strong); border-radius: 4px; }
::-webkit-scrollbar-thumb:hover { background: var(--text-dim); }

/* =========================================================
   Inline icons — base styling. All <svg class="icon"> bits
   inherit text color via currentColor and scale with font-size.
   ========================================================= */
.icon {
  width: 1em; height: 1em;
  vertical-align: -0.15em;
  flex-shrink: 0;
  fill: none;
  stroke: currentColor;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
}
.icon-lg { width: 1.25em; height: 1.25em; }

/* =========================================================
   APP HEADER — shared layout across all pages
   Grid : left brand · center tabs · right actions
   ========================================================= */
.app-header {
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  height: 52px;
  flex-shrink: 0;
  padding: 0 16px;
  background: var(--bg-panel);
  border-bottom: 1px solid var(--border);
  gap: 14px;
}
.hdr-left, .hdr-tabs, .hdr-right {
  display: flex;
  align-items: center;
  gap: 6px;
}
.hdr-right { justify-content: flex-end; }

.brand {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  font-size: 14px;
  font-weight: 700;
  color: var(--text-primary);
  text-decoration: none;
  padding: 4px 6px;
  letter-spacing: -0.01em;
}
.brand:hover { color: var(--accent); }
.brand .brand-mark {
  width: 18px; height: 18px;
  color: var(--accent);
}

.hdr-divider {
  width: 1px;
  height: 22px;
  background: var(--border-strong);
  margin: 0 4px;
}

/* =========================================================
   APP TABS — primary nav between Designer · API · Dynamic URL
   ========================================================= */
.app-tabs {
  display: inline-flex;
  align-items: center;
  gap: 2px;
  background: var(--bg-input);
  border: 1px solid var(--border-strong);
  padding: 3px;
  border-radius: 8px;
}
.app-tab {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  padding: 6px 12px;
  border-radius: 5px;
  font-size: 12px;
  font-weight: 600;
  color: var(--text-2);
  text-decoration: none;
  font-family: inherit;
  border: 0;
  background: transparent;
  cursor: pointer;
  transition: background 0.1s, color 0.1s;
  white-space: nowrap;
  line-height: 1;
}
.app-tab:hover {
  color: var(--text-primary);
  background: var(--bg-hover);
}
.app-tab .icon {
  width: 14px; height: 14px;
}
.app-tab.active {
  background: var(--bg-panel-alt);
  color: var(--accent);
  box-shadow: 0 1px 0 var(--accent) inset, 0 -1px 0 rgba(167, 139, 250, 0.3) inset;
}
.app-tab.active:hover {
  background: var(--bg-panel-alt);
  color: var(--accent);
}

/* =========================================================
   BUTTONS — primary / secondary / ghost
   ========================================================= */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  font-family: inherit;
  font-size: 12px;
  font-weight: 600;
  padding: 7px 14px;
  border-radius: var(--radius);
  border: 1px solid transparent;
  cursor: pointer;
  line-height: 1;
  transition: background 0.1s, opacity 0.1s, border-color 0.1s, color 0.1s;
  white-space: nowrap;
  font-family: inherit;
}
.btn:disabled { opacity: 0.4; cursor: not-allowed; }
.btn .icon { width: 14px; height: 14px; }

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

.btn-secondary {
  background: var(--bg-panel-alt);
  color: var(--text-primary);
  border-color: var(--border-strong);
}
.btn-secondary:hover:not(:disabled) { background: var(--bg-hover); }

.btn-ghost {
  background: transparent;
  color: var(--text-2);
  border-color: var(--border-strong);
}
.btn-ghost:hover:not(:disabled) { color: var(--text-primary); background: var(--bg-hover); }

.btn-sm { padding: 5px 10px; font-size: 11px; }

/* Icon-only button */
.icon-btn {
  width: 30px; height: 30px;
  display: inline-flex;
  align-items: center; justify-content: center;
  background: transparent;
  border: 1px solid transparent;
  color: var(--text-2);
  border-radius: var(--radius);
  cursor: pointer;
  padding: 0;
  transition: background 0.1s, color 0.1s;
  font-family: inherit;
}
.icon-btn:hover { background: var(--bg-hover); color: var(--text-primary); }
.icon-btn.active {
  background: var(--accent-soft); color: var(--accent);
  border-color: rgba(167, 139, 250, 0.25);
}
.icon-btn .icon { width: 16px; height: 16px; }

/* =========================================================
   FIELDS
   ========================================================= */
.field { margin-bottom: 12px; }
.field > label {
  display: block;
  font-size: 11px;
  color: var(--text-2);
  margin-bottom: 5px;
  font-weight: 600;
}
.field input[type="text"],
.field input[type="number"],
.field input[type="url"],
.field input[type="email"],
.field input[type="password"],
.field textarea,
.field select {
  width: 100%;
  padding: 8px 10px;
  background: var(--bg-input);
  border: 1px solid var(--border-strong);
  color: var(--text-primary);
  border-radius: var(--radius);
  font-size: 12px;
  font-family: inherit;
  transition: border-color 0.1s;
}
.field input:focus,
.field textarea:focus,
.field select:focus {
  outline: 0;
  border-color: var(--accent);
}
.field textarea { resize: vertical; min-height: 60px; }
.field input[type="checkbox"] { width: 16px; height: 16px; cursor: pointer; }

/* =========================================================
   COLOR INPUT
   ========================================================= */
.color-input {
  display: flex;
  align-items: center;
  gap: 8px;
  background: var(--bg-input);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius);
  padding: 4px 10px 4px 4px;
}
.color-input:focus-within { border-color: var(--accent); }
.color-input input[type="color"] {
  width: 32px; height: 28px;
  padding: 0; border: 0; border-radius: 3px;
  cursor: pointer; background: transparent;
}
.color-input input[type="text"] {
  flex: 1;
  background: transparent; border: 0; padding: 0;
  color: var(--text-primary);
  font-family: var(--font-mono);
  font-size: 12px;
}
.color-input input[type="text"]:focus { outline: 0; }

/* =========================================================
   RANGE / SLIDER ROW
   ========================================================= */
.slider-row {
  display: grid;
  grid-template-columns: 80px 1fr;
  gap: 10px;
  align-items: center;
}
.slider-row input[type="number"] { width: 100%; }
input[type="range"] {
  -webkit-appearance: none;
  appearance: none;
  height: 4px;
  background: var(--border-strong);
  border-radius: 2px;
  outline: 0;
}
input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 14px; height: 14px;
  border-radius: 50%;
  background: var(--accent);
  cursor: pointer;
}
input[type="range"]::-moz-range-thumb {
  width: 14px; height: 14px;
  border-radius: 50%;
  background: var(--accent);
  cursor: pointer;
  border: 0;
}

/* =========================================================
   SWITCH (toggle)
   ========================================================= */
.switch {
  position: relative;
  display: inline-block;
  width: 34px;
  height: 18px;
  flex-shrink: 0;
}
.switch input { opacity: 0; width: 0; height: 0; }
.switch .slider-pill {
  position: absolute;
  cursor: pointer;
  inset: 0;
  background: var(--text-dim);
  border-radius: 18px;
  transition: 0.15s;
}
.switch .slider-pill:before {
  position: absolute;
  content: '';
  height: 14px; width: 14px;
  left: 2px; bottom: 2px;
  background: white;
  border-radius: 50%;
  transition: 0.15s;
}
.switch input:checked + .slider-pill { background: var(--accent); }
.switch input:checked + .slider-pill:before { transform: translateX(16px); }

/* =========================================================
   CODE BLOCKS + COPY
   ========================================================= */
.code-block {
  position: relative;
  margin: 8px 0;
}
.code-block pre {
  background: var(--bg-input);
  padding: 12px 14px;
  border-radius: var(--radius);
  font-family: var(--font-mono);
  font-size: 11px;
  line-height: 1.55;
  overflow-x: auto;
  white-space: pre-wrap;
  word-break: break-word;
  max-height: 220px;
  overflow-y: auto;
  border: 1px solid var(--border-strong);
  color: var(--text-primary);
}
.copy-btn {
  position: absolute;
  top: 6px; right: 6px;
  display: inline-flex;
  align-items: center;
  gap: 4px;
  background: var(--bg-panel-alt);
  color: var(--text-2);
  border: 1px solid var(--border-strong);
  padding: 4px 9px;
  font-size: 10px;
  font-weight: 600;
  border-radius: 4px;
  z-index: 1;
  opacity: 0;
  cursor: pointer;
  font-family: inherit;
  transition: opacity 0.15s, background 0.15s, color 0.15s;
}
.copy-btn .icon { width: 11px; height: 11px; }
.code-block:hover .copy-btn,
.copy-btn:focus { opacity: 1; }
.copy-btn:hover { background: var(--bg-hover); color: var(--text-primary); }
.copy-btn.copied {
  background: var(--success);
  color: #FFFFFF;
  border-color: var(--success);
  opacity: 1;
}

/* =========================================================
   TOAST
   ========================================================= */
.toast-stack {
  position: fixed;
  bottom: 20px; right: 20px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  z-index: 200;
  pointer-events: none;
}
.toast {
  background: var(--bg-panel);
  color: var(--text-primary);
  border: 1px solid var(--border-strong);
  border-left: 3px solid var(--accent);
  padding: 10px 16px;
  border-radius: var(--radius);
  font-size: 12px;
  font-weight: 500;
  box-shadow: var(--shadow-1);
  pointer-events: auto;
  animation: toast-in 0.18s ease-out;
}
.toast.success { border-left-color: var(--success); }
.toast.error   { border-left-color: var(--error); }
.toast.fading  { opacity: 0; transform: translateY(8px); transition: 0.2s; }
@keyframes toast-in {
  from { opacity: 0; transform: translateY(8px); }
  to   { opacity: 1; transform: translateY(0); }
}

/* =========================================================
   MOBILE BLOCKER — fullscreen message shown on phones for
   workspace pages (Designer / API / Dynamic URL). The
   designer UI is dense (toolbar + 2 sidebars + canvas) and
   doesn't shrink usefully below ~768px, so we hard-block
   editing there. /projects + /projects/:slug stay accessible
   on phones (they're just card grids).
   The blocker shows when the page actually contains a
   .mobile-blocker element — :has() scopes both rules so this
   theme.css file can be loaded by every page without hiding
   non-workspace content. No "continue anyway" — categorical
   block per user request.
   ========================================================= */
.mobile-blocker { display: none; }
@media (max-width: 767px) {
  body:has(.mobile-blocker) .mobile-blocker {
    display: flex;
    position: fixed;
    inset: 0;
    z-index: 9999;
    background: var(--bg-app);
    align-items: center;
    justify-content: center;
    padding: 36px 22px;
    text-align: center;
    overflow-y: auto;
  }
  body:has(.mobile-blocker) > *:not(.mobile-blocker):not(script) {
    visibility: hidden;
  }
}
.mobile-blocker-inner {
  max-width: 360px;
  display: flex;
  flex-direction: column;
  align-items: center;
  width: 100%;
}
.mobile-blocker .brand {
  font-size: 16px;
  margin-bottom: 30px;
  cursor: default;
}
.mobile-blocker .brand:hover { color: var(--text-primary); }
.mobile-blocker .icon-orb {
  width: 84px; height: 84px;
  display: flex; align-items: center; justify-content: center;
  border-radius: 50%;
  background: var(--accent-soft);
  border: 1px solid rgba(167, 139, 250, 0.3);
  margin-bottom: 22px;
}
.mobile-blocker .icon-orb svg {
  width: 38px; height: 38px;
  color: var(--accent);
}
.mobile-blocker h1 {
  font-size: 22px;
  font-weight: 700;
  color: var(--text-primary);
  margin-bottom: 10px;
  letter-spacing: -0.01em;
  line-height: 1.25;
}
.mobile-blocker p {
  color: var(--text-2);
  font-size: 13.5px;
  line-height: 1.55;
  margin-bottom: 28px;
}
.mobile-blocker .device-row {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 22px;
  margin-bottom: 26px;
  padding: 18px 14px;
  background: var(--bg-panel);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  width: 100%;
}
.mobile-blocker .device {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 7px;
  color: var(--text-2);
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}
.mobile-blocker .device svg {
  width: 32px; height: 32px;
  color: var(--accent);
  opacity: 0.95;
}
.mobile-blocker .device-sep {
  color: var(--text-3);
  font-size: 14px;
}
.mobile-blocker .home-link {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 11px 20px;
  border-radius: var(--radius);
  background: var(--accent);
  color: #0E1116;
  font-size: 13px;
  font-weight: 700;
  text-decoration: none;
}
.mobile-blocker .home-link:hover { background: var(--accent-hover); }

/* =========================================================
   UTILITY
   ========================================================= */
.empty-state {
  text-align: center;
  color: var(--text-3);
  padding: 24px 16px;
  font-size: 12px;
}
.kbd {
  display: inline-block;
  padding: 2px 6px;
  background: var(--bg-input);
  border: 1px solid var(--border-strong);
  border-radius: 4px;
  font-family: var(--font-mono);
  font-size: 10px;
  color: var(--text-primary);
}

/* =========================================================
   JoyWriter — extensions du thème partagé
   ========================================================= */
.page {
  max-width: 1100px;
  margin: 0 auto;
  padding: 28px 20px 60px;
}
.page-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 22px;
  flex-wrap: wrap;
}
.page-head h1 {
  font-size: 20px;
  font-weight: 700;
  letter-spacing: -0.01em;
}
.page-head .sub { color: var(--text-3); font-size: 12px; margin-top: 3px; }

/* Cards grid (clients, personas) */
.card-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
  gap: 14px;
}
.card {
  background: var(--bg-panel);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 16px;
  transition: border-color 0.1s, transform 0.1s;
}
a.card { text-decoration: none; color: inherit; display: block; }
a.card:hover { border-color: var(--accent); transform: translateY(-1px); }
.card h3 { font-size: 14px; font-weight: 700; margin-bottom: 4px; }
.card .meta { color: var(--text-3); font-size: 11px; }
.card .row { display: flex; justify-content: space-between; align-items: center; margin-top: 12px; }

/* Stat tiles */
.stat-row { display: grid; grid-template-columns: repeat(auto-fit, minmax(140px, 1fr)); gap: 12px; margin-bottom: 22px; }
.stat-tile {
  background: var(--bg-panel);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 14px 16px;
}
.stat-tile .v { font-size: 22px; font-weight: 700; letter-spacing: -0.02em; }
.stat-tile .l { color: var(--text-3); font-size: 11px; margin-top: 2px; }

/* Tables */
.tbl { width: 100%; border-collapse: collapse; font-size: 12px; }
.tbl th {
  text-align: left; padding: 8px 10px;
  color: var(--text-3); font-size: 10px; font-weight: 700;
  text-transform: uppercase; letter-spacing: 0.05em;
  border-bottom: 1px solid var(--border-strong);
}
.tbl td { padding: 10px; border-bottom: 1px solid var(--border); }
.tbl tr:hover td { background: var(--bg-hover); }
.tbl a { color: var(--text-primary); text-decoration: none; font-weight: 600; }
.tbl a:hover { color: var(--accent); }

/* Badges */
.badge {
  display: inline-flex; align-items: center; gap: 4px;
  padding: 2px 8px; border-radius: 999px;
  font-size: 10px; font-weight: 700;
  background: var(--bg-panel-alt); color: var(--text-2);
  border: 1px solid var(--border-strong);
}
.badge.score { color: #fff; border: 0; }
.badge.v2 { color: var(--accent); border-color: rgba(167,139,250,0.4); }
.badge.published { color: var(--success); border-color: rgba(16,185,129,0.4); }

/* Modal */
.modal-backdrop {
  position: fixed; inset: 0; z-index: 100;
  background: rgba(0,0,0,0.55);
  display: none; align-items: flex-start; justify-content: center;
  padding: 6vh 16px; overflow-y: auto;
}
.modal-backdrop.open { display: flex; }
.modal {
  background: var(--bg-panel);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-lg);
  width: 100%; max-width: 560px;
  box-shadow: var(--shadow-2);
}
.modal-head {
  display: flex; align-items: center; justify-content: space-between;
  padding: 14px 18px; border-bottom: 1px solid var(--border);
  font-size: 14px; font-weight: 700;
}
.modal-body { padding: 18px; }
.modal-foot {
  display: flex; justify-content: flex-end; gap: 8px;
  padding: 12px 18px; border-top: 1px solid var(--border);
}

/* Tabs (client page) */
.tabs { display: flex; gap: 2px; border-bottom: 1px solid var(--border-strong); margin-bottom: 20px; }
.tab {
  padding: 9px 16px; font-size: 12px; font-weight: 600;
  color: var(--text-2); background: none; border: 0; cursor: pointer;
  border-bottom: 2px solid transparent; font-family: inherit;
}
.tab:hover { color: var(--text-primary); }
.tab.active { color: var(--accent); border-bottom-color: var(--accent); }

/* Article preview (rendered HTML) */
.article-preview {
  background: var(--bg-panel);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 30px 36px;
  font-size: 14px; line-height: 1.7;
  color: var(--text-primary);
  max-width: 100%;
}
.article-preview h2 { font-size: 19px; margin: 26px 0 10px; letter-spacing: -0.01em; }
.article-preview h3 { font-size: 15px; margin: 20px 0 8px; }
.article-preview p { margin: 0 0 13px; color: var(--text-2); }
.article-preview ul, .article-preview ol { margin: 0 0 13px 22px; color: var(--text-2); }
.article-preview li { margin-bottom: 5px; }
.article-preview strong { color: var(--text-primary); }
.article-preview table { border-collapse: collapse; margin: 14px 0; width: 100%; font-size: 13px; }
.article-preview th, .article-preview td { border: 1px solid var(--border-strong); padding: 8px 10px; text-align: left; }
.article-preview th { background: var(--bg-panel-alt); }
.article-preview blockquote {
  border-left: 3px solid var(--accent); margin: 14px 0; padding: 6px 14px;
  color: var(--text-2); background: var(--bg-panel-alt); border-radius: 0 var(--radius) var(--radius) 0;
}
.article-preview a { color: var(--accent); }

/* Quality panel */
.quality-bar { display: flex; align-items: center; gap: 14px; flex-wrap: wrap; }
.score-circle {
  width: 62px; height: 62px; border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  font-size: 19px; font-weight: 800; color: #fff;
  flex-shrink: 0;
}
.crit { display: flex; justify-content: space-between; gap: 10px; padding: 7px 0; border-bottom: 1px solid var(--border); font-size: 12px; }
.crit:last-child { border-bottom: 0; }
.crit .n { color: var(--text-2); }
.crit .d { color: var(--text-3); font-size: 11px; margin-top: 2px; }
.crit .s { font-weight: 700; flex-shrink: 0; }

/* Two-column layout (article page) */
.split { display: grid; grid-template-columns: 1fr 320px; gap: 20px; align-items: start; }
@media (max-width: 900px) { .split { grid-template-columns: 1fr; } }
.side-panel {
  background: var(--bg-panel);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 16px;
  position: sticky; top: 16px;
}
.side-panel h3 { font-size: 12px; font-weight: 700; text-transform: uppercase; letter-spacing: 0.05em; color: var(--text-3); margin-bottom: 12px; }
.side-panel + .side-panel { margin-top: 14px; }

/* Editor */
.editor-area {
  width: 100%; min-height: 420px;
  background: var(--bg-input);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius);
  color: var(--text-primary);
  font-family: var(--font-mono);
  font-size: 12px; line-height: 1.6;
  padding: 14px; resize: vertical;
}
.editor-area:focus { outline: 0; border-color: var(--accent); }

/* Spinner */
.spinner {
  width: 16px; height: 16px;
  border: 2px solid rgba(255,255,255,0.25);
  border-top-color: currentColor;
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
  display: inline-block; vertical-align: -3px;
}
@keyframes spin { to { transform: rotate(360deg); } }

.wizard-options { display: flex; flex-wrap: wrap; gap: 14px; }
.wizard-options label { display: flex; align-items: center; gap: 6px; font-size: 12px; color: var(--text-2); cursor: pointer; }

.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 0 14px; }
@media (max-width: 640px) { .form-grid { grid-template-columns: 1fr; } }
