/**
 * library.css
 *
 * Styles for library.html — Contract to Cradle Resource Library.
 * Scoped under body.lib-page so tokens never bleed into other pages.
 * Load order: style.css first, then this file.
 */

/* ── Design tokens ──────────────────────────────────────────────────────── */
body.lib-page {
  --sage:       #4A7C5E;
  --sage-dark:  #36614A;
  --sage-light: #E8F2EC;
  --sage-muted: #C4D9CB;
  --ink:        #1a1714;
  --ink-muted:  #6b6459;
  --ink-faint:  #9e958a;
  --surface:    #f8f6f2;
  --white:      #ffffff;
  --border:     #e4ddd4;
  --warm:       #B8855A;
  --warm-light: #f5ede0;
  --red:        #c0392b;
  --radius:     8px;
  --sidebar-w:  268px;

  background: var(--surface);
}

/* ── Loading / gate screens ─────────────────────────────────────────────── */
body.lib-page #loading-screen {
  position: fixed; inset: 0;
  display: flex; flex-direction: column;
  align-items: center; justify-content: center;
  background: var(--surface); z-index: 100; gap: 16px;
}

body.lib-page .loading-dots { display: flex; gap: 8px; }

body.lib-page .dot {
  width: 8px; height: 8px; border-radius: 50%;
  background: var(--sage); animation: libPulse 1.2s ease-in-out infinite;
}
body.lib-page .dot:nth-child(2) { animation-delay: .2s; }
body.lib-page .dot:nth-child(3) { animation-delay: .4s; }

@keyframes libPulse {
  0%, 80%, 100% { opacity: .3; transform: scale(.8); }
  40%           { opacity: 1;  transform: scale(1); }
}

/* Gate card */
body.lib-page #gate-screen {
  display: none;
  min-height: 100vh;
  align-items: center; justify-content: center;
  padding: 24px;
}

body.lib-page .gate-card {
  background: var(--white);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 48px 40px;
  max-width: 500px;
  width: 100%;
  text-align: center;
  position: relative;
  overflow: hidden;
}

body.lib-page .gate-card::before {
  content: "";
  position: absolute;
  top: 0; left: 0; right: 0; height: 4px;
  background: linear-gradient(90deg, var(--warm), var(--sage));
}

body.lib-page .gate-eyebrow {
  font-size: .7rem; font-weight: 600;
  letter-spacing: .14em; text-transform: uppercase;
  color: var(--sage); margin-bottom: 12px;
}

body.lib-page .gate-title {
  font-family: 'Cormorant Garamond', serif;
  font-size: 2rem; font-weight: 600;
  color: var(--ink); margin-bottom: 10px; line-height: 1.2;
}

body.lib-page .gate-sub {
  font-size: .9rem; color: var(--ink-muted);
  line-height: 1.65; margin-bottom: 20px;
}

body.lib-page .gate-contents {
  background: var(--sage-light);
  border-radius: var(--radius);
  padding: 16px 20px; margin: 0 0 24px; text-align: left;
}

body.lib-page .gate-contents-label {
  font-size: .72rem; font-weight: 600;
  text-transform: uppercase; letter-spacing: .1em;
  color: var(--sage-dark); margin-bottom: 10px;
}

body.lib-page .gate-contents-grid {
  display: grid; grid-template-columns: 1fr 1fr; gap: 5px 16px;
}

body.lib-page .gate-contents-item {
  font-size: .82rem; color: var(--ink-muted);
  padding-left: 14px; position: relative; line-height: 1.45;
}
body.lib-page .gate-contents-item::before {
  content: "—"; position: absolute; left: 0; color: var(--sage);
}

body.lib-page .gate-price {
  font-family: 'Cormorant Garamond', serif;
  font-size: 2.4rem; font-weight: 600; color: var(--ink);
}
body.lib-page .gate-price-note {
  font-size: .8rem; color: var(--ink-faint); margin: 4px 0 24px;
  line-height: 1.5;
}

