/* Mukalma — styles. Design tokens only: violet #5B4BDB, deep violet
   #2E2A55, amber #FF8A3D, background #F6F5FA, text #1E1B33,
   muted #6E6A8C, received-bubble border #E6E4F0. */
:root {
  --primary: #5B4BDB;
  --primary-dark: #2E2A55;
  --accent: #FF8A3D;
  --bg: #F6F5FA;
  --card: #FFFFFF;
  --text: #1E1B33;
  --muted: #6E6A8C;
  --border: #E6E4F0;
  --sent: #5B4BDB;
  --radius: 14px;
  --shadow: 0 2px 10px rgba(46, 42, 85, 0.08);
}
* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Arial, sans-serif;
  background: #EDEBF5;
  color: var(--text);
  font-size: 16px;
  line-height: 1.45;
}
button { font-family: inherit; cursor: pointer; }
input, textarea { font-family: inherit; font-size: 16px; }
img { max-width: 100%; display: block; }

.app-shell {
  max-width: 480px;
  margin: 0 auto;
  min-height: 100vh;
  min-height: 100dvh;
  background: var(--bg);
  display: flex;
  flex-direction: column;
  position: relative;
  box-shadow: 0 0 24px rgba(46, 42, 85, 0.12);
}
.app-header {
  background: var(--primary-dark);
  color: #fff;
  padding: 12px 16px;
  display: flex;
  align-items: center;
  gap: 10px;
  flex-shrink: 0;
}
.app-header .logo { width: 36px; height: 36px; border-radius: 10px; }
.app-header h1 { font-size: 20px; margin: 0; letter-spacing: 0.2px; }
.app-header .tagline { font-size: 12px; color: #C9C4F2; margin: 0; }
.app-header .header-spacer { flex: 1; }
.icon-btn {
  background: transparent;
  border: 0;
  color: #fff;
  font-size: 22px;
  padding: 6px 8px;
  border-radius: 10px;
}
.icon-btn:hover { background: rgba(255, 255, 255, 0.12); }

main { flex: 1; overflow-y: auto; padding-bottom: 8px; }
.screen { display: none; padding: 12px 12px 84px; }
.screen.active { display: block; }
.screen h2 { font-size: 18px; margin: 6px 4px 12px; }
.screen h3 { font-size: 15px; margin: 18px 4px 8px; color: var(--muted); font-weight: 600; }

.card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  box-shadow: var(--shadow);
  margin-bottom: 12px;
}
.field { margin-bottom: 14px; }
.field label { display: block; font-size: 13px; font-weight: 600; color: var(--muted); margin-bottom: 6px; }
.field input, .field textarea {
  width: 100%;
  padding: 11px 12px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: #fff;
  color: var(--text);
  outline: none;
}
.field input:focus, .field textarea:focus { border-color: var(--primary); box-shadow: 0 0 0 3px rgba(91, 75, 219, 0.15); }
.field textarea { min-height: 84px; resize: vertical; }

