/* ============================================================
   Panda Books — ABS-style design system (Variant A)
   Structure/UX inspired by Audiobookshelf, warm Panda palette.
   Shared tokens + components for the new cabinet:
   app shell, home shelves, library grid, persistent player.
   Consumed by: frontend/app/cabinet/preview/ (and, from phase 2,
   the live cabinet). See docs/MASTERPLAN_abs_ui.md.
   ============================================================ */

:root {
  /* palette — aligned with the existing cabinet tokens */
  --bg:          #FBF7EF;
  --bg-card:     #FFFDF8;
  --bg-hover:    rgba(94,122,82,0.08);
  --sage:        #5E7A52;
  --sage-light:  #7A9E6E;
  --accent-soft: rgba(94,122,82,0.14);
  --text:        #2C2416;
  --text-muted:  #7A6B52;
  --text-dim:    #B5A48A;
  --border:      #E8DCC8;
  --on-accent:   #FFFFFF;
  --f-display:   'Lora', Georgia, serif;
  --f-body:      'Nunito', system-ui, sans-serif;
  --shadow:      0 8px 30px rgba(44,36,22,0.12);
  --shadow-sm:   0 2px 10px rgba(44,36,22,0.08);

  /* layout metrics */
  --appbar-h:    60px;
  --player-h:    140px;
  --cover-w:     148px;
}

/* ============================ SHELL ============================ */
.app {
  display: grid;
  grid-template-columns: 240px 1fr;
  grid-template-rows: var(--appbar-h) 1fr;
  grid-template-areas:
    "sidebar appbar"
    "sidebar content";
  min-height: 100dvh;
  overflow: hidden;
}

/* --- Appbar --- */
.appbar {
  grid-area: appbar;
  display: flex; align-items: center; gap: 14px;
  padding: 0 18px;
  background: var(--bg-card);
  border-bottom: 1px solid var(--border);
  position: sticky; top: 0; z-index: 40;
}
.brand { display: flex; align-items: center; gap: 10px; font-family: var(--f-display); font-weight: 700; font-size: 1.05rem; color: var(--text); text-decoration: none; }
.brand .logo {
  width: 34px; height: 34px; border-radius: 9px; flex-shrink: 0;
  background: linear-gradient(135deg, var(--sage), var(--sage-light));
  display: flex; align-items: center; justify-content: center; color: var(--on-accent); font-size: 1.1rem;
}
.brand span { color: var(--sage); }
.search {
  flex: 1; max-width: 520px; margin: 0 auto;
  display: flex; align-items: center; gap: 8px;
  background: var(--bg); border: 1px solid var(--border); border-radius: 999px;
  padding: 8px 14px; color: var(--text-muted);
}
.search input { border: none; background: transparent; outline: none; color: var(--text); flex: 1; font-size: .92rem; }
.appbar-right { display: flex; align-items: center; gap: 12px; margin-left: auto; }
.chip {
  display: inline-flex; align-items: center; gap: 6px;
  background: var(--accent-soft); color: var(--sage);
  border: none; border-radius: 999px; padding: 7px 13px; font-weight: 700; font-size: .85rem;
}
.icon-btn {
  width: 38px; height: 38px; border-radius: 10px; border: 1px solid var(--border);
  background: var(--bg); display: inline-flex; align-items: center; justify-content: center;
}
.icon-btn:hover { background: var(--bg-hover); }
.avatar {
  width: 38px; height: 38px; border-radius: 50%; flex-shrink: 0;
  background: linear-gradient(135deg, var(--sage), var(--sage-light));
  color: var(--on-accent); display: flex; align-items: center; justify-content: center; font-weight: 800;
}

/* --- Sidebar --- */
.sidebar {
  grid-area: sidebar;
  background: var(--bg-card);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  gap: 6px;
  padding: 20px 14px;
  z-index: 45;
  overflow-y: auto;
}
/* Brand row at the top of the sidebar (desktop only — the mobile bottom
   tab bar has no room for it). */
