/* ============================================================
   FERALVOICE OS — APP SHELL LAYOUT
   Sidebar, Topbar, Content area, Client portal shell
   ============================================================ */

/* ---------- 1. APP SHELL ---------- */
html:has(.app-shell),
body:has(.app-shell) {
  height: 100% !important;
  overflow: hidden !important;
}
.app-shell {
  display: grid;
  grid-template-columns: 260px 1fr;
  grid-template-rows: 64px 1fr;
  grid-template-areas:
    "sidebar topbar"
    "sidebar content";
  height: 100vh;
  overflow: hidden;
}
.app-shell.collapsed { grid-template-columns: 72px 1fr; }
.app-shell.client-shell { grid-template-columns: 240px 1fr; }

/* ---------- 2. SIDEBAR ---------- */
.sidebar {
  grid-area: sidebar;
  background: var(--bg-surface);
  border-right: 1px solid var(--border-subtle);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  transition: width var(--t-base);
  position: relative;
  z-index: 30;
}
.sidebar-header {
  height: 64px;
  display: flex;
  align-items: center;
  padding: 0 var(--space-5);
  border-bottom: 1px solid var(--border-subtle);
  flex-shrink: 0;
  gap: var(--space-3);
}
.sidebar-header .fv-logo { flex: 1; }
.sidebar-collapse {
  width: 28px; height: 28px;
  border-radius: var(--radius-sm);
  display: grid; place-items: center;
  color: var(--text-muted);
  transition: all var(--t-fast);
}
.sidebar-collapse:hover { background: var(--bg-hover); color: var(--text-primary); }

.sidebar-nav { flex: 1; overflow-y: auto; overflow-x: hidden; padding: var(--space-3); }
.sidebar-nav::-webkit-scrollbar { width: 6px; }
.sidebar-section { margin-bottom: var(--space-4); }
.sidebar-section-label {
  font-size: 10px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: var(--text-muted);
  padding: var(--space-2) var(--space-3);
  margin-bottom: var(--space-1);
  white-space: nowrap;
}

.sidebar-item {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  padding: var(--space-2) var(--space-3);
  border-radius: var(--radius-md);
  color: var(--text-secondary);
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  transition: all var(--t-fast);
  margin-bottom: 2px;
  white-space: nowrap;
  position: relative;
}
.sidebar-item:hover { background: var(--bg-hover); color: var(--text-primary); }
.sidebar-item.active {
  background: var(--gradient-surface);
  color: var(--fv-violet-bright);
}
.sidebar-item.active::before {
  content: '';
  position: absolute;
  left: -12px;
  top: 50%;
  transform: translateY(-50%);
  width: 3px;
  height: 18px;
  background: var(--fv-violet);
  border-radius: 0 3px 3px 0;
}
.sidebar-item-icon { width: 18px; height: 18px; flex-shrink: 0; }
.sidebar-item-label { flex: 1; }
.sidebar-item-badge {
  font-size: 10px;
  font-weight: 600;
  padding: 1px 6px;
  border-radius: var(--radius-full);
  background: var(--fv-violet-glow);
  color: var(--fv-violet-bright);
}
.sidebar-item-badge.rose { background: rgba(244, 63, 94, 0.15); color: var(--fv-rose); }
.sidebar-item-badge.amber { background: rgba(245, 158, 11, 0.15); color: var(--fv-amber); }

/* Collapsed state */
.app-shell.collapsed .sidebar-item-label,
.app-shell.collapsed .sidebar-section-label,
.app-shell.collapsed .sidebar-item-badge,
.app-shell.collapsed .sidebar-footer-text { display: none; }
.app-shell.collapsed .sidebar-item { justify-content: center; padding: var(--space-3); }
.app-shell.collapsed .sidebar-header { padding: 0; justify-content: center; }
.app-shell.collapsed .sidebar-header .fv-logo span { display: none; }
.app-shell.collapsed .sidebar-footer { padding: var(--space-3); }
.app-shell.collapsed .sidebar-footer-user { justify-content: center; }
.app-shell.collapsed .sidebar-footer-user-info { display: none; }

