/* Modern 2026 admin panel theme: dark by default, soft surfaces,
   Inter/system typography, generous whitespace, clean data tables. */

:root {
  color-scheme: dark;
  --bg-0: #0a0d12;
  --bg-1: #0f141b;
  --bg-2: #141b24;
  --bg-3: #1a2230;
  --border: #232c3a;
  --border-strong: #2e3a4e;
  --text: #e7edf4;
  --text-dim: #8b95a3;
  --text-mute: #5b6575;
  --primary: #5b8dff;
  --primary-fg: #0a0d12;
  --accent: #3ecf8e;
  --warn: #f4a93c;
  --danger: #ef4444;
  --radius: 14px;
  --radius-sm: 10px;
  --shadow: 0 1px 0 rgba(255,255,255,0.02) inset, 0 4px 24px rgba(0,0,0,0.35);
  --mono: ui-monospace, SFMono-Regular, Menlo, Monaco, "SF Mono", monospace;
  --sans: "Inter", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: radial-gradient(ellipse at top, #131a27 0%, var(--bg-0) 55%) fixed;
  color: var(--text);
  font-family: var(--sans);
  font-size: 14px;
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
}

a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }

.layout {
  display: grid;
  grid-template-columns: 240px 1fr;
  min-height: 100vh;
}

/* ---------- sidebar ---------- */

.sidebar {
  position: sticky;
  top: 0;
  height: 100vh;
  background: linear-gradient(180deg, var(--bg-1) 0%, var(--bg-0) 100%);
  border-right: 1px solid var(--border);
  padding: 22px 16px;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 6px 8px 18px;
  border-bottom: 1px solid var(--border);
  margin-bottom: 12px;
}
.brand-logo {
  width: 32px; height: 32px;
  border-radius: 8px;
  background: linear-gradient(135deg, var(--primary) 0%, var(--accent) 100%);
  display: grid; place-items: center;
  font-weight: 700; color: var(--primary-fg);
  font-size: 15px;
  box-shadow: 0 4px 16px rgba(91,141,255,0.35);
}
.brand-name { font-weight: 600; letter-spacing: 0.2px; }
.brand-sub { color: var(--text-dim); font-size: 12px; }

.nav a {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 9px 10px;
  border-radius: var(--radius-sm);
  color: var(--text-dim);
  text-decoration: none;
  font-weight: 500;
  transition: background 120ms, color 120ms;
}
.nav a:hover { background: var(--bg-2); color: var(--text); text-decoration: none; }
.nav a.active { background: var(--bg-3); color: var(--text); }
.nav .hint { margin-top: auto; color: var(--text-mute); font-size: 12px; padding: 8px 10px; }

.logout-form { margin-top: 12px; padding: 8px 10px 0; border-top: 1px solid var(--border); }
.logout-form button {
  width: 100%; padding: 9px 12px; border-radius: 10px;
  background: transparent; border: 1px solid var(--border);
  color: var(--text-dim); cursor: pointer; font-weight: 500;
  font-family: inherit; font-size: 13px;
  transition: all 120ms;
}
.logout-form button:hover { color: var(--danger); border-color: var(--danger); }

/* ---------- main ---------- */

.main {
  padding: 28px 36px 64px;
  max-width: 1400px;
  width: 100%;
}

.header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 24px;
}

.header h1 {
  font-size: 22px;
  font-weight: 600;
  margin: 0;
  letter-spacing: -0.02em;
}
.header .sub { color: var(--text-dim); font-size: 13px; margin-top: 2px; }

.who {
  display: flex; align-items: center; gap: 10px;
  color: var(--text-dim); font-size: 13px;
}
.who .dot {
  width: 8px; height: 8px; border-radius: 50%;
  background: var(--accent);
  box-shadow: 0 0 12px rgba(62,207,142,0.7);
}

/* ---------- metric cards ---------- */

.cards {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 14px;
  margin-bottom: 32px;
}

