/* Synchronous Route Classification Pre-render Guard (v0.66A) */
html[data-route-kind="special"] #dashboardContent {
  display: none !important;
}
html[data-route-kind="special"] #specialPage:not([hidden]) {
  display: block !important;
}

/* Pre-render Guard for Auth Controls (Avoid flash of unauthenticated button) */
html[data-auth-state="loading"] #authControls {
  visibility: hidden;
}

/* Pre-render Guard for AI Floating Widget (Profile-only, never on special or other pages) */
html:not([data-route-kind="profile"]) #aiFloatingContainer,
html:not([data-route-kind="profile"]) #aiWidgetPanel,
body.is-special #aiFloatingContainer,
body.is-special #aiWidgetPanel {
  display: none !important;
}

.topbar {
  display: flex;
  justify-content: space-between;
  align-items: flex-end;
  gap: 20px;
  margin-bottom: 24px;
}

.brand-line {
  display: flex;
  align-items: baseline;
  gap: 12px;
  flex-wrap: wrap;
}

.eyebrow, .kicker {
  color: var(--muted);
  font-size: 0.7rem;
  font-weight: 850;
  letter-spacing: 0.14em;
  text-transform: uppercase;
}

.eyebrow {
  margin-bottom: 7px;
}

.current-page-link {
  display: inline-block;
  color: var(--muted);
  transition: 0.15s;
}

.current-page-link:hover {
  color: var(--text);
}

h1 {
  margin: 0;
  font-size: clamp(2.5rem, 7vw, 4.7rem);
  line-height: 0.95;
  letter-spacing: -0.055em;
}

.friends-trigger {
  border: 0;
  background: transparent;
  color: var(--muted);
  padding: 0 0 0.36rem;
  cursor: pointer;
  font-size: clamp(0.9rem, 2vw, 1.14rem);
  font-weight: 780;
  transition: 0.15s;
}

.friends-trigger:hover {
  color: var(--text);
}

.top-right {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  flex-shrink: 0;
}

.language-switch {
  display: flex;
  align-self: flex-end;
  padding: 3px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: rgba(0, 0, 0, 0.14);
  margin-bottom: 7px;
}

.language-button {
  border: 0;
  border-radius: 7px;
  background: transparent;
  color: var(--muted);
  padding: 5px 8px;
  cursor: pointer;
  font-size: 0.67rem;
  font-weight: 850;
  letter-spacing: 0.06em;
}

.language-button.active {
  background: var(--control-active-bg, rgba(255, 255, 255, 0.09));
  color: var(--control-active-text, var(--text));
}

.status {
  text-align: right;
  color: var(--muted);
  font-size: 0.8rem;
}

.status-actions {
  display: flex;
  flex-direction: column;
  gap: 0;
  align-items: flex-end;
}

.refresh {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border: 0;
  background: transparent;
  color: var(--muted);
  padding: 0;
  cursor: pointer;
  font-weight: 760;
  line-height: 1.35;
}

.refresh:hover {
  color: var(--text);
}

.refresh:disabled {
  opacity: 0.5;
  cursor: wait;
}

.profile-title {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
  margin: 2px 0 15px;
}

.profile-title h2 {
  margin: 3px 0 0;
  font-size: 1.45rem;
  letter-spacing: -0.03em;
}

.grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 18px;
}

.grid.one {
  grid-template-columns: minmax(0, 1fr);
}

.card, .wide {
  min-width: 0;
  border: 1px solid var(--line);
  border-radius: 21px;
  box-shadow: var(--panel-shadow, var(--shadow));
  overflow: hidden;
}

#settingsDrawer { background: var(--bg); }

.wide, .dashboard-section.wide {
  background: var(--panel-surface, var(--panel));
}

#profileSection {
  background: transparent;
  border: none;
  box-shadow: none;
}

.card {
  background: var(--card-surface, var(--panel2));
}

#profiles .card {
  background: var(--account-card-surface, var(--panel));
  border: 1px solid var(--line);
  display: flex;
  flex-direction: column;
  height: 100%;
  position: relative;
  overflow: visible;
}

