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

:root {
  --bg: #0d1117;
  --bg2: #161b22;
  --bg3: #21262d;
  --bg4: #30363d;
  --border: #30363d;
  --text: #e6edf3;
  --text2: #8b949e;
  --text3: #6e7681;
  --accent: #58a6ff;
  --accent-h: #79b8ff;
  --green: #3fb950;
  --red: #f85149;
  --yellow: #e3b341;
  --purple: #bc8cff;
  --orange: #ff9f0a;
  --sidebar-w: 220px;
  --radius: 8px;
}

html, body { height: 100%; font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif; background: var(--bg); color: var(--text); font-size: 14px; }

/* ── Scrollbar ── */
::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--bg4); border-radius: 3px; }

/* ══════════════════════════════════════════════
   LOGIN
══════════════════════════════════════════════ */
.login-bg {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: radial-gradient(ellipse at 50% 0%, rgba(88,166,255,0.12) 0%, transparent 60%),
              radial-gradient(ellipse at 80% 80%, rgba(188,140,255,0.08) 0%, transparent 50%),
              var(--bg);
}

.login-content { text-align: center; width: 100%; max-width: 700px; padding: 40px 20px; position: relative; z-index: 1; }

.login-logo { margin-bottom: 48px; }
.logo-icon {
  display: inline-flex; align-items: center; justify-content: center;
  width: 72px; height: 72px; background: var(--bg2); border: 1px solid var(--border);
  border-radius: 20px; font-size: 38px; margin-bottom: 16px;
  box-shadow: 0 0 40px rgba(88,166,255,0.15);
}
.login-logo h1 { font-size: 36px; font-weight: 700; color: var(--text); letter-spacing: -0.5px; }
.login-logo p { color: var(--text2); margin-top: 8px; font-size: 15px; }

.login-cards { display: flex; gap: 24px; justify-content: center; flex-wrap: wrap; }

.user-card {
  background: var(--bg2);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 40px 48px;
  cursor: pointer;
  transition: all 0.2s;
  min-width: 200px;
  position: relative;
  overflow: hidden;
}
.user-card::before {
  content: ''; position: absolute; top: 0; left: 0; right: 0; height: 2px;
  background: linear-gradient(90deg, var(--accent), transparent);
  opacity: 0; transition: opacity 0.2s;
}
.user-card:hover { border-color: var(--accent); transform: translateY(-4px); box-shadow: 0 12px 32px rgba(0,0,0,0.4); }
.user-card:hover::before { opacity: 1; }

.login-avatar-wrap { position: relative; width: 72px; height: 72px; margin: 0 auto 16px; }

