*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --bg:      #0e0e10;
  --surface: #18181b;
  --card:    #1f1f23;
  --border:  #2a2a2d;
  --purple:  #9147ff;
  --purple2: #772ce8;
  --green:   #1db954;
  --red:     #e91916;
  --yellow:  #f5a623;
  --text:    #efeff1;
  --muted:   #adadb8;
  --chat:    #1db954;
  --chit:    #e91916;
}

html, body { height: 100%; overflow: hidden; }

body { background: var(--bg); color: var(--text); font-family: 'Inter', system-ui, sans-serif; font-size: 14px; }

/* Layout – everything locked to viewport height */
#layout { display: flex; height: 100vh; overflow: hidden; }

nav {
  width: 220px; height: 100vh; background: var(--surface);
  border-right: 1px solid var(--border); display: flex; flex-direction: column;
  padding: 16px 0; flex-shrink: 0; overflow: hidden; /* nav never scrolls */
}

nav .logo {
  padding: 8px 20px 20px;
  font-size: 18px; font-weight: 700; color: var(--purple);
  border-bottom: 1px solid var(--border); margin-bottom: 12px; flex-shrink: 0;
}
nav .logo span { color: var(--text); }

nav button {
  display: flex; align-items: center; gap: 10px;
  width: 100%; padding: 10px 20px; background: none; border: none;
  color: var(--muted); cursor: pointer; font-size: 14px; text-align: left;
  transition: all .15s; border-left: 3px solid transparent; flex-shrink: 0;
}
nav button:hover { background: var(--card); color: var(--text); }
nav button.active { background: var(--card); color: var(--purple); border-left-color: var(--purple); }
nav button svg { width: 18px; height: 18px; flex-shrink: 0; }

#status-dot {
  margin: auto 20px 12px; padding: 8px 12px; border-radius: 8px;
  background: var(--card); font-size: 12px; color: var(--muted);
  display: flex; align-items: center; gap: 8px; flex-shrink: 0;
}
#status-dot .dot {
  width: 8px; height: 8px; border-radius: 50%; background: var(--red); flex-shrink: 0;
}
#status-dot.online .dot { background: var(--green); }
#status-dot.online .label { color: var(--green); }

main {
  flex: 1; min-width: 0; /* prevent flex overflow */
  padding: 28px;
  display: flex; flex-direction: column;
  overflow: hidden; /* main itself doesn't scroll */
  height: 100vh;
}

/* Pages – fill remaining height, column layout so table can grow */
.page { display: none; }
.page.active {
  display: flex; flex-direction: column;
  flex: 1; min-height: 0; overflow: hidden;
}

h1 { font-size: 22px; font-weight: 700; margin-bottom: 24px; flex-shrink: 0; }
h2 { font-size: 16px; font-weight: 600; margin-bottom: 14px; color: var(--muted); }

/* Stat cards */
.stats-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); gap: 14px; margin-bottom: 28px; flex-shrink: 0; }

.stat-card {
  background: var(--card); border: 1px solid var(--border); border-radius: 12px;
  padding: 18px; display: flex; flex-direction: column; gap: 6px;
}
.stat-card .label { font-size: 12px; color: var(--muted); text-transform: uppercase; letter-spacing: .5px; }
.stat-card .value { font-size: 28px; font-weight: 700; line-height: 1; }
.stat-card .sub   { font-size: 12px; color: var(--muted); }
.stat-card.green .value { color: var(--green); }
.stat-card.red   .value { color: var(--red); }
.stat-card.purple.value { color: var(--purple); }

/* Tables */
.table-wrap {
  background: var(--card); border: 1px solid var(--border); border-radius: 12px;
  overflow-y: auto; flex: 1; min-height: 0;
}
table { width: 100%; border-collapse: collapse; }
th {
  padding: 10px 14px; text-align: left; font-size: 11px; text-transform: uppercase;
  letter-spacing: .5px; color: var(--muted); background: var(--surface);
  border-bottom: 1px solid var(--border); white-space: nowrap; cursor: pointer;
  user-select: none; position: sticky; top: 0; z-index: 1;
}
th:hover { color: var(--text); }
th.sorted { color: var(--purple); }
td { padding: 10px 14px; border-bottom: 1px solid var(--border); vertical-align: middle; }
tr:last-child td { border-bottom: none; }
tr:hover td { background: rgba(255,255,255,.03); }

.badge {
  display: inline-block; padding: 2px 8px; border-radius: 20px; font-size: 11px; font-weight: 600;
}
.badge.chat { background: rgba(29,185,84,.15); color: var(--chat); }
.badge.chit { background: rgba(233,25,22,.15); color: var(--chit); }

.score-bar {
  display: flex; align-items: center; gap: 8px;
}
.score-bar .num { font-weight: 700; min-width: 34px; }
.bar-bg { flex: 1; height: 5px; background: var(--border); border-radius: 3px; overflow: hidden; }
.bar-fill { height: 100%; border-radius: 3px; background: var(--purple); transition: width .3s; }

