/* =============================================
   SaaS Shell — Shared UX Component Styles
   StackStats Apps LLC — March 2026
   Default: LIGHT theme. Dark mode via [data-theme="dark"] on <html>.
   ============================================= */

/* ── Light theme (default) ──────────────────── */
:root {
  --accent: #0066ff;
  --accent-dim: rgba(0, 102, 255, 0.1);
  --accent-text: #ffffff;
  --bg: #f5f6f8;
  --bg-card: #ffffff;
  --bg-elevated: #ffffff;
  --bg-sidebar: #1e2230;
  --sidebar-text: #c8cedd;
  --sidebar-active-bg: rgba(255,255,255,0.08);
  --sidebar-active-text: #ffffff;
  --text: #111827;
  --text-muted: #6b7280;
  --border: #e5e7eb;
  --danger: #dc2626;
  --danger-dim: rgba(220,38,38,0.08);
  --success: #16a34a;
  --warning: #d97706;
  --radius: 8px;
  --radius-lg: 12px;
  --shadow: 0 1px 4px rgba(0,0,0,0.08), 0 4px 16px rgba(0,0,0,0.04);
  --shadow-lg: 0 8px 32px rgba(0,0,0,0.12);
  --transition: 0.15s ease;
  --topbar-h: 58px;
}

/* ── Dark theme override ─────────────────────── */
[data-theme="dark"] {
  --bg: #05050a;
  --bg-card: #0d0d1a;
  --bg-elevated: #141428;
  --bg-sidebar: #0a0a18;
  --sidebar-text: #9090b0;
  --sidebar-active-bg: rgba(255,255,255,0.06);
  --sidebar-active-text: #e8e8f0;
  --text: #e8e8f0;
  --text-muted: #7070a0;
  --border: #1a1a2e;
  --danger: #ff4444;
  --danger-dim: rgba(255,68,68,0.1);
  --success: #00ff88;
  --warning: #ffbe00;
  --shadow: 0 4px 24px rgba(0,0,0,0.5);
  --shadow-lg: 0 8px 40px rgba(0,0,0,0.6);
}

/* Product accent: always set via SHELL_CONFIG, overrides above */

/* ── Reset ──────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; }

/* ── Topbar ─────────────────────────────────── */
.shell-topbar {
  position: fixed;
  top: 0; left: 0; right: 0;
  height: var(--topbar-h);
  background: var(--bg-card);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  padding: 0 20px;
  gap: 12px;
  z-index: 900;
  box-shadow: 0 1px 0 var(--border);
}

.shell-topbar-logo {
  font-size: 1.1rem;
  font-weight: 800;
  color: var(--text);
  text-decoration: none;
  white-space: nowrap;
  margin-right: 8px;
  letter-spacing: -0.02em;
}

.shell-topbar-logo span { color: var(--accent); }

.shell-topbar-nav {
  display: flex;
  align-items: center;
  gap: 2px;
  flex: 1;
}

.shell-topbar-nav a {
  color: var(--text-muted);
  text-decoration: none;
  font-size: 0.875rem;
  font-weight: 500;
  padding: 6px 12px;
  border-radius: var(--radius);
  transition: color var(--transition), background var(--transition);
}

.shell-topbar-nav a:hover { color: var(--text); background: var(--bg); }
.shell-topbar-nav a.active { color: var(--accent); background: var(--accent-dim); font-weight: 600; }

.shell-topbar-right {
  display: flex;
  align-items: center;
  gap: 6px;
  margin-left: auto;
}

/* ── Icon Buttons ───────────────────────────── */
.shell-icon-btn {
  background: none;
  border: none;
  cursor: pointer;
  color: var(--text-muted);
  width: 36px;
  height: 36px;
  border-radius: var(--radius);
  display: flex;
  align-items: center;
  justify-content: center;
  transition: color var(--transition), background var(--transition);
  position: relative;
  font-size: 1rem;
  font-weight: 500;
}

.shell-icon-btn:hover { color: var(--text); background: var(--bg); }

.shell-icon-btn .shell-dot {
  position: absolute;
  top: 6px; right: 6px;
  width: 7px; height: 7px;
  border-radius: 50%;
  background: var(--danger);
  border: 2px solid var(--bg-card);
  display: none;
}

.shell-icon-btn.has-notification .shell-dot { display: block; }

/* ── Theme toggle ───────────────────────────── */
#shell-theme-btn { font-size: 1rem; }

