/* ── 巢 Nest PWA — Phase 4B 完整样式 ── */

/* ===== 0. 主题变量 ===== */

:root, [data-theme="clay"] {
  --clay-rock:       #8B7355;
  --clay-dusk:       #C4A89B;
  --clay-sand:       #B5A08E;
  --clay-mountain:   #9B8EA8;
  --bubble-seb:      rgba(255, 255, 255, 0.70);
  --bubble-isa:      rgba(196, 168, 155, 0.30);
  --text-primary:    #3D3D3D;
  --text-secondary:  #8A8A8A;
  --text-muted:      #B0B0B0;
  --bg-primary:      #F5F0EB;
  --bg-card:         rgba(255, 255, 255, 0.50);
  --accent:          #C4A89B;
  --online:          #7BC67E;
  --sidebar-bg:     rgba(255, 255, 255, 0.55);
  --overlay:        rgba(0,0,0,0.25);
}

[data-theme="mist-blue"] {
  --clay-rock:       #5B6B7A;
  --clay-dusk:       #9BAAB8;
  --clay-sand:       #A8B5BE;
  --clay-mountain:   #8895A5;
  --bubble-seb:      rgba(255, 255, 255, 0.65);
  --bubble-isa:      rgba(155, 170, 184, 0.25);
  --bg-primary:      #EEF1F4;
  --bg-card:         rgba(255, 255, 255, 0.45);
  --accent:          #7A93A8;
  --sidebar-bg:     rgba(255, 255, 255, 0.50);
}

[data-theme="night"] {
  --clay-rock:       #5B5B5B;
  --clay-dusk:       #7A7A7A;
  --clay-sand:       #666666;
  --clay-mountain:   #6A6A6A;
  --bubble-seb:      rgba(60, 58, 55, 0.75);
  --bubble-isa:      rgba(80, 72, 65, 0.50);
  --text-primary:    #E0DDD8;
  --text-secondary:  #8A8580;
  --text-muted:      #6A6560;
  --bg-primary:      #1A1A1E;
  --bg-card:         rgba(40, 40, 45, 0.80);
  --accent:          #7A7A7A;
  --sidebar-bg:     rgba(30, 30, 35, 0.80);
  --overlay:        rgba(0,0,0,0.50);
}

/* ===== 1. Reset & Base ===== */

*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

html { font-size: 16px; -webkit-text-size-adjust: 100%; --app-height: 100dvh; }
body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  background: var(--bg-primary);
  color: var(--text-primary);
  line-height: 1.5;
  overflow: hidden;
  height: var(--app-height);
  width: 100vw;
  transition: background 0.3s, color 0.3s;
}
input, textarea, button { font-family: inherit; font-size: inherit; }
a { color: var(--accent); text-decoration: none; }
::-webkit-scrollbar { width: 4px; }
::-webkit-scrollbar-thumb { background: var(--clay-sand); border-radius: 2px; }

/* ===== 2. Background Gradient ===== */

.bg-canvas {
  position: fixed; inset: 0; z-index: 0;
  overflow: hidden; pointer-events: none;
}
.bg-blob {
  position: absolute; border-radius: 50%; filter: blur(80px);
  transition: background 0.3s;
}
[data-theme="clay"] .bg-blob:nth-child(1) { width: 400px; height: 400px; top: -100px; left: -100px; background: rgba(196,168,155,0.25); }
[data-theme="clay"] .bg-blob:nth-child(2) { width: 300px; height: 300px; bottom: -50px; right: -50px; background: rgba(155,142,168,0.2); }
[data-theme="mist-blue"] .bg-blob:nth-child(1) { width: 400px; height: 400px; top: -100px; left: -100px; background: rgba(155,170,184,0.2); }
[data-theme="mist-blue"] .bg-blob:nth-child(2) { width: 300px; height: 300px; bottom: -50px; right: -50px; background: rgba(136,149,165,0.15); }
[data-theme="night"] .bg-blob:nth-child(1) { width: 400px; height: 400px; top: -100px; left: -100px; background: rgba(60,58,55,0.3); }
[data-theme="night"] .bg-blob:nth-child(2) { width: 300px; height: 300px; bottom: -50px; right: -50px; background: rgba(40,40,45,0.3); }

/* ===== 3. Glass Base ===== */

.glass {
  background: var(--bg-card);
  backdrop-filter: blur(20px) saturate(1.2);
  -webkit-backdrop-filter: blur(20px) saturate(1.2);
  border: 1px solid rgba(255,255,255,0.18);
  border-radius: 16px;
}
.glass-card {
  background: var(--bg-card);
  backdrop-filter: blur(20px) saturate(1.2);
  -webkit-backdrop-filter: blur(20px) saturate(1.2);
  border: 1px solid rgba(255,255,255,0.18);
  border-radius: 16px;
}

/* ===== 4. Layout ===== */

.app-layout { display: flex; height: var(--app-height); position: relative; z-index: 1; }

