/* ============================================================================
   Marsi web — layout & components
   ============================================================================ */

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

html, body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  color: var(--on-bg);
  font-family: var(--font-sans);
  font-size: var(--body-lg);
  line-height: var(--body-lg-lh);
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

#app { height: 100%; }

button { font-family: inherit; cursor: pointer; }
a { color: var(--primary); text-decoration: none; }

:focus-visible {
  outline: 2px solid var(--primary);
  outline-offset: 2px;
  border-radius: var(--r-sm);
}

@media (prefers-reduced-motion: reduce) {
  * { animation-duration: 0.001ms !important; transition-duration: 0.001ms !important; }
}

/* ---- Utility text styles (mirror Typography) ---- */
.t-display  { font-size: var(--display-lg);  line-height: var(--display-lg-lh);  font-weight: 500; }
.t-headline { font-size: var(--headline-md); line-height: var(--headline-md-lh); font-weight: 500; }
.t-title    { font-size: var(--title-lg);    line-height: var(--title-lg-lh);    font-weight: 500; }
.t-body     { font-size: var(--body-lg);     line-height: var(--body-lg-lh); }
.t-body-md  { font-size: var(--body-md);     line-height: var(--body-md-lh); }
.t-muted    { color: var(--on-surface-variant); }
.field-label {
  font-size: var(--label-cap); font-weight: 500; letter-spacing: 1.5px;
  color: var(--on-surface-variant); text-transform: uppercase;
}

/* ============================================================================
   Buttons & inputs
   ============================================================================ */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  height: 56px; width: 100%; padding: 0 18px;
  border: none; border-radius: var(--r-sm);
  background: var(--primary); color: var(--on-primary);
  font-size: var(--body-lg); font-weight: 500; letter-spacing: 0.5px;
  transition: filter 0.15s var(--ease), opacity 0.15s var(--ease);
}
.btn:hover { filter: brightness(1.08); }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }
.btn--outline {
  background: transparent; color: var(--on-bg);
  border: 1px solid var(--outline);
}
.btn--sm { height: 44px; }
.btn--ghost { background: transparent; color: var(--primary); height: auto; width: auto; padding: 4px 6px; }

.input {
  width: 100%; height: 56px; padding: 0 14px;
  background: var(--surface); color: var(--on-bg);
  border: 1px solid var(--outline); border-radius: var(--r-sm);
  font-family: inherit; font-size: var(--body-lg);
}
.input:focus { outline: none; border-color: var(--primary); }
.input::placeholder { color: var(--on-surface-variant); opacity: 0.6; }
.input-wrap { position: relative; }
.input-wrap .trailing {
  position: absolute; right: 6px; top: 50%; transform: translateY(-50%);
  background: none; border: none; color: var(--on-surface-variant);
  display: inline-flex; padding: 8px;
}

.banner {
  border-radius: var(--r-sm); padding: 12px 14px;
  font-size: var(--body-md); line-height: var(--body-md-lh);
}
.banner--error { background: var(--error-bg); color: var(--error-fg); }
.banner--info {
  background: var(--surface); color: var(--on-bg);
  border: 1px solid var(--primary);
  display: flex; align-items: center; gap: 8px;
}

.spinner {
  width: 22px; height: 22px; border-radius: 50%;
  border: 2.5px solid color-mix(in srgb, var(--on-primary) 35%, transparent);
  border-top-color: var(--on-primary);
  animation: spin 0.7s linear infinite;
}
.spinner--page { width: 32px; height: 32px; border-width: 3px;
  border-color: color-mix(in srgb, var(--primary) 30%, transparent); border-top-color: var(--primary); }
@keyframes spin { to { transform: rotate(360deg); } }

/* ============================================================================
   Auth screens (centered column)
   ============================================================================ */
.auth {
  min-height: 100%; display: flex; flex-direction: column;
  max-width: 440px; margin: 0 auto; padding: 24px;
}
.auth__top { min-height: 40px; display: flex; align-items: center; }
.auth__brand { text-align: center; margin: 24px 0 36px; }
.auth__brand .logo { width: 40px; height: 46px; color: var(--primary); }
.auth__brand .wordmark {
  margin-top: 10px; font-size: var(--body-md); letter-spacing: 2.5px;
  color: var(--on-surface-variant);
}
.auth__spacer { flex: 1; }
.stack > * + * { margin-top: 0; }
.row-center { display: flex; justify-content: center; align-items: center; gap: 2px; }
.field + .field { margin-top: 20px; }
.field > .field-label { display: block; margin-bottom: 6px; }