/* ── User Avatar ────────────────────────────── */
.shell-avatar-btn {
  background: var(--accent-dim);
  border: 1.5px solid var(--accent);
  color: var(--accent);
  font-weight: 700;
  font-size: 0.78rem;
  cursor: pointer;
  width: 34px;
  height: 34px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: opacity var(--transition);
  position: relative;
  letter-spacing: 0.03em;
}

.shell-avatar-btn:hover { opacity: 0.8; }

/* ── User Menu Dropdown ─────────────────────── */
.shell-user-menu {
  position: absolute;
  top: calc(var(--topbar-h) + 4px);
  right: 16px;
  width: 248px;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg);
  z-index: 950;
  overflow: hidden;
  display: none;
  animation: shell-fadein 0.12s ease;
}

.shell-user-menu.open { display: block; }

.shell-menu-header {
  padding: 14px 16px 12px;
  border-bottom: 1px solid var(--border);
  background: var(--bg);
}

.shell-menu-header .name {
  font-size: 0.875rem;
  font-weight: 600;
  color: var(--text);
  margin-bottom: 2px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.shell-menu-header .email {
  font-size: 0.75rem;
  color: var(--text-muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.shell-menu-header .shell-badge { margin-top: 7px; display: inline-block; }

.shell-menu-items { padding: 6px; }

.shell-menu-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 10px;
  border-radius: var(--radius);
  font-size: 0.845rem;
  color: var(--text-muted);
  cursor: pointer;
  text-decoration: none;
  transition: color var(--transition), background var(--transition);
  border: none;
  background: none;
  width: 100%;
  text-align: left;
  font-weight: 500;
}

.shell-menu-item:hover { color: var(--text); background: var(--bg); }
.shell-menu-item.danger { color: var(--danger); }
.shell-menu-item.danger:hover { background: var(--danger-dim); }
.shell-menu-divider { height: 1px; background: var(--border); margin: 5px 0; }

/* ── Badge ──────────────────────────────────── */
.shell-badge {
  font-size: 0.63rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  padding: 2px 8px;
  border-radius: 20px;
  display: inline-block;
}

.shell-badge-free        { background: #f3f4f6; color: #6b7280; }
.shell-badge-pro         { background: #eff6ff; color: #2563eb; }
.shell-badge-api         { background: #f0fdf4; color: #16a34a; }
.shell-badge-enterprise  { background: #fffbeb; color: #d97706; }
.shell-badge-business    { background: #faf5ff; color: #7c3aed; }

[data-theme="dark"] .shell-badge-free        { background: rgba(112,112,160,0.15); color: var(--text-muted); }
[data-theme="dark"] .shell-badge-pro         { background: rgba(0,102,255,0.15);   color: #60a5fa; }
[data-theme="dark"] .shell-badge-api         { background: rgba(0,255,136,0.12);   color: var(--success); }
[data-theme="dark"] .shell-badge-enterprise  { background: rgba(255,190,0,0.12);   color: var(--warning); }
[data-theme="dark"] .shell-badge-business    { background: rgba(167,139,250,0.12); color: #a78bfa; }

/* ── Help Drawer ────────────────────────────── */
.shell-help-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.3);
  z-index: 980;
  display: none;
  animation: shell-fadein 0.15s ease;
}
.shell-help-overlay.open { display: block; }

.shell-help-drawer {
  position: fixed;
  top: 0; right: -380px;
  width: 360px;
  height: 100vh;
  background: var(--bg-elevated);
  border-left: 1px solid var(--border);
  box-shadow: var(--shadow-lg);
  z-index: 990;
  transition: right 0.24s ease;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}
.shell-help-drawer.open { right: 0; }

.shell-help-header {
  padding: 16px 20px;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: var(--bg);
}

.shell-help-header h2 { font-size: 1rem; font-weight: 700; color: var(--text); margin: 0; }

.shell-help-body { flex: 1; overflow-y: auto; padding: 20px; }

.shell-help-section { margin-bottom: 24px; }

.shell-help-section h3 {
  font-size: 0.7rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: var(--accent);
  margin: 0 0 8px;
}

.shell-help-link {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 9px 0;
  color: var(--text-muted);
  text-decoration: none;
  font-size: 0.875rem;
  font-weight: 500;
  border-bottom: 1px solid var(--border);
  transition: color var(--transition);
  cursor: pointer;
  background: none;
  border-top: none; border-left: none; border-right: none;
  width: 100%;
  text-align: left;
}
.shell-help-link:last-child { border-bottom: none; }
.shell-help-link:hover { color: var(--text); }
.shell-help-link .icon { opacity: 0.5; width: 18px; text-align: center; flex-shrink: 0; }

/* ── Settings Modal ─────────────────────────── */
.shell-modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.4);
  z-index: 1000;
  display: none;
  align-items: center;
  justify-content: center;
  animation: shell-fadein 0.12s ease;
}
.shell-modal-overlay.open { display: flex; }

.shell-settings-modal {
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  width: 580px;
  max-width: calc(100vw - 32px);
  max-height: calc(100vh - 60px);
  display: flex;
  flex-direction: column;
  box-shadow: var(--shadow-lg);
  overflow: hidden;
}

.shell-modal-header {
  padding: 16px 22px;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: var(--bg);
}

.shell-modal-header h2 { font-size: 1rem; font-weight: 700; color: var(--text); margin: 0; }

.shell-modal-body { display: flex; flex: 1; overflow: hidden; }

.shell-settings-tabs {
  width: 158px;
  border-right: 1px solid var(--border);
  padding: 12px 8px;
  display: flex;
  flex-direction: column;
  gap: 2px;
  flex-shrink: 0;
  background: var(--bg);
}

.shell-tab-btn {
  display: block;
  width: 100%;
  padding: 8px 10px;
  border-radius: var(--radius);
  font-size: 0.82rem;
  font-weight: 500;
  color: var(--text-muted);
  background: none;
  border: none;
  text-align: left;
  cursor: pointer;
  transition: color var(--transition), background var(--transition);
}

.shell-tab-btn:hover { color: var(--text); background: var(--bg-card); }
.shell-tab-btn.active { color: var(--accent); background: var(--accent-dim); font-weight: 600; }

.shell-settings-content { flex: 1; overflow-y: auto; padding: 22px 24px; }
.shell-settings-pane { display: none; }
.shell-settings-pane.active { display: block; }

.shell-form-group { margin-bottom: 18px; }

.shell-form-group label {
  display: block;
  font-size: 0.78rem;
  font-weight: 600;
  color: var(--text-muted);
  margin-bottom: 6px;
  text-transform: uppercase;
  letter-spacing: 0.06em;
}

.shell-input {
  width: 100%;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 9px 12px;
  color: var(--text);
  font-size: 0.875rem;
  outline: none;
  transition: border-color var(--transition), box-shadow var(--transition);
}

.shell-input:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-dim);
}

.shell-apikey-row { display: flex; gap: 8px; align-items: center; }
.shell-apikey-row .shell-input { flex: 1; font-family: ui-monospace, monospace; font-size: 0.78rem; }

.shell-danger-zone {
  border: 1px solid rgba(220,38,38,0.25);
  border-radius: var(--radius);
  padding: 18px;
  background: var(--danger-dim);
}

.shell-danger-zone h4 { color: var(--danger); font-size: 0.9rem; margin: 0 0 8px; }
.shell-danger-zone p  { font-size: 0.82rem; color: var(--text-muted); margin: 0 0 14px; }

/* ── Buttons ────────────────────────────────── */
.shell-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 8px 18px;
  border-radius: var(--radius);
  font-size: 0.855rem;
  font-weight: 600;
  cursor: pointer;
  border: none;
  transition: opacity var(--transition), box-shadow var(--transition);
  text-decoration: none;
  line-height: 1;
}

.shell-btn:hover { opacity: 0.88; }
.shell-btn-primary   { background: var(--accent); color: var(--accent-text); box-shadow: 0 2px 8px var(--accent-dim); }
.shell-btn-secondary { background: var(--bg); color: var(--text); border: 1px solid var(--border); }
.shell-btn-danger    { background: var(--danger); color: #fff; }
.shell-btn-sm        { padding: 5px 12px; font-size: 0.78rem; }

/* ── Chat Widget ────────────────────────────── */
.shell-chat-launcher {
  position: fixed;
  bottom: 24px; right: 24px;
  width: 52px; height: 52px;
  border-radius: 50%;
  background: var(--accent);
  color: var(--accent-text);
  font-size: 1.25rem;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  border: none;
  box-shadow: 0 4px 16px rgba(0,0,0,0.2);
  z-index: 970;
  transition: transform var(--transition), box-shadow var(--transition);
}

.shell-chat-launcher:hover { transform: scale(1.06); box-shadow: 0 6px 24px rgba(0,0,0,0.25); }

.shell-chat-panel {
  position: fixed;
  bottom: 90px; right: 24px;
  width: 330px; height: 440px;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg);
  z-index: 970;
  display: none;
  flex-direction: column;
  overflow: hidden;
  animation: shell-fadein 0.15s ease;
}
.shell-chat-panel.open { display: flex; }

.shell-chat-head {
  padding: 12px 16px;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: var(--bg);
}

.shell-chat-head span { font-size: 0.875rem; font-weight: 700; color: var(--text); }
.shell-chat-head small { font-size: 0.7rem; color: var(--accent); margin-left: 6px; font-weight: 600; }

.shell-chat-messages {
  flex: 1;
  overflow-y: auto;
  padding: 14px 12px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.shell-msg {
  max-width: 87%;
  padding: 9px 13px;
  border-radius: var(--radius);
  font-size: 0.83rem;
  line-height: 1.5;
}

.shell-msg.user {
  align-self: flex-end;
  background: var(--accent);
  color: var(--accent-text);
}

.shell-msg.ai {
  align-self: flex-start;
  background: var(--bg);
  color: var(--text);
  border: 1px solid var(--border);
}

.shell-msg.typing { color: var(--text-muted); font-style: italic; background: var(--bg); border: 1px solid var(--border); align-self: flex-start; }

.shell-chat-input-row {
  padding: 10px 12px;
  border-top: 1px solid var(--border);
  display: flex;
  gap: 8px;
  background: var(--bg);
}

.shell-chat-input-row input {
  flex: 1;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 8px 12px;
  color: var(--text);
  font-size: 0.83rem;
  outline: none;
  transition: border-color var(--transition);
}
.shell-chat-input-row input:focus { border-color: var(--accent); }

.shell-chat-send {
  background: var(--accent);
  color: var(--accent-text);
  border: none;
  border-radius: var(--radius);
  width: 36px;
  cursor: pointer;
  font-size: 0.95rem;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: opacity var(--transition);
  flex-shrink: 0;
}
.shell-chat-send:hover { opacity: 0.8; }

/* ── Toast ──────────────────────────────────── */
.shell-toast {
  position: fixed;
  bottom: 24px; left: 50%;
  transform: translateX(-50%) translateY(80px);
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 11px 22px;
  font-size: 0.875rem;
  font-weight: 500;
  color: var(--text);
  z-index: 1100;
  box-shadow: var(--shadow-lg);
  transition: transform 0.22s ease, opacity 0.22s ease;
  opacity: 0;
  white-space: nowrap;
}

.shell-toast.show { transform: translateX(-50%) translateY(0); opacity: 1; }
.shell-toast.success { border-color: var(--success); color: var(--success); }
.shell-toast.error   { border-color: var(--danger);  color: var(--danger); }
.shell-toast.info    { border-color: var(--accent);  color: var(--accent); }

/* ── Empty State ────────────────────────────── */
.shell-empty {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 56px 24px;
  text-align: center;
  gap: 12px;
}

.shell-empty .icon { font-size: 2.8rem; opacity: 0.25; }
.shell-empty h3 { font-size: 1.05rem; font-weight: 700; color: var(--text); margin: 0; }
.shell-empty p  { font-size: 0.875rem; color: var(--text-muted); margin: 0; max-width: 280px; line-height: 1.5; }

/* ── Body offset ────────────────────────────── */
body.shell-active { padding-top: var(--topbar-h); }

/* ── Animations ─────────────────────────────── */
@keyframes shell-fadein {
  from { opacity: 0; transform: translateY(-4px); }
  to   { opacity: 1; transform: translateY(0); }
}

/* ── Keyboard Shortcuts ─────────────────────── */
.shell-shortcuts-list { display: flex; flex-direction: column; gap: 10px; margin-top: 8px; }

.shell-shortcut-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-size: 0.85rem;
  color: var(--text-muted);
}

.shell-kbd { display: inline-flex; gap: 4px; }
.shell-kbd kbd {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 2px 7px;
  font-size: 0.73rem;
  color: var(--text);
  font-family: ui-monospace, monospace;
  box-shadow: 0 1px 0 var(--border);
}

/* ── Mobile ─────────────────────────────────── */
@media (max-width: 640px) {
  .shell-topbar-nav { display: none; }
  .shell-help-drawer { width: 100vw; right: -100vw; }
  .shell-settings-modal { max-height: 100vh; border-radius: 0; }
  .shell-modal-body { flex-direction: column; }
  .shell-settings-tabs {
    width: 100%;
    border-right: none;
    border-bottom: 1px solid var(--border);
    flex-direction: row;
    overflow-x: auto;
    padding: 8px;
    white-space: nowrap;
  }
  .shell-chat-panel { width: calc(100vw - 32px); right: 16px; }
}

/* ── Print ──────────────────────────────────── */
@media print {
  .shell-topbar,
  .shell-chat-launcher,
  .shell-chat-panel,
  .shell-help-overlay,
  .shell-modal-overlay { display: none !important; }
  body.shell-active { padding-top: 0 !important; }
}