/* -- Sidebar -- */
.sidebar {
  width: 220px; flex-shrink: 0;
  background: var(--sidebar-bg);
  backdrop-filter: blur(24px) saturate(1.3);
  -webkit-backdrop-filter: blur(24px) saturate(1.3);
  border-right: 1px solid rgba(255,255,255,0.15);
  display: flex; flex-direction: column;
  padding: 20px 12px; z-index: 10;
  transition: transform 0.3s;
}
.sidebar-header {
  text-align: center; padding-bottom: 16px;
  border-bottom: 1px dashed var(--clay-sand);
  margin-bottom: 12px;
}
.sidebar-header h1 {
  font-size: 1.1rem; font-weight: 600; letter-spacing: 0.5px;
  color: var(--clay-rock);
}
.sidebar-header .subtitle {
  font-size: 0.75rem; color: var(--text-secondary);
  margin-top: 2px;
}
.sidebar-illustration {
  width: 60px; height: 60px; margin: 0 auto 8px; border-radius: 50%;
  background: var(--clay-dusk); opacity: 0.6;
  display: flex; align-items: center; justify-content: center;
  font-size: 1.5rem; color: white;
}
.sidebar-ticket-cut {
  height: 12px; margin: 0 -12px;
  background: radial-gradient(circle, var(--bg-primary) 4px, transparent 4px);
  background-size: 12px 12px; background-repeat: repeat-x;
}
.nav-list { list-style: none; flex: 1; overflow-y: auto; }
.nav-item {
  display: flex; align-items: center; gap: 10px;
  padding: 10px 12px; margin: 2px 0;
  border-radius: 10px; cursor: pointer;
  color: var(--text-secondary); transition: all 0.2s;
  font-size: 0.9rem;
}
.nav-item:hover { background: rgba(255,255,255,0.3); color: var(--text-primary); }
.nav-item.active {
  background: var(--bg-card); color: var(--clay-rock); font-weight: 500;
}
.nav-item .icon { font-size: 1.1rem; width: 22px; text-align: center; }
.nav-item .status-dot {
  width: 8px; height: 8px; border-radius: 50%; margin-left: auto;
}
.sidebar-footer {
  padding-top: 12px; border-top: 1px dashed var(--clay-sand);
  font-size: 0.8rem;
}
.online-indicator { display: flex; align-items: center; gap: 6px; margin-top: 4px; }
.online-dot { width: 8px; height: 8px; border-radius: 50%; background: var(--online); }
.online-dot.offline { background: var(--text-muted); }

/* -- Main Content -- */
.main-content { flex: 1; overflow-y: auto; position: relative; }

/* -- Mobile Header -- */
.mobile-header {
  display: none; align-items: center; gap: 12px;
  padding: 12px 16px;
  background: var(--bg-card);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  position: sticky; top: 0; z-index: 5;
}
.mobile-header .hamburger {
  background: none; border: none; font-size: 1.4rem; cursor: pointer;
  color: var(--text-primary); padding: 4px;
}
.mobile-header .room-title { font-weight: 500; font-size: 1rem; }

/* -- Room panels -- */
.room-panel { display: none; padding: 24px; max-width: 800px; margin: 0 auto; }
.room-panel.active { display: block; }

/* ===== 5. Splash ===== */

.splash-screen {
  position: fixed; inset: 0; z-index: 100;
  background: var(--bg-primary);
  display: flex; flex-direction: column;
  align-items: center; justify-content: center;
  transition: opacity 0.8s, visibility 0.8s;
}
.splash-screen.hidden { opacity: 0; visibility: hidden; pointer-events: none; }
.splash-illustration {
  width: 120px; height: 120px; margin-bottom: 24px;
  position: relative;
}
.splash-bird {
  position: absolute; top: 0; left: 50%; transform: translateX(-50%);
  width: 48px; height: 48px;
  background: var(--clay-dusk); border-radius: 50% 50% 0 0;
  animation: splashFloat 2s ease-in-out infinite;
}
.splash-bird::after {
  content: ''; position: absolute; bottom: -8px; left: 50%;
  width: 20px; height: 16px;
  background: var(--clay-sand); border-radius: 50%;
  transform: translateX(-50%) rotate(-15deg);
}
.splash-nest {
  position: absolute; bottom: 0; left: 50%; transform: translateX(-50%);
  width: 80px; height: 30px;
  background: var(--clay-rock); border-radius: 0 0 40px 40px;
  opacity: 0.7;
}
.splash-title {
  font-size: 2rem; font-weight: 300; letter-spacing: 4px;
  color: var(--clay-rock); text-align: center;
}
.splash-title em { font-style: normal; font-size: 1.2rem; display: block; margin-top: 4px; opacity: 0.7; }

/* ===== 6. Foyer (门厅) ===== */

.foyer-grid { display: flex; flex-direction: column; gap: 20px; padding-top: 8px; }

