:root {
  --bg: #F6F4F0;
  --surface: #FFFFFF;
  --surface2: #EDEAE2;
  --border: #D8D3C8;
  --text: #1C1A17;
  --text-secondary: #6B655C;
  --accent: #1E4F7A;
  --accent-hover: #163D5E;
  --accent-light: #EBF2FA;
  --green: #1F8B4C;
  --green-hover: #166F3B;
  --red: #B91C1C;
  --red-light: #FEE2E2;
  --orange: #D97706;
  --orange-light: #FEF3C7;
  --gold: #F5C842;
  --gold-light: #FFF8E1;
  --shadow: 0 1px 3px rgba(0,0,0,.06), 0 4px 14px rgba(0,0,0,.04);
  --shadow-hover: 0 4px 12px rgba(0,0,0,.08), 0 12px 40px rgba(0,0,0,.06);
  --radius: 12px;
  --radius-sm: 8px;
  --transition: .25s cubic-bezier(.4,0,.2,1);
}

[data-theme="dark"] {
  --bg: #121212;
  --surface: #1E1E1E;
  --surface2: #2A2A2A;
  --border: #3A3A3A;
  --text: #E8E3D8;
  --text-secondary: #A8A098;
  --accent: #4A8DC7;
  --accent-hover: #5A9DD7;
  --accent-light: #1A2A3A;
  --green: #34B86A;
  --green-hover: #44C87A;
  --red: #EF4444;
  --red-light: #3A1A1A;
  --orange: #F59E0B;
  --orange-light: #3A2A0A;
  --gold: #F5C842;
  --gold-light: #3A2A0A;
  --shadow: 0 1px 3px rgba(0,0,0,.3), 0 4px 14px rgba(0,0,0,.2);
  --shadow-hover: 0 4px 12px rgba(0,0,0,.4), 0 12px 40px rgba(0,0,0,.3);
}

* { box-sizing: border-box; margin: 0; padding: 0; }
body {
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 14px;
  line-height: 1.6;
  min-height: 100vh;
  transition: background var(--transition), color var(--transition);
}

::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: var(--bg); }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 10px; }
::-webkit-scrollbar-thumb:hover { background: var(--text-secondary); }

.layout { display: grid; grid-template-columns: 280px 1fr; min-height: calc(100vh - 72px); }

.web-header {
  position: sticky;
  top: 0;
  z-index: 70;
  display: grid;
  grid-template-columns: auto minmax(220px, 420px) auto;
  align-items: center;
  gap: 28px;
  justify-content: space-between;
  min-height: 72px;
  padding: 12px 28px;
  border-bottom: 1px solid var(--border);
  background: color-mix(in srgb, var(--surface) 94%, transparent);
  box-shadow: 0 8px 28px rgba(0, 0, 0, .14);
  backdrop-filter: blur(18px);
}
.web-header-brand { display: grid; gap: 3px; min-width: 250px; }
.web-header-brand .brand-mark-row { gap: 7px; align-items: center; }
.web-header-brand .brand-wordmark { font-size: 28px; }
.web-header-brand .brand-icon { width: 25px; height: 20px; }
.web-header-subtitle { color: var(--accent); font-size: 9px; font-style: italic; font-weight: 500; letter-spacing: .08em; text-transform: uppercase; white-space: nowrap; }
.web-header-search { display: flex; align-items: center; gap: 8px; min-width: 0; height: 40px; padding: 0 13px; border: 1px solid var(--border); border-radius: 10px; background: var(--bg); color: var(--accent); }
.web-header-search:focus-within { border-color: var(--accent); box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 18%, transparent); }
.web-header-search input { width: 100%; min-width: 0; border: 0; outline: 0; background: transparent; color: var(--text); font: 500 13px/1.2 'Inter', sans-serif; }
.web-header-search input::placeholder { color: var(--text-secondary); }
.web-header-actions { display: flex; align-items: center; gap: 8px; }
.web-header-actions button, .web-options-menu summary { min-height: 38px; padding: 0 13px; border: 1px solid var(--border); border-radius: 9px; background: var(--surface2); color: var(--text); font: 700 12px/1 'Inter', sans-serif; cursor: pointer; }
.web-header-actions button:hover, .web-options-menu summary:hover { border-color: var(--accent); color: var(--accent); }
.web-header-help { background: transparent !important; }
.web-header-help { width: 38px; padding-inline: 0 !important; border-radius: 50% !important; color: var(--accent) !important; font: 700 19px/1 'Rajdhani', sans-serif !important; }
.web-options-menu { position: relative; }
.web-options-menu summary { display: inline-flex; align-items: center; gap: 8px; list-style: none; }
.web-options-menu summary::-webkit-details-marker { display: none; }
.web-options-menu summary span { color: var(--text-secondary); font-size: 10px; }
.web-options-content { position: absolute; top: calc(100% + 8px); right: 0; z-index: 90; display: grid; gap: 6px; width: 230px; padding: 10px; border: 1px solid var(--border); border-radius: 11px; background: var(--surface); box-shadow: var(--shadow-hover); }
.web-options-content button { width: 100%; min-height: 36px; padding: 8px 10px; text-align: left; }
.web-option-group { display: grid; gap: 5px; padding-bottom: 5px; border-bottom: 1px solid var(--border); }
.web-option-group label { color: var(--text-secondary); font: 700 10px/1 'Rajdhani', sans-serif; letter-spacing: .1em; text-transform: uppercase; }
.web-option-group select { width: 100%; min-height: 34px; }
.institutional-breadcrumb { margin-top: 8px; color: var(--accent); font: 700 12px/1 'Rajdhani', sans-serif; letter-spacing: .06em; }
.category-expand-toggle { display: inline-flex; width: 24px; min-width: 24px; height: 30px; align-items: center; justify-content: center; border: 0; background: transparent; color: var(--accent); font: 700 20px/1 'Rajdhani', sans-serif; cursor: pointer; }
.category-expand-toggle:hover { color: var(--text); }
.mobile-category-return { display: none; }

aside {
  background: var(--surface);
  border-right: 1px solid var(--border);
  display: flex; flex-direction: column;
  position: sticky; top: 0; height: 100vh;
  overflow-y: auto;
  transition: background var(--transition), border-color var(--transition);
}

.sb-head {
  padding: 24px 20px 16px;
  border-bottom: 1px solid var(--border);
}
.sb-head h1 {
  font-size: 18px;
  font-weight: 700;
  letter-spacing: -.02em;
}
.sb-head h1 span { color: var(--accent); }
.sb-head p {
  font-size: 10px;
  color: var(--text-secondary);
  letter-spacing: .08em;
  text-transform: uppercase;
  font-weight: 500;
  margin-top: 2px;
}
.theme-toggle {
  width: 100%;
  margin-top: 10px;
  padding: 6px 12px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--text);
  font-family: 'Inter', sans-serif;
  font-size: 12px;
  font-weight: 500;
  cursor: pointer;
  transition: all var(--transition);
  text-align: center;
}
.theme-toggle:hover {
  background: var(--surface2);
  border-color: var(--text-secondary);
}

.sb-search { padding: 12px 20px; }
.sb-search input {
  width: 100%;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 8px 14px;
  color: var(--text);
  font-family: 'Inter', sans-serif;
  font-size: 13px;
  outline: none;
  transition: all var(--transition);
}
.sb-search input::placeholder { color: var(--text-secondary); opacity: .6; }
.sb-search input:focus { border-color: var(--accent); box-shadow: 0 0 0 3px rgba(30,79,122,.15); }

.cat-lbl {
  padding: 12px 20px 4px;
  font-size: 10px;
  letter-spacing: .08em;
  text-transform: uppercase;
  color: var(--text-secondary);
  font-weight: 600;
}

nav ul {
  list-style: none;
  padding: 0 12px;
}

nav ul li {
  margin-bottom: 6px;
  list-style: none;
}

nav ul li a.cat-btn {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 8px 16px;
  border-radius: 8px;
  color: var(--text-secondary);
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  transition: all var(--transition);
  text-decoration: none;
  background: var(--bg);
  border: 1.5px solid var(--border);
  user-select: none;
}

nav ul li a.cat-btn:hover {
  background: var(--surface2);
  border-color: var(--text-secondary);
  color: var(--text);
}

nav ul li a.cat-btn.active {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
  font-weight: 600;
}

nav ul li a.cat-btn.active .nav-count {
  background: rgba(255,255,255,.2);
  color: #fff;
}

.nav-count {
  font-size: 11px;
  background: var(--surface2);
  padding: 0px 10px;
  border-radius: 12px;
  font-weight: 500;
  color: var(--text-secondary);
  transition: all var(--transition);
  pointer-events: none;
}

nav ul li.reorder-mode a.cat-btn {
  cursor: grab;
  border-style: dashed;
  border-color: var(--accent);
  background: var(--accent-light);
}

nav ul li.reorder-mode a.cat-btn:active {
  cursor: grabbing;
}

nav ul li.reorder-mode.drag-over a.cat-btn {
  background: var(--accent);
  color: #fff;
  border-color: var(--accent);
}

nav ul li.reorder-mode.drag-over .nav-count {
  background: rgba(255,255,255,.2);
  color: #fff;
}

nav ul li.reorder-mode.dragging a.cat-btn {
  opacity: .4;
  cursor: grabbing;
}

.sb-reorder {
  padding: 8px 20px 12px;
}
.sb-reorder .btn-reorder {
  width: 100%;
  padding: 8px 16px;
  border-radius: 8px;
  font-family: 'Inter', sans-serif;
  font-size: 12px;
  font-weight: 500;
  cursor: pointer;
  border: 1.5px solid var(--border);
  background: var(--bg);
  color: var(--text-secondary);
  transition: all var(--transition);
}
.sb-reorder .btn-reorder:hover {
  background: var(--surface2);
  border-color: var(--text-secondary);
}
.sb-reorder .btn-reorder.active {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
}
.sb-reorder .btn-reorder.active:hover {
  background: var(--accent-hover);
}

.sb-foot {
  margin-top: auto;
  padding: 16px 20px;
  border-top: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.sb-foot .config-section label {
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: .08em;
  color: var(--text-secondary);
  font-weight: 600;
  display: block;
  margin-bottom: 4px;
}
.sb-foot .config-section input {
  width: 100%;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 6px 12px;
  color: var(--text);
  font-family: 'Inter', sans-serif;
  font-size: 12px;
  outline: none;
  transition: all var(--transition);
}
.sb-foot .config-section input:focus { border-color: var(--accent); box-shadow: 0 0 0 3px rgba(30,79,122,.12); }

.sb-foot button {
  width: 100%;
  padding: 7px 12px;
  border-radius: var(--radius-sm);
  font-family: 'Inter', sans-serif;
  font-size: 12px;
  font-weight: 500;
  cursor: pointer;
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--text);
  transition: all var(--transition);
}
.sb-foot button:hover { background: var(--surface2); }
.sb-foot .btn-reset {
  border-color: var(--orange);
  color: var(--orange);
  background: var(--orange-light);
}
.sb-foot .btn-reset:hover {
  background: var(--orange);
  color: #fff;
}

/* Signature dock: a deliberately separate working aid, outside the crowded navigation rail. */
.signature-dock {
  display: grid;
  gap: 7px;
  width: min(100%, 340px);
  margin: 28px 0 0;
  padding: 13px 14px 14px;
  border: 1px solid var(--border);
  border-radius: 11px;
  background: color-mix(in srgb, var(--surface) 88%, transparent);
}
.signature-dock label {
  color: var(--text-secondary);
  font: 700 11px/1 'Rajdhani', sans-serif;
  letter-spacing: .1em;
  text-transform: uppercase;
}
.signature-dock input {
  width: 100%;
  min-height: 48px;
  padding: 10px 13px;
  border: 1px solid var(--border);
  border-radius: 9px;
  background: var(--surface2);
  color: var(--text);
  font-family: 'Rajdhani', sans-serif;
  font-size: 19px;
  font-style: italic;
  font-weight: 700;
  letter-spacing: .015em;
  line-height: 1;
  text-align: right;
  outline: none;
  transition: border-color var(--transition), box-shadow var(--transition), background-color var(--transition);
}
.signature-dock input::placeholder { text-align: right; font-style: italic; font-weight: 700; color: color-mix(in srgb, var(--text-secondary) 74%, transparent); }
.signature-dock input:focus { border-color: var(--accent); box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 18%, transparent); }

main { padding: 32px 40px; max-width: 1000px; }
main.is-initial-landing { max-width: none; width: 100%; }
.scriptz-initial-landing { display: grid; place-items: center; min-height: calc(100vh - 64px); }
.scriptz-initial-landing img { width: clamp(56px, 7.5vw, 94px); height: clamp(56px, 7.5vw, 94px); object-fit: contain; filter: drop-shadow(0 12px 20px rgba(0,0,0,.20)); }
main.is-initial-landing .top-bar { display: none; }
main.is-initial-landing .mobile-search-bar { display: none; }

.top-bar {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 28px;
  flex-wrap: wrap;
}
.top-bar h2 {
  font-size: 22px;
  font-weight: 700;
  letter-spacing: -.02em;
  flex: 1;
}
.top-bar .badge {
  font-size: 12px;
  background: var(--surface2);
  color: var(--text-secondary);
  padding: 4px 12px;
  border-radius: 20px;
  font-weight: 500;
}
.top-bar .sort-select {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 6px 12px;
  font-family: 'Inter', sans-serif;
  font-size: 12px;
  color: var(--text);
  cursor: pointer;
  outline: none;
  transition: all var(--transition);
}
.top-bar .sort-select:focus { border-color: var(--accent); }

.btn-add, .btn-export {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 7px 16px;
  border-radius: var(--radius-sm);
  font-family: 'Inter', sans-serif;
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
  transition: all var(--transition);
  border: none;
}
.btn-add {
  background: var(--accent);
  color: #fff;
}
.btn-add:hover { background: var(--accent-hover); transform: translateY(-1px); }
.btn-export {
  background: var(--surface2);
  color: var(--text);
  border: 1px solid var(--border);
}
.btn-export:hover { background: var(--border); transform: translateY(-1px); }

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  margin-bottom: 12px;
  box-shadow: var(--shadow);
  transition: all var(--transition);
}
.card:hover { box-shadow: var(--shadow-hover); }

.card-hd {
  display: flex;
  align-items: center;
  padding: 14px 18px;
  cursor: pointer;
  gap: 12px;
  border-radius: var(--radius);
  transition: background var(--transition);
}
.card-hd:hover { background: var(--bg); }
.card.open .card-hd { border-radius: var(--radius) var(--radius) 0 0; }