body.lib-page .btn-buy {
  display: block; width: 100%;
  background: var(--sage); color: var(--white);
  border: none; border-radius: var(--radius);
  padding: 14px 24px; font-size: .95rem;
  font-family: 'Figtree', sans-serif; font-weight: 500;
  cursor: pointer; transition: opacity .2s; margin-bottom: 12px;
}
body.lib-page .btn-buy:hover    { opacity: .88; }
body.lib-page .btn-buy:disabled { opacity: .5; cursor: not-allowed; }

body.lib-page .btn-signin {
  display: block; font-size: .82rem; color: var(--ink-muted);
  text-decoration: none; padding: 8px;
}
body.lib-page .btn-signin:hover { color: var(--sage); }

body.lib-page #gate-error {
  margin-top: 16px; font-size: .85rem; color: var(--red); display: none;
}

/* ── App shell ──────────────────────────────────────────────────────────── */
body.lib-page #app { display: none; min-height: 100vh; }

/* Top nav */
body.lib-page .top-nav {
  position: sticky; top: 0; z-index: 40;
  background: var(--white); border-bottom: 1px solid var(--border);
  padding: 0 24px; height: 56px;
  display: flex; align-items: center; justify-content: space-between;
}

body.lib-page .nav-right  { display: flex; align-items: center; gap: 16px; }
body.lib-page .nav-email  { font-size: .8rem; color: var(--ink-faint); }
body.lib-page .btn-signout {
  font-size: .8rem; color: var(--ink-muted);
  background: none; border: 1px solid var(--border);
  border-radius: 6px; padding: 5px 12px; cursor: pointer;
  font-family: 'Figtree', sans-serif; transition: border-color .2s;
}
body.lib-page .btn-signout:hover { border-color: var(--sage); color: var(--sage); }

body.lib-page .menu-toggle {
  display: none; background: none; border: none;
  cursor: pointer; padding: 4px; color: var(--ink);
}

/* Body layout */
body.lib-page .app-body { display: flex; min-height: calc(100vh - 56px); }

/* ── Sidebar ──────────────────────────────────────────────────────────────*/
body.lib-page .sidebar {
  width: var(--sidebar-w); min-width: var(--sidebar-w);
  background: var(--white); border-right: 1px solid var(--border);
  padding: 24px 0;
  position: sticky; top: 56px;
  height: calc(100vh - 56px); overflow-y: auto;
  display: flex; flex-direction: column;
  flex-shrink: 0;
}

body.lib-page .sidebar-label {
  font-size: .65rem; font-weight: 600; letter-spacing: .14em;
  text-transform: uppercase; color: var(--ink-faint);
  padding: 0 20px; margin-bottom: 16px;
  flex-shrink: 0;
}

/* ── Sidebar nav tree ─────────────────────────────────────────────────────
   Uses <div id="lib-nav">, not <nav>, to prevent style.css global
   nav { position:sticky; height:60px; display:flex } from applying.      */

body.lib-page #lib-nav {
  flex: 1;
  overflow-y: auto;
  /* Explicit resets — guard against any global nav rule bleeding in */
  display: block;
  position: static;
  height: auto;
  min-height: 0;
  background: none;
  border: none;
  backdrop-filter: none;
  padding: 0;
  margin: 0;
}

/* Section groups */
body.lib-page .nav-section { margin-bottom: 2px; }

body.lib-page .nav-section-header {
  width: 100%; text-align: left; background: none; border: none;
  cursor: pointer; padding: 8px 20px;
  display: flex; align-items: center; justify-content: space-between;
  font-family: 'Figtree', sans-serif;
  font-size: .72rem; font-weight: 700;
  letter-spacing: .1em; text-transform: uppercase;
  color: var(--ink-faint);
  transition: color .15s;
  /* Reset any height/position that could bleed from global nav or button rules */
  height: auto; min-height: unset;
  position: static;
  border-bottom: none;
  backdrop-filter: none;
  line-height: 1.4;
}
body.lib-page .nav-section-header:hover { color: var(--sage); background: none; }
body.lib-page .nav-section-header.active { color: var(--sage); }

body.lib-page .nav-section-chevron {
  font-size: .75rem; transition: transform .2s; flex-shrink: 0;
}
body.lib-page .nav-section.open .nav-section-chevron { transform: rotate(90deg); }

body.lib-page .nav-section-items { display: none; }
body.lib-page .nav-section.open .nav-section-items { display: block; }