.card {
  background: var(--bg-1);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 18px 20px;
  box-shadow: var(--shadow);
  position: relative;
  overflow: hidden;
}
.card::before {
  content: "";
  position: absolute; top: 0; left: 0; right: 0; height: 1px;
  background: linear-gradient(90deg, transparent, rgba(255,255,255,0.08), transparent);
}
.card .label {
  color: var(--text-dim);
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  margin-bottom: 10px;
}
.card .value {
  font-size: 28px;
  font-weight: 600;
  letter-spacing: -0.02em;
}
.card.accent .value { color: var(--accent); }
.card.warn .value { color: var(--warn); }
.card.danger .value { color: var(--danger); }

/* ---------- section + table ---------- */

.section {
  background: var(--bg-1);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 22px;
  margin-bottom: 22px;
  box-shadow: var(--shadow);
}
.section h2 {
  font-size: 15px;
  font-weight: 600;
  letter-spacing: 0.02em;
  margin: 0 0 4px;
  color: var(--text);
  display: flex; align-items: center; gap: 10px;
}
.section h2 .count {
  font-weight: 500; color: var(--text-dim); font-size: 13px;
}
.section .section-desc {
  color: var(--text-dim); font-size: 13px; margin: 0 0 16px;
}

.table-wrap { overflow-x: auto; }

/* Scrollable table container. Height is set precisely by JS (see
   dashboard / tenant templates) based on actual row height of the
   current data; this is a fallback for the brief moment before JS runs. */
.table-scroll {
  max-height: calc(var(--visible-rows, 5) * 60px + 48px);
  overflow-y: auto;
  overflow-x: auto;
  border-top: 1px solid var(--border);
  border-bottom: 1px solid var(--border);
  border-radius: 8px;
  background: var(--bg-0);
}
.table-scroll table.data thead th {
  position: sticky; top: 0; z-index: 1;
  background: var(--bg-2);
}

.table-toolbar {
  display: flex; justify-content: space-between; align-items: center;
  margin: 4px 0 10px; gap: 12px; flex-wrap: wrap;
}
.table-toolbar select {
  cursor: pointer;
}

table.data {
  width: 100%;
  border-collapse: separate;
  border-spacing: 0;
  font-size: 13px;
}
table.data th, table.data td {
  padding: 10px 12px;
  text-align: left;
  vertical-align: top;
  border-bottom: 1px solid var(--border);
}
table.data thead th {
  font-weight: 500;
  color: var(--text-dim);
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  background: var(--bg-2);
  position: sticky;
  top: 0;
}
table.data tbody tr:hover { background: var(--bg-2); }
table.data tbody tr:last-child td { border-bottom: none; }

.mono { font-family: var(--mono); font-size: 12.5px; }
.small { color: var(--text-dim); font-size: 12px; }
.muted { color: var(--text-mute); }

.badge {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 3px 8px; font-size: 12px; font-weight: 500;
  border-radius: 999px; border: 1px solid var(--border);
  background: var(--bg-2); color: var(--text-dim);
}
.badge.paid { color: var(--accent); border-color: rgba(62,207,142,0.25); background: rgba(62,207,142,0.08); }
.badge.sent { color: var(--warn); border-color: rgba(244,169,60,0.25); background: rgba(244,169,60,0.08); }
.badge.expired { color: var(--danger); border-color: rgba(239,68,68,0.25); background: rgba(239,68,68,0.08); }
.badge.active { color: var(--accent); border-color: rgba(62,207,142,0.25); background: rgba(62,207,142,0.08); }
.badge.on { color: var(--accent); }
.badge.off { color: var(--text-mute); }

/* ---------- forms / buttons ---------- */

input[type="text"], input[type="email"], input[type="password"],
input[type="number"], input[type="file"] {
  background: var(--bg-0);
  border: 1px solid var(--border-strong);
  border-radius: 10px;
  padding: 10px 12px;
  color: var(--text);
  font-family: inherit;
  font-size: 14px;
  width: 100%;
  transition: border 120ms, box-shadow 120ms;
}
input:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(91,141,255,0.18);
}