.sidebar-footer { padding: var(--space-3); border-top: 1px solid var(--border-subtle); flex-shrink: 0; }
.sidebar-footer-user {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  padding: var(--space-2);
  border-radius: var(--radius-md);
  cursor: pointer;
  transition: background var(--t-fast);
}
.sidebar-footer-user:hover { background: var(--bg-hover); }
.sidebar-footer-user-info { flex: 1; min-width: 0; }
.sidebar-footer-user-name { font-size: 13px; font-weight: 600; color: var(--text-primary); }
.sidebar-footer-user-role { font-size: 11px; color: var(--text-muted); }

/* ---------- 3. TOPBAR ---------- */
.topbar {
  grid-area: topbar;
  background: var(--bg-surface);
  border-bottom: 1px solid var(--border-subtle);
  display: flex;
  align-items: center;
  padding: 0 var(--space-6);
  gap: var(--space-4);
  z-index: 20;
  position: relative;
}
.topbar-search { flex: 1; max-width: 480px; }
.topbar-actions { display: flex; align-items: center; gap: var(--space-2); margin-left: auto; }
.topbar-btn {
  width: 36px; height: 36px;
  border-radius: var(--radius-md);
  display: grid; place-items: center;
  color: var(--text-secondary);
  transition: all var(--t-fast);
  position: relative;
}
.topbar-btn:hover { background: var(--bg-hover); color: var(--text-primary); }
.topbar-btn-dot { position: absolute; top: 8px; right: 8px; width: 7px; height: 7px; border-radius: 50%; background: var(--fv-rose); border: 2px solid var(--bg-surface); }
.topbar-divider { width: 1px; height: 24px; background: var(--border-subtle); margin: 0 var(--space-2); }

.topbar-quick-add {
  display: flex; align-items: center; gap: var(--space-2);
  padding: 0 var(--space-3);
  height: 36px;
  border-radius: var(--radius-md);
  background: var(--gradient-brand);
  color: white;
  font-size: 13px;
  font-weight: 500;
  transition: all var(--t-base);
  box-shadow: 0 2px 6px var(--fv-violet-glow);
}
.topbar-quick-add:hover { background: var(--gradient-brand-hover); }

/* Theme toggle */
.theme-toggle { width: 56px; height: 28px; background: var(--bg-surface-2); border-radius: var(--radius-full); border: 1px solid var(--border); display: flex; align-items: center; padding: 2px; position: relative; cursor: pointer; }
.theme-toggle-thumb { width: 22px; height: 22px; border-radius: 50%; background: var(--bg-surface); box-shadow: var(--shadow-sm); display: grid; place-items: center; color: var(--fv-amber); transition: transform var(--t-base); }
[data-theme="dark"] .theme-toggle-thumb { transform: translateX(0); color: var(--fv-violet-bright); }
[data-theme="light"] .theme-toggle-thumb { transform: translateX(28px); color: var(--fv-amber); }

/* ---------- 4. CONTENT AREA ---------- */
.content-area {
  grid-area: content;
  overflow-y: auto;
  background: var(--bg-base);
  position: relative;
}
.content-area::before {
  content: '';
  position: fixed;
  top: 0; left: 0; right: 0; height: 220px;
  background: var(--gradient-hero);
  pointer-events: none;
  z-index: 0;
}
.content-inner {
  padding: var(--space-6) var(--space-8);
  max-width: 1600px;
  margin: 0 auto;
  position: relative;
  z-index: 1;
}
.content-inner-narrow { max-width: 1200px; }

/* ---------- 5. LOGIN / AUTH ---------- */
.auth-shell {
  min-height: 100vh;
  display: grid;
  grid-template-columns: 1fr 1fr;
  background: var(--bg-base);
  position: relative;
  overflow: hidden;
}
.auth-visual {
  background: radial-gradient(ellipse 80% 60% at 30% 20%, rgba(139, 92, 246, 0.25), transparent), radial-gradient(ellipse 60% 50% at 70% 80%, rgba(99, 102, 241, 0.2), transparent), var(--bg-surface);
  position: relative;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  padding: var(--space-10);
  border-right: 1px solid var(--border-subtle);
}
.auth-visual::before {
  content: '';
  position: absolute;
  inset: 0;
  background-image:
    linear-gradient(rgba(139, 92, 246, 0.04) 1px, transparent 1px),
    linear-gradient(90deg, rgba(139, 92, 246, 0.04) 1px, transparent 1px);
  background-size: 48px 48px;
  mask-image: radial-gradient(ellipse 60% 50% at 50% 50%, black, transparent);
}
.auth-visual-content { position: relative; z-index: 1; }
.auth-visual h1 { font-size: 42px; line-height: 1.1; font-weight: 700; letter-spacing: -0.03em; margin: var(--space-6) 0 var(--space-4); }
.auth-visual p { font-size: 15px; line-height: 1.6; max-width: 380px; }
.auth-visual-stats { display: flex; gap: var(--space-8); position: relative; z-index: 1; }
.auth-visual-stat-value { font-size: 28px; font-weight: 700; color: var(--text-primary); }
.auth-visual-stat-label { font-size: 12px; color: var(--text-muted); margin-top: 4px; }

