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

html, body {
  height: 100%;
  overflow: hidden;
  background: #ffffff;
  font-family: 'Libre Caslon Text', Georgia, 'Times New Roman', serif;
  font-size: 15px;
  line-height: 1.6;
  color: #000000;
}

/* ---- layout ---- */
#app {
  display: flex;
  flex-direction: column;
  height: 100dvh;
  max-width: 800px;
  margin: 0 auto;
  padding: 0 24px;
  position: relative;
}

/* ---- messages area ---- */
#messages {
  flex: 1;
  overflow-y: auto;
  padding: 80px 0 24px 0;
  display: flex;
  flex-direction: column;
  gap: 20px;
  scrollbar-width: none;
  font-size: 18px;
}
#messages::-webkit-scrollbar {
  display: none;
}

.msg {
  max-width: 100%;
  white-space: pre-wrap;
  word-wrap: break-word;
  animation: fadeUp 0.3s ease both;
}

.msg.user {
  color: #999999;
  text-align: right;
  position: relative;
}

/* ---- edit button (below message, on hover) ---- */
.edit-btn-wrap {
  display: flex;
  justify-content: flex-end;
  margin-top: 6px;
  opacity: 0;
  transition: opacity 0.15s ease;
}

.msg.user:hover .edit-btn-wrap {
  opacity: 1;
}

/* Touch devices: no hover, so always show the edit button */
@media (hover: none) {
  .edit-btn-wrap {
    opacity: 0.6;
  }
}

.edit-btn {
  background: #ffffff;
  border: 1px solid #e0e0e0;
  border-radius: 16px;
  cursor: pointer;
  color: #999;
  padding: 5px 10px;
  display: flex;
  align-items: center;
  gap: 4px;
  font-family: inherit;
  font-size: 11px;
  transition: color 0.15s ease, border-color 0.15s ease;
}

.edit-btn:hover {
  color: #000;
  border-color: #ccc;
}

/* ---- inline editing state ---- */
.msg.user.editing {
  text-align: right;
}

.edit-inline-wrap {
  display: flex;
  align-items: flex-end;
  gap: 8px;
  justify-content: flex-end;
}

.edit-textarea {
  flex: 1;
  border: 1px solid #e0e0e0;
  border-radius: 20px;
  padding: 10px 16px;
  font-family: inherit;
  font-size: 20px;
  line-height: 1.5;
  color: #999999;
  background: #ffffff;
  resize: none;
  outline: none;
  text-align: right;
  overflow-y: auto;
  scrollbar-width: none;
  transition: border-color 0.15s ease;
}
.edit-textarea::-webkit-scrollbar { display: none; }

.edit-textarea:focus {
  border-color: #000000;
}

.edit-submit-btn {
  flex-shrink: 0;
  width: 36px;
  height: 36px;
  border-radius: 50%;
  border: none;
  background: #000000;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: transform 0.15s ease;
}
.edit-submit-btn:hover {
  transform: scale(1.05);
}
.edit-submit-btn:active {
  transform: scale(0.95);
}

.msg.ai {
  color: #000000;
  text-align: left;
}

/* ---- rendered markdown inside AI messages ---- */
.msg.ai p { margin: 0 0 0.6em 0; }
.msg.ai p:last-child { margin-bottom: 0; }
.msg.ai strong, .msg.ai b { font-weight: 700; }
.msg.ai em, .msg.ai i { font-style: italic; }
.msg.ai h1, .msg.ai h2, .msg.ai h3, .msg.ai h4 {
  font-weight: 700;
  margin: 1em 0 0.4em 0;
  line-height: 1.3;
}
.msg.ai h1 { font-size: 1.3em; }
.msg.ai h2 { font-size: 1.15em; }
.msg.ai h3 { font-size: 1.05em; }
.msg.ai h4 { font-size: 1em; }
.msg.ai ul, .msg.ai ol {
  margin: 0.4em 0 0.6em 1.4em;
  padding: 0;
}
.msg.ai li { margin-bottom: 0.25em; }
.msg.ai code {
  font-family: 'SF Mono', 'Fira Code', 'Consolas', monospace;
  font-size: 0.88em;
  background: #f5f5f5;
  border-radius: 4px;
  padding: 2px 5px;
}
.msg.ai pre {
  background: #f5f5f5;
  border-radius: 8px;
  padding: 14px 16px;
  overflow-x: auto;
  margin: 0.6em 0;
  font-size: 0.85em;
  line-height: 1.5;
}
.msg.ai pre code {
  background: none;
  padding: 0;
  border-radius: 0;
}
.msg.ai blockquote {
  border-left: 3px solid #e0e0e0;
  margin: 0.6em 0;
  padding: 0.2em 0 0.2em 16px;
  color: #666;
}
.msg.ai hr {
  border: none;
  border-top: 1px solid #e8e8e8;
  margin: 1em 0;
}
.msg.ai a {
  color: #000;
  text-decoration: underline;
  text-underline-offset: 2px;
  text-decoration-color: #ccc;
  transition: text-decoration-color 0.15s;
}
.msg.ai a:hover {
  text-decoration-color: #000;
}
.msg.ai table {
  border-collapse: collapse;
  margin: 0.6em 0;
  font-size: 0.92em;
  width: 100%;
  display: block;
  overflow-x: auto;
}
.msg.ai th, .msg.ai td {
  border: 1px solid #e0e0e0;
  padding: 6px 10px;
  text-align: left;
}
.msg.ai th {
  font-weight: 700;
  background: #fafafa;
}

