/* ── Root variables ────────────────────────────────────────── */
:root {
  --sidebar-w: 260px;
  --bg-body:   #0d1117;
  --bg-card:   #161b22;
  --bg-sidebar:#0d1117;
  --bg-hover:  #1c2129;
  --border:    #30363d;
  --text-muted:#8b949e;
  --accent:    #1f6feb;
}

/* ── Base ───────────────────────────────────────────────────── */
body {
  background: var(--bg-body);
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  font-size: 0.875rem;
}

#app {
  display: flex;
  height: 100vh;
  overflow: hidden;
}

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

/* ── Sidebar ────────────────────────────────────────────────── */
.sidebar {
  width: var(--sidebar-w);
  min-width: var(--sidebar-w);
  background: var(--bg-sidebar);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  height: 100vh;
  position: sticky;
  top: 0;
  overflow: hidden;
}

.sidebar-brand {
  padding: 1.25rem 1.5rem;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  gap: 0.75rem;
}

.sidebar-brand .brand-icon {
  width: 36px;
  height: 36px;
  background: var(--accent);
  border-radius: 10px;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  box-shadow: 0 4px 12px rgba(31,111,235,.3);
}

.sidebar-nav {
  flex: 1;
  padding: 0.75rem;
  overflow-y: auto;
}

.sidebar-nav .nav-link {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  color: var(--text-muted);
  padding: 0.6rem 0.75rem;
  border-radius: 10px;
  transition: all .15s;
  font-weight: 500;
  margin-bottom: 2px;
  text-decoration: none;
  cursor: pointer;
}

.sidebar-nav .nav-link:hover {
  color: #e6edf3;
  background: var(--bg-hover);
}

.sidebar-nav .nav-link.active {
  color: #fff;
  background: var(--accent);
  box-shadow: 0 4px 12px rgba(31,111,235,.25);
}

.sidebar-nav .nav-link i { font-size: 1rem; flex-shrink: 0; }

.sidebar-user {
  padding: 0.75rem;
  border-top: 1px solid var(--border);
}

.sidebar-user .user-card {
  background: var(--bg-hover);
  border-radius: 10px;
  padding: 0.6rem 0.75rem;
  display: flex;
  align-items: center;
  gap: 0.75rem;
  margin-bottom: 4px;
}

.user-avatar {
  width: 32px;
  height: 32px;
  border-radius: 8px;
  background: rgba(31,111,235,.2);
  border: 1px solid rgba(31,111,235,.3);
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  font-weight: 700;
  font-size: 0.75rem;
  color: #79c0ff;
}

.user-avatar.lg {
  width: 48px;
  height: 48px;
  border-radius: 12px;
  font-size: 1.1rem;
}

/* ── Layout ─────────────────────────────────────────────────── */
.app-layout {
  display: flex;
  height: 100vh;
  overflow: hidden;
}

.app-main {
  flex: 1;
  overflow-y: auto;
  padding: 2rem;
}

/* ── Cards ──────────────────────────────────────────────────── */
.crm-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 14px;
  overflow: hidden;
}

.crm-card .card-header {
  background: transparent;
  border-bottom: 1px solid var(--border);
  padding: 1rem 1.25rem;
}

.crm-card .card-body { padding: 1.25rem; }

/* ── Stat cards ─────────────────────────────────────────────── */
.stat-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 1.25rem;
  transition: transform .15s, border-color .15s;
}

.stat-card:hover { transform: translateY(-2px); border-color: var(--accent); }

.stat-icon {
  width: 44px;
  height: 44px;
  border-radius: 11px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.2rem;
}

