:root {
  --dm-primary: #4f46e5;
  --dm-primary-dark: #4338ca;
  --dm-primary-soft: #eef2ff;
  --dm-ink: #0f172a;
  --dm-muted: #64748b;
  --dm-line: #e6e9f2;
  --dm-surface: #ffffff;
  --dm-bg: #f5f7fb;
  --dm-success: #16a34a;
  --dm-danger: #dc2626;
  --dm-radius: 16px;
  --sidebar-w: 258px;
}

* { box-sizing: border-box; }

body {
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Arial, sans-serif;
  background: var(--dm-bg);
  color: var(--dm-ink);
  font-size: 14px;
  min-height: 100vh;
}

a { text-decoration: none; }

.tiny { font-size: 11px; }

.app-shell { min-height: 100vh; }

/* ---------------------------------------------------------------- sidebar */
.sidebar {
  position: fixed;
  inset: 0 auto 0 0;
  width: var(--sidebar-w);
  background: linear-gradient(180deg, #10162b 0%, #171f3a 55%, #10162b 100%);
  color: #cbd5e1;
  display: flex;
  flex-direction: column;
  z-index: 1045;
  transition: transform .25s ease;
  overflow-y: auto;
}
.sidebar-brand { padding: 22px 20px 10px; }
.sidebar-brand a { display: flex; align-items: center; gap: 10px; color: #fff; }
.brand-icon {
  width: 38px; height: 38px; border-radius: 12px;
  display: inline-flex; align-items: center; justify-content: center;
  background: linear-gradient(135deg, #25d366, #128c7e);
  color: #fff; font-size: 20px;
  box-shadow: 0 8px 20px rgba(37, 211, 102, .28);
}
.brand-text { font-size: 19px; font-weight: 800; letter-spacing: -.4px; }
.sidebar-meta { padding: 0 20px 14px; }
.sidebar-meta .pill {
  display: inline-flex; align-items: center; gap: 6px;
  font-size: 11px; color: #94a3b8;
  background: rgba(255,255,255,.06);
  border: 1px solid rgba(255,255,255,.08);
  border-radius: 999px; padding: 4px 10px;
}
.sidebar-nav { padding: 4px 12px 20px; flex: 1; }
.nav-label {
  font-size: 10px; letter-spacing: .14em; text-transform: uppercase;
  color: #64748b; padding: 10px 12px 6px; font-weight: 700;
}
.sidebar-nav .nav-item {
  display: flex; align-items: center; gap: 11px;
  padding: 10px 12px; margin-bottom: 2px;
  border-radius: 10px; color: #cbd5e1; font-weight: 500;
  transition: background .15s ease, color .15s ease, transform .15s ease;
}
.sidebar-nav .nav-item i { font-size: 16px; width: 20px; text-align: center; color: #94a3b8; }
.sidebar-nav .nav-item:hover { background: rgba(255,255,255,.07); color: #fff; }
.sidebar-nav .nav-item:hover i { color: #fff; }
.sidebar-nav .nav-item.active {
  background: linear-gradient(135deg, rgba(79,70,229,.95), rgba(99,102,241,.85));
  color: #fff;
  box-shadow: 0 8px 20px rgba(79,70,229,.32);
}
.sidebar-nav .nav-item.active i { color: #fff; }
.sidebar-footer {
  padding: 16px 20px; border-top: 1px solid rgba(255,255,255,.07);
  font-size: 11px;
}

/* ------------------------------------------------------------------- main */
.main-area {
  margin-left: var(--sidebar-w);
  display: flex; flex-direction: column; min-height: 100vh;
}
.topbar {
  position: sticky; top: 0; z-index: 1030;
  display: flex; align-items: center; gap: 12px;
  padding: 12px 26px;
  background: rgba(255,255,255,.85);
  backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--dm-line);
}
.topbar-eyebrow { font-size: 11px; text-transform: uppercase; letter-spacing: .1em; color: var(--dm-muted); font-weight: 700; }
.topbar-title { font-weight: 700; font-size: 15px; }
.btn-icon {
  border: 1px solid var(--dm-line); background: #fff; border-radius: 10px;
  width: 40px; height: 40px; display: inline-flex; align-items: center; justify-content: center;
}
.balance-pill {
  display: inline-flex; align-items: center; gap: 7px;
  background: #ecfdf5; color: #047857; font-weight: 700; font-size: 13px;
  border: 1px solid #a7f3d0; padding: 7px 12px; border-radius: 999px;
}
.user-chip {
  display: inline-flex; align-items: center; gap: 9px;
  background: #fff; border: 1px solid var(--dm-line); border-radius: 12px;
  padding: 5px 10px 5px 6px; color: var(--dm-ink);
}
.user-chip::after { margin-left: 2px; }
.avatar {
  width: 32px; height: 32px; border-radius: 9px;
  display: inline-flex; align-items: center; justify-content: center;
  background: var(--dm-primary-soft); color: var(--dm-primary); font-weight: 800;
}

.content { padding: 26px; flex: 1; }
.app-footer {
  display: flex; justify-content: space-between; gap: 12px;
  padding: 16px 26px; border-top: 1px solid var(--dm-line);
  font-size: 12px; color: var(--dm-muted);
}
.page-head {
  display: flex; align-items: flex-end; justify-content: space-between;
  gap: 16px; flex-wrap: wrap; margin-bottom: 20px;
}
.page-title { font-size: 24px; font-weight: 800; letter-spacing: -.5px; margin: 0; }
.page-subtitle { color: var(--dm-muted); margin: 4px 0 0; }
.page-actions { display: flex; gap: 8px; flex-wrap: wrap; }

/* ------------------------------------------------------------------ cards */
.card {
  border: 1px solid var(--dm-line); border-radius: var(--dm-radius);
  box-shadow: 0 1px 2px rgba(15,23,42,.03);
}
.card-header { background: transparent; border-bottom: 1px solid var(--dm-line); padding: 16px 18px; font-weight: 700; }
.card-body { padding: 18px; }
.stat-card { position: relative; overflow: hidden; }
.stat-card .card-body { display: flex; align-items: center; gap: 14px; }
.stat-icon {
  width: 46px; height: 46px; border-radius: 13px; display: inline-flex;
  align-items: center; justify-content: center; font-size: 20px; flex: 0 0 auto;
}
.stat-icon.indigo { background: #eef2ff; color: #4f46e5; }
.stat-icon.green { background: #ecfdf5; color: #059669; }
.stat-icon.blue { background: #eff6ff; color: #2563eb; }
.stat-icon.amber { background: #fffbeb; color: #d97706; }
.stat-icon.rose { background: #fff1f2; color: #e11d48; }
.stat-label { color: var(--dm-muted); font-size: 12px; font-weight: 600; text-transform: uppercase; letter-spacing: .05em; }
.stat-value { font-size: 22px; font-weight: 800; letter-spacing: -.4px; line-height: 1.15; }
.stat-hint { font-size: 11px; color: var(--dm-muted); }

.soft-panel { background: #f8fafc; border: 1px dashed var(--dm-line); border-radius: 12px; padding: 14px; }

/* ----------------------------------------------------------------- tables */
.table { --bs-table-bg: transparent; margin-bottom: 0; }
.table > :not(caption) > * > * { padding: .72rem .6rem; }
.table thead th {
  font-size: 11px; text-transform: uppercase; letter-spacing: .06em;
  color: var(--dm-muted); font-weight: 700; border-bottom: 1px solid var(--dm-line);
  white-space: nowrap;
}
.table tbody tr:hover { background: #f8fafc; }
.table td { vertical-align: middle; border-color: #f0f2f8; }
.msg-preview { max-width: 320px; color: #334155; }
.msg-preview .media-tag { color: var(--dm-primary); }

/* ------------------------------------------------------------------ forms */
.form-label { font-weight: 600; font-size: 12px; color: #334155; margin-bottom: 5px; }
.form-control, .form-select {
  border-radius: 10px; border-color: #dbe1ec; padding: .58rem .75rem; font-size: 14px;
}
.form-control:focus, .form-select:focus {
  border-color: #a5b4fc; box-shadow: 0 0 0 .2rem rgba(79,70,229,.12);
}
.form-text { font-size: 12px; }
.btn { border-radius: 10px; font-weight: 600; }
.btn-primary { background: var(--dm-primary); border-color: var(--dm-primary); }
.btn-primary:hover { background: var(--dm-primary-dark); border-color: var(--dm-primary-dark); }
.btn-sm { padding: .35rem .65rem; font-size: 12px; }

.badge { font-weight: 600; padding: .4em .6em; border-radius: 7px; }

/* ------------------------------------------------------------------- auth */
.auth-wrap {
  min-height: 100vh; display: flex; align-items: stretch;
  background: #0f172a;
}
.auth-aside {
  flex: 1; display: none; padding: 56px;
  background:
    radial-gradient(900px 500px at 10% 10%, rgba(79,70,229,.45), transparent 60%),
    radial-gradient(700px 500px at 90% 90%, rgba(37,211,102,.22), transparent 60%),
    #0f172a;
  color: #fff; flex-direction: column; justify-content: space-between;
}
.auth-aside h2 { font-size: 34px; font-weight: 800; letter-spacing: -1px; max-width: 460px; }
.auth-aside p { color: #94a3b8; max-width: 420px; }
.auth-feature { display: flex; gap: 12px; align-items: flex-start; margin-top: 16px; color: #cbd5e1; }
.auth-feature i { color: #34d399; font-size: 18px; }
.auth-main { width: 100%; max-width: 480px; background: var(--dm-bg); display: flex; align-items: center; justify-content: center; padding: 28px; }
.auth-card { width: 100%; max-width: 380px; }
.auth-brand { display: flex; align-items: center; gap: 10px; margin-bottom: 26px; }
.auth-brand .brand-icon { width: 44px; height: 44px; }

/* ------------------------------------------------------------------- chat */
.chat-box { display: flex; flex-direction: column; gap: 12px; max-height: 560px; overflow-y: auto; padding: 6px 2px; }
.chat-row { display: flex; }
.chat-row.out { justify-content: flex-end; }
.chat-bubble {
  max-width: 76%; padding: 10px 13px; border-radius: 14px;
  background: #fff; border: 1px solid var(--dm-line); position: relative;
}
.chat-row.out .chat-bubble { background: #eef2ff; border-color: #dbe3ff; }
.chat-meta { font-size: 10px; color: var(--dm-muted); margin-top: 5px; display: flex; gap: 8px; flex-wrap: wrap; }
.chat-text { white-space: pre-wrap; word-break: break-word; }

/* --------------------------------------------------------------- helpers */
.text-muted { color: var(--dm-muted) !important; }
.divider { height: 1px; background: var(--dm-line); margin: 16px 0; }
.empty-state { text-align: center; padding: 40px 20px; color: var(--dm-muted); }
.empty-state i { font-size: 34px; opacity: .4; display: block; margin-bottom: 8px; }
.code-block {
  background: #0f172a; color: #e2e8f0; padding: 14px 16px;
  border-radius: 12px; font-size: 12.5px; overflow-x: auto;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  white-space: pre;
}
.key-box {
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  background: #f8fafc; border: 1px solid var(--dm-line); border-radius: 10px;
  padding: 10px 12px; display: flex; align-items: center; gap: 10px; font-size: 12.5px;
  word-break: break-all;
}
.key-box .key-text { flex: 1; }
.section-title { font-size: 13px; text-transform: uppercase; letter-spacing: .08em; color: var(--dm-muted); font-weight: 700; margin-bottom: 12px; }
.list-clean { list-style: none; margin: 0; padding: 0; }
.list-clean li { display: flex; justify-content: space-between; gap: 12px; padding: 9px 0; border-bottom: 1px solid #f1f3f9; font-size: 13px; }
.list-clean li:last-child { border-bottom: 0; }

.sidebar-backdrop {
  position: fixed; inset: 0; background: rgba(15,23,42,.5);
  z-index: 1040; display: none;
}

@media (min-width: 992px) {
  .auth-aside { display: flex; }
}
@media (max-width: 991.98px) {
  .sidebar { transform: translateX(-100%); }
  body.sidebar-open .sidebar { transform: translateX(0); }
  body.sidebar-open .sidebar-backdrop { display: block; }
  .main-area { margin-left: 0; }
  .content { padding: 18px; }
  .topbar { padding: 10px 16px; }
  .app-footer { padding: 14px 18px; }
  .page-title { font-size: 20px; }
}
