/* ════════════════════════════════════════════════════════════
   PICOCRYPT SaaS UI THEME  —  saas-theme.css
   Layered on top of style.css. Uses .saas-* prefix throughout.
   ════════════════════════════════════════════════════════════ */

:root {
  --saas-topbar-h: 52px;
  --saas-topbar-bg: rgba(255,255,255,0.97);
  --saas-topbar-border: #cdd5cb;
  --saas-activity-w: 340px;
  --saas-accent: #4d8b2e;
  --saas-accent-glow: rgba(77,139,46,0.25);
  --saas-pulse-red: #ef4444;
  --saas-pulse-green: #22c55e;
  --saas-pulse-yellow: #f59e0b;
}

/* ── Topbar Layout Adjustments ── */

.main-content {
  padding-top: calc(var(--saas-topbar-h) + 24px) !important;
}

/* ════════════════════════════════════════════════════════════
   GLOBAL TOPBAR
   ════════════════════════════════════════════════════════════ */

.saas-topbar {
  position: fixed;
  top: 0;
  left: var(--sidebar-w);
  right: 0;
  height: var(--saas-topbar-h);
  background: var(--saas-topbar-bg);
  border-bottom: 1px solid var(--saas-topbar-border);
  display: flex;
  align-items: center;
  padding: 0 20px 0 16px;
  gap: 12px;
  z-index: 150;
  transition: left 0.3s cubic-bezier(0.4,0,0.2,1);
  backdrop-filter: blur(12px);
  color: #252927;
}

/* When sidebar collapses, topbar follows */
.sidebar.collapsed ~ * .saas-topbar,
body.sidebar-collapsed .saas-topbar {
  left: var(--sidebar-collapsed-w);
}

/* Mobile: topbar spans full width */
@media (max-width: 800px) {
  .saas-topbar { left: 0; }
}

/* ── Hamburger button ── */
.saas-menu-btn {
  width: 34px;
  height: 34px;
  border: none;
  background: transparent;
  cursor: pointer;
  border-radius: 8px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 4px;
  padding: 0;
  flex-shrink: 0;
  transition: background 0.15s;
}
.saas-menu-btn:hover { background: rgba(77,139,46,0.1); }
.saas-menu-btn span {
  display: block;
  width: 16px;
  height: 1.5px;
  background: #4e5a4c;
  border-radius: 2px;
  transition: background 0.15s;
}
.saas-menu-btn:hover span { background: #252927; }

/* ── Left: breadcrumb ── */
.saas-topbar-left {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-shrink: 0;
}

.saas-breadcrumb {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 13px;
}
.saas-breadcrumb-root {
  color: #4e5a4c;
  font-weight: 400;
}
.saas-breadcrumb-sep {
  color: #cdd5cb;
  font-size: 12px;
}
.saas-breadcrumb-page {
  color: #252927;
  font-weight: 500;
}

/* ── Center: search trigger ── */
.saas-topbar-center {
  flex: 1;
  display: flex;
  justify-content: center;
  min-width: 0;
}

.saas-search-trigger {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 7px 14px;
  background: #f8faf7;
  border: 1px solid #cdd5cb;
  border-radius: 10px;
  cursor: pointer;
  font-size: 13px;
  color: #4e5a4c;
  width: min(460px, 100%);
  text-align: left;
  transition: border-color 0.15s, background 0.15s;
}
.saas-search-trigger:hover {
  border-color: #4d8b2e;
  background: #f2f4f1;
  color: #94a3b8;
}
.saas-search-trigger span { flex: 1; }
.saas-search-trigger kbd {
  font-family: var(--font-mono);
  font-size: 10px;
  background: #f2f4f1;
  border: 1px solid #cdd5cb;
  border-radius: 4px;
  padding: 1px 5px;
  color: #4e5a4c;
  white-space: nowrap;
}

/* ── Right: status + icons + user ── */
.saas-topbar-right {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-shrink: 0;
}

/* Health pill */
.saas-health-pill {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 5px 10px;
  border-radius: 20px;
  background: #f2f4f1;
  border: 1px solid #cdd5cb;
  font-size: 11.5px;
  color: #22c55e;
  font-weight: 500;
  cursor: default;
  transition: background 0.3s, border-color 0.3s, color 0.3s;
  white-space: nowrap;
}
.saas-health-pill.degraded {
  background: rgba(245,158,11,0.08);
  border-color: rgba(245,158,11,0.25);
  color: #f59e0b;
}
.saas-health-pill.critical {
  background: rgba(239,68,68,0.08);
  border-color: rgba(239,68,68,0.25);
  color: #ef4444;
}

.saas-health-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: #22c55e;
  flex-shrink: 0;
  animation: saas-pulse-green 2.5s ease-in-out infinite;
}
.saas-health-pill.degraded .saas-health-dot {
  background: #f59e0b;
  animation: saas-pulse-yellow 2s ease-in-out infinite;
}
.saas-health-pill.critical .saas-health-dot {
  background: #ef4444;
  animation: saas-pulse-red 1.2s ease-in-out infinite;
}

