:root {
  --ink: #1e1730;
  --muted: #756f80;
  --line: #e8e3ed;
  --surface: #ffffff;
  --surface-soft: #f8f6fa;
  --plum: #4d2f78;
  --plum-dark: #34204f;
  --lilac: #eee6f8;
  --gold: #d9a441;
  --green: #1c7b57;
  --green-soft: #e7f5ef;
  --red: #b0444a;
  --red-soft: #faecee;
  --shadow: 0 20px 60px rgba(38, 24, 57, 0.12);
}

* { box-sizing: border-box; }
html { min-width: 320px; background: #f5f2f7; }
body {
  margin: 0;
  min-height: 100vh;
  color: var(--ink);
  background: #f5f2f7;
  font-family: "DM Sans", system-ui, sans-serif;
  -webkit-font-smoothing: antialiased;
}
button, input, select { font: inherit; }
button, a { -webkit-tap-highlight-color: transparent; }
button:focus-visible, a:focus-visible, input:focus-visible, select:focus-visible, [tabindex]:focus-visible {
  outline: 3px solid rgba(102, 70, 150, 0.3);
  outline-offset: 2px;
}
[hidden] { display: none !important; }

.ambient { position: fixed; pointer-events: none; border-radius: 50%; filter: blur(1px); z-index: 0; }
.ambient-one { width: 460px; height: 460px; left: -210px; top: -170px; background: radial-gradient(circle, rgba(189, 161, 224, .28), transparent 67%); }
.ambient-two { width: 520px; height: 520px; right: -260px; bottom: -250px; background: radial-gradient(circle, rgba(232, 190, 111, .18), transparent 66%); }

.login-shell { position: relative; z-index: 1; min-height: 100vh; display: grid; place-items: center; padding: 32px 20px; }
.login-card {
  width: min(440px, 100%);
  padding: 46px 44px 36px;
  border: 1px solid rgba(255,255,255,.8);
  border-radius: 24px;
  background: rgba(255,255,255,.92);
  box-shadow: var(--shadow);
  backdrop-filter: blur(18px);
}
.brand-mark, .mini-mark {
  display: grid;
  place-items: center;
  color: #fff;
  background: linear-gradient(145deg, #65468f, #35204f);
  box-shadow: 0 10px 26px rgba(77, 47, 120, .24);
}
.brand-mark { width: 52px; height: 52px; border-radius: 15px; margin-bottom: 28px; font-size: 24px; }
.mini-mark { width: 34px; height: 34px; border-radius: 10px; font-size: 17px; flex: 0 0 auto; }
.eyebrow { margin: 0 0 8px; color: var(--plum); font-weight: 700; font-size: 13px; text-transform: uppercase; letter-spacing: .15em; }
h1, h2, h3, p { margin-top: 0; }
h1, h2, h3 { font-family: Manrope, system-ui, sans-serif; }
.login-card h1 { margin-bottom: 10px; font-size: 32px; line-height: 1.15; letter-spacing: -.04em; }
.login-copy { margin-bottom: 30px; color: var(--muted); line-height: 1.55; }
label { display: block; margin: 18px 0 8px; color: #46404f; font-size: 13px; font-weight: 700; }
input, select {
  width: 100%;
  min-height: 46px;
  border: 1px solid #dcd6e2;
  border-radius: 11px;
  color: var(--ink);
  background: #fff;
  padding: 0 14px;
  transition: border-color .18s, box-shadow .18s;
}
input:focus, select:focus { border-color: #8e70b3; box-shadow: 0 0 0 4px rgba(100,70,143,.09); outline: none; }
input::placeholder { color: #aaa4b0; }
.password-wrap { position: relative; }
.password-wrap input { padding-right: 64px; }
.text-button { position: absolute; right: 6px; top: 6px; height: 34px; border: 0; background: transparent; color: var(--plum); font-size: 12px; font-weight: 700; cursor: pointer; }
.form-error { margin: 12px 0 0; color: var(--red); font-size: 13px; }
.primary-button, .secondary-button, .danger-button, .logout-button, .icon-button, .filter-button, .pagination-button {
  border: 0;
  border-radius: 10px;
  cursor: pointer;
  font-weight: 700;
  transition: transform .16s, box-shadow .16s, opacity .16s, background .16s;
}
.primary-button:hover, .danger-button:hover { transform: translateY(-1px); }
.primary-button { display: inline-flex; align-items: center; justify-content: center; gap: 10px; min-height: 47px; color: #fff; background: linear-gradient(135deg, #5c3989, #3c2559); box-shadow: 0 12px 24px rgba(71,43,105,.2); }
.full-button { width: 100%; margin-top: 24px; }
button:disabled { cursor: not-allowed; opacity: .52; transform: none !important; box-shadow: none !important; }
.secure-note { display: flex; justify-content: center; gap: 8px; margin: 24px 0 0; color: #8a8490; font-size: 12px; }
.secure-note span { color: var(--green); font-size: 8px; padding-top: 4px; }

.app-shell { position: relative; z-index: 1; min-height: 100vh; display: grid; grid-template-columns: 238px minmax(0, 1fr); }
.sidebar { position: sticky; top: 0; height: 100vh; display: flex; flex-direction: column; padding: 28px 18px 20px; color: #eae1f2; background: #21172f; }
.sidebar-brand { display: flex; align-items: center; gap: 11px; padding: 0 8px 30px; color: #fff; font-family: Manrope, sans-serif; font-size: 17px; font-weight: 800; }
.sidebar nav { flex: 1; }
.nav-item { display: flex; align-items: center; gap: 12px; min-height: 46px; padding: 0 14px; border-radius: 10px; color: #bdb2c9; text-decoration: none; font-size: 14px; font-weight: 600; }
.nav-item.active { color: #fff; background: rgba(255,255,255,.1); box-shadow: inset 3px 0 #c6a0e8; }
.nav-item span:first-child { color: #c6a0e8; }
.sidebar-footer { padding-top: 18px; border-top: 1px solid rgba(255,255,255,.1); }
.admin-chip { display: flex; align-items: center; gap: 10px; padding: 0 4px 14px; }
.avatar { width: 36px; height: 36px; display: grid; place-items: center; flex: 0 0 auto; border-radius: 50%; color: #36224d; background: #dec8ef; font-weight: 800; }
.admin-chip strong, .admin-chip small { display: block; }
.admin-chip strong { color: #fff; font-size: 13px; }
.admin-chip small { margin-top: 2px; color: #998da6; font-size: 11px; }
.logout-button { width: 100%; min-height: 38px; color: #bdb2c9; background: transparent; text-align: left; padding: 0 8px; font-size: 12px; }
.logout-button:hover { color: #fff; background: rgba(255,255,255,.06); }
.main-column { min-width: 0; }
.topbar { height: 64px; display: flex; align-items: center; justify-content: space-between; padding: 0 32px; border-bottom: 1px solid var(--line); background: rgba(255,255,255,.82); backdrop-filter: blur(12px); }
.topbar > div { display: flex; align-items: center; gap: 8px; color: #6f6878; font-size: 12px; font-weight: 600; }
.online-dot { width: 7px; height: 7px; border-radius: 50%; background: #31a775; box-shadow: 0 0 0 4px #e6f5ef; }
.icon-button { width: 36px; height: 36px; color: #615968; background: transparent; font-size: 20px; }
.icon-button:hover { background: #f0ecf3; }
.page-content { padding: 34px 36px 48px; }
.page-heading { display: flex; align-items: flex-start; justify-content: space-between; gap: 20px; margin-bottom: 28px; }
.page-heading h1 { margin-bottom: 7px; font-size: 28px; letter-spacing: -.035em; }
.page-heading p { margin: 0; color: var(--muted); font-size: 14px; }
.breadcrumb { display: inline-flex; align-items: center; gap: 8px; margin-bottom: 14px; color: var(--plum); text-decoration: none; font-size: 13px; font-weight: 700; }

.stats-grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 16px; margin-bottom: 20px; }
.stat-card { padding: 19px 20px; border: 1px solid var(--line); border-radius: 14px; background: var(--surface); box-shadow: 0 5px 18px rgba(35,22,52,.035); }
.stat-card small { display: block; margin-bottom: 8px; color: var(--muted); font-weight: 600; }
.stat-card strong { font-family: Manrope, sans-serif; font-size: 27px; letter-spacing: -.03em; }
.stat-card .stat-accent { color: var(--green); }
.stat-card .stat-muted { color: var(--red); }

.panel { overflow: hidden; border: 1px solid var(--line); border-radius: 15px; background: var(--surface); box-shadow: 0 7px 24px rgba(35,22,52,.04); }
.table-toolbar { display: grid; grid-template-columns: minmax(220px, 1fr) 170px; gap: 12px; padding: 17px 18px; border-bottom: 1px solid var(--line); }
.search-wrap { position: relative; max-width: 430px; }
.search-wrap::before { content: "⌕"; position: absolute; left: 14px; top: 9px; color: #938b9b; font-size: 22px; }
.search-wrap input { padding-left: 42px; min-height: 42px; }
.table-scroll { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: 13px; }
th { height: 45px; padding: 0 18px; color: #837b89; background: #faf9fb; font-size: 11px; text-align: left; text-transform: uppercase; letter-spacing: .07em; white-space: nowrap; }
td { padding: 15px 18px; border-top: 1px solid #f0edf2; vertical-align: middle; }
tbody tr { cursor: pointer; transition: background .15s; }
tbody tr:hover { background: #fbf9fd; }
.user-cell { display: flex; align-items: center; gap: 11px; min-width: 180px; }
.user-cell .avatar { width: 35px; height: 35px; color: var(--plum); background: var(--lilac); font-size: 12px; }
.user-cell strong, .user-cell small { display: block; }
.user-cell strong { margin-bottom: 2px; font-size: 13px; }
.user-cell small, .muted-cell { color: var(--muted); }
.user-id { max-width: 148px; overflow: hidden; color: #6f6878; font-family: ui-monospace, SFMono-Regular, Menlo, monospace; text-overflow: ellipsis; white-space: nowrap; }
.status-pill { display: inline-flex; align-items: center; gap: 6px; padding: 5px 9px; border-radius: 999px; font-size: 11px; font-weight: 700; text-transform: capitalize; }
.status-pill::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: currentColor; }
.status-active { color: var(--green); background: var(--green-soft); }
.status-revoked { color: var(--red); background: var(--red-soft); }
.revoke-button { min-height: 32px; padding: 0 11px; border: 1px solid #ecd0d3; border-radius: 8px; color: var(--red); background: #fff; font-size: 11px; font-weight: 700; cursor: pointer; }
.revoke-button:hover { background: var(--red-soft); }
.revoked-label { color: #9b939f; font-size: 11px; font-weight: 600; }
.pagination { display: flex; justify-content: space-between; align-items: center; padding: 14px 18px; border-top: 1px solid var(--line); color: var(--muted); font-size: 12px; }
.pagination-actions { display: flex; gap: 7px; }
.pagination-button { min-height: 33px; padding: 0 12px; color: #564e5d; background: #f3f0f5; font-size: 12px; }

.chat-shell { height: calc(100vh - 188px); min-height: 520px; display: grid; grid-template-columns: 340px minmax(0, 1fr); overflow: hidden; border: 1px solid var(--line); border-radius: 16px; background: #fff; box-shadow: 0 8px 26px rgba(35,22,52,.05); }
.chat-list-panel { min-width: 0; border-right: 1px solid var(--line); background: #fcfbfd; }
.chat-list-heading { padding: 18px 18px 14px; border-bottom: 1px solid var(--line); }
.chat-list-heading strong { display: block; margin-bottom: 3px; font-family: Manrope, sans-serif; font-size: 14px; }
.chat-list-heading span { color: var(--muted); font-size: 11px; }
.chat-list { height: calc(100% - 67px); overflow-y: auto; }
.chat-item { width: 100%; display: block; padding: 15px 17px; border: 0; border-bottom: 1px solid #f0edf2; color: inherit; background: transparent; text-align: left; cursor: pointer; }
.chat-item:hover { background: #f7f3fa; }
.chat-item.active { background: #efe8f6; box-shadow: inset 3px 0 var(--plum); }
.chat-item-top { display: flex; justify-content: space-between; gap: 10px; }
.chat-item strong { display: block; overflow: hidden; font-size: 13px; text-overflow: ellipsis; white-space: nowrap; }
.chat-item time { flex: 0 0 auto; color: #9a929f; font-size: 10px; }
.chat-item p { margin: 7px 0 8px; overflow: hidden; color: var(--muted); font-size: 12px; line-height: 1.4; text-overflow: ellipsis; white-space: nowrap; }
.chat-meta { display: flex; align-items: center; justify-content: space-between; color: #938b9b; font-size: 10px; }
.conversation { min-width: 0; display: flex; flex-direction: column; background: #fff; }
.conversation-header { min-height: 67px; display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 12px 20px; border-bottom: 1px solid var(--line); }
.conversation-header h2 { margin: 0 0 2px; font-size: 15px; }
.conversation-header p { margin: 0; color: var(--muted); font-size: 11px; }
.conversation-status { color: var(--green); font-size: 11px; font-weight: 700; text-transform: capitalize; }
.messages { flex: 1; overflow-y: auto; padding: 24px clamp(20px, 4vw, 52px); background: linear-gradient(180deg, #fdfcfe, #f9f7fb); }
.message-row { display: flex; align-items: flex-end; gap: 10px; margin-bottom: 20px; }
.message-row.user { flex-direction: row-reverse; }
.message-avatar { width: 30px; height: 30px; display: grid; place-items: center; flex: 0 0 auto; border-radius: 50%; color: #fff; background: #62448a; font-size: 10px; font-weight: 800; }
.message-row.user .message-avatar { color: #3e2a55; background: #dfd2eb; }
.message-stack { max-width: min(680px, 78%); }
.message-author { margin: 0 3px 5px; color: #89818f; font-size: 10px; font-weight: 700; }
.message-row.user .message-author { text-align: right; }
.message-bubble { padding: 12px 15px; border: 1px solid #e7e1eb; border-radius: 6px 15px 15px 15px; color: #3b3540; background: #fff; box-shadow: 0 3px 12px rgba(35,22,52,.035); font-size: 13px; line-height: 1.6; white-space: pre-wrap; overflow-wrap: anywhere; }
.message-row.user .message-bubble { border-color: #4c3070; border-radius: 15px 6px 15px 15px; color: #fff; background: #4c3070; }
.message-time { display: block; margin: 5px 4px 0; color: #9b939f; font-size: 10px; }
.message-row.user .message-time { text-align: right; }
.empty-state { min-height: 260px; display: grid; place-items: center; padding: 30px; color: var(--muted); text-align: center; }
.empty-state > div { max-width: 340px; }
.empty-symbol { width: 46px; height: 46px; display: grid; place-items: center; margin: 0 auto 14px; border-radius: 14px; color: var(--plum); background: var(--lilac); font-size: 20px; }
.empty-state h3 { margin-bottom: 7px; color: var(--ink); font-size: 15px; }
.empty-state p { margin: 0; font-size: 12px; line-height: 1.5; }
.loading-lines { padding: 20px; }
.loading-line { height: 54px; margin-bottom: 10px; border-radius: 10px; background: linear-gradient(90deg, #f1edf4 25%, #faf8fb 50%, #f1edf4 75%); background-size: 200% 100%; animation: shimmer 1.3s infinite; }
@keyframes shimmer { to { background-position: -200% 0; } }

.modal-backdrop { position: fixed; z-index: 50; inset: 0; display: grid; place-items: center; padding: 20px; background: rgba(23,14,34,.56); backdrop-filter: blur(4px); }
.modal-card { width: min(430px, 100%); padding: 30px; border-radius: 18px; background: #fff; box-shadow: var(--shadow); }
.warning-mark { width: 42px; height: 42px; display: grid; place-items: center; margin-bottom: 18px; border-radius: 12px; color: var(--red); background: var(--red-soft); font-weight: 800; }
.modal-card h2 { margin-bottom: 8px; font-size: 20px; }
.modal-card p { margin-bottom: 24px; color: var(--muted); font-size: 13px; line-height: 1.55; }
.modal-actions { display: flex; justify-content: flex-end; gap: 10px; }
.secondary-button, .danger-button { min-height: 41px; padding: 0 15px; }
.secondary-button { color: #554e5c; background: #f0edf3; }
.danger-button { color: #fff; background: var(--red); }
.toast { position: fixed; z-index: 60; right: 24px; bottom: 24px; max-width: min(380px, calc(100vw - 48px)); padding: 13px 16px; border-radius: 10px; color: #fff; background: #282030; box-shadow: 0 12px 32px rgba(26,17,36,.25); font-size: 13px; }
.toast.error { background: #922f37; }
.mobile-only { display: none; }

@media (max-width: 920px) {
  .app-shell { grid-template-columns: 74px minmax(0, 1fr); }
  .sidebar { padding-inline: 12px; }
  .sidebar-brand { justify-content: center; padding-inline: 0; }
  .sidebar-brand > span:last-child, .nav-item > span:last-child, .admin-chip > span:last-child, .logout-button { display: none; }
  .nav-item { justify-content: center; padding: 0; }
  .admin-chip { justify-content: center; }
  .page-content { padding-inline: 24px; }
  .chat-shell { grid-template-columns: 290px minmax(0, 1fr); }
}

@media (max-width: 700px) {
  .app-shell { display: block; }
  .sidebar { position: fixed; z-index: 20; left: 0; transform: translateX(-100%); width: 238px; transition: transform .2s; }
  .sidebar.open { transform: translateX(0); box-shadow: 20px 0 50px rgba(20,12,29,.28); }
  .sidebar-brand { justify-content: flex-start; }
  .sidebar-brand > span:last-child, .nav-item > span:last-child, .admin-chip > span:last-child, .logout-button { display: initial; }
  .nav-item { justify-content: flex-start; padding: 0 14px; }
  .admin-chip { justify-content: flex-start; }
  .logout-button { display: block; }
  .mobile-only { display: inline-grid; place-items: center; }
  .topbar { padding: 0 18px; }
  .topbar > div { margin-right: auto; margin-left: 10px; }
  .page-content { padding: 25px 16px 36px; }
  .page-heading { margin-bottom: 20px; }
  .page-heading h1 { font-size: 24px; }
  .stats-grid { grid-template-columns: 1fr; gap: 10px; }
  .stat-card { display: flex; align-items: center; justify-content: space-between; padding: 14px 16px; }
  .stat-card small { margin: 0; }
  .stat-card strong { font-size: 22px; }
  .table-toolbar { grid-template-columns: 1fr; }
  th, td { padding-inline: 13px; }
  .chat-shell { height: auto; min-height: calc(100vh - 170px); grid-template-columns: 1fr; }
  .chat-list-panel { border-right: 0; }
  .chat-list { max-height: calc(100vh - 250px); }
  .conversation { min-height: calc(100vh - 190px); }
  .chat-shell.has-selection .chat-list-panel { display: none; }
  .chat-shell:not(.has-selection) .conversation { display: none; }
  .mobile-chat-back { display: inline-grid; }
  .messages { min-height: 420px; padding-inline: 15px; }
  .message-stack { max-width: 84%; }
}

@media (max-width: 480px) {
  .login-card { padding: 36px 24px 28px; border-radius: 19px; }
  .login-card h1 { font-size: 28px; }
  .table-toolbar { padding: 14px; }
  .pagination { align-items: flex-start; gap: 12px; }
  .modal-actions { flex-direction: column-reverse; }
  .modal-actions button { width: 100%; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { scroll-behavior: auto !important; animation-duration: .01ms !important; animation-iteration-count: 1 !important; transition-duration: .01ms !important; }
}
