@import url('https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700&family=JetBrains+Mono:wght@400;500&display=swap');

:root {
  --ink: #141a22;
  --ink-soft: #232c38;
  --paper: #f5f6f8;
  --paper-raised: #ffffff;
  --line: #e2e5ea;
  --text: #1c2430;
  --text-dim: #6b7480;
  --accent: #2f8f89;
  --accent-soft: #e4f3f1;
  --danger: #c65f4f;
  --radius: 10px;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
  color: var(--text);
  background: var(--paper);
}

.hidden { display: none !important; }

button {
  font-family: inherit;
  cursor: pointer;
  border: none;
  background: var(--ink);
  color: #fff;
  border-radius: 7px;
  padding: 8px 14px;
  font-size: 13px;
  font-weight: 600;
}
button:hover { opacity: 0.88; }

input, textarea, select {
  font-family: inherit;
  font-size: 14px;
  border: 1px solid var(--line);
  border-radius: 7px;
  padding: 8px 10px;
  background: var(--paper-raised);
  color: var(--text);
}

/* ---------- Login ---------- */
.login-screen {
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--ink);
}
.login-card {
  background: var(--paper-raised);
  padding: 40px 36px;
  border-radius: 14px;
  width: 320px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  box-shadow: 0 20px 60px rgba(0,0,0,0.35);
}
.login-mark { color: var(--accent); letter-spacing: 4px; font-size: 10px; }
.login-card h1 { margin: 0; font-size: 22px; }
.login-sub { margin: 0 0 10px; color: var(--text-dim); font-size: 13px; }
.login-card label { display: flex; flex-direction: column; gap: 5px; font-size: 12px; color: var(--text-dim); font-weight: 600; }
.login-card button { margin-top: 6px; padding: 10px; }
.error-text { color: var(--danger); font-size: 12.5px; min-height: 16px; margin: 0; }

/* ---------- App shell ---------- */
.app {
  height: 100%;
  display: grid;
  grid-template-columns: 56px 1fr;
}

