:root {
  --bg: #f6efe3;
  --panel: #f1e6d8;
  --panel-2: #e7dcc9;
  --accent: #c47b2e;
  --text: #2c1f0f;
  --muted: #7a6a55;
  --border: #d5c8b4;
  --in: #d08c3f;
  --out: #b36a3a;
  --font: "Inter", system-ui, -apple-system, sans-serif;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background:
    radial-gradient(circle at 20% 20%, rgba(196,123,46,0.12), transparent 25%),
    radial-gradient(circle at 80% 10%, rgba(179,106,58,0.1), transparent 25%),
    linear-gradient(180deg, #f9f2e7 0%, #f3e8da 100%);
  color: var(--text);
  font-family: var(--font);
}

.backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.45);
  backdrop-filter: blur(2px);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s ease;
  z-index: 15;
}
.backdrop.show { opacity: 1; pointer-events: auto; }

.public-url {
  padding: 8px 12px;
  background: rgba(56,189,248,0.1);
  color: var(--accent);
  text-align: center;
  font-size: 13px;
}
.public-url a { color: var(--accent); text-decoration: none; }
.webapp-body .public-url { display: none !important; }

.app {
  display: grid;
  grid-template-columns: 320px 1fr;
  height: 100vh;
}
.app.mobile { grid-template-columns: 1fr; position: relative; min-height: 100vh; }

.sidebar {
  background: var(--panel);
  border-right: 1px solid var(--border);
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 16px;
  overflow: hidden;
}
.app.mobile .sidebar {
  position: fixed;
  top: 0;
  left: -320px;
  width: 320px;
  height: 100vh;
  z-index: 20;
  box-shadow: 0 10px 30px rgba(0,0,0,0.35);
  transition: left 0.2s ease;
  background: var(--panel);
}
.app.mobile .sidebar.open { left: 0; }

.logo {
  font-weight: 800;
  letter-spacing: 0.02em;
  color: var(--accent);
}
.logo-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.section { display: flex; flex-direction: column; gap: 8px; overflow: hidden; }
.section-title { font-size: 12px; text-transform: uppercase; color: var(--muted); letter-spacing: 0.08em; }

#accounts {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

.account-chip {
  padding: 8px 10px;
  background: var(--panel-2);
  border: 1px solid var(--border);
  border-radius: 10px;
  cursor: pointer;
  color: var(--muted);
  transition: all 0.15s ease;
}
.account-chip.active {
  background: var(--accent);
  color: #fffaf3;
  border-color: var(--accent);
  font-weight: 600;
}

.chat-list {
  overflow-y: auto;
  flex: 1;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: var(--panel-2);
}
.chat-item {
  padding: 12px 14px;
  border-bottom: 1px solid var(--border);
  cursor: pointer;
  transition: background 0.12s ease;
}
.chat-item:hover { background: rgba(255,255,255,0.03); }
.chat-item.active { background: rgba(196,123,46,0.18); border-left: 3px solid var(--accent); }
.chat-title { font-weight: 600; }
.chat-preview { color: var(--muted); font-size: 13px; margin-top: 4px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.chat-date { color: var(--muted); font-size: 12px; margin-top: 4px; }
.chat-list.empty, .messages.empty { display: grid; place-items: center; color: var(--muted); }

.content { display: flex; flex-direction: column; height: 100vh; }
.chat-header {
  padding: 16px 20px;
  border-bottom: 1px solid var(--border);
  background: rgba(255,255,255,0.5);
  display: flex;
  justify-content: space-between;
  align-items: center;
  position: sticky;
  top: 0;
  z-index: 10;
}
.chat-header .left { display: flex; align-items: center; gap: 10px; }
.title { font-size: 18px; font-weight: 700; }
.meta { color: var(--muted); font-size: 13px; margin-top: 4px; }
.status { color: var(--accent); font-size: 13px; }

.icon-btn {
  background: var(--panel-2);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 8px 10px;
  border-radius: 10px;
  cursor: pointer;
}

.messages {
  flex: 1;
  overflow-y: auto;
  padding: 10px 10px 14px;
  display: flex;
  flex-direction: column-reverse;
  gap: 10px;
}
.message {
  position: relative;
  max-width: 92%;
  padding: 8px 10px 14px 10px;
  border-radius: 14px;
  background: rgba(255,255,255,0.85);
  border: 1px solid var(--border);
}
.message.out { margin-left: auto; background: rgba(179,106,58,0.18); border-color: rgba(179,106,58,0.35); }
.message.in { margin-right: auto; background: rgba(208,140,63,0.14); border-color: rgba(208,140,63,0.3); }
.message .header { display: flex; justify-content: space-between; gap: 8px; color: var(--muted); font-size: 11px; align-items: flex-start; }
.message .date { white-space: nowrap; color: var(--muted); font-size: 11px; }
.message .body { margin-top: 4px; white-space: pre-wrap; word-break: break-word; font-size: 13px; }
.message .footer { margin-top: 8px; display: flex; gap: 6px; color: var(--muted); font-size: 11px; align-items: flex-end; flex-wrap: nowrap; padding-right: 0; justify-content: flex-end; }
.edited-note { display: inline-flex; gap: 4px; align-items: center; }
.badge { padding: 2px 6px; border-radius: 8px; background: rgba(0,0,0,0.05); border: 1px solid var(--border); }
.tag { padding: 2px 6px; border-radius: 8px; background: rgba(196,123,46,0.2); color: var(--text); font-size: 11px; text-decoration: none; }
.tag:hover { text-decoration: underline; }
.edited-note { font-size: 11px; color: var(--muted); }
.checks { position: static; display: inline-flex; }
.check { font-weight: 700; font-size: 12px; line-height: 1; }
.check.seen { color: #1c7ed6; }
.check.unseen { color: #8b8072; }
.media { margin-top: 6px; overflow: hidden; border-radius: 12px; }
.media img { display: block; width: 100%; height: auto; object-fit: cover; }
.placeholder { color: var(--muted); }
.webapp-body .placeholder { font-size: 18px; font-weight: 600; text-align: center; }

@media (max-width: 900px) {
  .app { grid-template-columns: 1fr; }
  .sidebar { flex-direction: column; height: auto; }
  .messages { padding: 12px; }
  .icon-btn { display: inline-flex; align-items: center; justify-content: center; }
}