#profiles .links {
  margin-top: auto;
  width: 100%;
}

.wide {
  margin-top: 18px;
}

.top-nav-group {
  display: inline-flex;
  align-items: baseline;
  gap: 12px;
  flex-wrap: wrap;
}

.top-nav-link {
  display: inline-flex;
  align-items: baseline;
  align-self: baseline;
  color: var(--muted);
  padding: 0 0 0.36rem;
  font-size: clamp(0.78rem, 1.6vw, 0.92rem);
  font-weight: 780;
  line-height: 1;
  transition: 0.15s;
  white-space: nowrap;
}

.top-nav-link:hover {
  color: var(--text);
}

.site-version {
  align-self: baseline;
  margin-left: -8px;
  padding: 4px 8px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.035);
  color: var(--muted);
  font-size: 0.62rem;
  font-weight: 850;
  letter-spacing: 0.06em;
}

.site-version:hover {
  color: var(--text);
  background: rgba(255, 255, 255, 0.07);
}

#adminNavMount {
  display: contents;
}

/* Drawer */
.drawer-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.52);
  opacity: 0;
  pointer-events: none;
  transition: 0.18s;
  z-index: 80;
}

.drawer {
  position: fixed;
  top: 0;
  height: 100dvh;
  width: min(380px, 90vw);
  padding: 22px;
  background: var(--settings-surface, var(--panel));
  transition: transform 0.25s cubic-bezier(0.16, 1, 0.3, 1);
  z-index: 100;
  display: flex;
  flex-direction: column;
}

.drawer-left {
  left: 0;
  right: auto;
  border-right: 1px solid var(--line);
  box-shadow: 20px 0 60px rgba(0, 0, 0, 0.45);
  transform: translateX(-102%);
}

.drawer-right {
  right: 0;
  left: auto;
  border-left: 1px solid var(--line);
  box-shadow: -20px 0 60px rgba(0, 0, 0, 0.45);
  transform: translateX(102%);
}

.drawer.open {
  transform: none;
}

.drawer-backdrop.open {
  opacity: 1;
  pointer-events: auto;
}

.drawer-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 9px;
}

.drawer-head h2 {
  margin: 0;
  font-size: 1.2rem;
}

.drawer-close {
  border: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.04);
  color: var(--text);
  border-radius: 10px;
  width: 36px;
  height: 36px;
  cursor: pointer;
}

.drawer-search-wrap {
  position: relative;
  display: flex;
  align-items: center;
  margin-bottom: 12px;
}

.drawer-search-icon {
  position: absolute;
  left: 12px;
  font-size: 0.85rem;
  opacity: 0.6;
  pointer-events: none;
}

.drawer-search-input {
  width: 100%;
  padding: 9px 12px 9px 34px;
  border: 1px solid var(--line);
  border-radius: 11px;
  background: var(--input-bg, rgba(0, 0, 0, 0.25));
  color: var(--text);
  font-size: 0.85rem;
  font-family: inherit;
  outline: none;
  transition: border-color 0.15s ease, background 0.15s ease;
  box-sizing: border-box;
}

.drawer-search-input:focus {
  border-color: var(--accent);
  background: var(--input-bg, rgba(0, 0, 0, 0.4));
}

.drawer-list {
  min-height: 0;
  overflow-y: auto;
  padding-bottom: 14px;
  scrollbar-width: thin;
  scrollbar-color: var(--scroll-thumb) var(--scroll-track);
}

.drawer-list::-webkit-scrollbar {
  width: 6px;
}
.drawer-list::-webkit-scrollbar-track {
  background: var(--scroll-track);
  border-radius: 3px;
}
.drawer-list::-webkit-scrollbar-thumb {
  background: var(--scroll-thumb);
  border-radius: 3px;
}
.drawer-list::-webkit-scrollbar-thumb:hover {
  background: var(--scroll-thumb-hover);
}