.auth-form-side {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: var(--space-10);
  position: relative;
}
.auth-card {
  width: 100%;
  max-width: 400px;
}
.auth-card h2 { font-size: 24px; font-weight: 700; }
.auth-tabs { display: flex; background: var(--bg-surface-2); padding: 4px; border-radius: var(--radius-md); margin: var(--space-5) 0; }
.auth-tab { flex: 1; padding: var(--space-2) var(--space-3); text-align: center; font-size: 13px; font-weight: 500; color: var(--text-muted); border-radius: var(--radius-sm); cursor: pointer; transition: all var(--t-fast); }
.auth-tab.active { background: var(--bg-surface); color: var(--text-primary); box-shadow: var(--shadow-sm); }

/* Floating orbs */
.auth-orb { position: absolute; border-radius: 50%; filter: blur(80px); pointer-events: none; }
.auth-orb-1 { width: 320px; height: 320px; background: rgba(139, 92, 246, 0.3); top: -100px; right: -80px; animation: fv-float 8s ease-in-out infinite; }
.auth-orb-2 { width: 240px; height: 240px; background: rgba(6, 182, 212, 0.2); bottom: 80px; left: -60px; animation: fv-float 10s ease-in-out infinite reverse; }

/* ---------- 6. DRAWER (right side panel) ---------- */
.drawer-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(5, 7, 12, 0.5);
  backdrop-filter: blur(4px);
  z-index: 900;
  opacity: 0;
  visibility: hidden;
  transition: all var(--t-base);
}
.drawer-backdrop.open { opacity: 1; visibility: visible; }
.drawer {
  position: fixed;
  top: 0; right: 0; bottom: 0;
  width: 480px;
  max-width: 90vw;
  background: var(--bg-surface);
  border-left: 1px solid var(--border);
  z-index: 901;
  transform: translateX(100%);
  transition: transform var(--t-slow);
  display: flex;
  flex-direction: column;
  box-shadow: var(--shadow-lg);
}
.drawer-backdrop.open .drawer { transform: translateX(0); }
.drawer-header { padding: var(--space-5) var(--space-6); border-bottom: 1px solid var(--border-subtle); display: flex; align-items: center; justify-content: space-between; }
.drawer-body { flex: 1; overflow-y: auto; padding: var(--space-5) var(--space-6); }
.drawer-footer { padding: var(--space-4) var(--space-6); border-top: 1px solid var(--border-subtle); display: flex; gap: var(--space-3); justify-content: flex-end; }

/* ---------- 7. NOTIFICATIONS PANEL ---------- */
.notification-panel {
  position: absolute;
  top: calc(100% + 8px);
  right: 24px;
  width: 360px;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg);
  z-index: 100;
  opacity: 0;
  visibility: hidden;
  transform: translateY(-4px);
  transition: all var(--t-base);
  overflow: hidden;
}
.notification-panel.open { opacity: 1; visibility: visible; transform: translateY(0); }
.notification-header { padding: var(--space-4); border-bottom: 1px solid var(--border-subtle); display: flex; align-items: center; justify-content: space-between; }
.notification-list { max-height: 360px; overflow-y: auto; }
.notification-item { padding: var(--space-3) var(--space-4); display: flex; gap: var(--space-3); cursor: pointer; transition: background var(--t-fast); border-bottom: 1px solid var(--border-subtle); }
.notification-item:hover { background: var(--bg-hover); }
.notification-item.unread { background: rgba(139, 92, 246, 0.04); }
.notification-icon { width: 32px; height: 32px; border-radius: var(--radius-md); display: grid; place-items: center; flex-shrink: 0; }

