/* ============================================================
   Pebbleworks Agent Portal — Global Styles
   ============================================================
   Covers: reset, login page, portal header, widget container.
   Widgets bring their own styles — nothing here should leak
   into widget internals.
   ============================================================ */

/* --- Variables --- */
:root {
  --color-dark: #1A202C;
  --color-primary: #2D3748;
  --color-mid: #4A5568;
  --color-hover: #3C4655;
  --color-text: #333;
  --color-text-muted: #666;
  --color-text-hint: #999;
  --color-border: #e5e7eb;
  --color-border-strong: #d1d5db;
  --color-bg: #f9fafb;
  --color-bg-alt: #f5f5f5;
  --color-white: #ffffff;
  --font-family: 'Instrument Sans', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
}

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

html, body {
  height: 100%;
}

body {
  font-family: var(--font-family);
  color: var(--color-text);
  background: var(--color-bg);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

a {
  text-decoration: none;
  color: inherit;
}

/* --- Chrome Shield ---
   Widgets inject global * { font-family: ... } rules that override
   inherited values on portal chrome elements. This sets Raleway on
   ALL chrome descendants, beating the widget's * rule via !important. */
#portal-topbar,
#portal-topbar *,
#portal-sidebar,
#portal-sidebar *,
#portal-footer,
#portal-footer * {
  font-family: 'Raleway', sans-serif !important;
}

/* ============================================================
   Login Page
   ============================================================ */

#login-container {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  padding: 24px;
  background: var(--color-primary);

  /* Subtle texture — fine noise-like radial to break up the flat color */
  background-image:
    radial-gradient(ellipse at 20% 50%, rgba(74, 85, 104, 0.4) 0%, transparent 60%),
    radial-gradient(ellipse at 80% 50%, rgba(26, 32, 44, 0.5) 0%, transparent 60%);
}

#login-card {
  width: 100%;
  max-width: 420px;
  background: var(--color-white);
  border-radius: 12px;
  padding: 48px 40px 40px;
  box-shadow:
    0 4px 6px rgba(0, 0, 0, 0.06),
    0 20px 50px rgba(0, 0, 0, 0.15);
  text-align: center;
}

#login-card h1 {
  font-size: 22px;
  font-weight: 700;
  letter-spacing: 4px;
  color: var(--color-primary);
  margin-bottom: 8px;
}

.login-subtitle {
  font-size: 15px;
  font-weight: 400;
  color: var(--color-text-muted);
  margin-bottom: 32px;
}

/* Clerk mounts its own UI inside this div — give it breathing room */
#clerk-sign-in {
  min-height: 200px;
  display: flex;
  align-items: center;
  justify-content: center;
}

/* ============================================================
   Top Bar
   ============================================================ */

#portal-topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  height: 72px;
  padding: 0 32px;
  background: var(--color-white) !important;
  color: var(--color-text) !important;
  font-family: 'Raleway', sans-serif !important;
  font-size: 13px !important;
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  z-index: 9000;
  border-bottom: 1px solid var(--color-border);
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.04);
}

#portal-logo-link {
  display: flex;
  align-items: center;
  gap: 14px;
  flex-shrink: 0;
}

#portal-logo-img {
  height: 48px;
  width: auto;
}

#portal-logo-text {
  font-family: 'Raleway', sans-serif !important;
  font-size: 22px !important;
  font-weight: 500 !important;
  letter-spacing: 0.08em !important;
  transition: opacity 0.15s ease;
}

.logo-pebble {
  color: #402f40 !important;
}

.logo-works {
  color: #806a80 !important;
}

#portal-logo-link:hover #portal-logo-text {
  opacity: 0.7;
}

/* Top bar navigation */
#portal-nav {
  display: flex;
  align-items: center;
  gap: 28px;
}

.portal-nav-link {
  font-family: 'Raleway', sans-serif !important;
  font-size: 11px !important;
  font-weight: 600 !important;
  letter-spacing: 1.2px !important;
  color: var(--color-text-muted);
  transition: color 0.15s ease;
  white-space: nowrap;
}

.portal-nav-link:hover {
  color: var(--color-primary);
}

.portal-nav-link.active {
  color: var(--color-primary);
}

/* User area */
#portal-user-area {
  display: flex;
  align-items: center;
  gap: 0;
  flex-shrink: 0;
}

#portal-avatar {
  width: 26px;
  height: 26px;
  border-radius: 50%;
  background: var(--color-white);
  border: 1.5px solid var(--color-border);
  color: var(--color-primary);
  font-family: 'Raleway', sans-serif !important;
  font-size: 9px !important;
  font-weight: 700 !important;
  letter-spacing: 0.5px !important;
  display: flex;
  align-items: center;
  justify-content: center;
  margin-right: 20px;
}

#portal-client-logo {
  height: 40px;
  width: auto;
  border-radius: 4px;
  object-fit: contain;
  margin-right: 20px;
}

#portal-signout {
  font-family: 'Raleway', sans-serif !important;
  font-size: 11px !important;
  font-weight: 500 !important;
  color: var(--color-text-muted);
  padding: 4px 10px;
  border: 1px solid var(--color-border);
  border-radius: 6px;
  transition: color 0.15s ease, border-color 0.15s ease, background 0.15s ease;
}

