/* ─── Variables ─── */
:root {
  --p:   #1a73e8;
  --pd:  #1557b0;
  --pl:  #4285f4;
  --bg:  #eef2ff;
  --sf:  #ffffff;
  --sf2: #f4f7ff;
  --tx:  #1e293b;
  --tm:  #64748b;
  --br:  #e2e8f0;
  --sh:  0 1px 3px rgba(26,115,232,.10), 0 4px 12px rgba(26,115,232,.07);
  --shh: 0 6px 20px rgba(26,115,232,.18), 0 14px 36px rgba(26,115,232,.10);
  --chip-bg: #eff6ff;
  --chip-tx: var(--p);
  --del: #ef4444;
  --ac:  var(--p);
}
.dark {
  --bg:  #0f1117;
  --sf:  #1a1d27;
  --sf2: #1e2130;
  --tx:  #e2e8f0;
  --tm:  #94a3b8;
  --br:  #2d3748;
  --sh:  0 1px 4px rgba(0,0,0,.35), 0 4px 14px rgba(0,0,0,.25);
  --shh: 0 6px 20px rgba(0,0,0,.45), 0 14px 36px rgba(0,0,0,.30);
  --chip-bg: rgba(26,115,232,.18);
}
body.has-bg:not(.dark) { --sf: rgba(255,255,255,0.82); --sf2: rgba(244,247,255,0.72); }
body.has-bg.dark       { --sf: rgba(26,29,39,0.84);    --sf2: rgba(30,33,48,0.74);    }
body.has-bg .card,
body.has-bg .sidebar,
body.has-bg .modal,
body.has-bg .drw       { backdrop-filter: blur(12px); -webkit-backdrop-filter: blur(12px); }

/* ─── Scrollbar ─── */
html {
  overflow-y: scroll;
  background-color: var(--bg);
  background-image: var(--bg-url, none);
  background-size: cover;
  background-attachment: fixed;
  background-position: center;
  transition: background-color .3s;
  scrollbar-width: thin;
  scrollbar-color: rgba(100,116,139,.35) transparent;
}
::-webkit-scrollbar              { width: 8px; }
::-webkit-scrollbar-track        { background: transparent; }
::-webkit-scrollbar-thumb        { background: rgba(100,116,139,.35); border-radius: 6px; }
::-webkit-scrollbar-thumb:hover  { background: rgba(100,116,139,.65); }