.btn {
  display: inline-block;
  width: 100%;
  padding: 12px 16px;
  border: 0;
  border-radius: 12px;
  background: var(--primary);
  color: #fff;
  font-size: 16px;
  font-weight: 600;
}
.btn:hover { background: #4A3DC8; }
.btn:disabled { opacity: 0.55; cursor: default; }
.btn-secondary {
  background: #fff;
  color: var(--primary);
  border: 1px solid var(--primary);
}
.btn-amber { background: var(--accent); color: #fff; }
.btn-amber:hover { background: #F07A28; }
.btn-small { width: auto; padding: 8px 14px; font-size: 14px; border-radius: 10px; }
.link-btn {
  background: none; border: 0; color: var(--primary);
  font-size: 14px; font-weight: 600; padding: 8px 4px; width: 100%; text-align: center;
}
.error-text { color: #C0392B; font-size: 14px; min-height: 20px; margin: 4px 2px 8px; }
.success-text { color: var(--primary); font-size: 14px; min-height: 20px; margin: 4px 2px 8px; }
.hint { font-size: 13px; color: var(--muted); }
.empty-state { text-align: center; color: var(--muted); padding: 36px 16px; font-size: 15px; }
.empty-state .empty-emoji { font-size: 40px; display: block; margin-bottom: 10px; }

/* Chat list */
.chat-row, .user-row, .status-row {
  display: flex; align-items: center; gap: 12px;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 12px;
  margin-bottom: 8px;
  width: 100%; text-align: left;
  box-shadow: var(--shadow);
}
.chat-row:hover, .user-row:hover, .status-row:hover { border-color: var(--primary); }
.avatar {
  width: 48px; height: 48px; border-radius: 50%;
  background: var(--primary); color: #fff;
  display: flex; align-items: center; justify-content: center;
  font-weight: 700; font-size: 18px; flex-shrink: 0;
}
.avatar.small { width: 36px; height: 36px; font-size: 14px; }
.row-body { flex: 1; min-width: 0; }
.row-title { font-weight: 600; font-size: 15px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.row-sub { font-size: 13px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.row-meta { font-size: 12px; color: var(--muted); text-align: right; flex-shrink: 0; }
.unread-badge {
  display: inline-block; min-width: 20px; height: 20px; line-height: 20px;
  border-radius: 10px; background: var(--accent); color: #fff;
  font-size: 12px; font-weight: 700; text-align: center; padding: 0 6px; margin-top: 4px;
}
.online-dot { width: 10px; height: 10px; border-radius: 50%; background: var(--accent); display: inline-block; margin-left: 4px; }
.status-ring {
  padding: 2px; border-radius: 50%;
  background: linear-gradient(135deg, var(--primary), var(--accent));
}
.status-ring.viewed { background: var(--border); }
.status-ring .avatar { border: 2px solid #fff; }

/* Chat screen */
.chat-header-bar {
  display: flex; align-items: center; gap: 10px;
  background: var(--card); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 8px 10px; margin-bottom: 10px;
  position: sticky; top: 0; z-index: 5;
}
.chat-header-bar .row-body { flex: 1; }
.chat-sub { font-size: 12px; color: var(--muted); }
.chat-sub.typing { color: var(--primary); font-weight: 600; }
.messages { display: flex; flex-direction: column; gap: 8px; padding: 4px 2px 10px; }
.bubble {
  max-width: 78%; padding: 9px 12px 7px; border-radius: 14px;
  font-size: 15px; word-wrap: break-word; overflow-wrap: anywhere;
  box-shadow: var(--shadow);
}
.bubble.sent { align-self: flex-end; background: var(--sent); color: #fff; border-bottom-right-radius: 4px; }
.bubble.received { align-self: flex-start; background: var(--card); border: 1px solid var(--border); border-bottom-left-radius: 4px; }
.bubble .sender-name { font-size: 12px; font-weight: 700; color: var(--accent); margin-bottom: 2px; }
.bubble.sent .sender-name { color: #FFD9BE; }
.bubble img { border-radius: 10px; margin-bottom: 4px; }
.bubble audio { width: 200px; max-width: 100%; margin: 2px 0; }
.bubble .caption { font-size: 14px; margin-top: 4px; }
.msg-meta { font-size: 11px; text-align: right; margin-top: 3px; opacity: 0.85; }
.bubble.received .msg-meta { color: var(--muted); }
.ticks { font-weight: 700; letter-spacing: -2px; margin-left: 4px; }
.ticks.read { color: #C9C4F2; }
.ticks.unread { color: rgba(255, 255, 255, 0.7); }
.bubble.received .ticks { display: none; }
.date-sep { text-align: center; font-size: 12px; color: var(--muted); margin: 8px 0 2px; }

.composer {
  position: sticky; bottom: 64px;
  display: flex; gap: 8px; align-items: flex-end;
  background: var(--card); border: 1px solid var(--border);
  border-radius: 16px; padding: 8px; box-shadow: var(--shadow);
}
.composer textarea {
  flex: 1; border: 0; outline: none; resize: none;
  padding: 8px 4px; min-height: 40px; max-height: 110px; background: transparent;
}
.composer .round-btn {
  width: 42px; height: 42px; border-radius: 50%; border: 0;
  background: var(--primary); color: #fff; font-size: 19px; flex-shrink: 0;
}
.composer .round-btn.amber { background: var(--accent); }
.composer .round-btn.recording { background: #C0392B; }
.composer .round-btn:disabled { opacity: 0.5; }
.rec-indicator { font-size: 13px; color: #C0392B; font-weight: 600; text-align: center; padding: 4px 0; }
.typing-line { font-size: 12px; color: var(--primary); min-height: 16px; padding: 0 4px 4px; }

/* Status viewer */
.status-viewer {
  background: var(--primary-dark); color: #fff;
  border-radius: var(--radius); padding: 16px; text-align: center;
}
.status-viewer img { border-radius: 12px; margin: 0 auto 12px; max-height: 320px; object-fit: contain; }
.status-viewer .status-text-big { font-size: 20px; line-height: 1.5; white-space: pre-wrap; }
.status-viewer .status-meta { font-size: 13px; color: #C9C4F2; margin-top: 12px; }
.viewer-nav { display: flex; gap: 8px; margin-top: 12px; }
.viewer-nav .btn { flex: 1; }

/* Bottom navigation */
.bottom-nav {
  position: fixed; bottom: 0; left: 50%; transform: translateX(-50%);
  width: 100%; max-width: 480px;
  background: var(--card); border-top: 1px solid var(--border);
  display: flex; z-index: 20;
}
.bottom-nav button {
  flex: 1; background: none; border: 0; padding: 10px 4px 12px;
  color: var(--muted); font-size: 13px; font-weight: 600;
}
.bottom-nav button .nav-icon { font-size: 21px; display: block; margin-bottom: 2px; }
.bottom-nav button.active { color: var(--primary); }
.bottom-nav.hidden { display: none; }

.toast {
  position: fixed; bottom: 76px; left: 50%; transform: translateX(-50%);
  background: var(--primary-dark); color: #fff; padding: 10px 16px;
  border-radius: 10px; font-size: 14px; z-index: 50; max-width: 90%;
  box-shadow: var(--shadow);
}
.check-row { display: flex; align-items: center; gap: 10px; padding: 10px 4px; }
.check-row input { width: 20px; height: 20px; accent-color: var(--primary); }
.lang-row { display: flex; gap: 8px; }
.lang-row .btn { flex: 1; }
.lang-row .btn.active-lang { outline: 3px solid rgba(255, 138, 61, 0.55); }
.center { text-align: center; }
.mt { margin-top: 12px; }
@media (max-width: 360px) {
  .bubble { max-width: 86%; }
  .app-header h1 { font-size: 18px; }
}
