/* App Shell Navigation - Based on Concept 09 Split Panel */

:root {
  --shell-primary: #051C2C;
  --shell-accent: #97D700;
  --shell-accent-dark: #7ab300;
  --shell-light-bg: #F3F3F3;
  --shell-border: #e2e8f0;
  --shell-text-muted: #94a3b8;
  --shell-text-secondary: #64748b;
  --shell-danger: #ef4444;
}

html,
body {
  height: 100%;
}

body.app-shell-page {
  height: 100vh;
  overflow: hidden;
}

/* Main shell container - replaces body flex */
.app-shell {
  display: flex;
  height: 100vh;
  font-family: 'Montserrat', sans-serif;
  background: var(--shell-light-bg);
  overflow: hidden;
  position: relative;
}

/* Primary Navigation Rail - 80px vertical */
.app-shell-rail {
  width: 80px;
  min-width: 80px;
  background: var(--shell-primary);
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 1.5rem 0;
  z-index: 40;
  box-shadow: 4px 0 10px rgba(0,0,0,0.10);
}

.app-shell-rail-logo {
  width: 48px;
  height: 48px;
  background: var(--shell-accent);
  border-radius: 12px;
  display: flex;
  align-items: center;
  justify-content: center;
  margin-bottom: 1.5rem;
  flex-shrink: 0;
}

.app-shell-rail-logo svg {
  width: 24px;
  height: 24px;
  stroke: var(--shell-primary);
  stroke-width: 2.5;
  fill: none;
}

.app-shell-rail-nav {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.25rem;
  flex: 1;
  /* Keep padding inside the 80px rail to avoid horizontal overflow */
  box-sizing: border-box;
  overflow-y: auto;
  overflow-x: hidden;
  overscroll-behavior: contain;
  -webkit-overflow-scrolling: touch;
  -ms-overflow-style: none;
  scrollbar-width: none;
  width: 100%;
  padding: 0 0.75rem;
  position: relative;
}

.app-shell-rail-nav::-webkit-scrollbar {
  display: none;
}

.app-shell-rail-selector {
  position: absolute;
  left: 0.75rem;
  width: 56px;
  height: 56px;
  border-radius: 14px;
  background: rgba(151, 215, 0, 0.15);
  box-shadow: inset 0 0 0 1px rgba(151, 215, 0, 0.20);
  transform: translateY(0);
  opacity: 0;
  transition: transform 160ms ease, opacity 160ms ease;
  z-index: 1;
  pointer-events: none;
}

.app-shell-rail-selector.is-visible {
  opacity: 1;
}

.app-shell-rail-item {
  width: 56px;
  height: 56px;
  border-radius: 14px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 0.25rem;
  cursor: pointer;
  color: rgba(255, 255, 255, 0.5);
  transition: all 0.2s ease;
  text-decoration: none;
  flex-shrink: 0;
  position: relative;
  z-index: 2;
}

.app-shell-rail-item:hover {
  color: white;
  background: rgba(255, 255, 255, 0.1);
}

.app-shell-rail-item.active {
  color: var(--shell-accent);
  background: rgba(151, 215, 0, 0.15);
}

.app-shell-rail-item svg {
  width: 22px;
  height: 22px;
  stroke: currentColor;
  stroke-width: 2;
  fill: none;
  flex-shrink: 0;
}

.app-shell-rail-item span {
  font-size: 0.55rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.03em;
  text-align: center;
  line-height: 1.1;
  max-width: 100%;
}

/* User controls - positioned at top of rail */
.app-shell-rail-user-controls {
  width: 100%;
  padding-bottom: 1.5rem;
  margin-bottom: 1.5rem;
  border-bottom: 1px solid rgba(255,255,255,0.10);
  display: flex;
  justify-content: center;
  position: relative;
  flex-shrink: 0;
}

/* Legacy footer class - kept for compatibility */
.app-shell-rail-footer {
  width: 100%;
  padding: 0.75rem 0;
  display: flex;
  justify-content: center;
  position: relative;
  flex-shrink: 0;
}

.app-shell-rail-user-control {
  position: relative;
  width: 100%;
  display: flex;
  justify-content: center;
}

.app-shell-rail-user-toggle {
  border: none;
  background: transparent;
  position: relative;
  cursor: pointer;
  padding: 0.25rem;
}