.user-avatar {
  width: 72px; height: 72px; border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  font-size: 24px; font-weight: 700; color: #fff;
  overflow: hidden;
}
.user-avatar img { width: 100%; height: 100%; object-fit: cover; border-radius: 50%; }
.av-jireh { background: linear-gradient(135deg, #58a6ff, #bc8cff); }
.av-jason  { background: linear-gradient(135deg, #3fb950, #58a6ff); }

.user-card h2 { font-size: 22px; font-weight: 600; margin-bottom: 8px; }
.user-card p  { color: var(--text2); font-size: 13px; }
.card-arrow   { margin-top: 20px; color: var(--accent); font-size: 20px; }

/* ══════════════════════════════════════════════
   APP LAYOUT
══════════════════════════════════════════════ */
#app-view { display: flex; height: 100vh; overflow: hidden; }

/* ── Sidebar ── */
#sidebar {
  width: var(--sidebar-w);
  background: var(--bg2);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  flex-shrink: 0;
  padding: 0;
}

.sidebar-top { padding: 20px 16px 12px; }

.sidebar-brand { display: flex; align-items: center; gap: 10px; margin-bottom: 20px; }
.brand-icon { font-size: 20px; line-height: 1; }
.brand-name { font-size: 15px; font-weight: 600; }

.sidebar-user {
  display: flex; align-items: center; gap: 10px;
  padding: 10px 12px; background: var(--bg3); border-radius: var(--radius);
  cursor: pointer; transition: background 0.15s;
}
.sidebar-user:hover { background: var(--bg4); }

.sidebar-avatar-wrap { position: relative; flex-shrink: 0; }
.sidebar-avatar {
  width: 36px; height: 36px; border-radius: 50%;
  background: linear-gradient(135deg, var(--accent), var(--purple));
  display: flex; align-items: center; justify-content: center;
  font-size: 13px; font-weight: 700; color: #fff;
  overflow: hidden;
}
.sidebar-avatar img { width: 100%; height: 100%; object-fit: cover; border-radius: 50%; }

.avatar-edit-badge {
  position: absolute; bottom: -2px; right: -2px;
  width: 16px; height: 16px; background: var(--bg2); border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  font-size: 9px; border: 1px solid var(--border); opacity: 0; transition: opacity 0.15s;
}
.sidebar-user:hover .avatar-edit-badge { opacity: 1; }
#sidebar-username { font-size: 14px; font-weight: 500; }

.sidebar-nav { flex: 1; padding: 8px 12px; display: flex; flex-direction: column; gap: 2px; overflow-y: auto; }

.nav-btn {
  display: flex; align-items: center; gap: 10px; width: 100%;
  padding: 9px 12px; border: none; background: transparent; color: var(--text2);
  border-radius: var(--radius); cursor: pointer; font-size: 13.5px; font-weight: 500;
  transition: all 0.15s; text-align: left; position: relative;
}
.nav-btn svg { width: 18px; height: 18px; flex-shrink: 0; }
.nav-emoji { font-size: 17px; width: 20px; text-align: center; flex-shrink: 0; line-height: 1; }
.nav-btn:hover { background: var(--bg3); color: var(--text); }
.nav-btn.active { background: rgba(88,166,255,0.12); color: var(--accent); }

.nav-badge {
  margin-left: auto; background: var(--red); color: #fff;
  border-radius: 10px; padding: 1px 6px; font-size: 11px; font-weight: 600;
}

.logout-btn {
  display: flex; align-items: center; gap: 10px; margin: 12px;
  padding: 9px 12px; border: none; background: transparent; color: var(--text2);
  border-radius: var(--radius); cursor: pointer; font-size: 13.5px; transition: all 0.15s;
}
.logout-btn svg { width: 18px; height: 18px; }
.logout-btn:hover { background: rgba(248,81,73,0.1); color: var(--red); }

/* ── Main ── */
#main-content { flex: 1; overflow-y: auto; display: flex; flex-direction: column; }

.section { display: none; flex-direction: column; padding: 32px 36px; flex: 1; }
.section.active { display: flex; }

.section-header { display: flex; align-items: flex-start; justify-content: space-between; margin-bottom: 28px; }
.section-header h1 { font-size: 26px; font-weight: 700; letter-spacing: -0.5px; }
.section-sub { color: var(--text2); font-size: 13px; margin-top: 4px; }

/* ── Buttons ── */
.btn {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 8px 16px; border-radius: var(--radius); border: none;
  cursor: pointer; font-size: 13.5px; font-weight: 500; transition: all 0.15s; text-decoration: none;
}
.btn-primary { background: var(--accent); color: #fff; }
.btn-primary:hover { background: var(--accent-h); }
.btn-secondary { background: var(--bg3); color: var(--text); border: 1px solid var(--border); }
.btn-secondary:hover { background: var(--bg4); }
.btn-ghost { background: transparent; color: var(--text2); border: 1px solid var(--border); }
.btn-ghost:hover { background: var(--bg3); color: var(--text); }
.btn-danger { background: transparent; color: var(--red); border: 1px solid transparent; }
.btn-danger:hover { background: rgba(248,81,73,0.1); }
.btn-sm { padding: 5px 10px; font-size: 12px; }
.link-btn { background: none; border: none; color: var(--accent); cursor: pointer; font-size: 13px; }

/* ══════════════════════════════════════════════
   DASHBOARD
══════════════════════════════════════════════ */
.stats-row { display: grid; grid-template-columns: repeat(4, 1fr); gap: 16px; margin-bottom: 28px; }

.stat-card {
  background: var(--bg2); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 20px; display: flex; align-items: center; gap: 16px;
}
.stat-icon {
  width: 44px; height: 44px; border-radius: var(--radius);
  display: flex; align-items: center; justify-content: center; flex-shrink: 0;
}
.stat-icon svg { width: 22px; height: 22px; }
.stat-icon.blue   { background: rgba(88,166,255,0.12); color: var(--accent); }
.stat-icon.green  { background: rgba(63,185,80,0.12);  color: var(--green); }
.stat-icon.purple { background: rgba(188,140,255,0.12); color: var(--purple); }
.stat-icon.orange { background: rgba(255,159,10,0.12); color: var(--orange); }
.stat-icon.teal   { background: rgba(45,212,191,0.12); color: #2dd4bf; }
.stat-value { font-size: 28px; font-weight: 700; }
.stat-label { font-size: 12px; color: var(--text2); margin-top: 2px; }

.dashboard-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 20px; }

.widget { background: var(--bg2); border: 1px solid var(--border); border-radius: var(--radius); padding: 20px; }
.widget-header { display: flex; align-items: center; justify-content: space-between; margin-bottom: 16px; }
.widget-header h3 { font-size: 15px; font-weight: 600; }

.dash-task-item { display: flex; align-items: center; gap: 10px; padding: 8px 0; border-bottom: 1px solid var(--bg3); }
.dash-task-item:last-child { border-bottom: none; }
.dash-empty { color: var(--text2); font-size: 13px; padding: 16px 0; text-align: center; }

.dash-notes-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
  gap: 12px;
}

.dash-note-card {
  background: var(--bg3);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 12px 14px;
  cursor: pointer;
  transition: transform 0.15s, box-shadow 0.15s;
  overflow: hidden;
}
.dash-note-card:hover { transform: translateY(-2px); box-shadow: 0 6px 18px rgba(0,0,0,0.3); }

.dash-note-title {
  font-size: 12px;
  font-weight: 600;
  color: var(--text);
  margin-bottom: 4px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.dash-note-body {
  font-size: 12px;
  color: var(--text2);
  line-height: 1.5;
  max-height: 60px;
  overflow: hidden;
  display: -webkit-box;
  -webkit-line-clamp: 3;
  -webkit-box-orient: vertical;
}

/* ══════════════════════════════════════════════
   TASKS
══════════════════════════════════════════════ */
.filter-tabs { display: flex; gap: 4px; margin-bottom: 20px; background: var(--bg2); border: 1px solid var(--border); border-radius: var(--radius); padding: 4px; width: fit-content; }
.filter-tab { padding: 6px 14px; border: none; background: transparent; color: var(--text2); border-radius: 6px; cursor: pointer; font-size: 13px; transition: all 0.15s; }
.filter-tab.active { background: var(--bg4); color: var(--text); }

.tasks-list { display: flex; flex-direction: column; gap: 10px; }

.task-card {
  background: var(--bg2); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 16px 18px; display: flex; align-items: flex-start; gap: 14px; transition: border-color 0.15s;
}
.task-card:hover { border-color: var(--bg4); }
.task-card.done { opacity: 0.55; }

.task-check {
  width: 20px; height: 20px; border-radius: 50%; border: 2px solid var(--border);
  display: flex; align-items: center; justify-content: center; cursor: pointer;
  flex-shrink: 0; margin-top: 1px; transition: all 0.15s; background: transparent;
}
.task-check.checked { background: var(--green); border-color: var(--green); }
.task-check.checked::after { content: '✓'; font-size: 11px; color: #fff; }

.task-body { flex: 1; min-width: 0; }
.task-title { font-size: 14px; font-weight: 500; margin-bottom: 4px; }
.task-desc  { font-size: 13px; color: var(--text2); margin-bottom: 8px; white-space: pre-wrap; word-break: break-word; }
.task-meta  { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }

.badge { padding: 2px 8px; border-radius: 4px; font-size: 11px; font-weight: 600; text-transform: uppercase; letter-spacing: 0.3px; }
.badge-high   { background: rgba(248,81,73,0.15);  color: var(--red); }
.badge-medium { background: rgba(227,179,65,0.15); color: var(--yellow); }
.badge-low    { background: rgba(63,185,80,0.15);  color: var(--green); }

.task-date { font-size: 11px; color: var(--text3); }
.task-actions { display: flex; gap: 4px; flex-shrink: 0; }
.icon-btn { background: none; border: none; cursor: pointer; color: var(--text3); padding: 4px; border-radius: 4px; transition: all 0.15s; }
.icon-btn:hover { color: var(--red); background: rgba(248,81,73,0.1); }
.icon-btn svg { width: 15px; height: 15px; }

/* ══════════════════════════════════════════════
   CALENDAR
══════════════════════════════════════════════ */
.calendar-wrapper { flex: 1; }
.cal-nav { display: flex; align-items: center; gap: 20px; margin-bottom: 20px; }
.cal-nav h2 { font-size: 20px; font-weight: 600; min-width: 160px; text-align: center; }

.cal-grid {
  display: grid; grid-template-columns: repeat(7, 1fr);
  gap: 1px; background: var(--border); border: 1px solid var(--border); border-radius: var(--radius); overflow: hidden;
}
#cal-days { display: contents; }

.cal-header { background: var(--bg2); padding: 10px; text-align: center; font-size: 12px; font-weight: 600; color: var(--text2); letter-spacing: 0.5px; }

.cal-day {
  background: var(--bg); min-height: 90px; padding: 8px; cursor: pointer; transition: background 0.15s; position: relative;
}
.cal-day:hover { background: var(--bg2); }
.cal-day.other-month { opacity: 0.3; }
.cal-day.today { background: rgba(88,166,255,0.05); }
.cal-day.today .day-num { color: var(--accent); background: var(--accent); color: #fff; border-radius: 50%; width: 24px; height: 24px; display: flex; align-items: center; justify-content: center; }
.day-num { font-size: 13px; font-weight: 500; margin-bottom: 4px; width: 24px; height: 24px; display: flex; align-items: center; justify-content: center; }
.day-notes { display: flex; flex-direction: column; gap: 2px; }
.day-note-dot {
  font-size: 11px; color: var(--accent); background: rgba(88,166,255,0.1);
  border-radius: 3px; padding: 1px 5px; white-space: nowrap; overflow: hidden;
  text-overflow: ellipsis; max-width: 100%;
}

/* ══════════════════════════════════════════════
   LINKS
══════════════════════════════════════════════ */
.search-bar-wrap { position: relative; margin-bottom: 20px; }
.search-icon { width: 16px; height: 16px; position: absolute; left: 12px; top: 50%; transform: translateY(-50%); color: var(--text3); }
.search-input { width: 100%; max-width: 400px; padding: 9px 12px 9px 36px; background: var(--bg2); border: 1px solid var(--border); border-radius: var(--radius); color: var(--text); font-size: 14px; outline: none; transition: border-color 0.15s; }
.search-input:focus { border-color: var(--accent); }

.links-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(300px, 1fr)); gap: 14px; }

.link-card {
  background: var(--bg2); border: 1px solid var(--border); border-radius: var(--radius); padding: 18px;
  display: flex; flex-direction: column; gap: 10px; transition: border-color 0.15s;
}
.link-card:hover { border-color: var(--bg4); }
.link-card-top { display: flex; align-items: flex-start; justify-content: space-between; gap: 8px; }
.link-card-favicon { width: 32px; height: 32px; border-radius: 6px; background: var(--bg3); display: flex; align-items: center; justify-content: center; font-size: 14px; flex-shrink: 0; }
.link-title { font-size: 14px; font-weight: 600; }
.link-url   { font-size: 12px; color: var(--accent); word-break: break-all; }
.link-url a { color: inherit; text-decoration: none; }
.link-url a:hover { text-decoration: underline; }
.link-desc  { font-size: 13px; color: var(--text2); }
.link-tags  { display: flex; flex-wrap: wrap; gap: 6px; }
.link-tag   { padding: 2px 8px; background: var(--bg3); border-radius: 4px; font-size: 11px; color: var(--text2); }

/* ══════════════════════════════════════════════
   PDFs
══════════════════════════════════════════════ */
.upload-zone {
  border: 2px dashed var(--border); border-radius: var(--radius); padding: 48px;
  text-align: center; margin-bottom: 24px; transition: all 0.2s; cursor: pointer;
}
.upload-zone.drag-over { border-color: var(--accent); background: rgba(88,166,255,0.05); }
.upload-zone:hover { border-color: var(--bg4); }
.upload-icon { color: var(--text3); margin-bottom: 12px; }
.upload-title { font-size: 16px; font-weight: 500; margin-bottom: 6px; }
.upload-sub   { color: var(--text2); font-size: 13px; margin-bottom: 12px; }

.pdfs-list { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 14px; }

.pdf-card {
  background: var(--bg2); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 18px; display: flex; flex-direction: column; gap: 12px; cursor: pointer; transition: border-color 0.15s;
}
.pdf-card:hover { border-color: var(--accent); }
.pdf-icon { font-size: 32px; }
.pdf-name { font-size: 13px; font-weight: 500; word-break: break-all; }
.pdf-size { font-size: 11px; color: var(--text3); }
.pdf-card-actions { display: flex; gap: 8px; }

.pdf-viewer-panel {
  position: fixed; inset: 0; background: var(--bg); z-index: 100;
  display: flex; flex-direction: column;
}
.pdf-viewer-header {
  display: flex; align-items: center; gap: 16px; padding: 12px 20px;
  background: var(--bg2); border-bottom: 1px solid var(--border); flex-shrink: 0;
}
#pdf-viewer-name { font-weight: 500; flex: 1; }
.pdf-page-nav { display: flex; align-items: center; gap: 10px; font-size: 13px; }
.pdf-canvas-wrap { flex: 1; overflow: auto; display: flex; justify-content: center; align-items: flex-start; padding: 24px; background: var(--bg3); }
#pdf-canvas { box-shadow: 0 4px 32px rgba(0,0,0,0.5); max-width: 100%; }

/* ══════════════════════════════════════════════
   AI CHAT
══════════════════════════════════════════════ */
.ai-container { display: flex; flex-direction: column; flex: 1; min-height: 0; background: var(--bg2); border: 1px solid var(--border); border-radius: var(--radius); overflow: hidden; }

.ai-messages { flex: 1; overflow-y: auto; padding: 20px; display: flex; flex-direction: column; gap: 16px; }

.ai-welcome { text-align: center; padding: 40px 20px; }
.ai-logo { font-size: 48px; margin-bottom: 16px; }
.ai-welcome h3 { font-size: 18px; font-weight: 600; margin-bottom: 8px; }
.ai-welcome p  { color: var(--text2); }

.msg { display: flex; gap: 12px; max-width: 80%; }
.msg.user { align-self: flex-end; flex-direction: row-reverse; }
.msg-avatar {
  width: 32px; height: 32px; border-radius: 50%; flex-shrink: 0;
  display: flex; align-items: center; justify-content: center; font-size: 14px; font-weight: 600;
}
.msg.user .msg-avatar { background: linear-gradient(135deg, var(--accent), var(--purple)); color: #fff; }
.msg.ai   .msg-avatar { background: var(--bg3); font-size: 18px; }

.msg-content { background: var(--bg3); border-radius: 12px; padding: 12px 16px; }
.msg.user .msg-content { background: rgba(88,166,255,0.15); }
.msg-content p    { margin-bottom: 8px; line-height: 1.6; }
.msg-content p:last-child { margin-bottom: 0; }
.msg-content code { background: var(--bg4); padding: 1px 5px; border-radius: 3px; font-size: 12px; font-family: monospace; }
.msg-content pre  { background: var(--bg); border: 1px solid var(--border); border-radius: 6px; padding: 12px; overflow-x: auto; font-family: monospace; font-size: 12px; line-height: 1.5; margin: 8px 0; }
.msg-content ul, .msg-content ol { padding-left: 20px; }
.msg-content li   { margin-bottom: 4px; line-height: 1.5; }

.msg-typing .msg-content { color: var(--text2); font-style: italic; }

.ai-input-wrap {
  display: flex; gap: 10px; padding: 16px; border-top: 1px solid var(--border);
  background: var(--bg2); align-items: flex-end;
}
.ai-input {
  flex: 1; background: var(--bg); border: 1px solid var(--border); color: var(--text);
  border-radius: var(--radius); padding: 10px 14px; font-size: 14px; resize: none; outline: none;
  font-family: inherit; line-height: 1.5; transition: border-color 0.15s;
}
.ai-input:focus { border-color: var(--accent); }
.ai-send-btn { align-self: flex-end; }

/* ══════════════════════════════════════════════
   CALCULATOR
══════════════════════════════════════════════ */
.calc-wrap { display: flex; gap: 24px; align-items: flex-start; flex-wrap: wrap; }

.calculator {
  background: var(--bg2); border: 1px solid var(--border); border-radius: 16px; overflow: hidden;
  width: 320px; flex-shrink: 0;
}
.calc-display { background: var(--bg); padding: 24px 20px 16px; text-align: right; }
.calc-expr { font-size: 14px; color: var(--text2); min-height: 20px; margin-bottom: 4px; }
.calc-num  { font-size: 44px; font-weight: 300; letter-spacing: -1px; word-break: break-all; }

.calc-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 1px; background: var(--border); }

.calc-btn {
  background: var(--bg3); border: none; color: var(--text); font-size: 20px; font-weight: 400;
  padding: 0; height: 72px; cursor: pointer; transition: background 0.1s; font-family: inherit;
}
.calc-btn:hover  { background: var(--bg4); }
.calc-btn:active { background: var(--border); }
.calc-btn.utility  { background: var(--bg4); color: var(--text2); font-size: 18px; }
.calc-btn.utility:hover { background: #444c56; }
.calc-btn.operator { background: var(--orange); color: #fff; }
.calc-btn.operator:hover  { background: #ffb340; }
.calc-btn.operator:active { background: #e89300; }
.calc-btn.zero { grid-column: span 2; text-align: left; padding-left: 28px; font-size: 20px; }

.calc-history {
  background: var(--bg2); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 16px; min-width: 200px; flex: 1;
}
.calc-history h3 { font-size: 14px; font-weight: 600; margin-bottom: 12px; color: var(--text2); }
.calc-history-list { display: flex; flex-direction: column; gap: 6px; max-height: 400px; overflow-y: auto; margin-bottom: 12px; }
.hist-item { padding: 6px 10px; background: var(--bg3); border-radius: 4px; font-size: 13px; font-family: monospace; color: var(--text2); }
.hist-item span { color: var(--text); font-weight: 600; }

/* ══════════════════════════════════════════════
   MODAL
══════════════════════════════════════════════ */
.modal-overlay {
  display: none; /* controlled by .open class only — never show by default */
  position: fixed; inset: 0; background: rgba(0,0,0,0.6); backdrop-filter: blur(4px);
  z-index: 200; align-items: center; justify-content: center; padding: 20px;
}
.modal-overlay.open { display: flex; }
.modal {
  background: var(--bg2); border: 1px solid var(--border); border-radius: 12px;
  width: 100%; max-width: 520px; max-height: 90vh; overflow-y: auto;
  box-shadow: 0 24px 64px rgba(0,0,0,0.6);
}
.modal-header { display: flex; align-items: center; justify-content: space-between; padding: 20px 24px 16px; border-bottom: 1px solid var(--border); }
.modal-header h2 { font-size: 18px; font-weight: 600; }
.modal-close { background: none; border: none; color: var(--text2); cursor: pointer; font-size: 24px; line-height: 1; padding: 0; transition: color 0.15s; }
.modal-close:hover { color: var(--text); }
.modal-body { padding: 24px; display: flex; flex-direction: column; gap: 16px; }

/* Form elements */
.form-group { display: flex; flex-direction: column; gap: 6px; }
.form-label { font-size: 13px; font-weight: 500; color: var(--text2); }
.form-input, .form-textarea, .form-select {
  background: var(--bg); border: 1px solid var(--border); border-radius: var(--radius);
  color: var(--text); padding: 9px 12px; font-size: 14px; font-family: inherit;
  outline: none; transition: border-color 0.15s; width: 100%;
}
.form-input:focus, .form-textarea:focus, .form-select:focus { border-color: var(--accent); }
.form-textarea { resize: vertical; min-height: 80px; line-height: 1.5; }
.form-select { cursor: pointer; }
option { background: var(--bg2); }
.form-row { display: flex; gap: 12px; }
.form-row .form-group { flex: 1; }
.modal-footer { display: flex; gap: 10px; justify-content: flex-end; padding-top: 4px; }

/* Notes list in calendar modal */
.note-item {
  display: flex; align-items: flex-start; justify-content: space-between; gap: 10px;
  padding: 10px 12px; background: var(--bg3); border-radius: 6px; font-size: 13px; line-height: 1.5;
}
.note-text { flex: 1; white-space: pre-wrap; }

/* ══════════════════════════════════════════════
   TOAST
══════════════════════════════════════════════ */
.toast {
  position: fixed; bottom: 24px; right: 24px; background: var(--bg3); border: 1px solid var(--border);
  color: var(--text); padding: 12px 18px; border-radius: var(--radius); font-size: 14px;
  box-shadow: 0 8px 24px rgba(0,0,0,0.4); z-index: 999; opacity: 0;
  transition: opacity 0.3s; pointer-events: none;
}
.toast.show { opacity: 1; }
.toast.success { border-left: 3px solid var(--green); }
.toast.error   { border-left: 3px solid var(--red); }

/* ══════════════════════════════════════════════
   PIN OVERLAY
══════════════════════════════════════════════ */
#pin-overlay {
  display: none; position: fixed; inset: 0; z-index: 300;
  background: radial-gradient(ellipse at 50% 0%, rgba(88,166,255,0.10) 0%, transparent 60%), var(--bg);
  align-items: center; justify-content: center;
}
#pin-overlay.open { display: flex; }

.pin-box {
  text-align: center; width: 100%; max-width: 360px; padding: 40px 32px;
  background: var(--bg2); border: 1px solid var(--border); border-radius: 20px;
  box-shadow: 0 24px 64px rgba(0,0,0,0.6);
}
.pin-box .user-avatar { margin: 0 auto 16px; }
.pin-box h2 { font-size: 22px; font-weight: 600; margin-bottom: 6px; }
.pin-box > p { font-size: 13px; color: var(--text2); margin-bottom: 28px; }

.pin-digits {
  display: flex; gap: 10px; justify-content: center; margin-bottom: 24px;
}
.pin-digit {
  width: 44px; height: 54px; background: var(--bg3); border: 2px solid var(--border);
  border-radius: 10px; color: var(--text); font-size: 22px; font-weight: 700;
  text-align: center; outline: none; caret-color: transparent; transition: border-color 0.15s;
  -webkit-text-security: disc;
}
.pin-digit:focus { border-color: var(--accent); }
.pin-digit.filled { border-color: var(--bg4); }

.pin-error {
  font-size: 13px; color: var(--red); min-height: 18px; margin-bottom: 16px;
  animation: shake 0.3s;
}
@keyframes shake {
  0%,100% { transform: translateX(0); }
  20%,60%  { transform: translateX(-6px); }
  40%,80%  { transform: translateX(6px); }
}

.pin-actions { display: flex; flex-direction: column; gap: 10px; }
.pin-actions .btn { width: 100%; justify-content: center; }

.pin-lock-icon {
  width: 52px; height: 52px; background: rgba(88,166,255,0.12);
  border-radius: 50%; display: flex; align-items: center; justify-content: center;
  margin: 0 auto 16px; font-size: 24px;
}

/* PIN button in sidebar */
.pin-sidebar-btn {
  display: flex; align-items: center; gap: 10px; margin: 0 12px 4px;
  padding: 8px 12px; border: none; background: transparent; color: var(--text2);
  border-radius: var(--radius); cursor: pointer; font-size: 13px; width: calc(100% - 24px);
  transition: all 0.15s;
}
.pin-sidebar-btn:hover { background: var(--bg3); color: var(--text); }
.pin-sidebar-btn svg { width: 16px; height: 16px; flex-shrink: 0; }

/* ══════════════════════════════════════════════
   DIRECT MESSAGES
══════════════════════════════════════════════ */
.dm-container {
  display: flex; flex-direction: column; flex: 1; min-height: 0;
  background: var(--bg2); border: 1px solid var(--border); border-radius: var(--radius); overflow: hidden;
}
.dm-messages {
  flex: 1; overflow-y: auto; padding: 12px 14px;
  display: flex; flex-direction: column; gap: 3px;
}

.dm-msg {
  display: flex; gap: 7px; align-items: flex-end;
  max-width: 78%; margin-bottom: 2px;
  width: fit-content;
}
.dm-msg.mine   { margin-left: auto; flex-direction: row-reverse; }
.dm-msg.theirs { margin-right: auto; }
.dm-msg.tail   { margin-bottom: 8px; }

.dm-avatar {
  width: 24px; height: 24px; border-radius: 50%; flex-shrink: 0;
  display: flex; align-items: center; justify-content: center;
  font-size: 9px; font-weight: 700; color: #fff; overflow: hidden;
  margin-bottom: 2px;
}
.dm-avatar img { width: 100%; height: 100%; object-fit: cover; border-radius: 50%; }
.dm-avatar.hidden { visibility: hidden; }

.dm-bubble-wrap { display: flex; flex-direction: column; gap: 1px; align-items: flex-start; }
.dm-msg.mine .dm-bubble-wrap { align-items: flex-end; }

.dm-sender { font-size: 10px; color: var(--text3); padding: 0 4px; display: none; }

.dm-bubble {
  padding: 7px 11px;
  border-radius: 16px;
  font-size: 13px;
  line-height: 1.45;
  word-break: break-word;
  white-space: pre-wrap;
  max-width: 100%;
}
.dm-msg.mine .dm-bubble {
  background: linear-gradient(135deg, #3b82f6, #6366f1);
  color: #fff;
  border-bottom-right-radius: 4px;
  box-shadow: 0 1px 4px rgba(99,102,241,0.3);
}
.dm-msg.theirs .dm-bubble {
  background: var(--bg3);
  color: var(--text);
  border-bottom-left-radius: 4px;
  border: 1px solid rgba(255,255,255,0.05);
}
.dm-msg.mine .dm-bubble img,
.dm-msg.theirs .dm-bubble img {
  max-width: 180px; border-radius: 10px; display: block; margin-top: 4px;
}

.dm-bubble-row {
  display: flex;
  align-items: center;
  gap: 5px;
}
.dm-msg.mine .dm-bubble-row { flex-direction: row-reverse; }

.dm-unsend-btn {
  background: none;
  border: none;
  color: var(--text3);
  font-size: 11px;
  cursor: pointer;
  padding: 2px 4px;
  border-radius: 4px;
  opacity: 0;
  transition: opacity 0.15s, color 0.15s;
  flex-shrink: 0;
  line-height: 1;
}
.dm-msg:hover .dm-unsend-btn { opacity: 1; }
.dm-unsend-btn:hover { color: var(--red); }

.dm-time {
  font-size: 9.5px; color: var(--text3); padding: 0 4px;
  opacity: 0.75;
}

.dm-date-divider {
  text-align: center; font-size: 10.5px; color: var(--text3);
  padding: 10px 0 6px; position: relative; align-self: stretch;
}
.dm-date-divider::before, .dm-date-divider::after {
  content: ''; position: absolute; top: 58%; width: 28%; height: 1px; background: var(--border);
}
.dm-date-divider::before { left: 0; }
.dm-date-divider::after  { right: 0; }

.dm-input-wrap {
  border-top: 1px solid var(--border);
  padding: 8px 10px;
  background: var(--bg2);
}
.dm-input-row { display: flex; gap: 8px; align-items: flex-end; }
#dm-input {
  padding: 7px 11px;
  font-size: 13px;
  line-height: 1.4;
  min-height: unset;
  max-height: 80px;
  overflow-y: auto;
}
.dm-send-btn {
  padding: 7px 14px;
  font-size: 13px;
  border-radius: 18px;
  flex-shrink: 0;
}

.dm-unread-badge {
  display: inline-block; background: var(--red); color: #fff;
  border-radius: 10px; padding: 1px 8px; font-size: 11px; font-weight: 700; margin-left: 6px;
}

/* ══════════════════════════════════════════════
   MISC
══════════════════════════════════════════════ */
.empty-state { text-align: center; padding: 48px 20px; color: var(--text2); }
.empty-state-icon { font-size: 40px; margin-bottom: 12px; opacity: 0.5; }
.empty-state p { font-size: 14px; }


/* ══════════════════════════════════════════════
   LOGIN VIEW (Stage 6 — dynamic users + canvas)
══════════════════════════════════════════════ */
#login-view {
  position: relative;
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  background: radial-gradient(ellipse at 50% 0%, rgba(88,166,255,0.10) 0%, transparent 60%),
              radial-gradient(ellipse at 80% 80%, rgba(188,140,255,0.07) 0%, transparent 50%),
              var(--bg);
}

#bg-canvas {
  position: absolute;
  inset: 0;
  z-index: 0;
  pointer-events: none;
}

/* ── Users Grid ── */
.users-grid {
  display: flex;
  flex-wrap: wrap;
  gap: 20px;
  justify-content: center;
  margin-top: 8px;
}

/* Override .user-card to fit the new dynamic card layout */
.user-card {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 28px 32px 24px;
  min-width: 160px;
  max-width: 180px;
  text-align: center;
}

.user-card h3 { font-size: 16px; font-weight: 600; margin: 12px 0 4px; }
.user-card p  { font-size: 12px; color: var(--text2); }

/* ── User Card Avatar ── */
.ucard-av {
  width: 72px; height: 72px; border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  font-size: 22px; font-weight: 700; color: #fff;
  overflow: hidden; flex-shrink: 0;
  box-shadow: 0 4px 16px rgba(0,0,0,0.3);
}
.ucard-av img { width: 100%; height: 100%; object-fit: cover; border-radius: 50%; }

/* ── Lock Badge ── */
.ucard-lock {
  position: absolute;
  top: 20px; right: 20px;
  font-size: 14px;
  line-height: 1;
  opacity: 0.8;
}

/* ── Delete Button ── */
.ucard-del {
  position: absolute;
  top: 8px; right: 8px;
  width: 22px; height: 22px;
  background: var(--bg4); border: none;
  color: var(--text3); border-radius: 50%;
  font-size: 16px; line-height: 1;
  cursor: pointer; display: flex; align-items: center; justify-content: center;
  opacity: 0; transition: opacity 0.15s, color 0.15s, background 0.15s;
  padding: 0;
}
.user-card:hover .ucard-del { opacity: 1; }
.ucard-del:hover { background: rgba(248,81,73,0.2); color: var(--red); }

/* ── Add a User card ── */
.add-card {
  border-style: dashed !important;
  border-color: var(--bg4) !important;
  background: transparent !important;
}
.add-card:hover {
  border-color: var(--accent) !important;
  background: rgba(88,166,255,0.04) !important;
}

.add-card-icon {
  width: 72px; height: 72px; border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  font-size: 28px; color: var(--text3);
  background: var(--bg3); border: 2px dashed var(--bg4);
  transition: all 0.2s;
}
.add-card:hover .add-card-icon {
  color: var(--accent); border-color: var(--accent);
  background: rgba(88,166,255,0.08);
}

/* ══════════════════════════════════════════════
   REGISTRATION OVERLAY
══════════════════════════════════════════════ */
#reg-overlay {
  display: none;
  position: fixed; inset: 0; z-index: 400;
  background: rgba(0,0,0,0.7);
  backdrop-filter: blur(6px);
  align-items: center; justify-content: center;
  padding: 20px;
}
#reg-overlay.open { display: flex; }

.reg-box {
  position: relative;
  background: var(--bg2); border: 1px solid var(--border);
  border-radius: 20px; padding: 36px 32px;
  width: 100%; max-width: 420px;
  box-shadow: 0 24px 64px rgba(0,0,0,0.6);
  display: flex; flex-direction: column; gap: 16px;
  max-height: 90vh; overflow-y: auto;
}

.reg-box h2 { font-size: 22px; font-weight: 700; text-align: center; }

.reg-sub { font-size: 13px; color: var(--text2); text-align: center; margin-top: -8px; }

.reg-close {
  position: absolute; top: 14px; right: 16px;
  background: none; border: none; color: var(--text2);
  font-size: 24px; line-height: 1; cursor: pointer; padding: 0;
  transition: color 0.15s;
}
.reg-close:hover { color: var(--text); }

/* ── Avatar upload button ── */
.reg-avatar-btn {
  width: 96px; height: 96px; border-radius: 50%;
  border: 2px dashed var(--border);
  background: var(--bg3);
  margin: 0 auto;
  cursor: pointer; overflow: hidden;
  display: flex; align-items: center; justify-content: center;
  transition: border-color 0.2s, background 0.2s;
  flex-shrink: 0;
}
.reg-avatar-btn:hover { border-color: var(--accent); background: rgba(88,166,255,0.07); }

.reg-avatar-preview {
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 6px; color: var(--text3); font-size: 11px;
  width: 100%; height: 100%;
}

/* ── Registration error ── */
.reg-error {
  font-size: 13px; color: var(--red); min-height: 16px;
  text-align: center; animation: shake 0.3s;
}

/* ══════════════════════════════════════════════
   TOGGLE SWITCH (iOS-style)
══════════════════════════════════════════════ */
.pin-toggle-row {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
}

.toggle {
  position: relative; display: inline-block;
  width: 44px; height: 24px; flex-shrink: 0; cursor: pointer;
}
.toggle input { opacity: 0; width: 0; height: 0; position: absolute; }

.toggle-track {
  position: absolute; inset: 0;
  background: var(--bg4); border-radius: 24px;
  transition: background 0.2s;
}
.toggle input:checked ~ .toggle-track { background: var(--accent); }

.toggle-thumb {
  position: absolute; top: 3px; left: 3px;
  width: 18px; height: 18px; border-radius: 50%;
  background: #fff;
  transition: transform 0.2s;
  box-shadow: 0 1px 4px rgba(0,0,0,0.3);
}
.toggle input:checked ~ .toggle-track .toggle-thumb { transform: translateX(20px); }

/* ══════════════════════════════════════════════
   MESSAGES — Two-column layout
══════════════════════════════════════════════ */
.dm-layout {
  display: flex;
  flex: 1;
  min-height: 0;
  gap: 0;
  background: var(--bg2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
}

/* ── Contacts sidebar ── */
.dm-contacts {
  width: 220px;
  flex-shrink: 0;
  border-right: 1px solid var(--border);
  overflow-y: auto;
  display: flex;
  flex-direction: column;
}

.dm-contacts-header {
  padding: 14px 16px 10px;
  font-size: 12px; font-weight: 600; color: var(--text3);
  text-transform: uppercase; letter-spacing: 0.6px;
  border-bottom: 1px solid var(--border);
}

.dm-contact {
  display: flex; align-items: center; gap: 12px;
  padding: 12px 14px; cursor: pointer;
  border-bottom: 1px solid rgba(48,54,61,0.4);
  transition: background 0.15s;
  position: relative;
}
.dm-contact:hover { background: var(--bg3); }
.dm-contact.dm-contact-active { background: rgba(88,166,255,0.08); }
.dm-contact.dm-contact-active::before {
  content: ''; position: absolute; left: 0; top: 0; bottom: 0;
  width: 3px; background: var(--accent); border-radius: 0 2px 2px 0;
}

.dm-contact-av {
  width: 38px; height: 38px; border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  font-size: 13px; font-weight: 700; color: #fff;
  overflow: hidden; flex-shrink: 0;
}
.dm-contact-av img { width: 100%; height: 100%; object-fit: cover; border-radius: 50%; }

.dm-contact-info { flex: 1; min-width: 0; }
.dm-contact-name { font-size: 13.5px; font-weight: 500; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.dm-contact-preview { font-size: 11.5px; color: var(--text3); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; margin-top: 2px; }

/* ── Chat panel ── */
.dm-chat-panel {
  flex: 1; min-width: 0;
  display: flex; flex-direction: column;
  min-height: 0;
}

.dm-chat-panel .dm-messages { flex: 1; }


/* ══════════════════════════════════════════════
   NOTES
══════════════════════════════════════════════ */
.notes-grid {
  columns: 220px auto;
  column-gap: 16px;
}

.note-card {
  break-inside: avoid;
  background: var(--bg2);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 16px;
  cursor: pointer;
  transition: transform 0.15s, box-shadow 0.15s;
  margin-bottom: 16px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  word-break: break-word;
}
.note-card:hover {
  transform: translateY(-3px);
  box-shadow: 0 8px 24px rgba(0,0,0,0.35);
}

.note-card-title {
  font-size: 14px;
  font-weight: 600;
  color: var(--text);
  line-height: 1.4;
}

.note-card-body {
  font-size: 13px;
  color: var(--text2);
  line-height: 1.65;
  max-height: 240px;
  overflow: hidden;
}

.note-card-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding-top: 8px;
  border-top: 1px solid rgba(255,255,255,0.06);
  margin-top: 4px;
}

.note-card-date {
  font-size: 11px;
  color: var(--text3);
}

.note-card-del {
  background: none;
  border: none;
  color: var(--text3);
  cursor: pointer;
  padding: 4px;
  border-radius: 4px;
  opacity: 0;
  transition: opacity 0.15s, color 0.15s;
  display: flex;
  align-items: center;
}
.note-card:hover .note-card-del { opacity: 1; }
.note-card-del:hover { color: var(--red); }

/* Color picker */
.note-color-picker {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  margin-top: 6px;
}

.note-color-dot {
  width: 26px;
  height: 26px;
  border-radius: 50%;
  border: 2px solid transparent;
  cursor: pointer;
  transition: transform 0.15s, box-shadow 0.15s;
  padding: 0;
  flex-shrink: 0;
}
.note-color-dot:hover { transform: scale(1.2); }
.note-color-dot.selected {
  box-shadow: 0 0 0 2px var(--text), 0 0 0 4px rgba(255,255,255,0.2);
  transform: scale(1.1);
}

/* ══════════════════════════════════════════════
   FLOATING CHAT BUTTON & PANEL
══════════════════════════════════════════════ */
/* ── Chat Bubble FAB ── */
#chat-bubble {
  position: fixed;
  bottom: 28px;
  right: 28px;
  z-index: 500;
  width: 58px;
  height: 58px;
  border-radius: 50%;
  background: linear-gradient(135deg, #58a6ff 0%, #7c6bff 100%);
  color: #fff;
  display: none;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  box-shadow: 0 4px 24px rgba(88,166,255,0.45), 0 1px 4px rgba(0,0,0,0.3);
  transition: transform 0.2s cubic-bezier(.34,1.56,.64,1), box-shadow 0.2s;
  user-select: none;
}
#chat-bubble.visible { display: flex; }
#chat-bubble::before {
  content: '';
  position: absolute;
  inset: -3px;
  border-radius: 50%;
  background: linear-gradient(135deg, rgba(88,166,255,0.35), rgba(124,107,255,0.35));
  z-index: -1;
  animation: bubble-pulse 2.8s ease-in-out infinite;
}
@keyframes bubble-pulse {
  0%, 100% { transform: scale(1); opacity: 0.7; }
  50%       { transform: scale(1.18); opacity: 0; }
}
#chat-bubble:hover {
  transform: scale(1.12);
  box-shadow: 0 8px 32px rgba(88,166,255,0.6), 0 2px 8px rgba(0,0,0,0.3);
}
#chat-bubble:active { transform: scale(0.95); }

.chat-bubble-badge {
  position: absolute;
  top: 2px;
  right: 2px;
  min-width: 20px;
  height: 20px;
  background: linear-gradient(135deg, #f85149, #e03d3d);
  color: #fff;
  border-radius: 10px;
  padding: 0 5px;
  font-size: 11px;
  font-weight: 700;
  display: flex;
  align-items: center;
  justify-content: center;
  border: 2px solid var(--bg);
  pointer-events: none;
  animation: badge-pop 0.3s cubic-bezier(.34,1.56,.64,1);
}
@keyframes badge-pop {
  from { transform: scale(0); }
  to   { transform: scale(1); }
}

/* ── Chat Panel ── */
#chat-panel {
  position: fixed;
  bottom: 100px;
  right: 28px;
  z-index: 500;
  width: 348px;
  height: 500px;
  background: var(--bg2);
  border: 1px solid rgba(88,166,255,0.15);
  border-radius: 18px;
  box-shadow: 0 20px 60px rgba(0,0,0,0.6), 0 0 0 1px rgba(255,255,255,0.04);
  display: none;
  flex-direction: column;
  overflow: hidden;
  transform-origin: bottom right;
  transition: opacity 0.2s, transform 0.25s cubic-bezier(.34,1.56,.64,1);
  opacity: 0;
  transform: scale(0.88) translateY(12px);
}
#chat-panel.open {
  display: flex;
  animation: panel-open 0.25s cubic-bezier(.34,1.56,.64,1) forwards;
}
@keyframes panel-open {
  from { opacity: 0; transform: scale(0.88) translateY(12px); }
  to   { opacity: 1; transform: scale(1) translateY(0); }
}

.chat-panel-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 14px;
  background: linear-gradient(135deg, #1a2a4a 0%, #1a1f2e 100%);
  border-bottom: 1px solid rgba(88,166,255,0.12);
  flex-shrink: 0;
}

.chat-panel-title {
  font-size: 14px;
  font-weight: 700;
  color: var(--text);
  letter-spacing: 0.2px;
  display: flex;
  align-items: center;
  gap: 8px;
}
.chat-panel-title::before {
  content: '';
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: #3fb950;
  box-shadow: 0 0 6px #3fb950;
  flex-shrink: 0;
}

.chat-panel-close {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  background: rgba(255,255,255,0.06);
  border: 1px solid rgba(255,255,255,0.08);
  color: var(--text2);
  font-size: 16px;
  line-height: 1;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.15s, color 0.15s, transform 0.15s;
  padding: 0;
}
.chat-panel-close:hover {
  background: rgba(248,81,73,0.15);
  color: var(--red);
  transform: rotate(90deg);
}

.chat-back-btn {
  background: rgba(88,166,255,0.1);
  border: 1px solid rgba(88,166,255,0.2);
  color: var(--accent);
  font-size: 12px;
  font-weight: 500;
  cursor: pointer;
  padding: 4px 10px;
  border-radius: 20px;
  transition: background 0.15s;
  margin-right: 6px;
}
.chat-back-btn:hover { background: rgba(88,166,255,0.2); }

.dm-contacts-list {
  flex: 1;
  overflow-y: auto;
}

.chat-empty-contacts {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  height: 100%;
  padding: 32px 24px;
  text-align: center;
  color: var(--text2);
  gap: 8px;
}
.chat-empty-contacts p { font-size: 13px; line-height: 1.5; }

#dm-conv-view {
  display: none;
  flex-direction: column;
  flex: 1;
  min-height: 0;
}

/* ══════════════════════════════════════════════
   MOBILE HEADER
══════════════════════════════════════════════ */
.mobile-header {
  display: none;
  align-items: center;
  gap: 12px;
  padding: 0 16px;
  height: 54px;
  background: var(--bg2);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 100;
  flex-shrink: 0;
}
.mobile-header-title {
  flex: 1;
  font-size: 16px;
  font-weight: 600;
  color: var(--text);
}

.hamburger-btn {
  background: none;
  border: none;
  color: var(--text);
  cursor: pointer;
  padding: 8px 6px;
  border-radius: 8px;
  display: flex;
  flex-direction: column;
  gap: 5px;
  transition: background 0.15s;
}
.hamburger-btn:hover { background: var(--bg3); }
.hamburger-btn span {
  display: block;
  width: 20px;
  height: 2px;
  background: currentColor;
  border-radius: 2px;
}

/* ── Sidebar overlay backdrop ── */
#sidebar-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.55);
  z-index: 999;
  backdrop-filter: blur(2px);
}
#sidebar-overlay.visible { display: block; }