.msg.ai.loading .cursor {
  display: inline-block;
  width: 6px;
  height: 15px;
  background: #000;
  margin-left: 2px;
  vertical-align: text-bottom;
  animation: blink 0.8s step-end infinite;
}

@keyframes blink {
  50% { opacity: 0; }
}

/* ---- Streaming sentence fade-in ---- */
.stream-cursor {
  display: inline-block;
  width: 6px;
  height: 15px;
  background: #000;
  margin-left: 2px;
  vertical-align: text-bottom;
  animation: blink 0.8s step-end infinite;
}

/* ---- Tool-call status indicator ---- */
.msg.ai.tool-working {
  min-height: 24px;
}

.tool-status {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  color: #888;
  font-size: 0.92em;
  animation: statusFadeIn 0.25s ease both;
}

.tool-status::before {
  content: '';
  display: inline-block;
  width: 14px;
  height: 14px;
  border: 2px solid #ddd;
  border-top-color: #888;
  border-radius: 50%;
  animation: statusSpin 0.7s linear infinite;
  flex-shrink: 0;
}

@keyframes statusFadeIn {
  from { opacity: 0; transform: translateY(4px); }
  to   { opacity: 1; transform: translateY(0); }
}

@keyframes statusSpin {
  to { transform: rotate(360deg); }
}

@keyframes fadeUp {
  from {
    opacity: 0;
    transform: translateY(8px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

/* ---- empty state ---- */
#empty {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
}
#empty span {
  color: #cccccc;
  font-size: 14px;
  letter-spacing: 0.02em;
}

/* ---- input area ---- */
#input-area {
  flex-shrink: 0;
  padding: 16px 0 max(env(safe-area-inset-bottom, 16px), 16px) 0;
}

#input-wrap {
  display: flex;
  align-items: center;
  border: 1px solid #e0e0e0;
  border-radius: 28px;
  padding: 4px 6px 4px 20px;
  transition: border-color 0.2s ease;
  background: #ffffff;
}

#input-wrap:focus-within {
  border-color: #000000;
}

#input {
  flex: 1;
  border: none;
  outline: none;
  font-family: inherit;
  font-size: 15px;
  line-height: 1.5;
  padding: 10px 0;
  background: transparent;
  color: #000000;
  resize: none;
  overflow-y: auto;
  scrollbar-width: none;
}
#input::-webkit-scrollbar { display: none; }
#input::placeholder {
  color: #cccccc;
}

#send {
  flex-shrink: 0;
  width: 40px;
  height: 40px;
  border-radius: 50%;
  border: none;
  background: #000000;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: opacity 0.15s ease, transform 0.15s ease;
  opacity: 0.25;
  pointer-events: none;
}

#send.active {
  opacity: 1;
  pointer-events: auto;
}
#send.active:hover {
  transform: scale(1.05);
}
#send.active:active {
  transform: scale(0.95);
}

#send svg {
  width: 18px;
  height: 18px;
  fill: none;
  stroke: #ffffff;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
}

/* ---- auth screen ---- */
#auth-screen {
  position: fixed;
  inset: 0;
  background: #ffffff;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 32px;
  z-index: 100;
}

#auth-screen p {
  color: #999999;
  font-size: 14px;
  text-align: center;
  max-width: 280px;
  line-height: 1.6;
}

