/* ═══════════════════════════════════════════════════════════════════════════
   DESIGN TOKENS — Dark Theme
═══════════════════════════════════════════════════════════════════════════ */
:root {
  --bg-base:       #0c0c0e;
  --bg-panel:      #131316;
  --bg-panel-alt:  #1a1a1f;
  --bg-hover:      #1f1f26;
  --bg-selected:   #22222c;
  --bg-input:      #1c1c22;
  --bg-modal:      #18181f;

  --border:        #2a2a35;
  --border-focus:  #5b5bd6;

  --text-primary:  #e8e8f0;
  --text-secondary:#8888a8;
  --text-muted:    #55556a;
  --text-link:     #8b8bff;

  --accent:        #5b5bd6;
  --accent-hover:  #6e6ef0;
  --accent-dim:    rgba(91,91,214,0.15);

  --green:         #34c77b;
  --green-dim:     rgba(52,199,123,0.15);
  --red:           #e05252;
  --red-dim:       rgba(224,82,82,0.15);
  --amber:         #e0a020;
  --amber-dim:     rgba(224,160,32,0.15);

  --msg-out-bg:    #2a2a4a;
  --msg-in-bg:     #1e1e28;

  --radius-sm:     6px;
  --radius-md:     10px;
  --radius-lg:     16px;
  --radius-pill:   999px;

  --font:          'Inter', system-ui, sans-serif;
  --transition:    150ms ease;

  --topbar-h:      52px;
  --left-w:        280px;
  --right-w:       260px;
}

/* ═══════════════════════════════════════════════════════════════════════════
   RESET & BASE
═══════════════════════════════════════════════════════════════════════════ */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

html, body {
  height: 100%;
  font-family: var(--font);
  font-size: 14px;
  background: var(--bg-base);
  color: var(--text-primary);
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

button {
  cursor: pointer;
  font-family: var(--font);
  font-size: 13px;
  font-weight: 500;
  border: 1px solid var(--border);
  background: var(--bg-panel-alt);
  color: var(--text-primary);
  border-radius: var(--radius-sm);
  padding: 6px 14px;
  transition: background var(--transition), border-color var(--transition);
}
button:hover { background: var(--bg-hover); border-color: var(--border-focus); }
button:active { opacity: 0.8; }

input, textarea {
  font-family: var(--font);
  font-size: 13px;
  background: var(--bg-input);
  color: var(--text-primary);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 8px 12px;
  width: 100%;
  outline: none;
  transition: border-color var(--transition);
  resize: none;
}
input:focus, textarea:focus { border-color: var(--border-focus); }
input::placeholder, textarea::placeholder { color: var(--text-muted); }

h2 { font-size: 12px; font-weight: 600; text-transform: uppercase;
     letter-spacing: 0.08em; color: var(--text-secondary); margin-bottom: 12px; }

a { color: var(--text-link); text-decoration: none; }

/* ═══════════════════════════════════════════════════════════════════════════
   TOP BAR
═══════════════════════════════════════════════════════════════════════════ */
#topbar {
  position: fixed;
  top: 0; left: 0; right: 0;
  height: var(--topbar-h);
  background: var(--bg-panel);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  padding: 0 20px;
  gap: 16px;
  z-index: 100;
}

#topbar-brand {
  font-weight: 600;
  font-size: 15px;
  color: var(--text-primary);
  flex: 1;
}

#topbar-status {
  display: flex;
  align-items: center;
  gap: 7px;
  font-size: 12px;
  color: var(--text-secondary);
}

.dot {
  width: 8px; height: 8px;
  border-radius: 50%;
  display: inline-block;
  flex-shrink: 0;
}
.dot.online  { background: var(--green); box-shadow: 0 0 6px var(--green); }
.dot.offline { background: var(--text-muted); }
.dot.ringing { background: var(--amber); box-shadow: 0 0 6px var(--amber);
               animation: pulse-dot 1s ease infinite; }

@keyframes pulse-dot {
  0%, 100% { opacity: 1; }
  50%       { opacity: 0.3; }
}

#topbar-number {
  font-size: 12px;
  color: var(--text-secondary);
  font-variant-numeric: tabular-nums;
}

/* ═══════════════════════════════════════════════════════════════════════════
   MAIN LAYOUT
═══════════════════════════════════════════════════════════════════════════ */
#layout {
  display: grid;
  grid-template-columns: var(--left-w) 1fr var(--right-w);
  height: 100vh;
  padding-top: var(--topbar-h);
}