.friend-row {
  display: flex;
  align-items: stretch;
  margin-top: 9px;
  border: 1px solid var(--line);
  border-radius: 13px;
  background: rgba(255, 255, 255, 0.025);
  overflow: hidden;
}

.friend-row:hover, .friend-row.active {
  background: rgba(255, 255, 255, 0.075);
}

.friend-link {
  display: block;
  flex: 1;
  min-width: 0;
  padding: 12px 13px;
}

.friend-name {
  font-weight: 830;
}

.friend-path {
  margin-top: 3px;
  color: var(--muted);
  font-size: 0.7rem;
}

.friend-star {
  width: 45px;
  flex: 0 0 45px;
  border: 0;
  border-left: 1px solid var(--line);
  background: transparent;
  color: var(--muted);
  opacity: 0.45;
  font-size: 1.22rem;
  cursor: pointer;
  transition: opacity 0.15s ease, color 0.15s ease, background 0.15s ease;
}

.friend-star:hover {
  background: rgba(232, 197, 106, 0.08);
  color: var(--accent);
  opacity: 1;
}

.friend-star.favorite {
  color: var(--accent);
  opacity: 1;
}

.drawer-actions {
  margin-top: auto;
  padding-top: 15px;
  border-top: 1px solid var(--line);
}

.drawer-join {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 13px 14px;
  border: 1px solid var(--accent-secondary-soft, rgba(111, 168, 255, 0.28));
  border-radius: 13px;
  background: var(--control-bg, rgba(111, 168, 255, 0.08));
  color: var(--text);
  font-weight: 850;
  transition: all 0.15s ease;
}

.drawer-join:hover {
  background: var(--accent-secondary-soft, rgba(111, 168, 255, 0.16));
  border-color: var(--accent-secondary, var(--accent));
}

.drawer-join span:last-child {
  color: var(--accent-secondary, var(--accent));
  font-size: 1.1rem;
}

/* ==========================================================================
   2 Układy Dashboardu: Klasyczny i Panoramiczny (data-layout)
   ========================================================================== */

/* Zero-shift boot: natychmiastowe zaaplikowanie szerokości dla Panoramicznego */
html[data-layout="panoramic"] main,
html[data-layout="wide"] main,
body:has(#dashboardContent[data-layout="panoramic"]) main,
body:has(#dashboardContent[data-layout="wide"]) main,
main.layout-wide-active {
  width: min(1740px, calc(100% - 48px));
  max-width: 1740px;
}

/* Dashboard flex wrap container */
#dashboardContent {
  display: flex;
  flex-wrap: wrap;
  gap: 24px;
  align-items: stretch;
}

.dashboard-section {
  flex: 0 0 100%;
  width: 100%;
  min-width: 0;
  box-sizing: border-box;
}

/* 50% szerokości panelu na ekranach >= 900px */
@media (min-width: 900px) {
  .dashboard-section[data-panel-width="50"],
  .dashboard-section[data-section-width="50"],
  .dashboard-section[data-section-width="1/2"],
  .dashboard-section.width-50 {
    flex: 0 0 calc(50% - 12px) !important;
    width: calc(50% - 12px) !important;
  }

  /* Profil przy 50% - konta w 1 kolumnie (jedno pod drugim) */
  #profileSection[data-panel-width="50"] .grid,
  #profileSection[data-section-width="50"] .grid,
  #profileSection[data-section-width="1/2"] .grid,
  #profileSection.width-50 .grid,
  #profileSection[data-panel-width="50"] #profiles,
  #profileSection[data-section-width="50"] #profiles,
  #profileSection[data-section-width="1/2"] #profiles,
  #profileSection.width-50 #profiles {
    grid-template-columns: 1fr !important;
  }
}

@media (max-width: 899px) {
  .dashboard-section {
    flex: 0 0 100% !important;
    width: 100% !important;
  }
}

/* ==========================================================================
   Tryb Dostosowywania Układu (.layout-customizing)
   ========================================================================== */