.sidebar-brand {
  display: flex; align-items: center; gap: 10px;
  padding: 4px 10px 16px;
  font-family: var(--f-display); font-weight: 700; font-size: 1.02rem;
  color: var(--text); text-decoration: none;
}
.sidebar-brand .logo {
  width: 34px; height: 34px; border-radius: 9px; flex-shrink: 0;
  background: linear-gradient(135deg, var(--sage), var(--sage-light));
  display: flex; align-items: center; justify-content: center;
  color: var(--on-accent); font-size: 1.1rem;
}
/* Profile entry pinned to the bottom of the sidebar (desktop only). */
.sidebar-profile {
  display: flex; align-items: center; gap: 10px;
  margin-top: 4px;
  padding: 10px 12px;
  border: none; border-radius: 12px;
  background: var(--bg); cursor: pointer;
  font-family: var(--f-body); text-align: left; width: 100%;
}
.sidebar-profile:hover { background: var(--bg-hover); }
.sidebar-profile .avatar { width: 34px; height: 34px; font-size: .9rem; }
.sidebar-profile .who { min-width: 0; }
.sidebar-profile .who .name {
  font-weight: 800; font-size: .88rem; color: var(--text);
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.sidebar-profile .who .sub { font-size: .74rem; color: var(--text-muted); }
/* Plain-link nav items (e.g. a sidebar entry that navigates to another
   page rather than switching an in-page tab) share the button styling. */
.sidebar a.nav-item {
  display: flex; align-items: center; justify-content: flex-start; gap: 12px;
  padding: 12px 16px; border-radius: 12px;
  color: var(--text-muted); font-size: .92rem; font-weight: 700;
  font-family: var(--f-body); text-decoration: none;
  transition: background .15s, color .15s;
}
.sidebar a.nav-item svg { width: 22px; height: 22px; flex-shrink: 0; }
.sidebar a.nav-item:hover { background: var(--bg-hover); color: var(--text); }
.sidebar a.nav-item.active { color: var(--sage); background: var(--accent-soft); }
.sidebar button {
  display: flex;
  align-items: center;
  justify-content: flex-start;
  gap: 12px;
  padding: 12px 16px;
  border-radius: 12px;
  border: none;
  background: none;
  color: var(--text-muted);
  font-size: .92rem;
  font-weight: 700;
  font-family: var(--f-body);
  width: 100%;
  cursor: pointer;
  transition: background 0.15s, color 0.15s;
}
.sidebar button svg { width: 22px; height: 22px; flex-shrink: 0; }
.sidebar button:hover { background: var(--bg-hover); color: var(--text); }
.sidebar button.active { color: var(--sage); background: var(--accent-soft); }

/* --- Content --- */
.content { grid-area: content; overflow-y: auto; height: calc(100dvh - var(--appbar-h)); padding-bottom: var(--player-h); }
.view { display: none; padding: 26px 30px; }
.view.active { display: block; animation: abs-fade .25s ease; }
@keyframes abs-fade { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }
.view-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 18px; flex-wrap: wrap; gap: 10px; }
.view-head h1 { font-family: var(--f-display); font-size: 1.5rem; font-weight: 700; }
.view-head .sub { color: var(--text-muted); font-size: .9rem; }

/* --- Shelves (Home) --- */
.shelf { margin-bottom: 30px; }
.shelf-head { display: flex; align-items: baseline; justify-content: space-between; margin-bottom: 12px; }
.shelf-head h2 { font-family: var(--f-display); font-size: 1.12rem; font-weight: 600; }
.shelf-head a { color: var(--sage); font-size: .82rem; font-weight: 700; text-decoration: none; }
.shelf-track {
  display: grid; grid-auto-flow: column; grid-auto-columns: 158px;
  gap: 18px; overflow-x: auto; padding-bottom: 8px; scroll-snap-type: x proximity;
}
.shelf-track::-webkit-scrollbar { height: 6px; }