.rail {
  background: var(--ink);
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  align-items: center;
  padding: 16px 0;
}
.rail-top, .rail-bottom { display: flex; flex-direction: column; gap: 6px; }
.rail-btn {
  background: transparent;
  color: #8b95a3;
  width: 36px;
  height: 36px;
  border-radius: 9px;
  font-size: 16px;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0;
}
.rail-btn:hover { background: var(--ink-soft); color: #fff; opacity: 1; }
.rail-btn.active { background: var(--accent); color: #fff; }

.view { display: grid; grid-template-columns: 220px 280px 1fr; height: 100%; overflow: hidden; }
#view-numbers, #view-canned { grid-template-columns: 1fr; padding: 28px 36px; overflow-y: auto; }

.col-header {
  height: 52px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 16px;
  font-size: 12px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-dim);
  border-bottom: 1px solid var(--line);
  flex-shrink: 0;
}
.col-header button { padding: 3px 9px; font-size: 15px; line-height: 1; }

/* ---------- Numbers column ---------- */
.numbers-col { background: var(--paper-raised); border-right: 1px solid var(--line); overflow-y: auto; }
.number-item {
  padding: 11px 16px;
  cursor: pointer;
  font-size: 13.5px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  border-left: 3px solid transparent;
}
.number-item:hover { background: var(--paper); }
.number-item.active { background: var(--accent-soft); border-left-color: var(--accent); font-weight: 600; }
.number-item .unread-dot {
  background: var(--accent);
  color: #fff;
  font-size: 10px;
  font-weight: 700;
  min-width: 16px;
  height: 16px;
  border-radius: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0 4px;
}

/* ---------- Threads column ---------- */
.threads-col { background: var(--paper); border-right: 1px solid var(--line); overflow-y: auto; }
.thread-item {
  padding: 12px 16px;
  cursor: pointer;
  border-bottom: 1px solid var(--line);
}
.thread-item:hover { background: var(--paper-raised); }
.thread-item.active { background: var(--paper-raised); box-shadow: inset 3px 0 0 var(--accent); }
.thread-name { font-weight: 600; font-size: 13.5px; display: flex; justify-content: space-between; }
.thread-number { font-family: 'JetBrains Mono', monospace; font-size: 11.5px; color: var(--text-dim); }
.thread-preview { font-size: 12.5px; color: var(--text-dim); margin-top: 3px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.thread-item.unread .thread-preview, .thread-item.unread .thread-name { color: var(--text); font-weight: 700; }
.thread-dot { width: 8px; height: 8px; border-radius: 50%; background: var(--accent); display: inline-block; }

/* ---------- Chat column ---------- */
.chat-col { display: flex; flex-direction: column; background: var(--paper-raised); overflow: hidden; }
.chat-empty { flex: 1; display: flex; align-items: center; justify-content: center; color: var(--text-dim); font-size: 13.5px; }
.chat-active { display: flex; flex-direction: column; height: 100%; }
.chat-header { padding: 14px 20px; border-bottom: 1px solid var(--line); flex-shrink: 0; display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.chat-contact { font-weight: 700; font-size: 14.5px; }
.chat-did { font-family: 'JetBrains Mono', monospace; font-size: 11.5px; color: var(--text-dim); margin-top: 2px; }
.chat-messages { flex: 1; overflow-y: auto; padding: 18px 20px; display: flex; flex-direction: column; gap: 10px; }

.msg { max-width: 60%; padding: 9px 13px; border-radius: 14px; font-size: 13.5px; line-height: 1.42; }
.msg img { max-width: 220px; border-radius: 8px; display: block; margin-top: 6px; }
.msg.in { align-self: flex-start; background: var(--paper); border-bottom-left-radius: 4px; }
.msg.out { align-self: flex-end; background: var(--accent); color: #fff; border-bottom-right-radius: 4px; }
.msg-time { font-size: 10.5px; opacity: 0.65; margin-top: 4px; font-family: 'JetBrains Mono', monospace; }

.compose { border-top: 1px solid var(--line); padding: 10px 16px 14px; flex-shrink: 0; }
.compose select { width: 100%; margin-bottom: 8px; }
.compose-row { display: flex; align-items: flex-end; gap: 8px; }
.compose-row textarea { flex: 1; resize: none; max-height: 100px; }
.attach-btn {
  background: var(--paper);
  border: 1px solid var(--line);
  border-radius: 7px;
  width: 36px;
  height: 36px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  flex-shrink: 0;
}
.attach-preview { margin-top: 8px; font-size: 12px; color: var(--text-dim); display: flex; align-items: center; gap: 8px; }
.attach-preview img { height: 40px; border-radius: 5px; }
.attach-preview button { background: var(--danger); padding: 3px 8px; font-size: 11px; }

/* ---------- Admin panels ---------- */
.panel { max-width: 900px; }
.panel-header { display: flex; align-items: center; justify-content: space-between; margin-bottom: 18px; }
.panel-header h2 { margin: 0; }
.table { width: 100%; border-collapse: collapse; background: var(--paper-raised); border-radius: var(--radius); overflow: hidden; border: 1px solid var(--line); }
.table th { text-align: left; font-size: 11.5px; text-transform: uppercase; letter-spacing: 0.05em; color: var(--text-dim); padding: 10px 14px; border-bottom: 1px solid var(--line); }
.table td { padding: 10px 14px; border-bottom: 1px solid var(--line); font-size: 13.5px; vertical-align: middle; }
.table tr:last-child td { border-bottom: none; }
.table input[type=text] { width: 100%; }
.table .row-actions { display: flex; gap: 6px; }
.table .row-actions button.secondary { background: var(--paper); color: var(--text); border: 1px solid var(--line); }
.table .row-actions button.danger { background: var(--danger); }
button.danger { background: var(--danger); }
button.danger:hover { opacity: 0.85; }

.msg { position: relative; }
.msg-delete {
  position: absolute;
  top: -8px;
  right: -8px;
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: var(--danger);
  color: #fff;
  font-size: 12px;
  line-height: 1;
  padding: 0;
  display: none;
  align-items: center;
  justify-content: center;
}
.msg:hover .msg-delete { display: flex; }
.toggle { width: 38px; height: 21px; border-radius: 11px; background: var(--line); position: relative; cursor: pointer; border: none; padding: 0; }
.toggle.on { background: var(--accent); }
.toggle::after { content: ''; position: absolute; top: 2px; left: 2px; width: 17px; height: 17px; border-radius: 50%; background: #fff; transition: left 0.15s; }
.toggle.on::after { left: 19px; }