.card-info { flex: 1; min-width: 0; }
.card-title {
  font-size: 14px;
  font-weight: 600;
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

.card-tag {
  font-size: 10px;
  background: var(--surface2);
  color: var(--text-secondary);
  padding: 2px 10px;
  border-radius: 4px;
  font-weight: 500;
  display: inline-block;
  margin-top: 2px;
}

.card-btns {
  display: flex;
  gap: 4px;
  flex-shrink: 0;
  opacity: 0;
  max-height: 0;
  overflow: hidden;
  transition: opacity 0.4s ease, max-height 0.4s ease, margin 0.4s ease;
  margin: 0;
}

.card.open .card-btns {
  opacity: 1;
  max-height: 100px;
  margin: 0;
}

.btn {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 5px 10px;
  border-radius: var(--radius-sm);
  font-family: 'Inter', sans-serif;
  font-size: 12px;
  font-weight: 500;
  cursor: pointer;
  border: none;
  transition: all var(--transition);
  white-space: nowrap;
}
.btn-copy { background: var(--accent); color: #fff; }
.btn-copy:hover { background: var(--accent-hover); }
.btn-copy.ok { background: var(--green); }
.btn-ghost { background: var(--surface2); color: var(--text-secondary); }
.btn-ghost:hover { background: var(--border); color: var(--text); }
.btn-del {
  background: var(--red-light);
  color: var(--red);
  padding: 5px 10px;
}
.btn-del:hover {
  background: var(--red);
  color: #fff;
}

.fav-star {
  background: none;
  border: none;
  font-size: 20px;
  cursor: pointer;
  transition: all var(--transition);
  padding: 0 4px;
  opacity: 0.4;
  line-height: 1;
  color: var(--text-secondary);
}
.fav-star:hover {
  opacity: 0.9;
  transform: scale(1.15);
}
.fav-star.active {
  opacity: 1;
  color: #F5C842;
  text-shadow: 0 0 12px rgba(245, 200, 66, 0.4);
}

[data-theme="dark"] .fav-star {
  opacity: 0.6;
}
[data-theme="dark"] .fav-star.active {
  opacity: 1;
  text-shadow: 0 0 16px rgba(245, 200, 66, 0.6);
}

.chev {
  width: 16px;
  height: 16px;
  color: var(--text-secondary);
  transition: transform var(--transition);
  flex-shrink: 0;
}
.card.open .chev { transform: rotate(180deg); }

.card-body { display: none; border-top: 1px solid var(--border); }
.card.open .card-body { display: block; }

.preview-wrapper {
  padding: 12px 18px 4px 18px;
}

.preview-container {
  max-height: 600px;
  opacity: 1;
  padding: 0;
  overflow: visible;
}

.preview-container .preview {
  padding: 18px 22px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  font-size: 13.5px;
  line-height: 1.6;
  margin-top: 4px;
  border-left: 3px solid var(--accent);
}
.preview-container .preview p { margin-bottom: 0.8em; }
.preview-container .preview p:last-child { margin-bottom: 0; }
.preview-container .preview a { color: var(--accent); text-decoration: none; }
.preview-container .preview a:hover { text-decoration: underline; }
.preview-container .preview ul { padding-left: 1.5em; margin-bottom: 0.8em; }
.preview-container .preview li { margin-bottom: 0.2em; }

.editor-wrap {
  display: none;
  flex-direction: column;
  padding: 0 18px 12px 18px;
}
.editor-wrap.visible {
  display: flex;
}

.fmt-bar {
  display: flex;
  align-items: center;
  gap: 2px;
  padding: 6px 14px;
  border: 1px solid var(--border);
  border-bottom: none;
  border-radius: var(--radius-sm) var(--radius-sm) 0 0;
  background: var(--surface2);
  flex-wrap: wrap;
}

.fmt-btn {
  width: 30px;
  height: 30px;
  border-radius: var(--radius-sm);
  border: none;
  background: transparent;
  color: var(--text-secondary);
  cursor: pointer;
  font-size: 13px;
  font-weight: 600;
  transition: all var(--transition);
}
.fmt-btn:hover { background: var(--border); color: var(--text); }
.fmt-btn.active { background: var(--accent); color: #fff; }
.fmt-sep { width: 1px; height: 20px; background: var(--border); margin: 0 4px; }
.fmt-btn-link { font-size: 14px; }

.link-url-input {
  display: none;
  padding: 4px 12px;
  background: var(--surface2);
  border: 1px solid var(--border);
  border-top: none;
  gap: 6px;
  align-items: center;
}
.link-url-input.visible {
  display: flex;
}
.link-url-input input {
  flex: 1;
  padding: 4px 10px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  font-family: 'Inter', sans-serif;
  font-size: 12px;
  background: var(--bg);
  color: var(--text);
  outline: none;
}
.link-url-input input:focus {
  border-color: var(--accent);
}
.link-url-input button {
  padding: 4px 12px;
  border-radius: var(--radius-sm);
  border: none;
  background: var(--accent);
  color: #fff;
  font-family: 'Inter', sans-serif;
  font-size: 12px;
  font-weight: 500;
  cursor: pointer;
  transition: background var(--transition);
}
.link-url-input button:hover {
  background: var(--accent-hover);
}
.link-url-input .btn-ghost {
  background: transparent;
  color: var(--text-secondary);
  padding: 4px 8px;
  font-size: 11px;
}

[contenteditable] {
  padding: 18px 22px;
  min-height: 160px;
  font-family: 'Inter', sans-serif;
  font-size: 13.5px;
  line-height: 1.6;
  color: var(--text);
  outline: none;
  transition: background var(--transition);
  border: 1px solid var(--border);
  border-radius: 0 0 var(--radius-sm) var(--radius-sm);
  background: #faf8f5;
}

[data-theme="dark"] [contenteditable] {
  background: #1a1a1a;
}

[contenteditable]:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(30, 79, 122, 0.15);
}

[contenteditable] p { margin-bottom: 0.8em; }
[contenteditable] p:last-child { margin-bottom: 0; }
[contenteditable] a { color: var(--accent); }
[contenteditable] ul { padding-left: 1.5em; margin-bottom: 0.8em; }
[contenteditable] li { margin-bottom: 0.2em; }
[contenteditable]:empty::before { content: attr(data-placeholder); color: var(--text-secondary); opacity: .5; pointer-events: none; }

.edit-bar {
  display: flex;
  gap: 8px;
  align-items: center;
  padding: 8px 14px;
  background: var(--surface2);
  border: 1px solid var(--border);
  border-top: none;
  border-radius: 0 0 var(--radius-sm) var(--radius-sm);
  flex-wrap: wrap;
}
.edit-bar .title-field {
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 4px 10px;
  font-family: 'Inter', sans-serif;
  font-size: 12px;
  background: var(--bg);
  color: var(--text);
  outline: none;
  width: 180px;
}
.edit-bar .category-select {
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 4px 8px;
  font-family: 'Inter', sans-serif;
  font-size: 12px;
  background: var(--bg);
  color: var(--text);
  outline: none;
  width: 160px;
}
.edit-bar .category-select:focus { border-color: var(--accent); }
.edit-bar .title-field:focus { border-color: var(--accent); }
.edit-bar .editor-checkboxes {
  display: flex;
  gap: 16px;
  margin-left: auto;
  align-items: center;
}
.edit-bar .editor-checkboxes label {
  font-size: 12px;
  color: var(--text-secondary);
  display: flex;
  align-items: center;
  gap: 5px;
  cursor: pointer;
  font-weight: 500;
}
.edit-bar .editor-checkboxes input[type="checkbox"] {
  width: 15px;
  height: 15px;
  cursor: pointer;
}
.editor-meta .editor-greeting-label { gap: 7px; }
.editor-greeting-select { min-width: 180px; border: 1px solid var(--border); border-radius: 6px; padding: 5px 8px; background: var(--surface2); color: var(--text); font: 600 12px/1.2 'Inter', sans-serif; }
.editor-greeting-select:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 16%, transparent); }
.greeting-select.is-disabled,
.editor-greeting-select.is-disabled { color: var(--text-secondary); opacity: .7; }
.btn-save { background: var(--green); color: #fff; }
.btn-save:hover { background: var(--green-hover); }
.btn-save:disabled { opacity: .5; cursor: not-allowed; }

.overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,.5);
  backdrop-filter: blur(4px);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 200;
  opacity: 0;
  pointer-events: none;
  transition: opacity var(--transition);
}
.overlay[hidden] { display: none !important; }
.overlay.show { opacity: 1; pointer-events: all; }
.auth-overlay { z-index: 700; }
.modal {
  background: var(--surface);
  border-radius: var(--radius);
  padding: 28px 32px;
  width: 540px;
  max-width: 95vw;
  box-shadow: 0 20px 60px rgba(0,0,0,.2);
  transform: translateY(12px);
  transition: transform var(--transition);
}
.overlay.show .modal { transform: translateY(0); }
.modal h3 { font-size: 20px; font-weight: 700; margin-bottom: 20px; }
.auth-modal { display: flex; flex-direction: column; gap: 9px; }
.auth-modal label { display: flex; align-items: center; color: var(--text-secondary); font: 700 12px/1.2 'Rajdhani', sans-serif; letter-spacing: .06em; }
.auth-label-icon { display: inline-flex; width: 1.25em; height: 1.25em; margin-right: 2px; align-items: center; justify-content: center; color: var(--accent); font-size: 1.2em; line-height: 1; text-align: center; }
.auth-login-icon { color: #f59b45; font-size: 1em; font-weight: 700; }
.auth-modal input { width: 100%; min-height: 44px; box-sizing: border-box; padding: 11px 13px; font-size: 15px; }
.auth-modal .modal-actions { margin-top: 8px; }
.field { margin-bottom: 14px; }
.field label {
  display: block;
  font-size: 11px;
  font-weight: 600;
  color: var(--text-secondary);
  margin-bottom: 4px;
  letter-spacing: .05em;
  text-transform: uppercase;
}
.field input, .field select, .field textarea {
  width: 100%;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 8px 12px;
  font-family: 'Inter', sans-serif;
  font-size: 13.5px;
  color: var(--text);
  background: var(--bg);
  outline: none;
  transition: all var(--transition);
}
.field input:focus, .field select:focus, .field textarea:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(30,79,122,.12);
}
.field textarea { min-height: 100px; resize: vertical; line-height: 1.6; }
.checkbox-field {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 14px;
}
.checkbox-field input[type="checkbox"] {
  width: 16px;
  height: 16px;
  cursor: pointer;
}
.checkbox-field label {
  cursor: pointer;
  font-size: 13px;
  color: var(--text);
  font-weight: 400;
  text-transform: none;
}
@media (max-width: 820px) { .editor-greeting-select { flex: 1 1 180px; min-height: 34px; } }
.modal-btns { display: flex; gap: 8px; justify-content: flex-end; margin-top: 18px; }
.btn-primary {
  background: var(--accent);
  color: #fff;
  padding: 8px 20px;
  border-radius: var(--radius-sm);
  font-family: 'Inter', sans-serif;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  border: none;
  transition: all var(--transition);
}
.btn-primary:hover { background: var(--accent-hover); }
.btn-sec {
  background: var(--surface2);
  color: var(--text-secondary);
  padding: 8px 18px;
  border-radius: var(--radius-sm);
  font-family: 'Inter', sans-serif;
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  border: 1px solid var(--border);
  transition: all var(--transition);
}
.btn-sec:hover { background: var(--border); }

.toast {
  position: fixed;
  bottom: 24px;
  right: 24px;
  max-width: min(390px, calc(100vw - 40px));
  background: var(--surface);
  color: var(--text);
  padding: 11px 14px;
  border: 1px solid var(--border);
  border-left: 3px solid var(--accent);
  border-radius: 8px;
  font: 600 14px/1.35 'Rajdhani', sans-serif;
  box-shadow: var(--shadow-hover);
  opacity: 0;
  transform: translateY(8px);
  transition: opacity .18s cubic-bezier(.23,1,.32,1), transform .24s cubic-bezier(.23,1,.32,1);
  pointer-events: none;
  z-index: 300;
  display: flex;
  align-items: center;
  gap: 8px;
}
.toast.show { opacity: 1; transform: translateY(0); }
.toast .icon { color: var(--accent); font-size: 16px; }

.empty { text-align: center; padding: 60px 20px; color: var(--text-secondary); }
.empty .icon { font-size: 40px; margin-bottom: 12px; opacity: .4; }
.empty p { font-size: 14px; }

.drop-zone {
  border: 2px dashed var(--border);
  border-radius: var(--radius);
  padding: 30px;
  text-align: center;
  color: var(--text-secondary);
  transition: all var(--transition);
  cursor: pointer;
  margin-top: 12px;
}
.drop-zone.dragover {
  border-color: var(--accent);
  background: var(--accent-light);
}

.category-input-wrapper {
  position: relative;
}

.suggestions-list {
  position: absolute;
  top: 100%;
  left: 0;
  right: 0;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  max-height: 200px;
  overflow-y: auto;
  z-index: 100;
  display: none;
  box-shadow: var(--shadow-hover);
}
.suggestions-list.show {
  display: block;
}
.suggestions-list .suggestion-item {
  padding: 8px 12px;
  cursor: pointer;
  transition: background var(--transition);
  font-size: 13px;
  color: var(--text);
}
.suggestions-list .suggestion-item:hover {
  background: var(--accent-light);
}
.suggestions-list .suggestion-item.create-new {
  color: var(--accent);
  font-weight: 500;
  border-top: 1px solid var(--border);
}
.suggestions-list .suggestion-item.create-new:hover {
  background: var(--accent-light);
}
.suggestions-list .suggestion-item .highlight {
  font-weight: 600;
  color: var(--accent);
}

.modal-category {
    max-width: 500px;
}
.modal-category .category-list-loading {
    text-align: center;
    padding: 20px;
    color: var(--text-secondary);
}
#categoryListContainer {
    max-height: 350px;
    overflow-y: auto;
    margin-bottom: 16px;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    padding: 8px;
    background: var(--bg);
}
.category-item {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 8px 12px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    margin-bottom: 4px;
    cursor: grab;
    transition: all var(--transition);
}
.category-item:hover {
    border-color: var(--accent);
    box-shadow: var(--shadow-hover);
}
.category-item.dragging {
    opacity: 0.4;
    cursor: grabbing;
}
.category-item.drag-over {
    border-color: var(--accent);
    background: var(--accent-light);
}
.category-item .category-name {
    flex: 1;
    font-size: 14px;
    font-weight: 500;
    color: var(--text);
    cursor: pointer;
    padding: 4px 8px;
    border-radius: 4px;
    transition: background var(--transition);
}
.category-item .category-name:hover {
    background: var(--accent-light);
}
.category-item .category-name.editing {
    background: var(--accent-light);
    outline: 2px solid var(--accent);
    outline-offset: 2px;
}
.category-item .category-count {
    font-size: 12px;
    color: var(--text-secondary);
    background: var(--surface2);
    padding: 0px 8px;
    border-radius: 12px;
    margin: 0 8px;
}
.category-item .category-actions {
    display: flex;
    gap: 4px;
}
.category-item .category-actions button {
    background: none;
    border: none;
    cursor: pointer;
    font-size: 14px;
    padding: 4px 6px;
    border-radius: 4px;
    transition: all var(--transition);
}
.category-item .category-actions .btn-rename {
    color: var(--accent);
}
.category-item .category-actions .btn-rename:hover {
    background: var(--accent-light);
}
.category-item .category-actions .btn-delete {
    color: var(--red);
}
.category-item .category-actions .btn-delete:hover {
    background: var(--red-light);
}
.category-modal-actions {
    display: flex;
    gap: 8px;
    margin-bottom: 16px;
}
.category-modal-actions input {
    flex: 1;
    padding: 8px 12px;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    font-family: 'Inter', sans-serif;
    font-size: 13px;
    background: var(--bg);
    color: var(--text);
    outline: none;
    transition: all var(--transition);
}
.category-modal-actions input:focus {
    border-color: var(--accent);
    box-shadow: 0 0 0 3px rgba(30,79,122,.12);
}
.category-modal-actions .btn-primary {
    padding: 8px 16px;
    white-space: nowrap;
}

@media (max-width: 820px) {
  .layout { grid-template-columns: 1fr; }
  aside { position: static; height: auto; border-right: none; border-bottom: 1px solid var(--border); }
  main { padding: 20px; }
  .signature-dock { width: 100%; margin-top: 22px; }
  .sb-foot > .signature-dock {
    width: 100%;
    margin: 0 0 10px;
    padding: 0;
    border: 0;
    border-radius: 0;
    background: transparent;
  }
  .sb-foot > .signature-dock label,
  .sb-foot > .signature-dock input,
  .sb-foot > .signature-dock input::placeholder { text-align: left; }
  .sb-foot > .signature-dock input { width: 100% !important; max-width: none; }
}

@media (max-width: 480px) {
  .top-bar { flex-direction: column; align-items: stretch; }
  .card-hd { flex-wrap: wrap; }
  .card-btns { margin-top: 6px; flex-wrap: wrap; }
  .edit-bar { flex-direction: column; align-items: stretch; }
  .edit-bar .title-field { width: 100%; margin-left: 0; }
  .edit-bar .category-select { width: 100%; }
  .edit-bar .editor-checkboxes { margin-left: 0; width: 100%; justify-content: flex-start; }
  .modal { padding: 20px; }
  .modal-category { max-width: 100%; }
}


/* Scriptz visual system: navy-first dark workspace, Rajdhani-led brand hierarchy, crisp white mark, and restrained blue accents. */
:root {
  --bg: #0b1230;
  --surface: #101a43;
  --surface2: #162352;
  --border: #28376c;
  --text: #f6f7fb;
  --text-secondary: #aab6d8;
  --accent: #6d9dff;
  --accent-hover: #8bb4ff;
  --accent-light: #1a2b5e;
  --green: #43d18a;
  --green-hover: #64e09d;
  --red: #ff6b7d;
  --red-light: #3b1c36;
  --orange: #ffb45e;
  --orange-light: #3a2b23;
  --gold: #f5c842;
  --gold-light: #3a3218;
  --shadow: 0 2px 8px rgba(0,0,0,.18), 0 16px 40px rgba(3,8,28,.18);
  --shadow-hover: 0 4px 14px rgba(0,0,0,.24), 0 20px 50px rgba(3,8,28,.25);
  --radius: 14px;
  --radius-sm: 9px;
  --transition: .22s cubic-bezier(.23,1,.32,1);
}

[data-theme="dark"] {
  --bg: #0b1230;
  --surface: #101a43;
  --surface2: #162352;
  --border: #28376c;
  --text: #f6f7fb;
  --text-secondary: #aab6d8;
  --accent: #6d9dff;
  --accent-hover: #8bb4ff;
  --accent-light: #1a2b5e;
  --green: #43d18a;
  --green-hover: #64e09d;
  --red: #ff6b7d;
  --red-light: #3b1c36;
  --orange: #ffb45e;
  --orange-light: #3a2b23;
  --gold: #f5c842;
  --gold-light: #3a3218;
  --shadow: 0 2px 8px rgba(0,0,0,.18), 0 16px 40px rgba(3,8,28,.18);
  --shadow-hover: 0 4px 14px rgba(0,0,0,.24), 0 20px 50px rgba(3,8,28,.25);
}

body {
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
  background: radial-gradient(circle at 90% -10%, rgba(77,117,220,.14), transparent 34%), var(--bg);
  color: var(--text);
}

