/* Living Atlas — production adaptation of Magic Patterns Concept A.
   Existing DOM, API behavior, and evidence semantics remain authoritative. */
:root {
  --atlas-shadow: 0 24px 70px rgba(59, 13, 22, .12);
  --atlas-radius: 24px;
  --atlas-line: rgba(59, 13, 22, .14);
  --atlas-white: #fffdf9;
}

html { scroll-behavior: smooth; }
body { overflow: hidden; background: var(--ivory-100); }
body::before,
body::after { content: ""; position: fixed; inset: 0; z-index: -2; pointer-events: none; }
body::before {
  background:
    radial-gradient(circle at 8% 8%, rgba(190, 137, 97, .16), transparent 23%),
    radial-gradient(circle at 88% 45%, rgba(183, 106, 120, .12), transparent 26%),
    linear-gradient(115deg, transparent 49.7%, rgba(59, 13, 22, .035) 50%, transparent 50.3%);
  background-size: auto, auto, 44px 44px;
}
body::after {
  z-index: -1;
  opacity: .2;
  background: repeating-radial-gradient(ellipse at 72% 18%, transparent 0 31px, rgba(59, 13, 22, .12) 32px 33px, transparent 34px 48px);
}

.skip-link { position: fixed; left: 18px; top: -72px; z-index: 100; padding: 12px 18px; border-radius: 999px; background: var(--charcoal-900); color: var(--atlas-white); }
.skip-link:focus { top: 14px; }

.app-shell { display: block; height: 100dvh; overflow: hidden; }
.main { height: 100dvh; padding-left: 96px; background: transparent; }
.main-header {
  position: relative;
  z-index: 20;
  height: 88px;
  padding: 0 42px 0 26px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  border-bottom: 1px solid var(--atlas-line);
  background: rgba(250, 247, 242, .9);
  backdrop-filter: blur(18px);
}
.header-home { display: flex; align-items: center; gap: 13px; color: var(--wine-900); text-align: left; }
.header-home img { width: 42px; height: 42px; border-radius: 9px; box-shadow: 0 8px 18px rgba(59, 13, 22, .18); }
.header-home strong { display: block; font: 600 24px/1 var(--font-display); letter-spacing: .04em; }
.header-home small { display: block; margin-top: 5px; color: var(--charcoal-500); font: 10px var(--font-body); letter-spacing: .18em; text-transform: uppercase; }
.atlas-coordinates { display: flex; align-items: center; gap: 18px; color: var(--charcoal-500); font-size: 10px; letter-spacing: .12em; text-transform: uppercase; }
.atlas-status { display: inline-flex; align-items: center; gap: 7px; padding: 8px 12px; border: 1px solid var(--atlas-line); border-radius: 999px; background: var(--atlas-white); }
.atlas-status i { width: 6px; height: 6px; border-radius: 50%; background: var(--copper); }
.icon-btn { display: none; }

