/* ─── Reset & Base ─────────────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --green-dark: #075e54;
  --green-mid: #128c7e;
  --green-light: #25d366;
  --bg: #f0f2f5;
  --sidebar-bg: #fff;
  --sent-bg: #d9fdd3;
  --received-bg: #fff;
  --text: #111b21;
  --text-muted: #667781;
  --border: #e9edef;
  --tag-pets: #ff8f00;
  --tag-sports: #1565c0;
  --tag-food: #2e7d32;
  --shadow: 0 1px 3px rgba(0,0,0,.1);
}

body { font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Helvetica, sans-serif;
  background: var(--bg); color: var(--text); height: 100dvh; overflow: hidden; }

/* ─── Login Page ───────────────────────────────────────────────────────────── */
.login-page { display: flex; align-items: center; justify-content: center;
  min-height: 100dvh; padding: 1rem; }

.login-card { background: #fff; border-radius: 12px; padding: 2.5rem 2rem;
  box-shadow: 0 4px 24px rgba(0,0,0,.12); width: 100%; max-width: 380px; text-align: center; }

.login-logo h1 { font-size: 1.8rem; color: var(--green-dark); margin-bottom: .25rem; }
.login-logo p { color: var(--text-muted); margin-bottom: 2rem; font-size: .9rem; }

#login-form input {
  width: 100%; padding: .75rem 1rem; border: 1.5px solid var(--border);
  border-radius: 8px; font-size: 1rem; outline: none;
  transition: border-color .2s; margin-bottom: 1rem; }
#login-form input:focus { border-color: var(--green-mid); }

#login-form button {
  width: 100%; padding: .75rem; background: var(--green-dark); color: #fff;
  border: none; border-radius: 8px; font-size: 1rem; cursor: pointer; font-weight: 600;
  transition: background .2s; }
#login-form button:hover:not(:disabled) { background: var(--green-mid); }
#login-form button:disabled { opacity: .6; cursor: not-allowed; }

.login-note { color: var(--text-muted); font-size: .8rem; margin-top: 1.5rem; line-height: 1.5; }

/* ─── App Layout ───────────────────────────────────────────────────────────── */
.chat-page { height: 100dvh; overflow: hidden; }

.app { display: flex; height: 100dvh; }

/* ─── Sidebar ──────────────────────────────────────────────────────────────── */
.sidebar {
  width: 340px; min-width: 260px; background: var(--sidebar-bg);
  border-right: 1px solid var(--border); display: flex; flex-direction: column;
  flex-shrink: 0; }

.sidebar-header {
  background: var(--green-dark); color: #fff; padding: .85rem 1rem;
  display: flex; align-items: center; justify-content: space-between; }

.sidebar-user { display: flex; align-items: center; gap: .6rem; }
.sidebar-user .avatar { width: 38px; height: 38px; border-radius: 50%;
  background: var(--green-mid); color: #fff; display: flex; align-items: center;
  justify-content: center; font-weight: 700; font-size: 1rem; flex-shrink: 0; }
#my-username { font-weight: 600; }

.logout-btn { background: transparent; border: none; color: rgba(255,255,255,.8);
  font-size: 1.1rem; cursor: pointer; padding: .25rem .5rem; border-radius: 4px; }
.logout-btn:hover { background: rgba(255,255,255,.15); }

.sidebar-search { padding: .5rem .75rem; background: var(--bg); }
.sidebar-search input {
  width: 100%; padding: .55rem .9rem; background: #fff; border: none;
  border-radius: 20px; font-size: .9rem; outline: none; color: var(--text); }

.users-list { list-style: none; flex: 1; overflow-y: auto; }

.user-item {
  display: flex; align-items: center; gap: .75rem; padding: .75rem 1rem;
  cursor: pointer; transition: background .15s; border-bottom: 1px solid var(--border); }
