:root {
  --navy-950: #0A1522;
  --navy-900: #0D1B2A;
  --navy-800: #14283D;
  --navy-700: #1C3854;
  --navy-600: #274a6e;
  --ink-100: #E9EEF4;
  --ink-300: #B9C6D6;
  --ink-500: #7E92A8;
  --amber-400: #E6A857;
  --amber-500: #D8933A;
  --teal-400: #4FB6A8;
  --teal-600: #2C8478;
  --danger: #D96C6C;
  --success: #5FAE8A;

  --font-display: "Fraunces", serif;
  --font-body: "Work Sans", sans-serif;
  --font-mono: "IBM Plex Mono", monospace;

  --radius-md: 10px;
  --radius-lg: 16px;
}

* { box-sizing: border-box; }

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

body {
  font-family: var(--font-body);
  background: var(--navy-950);
  color: var(--ink-100);
  -webkit-font-smoothing: antialiased;
  overflow: hidden;
}

.hidden { display: none !important; }

button {
  font-family: inherit;
  cursor: pointer;
}

input {
  font-family: inherit;
}

/* ---------- Brand ---------- */
.brand-mark {
  width: 52px;
  height: 52px;
  border-radius: var(--radius-md);
  background: linear-gradient(160deg, var(--navy-700), var(--navy-900));
  border: 1px solid var(--navy-600);
  display: flex;
  align-items: center;
  justify-content: center;
  font-family: var(--font-display);
  font-weight: 600;
  font-size: 1.3rem;
  color: var(--amber-400);
  letter-spacing: 0.02em;
  flex-shrink: 0;
}
.brand-mark.small {
  width: 38px;
  height: 38px;
  font-size: 1rem;
  border-radius: 9px;
}

/* ---------- Views ---------- */
.view {
  height: 100vh;
  height: 100svh;
}

/* ---------- Auth ---------- */
.view-auth {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  background:
    radial-gradient(circle at 20% 10%, rgba(79,182,168,0.08), transparent 40%),
    radial-gradient(circle at 80% 90%, rgba(230,168,87,0.08), transparent 40%),
    var(--navy-950);
}

.auth-card {
  width: 100%;
  max-width: 380px;
  background: var(--navy-900);
  border: 1px solid var(--navy-700);
  border-radius: var(--radius-lg);
  padding: 28px;
}

.brand {
  display: flex;
  align-items: center;
  gap: 14px;
  margin-bottom: 24px;
}
.brand-name {
  display: flex;
  flex-direction: column;
}
.brand-name strong {
  font-family: var(--font-display);
  font-size: 1.6rem;
  color: var(--ink-100);
  line-height: 1.1;
}
.brand-name span {
  font-size: 0.72rem;
  color: var(--ink-500);
  font-family: var(--font-mono);
  letter-spacing: 0.02em;
}

.auth-tabs {
  display: flex;
  background: var(--navy-800);
  border-radius: 999px;
  padding: 4px;
  margin-bottom: 22px;
}
.auth-tab {
  flex: 1;
  border: none;
  background: transparent;
  color: var(--ink-500);
  padding: 9px 0;
  border-radius: 999px;
  font-weight: 600;
  font-size: 0.85rem;
  transition: background .15s, color .15s;
}
.auth-tab.active {
  background: var(--amber-400);
  color: var(--navy-950);
}