#auth-btn {
  padding: 14px 36px;
  border: 1px solid #e0e0e0;
  border-radius: 28px;
  background: #ffffff;
  color: #000000;
  font-family: inherit;
  font-size: 14px;
  font-weight: 700;
  cursor: pointer;
  transition: background 0.15s ease, border-color 0.15s ease;
  letter-spacing: 0.01em;
}
#auth-btn:hover {
  background: #fafafa;
  border-color: #000000;
}

/* ---- loading screen ---- */
#loading-screen {
  position: fixed;
  inset: 0;
  background: #ffffff;
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 200;
  transition: opacity 0.3s ease;
}
#loading-screen.hidden {
  opacity: 0;
  pointer-events: none;
}
.spinner {
  width: 20px;
  height: 20px;
  border: 2px solid #e0e0e0;
  border-top-color: #000;
  border-radius: 50%;
  animation: spin 0.6s linear infinite;
}
@keyframes spin {
  to { transform: rotate(360deg); }
}

/* ---- settings bar (gear button on chat page) ---- */
#settings-bar {
  position: fixed;
  top: max(env(safe-area-inset-top, 16px), 16px);
  left: max(env(safe-area-inset-left, 16px), 16px);
  z-index: 10;
}
#settings-btn {
  background: none;
  border: none;
  border-radius: 8px;
  width: 36px;
  height: 36px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  color: #999;
  transition: color 0.15s, background-color 0.15s;
}
#settings-btn:hover { color: #000; background-color: rgba(0,0,0,0.05); }

/* ===========================================================================
   FULL-SCREEN SETTINGS PAGE
   =========================================================================== */

#settings-page {
  display: none;
  position: fixed;
  inset: 0;
  background: #ffffff;
  z-index: 80;
  animation: settingsIn 0.25s ease both;
}
#settings-page.closing {
  animation: settingsOut 0.2s ease both;
}

@keyframes settingsIn {
  from { opacity: 0; transform: translateX(40px); }
  to   { opacity: 1; transform: translateX(0); }
}
@keyframes settingsOut {
  from { opacity: 1; transform: translateX(0); }
  to   { opacity: 0; transform: translateX(40px); }
}

/* ---- sidebar nav ---- */
#settings-nav {
  position: fixed;
  top: 0;
  left: 0;
  width: 220px;
  height: 100dvh;
  border-right: 1px solid #f0f0f0;
  padding: 24px 16px;
  display: flex;
  flex-direction: column;
  gap: 4px;
  z-index: 2;
}

#settings-back {
  display: flex;
  align-items: center;
  gap: 8px;
  background: none;
  border: none;
  cursor: pointer;
  color: #999;
  font-family: inherit;
  font-size: 13px;
  padding: 8px 8px;
  margin-bottom: 24px;
  border-radius: 8px;
  transition: color 0.15s, background 0.15s;
}
#settings-back:hover {
  color: #000;
  background: #fafafa;
}

#settings-nav-items {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.settings-tab {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  border: none;
  background: none;
  cursor: pointer;
  font-family: inherit;
  font-size: 13px;
  color: #999;
  border-radius: 8px;
  transition: color 0.15s, background 0.15s;
  text-align: left;
  width: 100%;
}
.settings-tab:hover {
  color: #000;
  background: #fafafa;
}
.settings-tab.active {
  color: #000;
  background: #f5f5f5;
  font-weight: 700;
}
.settings-tab svg {
  flex-shrink: 0;
}

/* ---- content area ---- */
#settings-content {
  margin-left: 220px;
  height: 100dvh;
  overflow-y: auto;
  scrollbar-width: none;
  padding: 48px 48px 80px 48px;
  max-width: 720px;
}
#settings-content::-webkit-scrollbar { display: none; }

/* ---- tab panes ---- */
.tab-pane {
  display: none;
  animation: fadeUp 0.2s ease both;
}
.tab-pane.active {
  display: block;
}
.tab-pane[data-pane="graph"].active {
  display: block;
  height: 100%;
  position: relative;
}

.tab-header {
  margin-bottom: 32px;
}
.tab-header h1 {
  font-size: 24px;
  font-weight: 700;
  letter-spacing: -0.01em;
  margin-bottom: 8px;
}
.tab-header p {
  font-size: 14px;
  color: #999;
  line-height: 1.6;
}