.app-shell-rail-avatar {
  width: 44px;
  height: 44px;
  border-radius: 14px;
  background: var(--shell-accent);
  color: var(--shell-primary);
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 2px 6px rgba(0,0,0,0.18);
}

.app-shell-rail-avatar svg {
  width: 22px;
  height: 22px;
  stroke: currentColor;
  stroke-width: 2;
  fill: none;
}

.app-shell-rail-avatar-img {
  width: 100%;
  height: 100%;
  border-radius: 14px;
  object-fit: cover;
}

.app-shell-rail-cog {
  position: absolute;
  bottom: 0;
  right: 0;
  width: 20px;
  height: 20px;
  border-radius: 50%;
  background: rgba(5, 28, 44, 0.9);
  border: 1px solid rgba(255, 255, 255, 0.4);
  display: grid;
  place-items: center;
  color: var(--shell-accent);
  transition: transform 0.3s ease;
}

.app-shell-rail-user-toggle:hover .app-shell-rail-cog,
.app-shell-rail-user-toggle[aria-expanded="true"] .app-shell-rail-cog {
  transform: rotate(90deg);
}

.app-shell-rail-cog svg {
  width: 12px;
  height: 12px;
  stroke: currentColor;
  stroke-width: 1.8;
  fill: none;
}

.app-shell-rail-panel {
  position: absolute;
  left: calc(80px + 0.75rem);
  top: 0;
  bottom: auto;
  right: auto;
  min-width: 260px;
  background: #f8fafc;
  border: 1px solid rgba(5, 28, 44, 0.1);
  border-radius: 14px;
  padding: 1rem;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.18);
  max-height: 0;
  overflow: hidden;
  opacity: 0;
  pointer-events: none;
  transform: translateX(-12px);
  transition: opacity 0.2s ease, transform 0.2s ease, max-height 0.2s ease;
  z-index: 60;
}

.app-shell-rail-panel.open {
  opacity: 1;
  pointer-events: auto;
  transform: translateX(0);
  max-height: calc(100dvh - 6rem);
  overflow-y: auto;
}

.app-shell-rail-panel-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 0.75rem;
  gap: 0.75rem;
}

.app-shell-rail-panel-user {
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
}

.app-shell-rail-panel-name {
  font-size: 0.9rem;
  font-weight: 600;
  color: var(--shell-primary);
  max-width: 160px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.app-shell-rail-panel-session {
  font-size: 0.75rem;
  color: var(--shell-text-secondary);
}

.app-shell-rail-panel-section {
  margin-bottom: 0.75rem;
}

.app-shell-rail-panel-title {
  display: block;
  font-size: 0.65rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--shell-text-muted);
  margin-bottom: 0.5rem;
}

.app-shell-rail-panel-actions {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.app-shell-rail-panel-links {
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
  padding-bottom: 0.5rem;
}

.app-shell-rail-panel-link {
  display: flex;
  align-items: center;
  padding: 0.5rem 0.5rem;
  border-radius: 8px;
  font-size: 0.85rem;
  color: var(--shell-primary);
  text-decoration: none;
  transition: background 0.15s ease;
}

.app-shell-rail-panel-link:hover {
  background: rgba(5, 28, 44, 0.08);
}

.app-shell-rail-panel-link.danger {
  color: var(--shell-danger);
  font-weight: 500;
}

.app-shell-rail-panel-link.danger:hover {
  background: rgba(239, 68, 68, 0.08);
}

.app-shell-rail-panel-label {
  font-size: 0.65rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--shell-text-muted);
  padding: 0.25rem 0.5rem;
}

.app-shell-rail-panel-divider {
  height: 1px;
  background: rgba(5, 28, 44, 0.12);
  margin: 0.75rem 0;
}

.app-shell-rail-panel-divider.compact {
  margin: 0.5rem 0;
}

.app-shell-panel-submenu {
  right: auto;
  left: 0;
}

.app-shell-rail-panel-version {
  font-size: 0.7rem;
  color: var(--shell-text-muted);
  padding: 0.25rem 0.5rem;
  text-align: center;
  display: block;
}

.app-shell-rail-item:focus-visible,
.app-shell-rail-user-toggle:focus-visible,
.app-shell-rail-panel-link:focus-visible {
  outline: 2px solid rgba(151, 215, 0, 0.8);
  outline-offset: 2px;
}

