/* Landscape — light ambient backdrop + Claude-style centered search bar */

body.landscape-ui {
  overflow: hidden;
  min-height: 100dvh;
  margin: 0;
  padding: 0;
  transition: background 2.2s ease;
}
body.landscape-ui::before { display: none; }

/* Filter defs SVG is inline by default — it still creates a line box and pushes .app down.
   Take it out of flow so the shell sits flush to the top. */
body.landscape-ui > svg[aria-hidden="true"] {
  position: fixed;
  left: 0;
  top: 0;
  width: 0;
  height: 0;
  overflow: hidden;
  pointer-events: none;
  z-index: 0;
  border: 0;
  margin: 0;
  padding: 0;
}

/* When typing or in an active thread, mountains fade; clouds soften */
body.landscape-ui.landscape-backdrop-dim #mountains-container {
  opacity: 0;
  visibility: hidden;
}
body.landscape-ui.landscape-backdrop-dim #sky-clouds {
  opacity: 0.42;
}
body.landscape-ui.landscape-backdrop-dim::after {
  opacity: 0.25;
}
body.landscape-ui::after {
  transition: opacity 0.65s ease;
}

:root { --mountain: #dce3ec; }

/* ── Sky + clouds ── */

#sky-clouds {
  position: fixed; inset: 0; z-index: 1;
  pointer-events: none; overflow: hidden;
  transition: opacity 0.65s ease;
  opacity: 1;
}
#sky-clouds .cloud {
  border-radius: 50%; position: absolute; top: auto; left: auto;
}

/* ── Mountains ── */

#mountains-container {
  position: fixed; bottom: 0; left: 0;
  width: 100%; height: 100%; z-index: 2;
  pointer-events: none;
  opacity: 1;
  visibility: visible;
  transition: opacity 0.65s ease, visibility 0.65s;
}
#mountains-container .mountain {
  position: absolute; bottom: 0; white-space: pre;
  font-family: "Courier New", Courier, monospace; line-height: 1.05;
  color: var(--mountain); transition: color 2.2s ease; opacity: 0.48;
}

body.landscape-ui::after {
  content: ''; position: fixed; bottom: 0; left: 0; right: 0;
  height: 40%; z-index: 1; pointer-events: none;
  background: radial-gradient(ellipse 120% 60% at 50% 100%,
    rgba(15, 118, 110, 0.03) 0%, rgba(15, 118, 110, 0.01) 40%, transparent 70%);
}

/* ── App shell above landscape ── */

/* Fill viewport reliably (avoids % height gaps above/below flex children) */
body.landscape-ui .app {
  position: relative;
  z-index: 10;
  min-height: 100dvh;
  height: 100dvh;
  max-height: 100dvh;
  display: flex;
  flex-direction: row;
  align-items: stretch;
  box-sizing: border-box;
}

/* ── Topbar: hidden ── */
body.landscape-ui .topbar { display: none !important; }

/* ── Rail sidebar — flush to top, full height ── */

body.landscape-ui .sidebar.sidebar-rail {
  width: 56px;
  min-width: 56px;
  min-height: 100%;
  height: 100%;
  max-height: 100%;
  flex-shrink: 0;
  align-self: stretch;
  display: flex;
  flex-direction: column;
  gap: 2px;
  box-sizing: border-box;
  padding-top: 0;
  padding-right: 8px;
  padding-bottom: max(8px, env(safe-area-inset-bottom, 0px));
  padding-left: 8px;
  background: rgba(255, 255, 255, 0.92);
  backdrop-filter: blur(24px) saturate(1.2);
  -webkit-backdrop-filter: blur(24px) saturate(1.2);
  border-right: 1px solid #e2e8f0;
  box-shadow: 2px 0 16px rgba(0, 0, 0, 0.04);
  transition: width 0.35s var(--ease-out-expo);
  overflow: hidden;
}
html.sidebar-expanded body.landscape-ui .sidebar.sidebar-rail {
  width: min(288px, 86vw); min-width: min(288px, 86vw);
}

/* ── Rail: expand button ── */