/* ---- settings cards ---- */
.settings-card {
  border: 1px solid #e8e8e8;
  border-radius: 12px;
  padding: 24px;
  margin-bottom: 16px;
}
.settings-card.muted {
  border-style: dashed;
  border-color: #e0e0e0;
  opacity: 0.6;
}
.settings-card-header {
  margin-bottom: 8px;
}
.settings-card-title {
  font-weight: 700;
  font-size: 15px;
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 4px;
}
.settings-card-desc {
  font-size: 13px;
  color: #999;
  line-height: 1.5;
}

/* ---- shared button styles ---- */
.settings-card button,
#memory-actions button {
  padding: 8px 20px;
  border: 1px solid #e0e0e0;
  border-radius: 20px;
  background: #fff;
  font-family: inherit;
  font-size: 13px;
  font-weight: 700;
  cursor: pointer;
  transition: border-color 0.15s, color 0.15s;
}
.settings-card button:hover,
#memory-actions button:hover {
  border-color: #000;
}
.btn-danger {
  color: #999 !important;
}
.btn-danger:hover {
  border-color: #c00 !important;
  color: #c00 !important;
}

/* ---- Hue-specific ---- */
#hue-setup-body p {
  font-size: 13px;
  line-height: 1.5;
  color: #666;
}
.hint {
  font-size: 12px !important;
  color: #999 !important;
  margin: 8px 0;
}
.hue-row {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 10px;
}
.hue-or {
  color: #ccc;
  font-size: 12px;
}
#hue-ip-input {
  border: 1px solid #e0e0e0;
  border-radius: 8px;
  padding: 8px 12px;
  font-family: inherit;
  font-size: 13px;
  width: 100%;
  max-width: 280px;
  outline: none;
  transition: border-color 0.15s;
}
#hue-ip-input:focus { border-color: #000; }
#hue-status, #google-status, #spotify-status {
  font-size: 12px;
}
.status-dot {
  display: inline-block;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  margin-right: 6px;
  vertical-align: middle;
}
.status-dot.on { background: #2a2; }
.status-dot.off { background: #ccc; }
.hue-dot {
  display: inline-block;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  margin-right: 6px;
  vertical-align: middle;
}
.hue-dot.on { background: #2a2; }
.hue-dot.off { background: #ccc; }
#hue-error, #spotify-error {
  color: #c00;
  font-size: 13px;
  margin-top: 8px;
  display: none;
}

/* ---- Presence detection ---- */
#presence-status {
  font-size: 12px;
}
#presence-error {
  color: #c00;
  font-size: 13px;
  margin-top: 8px;
  display: none;
}
#presence-mac-input {
  border: 1px solid #e0e0e0;
  border-radius: 8px;
  padding: 8px 12px;
  font-family: 'SF Mono', 'Fira Code', 'Consolas', monospace;
  font-size: 13px;
  width: 100%;
  max-width: 280px;
  outline: none;
  transition: border-color 0.15s;
  letter-spacing: 0.5px;
}
#presence-mac-input:focus { border-color: #000; }
.presence-toggle-row {
  margin-bottom: 12px;
}
.toggle-label {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 14px;
  cursor: pointer;
}
.toggle-label input[type="checkbox"] {
  width: 18px;
  height: 18px;
  accent-color: #000;
  cursor: pointer;
}
.presence-device-btn {
  display: block;
  width: 100%;
  text-align: left;
  padding: 8px 12px;
  margin: 4px 0;
  border: 1px solid #e0e0e0;
  border-radius: 8px;
  background: #fafafa;
  font-family: 'SF Mono', 'Fira Code', 'Consolas', monospace;
  font-size: 12px;
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s;
}
.presence-device-btn:hover {
  background: #f0f0f0;
  border-color: #000;
}

/* ---- Google / Spotify connection cards ---- */
.service-list {
  font-size: 12px;
  color: #999;
  margin-top: 4px;
  margin-bottom: 12px;
  letter-spacing: 0.02em;
}
#google-setup-body, #spotify-setup-body {
  margin-top: 12px;
}
#spotify-user-name {
  font-size: 13px;
  color: #666;
  margin-right: 12px;
}
#spotify-step-done {
  display: flex;
  align-items: center;
  gap: 8px;
}