/* Active indicator on the item wrapper, not the button, for clean alignment */
body.lib-page .nav-item {
  border-left: 3px solid transparent;
  transition: border-color .15s;
}
body.lib-page .nav-item.active {
  border-left-color: var(--sage);
  background: var(--sage-light);
}

body.lib-page .nav-item button {
  width: 100%; text-align: left; background: none; border: none; cursor: pointer;
  padding: 7px 16px 7px 25px;
  display: block;
  font-family: 'Figtree', sans-serif; font-size: .82rem; color: var(--ink-muted);
  transition: background .15s, color .15s;
  line-height: 1.4; white-space: normal;
  /* Explicit resets */
  height: auto; min-height: unset;
  position: static;
  border-bottom: none;
  backdrop-filter: none;
}
body.lib-page .nav-item button:hover { background: var(--sage-light); color: var(--ink); }
body.lib-page .nav-item.active button { color: var(--sage); font-weight: 600; }

body.lib-page .nav-item-icon { font-size: .82rem; opacity: .6; flex-shrink: 0; }

/* ── Content area ──────────────────────────────────────────────────────── */
body.lib-page .content-area {
  flex: 1; padding: 36px 48px; max-width: 860px; min-width: 0;
}

/* ── Page header ────────────────────────────────────────────────────────── */
body.lib-page .page-header { margin-bottom: 28px; padding-bottom: 20px; border-bottom: 1px solid var(--border); }

body.lib-page .page-eyebrow {
  font-size: .68rem; font-weight: 600; letter-spacing: .14em;
  text-transform: uppercase; color: var(--sage); margin-bottom: 8px;
}

body.lib-page .page-title {
  font-family: 'Cormorant Garamond', serif;
  font-size: 2rem; font-weight: 600; color: var(--ink);
  line-height: 1.2; margin-bottom: 8px;
}

body.lib-page .page-desc {
  font-size: .92rem; color: var(--ink-muted); line-height: 1.65; max-width: 660px;
}

/* ── Section heading ────────────────────────────────────────────────────── */
body.lib-page .section-head {
  font-family: 'Cormorant Garamond', serif; font-size: 1.1rem; font-weight: 600;
  color: var(--ink); margin: 28px 0 14px; padding-bottom: 8px;
  border-bottom: 1px solid var(--border);
}

/* ── Card grid (home page) ─────────────────────────────────────────────── */
body.lib-page .section-grid {
  display: grid; grid-template-columns: repeat(2, 1fr); gap: 14px; margin-bottom: 32px;
}

body.lib-page .section-card {
  background: var(--white); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 20px;
  cursor: pointer; transition: box-shadow .15s, border-color .15s;
  text-align: left;
}
body.lib-page .section-card:hover {
  border-color: var(--sage); box-shadow: 0 4px 16px rgba(26,23,20,.07);
}

body.lib-page .section-card-icon { font-size: 1.2rem; margin-bottom: 8px; display: block; }
body.lib-page .section-card-title {
  font-size: .9rem; font-weight: 600; color: var(--ink); margin-bottom: 4px;
}
body.lib-page .section-card-count {
  font-size: .75rem; color: var(--ink-faint);
}

/* ── Issue router (home page) ──────────────────────────────────────────── */
body.lib-page .issue-router {
  background: var(--sage-light); border: 1px solid var(--sage-muted);
  border-radius: var(--radius); padding: 20px 24px; margin-bottom: 32px;
}

body.lib-page .issue-router-label {
  font-size: .72rem; font-weight: 700; letter-spacing: .1em;
  text-transform: uppercase; color: var(--sage-dark); margin-bottom: 14px;
}

body.lib-page .issue-buttons {
  display: flex; flex-wrap: wrap; gap: 8px;
}

body.lib-page .issue-btn {
  padding: 8px 16px; background: var(--white);
  border: 1px solid var(--sage-muted); border-radius: 20px;
  font-size: .82rem; color: var(--ink-muted);
  cursor: pointer; font-family: 'Figtree', sans-serif;
  transition: all .15s;
}
body.lib-page .issue-btn:hover {
  background: var(--sage); border-color: var(--sage); color: var(--white);
}