.sb-expand {
  width: 100%; min-height: 42px; border: none; border-radius: 12px;
  background: transparent; color: var(--t2); cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  flex-shrink: 0; transition: all 0.2s var(--ease-out-expo);
}
html.sidebar-expanded .sb-expand {
  justify-content: flex-start; padding-left: 10px; gap: 10px;
}
.sb-expand:hover { background: #f1f5f9; color: var(--t1); }
.sb-expand:focus-visible { outline: 2px solid var(--acB); outline-offset: 2px; }
.sb-expand .sb-expand-label {
  display: none; font: 600 13px var(--ff); color: var(--t1);
}
html.sidebar-expanded .sb-expand .sb-expand-label { display: inline; }

.icon-bars {
  width: 20px; height: 14px; display: flex;
  flex-direction: column; justify-content: space-between; flex-shrink: 0;
}
.icon-bars span {
  display: block; height: 2px; background: currentColor; border-radius: 1px;
}

/* ── Rail: nav rows ── */

body.landscape-ui .sb-nav {
  display: flex; flex-direction: column; gap: 2px; flex-shrink: 0;
}
.sb-row {
  width: 100%; min-height: 42px; border: none; border-radius: 12px;
  background: transparent; color: var(--t3); cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  gap: 0; padding: 0 8px; transition: all 0.2s var(--ease-out-expo);
}
html.sidebar-expanded .sb-row { justify-content: flex-start; gap: 12px; }
.sb-row:hover { background: #f1f5f9; color: var(--t1); transform: scale(1.02); }
.sb-row:active { transform: scale(0.97); }
.sb-row:focus-visible { outline: 2px solid var(--acB); outline-offset: 2px; }
.sb-row .sb-ico {
  width: 20px; height: 20px; flex-shrink: 0;
  display: flex; align-items: center; justify-content: center;
}
.sb-row .sb-ico svg {
  width: 20px; height: 20px; stroke: currentColor;
  fill: none; stroke-width: 1.75; stroke-linecap: round; stroke-linejoin: round;
}
.sb-row.sb-plus .sb-ico svg { stroke-width: 2; }
.sb-row .sb-txt {
  font: 500 13px/1.35 var(--ff);
  letter-spacing: 0.02em;
  white-space: nowrap;
  overflow: hidden;
  max-width: 0;
  opacity: 0;
  transition: max-width 0.3s ease, opacity 0.2s ease;
}
html.sidebar-expanded .sb-row .sb-txt { max-width: 220px; opacity: 1; }

/* ── Rail: auth section ── */

.sb-rail-auth {
  padding: 4px 0; flex-shrink: 0;
  position: relative;
  display: flex; flex-direction: column; gap: 2px;
}
.sb-rail-auth .auth-menu-wrap {
  display: flex; flex-direction: column; gap: 2px;
}
.sb-rail-auth .auth-avatar {
  width: 20px; height: 20px; border-radius: 6px;
  background: #f1f5f9; color: #64748b;
  display: flex; align-items: center; justify-content: center;
  font: 600 10px var(--ff); line-height: 1;
}
/* fixed: sidebar overflow:hidden would clip absolute dropdowns */
.sb-rail-auth .auth-dropdown {
  position: fixed;
  left: 56px;
  bottom: max(72px, env(safe-area-inset-bottom, 0px));
  min-width: 260px;
  z-index: 600;
  background: rgba(255, 255, 255, 0.97);
  border: 1px solid #e2e8f0;
  border-radius: 14px;
  padding: 10px;
  box-shadow: 0 12px 40px rgba(0, 0, 0, 0.1);
  backdrop-filter: blur(20px);
}
html.sidebar-expanded body.landscape-ui .sb-rail-auth .auth-dropdown {
  left: min(288px, 86vw);
}

/* ── Rail: chat log strip ── */

.sb-chatlog {
  flex: 0 0 auto; max-height: 0; margin-top: 0; padding-top: 0;
  border-top: 0 solid var(--bdr); min-height: 0;
  display: flex; flex-direction: column; opacity: 0;
  pointer-events: none; overflow: hidden;
  transition: opacity 0.22s ease, max-height 0.3s ease, margin 0.3s ease, padding 0.3s ease, border-width 0.3s ease;
}
html.sidebar-expanded .sb-chatlog {
  flex: 1; max-height: min(52vh, 420px); margin-top: 8px;
  padding-top: 10px; border-top-width: 1px; opacity: 1; pointer-events: auto;
}
.sb-chatlog-hd {
  font: 600 10px var(--ff); color: var(--t4); text-transform: uppercase;
  letter-spacing: 0.08em; padding: 0 10px 10px; white-space: nowrap;
  overflow: hidden; flex-shrink: 0;
}
body.landscape-ui .sb-chatlog .sb-list {
  flex: 1; overflow-y: auto; min-height: 0; padding: 0 4px 8px;
  scrollbar-width: thin; scrollbar-color: var(--bdr2) transparent;
}

body.landscape-ui .sidebar.sidebar-rail .sb-item {
  padding: 10px; border-radius: 8px; margin-bottom: 2px; background: transparent;
}
body.landscape-ui .sidebar.sidebar-rail .sb-item:hover { background: #f1f5f9; }
body.landscape-ui .sidebar.sidebar-rail .sb-item.active { background: #e2e8f0; }
body.landscape-ui .sidebar.sidebar-rail .sb-item-title { color: var(--t1); font: 500 13px var(--ff); }
body.landscape-ui .sidebar.sidebar-rail .sb-item-time { color: var(--t4); }
body.landscape-ui .sidebar.sidebar-rail .sb-item-del { color: var(--t4); }
body.landscape-ui .sidebar.sidebar-rail .sb-item-del:hover { background: var(--negD); color: var(--neg); }

/* ── Rail: stats footer ── */

.sb-rail-footer {
  margin-top: auto; flex-shrink: 0;
  padding: 10px 8px 4px; border-top: 1px solid var(--bdr);
  font: 500 9px var(--fm); color: var(--t4); line-height: 1.35;
  overflow: hidden; white-space: nowrap;
  max-height: 0; opacity: 0;
  transition: max-height 0.3s ease, opacity 0.2s ease, padding 0.3s ease;
}
html.sidebar-expanded .sb-rail-footer {
  max-height: 60px; opacity: 1;
}
.sb-rail-footer b { color: var(--t3); font-weight: 600; }

/* ═══════════════════════════════════════════════════════
   MAIN — full height, no topbar gap
   ═══════════════════════════════════════════════════════ */

body.landscape-ui .main {
  flex: 1;
  min-width: 0;
  min-height: 0;
  display: flex;
  flex-direction: column;
  height: 100%;
}

body.landscape-ui .content-area {
  flex: 1; display: flex; overflow: hidden;
  padding: 0; gap: 0; align-items: stretch;
  min-height: 0;
}

/* ═══════════════════════════════════════════════════════
   CHAT-WRAP: invisible shell, stretches full
   ═══════════════════════════════════════════════════════ */

body.landscape-ui .chat-wrap {
  flex: 1; min-width: 0; min-height: 0;
  display: flex; flex-direction: column;
  align-items: center;
  background: transparent;
  border: none; border-radius: 0;
  box-shadow: none;
  backdrop-filter: none; -webkit-backdrop-filter: none;
  margin: 0; max-width: none;
}

body.landscape-ui .chat-wrap .chat {
  flex: 1; min-height: 0;
  display: flex; flex-direction: column;
  background: transparent;
  padding: 0;
  width: 100%;
  max-width: 680px;
  margin-left: auto;
  margin-right: auto;
}

/* Empty home: vertically center brand + search + preset row */
body.landscape-ui .chat-wrap.chat-wrap--empty {
  justify-content: center;
  align-items: center;
  padding: 0 12px;
}

body.landscape-ui .chat-wrap.chat-wrap--empty .chat {
  flex: 0 0 auto;
  min-height: 0;
  width: 100%;
  max-width: 680px;
}

body.landscape-ui .chat-wrap.chat-wrap--empty .scroll-btn {
  display: none !important;
}

/* ── Claude-style empty state: brand -> pills -> search bar ── */

body.landscape-ui .chat-wrap .chat:has(> .empty) {
  justify-content: center;
  align-items: center;
}

body.landscape-ui .empty {
  min-height: 0; flex: 0 1 auto;
  display: flex; flex-direction: column; align-items: center;
  padding: 0 20px 0; gap: 0;
  margin-bottom: 0;
}

body.landscape-ui .empty-brand {
  font: 700 34px var(--ff);
  color: #0f172a;
  letter-spacing: -0.04em;
  margin-bottom: 14px;
}

/* Presets live below the search bar (see #emptyPresetsRow) */
body.landscape-ui .empty-presets-below {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  justify-content: center;
  align-items: center;
  max-width: 680px;
  width: 100%;
  margin-top: 14px;
  padding: 0 8px 8px;
  flex-shrink: 0;
  transition: opacity 0.25s ease;
}
body.landscape-ui .empty-presets-below[hidden] {
  display: none !important;
}

body.landscape-ui .empty-preset {
  padding: 8px 18px; border-radius: 999px;
  border: 1px solid #e2e8f0;
  background: #ffffff;
  color: #64748b;
  font: 500 12px var(--ff); cursor: pointer;
  transition: all 0.2s var(--ease-out-expo);
}
body.landscape-ui .empty-preset:hover {
  border-color: #cbd5e1;
  background: #f8fafc;
  color: #0f172a;
  transform: translateY(-1px);
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.06);
}
body.landscape-ui .empty-preset:active { transform: translateY(0); }

/* hide old elements we no longer use */
body.landscape-ui .empty-icon,
body.landscape-ui .empty-title,
body.landscape-ui .empty-sub { display: none; }

body.landscape-ui .chat-wrap ::selection { background: rgba(15, 23, 42, 0.1); }
body.landscape-ui .chat-wrap ::-moz-selection { background: rgba(15, 23, 42, 0.1); }

/* ═══════════════════════════════════════════════════════
   SEARCH BAR — white rounded pill, centered
   ═══════════════════════════════════════════════════════ */

body.landscape-ui .input-wrap {
  border-top: none;
  background: transparent;
  border-radius: 0;
  margin: 0;
  max-width: 680px;
  width: 100%;
  align-self: center;
  padding: 0 20px 40px;
  flex-shrink: 0;
}

/* Centered stack: brand -> search bar -> preset chips */
body.landscape-ui .chat-wrap.chat-wrap--empty .input-wrap {
  padding: 4px 20px 0;
  margin-top: 0;
}

body.landscape-ui .input-box {
  background: #ffffff;
  border: 1px solid #e2e8f0;
  border-radius: 24px;
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.04);
  transition: border-color 0.25s ease, box-shadow 0.25s ease;
}

body.landscape-ui .input-box:focus-within {
  border-color: rgba(15, 23, 42, 0.2);
  box-shadow: 0 0 0 3px rgba(15, 23, 42, 0.04), 0 1px 4px rgba(0, 0, 0, 0.04);
}

body.landscape-ui .input-ta { color: #0f172a; }
body.landscape-ui .input-ta::placeholder { color: #94a3b8; }

body.landscape-ui .input-attach {
  border-color: #e2e8f0;
  color: #94a3b8;
}
body.landscape-ui .input-attach:hover {
  border-color: #cbd5e1;
  color: #64748b;
  background: #f8fafc;
}

body.landscape-ui .input-send {
  background: #0f172a;
  color: #fff;
}
body.landscape-ui .input-send:hover {
  background: #1e293b;
}
body.landscape-ui .input-send:disabled {
  opacity: 0.2;
  background: #94a3b8;
}

/* ── Scroll button ── */

body.landscape-ui .scroll-btn {
  background: #ffffff;
  border: 1px solid #e2e8f0;
  color: #64748b;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.06);
  border-radius: 20px;
}
body.landscape-ui .scroll-btn:hover {
  border-color: #cbd5e1; color: #0f172a;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.08);
}

/* ═══════════════════════════════════════════════════════
   MESSAGE BUBBLES — clean cards on white bg
   ═══════════════════════════════════════════════════════ */

body.landscape-ui .chat-wrap .chat {
  padding: 24px 20px 12px;
  max-width: 740px;
  width: 100%;
  margin: 0 auto;
}

body.landscape-ui .chat-wrap .msg-user-bubble {
  background: #f1f5f9;
  border: 1px solid #e2e8f0;
  color: #0f172a;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.04);
}

body.landscape-ui .chat-wrap .msg-body {
  background: #ffffff;
  border: 1px solid #f1f5f9;
  color: #0f172a;
  box-shadow: 0 1px 6px rgba(0, 0, 0, 0.04);
}
body.landscape-ui .chat-wrap .msg-body:hover {
  box-shadow: 0 2px 12px rgba(0, 0, 0, 0.06);
}

body.landscape-ui .chat-wrap .msg-body code:not(pre code) {
  background: #e2e8f0; color: #0f172a;
}

body.landscape-ui .chat-wrap .msg-body .md-table th {
  background: #f1f5f9; color: #0f172a; border-color: #e2e8f0;
}
body.landscape-ui .chat-wrap .msg-body .md-table td {
  color: #334155; border-color: #e2e8f0;
}
body.landscape-ui .chat-wrap .msg-body .md-table tr:nth-child(even) {
  background: rgba(241, 245, 249, 0.6);
}
body.landscape-ui .chat-wrap .msg-retry {
  background: #ffffff; border-color: #e2e8f0; color: #64748b;
}
body.landscape-ui .chat-wrap .msg-retry:hover {
  border-color: #cbd5e1; color: #0f172a;
}

/* ═══════════════════════════════════════════════════════
   ROUTING PANEL — collapsed by default, slide-in from right
   ═══════════════════════════════════════════════════════ */

body.landscape-ui .route-panel {
  width: 0; min-width: 0; opacity: 0; overflow: hidden;
  background: #ffffff;
  border-left: none; border-radius: 0;
  backdrop-filter: none; -webkit-backdrop-filter: none;
  box-shadow: none;
  transition: width 0.35s var(--ease-out-expo), min-width 0.35s var(--ease-out-expo), opacity 0.25s ease;
  --t1: #0f172a; --t2: #334155; --t3: #64748b; --t4: #94a3b8;
  --sf: #f8fafc; --sf2: #f1f5f9;
  --bdr: #f1f5f9; --bdr2: #e2e8f0;
}
body.landscape-ui.route-open .route-panel {
  width: 280px; min-width: 280px;
  opacity: 1; overflow: auto;
  border-left: 1px solid #e2e8f0;
}
body.landscape-ui .route-panel .rp-head {
  border-bottom-color: #e2e8f0;
}
body.landscape-ui .route-panel .rp-empty {
  color: #94a3b8;
}

/* ═══════════════════════════════════════════════════════
   AUTH MODAL — centered, polished (landscape shell)
   ═══════════════════════════════════════════════════════ */

body.landscape-ui .auth-modal-overlay {
  display: grid;
  place-items: center;
  padding: max(20px, env(safe-area-inset-top)) 20px max(24px, env(safe-area-inset-bottom));
  background: rgba(15, 23, 42, 0.3);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
}

body.landscape-ui .auth-modal {
  width: 100%;
  max-width: 400px;
  margin: 0 auto;
  padding: 28px 28px 30px;
  border-radius: 22px;
  border: 1px solid #e2e8f0;
  background: #ffffff;
  box-shadow:
    0 0 0 1px rgba(0, 0, 0, 0.02),
    0 20px 48px rgba(0, 0, 0, 0.1);
}

body.landscape-ui .auth-modal-title {
  font: 700 22px/1.2 var(--ff);
  color: #0f172a;
  letter-spacing: -0.02em;
  text-align: center;
  margin: 0 0 18px;
}

body.landscape-ui .auth-tabs {
  gap: 6px;
  margin-bottom: 16px;
}

body.landscape-ui .auth-tab {
  padding: 10px 14px;
  border-radius: 10px;
  font: 600 13px var(--ff);
}

body.landscape-ui .auth-field label {
  font: 600 10px var(--fm);
  color: #64748b;
  letter-spacing: 0.04em;
}

body.landscape-ui .auth-modal-input {
  padding: 12px 14px;
  border-radius: 10px;
  border: 1px solid #e2e8f0;
  background: #f8fafc;
  color: #0f172a;
}
body.landscape-ui .auth-modal-input:focus {
  border-color: rgba(15, 118, 110, 0.5);
  outline: none;
  box-shadow: 0 0 0 3px rgba(15, 118, 110, 0.08);
}

body.landscape-ui .auth-submit {
  margin-top: 10px;
  padding: 14px 18px;
  border-radius: 12px;
  font: 700 14px var(--ff);
}

/* ═══════════════════════════════════════════════════════
   MOBILE
   ═══════════════════════════════════════════════════════ */

@media (max-width: 768px) {
  body.landscape-ui .sidebar.sidebar-rail {
    position: fixed;
    top: 0;
    left: 0;
    bottom: 0;
    height: 100dvh;
    max-height: 100dvh;
    min-height: 100dvh;
    z-index: 500;
    margin: 0;
    padding-top: max(0px, env(safe-area-inset-top, 0px));
  }
  body.landscape-ui .main { margin-left: 56px; }
  html.sidebar-expanded body.landscape-ui .main {
    margin-left: min(288px, 86vw);
  }
  body.landscape-ui .input-wrap {
    padding: 0 12px 20px;
  }
  body.landscape-ui .chat-wrap.chat-wrap--empty .input-wrap {
    padding: 8px 12px 0;
  }
  body.landscape-ui .chat-wrap .chat {
    padding: 16px 12px 8px;
  }
  body.landscape-ui .empty-presets-below {
    padding: 0 4px 12px;
  }
}