/* ── Tables ─────────────────────────────────────────────────── */
.crm-table { color: #e6edf3; }
.crm-table thead th {
  background: var(--bg-hover);
  border-color: var(--border);
  color: var(--text-muted);
  font-weight: 600;
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: .05em;
  padding: 0.75rem 1rem;
}
.crm-table tbody td {
  border-color: var(--border);
  padding: 0.85rem 1rem;
  vertical-align: middle;
}
.crm-table tbody tr { transition: background .1s; }
.crm-table tbody tr:hover { background: var(--bg-hover); cursor: pointer; }

/* ── Forms ──────────────────────────────────────────────────── */
.form-control, .form-select {
  background: var(--bg-hover) !important;
  border-color: var(--border) !important;
  color: #e6edf3 !important;
  border-radius: 10px;
}
.form-control::placeholder { color: var(--text-muted); }
.form-control:focus, .form-select:focus {
  box-shadow: 0 0 0 3px rgba(31,111,235,.25) !important;
  border-color: var(--accent) !important;
}

/* ── Modals ─────────────────────────────────────────────────── */
.modal-content {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 16px;
}
.modal-header {
  border-bottom: 1px solid var(--border);
  padding: 1.1rem 1.5rem;
}
.modal-footer { border-top: 1px solid var(--border); }

/* ── Buttons ────────────────────────────────────────────────── */
.btn { border-radius: 10px; font-weight: 500; }
.btn-primary { background: var(--accent); border-color: var(--accent); }
.btn-primary:hover { background: #388bfd; border-color: #388bfd; }
.btn-sm { font-size: 0.8rem; padding: 0.3rem 0.65rem; }

/* ── Badges ─────────────────────────────────────────────────── */
.badge-unread {
  background: #da3633;
  color: #fff;
  font-size: 0.65rem;
  font-weight: 700;
  border-radius: 20px;
  padding: 2px 6px;
  min-width: 18px;
  text-align: center;
}

/* ── Login page ─────────────────────────────────────────────── */
.login-wrap {
  flex: 1;
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--bg-body);
}
.login-box {
  width: 100%;
  max-width: 420px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 18px;
  padding: 2.5rem;
}

/* ── Notes ──────────────────────────────────────────────────── */
.note-bubble {
  background: var(--bg-hover);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 0.85rem 1rem;
  margin-bottom: 0.5rem;
}
.note-bubble.own {
  background: rgba(31,111,235,.08);
  border-color: rgba(31,111,235,.2);
}
.note-area {
  max-height: 420px;
  overflow-y: auto;
  padding: 1rem;
}

/* ── Alert/message card ─────────────────────────────────────── */
.msg-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 1.1rem 1.25rem;
  margin-bottom: 0.75rem;
  transition: border-color .15s;
}
.msg-card.unread { border-color: rgba(31,111,235,.5); background: rgba(31,111,235,.04); }