.sb-head {
  padding: 20px 20px 16px;
  background: linear-gradient(180deg, rgba(22,35,82,.72), rgba(16,26,67,.2));
}
.brand-lockup { display: flex; flex-direction: column; gap: 10px; }
.brand-mark-row { display: inline-flex; align-items: center; gap: 8px; min-height: 26px; }
.brand-icon { display: block; width: 24px; height: 18px; object-fit: contain; object-position: center; flex: 0 0 auto; }
.brand-wordmark { color: #fff; font-family: 'Rajdhani', 'Inter', sans-serif; font-size: 31px; line-height: .78; font-weight: 700; font-style: italic; letter-spacing: .01em; }
.brand-lockup p { margin-top: -2px; }

h1, h2, h3, .top-bar h2, .card-title, .btn-add, .btn-export, .btn, .theme-toggle, .btn-reorder, .modal h3 {
  font-family: 'Rajdhani', 'Inter', sans-serif;
  letter-spacing: .01em;
}
.top-bar h2 { font-size: 25px; font-weight: 700; }
.card-title { font-size: 16px; font-weight: 600; }

.theme-toggle, .btn-reorder, .btn-add, .btn-export, .btn, .btn-primary, .btn-sec {
  border-radius: 10px;
}
.theme-toggle { background: rgba(11,18,48,.65); border-color: var(--border); font-size: 14px; font-weight: 600; }
.theme-toggle:hover { background: var(--surface2); border-color: var(--accent); color: var(--text); }

.sb-search input, .sb-foot .config-section input, .top-bar .sort-select, .category-modal-actions input, .link-url-input input {
  background: rgba(11,18,48,.7);
  border-color: var(--border);
}
.sb-search input:focus, .sb-foot .config-section input:focus, .category-modal-actions input:focus, .link-url-input input:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(109,157,255,.16);
}