.app-shell-rail-item:focus-visible {
  border-radius: 14px;
}

.app-shell-rail-user-toggle:focus-visible {
  border-radius: 14px;
}

.app-shell-rail-panel-link:focus-visible {
  border-radius: 8px;
}

@media (prefers-reduced-motion: reduce) {
  .app-shell-rail-selector,
  .app-shell-rail-panel,
  .app-shell-rail-item,
  .app-shell-rail-panel-link,
  .app-shell-rail-user-toggle {
    transition: none;
  }
}

/* Secondary Navigation Panel - 260px contextual tools */
.app-shell-secondary {
  width: 260px;
  min-width: 260px;
  background: white;
  border-right: 1px solid var(--shell-border);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.app-shell-secondary-scroll {
  flex: 1;
  min-height: 0; /* Required for flex child overflow */
  overflow-y: auto;
  overflow-x: hidden;
  overscroll-behavior: contain;
  -webkit-overflow-scrolling: touch;
  padding: 1.5rem;
  box-sizing: border-box;
  -ms-overflow-style: none;
  scrollbar-width: none;
}

.app-shell-secondary-scroll::-webkit-scrollbar {
  display: none;
}

.app-shell-secondary-title {
  font-size: 0.7rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: var(--shell-text-muted);
  margin-bottom: 1rem;
  padding: 0 0.25rem;
}

.app-shell-secondary-item {
  display: flex;
  align-items: center;
  gap: 0.875rem;
  padding: 0.75rem 0.875rem;
  border-radius: 12px;
  cursor: pointer;
  transition: all 0.2s ease;
  margin-bottom: 0.25rem;
  text-decoration: none;
  color: inherit;
}

.app-shell-secondary-item:hover {
  background: var(--shell-light-bg);
}

.app-shell-secondary-item.active {
  background: linear-gradient(135deg, var(--shell-accent), var(--shell-accent-dark));
}

.app-shell-secondary-item.active .app-shell-item-title,
.app-shell-secondary-item.active .app-shell-item-icon {
  color: var(--shell-primary);
}

.app-shell-secondary-item.active .app-shell-item-icon {
  background: rgba(255, 255, 255, 0.3);
}

.app-shell-secondary-item.active .app-shell-item-desc {
  color: var(--shell-primary);
  opacity: 0.7;
}

.app-shell-item-icon {
  width: 36px;
  height: 36px;
  min-width: 36px;
  border-radius: 10px;
  background: var(--shell-light-bg);
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--shell-text-secondary);
  transition: all 0.2s ease;
}

.app-shell-item-icon svg {
  width: 18px;
  height: 18px;
  stroke: currentColor;
  stroke-width: 2;
  fill: none;
}

.app-shell-item-text {
  flex: 1;
  min-width: 0;
}

