/* ZZSocial — dark, minimalist. Two-pane messenger layout. */

:root {
  --bg:        #0c0e11;
  --surface:   #15181d;
  --surface-2: #1b1f25;
  --border:    #1e222a;
  --text:      #e6e8ec;
  --text-dim:  #767c86;
  --text-faint:#565c66;
  --accent:    #6c8cff;
  --accent-ink:#ffffff;
  --bubble-me: #222a3d;
  --danger:    #e06666;

  --radius:    14px;
  --radius-sm: 9px;
  --sidebar-w: 280px;

  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica,
          Arial, sans-serif;
}

* { box-sizing: border-box; }

html, body { margin: 0; padding: 0; height: 100%; }

body {
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  font-size: 16px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  overscroll-behavior: none;
}

[hidden] { display: none !important; }

/* App shell — two columns */
.app {
  display: flex;
  height: 100dvh;
  height: 100vh;
  overflow: hidden;
}

/* ---------- Sidebar ---------- */
.sidebar {
  flex: 0 0 var(--sidebar-w);
  width: var(--sidebar-w);
  display: flex;
  flex-direction: column;
  background: var(--bg);
  border-right: 1px solid var(--border);
  min-height: 0;
}

.sidebar__header {
  padding: 18px 16px 12px;
  padding-top: max(18px, env(safe-area-inset-top));
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.sidebar__top {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.brand { display: flex; align-items: baseline; gap: 8px; }

/* Minimal wordmark — the badge is decoration; keep it quiet. */
.brand__mark {
  display: none;
}
.brand__mark--lg {
  display: grid;
  place-items: center;
  width: 44px; height: 44px;
  border-radius: 12px;
  border: 1px solid var(--border);
  color: var(--text-dim);
  font-weight: 600;
  font-size: 15px;
  letter-spacing: 0.5px;
}

.brand__name {
  font-size: 16px;
  font-weight: 600;
  letter-spacing: 0.2px;
  color: var(--text);
}

/* ---------- Buttons ---------- */
.btn {
  border: none;
  border-radius: var(--radius-sm);
  font-family: inherit;
  font-size: 14px;
  font-weight: 500;
  color: var(--text);
  background: transparent;
  cursor: pointer;
  transition: background 0.15s ease, color 0.15s ease, opacity 0.15s ease;
  -webkit-tap-highlight-color: transparent;
}
.btn:disabled { opacity: 0.4; cursor: default; }

/* Ghost primary — quiet by default, accent text */
.btn--primary {
  border: 1px solid var(--border);
  padding: 10px 20px;
  color: var(--text);
}
.btn--primary:hover { background: var(--surface); }

.btn--new {
  width: 100%;
  padding: 9px 12px;
  border: 1px solid var(--border);
  color: var(--text-dim);
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
}
.btn--new:hover { background: var(--surface); color: var(--text); }
.btn--new__plus { font-size: 16px; line-height: 1; margin-top: -1px; }

.icon-btn {
  border: none;
  background: transparent;
  color: var(--text-faint);
  font-size: 20px;
  line-height: 1;
  width: 36px;
  height: 36px;
  border-radius: 8px;
  display: grid;
  place-items: center;
  cursor: pointer;
  flex: 0 0 auto;
  transition: color 0.15s ease, background 0.15s ease;
  -webkit-tap-highlight-color: transparent;
}
.icon-btn:hover { color: var(--text-dim); background: var(--surface); }

/* ---------- Chat list ---------- */
.chat-list {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  padding: 4px 8px;
  display: flex;
  flex-direction: column;
  gap: 1px;
}

.chat-item {
  position: relative;
  display: flex;
  flex-direction: column;
  gap: 1px;
  padding: 9px 32px 9px 11px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: background 0.12s ease;
}
.chat-item:hover { background: var(--surface); }
.chat-item.is-active { background: var(--surface); }

.chat-item__title {
  font-size: 13.5px;
  font-weight: 500;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.chat-item.is-active .chat-item__title { color: var(--text); }

.chat-item__preview {
  font-size: 12px;
  color: var(--text-faint);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.chat-item__del {
  position: absolute;
  top: 50%;
  right: 6px;
  transform: translateY(-50%);
  width: 22px; height: 22px;
  border: none;
  background: transparent;
  color: var(--text-faint);
  font-size: 14px;
  border-radius: 6px;
  cursor: pointer;
  display: none;
  place-items: center;
}
.chat-item:hover .chat-item__del { display: grid; }
.chat-item__del:hover { color: var(--danger); }

.chat-list__empty {
  margin: 20px 12px;
  color: var(--text-faint);
  font-size: 12.5px;
  text-align: center;
}

/* ---------- Chat pane ---------- */
.chat {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  min-height: 0;
  background: var(--bg);
}

.chat__header {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 14px 14px;
  padding-top: max(14px, env(safe-area-inset-top));
  border-bottom: 1px solid var(--border);
}
.chat__back { display: none; }
.chat__title {
  flex: 1;
  font-weight: 500;
  font-size: 14.5px;
  color: var(--text-dim);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* Chat mood (header) — same dropdown style as the modals, sized for the header.
   User seeds it, the AI keeps it current. */
.chat__mood { flex: none; width: 138px; }
.chat__mood .dropdown__btn { padding: 8px 12px; }
.chat__mood .dropdown__menu {
  left: auto;
  right: 0;
  min-width: 100%;
}

.chat__messages {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  padding: 22px 20px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.msg {
  padding: 9px 13px;
  border-radius: var(--radius);
  font-size: 14.5px;
  line-height: 1.5;
  white-space: pre-wrap;
  word-wrap: break-word;
  overflow-wrap: anywhere;
  animation: fade 0.16s ease;
}
@keyframes fade {
  from { opacity: 0; }
  to   { opacity: 1; }
}

/* Them = incoming (what you paste in), left side */
.bubble-wrap--them {
  align-self: flex-start;
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 4px;
  max-width: 72%;
}
.msg--them {
  max-width: 100%;
  background: var(--surface);
  border-bottom-left-radius: 4px;
}

/* Me = your suggested reply (to copy), right side, with actions */
.bubble-wrap--me {
  align-self: flex-end;
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 4px;
  max-width: 72%;
}
.msg--me {
  background: var(--bubble-me);
  border-bottom-right-radius: 4px;
  max-width: 100%;
}
.msg--me.msg--pending { color: var(--text-faint); background: transparent; font-style: italic; }

.msg-actions { display: flex; align-items: center; gap: 6px; padding: 0 2px; }
.msg-time {
  font-size: 11px;
  color: var(--text-faint);
  padding: 0 2px;
  white-space: nowrap;
}
.msg-act {
  border: none;
  background: transparent;
  color: var(--text-faint);
  font-family: inherit;
  font-size: 11.5px;
  font-weight: 500;
  padding: 2px 6px;
  border-radius: 6px;
  cursor: pointer;
  transition: color 0.12s ease, background 0.12s ease;
}
.msg-act:hover { color: var(--text); background: var(--surface); }
.msg-act.is-done { color: var(--accent); }
.msg-act--del:hover { color: var(--danger); }

.msg--error {
  align-self: center;
  max-width: 88%;
  text-align: center;
  color: var(--danger);
  font-size: 12.5px;
  padding: 6px 10px;
}

/* In-chat empty state (no messages yet for this person) */
.chat-empty {
  margin: auto;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 14px;
  text-align: center;
  max-width: 320px;
}
.chat-empty__hint { margin: 0; color: var(--text-faint); font-size: 13.5px; line-height: 1.5; }

/* ---------- Composer ---------- */
.composer {
  display: flex;
  flex-direction: column;
  align-items: stretch;
  gap: 8px;
  padding: 14px 18px;
  padding-bottom: max(14px, env(safe-area-inset-bottom));
}
.composer__row {
  display: flex;
  align-items: flex-end;
  gap: 8px;
}
.composer__modes { display: flex; gap: 6px; }
.mode-btn {
  padding: 4px 13px;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: transparent;
  color: var(--text-dim);
  font-family: inherit;
  font-size: 12px;
  cursor: pointer;
  transition: border-color 0.15s ease, color 0.15s ease, background 0.15s ease;
}
.mode-btn:hover { color: var(--text); }
.mode-btn.is-active { border-color: var(--accent); color: var(--text); background: var(--surface); }
.composer__input {
  flex: 1;
  resize: none;
  max-height: 160px;
  padding: 10px 14px;
  border: 1px solid var(--border);
  border-radius: 18px;
  background: var(--surface);
  color: var(--text);
  font-family: inherit;
  font-size: 14.5px;
  line-height: 1.4;
  outline: none;
  transition: border-color 0.15s ease;
}
.composer__input::placeholder { color: var(--text-faint); }
.composer__input:focus { border-color: var(--surface-2); }

.btn--send {
  flex: 0 0 auto;
  width: 38px; height: 38px;
  border-radius: 50%;
  background: var(--surface-2);
  color: var(--text-dim);
  font-size: 18px;
  display: grid;
  place-items: center;
  padding: 0;
  transition: background 0.15s ease, color 0.15s ease;
}
.btn--send:hover:not(:disabled) { background: var(--accent); color: var(--accent-ink); }

/* ---------- Empty state ---------- */
.empty-state {
  flex: 1;
  min-width: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  background: var(--bg);
}
.empty-state__inner {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
  text-align: center;
  color: var(--text-faint);
}
.empty-state__inner h1 { margin: 8px 0 0; font-size: 19px; color: var(--text-dim); font-weight: 600; }
.empty-state__inner p { margin: 0 0 4px; font-size: 13.5px; }

/* ---------- Settings modal ---------- */
.modal {
  position: fixed;
  inset: 0;
  z-index: 50;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
}
.modal__backdrop {
  position: absolute;
  inset: 0;
  background: rgba(0, 0, 0, 0.55);
}
.modal__card {
  position: relative;
  width: 100%;
  max-width: 440px;
  max-height: 88vh;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
  display: flex;
  flex-direction: column;
  gap: 16px;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.5);
}

.modal__section {
  display: flex;
  flex-direction: column;
  gap: 12px;
  padding-top: 16px;
  border-top: 1px solid var(--border);
}
.modal__section-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}
.modal__section-title {
  font-size: 12px;
  font-weight: 600;
  letter-spacing: 0.4px;
  text-transform: uppercase;
  color: var(--text-dim);
}
.modal__section-sub {
  margin: -4px 0 0;
  font-size: 12px;
  color: var(--text-faint);
  line-height: 1.4;
}
.modal__section-sub.is-working { color: var(--accent); }
.modal__section-sub.is-error { color: var(--danger); }

.field-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}
.field-grid .field--wide { grid-column: 1 / -1; }

.btn--mini {
  padding: 6px 10px;
  font-size: 12px;
  border: 1px solid var(--border);
  color: var(--text-dim);
  flex: 0 0 auto;
}
.btn--mini:hover:not(:disabled) { background: var(--surface-2); color: var(--text); }
.modal__head {
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.modal__title { margin: 0; font-size: 16px; font-weight: 600; }

.field { display: flex; flex-direction: column; gap: 6px; }
.field--row { flex-direction: row; align-items: center; justify-content: space-between; }
.field__label { font-size: 12.5px; color: var(--text-dim); font-weight: 500; }

/* Toggle switch */
.toggle { position: relative; display: inline-flex; cursor: pointer; flex: 0 0 auto; }
.toggle input { position: absolute; opacity: 0; width: 0; height: 0; }
.toggle__track {
  width: 40px; height: 22px;
  border-radius: 999px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  display: flex;
  align-items: center;
  padding: 2px;
  transition: background 0.15s ease, border-color 0.15s ease;
}
.toggle__thumb {
  width: 16px; height: 16px;
  border-radius: 50%;
  background: var(--text-dim);
  transition: transform 0.15s ease, background 0.15s ease;
}
.toggle input:checked + .toggle__track { background: var(--accent); border-color: var(--accent); }
.toggle input:checked + .toggle__track .toggle__thumb { transform: translateX(18px); background: #fff; }
.toggle input:focus-visible + .toggle__track { outline: 2px solid var(--accent); outline-offset: 2px; }
.field__opt { color: var(--text-faint); font-weight: 400; }
.field__textarea { resize: vertical; min-height: 72px; line-height: 1.45; }
select.field__input { appearance: none; -webkit-appearance: none; cursor: pointer; }

/* Custom dropdown (enhances a native <select>) */
.dropdown__native { display: none; }
.dropdown { position: relative; }
.dropdown__btn {
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--bg);
  color: var(--text);
  font-family: inherit;
  font-size: 14px;
  text-align: left;
  cursor: pointer;
  transition: border-color 0.15s ease;
}
.dropdown__btn:hover { border-color: var(--surface-2); }
.dropdown.is-open .dropdown__btn { border-color: var(--accent); }
.dropdown__value { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.dropdown__caret { color: var(--text-faint); font-size: 11px; transition: transform 0.15s ease; }
.dropdown.is-open .dropdown__caret { transform: rotate(180deg); }

.dropdown__menu {
  position: absolute;
  left: 0; right: 0;
  top: calc(100% + 4px);
  z-index: 20;
  padding: 4px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  max-height: 220px;
  overflow-y: auto;
  box-shadow: 0 14px 34px rgba(0, 0, 0, 0.5);
  animation: ddIn 0.12s ease;
}
.dropdown--up .dropdown__menu { top: auto; bottom: calc(100% + 4px); transform-origin: bottom; }
@keyframes ddIn { from { opacity: 0; transform: translateY(-4px); } to { opacity: 1; transform: none; } }

.dropdown__opt {
  padding: 8px 10px;
  border-radius: 6px;
  font-size: 13.5px;
  color: var(--text-dim);
  cursor: pointer;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.dropdown__opt.is-active { background: var(--surface); color: var(--text); }
.dropdown__opt.is-selected { color: var(--text); }
.dropdown__opt.is-selected::after { content: "✓"; float: right; margin-left: 10px; color: var(--accent); }

/* Combobox (free-text input + themed suggestion menu) */
.combo { position: relative; }
.combo .field__input { padding-right: 28px; }
.combo::after {
  content: "▾";
  position: absolute;
  right: 12px;
  top: 50%;
  transform: translateY(-50%);
  color: var(--text-faint);
  font-size: 11px;
  pointer-events: none;
  transition: transform 0.15s ease;
}
.combo.is-open::after { transform: translateY(-50%) rotate(180deg); }
.combo.is-up .dropdown__menu { top: auto; bottom: calc(100% + 4px); }

@media (prefers-reduced-motion: reduce) {
  .dropdown__caret, .combo::after { transition: none; }
  .dropdown__menu { animation: none; }
}
.field__input {
  width: 100%;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--bg);
  color: var(--text);
  font-family: inherit;
  font-size: 14px;
  outline: none;
  transition: border-color 0.15s ease;
}
.field__input:focus { border-color: var(--surface-2); }
.field__hint { font-size: 11.5px; color: var(--text-faint); line-height: 1.4; }

/* ---------- Custom dropdown ---------- */
.dropdown { position: relative; }
.dropdown__native {
  position: absolute;
  width: 1px; height: 1px;
  opacity: 0;
  pointer-events: none;
}
.dropdown__toggle {
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--bg);
  color: var(--text);
  font-family: inherit;
  font-size: 14px;
  text-align: left;
  cursor: pointer;
  transition: border-color 0.15s ease;
  -webkit-tap-highlight-color: transparent;
}
.dropdown__toggle:hover { border-color: var(--surface-2); }
.dropdown.is-open .dropdown__toggle { border-color: var(--accent); }
.dropdown__value { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.dropdown__value.is-placeholder { color: var(--text-faint); }
.dropdown__chevron {
  flex: 0 0 auto;
  color: var(--text-faint);
  font-size: 10px;
  transition: transform 0.15s ease;
}
.dropdown.is-open .dropdown__chevron { transform: rotate(180deg); }

.dropdown__menu {
  display: none;
  margin-top: 6px;
  padding: 4px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface);
  max-height: 230px;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
}
.dropdown.is-open .dropdown__menu { display: block; animation: fade 0.12s ease; }

.dropdown__option {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 9px 10px;
  border-radius: 7px;
  font-size: 14px;
  color: var(--text-dim);
  cursor: pointer;
}
.dropdown__option:hover,
.dropdown__option.is-active { background: var(--surface-2); color: var(--text); }
.dropdown__option.is-selected { color: var(--text); }
.dropdown__option.is-selected::after {
  content: "✓";
  color: var(--accent);
  font-size: 12px;
  flex: 0 0 auto;
}
.field__hint a { color: var(--text-dim); }
.field__hint code {
  font-size: 11px;
  padding: 1px 4px;
  border-radius: 4px;
  background: var(--bg);
  color: var(--text-dim);
}

.modal__card--sm { max-width: 380px; }
.confirm__msg { margin: 0; font-size: 14px; color: var(--text-dim); line-height: 1.5; }

.modal__actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
}
.modal__actions .btn { padding: 9px 16px; }
.modal__actions .btn:not(.btn--primary):not(.btn--danger) { color: var(--text-dim); }
.modal__actions .btn:not(.btn--primary):not(.btn--danger):hover { background: var(--surface-2); color: var(--text); }

.btn--danger { background: var(--danger); color: #1a0d0d; }
.btn--danger:hover:not(:disabled) { filter: brightness(1.08); }

/* ---------- Summary modal ---------- */
.seg {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
  margin: 4px 0 12px;
}
.seg__btn {
  flex: 1 1 auto;
  padding: 8px 10px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--bg);
  color: var(--text-dim);
  font-family: inherit;
  font-size: 13px;
  cursor: pointer;
  transition: border-color 0.15s ease, color 0.15s ease, background 0.15s ease;
}
.seg__btn:hover:not(:disabled) { border-color: var(--surface-2); color: var(--text); }
.seg__btn.is-active { border-color: var(--accent); color: var(--text); background: var(--surface); }
.seg__btn:disabled { opacity: 0.5; cursor: default; }

.summary__out {
  min-height: 96px;
  max-height: 320px;
  overflow-y: auto;
  padding: 12px 14px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--bg);
  font-size: 14px;
  line-height: 1.55;
  color: var(--text);
}
.summary__out.is-empty, .summary__out.is-working { color: var(--text-dim); }
.summary__out.is-error { color: var(--danger); white-space: pre-wrap; }
.summary__out--msg { white-space: pre-wrap; }

/* Suggested message block (Advice modal) */
.advice-msg {
  margin-top: 12px;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-left: 3px solid var(--accent);
  border-radius: var(--radius-sm);
  background: var(--surface);
}
.advice-msg__label {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--text-faint);
  margin-bottom: 5px;
}
.advice-msg__text {
  font-size: 14px;
  line-height: 1.5;
  color: var(--text);
  white-space: pre-wrap;
}

.summary__out p { margin: 0 0 8px; }
.summary__out ul { margin: 0 0 8px; padding-left: 18px; list-style: disc; }
.summary__out li { margin: 3px 0; }
.summary__out li.sub { list-style: circle; margin-left: 18px; }
.summary__out > :last-child { margin-bottom: 0; }
.summary__out strong { color: var(--text); font-weight: 600; }

/* ---------- Compacting (memory note + banner) ---------- */
.compact-note {
  align-self: stretch;
  margin-bottom: 6px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface);
  overflow: hidden;
}
.compact-note > summary {
  cursor: pointer;
  padding: 9px 12px;
  font-size: 12.5px;
  color: var(--text-dim);
  list-style: none;
  user-select: none;
}
.compact-note > summary::-webkit-details-marker { display: none; }
.compact-note > summary:hover { color: var(--text); }
.compact-note[open] > summary { border-bottom: 1px solid var(--border); color: var(--text); }
.compact-note__body {
  padding: 11px 13px;
  font-size: 13px;
  line-height: 1.5;
  color: var(--text);
}
.compact-note__body p { margin: 0 0 6px; }
.compact-note__body ul { margin: 0 0 6px; padding-left: 18px; list-style: disc; }
.compact-note__body li { margin: 2px 0; }
.compact-note__body li.sub { list-style: circle; margin-left: 18px; }
.compact-note__body > :last-child { margin-bottom: 0; }
.compact-note__body strong { font-weight: 600; }

/* ---------- Responsive: one pane on narrow screens ---------- */
@media (max-width: 720px) {
  :root { --sidebar-w: 100%; }

  .sidebar { flex-basis: 100%; border-right: none; }
  .chat, .empty-state { display: none; }

  .app.is-chat-open .sidebar { display: none; }
  .app.is-chat-open .chat { display: flex; }

  .chat__back { display: grid; }

  .msg { max-width: 82%; }
}