/* ─── Reset ─── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
body {
  padding-top: 58px;
  padding-left: 0;
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
  background-color: transparent;
  color: var(--tx);
  min-height: 100vh;
  transition: color .3s, padding-left .32s cubic-bezier(0.25,0.46,0.45,0.94);
}
body.sb-visible { padding-left: 220px; }

/* ─── Header ─── */
.hdr {
  background: var(--p);
  color: #fff;
  height: 58px;
  display: flex; align-items: center; justify-content: space-between;
  padding: 0 16px;
  position: fixed; top: 0; left: 0; right: 0; z-index: 100;
  box-shadow: 0 2px 14px rgba(0,0,0,.18);
}
.hdr-left  { display: flex; align-items: center; gap: 8px; overflow: hidden; min-width: 0; flex-shrink: 0; }
.hdr-brand { font-size: 1.2rem; font-weight: 700; letter-spacing: -.3px; user-select: none; white-space: nowrap; }
.hdr-brand em { font-style: normal; font-weight: 400; opacity: .75; }
.hdr-user {
  font-size: .75rem; font-weight: 600;
  background: rgba(255,255,255,.18); color: #fff;
  padding: 3px 10px; border-radius: 20px;
  white-space: nowrap; max-width: 180px;
  overflow: hidden; text-overflow: ellipsis; flex-shrink: 0;
}
.hdr-role-chip {
  display: inline-block; font-size: .62rem; font-weight: 700;
  letter-spacing: .5px; text-transform: uppercase;
  padding: 2px 8px; border-radius: 20px; white-space: nowrap; flex-shrink: 0;
}
.chip-user        { background: rgba(255,255,255,.15); color: rgba(255,255,255,.9); }
.chip-tenant-admin{ background: rgba(52,211,153,.28);  color: #34d399; }
.chip-admin       { background: rgba(251,191,36,.28);  color: #fbbf24; }
.chip-super       { background: rgba(167,139,250,.28); color: #c4b5fd; }
.chip-master      { background: rgba(249,115,22,.28);  color: #fb923c; }
.hdr-acts { display: flex; gap: 4px; flex-shrink: 0; }
.ibtn {
  width: 38px; height: 38px; border-radius: 50%; border: none;
  background: rgba(255,255,255,.15); color: #fff; cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  transition: background .2s; flex-shrink: 0;
}
.ibtn:hover { background: rgba(255,255,255,.28); }
.ibtn svg { pointer-events: none; }

/* ─── Sidebar (pinned) ─── */
.sidebar {
  position: fixed; left: 0; top: 58px; bottom: 0; width: 220px;
  background: var(--sf); border-right: 1px solid var(--br);
  display: flex; flex-direction: column; z-index: 80;
  transform: translateX(-100%);
  transition: background .3s, border-color .3s, transform .32s cubic-bezier(0.25,0.46,0.45,0.94);
  overflow: hidden;
}
.sidebar.visible { transform: translateX(0); }
.sb-hd {
  font-size: .65rem; font-weight: 700; text-transform: uppercase;
  letter-spacing: .6px; color: var(--tm); padding: 14px 14px 6px; flex-shrink: 0;
}
.sb-list { flex: 1; overflow-y: auto; padding: 2px 6px 16px; }
.sb-item {
  display: flex; align-items: center; gap: 9px;
  padding: 7px 8px; border-radius: 8px;
  color: var(--tx); text-decoration: none;
  transition: background .15s;
  cursor: pointer; user-select: none;
}
.sb-item:hover { background: var(--sf2); }
.sb-ico {
  width: 28px; height: 28px; border-radius: 7px; flex-shrink: 0;
  background: var(--p); color: #fff;
  display: flex; align-items: center; justify-content: center;
  font-size: .7rem; font-weight: 700; text-transform: uppercase;
}
.sb-info { min-width: 0; display: flex; flex-direction: column; gap: 1px; }
.sb-name { font-size: .79rem; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.sb-type { font-size: .69rem; color: var(--tm); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.sb-empty { font-size: .78rem; color: var(--tm); padding: 20px 10px; text-align: center; line-height: 1.6; }

/* ─── Main ─── */
.main { max-width: 1300px; margin: 0 auto; padding: 24px 16px 80px; width: 100%; }

/* ─── Toolbar ─── */
.toolbar {
  display: flex; align-items: center; gap: 10px;
  margin-bottom: 20px; flex-wrap: wrap;
}
.search-wrap { flex: 1; min-width: 220px; display: flex; align-items: center; gap: 6px; position: relative; }
.cat-btn {
  display: flex; align-items: center; gap: 4px;
  padding: 0 10px; height: 40px; border-radius: 8px;
  border: 2px solid var(--br); background: var(--sf2); color: var(--tm);
  font-size: .78rem; font-weight: 600; cursor: pointer;
  white-space: nowrap; transition: border-color .15s, color .15s;
  flex-shrink: 0;
}
.cat-btn:hover { border-color: var(--p); color: var(--p); }
.search-inp {
  flex: 1; height: 40px; padding: 0 12px;
  border: 2px solid var(--br); border-radius: 8px;
  background: var(--sf); color: var(--tx);
  font-size: .87rem; font-family: inherit; outline: none;
  transition: border-color .18s;
}
.search-inp:focus { border-color: var(--p); }
.sort-btn {
  width: 40px; height: 40px; border-radius: 8px;
  border: 2px solid var(--br); background: var(--sf2); color: var(--tm);
  cursor: pointer; display: flex; align-items: center; justify-content: center;
  transition: border-color .15s, color .15s; flex-shrink: 0;
}
.sort-btn:hover { border-color: var(--p); color: var(--p); }
.sort-btn.newest svg { transform: rotate(0deg); }
.sort-btn.oldest svg { transform: rotate(180deg); }

/* Cat dropdown */
.cat-drop {
  position: absolute; top: calc(100% + 6px); left: 0;
  background: var(--sf); border: 1px solid var(--br);
  border-radius: 10px; box-shadow: var(--sh); z-index: 50;
  min-width: 180px; padding: 6px 0; display: none;
}
.cat-drop.open { display: block; }
.cat-opt {
  padding: 8px 14px; font-size: .84rem; cursor: pointer; color: var(--tx);
  transition: background .12s;
}
.cat-opt:hover { background: var(--sf2); }
.cat-opt.active { color: var(--p); font-weight: 600; }

/* Per-page + pagination bar */
.list-hdr {
  display: flex; align-items: center; justify-content: space-between;
  gap: 10px; margin-bottom: 14px; flex-wrap: wrap;
}
.per-page-wrap { display: flex; align-items: center; gap: 6px; font-size: .82rem; color: var(--tm); }
.per-sel {
  padding: 4px 8px; border: 1px solid var(--br); border-radius: 6px;
  background: var(--sf2); color: var(--tx); font-size: .82rem; cursor: pointer;
}
.list-count { font-size: .82rem; color: var(--tm); }

/* ─── Code Cards ─── */
.cards { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
@media (max-width: 700px) { .cards { grid-template-columns: 1fr; } }
.card {
  background: var(--sf); border-radius: 12px;
  border: 1px solid var(--br); box-shadow: var(--sh);
  padding: 16px 18px;
  cursor: pointer; user-select: none;
  transition: transform .2s, box-shadow .2s;
  position: relative; overflow: hidden;
}
.card::before { content:''; position:absolute; top:0;left:0;right:0; height:3px; background:var(--p); }
.card:hover { transform: translateY(-2px); box-shadow: var(--shh); }
.card-top { display: flex; align-items: flex-start; gap: 10px; margin-bottom: 6px; }
.card-desc { font-size: .97rem; font-weight: 700; color: var(--tx); flex: 1; line-height: 1.4; }
.card-chip {
  display: inline-flex; align-items: center;
  padding: 2px 9px; background: var(--chip-bg); color: var(--chip-tx);
  border-radius: 12px; font-size: .7rem; font-weight: 700; letter-spacing: .2px;
  flex-shrink: 0; white-space: nowrap;
}
.card-summary { font-size: .83rem; color: var(--tm); line-height: 1.5; margin-bottom: 8px; }
.card-meta { display: flex; gap: 14px; flex-wrap: wrap; }
.card-meta span { font-size: .74rem; color: var(--tm); }
.card-meta strong { color: var(--tx); font-weight: 600; }

/* ─── Empty state ─── */
.empty {
  text-align: center; padding: 72px 24px; color: var(--tm);
}
.empty svg { width: 52px; height: 52px; opacity: .22; margin-bottom: 14px; display: block; margin-inline: auto; }
.empty strong { font-size: 1rem; display: block; margin-bottom: 4px; }
.empty span { font-size: .85rem; }

/* ─── Pagination ─── */
.pagination { display: flex; align-items: center; justify-content: center; gap: 4px; margin-top: 24px; flex-wrap: wrap; }
.pg-btn {
  min-width: 36px; height: 36px; padding: 0 10px; border-radius: 8px;
  border: 1px solid var(--br); background: var(--sf); color: var(--tx);
  font-size: .84rem; cursor: pointer; display: flex; align-items: center; justify-content: center;
  transition: background .15s, border-color .15s;
}
.pg-btn:hover:not(:disabled):not(.active) { border-color: var(--p); color: var(--p); }
.pg-btn.active { background: var(--p); color: #fff; border-color: var(--p); }
.pg-btn:disabled { opacity: .4; cursor: not-allowed; }

/* ─── FAB ─── */
.fab {
  position: fixed; bottom: 28px; right: 28px;
  width: 54px; height: 54px; border-radius: 50%; border: none;
  background: var(--p); color: #fff; cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  box-shadow: 0 4px 18px rgba(26,115,232,.42);
  transition: transform .2s, box-shadow .2s; z-index: 50;
}
.fab:hover { transform: scale(1.09); box-shadow: 0 6px 22px rgba(26,115,232,.55); }

/* ─── Modal overlay ─── */
.ovl {
  position: fixed; inset: 0;
  background: rgba(0,0,0,.46);
  display: flex; align-items: flex-start; justify-content: center;
  padding: 16px; padding-top: 74px; z-index: 200;
  opacity: 0; visibility: hidden;
  transition: opacity .22s, visibility .22s;
  backdrop-filter: blur(3px);
  overflow-y: auto;
}
.ovl.open { opacity: 1; visibility: visible; }
.modal {
  background: var(--sf); border-radius: 16px;
  padding: 26px 28px 24px; width: 100%;
  box-shadow: 0 20px 52px rgba(0,0,0,.28);
  transform: translateY(14px) scale(.97); transition: transform .22s;
}
.ovl.open .modal { transform: none; }
.modal-hd {
  display: flex; align-items: center; justify-content: space-between;
  margin-bottom: 20px;
}
.modal-hd h2 { font-size: 1.1rem; font-weight: 700; }
.modal-x {
  width: 30px; height: 30px; border-radius: 50%; border: none;
  background: var(--sf2); color: var(--tm); cursor: pointer;
  display: flex; align-items: center; justify-content: center; font-size: 1rem;
  transition: background .15s;
}
.modal-x:hover { background: var(--br); }

/* Full card view modal */
.card-modal { max-width: 1100px; }
.cm-layout { display: grid; grid-template-columns: 1fr 260px; gap: 20px; }
@media (max-width: 768px) { .cm-layout { grid-template-columns: 1fr; } }
.cm-main {}
.cm-desc { font-size: 1.15rem; font-weight: 700; color: var(--p); margin-bottom: 8px; line-height: 1.4; }
.cm-summary { font-size: .9rem; color: var(--tm); margin-bottom: 18px; line-height: 1.6; }
.cm-blocks { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; margin-bottom: 12px; align-items: stretch; }
@media (max-width: 600px) { .cm-blocks { grid-template-columns: 1fr; } }
.cm-block {
  display: flex; flex-direction: column;
  background: var(--sf2); border: 1px solid var(--br); border-radius: 10px;
  overflow: hidden; min-height: 260px;
}
.cm-block-lbl {
  font-size: .68rem; font-weight: 700; text-transform: uppercase; letter-spacing: .5px;
  color: var(--tm); padding: 8px 12px; display: flex; align-items: center; justify-content: space-between;
  border-bottom: 1px solid var(--br); flex-shrink: 0; background: var(--sf);
}
.cm-textarea {
  flex: 1; width: 100%; border: none; border-radius: 0;
  background: transparent; color: var(--tx);
  font-size: .83rem; font-family: 'Courier New', Courier, monospace;
  padding: 10px 12px; resize: none;
  outline: none;
  white-space: pre; overflow: auto;
}
.cm-textarea:focus { outline: none; }
.cm-output { min-height: unset; margin-bottom: 12px; }
.cm-textarea.output { flex: none; height: 110px; max-height: 160px; font-family: inherit; resize: vertical; }
.copy-btn {
  padding: 3px 9px; border-radius: 6px; border: 1px solid var(--br);
  background: var(--sf2); color: var(--tm); font-size: .72rem; cursor: pointer;
  transition: background .15s, color .15s;
}
.copy-btn:hover { background: var(--chip-bg); color: var(--p); }
.cm-sidebar {}
.cm-info-box {
  background: var(--sf2); border-radius: 10px; padding: 14px 16px; margin-bottom: 12px;
  font-size: .82rem; line-height: 1.7;
}
.cm-info-box h4 { font-size: .7rem; font-weight: 700; text-transform: uppercase; letter-spacing: .5px; color: var(--tm); margin-bottom: 8px; }
.cm-info-row { display: flex; gap: 6px; margin-bottom: 4px; }
.cm-info-label { color: var(--tm); flex-shrink: 0; min-width: 90px; }
.cm-info-value { color: var(--tx); font-weight: 500; word-break: break-all; }
.cm-mod-item { font-size: .78rem; color: var(--tm); padding: 2px 0; }
.cm-mod-item strong { color: var(--tx); }
.cm-share-item {
  font-size: .78rem; color: var(--tx); padding: 3px 8px;
  background: var(--chip-bg); color: var(--chip-tx); border-radius: 10px;
  display: inline-flex; align-items: center; gap: 6px; margin: 2px;
}
.share-rm { background: none; border: none; cursor: pointer; color: var(--del); font-size: .9rem; line-height: 1; padding: 0 2px; }
.cm-actions { display: flex; gap: 8px; margin-top: 16px; flex-wrap: wrap; }
.pin-btn { display: flex; align-items: center; gap: 5px; }

/* Edit modal */
.edit-modal { max-width: 900px; }
.form-grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
@media (max-width: 600px) { .form-grid2 { grid-template-columns: 1fr; } }

/* Share user search */
.share-search-wrap { display: flex; gap: 6px; margin-bottom: 8px; }
.share-results { max-height: 160px; overflow-y: auto; border: 1px solid var(--br); border-radius: 8px; background: var(--sf); }
.share-result-item { padding: 8px 12px; font-size: .83rem; cursor: pointer; transition: background .12s; }
.share-result-item:hover { background: var(--sf2); }
.share-current { display: flex; flex-wrap: wrap; gap: 4px; margin-top: 8px; min-height: 28px; }

/* ─── Form ─── */
.fld { margin-bottom: 13px; }
.fld label {
  display: block; font-size: .73rem; font-weight: 700;
  text-transform: uppercase; letter-spacing: .45px;
  color: var(--tm); margin-bottom: 5px;
}
.inp, textarea.inp {
  width: 100%; padding: 9px 12px;
  border: 2px solid var(--br); border-radius: 8px;
  background: var(--sf2); color: var(--tx);
  font-size: .88rem; font-family: inherit; outline: none;
  transition: border-color .18s;
}
.inp:focus { border-color: var(--p); }
textarea.inp { resize: vertical; min-height: 80px; }
textarea.code-inp { font-family: 'Courier New', Courier, monospace; font-size: .84rem; min-height: 180px; }
.modal-ft { display: flex; justify-content: flex-end; gap: 8px; margin-top: 20px; }
.btn { padding: 9px 20px; border-radius: 8px; border: none; font-size: .87rem; font-weight: 600; cursor: pointer; transition: opacity .18s, transform .12s; display: inline-flex; align-items: center; gap: 6px; }
.btn:active  { transform: scale(.96); }
.btn-g       { background: var(--sf2); color: var(--tx); border: 2px solid var(--br); }
.btn-g:hover { border-color: var(--p); }
.btn-p       { background: var(--p); color: #fff; }
.btn-p:hover { opacity: .88; }
.btn-danger  { background: rgba(239,68,68,.1); color: var(--del); border: 2px solid rgba(239,68,68,.2); }
.btn-danger:hover { background: rgba(239,68,68,.18); }
.btn-sm { padding: 5px 12px; font-size: .78rem; }
.err { color: #dc2626; font-size: .82rem; margin-top: 6px; }

/* ─── Settings drawer ─── */
.drw-bg { position: fixed; inset: 0; z-index: 149; display: none; }
.drw-bg.open { display: block; }
.drw {
  position: fixed; top: 0; right: -380px;
  width: 360px; height: 100%;
  background: var(--sf); box-shadow: -4px 0 28px rgba(0,0,0,.14);
  z-index: 150; transition: right .3s cubic-bezier(.4,0,.2,1);
  overflow-y: auto;
}
.drw.open { right: 0; }
.drw-hd {
  display: flex; align-items: center; justify-content: space-between;
  padding: 16px 20px; border-bottom: 1px solid var(--br);
  position: sticky; top: 0; background: var(--sf); z-index: 1;
}
.drw-hd h2 { font-size: .97rem; font-weight: 700; }
.drw-sec { padding: 18px 20px; border-bottom: 1px solid var(--br); }
.drw-sec:last-child { border-bottom: none; }
.drw-sec.drw-locked { opacity: .55; pointer-events: none; }
.drw-lock-note { font-size: .75rem; color: var(--tm); font-style: italic; margin-bottom: 10px; margin-top: -6px; }
.sec-lbl { font-size: .7rem; font-weight: 700; text-transform: uppercase; letter-spacing: .55px; color: var(--tm); margin-bottom: 14px; }
.swatches { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; }
.sw {
  aspect-ratio: 1; border-radius: 10px; cursor: pointer;
  border: 3px solid transparent; transition: transform .2s, border-color .2s; position: relative; overflow: hidden;
}
.sw:hover { transform: scale(1.08); }
.sw.on    { border-color: var(--tx); }
.sw-lbl   { position: absolute; bottom:0; left:0; right:0; text-align:center; font-size:.58rem; color:rgba(255,255,255,.92); font-weight:700; padding:2px; background:rgba(0,0,0,.22); }
.clr-row  { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-top: 12px; }
.clr-fld label { display: block; font-size: .73rem; color: var(--tm); margin-bottom: 4px; }
.clr-fld input[type="color"] { width:100%; height:38px; border:2px solid var(--br); border-radius:8px; cursor:pointer; padding:2px 4px; background:var(--sf2); }
.full-btn { width: 100%; margin-top: 10px; }
.bg-drop {
  width:100%; height:110px; border-radius:10px;
  border:2px dashed var(--br); overflow:hidden;
  background:var(--sf2); display:flex; align-items:center; justify-content:center;
  color:var(--tm); font-size:.85rem; cursor:pointer; transition:border-color .18s;
}
.bg-drop:hover { border-color: var(--p); }
.bg-drop img   { width:100%; height:100%; object-fit:cover; }
.tog-row { display: flex; align-items: center; justify-content: space-between; }
.tog-lbl { font-size: .9rem; }
.tog     { position: relative; width: 42px; height: 22px; }
.tog input { display: none; }
.trk { position: absolute; inset: 0; background: var(--br); border-radius: 22px; cursor: pointer; transition: background .2s; }
.trk::after { content:''; position:absolute; width:16px; height:16px; background:#fff; border-radius:50%; top:3px; left:3px; transition:transform .2s; box-shadow:0 1px 3px rgba(0,0,0,.22); }
.tog input:checked + .trk           { background: var(--p); }
.tog input:checked + .trk::after   { transform: translateX(20px); }
.acct-user { font-size: .88rem; color: var(--tm); margin-bottom: 14px; word-break: break-all; }
.acct-user strong { color: var(--tx); font-weight: 700; }

/* ─── Toast ─── */
.toast {
  position: fixed; bottom: 94px; right: 28px;
  padding: 10px 18px; background: var(--tx); color: var(--sf);
  border-radius: 8px; font-size: .84rem; font-weight: 500;
  z-index: 400; transform: translateY(10px); opacity: 0;
  transition: all .24s; pointer-events: none;
}
.toast.show { transform: none; opacity: 1; }

/* ─── Context menu ─── */
.ctx-menu {
  position: fixed; background: var(--sf); border: 1px solid var(--br);
  border-radius: 10px; box-shadow: var(--shh); z-index: 500;
  padding: 6px 0; min-width: 160px; display: none;
}
.ctx-menu.open { display: block; }
.ctx-item { padding: 9px 16px; font-size: .84rem; cursor: pointer; color: var(--tx); transition: background .12s; }
.ctx-item:hover { background: var(--sf2); }
.ctx-item.danger { color: var(--del); }

/* ─── Tenant request modal ─── */
.req-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
@media (max-width: 500px) { .req-grid { grid-template-columns: 1fr; } }

/* ─── Responsive ─── */
@media (max-width: 640px) {
  .sidebar { display: none; }
  body, body.sb-visible { padding-left: 0; }
  .main { padding: 14px 12px 84px; }
  .fab  { bottom: 20px; right: 20px; }
  .drw  { width: 100%; right: -100%; }
  .hdr-user { display: none; }
  .cm-layout { grid-template-columns: 1fr; }
}
