/* ═══════════════════════════════════════════════════════════════
   KREDITS — App Shell Styles
   Requires kredits-tokens.css to be loaded first.
   All shell elements are injected by kredits-shell.js;
   this file only styles them.
═══════════════════════════════════════════════════════════════ */

/* ── SHARED ICON-BUTTON ─────────────────────────────────────── */
.ks-icon-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 36px;
  height: 36px;
  border-radius: var(--radius-sm);
  border: none;
  background: transparent;
  color: var(--color-text-secondary);
  cursor: pointer;
  flex-shrink: 0;
  transition: background 150ms ease, color 150ms ease;
  padding: 0;
}
.ks-icon-btn:hover {
  background: var(--color-surface-subtle);
  color: var(--color-text-primary);
}
.ks-icon-btn:focus-visible {
  outline: 2px solid var(--color-accent);
  outline-offset: 2px;
}


/* ── TOP BAR ────────────────────────────────────────────────── */
#ks-topbar {
  position: fixed;
  top: 0; left: 0; right: 0;
  height: var(--ks-topbar-h);
  z-index: 300;
  display: flex;
  align-items: center;
  padding: 0 var(--space-4);
  gap: var(--space-2);
  background: var(--color-surface);
  border-bottom: 1px solid var(--color-border);
  box-shadow: var(--shadow-sm);
}

#ks-topbar-center {
  flex: 1;
  min-width: 0;
  display: flex;
  align-items: center;
  justify-content: center;
}

#ks-topbar-class {
  font-family: var(--font-body);
  font-size: var(--text-sm);
  font-weight: 600;
  color: var(--color-text-primary);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  max-width: 240px;
}

/* Search button – non-functional placeholder in this phase */
#ks-search-btn {
  /* inherits .ks-icon-btn */
}

/* Avatar circle (right side → links to Settings) */
.ks-avatar {
  width: 32px;
  height: 32px;
  border-radius: var(--radius-full);
  background: var(--color-accent);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  text-decoration: none;
  flex-shrink: 0;
  transition: opacity 150ms ease;
}
.ks-avatar:hover {
  opacity: 0.85;
}
.ks-avatar:focus-visible {
  outline: 2px solid var(--color-accent);
  outline-offset: 2px;
}
.ks-avatar span {
  font-family: var(--font-heading);
  font-size: var(--text-xs);
  font-weight: 700;
  color: #fff;
  letter-spacing: 0.04em;
  line-height: 1;
  user-select: none;
}


/* ── LEFT SIDEBAR ───────────────────────────────────────────── */
#ks-sidebar {
  position: fixed;
  top: var(--ks-topbar-h);
  left: 0;
  bottom: 0;
  width: var(--ks-sidebar-w);
  z-index: 200;
  display: flex;
  flex-direction: column;
  background: var(--color-surface);
  border-right: 1px solid var(--color-border);
  overflow: hidden;
  /* transition added via .ks-transitions-ready (prevents flash on load) */
}

body.ks-transitions-ready #ks-sidebar {
  transition: width 250ms cubic-bezier(0.4, 0, 0.2, 1);
}

#ks-sidebar.ks-collapsed {
  width: var(--ks-sidebar-cw);
}

/* Nav item list */
#ks-sidebar-nav {
  flex: 1;
  overflow-y: auto;
  overflow-x: hidden;
  padding: var(--space-3) var(--space-2);
  display: flex;
  flex-direction: column;
  gap: var(--space-1);
  scrollbar-width: thin;
  scrollbar-color: var(--color-border) transparent;
}

/* Sidebar nav items */
.ks-nav-item {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  height: 36px;
  padding: 0 var(--space-2);
  border-radius: var(--radius-sm);
  border-left: 2px solid transparent;
  text-decoration: none;
  color: var(--color-text-secondary);
  font-family: var(--font-body);
  font-size: var(--text-sm);
  font-weight: 500;
  white-space: nowrap;
  overflow: hidden;
  cursor: pointer;
  flex-shrink: 0;
  transition: background 150ms ease, color 150ms ease, border-color 150ms ease;
}
.ks-nav-item:hover {
  background: var(--color-surface-subtle);
  color: var(--color-text-primary);
}
.ks-nav-item.ks-active {
  background: var(--color-accent-subtle);
  color: var(--color-accent);
  border-left-color: var(--color-accent);
}
.ks-nav-item:focus-visible {
  outline: 2px solid var(--color-accent);
  outline-offset: 2px;
}