nav ul li a.cat-btn { background: rgba(11,18,48,.35); border-color: transparent; }
nav ul li a.cat-btn:hover { background: var(--surface2); border-color: var(--border); }
nav ul li a.cat-btn.active { background: linear-gradient(135deg, #446fc6, #31509a); border-color: #6d9dff; box-shadow: 0 8px 20px rgba(52,91,181,.22); }

.card { border-color: var(--border); background: linear-gradient(135deg, rgba(16,26,67,.98), rgba(14,23,58,.98)); }
.card-hd:hover { background: rgba(109,157,255,.06); }
.card-tag, .top-bar .badge, .btn-export, .btn-ghost { background: var(--surface2); }
.preview-container .preview { background: rgba(11,18,48,.72); border-color: var(--border); border-left-color: var(--accent); }
.fmt-bar { background: var(--surface2); }

.modal, .modal-category, .overlay .modal { background: var(--surface); border-color: var(--border); box-shadow: var(--shadow-hover); }
input, textarea, select { color-scheme: dark; }

@media (max-width: 820px) {
  .brand-mark-row { gap: 7px; }
  .brand-icon { width: 22px; height: 17px; }
  .brand-wordmark { font-size: 29px; }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .01ms !important; transition-duration: .01ms !important; }
}


/* Optional light mode: same Scriptz blue accents, with a readable warm-white workspace. */
[data-theme="light"] {
  --bg: #f4f6fb;
  --surface: #ffffff;
  --surface2: #e9eef8;
  --border: #cbd5e8;
  --text: #172047;
  --text-secondary: #596887;
  --accent: #3159a5;
  --accent-hover: #244787;
  --accent-light: #e5edff;
  --green: #1f8b4c;
  --green-hover: #166f3b;
  --red: #b91c1c;
  --red-light: #fee2e2;
  --orange: #b86200;
  --orange-light: #fff0d7;
  --gold: #a47700;
  --gold-light: #fff6cf;
  --shadow: 0 1px 3px rgba(25,41,85,.08), 0 10px 28px rgba(25,41,85,.08);
  --shadow-hover: 0 4px 12px rgba(25,41,85,.12), 0 16px 40px rgba(25,41,85,.12);
}
[data-theme="light"] body { background: var(--bg); }
[data-theme="light"] .sb-head { background: linear-gradient(180deg, #eef3ff, rgba(255,255,255,.3)); }
[data-theme="light"] .sb-search input,
[data-theme="light"] .sb-foot .config-section input,
[data-theme="light"] .top-bar .sort-select,
[data-theme="light"] .category-modal-actions input,
[data-theme="light"] .link-url-input input { background: #fff; }


/* Scriptz editing state: a distinct cobalt-navy work surface clearly separates editing from preview without leaving the brand palette. */
.card.editing {
  border-color: #6d9dff;
  box-shadow: 0 0 0 1px rgba(109,157,255,.24), 0 18px 48px rgba(2,8,31,.34);
}
.card.editing .card-hd {
  background: linear-gradient(90deg, rgba(65,104,193,.32), rgba(27,46,103,.18));
  border-bottom: 1px solid rgba(109,157,255,.28);
}
.card.editing .card-title::after {
  content: 'EDITANDO';
  display: inline-flex;
  align-items: center;
  padding: 2px 8px;
  border-radius: 999px;
  background: #6d9dff;
  color: #08122f;
  font-family: 'Rajdhani', 'Inter', sans-serif;
  font-size: 10px;
  font-weight: 700;
  letter-spacing: .08em;
}
.card.editing .preview-wrapper {
  background: #121f4b;
  border-left: 3px solid #6d9dff;
  padding-left: 15px;
}
.card.editing .preview-container .preview {
  background: #17285c;
  border-color: #3659a7;
  color: #dbe6ff;
}
.editor-wrap.visible {
  margin: 4px 18px 16px;
  padding: 0;
  border: 1px solid #3659a7;
  border-radius: 12px;
  overflow: hidden;
  background: #0e1a40;
  box-shadow: inset 0 1px 0 rgba(139,180,255,.12);
}
.editor-wrap.visible .fmt-bar {
  background: #203b7c;
  border: 0;
  border-bottom: 1px solid #426bc1;
  padding: 8px 14px;
}
.editor-wrap.visible .fmt-btn { color: #dbe6ff; }
.editor-wrap.visible .fmt-btn:hover { background: #3159a5; color: #fff; }
.editor-wrap.visible [contenteditable] {
  min-height: 150px;
  background: #0b1535;
  color: #f5f7ff;
  border: 0;
  outline: none;
  box-shadow: inset 0 0 0 1px rgba(109,157,255,.08);
}
.editor-wrap.visible [contenteditable]:focus {
  box-shadow: inset 0 0 0 2px rgba(109,157,255,.62);
}
.editor-wrap.visible .edit-bar {
  background: #162b5e;
  border-top: 1px solid #3659a7;
  padding: 10px 14px;
}
.editor-wrap.visible .btn-save {
  background: #6d9dff;
  color: #08122f;
  font-weight: 700;
}
.editor-wrap.visible .btn-save:hover { background: #8bb4ff; }


/* Scriptz light mode refinement: cool blue-white surfaces, navy typography, and the same cobalt action hierarchy as dark mode. */
[data-theme="light"] {
  --bg: #edf2fb;
  --surface: #ffffff;
  --surface2: #e3eaf8;
  --border: #c4d1e8;
  --text: #14234d;
  --text-secondary: #526486;
  --accent: #3159a5;
  --accent-hover: #244787;
  --accent-light: #dfeaff;
  --green: #18784a;
  --green-hover: #12603b;
  --red: #b4233c;
  --red-light: #fde5ea;
  --orange: #9a5b00;
  --orange-light: #fff0d7;
  --gold: #8a6700;
  --gold-light: #fff5c9;
  --shadow: 0 2px 8px rgba(34,58,112,.08), 0 14px 32px rgba(34,58,112,.08);
  --shadow-hover: 0 4px 14px rgba(34,58,112,.14), 0 20px 44px rgba(34,58,112,.12);
}
[data-theme="light"] body {
  background: linear-gradient(135deg, #f6f8fd 0%, #edf2fb 52%, #e8effb 100%);
}
[data-theme="light"] aside {
  background: linear-gradient(180deg, #f8faff 0%, #eaf0fb 100%);
  border-right-color: #c4d1e8;
}
[data-theme="light"] .sb-head {
  background: linear-gradient(180deg, #e5edff, rgba(248,250,255,.7));
  border-bottom-color: #c4d1e8;
}
[data-theme="light"] .brand-icon { filter: brightness(0) saturate(100%) invert(14%) sepia(30%) saturate(1360%) hue-rotate(190deg) brightness(83%) contrast(98%); }
[data-theme="light"] .brand-wordmark { color: #14234d; }
[data-theme="light"] .theme-toggle,
[data-theme="light"] .sb-search input,
[data-theme="light"] .sb-foot .config-section input,
[data-theme="light"] .top-bar .sort-select,
[data-theme="light"] .category-modal-actions input,
[data-theme="light"] .link-url-input input {
  background: #ffffff;
  border-color: #b9c9e4;
  color: #14234d;
}
[data-theme="light"] nav ul li a.cat-btn {
  background: rgba(255,255,255,.72);
  border-color: #d5e0f2;
  color: #526486;
}
[data-theme="light"] nav ul li a.cat-btn:hover {
  background: #e4ecfb;
  border-color: #a8bce0;
  color: #14234d;
}
[data-theme="light"] nav ul li a.cat-btn.active {
  background: linear-gradient(135deg, #3159a5, #244787);
  border-color: #3159a5;
  color: #ffffff;
}
[data-theme="light"] .card {
  background: rgba(255,255,255,.88);
  border-color: #c4d1e8;
}
[data-theme="light"] .card-hd:hover { background: #f2f6fd; }
[data-theme="light"] .preview-container .preview {
  background: #f6f8fd;
  border-color: #c4d1e8;
  border-left-color: #3159a5;
  color: #14234d;
}
[data-theme="light"] .card.editing {
  border-color: #3159a5;
  box-shadow: 0 0 0 1px rgba(49,89,165,.22), 0 18px 44px rgba(34,58,112,.16);
}
[data-theme="light"] .card.editing .card-hd {
  background: linear-gradient(90deg, #dce8ff, #edf3fd);
  border-bottom-color: #a9bfe8;
}
[data-theme="light"] .card.editing .preview-wrapper { background: #e6efff; border-left-color: #3159a5; }
[data-theme="light"] .card.editing .preview-container .preview { background: #f7faff; border-color: #afc4e8; color: #14234d; }
[data-theme="light"] .editor-wrap.visible { background: #e6efff; border-color: #9ab5e4; }
[data-theme="light"] .editor-wrap.visible .fmt-bar { background: #d1e0fb; border-bottom-color: #9ab5e4; }
[data-theme="light"] .editor-wrap.visible .fmt-btn { color: #244787; }
[data-theme="light"] .editor-wrap.visible .fmt-btn:hover { background: #3159a5; color: #fff; }
[data-theme="light"] .editor-wrap.visible [contenteditable] { background: #ffffff; color: #14234d; box-shadow: inset 0 0 0 1px #d0ddf0; }
[data-theme="light"] .editor-wrap.visible .edit-bar { background: #dbe8fb; border-top-color: #9ab5e4; }
[data-theme="light"] .btn-copy { background: #3159a5; }
[data-theme="light"] .btn-copy:hover { background: #244787; }
[data-theme="light"] .btn-export,
[data-theme="light"] .btn-ghost { background: #e3eaf8; color: #244787; border-color: #c4d1e8; }
[data-theme="light"] .btn-export:hover,
[data-theme="light"] .btn-ghost:hover { background: #d5e1f5; color: #14234d; }


/* Final light-mode precedence fixes for open and editing cards. */
[data-theme="light"] .card,
[data-theme="light"] .card.open,
[data-theme="light"] .card.editing {
  background: #ffffff !important;
  color: #14234d;
}
[data-theme="light"] .card.open .card-hd {
  background: #f5f8fe;
}
[data-theme="light"] .card.editing .card-hd {
  background: linear-gradient(90deg, #dce8ff, #f5f8fe);
}
[data-theme="light"] .card.editing .preview-wrapper {
  background: #e6efff;
}
[data-theme="light"] .card.editing .preview-container .preview {
  background: #ffffff;
  color: #14234d;
}
[data-theme="light"] .card.editing .card-title::after {
  background: #3159a5;
  color: #ffffff;
}
[data-theme="light"] .card-tag,
[data-theme="light"] .top-bar .badge {
  background: #e3eaf8;
  color: #526486;
}
[data-theme="light"] .chev,
[data-theme="light"] .fav-star {
  color: #526486;
}
[data-theme="light"] .fav-star.active {
  color: #8a6700;
}


/* Scriptz mobile adaptation: touch-first spacing, stacked navigation, readable cards, and full-width controls under 820px. */
@media (max-width: 820px) {
  html, body { min-width: 0; overflow-x: hidden; }
  .layout { display: block; min-height: 100vh; }
  aside {
    position: relative;
    width: 100%;
    height: auto;
    min-height: 0;
    border-right: 0;
    border-bottom: 1px solid var(--border);
  }
  .sb-head { padding: 14px 16px 12px; }
  .brand-lockup { gap: 8px; }
  .brand-mark-row { gap: 7px; }
  .brand-icon { width: 22px; height: 17px; }
  .brand-wordmark { font-size: 28px; }
  .brand-lockup p { font-size: 9px; letter-spacing: .08em; }
  .theme-toggle { width: 100%; min-height: 38px; }
  .sb-search { padding: 10px 16px; }
  .sb-search input { min-height: 40px; font-size: 14px; }
  #sidebarNav { padding: 0 16px 8px; }
  #sidebarNav ul { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 6px; }
  #sidebarNav .cat-lbl { margin: 8px 0 6px; }
  #sidebarNav ul li a.cat-btn { min-height: 38px; padding: 8px 10px !important; font-size: 12px !important; }
  .sb-reorder { padding: 0 16px 12px; }
  .btn-reorder { width: 100%; min-height: 40px; }
  .sb-foot { padding: 12px 16px 16px; }
  .sb-foot .config-section input, .btn-reset, .drop-zone { width: 100%; }
  .drop-zone { min-height: 72px; display: flex; align-items: center; justify-content: center; text-align: center; }
  main { min-width: 0; padding: 16px; }
  .top-bar { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 8px; align-items: center; margin-bottom: 16px; }
  .top-bar h2 { grid-column: 1 / -1; font-size: 25px; line-height: 1; margin-bottom: 2px; }
  .top-bar .badge { justify-self: start; }
  .top-bar .sort-select { min-width: 0; width: 100%; height: 38px; }
  .btn-export, .btn-add { width: 100%; min-height: 38px; padding: 8px 10px; white-space: nowrap; }
  .card { border-radius: 12px; }
  .card-hd { min-height: 58px; padding: 10px 12px; gap: 8px; align-items: flex-start; }
  .card-title { min-width: 0; font-size: 14px; line-height: 1.18; }
  .card-tag { font-size: 10px; max-width: 100%; }
  .card-btns { margin-left: auto; gap: 4px; flex-wrap: wrap; justify-content: flex-end; }
  .card-btns button { min-height: 30px; padding: 5px 7px; font-size: 11px; }
  .card-body { padding: 0 12px 12px; }
  .preview-container .preview { padding: 12px; font-size: 13px; line-height: 1.48; }
  .editor-wrap.visible { margin: 4px 12px 12px; }
  .editor-wrap.visible .fmt-bar { display: flex; flex-wrap: wrap; gap: 4px; padding: 7px 9px; }
  .editor-wrap.visible .fmt-btn { min-width: 32px; min-height: 32px; }
  .editor-wrap.visible [contenteditable] { min-height: 180px; padding: 12px; font-size: 14px; }
  .edit-bar { gap: 8px; padding: 9px 10px; }
  .edit-bar .title-field, .edit-bar .category-select { width: 100%; min-width: 0; }
  .edit-bar .editor-checkboxes { width: 100%; margin-left: 0; flex-wrap: wrap; }
  .modal, .modal-category { width: calc(100vw - 28px); max-width: none; max-height: calc(100vh - 28px); overflow-y: auto; padding: 18px; }
  .category-modal-actions { flex-wrap: wrap; }
  .category-modal-actions input, .category-modal-actions .btn-primary { width: 100%; flex: 1 1 100%; }
}

@media (max-width: 480px) {
  .sb-head { padding-inline: 12px; }
  .brand-wordmark { font-size: 26px; }
  #sidebarNav { padding-inline: 12px; }
  .sb-search, .sb-reorder, .sb-foot { padding-inline: 12px; }
  main { padding: 12px; }
  .top-bar { grid-template-columns: 1fr; }
  .top-bar h2, .top-bar .badge, .top-bar .sort-select, .btn-export, .btn-add { grid-column: 1; width: 100%; }
  .top-bar .badge { justify-self: start; }
  .card-hd { display: grid; grid-template-columns: minmax(0, 1fr) auto; }
  .card-btns { grid-column: 1 / -1; justify-content: flex-start; width: 100%; }
  .card-btns button { flex: 1 1 auto; }
  .card-title { font-size: 13px; }
  #sidebarNav ul { grid-template-columns: 1fr; }
}


/* Scriptz theme system v2: light, black, midnight blue, and dark purple with shared contrast rules. */
:root {
  --sidebar-width: 280px;
  --bg: #0b1224;
  --surface: #111a31;
  --surface2: #182442;
  --border: #2a3b62;
  --text: #f8fafc;
  --text-secondary: #aebbd4;
  --accent: #7da6ff;
  --accent-hover: #9abaff;
  --accent-light: #20345e;
  --green: #4ade80;
  --green-hover: #69ee9a;
  --red: #fb7185;
  --red-light: #3c1e32;
  --orange: #fbbf65;
  --orange-light: #3c2d22;
  --gold: #f5cf55;
  --gold-light: #3c341d;
  --shadow: 0 12px 32px rgba(0,0,0,.22);
  --shadow-hover: 0 16px 42px rgba(0,0,0,.32);
}

[data-theme="midnight"] {
  --bg: #071426;
  --surface: #0d1d36;
  --surface2: #15294a;
  --border: #29476e;
  --text: #f3f7ff;
  --text-secondary: #a9bbd6;
  --accent: #6f9eff;
  --accent-hover: #91b4ff;
  --accent-light: #1c3764;
  --green: #48d694;
  --red: #fb7185;
  --red-light: #402039;
  --orange: #ffbd67;
  --orange-light: #453022;
  --gold: #f5ce52;
  --gold-light: #423817;
}

[data-theme="black"] {
  --bg: #050505;
  --surface: #101010;
  --surface2: #191919;
  --border: #343434;
  --text: #f7f7f7;
  --text-secondary: #b4b4b4;
  --accent: #8db4ff;
  --accent-hover: #b0caff;
  --accent-light: #222b3b;
  --green: #53e39a;
  --red: #ff7b8f;
  --red-light: #3b2025;
  --orange: #ffc477;
  --orange-light: #3a2b1d;
  --gold: #f3d05b;
  --gold-light: #3a321a;
}

[data-theme="purple"] {
  --bg: #11001c;
  --surface: #1d0b2b;
  --surface2: #2b1240;
  --border: #50336c;
  --text: #fbf6ff;
  --text-secondary: #cdbada;
  --accent: #c7a0ff;
  --accent-hover: #dabdff;
  --accent-light: #42265b;
  --green: #64e5a5;
  --red: #ff829b;
  --red-light: #4a203c;
  --orange: #ffc27e;
  --orange-light: #4a3025;
  --gold: #f2d26b;
  --gold-light: #4b3b22;
}

[data-theme="light"] {
  --bg: #eef3fb;
  --surface: #ffffff;
  --surface2: #e5edf9;
  --border: #c6d3e8;
  --text: #17294c;
  --text-secondary: #526887;
  --accent: #315da8;
  --accent-hover: #244987;
  --accent-light: #dce8fb;
  --green: #19784a;
  --red: #b4233c;
  --red-light: #fde7eb;
  --orange: #995a00;
  --orange-light: #fff0d7;
  --gold: #866300;
  --gold-light: #fff5c7;
}

html, body { background: var(--bg); color: var(--text); }
.layout { grid-template-columns: var(--sidebar-width) minmax(0, 1fr); transition: grid-template-columns .18s ease-out; }
aside { position: relative; }
.sidebar-resize-handle { position: absolute; z-index: 8; top: 0; right: -4px; width: 8px; height: 100%; cursor: col-resize; background: transparent; transition: background .18s ease; }
.sidebar-resize-handle:hover, body.resizing-sidebar .sidebar-resize-handle { background: var(--accent); opacity: .7; }
body.resizing-sidebar, body.resizing-sidebar * { cursor: col-resize !important; user-select: none !important; }
.theme-control { display: grid; gap: 5px; min-width: 166px; }
.theme-control label { color: var(--text-secondary); font: 600 10px/1 'Rajdhani', sans-serif; letter-spacing: .12em; text-transform: uppercase; }
.theme-control select { width: 100%; min-height: 36px; padding: 7px 10px; border: 1px solid var(--border); border-radius: 8px; background: var(--surface2); color: var(--text); font: 600 12px/1 'Rajdhani', sans-serif; outline: none; cursor: pointer; }
.theme-control select:focus { border-color: var(--accent); box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 22%, transparent); }
.mobile-nav-toggle { display: none; }

/* Cross-theme component contrast. */
.card, .modal, .category-modal, .overlay .modal { background: var(--surface); color: var(--text); border-color: var(--border); }
.card-hd, .card-body, .preview-container, .editor-wrap.visible { border-color: var(--border); }
.card-hd:hover { background: color-mix(in srgb, var(--surface2) 70%, var(--surface)); }
.card.editing { border-color: var(--accent); box-shadow: 0 0 0 1px var(--accent), var(--shadow); }
.card.editing .preview-wrapper { background: var(--accent-light); border-left-color: var(--accent); }
.card.editing .preview-container .preview { background: color-mix(in srgb, var(--surface) 72%, var(--accent-light)); color: var(--text); border-color: var(--border); }
.card.editing .preview-container .preview { filter: saturate(.84) contrast(.97); opacity: .9; }
.editor-wrap.visible { background: color-mix(in srgb, var(--surface2) 78%, var(--accent-light)); border-color: var(--accent); }
.editor-wrap.visible .fmt-bar { background: var(--surface2); border-bottom-color: var(--border); }
.editor-wrap.visible .fmt-btn { color: var(--text-secondary); }
.editor-wrap.visible .fmt-btn:hover { background: var(--accent); color: var(--bg); }
.editor-wrap.visible [contenteditable] { background: var(--surface); color: var(--text); border-color: var(--border); }
.editor-wrap.visible .edit-bar { background: var(--surface2); border-top-color: var(--border); }
.btn-copy { background: var(--accent); color: var(--bg); }
.btn-copy:hover, .btn-primary:hover { background: var(--accent-hover); }
.btn-ghost { background: var(--surface2); color: var(--text-secondary); border-color: var(--border); }
.btn-ghost:hover { background: var(--accent-light); color: var(--text); }
input, select, textarea { background: var(--surface); color: var(--text); border-color: var(--border); }
input::placeholder, textarea::placeholder { color: color-mix(in srgb, var(--text-secondary) 75%, transparent); }

@media (max-width: 820px) {
  .layout { display: block; }
  body { overflow-x: hidden; }
  .mobile-nav-toggle { display: inline-flex; align-items: center; justify-content: center; min-height: 38px; padding: 8px 12px; border: 1px solid var(--border); border-radius: 9px; background: var(--surface); color: var(--text); font: 700 13px/1 'Rajdhani', sans-serif; }
  .top-bar { grid-template-columns: auto minmax(0, 1fr); }
  .top-bar h2 { grid-column: 1 / -1; }
  aside { position: fixed; inset: 0 auto 0 0; z-index: 30; width: min(86vw, 340px); height: 100dvh; overflow-y: auto; transform: translateX(-105%); transition: transform .22s cubic-bezier(.23,1,.32,1); box-shadow: 18px 0 48px rgba(0,0,0,.28); }
  body.mobile-nav-open aside { transform: translateX(0); }
  body.mobile-nav-open::after { content: ''; position: fixed; inset: 0; z-index: 20; background: rgba(2,8,20,.56); backdrop-filter: blur(2px); }
  .sidebar-resize-handle { display: none; }
  .sb-head { padding-top: max(14px, env(safe-area-inset-top)); }
  .theme-control { min-width: 0; }
  main { position: relative; z-index: 1; }
  .card-hd { min-height: 60px; }
  .card-btns button { min-height: 34px; }
}

@media (max-width: 480px) {
  .mobile-nav-toggle { width: auto; }
  .top-bar { gap: 7px; }
  .top-bar h2 { font-size: 24px; }
  .theme-control { grid-template-columns: 1fr; }
  .card-hd { grid-template-columns: minmax(0, 1fr) auto; }
  .card-btns { grid-column: 1 / -1; }
}


/* Final theme precedence: remove legacy white surfaces from non-light themes. */
[data-theme="black"] .card,
[data-theme="black"] .card.open,
[data-theme="black"] .card.editing,
[data-theme="midnight"] .card,
[data-theme="midnight"] .card.open,
[data-theme="midnight"] .card.editing,
[data-theme="purple"] .card,
[data-theme="purple"] .card.open,
[data-theme="purple"] .card.editing {
  background: var(--surface) !important;
  color: var(--text) !important;
}
[data-theme="black"] .card-hd,
[data-theme="midnight"] .card-hd,
[data-theme="purple"] .card-hd,
[data-theme="black"] .card-body,
[data-theme="midnight"] .card-body,
[data-theme="purple"] .card-body,
[data-theme="black"] .preview-container .preview,
[data-theme="midnight"] .preview-container .preview,
[data-theme="purple"] .preview-container .preview {
  background: var(--surface) !important;
  color: var(--text) !important;
  border-color: var(--border) !important;
}
[data-theme="black"] .card.open .card-hd,
[data-theme="midnight"] .card.open .card-hd,
[data-theme="purple"] .card.open .card-hd {
  background: var(--surface2) !important;
}
[data-theme="black"] .card.editing .card-hd,
[data-theme="midnight"] .card.editing .card-hd,
[data-theme="purple"] .card.editing .card-hd {
  background: color-mix(in srgb, var(--surface2) 78%, var(--accent-light)) !important;
}
[data-theme="black"] .card.editing .preview-container .preview,
[data-theme="midnight"] .card.editing .preview-container .preview,
[data-theme="purple"] .card.editing .preview-container .preview {
  background: color-mix(in srgb, var(--surface) 75%, var(--accent-light)) !important;
}
[data-theme="black"] .top-bar .badge,
[data-theme="midnight"] .top-bar .badge,
[data-theme="purple"] .top-bar .badge,
[data-theme="black"] .card-tag,
[data-theme="midnight"] .card-tag,
[data-theme="purple"] .card-tag {
  background: var(--surface2) !important;
  color: var(--text-secondary) !important;
}
[data-theme="black"] .brand-wordmark,
[data-theme="midnight"] .brand-wordmark,
[data-theme="purple"] .brand-wordmark,
[data-theme="black"] .card-title,
[data-theme="midnight"] .card-title,
[data-theme="purple"] .card-title { color: var(--text) !important; }


/* Mobile mail-style redesign: compact app bar, icon-first actions, searchable inbox, and a dismissible navigation drawer. */
.mobile-search-toggle,
.mobile-search-bar,
.mobile-nav-backdrop { display: none; }

@media (max-width: 820px) {
  body { background: var(--bg); }
  .web-header { display: none; }
  .web-header ~ .scriptz-help-button { display: inline-flex; }
  .layout { min-height: 100vh; }
  .mobile-only-control { display: block !important; }
  #sidebarNav .category-root-list,
  #sidebarNav .category-child-list { display: grid; grid-template-columns: 1fr; }
  .mobile-category-return { display: block; margin: 0 0 10px; }
  .mobile-category-return button { display: inline-flex; align-items: center; gap: 6px; min-height: 36px; padding: 7px 10px; border: 1px solid var(--border); border-radius: 8px; background: var(--surface); color: var(--text-secondary); font: 600 13px/1 'Inter', sans-serif; }
  .mobile-category-return button span { color: var(--accent); font: 700 22px/.7 'Rajdhani', sans-serif; }
  .sb-head .brand-lockup { display: block; }
  .sb-search { display: none; }
  #scriptzFirebaseAuthButton { display: inline-flex !important; }
  .layout { display: block; }
  main { padding: 0 12px 24px; }

  .top-bar {
    position: sticky;
    top: 0;
    z-index: 12;
    display: grid;
    grid-template-columns: auto minmax(0, 1fr) auto;
    grid-template-areas:
      "menu title search"
      "badge sort export"
      "add add add";
    gap: 8px;
    padding: 12px 2px 10px;
    margin: 0 -12px 12px;
    padding-inline: 12px;
    background: color-mix(in srgb, var(--bg) 92%, transparent);
    border-bottom: 1px solid color-mix(in srgb, var(--border) 75%, transparent);
    backdrop-filter: blur(16px);
  }
  .mobile-nav-toggle { grid-area: menu; display: inline-flex; width: 38px; height: 38px; padding: 0; align-items: center; justify-content: center; border: 1px solid var(--border); border-radius: 10px; background: var(--surface); color: var(--text); font-size: 0; }
  .mobile-nav-toggle::before { content: '☰'; font-size: 18px; line-height: 1; }
  body.mobile-nav-open .mobile-nav-toggle { background: var(--accent); color: var(--bg); border-color: var(--accent); }
  body.mobile-nav-open .mobile-nav-toggle::before { content: '✕'; }
  .top-bar h2 { grid-area: title; align-self: center; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 21px; line-height: 1.05; }
  .mobile-search-toggle { grid-area: search; display: inline-flex; width: 38px; height: 38px; align-items: center; justify-content: center; padding: 0; border: 1px solid var(--border); border-radius: 10px; background: var(--surface); color: var(--text); font-size: 24px; line-height: 1; }
  .mobile-search-toggle:hover, .mobile-search-toggle[aria-expanded="true"] { background: var(--accent); color: var(--bg); border-color: var(--accent); }
  .top-bar .badge { grid-area: badge; align-self: center; justify-self: start; max-width: 90px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; padding-inline: 9px; }
  .top-bar .sort-select { grid-area: sort; width: 100%; min-width: 0; height: 38px; }
  .btn-export { grid-area: export; width: 38px; min-height: 38px; padding: 0; justify-content: center; }
  .btn-export .btn-label { display: none; }
  .btn-export .btn-icon { font-size: 16px; }
  .btn-add { grid-area: add; width: 100%; min-height: 40px; justify-content: center; }
  .btn-add .btn-icon { font-size: 16px; }

  .mobile-search-bar { align-items: center; gap: 8px; margin: 0 0 12px; padding: 8px 10px; border: 1px solid var(--accent); border-radius: 12px; background: var(--surface); box-shadow: var(--shadow); }
  .mobile-search-bar.visible { display: flex; }
  .mobile-search-glyph { color: var(--accent); font-size: 22px; line-height: 1; }
  .mobile-search-bar input { flex: 1; min-width: 0; border: 0; outline: 0; background: transparent; color: var(--text); font: 500 14px/1.2 'Inter', sans-serif; }
  .mobile-search-bar button { width: 28px; height: 28px; border: 0; border-radius: 8px; background: var(--surface2); color: var(--text-secondary); font-size: 14px; }

  aside { position: fixed; inset: 0 auto 0 0; z-index: 40; width: min(88vw, 360px); height: 100dvh; overflow-y: auto; transform: translateX(-105%); transition: transform .24s cubic-bezier(.23,1,.32,1); box-shadow: 20px 0 55px rgba(0,0,0,.32); }
  body.mobile-nav-open aside { transform: translateX(0); }
  .mobile-nav-backdrop { position: fixed; inset: 0; z-index: 30; background: rgba(2,8,20,.62); backdrop-filter: blur(3px); }
  body.mobile-nav-open .mobile-nav-backdrop { display: block; }
  .sb-head { padding: max(58px, calc(env(safe-area-inset-top) + 54px)) 18px 16px; }
  .sb-search { display: none; }
  #sidebarNav { padding: 10px 14px; }
  #sidebarNav ul { display: block; padding: 0; }
  #sidebarNav ul li { margin-bottom: 6px; }
  #sidebarNav ul li a.cat-btn { min-height: 44px; padding: 10px 12px !important; font-size: 13px !important; }
  .sb-reorder { padding: 4px 18px 12px; }
  .sb-foot { padding: 14px 18px calc(18px + env(safe-area-inset-bottom)); }

  .card { margin-bottom: 9px; border-radius: 12px; }
  .card-hd { min-height: 56px; padding: 11px 12px; gap: 8px; }
  .card-title { font-size: 13px; line-height: 1.25; }
  .card-tag { max-width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  .card-btns { gap: 5px; }
  .card-btns .btn-copy,
  .card-btns .btn-ghost,
  .card-btns .btn-del { width: 34px; height: 32px; padding: 0; justify-content: center; font-size: 0; }
  .card-btns .btn-copy::before { content: '📋'; font-size: 16px; }
  .card-btns .btn-ghost::before { content: '✏️'; font-size: 15px; }
  .card-btns .btn-del::before { content: '🗑️'; font-size: 15px; }
  .fav-star { width: 34px; height: 32px; padding: 0; }
  .card-body { padding-bottom: 4px; }
  .preview-container .preview { padding: 13px 12px; font-size: 13px; }
}

@media (max-width: 480px) {
  .top-bar { grid-template-areas: "menu title search" "badge sort export" "add add add"; }
  .top-bar h2 { font-size: 20px; }
  .top-bar .sort-select { font-size: 11px; padding-inline: 8px; }
  .card-hd { grid-template-columns: minmax(0, 1fr) auto; }
  .card-btns { grid-column: 1 / -1; width: 100%; justify-content: flex-end; }
}


/* Mobile header refinement: envelope-only brand mark, compact primary action, and tighter drawer top. */
.mobile-brand-icon { display: none; }

@media (max-width: 820px) {
  .top-bar {
    grid-template-columns: auto minmax(0, 1fr) auto auto;
    grid-template-areas:
      "menu brand search add"
      "title title title title"
      "badge sort export export";
    align-items: center;
  }
  .mobile-brand-icon { grid-area: brand; display: inline-flex; align-items: center; justify-content: center; min-width: 0; }
  .mobile-brand-icon img { display: block; width: 22px; height: 17px; object-fit: contain; }
  .top-bar h2 { grid-area: title; font-size: 18px; line-height: 1.1; text-align: center; margin: 2px 0 0; }
  .btn-add { grid-area: add; width: 38px; min-height: 38px; height: 38px; padding: 0; justify-content: center; }
  .btn-add .btn-label { display: none; }
  .btn-add .btn-icon { font-size: 15px; }
  .top-bar .badge { grid-area: badge; }
  .top-bar .sort-select { grid-area: sort; }
  .btn-export { grid-area: export; justify-self: end; }
  .sb-head { padding-top: max(42px, calc(env(safe-area-inset-top) + 36px)); padding-bottom: 12px; }
}

@media (max-width: 480px) {
  .top-bar { grid-template-columns: auto minmax(0, 1fr) auto auto; }
  .mobile-brand-icon img { width: 20px; height: 16px; }
  .top-bar h2 { font-size: 17px; }
  .top-bar .sort-select { font-size: 10px; }
}

[data-theme="light"] .mobile-brand-icon img { filter: brightness(0) saturate(100%) invert(14%) sepia(30%) saturate(1360%) hue-rotate(190deg) brightness(83%) contrast(98%); }


/* Mobile header v18: category title shares the control row; drawer identity sits higher. */
@media (max-width: 820px) {
  .top-bar {
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto minmax(116px, 1.25fr) auto;
    grid-template-areas: "title badge sort add";
    gap: 7px;
    align-items: center;
    margin-bottom: 12px;
  }
  .mobile-nav-toggle, .mobile-brand-icon, .mobile-search-toggle { display: none !important; }
  .top-bar h2 { grid-area: title; min-width: 0; margin: 0; text-align: left; font-size: 17px; line-height: 1.1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  .top-bar .badge { grid-area: badge; justify-self: end; max-width: 112px; padding-inline: 7px; font-size: 10px; white-space: nowrap; }
  .top-bar .sort-select { grid-area: sort; width: 100%; min-width: 0; height: 34px; padding-inline: 7px; font-size: 10px; }
  .btn-export { display: none; }
  .btn-add { grid-area: add; width: 34px; min-height: 34px; height: 34px; padding: 0; justify-content: center; }
  .btn-add .btn-label { display: none; }
  .btn-add .btn-icon { font-size: 14px; }
  .sb-head { padding-top: max(30px, calc(env(safe-area-inset-top) + 24px)); padding-bottom: 10px; }
  .sb-head .sb-brand { transform: translateY(-5px); }
}
@media (max-width: 480px) {
  .top-bar { grid-template-columns: minmax(0, 1fr) auto minmax(104px, 1.1fr) auto; gap: 5px; }
  .top-bar h2 { font-size: 15px; }
  .top-bar .badge { max-width: 94px; font-size: 9px; }
  .top-bar .sort-select { font-size: 9px; }
}


/* Mobile header v18 correction: keep navigation/search actions reachable and lift the actual brand lockup. */
@media (max-width: 820px) {
  .top-bar {
    grid-template-columns: auto minmax(72px, 1fr) auto minmax(104px, 1.12fr) auto auto;
    grid-template-areas: "menu title badge sort search add";
    gap: 5px;
  }
  .mobile-nav-toggle { grid-area: menu; display: inline-flex !important; }
  .mobile-brand-icon { display: none !important; }
  .mobile-search-toggle { grid-area: search; display: inline-flex !important; width: 32px; height: 34px; align-items: center; justify-content: center; padding: 0; }
  .top-bar h2 { grid-area: title; }
  .sb-head .brand-lockup { transform: translateY(-5px); }
}
@media (max-width: 480px) {
  .top-bar { grid-template-columns: auto minmax(56px, 1fr) auto minmax(92px, 1.05fr) auto auto; gap: 4px; }
  .top-bar h2 { font-size: 14px; }
  .top-bar .sort-select { font-size: 8px; padding-inline: 5px; }
  .mobile-search-toggle { width: 29px; font-size: 17px; }
  .btn-add { width: 31px; height: 31px; min-height: 31px; }
}


/* Mobile header v19: fixed envelope rail, title/count stack, and larger touch targets. */
.mobile-fixed-brand { display: none; }
.title-stack { min-width: 0; }
@media (max-width: 820px) {
  main { padding-top: calc(66px + env(safe-area-inset-top)); }
  .scriptz-initial-landing { min-height: calc(100vh - 108px); }
  .scriptz-initial-landing img { width: 63px; height: 63px; }
  main.is-initial-landing .mobile-fixed-brand { opacity: 0; }
  .mobile-fixed-brand {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    z-index: 25;
    display: flex;
    align-items: center;
    justify-content: center;
    height: calc(54px + env(safe-area-inset-top));
    padding-top: env(safe-area-inset-top);
    background: var(--surface);
    border-bottom: 1px solid var(--border);
    box-shadow: 0 3px 14px rgba(0,0,0,.12);
  }
  .mobile-fixed-brand img { width: 28px; height: 22px; object-fit: contain; }
  [data-theme="light"] .mobile-fixed-brand img { filter: brightness(0) saturate(100%) invert(14%) sepia(30%) saturate(1360%) hue-rotate(190deg) brightness(83%) contrast(98%); }
  .top-bar {
    grid-template-columns: auto minmax(82px, 1fr) auto minmax(118px, 1.15fr) auto auto;
    grid-template-areas: "menu title badge sort search add";
    gap: 7px;
    margin-bottom: 16px;
  }
  .title-stack { grid-area: title; align-self: center; }
  .top-bar h2 { margin: 0; text-align: left; font-size: 17px; line-height: 1.12; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  .top-bar .badge { display: block; max-width: none; margin-top: 2px; padding: 0; background: transparent; color: var(--text-secondary); font-size: 11px; line-height: 1.15; text-align: left; }
  .top-bar .sort-select { height: 42px; min-width: 0; padding: 7px 10px; font-size: 11px; }
  .mobile-nav-toggle, .mobile-search-toggle, .btn-add { min-height: 42px; height: 42px; }
  .mobile-nav-toggle, .mobile-search-toggle { width: 42px; }
  .mobile-search-toggle { display: inline-flex !important; align-items: center; justify-content: center; padding: 0; }
  .btn-add { width: 42px; padding: 0; justify-content: center; }
  .btn-add .btn-label { display: none; }
  .btn-add .btn-icon { font-size: 16px; }
  .sb-head { padding-top: max(18px, calc(env(safe-area-inset-top) + 12px)); padding-bottom: 10px; }
  .sb-head .brand-lockup { transform: translateY(-8px); }
}
@media (max-width: 480px) {
  main { padding-top: calc(64px + env(safe-area-inset-top)); }
  .mobile-fixed-brand { height: calc(52px + env(safe-area-inset-top)); }
  .mobile-fixed-brand img { width: 26px; height: 20px; }
  .top-bar { grid-template-columns: auto minmax(70px, 1fr) auto minmax(105px, 1.08fr) auto auto; gap: 5px; }
  .top-bar h2 { font-size: 15px; }
  .top-bar .badge { font-size: 10px; }
  .top-bar .sort-select { height: 40px; font-size: 10px; padding-inline: 7px; }
  .mobile-nav-toggle, .mobile-search-toggle, .btn-add { width: 40px; height: 40px; min-height: 40px; }
}


/* Mobile badge v20: hidden when empty and sized to its text when present. */
.top-bar .badge[hidden] { display: none !important; }
@media (max-width: 820px) {
  .top-bar .badge {
    display: inline-flex;
    width: max-content;
    max-width: 100%;
    align-items: center;
    justify-self: start;
    margin-top: 3px;
    padding: 2px 7px;
    border-radius: 999px;
    background: var(--surface2);
    color: var(--text-secondary);
    font-size: 10px;
    line-height: 1.2;
    white-space: nowrap;
  }
}


/* Drawer typography v21: italic subtitle, slightly above the theme label, with clearer separation. */
.brand-lockup p {
  margin-top: 1px;
  margin-bottom: 11px;
  color: var(--accent);
  font-size: 11px;
  line-height: 1.25;
  font-style: italic;
  letter-spacing: .075em;
}
.theme-control { gap: 7px; }
@media (max-width: 820px) {
  .brand-lockup p { margin-top: 1px; margin-bottom: 10px; font-size: 10px; }
  .theme-control { gap: 7px; }
}


/* PWA install action and compact header v22. */
.install-app-btn {
  width: 100%;
  padding: 8px 12px;
  border: 1px solid var(--accent);
  border-radius: var(--radius-sm);
  background: var(--accent-light);
  color: var(--accent);
  font-family: 'Inter', sans-serif;
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
  transition: all var(--transition);
}
.install-app-btn:hover { background: var(--accent); color: #fff; }
.install-app-btn[hidden] { display: none; }
@media (max-width: 820px) {
  .mobile-fixed-brand { height: calc(46px + env(safe-area-inset-top)); }
  .mobile-fixed-brand img { width: 25px; height: 19px; }
  main { padding-top: calc(56px + env(safe-area-inset-top)); }
  .sb-head { padding-top: max(8px, calc(env(safe-area-inset-top) + 4px)); padding-bottom: 7px; }
  .sb-head .brand-lockup { transform: translateY(-10px); }
  .install-app-btn { font-size: 11px; padding: 8px 10px; }
}
@media (max-width: 480px) {
  .mobile-fixed-brand { height: calc(44px + env(safe-area-inset-top)); }
  main { padding-top: calc(54px + env(safe-area-inset-top)); }
}


/* Desktop sidebar v24: room for the full one-line subtitle without changing manual resizing. */
@media (min-width: 821px) {
  :root { --sidebar-width: 320px; }
  .brand-lockup p { white-space: nowrap; }
}


/* Desktop sidebar v25: full-height column that grows naturally instead of looking vertically boxed. */
@media (min-width: 821px) {
  aside {
    position: sticky;
    top: 0;
    align-self: stretch;
    height: auto;
    min-height: 100vh;
    max-height: none;
    overflow-y: visible;
  }
}


/* Desktop sidebar v26: fixed viewport column with scrollable categories and anchored footer. */
@media (min-width: 821px) {
  aside {
    position: sticky;
    top: 0;
    align-self: start;
    height: 100vh;
    min-height: 100vh;
    max-height: 100vh;
    overflow: hidden;
  }
  #sidebarNav {
    flex: 1 1 auto;
    min-height: 0;
    overflow-y: auto;
    scrollbar-gutter: stable;
  }
  .sb-reorder { flex: 0 0 auto; }
  .sb-foot { flex: 0 0 auto; margin-top: auto; }
}


/* Desktop sidebar v27: the complete sidebar scrolls independently, like the scripts menu. */
@media (min-width: 821px) {
  aside {
    height: 100vh;
    min-height: 100vh;
    max-height: 100vh;
    overflow-y: auto;
    overflow-x: hidden;
    scrollbar-gutter: stable;
  }
  #sidebarNav {
    flex: 0 0 auto;
    min-height: auto;
    overflow: visible;
    scrollbar-gutter: auto;
  }
}


/* Mobile drawer identity v29: slightly lower logo, wordmark, and subtitle as a single lockup. */
@media (max-width: 820px) {
  .sb-head .brand-lockup { transform: translateY(-4px); }
}


/* Mobile drawer identity v30: additional top clearance for browser chrome and safe-area cropping. */
@media (max-width: 820px) {
  .sb-head { padding-top: max(18px, calc(env(safe-area-inset-top) + 14px)); }
  .sb-head .brand-lockup { transform: translateY(2px); }
}


/* Mobile drawer identity v31: structural clearance, not transform-only positioning. */
@media (max-width: 820px) {
  .sb-head {
    padding-top: max(46px, calc(env(safe-area-inset-top) + 38px)) !important;
    padding-bottom: 12px;
  }
  .sb-head .brand-lockup {
    transform: none !important;
    position: relative;
    top: 0;
  }
}
@media (max-width: 480px) {
  .sb-head {
    padding-top: max(42px, calc(env(safe-area-inset-top) + 34px)) !important;
  }
}


/* Mobile drawer v32: explicit structural spacer above the identity; desktop remains unchanged. */
@media (max-width: 820px) {
  .sb-head::before {
    content: '';
    display: block;
    width: 100%;
    height: 32px;
  }
  .sb-head .brand-lockup { margin-top: 0; transform: none !important; }
}


/* Mobile drawer v33: explicit margin above the identity; desktop untouched. */
@media (max-width: 820px) {
  .sb-head .brand-lockup {
    margin-top: 32px !important;
    transform: none !important;
  }
}

/* Restore original mobile drawer identity position from v28. */
@media (max-width: 820px) {
  .sb-head::before { display: none !important; content: none !important; }
  .sb-head { padding-top: max(8px, calc(env(safe-area-inset-top) + 4px)) !important; padding-bottom: 7px !important; }
  .sb-head .brand-lockup { margin-top: 0 !important; transform: translateY(-10px) !important; }
}


/* Mobile brand balance v35: moderate top/bottom space, no accumulated offsets. */
@media (max-width: 820px) {
  .sb-head {
    padding: max(16px, calc(env(safe-area-inset-top) + 12px)) 18px 12px !important;
  }
  .sb-head .brand-lockup {
    margin: 0 !important;
    gap: 8px;
    transform: none !important;
  }
  .sb-head .brand-mark-row {
    min-height: 26px;
    gap: 8px;
  }
}


/* Editor v36: metadata belongs above the editing canvas on desktop and mobile. */
.editor-meta {
  display: grid;
  grid-template-columns: minmax(180px, 1.25fr) minmax(150px, .9fr) auto;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  margin-bottom: 8px;
  border: 1px solid color-mix(in srgb, var(--accent) 55%, var(--border));
  border-radius: 10px;
  background: color-mix(in srgb, var(--accent-light) 52%, var(--surface));
}
.editor-meta .title-field,
.editor-meta .category-select { min-width: 0; width: 100%; }
.editor-meta .editor-checkboxes { display: flex; flex-wrap: wrap; gap: 8px 12px; align-items: center; }
.card[draggable="true"] { cursor: grab; }
.card[draggable="true"]:active { cursor: grabbing; }
.card.dragging { opacity: .55; outline: 2px dashed var(--accent); }
@media (max-width: 820px) {
  .editor-meta { grid-template-columns: 1fr; gap: 8px; padding: 9px; }
  .editor-meta .editor-checkboxes { justify-content: flex-start; }
}


/* Custom script ordering controls: drag on desktop, explicit buttons on touch screens. */
.script-order-controls { display: inline-flex; gap: 3px; align-items: center; margin-left: auto; margin-right: 8px; }
.script-order-controls button { border: 1px solid var(--border); background: var(--surface2); color: var(--text-secondary); border-radius: 5px; min-width: 28px; min-height: 28px; cursor: pointer; }
.script-order-controls button:hover { color: var(--text); border-color: var(--accent); }
@media (max-width: 820px) {
  .script-order-controls button { min-width: 34px; min-height: 34px; font-size: 16px; }
}

/* Stabilization v59: explicit, interruptible feedback for themes and modal state. */
@media (prefers-reduced-motion: no-preference) {
  html.theme-transitioning body,
  html.theme-transitioning aside,
  html.theme-transitioning main,
  html.theme-transitioning .top-bar,
  html.theme-transitioning .card,
  html.theme-transitioning .modal,
  html.theme-transitioning .theme-control select,
  html.theme-transitioning input,
  html.theme-transitioning select,
  html.theme-transitioning textarea,
  html.theme-transitioning .preview-container .preview {
    transition-property: background-color, background, color, border-color, box-shadow, filter;
    transition-duration: .22s;
    transition-timing-function: cubic-bezier(.23,1,.32,1);
  }
}
.overlay .modal {
  opacity: 0;
  transform: translateY(12px) scale(.985);
  transition: opacity .18s cubic-bezier(.23,1,.32,1), transform .24s cubic-bezier(.23,1,.32,1);
}
.overlay.show .modal { opacity: 1; transform: translateY(0) scale(1); }
.modal:focus-visible { outline: 3px solid color-mix(in srgb, var(--accent) 60%, transparent); outline-offset: 3px; }
@media (max-width: 820px) {
  .overlay { padding: 14px; align-items: center; }
  .overlay .modal { width: min(100%, 620px); max-height: calc(100dvh - 28px); }
  .modal-btns { flex-wrap: wrap; gap: 10px; }
  .modal-btns .btn-primary, .modal-btns .btn-sec { min-height: 42px; flex: 1 1 140px; }
}

/* Category drag handle: explicit desktop and touch target. */
.category-drag-handle { display:inline-flex; align-items:center; justify-content:center; width:28px; min-width:28px; color:var(--text-secondary); cursor:grab; user-select:none; touch-action:none; font-size:20px; line-height:1; }
.category-drag-handle:active { cursor:grabbing; }
@media (max-width:820px) { .category-drag-handle { width:34px; min-width:34px; min-height:34px; font-size:22px; } }

/* Scriptz v41: context selection, standard-script protection, and first-run flow. */
.mode-control { margin-top: 10px; }
.top-actions { display: flex; align-items: center; gap: 8px; margin-left: auto; }
.context-search { display: flex; min-width: min(250px, 24vw); }
.context-search input { width: 100%; height: 36px; padding: 0 12px; border: 1px solid var(--border); border-radius: 9px; background: var(--surface2); color: var(--text); font: 500 13px/1.2 'Inter', sans-serif; outline: none; }
.context-search input::placeholder { color: var(--text-secondary); }
.context-search input:focus { border-color: var(--accent); box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 18%, transparent); }
.sr-only { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0, 0, 0, 0); white-space: nowrap; border: 0; }
.context-action { margin-top: 8px; border-color: var(--border); background: var(--surface2); color: var(--text); }
.context-action:hover { border-color: var(--accent); background: var(--accent-light); }
.standard-lock { display: inline-flex; width: 15px; height: 15px; margin-left: 6px; vertical-align: -2px; color: var(--gold); opacity: .82; }
.standard-lock svg { width: 100%; height: 100%; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.standard-lock:hover, .standard-lock:focus-visible { opacity: 1; color: color-mix(in srgb, var(--gold) 82%, var(--text)); outline: none; }
.standard-script { border-left: 3px solid var(--gold); }
.standard-script .card-hd { background: color-mix(in srgb, var(--gold-light) 30%, var(--surface)); }
.standard-script .btn[disabled], .standard-script input:disabled, .standard-script select:disabled { opacity: .42; filter: grayscale(.3); cursor: not-allowed; }
.standard-script .btn[disabled]:hover { transform: none; background: var(--surface2); color: var(--text-secondary); }
.standard-category { border-left: 2px solid var(--gold); }
.category-standard-lock { color: var(--gold); font-size: 12px; }
.standard-category .category-name { cursor: default; }
.standard-category .category-actions button:disabled { opacity: .36; cursor: not-allowed; }
.template-base-modal p { margin: -8px 0 20px; color: var(--text-secondary); font-size: 13px; line-height: 1.5; }
.template-base-grid, .welcome-choice-grid { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 12px; }
.template-base-grid button { min-height: 72px; padding: 12px; border: 1px solid var(--border); border-radius: 12px; background: var(--surface2); color: var(--text); font: 700 15px/1 'Rajdhani', sans-serif; cursor: pointer; transition: transform .16s cubic-bezier(.23,1,.32,1), background .16s ease, border-color .16s ease; }
.template-base-grid button:hover { transform: translateY(-2px); background: var(--accent-light); border-color: var(--accent); }

.welcome-screen { position: fixed; inset: 0; z-index: 500; display: grid; place-items: center; overflow: auto; padding: max(24px, env(safe-area-inset-top)) 24px max(24px, env(safe-area-inset-bottom)); background: radial-gradient(circle at 50% 10%, color-mix(in srgb, var(--accent) 32%, transparent), transparent 46%), var(--bg); color: var(--text); opacity: 0; transition: opacity .52s cubic-bezier(.23,1,.32,1); }
.welcome-screen[hidden] { display: none; }
html.scriptz-awaiting-onboarding .layout, html.scriptz-awaiting-daily-welcome .layout { visibility: hidden; pointer-events: none; }
.welcome-screen.visible { opacity: 1; }
.welcome-screen.leaving { opacity: 0; }
.welcome-splash { display: grid; justify-items: center; gap: 16px; opacity: 0; transform: translateY(14px) scale(.985); transition: opacity .56s cubic-bezier(.23,1,.32,1), transform .56s cubic-bezier(.23,1,.32,1); }
.welcome-splash.visible { opacity: 1; transform: translateY(0); }
.welcome-splash.leaving { opacity: 0; transform: translateY(-12px) scale(.99); }
.welcome-splash p { margin: 0; color: var(--text-secondary); font: 600 clamp(18px, 3vw, 28px)/1 'Rajdhani', sans-serif; letter-spacing: .08em; text-transform: uppercase; }
.welcome-splash div { display: flex; align-items: center; gap: 14px; font: 700 italic clamp(44px, 8vw, 80px)/.9 'Rajdhani', sans-serif; }
.welcome-splash img { width: clamp(52px, 7vw, 76px); height: auto; object-fit: contain; }
.welcome-menu { width: min(860px, 100%); opacity: 0; transform: translateY(16px) scale(.99); transition: opacity .58s cubic-bezier(.23,1,.32,1), transform .58s cubic-bezier(.23,1,.32,1); }
.welcome-menu.visible { opacity: 1; transform: translateY(0); }
.welcome-step { padding: clamp(28px, 5vw, 52px); border: 1px solid var(--border); border-radius: 22px; background: color-mix(in srgb, var(--surface) 90%, transparent); box-shadow: 0 28px 80px rgba(0,0,0,.22); text-align: center; }
.welcome-kicker { margin: 0 0 8px; color: var(--accent); font: 700 13px/1 'Rajdhani', sans-serif; letter-spacing: .16em; text-transform: uppercase; }
.welcome-step h1 { margin: 0 0 28px; font: 700 clamp(30px, 5vw, 48px)/.95 'Rajdhani', sans-serif; letter-spacing: -.02em; }
.welcome-brand-inline { display: inline-flex; align-items: center; gap: .12em; white-space: nowrap; color: #fff; font-style: italic; }
.welcome-brand-inline img { width: .8em; height: .8em; object-fit: contain; vertical-align: -.05em; }
.welcome-brand-inline strong { font-weight: 700; }
.welcome-choice-grid button { min-height: 132px; padding: 18px; border: 1px solid var(--border); border-radius: 18px; background: var(--surface2); color: var(--text); font: 700 clamp(22px, 3vw, 30px)/1 'Rajdhani', sans-serif; cursor: pointer; transition: transform .16s cubic-bezier(.23,1,.32,1), border-color .16s ease, background .16s ease, box-shadow .16s ease; }
.welcome-choice-grid button:hover { transform: translateY(-3px); border-color: var(--accent); background: var(--accent-light); box-shadow: 0 12px 26px color-mix(in srgb, var(--accent) 22%, transparent); }
.welcome-choice-grid .welcome-free { grid-column: span 2; background: var(--accent); color: var(--bg); border-color: var(--accent); }
.welcome-back { display: inline-flex; margin: 0 auto 22px; border: 0; background: transparent; color: var(--text-secondary); font: 600 14px/1 'Inter', sans-serif; cursor: pointer; }
.welcome-back:hover { color: var(--accent); }
.welcome-splash, .welcome-menu { grid-area: 1 / 1; }

@media (min-width: 821px) {
  .top-bar { width: 100%; }
  .top-actions { justify-content: flex-end; }
}
@media (max-width: 820px) {
  .top-actions { display: contents; }
  .context-search { display: none; }
  .mode-control { margin-top: 8px; }
  .context-action { min-height: 40px; font-size: 12px; }
  .standard-lock { width: 14px; height: 14px; margin-left: 5px; }
  .welcome-screen { padding-inline: 16px; }
  .welcome-step { padding: 26px 18px; border-radius: 18px; }
  .welcome-choice-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
  .welcome-choice-grid button { min-height: 104px; font-size: 24px; }
  .welcome-choice-grid .welcome-free { grid-column: 1 / -1; min-height: 72px; }
  .template-base-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}
@media (max-width: 480px) {
  .welcome-splash div { gap: 10px; }
  .welcome-step h1 { font-size: 30px; }
  .welcome-choice-grid button { min-height: 92px; }
}

/* Scriptz v45: criação rica espelha as ferramentas do editor e amplia a leitura em ambos os fluxos. */
.new-script-modal { width: min(680px, 95vw); max-height: calc(100vh - 32px); overflow-y: auto; overscroll-behavior: contain; scrollbar-gutter: stable; }
.new-script-modal .modal-btns { position: sticky; bottom: -28px; z-index: 2; margin-inline: -2px; padding: 14px 2px 2px; background: linear-gradient(to bottom, color-mix(in srgb, var(--surface) 78%, transparent), var(--surface) 36%); }
.field-limit { margin-left: 6px; color: var(--text-secondary); font-weight: 500; letter-spacing: 0; text-transform: none; }

@media (min-width: 821px) {
  html, body { height: 100%; overflow: hidden; }
  .layout { height: calc(100vh - 72px); min-height: 0; }
  aside { position: relative; top: auto; height: 100%; min-height: 0; overflow-y: auto; }
  main { min-width: 0; height: 100%; overflow-y: auto; overscroll-behavior: contain; }
}
.category-select-stack { display: grid; grid-template-columns: 1fr; gap: 8px; width: 100%; }
.category-select-stack select { min-width: 0; }
.category-select-list { display: grid; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); gap: 8px; width: 100%; }
.category-select-list .category-select { min-width: 0; width: 100%; }
.new-script-modal .category-select-stack { grid-template-columns: 1fr; }
.new-script-modal .category-select-list { grid-template-columns: 1fr; }
.new-script-modal #newCategoryPrimary[hidden] { display: none; }
.new-script-modal #newCategoryPrimary:not([hidden]) { display: block; width: 100%; }
.new-category-context { min-height: 38px; display: flex; align-items: center; padding: 8px 10px; border: 1px solid color-mix(in srgb, var(--accent) 38%, var(--border)); border-radius: var(--radius-sm); background: var(--accent-light); color: var(--accent); font-size: 12px; font-weight: 700; }
.editor-meta .editor-category-stack { min-width: 150px; }
.new-editor-shell { border: 1px solid var(--border); border-radius: var(--radius-sm); overflow: hidden; background: var(--surface2); }
.new-editor-shell .new-editor-fmt-bar { border: 0; border-bottom: 1px solid var(--border); border-radius: 0; }
.new-editor-shell [contenteditable] { min-height: 235px; max-height: 320px; overflow-y: auto; padding: 18px 20px; background: var(--surface); color: var(--text); font-size: 16px; line-height: 1.7; }
.new-editor-shell [contenteditable]:focus { box-shadow: inset 0 0 0 2px color-mix(in srgb, var(--accent) 60%, transparent); }
.new-editor-shell .link-url-input { margin: 0; border: 0; border-bottom: 1px solid var(--border); border-radius: 0; }
.editor-wrap.visible [contenteditable] { min-height: 205px; font-size: 16px; line-height: 1.7; }
input[type="text"], input[type="url"], input[type="search"], textarea, [contenteditable="true"] { cursor: text; }
body.ordering-locked .sort-select { opacity: .58; cursor: not-allowed; }

@media (max-width: 820px) {
  .new-script-modal { width: calc(100vw - 20px); max-height: calc(100vh - 20px); padding: 18px; overflow-y: auto; }
  .new-script-modal .modal-btns { bottom: -18px; }
  .category-select-stack { grid-template-columns: 1fr; }
  .category-select-list { grid-template-columns: 1fr; }
  .new-editor-shell [contenteditable] { min-height: 245px; max-height: 38vh; padding: 14px; font-size: 15px; line-height: 1.65; }
  .editor-wrap.visible [contenteditable] { min-height: 205px; padding: 14px; font-size: 15px; line-height: 1.65; }
}

/* Na tela inicial mobile, o menu permanece disponível mesmo sem a barra contextual. */
.mobile-persistent-nav-toggle { display: none; }
@media (max-width: 820px) {
  .layout:has(main.is-initial-landing) .mobile-persistent-nav-toggle {
    position: fixed;
    top: calc(12px + env(safe-area-inset-top));
    left: 12px;
    z-index: 60;
    display: inline-flex;
    width: 42px;
    height: 42px;
    align-items: center;
    justify-content: center;
    padding: 0;
    border: 1px solid var(--border);
    border-radius: 10px;
    background: var(--surface);
    color: var(--text);
    box-shadow: 0 8px 22px color-mix(in srgb, var(--bg) 45%, transparent);
    font-size: 0;
    transition: left .24s cubic-bezier(.23,1,.32,1), background-color .16s ease, color .16s ease, border-color .16s ease;
  }
  body.mobile-nav-open .layout:has(main.is-initial-landing) .mobile-persistent-nav-toggle { left: calc(min(88vw, 360px) - 54px); }
  .layout:has(main.is-initial-landing) .mobile-persistent-nav-toggle::before { content: '☰'; font-size: 19px; line-height: 1; }
  body.mobile-nav-open .layout:has(main.is-initial-landing) .mobile-persistent-nav-toggle { background: var(--accent); color: var(--bg); border-color: var(--accent); }
  body.mobile-nav-open .layout:has(main.is-initial-landing) .mobile-persistent-nav-toggle::before { content: '✕'; }
}

/* Ponto discreto de ajuda, disponível sem competir com os controles do workspace. */
.scriptz-help-button {
  position: fixed;
  top: 14px;
  right: 14px;
  z-index: 80;
  display: inline-flex;
  width: 32px;
  height: 32px;
  align-items: center;
  justify-content: center;
  padding: 0;
  border: 1px solid color-mix(in srgb, var(--accent) 52%, var(--border));
  border-radius: 50%;
  background: color-mix(in srgb, var(--surface) 88%, transparent);
  color: var(--accent);
  box-shadow: 0 5px 16px rgba(0, 0, 0, .14);
  font: 700 17px/1 'Rajdhani', sans-serif;
  cursor: pointer;
}
.mobile-only-control { display: none !important; }
.web-header ~ .scriptz-help-button { display: none; }
.sb-head .brand-lockup, .sb-search { display: none; }
@media (min-width: 821px) {
  #scriptzFirebaseAuthButton { display: none !important; }
}
.scriptz-help-button::after {
  content: 'Informações, ajuda e feedback';
  position: absolute;
  top: 50%;
  right: calc(100% + 9px);
  transform: translateY(-50%) translateX(4px);
  width: max-content;
  max-width: min(250px, calc(100vw - 68px));
  padding: 7px 9px;
  border: 1px solid var(--border);
  border-radius: 7px;
  background: var(--surface);
  color: var(--text);
  box-shadow: var(--shadow);
  font: 600 12px/1.15 'Inter', sans-serif;
  opacity: 0;
  pointer-events: none;
  transition: opacity .16s cubic-bezier(.23,1,.32,1), transform .16s cubic-bezier(.23,1,.32,1);
}
.scriptz-help-button:hover, .scriptz-help-button:focus-visible { border-color: var(--accent); background: var(--accent-light); outline: none; }
.scriptz-help-button:hover::after, .scriptz-help-button:focus-visible::after { opacity: 1; transform: translateY(-50%) translateX(0); }
.help-info-modal { width: min(600px, calc(100vw - 28px)); padding: 32px 40px; position: relative; box-sizing: border-box; }
.help-info-modal h3 { margin: 0 0 14px; font: 700 italic 34px/1 'Rajdhani', sans-serif; color: var(--accent); }
.help-brand-line { display: flex; align-items: center; gap: 10px; }
.help-brand-envelope { display: inline-block; width: 30px; height: 24px; flex: 0 0 auto; background: var(--accent); -webkit-mask: url('../assets/scriptz_icone_branco_transparente.png') center / contain no-repeat; mask: url('../assets/scriptz_icone_branco_transparente.png') center / contain no-repeat; }
.help-info-modal p { margin: 0 0 12px; color: var(--text-secondary); font-size: 14px; line-height: 1.55; }
.help-info-modal p strong { color: var(--text); }
.help-author-line { white-space: nowrap; font-size: 13.5px !important; letter-spacing: -.01em; }
.help-info-modal a { color: var(--accent); font-weight: 700; word-break: break-word; }
.help-info-kicker { color: var(--accent) !important; font: 700 11px/1 'Rajdhani', sans-serif !important; letter-spacing: .13em; }
.help-version-line { margin: 10px 0 0; color: var(--text-secondary); font: 600 12px/1.35 'Inter', sans-serif; }
.help-version-line strong { color: var(--text); }

.help-license-note { margin-top: 18px; padding: 11px 12px; border-left: 3px solid var(--accent); background: var(--accent-light); color: var(--text); font-size: 13px; line-height: 1.45; }
.help-info-modal .modal-btns { width: 100%; box-sizing: border-box; justify-content: flex-end; }
.copy-signature-modal, .notice-modal { width: min(500px, calc(100vw - 28px)); padding: 28px 30px; }
.copy-signature-modal h3, .notice-modal h3 { margin: 0 0 10px; color: var(--accent); font: 700 italic 28px/1.05 'Rajdhani', sans-serif; }
.copy-signature-modal p, .notice-modal p { margin: 0 0 12px; color: var(--text-secondary); font-size: 14px; line-height: 1.5; }
.copy-signature-modal .copy-signature-note, .notice-modal .notice-note { padding: 10px 12px; border-left: 3px solid var(--accent); background: var(--accent-light); color: var(--text); font-size: 13px; }
.copy-signature-modal label, .notice-modal label { display: block; margin: 18px 0 7px; color: var(--text); font: 700 13px/1 'Rajdhani', sans-serif; letter-spacing: .06em; }
.copy-signature-modal input, .notice-modal input { width: 100%; box-sizing: border-box; font: 700 italic 18px/1.2 'Rajdhani', sans-serif; }
.copy-signature-error, .notice-error { min-height: 18px; margin-top: 8px !important; color: var(--red) !important; font-size: 12px !important; }
.notice-modal.is-danger .notice-note { border-left-color: var(--red); background: color-mix(in srgb, var(--red) 10%, var(--surface)); }
.notice-modal.is-danger .btn-primary { background: var(--red); }
.notice-modal.is-danger .btn-primary:hover { background: color-mix(in srgb, var(--red) 82%, #000); }
@media (max-width: 820px) {
  .scriptz-help-button { top: calc(10px + env(safe-area-inset-top)); right: 10px; width: 30px; height: 30px; font-size: 16px; }
  .scriptz-help-button::after { display: none; }
  .help-info-modal { padding: 26px 22px 22px; }
  .help-author-line { white-space: normal; }
}

/* Scriptz v46: ações contextuais agrupadas e escolha direta da unidade no primeiro acesso. */
.actions-menu { border: 1px solid var(--border); border-radius: 10px; background: color-mix(in srgb, var(--surface2) 72%, transparent); overflow: hidden; }
.actions-menu summary { display: flex; align-items: center; justify-content: space-between; min-height: 40px; padding: 0 12px; color: var(--text); font: 700 14px/1 'Rajdhani', sans-serif; letter-spacing: .04em; cursor: pointer; list-style: none; }
.actions-menu summary::-webkit-details-marker { display: none; }
.actions-menu-chevron { color: var(--text-secondary); font-size: 12px; line-height: 1; transform: translateY(2px); transition: transform .24s cubic-bezier(.23,1,.32,1), color .24s cubic-bezier(.23,1,.32,1); }
.actions-menu[open] summary { border-bottom: 1px solid var(--border); }
.actions-menu.is-open .actions-menu-chevron { color: var(--accent); transform: translateY(-1px); }
.actions-menu:not([open]) > .actions-menu-clip { display: grid; }
.actions-menu-clip { display: grid; grid-template-rows: 0fr; transition: grid-template-rows .24s cubic-bezier(.23,1,.32,1); }
.actions-menu.is-open .actions-menu-clip { grid-template-rows: 1fr; }
.actions-menu-content { display: grid; min-height: 0; overflow: hidden; gap: 7px; padding: 0 9px; opacity: 0; transform: translateY(-5px); transition: padding .24s cubic-bezier(.23,1,.32,1), opacity .16s cubic-bezier(.23,1,.32,1), transform .24s cubic-bezier(.23,1,.32,1); }
.actions-menu.is-open .actions-menu-content { padding: 9px; opacity: 1; transform: translateY(0); }
.actions-menu-content button { min-height: 38px; text-align: left; }
.actions-menu-content .btn-reset { border-color: var(--orange); color: var(--orange); background: var(--orange-light); }

/* Indicador unificado para todos os selects nativos. O navegador mantém o menu de opções e o teclado; em navegadores com :open, a seta sobe no mesmo ritmo. */
select:not([multiple]):not([size]) {
  appearance: none;
  -webkit-appearance: none;
  padding-right: 34px !important;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 12 12'%3E%3Ctext x='6' y='10' text-anchor='middle' font-size='12' fill='%23aebbd4'%3E%E2%96%BC%3C/text%3E%3C/svg%3E") !important;
  background-repeat: no-repeat !important;
  background-position: right 11px center !important;
  background-size: 12px 12px !important;
  transition: background-position .24s cubic-bezier(.23,1,.32,1), border-color var(--transition), box-shadow var(--transition), background-color var(--transition) !important;
}
select:not([multiple]):not([size]):open {
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 12 12'%3E%3Ctext x='6' y='10' text-anchor='middle' font-size='12' fill='%236f9eff'%3E%E2%96%B2%3C/text%3E%3C/svg%3E") !important;
  background-position: right 11px calc(50% - 3px) !important;
}
[data-theme="light"] select:not([multiple]):not([size]) {
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 12 12'%3E%3Ctext x='6' y='10' text-anchor='middle' font-size='12' fill='%23526887'%3E%E2%96%BC%3C/text%3E%3C/svg%3E") !important;
}
[data-theme="light"] select:not([multiple]):not([size]):open {
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 12 12'%3E%3Ctext x='6' y='10' text-anchor='middle' font-size='12' fill='%23315da8'%3E%E2%96%B2%3C/text%3E%3C/svg%3E") !important;
}

.welcome-units-step { max-width: 860px; }
.welcome-units-step h1 { max-width: 670px; margin-inline: auto; font-size: clamp(23px, 3.1vw, 34px); line-height: 1.06; }
.welcome-units-grid { grid-template-columns: repeat(3, minmax(0, 1fr)); max-width: 760px; margin-inline: auto; }
.welcome-units-grid button { grid-column: auto; min-height: 102px; font-size: clamp(20px, 2.5vw, 28px); }
.welcome-editor-link { margin: 26px 0 0; color: var(--text-secondary); font: 500 15px/1.5 'Inter', sans-serif; }
.welcome-editor-link button { margin: 0; padding: 0; border: 0; background: transparent; color: var(--accent); font: inherit; font-weight: 700; text-decoration: underline; text-underline-offset: 3px; cursor: pointer; }
.welcome-editor-link button:hover { color: var(--text); }
.welcome-access-step { max-width: 720px; margin-inline: auto; }
.welcome-access-copy { max-width: 560px; margin: -8px auto 28px; color: var(--text-secondary); font: 500 16px/1.55 'Inter', sans-serif; }
.welcome-access-actions { display: grid; gap: 12px; max-width: 520px; margin-inline: auto; }
.welcome-access-actions button { min-height: 58px; padding: 14px 18px; border-radius: 12px; font: 700 16px/1.2 'Inter', sans-serif; cursor: pointer; }
.welcome-primary-action { border: 1px solid var(--accent); background: var(--accent); color: var(--bg); }
.welcome-secondary-action { border: 1px solid var(--border); background: var(--surface2); color: var(--text); }
.welcome-access-actions button:hover { transform: translateY(-2px); box-shadow: 0 10px 24px color-mix(in srgb, var(--accent) 20%, transparent); }
.welcome-access-status { min-height: 1.4em; margin: 16px 0 0; color: var(--danger, #ff8e8e); font-size: 13px; }
.welcome-back-action { margin-top: 22px; min-height: 42px; padding: 10px 22px; border: 1px solid var(--border); border-radius: 10px; background: transparent; color: var(--text-secondary); font: 700 14px/1.2 'Inter', sans-serif; cursor: pointer; }
.welcome-back-action:hover, .welcome-back-action:focus-visible { border-color: var(--accent); color: var(--accent); outline: none; }

@media (max-width: 820px) {
  .actions-menu summary { min-height: 42px; }
  .welcome-units-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .welcome-units-grid button { grid-column: auto; min-height: 82px; font-size: 21px; }
}

@media (prefers-reduced-motion: reduce) {
  .welcome-screen, .welcome-splash, .welcome-menu { transition-duration: .01ms; }
}

/* Scriptz v52: categorias principais na sidebar; subcategorias e suas ações no conteúdo principal. */
#sidebarNav .category-root-list { display: grid; grid-template-columns: 1fr; gap: 4px; }
#sidebarNav .category-nav-item { margin: 0; }
#sidebarNav .category-root-list > li,
#sidebarNav .category-child-list > li { width: 100%; }
#sidebarNav .category-root-list,
#sidebarNav .category-child-list { width: 100%; }
#sidebarNav .category-tree-row { position: relative; display: grid; grid-template-columns: minmax(0, 1fr) 24px; align-items: center; gap: 3px; width: 100%; }
#sidebarNav .category-tree-row > .category-root-btn { width: 100%; }
#sidebarNav .category-child-list { position: relative; display: grid; gap: 3px; margin: 2px 0 3px 18px; padding-left: 14px; }
#sidebarNav .category-child-list::before { content: ''; position: absolute; top: -4px; bottom: 10px; left: 0; border-left: 1px solid color-mix(in srgb, var(--accent) 42%, var(--border)); }
#sidebarNav .category-child-item { position: relative; }
#sidebarNav .category-child-item::before { content: ''; position: absolute; top: 20px; left: -14px; width: 14px; border-top: 1px solid color-mix(in srgb, var(--accent) 42%, var(--border)); }
#sidebarNav .category-root-list,
#sidebarNav .category-child-list { grid-template-columns: 1fr; }
#sidebarNav .category-nav-item.is-editable { display: grid; grid-template-columns: minmax(0, 1fr) auto; align-items: center; gap: 3px; }
#sidebarNav button.cat-btn {
  display: flex;
  flex: 1;
  min-width: 0;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  min-height: 38px;
  padding: 8px 12px;
  border: 1.5px solid var(--border);
  border-radius: 8px;
  background: var(--bg);
  color: var(--text-secondary);
  font: 500 13px/1.15 'Inter', sans-serif;
  text-align: left;
  cursor: pointer;
  transition: background var(--transition), border-color var(--transition), color var(--transition), transform .16s cubic-bezier(.23,1,.32,1);
}
#sidebarNav button.cat-btn:hover { background: var(--surface2); border-color: var(--text-secondary); color: var(--text); }
#sidebarNav button.cat-btn:active { transform: scale(.97); }
#sidebarNav button.cat-btn.active { background: var(--accent); border-color: var(--accent); color: #fff; font-weight: 600; }
#sidebarNav .cat-btn-label { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
#sidebarNav button.category-root-btn { display: grid; grid-template-columns: 13px minmax(0, 1fr) 42px; gap: 9px; min-height: 42px; padding: 9px 10px; border-color: transparent; border-radius: 8px; background: transparent; color: var(--text-secondary); }
#sidebarNav button.category-root-btn:hover { border-color: var(--border); background: var(--surface2); color: var(--text); }
#sidebarNav button.category-root-btn.active { border-color: color-mix(in srgb, var(--accent) 35%, var(--border)); background: color-mix(in srgb, var(--accent-light) 72%, var(--surface)); box-shadow: inset 3px 0 0 var(--accent); color: var(--text); }
#sidebarNav .category-root-symbol { color: var(--accent); font-size: 14px; line-height: 1; }
#sidebarNav .category-root-arrow { color: var(--text-secondary); font: 700 18px/.8 'Rajdhani', sans-serif; }
#sidebarNav button.category-root-btn .nav-count { justify-self: end; min-width: 36px; padding: 2px 6px; border-radius: 999px; background: var(--surface2); color: var(--text-secondary); font-size: 11px; line-height: 1.2; text-align: center; }
#sidebarNav button.category-root-btn.active .nav-count { background: color-mix(in srgb, var(--accent) 16%, var(--surface)); color: var(--accent); }
#sidebarNav .overview-sidebar-btn { width: 100%; }
#sidebarNav .sidebar-category-actions { display: inline-flex; gap: 2px; }
#sidebarNav .sidebar-category-actions button { width: 26px; min-width: 26px; min-height: 30px; padding: 2px; border: 0; border-radius: 6px; background: transparent; cursor: pointer; }
#sidebarNav .sidebar-category-actions button:hover { background: var(--surface2); }
#sidebarNav .sidebar-category-empty { padding: 9px 10px; color: var(--text-secondary); font-size: 12px; font-style: italic; }
.sidebar-category-manager { display: grid; gap: 7px; margin-top: 9px; }
.sidebar-category-tools { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; }
.sidebar-tool-btn { min-height: 34px; padding: 7px 8px; border: 1px solid var(--border); border-radius: 7px; background: var(--surface2); color: var(--text-secondary); font: 600 11px/1 'Inter', sans-serif; cursor: pointer; }
.sidebar-tool-btn:hover, .sidebar-tool-btn.active { border-color: var(--accent); color: var(--accent); background: var(--accent-light); }
.sidebar-category-create { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 5px; }
.sidebar-category-create input { min-width: 0; min-height: 34px; padding: 7px 8px; border: 1px solid var(--border); border-radius: 7px; background: var(--bg); color: var(--text); font-size: 12px; outline: none; }
.sidebar-category-create input:focus { border-color: var(--accent); }
.sidebar-category-create button { min-height: 34px; padding: 7px 9px; border: 0; border-radius: 7px; background: var(--accent); color: #fff; font-size: 11px; font-weight: 700; cursor: pointer; }
.sidebar-library-section { margin: 0 0 8px; border: 1px solid var(--border); border-radius: 9px; background: var(--surface); overflow: hidden; }
.sidebar-library-section summary { display: grid; grid-template-columns: minmax(0, 1fr) auto 14px; align-items: center; gap: 8px; min-height: 44px; padding: 9px 10px; color: var(--text); cursor: pointer; list-style: none; }
.sidebar-library-section summary::-webkit-details-marker { display: none; }
.sidebar-library-section.is-active summary { background: color-mix(in srgb, var(--accent-light) 72%, var(--surface)); box-shadow: inset 3px 0 0 var(--accent); }
.sidebar-library-title { display: inline-flex; align-items: center; gap: 7px; min-width: 0; overflow: hidden; font: 700 13px/1 'Rajdhani', sans-serif; letter-spacing: .02em; }
.sidebar-library-title span { color: var(--accent); }
.sidebar-library-chevron { color: var(--text-secondary); font-size: 12px; line-height: 1; text-align: center; transform: translateY(2px); transition: transform .24s cubic-bezier(.23,1,.32,1), color .24s cubic-bezier(.23,1,.32,1); }
.sidebar-library-section.is-open .sidebar-library-chevron { color: var(--accent); transform: translateY(-1px); }
.sidebar-library-clip { display: grid; grid-template-rows: 0fr; transition: grid-template-rows .24s cubic-bezier(.23,1,.32,1); }
.sidebar-library-section.is-open .sidebar-library-clip { grid-template-rows: 1fr; }
.sidebar-library-content { display: grid; min-height: 0; overflow: hidden; gap: 7px; padding: 0 8px; opacity: 0; transform: translateY(-5px); transition: padding .24s cubic-bezier(.23,1,.32,1), opacity .16s cubic-bezier(.23,1,.32,1), transform .24s cubic-bezier(.23,1,.32,1); }
.sidebar-library-section.is-open .sidebar-library-content { padding: 0 8px 9px; opacity: 1; transform: translateY(0); }
.sidebar-library-overview { min-height: 32px; padding: 6px 8px; border: 1px solid var(--border); border-radius: 7px; background: transparent; color: var(--text-secondary); font-size: 11px; text-align: left; cursor: pointer; }
.sidebar-library-overview:hover { border-color: var(--accent); color: var(--accent); }

.category-group { margin-bottom: 7px; }
.category-group > .category-item { margin-bottom: 0; }
.category-subcategory-list { display: grid; gap: 4px; margin: 4px 0 0 34px; }
.category-item { display: grid; grid-template-columns: 28px minmax(0, 1fr) auto auto; gap: 10px; min-height: 54px; padding: 8px 10px; }
.category-item.category-sub { min-height: 52px; padding-left: 4px; border-style: dashed; background: color-mix(in srgb, var(--surface2) 64%, transparent); }
.category-item.category-sub .category-name::before { content: '↳ '; color: var(--accent); }
.category-drag-spacer { width: 28px; min-width: 28px; }
.category-item-details { display: grid; min-width: 0; gap: 3px; }
.category-item .category-name { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; padding: 0; line-height: 1.2; }
.category-level { min-width: 0; overflow: hidden; color: var(--text-secondary); font-size: 10px; line-height: 1.15; text-overflow: ellipsis; white-space: nowrap; }
.category-item .category-count { margin: 0; align-self: center; white-space: nowrap; }
.category-item .category-actions { align-self: center; flex-wrap: nowrap; }
.category-item .category-actions button { width: 30px; min-width: 30px; min-height: 30px; padding: 3px; }
.category-modal-actions { display: grid; grid-template-columns: minmax(0, 1fr) auto; align-items: stretch; gap: 8px; }
.category-modal-actions input { grid-column: auto; min-width: 0; width: 100%; }
.category-modal-actions select {
  grid-column: 1;
  width: 100%;
  min-width: 150px;
  padding: 8px 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--bg);
  color: var(--text);
  font: 13px 'Inter', sans-serif;
  outline: none;
}
.category-modal-actions select:focus { border-color: var(--accent); box-shadow: 0 0 0 3px rgba(30,79,122,.12); }
.category-modal-actions .btn-primary { grid-column: 2; min-width: 118px; padding-inline: 12px; }

.subcategory-navigator { margin: 0 0 18px; padding: 16px; border: 1px solid color-mix(in srgb, var(--accent) 44%, var(--border)); border-radius: 14px; background: linear-gradient(135deg, color-mix(in srgb, var(--accent-light) 74%, var(--surface)) 0%, var(--surface) 100%); }
.subcategory-navigator-heading { display: flex; align-items: center; justify-content: space-between; gap: 16px; margin-bottom: 12px; }
.subcategory-navigator-heading > span { color: var(--text-secondary); font-size: 12px; white-space: nowrap; }
.subcategory-navigator-kicker { color: var(--accent); font: 700 10px/1 'Inter', sans-serif; letter-spacing: .12em; text-transform: uppercase; }
.field-required { margin-left: 6px; color: var(--accent); font-size: 10px; font-weight: 700; letter-spacing: .04em; text-transform: uppercase; }
.category-empty-choice { margin: 0 0 18px; padding: 20px; border: 1px solid color-mix(in srgb, var(--accent) 44%, var(--border)); border-radius: 14px; background: linear-gradient(135deg, color-mix(in srgb, var(--accent-light) 74%, var(--surface)) 0%, var(--surface) 100%); }
.category-empty-choice-copy { display: grid; gap: 7px; margin-bottom: 16px; }
.category-empty-choice-copy p { margin: 0; color: var(--text-secondary); font-size: 14px; }
.category-empty-choice-actions { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
.category-empty-choice-actions.single-action { grid-template-columns: minmax(0, 1fr); max-width: 430px; }
.category-empty-choice-actions button { display: grid; grid-template-columns: 28px minmax(0, 1fr); grid-template-areas: 'icon title' 'icon copy'; gap: 4px 10px; min-height: 92px; padding: 14px; border-radius: 10px; text-align: left; cursor: pointer; transition: transform .16s cubic-bezier(.23,1,.32,1), border-color .16s ease, background .16s ease; }
.category-empty-choice-actions button:active { transform: scale(.98); }
.category-empty-choice-actions button > span { grid-area: icon; align-self: center; color: var(--accent); font-size: 21px; }
.category-empty-choice-actions button strong { grid-area: title; color: var(--text); font: 700 17px/1 'Rajdhani', sans-serif; }
.category-empty-choice-actions button small { grid-area: copy; color: var(--text-secondary); font-size: 11px; line-height: 1.25; }
.category-empty-primary { border: 1px solid var(--accent); background: color-mix(in srgb, var(--accent-light) 84%, var(--surface)); }
.category-empty-secondary { border: 1px solid var(--border); background: var(--surface2); }
.category-empty-choice-actions button:hover { transform: translateY(-1px); border-color: var(--accent); background: var(--accent-light); }
.subcategory-choice-list { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; }
.subcategory-choice { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 0; min-height: 78px; border: 1px solid var(--border); border-radius: 10px; background: color-mix(in srgb, var(--surface2) 82%, transparent); color: var(--text); overflow: hidden; transition: transform .16s cubic-bezier(.23,1,.32,1), border-color .16s ease, background .16s ease; }
.subcategory-choice:hover { transform: translateY(-1px); border-color: var(--accent); background: var(--accent-light); }
.subcategory-choice-open { display: grid; grid-template-columns: minmax(0, 1fr) auto; grid-template-areas: 'name arrow' 'count arrow'; gap: 4px 10px; min-width: 0; padding: 12px; border: 0; background: transparent; color: inherit; text-align: left; cursor: pointer; }
.subcategory-choice-open:active { transform: scale(.98); }
.subcategory-choice-name { grid-area: name; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font: 700 16px/1.1 'Rajdhani', sans-serif; }
.subcategory-choice-count { grid-area: count; color: var(--text-secondary); font-size: 11px; }
.subcategory-choice-arrow { grid-area: arrow; align-self: center; color: var(--accent); font: 700 24px/1 'Rajdhani', sans-serif; }
.subcategory-choice-actions { display: flex; flex-direction: column; justify-content: center; gap: 3px; padding: 6px 7px 6px 0; }
.subcategory-choice-actions button { width: 28px; min-height: 28px; padding: 2px; border: 0; border-radius: 6px; background: transparent; cursor: pointer; }
.subcategory-choice-actions button:hover { background: var(--surface2); }
.subcategory-empty-state { margin: 0 0 12px; color: var(--text-secondary); font-size: 13px; }
.subcategory-create-row { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 8px; margin-top: 12px; }
.subcategory-create-row input { min-width: 0; min-height: 40px; padding: 9px 11px; border: 1px solid var(--border); border-radius: 8px; background: var(--bg); color: var(--text); outline: none; }
.subcategory-create-row input:focus { border-color: var(--accent); box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 16%, transparent); }
.subcategory-create-row .btn-primary { min-height: 40px; padding-inline: 12px; white-space: nowrap; }
.subcategory-return { margin: 0 0 14px; }
.subcategory-return button { display: inline-flex; align-items: center; gap: 7px; min-height: 36px; padding: 7px 10px; border: 1px solid var(--border); border-radius: 8px; background: var(--surface); color: var(--text-secondary); font: 600 13px/1 'Inter', sans-serif; cursor: pointer; }
.subcategory-return button:hover { color: var(--accent); border-color: var(--accent); }
.subcategory-return button span { color: var(--accent); font: 700 22px/.7 'Rajdhani', sans-serif; }

@media (max-width: 820px) {
  #sidebarNav .category-root-list { display: grid; grid-template-columns: 1fr; gap: 4px; }
  #sidebarNav .category-nav-item { margin: 0; min-width: 0; }
  #sidebarNav button.cat-btn { min-height: 40px; padding: 8px 9px; font-size: 12px; }
  #sidebarNav button.category-root-btn { min-height: 42px; }
  .sidebar-library-section summary { min-height: 46px; }
  .sidebar-category-actions button { width: 30px; min-width: 30px; min-height: 34px; }
  .category-subcategory-list { margin-left: 22px; }
  .category-item { grid-template-columns: 32px minmax(0, 1fr) auto auto; gap: 7px; }
  .category-level { display: none; }
  .category-item.category-sub { padding-left: 2px; }
  .category-modal-actions { grid-template-columns: 1fr; }
  .category-modal-actions input, .category-modal-actions select, .category-modal-actions .btn-primary { grid-column: auto; }
  .category-modal-actions select, .category-modal-actions .btn-primary { width: 100%; min-height: 40px; }
  .subcategory-navigator { padding: 14px; margin-bottom: 14px; }
  .category-empty-choice { padding: 16px; }
  .category-empty-choice-actions { grid-template-columns: 1fr; }
  .category-empty-choice-actions button { min-height: 76px; }
  .subcategory-choice-list { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .subcategory-create-row { grid-template-columns: 1fr; }
  .subcategory-create-row .btn-primary { width: 100%; }
}

@media (max-width: 480px) {
  #sidebarNav .category-root-list { grid-template-columns: 1fr; }
}

/* O atalho superior de criação só existe em contextos pessoais que já possuem scriptz. */
#newScriptBtn[hidden] { display: none !important; }

/* Operações exclusivas: durante a criação ou reordenação pela sidebar, somente o respectivo controle permanece interativo. */
body.sidebar-reorder-active main,
body.sidebar-reorder-active .sb-head,
body.sidebar-reorder-active .sb-search,
body.sidebar-reorder-active .sb-foot,
body.sidebar-category-creation-active main,
body.sidebar-category-creation-active .sb-head,
body.sidebar-category-creation-active .sb-search,
body.sidebar-category-creation-active .sb-foot {
  pointer-events: none;
  user-select: none;
  opacity: .58;
}
body.sidebar-reorder-active #sidebarNav .sidebar-library-overview,
body.sidebar-reorder-active #sidebarNav .sidebar-category-actions,
body.sidebar-reorder-active #sidebarNav .sidebar-library-section > summary,
body.sidebar-category-creation-active #sidebarNav > :not(.sidebar-category-manager),
body.sidebar-category-creation-active #sidebarNav .sidebar-library-section > :not(.sidebar-library-clip),
body.sidebar-category-creation-active #sidebarNav .sidebar-library-clip > :not(.sidebar-category-manager) {
  pointer-events: none;
}
body.sidebar-reorder-active #sidebarNav .category-root-btn { pointer-events: none; }
body.sidebar-reorder-active #sidebarNav .category-root-list[data-editable-roots="true"] > li { cursor: grab; }
body.sidebar-reorder-active #sidebarNav .sidebar-category-manager,
body.sidebar-category-creation-active #sidebarNav .sidebar-category-manager { pointer-events: auto; opacity: 1; }

/* No desktop, a assinatura é uma janela de trabalho sempre visível e independente do conteúdo do painel. */
@media (min-width: 821px) {
  :root { --signature-reserve: 292px; }
  main {
    width: 100%;
    max-width: min(1000px, calc(100vw - var(--sidebar-width) - var(--signature-reserve)));
  }
  main > .signature-dock {
    position: fixed;
    z-index: 20;
    right: 18px;
    bottom: 20px;
    width: max-content;
    min-width: 164px;
    max-width: calc(var(--signature-reserve) - 18px);
    margin: 0;
    padding: 7px 9px 8px 12px;
    gap: 4px;
    justify-items: stretch;
    border: 0;
    border-left: 3px solid var(--accent);
    border-radius: 0 9px 9px 0;
    background: linear-gradient(90deg, color-mix(in srgb, var(--accent) 13%, transparent), transparent);
    box-shadow: none;
  }
  main > .signature-dock label {
    font-size: 9px;
    letter-spacing: .12em;
    text-align: left;
    color: var(--accent);
  }
  main > .signature-dock input {
    width: 8ch;
    min-width: 8ch;
    max-width: calc(var(--signature-reserve) - 26px);
    min-height: 34px;
    padding: 5px 2px;
    font-size: 17px;
    text-align: left;
    border: 0;
    border-bottom: 1px solid var(--border);
    border-radius: 0;
    background: transparent;
    box-shadow: none;
  }
  main > .signature-dock input::placeholder { text-align: left; }
}

/* Hover system for the historical build: feedback only on actionable surfaces. */
.card {
  transition: transform .16s cubic-bezier(.23,1,.32,1), border-color .16s ease, box-shadow .16s ease, background-color .16s ease;
}
.card:hover:not(.editing) {
  transform: translateY(-2px);
  border-color: color-mix(in srgb, var(--accent) 68%, var(--border));
  box-shadow: 0 12px 28px rgba(2, 8, 31, .22);
}
.card-hd { transition: background-color .16s ease; }
.card-hd:hover { background-color: color-mix(in srgb, var(--accent) 9%, transparent); }
.card .btn, .card .fav-star, .card .script-order-controls button,
.sidebar-tool-btn, .sidebar-library-overview, .category-root-btn, .cat-btn {
  transition: transform .14s cubic-bezier(.23,1,.32,1), background-color .14s ease, border-color .14s ease, color .14s ease, box-shadow .14s ease;
}
.card .btn:hover, .sidebar-tool-btn:hover, .sidebar-library-overview:hover,
.category-root-btn:hover, .cat-btn:hover { transform: translateY(-1px); }
.card .fav-star:hover { transform: scale(1.12); color: var(--accent); }
.card .script-order-controls button:hover { transform: translateY(-1px); color: var(--accent); background: var(--accent-light); }
.options-menu summary:hover, .actions-menu summary:hover { border-color: var(--accent); color: var(--text); }

@media (prefers-reduced-motion: reduce) {
  .card, .card-hd, .card .btn, .card .fav-star, .card .script-order-controls button,
  .sidebar-tool-btn, .sidebar-library-overview, .category-root-btn, .cat-btn {
    transition: none !important;
  }
  .card:hover:not(.editing), .card .btn:hover, .card .fav-star:hover,
  .card .script-order-controls button:hover, .sidebar-tool-btn:hover,
  .sidebar-library-overview:hover, .category-root-btn:hover, .cat-btn:hover {
    transform: none;
  }
}

/* Cross-browser editor controls: keep greeting and signature readable at every width. */
.editor-meta {
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
  align-items: start;
}
.editor-meta .title-field,
.editor-meta .category-select-stack { min-width: 0; }
.editor-meta .editor-checkboxes {
  grid-column: 1 / -1;
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  align-items: center;
  gap: 10px 16px;
  min-width: 0;
  padding-top: 2px;
}
.editor-meta .editor-checkboxes > label {
  min-width: 0;
  display: flex;
  align-items: center;
  gap: 7px;
  flex-wrap: wrap;
  line-height: 1.35;
}
.editor-meta .editor-checkboxes select {
  flex: 1 1 150px;
  min-width: 0;
  max-width: 100%;
}
@media (max-width: 900px) {
  .editor-meta .editor-checkboxes { grid-template-columns: 1fr; }
}
@media (max-width: 560px) {
  .editor-meta { grid-template-columns: 1fr; }
  .editor-meta .editor-checkboxes { grid-column: 1; gap: 9px; }
}

/* Build 99 · gamificação administrativa discreta. O progresso é pessoal e não altera modelos oficiais. */
.title-stack {
  flex: 1 1 300px;
  display: grid;
  justify-items: start;
  gap: 2px;
}
.title-stack > h2 { flex: none; }
.flow-experience {
  width: min(390px, 100%);
  margin-top: 7px;
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  grid-template-areas: "meta review" "track review";
  gap: 5px 10px;
  align-items: center;
}
.flow-experience[hidden] { display: none !important; }
.flow-experience-row {
  grid-area: meta;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  min-width: 0;
  font-size: 10px;
  color: var(--text-secondary);
}
.flow-state {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  color: var(--accent);
  font: 700 11px/1 'Rajdhani', 'Inter', sans-serif;
  letter-spacing: .04em;
  white-space: nowrap;
}
.flow-state::before {
  content: '';
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: currentColor;
  box-shadow: 0 0 0 3px color-mix(in srgb, currentColor 15%, transparent);
}
.flow-progress-label { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.flow-progress-track {
  grid-area: track;
  height: 5px;
  overflow: hidden;
  border-radius: 999px;
  background: color-mix(in srgb, var(--border) 70%, transparent);
}
.flow-progress-track > span {
  display: block;
  width: 100%;
  height: 100%;
  border-radius: inherit;
  background: linear-gradient(90deg, var(--accent), color-mix(in srgb, var(--accent) 58%, #9bd8ff));
  transform: scaleX(var(--flow-progress-scale, 0));
  transform-origin: left center;
  transition: transform .28s cubic-bezier(.23,1,.32,1);
}
.flow-review-button {
  grid-area: review;
  min-height: 31px;
  padding: 5px 9px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface2);
  color: var(--text-secondary);
  font: 600 11px/1.1 'Rajdhani', 'Inter', sans-serif;
  cursor: pointer;
  transition: transform .15s cubic-bezier(.23,1,.32,1), border-color .15s ease, color .15s ease, background-color .15s ease;
}
.flow-review-button:hover { transform: translateY(-1px); border-color: var(--accent); color: var(--text); }
.flow-review-button[aria-pressed="true"] { border-color: var(--green); background: color-mix(in srgb, var(--green) 14%, var(--surface)); color: var(--green); }
.flow-experience[data-state="reviewed"] .flow-state { color: var(--green); }
.flow-experience[data-state="explored"] .flow-state { color: color-mix(in srgb, var(--accent) 60%, var(--green)); }

.script-explored-mark {
  display: inline-grid;
  place-items: center;
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: color-mix(in srgb, var(--green) 14%, transparent);
  color: var(--green);
  font: 700 11px/1 'Rajdhani', sans-serif;
  box-shadow: inset 0 0 0 1px color-mix(in srgb, var(--green) 38%, transparent);
}
.card.is-explored:not(.standard-script) { border-left: 3px solid color-mix(in srgb, var(--accent) 62%, var(--green)); }
.card.is-explored .card-tag { color: color-mix(in srgb, var(--text-secondary) 76%, var(--green)); }
.btn-copy.copy-confirmed { background: var(--green); color: #07141d; box-shadow: 0 0 0 3px color-mix(in srgb, var(--green) 18%, transparent); }

/* Abertura reversível e suave sem remover o conteúdo do fluxo do documento. */
.card-body {
  display: block;
  max-height: 0;
  opacity: 0;
  visibility: hidden;
  overflow: clip;
  border-top-color: transparent;
  transform: translateY(-4px);
  transition: max-height .24s cubic-bezier(.23,1,.32,1), opacity .16s ease, transform .2s cubic-bezier(.23,1,.32,1), border-color .16s ease;
}
.card.open .card-body {
  display: block;
  max-height: 5000px;
  opacity: 1;
  visibility: visible;
  border-top-color: var(--border);
  transform: translateY(0);
}
.card.experience-pulse, .card.copy-pulse { animation: scriptz-experience-pulse .42s cubic-bezier(.23,1,.32,1); }
.card.copy-pulse { animation-duration: .52s; }
@keyframes scriptz-experience-pulse {
  0% { box-shadow: var(--shadow); }
  45% { box-shadow: 0 0 0 2px color-mix(in srgb, var(--accent) 32%, transparent), 0 16px 34px rgba(2,8,31,.25); }
  100% { box-shadow: var(--shadow-hover); }
}

[data-theme="light"] .script-explored-mark { background: #e4f5ec; color: #20764d; box-shadow: inset 0 0 0 1px #9fd2b9; }
[data-theme="light"] .flow-progress-track { background: #d6e0f0; }
[data-theme="light"] .flow-review-button[aria-pressed="true"] { background: #e7f6ee; color: #20764d; border-color: #62aa83; }
[data-theme="light"] .btn-copy.copy-confirmed { background: #2f8a5d; color: #fff; }

@media (max-width: 820px) {
  .title-stack { grid-area: title; align-self: center; }
  .flow-experience { grid-template-columns: minmax(0, 1fr); grid-template-areas: "meta" "track" "review"; width: 100%; margin-top: 5px; }
  .flow-review-button { justify-self: start; min-height: 29px; }
  .top-bar:has(.flow-experience:not([hidden])) { align-items: start; }
}
@media (max-width: 480px) {
  .flow-experience-row { align-items: flex-start; flex-direction: column; gap: 3px; }
  .flow-review-button { width: 100%; }
}

@media (max-width: 820px) {
  .mobile-only-control { display: block !important; }
  .sb-head .brand-lockup { display: grid !important; }
  .sb-search { display: none !important; }
  .web-header ~ .scriptz-help-button { display: inline-flex !important; }
}
@media (prefers-reduced-motion: reduce) {
  .flow-progress-track > span, .flow-review-button, .card-body, .btn-copy.copy-confirmed { transition: none !important; }
  .card.experience-pulse, .card.copy-pulse { animation: none !important; }
}

/* O progresso é um bloco próprio no mobile: título e controles permanecem íntegros. */
@media (max-width: 820px) {
  .top-bar:has(#flowExperience:not([hidden])) {
    grid-template-columns: auto minmax(0, 1fr) auto auto;
    grid-template-areas:
      "menu title search add"
      "experience experience experience experience"
      "badge sort sort sort";
    align-items: center;
  }
  .top-bar:has(#flowExperience:not([hidden])) .flow-experience {
    grid-area: experience;
    width: 100%;
    margin: 1px 0 0;
    grid-template-columns: minmax(0, 1fr) auto;
    grid-template-areas: "meta review" "track review";
    align-items: center;
  }
  .top-bar:has(#flowExperience:not([hidden])) .flow-experience-row {
    flex-direction: row;
    align-items: center;
  }
  .top-bar:has(#flowExperience:not([hidden])) .flow-review-button {
    width: auto;
    min-width: 106px;
    align-self: stretch;
  }
  .top-bar:has(#flowExperience:not([hidden])) .top-bar .badge { grid-area: badge; }
}
@media (max-width: 480px) {
  .top-bar:has(#flowExperience:not([hidden])) {
    grid-template-columns: auto minmax(0, 1fr) auto auto;
    gap: 6px;
  }
  .top-bar:has(#flowExperience:not([hidden])) .flow-experience-row { gap: 5px; }
  .top-bar:has(#flowExperience:not([hidden])) .flow-progress-label { font-size: 9px; }
  .top-bar:has(#flowExperience:not([hidden])) .flow-review-button { min-width: 102px; padding-inline: 7px; font-size: 10px; }
}
