/* =====================================================================
   [APP_NAME] — monochrome design system (black / white / gray only)
   ===================================================================== */

:root {
  --ink: #0F1419;
  --paper: #FFFFFF;
  --surface-dim: #F7F8F8;
  --border: #EFF3F4;
  --muted: #536471;
  --hover: #F2F3F4;
  --danger: #0F1419; /* kept monochrome even for destructive actions; weight/underline signal intent instead of color */
  --radius: 14px;
  --radius-pill: 999px;
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
}

[data-theme="dark"] {
  --ink: #E7E9EA;
  --paper: #000000;
  --surface-dim: #16181C;
  --border: #2F3336;
  --muted: #71767B;
  --hover: #16181C;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
  background: var(--paper);
  color: var(--ink);
  font-family: var(--font);
  font-size: 15px;
  -webkit-font-smoothing: antialiased;
}

a { color: inherit; text-decoration: none; }

button, input, textarea, select { font-family: inherit; }

.h-display { font-weight: 700; }
.h-body { font-weight: 400; }
.h-utility { font-weight: 400; font-size: 13px; color: var(--muted); }

/* ---- Layout shells ---- */
.app-shell {
  display: grid;
  grid-template-columns: 88px 360px 1fr;
  height: 100vh;
}
@media (max-width: 1080px) {
  .app-shell { grid-template-columns: 76px 320px 1fr; }
}
@media (max-width: 768px) {
  .app-shell { grid-template-columns: 1fr; }
  .app-shell .nav-rail { display: none; }
  .app-shell { padding-bottom: 56px; }
  .mobile-tabbar { z-index: 10; }
}

.nav-rail {
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 20px 0;
  gap: 10px;
}
.nav-rail a {
  width: 48px; height: 48px;
  display: flex; align-items: center; justify-content: center;
  border-radius: var(--radius-pill);
}
.nav-rail a:hover, .nav-rail a.active { background: var(--hover); }

.chat-list-pane {
  border-right: 1px solid var(--border);
  overflow-y: auto;
}
.chat-list-header {
  padding: 16px;
  border-bottom: 1px solid var(--border);
  display: flex; align-items: center; justify-content: space-between;
}
.chat-list-header h1 { font-size: 20px; margin: 0; }

.search-box {
  margin: 12px 16px;
  background: var(--surface-dim);
  border-radius: var(--radius-pill);
  border: 1px solid transparent;
  padding: 10px 16px;
}
.search-box input {
  border: none; background: transparent; outline: none; width: 100%;
  color: var(--ink); font-size: 15px;
}

.chat-row {
  display: flex; align-items: center; gap: 12px;
  padding: 12px 16px;
  border-bottom: 1px solid var(--border);
  cursor: pointer;
}
.chat-row:hover { background: var(--hover); }
.chat-row.active { background: var(--surface-dim); }

.avatar {
  width: 48px; height: 48px; border-radius: 50%;
  background: var(--surface-dim);
  display: flex; align-items: center; justify-content: center;
  font-weight: 700; color: var(--muted);
  flex-shrink: 0;
  overflow: hidden;
  border: 1px solid var(--border);
}
.avatar img { width: 100%; height: 100%; object-fit: cover; }
.avatar-sm { width: 32px; height: 32px; font-size: 13px; }
.avatar-lg { width: 84px; height: 84px; font-size: 28px; }

.chat-row-body { flex: 1; min-width: 0; }
.chat-row-top { display: flex; justify-content: space-between; align-items: baseline; }
.chat-row-name { font-weight: 600; font-size: 15px; }
.chat-row-time { font-size: 12px; color: var(--muted); }
.chat-row-preview {
  color: var(--muted); font-size: 13px;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}

.badge {
  background: var(--ink); color: var(--paper);
  border-radius: var(--radius-pill);
  font-size: 11px; font-weight: 700;
  padding: 2px 7px; min-width: 18px; text-align: center;
}

/* ---- Conversation pane ---- */
.conversation-pane { display: flex; flex-direction: column; height: 100vh; }
.conversation-header {
  padding: 12px 20px;
  border-bottom: 1px solid var(--border);
  display: flex; align-items: center; gap: 12px;
}
.conversation-header .titles { flex: 1; }
.conversation-header .name { font-weight: 700; font-size: 16px; }
.conversation-header .status { font-size: 13px; color: var(--muted); }

.messages-scroll {
  flex: 1; overflow-y: auto; padding: 20px;
  display: flex; flex-direction: column; gap: 6px;
}

.msg-row { display: flex; flex-direction: column; max-width: 65%; }
.msg-row.mine { align-self: flex-end; align-items: flex-end; }
.msg-row.theirs { align-self: flex-start; align-items: flex-start; }