/* Tablet: taller touch target */
@media (min-width: 768px) and (max-width: 1023px) {
  .ks-nav-item { height: 44px; }
}

.ks-nav-icon {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 20px;
  height: 20px;
  flex-shrink: 0;
  color: inherit;
}

.ks-nav-label {
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  opacity: 1;
  max-width: 200px;
  transition: opacity 180ms ease, max-width 250ms ease;
}

/* Collapsed: hide labels, centre icons */
#ks-sidebar.ks-collapsed .ks-nav-label {
  opacity: 0;
  max-width: 0;
  pointer-events: none;
}

#ks-sidebar.ks-collapsed .ks-nav-item {
  justify-content: center;
  padding: 0;
  gap: 0;
  border-left-color: transparent;
  border-radius: var(--radius-sm);
}

/* Active state in collapsed mode: accent background without left border */
#ks-sidebar.ks-collapsed .ks-nav-item.ks-active {
  background: var(--color-accent-subtle);
  color: var(--color-accent);
}

/* Pinned-bottom nav section (e.g. Settings) */
#ks-sidebar-nav-bottom {
  flex-shrink: 0;
  padding: var(--space-2);
  border-top: 1px solid var(--color-border);
  display: flex;
  flex-direction: column;
  gap: var(--space-1);
}

/* Collapse toggle button at the bottom of the sidebar */
#ks-collapse-btn {
  margin: var(--space-2);
  align-self: flex-start;
  flex-shrink: 0;
}

#ks-sidebar.ks-collapsed #ks-collapse-btn {
  align-self: center;
  margin: var(--space-2) auto;
}


/* ── BOTTOM TAB BAR (mobile only) ───────────────────────────── */
#ks-bottombar {
  position: fixed;
  bottom: 0; left: 0; right: 0;
  height: var(--ks-bottombar-h);
  z-index: 200;
  display: flex;
  align-items: stretch;
  background: var(--color-surface);
  border-top: 1px solid var(--color-border);
  box-shadow: 0 -2px 8px rgba(0,0,0,0.06);
  overflow-x: auto; overflow-y: hidden;
  -webkit-overflow-scrolling: touch;
  scrollbar-width: none;
  padding-bottom: env(safe-area-inset-bottom, 0);
}
#ks-bottombar::-webkit-scrollbar { display: none; }

.ks-tab-item {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 5px;
  min-height: 64px;
  padding: 12px var(--space-2);
  text-decoration: none;
  color: var(--color-text-muted);
  font-family: var(--font-body);
  font-size: 11px;
  line-height: 1;
  font-weight: 600;
  transition: color 150ms ease;
  border: none;
  background: transparent;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}
.ks-tab-item:hover {
  color: var(--color-text-secondary);
}
.ks-tab-item.ks-active {
  color: var(--color-accent);
}
.ks-tab-item:focus-visible {
  outline: 2px solid var(--color-accent);
  outline-offset: -2px;
}

.ks-tab-icon {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 24px;
  height: 24px;
  font-size: 22px;
  color: inherit;
  flex-shrink: 0;
}

.ks-tab-label {
  line-height: 1;
  letter-spacing: 0.02em;
}


/* ── BODY SPACING WHEN SHELL IS ACTIVE ──────────────────────── */
body.ks-active {
  padding-top: var(--ks-topbar-h);
  /*
   * _shared.css sets overflow-x:hidden on body. On iOS Safari and Chrome/Android,
   * this makes position:fixed children use the body (not the viewport) as their
   * containing block. Since the body is min-height:100vh + padding-bottom:72px,
   * a bottom:0 fixed element ends up ~72px below the visible screen.
   * Unsetting overflow-x here restores correct viewport-relative fixed positioning.
   */
  overflow-x: visible;
}