/* ═══════════════════════════════════════════════════════════════════════════
   LEFT PANEL
═══════════════════════════════════════════════════════════════════════════ */
#left-panel {
  background: var(--bg-panel);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

/* Nav */
#main-nav {
  display: flex;
  border-bottom: 1px solid var(--border);
  padding: 8px 8px 0;
  gap: 2px;
}

.nav-btn {
  flex: 1;
  border: none;
  border-bottom: 2px solid transparent;
  border-radius: var(--radius-sm) var(--radius-sm) 0 0;
  background: transparent;
  color: var(--text-secondary);
  padding: 8px 4px;
  font-size: 12px;
  font-weight: 500;
  transition: color var(--transition), border-color var(--transition);
}
.nav-btn:hover  { background: var(--bg-hover); color: var(--text-primary); }
.nav-btn.active {
  color: var(--accent);
  border-bottom-color: var(--accent);
  background: transparent;
}

/* Search */
#search-bar {
  padding: 10px 12px;
  border-bottom: 1px solid var(--border);
}
#search-input { border-radius: var(--radius-pill); font-size: 13px; }

/* List */
#list-pane {
  flex: 1;
  overflow-y: auto;
  overflow-x: hidden;
}

.empty-state {
  padding: 40px 20px;
  text-align: center;
  color: var(--text-muted);
  font-size: 13px;
  line-height: 2;
}

/* Thread row */
.thread-row {
  display: flex;
  flex-direction: column;
  padding: 12px 14px;
  border-bottom: 1px solid var(--border);
  cursor: pointer;
  transition: background var(--transition);
  gap: 3px;
}
.thread-row:hover { background: var(--bg-hover); }
.thread-row.active { background: var(--bg-selected); }

.thread-name {
  font-weight: 500;
  font-size: 13px;
  color: var(--text-primary);
  display: flex;
  justify-content: space-between;
}
.thread-time {
  font-size: 11px;
  color: var(--text-muted);
  font-variant-numeric: tabular-nums;
  flex-shrink: 0;
}
.thread-preview {
  font-size: 12px;
  color: var(--text-secondary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.thread-dir-badge {
  font-size: 10px;
  font-weight: 600;
  color: var(--text-muted);
  margin-right: 4px;
}

/* Call row */
.call-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 11px 14px;
  border-bottom: 1px solid var(--border);
  cursor: pointer;
  transition: background var(--transition);
}
.call-row:hover { background: var(--bg-hover); }
.call-left  { display: flex; flex-direction: column; gap: 2px; }
.call-name  { font-size: 13px; font-weight: 500; }
.call-meta  { font-size: 11px; color: var(--text-secondary); }
.call-right { font-size: 11px; color: var(--text-muted); text-align: right; }

.call-dir-in  { color: var(--green); font-weight: 600; }
.call-dir-out { color: var(--accent); font-weight: 600; }

/* Contact row */
.contact-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 11px 14px;
  border-bottom: 1px solid var(--border);
  transition: background var(--transition);
}
.contact-row:hover { background: var(--bg-hover); }
.contact-left  { display: flex; flex-direction: column; gap: 2px; }
.contact-name  { font-size: 13px; font-weight: 500; }
.contact-phone { font-size: 12px; color: var(--text-secondary); }
.contact-actions { display: flex; gap: 6px; }
.contact-actions button { padding: 4px 10px; font-size: 11px; }

/* New message bar */
#new-message-bar {
  padding: 10px 12px;
  border-top: 1px solid var(--border);
}
#btn-new-message {
  width: 100%;
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
  font-weight: 600;
}
#btn-new-message:hover { background: var(--accent-hover); border-color: var(--accent-hover); }

/* ═══════════════════════════════════════════════════════════════════════════
   CENTER PANEL — Conversation
═══════════════════════════════════════════════════════════════════════════ */
#center-panel {
  display: flex;
  flex-direction: column;
  background: var(--bg-base);
  overflow: hidden;
}

#conversation-header {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 20px;
  border-bottom: 1px solid var(--border);
  background: var(--bg-panel);
  flex-shrink: 0;
}
#conv-name   { font-weight: 600; font-size: 15px; flex: 1; }
#conv-phone  { font-size: 12px; color: var(--text-secondary); }
#conv-actions button { padding: 5px 14px; font-size: 12px; }

