:root {
  --brand: #2ab7a9;
  --brand-dark: #1f9a8e;
  --bg: #f5f6f8;
  --surface: #ffffff;
  --text: #1c1c1e;
  --muted: #8e8e93;
  --border: #e5e5ea;
  --danger: #ff3b30;
  --badge: #ff3b30;
  --radius: 12px;
  --header-h: 52px;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

* { box-sizing: border-box; margin: 0; padding: 0; -webkit-tap-highlight-color: transparent; }
html, body { height: 100%; }
body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 15px;
  line-height: 1.4;
}

/* Splash */
.splash { display: flex; flex-direction: column; align-items: center; justify-content: center; height: 100%; gap: 12px; }
.splash-logo { width: 72px; height: 72px; border-radius: 18px; background: var(--brand); color: #fff; display: flex; align-items: center; justify-content: center; font-size: 30px; font-weight: 800; }
.splash h1 { font-size: 22px; }
.splash p { color: var(--muted); }

/* App shell */
.app { height: 100%; display: flex; flex-direction: column; }
.app-header {
  position: sticky; top: 0; z-index: 20;
  height: calc(var(--header-h) + var(--safe-top));
  padding-top: var(--safe-top);
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  display: flex; align-items: center; gap: 8px;
  padding-left: 8px; padding-right: 12px;
}
.app-header .hamburger, .app-header .back-btn {
  width: 40px; height: 40px; border: none; background: none; font-size: 22px; color: var(--text);
  display: flex; align-items: center; justify-content: center; cursor: pointer; border-radius: 50%;
}
.app-header .back-btn { font-size: 26px; }
.app-header .title { font-weight: 600; font-size: 17px; flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.app-header .subtitle { font-size: 12px; color: var(--muted); }
.app-header .actions { display: flex; align-items: center; gap: 4px; }
.icon-btn { width: 40px; height: 40px; border: none; background: none; font-size: 20px; cursor: pointer; border-radius: 50%; display: flex; align-items: center; justify-content: center; position: relative; color: var(--text); }

.badge-count {
  position: absolute; top: 2px; right: 0; min-width: 18px; height: 18px; padding: 0 4px;
  background: var(--badge); color: #fff; border-radius: 10px; font-size: 11px; font-weight: 700;
  display: flex; align-items: center; justify-content: center;
}
.badge-count.hidden { display: none; }

/* Scrollable content */
.content { flex: 1; overflow-y: auto; -webkit-overflow-scrolling: touch; }

/* Lists */
.list { list-style: none; }
.list-item {
  display: flex; align-items: center; gap: 12px; padding: 12px 16px;
  background: var(--surface); border-bottom: 1px solid var(--border); cursor: pointer;
}
.list-item:hover { background: #f9f9fa; }
.list-item.unread { background: #eef9f8; }
.avatar {
  width: 48px; height: 48px; border-radius: 50%; background: var(--brand);
  color: #fff; display: flex; align-items: center; justify-content: center;
  font-weight: 700; font-size: 18px; flex-shrink: 0; overflow: hidden;
}
.avatar img { width: 100%; height: 100%; object-fit: cover; }
.list-item .info { flex: 1; min-width: 0; }
.list-item .top { display: flex; justify-content: space-between; align-items: baseline; }
.list-item .name { font-weight: 600; font-size: 16px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.list-item .time { font-size: 12px; color: var(--muted); flex-shrink: 0; margin-left: 8px; }
.list-item .sub { display: flex; justify-content: space-between; align-items: center; margin-top: 2px; }
.list-item .last { font-size: 13px; color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.list-item .count {
  background: var(--badge); color: #fff; border-radius: 12px; min-width: 22px; height: 22px;
  padding: 0 6px; font-size: 12px; font-weight: 700; display: flex; align-items: center; justify-content: center; flex-shrink: 0;
}
.list-item .count.hidden { display: none; }

/* Cards / empty */
.empty { text-align: center; color: var(--muted); padding: 48px 24px; font-size: 15px; }
.section-title { padding: 10px 16px 6px; color: var(--muted); font-size: 13px; font-weight: 600; text-transform: uppercase; letter-spacing: .5px; }

/* Buttons */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  padding: 12px 18px; border: none; border-radius: 10px; font-size: 15px; font-weight: 600;
  cursor: pointer; text-decoration: none; background: var(--surface); color: var(--text);
  border: 1px solid var(--border); width: 100%;
}
.btn-primary { background: var(--brand); color: #fff; border-color: var(--brand); }
.btn-danger { background: var(--danger); color: #fff; border-color: var(--danger); }
.btn-ghost { background: none; border: none; color: var(--brand); }
.btn-sm { padding: 6px 12px; font-size: 13px; width: auto; }
.btn:disabled { opacity: .5; }

/* Forms */
.field { margin-bottom: 14px; }
.field label { display: block; margin-bottom: 6px; font-size: 13px; color: var(--muted); font-weight: 600; }
.field input, .field select, .field textarea {
  width: 100%; padding: 12px; border: 1px solid var(--border); border-radius: 10px;
  font-size: 15px; background: var(--surface); color: var(--text);
}
.field input:focus, .field select:focus, .field textarea:focus { outline: none; border-color: var(--brand); }
.field .hint { font-size: 12px; color: var(--muted); margin-top: 4px; }

/* Alerts */
.alert { padding: 12px 14px; border-radius: 10px; margin-bottom: 12px; font-size: 14px; }
.alert-error { background: #ffeceb; color: #b3261e; }
.alert-success { background: #e6f7ef; color: #1a7f4e; }
.alert-warning { background: #fff6e0; color: #8a6d1a; }

/* Drawer (hamburger) */
.drawer-overlay { position: fixed; inset: 0; background: rgba(0,0,0,.4); z-index: 50; opacity: 0; pointer-events: none; transition: opacity .2s; }
.drawer-overlay.open { opacity: 1; pointer-events: auto; }
.drawer {
  position: fixed; top: 0; left: 0; bottom: 0; width: 280px; max-width: 85%;
  background: var(--surface); z-index: 60; transform: translateX(-100%); transition: transform .25s ease;
  display: flex; flex-direction: column; padding-top: var(--safe-top);
}
.drawer.open { transform: translateX(0); }
.drawer .drawer-brand { padding: 20px 20px 16px; border-bottom: 1px solid var(--border); font-size: 20px; font-weight: 800; color: var(--brand); }
.drawer nav { flex: 1; overflow-y: auto; padding: 8px 0; }
.drawer nav a {
  display: flex; align-items: center; gap: 14px; padding: 13px 20px; text-decoration: none;
  color: var(--text); font-size: 16px; position: relative;
}
.drawer nav a.active { color: var(--brand); font-weight: 600; }
.drawer nav a .drawer-emoji { font-size: 18px; width: 24px; text-align: center; }
.drawer .drawer-section { color: var(--muted); font-size: 12px; text-transform: uppercase; padding: 12px 20px 4px; letter-spacing: .5px; }
.drawer .logout { color: var(--danger); }

/* Floating action button */
.fab {
  position: fixed; right: 18px; bottom: calc(18px + var(--safe-bottom)); z-index: 30;
  width: 56px; height: 56px; border-radius: 50%; border: none; background: var(--brand); color: #fff;
  font-size: 26px; box-shadow: 0 4px 12px rgba(0,0,0,.2); display: flex; align-items: center; justify-content: center; cursor: pointer;
}

/* Modal */
.modal-overlay { position: fixed; inset: 0; background: rgba(0,0,0,.4); z-index: 70; display: flex; align-items: flex-end; }
.modal {
  background: var(--surface); width: 100%; border-radius: 16px 16px 0 0; padding: 20px 20px calc(20px + var(--safe-bottom));
  max-height: 85vh; overflow-y: auto; animation: slideUp .2s ease;
}
@keyframes slideUp { from { transform: translateY(40px); opacity: 0; } to { transform: translateY(0); opacity: 1; } }
.modal h2 { margin-bottom: 16px; font-size: 18px; }

/* Tabs */
.tabs { display: flex; border-bottom: 1px solid var(--border); background: var(--surface); }
.tabs button { flex: 1; padding: 12px; border: none; background: none; font-size: 14px; font-weight: 600; color: var(--muted); border-bottom: 2px solid transparent; cursor: pointer; }
.tabs button.active { color: var(--brand); border-bottom-color: var(--brand); }
.tab-pane { display: none; }
.tab-pane.active { display: block; }

/* Utility */
.flex { display: flex; align-items: center; gap: 8px; }
.between { justify-content: space-between; }
.muted { color: var(--muted); }
.mt { margin-top: 16px; }
.center { text-align: center; }
