:root {
  --header-h: 56px;
}

/* ═══════════════════════════════════════════════════════════
   MindPal — Global Styles
   ═══════════════════════════════════════════════════════════ */

:root {
  --bg:        #0f1117;
  --bg2:       #181c27;
  --bg3:       #1e2338;
  --surface:   #252b3e;
  --surface2:  #2e364f;
  --border:    #3a4260;
  --text:      #e2e8f5;
  --text2:     #8b9abf;
  --accent:    #6366f1;
  --accent2:   #818cf8;
  --success:   #22c55e;
  --danger:    #ef4444;
  --warning:   #f59e0b;
  --radius:    10px;
  --shadow:    0 4px 24px rgba(0,0,0,0.35);
  --trans:     cubic-bezier(0.4,0,0.2,1);
}

*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

html, body {
  height: 100%;
  font-family: 'Segoe UI', system-ui, -apple-system, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.6;
}

/* ── Typography ──────────────────────────────────────────── */
h1 { font-size: 1.8rem; font-weight: 700; }
h2 { font-size: 1.4rem; font-weight: 600; }
h3 { font-size: 1.1rem; font-weight: 600; margin-bottom: .5rem; }
a  { color: var(--accent2); text-decoration: none; }
a:hover { text-decoration: underline; }

/* ── Buttons ─────────────────────────────────────────────── */
.btn {
  display: inline-flex; align-items: center; gap: .4rem;
  padding: .45rem 1rem;
  border: none; border-radius: var(--radius);
  font-size: .875rem; font-weight: 500;
  cursor: pointer; transition: all .15s var(--trans);
  white-space: nowrap;
}
.btn:active { transform: scale(.97); }
.btn-primary  { background: var(--accent);  color: #fff; }
.btn-primary:hover  { background: var(--accent2); }
.btn-secondary{ background: var(--surface2); color: var(--text); }
.btn-secondary:hover { background: var(--border); }
.btn-ghost    { background: transparent; color: var(--text2); }
.btn-ghost:hover { background: var(--surface); }
.btn-danger   { background: var(--danger);  color: #fff; }
.btn-danger:hover  { background: #dc2626; }
.btn-xs { padding: .2rem .5rem; font-size: .75rem; border-radius: 6px; }

/* ── Inputs ──────────────────────────────────────────────── */
.input, textarea.input {
  width: 100%;
  padding: .5rem .75rem;
  background: var(--bg3);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text);
  font-size: .9rem;
  transition: border-color .15s;
  outline: none;
}
.input:focus, textarea.input:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(99,102,241,.2);
}
select.input { appearance: none; cursor: pointer; }
label {
  display: flex; flex-direction: column; gap: .3rem;
  font-size: .85rem; font-weight: 500; color: var(--text2);
}

/* ── Topbar ──────────────────────────────────────────────── */
.topbar {
  position: fixed; top: 0; left: 0; right: 0; z-index: 100;
  height: var(--header-h);
  min-height: var(--header-h);
  box-sizing: border-box;
  display: flex; align-items: center; gap: 1rem;
  padding: 0 1.25rem;
  background: var(--bg2);
  border-bottom: 1px solid var(--border);
  box-shadow: 0 2px 8px rgba(0,0,0,0.2);
}
.topbar-brand {
  font-size: 1.2rem; font-weight: 800;
  background: linear-gradient(135deg, var(--accent), var(--accent2));
  -webkit-background-clip: text; -webkit-text-fill-color: transparent;
  background-clip: text;
  letter-spacing: -.5px;
  text-decoration: none;
  flex-shrink: 0;
}
.topbar-search-wrap {
  flex: 1; max-width: 440px; position: relative;
}
.topbar-search-wrap input {
  padding-left: 2.2rem; background: var(--bg3);
}
.search-icon {
  position: absolute; left: .7rem; top: 50%; transform: translateY(-50%);
  color: var(--text2); pointer-events: none;
}
#search-panel {
  position: absolute; top: calc(100% + 6px); left: 0; right: 0;
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); box-shadow: var(--shadow);
  max-height: 400px; overflow-y: auto;
  display: none; z-index: 200;
}
#search-panel.open { display: block; }
.search-result {
  display: flex; flex-direction: column; gap: .15rem;
  padding: .6rem 1rem;
  border-bottom: 1px solid var(--border);
  color: var(--text); text-decoration: none;
  transition: background .1s;
}
.search-result:hover { background: var(--surface2); }
.sr-type {
  font-size: .7rem; font-weight: 700; letter-spacing: .05em;
  padding: .1rem .4rem; border-radius: 4px; align-self: flex-start;
  background: var(--accent); color: #fff;
}
.sr-type-file    { background: var(--warning); color: #000; }
.sr-type-link    { background: var(--success); color: #000; }
.sr-title { font-weight: 500; }
.sr-path  { font-size: .75rem; color: var(--text2); }
.search-empty { padding: 1rem; color: var(--text2); text-align: center; }

.topbar-spacer { flex: 1; }
#user-menu-btn {
  background: var(--surface); border: 1px solid var(--border);
  color: var(--text); padding: .35rem .8rem; border-radius: 20px;
  cursor: pointer; font-size: .85rem; font-weight: 500;
  transition: background .15s;
}
#user-menu-btn:hover { background: var(--surface2); }

/* ── Page wrapper (below topbar) ─────────────────────────── */
.page {
  padding-top: var(--header-h);
  min-height: 100vh;
}

/* ── Login page ──────────────────────────────────────────── */
.login-page {
  display: flex; align-items: center; justify-content: center;
  min-height: 100vh;
  background: radial-gradient(ellipse at 60% 40%, #1a1f3a 0%, var(--bg) 70%);
}
.login-card {
  width: 100%; max-width: 380px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 2.5rem 2rem;
  box-shadow: var(--shadow);
}
.login-logo {
  text-align: center; margin-bottom: 1.5rem;
  font-size: 2.5rem;
}
.login-card h1 { text-align: center; margin-bottom: .25rem; }
.login-card .tagline {
  text-align: center; color: var(--text2); margin-bottom: 2rem;
  font-size: .9rem;
}
.login-card form { display: flex; flex-direction: column; gap: 1rem; }
.login-switch { text-align: center; margin-top: 1rem; color: var(--text2); font-size: .875rem; }
.login-switch a { color: var(--accent2); }
.login-error { color: var(--danger); font-size: .875rem; text-align: center; }

/* ── Dashboard ───────────────────────────────────────────── */
.dashboard {
  max-width: 1100px; margin: 0 auto;
  padding: 2rem 1.5rem;
  padding-top: calc(var(--header-h) + 2rem);
}
.dashboard-header {
  display: flex; align-items: center; justify-content: space-between;
  margin-bottom: 2rem; flex-wrap: wrap; gap: 1rem;
}
.section-label {
  font-size: .75rem; font-weight: 700; text-transform: uppercase;
  letter-spacing: .08em; color: var(--text2); margin-bottom: 1rem;
}
.palace-grid {
  display: grid; grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: 1.25rem; margin-bottom: 2.5rem;
}
.palace-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 1.25rem;
  cursor: pointer;
  transition: all .2s var(--trans);
  text-decoration: none; color: var(--text);
  position: relative;
}
.palace-card:hover {
  border-color: var(--accent);
  box-shadow: 0 0 0 1px var(--accent), 0 8px 20px rgba(99,102,241,.15);
  transform: translateY(-2px);
}
.palace-card-icon { font-size: 2rem; margin-bottom: .5rem; }
.palace-card-name { font-size: 1.05rem; font-weight: 700; margin-bottom: .25rem; }
.palace-card-desc { color: var(--text2); font-size: .85rem; margin-bottom: .75rem;
  display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.palace-card-meta { display: flex; align-items: center; gap: .5rem; flex-wrap: wrap; }
.role-badge {
  font-size: .7rem; font-weight: 700; letter-spacing: .04em; text-transform: uppercase;
  padding: .15rem .5rem; border-radius: 20px;
}
.role-admin  { background: #6366f120; color: var(--accent2); border: 1px solid var(--accent); }
.role-editor { background: #22c55e20; color: #4ade80; border: 1px solid var(--success); }
.role-viewer { background: #f59e0b20; color: #fbbf24; border: 1px solid var(--warning); }
.palace-owner { font-size: .75rem; color: var(--text2); }

/* ── Palace view layout ──────────────────────────────────── */
.palace-layout {
  display: flex; height: calc(100vh - var(--header-h));
}
.palace-sidebar {
  width: 240px; flex-shrink: 0;
  background: var(--bg2);
  border-right: 1px solid var(--border);
  display: flex; flex-direction: column;
  overflow: hidden;
}
.sidebar-header {
  padding: 1rem;
  border-bottom: 1px solid var(--border);
}
.sidebar-title { font-weight: 700; font-size: 1rem; margin-bottom: .25rem; }
.sidebar-desc  { font-size: .8rem; color: var(--text2); line-height: 1.4; }
.sidebar-actions { padding: .75rem 1rem; border-bottom: 1px solid var(--border); display: flex; flex-direction: column; gap: .5rem; }
.room-list {
  list-style: none; overflow-y: auto; flex: 1; padding: .5rem;
}
.room-list-item {
  display: flex; align-items: center; gap: .5rem;
  padding: .5rem .75rem; border-radius: 8px; cursor: pointer;
  font-size: .875rem; transition: background .1s;
}
.room-list-item:hover { background: var(--surface); }
.room-icon-sm { font-size: 1.1rem; }

#canvas-wrap {
  flex: 1; position: relative; overflow: hidden;
}
#palace-canvas { position: absolute; inset: 0; }

/* ── Room view layout ────────────────────────────────────── */
.room-layout {
  display: flex; height: calc(100vh - var(--header-h));
}
#canvas-wrap {
  flex: 1; position: relative; overflow: hidden;
}
#room-canvas { position: absolute; inset: 0; background: var(--bg2); }

/* ── Asset panel ─────────────────────────────────────────── */
#asset-panel {
  width: 0; flex-shrink: 0;
  background: var(--bg2);
  border-left: 1px solid var(--border);
  transition: width .25s var(--trans);
  overflow: hidden; display: flex; flex-direction: column;
}
#asset-panel.open { width: 340px; }
.panel-header {
  display: flex; align-items: center; gap: .75rem;
  padding: 1rem;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}
.panel-peg-icon { font-size: 1.8rem; }
.panel-peg-name { font-weight: 700; font-size: 1rem; flex: 1; }
.panel-tabs {
  display: flex;
  border-bottom: 1px solid var(--border); flex-shrink: 0;
}
.panel-tab {
  flex: 1; padding: .6rem; background: none; border: none;
  color: var(--text2); font-size: .8rem; font-weight: 500;
  cursor: pointer; border-bottom: 2px solid transparent;
  transition: all .15s;
}
.panel-tab:hover { color: var(--text); background: var(--surface); }
.panel-tab.active { color: var(--accent2); border-bottom-color: var(--accent); }
.panel-body { flex: 1; overflow-y: auto; }
.panel-section { display: none; padding: 1rem; }
.panel-section.active { display: block; }

.asset-card {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: 10px; padding: .75rem; margin-bottom: .75rem;
}
.asset-header {
  display: flex; align-items: center; justify-content: space-between;
  gap: .5rem; margin-bottom: .4rem;
}
.asset-title { font-weight: 600; font-size: .875rem; }
.asset-actions { display: flex; gap: .25rem; }
.asset-textarea {
  width: 100%; min-height: 80px; resize: vertical;
  background: var(--bg3); border: 1px solid var(--border);
  border-radius: 8px; color: var(--text); padding: .5rem;
  font-size: .85rem; margin-bottom: .5rem;
}
.asset-url  { color: var(--text2); font-size: .75rem; word-break: break-all; }
.asset-link { color: var(--accent2); font-weight: 500; font-size: .875rem; }
.asset-meta { color: var(--text2); font-size: .75rem; }
.asset-new {
  display: flex; flex-direction: column; gap: .5rem;
  margin-top: .75rem; padding-top: .75rem;
  border-top: 1px dashed var(--border);
}
.upload-label { cursor: pointer; }

/* ── Breadcrumb ──────────────────────────────────────────── */
.breadcrumb {
  display: flex; align-items: center; gap: .4rem;
  font-size: .8rem; color: var(--text2); padding: .6rem 1rem;
  background: var(--bg2); border-bottom: 1px solid var(--border);
}
.breadcrumb a { color: var(--text2); }
.breadcrumb a:hover { color: var(--accent2); }
.breadcrumb-sep { color: var(--border); }

/* ── Room toolbar ────────────────────────────────────────── */
.room-toolbar {
  position: absolute; top: .75rem; left: .75rem; z-index: 10;
  display: flex; gap: .5rem;
}
.palace-toolbar {
  position: absolute; top: .75rem; right: .75rem; z-index: 10;
  display: flex; gap: .5rem;
}

/* ── Context menu ────────────────────────────────────────── */
.ctx-menu {
  position: fixed; z-index: 999;
  background: var(--surface); border: 1px solid var(--border);
  border-radius: 10px; box-shadow: var(--shadow);
  overflow: hidden; min-width: 150px;
  display: none;
}
.ctx-menu.open { display: block; }
.ctx-item {
  display: block; width: 100%; padding: .55rem 1rem;
  background: none; border: none; text-align: left;
  color: var(--text); font-size: .875rem; cursor: pointer;
  transition: background .1s;
}
.ctx-item:hover { background: var(--surface2); }
.ctx-item.danger { color: var(--danger); }

/* ── Modal ───────────────────────────────────────────────── */
.modal-overlay {
  position: fixed; inset: 0; z-index: 900;
  background: rgba(0,0,0,0.6);
  display: flex; align-items: center; justify-content: center;
  opacity: 0; transition: opacity .2s;
  backdrop-filter: blur(3px);
}
.modal-overlay.show { opacity: 1; }
.modal-box {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: 14px; padding: 1.75rem;
  width: min(520px, 92vw); max-height: 85vh; overflow-y: auto;
  box-shadow: var(--shadow);
  display: flex; flex-direction: column; gap: 1rem;
  transform: scale(.95); transition: transform .2s;
}
.modal-overlay.show .modal-box { transform: scale(1); }
.modal-actions {
  display: flex; justify-content: flex-end; gap: .5rem; margin-top: .5rem;
}
.confirm-box { max-width: 360px; }
.confirm-box p { font-size: .95rem; }

/* ── Icon library picker ─────────────────────────────────── */
.icon-library {
  display: flex; flex-wrap: wrap; gap: .3rem;
}
.icon-btn {
  font-size: 1.4rem; padding: .25rem; width: 44px; height: 44px;
  background: var(--bg3); border: 2px solid transparent;
  border-radius: 8px; cursor: pointer; display: flex;
  align-items: center; justify-content: center; transition: all .1s;
}
.icon-btn:hover   { background: var(--surface2); border-color: var(--border); }
.icon-btn.selected{ border-color: var(--accent); background: var(--surface2); }

/* ── Share member list ───────────────────────────────────── */
.share-member-list { display: flex; flex-direction: column; gap: .5rem; }
.share-member {
  display: flex; align-items: center; gap: .5rem;
  padding: .5rem; background: var(--bg3); border-radius: 8px; font-size: .875rem;
}
.share-member span:first-child { flex: 1; }

/* ── Toast ───────────────────────────────────────────────── */
#toast-container {
  position: fixed; bottom: 1.5rem; right: 1.5rem; z-index: 9999;
  display: flex; flex-direction: column; gap: .5rem; pointer-events: none;
}
.toast {
  padding: .65rem 1.1rem; border-radius: 10px;
  font-size: .875rem; font-weight: 500;
  background: var(--surface2); color: var(--text);
  border: 1px solid var(--border);
  box-shadow: var(--shadow);
  opacity: 0; transform: translateX(20px);
  transition: all .25s var(--trans);
}
.toast.show { opacity: 1; transform: translateX(0); }
.toast-error   { background: #7f1d1d; border-color: var(--danger); }
.toast-success { background: #14532d; border-color: var(--success); }

/* ── Scrollbar ───────────────────────────────────────────── */
::-webkit-scrollbar { width: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 99px; }
::-webkit-scrollbar-thumb:hover { background: var(--text2); }

/* ── Utility ─────────────────────────────────────────────── */
.flex { display: flex; }
.gap-1 { gap: .5rem; }
.mt-1 { margin-top: .5rem; }
.mt-2 { margin-top: 1rem; }
hr { border: none; border-top: 1px solid var(--border); }

/* ── Responsive ──────────────────────────────────────────── */
@media (max-width: 768px) {
  .palace-sidebar { width: 200px; }
  #asset-panel.open { width: 100%; position: absolute; right: 0; top: 0; bottom: 0; z-index: 50; }
  .topbar-search-wrap { max-width: 200px; }
}

/* ── Admin-only elements (hidden for viewer/editor roles) ───────────────────── */
.admin-only { /* shown by default, hidden via JS for non-admins */ }

/* ── Upload progress ─────────────────────────────────────────────────────────── */
#upload-progress {
  font-size: .8rem; color: var(--text2);
  padding: .4rem; text-align: center;
  border: 1px dashed var(--border); border-radius: 8px;
  animation: pulse 1s ease-in-out infinite alternate;
}
@keyframes pulse { from { opacity: .5 } to { opacity: 1 } }