/* -- Status Card -- */
.status-card {
  position: relative; perspective: 1000px; min-height: 200px; cursor: default;
}
.status-card-inner {
  position: relative; width: 100%; padding: 20px;
  transition: transform 0.6s; transform-style: preserve-3d;
}
.status-card.flipped .status-card-inner { transform: rotateY(180deg); }
.status-card-face {
  backface-visibility: hidden; -webkit-backface-visibility: hidden;
}
.status-card-back {
  backface-visibility: hidden; -webkit-backface-visibility: hidden;
  position: absolute; inset: 0; padding: 20px;
  transform: rotateY(180deg);
}
.status-card h3 { font-size: 0.8rem; color: var(--text-muted); margin-bottom: 10px; letter-spacing: 1px; }
.status-card .edit-icon {
  position: absolute; top: 12px; right: 16px; cursor: pointer;
  color: var(--text-muted); font-size: 0.85rem;
}
.status-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.status-item { }
.status-item .label { font-size: 0.7rem; color: var(--text-muted); text-transform: uppercase; letter-spacing: 0.5px; }
.status-item .value { font-size: 0.95rem; margin-top: 2px; }
.drive-mini-grid {
  display: grid; grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 7px; margin-top: 12px;
}
.drive-mini { min-width: 0; }
.drive-mini-label {
  display: flex; justify-content: space-between; gap: 4px;
  color: var(--text-muted); font-size: 0.64rem; line-height: 1.2;
}
.drive-mini-label span:first-child { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.drive-mini-bar {
  height: 4px; margin-top: 3px; overflow: hidden; border-radius: 999px;
  background: rgba(0,0,0,0.08);
}
.drive-mini-bar span { display: block; height: 100%; border-radius: inherit; background: var(--clay-rock); }
[data-theme="night"] .drive-mini-bar { background: rgba(255,255,255,0.12); }
.status-flip-btn {
  position: absolute; bottom: 12px; right: 16px;
  background: none; border: none; color: var(--text-muted); cursor: pointer;
  font-size: 0.8rem;
}

/* -- Today Summary -- */
.today-summary {
  padding: 16px 20px;
}
.today-summary .days {
  font-size: 1.2rem; font-weight: 500; color: var(--clay-rock);
}
.today-summary .stats { display: flex; gap: 16px; margin-top: 8px; font-size: 0.85rem; color: var(--text-secondary); }

/* -- Stars -- */
.stars-section { margin-top: 8px; }
.stars-section h3 { font-size: 0.8rem; color: var(--text-muted); letter-spacing: 1px; margin-bottom: 12px; }
.stars-constellation {
  display: flex; justify-content: center; gap: 24px; padding: 16px;
}
.star-item { text-align: center; max-width: 150px; }
.star-body {
  width: 36px; height: 36px; margin: 0 auto 8px;
  background: var(--accent); border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  color: white; font-size: 0.7rem;
  box-shadow: 0 0 12px rgba(232,200,122,0.4);
  transition: all 0.3s;
}
.star-body.fixation { animation: starPulse 2s ease-in-out infinite; }
.star-body.dim { opacity: 0.4; transform: scale(0.7); }
.star-text { font-size: 0.8rem; color: var(--text-secondary); }
.star-drive { font-size: 0.65rem; color: var(--text-muted); margin-top: 2px; }

/* ===== 7. Bedroom (卧室) ===== */

.chat-container { display: flex; flex-direction: column; height: calc(100dvh - 100px); min-height: 0; }
.chat-messages { flex: 1 1 auto; min-height: 0; overflow-y: auto; overscroll-behavior: contain; -webkit-overflow-scrolling: touch; padding: 8px 0; }
.chat-messages .empty-state {
  text-align: center; padding: 60px 20px; color: var(--text-muted);
}

/* -- Time Label -- */
.time-label {
  text-align: center; font-size: 0.7rem; color: var(--text-muted);
  padding: 12px 0 8px; user-select: none;
}
.time-label.expanded { cursor: pointer; }
.time-label .full-time { display: none; }
.time-label.expanded .short-time { display: none; }
.time-label.expanded .full-time { display: inline; }

/* -- Bubbles -- */
.chat-bubble {
  max-width: 75%; margin: 4px 16px; padding: 12px 16px;
  line-height: 1.5; font-size: 0.9rem;
  word-wrap: break-word; overflow-wrap: anywhere; white-space: pre-wrap; position: relative;
  transition: opacity 0.3s;
}
.chat-bubble.seb {
  background: var(--bubble-seb);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  border-radius: 16px 16px 4px 16px;
  margin-right: auto; align-self: flex-start;
}
.chat-bubble.isa {
  background: var(--bubble-isa);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  border-radius: 16px 16px 16px 4px;
  margin-left: auto; align-self: flex-end;
}
.bubble-toolbar {
  display: flex; gap: 8px; margin-top: 4px;
  font-size: 0.7rem; color: var(--text-muted); opacity: 0;
  transition: opacity 0.2s;
}
.chat-bubble:hover .bubble-toolbar { opacity: 1; }
.bubble-toolbar span { cursor: pointer; }

/* -- CoT Fold -- */
/* Sebastian 气泡组：CoT + 工具调用 + 回复文本 */
.cot-block { margin: 4px auto 4px 16px; max-width: 75%; }
.cot-toggle {
  display: flex; align-items: center; gap: 6px;
  padding: 8px 12px; font-size: 0.8rem;
  background: var(--bubble-seb); backdrop-filter: blur(20px); -webkit-backdrop-filter: blur(20px);
  border-radius: 16px 16px 4px 16px; cursor: pointer;
  color: var(--text-secondary); border: none; width: 100%; text-align: left;
  transition: background 0.2s;
}
.cot-toggle:hover { background: rgba(255,255,255,0.5); }
.cot-toggle .check { margin-left: auto; color: var(--online); }
.cot-content {
  display: none; padding: 12px; margin-top: 4px;
  font-family: "SF Mono", "Fira Code", monospace; font-size: 0.8rem;
  background: var(--bubble-seb); backdrop-filter: blur(20px); -webkit-backdrop-filter: blur(20px);
  border-radius: 16px; white-space: pre-wrap;
  max-height: 300px; overflow-y: auto;
}
.cot-content.open { display: block; }
.tool-call-line {
  display: flex; align-items: center; gap: 6px; font-size: 0.8rem;
  padding: 6px 12px; margin: 2px auto 2px 16px; max-width: 75%;
  background: var(--bubble-seb); backdrop-filter: blur(20px); -webkit-backdrop-filter: blur(20px);
  border-radius: 16px 16px 4px 16px; color: var(--text-secondary);
}

/* -- Typing Indicator -- */
.typing-indicator {
  display: none; align-items: center; gap: 4px;
  padding: 12px 16px; margin: 4px 16px 4px auto;
  background: var(--bubble-seb); border-radius: 16px 16px 4px 16px;
  max-width: 60px;
}
.typing-indicator.show { display: flex; }
.typing-dot {
  width: 6px; height: 6px; border-radius: 50%;
  background: var(--text-muted);
  animation: typingBounce 1.4s ease-in-out infinite;
}
.typing-dot:nth-child(2) { animation-delay: 0.2s; }
.typing-dot:nth-child(3) { animation-delay: 0.4s; }

/* -- Isa Status Bar -- */
.isa-status-bar {
  display: flex; align-items: center; gap: 12px;
  padding: 8px 16px;
  font-size: 0.75rem; color: var(--text-muted);
  border-top: 1px solid rgba(255,255,255,0.1);
  cursor: pointer;
}
.isa-status-bar:hover { color: var(--text-secondary); }

/* -- Chat Input -- */
.chat-input-area {
  display: flex; align-items: flex-end; gap: 8px;
  padding: 8px 12px; background: var(--bg-card);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  border-top: 1px solid rgba(255,255,255,0.1);
}
.chat-input-area .attach-btn {
  background: none; border: none; font-size: 1.3rem; cursor: pointer;
  color: var(--text-muted); padding: 4px 8px; flex-shrink: 0;
}
.chat-input-area textarea {
  flex: 1; resize: none; border: none; background: transparent;
  outline: none; color: var(--text-primary);
  font-size: 0.9rem; padding: 8px 0;
  max-height: 120px; line-height: 1.4;
}
.chat-input-area textarea::placeholder { color: var(--text-muted); }
.chat-input-area .send-btn {
  background: var(--clay-dusk); border: none; color: white;
  width: 36px; height: 36px; border-radius: 50%;
  cursor: pointer; font-size: 1rem; flex-shrink: 0;
  display: flex; align-items: center; justify-content: center;
  transition: background 0.2s;
}
.chat-input-area .send-btn:hover { background: var(--clay-rock); }
.chat-input-area .send-btn:disabled { opacity: 0.55; cursor: default; }

/* ===== 8. Study (书房) ===== */

.study-tabs { display: flex; gap: 4px; margin-bottom: 16px; background: var(--bg-card); border-radius: 12px; padding: 4px; }
.study-tab {
  flex: 1; padding: 8px; text-align: center; border-radius: 8px;
  cursor: pointer; font-size: 0.85rem; color: var(--text-secondary);
  border: none; background: transparent; transition: all 0.2s;
}
.study-tab.active { background: rgba(255,255,255,0.5); color: var(--clay-rock); font-weight: 500; }
.study-panel { display: none; min-height: 400px; }
.study-panel.active { display: block; }

/* Activity Log */
.timeline { }
.timeline-item {
  padding: 10px 0; border-bottom: 1px solid rgba(255,255,255,0.15);
  display: flex; gap: 10px; font-size: 0.85rem;
}
.timeline-time { color: var(--text-muted); white-space: nowrap; min-width: 60px; }
.timeline-content { color: var(--text-secondary); }
.timeline-content .encrypted { font-style: italic; color: var(--clay-dusk); }

/* Library (BuJo) */
.library-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(160px, 1fr)); gap: 12px; }
.library-card { padding: 14px; cursor: pointer; }
.library-card .type-icon { font-size: 1.2rem; margin-bottom: 6px; }
.library-card .title { font-size: 0.85rem; }
.library-card .date { font-size: 0.7rem; color: var(--text-muted); margin-top: 4px; }
.library-tabs { display: flex; gap: 8px; margin-bottom: 12px; font-size: 0.85rem; }
.library-tab { cursor: pointer; color: var(--text-muted); padding: 4px 8px; border-radius: 6px; }
.library-tab.active { background: var(--bg-card); color: var(--text-primary); }