/* ── Content item list (scenario guides, clauses, etc.) ────────────────── */
body.lib-page .content-list { display: flex; flex-direction: column; gap: 10px; }

body.lib-page .content-item {
  background: var(--white); border: 1px solid var(--border);
  border-radius: var(--radius); overflow: hidden;
}

body.lib-page .content-item-header {
  width: 100%; text-align: left; background: none; border: none;
  padding: 16px 20px; cursor: pointer;
  display: flex; align-items: center; gap: 14px;
  font-family: 'Figtree', sans-serif; transition: background .15s;
}
body.lib-page .content-item-header:hover { background: var(--sage-light); }

body.lib-page .content-item-num {
  font-size: .72rem; font-weight: 700; color: var(--ink-faint);
  min-width: 22px; flex-shrink: 0;
}

body.lib-page .content-item-title {
  font-size: .9rem; font-weight: 600; color: var(--ink); flex: 1; text-align: left;
  line-height: 1.3;
}

body.lib-page .content-item-chevron {
  color: var(--ink-faint); font-size: .88rem; transition: transform .2s;
}
body.lib-page .content-item.open .content-item-chevron { transform: rotate(90deg); }

body.lib-page .content-item-body {
  display: none; padding: 0 20px 20px 56px; font-size: .87rem;
  color: var(--ink-muted); line-height: 1.7;
}
body.lib-page .content-item.open .content-item-body { display: block; }

/* Sub-sections within a content item */
body.lib-page .item-section { margin-bottom: 16px; }
body.lib-page .item-section-label {
  font-size: .68rem; font-weight: 700; letter-spacing: .1em;
  text-transform: uppercase; color: var(--sage); margin-bottom: 6px;
}
body.lib-page .item-section-body {
  font-size: .86rem; color: var(--ink-muted); line-height: 1.65;
}

body.lib-page .item-callout {
  background: var(--sage-light); border-left: 3px solid var(--sage);
  border-radius: 4px; padding: 12px 16px;
  font-size: .84rem; color: var(--ink); line-height: 1.6;
  margin-top: 8px; font-style: italic;
}

/* Tagged list */
body.lib-page .tag-list { list-style: none; display: flex; flex-direction: column; gap: 5px; }
body.lib-page .tag-list li {
  font-size: .84rem; color: var(--ink-muted);
  padding-left: 16px; position: relative; line-height: 1.45;
}
body.lib-page .tag-list li::before { content: "—"; position: absolute; left: 0; color: var(--sage); }

/* ── Template tone tabs ─────────────────────────────────────────────────── */
body.lib-page .tone-tabs { display: flex; gap: 6px; margin: 14px 0 12px; flex-wrap: wrap; }
body.lib-page .tone-tab {
  padding: 5px 14px; border-radius: 20px; border: 1px solid var(--border);
  background: none; font-size: .78rem; color: var(--ink-muted);
  cursor: pointer; font-family: 'Figtree', sans-serif; transition: all .15s;
}
body.lib-page .tone-tab:hover { border-color: var(--sage); color: var(--sage); }
body.lib-page .tone-tab.active { background: var(--sage); border-color: var(--sage); color: var(--white); }

body.lib-page .template-block { display: none; }
body.lib-page .template-block.active { display: block; }

body.lib-page .template-subject {
  font-size: .78rem; font-weight: 600; color: var(--ink-faint); margin-bottom: 8px;
}
body.lib-page .template-subject span { color: var(--ink); }

body.lib-page .template-body-text {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 14px 16px; font-size: .84rem; line-height: 1.75; color: var(--ink);
  white-space: pre-wrap; font-family: 'Figtree', sans-serif;
}