.layout-edit-bar {
  position: fixed;
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 999;
  background: var(--panel2, #141c26);
  border: 1px solid var(--accent);
  box-shadow: 0 16px 50px rgba(0, 0, 0, 0.7);
  padding: 10px 18px;
  border-radius: 999px;
  display: flex;
  align-items: center;
  gap: 12px;
  backdrop-filter: blur(14px);
}

.layout-edit-bar-title {
  font-size: 0.82rem;
  font-weight: 800;
  color: var(--text);
  margin-right: 4px;
}

.layout-edit-btn {
  padding: 6px 14px;
  border-radius: 999px;
  border: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.05);
  color: var(--text);
  font-size: 0.78rem;
  font-weight: 750;
  cursor: pointer;
  transition: 0.15s;
}

.layout-edit-btn:hover {
  background: rgba(255, 255, 255, 0.1);
}

.layout-edit-btn.primary {
  background: var(--accent);
  color: var(--on-accent);
  border-color: var(--accent);
  font-weight: 850;
}

.layout-edit-btn.primary:hover {
  filter: brightness(1.1);
}

.section-edit-handle {
  display: none;
}

body.layout-customizing .section-edit-handle {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  background: var(--panel2, #141c26);
  border: 1px solid var(--accent);
  padding: 8px 14px;
  border-radius: 12px;
  margin-bottom: 12px;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.4);
}

body.layout-customizing .dashboard-section {
  position: relative;
  outline: 2px dashed rgba(232, 197, 106, 0.45);
  outline-offset: 4px;
  border-radius: 18px;
  transition: transform 0.15s ease, opacity 0.15s ease;
}

body.layout-customizing .dashboard-section.is-dragging {
  opacity: 0.35;
  transform: scale(0.98);
  outline: 2px solid var(--accent);
}

.section-edit-handle .drag-handle-pill {
  display: flex;
  align-items: center;
  gap: 8px;
  cursor: grab;
  user-select: none;
}

.section-edit-handle .drag-handle-pill:active {
  cursor: grabbing;
}

.section-edit-handle .drag-grip {
  color: var(--accent);
  font-size: 1.15rem;
  line-height: 1;
  letter-spacing: -2px;
}

.section-edit-handle .handle-title {
  color: var(--text);
  font-size: 0.82rem;
  font-weight: 800;
}

.section-edit-handle .handle-controls {
  display: flex;
  align-items: center;
  gap: 6px;
}

.section-edit-handle .btn-panel-order {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 28px;
  height: 28px;
  border-radius: 8px;
  border: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.05);
  color: var(--text);
  font-size: 0.88rem;
  font-weight: 850;
  cursor: pointer;
  transition: all 0.15s ease;
}

.section-edit-handle .btn-panel-order:hover {
  background: rgba(255, 255, 255, 0.12);
  border-color: var(--accent);
  color: var(--accent);
}

.section-edit-handle .btn-panel-size {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 28px;
  height: 28px;
  padding: 0;
  border-radius: 8px;
  border: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.05);
  color: var(--text);
  cursor: pointer;
  transition: all 0.15s ease;
}

.section-edit-handle .btn-panel-size svg {
  display: block;
  stroke: currentColor;
  fill: none;
}

.section-edit-handle .btn-panel-size:hover {
  background: rgba(255, 255, 255, 0.12);
  border-color: var(--accent);
  color: var(--accent);
}

/* ==========================================================================
   AI Widget State: Expanded
   ========================================================================== */
.ai-widget-panel.expanded {
  width: min(900px, calc(100vw - 40px)) !important;
  height: min(760px, calc(100dvh - 80px)) !important;
  max-height: calc(100dvh - 80px) !important;
}

@media (max-width: 899px) {
  .ai-widget-panel.expanded {
    position: fixed !important;
    inset: 0 !important;
    width: 100vw !important;
    height: 100dvh !important;
    max-height: 100dvh !important;
    border-radius: 0 !important;
    bottom: 0 !important;
    right: 0 !important;
    z-index: 1000 !important;
  }
}