/* ---- memory section ---- */
.count-badge {
  font-weight: 400;
  font-size: 14px;
  color: #ccc;
}
.memory-empty {
  font-size: 14px;
  color: #ccc;
  font-style: italic;
  padding: 24px 0;
}
#memory-list {
  display: flex;
  flex-direction: column;
  gap: 2px;
}
.memory-category {
  font-size: 11px;
  font-weight: 700;
  color: #999;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  margin-top: 20px;
  margin-bottom: 6px;
  padding-bottom: 6px;
  border-bottom: 1px solid #f0f0f0;
}
.memory-category:first-child {
  margin-top: 0;
}
.memory-item {
  display: flex;
  align-items: flex-start;
  gap: 12px;
  padding: 10px 0;
  font-size: 14px;
  line-height: 1.5;
  color: #333;
  border-bottom: 1px solid #fafafa;
}
.memory-item:last-child {
  border-bottom: none;
}
.memory-item-text {
  flex: 1;
  min-width: 0;
}
.memory-delete-btn {
  flex-shrink: 0;
  background: none;
  border: none;
  cursor: pointer;
  color: #ddd;
  font-size: 16px;
  line-height: 1;
  padding: 2px 4px;
  border-radius: 4px;
  transition: color 0.15s, background 0.15s;
}
.memory-delete-btn:hover {
  color: #c00;
  background: #fff0f0;
}
#memory-actions {
  margin-top: 20px;
  padding-top: 16px;
  border-top: 1px solid #f0f0f0;
}

/* ---- knowledge graph full-panel ---- */
#settings-content.graph-active {
  padding: 0;
  max-width: none;
  width: calc(100% - 220px);
  overflow: hidden;
  position: relative;
}
#graph-fullpanel {
  position: absolute;
  inset: 0;
  background: #f8f9fa;
  background-image: radial-gradient(circle, #e4e6e8 0.8px, transparent 0.8px);
  background-size: 24px 24px;
  overflow: hidden;
}
#graph-fullpanel #graph-canvas {
  width: 100%;
  height: 100%;
  display: block;
  cursor: grab;
}
#graph-fullpanel #graph-canvas:active {
  cursor: grabbing;
}
#graph-fullpanel #graph-empty {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  pointer-events: none;
}
#graph-fullpanel #graph-empty p {
  font-size: 13px;
  color: #ccc;
  font-style: italic;
}
#graph-fullpanel #graph-tooltip {
  position: absolute;
  display: none;
  background: #fff;
  border: 1px solid #e0e0e0;
  border-radius: 8px;
  padding: 8px 12px;
  font-size: 12px;
  color: #333;
  pointer-events: none;
  box-shadow: 0 2px 8px rgba(0,0,0,0.06);
  max-width: 220px;
  z-index: 10;
  line-height: 1.5;
}
#graph-fullpanel #graph-tooltip .tt-name {
  font-weight: 700;
  margin-bottom: 2px;
}
#graph-fullpanel #graph-tooltip .tt-type {
  color: #999;
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}
#graph-fullpanel #graph-tooltip .tt-edges {
  margin-top: 4px;
  font-size: 11px;
  color: #666;
}
#graph-fullpanel #graph-legend {
  position: absolute;
  bottom: 16px;
  left: 20px;
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
  max-width: calc(100% - 280px);
}
#graph-overlay-top {
  position: absolute;
  top: 20px;
  left: 24px;
  pointer-events: none;
  display: flex;
  align-items: center;
  gap: 16px;
}
#graph-overlay-title {
  font-weight: 700;
  font-size: 15px;
  color: #333;
  display: flex;
  align-items: center;
  gap: 10px;
}
#graph-search {
  pointer-events: auto;
  border: 1px solid #e0e0e0;
  border-radius: 16px;
  padding: 5px 14px;
  font-family: inherit;
  font-size: 12px;
  width: 160px;
  outline: none;
  background: #fff;
  transition: border-color 0.15s, width 0.2s;
}
#graph-search:focus {
  border-color: #999;
  width: 200px;
}
#graph-search::placeholder {
  color: #ccc;
}
#graph-overlay-actions {
  position: absolute;
  bottom: 16px;
  right: 20px;
  display: flex;
  align-items: center;
  gap: 8px;
}
#graph-rebuild-btn,
#graph-reset-btn {
  font-size: 12px;
  padding: 6px 16px;
  color: #999;
  border: 1px solid #e0e0e0;
  border-radius: 16px;
  background: #fff;
  cursor: pointer;
  font-family: inherit;
  font-weight: 600;
  transition: border-color 0.15s, color 0.15s;
}
#graph-rebuild-btn:hover,
#graph-reset-btn:hover {
  border-color: #000;
  color: #000;
}
#graph-rebuild-btn:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}
.legend-item {
  display: flex;
  align-items: center;
  gap: 4px;
  font-size: 10px;
  color: #777;
  text-transform: uppercase;
  letter-spacing: 0.03em;
  cursor: pointer;
  user-select: none;
  padding: 3px 8px;
  border-radius: 10px;
  background: rgba(255,255,255,0.85);
  border: 1px solid #eee;
  transition: opacity 0.15s, border-color 0.15s;
}
.legend-item:hover {
  border-color: #ccc;
}
.legend-item.legend-hidden {
  opacity: 0.35;
  text-decoration: line-through;
}
.legend-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  flex-shrink: 0;
}