#portal-signout:hover {
  color: var(--color-primary);
  border-color: var(--color-border-strong);
  background: var(--color-bg);
}

/* ============================================================
   Body Layout (Sidebar + Main)
   ============================================================ */

#portal-body {
  display: flex;
  position: fixed;
  top: 72px;
  left: 0;
  right: 0;
  bottom: 0;
}

/* ============================================================
   Sidebar
   ============================================================ */

#portal-sidebar {
  width: 240px;
  flex-shrink: 0;
  background: var(--color-white);
  border-right: 1px solid var(--color-border);
  overflow-y: auto;
  display: flex;
  flex-direction: column;
}

#sidebar-nav {
  padding: 20px 14px;
  display: flex;
  flex-direction: column;
  gap: 2px;
}

/* Section labels (AGENTS, etc.) */
.sidebar-section-label {
  font-family: 'Raleway', sans-serif !important;
  font-size: 10px !important;
  font-weight: 700 !important;
  letter-spacing: 1.5px !important;
  color: var(--color-text-hint);
  text-transform: uppercase;
  padding: 16px 14px 6px;
}

/* Sidebar items (shared base for links, folder toggle, children) */
.sidebar-item {
  display: flex;
  flex-direction: column;
  gap: 1px;
  padding: 10px 14px;
  font-family: 'Raleway', sans-serif !important;
  color: var(--color-text-muted);
  border-radius: 8px;
  border-left: 3px solid transparent;
  transition: background 0.12s ease, color 0.12s ease, border-color 0.12s ease;
  cursor: pointer;
}

.sidebar-item:hover {
  background: var(--color-bg);
  color: var(--color-text);
}

.sidebar-item.active {
  background: #f5f0f5;
  border-left-color: #402f40;
}

.sidebar-item.active .sidebar-agent-name {
  color: #402f40;
}

.sidebar-item.active .sidebar-agent-desc {
  color: #806a80;
}

/* Agent name — bold, primary */
.sidebar-agent-name {
  font-size: 13px !important;
  font-weight: 600 !important;
  line-height: 1.3;
  color: inherit;
}

/* Agent descriptor — small, muted */
.sidebar-agent-desc {
  font-size: 11px !important;
  font-weight: 400 !important;
  color: var(--color-text-hint);
  line-height: 1.3;
}

.sidebar-item:hover .sidebar-agent-desc {
  color: var(--color-text-muted);
}

/* Utilities folder toggle */
.sidebar-folder {
  flex-direction: row;
  align-items: center;
  gap: 6px;
  background: none;
  border: none;
  border-left: 3px solid transparent;
  width: 100%;
  text-align: left;
  font-family: 'Raleway', sans-serif !important;
  font-size: 10px !important;
  font-weight: 700 !important;
  color: var(--color-text-hint);
  letter-spacing: 1.5px !important;
  text-transform: uppercase;
  margin-top: 12px;
  padding: 10px 14px;
  border-radius: 8px;
}

.sidebar-folder:hover {
  color: var(--color-text-muted);
  background: var(--color-bg);
}

.folder-chevron {
  font-size: 10px;
  display: inline-block;
  transition: transform 0.15s ease;
  line-height: 1;
}

.sidebar-folder.expanded .folder-chevron {
  transform: rotate(90deg);
}

/* Collapsible children container */
.sidebar-children {
  overflow: hidden;
  max-height: 500px;
  transition: max-height 0.2s ease;
}

.sidebar-children.collapsed {
  max-height: 0;
}

/* Utility child items — indented */
.sidebar-child {
  padding-left: 24px;
}

/* Sub-folder toggles nested inside a parent folder's children */
.sidebar-children .sidebar-folder {
  padding-left: 28px;
  font-size: 9px !important;
  letter-spacing: 1px !important;
  margin-top: 4px;
}

/* Items inside a sub-folder — double-indented */
.sidebar-children .sidebar-children .sidebar-child {
  padding-left: 40px;
}

/* Admin bottom link — pinned to bottom of sidebar */
#sidebar-admin-bottom {
  margin-top: auto;
  padding: 14px;
  border-top: 1px solid var(--color-border);
}

/* ============================================================
   Main Content Area
   ============================================================ */

#portal-main {
  flex: 1;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  min-width: 0;
}

/* ============================================================
   Widget Container
   ============================================================ */

#widget-container {
  width: 100%;
  flex: 1;
  overflow-y: auto;
}

/* ============================================================
   Footer
   ============================================================ */

#portal-footer {
  padding: 24px 20px 20px;
  text-align: center;
  border-top: 1px solid var(--color-border);
  background: var(--color-white);
  flex-shrink: 0;
}

#footer-links {
  font-family: 'Raleway', sans-serif !important;
  font-size: 12px !important;
  color: var(--color-text-muted);
  margin-bottom: 6px;
}

#footer-links a {
  color: var(--color-text-muted);
  transition: color 0.12s ease;
}

#footer-links a:hover {
  color: var(--color-primary);
}

.footer-dot {
  margin: 0 8px;
  color: var(--color-text-hint);
}

#footer-brand {
  font-family: 'Raleway', sans-serif !important;
  font-size: 12px !important;
  font-weight: 700 !important;
  letter-spacing: 3px !important;
  color: var(--color-text-hint);
}
