/* ─── RADEM v2 — Design System ─────────────────────────────────────────── */
:root {
  --c-bg:       #0f1117;
  --c-surface:  #1a1d27;
  --c-card:     #22263a;
  --c-border:   #2e3347;
  --c-accent:   #4f8ef7;
  --c-accent2:  #7c5cbf;
  --c-success:  #2dce89;
  --c-warn:     #fb6340;
  --c-text:     #e8eaf0;
  --c-muted:    #8890a8;
  --c-shadow:   0 4px 24px rgba(0,0,0,.4);
  --r:          10px;
  --font:       'Inter', system-ui, sans-serif;
}

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

html { font-size: 15px; }

body {
  font-family: var(--font);
  background: var(--c-bg);
  color: var(--c-text);
  min-height: 100vh;
  line-height: 1.5;
}

/* ─── Auth Screen ─── */
#auth-screen {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: radial-gradient(ellipse at 20% 60%, #1a1f3a 0%, var(--c-bg) 70%);
}

.auth-card {
  background: var(--c-surface);
  border: 1px solid var(--c-border);
  border-radius: 16px;
  padding: 2.5rem;
  width: 100%;
  max-width: 380px;
  box-shadow: var(--c-shadow);
}

.auth-logo {
  text-align: center;
  margin-bottom: 2rem;
}
.auth-logo .logo-circle {
  width: 64px; height: 64px;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--c-accent), var(--c-accent2));
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 1.6rem;
  font-weight: 800;
  color: #fff;
  margin-bottom: .75rem;
}
.auth-logo h1 { font-size: 1.4rem; font-weight: 700; }
.auth-logo p  { font-size: .85rem; color: var(--c-muted); }

/* ─── Layout ─── */
#app { display: flex; min-height: 100vh; }

/* Sidebar */
.sidebar {
  width: 220px;
  background: var(--c-surface);
  border-right: 1px solid var(--c-border);
  display: flex;
  flex-direction: column;
  position: fixed;
  top: 0; left: 0; bottom: 0;
  z-index: 10;
  transition: transform .25s ease;
}

.sidebar-logo {
  padding: 1.25rem 1rem;
  border-bottom: 1px solid var(--c-border);
  display: flex; align-items: center; gap: .75rem;
}
.sidebar-logo .logo-sm {
  width: 36px; height: 36px; border-radius: 50%;
  background: linear-gradient(135deg, var(--c-accent), var(--c-accent2));
  display: flex; align-items: center; justify-content: center;
  font-weight: 800; font-size: .95rem; color: #fff;
  flex-shrink: 0;
}
.sidebar-logo span { font-weight: 700; font-size: 1rem; }

.sidebar-nav {
  flex: 1;
  overflow-y: auto;
  padding: .75rem 0;
  scrollbar-width: thin;
  scrollbar-color: var(--c-border) transparent;
}

.nav-section {
  padding: .4rem 1rem .2rem;
  font-size: .7rem;
  font-weight: 600;
  letter-spacing: .08em;
  text-transform: uppercase;
  color: var(--c-muted);
}

.nav-item {
  display: flex;
  align-items: center;
  gap: .6rem;
  padding: .55rem 1rem;
  cursor: pointer;
  transition: background .15s, color .15s;
  border-radius: 0;
  font-size: .88rem;
  color: var(--c-muted);
  user-select: none;
}
.nav-item:hover { background: rgba(255,255,255,.04); color: var(--c-text); }
.nav-item.active {
  background: rgba(79,142,247,.12);
  color: var(--c-accent);
  font-weight: 600;
}
.nav-item .icon { font-size: 1rem; width: 18px; text-align: center; }
.nav-badge {
  margin-left: auto;
  background: var(--c-warn);
  color: #fff;
  font-size: .68rem;
  font-weight: 700;
  border-radius: 99px;
  padding: 1px 6px;
  min-width: 18px;
  text-align: center;
}