.app-shell-item-title {
  font-size: 0.875rem;
  font-weight: 600;
  color: var(--shell-primary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.app-shell-item-desc {
  font-size: 0.75rem;
  color: var(--shell-text-muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.app-shell-divider {
  height: 1px;
  background: var(--shell-border);
  margin: 1rem 0;
}

/* Secondary panel header for filters/actions */
.app-shell-secondary-header {
  padding: 1rem 1.5rem;
  border-bottom: 1px solid var(--shell-border);
  background: white;
}

.app-shell-secondary-header-title {
  font-size: 1rem;
  font-weight: 700;
  color: var(--shell-primary);
  margin-bottom: 0.5rem;
}

/* Action button in secondary panel */
.app-shell-action-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  width: 100%;
  padding: 0.75rem 1rem;
  border-radius: 10px;
  background: var(--shell-accent);
  color: var(--shell-primary);
  font-size: 0.875rem;
  font-weight: 600;
  cursor: pointer;
  border: none;
  transition: all 0.2s ease;
  text-decoration: none;
}

.app-shell-action-btn:hover {
  background: var(--shell-accent-dark);
}

.app-shell-action-btn svg {
  width: 18px;
  height: 18px;
  stroke: currentColor;
  stroke-width: 2;
  fill: none;
}

/* Form controls in secondary panel */
.app-shell-form-group {
  margin-bottom: 1rem;
}

.app-shell-form-label {
  display: block;
  font-size: 0.75rem;
  font-weight: 600;
  color: var(--shell-text-secondary);
  margin-bottom: 0.375rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.app-shell-form-select {
  width: 100%;
  padding: 0.625rem 0.875rem;
  border: 1px solid var(--shell-border);
  border-radius: 8px;
  font-size: 0.875rem;
  color: var(--shell-primary);
  background: white;
  cursor: pointer;
  transition: border-color 0.2s ease;
}

.app-shell-form-select:focus {
  outline: none;
  border-color: var(--shell-accent);
}

.app-shell-form-input {
  width: 100%;
  padding: 0.625rem 0.875rem;
  border: 1px solid var(--shell-border);
  border-radius: 8px;
  font-size: 0.875rem;
  color: var(--shell-primary);
  background: white;
  transition: border-color 0.2s ease;
}

.app-shell-form-input:focus {
  outline: none;
  border-color: var(--shell-accent);
}

/* Main content wrapper */
.app-shell-main {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-width: 0;
  overflow: hidden;
}

/* Top utility bar - only renders when content exists */
.app-shell-topbar {
  background: white;
  border-bottom: 1px solid var(--shell-border);
  padding: 0.75rem 1.5rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-shrink: 0;
}

/* Prevent empty topbars from reserving space */
.app-shell-topbar:empty {
  display: none;
}

.app-shell-topbar-left {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  font-size: 0.875rem;
  color: var(--shell-text-secondary);
}

.app-shell-topbar-right {
  display: flex;
  align-items: center;
  gap: 0.75rem;
}

/* Main content area */
.app-shell-content {
  flex: 1;
  overflow-y: auto;
  overflow-x: hidden;
  overscroll-behavior: contain;
  -webkit-overflow-scrolling: touch;
  background: var(--shell-light-bg);
  min-height: 0;
  -ms-overflow-style: none;
  scrollbar-width: none;
}

.app-shell-content::-webkit-scrollbar {
  display: none;
}

/* Utility classes for spacing in content */
.app-shell-content-padded {
  padding: 1.5rem;
}

/* Breadcrumb in topbar */
.app-shell-breadcrumb {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  font-size: 0.875rem;
  color: var(--shell-text-secondary);
}

.app-shell-breadcrumb-sep {
  color: var(--shell-border);
}

.app-shell-breadcrumb-current {
  color: var(--shell-primary);
  font-weight: 500;
}

/* Utility button styles (for mood, timer, alerts) */
.app-shell-util-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 36px;
  height: 36px;
  border-radius: 10px;
  background: var(--shell-light-bg);
  color: var(--shell-text-secondary);
  cursor: pointer;
  border: none;
  transition: all 0.2s ease;
  position: relative;
}

.app-shell-util-btn:hover {
  background: var(--shell-border);
  color: var(--shell-primary);
}

.app-shell-util-btn svg {
  width: 20px;
  height: 20px;
  stroke: currentColor;
  stroke-width: 2;
  fill: none;
}

.timer-icon #timer-hand {
  transform-origin: 8.5px 9.5px;
}

@keyframes timer-spin {
  from { transform: rotate(0deg); }
  to { transform: rotate(360deg); }
}

@keyframes timer-glow {
  0%, 100% { filter: drop-shadow(0 0 3px rgba(151, 215, 0, 0.6)); }
  50% { filter: drop-shadow(0 0 8px rgba(151, 215, 0, 0.9)); }
}

.timer-on .timer-icon #timer-hand {
  animation: timer-spin 2s linear infinite;
}

.timer-on .timer-icon {
  animation: timer-glow 1.5s ease-in-out infinite;
}

.app-shell-util-badge {
  position: absolute;
  top: -4px;
  right: -4px;
  min-width: 18px;
  height: 18px;
  padding: 0 5px;
  border-radius: 9px;
  background: #ef4444;
  color: white;
  font-size: 0.625rem;
  font-weight: 700;
  display: flex;
  align-items: center;
  justify-content: center;
}

/* User avatar in topbar */
.app-shell-user-avatar {
  width: 36px;
  height: 36px;
  border-radius: 10px;
  object-fit: cover;
  cursor: pointer;
}

/* Dropdown menu base */
.app-shell-dropdown {
  position: absolute;
  top: 100%;
  right: 0;
  margin-top: 0.5rem;
  min-width: 200px;
  background: white;
  border-radius: 12px;
  box-shadow: 0 10px 40px rgba(0, 0, 0, 0.15);
  z-index: 50;
  opacity: 0;
  transform: translateY(-8px);
  pointer-events: none;
  transition: all 0.2s ease;
}

.app-shell-dropdown.open {
  opacity: 1;
  transform: translateY(0);
  pointer-events: auto;
}

.app-shell-dropdown-item {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0.75rem 1rem;
  font-size: 0.875rem;
  color: var(--shell-primary);
  cursor: pointer;
  transition: background 0.15s ease;
  text-decoration: none;
}

.app-shell-dropdown-item:first-child {
  border-radius: 12px 12px 0 0;
}

.app-shell-dropdown-item:last-child {
  border-radius: 0 0 12px 12px;
}

.app-shell-dropdown-item:hover {
  background: var(--shell-light-bg);
}

.app-shell-dropdown-divider {
  height: 1px;
  background: var(--shell-border);
  margin: 0.25rem 0;
}

/* Hide secondary panel when empty */
.app-shell-secondary:empty {
  display: none;
}

.app-shell-secondary.hidden {
  display: none;
}

.app-shell-secondary-toggle {
  position: absolute;
  top: 140px;
  left: calc(80px + 260px - 14px);
  width: 28px;
  height: 48px;
  border-radius: 999px;
  border: 1px solid var(--shell-border);
  background: white;
  color: var(--shell-primary);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 4px 10px rgba(5, 28, 44, 0.12);
  z-index: 60;
  cursor: pointer;
  transition: background 0.2s ease, transform 0.2s ease, left 0.2s ease;
}

.app-shell-secondary-toggle:hover {
  background: var(--shell-light-bg);
}

.app-shell-secondary-toggle:focus-visible {
  outline: 2px solid rgba(151, 215, 0, 0.8);
  outline-offset: 2px;
}

.app-shell-secondary-toggle-icon {
  width: 16px;
  height: 16px;
  transition: transform 0.2s ease;
}

.app-shell-secondary-toggle[aria-expanded="true"] .app-shell-secondary-toggle-icon {
  transform: rotate(180deg);
}

.app-shell.secondary-panel-hidden .app-shell-secondary-toggle {
  left: calc(80px - 14px);
}

/* Slider styling for filters */
.app-shell-slider {
  width: 100%;
  margin: 0.5rem 0;
  -webkit-appearance: none;
  appearance: none;
  height: 6px;
  background: var(--shell-border);
  border-radius: 3px;
  outline: none;
}

.app-shell-slider::-webkit-slider-thumb {
  -webkit-appearance: none;
  appearance: none;
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: var(--shell-accent);
  cursor: pointer;
  border: 2px solid white;
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.15);
}

