:root {
  --bg: #f4f5f7;
  --surface: #ffffff;
  --border: #e3e5e9;
  --text: #1c1e21;
  --text-muted: #6b7280;
  --brand: #25d366;
  --brand-dark: #1da851;
  --accent: #128c7e;
  --danger: #e0245e;
  --radius: 12px;
  --shadow: 0 1px 3px rgba(0, 0, 0, 0.08), 0 1px 2px rgba(0, 0, 0, 0.06);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-size: 14px;
}

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

button {
  font-family: inherit;
  cursor: pointer;
}

.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 9px 16px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  font-size: 14px;
  font-weight: 500;
}

.btn:hover { border-color: #c9cdd3; }

.btn-primary {
  background: var(--brand);
  border-color: var(--brand);
  color: #fff;
}

.btn-primary:hover { background: var(--brand-dark); }

.btn-danger {
  background: var(--danger);
  border-color: var(--danger);
  color: #fff;
}

.btn-small { padding: 5px 10px; font-size: 12px; }

input[type="text"],
input[type="email"],
input[type="password"],
input[type="number"],
input[type="search"],
textarea,
select {
  width: 100%;
  padding: 9px 11px;
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: 14px;
  background: var(--surface);
  color: var(--text);
}

label {
  display: block;
  font-size: 12px;
  font-weight: 600;
  color: var(--text-muted);
  margin-bottom: 4px;
  text-transform: uppercase;
  letter-spacing: 0.03em;
}

.field { margin-bottom: 14px; }

/* ---------- App shell ---------- */
.app-shell {
  display: flex;
  min-height: 100vh;
}

.sidebar {
  width: 220px;
  flex-shrink: 0;
  background: var(--surface);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  padding: 16px 12px;
}

.sidebar .brand {
  font-weight: 700;
  font-size: 16px;
  padding: 8px 10px 18px;
}

.sidebar nav { display: flex; flex-direction: column; gap: 2px; flex: 1; }

.sidebar nav a {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  border-radius: 8px;
  color: var(--text);
  font-weight: 500;
}

.sidebar nav a:hover { background: var(--bg); }
.sidebar nav a.active { background: #e8f8ef; color: var(--brand-dark); }

.sidebar .sidebar-footer {
  border-top: 1px solid var(--border);
  padding-top: 12px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.locale-switch { display: flex; gap: 4px; }
.locale-switch button {
  flex: 1;
  padding: 6px;
  border-radius: 6px;
  border: 1px solid var(--border);
  background: var(--surface);
  font-size: 12px;
}
.locale-switch button.active { background: var(--text); color: #fff; border-color: var(--text); }

.main-content {
  flex: 1;
  min-width: 0;
  padding: 20px 24px;
}

.page-header { margin-bottom: 18px; }
.page-header h1 { margin: 0 0 4px; font-size: 20px; }
.page-header p { margin: 0; color: var(--text-muted); }

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  box-shadow: var(--shadow);
}

.toolbar { display: flex; justify-content: space-between; align-items: center; gap: 10px; margin-bottom: 14px; flex-wrap: wrap; }

.grid { display: grid; gap: 14px; }
.grid-cols-3 { grid-template-columns: repeat(3, 1fr); }

table { width: 100%; border-collapse: collapse; }
th, td { padding: 8px 10px; text-align: left; border-bottom: 1px solid var(--border); font-size: 13px; }
th { color: var(--text-muted); font-weight: 600; text-transform: uppercase; font-size: 11px; }

.badge { display: inline-block; padding: 2px 8px; border-radius: 999px; font-size: 11px; font-weight: 600; background: var(--bg); color: var(--text-muted); }
.badge-success { background: #e8f8ef; color: var(--brand-dark); }
.badge-danger { background: #fdeaef; color: var(--danger); }

/* ---------- Toast ---------- */
#toasts { position: fixed; bottom: 20px; right: 20px; display: flex; flex-direction: column; gap: 8px; z-index: 999; }
.toast { background: var(--text); color: #fff; padding: 10px 16px; border-radius: 8px; font-size: 13px; box-shadow: var(--shadow); animation: toast-in 0.2s ease-out; }
.toast.error { background: var(--danger); }
@keyframes toast-in { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: translateY(0); } }

/* ---------- Login ---------- */
.login-page { display: flex; align-items: center; justify-content: center; min-height: 100vh; background: linear-gradient(135deg, #0f2027, #203a43 50%, #2c5364); }
.login-card { width: 360px; background: var(--surface); border-radius: var(--radius); padding: 32px; box-shadow: 0 20px 60px rgba(0,0,0,0.3); }
.login-card h1 { margin: 0 0 4px; font-size: 22px; }
.login-card p.subtitle { margin: 0 0 24px; color: var(--text-muted); }
.login-divider { display: flex; align-items: center; gap: 10px; margin: 18px 0; color: var(--text-muted); font-size: 12px; }
.login-divider::before, .login-divider::after { content: ""; flex: 1; height: 1px; background: var(--border); }
.btn-meta { width: 100%; background: #1877f2; border-color: #1877f2; color: #fff; justify-content: center; }
.btn-block { width: 100%; justify-content: center; }
.login-error { background: #fdeaef; color: var(--danger); border-radius: 8px; padding: 10px 12px; font-size: 13px; margin-bottom: 14px; }

/* ---------- Dashboard ---------- */
.dashboard-grid {
  display: grid;
  grid-template-columns: 300px minmax(340px, 420px) 1fr;
  gap: 16px;
  height: calc(100vh - 80px);
}

.conv-list { overflow-y: auto; }
.conv-item { display: flex; gap: 10px; align-items: center; padding: 10px; border-radius: 8px; cursor: pointer; }
.conv-item:hover { background: var(--bg); }
.conv-item.selected { background: #e8f8ef; }
.conv-avatar { width: 38px; height: 38px; border-radius: 50%; background: #d8dce1; display: flex; align-items: center; justify-content: center; font-weight: 700; color: #fff; background: var(--accent); flex-shrink: 0; }
.conv-meta { flex: 1; min-width: 0; }
.conv-name-row { display: flex; justify-content: space-between; gap: 6px; }
.conv-name { font-weight: 600; font-size: 13px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.conv-time { font-size: 11px; color: var(--text-muted); flex-shrink: 0; }
.conv-preview { font-size: 12px; color: var(--text-muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 170px; }
.conv-dot { width: 8px; height: 8px; border-radius: 50%; background: #c9cdd3; flex-shrink: 0; }
.conv-dot.open { background: var(--brand); }
.conv-unread { background: var(--brand); color: #fff; font-size: 11px; font-weight: 700; border-radius: 999px; min-width: 18px; height: 18px; display: flex; align-items: center; justify-content: center; padding: 0 5px; }

.phone-column { display: flex; justify-content: center; }
.phone-mockup {
  width: 360px;
  max-width: 100%;
  background: #111;
  border-radius: 40px;
  padding: 14px;
  box-shadow: 0 20px 50px rgba(0,0,0,0.25);
  display: flex;
  flex-direction: column;
  height: 100%;
}
.phone-notch { width: 120px; height: 20px; background: #111; border-radius: 0 0 14px 14px; margin: 0 auto 6px; position: relative; top: 2px; }
.phone-screen { flex: 1; background: #ece5dd; border-radius: 28px; overflow: hidden; display: flex; flex-direction: column; min-height: 0; }
.chat-header { background: #075e54; color: #fff; padding: 10px 14px; font-weight: 600; font-size: 13px; }
.chat-messages { flex: 1; overflow-y: auto; padding: 10px; display: flex; flex-direction: column; gap: 6px; }
.bubble { max-width: 78%; padding: 7px 10px; border-radius: 10px; font-size: 13px; line-height: 1.35; box-shadow: 0 1px 1px rgba(0,0,0,0.08); }
.bubble.in { align-self: flex-start; background: #fff; border-top-left-radius: 2px; }
.bubble.out, .bubble.echo { align-self: flex-end; background: #dcf8c6; border-top-right-radius: 2px; }
.bubble .bubble-label { font-size: 10px; color: var(--text-muted); margin-bottom: 2px; }
.bubble audio { width: 220px; }
.bubble img { max-width: 100%; border-radius: 6px; display: block; }
.bubble .bubble-status { font-size: 10px; color: var(--text-muted); margin-top: 2px; text-align: right; }

.keyboard-wrap { background: #d1d4da; border-radius: 0 0 28px 28px; }
.compose-row { display: flex; align-items: center; gap: 8px; padding: 8px 10px; background: #ece5dd; }
.compose-field { flex: 1; background: #fff; border-radius: 18px; padding: 8px 14px; font-size: 13px; min-height: 18px; }
.compose-send { width: 32px; height: 32px; border-radius: 50%; background: var(--brand); color: #fff; border: none; display: flex; align-items: center; justify-content: center; flex-shrink: 0; }

.suggestion-bar { display: flex; gap: 6px; padding: 6px 8px; background: #bfc3ca; }
.suggestion-chip { flex: 1; background: #fff; border-radius: 6px; padding: 7px 6px; font-size: 11px; text-align: center; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; border: none; }
.suggestion-bolt { width: 34px; flex: 0 0 34px; background: #fff; border-radius: 6px; border: none; font-size: 14px; }

.kb-rows { padding: 6px 4px 10px; }
.kb-row { display: flex; gap: 5px; margin-bottom: 6px; justify-content: center; }
.kb-key { flex: 1; max-width: 32px; height: 38px; background: #fff; border: none; border-radius: 5px; box-shadow: 0 1px 0 rgba(0,0,0,0.25); font-size: 14px; display: flex; align-items: center; justify-content: center; }
.kb-key.wide { max-width: none; flex: 1.6; font-size: 11px; }
.kb-key.space { flex: 5; }
.kb-key.active { background: #a9adb3; }

.quick-sheet { position: absolute; inset: 0; background: #ece5dd; display: flex; flex-direction: column; }
.quick-sheet-header { padding: 10px; display: flex; gap: 8px; align-items: center; background: #fff; border-bottom: 1px solid var(--border); }
.quick-sheet-list { flex: 1; overflow-y: auto; padding: 8px; }
.quick-sheet-category { font-size: 11px; text-transform: uppercase; color: var(--text-muted); margin: 10px 4px 4px; font-weight: 700; }
.quick-sheet-item { display: flex; align-items: center; gap: 8px; background: #fff; border-radius: 8px; padding: 8px 10px; margin-bottom: 6px; }
.quick-sheet-item .qi-icon { width: 22px; text-align: center; }
.quick-sheet-item .qi-title { flex: 1; font-size: 12px; font-weight: 600; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.quick-sheet-item .qi-send { background: var(--brand); color: #fff; border: none; border-radius: 6px; padding: 5px 10px; font-size: 11px; }

.phone-screen-inner { position: relative; flex: 1; display: flex; flex-direction: column; min-height: 0; }

.details-column { display: flex; flex-direction: column; gap: 12px; }
.details-column .card h3 { margin: 0 0 10px; font-size: 13px; }
.details-row { display: flex; justify-content: space-between; padding: 4px 0; font-size: 12px; }
.details-row span:first-child { color: var(--text-muted); }
.ai-placeholder { text-align: center; color: var(--text-muted); font-size: 12px; padding: 18px 8px; }

/* ---------- Media grid ---------- */
.media-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 12px; }
.media-card { border: 1px solid var(--border); border-radius: 10px; overflow: hidden; background: var(--surface); }
.media-card .thumb { height: 110px; background: var(--bg); display: flex; align-items: center; justify-content: center; font-size: 28px; }
.media-card .thumb img { width: 100%; height: 100%; object-fit: cover; }
.media-card .meta { padding: 8px; }
.media-card .meta .title { font-weight: 600; font-size: 12px; margin-bottom: 2px; }
.media-card .meta .cat { font-size: 11px; color: var(--text-muted); }
.media-card .actions { display: flex; justify-content: flex-end; padding: 6px 8px; gap: 6px; }

.record-btn { width: 86px; height: 86px; border-radius: 50%; background: var(--danger); border: none; color: #fff; font-size: 24px; display: flex; align-items: center; justify-content: center; margin: 0 auto; }
.record-timer { text-align: center; font-size: 20px; font-weight: 700; margin: 12px 0; }

.modal-backdrop { position: fixed; inset: 0; background: rgba(0,0,0,0.4); display: flex; align-items: center; justify-content: center; z-index: 50; }
.modal { background: var(--surface); border-radius: var(--radius); padding: 20px; width: 420px; max-width: 92vw; max-height: 86vh; overflow-y: auto; }
.modal h2 { margin: 0 0 14px; font-size: 16px; }
.modal-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 16px; }

.token-value { font-family: monospace; font-size: 13px; background: var(--bg); padding: 8px 10px; border-radius: 6px; word-break: break-all; }

@media (max-width: 1000px) {
  .dashboard-grid { grid-template-columns: 1fr; height: auto; }
  .phone-mockup { height: 640px; }
  .app-shell { flex-direction: column; }
  .sidebar { width: 100%; flex-direction: row; align-items: center; overflow-x: auto; }
  .sidebar nav { flex-direction: row; }
  .sidebar .sidebar-footer { flex-direction: row; border-top: none; }
}