.sidebar-user {
  padding: .75rem 1rem;
  border-top: 1px solid var(--c-border);
  display: flex; align-items: center; gap: .6rem;
}
.user-avatar {
  width: 32px; height: 32px; border-radius: 50%;
  background: linear-gradient(135deg, var(--c-accent2), var(--c-accent));
  display: flex; align-items: center; justify-content: center;
  font-size: .75rem; font-weight: 700; color: #fff; flex-shrink: 0;
}
.user-info { flex: 1; overflow: hidden; }
.user-name  { font-size: .82rem; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.user-role  { font-size: .72rem; color: var(--c-muted); }
.btn-logout {
  background: none; border: none; cursor: pointer;
  color: var(--c-muted); font-size: 1rem; padding: 4px;
  border-radius: 6px; transition: color .15s;
}
.btn-logout:hover { color: var(--c-warn); }

/* Main */
.main {
  margin-left: 220px;
  flex: 1;
  display: flex;
  flex-direction: column;
  min-height: 100vh;
}

.topbar {
  height: 52px;
  background: var(--c-surface);
  border-bottom: 1px solid var(--c-border);
  display: flex; align-items: center;
  padding: 0 1.5rem;
  gap: 1rem;
  position: sticky; top: 0; z-index: 5;
}
.topbar h2 { font-size: 1rem; font-weight: 600; flex: 1; }
.topbar-actions { display: flex; align-items: center; gap: .5rem; }

.page-content {
  padding: 1.5rem;
  flex: 1;
}

/* ─── Components ─── */
/* Stat tiles */
.stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
  gap: 1rem;
  margin-bottom: 1.5rem;
}

.stat-card {
  background: var(--c-card);
  border: 1px solid var(--c-border);
  border-radius: var(--r);
  padding: 1.1rem 1.2rem;
}
.stat-label { font-size: .75rem; color: var(--c-muted); margin-bottom: .35rem; }
.stat-value { font-size: 1.65rem; font-weight: 700; line-height: 1; }
.stat-sub   { font-size: .75rem; color: var(--c-muted); margin-top: .3rem; }
.stat-card.accent  { border-color: rgba(79,142,247,.3); }
.stat-card.success { border-color: rgba(45,206,137,.3); }
.stat-card.warn    { border-color: rgba(251,99,64,.3);  }