#message-thread {
  flex: 1;
  overflow-y: auto;
  padding: 16px 24px;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

/* Message bubbles */
.msg-bubble-wrap {
  display: flex;
  flex-direction: column;
  max-width: 72%;
}
.msg-bubble-wrap.out { align-self: flex-end; align-items: flex-end; }
.msg-bubble-wrap.in  { align-self: flex-start; align-items: flex-start; }

.msg-bubble {
  padding: 9px 14px;
  border-radius: var(--radius-lg);
  font-size: 13px;
  line-height: 1.55;
  word-break: break-word;
}
.msg-bubble.out {
  background: var(--msg-out-bg);
  border-bottom-right-radius: var(--radius-sm);
}
.msg-bubble.in {
  background: var(--msg-in-bg);
  border: 1px solid var(--border);
  border-bottom-left-radius: var(--radius-sm);
}

.msg-meta {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 10px;
  color: var(--text-muted);
  margin-top: 3px;
}
.msg-status { color: var(--green); }
.msg-status.failed { color: var(--red); }

.rcs-badge {
  font-size: 9px;
  font-weight: 700;
  padding: 1px 5px;
  border-radius: var(--radius-pill);
  background: var(--accent-dim);
  color: var(--accent);
  letter-spacing: 0.05em;
}

.msg-date-divider {
  text-align: center;
  font-size: 11px;
  color: var(--text-muted);
  margin: 12px 0 4px;
  position: relative;
}
.msg-date-divider::before, .msg-date-divider::after {
  content: '';
  position: absolute;
  top: 50%;
  width: 30%;
  height: 1px;
  background: var(--border);
}
.msg-date-divider::before { left: 0; }
.msg-date-divider::after  { right: 0; }

/* Compose */
#compose-bar {
  display: flex;
  gap: 8px;
  align-items: flex-end;
  padding: 12px 20px;
  border-top: 1px solid var(--border);
  background: var(--bg-panel);
  flex-shrink: 0;
}
#compose-input {
  flex: 1;
  max-height: 120px;
  overflow-y: auto;
  border-radius: var(--radius-md);
  line-height: 1.5;
}
#compose-controls { display: flex; align-items: center; gap: 8px; flex-shrink: 0; }

#rcs-indicator {
  font-size: 10px;
  font-weight: 700;
  padding: 2px 7px;
  border-radius: var(--radius-pill);
  background: var(--accent-dim);
  color: var(--accent);
  letter-spacing: 0.05em;
}
#btn-send {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
  font-weight: 600;
  padding: 8px 20px;
}
#btn-send:hover { background: var(--accent-hover); border-color: var(--accent-hover); }

/* ═══════════════════════════════════════════════════════════════════════════
   RIGHT PANEL — Dialer / Call
═══════════════════════════════════════════════════════════════════════════ */
#right-panel {
  background: var(--bg-panel);
  border-left: 1px solid var(--border);
  padding: 20px 16px;
  display: flex;
  flex-direction: column;
  gap: 24px;
  overflow-y: auto;
}

#dialer-section, #active-call-section, #incoming-call-section {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

#dial-input {
  font-size: 18px;
  font-weight: 300;
  text-align: center;
  letter-spacing: 0.06em;
  border-radius: var(--radius-md);
  padding: 12px;
}

#dialpad-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 6px;
}
.dialpad-key {
  aspect-ratio: 1;
  font-size: 18px;
  font-weight: 300;
  border-radius: var(--radius-md);
  background: var(--bg-panel-alt);
  border: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: center;
}
.dialpad-key:hover { background: var(--bg-hover); }
.dialpad-key:active { background: var(--bg-selected); }

#dialer-actions {
  display: grid;
  grid-template-columns: 1fr 2fr;
  gap: 6px;
}
#btn-call {
  background: var(--green);
  border-color: var(--green);
  color: #fff;
  font-weight: 600;
  font-size: 14px;
  padding: 10px;
}
#btn-call:hover { background: #2db86d; border-color: #2db86d; }

/* Active call */
#active-call-section {
  background: var(--green-dim);
  border: 1px solid var(--green);
  border-radius: var(--radius-md);
  padding: 16px;
}
#call-peer-name   { font-weight: 600; font-size: 16px; }
#call-peer-number { font-size: 12px; color: var(--text-secondary); }
#call-timer       { font-size: 22px; font-weight: 300; font-variant-numeric: tabular-nums;
                    letter-spacing: 0.05em; margin: 4px 0; }