/* Diary */
.diary-header { display: flex; align-items: center; justify-content: space-between; margin-bottom: 16px; }
.diary-header .month { font-size: 1rem; font-weight: 500; }
.diary-nav { display: flex; gap: 8px; }
.diary-nav button { background: none; border: none; color: var(--text-muted); cursor: pointer; font-size: 1.1rem; }
.calendar-grid { display: grid; grid-template-columns: repeat(7, 1fr); gap: 2px; text-align: center; font-size: 0.8rem; }
.calendar-day-name { color: var(--text-muted); padding: 6px 0; font-size: 0.7rem; }
.calendar-date { padding: 8px 4px; border-radius: 8px; cursor: pointer; }
.calendar-date:hover { background: var(--bg-card); }
.calendar-date.has-entry { color: var(--clay-rock); font-weight: 500; }
.calendar-date.today { background: var(--clay-dusk); color: white; }
.calendar-date.empty { cursor: default; }
.diary-entry { margin-top: 12px; padding: 16px; font-size: 0.85rem; line-height: 1.7; }

/* ===== 9. Balcony (阳台) ===== */

.pet-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.pet-card { padding: 20px; }
.pet-card .pet-header { display: flex; align-items: center; gap: 12px; margin-bottom: 12px; }
.pet-avatar { width: 48px; height: 48px; border-radius: 50%; background: var(--clay-sand); display: flex; align-items: center; justify-content: center; font-size: 1.3rem; }
.pet-name { font-weight: 500; font-size: 1rem; }
.pet-status { font-size: 0.75rem; color: var(--text-secondary); }
.care-log { margin-top: 8px; }
.care-item { padding: 6px 0; font-size: 0.8rem; color: var(--text-secondary); border-bottom: 1px solid rgba(255,255,255,0.1); }
.care-item .time { font-size: 0.7rem; color: var(--text-muted); }