/* ---- toast notification ---- */
#toast {
  position: fixed;
  bottom: 100px;
  left: 50%;
  transform: translateX(-50%) translateY(10px);
  background: #ffffff;
  border: 1px solid #e0e0e0;
  border-radius: 20px;
  padding: 8px 20px;
  font-family: inherit;
  font-size: 13px;
  color: #999;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.3s ease, transform 0.3s ease;
  z-index: 300;
}
#toast.visible {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}

/* ---- sheet card in chat ---- */
.sheet-card {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 14px 16px;
  margin-top: 10px;
  border: 1px solid #e0e0e0;
  border-radius: 12px;
  cursor: pointer;
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
  background: #fff;
}
.sheet-card:hover {
  border-color: #0f9d58;
  box-shadow: 0 2px 8px rgba(15, 157, 88, 0.08);
}
.sheet-card-icon {
  flex-shrink: 0;
  width: 40px;
  height: 40px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: #f0faf4;
  border-radius: 10px;
}
.sheet-card-info {
  flex: 1;
  min-width: 0;
}
.sheet-card-title {
  font-weight: 700;
  font-size: 14px;
  line-height: 1.3;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.sheet-card-subtitle {
  font-size: 12px;
  color: #999;
  margin-top: 2px;
}
.sheet-card-arrow {
  flex-shrink: 0;
  color: #ccc;
  transition: color 0.15s;
}
.sheet-card:hover .sheet-card-arrow {
  color: #0f9d58;
}

/* ===========================================================================
   SHEETS SIDE PANEL
   =========================================================================== */

#sheets-panel {
  position: fixed;
  top: 0;
  right: 0;
  width: 50vw;
  max-width: 720px;
  height: 100dvh;
  background: #ffffff;
  border-left: 1px solid #e8e8e8;
  z-index: 70;
  display: flex;
  flex-direction: column;
  transform: translateX(100%);
  transition: transform 0.3s ease;
}
#sheets-panel.open {
  transform: translateX(0);
}

#sheets-panel-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 16px;
  border-bottom: 1px solid #f0f0f0;
  flex-shrink: 0;
}
#sheets-panel-title {
  font-weight: 700;
  font-size: 14px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  flex: 1;
  min-width: 0;
}
#sheets-panel-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-shrink: 0;
}
#sheets-panel-open {
  color: #999;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 6px;
  border-radius: 6px;
  transition: color 0.15s, background 0.15s;
}
#sheets-panel-open:hover {
  color: #000;
  background: #f5f5f5;
}
#sheets-panel-close {
  background: none;
  border: none;
  cursor: pointer;
  color: #999;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 6px;
  border-radius: 6px;
  transition: color 0.15s, background 0.15s;
}
#sheets-panel-close:hover {
  color: #000;
  background: #f5f5f5;
}
#sheets-panel-body {
  flex: 1;
  overflow: hidden;
}
#sheets-panel-iframe {
  width: 100%;
  height: 100%;
  border: none;
}

/* Shrink the chat area when panel is open */
#app.panel-open {
  max-width: calc(100vw - 50vw);
  margin-left: 0;
  margin-right: auto;
  transition: max-width 0.3s ease;
}

/* ===========================================================================
   CALENDAR CARD (in chat messages)
   =========================================================================== */