.btn {
  display: inline-flex; align-items: center; gap: 8px;
  padding: 9px 14px;
  background: var(--primary);
  color: var(--primary-fg);
  border: none;
  border-radius: 10px;
  font-weight: 600; font-family: inherit; font-size: 13px;
  cursor: pointer;
  transition: transform 80ms, box-shadow 120ms, filter 120ms;
}
.btn:hover { filter: brightness(1.08); box-shadow: 0 6px 18px rgba(91,141,255,0.35); }
.btn:active { transform: translateY(1px); }
.btn.ghost {
  background: transparent; color: var(--text); border: 1px solid var(--border-strong);
}
.btn.ghost:hover { background: var(--bg-2); box-shadow: none; }
.btn.danger { background: var(--danger); color: #fff; }
.btn.danger:hover { box-shadow: 0 6px 18px rgba(239,68,68,0.35); }

form.inline { display: inline-flex; align-items: center; gap: 8px; }
form.inline input[type="number"] { width: 88px; padding: 6px 8px; }

/* ---------- auth page ---------- */

.auth-wrap {
  min-height: 100vh;
  display: grid; place-items: center;
  padding: 24px;
}
.auth-card {
  width: 100%; max-width: 420px;
  background: var(--bg-1);
  border: 1px solid var(--border);
  border-radius: 20px;
  padding: 36px 32px;
  box-shadow: var(--shadow);
}
.auth-card .brand { border: none; margin: 0 0 18px; padding: 0 0 14px; }
.auth-card h1 {
  font-size: 18px; font-weight: 600; margin: 0 0 6px;
}
.auth-card .sub { color: var(--text-dim); font-size: 13px; margin: 0 0 22px; }
.auth-card .field { margin-bottom: 14px; }
.auth-card label { display: block; color: var(--text-dim); font-size: 12px; margin-bottom: 6px; }
.auth-card .btn { width: 100%; justify-content: center; padding: 12px; font-size: 14px; }
.auth-card .error {
  background: rgba(239,68,68,0.08);
  border: 1px solid rgba(239,68,68,0.25);
  color: var(--danger);
  padding: 10px 12px;
  border-radius: 10px;
  font-size: 13px;
  margin-bottom: 14px;
}
.auth-card .hint {
  color: var(--text-mute); font-size: 12px; text-align: center;
  margin: 18px 0 0;
}

.otp-input {
  letter-spacing: 10px;
  font-family: var(--mono);
  font-size: 22px;
  text-align: center;
}

/* ---------- messenger ---------- */

.nav-badge {
  background: var(--primary);
  color: var(--primary-fg);
  font-size: 11px;
  font-weight: 700;
  border-radius: 999px;
  padding: 1px 7px;
  margin-left: 6px;
  box-shadow: 0 0 10px rgba(91,141,255,0.5);
}

/* Messenger uses a fixed viewport height so the body never scrolls;
   each pane gets its own overflow. Override the generic .layout's
   min-height so the grid can shrink. */
.chats-layout {
  height: 100vh;
  min-height: 0;
  overflow: hidden;
}
.chats-main {
  padding: 0; max-width: none; width: 100%;
  height: 100vh; overflow: hidden;
  min-height: 0; min-width: 0;
}
.chats-split {
  display: grid;
  grid-template-columns: 340px 1fr;
  height: 100vh;
  min-height: 0;
  background: var(--bg-0);
}

.chat-list {
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  min-height: 0;
  height: 100%;
  background: var(--bg-1);
  overflow: hidden;
}
.chat-list-header {
  padding: 18px 18px 14px;
  border-bottom: 1px solid var(--border);
  display: flex; justify-content: space-between; align-items: center;
  flex-shrink: 0;
}
.chat-list-body { overflow-y: auto; flex: 1 1 0; min-height: 0; }
.chat-list-empty { padding-top: 24px; }

.chat-item {
  display: flex; align-items: center; gap: 12px;
  padding: 12px 16px;
  border-bottom: 1px solid var(--border);
  color: var(--text);
  text-decoration: none;
  transition: background 100ms;
}
.chat-item:hover { background: var(--bg-2); text-decoration: none; }
.chat-item.open { background: var(--bg-3); }
.chat-item.unread .chat-name { font-weight: 700; color: var(--text); }
.chat-item.unread .chat-preview { color: var(--text); }

.chat-avatar {
  flex-shrink: 0;
  width: 42px; height: 42px;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--primary) 0%, var(--accent) 100%);
  display: grid; place-items: center;
  color: var(--primary-fg);
  font-weight: 700;
  font-size: 16px;
}