.auth-form { display: flex; flex-direction: column; gap: 14px; }
.auth-form label {
  font-size: 0.8rem;
  color: var(--ink-300);
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.auth-form input {
  background: var(--navy-800);
  border: 1px solid var(--navy-600);
  color: var(--ink-100);
  padding: 11px 12px;
  border-radius: var(--radius-md);
  font-size: 0.95rem;
  outline: none;
}
.auth-form input:focus {
  border-color: var(--teal-400);
}

.btn {
  border: none;
  border-radius: var(--radius-md);
  padding: 12px 16px;
  font-weight: 600;
  font-size: 0.9rem;
  transition: filter .15s, background .15s;
}
.btn-primary {
  background: var(--amber-400);
  color: var(--navy-950);
}
.btn-primary:hover { filter: brightness(1.08); }
.btn-ghost {
  background: var(--navy-800);
  color: var(--ink-100);
  border: 1px solid var(--navy-600);
}
.btn-text {
  background: transparent;
  color: var(--ink-500);
  padding: 8px 0;
}
.btn-danger {
  background: var(--danger);
  color: var(--navy-950);
}
.btn-small {
  padding: 7px 12px;
  font-size: 0.78rem;
}

.form-error {
  color: var(--danger);
  font-size: 0.8rem;
  min-height: 1em;
  margin: 0;
}
.form-hint {
  color: var(--ink-500);
  font-size: 0.75rem;
  text-align: center;
  margin: 4px 0 0;
}

/* ---------- Pending ---------- */
.view-pending {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  background: var(--navy-950);
}
.pending-card {
  max-width: 380px;
  text-align: center;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 14px;
}
.pending-card h1 {
  font-family: var(--font-display);
  font-size: 1.6rem;
  margin: 6px 0 0;
}
.pending-card p {
  color: var(--ink-300);
  font-size: 0.92rem;
  line-height: 1.5;
}

/* ---------- App shell ---------- */
.view-app {
  display: flex;
  height: 100%;
  min-height: 0;
}

.sidebar {
  width: 320px;
  flex-shrink: 0;
  background: var(--navy-900);
  border-right: 1px solid var(--navy-700);
  display: flex;
  flex-direction: column;
}

.sidebar-header {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 16px;
  border-bottom: 1px solid var(--navy-700);
}
.sidebar-title {
  display: flex;
  flex-direction: column;
  flex: 1;
  min-width: 0;
}
.sidebar-title strong {
  font-family: var(--font-display);
  font-size: 1rem;
}
.sidebar-title span {
  font-size: 0.72rem;
  color: var(--ink-500);
  font-family: var(--font-mono);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.icon-btn {
  width: 34px;
  height: 34px;
  border-radius: 9px;
  border: 1px solid var(--navy-600);
  background: var(--navy-800);
  color: var(--ink-300);
  font-size: 1rem;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}
.icon-btn:hover { border-color: var(--teal-400); color: var(--ink-100); }

.sidebar-search { padding: 10px 14px; }
.sidebar-search input {
  width: 100%;
  background: var(--navy-800);
  border: 1px solid var(--navy-700);
  color: var(--ink-100);
  padding: 9px 12px;
  border-radius: 999px;
  font-size: 0.85rem;
  outline: none;
}
.sidebar-search input:focus { border-color: var(--teal-400); }

.chat-list {
  flex: 1;
  overflow-y: auto;
  padding: 6px 8px;
}

.chat-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 10px;
  border-radius: var(--radius-md);
  margin-bottom: 2px;
}
.chat-item:hover { background: var(--navy-800); }
.chat-item.active { background: var(--navy-700); }

.avatar {
  width: 38px;
  height: 38px;
  border-radius: 50%;
  background: var(--navy-700);
  color: var(--teal-400);
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 600;
  font-size: 0.8rem;
  flex-shrink: 0;
  border: 1px solid var(--navy-600);
  overflow: hidden;
}
.avatar.group { color: var(--amber-400); }
.avatar img { width: 100%; height: 100%; object-fit: cover; }

.avatar-upload {
  position: relative;
  width: 38px;
  height: 38px;
  border-radius: 50%;
  border: 1px solid var(--navy-600);
  background: var(--navy-700);
  color: var(--teal-400);
  font-weight: 600;
  font-size: 0.8rem;
  flex-shrink: 0;
  overflow: hidden;
  cursor: pointer;
  padding: 0;
}
.avatar-upload img { width: 100%; height: 100%; object-fit: cover; display: block; }
.avatar-upload span { display: flex; align-items: center; justify-content: center; width: 100%; height: 100%; }
.avatar-upload::after {
  content: "\270E";
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(10, 21, 34, 0.65);
  color: var(--ink-100);
  font-size: 0.75rem;
  opacity: 0;
  transition: opacity 0.15s ease;
}
.avatar-upload:hover::after { opacity: 1; }

.chat-item-text { min-width: 0; flex: 1; }
.chat-item-text strong {
  display: block;
  font-size: 0.88rem;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.chat-item-text span {
  display: block;
  font-size: 0.74rem;
  color: var(--ink-500);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.section-label {
  font-size: 0.68rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--ink-500);
  padding: 12px 10px 6px;
  font-family: var(--font-mono);
}

/* ---------- Chat pane ---------- */
.chat-pane {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-width: 0;
  min-height: 0;
  background:
    radial-gradient(circle at 10% 0%, rgba(79,182,168,0.05), transparent 30%),
    var(--navy-950);
}

.chat-empty {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 14px;
  color: var(--ink-500);
  text-align: center;
  padding: 24px;
}

.chat-active {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-height: 0;
}

.chat-header {
  padding: 14px 20px;
  border-bottom: 1px solid var(--navy-700);
  display: flex;
  align-items: center;
}
.chat-header-title strong {
  font-family: var(--font-display);
  font-size: 1.05rem;
  display: block;
}
.chat-header-title span {
  font-size: 0.75rem;
  color: var(--ink-500);
}

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

.msg {
  max-width: 62%;
  align-self: flex-start;
  background: var(--navy-800);
  border: 1px solid var(--navy-700);
  border-radius: var(--radius-md);
  padding: 9px 12px;
  margin-bottom: 6px;
}
.msg.mine {
  align-self: flex-end;
  background: linear-gradient(160deg, var(--teal-600), var(--teal-400));
  border-color: transparent;
  color: var(--navy-950);
}
.msg-sender {
  font-size: 0.72rem;
  font-weight: 600;
  color: var(--amber-400);
  margin-bottom: 2px;
}
.msg.mine .msg-sender { color: var(--navy-800); }
.msg-text { font-size: 0.92rem; line-height: 1.4; white-space: pre-wrap; word-break: break-word; }
.msg-time {
  font-size: 0.65rem;
  color: var(--ink-500);
  margin-top: 4px;
  text-align: right;
}
.msg.mine .msg-time { color: rgba(10,21,34,0.55); }

.msg-tick {
  margin-left: 5px;
  font-size: 0.72rem;
  letter-spacing: -1px;
  color: rgba(10,21,34,0.55);
}
.msg-tick.read { color: var(--navy-950); font-weight: 700; }

.msg-file {
  display: flex;
  align-items: center;
  gap: 10px;
  background: rgba(0,0,0,0.15);
  border-radius: 8px;
  padding: 8px 10px;
  text-decoration: none;
  color: inherit;
}
.msg-file-icon { font-size: 1.3rem; }
.msg-file-name { font-size: 0.85rem; font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 220px; }
.msg-file-size { font-size: 0.7rem; opacity: 0.75; }
.msg-image { max-width: 260px; border-radius: 8px; display: block; margin-top: 2px; }

.day-divider {
  align-self: center;
  font-size: 0.7rem;
  color: var(--ink-500);
  font-family: var(--font-mono);
  padding: 10px 0 6px;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

/* ---------- Composer ---------- */
.composer {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 12px 16px calc(12px + env(safe-area-inset-bottom));
  border-top: 1px solid var(--navy-700);
  background: var(--navy-900);
  position: relative;
}
.composer input[type="text"] {
  flex: 1;
  background: var(--navy-800);
  border: 1px solid var(--navy-700);
  color: var(--ink-100);
  padding: 11px 14px;
  border-radius: 999px;
  font-size: 0.9rem;
  outline: none;
}
.composer input[type="text"]:focus { border-color: var(--teal-400); }
.btn-send { border-radius: 999px; padding: 11px 20px; }

.file-preview {
  position: absolute;
  bottom: 62px;
  left: 16px;
  background: var(--navy-800);
  border: 1px solid var(--navy-600);
  border-radius: var(--radius-md);
  padding: 8px 12px;
  font-size: 0.78rem;
  display: flex;
  align-items: center;
  gap: 10px;
}
.file-preview button {
  background: none;
  border: none;
  color: var(--danger);
  font-size: 0.9rem;
}

/* ---------- Admin modal ---------- */
.modal {
  position: fixed;
  inset: 0;
  background: rgba(10,21,34,0.7);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 50;
  padding: 20px;
}
.modal-card {
  width: 100%;
  max-width: 480px;
  max-height: 84vh;
  background: var(--navy-900);
  border: 1px solid var(--navy-700);
  border-radius: var(--radius-lg);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}
.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 18px;
  border-bottom: 1px solid var(--navy-700);
}
.modal-header h2 {
  font-family: var(--font-display);
  font-size: 1.1rem;
  margin: 0;
}

.admin-tabs {
  display: flex;
  gap: 6px;
  padding: 12px 18px 0;
}
.admin-tab {
  border: none;
  background: var(--navy-800);
  color: var(--ink-300);
  padding: 8px 14px;
  border-radius: 999px;
  font-size: 0.8rem;
  font-weight: 600;
  display: flex;
  align-items: center;
  gap: 6px;
}
.admin-tab.active { background: var(--amber-400); color: var(--navy-950); }

.badge {
  background: var(--danger);
  color: white;
  border-radius: 999px;
  font-size: 0.65rem;
  padding: 1px 7px;
}
.admin-tab.active .badge { background: var(--navy-950); color: var(--amber-400); }

.admin-panel {
  padding: 14px 18px 18px;
  overflow-y: auto;
}
.empty-hint {
  color: var(--ink-500);
  font-size: 0.85rem;
  text-align: center;
  padding: 20px 0;
}

.people-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.people-row {
  display: flex;
  align-items: center;
  gap: 10px;
  background: var(--navy-800);
  border: 1px solid var(--navy-700);
  border-radius: var(--radius-md);
  padding: 10px 12px;
}
.people-row-text { flex: 1; min-width: 0; }
.people-row-text strong { display: block; font-size: 0.87rem; }
.people-row-text span { display: block; font-size: 0.72rem; color: var(--ink-500); }
.people-row-actions { display: flex; gap: 6px; flex-shrink: 0; }
.role-tag {
  font-size: 0.65rem;
  font-family: var(--font-mono);
  background: var(--navy-700);
  color: var(--teal-400);
  padding: 2px 7px;
  border-radius: 6px;
  margin-left: 6px;
}

/* ---------- Toast ---------- */
.toast {
  position: fixed;
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%);
  background: var(--navy-800);
  border: 1px solid var(--navy-600);
  color: var(--ink-100);
  padding: 10px 18px;
  border-radius: 999px;
  font-size: 0.82rem;
  z-index: 100;
  box-shadow: 0 6px 24px rgba(0,0,0,0.35);
}

/* ---------- Voice calling ---------- */
.chat-header { justify-content: space-between; }

.call-bar {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 20px;
  background: var(--teal-600);
  color: var(--ink-100);
  font-size: 0.85rem;
}
.call-bar span { flex: 1; font-weight: 600; }

.call-modal-card {
  align-items: center;
  text-align: center;
  padding: 32px 24px;
  gap: 10px;
}
.call-modal-card .brand-mark { margin: 0 auto 6px; }
.call-modal-card h2 { font-family: var(--font-display); font-size: 1.3rem; margin: 0; }
.call-modal-card p { color: var(--ink-500); margin: 0 0 10px; }
.call-modal-actions { display: flex; gap: 12px; width: 100%; }
.call-modal-actions .btn { flex: 1; }

.chat-back-btn {
  display: none;
  background: none;
  border: none;
  color: var(--ink-100);
  font-size: 1.3rem;
  line-height: 1;
  cursor: pointer;
  padding: 4px 4px 4px 0;
  flex-shrink: 0;
}

/* ---------- Responsive (phones) ---------- */
@media (max-width: 760px) {
  .view-app { flex-direction: column; }
  .sidebar {
    width: 100%;
    height: 100%;
    border-right: none;
  }
  .view-app.chat-open .sidebar { display: none; }
  .view-app:not(.chat-open) .chat-pane { display: none; }
  .msg { max-width: 82%; }
  .chat-header { gap: 10px; }
  .chat-back-btn { display: inline-flex; align-items: center; }
}