/* ===== 10. Workshop (工作间) ===== */

.ops-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.ops-card { padding: 16px; }
.ops-card h4 { font-size: 0.7rem; color: var(--text-muted); text-transform: uppercase; letter-spacing: 0.5px; margin-bottom: 6px; }
.ops-card .value { font-size: 1.5rem; font-weight: 300; color: var(--clay-rock); }
.ops-status { display: inline-flex; align-items: center; gap: 6px; font-size: 0.85rem; }
.ops-status .dot { width: 8px; height: 8px; border-radius: 50%; }
.ops-status .dot.green { background: var(--online); }
.ops-status .dot.red { background: #E87A7A; }
.ops-section-title { font-size: 0.8rem; color: var(--text-muted); letter-spacing: 1px; margin: 20px 0 10px; }
.ops-advanced { display: none; }
.ops-advanced.open { display: block; }
.ops-advanced-toggle { font-size: 0.8rem; color: var(--text-muted); cursor: pointer; margin-top: 8px; }

/* ===== 11. Settings ===== */

.settings-panel { display: none; }
.settings-panel.active { display: block; }
.theme-options { display: flex; gap: 12px; margin: 16px 0; }
.theme-option {
  padding: 12px 16px; border-radius: 12px; cursor: pointer;
  background: var(--bg-card); text-align: center; flex: 1;
  font-size: 0.85rem; transition: all 0.2s;
}
.theme-option:hover { background: rgba(255,255,255,0.3); }
.theme-option.active { border: 2px solid var(--clay-dusk); font-weight: 500; }
.theme-preview { width: 100%; height: 40px; border-radius: 6px; margin-bottom: 6px; }
.settings-section { margin: 16px 0; }
.settings-section h4 { font-size: 0.75rem; color: var(--text-muted); letter-spacing: 1px; margin-bottom: 8px; }
.settings-input { width: 100%; padding: 10px 12px; border-radius: 8px; border: 1px solid rgba(255,255,255,0.2); background: var(--bg-card); color: var(--text-primary); font-size: 0.85rem; }
.settings-input:focus { outline: none; border-color: var(--clay-dusk); }
.settings-save {
  padding: 10px 24px; border-radius: 8px; border: none;
  background: var(--clay-dusk); color: white; cursor: pointer;
  font-size: 0.85rem; margin-top: 8px;
}
.settings-save:hover { background: var(--clay-rock); }

/* ===== 12. Search ===== */

.search-overlay {
  position: fixed; inset: 0; z-index: 50; display: none;
  background: rgba(0,0,0,0.3);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
}
.search-overlay.open { display: flex; align-items: flex-start; justify-content: center; padding-top: 60px; }
.search-panel { width: 90%; max-width: 500px; max-height: 80vh; overflow-y: auto; padding: 20px; }
.search-panel input {
  width: 100%; padding: 12px 16px; border-radius: 10px;
  border: 1px solid rgba(255,255,255,0.2); background: rgba(255,255,255,0.6);
  color: var(--text-primary); font-size: 0.95rem; outline: none;
}
.search-results { margin-top: 12px; }
.search-result { padding: 10px 0; border-bottom: 1px solid rgba(255,255,255,0.1); cursor: pointer; }
.search-result:hover { opacity: 0.8; }
.search-result .highlight { background: rgba(232,200,122,0.3); padding: 0 2px; border-radius: 2px; }

/* ===== 13. Animations ===== */

@keyframes splashFloat {
  0%, 100% { transform: translateX(-50%) translateY(0); }
  50% { transform: translateX(-50%) translateY(-12px); }
}
@keyframes starPulse {
  0%, 100% { box-shadow: 0 0 12px rgba(232,200,122,0.4); }
  50% { box-shadow: 0 0 24px rgba(232,200,122,0.8); }
}
@keyframes typingBounce {
  0%, 60%, 100% { transform: translateY(0); }
  30% { transform: translateY(-6px); }
}
@keyframes highlightFade {
  0% { background: rgba(232,200,122,0.4); }
  100% { background: transparent; }
}
.highlight-flash { animation: highlightFade 1s ease-out; }

/* ===== 14. Mobile Responsive ===== */

@media (max-width: 768px) {
  .sidebar {
    position: fixed; left: 0; top: 0; bottom: 0;
    transform: translateX(-100%); z-index: 20;
  }
  .sidebar.open { transform: translateX(0); }
  .mobile-header { display: flex; }
  .sidebar-overlay {
    display: none; position: fixed; inset: 0; z-index: 15;
    background: var(--overlay);
  }
  .sidebar-overlay.show { display: block; }
  .room-panel { padding: 12px; }
  .pet-grid { grid-template-columns: 1fr; }
  .ops-grid { grid-template-columns: 1fr; }
  .status-card-inner { padding: 14px; }
  .chat-bubble { max-width: 85%; margin: 4px 8px; }
}

/* ===== Phase 4B visual pass: quieter house, stronger glass ===== */
:root, [data-theme="clay"] {
  --bg-primary: #f4eee8;
  --bg-wash: linear-gradient(135deg, #f8f3ee 0%, #eee6df 46%, #e8edf0 100%);
  --glass-surface: rgba(255,255,255,0.48);
  --glass-strong: rgba(255,255,255,0.68);
  --glass-edge: rgba(255,255,255,0.72);
  --shadow-soft: 0 24px 70px rgba(90,72,58,0.12), 0 6px 22px rgba(90,72,58,0.08);
  --shadow-low: 0 12px 36px rgba(90,72,58,0.10);
  --line-soft: rgba(98,80,66,0.10);
}
[data-theme="mist-blue"] {
  --bg-wash: linear-gradient(135deg, #f2f5f6 0%, #e8edf1 48%, #eef0ed 100%);
  --glass-surface: rgba(255,255,255,0.46);
  --glass-strong: rgba(255,255,255,0.64);
  --glass-edge: rgba(255,255,255,0.70);
  --shadow-soft: 0 24px 70px rgba(69,88,104,0.12), 0 6px 22px rgba(69,88,104,0.08);
  --shadow-low: 0 12px 36px rgba(69,88,104,0.10);
  --line-soft: rgba(69,88,104,0.11);
}
[data-theme="night"] {
  --bg-wash: linear-gradient(135deg, #1b1a1d 0%, #242226 54%, #20252a 100%);
  --glass-surface: rgba(45,44,48,0.58);
  --glass-strong: rgba(55,53,58,0.74);
  --glass-edge: rgba(255,255,255,0.12);
  --shadow-soft: 0 24px 70px rgba(0,0,0,0.28), 0 6px 22px rgba(0,0,0,0.20);
  --shadow-low: 0 12px 36px rgba(0,0,0,0.22);
  --line-soft: rgba(255,255,255,0.08);
}

body { background: var(--bg-wash); }
.bg-canvas { background: linear-gradient(180deg, rgba(255,255,255,0.18), rgba(255,255,255,0)); }
.bg-blob { display: none; }

.glass, .glass-card {
  background: linear-gradient(145deg, var(--glass-strong), var(--glass-surface));
  border: 1px solid var(--glass-edge);
  box-shadow: var(--shadow-soft), inset 0 1px 0 rgba(255,255,255,0.55), inset 0 -1px 0 rgba(255,255,255,0.14);
  backdrop-filter: blur(28px) saturate(1.45);
  -webkit-backdrop-filter: blur(28px) saturate(1.45);
  border-radius: 18px;
}

.sidebar {
  width: 236px;
  background: linear-gradient(180deg, rgba(255,255,255,0.64), rgba(255,255,255,0.38));
  border-right: 1px solid var(--glass-edge);
  box-shadow: 18px 0 46px rgba(90,72,58,0.08);
}
[data-theme="night"] .sidebar { background: linear-gradient(180deg, rgba(36,35,40,0.86), rgba(28,28,32,0.76)); }
.sidebar-header { border-bottom-color: var(--line-soft); }
.sidebar-ticket-cut { opacity: 0.42; }
.nav-item { border: 1px solid transparent; }
.nav-item:hover { background: rgba(255,255,255,0.34); border-color: var(--glass-edge); }
.nav-item.active { background: rgba(255,255,255,0.58); border-color: var(--glass-edge); box-shadow: var(--shadow-low); }

.main-content { padding: 0 10px; }
.room-panel { max-width: 980px; padding: 30px 28px 36px; }
.foyer-grid { min-height: calc(100dvh - 72px); justify-content: center; gap: 18px; max-width: 760px; margin: 0 auto; }
.status-card { min-height: 0; }
.status-card-inner { padding: 26px; }
.status-card h3, .section-eyebrow, .ops-section-title {
  letter-spacing: 0.08em; text-transform: uppercase; font-size: 0.72rem; color: var(--text-muted);
}
.status-card .status-grid[style] { gap: 22px !important; }
.status-item .label { letter-spacing: 0.02em; text-transform: none; }
.status-item .value { color: var(--text-primary); font-size: 1rem; }
.today-summary { display: flex; align-items: baseline; justify-content: space-between; gap: 18px; padding: 15px 20px; box-shadow: var(--shadow-low); }
.today-summary .days { font-size: 1rem; color: var(--clay-rock); }
.today-summary .stats { margin-top: 0; flex-wrap: wrap; justify-content: flex-end; }

.chat-container { height: calc(100dvh - 72px); max-width: 820px; margin: 0 auto; }
.chat-messages { padding: 14px 4px 18px; }
.chat-bubble, .cot-toggle, .cot-content, .tool-call-line, .typing-indicator {
  box-shadow: 0 10px 30px rgba(70,58,48,0.08), inset 0 1px 0 rgba(255,255,255,0.46);
  border: 1px solid rgba(255,255,255,0.42);
}
.chat-bubble { margin-top: 7px; margin-bottom: 7px; font-size: 0.94rem; }
.chat-bubble.seb { border-radius: 18px 18px 18px 6px; }
.chat-bubble.isa { border-radius: 18px 18px 6px 18px; }
.chat-input-area { border-radius: 20px; margin: 0 6px 8px; border: 1px solid var(--glass-edge); box-shadow: var(--shadow-low); }
.isa-status-bar { margin: 0 8px 8px; border-top: 0; justify-content: center; }

.study-atmosphere { padding: 22px; margin-bottom: 18px; }
.study-atmosphere-head { display: flex; justify-content: space-between; gap: 16px; align-items: flex-start; margin-bottom: 18px; }
.study-atmosphere-head h2 { font-size: 1.25rem; font-weight: 520; color: var(--clay-rock); margin-top: 2px; }
.study-atmosphere-note { font-size: 0.76rem; color: var(--text-muted); text-align: right; }
.study-atmosphere-grid { display: grid; grid-template-columns: minmax(240px, 0.92fr) minmax(280px, 1.08fr); gap: 18px; align-items: stretch; }
.drive-map { display: grid; gap: 9px; align-content: center; }
.drive-row { min-width: 0; }
.drive-row-top { display: flex; justify-content: space-between; color: var(--text-secondary); font-size: 0.76rem; margin-bottom: 4px; }
.drive-track { height: 7px; border-radius: 999px; overflow: hidden; background: rgba(0,0,0,0.065); box-shadow: inset 0 1px 2px rgba(0,0,0,0.08); }
.drive-track span { display: block; width: var(--drive); height: 100%; border-radius: inherit; background: linear-gradient(90deg, var(--clay-dusk), var(--clay-mountain)); box-shadow: 0 0 16px rgba(196,168,155,0.34); }
.stars-section { margin-top: 0; }
.stars-constellation { padding: 0; display: block; }
.star-curve-card { position: relative; min-height: 190px; padding: 14px 14px 48px; border-radius: 16px; background: linear-gradient(180deg, rgba(255,255,255,0.34), rgba(255,255,255,0.18)); border: 1px solid var(--glass-edge); overflow: hidden; box-shadow: inset 0 1px 0 rgba(255,255,255,0.38); }
.star-curve-card svg { width: 100%; height: 136px; overflow: visible; }
.star-curve-fill { fill: rgba(196,168,155,0.16); }
.star-curve-line { fill: none; stroke: var(--clay-rock); stroke-width: 3; stroke-linecap: round; stroke-linejoin: round; vector-effect: non-scaling-stroke; }
.star-curve-card circle { fill: var(--glass-strong); stroke: var(--clay-rock); stroke-width: 2; vector-effect: non-scaling-stroke; }
.star-curve-card text { fill: var(--text-muted); font-size: 9px; }
.star-current { position: absolute; left: 16px; right: 16px; bottom: 14px; display: flex; justify-content: space-between; gap: 12px; align-items: center; color: var(--text-secondary); font-size: 0.82rem; }
.star-current span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.star-current strong { color: var(--clay-rock); font-weight: 560; }

.study-tabs { border: 1px solid var(--glass-edge); box-shadow: var(--shadow-low); background: rgba(255,255,255,0.34); }
.timeline { padding: 6px 2px; }
.timeline-item { border-bottom: 1px solid var(--line-soft); padding: 12px 2px; align-items: flex-start; }
.timeline-time { color: var(--clay-rock); font-variant-numeric: tabular-nums; }
.timeline-content { display: flex; flex-direction: column; gap: 3px; min-width: 0; }
.timeline-title { color: var(--text-primary); line-height: 1.55; white-space: pre-wrap; overflow-wrap: anywhere; }
.timeline-meta { color: var(--text-muted); font-size: 0.72rem; }
.library-card, .diary-entry { box-shadow: var(--shadow-low); }

.workshop-shell { display: grid; gap: 18px; }
.workshop-subset { padding: 20px; }
.ops-section-title { margin: 0 0 14px; display: flex; align-items: center; gap: 7px; }
.ops-grid, .safety-grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 10px; }
.ops-card { padding: 14px; border-radius: 14px; background: rgba(255,255,255,0.28); border: 1px solid var(--line-soft); box-shadow: inset 0 1px 0 rgba(255,255,255,0.28); }
.ops-card .value { font-size: 1.26rem; line-height: 1.2; }
.ops-card .value.compact { font-size: 0.9rem; overflow-wrap: anywhere; }
.render-debug { margin-top: 12px; display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; }
.render-debug div { display: flex; justify-content: space-between; gap: 12px; padding: 9px 10px; border-radius: 12px; background: rgba(0,0,0,0.035); color: var(--text-secondary); font-size: 0.78rem; }
.render-debug strong { color: var(--text-primary); font-weight: 520; text-align: right; }

@media (max-width: 768px) {
  .main-content { padding: 0; }
  .room-panel { padding: 14px; }
  .foyer-grid { min-height: calc(100dvh - 72px); justify-content: flex-start; padding-top: 18px; }
  .status-card .status-grid[style] { grid-template-columns: 1fr !important; }
  .today-summary { display: block; }
  .today-summary .stats { justify-content: flex-start; margin-top: 8px; }
  .study-atmosphere { padding: 16px; }
  .study-atmosphere-head, .study-atmosphere-grid { display: block; }
  .study-atmosphere-note { text-align: left; margin-top: 4px; }
  .stars-section { margin-top: 16px; }
  .ops-grid, .safety-grid, .render-debug { grid-template-columns: 1fr; }
}


/* ===== Sidebar and Sebastian typing polish ===== */
.sidebar {
  position: relative;
  padding: 22px 14px;
  overflow: hidden;
}
.sidebar::before,
.sidebar::after {
  content: '';
  position: absolute;
  top: 0;
  bottom: 0;
  width: 14px;
  background: radial-gradient(circle at 7px 10px, var(--bg-primary) 0 4px, transparent 4.5px) repeat-y;
  background-size: 14px 22px;
  opacity: 0.72;
  pointer-events: none;
}
.sidebar::before { left: -7px; }
.sidebar::after { right: -7px; }
.sidebar-header {
  position: relative;
  padding: 4px 8px 18px;
  margin-bottom: 14px;
  border-bottom: 1px dashed var(--line-soft);
}
.sidebar-illustration {
  width: 72px;
  height: 54px;
  border-radius: 20px;
  margin-bottom: 10px;
  background:
    radial-gradient(circle at 31% 46%, rgba(61,61,61,0.76) 0 8px, transparent 9px),
    radial-gradient(circle at 66% 46%, rgba(196,168,155,0.82) 0 8px, transparent 9px),
    linear-gradient(145deg, rgba(255,255,255,0.42), rgba(255,255,255,0.14));
  border: 1px solid var(--glass-edge);
  box-shadow: inset 0 1px 0 rgba(255,255,255,0.48), var(--shadow-low);
  opacity: 1;
}
.sidebar-illustration i { display: none; }
.sidebar-header h1 { font-size: 1.05rem; letter-spacing: 0.03em; }
.sidebar-header .subtitle { font-size: 0.72rem; }
.sidebar-ticket-cut { display: none; }
.nav-list {
  display: flex;
  flex-direction: column;
  gap: 5px;
  padding: 2px 0;
}
.nav-item {
  position: relative;
  min-height: 42px;
  padding: 10px 12px;
  border-radius: 14px;
  color: var(--text-secondary);
}
.nav-item .icon {
  width: 24px;
  height: 24px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: 9px;
  color: var(--clay-rock);
  background: rgba(255,255,255,0.22);
}
.nav-item .nav-label {
  flex: 1;
  line-height: 1;
}
.nav-item.active {
  background: linear-gradient(145deg, rgba(255,255,255,0.68), rgba(255,255,255,0.36));
  color: var(--text-primary);
  transform: translateX(2px);
}
.nav-item.active::before {
  content: '';
  position: absolute;
  left: -5px;
  top: 11px;
  bottom: 11px;
  width: 3px;
  border-radius: 999px;
  background: var(--clay-rock);
  box-shadow: 0 0 14px rgba(139,115,85,0.34);
}
.nav-item.active .icon {
  background: var(--clay-rock);
  color: white;
}
.sidebar-footer {
  margin: 12px 4px 0;
  padding: 12px 10px 2px;
  border-top: 1px dashed var(--line-soft);
}
.online-indicator {
  justify-content: center;
  padding: 8px 10px;
  border-radius: 999px;
  background: rgba(255,255,255,0.24);
  border: 1px solid var(--line-soft);
}

.typing-indicator {
  margin: 7px auto 7px 16px;
  border-radius: 18px 18px 18px 6px;
  align-self: flex-start;
}
@media (max-width: 768px) {
  .typing-indicator { margin-left: 8px; }
}

/* Mobile layout hard reset: sidebar must not occupy flex width. */
@media (max-width: 768px) {
  html, body {
    width: 100%;
    max-width: 100%;
    overflow-x: hidden;
  }
  .app-layout {
    display: block;
    width: 100%;
    min-width: 0;
  }
  .sidebar {
    position: fixed;
    left: 0;
    top: 0;
    bottom: 0;
    width: min(82vw, 286px);
    max-width: 286px;
    transform: translateX(-100%);
    z-index: 20;
  }
  .sidebar.open {
    transform: translateX(0);
  }
  .main-content {
    width: 100%;
    min-width: 0;
    height: var(--app-height);
    margin: 0;
    padding: 0;
    overflow-x: hidden;
  }
  .room-panel {
    width: 100%;
    max-width: 100%;
    margin: 0;
  }
  #bedroom {
    height: calc(var(--app-height) - 52px);
    min-height: 0;
    overflow: hidden;
  }
  #bedroom .chat-container {
    height: 100%;
    max-width: none;
  }
  #bedroom .chat-messages {
    padding: 10px 4px 14px;
  }
  #bedroom .chat-input-area {
    flex-shrink: 0;
    margin-bottom: 8px;
  }
}
