/* =================================================
   THEME STUDIO — single authoritative stylesheet
   All Theme Studio styles live here and only here
   ================================================= */

/* Overlay */
.theme-studio-overlay{background:rgba(2,6,23,.82);backdrop-filter:blur(12px);padding:24px}
.theme-studio-overlay.open{display:flex}

/* Shell */
.theme-studio-shell{
  width:min(1320px,96vw);
  height:min(880px,92vh);
  background:linear-gradient(180deg,#0f172a,#111827 42%,#020617);
  border:1px solid rgba(148,163,184,.22);
  border-radius:24px;
  box-shadow:0 30px 100px rgba(0,0,0,.55);
  display:flex;
  flex-direction:column;
  overflow:hidden;
  color:#e5eefc;
  font-family:Inter,system-ui,-apple-system,sans-serif;
}

/* Top bar */
.theme-studio-topbar{
  flex-shrink:0;
  display:flex;
  justify-content:space-between;
  align-items:center;
  gap:16px;
  padding:18px 24px;
  border-bottom:1px solid rgba(148,163,184,.16);
  background:linear-gradient(180deg,rgba(255,255,255,.04),rgba(255,255,255,.01));
}
.theme-studio-title{font-size:24px;font-weight:700;letter-spacing:-.03em;color:#fff}
.theme-studio-subtitle{font-size:13px;color:#94a3b8;margin-top:4px;max-width:700px;line-height:1.5}
.theme-studio-top-actions{display:flex;gap:10px;align-items:center;flex-shrink:0}

/* Layout — fills all space between topbar and actionbar */
.theme-studio-layout{
  flex:1;
  min-height:0;
  display:grid;
  grid-template-columns:minmax(290px,360px) minmax(0,1fr) minmax(270px,330px);
  gap:16px;
  padding:16px 18px;
  overflow:hidden;
}

/* Panels */
.theme-studio-panel{
  background:rgba(15,23,42,.72);
  border:1px solid rgba(148,163,184,.14);
  border-radius:20px;
  padding:16px;
  overflow-y:auto;
  overflow-x:hidden;
  min-height:0;
}

/* Preview stage */
.theme-studio-stage{min-width:0;display:flex;flex-direction:column;min-height:0}
.theme-studio-stage-card{
  flex:1;
  position:relative;
  background:radial-gradient(circle at top,#1e293b,#0f172a 70%);
  border:1px solid rgba(148,163,184,.16);
  border-radius:24px;
  padding:18px;
  display:flex;
  flex-direction:column;
  min-height:0;
}
.theme-studio-live-frame{
  flex:1;
  min-height:0;
  display:flex;
  align-items:center;
  justify-content:center;
  overflow:auto;
  border-radius:18px;
  background:linear-gradient(135deg,#0b1220,#111827);
  border:1px solid rgba(148,163,184,.12);
  padding:18px;
}

/* Library panel */
.theme-studio-library-panel{display:flex;flex-direction:column}
.theme-studio-library-panel .theme-studio-library-list{flex:1;min-height:100px;overflow-y:auto;display:flex;flex-direction:column;gap:8px;padding-right:2px}

/* Action bar — pinned at bottom, never overlaps */
.theme-studio-actionbar{
  flex-shrink:0;
  display:flex;
  flex-wrap:wrap;
  align-items:center;
  justify-content:flex-end;
  gap:10px;
  padding:13px 20px 17px;
  border-top:1px solid rgba(148,163,184,.12);
  background:linear-gradient(180deg,rgba(15,23,42,.94),rgba(2,6,23,.98));
}
.theme-studio-actionbar-note{margin-right:auto;color:#94a3b8;font-size:13px;line-height:1.35;max-width:440px}

/* Buttons */
.theme-studio-close,
.theme-studio-reset-top,
.theme-studio-ghost,
.theme-studio-actionbar button,
.theme-studio-preset-row button,
.theme-studio-library-item button,
.theme-studio-library-actions button{
  font:600 13px/1.1 Inter,system-ui,sans-serif;
  border:1px solid rgba(148,163,184,.16);
  border-radius:12px;
  padding:10px 14px;
  cursor:pointer;
  transition:transform .15s ease,background .15s ease;
  white-space:nowrap;
}
.theme-studio-close{background:#8b5cf6;color:#fff;border-color:#8b5cf6}
.theme-studio-close:hover{background:#7c3aed}
.theme-studio-reset-top{background:rgba(148,163,184,.12);color:#cbd5e1}
.theme-studio-reset-top:hover{background:rgba(148,163,184,.2)}
.theme-studio-ghost{background:rgba(148,163,184,.12);color:#cbd5e1}
.theme-studio-ghost:hover{background:rgba(148,163,184,.2);transform:translateY(-1px)}
.theme-studio-primary{
  background:linear-gradient(135deg,#7c3aed,#8b5cf6);
  color:#fff;
  border:none;
  border-radius:12px;
  padding:12px 22px;
  font:700 14px/1.1 Inter,system-ui,sans-serif;
  cursor:pointer;
  box-shadow:0 4px 18px rgba(139,92,246,.4);
  transition:transform .15s ease,box-shadow .15s ease;
  white-space:nowrap;
}
.theme-studio-primary:hover{transform:translateY(-1px);box-shadow:0 8px 24px rgba(139,92,246,.55)}
.theme-studio-actionbar button:not(.theme-studio-ghost):not(.theme-studio-primary){background:#8b5cf6;color:#fff;border-color:#8b5cf6}
.theme-studio-preset-row button{background:#0b1220;color:#e5eefc;text-align:left}
.theme-studio-preset-row button:hover{background:rgba(139,92,246,.16);transform:translateY(-1px)}
.theme-studio-library-actions button{background:#0b1220;color:#e5eefc}
.theme-studio-library-actions button:hover{background:rgba(139,92,246,.16)}
.theme-studio-library-item button{background:rgba(139,92,246,.14);color:#ddd6fe;padding:8px 10px;border-radius:10px}
.theme-studio-library-item button:hover{background:rgba(139,92,246,.26);transform:translateY(-1px)}

/* Panel titles */
.theme-studio-panel-title{font-size:12px;font-weight:700;letter-spacing:.12em;text-transform:uppercase;color:#93c5fd;margin-bottom:12px}
.theme-studio-panel-title-spaced{margin-top:16px}

/* Groups */
.theme-studio-group{background:rgba(255,255,255,.03);border:1px solid rgba(148,163,184,.12);border-radius:16px;padding:14px;margin-bottom:12px}
.theme-studio-group-title{font-size:11px;font-weight:700;letter-spacing:.12em;text-transform:uppercase;color:#cbd5e1;margin-bottom:10px}
.theme-studio-group label{display:flex;justify-content:space-between;align-items:center;font-size:11px;color:#94a3b8;letter-spacing:.08em;text-transform:uppercase;margin:8px 0 6px}
.theme-studio-group input[type="text"],.theme-studio-group select{width:100%;background:#0b1220;border:1px solid rgba(148,163,184,.18);color:#e5eefc;border-radius:12px;padding:10px 12px;font:500 13px/1.2 Inter,system-ui,sans-serif;box-sizing:border-box}
.theme-studio-group input[type="color"]{width:100%;height:42px;border-radius:12px;border:1px solid rgba(148,163,184,.18);background:#0b1220;padding:4px;cursor:pointer;display:block}
.theme-studio-group input[type="range"]{width:100%}

/* Friendly field labels */
.theme-studio-field{display:block;margin:0 0 10px}
.theme-studio-field span{display:block;font-size:12px;font-weight:700;color:#f8fafc;margin-bottom:3px}
.theme-studio-field small{display:block;font-size:11px;color:#94a3b8;margin-bottom:6px;line-height:1.35}
.theme-studio-field input[type="color"]{width:100%;height:46px;border-radius:12px;border:1px solid rgba(148,163,184,.18);background:#0b1220;padding:4px;cursor:pointer;display:block}
.theme-studio-field input[type="text"],.theme-studio-field input[type="url"]{width:100%;background:#0b1220;border:1px solid rgba(148,163,184,.18);color:#e5eefc;border-radius:12px;padding:10px 12px;font:500 13px/1.2 Inter,system-ui,sans-serif;box-sizing:border-box}
.theme-studio-field-wide{margin-bottom:12px}

/* Colour grids */
.theme-studio-colour-grid{display:grid;grid-template-columns:1fr 1fr;gap:10px;margin-top:8px}

/* Preset row */
.theme-studio-preset-row{display:grid;grid-template-columns:1fr 1fr;gap:8px;margin-bottom:10px}

/* More options */
.theme-studio-more{margin-top:10px;background:rgba(255,255,255,.025);border:1px solid rgba(148,163,184,.12);border-radius:14px;overflow:hidden}
.theme-studio-more summary{list-style:none;cursor:pointer;color:#dbeafe;font:700 11px/1 Inter,system-ui,sans-serif;letter-spacing:.08em;text-transform:uppercase;padding:12px 14px;background:rgba(148,163,184,.08)}
.theme-studio-more summary::-webkit-details-marker{display:none}
.theme-studio-more[open] summary{border-bottom:1px solid rgba(148,163,184,.12)}
.theme-studio-more .theme-studio-group{margin:12px}

/* Library */
.theme-studio-library-list{display:flex;flex-direction:column;gap:8px}
.theme-studio-library-item{background:#0b1220;border:1px solid rgba(148,163,184,.14);border-radius:14px;padding:12px}
.theme-studio-library-item-header{display:flex;justify-content:space-between;gap:8px;align-items:flex-start;margin-bottom:8px}
.theme-studio-library-item-name{font:600 13px/1.2 Inter,system-ui,sans-serif;color:#fff}
.theme-studio-library-swatches{display:flex;gap:6px;margin-bottom:10px}
.theme-studio-library-swatches span{width:18px;height:18px;border-radius:50%;border:1px solid rgba(255,255,255,.12);display:block}
.theme-studio-library-item-actions{display:flex;gap:8px;flex-wrap:wrap}
.theme-studio-library-help{font-size:12px;line-height:1.4;color:#94a3b8;margin-bottom:10px}
.theme-studio-library-actions{display:grid;grid-template-columns:1fr 1fr;gap:8px;margin-top:10px;padding-top:10px;border-top:1px solid rgba(148,163,184,.12)}

/* Preview elements */
.theme-studio-preview-badge{position:absolute;top:14px;right:14px;z-index:2;background:rgba(15,23,42,.72);border:1px solid rgba(148,163,184,.22);border-radius:999px;color:#cbd5e1;font:800 10px/1 Inter,system-ui,sans-serif;letter-spacing:.12em;text-transform:uppercase;padding:7px 10px;pointer-events:none}
.theme-studio-preview-window{width:min(720px,100%);background:#111827;border:1px solid #334155;border-radius:16px;overflow:hidden;box-shadow:0 24px 60px rgba(0,0,0,.35)}
.theme-studio-preview-titlebar{padding:12px 14px;background:linear-gradient(180deg,#1f2937,#0f172a);color:#f8fafc;font:600 13px/1.1 Inter,system-ui,sans-serif}
.theme-studio-preview-body{padding:18px;background:#111827;color:#f8fafc;font:500 14px/1.4 Inter,system-ui,sans-serif}
.theme-studio-preview-brand{font-family:"VT323",monospace;font-size:56px;line-height:1;color:#fff;margin-bottom:6px}
.theme-studio-preview-brand span{color:#8b5cf6}
.theme-studio-preview-tag{font-size:13px;color:#cbd5e1;margin-bottom:16px}
.theme-studio-preview-search{background:#1f2937;border:1px solid #334155;border-radius:16px;padding:14px;margin-bottom:16px}
.theme-studio-preview-search-title{font-size:12px;font-weight:700;color:#8b5cf6;letter-spacing:.1em;text-transform:uppercase;margin-bottom:10px}
.theme-studio-preview-search-bar{background:#0f172a;border:1px solid #334155;border-radius:12px;padding:12px 14px;color:#e5eefc;margin-bottom:12px}
.theme-studio-preview-search-buttons{display:flex;gap:10px}
.theme-studio-preview-search-buttons span{display:inline-flex;align-items:center;justify-content:center;padding:10px 14px;background:#8b5cf6;color:#fff;border-radius:12px;font:600 12px/1 Inter,system-ui,sans-serif;pointer-events:none;user-select:none}
.theme-studio-preview-links{display:flex;gap:10px;flex-wrap:wrap}
.theme-studio-preview-chip{padding:10px 12px;background:#1f2937;border:1px solid #334155;border-radius:999px;color:#cbd5e1;font:600 12px/1 Inter,system-ui,sans-serif}
.theme-studio-preview-taskbar{margin-top:10px;padding:7px 10px;border:1px solid var(--ts-border-color,#334155);border-radius:var(--ts-radius,12px);background:var(--ts-taskbar,#0f172a);color:#fff;display:flex;align-items:center;justify-content:space-between;gap:8px;font:700 11px/1 Inter,system-ui,sans-serif}
.theme-studio-preview-tab{border:1px solid rgba(51,65,85,.7);border-radius:999px;padding:4px 8px;background:var(--ts-tab,#374151)}
.theme-studio-live-note{margin-top:12px;font-size:12px;color:#94a3b8;flex-shrink:0}

/* Toast */
.theme-studio-toast{position:fixed;right:22px;bottom:22px;background:#0f172a;color:#fff;border:1px solid rgba(148,163,184,.18);border-radius:14px;padding:12px 14px;box-shadow:0 18px 40px rgba(0,0,0,.28);z-index:10050;opacity:0;transform:translateY(8px);pointer-events:none;transition:opacity .18s ease,transform .18s ease}
.theme-studio-toast.show{opacity:1;transform:translateY(0)}

/* Custom theme overrides */
body.custom a{color:var(--link,var(--accent2))}
body.custom .module-head .tb-title,body.custom .titlebar .tb-title{color:var(--panel-title,var(--tb-text))}
body.custom .tbtn,body.custom .add-btn,body.custom .modal-btns button,body.custom .modal-footer button{color:var(--btnText,var(--text-inv))}

/* Responsive */
@media(max-width:1120px){
  .theme-studio-layout{grid-template-columns:300px minmax(0,1fr)}
  .theme-studio-library-panel{grid-column:1/-1;max-height:220px}
  .theme-studio-library-panel .theme-studio-library-list{max-height:120px}
  .theme-studio-library-actions{grid-template-columns:repeat(3,1fr)}
  .theme-studio-actionbar-note{display:none}
}
@media(max-width:820px){
  .theme-studio-overlay{padding:10px}
  .theme-studio-shell{width:100vw;height:100vh;border-radius:0}
  .theme-studio-layout{grid-template-columns:1fr;overflow-y:auto}
  .theme-studio-panel{overflow-y:visible}
  .theme-studio-live-frame{min-height:300px}
  .theme-studio-preview-brand{font-size:40px}
  .theme-studio-topbar{padding:16px}
  .theme-studio-title{font-size:20px}
  .theme-studio-actionbar{justify-content:stretch}
  .theme-studio-actionbar button{flex:1 1 calc(50% - 5px)}
  .theme-studio-actionbar-note{display:none}
}