/* ══════════════════════════════════════════════
   DARK MODE TOGGLE (iPhone style)
══════════════════════════════════════════════ */
.darkmode-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 9px 12px;
  margin: 4px 12px 4px;
  background: var(--bg3);
  border-radius: var(--radius);
}
.darkmode-label {
  font-size: 13px;
  font-weight: 500;
  color: var(--text2);
}

.ios-toggle {
  position: relative;
  display: inline-block;
  width: 46px;
  height: 27px;
  flex-shrink: 0;
  cursor: pointer;
}
.ios-toggle input { opacity: 0; width: 0; height: 0; position: absolute; }
.ios-track {
  position: absolute;
  inset: 0;
  border-radius: 14px;
  background: var(--bg4);
  transition: background 0.22s;
  cursor: pointer;
}
.ios-toggle input:checked ~ .ios-track { background: #34c759; }
.ios-thumb {
  position: absolute;
  top: 3px; left: 3px;
  width: 21px; height: 21px;
  border-radius: 50%;
  background: #fff;
  box-shadow: 0 1px 5px rgba(0,0,0,0.3);
  transition: transform 0.22s cubic-bezier(.34,1.56,.64,1);
}
.ios-toggle input:checked ~ .ios-track .ios-thumb { transform: translateX(19px); }

/* ══════════════════════════════════════════════
   LIGHT MODE THEME
══════════════════════════════════════════════ */
body.light-mode {
  --bg: #f6f8fa;
  --bg2: #ffffff;
  --bg3: #f0f2f5;
  --bg4: #e1e4e8;
  --border: #d0d7de;
  --text: #24292f;
  --text2: #57606a;
  --text3: #8c959f;
}
body.light-mode #bg-canvas { opacity: 0.3; }
body.light-mode .user-card { box-shadow: 0 2px 8px rgba(0,0,0,0.08); }
body.light-mode #sidebar { box-shadow: 1px 0 0 var(--border); }

/* ══════════════════════════════════════════════
   RESPONSIVE — must be last to win cascade
══════════════════════════════════════════════ */
@media (max-width: 900px) {
  .stats-row { grid-template-columns: repeat(2, 1fr); }
  .dashboard-grid { grid-template-columns: 1fr; }
}

@media (max-width: 680px) {
  /* Sidebar becomes a slide-in drawer */
  #sidebar {
    position: fixed;
    top: 0; left: 0; bottom: 0;
    z-index: 1000;
    width: 260px;
    transform: translateX(-100%);
    transition: transform 0.28s cubic-bezier(0.4,0,0.2,1);
  }
  #sidebar.mobile-open {
    transform: translateX(0);
    box-shadow: 6px 0 32px rgba(0,0,0,0.45);
  }
  /* Show mobile header bar */
  .mobile-header { display: flex; }
  .section { padding: 16px; }
  .stats-row { grid-template-columns: repeat(2, 1fr); }
  .dm-layout { flex-direction: column; }
  .dm-contacts { width: 100%; max-height: 180px; border-right: none; border-bottom: 1px solid var(--border); }
}