/* Welcome carousel */
.welcome__logo { width: 60px; height: 70px; color: var(--primary); margin: 72px auto 20px; display: block; }
.welcome__wordmark { text-align: center; letter-spacing: 3px; font-weight: 500; }
.carousel { text-align: center; }
.carousel h2 { margin: 0 0 12px; }
.dots { display: flex; gap: 8px; justify-content: center; margin-top: 28px; }
.dot { height: 3px; width: 3px; border-radius: 2px; background: var(--outline); transition: width 0.3s var(--ease); }
.dot.active { width: 20px; background: var(--primary); }

/* ============================================================================
   App shell: drawer + content
   ============================================================================ */
.shell { display: flex; height: 100%; }

.drawer {
  width: var(--drawer-w); flex: 0 0 var(--drawer-w);
  background: var(--surface);
  border-right: 1px solid color-mix(in srgb, var(--outline) 50%, transparent);
  display: flex; flex-direction: column; padding: 8px;
}
.drawer__brand { display: flex; align-items: center; gap: 10px; padding: 12px; }
.drawer__brand .logo { width: 20px; height: 24px; color: var(--primary); }
.drawer__brand .wordmark { letter-spacing: 2.5px; font-size: var(--body-md); color: var(--on-surface-variant); }
.drawer__item {
  display: flex; align-items: center; gap: 12px; width: 100%;
  background: none; border: none; text-align: left;
  padding: 14px 12px; border-radius: var(--r-sm);
  color: var(--on-bg); font-size: var(--body-lg); font-weight: 500;
}
.drawer__item:hover { background: color-mix(in srgb, var(--primary) 10%, transparent); }
.drawer__item.active { background: color-mix(in srgb, var(--primary) 16%, transparent); }
.drawer__item--muted { color: var(--on-surface-variant); font-weight: 400; }
.drawer__divider { height: 1px; background: color-mix(in srgb, var(--outline) 50%, transparent); margin: 12px 16px; }
.drawer__spacer { flex: 1; }

.content { flex: 1; min-width: 0; display: flex; flex-direction: column; height: 100%; }
.scrim { display: none; }

/* Mobile: drawer becomes an overlay */
@media (max-width: 840px) {
  .drawer {
    position: fixed; inset: 0 auto 0 0; z-index: 30;
    transform: translateX(-100%); transition: transform 0.25s var(--ease);
    box-shadow: 0 0 40px rgba(0,0,0,0.4);
  }
  .shell.drawer-open .drawer { transform: translateX(0); }
  .scrim {
    display: block; position: fixed; inset: 0; z-index: 20;
    background: rgba(0,0,0,0.5); opacity: 0; pointer-events: none;
    transition: opacity 0.25s var(--ease);
  }
  .shell.drawer-open .scrim { opacity: 1; pointer-events: auto; }
  .menu-btn { display: inline-flex !important; }
}
.menu-btn { display: none; }

/* ---- top bar (per-screen) ---- */
.topbar {
  display: flex; align-items: center; gap: 4px;
  min-height: var(--topbar-h); padding: 8px;
  border-bottom: 1px solid color-mix(in srgb, var(--outline) 30%, transparent);
}
.topbar h1 { margin: 0 0 0 4px; }
.iconbtn {
  display: inline-flex; align-items: center; justify-content: center;
  width: 40px; height: 40px; border: none; background: none;
  color: var(--on-bg); border-radius: var(--r-sm);
}
.iconbtn:hover { background: color-mix(in srgb, var(--on-bg) 8%, transparent); }
.iconbtn:disabled { color: color-mix(in srgb, var(--on-surface-variant) 40%, transparent); }
.iconbtn--primary { color: var(--primary); }
.grow { flex: 1; }

/* ============================================================================
   Chat
   ============================================================================ */