/* ---------- 8. RESPONSIVE ---------- */
@media (max-width: 1024px) {
  .app-shell { grid-template-columns: 72px 1fr; }
  .app-shell .sidebar-item-label,
  .app-shell .sidebar-section-label,
  .app-shell .sidebar-item-badge,
  .app-shell .sidebar-footer-text { display: none; }
  .app-shell .sidebar-item { justify-content: center; padding: var(--space-3); }
  .app-shell .sidebar-header { padding: 0; justify-content: center; }
  .app-shell .sidebar-header .fv-logo span { display: none; }
  .content-inner { padding: var(--space-4); }
}
@media (max-width: 768px) {
  .auth-shell { grid-template-columns: 1fr; }
  .auth-visual { display: none; }
  .form-row, .form-row-3 { grid-template-columns: 1fr; }
  .page-header { flex-direction: column; align-items: flex-start; }
  .page-actions { width: 100%; flex-wrap: wrap; }
  .topbar-search { display: none; }
}

/* ---------- 9. CLIENT PORTAL THEME VARIATION ---------- */
.client-shell .sidebar { background: linear-gradient(180deg, var(--bg-surface) 0%, var(--bg-surface-2) 100%); }
.client-shell .sidebar-item.active { background: rgba(6, 182, 212, 0.1); color: var(--fv-cyan); }
.client-shell .sidebar-item.active::before { background: var(--fv-cyan); }
.client-shell .topbar-quick-add { background: linear-gradient(135deg, #06b6d4, #3b82f6); }

/* ---------- 10. CHAT / MESSAGING ---------- */
.chat-layout { display: grid; grid-template-columns: 320px 1fr; height: calc(100vh - 64px - 48px); background: var(--bg-surface); border-radius: var(--radius-lg); border: 1px solid var(--border-subtle); overflow: hidden; }
.chat-sidebar { border-right: 1px solid var(--border-subtle); display: flex; flex-direction: column; }
.chat-sidebar-header { padding: var(--space-4); border-bottom: 1px solid var(--border-subtle); }
.chat-list { flex: 1; overflow-y: auto; }
.chat-item { padding: var(--space-3) var(--space-4); display: flex; gap: var(--space-3); cursor: pointer; border-bottom: 1px solid var(--border-subtle); transition: background var(--t-fast); }
.chat-item:hover { background: var(--bg-hover); }
.chat-item.active { background: var(--bg-hover); }
.chat-main { display: flex; flex-direction: column; }
.chat-header { padding: var(--space-4); border-bottom: 1px solid var(--border-subtle); display: flex; align-items: center; justify-content: space-between; }
.chat-messages { flex: 1; overflow-y: auto; padding: var(--space-5); display: flex; flex-direction: column; gap: var(--space-4); }
.chat-message { display: flex; gap: var(--space-3); max-width: 70%; }
.chat-message-bubble { padding: var(--space-3) var(--space-4); border-radius: var(--radius-lg); font-size: 13px; line-height: 1.5; }
.chat-message.outbound { align-self: flex-end; flex-direction: row-reverse; }
.chat-message.outbound .chat-message-bubble { background: var(--gradient-brand); color: white; border-bottom-right-radius: 4px; }
.chat-message.inbound .chat-message-bubble { background: var(--bg-elevated); color: var(--text-primary); border-bottom-left-radius: 4px; }
.chat-input { padding: var(--space-3) var(--space-4); border-top: 1px solid var(--border-subtle); display: flex; gap: var(--space-2); align-items: center; }

/* ---------- 11. CALENDAR ---------- */
.calendar-grid { display: grid; grid-template-columns: repeat(7, 1fr); gap: 1px; background: var(--border-subtle); border: 1px solid var(--border-subtle); border-radius: var(--radius-lg); overflow: hidden; }
.calendar-header { padding: var(--space-3); text-align: center; font-size: 11px; font-weight: 600; text-transform: uppercase; letter-spacing: 0.06em; color: var(--text-muted); background: var(--bg-surface-2); }
.calendar-cell { background: var(--bg-surface); min-height: 110px; padding: var(--space-2); position: relative; transition: background var(--t-fast); }
.calendar-cell:hover { background: var(--bg-surface-2); }
.calendar-cell.other-month { background: var(--bg-base); opacity: 0.5; }
.calendar-cell.today { background: rgba(139, 92, 246, 0.05); }
.calendar-cell.today .calendar-day { background: var(--fv-violet); color: white; width: 24px; height: 24px; border-radius: 50%; display: grid; place-items: center; }
.calendar-day { font-size: 12px; font-weight: 600; color: var(--text-secondary); margin-bottom: var(--space-1); }
.calendar-event { font-size: 11px; padding: 2px 6px; border-radius: 3px; margin-bottom: 2px; cursor: pointer; truncate: 1; }

/* ---------- 12. FILE MANAGER ---------- */
.file-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(180px, 1fr)); gap: var(--space-3); }
.file-card { background: var(--bg-surface); border: 1px solid var(--border-subtle); border-radius: var(--radius-md); padding: var(--space-3); cursor: pointer; transition: all var(--t-base); position: relative; }
.file-card:hover { border-color: var(--border); transform: translateY(-2px); box-shadow: var(--shadow-md); }
.file-card-icon { width: 48px; height: 48px; border-radius: var(--radius-md); display: grid; place-items: center; margin: 0 auto var(--space-3); font-size: 22px; }
.file-card-name { font-size: 12px; font-weight: 500; text-align: center; color: var(--text-primary); }
.file-card-meta { font-size: 11px; color: var(--text-muted); text-align: center; margin-top: 2px; }
.file-card-checkbox { position: absolute; top: var(--space-2); left: var(--space-2); opacity: 0; transition: opacity var(--t-fast); }
.file-card:hover .file-card-checkbox { opacity: 1; }

