/* ============================================================
   Vibe — Dark Signal Design System
   ============================================================ */

@import url('https://fonts.googleapis.com/css2?family=DM+Sans:ital,opsz,wght@0,9..40,300;0,9..40,400;0,9..40,500;0,9..40,600;0,9..40,700;1,9..40,400&display=swap');

:root {
  /* Core palette */
  --bg:        #0f0f14;
  --surface-0: #13131c;
  --surface-1: #1c1c28;
  --surface-2: #252535;
  --surface-3: #2f2f42;

  /* Accent */
  --teal:      #00d4aa;
  --teal-dim:  #00a888;
  --teal-glow: rgba(0,212,170,.18);
  --teal-flat: rgba(0,212,170,.12);
  --blue:      #4d9eff;
  --blue-dim:  #2d7dde;

  /* Semantic */
  --green:  #30d158;
  --red:    #ff453a;
  --orange: #ff9f0a;

  /* Text */
  --text:   #eeeef5;
  --text-2: #9898b2;
  --text-3: #55556a;

  /* Borders */
  --border:   rgba(255,255,255,.07);
  --border-2: rgba(255,255,255,.13);

  /* Bubbles */
  --bubble-out-from: #00d4aa;
  --bubble-out-to:   #4d9eff;
  --bubble-in-bg:    rgba(255,255,255,.09);

  /* Layout */
  --sidebar-width: 300px;
  --header-height: 58px;
  --radius:    20px;
  --radius-sm: 10px;
  --radius-xs: 6px;
  --shadow:    0 4px 24px rgba(0,0,0,.45);
  --shadow-sm: 0 2px 10px rgba(0,0,0,.3);

  /* Frosted glass surfaces */
  --frost-sidebar: rgba(19,19,28,.88);
  --frost-header:  rgba(15,15,20,.85);
  --frost-compose: rgba(15,15,20,.92);
  --frost-modal:   rgba(0,0,0,.6);

  --font: 'DM Sans', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
}

/* ---- Light theme overrides ---- */
[data-theme="light"] {
  --bg:        #f5f5f7;
  --surface-0: #ffffff;
  --surface-1: #f0f0f5;
  --surface-2: #e6e6ed;
  --surface-3: #d4d4de;

  --teal:      #00a888;
  --teal-dim:  #008870;
  --teal-glow: rgba(0,168,136,.14);
  --teal-flat: rgba(0,168,136,.09);
  --blue:      #2d7dde;
  --blue-dim:  #1a66cc;

  --text:   #1a1a2e;
  --text-2: #4a4a6a;
  --text-3: #9090a8;

  --border:   rgba(0,0,0,.08);
  --border-2: rgba(0,0,0,.14);

  --bubble-out-from: #00a888;
  --bubble-out-to:   #2d7dde;
  --bubble-in-bg:    rgba(0,0,0,.07);

  --shadow:    0 4px 24px rgba(0,0,0,.12);
  --shadow-sm: 0 2px 10px rgba(0,0,0,.07);

  --frost-sidebar: rgba(255,255,255,.9);
  --frost-header:  rgba(245,245,247,.88);
  --frost-compose: rgba(255,255,255,.94);
  --frost-modal:   rgba(0,0,0,.35);
}

/* ============================================================
   Reset & Base
   ============================================================ */

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

html, body {
  height: 100%;
  font-family: var(--font);
  font-size: 15px;
  color: var(--text);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

a { color: var(--teal); text-decoration: none; }
a:hover { color: var(--teal-dim); }

/* ============================================================
   Buttons
   ============================================================ */

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  padding: 8px 18px; border-radius: var(--radius-sm); border: none;
  font-family: var(--font); font-size: 14px; font-weight: 500;
  cursor: pointer; transition: opacity .15s, background .15s, box-shadow .15s;
  white-space: nowrap; line-height: 1;
}
.btn:disabled { opacity: .4; pointer-events: none; }

.btn--primary {
  background: linear-gradient(135deg, var(--teal) 0%, var(--blue) 100%);
  color: #fff; box-shadow: 0 2px 12px var(--teal-glow);
}
.btn--primary:hover { opacity: .88; box-shadow: 0 4px 20px var(--teal-glow); }

.btn--ghost {
  background: transparent; color: var(--teal);
  border: 1px solid var(--border-2);
}
.btn--ghost:hover { background: var(--teal-flat); border-color: var(--teal); }

