/* =========================================================
   Joylayer — 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:        #22D3EE;
  --accent-hover:  #4DDFEF;
  --accent-soft:   rgba(34, 211, 238, 0.12);
  --success:       #10B981;
  --error:         #F87171;
  --selected:      #0E7490;
  --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(34, 211, 238, 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(34, 211, 238, 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); }
}

/* =========================================================
   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);
}