/* A compact orbital dock expands for saved conversations and account controls. */
.sidebar {
  position: fixed;
  inset: 104px auto 20px 20px;
  z-index: 40;
  width: 70px;
  min-height: 0;
  padding: 10px 8px;
  gap: 4px;
  overflow-x: hidden;
  overflow-y: auto;
  border: 1px solid rgba(255, 253, 249, .16);
  border-radius: 35px;
  background: rgba(59, 13, 22, .97);
  box-shadow: var(--atlas-shadow);
  transition: width 180ms ease, border-radius 180ms ease, padding 180ms ease;
}
.sidebar::-webkit-scrollbar { width: 0; height: 0; }
.sidebar { scrollbar-width: none; }
.sidebar:hover,
.sidebar:focus-within { width: 286px; padding: 14px; overflow-y: auto; border-radius: 28px; }
.sidebar .brand { min-height: 48px; margin: 0 0 4px; padding: 3px 4px; gap: 12px; overflow: hidden; }
.sidebar .brand img { width: 38px; height: 38px; }
.sidebar .brand > div,
.sidebar .btn-new-chat b,
.sidebar .nav-label,
.sidebar .nav-section-label,
.sidebar #history-status,
.sidebar .chat-history-list,
.sidebar .sidebar-footer { opacity: 0; pointer-events: none; transition: opacity 100ms ease; }
.sidebar:not(:hover):not(:focus-within) .nav-section-label,
.sidebar:not(:hover):not(:focus-within) #history-status,
.sidebar:not(:hover):not(:focus-within) .chat-history-list,
.sidebar:not(:hover):not(:focus-within) .sidebar-footer { display: none; }
.sidebar:hover .brand > div,
.sidebar:focus-within .brand > div,
.sidebar:hover .btn-new-chat b,
.sidebar:focus-within .btn-new-chat b,
.sidebar:hover .nav-label,
.sidebar:focus-within .nav-label,
.sidebar:hover .nav-section-label,
.sidebar:focus-within .nav-section-label,
.sidebar:hover #history-status,
.sidebar:focus-within #history-status,
.sidebar:hover .chat-history-list,
.sidebar:focus-within .chat-history-list,
.sidebar:hover .sidebar-footer,
.sidebar:focus-within .sidebar-footer { opacity: 1; pointer-events: auto; }
.sidebar .brand-mark { font-size: 24px; }
.sidebar .btn-new-chat { flex: 0 0 auto; width: 52px; min-height: 48px; margin: 0; padding: 0 17px; gap: 12px; border-color: transparent; border-radius: 24px; white-space: nowrap; overflow: hidden; }
.sidebar:hover .btn-new-chat,
.sidebar:focus-within .btn-new-chat { width: 100%; border-color: rgba(250, 247, 242, .24); }
.sidebar .nav-section-label { margin: 9px 0 3px; }
.sidebar .nav-list { display: grid; gap: 3px; }
.sidebar .nav-item { min-height: 42px; padding: 0 14px; gap: 16px; border-radius: 24px; overflow: visible; }
.sidebar .nav-icon { width: 22px; flex: 0 0 22px; display: grid; place-items: center; font-size: 17px; }
.sidebar .nav-item.is-active { background: var(--atlas-white); color: var(--wine-900); }
.sidebar .chat-history-list { min-height: 40px; }
.sidebar .sidebar-footer { margin-top: auto; padding: 10px 8px 4px; }
.sidebar .sidebar-footer .wi-btn { color: var(--ivory-100); border-color: rgba(250, 247, 242, .3); }

.view { height: calc(100dvh - 88px); }
.section-page { height: 100%; overflow: auto; padding: 48px clamp(24px, 4vw, 60px) 80px; }
.section-page > * { width: min(1380px, 100%); margin-left: auto; margin-right: auto; }
.section-heading { align-items: end; margin-bottom: 36px; }
.section-heading h1 { color: var(--wine-900); font-size: clamp(42px, 6vw, 78px); line-height: .98; letter-spacing: -.045em; }
.section-heading .muted { max-width: 680px; font: 18px/1.5 var(--font-display); }
.eyebrow { display: flex; align-items: center; gap: 10px; color: var(--wine-500); font-size: 10px; font-weight: 700; letter-spacing: .18em; }
.eyebrow::before { content: ""; width: 32px; height: 1px; background: var(--copper); }

.home-scroll { height: calc(100dvh - 88px); padding: 48px clamp(24px, 4vw, 60px) 160px; }
.home-scroll > * { width: min(1380px, 100%); }
.home-hero { padding: 0 0 34px; }
.home-hero h1 { max-width: 980px; color: var(--wine-900); font-size: clamp(46px, 6.4vw, 88px); line-height: .96; letter-spacing: -.05em; }
.home-hero > p:last-child { max-width: 720px; color: var(--charcoal-700); font: clamp(18px, 2vw, 24px)/1.48 var(--font-display); }