.calendar-card {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 14px 16px;
  margin-top: 10px;
  border: 1px solid #e0e0e0;
  border-radius: 12px;
  cursor: pointer;
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
  background: #fff;
}
.calendar-card:hover {
  border-color: #4285f4;
  box-shadow: 0 2px 8px rgba(66, 133, 244, 0.08);
}
.calendar-card-icon {
  flex-shrink: 0;
  width: 40px;
  height: 40px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: #e8f0fe;
  border-radius: 10px;
}
.calendar-card-info {
  flex: 1;
  min-width: 0;
}
.calendar-card-title {
  font-weight: 700;
  font-size: 14px;
  line-height: 1.3;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.calendar-card-subtitle {
  font-size: 12px;
  color: #999;
  margin-top: 2px;
}
.calendar-card-arrow {
  flex-shrink: 0;
  color: #ccc;
  transition: color 0.15s;
}
.calendar-card:hover .calendar-card-arrow {
  color: #4285f4;
}

/* ===========================================================================
   CALENDAR SIDE PANEL
   =========================================================================== */

#calendar-panel {
  position: fixed;
  top: 0;
  right: 0;
  width: 340px;
  max-width: 90vw;
  height: 100dvh;
  background: #ffffff;
  border-left: 1px solid #e8e8e8;
  box-shadow: -4px 0 24px rgba(0,0,0,0.08);
  z-index: 70;
  display: flex;
  flex-direction: column;
  transform: translateX(100%);
  transition: transform 0.3s ease;
}
#calendar-panel.open {
  transform: translateX(0);
}

#calendar-panel-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 16px;
  border-bottom: 1px solid #f0f0f0;
  flex-shrink: 0;
}
#calendar-panel-title {
  font-weight: 700;
  font-size: 14px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  flex: 1;
  min-width: 0;
}
#calendar-panel-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-shrink: 0;
}
#calendar-panel-open {
  color: #999;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 6px;
  border-radius: 6px;
  transition: color 0.15s, background 0.15s;
}
#calendar-panel-open:hover {
  color: #000;
  background: #f5f5f5;
}
#calendar-panel-close {
  background: none;
  border: none;
  cursor: pointer;
  color: #999;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 6px;
  border-radius: 6px;
  transition: color 0.15s, background 0.15s;
}
#calendar-panel-close:hover {
  color: #000;
  background: #f5f5f5;
}
#calendar-panel-body {
  flex: 1;
  overflow-y: auto;
  padding: 0;
}
#calendar-panel-loading {
  padding: 24px;
  text-align: center;
  color: #999;
  font-size: 13px;
}
#calendar-panel-agenda {
  padding: 0 0 24px;
}

/* Agenda day groups */
.cal-day-group {
  padding: 0 16px;
}
.cal-day-group + .cal-day-group {
  margin-top: 4px;
}
.cal-day-label {
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: #999;
  padding: 12px 0 6px;
  position: sticky;
  top: 0;
  background: #fff;
  z-index: 1;
}
.cal-event {
  display: flex;
  align-items: flex-start;
  gap: 12px;
  padding: 10px 0;
  border-bottom: 1px solid #f5f5f5;
}
.cal-event:last-child {
  border-bottom: none;
}
.cal-event-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: #4285f4;
  flex-shrink: 0;
  margin-top: 5px;
}
.cal-event-details {
  flex: 1;
  min-width: 0;
}
.cal-event-title {
  font-size: 14px;
  font-weight: 600;
  line-height: 1.3;
}
.cal-event-time {
  font-size: 12px;
  color: #999;
  margin-top: 2px;
}
.cal-event-location {
  font-size: 12px;
  color: #bbb;
  margin-top: 1px;
}
.cal-empty {
  padding: 40px 24px;
  text-align: center;
  color: #bbb;
  font-size: 14px;
}

/* ===========================================================================
   ATTACH BUTTON
   =========================================================================== */

#attach-btn {
  flex-shrink: 0;
  width: 36px;
  height: 36px;
  border-radius: 50%;
  border: none;
  background: none;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  color: #bbb;
  transition: color 0.15s ease;
  padding: 0;
}
#attach-btn:hover {
  color: #000;
}

/* ===========================================================================
   DROP OVERLAY
   =========================================================================== */

#drop-overlay {
  position: fixed;
  inset: 0;
  background: rgba(255, 255, 255, 0.92);
  z-index: 500;
  display: flex;
  align-items: center;
  justify-content: center;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s ease;
}
#drop-overlay.visible {
  opacity: 1;
  pointer-events: auto;
}
#drop-overlay-content {
  text-align: center;
  color: #999;
}
#drop-overlay-content svg {
  margin-bottom: 12px;
  color: #ccc;
}
#drop-overlay-content p {
  font-size: 15px;
  font-weight: 700;
  letter-spacing: 0.01em;
}

/* ===========================================================================
   ATTACHMENT CHIPS
   =========================================================================== */

#attachments {
  display: none;
  flex-wrap: wrap;
  gap: 8px;
  padding: 0 0 10px 0;
}