/* ── Misc ───────────────────────────────────────────────────── */
.page-title { font-size: 1.4rem; font-weight: 700; color: #e6edf3; margin-bottom: 0; }
.page-sub   { color: var(--text-muted); font-size: 0.8rem; }
.section-label { font-size: 0.7rem; font-weight: 600; text-transform: uppercase; letter-spacing:.06em; color: var(--text-muted); }
.empty-state { text-align: center; padding: 3.5rem 1rem; color: var(--text-muted); }
.empty-state i { font-size: 2.5rem; opacity: .3; display: block; margin-bottom: .75rem; }
.cursor-pointer { cursor: pointer; }
.search-box { position: relative; }
.search-box i { position: absolute; left: 12px; top: 50%; transform: translateY(-50%); color: var(--text-muted); pointer-events: none; }
.search-box .form-control { padding-left: 2.25rem; }

/* ── Staff copy protection ──────────────────────────────────── */
.no-select,
.no-select * { user-select: none; -webkit-user-select: none; }

/* ── Language Picker ────────────────────────────────────────── */
.lang-picker { display: flex; gap: 4px; margin-bottom: 4px; }
.lang-btn { flex: 1; background: var(--bg-hover); border: 1px solid var(--border); border-radius: 8px; color: var(--text-muted); font-size: .72rem; font-weight: 600; padding: 5px 0; cursor: pointer; transition: all .15s; letter-spacing: .03em; }
.lang-btn:hover { color: #e6edf3; border-color: #484f58; }
.lang-btn.active { background: rgba(31,111,235,.2); border-color: var(--accent); color: #79c0ff; }

/* ── Personal Notes ─────────────────────────────────────────── */
.notes-main { padding: 1.5rem; overflow: hidden; display: flex; flex-direction: column; height: 100%; }
.notes-layout { display: grid; grid-template-columns: 280px 1fr; gap: 1.25rem; height: calc(100vh - 3rem); }
.notes-list-panel { display: flex; flex-direction: column; min-height: 0; }
.notes-list-card { flex: 1; overflow-y: auto; }
.notes-editor-panel { display: flex; flex-direction: column; min-height: 0; }
.notes-editor-card { flex: 1; display: flex; flex-direction: column; overflow: hidden; }

.note-list-item { padding: .875rem 1rem; cursor: pointer; border-bottom: 1px solid var(--border); transition: background .12s; }
.note-list-item:last-child { border-bottom: none; }
.note-list-item:hover { background: rgba(255,255,255,.04); }
.note-list-item.active { background: rgba(31,111,235,.1); border-left: 3px solid var(--accent); padding-left: calc(1rem - 3px); }
.note-item-title { font-weight: 600; color: #e6edf3; font-size: .875rem; margin-bottom: .2rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.note-item-preview { font-size: .76rem; color: var(--text-muted); margin-bottom: .25rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.note-item-date { font-size: .7rem; color: #484f58; }
.notes-list-empty { text-align: center; padding: 2.5rem 1rem; color: var(--text-muted); font-size: .82rem; line-height: 1.7; }
.notes-list-empty i { font-size: 1.75rem; opacity: .25; display: block; margin-bottom: .5rem; }

.notes-editor-header { display: flex; align-items: center; gap: 1rem; padding: 1rem 1.25rem; border-bottom: 1px solid var(--border); }
.notes-title-input { flex: 1; background: transparent; border: none; outline: none; color: #e6edf3; font-size: 1.05rem; font-weight: 700; padding: 0; box-shadow: none !important; }
.notes-title-input::placeholder { color: #484f58; }
.notes-editor-meta { padding: .4rem 1.25rem; font-size: .72rem; color: #484f58; border-bottom: 1px solid var(--border); }
.notes-textarea { flex: 1; background: transparent; border: none; outline: none; resize: none; color: #e6edf3; font-size: .9rem; line-height: 1.8; padding: 1.25rem; box-shadow: none !important; overflow-y: auto; }
.notes-textarea::placeholder { color: #484f58; }
.notes-save-status { font-size: .72rem; color: #484f58; min-width: 70px; text-align: right; }
.notes-save-status.saving { color: var(--text-muted); }
.notes-save-status.saved { color: #3fb950; }
.notes-empty-editor { display: flex; flex-direction: column; align-items: center; justify-content: center; flex: 1; text-align: center; padding: 2rem; color: var(--text-muted); }
.notes-empty-icon { width: 64px; height: 64px; border-radius: 16px; background: rgba(31,111,235,.1); display: flex; align-items: center; justify-content: center; margin-bottom: 1rem; }
.notes-empty-icon i { font-size: 1.75rem; color: var(--accent); opacity: .7; }

@media (max-width: 768px) {
  .notes-layout { grid-template-columns: 1fr; height: auto; }
  .notes-editor-panel { min-height: 500px; }
}
.rounded-tag { background: var(--bg-hover); border: 1px solid var(--border); border-radius: 8px; padding: 2px 8px; font-size: 0.75rem; color: var(--text-muted); display: inline-flex; align-items: center; gap: 4px; }

/* ── Chat Layout ────────────────────────────────────────────── */
.chat-main-wrap { display: flex; height: 100vh; overflow: hidden; }
.chat-list-col { width: 280px; flex-shrink: 0; border-right: 1px solid var(--border); overflow-y: auto; display: flex; flex-direction: column; background: var(--surface); }
.chat-room-col { flex: 1; display: flex; flex-direction: column; overflow: hidden; min-width: 0; }
.chat-list-header { padding: 1.1rem 1.25rem; border-bottom: 1px solid var(--border); background: var(--surface); position: sticky; top: 0; z-index: 1; }
.chat-list-header .page-title { font-size: 1rem; }

/* Staff items in chat list */
.chat-staff-item { display: flex; align-items: center; gap: .75rem; padding: .875rem 1.25rem; cursor: pointer; border-bottom: 1px solid var(--border); transition: background .12s; }
.chat-staff-item:hover { background: var(--surface-2); }
.chat-staff-item.active { background: rgba(31,111,235,.12); border-left: 3px solid var(--accent); }
.chat-staff-item .ci-name { font-weight: 600; font-size: .85rem; color: #e6edf3; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.chat-staff-item .ci-preview { font-size: .74rem; color: var(--text-muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 160px; }
.chat-staff-item .ci-time { font-size: .68rem; color: var(--text-muted); white-space: nowrap; flex-shrink: 0; }

/* Chat room header */
.chat-header { padding: .875rem 1.25rem; border-bottom: 1px solid var(--border); display: flex; align-items: center; gap: .75rem; background: var(--surface); flex-shrink: 0; }

/* Message area */
.chat-msgs { flex: 1; overflow-y: auto; padding: 1rem 1.25rem; display: flex; flex-direction: column; gap: .3rem; }

/* Message bubbles */
.cmsg { display: flex; flex-direction: column; max-width: 72%; }
.cmsg.sent { align-self: flex-end; align-items: flex-end; }
.cmsg.recv { align-self: flex-start; align-items: flex-start; }
.cmsg .bubble { padding: .5rem .8rem; border-radius: 14px; font-size: .875rem; line-height: 1.5; word-break: break-word; }
.cmsg.sent  .bubble { background: #1f6feb; color: #fff; border-bottom-right-radius: 4px; }
.cmsg.recv  .bubble { background: var(--surface-2); color: #e6edf3; border-bottom-left-radius: 4px; }
.cmsg .bubble img { max-width: 200px; max-height: 200px; border-radius: 8px; cursor: pointer; display: block; object-fit: cover; }
.cmsg .meta { font-size: .68rem; color: var(--text-muted); margin-top: .2rem; padding: 0 .2rem; }

/* Date separator */
.chat-date-sep { text-align: center; font-size: .7rem; color: var(--text-muted); padding: .6rem 0; position: relative; }
.chat-date-sep::before { content: ''; position: absolute; top: 50%; left: 0; right: 0; height: 1px; background: var(--border); z-index: 0; }
.chat-date-sep span, .chat-date-sep { background: transparent; position: relative; z-index: 1; padding: 0 .5rem; display: inline-block; }

/* Image preview before sending */
.chat-img-pre { display: flex; align-items: center; gap: .5rem; padding: .5rem 1rem; border-top: 1px solid var(--border); background: var(--surface-2); }

/* Send bar */
.chat-bar { padding: .75rem 1rem; border-top: 1px solid var(--border); display: flex; align-items: center; gap: .5rem; background: var(--surface); flex-shrink: 0; }
.chat-img-lbl { cursor: pointer; padding: .375rem .625rem; }

/* Image modal */
.chat-img-modal { position: fixed; inset: 0; background: rgba(0,0,0,.88); display: flex; align-items: center; justify-content: center; z-index: 9999; cursor: zoom-out; }
.chat-img-modal img { max-width: 90vw; max-height: 90vh; border-radius: 10px; box-shadow: 0 20px 60px rgba(0,0,0,.5); }

/* Empty state for chat room */
.chat-empty-room { flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center; color: var(--text-muted); gap: .5rem; }
.chat-empty-room i { font-size: 3rem; opacity: .18; }

@media (max-width: 768px) {
  .chat-list-col { width: 100%; }
  .chat-room-col { display: none; }
  .chat-room-col.open { display: flex; position: fixed; inset: 0; z-index: 100; background: var(--bg); }
}