.msg-bubble {
  padding: 9px 14px;
  border-radius: 18px;
  border: 1px solid var(--border);
  font-size: 15px;
  line-height: 1.4;
  word-wrap: break-word;
}
.msg-row.mine .msg-bubble { background: var(--ink); color: var(--paper); border-color: var(--ink); }
.msg-row.theirs .msg-bubble { background: var(--surface-dim); color: var(--ink); }

.msg-meta { font-size: 11px; color: var(--muted); margin-top: 2px; display: flex; gap: 4px; align-items: center; }

.composer {
  border-top: 1px solid var(--border);
  padding: 12px 16px;
  display: flex; align-items: flex-end; gap: 10px;
}
.composer textarea {
  flex: 1; resize: none; border: 1px solid var(--border);
  border-radius: 20px; padding: 10px 16px; max-height: 140px;
  outline: none; background: var(--surface-dim); color: var(--ink);
  font-size: 15px;
}
.icon-btn {
  width: 40px; height: 40px; border-radius: 50%;
  border: none; background: transparent; cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  color: var(--ink);
}
.icon-btn:hover { background: var(--hover); }
.send-btn { background: var(--ink); color: var(--paper); }
.send-btn:hover { opacity: .85; background: var(--ink); }

/* ---- Buttons / forms ---- */
.btn {
  display: inline-flex; align-items: center; justify-content: center;
  border-radius: var(--radius-pill);
  padding: 10px 22px;
  font-weight: 700; font-size: 15px;
  border: 1px solid var(--ink);
  background: var(--ink); color: var(--paper);
  cursor: pointer;
}
.btn:hover { opacity: .88; }
.btn-outline { background: transparent; color: var(--ink); }
.btn-block { width: 100%; }
.btn-sm { padding: 6px 14px; font-size: 13px; }

.field { margin-bottom: 16px; }
.field label { display: block; font-size: 13px; color: var(--muted); margin-bottom: 6px; font-weight: 600; }
.field input, .field select, .field textarea {
  width: 100%; padding: 12px 14px; border-radius: 10px;
  border: 1px solid var(--border); background: var(--paper); color: var(--ink);
  font-size: 15px; outline: none;
}
.field input:focus, .field textarea:focus { border-color: var(--ink); }

.auth-shell {
  min-height: 100vh; display: flex; align-items: center; justify-content: center;
  padding: 24px;
}
.auth-card { width: 100%; max-width: 400px; }
.auth-card h1 { font-size: 26px; margin-bottom: 8px; }
.auth-card p.sub { color: var(--muted); margin-bottom: 28px; }

.divider { border: none; border-top: 1px solid var(--border); margin: 20px 0; }

.toggle {
  position: relative; width: 42px; height: 24px;
  display: inline-block;
}
.toggle input { opacity: 0; width: 0; height: 0; }
.toggle .track {
  position: absolute; inset: 0; background: var(--border);
  border-radius: var(--radius-pill); transition: .15s;
}
.toggle .track::after {
  content: ""; position: absolute; left: 3px; top: 3px;
  width: 18px; height: 18px; background: var(--paper); border: 1px solid var(--border);
  border-radius: 50%; transition: .15s;
}
.toggle input:checked + .track { background: var(--ink); }
.toggle input:checked + .track::after { left: 21px; background: var(--paper); border-color: var(--ink); }

.pref-row {
  display: flex; align-items: center; justify-content: space-between;
  padding: 14px 0; border-bottom: 1px solid var(--border);
}
.pref-row .label { font-weight: 600; }
.pref-row .toggles { display: flex; gap: 20px; align-items: center; }
.pref-row .toggles .toggle-label { font-size: 12px; color: var(--muted); display: flex; flex-direction: column; align-items: center; gap: 4px; }

.settings-shell { max-width: 640px; margin: 0 auto; padding: 32px 20px; }
.settings-shell h1 { font-size: 22px; }
.settings-nav { display: flex; gap: 6px; flex-wrap: wrap; margin: 20px 0 28px; }
.settings-nav a {
  padding: 8px 14px; border-radius: var(--radius-pill); border: 1px solid var(--border); font-size: 14px;
}
.settings-nav a.active { background: var(--ink); color: var(--paper); border-color: var(--ink); }

.empty-state {
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  height: 100%; color: var(--muted); text-align: center; padding: 40px;
}

.alert {
  padding: 12px 16px; border-radius: 10px; border: 1px solid var(--border);
  background: var(--surface-dim); font-size: 14px; margin-bottom: 16px;
}
.alert-error { border-color: var(--ink); }

.mobile-tabbar {
  display: none;
  position: fixed; bottom: 0; left: 0; right: 0;
  border-top: 1px solid var(--border); background: var(--paper);
  justify-content: space-around; padding: 8px 0;
}
@media (max-width: 768px) {
  .mobile-tabbar { display: flex; }
}