.attach-chip {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 6px 10px;
  border: 1px solid #e0e0e0;
  border-radius: 10px;
  background: #fafafa;
  font-size: 13px;
  color: #333;
  max-width: 220px;
  animation: fadeUp 0.2s ease both;
}
.attach-chip-preview {
  width: 32px;
  height: 32px;
  border-radius: 6px;
  object-fit: cover;
  flex-shrink: 0;
}
.attach-chip-icon {
  flex-shrink: 0;
  width: 20px;
  height: 20px;
  display: flex;
  align-items: center;
  justify-content: center;
}
.attach-chip-name {
  flex: 1;
  min-width: 0;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.attach-chip-remove {
  flex-shrink: 0;
  background: none;
  border: none;
  cursor: pointer;
  color: #ccc;
  font-size: 16px;
  line-height: 1;
  padding: 0 2px;
  border-radius: 4px;
  transition: color 0.15s;
}
.attach-chip-remove:hover {
  color: #c00;
}

/* ---- upload spinner inside chip ---- */
.attach-spinner {
  width: 14px;
  height: 14px;
  border: 2px solid #e0e0e0;
  border-top-color: #999;
  border-radius: 50%;
  animation: spin 0.6s linear infinite;
}

/* ---- mobile responsive ---- */
@media (max-width: 640px) {
  /* Tighter side padding on small screens */
  #app {
    padding: 0 16px;
  }
  #messages {
    padding-top: 56px;
  }

  /* Larger touch targets */
  #settings-btn {
    width: 44px;
    height: 44px;
  }
  #attach-btn {
    width: 44px;
    height: 44px;
  }
  #send {
    width: 44px;
    height: 44px;
  }

  #settings-nav {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    width: 100%;
    height: auto;
    border-right: none;
    border-bottom: 1px solid #f0f0f0;
    padding: 12px 16px;
    flex-direction: row;
    align-items: center;
    gap: 0;
    background: #fff;
    z-index: 3;
  }

  #settings-back {
    margin-bottom: 0;
    margin-right: 8px;
    padding: 8px;
  }
  #settings-back span { display: none; }

  #settings-nav-items {
    flex-direction: row;
    gap: 0;
    flex: 1;
    overflow-x: auto;
    scrollbar-width: none;
  }
  #settings-nav-items::-webkit-scrollbar { display: none; }

  .settings-tab {
    padding: 8px 12px;
    white-space: nowrap;
    font-size: 12px;
    gap: 6px;
    border-radius: 6px;
  }
  .settings-tab svg { width: 14px; height: 14px; }

  #settings-content {
    margin-left: 0;
    padding: 80px 20px 60px 20px;
  }

  .tab-header h1 { font-size: 20px; }
  .settings-card { padding: 18px; }

  /* Graph full-panel on mobile */
  #settings-content.graph-active {
    width: 100%;
    margin-left: 0;
    padding: 0;
    height: calc(100dvh - 56px);
    margin-top: 56px;
  }

  /* Sheets panel full-width on mobile */
  #sheets-panel {
    width: 100vw;
    max-width: 100vw;
  }
  /* Calendar panel full-width on mobile */
  #calendar-panel {
    width: 100vw;
    max-width: 100vw;
    box-shadow: none;
  }
  #app.panel-open {
    display: none;
  }
}

/* ---- onboarding banner ---- */
#onboarding-banner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 16px;
  background: #f8f8f8;
  border-radius: 12px;
  margin-bottom: 8px;
  animation: onboard-slide-in 0.3s ease;
}
@keyframes onboard-slide-in {
  from { opacity: 0; transform: translateY(8px); }
  to   { opacity: 1; transform: translateY(0); }
}
#onboarding-banner.onboarding-fade-out {
  opacity: 0;
  transform: translateY(8px);
  transition: opacity 0.3s ease, transform 0.3s ease;
}
.onboarding-label {
  font-size: 12px;
  color: #999;
  font-weight: 500;
  letter-spacing: 0.02em;
}
.onboarding-btn {
  font-family: inherit;
  font-size: 12px;
  font-weight: 600;
  padding: 5px 14px;
  border-radius: 16px;
  border: 1px solid #e0e0e0;
  background: #fff;
  color: #666;
  cursor: pointer;
  transition: background 0.15s, color 0.15s, border-color 0.15s;
}
.onboarding-btn:hover {
  background: #f0f0f0;
  color: #333;
  border-color: #ccc;
}
.onboarding-finish {
  background: #000;
  color: #fff;
  border-color: #000;
}
.onboarding-finish:hover {
  background: #222;
  color: #fff;
  border-color: #222;
}