.ratio-bar { display: flex; height: 6px; border-radius: 3px; overflow: hidden; gap: 1px; width: 80px; }
.ratio-bar .chat-part { background: var(--chat); }
.ratio-bar .chit-part { background: var(--chit); }

/* Buttons */
.btn {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 7px 14px; border-radius: 8px; border: none; cursor: pointer;
  font-size: 13px; font-weight: 500; transition: all .15s;
}
.btn-primary  { background: var(--purple); color: #fff; }
.btn-primary:hover  { background: var(--purple2); }
.btn-danger   { background: rgba(233,25,22,.15); color: var(--chit); border: 1px solid var(--chit); }
.btn-danger:hover   { background: rgba(233,25,22,.3); }
.btn-ghost    { background: transparent; color: var(--muted); border: 1px solid var(--border); }
.btn-ghost:hover    { background: var(--card); color: var(--text); }
.btn-sm { padding: 4px 10px; font-size: 12px; }

/* Toolbar */
.toolbar {
  display: flex; gap: 10px; margin-bottom: 16px; flex-wrap: wrap; align-items: center; flex-shrink: 0;
}
.search-wrap { position: relative; flex: 1; min-width: 180px; max-width: 340px; }
.search-wrap svg { position: absolute; left: 10px; top: 50%; transform: translateY(-50%); color: var(--muted); width: 16px; }
.search-wrap input { padding-left: 34px; }

input, select {
  background: var(--card); border: 1px solid var(--border); border-radius: 8px;
  color: var(--text); padding: 7px 12px; font-size: 13px; outline: none; width: 100%;
}
input::placeholder { color: var(--muted); }
input:focus, select:focus { border-color: var(--purple); }
select { cursor: pointer; }

/* Pagination */
.pagination { display: flex; align-items: center; gap: 8px; margin-top: 14px; flex-shrink: 0; }
.pagination .info { color: var(--muted); font-size: 12px; flex: 1; }

/* Modal */
.overlay {
  position: fixed; inset: 0; background: rgba(0,0,0,.7); z-index: 100;
  display: flex; align-items: center; justify-content: center; padding: 20px;
}
.overlay.hidden { display: none; }
.modal {
  background: var(--surface); border: 1px solid var(--border); border-radius: 16px;
  width: 100%; max-width: 580px; max-height: 90vh; overflow-y: auto;
}
.modal-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 18px 22px; border-bottom: 1px solid var(--border);
}
.modal-header h3 { font-size: 16px; font-weight: 700; }
.modal-body { padding: 22px; }
.modal-footer {
  display: flex; gap: 10px; justify-content: flex-end;
  padding: 14px 22px; border-top: 1px solid var(--border);
}

.form-row { margin-bottom: 16px; }
.form-row label { display: block; font-size: 12px; color: var(--muted); margin-bottom: 6px; }

.user-stats-row { display: flex; gap: 10px; margin-bottom: 18px; flex-wrap: wrap; }
.mini-stat {
  flex: 1; min-width: 90px; padding: 12px; background: var(--card);
  border-radius: 10px; text-align: center; border: 1px solid var(--border);
}
.mini-stat .mv { font-size: 20px; font-weight: 700; }
.mini-stat .ml { font-size: 11px; color: var(--muted); margin-top: 2px; }

/* History message */
.msg-text { max-width: 340px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.reasons-cell { font-size: 11px; color: var(--muted); max-width: 200px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* Two-column layout for dashboard */
.dash-cols { display: grid; grid-template-columns: 1fr 1fr; gap: 20px; flex: 1; min-height: 0; overflow: hidden; }
.dash-cols > div { display: flex; flex-direction: column; min-height: 0; overflow: hidden; }
@media (max-width: 900px) { .dash-cols { grid-template-columns: 1fr; } }

/* Empty state */
.empty { text-align: center; padding: 48px; color: var(--muted); }
.empty svg { width: 40px; height: 40px; opacity: .3; margin-bottom: 12px; }

/* Live row flash animation */
@keyframes rowFlash {
  0%   { background: rgba(145, 71, 255, 0.25); }
  100% { background: transparent; }
}
tr.new-row td { animation: rowFlash 1.4s ease-out forwards; }

/* Animated counter */
@keyframes numPop {
  0%   { transform: scale(1.25); color: var(--purple); }
  100% { transform: scale(1);    color: inherit; }
}
.stat-pop { animation: numPop .4s ease-out; }

/* Live indicator pulse */
@keyframes pulse {
  0%, 100% { opacity: 1; }
  50%       { opacity: .35; }
}
#live-dot { display: inline-block; width: 8px; height: 8px; border-radius: 50%; background: var(--green); animation: pulse 1.5s infinite; vertical-align: middle; margin-right: 6px; }

/* Auth-Gating: hide write controls when locked */
body:not(.unlocked) .requires-auth { display: none !important; }
/* Login button hides when already unlocked */
body.unlocked #login-btn { display: none; }

/* Disabled inputs in modal (read-only when locked) */
input:disabled {
  opacity: .55; cursor: not-allowed;
  background: var(--surface); border-color: var(--border);
}

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