@keyframes saas-pulse-green {
  0%, 100% { box-shadow: 0 0 0 0 rgba(16,185,129,0.5); }
  50% { box-shadow: 0 0 0 4px rgba(16,185,129,0); }
}
@keyframes saas-pulse-yellow {
  0%, 100% { box-shadow: 0 0 0 0 rgba(245,158,11,0.5); }
  50% { box-shadow: 0 0 0 4px rgba(245,158,11,0); }
}
@keyframes saas-pulse-red {
  0%, 100% { box-shadow: 0 0 0 0 rgba(239,68,68,0.6); }
  50% { box-shadow: 0 0 0 5px rgba(239,68,68,0); }
}

/* Icon buttons */
.saas-topbar-icon-btn {
  position: relative;
  width: 34px;
  height: 34px;
  border: none;
  background: transparent;
  cursor: pointer;
  border-radius: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  color: #4e5a4c;
  transition: background 0.15s, color 0.15s;
}
.saas-topbar-icon-btn:hover {
  background: rgba(77,139,46,0.1);
  color: #252927;
}
.saas-topbar-icon-btn.active {
  background: rgba(77,139,46,0.15);
  color: #4d8b2e;
}

.saas-live-badge {
  position: absolute;
  top: 5px;
  right: 5px;
  font-size: 7px;
  color: #ef4444;
  animation: saas-pulse-red 1.2s ease-in-out infinite;
  line-height: 1;
}

.saas-notif-count {
  position: absolute;
  top: 4px;
  right: 4px;
  min-width: 14px;
  height: 14px;
  background: #4d8b2e;
  color: white;
  font-size: 9px;
  font-weight: 700;
  border-radius: 7px;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0 3px;
}