/* Desktop / tablet: sidebar pushes content right */
@media (min-width: 768px) {
  body.ks-active {
    padding-left: var(--ks-sidebar-w);
  }
  body.ks-active.ks-collapsed {
    padding-left: var(--ks-sidebar-cw);
  }
  body.ks-transitions-ready.ks-active {
    transition: padding-left 250ms cubic-bezier(0.4, 0, 0.2, 1);
  }

  /* Hide bottom bar on desktop */
  #ks-bottombar { display: none; }

  /* Hide hamburger tooltip on desktop (sidebar is always visible) */
  #ks-menu-toggle { display: none; }
}

/* Mobile: bottom bar pads content */
@media (max-width: 767px) {
  body.ks-active {
    padding-bottom: var(--ks-bottombar-h);
  }

  /* No sidebar or hamburger on mobile */
  #ks-sidebar,
  #ks-menu-toggle {
    display: none;
  }

  /* Top bar: no left padding gap where hamburger would be */
  #ks-topbar {
    padding-left: var(--space-4);
  }
}


/* ── MORE SHEET (mobile only) ───────────────────────────────── */
#ks-more-backdrop {
  position: fixed;
  top: 0; left: 0; right: 0;
  bottom: var(--ks-bottombar-h);
  z-index: 298;
  background: rgba(0, 0, 0, 0.4);
  opacity: 0;
  pointer-events: none;
  transition: opacity 240ms ease;
}
#ks-more-backdrop.ks-open {
  opacity: 1;
  pointer-events: auto;
}

#ks-more-sheet {
  position: fixed;
  bottom: var(--ks-bottombar-h);
  left: 0; right: 0;
  z-index: 299;
  background: var(--color-surface);
  border-radius: 20px 20px 0 0;
  border-top: 1px solid var(--color-border);
  box-shadow: 0 -4px 32px rgba(0, 0, 0, 0.12);
  max-height: 65vh;
  overflow-y: auto;
  transform: translateY(calc(100% + var(--ks-bottombar-h)));
  transition: transform 240ms cubic-bezier(0.4, 0, 0.2, 1);
}
#ks-more-sheet.ks-open {
  transform: translateY(0);
}

#ks-more-handle {
  width: 36px;
  height: 4px;
  background: var(--color-border);
  border-radius: 2px;
  margin: 12px auto 0;
}

#ks-more-title {
  font-family: var(--font-heading);
  font-size: var(--text-xs);
  font-weight: 700;
  color: var(--color-text-muted);
  letter-spacing: 0.06em;
  text-transform: uppercase;
  text-align: center;
  padding: 10px var(--space-4) var(--space-2);
}

#ks-more-apps {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  padding: var(--space-2) var(--space-2) var(--space-6);
  gap: var(--space-1);
}

.ks-more-app {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: flex-start;
  gap: var(--space-2);
  padding: var(--space-3) var(--space-2);
  border-radius: var(--radius-md);
  text-decoration: none;
  color: var(--color-text-secondary);
  font-family: var(--font-body);
  font-size: 11px;
  font-weight: 600;
  line-height: 1.2;
  text-align: center;
  transition: background 150ms ease, color 150ms ease;
  -webkit-tap-highlight-color: transparent;
}
.ks-more-app:hover,
.ks-more-app:active {
  background: var(--color-surface-subtle);
  color: var(--color-text-primary);
}

.ks-more-app-icon {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 44px;
  height: 44px;
  border-radius: var(--radius-md);
  background: var(--color-surface-subtle);
  color: var(--color-accent);
  flex-shrink: 0;
  transition: background 150ms ease;
}
.ks-more-app:hover .ks-more-app-icon,
.ks-more-app:active .ks-more-app-icon {
  background: var(--color-accent-subtle);
}

.ks-more-app-label {
  word-break: break-word;
  hyphens: auto;
}

@media (min-width: 768px) {
  #ks-more-backdrop,
  #ks-more-sheet { display: none; }
}