/* ---------- 13. WIKI / KNOWLEDGE BASE ---------- */
.wiki-layout { display: grid; grid-template-columns: 280px 1fr; gap: var(--space-5); }
.wiki-sidebar { background: var(--bg-surface); border: 1px solid var(--border-subtle); border-radius: var(--radius-lg); padding: var(--space-3); height: fit-content; }
.wiki-nav-item { padding: var(--space-2) var(--space-3); border-radius: var(--radius-sm); font-size: 13px; color: var(--text-secondary); cursor: pointer; transition: all var(--t-fast); display: flex; align-items: center; gap: var(--space-2); }
.wiki-nav-item:hover { background: var(--bg-hover); color: var(--text-primary); }
.wiki-nav-item.active { background: var(--gradient-surface); color: var(--fv-violet-bright); font-weight: 500; }
.wiki-content { background: var(--bg-surface); border: 1px solid var(--border-subtle); border-radius: var(--radius-lg); padding: var(--space-6); }
.wiki-content h1 { font-size: 28px; margin-bottom: var(--space-3); }
.wiki-content h2 { font-size: 20px; margin: var(--space-6) 0 var(--space-3); }
.wiki-content p { font-size: 14px; line-height: 1.7; margin-bottom: var(--space-4); }
.wiki-content ul { margin: var(--space-3) 0; padding-left: var(--space-5); }
.wiki-content li { font-size: 14px; line-height: 1.7; color: var(--text-secondary); list-style: disc; }
.wiki-content code { background: var(--bg-elevated); padding: 2px 6px; border-radius: 4px; font-size: 13px; }
.wiki-content pre { background: var(--bg-base); border: 1px solid var(--border-subtle); border-radius: var(--radius-md); padding: var(--space-4); overflow-x: auto; margin: var(--space-4) 0; }
.wiki-content pre code { background: none; padding: 0; }

/* ---------- 14. FUNNEL BUILDER ---------- */
.funnel-canvas { display: flex; flex-direction: column; align-items: center; gap: var(--space-3); padding: var(--space-6); }
.funnel-stage { width: 60%; background: var(--bg-surface); border: 1px solid var(--border-subtle); border-radius: var(--radius-lg); padding: var(--space-4); position: relative; transition: all var(--t-base); cursor: pointer; }
.funnel-stage:hover { border-color: var(--fv-violet); transform: translateY(-2px); box-shadow: var(--shadow-md); }
.funnel-stage-connector { width: 2px; height: 24px; background: var(--border); }
.funnel-stage-num { position: absolute; left: -32px; top: 50%; transform: translateY(-50%); width: 24px; height: 24px; border-radius: 50%; background: var(--gradient-brand); color: white; display: grid; place-items: center; font-size: 11px; font-weight: 700; }