/* Buttons */
.btn {
  display: inline-flex; align-items: center; gap: .4rem;
  padding: .45rem 1rem;
  border: none; border-radius: 7px;
  font-size: .85rem; font-weight: 600;
  cursor: pointer; transition: opacity .15s, transform .1s;
  text-decoration: none;
}
.btn:hover  { opacity: .85; }
.btn:active { transform: scale(.97); }
.btn-primary   { background: var(--c-accent); color: #fff; }
.btn-secondary { background: var(--c-card); color: var(--c-text); border: 1px solid var(--c-border); }
.btn-danger    { background: var(--c-warn); color: #fff; }
.btn-success   { background: var(--c-success); color: #fff; }
.btn-ghost     { background: transparent; color: var(--c-muted); }
.btn-sm { padding: .3rem .7rem; font-size: .78rem; }
.btn-icon { width: 32px; height: 32px; padding: 0; justify-content: center; }

/* Forms */
.form-group { margin-bottom: 1rem; }
.form-label { display: block; font-size: .8rem; font-weight: 600; color: var(--c-muted); margin-bottom: .4rem; }
.form-control {
  width: 100%;
  background: var(--c-bg);
  border: 1px solid var(--c-border);
  border-radius: 7px;
  padding: .5rem .75rem;
  color: var(--c-text);
  font-size: .88rem;
  transition: border-color .15s;
  outline: none;
  font-family: var(--font);
}
.form-control:focus { border-color: var(--c-accent); }
.form-control::placeholder { color: var(--c-muted); }
select.form-control { cursor: pointer; }
textarea.form-control { resize: vertical; min-height: 80px; }
.form-row { display: grid; grid-template-columns: 1fr 1fr; gap: 1rem; }
.form-actions { display: flex; justify-content: flex-end; gap: .5rem; margin-top: 1.5rem; }

/* Tables */
.table-wrap { overflow-x: auto; }
.data-table {
  width: 100%;
  border-collapse: collapse;
  font-size: .85rem;
}
.data-table th {
  text-align: left;
  padding: .6rem .8rem;
  font-size: .72rem;
  font-weight: 600;
  color: var(--c-muted);
  text-transform: uppercase;
  letter-spacing: .05em;
  border-bottom: 1px solid var(--c-border);
  white-space: nowrap;
}
.data-table td {
  padding: .65rem .8rem;
  border-bottom: 1px solid rgba(46,51,71,.5);
  vertical-align: middle;
}
.data-table tr:last-child td { border-bottom: none; }
.data-table tr:hover td { background: rgba(255,255,255,.02); }

/* Cards */
.card {
  background: var(--c-card);
  border: 1px solid var(--c-border);
  border-radius: var(--r);
  overflow: hidden;
}
.card-header {
  padding: .9rem 1.2rem;
  border-bottom: 1px solid var(--c-border);
  display: flex; align-items: center; justify-content: space-between;
}
.card-title { font-size: .92rem; font-weight: 700; }
.card-body { padding: 1.2rem; }

/* Badges */
.badge {
  display: inline-flex; align-items: center;
  padding: 2px 8px;
  border-radius: 99px;
  font-size: .72rem;
  font-weight: 600;
}
.badge-success { background: rgba(45,206,137,.15); color: var(--c-success); }
.badge-warn    { background: rgba(251,99,64,.15);  color: var(--c-warn);    }
.badge-info    { background: rgba(79,142,247,.15); color: var(--c-accent);  }
.badge-muted   { background: rgba(136,144,168,.15); color: var(--c-muted); }

/* Modal */
.modal-overlay {
  position: fixed; inset: 0;
  background: rgba(0,0,0,.65);
  display: flex; align-items: center; justify-content: center;
  z-index: 100;
  backdrop-filter: blur(4px);
}
.modal-box {
  background: var(--c-surface);
  border: 1px solid var(--c-border);
  border-radius: 14px;
  width: min(520px, calc(100vw - 2rem));
  max-height: 90vh;
  overflow-y: auto;
  box-shadow: 0 24px 64px rgba(0,0,0,.6);
}
.modal-header {
  padding: 1.1rem 1.4rem;
  border-bottom: 1px solid var(--c-border);
  display: flex; align-items: center; justify-content: space-between;
}
.modal-title { font-size: 1rem; font-weight: 700; }
.modal-close {
  background: none; border: none; cursor: pointer;
  color: var(--c-muted); font-size: 1.2rem; line-height: 1;
  padding: 2px 6px; border-radius: 5px; transition: color .15s;
}
.modal-close:hover { color: var(--c-text); }
.modal-body { padding: 1.4rem; }

/* Alerts */
.alert {
  padding: .75rem 1rem;
  border-radius: 8px;
  font-size: .85rem;
  margin-bottom: 1rem;
  border-left: 3px solid;
}
.alert-error   { background: rgba(251,99,64,.1); border-color: var(--c-warn); color: #ff9280; }
.alert-success { background: rgba(45,206,137,.1); border-color: var(--c-success); color: #5adea3; }
.alert-info    { background: rgba(79,142,247,.1); border-color: var(--c-accent); color: #80aef9; }

/* Empty state */
.empty-state {
  text-align: center;
  padding: 3rem 1rem;
  color: var(--c-muted);
}
.empty-state .empty-icon { font-size: 2.5rem; margin-bottom: .75rem; }
.empty-state p { font-size: .88rem; }

/* Search bar */
.search-bar {
  display: flex; align-items: center; gap: .5rem;
  background: var(--c-card);
  border: 1px solid var(--c-border);
  border-radius: 8px;
  padding: .4rem .75rem;
}
.search-bar input {
  background: none; border: none; color: var(--c-text);
  font-size: .85rem; outline: none; flex: 1; min-width: 0;
  font-family: var(--font);
}
.search-bar input::placeholder { color: var(--c-muted); }

/* Loading */
.spinner {
  display: inline-block;
  width: 20px; height: 20px;
  border: 2px solid var(--c-border);
  border-top-color: var(--c-accent);
  border-radius: 50%;
  animation: spin .6s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
.loading-overlay {
  position: fixed; inset: 0;
  background: var(--c-bg);
  display: flex; align-items: center; justify-content: center;
  z-index: 200;
  flex-direction: column; gap: 1rem;
}

/* Progress bar */
.progress-bar {
  background: var(--c-border);
  border-radius: 99px;
  height: 6px;
  overflow: hidden;
}
.progress-fill {
  height: 100%;
  background: var(--c-accent);
  border-radius: 99px;
  transition: width .3s ease;
}

/* Tabs */
.tabs { display: flex; gap: .25rem; border-bottom: 1px solid var(--c-border); margin-bottom: 1.2rem; }
.tab {
  padding: .55rem 1rem;
  font-size: .85rem; font-weight: 500;
  color: var(--c-muted);
  cursor: pointer;
  border-bottom: 2px solid transparent;
  transition: color .15s, border-color .15s;
}
.tab.active { color: var(--c-accent); border-bottom-color: var(--c-accent); font-weight: 600; }
.tab:hover:not(.active) { color: var(--c-text); }

/* Avatar grid */
.member-avatar {
  width: 32px; height: 32px; border-radius: 50%;
  background: linear-gradient(135deg, var(--c-accent2), var(--c-accent));
  display: inline-flex; align-items: center; justify-content: center;
  font-size: .75rem; font-weight: 700; color: #fff;
  flex-shrink: 0;
}

/* Toasts */
#toast-container {
  position: fixed; bottom: 1.5rem; right: 1.5rem; z-index: 300;
  display: flex; flex-direction: column; gap: .5rem;
}
.toast {
  background: var(--c-card);
  border: 1px solid var(--c-border);
  border-radius: 9px;
  padding: .75rem 1.1rem;
  font-size: .85rem;
  box-shadow: 0 8px 24px rgba(0,0,0,.4);
  display: flex; align-items: center; gap: .6rem;
  animation: slideIn .2s ease;
  max-width: 320px;
}
.toast.success { border-left: 3px solid var(--c-success); }
.toast.error   { border-left: 3px solid var(--c-warn);    }
@keyframes slideIn { from { transform: translateX(20px); opacity: 0; } }

/* Responsive */
@media (max-width: 768px) {
  .sidebar { transform: translateX(-100%); }
  .sidebar.open { transform: translateX(0); }
  .main { margin-left: 0; }
  .form-row { grid-template-columns: 1fr; }
  .stats-grid { grid-template-columns: repeat(2, 1fr); }
}

/* Utilities */
.flex { display: flex; }
.flex-1 { flex: 1; }
.items-center { align-items: center; }
.justify-between { justify-content: space-between; }
.gap-2 { gap: .5rem; }
.gap-3 { gap: .75rem; }
.mb-1 { margin-bottom: .5rem; }
.mb-2 { margin-bottom: 1rem; }
.mb-3 { margin-bottom: 1.5rem; }
.text-muted { color: var(--c-muted); }
.text-sm { font-size: .82rem; }
.text-right { text-align: right; }
.fw-600 { font-weight: 600; }
.fw-700 { font-weight: 700; }
.hidden { display: none !important; }
.w-full { width: 100%; }
.truncate { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.amount { font-variant-numeric: tabular-nums; font-weight: 600; }
.amount-pos { color: var(--c-success); }
.amount-neg { color: var(--c-warn); }