.btn--danger { background: var(--red); color: #fff; }
.btn--danger:hover { opacity: .85; }

.btn--sm { padding: 5px 12px; font-size: 12px; }
.btn--full { width: 100%; }

.btn--icon {
  padding: 7px; border-radius: 50%;
  background: transparent; border: none; color: var(--teal);
}
.btn--icon:hover { background: var(--teal-flat); }

/* ============================================================
   Forms
   ============================================================ */

.form-group { margin-bottom: 16px; }
.form-group label {
  display: block; font-size: 12px; font-weight: 600;
  color: var(--text-3); margin-bottom: 6px; text-transform: uppercase; letter-spacing: .06em;
}
.form-control {
  width: 100%; padding: 11px 14px;
  border: 1px solid var(--border-2);
  border-radius: var(--radius-sm); font-family: var(--font); font-size: 15px;
  background: var(--surface-1); color: var(--text);
  transition: border-color .15s, box-shadow .15s; outline: none;
}
.form-control:focus {
  border-color: var(--teal);
  box-shadow: 0 0 0 3px var(--teal-glow);
}
.form-control::placeholder { color: var(--text-3); }
.form-hint { font-size: 12px; color: var(--text-3); margin-top: 4px; }
.form-row { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.form-actions { display: flex; gap: 10px; margin-top: 24px; }
.checkbox-label { display: flex; align-items: center; gap: 8px; cursor: pointer; font-size: 14px; }
.radio-label { display: flex; align-items: center; gap: 4px; font-size: 13px; color: var(--text-2); }

/* ============================================================
   Flash Messages
   ============================================================ */

.flash-container {
  position: fixed; top: 16px; right: 16px; z-index: 1000;
  display: flex; flex-direction: column; gap: 8px; max-width: 360px;
}
.flash {
  padding: 12px 40px 12px 16px; border-radius: var(--radius-sm); font-size: 14px;
  box-shadow: var(--shadow); position: relative; animation: slideIn .2s ease;
  border: 1px solid var(--border-2); backdrop-filter: blur(12px);
}
.flash--success { background: rgba(48,209,88,.15);  color: #6ee7a0; border-color: rgba(48,209,88,.3); }
.flash--danger  { background: rgba(255,69,58,.15);  color: #ff8a80; border-color: rgba(255,69,58,.3); }
.flash--info    { background: rgba(77,158,255,.15); color: #90c4ff; border-color: rgba(77,158,255,.3); }
.flash--warning { background: rgba(255,159,10,.22); color: #ffb830; border-color: rgba(255,159,10,.5); }
[data-theme="light"] .flash--warning { background: #fef3c7; color: #92400e; border-color: #f59e0b; }
.flash__close {
  position: absolute; top: 8px; right: 10px; background: none; border: none;
  cursor: pointer; font-size: 18px; line-height: 1; color: inherit; opacity: .5;
}
.flash__close:hover { opacity: 1; }
@keyframes slideIn { from { transform: translateX(20px); opacity: 0; } to { transform: none; opacity: 1; } }

/* ============================================================
   PWA Banners
   ============================================================ */

.pwa-banner {
  position: fixed; bottom: 0; left: 0; right: 0; z-index: 999;
  background: rgba(28,28,40,.9); backdrop-filter: blur(16px);
  border-top: 1px solid var(--border-2);
  padding: 12px 16px; display: flex; align-items: center; gap: 10px;
  font-size: 14px; box-shadow: 0 -4px 20px rgba(0,0,0,.3);
}
.pwa-banner span { flex: 1; color: var(--text-2); }

/* ============================================================
   Login Page
   ============================================================ */

.login-page {
  display: flex; align-items: center; justify-content: center;
  min-height: 100vh; background: var(--bg);
}
.login-container { width: 100%; max-width: 380px; padding: 16px; }
.login-card {
  background: var(--surface-1);
  border: 1px solid var(--border-2);
  padding: 40px 32px; border-radius: 20px; box-shadow: var(--shadow);
}
.login-logo { text-align: center; margin-bottom: 32px; }
.login-logo img { border-radius: 22px; }
.login-logo h1 { margin-top: 14px; font-size: 28px; font-weight: 700; color: var(--text); }
.login-tagline { color: var(--text-3); font-size: 14px; margin-top: 4px; }

/* ============================================================
   App Shell & Nav Rail
   ============================================================ */

.app-page { height: 100vh; overflow: hidden; background: var(--bg); }

.app-shell {
  display: flex;
  height: 100vh;
  overflow: hidden;
}

.app-content {
  flex: 1;
  min-width: 0;
  overflow: hidden;
  display: flex;
  flex-direction: column;
}

/* ---- Nav Rail ---- */

.nav-rail {
  width: 64px;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  background: var(--surface-0);
  border-right: 1px solid var(--border);
  flex-shrink: 0;
  padding: 10px 0;
  overflow: hidden;
}

.nav-rail__top,
.nav-rail__bottom {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
}

.nav-rail__item {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  width: 48px;
  height: 48px;
  border-radius: 14px;
  color: var(--text-3);
  text-decoration: none;
  cursor: pointer;
  transition: background .15s, color .15s;
  border: none;
  background: transparent;
  position: relative;
}
.nav-rail__item:hover {
  background: var(--teal-flat);
  color: var(--teal);
  text-decoration: none;
}
.nav-rail__item--active {
  background: var(--teal-flat);
  color: var(--teal);
}
.nav-rail__item--active::before {
  content: '';
  position: absolute;
  left: -10px;
  top: 50%;
  transform: translateY(-50%);
  width: 3px;
  height: 24px;
  background: var(--teal);
  border-radius: 0 3px 3px 0;
}

.nav-rail__label {
  display: none;
}

/* Tooltip on hover */
.nav-rail__item[title]:hover::after {
  content: attr(title);
  position: absolute;
  left: calc(100% + 12px);
  top: 50%;
  transform: translateY(-50%);
  background: var(--surface-2);
  color: var(--text);
  font-family: var(--font);
  font-size: 12px;
  font-weight: 500;
  white-space: nowrap;
  padding: 5px 10px;
  border-radius: 8px;
  border: 1px solid var(--border-2);
  box-shadow: var(--shadow-sm);
  pointer-events: none;
  z-index: 999;
}

/* ---- Placeholder pages ---- */

.placeholder-page {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  height: 100%;
  background: var(--bg);
}
.placeholder-page__inner {
  text-align: center;
  max-width: 360px;
  padding: 32px;
}
.placeholder-page__icon {
  width: 88px;
  height: 88px;
  border-radius: 24px;
  background: var(--teal-flat);
  border: 1px solid var(--border-2);
  display: flex;
  align-items: center;
  justify-content: center;
  margin: 0 auto 24px;
  color: var(--teal);
}
.placeholder-page__title {
  font-size: 26px;
  font-weight: 700;
  color: var(--text);
  letter-spacing: -.4px;
  margin-bottom: 12px;
}
.placeholder-page__desc {
  font-size: 15px;
  color: var(--text-2);
  line-height: 1.65;
  margin-bottom: 24px;
}
.placeholder-page__badge {
  display: inline-block;
  padding: 5px 14px;
  border-radius: 20px;
  font-size: 12px;
  font-weight: 600;
  background: var(--teal-flat);
  color: var(--teal);
  border: 1px solid var(--teal-glow);
  text-transform: uppercase;
  letter-spacing: .06em;
}

/* ============================================================
   Messages Layout
   ============================================================ */

.messages-page { height: 100vh; overflow: hidden; background: var(--bg); }

.messages-layout {
  display: grid;
  grid-template-columns: var(--sidebar-width) 1fr;
  height: 100vh;
}

/* ============================================================
   Sidebar
   ============================================================ */

.sidebar {
  display: flex; flex-direction: column;
  border-right: 1px solid var(--border);
  background: var(--surface-0); overflow: hidden;
}

.sidebar__header {
  padding: 16px;
  border-bottom: 1px solid var(--border);
  background: var(--frost-sidebar);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  flex-shrink: 0;
}
.sidebar__title-row { display: flex; justify-content: space-between; align-items: center; }
.sidebar__title { font-size: 20px; font-weight: 700; color: var(--text); letter-spacing: -.3px; }
.sidebar__actions { display: flex; align-items: center; gap: 2px; }

.sidebar__user-row {
  display: flex; align-items: center; gap: 8px;
  margin-top: 8px; font-size: 12px; color: var(--text-3);
}
.sidebar__user-name { flex: 1; font-weight: 500; color: var(--text-2); }

.sidebar__search { padding: 10px 12px; border-bottom: 1px solid var(--border); flex-shrink: 0; }
.search-input {
  width: 100%; padding: 8px 14px;
  border: 1px solid var(--border-2); border-radius: 20px;
  font-family: var(--font); font-size: 14px;
  background: var(--surface-1); color: var(--text);
  outline: none; transition: border-color .15s, box-shadow .15s;
}
.search-input::placeholder { color: var(--text-3); }
.search-input:focus {
  border-color: var(--teal);
  box-shadow: 0 0 0 3px var(--teal-glow);
}

/* ---- Conversation list ---- */

.conversation-list { flex: 1; overflow-y: auto; list-style: none; }
.conversation-list::-webkit-scrollbar { width: 4px; }
.conversation-list::-webkit-scrollbar-track { background: transparent; }
.conversation-list::-webkit-scrollbar-thumb { background: var(--surface-3); border-radius: 4px; }

.convo-item {
  display: flex; align-items: center; gap: 12px; padding: 11px 14px;
  cursor: pointer; border-bottom: 1px solid var(--border);
  transition: background .12s; position: relative;
}
.convo-item:hover { background: var(--surface-1); }

.convo-item--active {
  background: var(--teal-flat) !important;
  border-left: 2px solid var(--teal);
  padding-left: 12px;
}

.convo-avatar {
  width: 44px; height: 44px; border-radius: 50%;
  background: var(--surface-2);
  border: 1px solid var(--border-2);
  display: flex; align-items: center; justify-content: center;
  font-weight: 600; font-size: 12px; color: var(--text-2); flex-shrink: 0;
  font-family: monospace; letter-spacing: .02em;
}
.convo-item--active .convo-avatar {
  background: var(--teal-glow);
  border-color: var(--teal);
  color: var(--teal);
}

.convo-details { flex: 1; min-width: 0; }
.convo-top { display: flex; justify-content: space-between; align-items: baseline; }
.convo-contact { font-weight: 600; font-size: 14px; color: var(--text); }
.convo-item--active .convo-contact { color: var(--teal); }
.convo-time { font-size: 11px; color: var(--text-3); flex-shrink: 0; margin-left: 6px; }
.convo-item--active .convo-time { color: var(--teal); opacity: .7; }

.convo-bottom { display: flex; align-items: center; gap: 6px; margin-top: 2px; }
.convo-preview {
  font-size: 13px; color: var(--text-3);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis; flex: 1;
}
.convo-item--active .convo-preview { color: var(--text-2); }

.convo-badge {
  background: var(--teal); color: #000;
  font-size: 10px; font-weight: 700; border-radius: 12px; padding: 2px 7px;
  flex-shrink: 0;
}
.convo-item--unread .convo-contact { color: var(--text); }
.convo-item--unread .convo-preview { color: var(--text-2); font-weight: 500; }

.convo-number-tag { font-size: 11px; color: var(--text-3); margin-top: 2px; font-family: monospace; }
.convo-item--active .convo-number-tag { color: var(--teal); opacity: .6; }

.convo-empty {
  padding: 48px 20px; text-align: center;
  color: var(--text-3); font-size: 14px; line-height: 1.7;
}

/* ============================================================
   Thread Area
   ============================================================ */

.thread-area {
  display: flex; flex-direction: column; height: 100vh; overflow: hidden;
  background: var(--bg);
}

.thread-placeholder {
  flex: 1; display: flex; align-items: center; justify-content: center;
}
.thread-placeholder__inner { text-align: center; color: var(--text-3); }
.thread-placeholder__inner img {
  border-radius: 28px; margin-bottom: 20px;
  opacity: .35; filter: saturate(.4);
}
.thread-placeholder__inner h2 {
  font-size: 22px; font-weight: 700;
  color: var(--text-2); margin-bottom: 8px; letter-spacing: -.3px;
}
.thread-placeholder__inner p { font-size: 14px; color: var(--text-3); }

.thread-view { display: flex; flex-direction: column; height: 100%; }

/* ---- Thread header ---- */

.thread-header {
  display: flex; align-items: center; gap: 12px; padding: 12px 20px;
  border-bottom: 1px solid var(--border);
  background: var(--frost-header);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  min-height: var(--header-height); flex-shrink: 0;
}
.back-btn { display: none; }
.thread-header__info { flex: 1; }
.thread-header__contact {
  font-weight: 600; font-size: 16px; display: block;
  color: var(--text); letter-spacing: -.2px;
}
.thread-header__via { font-size: 12px; color: var(--text-3); font-family: monospace; }

/* ---- Message bubbles area ---- */

.message-bubbles {
  flex: 1; overflow-y: auto; padding: 20px 20px 12px;
  display: flex; flex-direction: column; gap: 2px;
  background: var(--bg);
}
.message-bubbles::-webkit-scrollbar { width: 4px; }
.message-bubbles::-webkit-scrollbar-track { background: transparent; }
.message-bubbles::-webkit-scrollbar-thumb { background: var(--surface-3); border-radius: 4px; }

/* ---- Bubbles ---- */

.bubble-group { display: flex; flex-direction: column; margin-bottom: 6px; }
.bubble-group--out { align-items: flex-end; }
.bubble-group--in  { align-items: flex-start; }

.bubble {
  max-width: 68%; padding: 10px 15px; font-size: 15px;
  line-height: 1.45; position: relative; word-break: break-word;
  font-weight: 400;
}

/* Outbound: teal→blue gradient */
.bubble--out {
  background: linear-gradient(135deg, var(--bubble-out-from) 0%, var(--bubble-out-to) 100%);
  color: #fff;
  border-radius: var(--radius) var(--radius) 4px var(--radius);
  box-shadow: 0 2px 16px var(--teal-glow);
}

/* Inbound: frosted glass */
.bubble--in {
  background: var(--bubble-in-bg);
  color: var(--text);
  border-radius: var(--radius) var(--radius) var(--radius) 4px;
  border: 1px solid var(--border-2);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
}

.bubble img { max-width: 220px; border-radius: 12px; display: block; margin-top: 4px; }

/* ---- Bubble meta ---- */

.bubble-meta {
  font-size: 11px; color: var(--text-3); margin-top: 3px; padding: 0 4px;
  display: flex; align-items: center; gap: 6px;
}
.bubble-group--out .bubble-meta { justify-content: flex-end; }

.bubble-status { font-size: 11px; }
.bubble-status--queued   { color: var(--text-3); }
.bubble-status--sent     { color: var(--text-3); }
.bubble-status--delivered{ color: var(--teal); }
.bubble-status--failed   { color: var(--red); font-weight: 600; }
.bubble-status--received { color: var(--teal); }

/* ============================================================
   Compose Area
   ============================================================ */

.compose-area {
  padding: 12px 16px;
  border-top: 1px solid var(--border);
  background: var(--frost-compose);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  flex-shrink: 0;
}
.compose-from {
  display: flex; align-items: center; gap: 8px;
  margin-bottom: 8px; font-size: 12px; color: var(--text-3);
}
.from-select {
  border: none; background: transparent;
  font-family: var(--font); font-size: 12px; color: var(--teal);
  font-weight: 600; cursor: pointer; padding: 2px 0; outline: none;
}
.from-select option { background: var(--surface-1); color: var(--text); }

.compose-input-row { display: flex; align-items: flex-end; gap: 10px; }

.attach-btn {
  cursor: pointer; color: var(--text-2); flex-shrink: 0; padding: 6px;
  border-radius: 50%; transition: color .15s, background .15s;
}
.attach-btn:hover { color: var(--teal); background: var(--teal-flat); }

.message-input {
  flex: 1;
  border: 1px solid var(--border-2); border-radius: 22px;
  padding: 10px 16px;
  font-family: var(--font); font-size: 15px;
  background: var(--surface-1); color: var(--text);
  resize: none; outline: none; max-height: 120px;
  overflow-y: auto; line-height: 1.4;
  transition: border-color .15s, box-shadow .15s;
}
.message-input::placeholder { color: var(--text-3); }
.message-input:focus {
  border-color: var(--teal);
  box-shadow: 0 0 0 3px var(--teal-glow);
}

.send-btn {
  width: 38px; height: 38px; border-radius: 50%; flex-shrink: 0;
  background: linear-gradient(135deg, var(--teal) 0%, var(--blue) 100%);
  color: white; border: none; cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  box-shadow: 0 2px 12px var(--teal-glow);
  transition: opacity .15s, box-shadow .15s;
}
.send-btn:hover { opacity: .85; box-shadow: 0 4px 20px var(--teal-glow); }
.send-btn:disabled { background: var(--surface-2); box-shadow: none; cursor: default; }

.opted-out-notice {
  display: flex; align-items: center; gap: 7px;
  font-size: 13px; color: var(--orange);
  padding: 7px 12px; margin-bottom: 8px;
  background: rgba(255,159,10,.1);
  border: 1px solid rgba(255,159,10,.25);
  border-radius: var(--radius-sm);
}
[data-theme="light"] .opted-out-notice {
  color: #92400e; background: #fef3c7; border-color: #f59e0b;
}

.compose-area--locked .message-input {
  background: var(--surface-2);
  color: var(--text-3);
  cursor: not-allowed;
  border-color: var(--border);
}
.compose-area--locked .send-btn {
  background: var(--surface-2);
  box-shadow: none;
  cursor: not-allowed;
}

.media-preview { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 8px; }
.media-preview img { width: 64px; height: 64px; object-fit: cover; border-radius: 10px; }
.media-preview-item { position: relative; }
.media-preview-remove {
  position: absolute; top: -5px; right: -5px;
  width: 20px; height: 20px; border-radius: 50%;
  background: var(--red); color: white; border: none; cursor: pointer;
  font-size: 12px; display: flex; align-items: center; justify-content: center;
  box-shadow: 0 1px 4px rgba(0,0,0,.4);
}

/* ============================================================
   Compose Modal
   ============================================================ */

.modal-overlay {
  position: fixed; inset: 0;
  background: var(--frost-modal);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  z-index: 500; display: flex; align-items: center; justify-content: center;
}
.modal {
  background: var(--surface-1);
  border: 1px solid var(--border-2);
  border-radius: 20px; width: 100%; max-width: 440px; margin: 16px;
  box-shadow: var(--shadow); overflow: hidden;
}
.modal__header {
  display: flex; justify-content: space-between; align-items: center;
  padding: 18px 22px; border-bottom: 1px solid var(--border);
}
.modal__header h3 { font-size: 17px; font-weight: 700; color: var(--text); }
.modal__body { padding: 22px; }
.modal__footer {
  padding: 14px 22px; border-top: 1px solid var(--border);
  display: flex; justify-content: flex-end; gap: 10px;
}
.pw-display {
  display: flex; align-items: center; gap: 10px;
  background: var(--surface-2); border: 1px solid var(--border-2);
  border-radius: var(--radius-sm); padding: 10px 14px;
}
.pw-display code {
  flex: 1; font-size: 17px; font-family: monospace;
  letter-spacing: .08em; color: var(--teal); user-select: all;
}

/* ============================================================
   Contacts Page
   ============================================================ */

.contacts-layout {
  display: grid;
  grid-template-columns: 300px 1fr;
  height: 100%;
  overflow: hidden;
}

/* ---- Contact sidebar ---- */

.contacts-sidebar {
  display: flex; flex-direction: column;
  background: var(--surface-0);
  border-right: 1px solid var(--border);
  overflow: hidden;
}
.contacts-sidebar__header {
  padding: 16px;
  border-bottom: 1px solid var(--border);
  background: var(--frost-sidebar);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  display: flex; align-items: center; justify-content: space-between;
  flex-shrink: 0;
}
.contacts-sidebar__title { font-size: 20px; font-weight: 700; color: var(--text); letter-spacing: -.3px; }
.contacts-count { font-size: 12px; color: var(--text-3); }
.contacts-sidebar__search { padding: 10px 12px; border-bottom: 1px solid var(--border); flex-shrink: 0; }

.contact-list { flex: 1; overflow-y: auto; list-style: none; }
.contact-list::-webkit-scrollbar { width: 4px; }
.contact-list::-webkit-scrollbar-thumb { background: var(--surface-3); border-radius: 4px; }

.contact-list__loading,
.contact-list__empty {
  padding: 32px 16px; text-align: center; color: var(--text-3); font-size: 14px;
}

/* ---- Contact list item ---- */

.contact-item {
  display: flex; align-items: center; gap: 12px;
  padding: 11px 14px; cursor: pointer;
  border-bottom: 1px solid var(--border);
  transition: background .12s;
}
.contact-item:hover { background: var(--surface-1); }
.contact-item--active {
  background: var(--teal-flat) !important;
  border-left: 2px solid var(--teal);
  padding-left: 12px;
}
.contact-item__avatar {
  width: 44px; height: 44px; border-radius: 50%; flex-shrink: 0;
  background: var(--surface-2); border: 1px solid var(--border-2);
  display: flex; align-items: center; justify-content: center;
  font-size: 13px; font-weight: 600; color: var(--text-2);
  font-family: monospace;
}
.contact-item--active .contact-item__avatar {
  background: var(--teal-glow); border-color: var(--teal); color: var(--teal);
}
.contact-item__info { flex: 1; min-width: 0; }
.contact-item__name {
  font-size: 14px; font-weight: 600; color: var(--text);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.contact-item--active .contact-item__name { color: var(--teal); }
.contact-item__company {
  font-size: 12px; color: var(--text-3); margin-top: 1px;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.contact-item__badges { display: flex; gap: 4px; margin-top: 4px; flex-wrap: wrap; }

/* ---- Contact badges ---- */

.contact-badge {
  display: inline-block; font-size: 10px; font-weight: 600;
  padding: 1px 6px; border-radius: 8px; text-transform: uppercase; letter-spacing: .04em;
}
.contact-badge--blocked { background: rgba(255,69,58,.15); color: var(--red); }
.contact-badge--optout  { background: rgba(255,159,10,.15); color: var(--orange); }
.contact-badge--new     { background: var(--teal-flat); color: var(--teal); }

/* ---- Contact detail ---- */

.contact-detail {
  display: flex; flex-direction: column;
  background: var(--bg); overflow-y: auto;
}
.contact-detail__placeholder {
  flex: 1; display: flex; flex-direction: column;
  align-items: center; justify-content: center; gap: 16px;
  color: var(--text-3); font-size: 14px;
}
.contact-detail__placeholder .placeholder-page__icon { margin: 0; }

/* ---- Contact form ---- */

.contact-form {
  display: flex; flex-direction: column; height: 100%;
}
.contact-form__header {
  display: flex; align-items: center; gap: 16px;
  padding: 20px 28px;
  border-bottom: 1px solid var(--border);
  background: var(--frost-header);
  backdrop-filter: blur(16px); -webkit-backdrop-filter: blur(16px);
  flex-shrink: 0;
}
.contact-form__avatar {
  width: 56px; height: 56px; border-radius: 50%; flex-shrink: 0;
  background: var(--teal-flat); border: 2px solid var(--teal);
  display: flex; align-items: center; justify-content: center;
  font-size: 18px; font-weight: 700; color: var(--teal); font-family: monospace;
}
.contact-form__header-info { flex: 1; }
.contact-form__phone { font-size: 18px; font-weight: 700; color: var(--text); letter-spacing: -.2px; }
.contact-form__badges { display: flex; gap: 6px; margin-top: 6px; flex-wrap: wrap; }
.contact-form__header-actions { display: flex; gap: 8px; flex-shrink: 0; }

.contact-form__body { flex: 1; padding: 24px 28px; overflow-y: auto; }
.contact-form__row { display: grid; grid-template-columns: 1fr 1fr; gap: 0 20px; }

/* ---- Opt-out toggle ---- */

.contact-form__toggles { margin-top: 8px; }
.toggle-label {
  display: flex; align-items: center; gap: 14px;
  padding: 14px 16px; border-radius: var(--radius-sm);
  border: 1px solid var(--border-2); background: var(--surface-1);
  cursor: pointer;
}
.toggle-checkbox { display: none; }
.toggle-track {
  width: 42px; height: 24px; border-radius: 12px;
  background: var(--surface-3); flex-shrink: 0;
  position: relative; transition: background .2s;
}
.toggle-track::after {
  content: ''; position: absolute;
  top: 3px; left: 3px;
  width: 18px; height: 18px; border-radius: 50%;
  background: white; transition: transform .2s;
  box-shadow: 0 1px 4px rgba(0,0,0,.3);
}
.toggle-checkbox:checked + .toggle-track { background: var(--orange); }
.toggle-checkbox:checked + .toggle-track::after { transform: translateX(18px); }
.toggle-text { flex: 1; }
.toggle-text__title { display: block; font-size: 14px; font-weight: 500; color: var(--text); }
.toggle-text__desc  { display: block; font-size: 12px; color: var(--text-3); margin-top: 2px; }

/* ---- Form footer ---- */

.contact-form__footer {
  padding: 16px 28px;
  border-top: 1px solid var(--border);
  background: var(--frost-compose);
  backdrop-filter: blur(16px); -webkit-backdrop-filter: blur(16px);
  display: flex; align-items: center; justify-content: flex-end; gap: 12px;
  flex-shrink: 0;
}
.contact-form__status { font-size: 13px; color: var(--text-3); flex: 1; }
.contact-form__status--success { color: var(--green); }
.contact-form__status--error   { color: var(--red); }

/* ---- Contacts responsive ---- */

@media (max-width: 768px) {
  .contacts-layout { grid-template-columns: 1fr; }
  .contact-detail {
    position: fixed; inset: 0 0 56px 0; z-index: 200;
    transform: translateX(100%); transition: transform .3s cubic-bezier(.4,0,.2,1);
  }
  .contact-detail.active { transform: translateX(0); }
  .contact-form__row { grid-template-columns: 1fr; }
  .contact-form__header { padding: 16px; }
  .contact-form__body { padding: 16px; }
  .contact-form__footer { padding: 12px 16px; }
}

/* ============================================================
   Admin Layout
   ============================================================ */

.admin-page { min-height: 100vh; background: var(--bg); }
.admin-layout { display: grid; grid-template-columns: 220px 1fr; min-height: 100vh; }

.admin-nav {
  background: var(--surface-0); color: var(--text);
  border-right: 1px solid var(--border);
  display: flex; flex-direction: column; min-height: 100vh;
}
.admin-nav__brand {
  padding: 20px 16px; font-size: 16px; font-weight: 700;
  border-bottom: 1px solid var(--border); color: var(--text);
}
.admin-nav__brand a { color: var(--teal); }
.admin-nav__links { list-style: none; flex: 1; padding: 8px 0; }
.admin-nav__links li a {
  display: block; padding: 10px 16px;
  color: var(--text-2); font-size: 14px; transition: all .15s;
  border-left: 2px solid transparent;
}
.admin-nav__links li a:hover,
.admin-nav__links li a.active {
  color: var(--teal); background: var(--teal-flat);
  border-left-color: var(--teal); text-decoration: none;
}
.admin-nav__footer {
  padding: 16px; border-top: 1px solid var(--border);
  display: flex; flex-direction: column; gap: 8px; font-size: 13px;
}
.admin-nav__footer a { color: var(--text-3); }
.admin-nav__footer a:hover { color: var(--teal); }

.admin-content { padding: 28px 32px; max-width: 1100px; }
.admin-header { display: flex; align-items: center; justify-content: space-between; margin-bottom: 24px; }
.admin-header h1 { font-size: 24px; font-weight: 700; color: var(--text); letter-spacing: -.4px; }

/* ---- Stat cards ---- */
.stat-cards { display: grid; grid-template-columns: repeat(3, 1fr); gap: 16px; }
.stat-card {
  background: var(--surface-1); border: 1px solid var(--border);
  border-radius: 14px; padding: 24px; box-shadow: var(--shadow-sm);
}
.stat-card__value { font-size: 40px; font-weight: 700; color: var(--teal); }
.stat-card__label { font-size: 14px; color: var(--text-2); margin-top: 4px; }
.stat-card__link { font-size: 13px; color: var(--teal); margin-top: 12px; display: inline-block; }

/* ---- Data table ---- */
.table-container {
  background: var(--surface-1); border: 1px solid var(--border);
  border-radius: 14px; box-shadow: var(--shadow-sm); overflow: hidden;
}
.data-table { width: 100%; border-collapse: collapse; font-size: 14px; }
.data-table th {
  padding: 12px 16px; text-align: left; font-weight: 600;
  font-size: 11px; text-transform: uppercase; letter-spacing: .07em;
  color: var(--text-3); background: var(--surface-2);
  border-bottom: 1px solid var(--border);
}
.data-table td { padding: 12px 16px; border-bottom: 1px solid var(--border); vertical-align: middle; color: var(--text-2); }
.data-table tbody tr:last-child td { border-bottom: none; }
.data-table tbody tr:hover td { background: var(--surface-2); color: var(--text); }
.row--muted td { opacity: .4; }
.actions { display: flex; gap: 6px; flex-wrap: wrap; }
.text-center { text-align: center; }
.text-muted { color: var(--text-3); }
.text-sm { font-size: 12px; }
.text-nowrap { white-space: nowrap; }

/* ---- Admin form ---- */
.admin-form {
  background: var(--surface-1); border: 1px solid var(--border);
  border-radius: 14px; padding: 28px; box-shadow: var(--shadow-sm); max-width: 640px;
}
.phone-number-list { display: flex; flex-direction: column; gap: 8px; }
.phone-number-row {
  display: flex; align-items: center; justify-content: space-between;
  padding: 10px 14px; border: 1px solid var(--border-2);
  border-radius: var(--radius-sm); background: var(--surface-2);
}
.simple-list { list-style: none; }
.simple-list li { padding: 6px 0; border-bottom: 1px solid var(--border); font-size: 14px; color: var(--text-2); }

/* ---- Badges / Pills ---- */
.badge { display: inline-block; padding: 2px 8px; border-radius: 10px; font-size: 11px; font-weight: 600; }
.badge--admin    { background: rgba(139,92,246,.2);  color: #c4b5fd; }
.badge--user     { background: var(--surface-2);     color: var(--text-3); }
.badge--active   { background: rgba(48,209,88,.15);  color: var(--green); }
.badge--inactive { background: rgba(255,69,58,.15);  color: var(--red); }
.number-pill {
  display: inline-block; background: var(--surface-2); color: var(--text-2);
  border-radius: 10px; padding: 2px 8px; font-size: 12px; font-family: monospace;
}
.number-pill--default { background: rgba(77,158,255,.15); color: var(--blue); }

/* ---- Filter form ---- */
.filter-form { display: flex; gap: 8px; margin-bottom: 16px; }
.filter-form .form-control { max-width: 300px; }

/* ---- Pagination ---- */
.pagination { display: flex; align-items: center; gap: 12px; margin-top: 16px; justify-content: center; }
.pagination__info { font-size: 14px; color: var(--text-2); }

/* ============================================================
   Responsive
   ============================================================ */

/* ============================================================
   Theme toggle icons
   Dark mode  → show sun  (click to switch to light)
   Light mode → show moon (click to switch to dark)
   ============================================================ */

/* Default (light): show moon, hide sun */
.icon-sun  { display: none; }
.icon-moon { display: block; }

/* Dark: hide moon, show sun */
[data-theme="dark"] .icon-sun  { display: block; }
[data-theme="dark"] .icon-moon { display: none; }

@media (max-width: 768px) {
  /* Nav rail → bottom tab bar */
  .app-shell { flex-direction: column; }
  .nav-rail {
    width: 100%; height: 56px; flex-direction: row;
    border-right: none; border-top: 1px solid var(--border);
    order: 2; padding: 0 8px;
    justify-content: space-around; align-items: center;
  }
  .nav-rail__top, .nav-rail__bottom {
    flex-direction: row; gap: 0;
  }
  .nav-rail__bottom { margin-left: auto; }
  .nav-rail__item { width: 44px; height: 44px; border-radius: 12px; }
  .nav-rail__item--active::before { display: none; }
  .nav-rail__item[title]:hover::after { display: none; }
  .app-content { order: 1; flex: 1; min-height: 0; }

  /* Messages layout */
  .messages-layout { grid-template-columns: 1fr; }
  .sidebar { position: fixed; inset: 0 0 56px 0; z-index: 100; transform: translateX(0); }
  .sidebar.hidden { transform: translateX(-100%); }
  .thread-area {
    position: fixed; inset: 0 0 56px 0; z-index: 200;
    background: var(--bg); transform: translateX(100%); transition: transform .3s cubic-bezier(.4,0,.2,1);
  }
  .thread-area.active { transform: translateX(0); }
  .back-btn { display: flex !important; }

  /* Admin */
  .admin-layout { grid-template-columns: 1fr; }
  .admin-nav { min-height: auto; }
  .stat-cards { grid-template-columns: 1fr; }
  .form-row { grid-template-columns: 1fr; }
}