/* User chip */
.saas-user-chip {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 4px 10px 4px 4px;
  border-radius: 20px;
  border: 1px solid transparent;
  cursor: pointer;
  transition: border-color 0.15s, background 0.15s;
}
.saas-user-chip:hover {
  background: rgba(77,139,46,0.08);
  border-color: #cdd5cb;
}
.saas-user-avatar {
  width: 26px;
  height: 26px;
  border-radius: 50%;
  background: linear-gradient(135deg, #4d8b2e, #2e5218);
  color: #ffffff;
  font-size: 11px;
  font-weight: 700;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}
.saas-user-name {
  font-size: 12.5px;
  font-weight: 500;
  color: #94a3b8;
  max-width: 100px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* ════════════════════════════════════════════════════════════
   COMPACT COLLAPSIBLE NAV GROUPS
   ════════════════════════════════════════════════════════════ */

/* Group header — now clickable */
.saas-group-header {
  display: flex !important;
  align-items: center;
  gap: 10px;
  cursor: pointer;
  user-select: none;
  padding: 8px 12px !important;
  border-radius: 8px;
  margin: 2px 0;
  transition: background 0.15s;
}
.saas-group-header:hover { background: rgba(77,139,46,0.06); }

.saas-group-icon {
  width: 20px;
  height: 20px;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  color: #8a9487;
  transition: color 0.15s;
}
.saas-group-header:hover .saas-group-icon,
.saas-group.saas-open .saas-group-header .saas-group-icon {
  color: #4e5a4c;
}

.saas-group-header > span:not(.saas-group-icon) {
  flex: 1;
  font-size: 13px;
  font-weight: 500;
  color: #8a9487;
  text-transform: none;
  letter-spacing: normal;
}

.saas-chevron {
  flex-shrink: 0;
  color: #8a9487;
  transition: transform 0.2s ease, color 0.15s;
}
.saas-group-header:hover .saas-chevron { color: #4d8b2e; }
.saas-group.saas-open .saas-chevron {
  transform: rotate(180deg);
  color: #4d8b2e;
}

/* Collapsed state: hide all nav items */
.saas-group:not(.saas-open) > .nav-item {
  display: none !important;
}
.saas-group:not(.saas-open) > .nav-group-secondary {
  display: none !important;
}
.saas-group:not(.saas-open) > .saas-expand-btn {
  display: none !important;
}

/* Open state: show primary items */
.saas-group.saas-open > .nav-item {
  display: flex !important;
}

/* Secondary items — hidden until expanded */
.nav-group-secondary {
  overflow: hidden;
  max-height: 0;
  transition: max-height 0.25s ease;
}
.saas-group.saas-open.saas-expanded .nav-group-secondary {
  max-height: 800px;
}

/* When nav search is active — expand all */
.sidebar-nav.saas-search-active .nav-group-secondary {
  max-height: 800px !important;
}
.sidebar-nav.saas-search-active .saas-group:not(.saas-open) > .nav-item {
  display: flex !important;
}
.sidebar-nav.saas-search-active .saas-expand-btn {
  display: none !important;
}

/* Expand/collapse button */
.saas-expand-btn {
  display: flex;
  align-items: center;
  gap: 4px;
  width: calc(100% - 24px);
  margin: 1px 12px 2px;
  padding: 4px 8px;
  background: none;
  border: none;
  border-radius: 5px;
  cursor: pointer;
  font-size: 11px;
  color: #8a9487;
  font-family: var(--font);
  transition: color 0.15s, background 0.15s;
  text-align: left;
}
.saas-expand-btn:hover {
  color: #4d8b2e;
  background: rgba(77,139,46,0.08);
}
.saas-expand-btn::before {
  content: '›';
  font-size: 13px;
  line-height: 1;
  transition: transform 0.2s;
}
.saas-group.saas-expanded .saas-expand-btn::before {
  transform: rotate(90deg);
}
.saas-expand-label { display: inline; }
.saas-collapse-label { display: none; }
.saas-group.saas-expanded .saas-expand-label { display: none; }
.saas-group.saas-expanded .saas-collapse-label { display: inline; }

/* Secondary items — same indent as primary items */
.nav-group-secondary .nav-item {
  padding-left: 12px !important;
  font-size: 13px !important;
  opacity: 1;
}

/* Collapsed sidebar: hide group labels text */
.sidebar.collapsed .saas-group-header > span:not(.saas-group-icon),
.sidebar.collapsed .saas-chevron {
  display: none;
}
.sidebar.collapsed .saas-group-header {
  justify-content: center;
  margin: 2px 6px;
}

/* ════════════════════════════════════════════════════════════
   LIVE ACTIVITY PANEL
   ════════════════════════════════════════════════════════════ */

.saas-activity-panel {
  position: fixed;
  top: var(--saas-topbar-h);
  right: calc(-1 * var(--saas-activity-w) - 2px);
  bottom: 0;
  width: var(--saas-activity-w);
  background: #f2f4f1;
  border-left: 1px solid #cdd5cb;
  display: flex;
  flex-direction: column;
  z-index: 140;
  transition: right 0.3s cubic-bezier(0.4,0,0.2,1);
  box-shadow: -4px 0 20px rgba(0,0,0,0.3);
}
.saas-activity-panel.saas-open {
  right: 0;
}

/* When activity panel is open, push main content */
body.saas-activity-open .saas-topbar {
  right: var(--saas-activity-w);
}
body.saas-activity-open .main-content {
  width: calc(100vw - var(--sidebar-w) - var(--saas-activity-w)) !important;
}

.saas-activity-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 16px 10px;
  border-bottom: 1px solid #cdd5cb;
  flex-shrink: 0;
}
.saas-activity-title {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 13px;
  font-weight: 600;
  color: #252927;
}
.saas-live-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: #22c55e;
  animation: saas-pulse-green 2s ease-in-out infinite;
  flex-shrink: 0;
}
.saas-activity-close {
  width: 28px;
  height: 28px;
  border: none;
  background: transparent;
  cursor: pointer;
  border-radius: 6px;
  display: flex;
  align-items: center;
  justify-content: center;
  color: #4e5a4c;
  transition: background 0.15s, color 0.15s;
}
.saas-activity-close:hover { background: rgba(77,139,46,0.1); color: #252927; }

/* Filter chips */
.saas-activity-filters {
  display: flex;
  gap: 4px;
  padding: 8px 12px;
  border-bottom: 1px solid #cdd5cb;
  flex-shrink: 0;
}
.saas-filter-chip {
  padding: 3px 10px;
  border: 1px solid #cdd5cb;
  border-radius: 12px;
  background: transparent;
  font-size: 11px;
  font-family: var(--font);
  color: #4e5a4c;
  cursor: pointer;
  transition: all 0.15s;
}
.saas-filter-chip:hover {
  border-color: #4d8b2e;
  color: #4d8b2e;
}
.saas-filter-chip.active {
  background: #4d8b2e;
  border-color: #4d8b2e;
  color: #ffffff;
  font-weight: 500;
}

/* Feed area */
.saas-activity-feed {
  flex: 1;
  overflow-y: auto;
  padding: 4px 0;
}
.saas-activity-feed::-webkit-scrollbar { width: 4px; }
.saas-activity-feed::-webkit-scrollbar-thumb { background: #cdd5cb; border-radius: 2px; }

.saas-activity-empty {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  height: 200px;
  gap: 10px;
  color: #8a9487;
}
.saas-activity-empty p {
  font-size: 12px;
  text-align: center;
}

/* Individual event entries */
.saas-event {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  padding: 9px 14px;
  border-bottom: 1px solid #cdd5cb;
  animation: saas-slide-in 0.3s ease;
  cursor: pointer;
  transition: background 0.12s;
}
.saas-event:hover { background: rgba(77,139,46,0.05); }

@keyframes saas-slide-in {
  from { opacity: 0; transform: translateX(16px); }
  to { opacity: 1; transform: translateX(0); }
}

.saas-event-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  margin-top: 5px;
  flex-shrink: 0;
}
.saas-event-dot.issued { background: #22c55e; }
.saas-event-dot.revoked { background: #ef4444; }
.saas-event-dot.error { background: #f59e0b; }
.saas-event-dot.info { background: #6b7280; }
.saas-event-dot.warning { background: #f97316; }

.saas-event-body { flex: 1; min-width: 0; }
.saas-event-label {
  font-size: 12px;
  font-weight: 500;
  color: #252927;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.saas-event-detail {
  font-size: 11px;
  color: #4e5a4c;
  margin-top: 1px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.saas-event-time {
  font-size: 10.5px;
  color: #8a9487;
  flex-shrink: 0;
  margin-top: 3px;
  font-variant-numeric: tabular-nums;
}

/* Footer */
.saas-activity-footer {
  border-top: 1px solid #cdd5cb;
  padding: 10px 16px;
  flex-shrink: 0;
}
.saas-activity-viewall {
  font-size: 12px;
  color: #4e5a4c;
  text-decoration: none;
  transition: color 0.15s;
}
.saas-activity-viewall:hover { color: #252927; }

/* ════════════════════════════════════════════════════════════
   TICKER — live stats strip at bottom of sidebar
   ════════════════════════════════════════════════════════════ */

.saas-ticker {
  padding: 8px 14px;
  border-top: 1px solid var(--sidebar-border);
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  flex-shrink: 0;
}
.saas-ticker-stat {
  display: flex;
  flex-direction: column;
  flex: 1;
  min-width: 60px;
}
.saas-ticker-value {
  font-size: 15px;
  font-weight: 700;
  color: #fff;
  font-variant-numeric: tabular-nums;
  line-height: 1.2;
  transition: color 0.3s;
}
.saas-ticker-value.flash {
  color: var(--saas-accent);
}
.saas-ticker-label {
  font-size: 9.5px;
  color: #4b5563;
  text-transform: uppercase;
  letter-spacing: 0.4px;
  margin-top: 1px;
}

/* ════════════════════════════════════════════════════════════
   TOPBAR OFFSET — sidebar follow
   ════════════════════════════════════════════════════════════ */

.sidebar.collapsed ~ .saas-topbar,
.sidebar.collapsed + .saas-topbar {
  left: var(--sidebar-collapsed-w);
}

/* Fix: the topbar is inside app-layout which is flex,
   but topbar is fixed. We need to handle the sidebar
   collapsed state via the class on body. */

body.sidebar-collapsed .saas-topbar {
  left: var(--sidebar-collapsed-w);
}

/* ════════════════════════════════════════════════════════════
   NAV ITEM — tighter for SaaS density
   ════════════════════════════════════════════════════════════ */

/* Primary items stay the same size but secondary items are
   slightly more compact */
.nav-group-secondary .nav-item {
  min-height: 30px !important;
  padding-top: 5px !important;
  padding-bottom: 5px !important;
}

/* ════════════════════════════════════════════════════════════
   DASHBOARD — modern SaaS improvements
   ════════════════════════════════════════════════════════════ */

/* Real-time update flash on KPI cards */
@keyframes saas-kpi-flash {
  0% { background: #f2f4f1; }
  30% { background: rgba(77,139,46,0.08); }
  100% { background: #f2f4f1; }
}
.saas-kpi-updated {
  animation: saas-kpi-flash 1s ease;
}

/* ════════════════════════════════════════════════════════════
   HEALTH CENTER ENHANCEMENTS
   ════════════════════════════════════════════════════════════ */

/* Service status badges in topbar health pill */
.saas-health-text { font-size: 11.5px; }

/* ════════════════════════════════════════════════════════════
   RESPONSIVE — mobile
   ════════════════════════════════════════════════════════════ */

@media (max-width: 800px) {
  .saas-topbar { left: 0; padding: 0 12px; gap: 8px; }
  .saas-breadcrumb-root, .saas-breadcrumb-sep { display: none; }
  .saas-health-text { display: none; }
  .saas-user-name { display: none; }
  .saas-activity-panel { width: 100%; right: -100%; }
  .saas-activity-panel.saas-open { right: 0; }
  body.saas-activity-open .main-content { width: 100% !important; }
}

@media (max-width: 480px) {
  .saas-health-pill { display: none; }
}

/* ════════════════════════════════════════════════════════════
   SIDEBAR TOGGLE — original pill button hidden; topbar hamburger used
   ════════════════════════════════════════════════════════════ */

/* Hide the sidebar edge-pill toggle; topbar hamburger delegates to it */
#sidebar-toggle.sidebar-toggle {
  opacity: 0;
  pointer-events: none;
}

/* ════════════════════════════════════════════════════════════
   USP HIGHLIGHT BADGES — shown on certain nav items
   ════════════════════════════════════════════════════════════ */

.saas-usp-badge {
  display: inline-flex;
  align-items: center;
  padding: 1px 5px;
  background: rgba(77,139,46,0.12);
  border: 1px solid rgba(77,139,46,0.25);
  border-radius: 4px;
  font-size: 9px;
  font-weight: 600;
  color: #4d8b2e;
  text-transform: uppercase;
  letter-spacing: 0.3px;
  margin-left: auto;
  flex-shrink: 0;
}
.saas-usp-badge.new { background: rgba(77,139,46,0.1); border-color: rgba(77,139,46,0.25); color: #2563eb; }

/* ════════════════════════════════════════════════════════════
   NOTIFICATION PANEL (dropdown from topbar)
   ════════════════════════════════════════════════════════════ */

.saas-notif-panel {
  position: fixed;
  top: calc(var(--saas-topbar-h) + 6px);
  right: 12px;
  width: 320px;
  background: #f2f4f1;
  border: 1px solid #cdd5cb;
  border-radius: 12px;
  box-shadow: 0 8px 32px rgba(0,0,0,0.4);
  z-index: 200;
  display: none;
}
.saas-notif-panel.open { display: block; }
.saas-notif-panel-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 16px 10px;
  border-bottom: 1px solid #cdd5cb;
}
.saas-notif-panel-header h4 {
  font-size: 13px;
  font-weight: 600;
  color: #252927;
}
.saas-notif-panel-body { max-height: 360px; overflow-y: auto; }
.saas-notif-item {
  display: flex;
  gap: 10px;
  padding: 10px 14px;
  border-bottom: 1px solid #cdd5cb;
  cursor: pointer;
  transition: background 0.12s;
}
.saas-notif-item:hover { background: rgba(77,139,46,0.05); }
.saas-notif-item-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  margin-top: 4px;
  flex-shrink: 0;
}
.saas-notif-item-body { flex: 1; }
.saas-notif-item-title { font-size: 12px; font-weight: 500; color: #252927; }
.saas-notif-item-sub { font-size: 11px; color: #4e5a4c; margin-top: 1px; }
.saas-notif-panel-footer { padding: 8px 14px; }
.saas-notif-panel-footer a { font-size: 12px; color: #4e5a4c; text-decoration: none; }
.saas-notif-panel-footer a:hover { color: #252927; }