.chat { display: flex; flex-direction: column; height: 100%; }
.chat__list { flex: 1; overflow-y: auto; padding: 16px; }
.chat__inner { max-width: var(--content-max); margin: 0 auto; }
.msg { display: flex; margin-bottom: 16px; }
.msg--user { justify-content: flex-end; }
.bubble {
  max-width: 75%; padding: 10px 14px; border-radius: var(--r-sm);
  background: var(--primary); color: var(--on-primary);
  white-space: pre-wrap; word-wrap: break-word;
}
.bubble .attach { display: inline-flex; align-items: center; gap: 6px; opacity: 0.9; }
.msg--assistant { gap: 12px; align-items: flex-start; }
.msg--assistant .logo { width: 12px; height: 14px; color: var(--primary); margin-top: 6px; flex: 0 0 auto; }
.assistant-text { white-space: pre-wrap; word-wrap: break-word; }
.sources {
  margin-top: 10px; border-top: 1px solid color-mix(in srgb, var(--outline) 40%, transparent);
  padding-top: 8px;
}
.sources summary { cursor: pointer; color: var(--on-surface-variant); font-size: var(--body-md); }
.source-item { font-size: var(--body-md); color: var(--on-surface-variant); padding: 6px 0; }
.figure-grid { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 10px; }
.figure-grid img { max-width: 220px; border-radius: var(--r-sm); border: 1px solid var(--outline); }

.chat__empty {
  flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center;
  text-align: center; padding: 24px; gap: 20px;
}
.chat__empty .logo { width: 32px; height: 36px; color: color-mix(in srgb, var(--primary) 35%, transparent); }

/* input bar */
.composer { padding: 10px 12px; }
.composer__inner { max-width: var(--content-max); margin: 0 auto; }
.staged {
  display: inline-flex; align-items: center; gap: 8px; margin-bottom: 8px;
  padding: 4px 6px 4px 10px; border: 1px solid var(--primary);
  border-radius: var(--r-sm); background: var(--surface); font-size: var(--body-md);
}
.composer__row { display: flex; align-items: flex-end; gap: 8px; }
.composer__box {
  flex: 1; display: flex; align-items: flex-end;
  background: var(--surface); border: 1px solid var(--outline);
  border-radius: var(--r-sm); padding: 4px 5px 4px 14px;
}
.composer__box.listening { border-color: var(--primary); }
.composer textarea {
  flex: 1; resize: none; border: none; background: none; color: var(--on-bg);
  font-family: inherit; font-size: 15px; line-height: 22px; padding: 10px 0; max-height: 120px;
}
.composer textarea:focus { outline: none; }
.composer textarea::placeholder { color: color-mix(in srgb, var(--on-surface-variant) 60%, transparent); }
.composer__box.listening textarea::placeholder { color: var(--primary); font-style: italic; }
.square-btn {
  flex: 0 0 auto; width: 44px; height: 44px; border-radius: var(--r-sm);
  background: var(--surface); border: 1px solid var(--outline);
  color: var(--on-surface-variant); display: inline-flex; align-items: center; justify-content: center;
}
.trailing-action {
  width: 34px; height: 34px; border-radius: var(--r-sm); border: none;
  display: inline-flex; align-items: center; justify-content: center;
  background: transparent; color: var(--on-surface-variant);
}
.trailing-action.filled { background: var(--primary); color: var(--on-primary); }
.voice-status { font-size: var(--body-sm); color: var(--on-surface-variant); padding: 4px 2px 0; min-height: 18px; }

/* ============================================================================
   Lists: documents & history
   ============================================================================ */
.view-scroll { flex: 1; overflow-y: auto; padding: 8px 16px 40px; }
.view-scroll__inner { max-width: var(--content-max); margin: 0 auto; }
.list { display: flex; flex-direction: column; gap: 8px; }

