:root {
  color-scheme: dark;
  --bg: #07090d;
  --panel: rgba(20, 24, 31, 0.94);
  --panel-2: rgba(27, 32, 41, 0.96);
  --line: rgba(255, 255, 255, 0.09);
  --line-strong: rgba(255, 255, 255, 0.16);
  --text: #f7f8fb;
  --muted: #a5adba;
  --red: #bf2028;
  --red-bright: #ee3b43;
  --red-dark: #741015;
  --success: #52d994;
  --warning: #f6c964;
  --shadow: 0 22px 70px rgba(0, 0, 0, 0.48);
  --radius: 20px;
}

* { box-sizing: border-box; }
html, body { min-height: 100%; }
body {
  margin: 0;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  background:
    radial-gradient(circle at 10% 0%, rgba(191, 32, 40, 0.19), transparent 32rem),
    radial-gradient(circle at 100% 100%, rgba(191, 32, 40, 0.08), transparent 35rem),
    linear-gradient(145deg, #05070a, #10131a 55%, #080a0f);
  color: var(--text);
  overflow: hidden;
}

button, input, textarea, select { font: inherit; }
button { cursor: pointer; }
.hidden { display: none !important; }

.app-shell { min-height: 100dvh; }
.center-stage {
  min-height: 100dvh;
  display: grid;
  place-items: center;
  padding: 24px;
}

.glass-card, .settings-card {
  border: 1px solid var(--line);
  background: linear-gradient(150deg, rgba(34, 40, 51, 0.94), rgba(13, 16, 22, 0.96));
  box-shadow: var(--shadow);
  backdrop-filter: blur(22px);
}

.login-card {
  width: min(100%, 440px);
  border-radius: 28px;
  padding: 34px;
}

.brand-mark {
  width: 74px;
  height: 74px;
  display: grid;
  place-items: center;
  border-radius: 23px;
  margin-bottom: 22px;
  background: linear-gradient(145deg, rgba(255,255,255,.09), rgba(255,255,255,.02));
  border: 1px solid var(--line-strong);
  box-shadow: inset 0 1px rgba(255,255,255,.08), 0 12px 28px rgba(0,0,0,.35);
}
.brand-mark img { width: 56px; height: 56px; }

h1, h2, h3, p { margin-top: 0; }
h1 { font-size: clamp(2rem, 6vw, 2.75rem); margin-bottom: 10px; letter-spacing: -0.04em; }
h2 { margin-bottom: 0; letter-spacing: -0.03em; }
h3 { margin-bottom: 16px; }

.eyebrow {
  color: var(--red-bright);
  font-weight: 800;
  font-size: .72rem;
  letter-spacing: .18em;
  margin-bottom: 8px;
}
.muted { color: var(--muted); line-height: 1.55; }

label {
  display: grid;
  gap: 8px;
  margin-top: 16px;
  color: #dfe3ea;
  font-size: .88rem;
  font-weight: 700;
}

input, textarea, select {
  width: 100%;
  color: var(--text);
  background: rgba(6, 8, 12, .82);
  border: 1px solid var(--line-strong);
  border-radius: 13px;
  padding: 13px 14px;
  outline: none;
  transition: border-color .2s, box-shadow .2s, background .2s;
}
input:focus, textarea:focus, select:focus {
  border-color: rgba(238, 59, 67, .9);
  box-shadow: 0 0 0 4px rgba(238, 59, 67, .11);
  background: rgba(8, 10, 14, .98);
}
select option { background: #151922; color: #fff; }

.primary-btn, .ghost-btn, .danger-btn, .danger-outline, .send-button {
  border: 0;
  border-radius: 13px;
  min-height: 45px;
  padding: 0 17px;
  font-weight: 800;
}
.primary-btn, .send-button {
  color: #fff;
  background: linear-gradient(135deg, var(--red-bright), var(--red-dark));
  box-shadow: 0 10px 24px rgba(191, 32, 40, .25);
}
.login-card .primary-btn { width: 100%; margin-top: 22px; }
.ghost-btn, .icon-button {
  color: #fff;
  background: rgba(255,255,255,.06);
  border: 1px solid var(--line);
}
.login-card .ghost-btn { width: 100%; margin-top: 10px; }
.danger-btn { color: #fff; background: #b51d25; }
.danger-outline {
  color: #ffb9bc;
  background: transparent;
  border: 1px solid rgba(238,59,67,.45);
}
.compact { min-height: 36px; padding: 0 13px; }

.status-message {
  min-height: 22px;
  color: #ffb9bc;
  text-align: center;
  margin-top: 14px;
  font-size: .88rem;
}
.status-message.success { color: var(--success); }

.chat-layout {
  min-height: 100dvh;
  display: grid;
  grid-template-columns: 280px minmax(0, 1fr);
  grid-template-rows: 76px minmax(0, 1fr);
}
.topbar {
  grid-column: 1 / -1;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 20px;
  border-bottom: 1px solid var(--line);
  background: rgba(8, 10, 14, .88);
  backdrop-filter: blur(18px);
  z-index: 5;
}
.brand-row, .profile-card, .topbar-actions, .section-title, .card-heading {
  display: flex;
  align-items: center;
}
.brand-row { gap: 12px; }
.brand-row small, .profile-card small { display: block; color: var(--muted); margin-top: 2px; }
.topbar-icon { width: 44px; height: 44px; }
.topbar-actions { gap: 9px; }
.icon-button {
  min-height: 40px;
  border-radius: 11px;
  padding: 0 14px;
  font-weight: 750;
}

.sidebar {
  min-height: 0;
  overflow: auto;
  border-right: 1px solid var(--line);
  padding: 18px;
  background: rgba(10, 12, 17, .75);
}
.profile-card {
  gap: 12px;
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 16px;
  background: rgba(255,255,255,.035);
}
.avatar {
  flex: 0 0 auto;
  width: 42px;
  height: 42px;
  display: grid;
  place-items: center;
  border-radius: 50%;
  background: linear-gradient(145deg, var(--red-bright), var(--red-dark));
  font-weight: 900;
}
.sidebar-section { margin-top: 24px; }
.section-title { justify-content: space-between; color: #dfe3e9; font-weight: 800; margin-bottom: 10px; }
.pill {
  min-width: 28px;
  text-align: center;
  color: var(--success);
  background: rgba(82,217,148,.1);
  border: 1px solid rgba(82,217,148,.2);
  border-radius: 999px;
  padding: 2px 8px;
}
.user-list { display: grid; gap: 8px; }
.user-entry {
  display: flex;
  align-items: center;
  gap: 9px;
  padding: 9px 10px;
  color: #dfe3e9;
  border-radius: 11px;
}
.online-dot { width: 9px; height: 9px; border-radius: 50%; background: var(--success); box-shadow: 0 0 10px rgba(82,217,148,.65); }
.privacy-note {
  margin-top: 28px;
  padding: 14px;
  border-radius: 14px;
  border: 1px solid rgba(238,59,67,.17);
  background: rgba(191,32,40,.07);
}
.privacy-note span { display: block; color: var(--muted); font-size: .78rem; line-height: 1.5; margin-top: 5px; }

.chat-main {
  min-height: 0;
  display: grid;
  grid-template-rows: auto minmax(0, 1fr) auto auto;
  padding: 22px;
  gap: 14px;
}
.chat-heading { display: flex; align-items: center; justify-content: space-between; }
.cleanup-notice {
  color: #c7ccd5;
  font-size: .8rem;
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 8px 12px;
  background: rgba(255,255,255,.035);
}
.messages {
  min-height: 0;
  overflow-y: auto;
  scroll-behavior: smooth;
  padding: 10px 6px 12px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}
.message {
  width: min(78%, 720px);
  align-self: flex-start;
}
.message.mine { align-self: flex-end; }
.message-meta {
  display: flex;
  align-items: baseline;
  gap: 8px;
  margin: 0 8px 5px;
  color: var(--muted);
  font-size: .72rem;
}
.message.mine .message-meta { justify-content: flex-end; }
.message-bubble {
  padding: 12px 14px;
  border-radius: 7px 18px 18px 18px;
  border: 1px solid var(--line);
  background: linear-gradient(145deg, rgba(35,40,50,.96), rgba(20,24,31,.96));
  box-shadow: 0 8px 20px rgba(0,0,0,.18);
  line-height: 1.45;
  overflow-wrap: anywhere;
}
.message.mine .message-bubble {
  border-radius: 18px 7px 18px 18px;
  background: linear-gradient(145deg, rgba(191,32,40,.96), rgba(111,14,19,.98));
}
.message-image {
  display: block;
  max-width: 100%;
  max-height: 420px;
  border-radius: 13px;
  margin-top: 8px;
  object-fit: contain;
  background: #090b0f;
}
.file-card {
  display: flex;
  align-items: center;
  gap: 11px;
  color: #fff;
  text-decoration: none;
}
.file-icon {
  width: 42px;
  height: 42px;
  display: grid;
  place-items: center;
  border-radius: 12px;
  background: rgba(255,255,255,.11);
  font-weight: 900;
}
.system-message {
  align-self: center;
  width: auto;
  color: var(--warning);
  font-size: .82rem;
  border: 1px solid rgba(246,201,100,.2);
  border-radius: 999px;
  padding: 7px 12px;
  background: rgba(246,201,100,.07);
}

.composer {
  display: grid;
  grid-template-columns: 48px minmax(0,1fr) auto;
  gap: 10px;
  align-items: end;
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: 18px;
  background: rgba(15,18,24,.96);
  box-shadow: 0 16px 38px rgba(0,0,0,.23);
}
.composer textarea {
  min-height: 46px;
  max-height: 150px;
  resize: none;
  border: 0;
  background: transparent;
  box-shadow: none;
}
.attach-button {
  width: 46px;
  height: 46px;
  border: 1px solid var(--line);
  border-radius: 14px;
  color: #fff;
  background: rgba(255,255,255,.055);
  font-size: 1.5rem;
}
.send-button { min-height: 46px; }
.upload-preview {
  padding: 10px 13px;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: rgba(255,255,255,.035);
  color: var(--muted);
  font-size: .85rem;
}

.modal-backdrop {
  position: fixed;
  inset: 0;
  z-index: 20;
  display: grid;
  place-items: center;
  padding: 18px;
  background: rgba(0,0,0,.72);
  backdrop-filter: blur(10px);
}
.admin-modal {
  width: min(100%, 1040px);
  max-height: min(92dvh, 920px);
  display: grid;
  grid-template-rows: auto auto minmax(0,1fr) auto;
  overflow: hidden;
  border: 1px solid var(--line-strong);
  border-radius: 24px;
  background: #10141b;
  box-shadow: var(--shadow);
}
.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 22px;
  border-bottom: 1px solid var(--line);
}
.close-button {
  width: 42px; height: 42px; border-radius: 12px;
  color: #fff; background: rgba(255,255,255,.06); border: 1px solid var(--line);
  font-size: 1.65rem;
}
.admin-tabs { display: flex; gap: 5px; padding: 10px 14px; border-bottom: 1px solid var(--line); }
.tab {
  min-height: 40px; padding: 0 17px; border: 0; border-radius: 11px;
  color: var(--muted); background: transparent; font-weight: 800;
}
.tab.active { color: #fff; background: rgba(191,32,40,.18); }
.admin-content { min-height: 0; overflow: auto; padding: 18px; }
.tab-panel { display: grid; gap: 16px; }
.settings-card { border-radius: 18px; padding: 18px; box-shadow: none; }
.form-grid { grid-template-columns: repeat(2, minmax(0,1fr)); align-items: end; }
.form-grid h3 { grid-column: 1 / -1; }
.form-grid .primary-btn { min-height: 47px; margin-top: 16px; }
.card-heading { justify-content: space-between; gap: 15px; }
.data-list { display: grid; gap: 9px; }
.data-row {
  display: grid;
  grid-template-columns: minmax(0,1fr) auto;
  align-items: center;
  gap: 14px;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 13px;
  background: rgba(255,255,255,.025);
}
.data-main { min-width: 0; }
.data-main strong, .data-main small { display: block; overflow-wrap: anywhere; }
.data-main small { color: var(--muted); margin-top: 3px; }
.row-actions { display: flex; flex-wrap: wrap; justify-content: flex-end; gap: 7px; }
.row-actions button {
  min-height: 34px; border-radius: 9px; padding: 0 10px;
  color: #fff; background: rgba(255,255,255,.06); border: 1px solid var(--line);
}
.row-actions .danger-small { color: #ffb4b8; border-color: rgba(238,59,67,.25); }
.switch-row {
  grid-template-columns: minmax(0,1fr) auto;
  align-items: center;
  gap: 14px;
  padding: 13px 0;
}
.switch-row small { display: block; color: var(--muted); margin-top: 4px; font-weight: 400; }
.switch-row input { width: 22px; height: 22px; accent-color: var(--red-bright); }
.inline-input { display: flex; align-items: center; gap: 10px; }
.inline-input input { max-width: 180px; }
.info-box {
  margin: 16px 0;
  padding: 13px;
  border-radius: 12px;
  color: var(--muted);
  background: rgba(255,255,255,.035);
  border: 1px solid var(--line);
}
.danger-zone { border-color: rgba(238,59,67,.28); }
.admin-status { padding: 0 18px 12px; margin: 0; }

@media (max-width: 820px) {
  body { overflow: auto; }
  .chat-layout {
    min-height: 100dvh;
    grid-template-columns: 1fr;
    grid-template-rows: 68px minmax(0,1fr);
  }
  .topbar { padding: 0 12px; }
  .topbar-icon { width: 38px; height: 38px; }
  .brand-row strong { font-size: .93rem; }
  .brand-row small { font-size: .7rem; }
  .topbar-actions { gap: 6px; }
  .icon-button, .danger-outline { min-height: 37px; padding: 0 10px; font-size: .78rem; }
  .sidebar { display: none; }
  .chat-main { padding: 13px 10px max(12px, env(safe-area-inset-bottom)); gap: 10px; }
  .chat-heading { padding: 2px 4px; }
  .cleanup-notice { max-width: 46%; text-align: center; font-size: .68rem; padding: 7px 9px; }
  .message { width: min(90%, 720px); }
  .composer { grid-template-columns: 44px minmax(0,1fr) auto; gap: 6px; padding: 7px; }
  .attach-button { width: 42px; height: 42px; }
  .send-button { min-height: 42px; padding: 0 13px; }
  .form-grid { grid-template-columns: 1fr; }
  .form-grid h3 { grid-column: auto; }
  .admin-content { padding: 12px; }
  .modal-backdrop { padding: 6px; }
  .admin-modal { max-height: 98dvh; border-radius: 18px; }
  .modal-header { padding: 17px; }
  .admin-tabs { overflow-x: auto; }
  .data-row { grid-template-columns: 1fr; }
  .row-actions { justify-content: flex-start; }
}

@media (max-width: 470px) {
  .login-card { padding: 26px 20px; border-radius: 22px; }
  .brand-row small { display: none; }
  #installButton { display: none !important; }
}


/* v1.3 diagnostic error report */
.error-report {
  width: 100%;
  min-height: 380px;
  resize: vertical;
  padding: 14px;
  border: 1px solid rgba(255,255,255,.14);
  border-radius: 12px;
  background: #090a0f;
  color: #e8e8ed;
  font: 12px/1.55 Consolas, Monaco, monospace;
  white-space: pre;
}
.row-actions { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