body.lib-page .btn-copy {
  display: inline-flex; align-items: center; gap: 6px; padding: 7px 14px;
  background: var(--sage); border: none; border-radius: var(--radius);
  font-size: .8rem; color: var(--white); cursor: pointer;
  font-family: 'Figtree', sans-serif; transition: opacity .2s; margin-top: 10px;
}
body.lib-page .btn-copy:hover  { opacity: .88; }
body.lib-page .btn-copy.copied { background: #27735e; }

/* ── Info box / callout ─────────────────────────────────────────────────── */
body.lib-page .info-box {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 14px 18px;
  font-size: .84rem; color: var(--ink-muted); line-height: 1.65;
  margin-bottom: 20px;
}
body.lib-page .info-box strong { color: var(--ink); }

body.lib-page .warn-box {
  background: #fff8f0; border: 1px solid #e8c99a;
  border-radius: var(--radius); padding: 14px 18px;
  font-size: .84rem; color: var(--ink-muted); line-height: 1.65;
  margin-bottom: 20px;
}

/* ── Related resources footer ───────────────────────────────────────────── */
body.lib-page .related-box {
  background: var(--sage-light); border: 1px solid var(--sage-muted);
  border-radius: var(--radius); padding: 16px 20px; margin-top: 24px;
}
body.lib-page .related-label {
  font-size: .68rem; font-weight: 700; letter-spacing: .1em;
  text-transform: uppercase; color: var(--sage-dark); margin-bottom: 10px;
}
body.lib-page .related-links { display: flex; flex-wrap: wrap; gap: 8px; }
body.lib-page .related-link {
  font-size: .82rem; color: var(--sage); text-decoration: none;
  background: var(--white); border: 1px solid var(--sage-muted);
  border-radius: 20px; padding: 5px 14px; transition: all .15s;
}
body.lib-page .related-link:hover { background: var(--sage); color: var(--white); }

/* ── Tracker/worksheet item ─────────────────────────────────────────────── */
body.lib-page .tracker-item {
  background: var(--white); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 20px 24px; margin-bottom: 10px;
}
body.lib-page .tracker-title {
  font-size: .9rem; font-weight: 600; color: var(--ink); margin-bottom: 4px;
}
body.lib-page .tracker-desc {
  font-size: .84rem; color: var(--ink-muted); line-height: 1.55; margin-bottom: 12px;
}
body.lib-page .tracker-columns {
  display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 12px;
}
body.lib-page .tracker-col-tag {
  font-size: .75rem; background: var(--surface); border: 1px solid var(--border);
  border-radius: 4px; padding: 3px 10px; color: var(--ink-muted);
}
body.lib-page .btn-tracker {
  display: inline-flex; align-items: center; gap: 6px; padding: 7px 14px;
  background: none; border: 1px solid var(--border); border-radius: var(--radius);
  font-size: .8rem; color: var(--ink-muted); cursor: pointer;
  font-family: 'Figtree', sans-serif; transition: all .2s;
}
body.lib-page .btn-tracker:hover { border-color: var(--sage); color: var(--sage); }

/* ── Updates badge ──────────────────────────────────────────────────────── */
body.lib-page .new-badge {
  display: inline-block; font-size: .65rem; font-weight: 700;
  letter-spacing: .08em; text-transform: uppercase;
  background: var(--sage); color: var(--white);
  border-radius: 3px; padding: 2px 7px; margin-left: 8px;
  vertical-align: middle;
}

/* ── Clause disclaimer footer ───────────────────────────────────────────── */
body.lib-page .clause-disclaimer {
  margin-top: 20px;
  padding: 12px 16px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-size: .78rem;
  color: var(--ink-faint);
  line-height: 1.6;
}

/* ── Responsive ─────────────────────────────────────────────────────────── */
@media (max-width: 768px) {
  body.lib-page .sidebar {
    position: fixed; top: 56px; left: -100%; width: 80%; max-width: 300px;
    height: calc(100vh - 56px); z-index: 30;
    transition: left .25s ease;
  }
  body.lib-page .sidebar.open { left: 0; box-shadow: 4px 0 20px rgba(0,0,0,.08); }
  body.lib-page .menu-toggle  { display: block; }
  body.lib-page .content-area { padding: 24px 20px; }
  body.lib-page .section-grid { grid-template-columns: 1fr; }
  body.lib-page .sidebar-overlay {
    display: none; position: fixed; inset: 0;
    background: rgba(0,0,0,.3); z-index: 25;
  }
  body.lib-page .sidebar-overlay.active { display: block; }
}

@media (max-width: 640px) {
  body.lib-page .gate-card { padding: 36px 24px; }
  body.lib-page .gate-contents-grid { grid-template-columns: 1fr; }
  body.lib-page .content-item-body { padding-left: 20px; }
}

main { display: block !important; }