.card {
  display: flex; align-items: center; gap: 12px; width: 100%; text-align: left;
  background: var(--surface); border: 1px solid color-mix(in srgb, var(--outline) 30%, transparent);
  border-radius: var(--r-sm); padding: 10px 12px; color: var(--on-bg);
}
.card .icon { color: var(--primary); flex: 0 0 auto; }
.card .meta { flex: 1; min-width: 0; }
.card .name { font-weight: 500; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.card .sub { font-size: var(--body-sm); color: var(--on-surface-variant); margin-top: 2px;
  display: flex; gap: 8px; align-items: center; }
.badge { font-size: var(--label-cap); letter-spacing: 0.5px; }
.badge--ready { color: var(--primary); }
.badge--processing { color: var(--tertiary); }
.badge--failed { color: var(--error); }
.badge--uploaded, .badge--unknown { color: var(--on-surface-variant); }

.group-header {
  font-size: var(--label-cap); letter-spacing: 1.5px; text-transform: uppercase;
  color: var(--on-surface-variant); font-weight: 500; padding: 16px 4px 8px;
}
.session-row { background: var(--surface); border-radius: var(--r-sm); padding: 14px; width: 100%;
  text-align: left; border: none; color: var(--on-bg); }
.session-row:hover { background: color-mix(in srgb, var(--primary) 8%, transparent); }
.session-row .title { font-weight: 500; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.session-row .preview { font-size: var(--body-md); color: var(--on-surface-variant); margin-top: 4px;
  display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.session-row .when { font-size: var(--body-sm); color: color-mix(in srgb, var(--on-surface-variant) 70%, transparent); margin-top: 6px; }

.empty {
  flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center;
  text-align: center; gap: 8px; padding: 48px 24px;
}
.empty .icon { color: color-mix(in srgb, var(--primary) 35%, transparent); margin-bottom: 8px; }

.upload-banner { padding: 12px 16px; }
.progress { height: 4px; background: var(--surface-variant); border-radius: 2px; overflow: hidden; margin-top: 6px; }
.progress > div { height: 100%; background: var(--primary); transition: width 0.2s var(--ease); }

/* ============================================================================
   Settings & profile
   ============================================================================ */
.section { padding: 8px 0 28px; }
.section__head { font-size: var(--body-md); letter-spacing: 1px; text-transform: uppercase;
  color: var(--primary); font-weight: 600; margin-bottom: 14px; }
.setting-label { font-weight: 500; margin-bottom: 8px; }
.segmented {
  display: flex; border: 1px solid color-mix(in srgb, var(--outline) 60%, transparent);
  border-radius: var(--r-sm); overflow: hidden;
}
.segmented button {
  flex: 1; padding: 12px; border: none; background: var(--surface);
  color: var(--on-surface-variant); font-size: var(--body-md);
  border-right: 1px solid color-mix(in srgb, var(--outline) 50%, transparent);
}
.segmented button:last-child { border-right: none; }
.segmented button.active { background: var(--primary); color: var(--on-primary); font-weight: 500; }
.segmented button:disabled { opacity: 0.4; }
select.input { appearance: none; background-image: none; }

.switch-row { display: flex; align-items: center; gap: 12px; padding: 14px 16px;
  background: var(--surface); border-radius: var(--r-sm); }
.switch-row .meta { flex: 1; }
.switch-row .sub { font-size: var(--body-sm); color: var(--on-surface-variant); margin-top: 2px; }
.switch {
  flex: 0 0 auto; width: 44px; height: 26px; border-radius: 13px; border: none;
  background: var(--outline); position: relative; transition: background 0.15s var(--ease);
}
.switch.on { background: var(--primary); }
.switch::after { content: ""; position: absolute; top: 3px; left: 3px; width: 20px; height: 20px;
  border-radius: 50%; background: #fff; transition: transform 0.15s var(--ease); }
.switch.on::after { transform: translateX(18px); }

.avatar {
  width: 72px; height: 72px; border-radius: 50%; margin: 0 auto 36px;
  background: var(--surface-variant); color: var(--on-surface);
  display: flex; align-items: center; justify-content: center;
  font-size: var(--headline-md); font-weight: 500;
}
.readonly-field {
  display: flex; align-items: center; height: 56px; padding: 0 14px;
  border: 1px solid color-mix(in srgb, var(--outline) 40%, transparent);
  border-radius: var(--r-sm); color: var(--on-surface-variant);
}
.divider { height: 1px; background: color-mix(in srgb, var(--outline) 30%, transparent); margin: 28px 0; }
.nav-row { display: flex; align-items: center; padding: 14px; background: var(--surface);
  border-radius: var(--r-sm); width: 100%; border: none; color: var(--on-bg); text-align: left; }
.nav-row .chev { color: var(--on-surface-variant); font-size: 22px; }

/* ============================================================================
   Toast
   ============================================================================ */
.toast {
  position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%) translateY(20px);
  background: var(--surface); color: var(--on-surface);
  border: 1px solid var(--outline); border-radius: var(--r-sm);
  padding: 12px 16px; font-size: var(--body-md); z-index: 50;
  opacity: 0; pointer-events: none; transition: opacity 0.2s var(--ease), transform 0.2s var(--ease);
  max-width: min(90vw, 480px);
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

.hidden { display: none !important; }