.chat-meta { flex: 1; min-width: 0; }
.chat-row1 {
  display: flex; justify-content: space-between; align-items: baseline;
  gap: 8px; margin-bottom: 3px;
}
.chat-name {
  font-weight: 500;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 180px;
}
.chat-time { color: var(--text-mute); font-size: 11px; flex-shrink: 0; }
.chat-row2 {
  display: flex; justify-content: space-between; align-items: center;
  gap: 8px;
}
.chat-preview {
  color: var(--text-dim);
  font-size: 13px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  flex: 1; min-width: 0;
}
.chat-badge {
  background: var(--primary);
  color: var(--primary-fg);
  font-size: 11px;
  font-weight: 700;
  border-radius: 999px;
  padding: 1px 8px;
  min-width: 20px;
  text-align: center;
  box-shadow: 0 0 12px rgba(91,141,255,0.5);
  flex-shrink: 0;
}

.chat-window {
  display: flex; flex-direction: column;
  background:
    radial-gradient(ellipse at top left, rgba(91,141,255,0.04), transparent 50%),
    var(--bg-0);
  min-width: 0;
  min-height: 0;
  height: 100%;
  overflow: hidden;
}
.chat-empty {
  flex: 1; display: grid; place-items: center;
}
.chat-header {
  display: flex; align-items: center;
  padding: 14px 24px;
  border-bottom: 1px solid var(--border);
  background: var(--bg-1);
  flex-shrink: 0;
}

.chat-messages {
  flex: 1 1 0;
  min-height: 0;
  overflow-y: auto;
  padding: 18px 24px;
  display: flex; flex-direction: column; gap: 8px;
}
.chat-daysep {
  text-align: center; margin: 16px 0 8px;
  color: var(--text-mute); font-size: 12px;
}
.chat-daysep span {
  background: var(--bg-2); padding: 3px 12px; border-radius: 999px;
  border: 1px solid var(--border);
}
.chat-msg { display: flex; }
.chat-msg.out { justify-content: flex-end; }
.bubble {
  max-width: 70%;
  padding: 9px 13px 7px;
  border-radius: 14px;
  font-size: 14px;
  line-height: 1.4;
  word-wrap: break-word;
}
.chat-msg.in .bubble {
  background: var(--bg-2);
  border: 1px solid var(--border);
  border-bottom-left-radius: 4px;
  color: var(--text);
}
.chat-msg.out .bubble {
  background: linear-gradient(135deg, #3b82f6 0%, #2563eb 100%);
  color: #fff;
  border-bottom-right-radius: 4px;
}
.bubble-text { white-space: pre-wrap; }
.bubble-time {
  font-size: 11px; color: rgba(255,255,255,0.65);
  text-align: right; margin-top: 4px;
}
.chat-msg.in .bubble-time { color: var(--text-mute); }

.chat-compose {
  display: flex; gap: 10px;
  padding: 12px 16px;
  border-top: 1px solid var(--border);
  background: var(--bg-1);
  flex-shrink: 0;
}
.chat-compose textarea {
  flex: 1;
  background: var(--bg-0);
  border: 1px solid var(--border-strong);
  border-radius: 12px;
  padding: 10px 14px;
  color: var(--text);
  font-family: inherit; font-size: 14px; line-height: 1.4;
  resize: none;
  min-height: 42px;
  max-height: 160px;
}
.chat-compose textarea:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(91,141,255,0.18);
}
.chat-compose button {
  width: 46px; height: 46px;
  padding: 0;
  border-radius: 50%;
  font-size: 18px;
  align-self: flex-end;
}

@media (max-width: 720px) {
  .layout { grid-template-columns: 1fr; }
  .sidebar { position: static; height: auto; }
  .main { padding: 20px 16px 48px; }
  .chats-split { grid-template-columns: 1fr; }
  .chat-list { max-height: 40vh; }
}