/* --- Cover card --- */
.card { scroll-snap-align: start; cursor: pointer; }
.cover {
  position: relative; width: 100%; aspect-ratio: 2/3; border-radius: 12px; overflow: hidden;
  box-shadow: var(--shadow-sm); display: flex; align-items: flex-end;
  transition: transform .18s ease, box-shadow .18s ease;
}
.card:hover .cover { transform: translateY(-4px); box-shadow: var(--shadow); }
.cover .cover-title {
  position: relative; z-index: 2; padding: 12px; color: #fff; font-family: var(--f-display);
  font-weight: 700; font-size: .95rem; line-height: 1.2; text-shadow: 0 1px 4px rgba(0,0,0,.5);
}
.cover .play-overlay {
  position: absolute; inset: 0; z-index: 3; display: flex; align-items: center; justify-content: center;
  background: rgba(0,0,0,.28); opacity: 0; transition: opacity .18s ease;
}
.card:hover .cover .play-overlay { opacity: 1; }
.play-overlay .circle {
  width: 52px; height: 52px; border-radius: 50%; background: var(--sage); color: var(--on-accent);
  display: flex; align-items: center; justify-content: center; box-shadow: 0 4px 14px rgba(0,0,0,.4);
}
.cover .progress { position: absolute; left: 0; right: 0; bottom: 0; height: 4px; z-index: 4; background: rgba(0,0,0,.35); }
.cover .progress > i { display: block; height: 100%; background: var(--sage-light); }
.card .meta { padding: 8px 2px 0; }
.card .meta .t { font-weight: 700; font-size: .86rem; line-height: 1.25; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.card .meta .a { color: var(--text-muted); font-size: .76rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* --- Library grid --- */
.grid {
  display: grid; gap: 22px;
  grid-template-columns: repeat(auto-fill, minmax(var(--cover-w), 1fr));
}
.toolbar { display: flex; align-items: center; gap: 14px; }
.toolbar .seg { display: flex; background: var(--bg-card); border: 1px solid var(--border); border-radius: 10px; overflow: hidden; }
.toolbar .seg button { padding: 7px 12px; border: none; background: none; color: var(--text-muted); font-weight: 700; font-size: .8rem; font-family: var(--f-body); }
.toolbar .seg button.active { background: var(--accent-soft); color: var(--sage); }
.range { display: flex; align-items: center; gap: 8px; color: var(--text-muted); font-size: .8rem; }
.range input { accent-color: var(--sage); }

/* --- Placeholder panels --- */
.panel { background: var(--bg-card); border: 1px solid var(--border); border-radius: 16px; padding: 28px; color: var(--text-muted); }
.panel h3 { font-family: var(--f-display); color: var(--text); margin-bottom: 8px; }

/* ============================ PLAYER ============================ */
.player {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 60;
  background: var(--bg-card); border-top: 1px solid var(--border);
  box-shadow: 0 -6px 30px rgba(0,0,0,.14);
  transform: translateY(110%); transition: transform .3s cubic-bezier(.2,.7,.3,1);
  padding-bottom: env(safe-area-inset-bottom, 0px);
}
.player.show { transform: none; }
.player-seek { display: flex; align-items: center; gap: 10px; padding: 8px 18px 0; }
.player-seek .time { font-variant-numeric: tabular-nums; font-size: .72rem; color: var(--text-muted); width: 42px; text-align: center; }
.player-seek input[type=range] { flex: 1; accent-color: var(--sage); height: 4px; }
.player-body { display: grid; grid-template-columns: minmax(0,1fr) auto minmax(0,1fr); align-items: center; gap: 14px; padding: 6px 18px 12px; }
.now { display: flex; align-items: center; gap: 12px; min-width: 0; }
.now .mini-cover { width: 48px; height: 48px; border-radius: 8px; flex-shrink: 0; box-shadow: var(--shadow-sm); }
.now .txt { min-width: 0; }
.now .txt .t { font-weight: 800; font-size: .9rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.now .txt .s { color: var(--text-muted); font-size: .76rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.transport { display: flex; align-items: center; gap: 10px; justify-self: center; }
.transport button { width: 40px; height: 40px; border-radius: 50%; border: none; background: none; display: flex; align-items: center; justify-content: center; color: var(--text); }
.transport button:hover { background: var(--bg-hover); }
.transport .play { width: 50px; height: 50px; background: var(--sage); color: var(--on-accent); box-shadow: var(--shadow-sm); }
.transport .play:hover { background: var(--sage-light); }
.player-extra { display: flex; align-items: center; gap: 6px; justify-content: flex-end; }
.pill {
  display: inline-flex; align-items: center; gap: 6px; border: 1px solid var(--border); background: var(--bg);
  border-radius: 999px; padding: 6px 11px; font-weight: 700; font-size: .78rem; color: var(--text-muted); font-family: var(--f-body);
}
.pill:hover { color: var(--text); border-color: var(--sage); }
.pill.on { color: var(--sage); border-color: var(--sage); background: var(--accent-soft); }

/* popover menus (chapters / speed / sleep) */
.pop {
  position: fixed; z-index: 70; background: var(--bg-card); border: 1px solid var(--border);
  border-radius: 14px; box-shadow: var(--shadow); padding: 8px; min-width: 180px; display: none;
}
.pop.show { display: block; }
.pop .opt {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 9px 12px; border-radius: 9px; font-size: .85rem; font-weight: 600;
}
.pop .opt:hover { background: var(--bg-hover); }
.pop .opt.active { color: var(--sage); background: var(--accent-soft); }
.pop .pop-title { font-size: .7rem; text-transform: uppercase; letter-spacing: .08em; color: var(--text-dim); padding: 4px 12px 6px; font-weight: 800; }
.chapter-list { max-height: 320px; overflow-y: auto; }

/* ============================ RESPONSIVE ============================ */
/* On desktop the sidebar already shows the brand (.sidebar-brand) and the
   profile card (.sidebar-profile) at all times, so the appbar's copies of
   the same info are pure duplication — only needed on mobile, where the
   sidebar collapses into a bottom tab bar with no room for either.
   Scoped to shells that actually have .sidebar-brand: the standalone
   frontend/app/cabinet/preview/ demo uses a bare .rail with no sidebar
   brand/profile, so its appbar brand/avatar/balance are its only copy
   and must stay visible at every width. */
@media (min-width: 821px) {
  .app:has(.sidebar-brand) .appbar .brand,
  .app:has(.sidebar-brand) .appbar-right { display: none; }
}
@media (max-width: 820px) {
  .app {
    grid-template-columns: 1fr;
    grid-template-rows: var(--appbar-h) 1fr auto;
    grid-template-areas:
      "appbar"
      "content"
      "sidebar";
    overflow: visible;
  }
  .brand span { display: none; }
  .search { margin: 0; max-width: none; }
  .chip { display: none; }
  .view { padding: 18px 16px; }
  .view-head h1 { font-size: 1.25rem; }
  .content { padding-bottom: 132px; overflow-y: visible; height: auto; }
  .sidebar {
    position: fixed;
    bottom: 0; left: 0; right: 0;
    flex-direction: row;
    border-right: none;
    border-top: 1px solid var(--border);
    padding: 0;
    gap: 0;
    z-index: 55;
    background: var(--bg-card);
    justify-content: flex-start;
    overflow-x: auto;
    padding-bottom: env(safe-area-inset-bottom, 0px);
  }
  .sidebar button {
    flex: 1;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 3px;
    padding: 9px 0;
    border-radius: 0;
    font-size: .64rem;
    font-weight: 700;
  }
  .sidebar button svg { width: 21px; height: 21px; margin: 0; }
  .sidebar a.nav-item {
    flex: 1; flex-direction: column; align-items: center; justify-content: center;
    gap: 3px; padding: 9px 0; border-radius: 0; font-size: .64rem; font-weight: 700;
  }
  .sidebar a.nav-item svg { width: 21px; height: 21px; }
  /* .sidebar-profile is a <button>, so this must outrank the base
     `.sidebar button { display:flex }` (0-1-1) — hence the qualified form. */
  .sidebar-brand, .sidebar button.sidebar-profile { display: none; }
  .player { bottom: 0; }
  .player-extra .pill span.lbl { display: none; }
  .player-body { grid-template-columns: minmax(0,1fr) auto; gap: 10px; }
  .player-extra { grid-column: 1 / -1; justify-content: space-between; }
}