#call-status-label { font-size: 11px; color: var(--text-secondary); }

#call-controls { display: flex; gap: 8px; }
#btn-mute   { flex: 1; }
#btn-hangup { flex: 2; background: var(--red); border-color: var(--red); color: #fff; font-weight: 600; }
#btn-hangup:hover { background: #c94444; border-color: #c94444; }

/* Incoming call */
#incoming-call-section {
  background: var(--amber-dim);
  border: 1px solid var(--amber);
  border-radius: var(--radius-md);
  padding: 16px;
  animation: glow-amber 1.5s ease infinite;
}
@keyframes glow-amber {
  0%, 100% { box-shadow: 0 0 0 0 rgba(224,160,32,0); }
  50%       { box-shadow: 0 0 16px 2px rgba(224,160,32,0.25); }
}
#incoming-caller-name   { font-weight: 600; font-size: 16px; }
#incoming-caller-number { font-size: 12px; color: var(--text-secondary); margin-bottom: 8px; }
#incoming-actions { display: flex; gap: 8px; }
#btn-answer  { flex: 1; background: var(--green); border-color: var(--green); color: #fff; font-weight: 600; }
#btn-decline { flex: 1; background: var(--red);   border-color: var(--red);   color: #fff; font-weight: 600; }

/* ═══════════════════════════════════════════════════════════════════════════
   MODALS
═══════════════════════════════════════════════════════════════════════════ */
.modal {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.6);
  backdrop-filter: blur(4px);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 200;
  animation: fade-in 120ms ease;
}
@keyframes fade-in { from { opacity: 0; } to { opacity: 1; } }

.modal-box {
  background: var(--bg-modal);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 24px;
  width: 420px;
  max-width: 95vw;
  display: flex;
  flex-direction: column;
  gap: 10px;
  box-shadow: 0 24px 80px rgba(0,0,0,0.6);
  animation: slide-up 150ms ease;
}
@keyframes slide-up { from { transform: translateY(12px); opacity: 0; } to { transform: translateY(0); opacity: 1; } }

.modal-box h3 { font-size: 15px; font-weight: 600; margin-bottom: 4px; }
.modal-box label { font-size: 12px; color: var(--text-secondary); margin-top: 4px; }

.modal-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 8px; }
.modal-actions button:last-child {
  background: var(--accent); border-color: var(--accent); color: #fff; font-weight: 600;
}
.modal-actions button:last-child:hover { background: var(--accent-hover); }

.suggestion-list { display: flex; flex-direction: column; gap: 2px; }
.suggestion-item {
  padding: 7px 10px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  font-size: 13px;
  transition: background var(--transition);
}
.suggestion-item:hover { background: var(--bg-hover); }
.suggestion-item .sug-phone { font-size: 11px; color: var(--text-secondary); }

/* ═══════════════════════════════════════════════════════════════════════════
   TOAST
═══════════════════════════════════════════════════════════════════════════ */
#toast {
  position: fixed;
  bottom: 28px;
  left: 50%;
  transform: translateX(-50%) translateY(20px);
  background: var(--bg-panel-alt);
  border: 1px solid var(--border);
  color: var(--text-primary);
  padding: 10px 20px;
  border-radius: var(--radius-pill);
  font-size: 13px;
  font-weight: 500;
  z-index: 300;
  opacity: 0;
  transition: opacity 250ms ease, transform 250ms ease;
  pointer-events: none;
  box-shadow: 0 8px 32px rgba(0,0,0,0.4);
}
#toast.show {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}

/* ═══════════════════════════════════════════════════════════════════════════
   UTILITY
═══════════════════════════════════════════════════════════════════════════ */
.hidden { display: none !important; }

/* Scrollbar */
::-webkit-scrollbar            { width: 5px; }
::-webkit-scrollbar-track      { background: transparent; }
::-webkit-scrollbar-thumb      { background: var(--border); border-radius: 99px; }
::-webkit-scrollbar-thumb:hover { background: var(--text-muted); }

/* Add contact button in contacts view */
#btn-add-contact {
  width: 100%;
  background: transparent;
  border: 1px dashed var(--border);
  color: var(--text-secondary);
  margin-top: 4px;
}
#btn-add-contact:hover { background: var(--bg-hover); color: var(--text-primary); border-style: solid; }