.atlas-home-grid { display: grid; grid-template-columns: minmax(0, 1.5fr) minmax(300px, .78fr); grid-template-rows: auto auto; gap: 22px; margin-bottom: 22px; }
.sensory-world { grid-row: span 2; min-height: 590px; position: relative; overflow: hidden; isolation: isolate; padding: 42px 38px; border-radius: 132px 24px 24px 24px; background: var(--wine-900); color: var(--atlas-white); box-shadow: var(--atlas-shadow); }
.world-copy { position: relative; z-index: 4; max-width: 450px; }
.world-copy .eyebrow { color: var(--copper); }
.world-copy h2 { color: var(--atlas-white); font-size: clamp(38px, 4vw, 54px); line-height: 1; }
.world-copy p:not(.eyebrow) { color: rgba(255, 253, 249, .74); }
.atlas-light-button,
.atlas-dark-button { min-height: 44px; padding: 0 18px; border: 1px solid currentColor; border-radius: 999px; cursor: pointer; }
.atlas-light-button { background: var(--atlas-white); color: var(--wine-900); }
.atlas-dark-button { background: var(--wine-900); color: var(--atlas-white); }
.atlas-orbit { position: absolute; border: 1px solid rgba(250, 247, 242, .17); border-radius: 50%; animation: atlas-spin 22s linear infinite; }
.orbit-one { width: 520px; height: 350px; left: 14%; top: 29%; transform: rotate(-12deg); }
.orbit-two { width: 350px; height: 510px; right: 4%; top: 7%; animation-direction: reverse; animation-duration: 29s; }
@keyframes atlas-spin { to { transform: rotate(348deg); } }
.atlas-node { position: absolute; z-index: 3; width: var(--node-size); height: var(--node-size); display: grid; place-content: center; padding: 8px; border: 0; border-radius: 50%; background: var(--ivory-100); color: var(--wine-900); text-align: center; box-shadow: 0 0 0 10px rgba(250, 247, 242, .06); animation: atlas-float 5s ease-in-out infinite; }
.atlas-node strong { font: 500 14px/1.05 var(--font-display); text-transform: capitalize; }
.atlas-node small { display: block; margin-top: 5px; color: var(--charcoal-500); font-size: 9px; }
.atlas-node.n1 { --node-size: 118px; left: 17%; top: 49%; }
.atlas-node.n2 { --node-size: 92px; right: 14%; top: 29%; animation-delay: -1s; }
.atlas-node.n3 { --node-size: 100px; right: 25%; bottom: 10%; animation-delay: -2.2s; }
.atlas-node.n4 { --node-size: 76px; left: 48%; top: 40%; background: var(--copper); animation-delay: -3s; }
.atlas-node.n5 { --node-size: 82px; left: 8%; bottom: 7%; background: var(--wine-300); color: var(--atlas-white); animation-delay: -4s; }
.atlas-node.n5 small { color: rgba(255, 253, 249, .72); }
.atlas-node.is-open { border: 1px dashed var(--copper); background: transparent; color: var(--atlas-white); }
.atlas-node.is-open small { color: rgba(255, 253, 249, .7); }
@keyframes atlas-float { 50% { transform: translateY(-9px); } }

.home-module,
.catalog-row,
.metric-card,
.palate-summary,
.pairing-intro,
.insight-note,
.sensory-profile,
.loading-state,
.empty-state,
.error-state { border-color: var(--atlas-line); border-radius: var(--atlas-radius); background: rgba(255, 253, 249, .86); box-shadow: 0 12px 40px rgba(59, 13, 22, .055); }
.atlas-ripple-card { margin: 0; padding: 24px; }
.atlas-ripple { display: grid; grid-template-columns: 50px minmax(0, 1fr) auto; gap: 13px; align-items: center; padding: 16px 0; border-bottom: 1px solid var(--atlas-line); }
.atlas-ripple:last-child { border-bottom: 0; }
.atlas-ripple > span { width: 48px; height: 48px; display: grid; place-items: center; border: 1px solid var(--wine-300); border-radius: 50%; color: var(--wine-500); font: 18px var(--font-display); }
.atlas-ripple strong,
.atlas-ripple small { display: block; }
.atlas-ripple small { margin-top: 3px; color: var(--charcoal-500); font-size: 10px; }
.atlas-destination { position: relative; margin: 0; overflow: hidden; background: var(--copper); }
.atlas-destination::after { content: "17"; position: absolute; right: 8px; bottom: -42px; color: rgba(59, 13, 22, .1); font: 126px var(--font-display); }
.atlas-destination > * { position: relative; z-index: 1; }
.atlas-destination h3 { color: var(--wine-900); font-size: 30px; }

.home-module { border-radius: var(--atlas-radius); }
.journal-card img { border-radius: 18px; }
.home-wine { border-radius: 18px; padding: 15px; background: var(--ivory-100); border: 1px solid var(--atlas-line); }
.preference-tags span,
.context-chip,
.prompt-chip,
.wi-btn { border-radius: 999px; }
.module-prompt { min-height: 44px; border-radius: 999px; }
.home-conversation { left: calc(96px + (100vw - 96px) / 2); width: min(780px, calc(100vw - 150px)); border-radius: 22px; background: rgba(255, 253, 249, .94); backdrop-filter: blur(18px); }