.app-shell-slider::-moz-range-thumb {
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: var(--shell-accent);
  cursor: pointer;
  border: 2px solid white;
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.15);
}

/* Hide scrollbars in app shell scroll regions */
.app-shell-rail-nav::-webkit-scrollbar,
.app-shell-secondary-scroll::-webkit-scrollbar,
.app-shell-content::-webkit-scrollbar {
  display: none;
}

/* Tab navigation in secondary panel */
.app-shell-tabs {
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
}

.app-shell-tab {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0.75rem 0.875rem;
  border-radius: 10px;
  cursor: pointer;
  transition: all 0.2s ease;
  color: var(--shell-text-secondary);
  font-size: 0.875rem;
  font-weight: 500;
  text-decoration: none;
}

.app-shell-tab:hover {
  background: var(--shell-light-bg);
  color: var(--shell-primary);
}

.app-shell-tab.active {
  background: var(--shell-accent);
  color: var(--shell-primary);
  font-weight: 600;
}

.app-shell-tab svg {
  width: 18px;
  height: 18px;
  stroke: currentColor;
  stroke-width: 2;
  fill: none;
}

/* Shared modal styling */
.cg-modal {
  padding: 0;
  border: none;
  background: transparent;
}

.cg-modal[open] {
  display: flex;
}

.cg-modal::backdrop {
  background: rgba(5, 28, 44, 0.45);
  -webkit-backdrop-filter: blur(6px);
  backdrop-filter: blur(6px);
}

.cg-modal__viewport {
  pointer-events: none;
}

.cg-modal__panel {
  pointer-events: auto;
  border: 1px solid var(--shell-border);
}