.user-item:hover { background: var(--bg); }
.user-item.active { background: #f0f2f5; }

.user-item .avatar { width: 42px; height: 42px; border-radius: 50%;
  background: var(--green-mid); color: #fff; display: flex; align-items: center;
  justify-content: center; font-weight: 700; font-size: 1.1rem; flex-shrink: 0; }

.user-info { flex: 1; min-width: 0; }
.user-name { font-weight: 600; display: block; white-space: nowrap;
  overflow: hidden; text-overflow: ellipsis; }
.user-preview { font-size: .8rem; color: var(--text-muted); white-space: nowrap;
  overflow: hidden; text-overflow: ellipsis; display: block; }

.unread-badge { background: var(--green-light); color: #fff; border-radius: 50%;
  width: 20px; height: 20px; font-size: .72rem; font-weight: 700;
  display: flex; align-items: center; justify-content: center; flex-shrink: 0; }
.unread-badge.hidden { display: none; }

/* ─── Main Panel ───────────────────────────────────────────────────────────── */
.main-panel { flex: 1; display: flex; flex-direction: column; min-width: 0; }

.empty-state { display: flex; flex-direction: column; align-items: center;
  justify-content: center; height: 100%; color: var(--text-muted); text-align: center;
  padding: 2rem; }
.empty-icon { font-size: 4rem; margin-bottom: 1rem; }
.empty-state h2 { font-size: 1.3rem; color: var(--text); margin-bottom: .5rem; }
.empty-state p { font-size: .9rem; }
.security-note { margin-top: 1rem; color: var(--green-mid); font-size: .85rem !important; }

.chat-header {
  background: var(--green-dark); color: #fff; padding: .75rem 1rem;
  display: flex; align-items: center; gap: .75rem; flex-shrink: 0; }
.chat-header-avatar { width: 38px; height: 38px; border-radius: 50%;
  background: var(--green-mid); display: flex; align-items: center;
  justify-content: center; font-weight: 700; flex-shrink: 0; }
#chat-header-name { font-weight: 600; font-size: 1rem; }

.back-btn { background: transparent; border: none; color: #fff; font-size: 1.2rem;
  cursor: pointer; padding: .2rem .4rem; border-radius: 4px; display: none; }
.back-btn:hover { background: rgba(255,255,255,.15); }

/* ─── Messages ─────────────────────────────────────────────────────────────── */
.messages {
  flex: 1; overflow-y: auto; padding: 1rem; display: flex;
  flex-direction: column; gap: .3rem; background: var(--bg); }

.message { display: flex; max-width: 72%; }
.message.sent { align-self: flex-end; }
.message.received { align-self: flex-start; }

.bubble {
  padding: .5rem .75rem .4rem; border-radius: 8px;
  box-shadow: var(--shadow); word-break: break-word; max-width: 100%; }
.sent .bubble { background: var(--sent-bg); border-radius: 8px 0 8px 8px; }
.received .bubble { background: var(--received-bg); border-radius: 0 8px 8px 8px; }

.message-text { font-size: .95rem; line-height: 1.45; white-space: pre-wrap; }

.message-tags { display: flex; flex-wrap: wrap; gap: .25rem; margin-top: .3rem; }
.tag { font-size: .7rem; padding: .15rem .4rem; border-radius: 10px; font-weight: 600; }
.tag-pets { background: #fff3e0; color: var(--tag-pets); }
.tag-sports { background: #e3f2fd; color: var(--tag-sports); }
.tag-food { background: #e8f5e9; color: var(--tag-food); }

.message-meta { font-size: .7rem; color: var(--text-muted);
  text-align: right; margin-top: .2rem; }

/* ─── Message Input ────────────────────────────────────────────────────────── */
.message-form {
  display: flex; align-items: flex-end; gap: .5rem; padding: .6rem .75rem;
  background: var(--bg); border-top: 1px solid var(--border); flex-shrink: 0; }

#message-input {
  flex: 1; resize: none; padding: .6rem .9rem; background: #fff;
  border: none; border-radius: 20px; font-size: .95rem; outline: none;
  line-height: 1.4; max-height: 120px; overflow-y: auto;
  font-family: inherit; }

.send-btn { width: 40px; height: 40px; border-radius: 50%; background: var(--green-dark);
  color: #fff; border: none; font-size: 1.1rem; cursor: pointer; display: flex;
  align-items: center; justify-content: center; flex-shrink: 0;
  transition: background .2s; }
.send-btn:hover { background: var(--green-mid); }

.hidden { display: none !important; }

/* ─── Dashboard ────────────────────────────────────────────────────────────── */
.dashboard-page { overflow-y: auto; height: 100dvh; background: var(--bg); }

.dash-header { background: var(--green-dark); color: #fff; padding: 1rem 1.5rem;
  display: flex; align-items: center; justify-content: space-between; }
.dash-header h1 { font-size: 1.3rem; }

.dash-body { padding: 1.5rem; max-width: 1200px; margin: 0 auto; }

.stat-cards { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 1rem; margin-bottom: 1.5rem; }
.stat-card { background: #fff; border-radius: 10px; padding: 1.25rem;
  box-shadow: var(--shadow); text-align: center; }
.stat-card .value { font-size: 2rem; font-weight: 700; color: var(--green-dark); }
.stat-card .label { font-size: .8rem; color: var(--text-muted); margin-top: .25rem; }

.charts-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(400px, 1fr));
  gap: 1.5rem; }
.chart-card { background: #fff; border-radius: 10px; padding: 1.25rem;
  box-shadow: var(--shadow); }
.chart-card h3 { font-size: .95rem; color: var(--text-muted); margin-bottom: 1rem;
  text-transform: uppercase; letter-spacing: .05em; font-weight: 600; }

.error-table { width: 100%; border-collapse: collapse; margin-top: .5rem; }
.error-table th, .error-table td { padding: .5rem .75rem; text-align: left;
  border-bottom: 1px solid var(--border); font-size: .9rem; }
.error-table th { color: var(--text-muted); font-weight: 600; font-size: .8rem;
  text-transform: uppercase; }

/* ─── Mobile ───────────────────────────────────────────────────────────────── */
@media (max-width: 767px) {
  .sidebar { width: 100%; }
  .sidebar.hidden-mobile { display: none; }
  .back-btn { display: block; }
  .charts-grid { grid-template-columns: 1fr; }
  .stat-cards { grid-template-columns: repeat(2, 1fr); }
}