.metrics-grid { gap: 14px; }
.metric-card { min-height: 118px; padding: 22px; }
.metric-card strong { color: var(--wine-900); font-size: 40px; }
.catalog-row { padding: 18px 20px; }
.catalog-search input { min-height: 48px; border-radius: 999px; background: var(--atlas-white); }
.dimension-track,
.sensory-track { border-radius: 999px; }
.palate-summary { border-left: 4px solid var(--copper); }
.pairing-intro { padding: clamp(24px, 4vw, 46px); background: var(--wine-900); color: var(--atlas-white); }
.pairing-intro h2 { color: var(--atlas-white); font-size: 42px; }
.pairing-intro p { color: rgba(255, 253, 249, .72); }

.conversation-toolbar { background: rgba(250, 247, 242, .86); backdrop-filter: blur(16px); }
.chat-scroll { background: transparent; }
.msg-bubble { border-radius: 22px; }
.msg-row.user .msg-bubble { background: var(--wine-900); }
.composer-wrap { border-top-color: var(--atlas-line); background: rgba(250, 247, 242, .92); backdrop-filter: blur(18px); }
.composer { border-radius: 24px; }

#record-detail { border-radius: var(--atlas-radius); box-shadow: var(--atlas-shadow); }
.auth-gate { background: transparent; }
.auth-card { border-radius: 32px 8px 32px 8px; background: rgba(255, 253, 249, .94); box-shadow: var(--atlas-shadow); }
.auth-card input { border-radius: 12px; }

@media (prefers-reduced-motion: reduce) {
  html { scroll-behavior: auto; }
  .atlas-orbit,
  .atlas-node { animation: none; }
  .sidebar { transition: none; }
}

@media (max-width: 1050px) {
  .atlas-home-grid { grid-template-columns: 1fr; }
  .sensory-world { grid-row: auto; }
  .atlas-ripple-card,
  .atlas-destination { min-height: 220px; }
}

@media (max-width: 760px) {
  body { padding-bottom: 78px; }
  .main { padding-left: 0; }
  .main-header { height: 72px; padding: 0 18px; }
  .header-home img { width: 36px; height: 36px; }
  .header-home strong { font-size: 20px; }
  .header-home small,
  .atlas-coordinates > span:first-child { display: none; }
  .atlas-status { padding: 7px 9px; font-size: 9px; }
  .icon-btn { display: none; }
  .view { height: calc(100dvh - 72px); }
  .home-scroll { height: calc(100dvh - 72px); padding: 30px 18px 150px; }
  .section-page { padding: 30px 18px 130px; }
  .home-hero h1,
  .section-heading h1 { font-size: 44px; }
  .sensory-world { min-height: 560px; padding: 38px 26px; border-radius: 72px 24px 24px 24px; }
  .atlas-node.n1 { left: 7%; }
  .atlas-node.n2 { right: 5%; }
  .atlas-node.n3 { right: 9%; }
  .atlas-node.n4 { left: 52%; }
  .home-conversation { left: 16px; right: 16px; bottom: 86px; width: auto; }

  .sidebar,
  .sidebar:hover,
  .sidebar:focus-within {
    inset: auto 12px 10px 12px;
    width: auto;
    height: 66px;
    padding: 7px;
    display: block;
    overflow-x: auto;
    overflow-y: hidden;
    border-radius: 22px;
    transform: none;
  }
  .sidebar .brand,
  .sidebar .btn-new-chat,
  .sidebar .nav-section-label,
  .sidebar #history-status,
  .sidebar .chat-history-list,
  .sidebar .sidebar-footer { display: none; }
  .sidebar .nav-list { display: flex; width: max-content; min-width: 100%; gap: 4px; justify-content: space-between; }
  .sidebar .nav-item { width: 48px; min-height: 50px; padding: 0 13px; }
  .sidebar .nav-label { display: none; }
  .sidebar-scrim { display: none !important; }
  .journal-grid,
  .home-wines { grid-template-columns: 1fr; }
}

@media (max-width: 480px) {
  .atlas-status { font-size: 0; }
  .atlas-status::after { content: "Grounded"; font-size: 9px; }
  .atlas-ripple { grid-template-columns: 48px 1fr; }
  .atlas-ripple .quiet-link { grid-column: 2; justify-self: start; }
}
