* { box-sizing: border-box; }
body { margin: 0; font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif; color: #1b1b1b; }

.auth-page { display: grid; place-items: center; min-height: 100vh; background: #f3f4f6; }
.auth-card { background: white; padding: 32px; border-radius: 12px; box-shadow: 0 4px 20px rgba(0,0,0,0.08); width: 320px; display: flex; flex-direction: column; gap: 12px; }
.auth-card h1 { margin: 0 0 8px; font-size: 20px; }
.auth-card label { display: flex; flex-direction: column; font-size: 13px; gap: 4px; }
.auth-card input { padding: 8px 10px; border: 1px solid #d1d5db; border-radius: 6px; font-size: 14px; }
.auth-card .checkbox { flex-direction: row; align-items: center; gap: 6px; }
.auth-card button { padding: 10px; background: #2563eb; color: white; border: 0; border-radius: 6px; font-weight: 600; cursor: pointer; }
.auth-card button:hover { background: #1d4ed8; }
.auth-card .error { color: #b91c1c; font-size: 13px; background: #fee2e2; padding: 8px; border-radius: 6px; }

.app { display: flex; flex-direction: column; height: 100vh; }
.topbar { display: flex; align-items: center; gap: 16px; padding: 10px 16px; background: #1e3a8a; color: white; }
.topbar .brand { font-weight: 700; }
.topbar .user { margin-left: auto; opacity: 0.9; font-size: 14px; }
.topbar .link { background: transparent; color: white; border: 0; cursor: pointer; text-decoration: underline; font-size: 14px; padding: 0; }

.layout { display: grid; grid-template-columns: 320px 1fr; flex: 1; min-height: 0; }
.sidebar { border-right: 1px solid #e5e7eb; overflow-y: auto; background: #f9fafb; }
.convo { display: block; padding: 12px 14px; border-bottom: 1px solid #e5e7eb; text-decoration: none; color: inherit; }
.convo:hover { background: #f3f4f6; }
.convo.active { background: #e0ecff; }
.convo-head { display: flex; justify-content: space-between; gap: 8px; font-size: 13px; }
.convo-name { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.convo-time { color: #6b7280; font-size: 11px; white-space: nowrap; }
.convo-preview { color: #4b5563; font-size: 12px; margin-top: 4px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.convo-count { color: #9ca3af; font-size: 11px; margin-top: 4px; }

.thread { display: flex; flex-direction: column; min-height: 0; }
.thread-head { padding: 12px 16px; border-bottom: 1px solid #e5e7eb; font-weight: 600; background: white; display: flex; align-items: center; gap: 10px; }
.thread-title { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.thread-phone { color: #6b7280; font-weight: 400; font-size: 13px; }
.alias-edit { background: transparent; border: 0; cursor: pointer; font-size: 16px; color: #6b7280; padding: 2px 6px; border-radius: 4px; }
.alias-edit:hover { background: #f3f4f6; color: #1b1b1b; }
.alias-form { display: flex; gap: 6px; align-items: center; }
.alias-form input[type=text] { padding: 6px 10px; border: 1px solid #d1d5db; border-radius: 6px; font-size: 13px; min-width: 180px; }
.alias-form button { padding: 6px 12px; background: #2563eb; color: white; border: 0; border-radius: 6px; font-size: 13px; cursor: pointer; }
.alias-form button:hover { background: #1d4ed8; }
.thread-body { flex: 1; overflow-y: auto; padding: 16px; display: flex; flex-direction: column; gap: 10px; background: #f3f4f6; }
.msg { background: white; padding: 10px 14px; border-radius: 10px; max-width: 640px; box-shadow: 0 1px 2px rgba(0,0,0,0.04); }
.msg-subject { font-weight: 600; margin-bottom: 4px; font-size: 14px; }
.msg-body { white-space: pre-wrap; font-size: 14px; }
.msg-time { color: #9ca3af; font-size: 11px; margin-top: 6px; }

.empty { padding: 32px; text-align: center; color: #9ca3af; }
