/* ── Design Tokens ───────────────────────────────────────── */
:root {
    --bg:          #080b14;
    --surface:     #0f1623;
    --surface-2:   #161d2e;
    --border:      #1e2d45;
    --primary:     #60a5fa;
    --primary-d:   #3b82f6;
    --success:     #34d399;
    --danger:      #f87171;
    --warn:        #fbbf24;
    --purple:      #a78bfa;
    --text:        #e2e8f0;
    --muted:       #64748b;
    --radius:      14px;
}

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

body {
    font-family: 'Inter', sans-serif;
    background: var(--bg);
    color: var(--text);
    min-height: 100vh;
}

/* ── Back / TS Badge ─────────────────────────────────────── */
.back-link {
    position: fixed; top: 1.25rem; left: 1.25rem; z-index: 20;
    text-decoration: none; color: var(--muted);
    font-size: .875rem; font-weight: 500;
    display: flex; align-items: center; gap: .45rem;
    transition: color .2s;
}
.back-link:hover { color: var(--text); }

.ts-badge {
    position: fixed; top: 1.25rem; right: 1.25rem; z-index: 20;
    background: var(--primary-d); color: #fff;
    border-radius: 8px; width: 38px; height: 38px;
    display: flex; align-items: center; justify-content: center;
    font-size: .78rem; font-weight: 700; letter-spacing: .05em;
    box-shadow: 0 0 16px rgba(59,130,246,.4);
}

/* ── Layout ──────────────────────────────────────────────── */
.page-layout {
    display: grid;
    grid-template-columns: 320px 1fr;
    min-height: 100vh;
}

/* ── Sidebar ─────────────────────────────────────────────── */
.sidebar {
    background: var(--surface);
    border-right: 1px solid var(--border);
    padding: 5rem 1.75rem 2rem;
    display: flex; flex-direction: column; gap: 2rem;
    position: sticky; top: 0; height: 100vh; overflow-y: auto;
}

.sidebar-header h1 {
    font-size: 1.45rem; font-weight: 700;
    background: linear-gradient(90deg, var(--primary), var(--purple));
    -webkit-background-clip: text; background-clip: text;
    -webkit-text-fill-color: transparent;
}
.sidebar-header .subtitle { color: var(--muted); font-size: .85rem; margin-top: .25rem; }

/* ── Add User Form ───────────────────────────────────────── */
.user-form { display: flex; flex-direction: column; gap: 1rem; }

.form-title {
    font-size: 1rem; font-weight: 600; color: var(--text);
    display: flex; align-items: center; gap: .5rem;
    margin-bottom: .25rem;
}
.form-title i { color: var(--primary); }

.form-group { display: flex; flex-direction: column; gap: .4rem; }
.form-group label { font-size: .8rem; font-weight: 500; color: var(--muted); }

input[type="text"], input[type="email"], select {
    width: 100%; padding: .7rem .9rem;
    background: var(--surface-2); border: 1px solid var(--border);
    border-radius: 9px; color: var(--text);
    font-family: inherit; font-size: .9rem; outline: none;
    transition: border-color .2s, box-shadow .2s;
}
input::placeholder { color: var(--muted); }
input:focus, select:focus {
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(96,165,250,.12);
}
select { cursor: pointer; }

.form-row { display: grid; grid-template-columns: 1fr 1fr; gap: .75rem; }

.form-error {
    font-size: .82rem; color: var(--danger);
    background: rgba(248,113,113,.08);
    border: 1px solid rgba(248,113,113,.2);
    border-radius: 8px; padding: .6rem .85rem;
}

.submit-btn {
    width: 100%; padding: .8rem;
    background: var(--primary-d); color: #fff; border: none;
    border-radius: 9px; font-family: inherit; font-size: .95rem;
    font-weight: 600; cursor: pointer;
    display: flex; align-items: center; justify-content: center; gap: .5rem;
    transition: background .2s, transform .1s, box-shadow .2s;
    box-shadow: 0 4px 14px rgba(59,130,246,.3);
}
.submit-btn:hover { background: var(--primary); box-shadow: 0 6px 20px rgba(96,165,250,.4); }
.submit-btn:active { transform: scale(.97); }

/* ── TS Topics ───────────────────────────────────────────── */
.ts-topics { margin-top: auto; }
.topics-label { font-size: .75rem; font-weight: 600; color: var(--muted); text-transform: uppercase; letter-spacing: .06em; margin-bottom: .6rem; }
.topic-tags { display: flex; flex-wrap: wrap; gap: .45rem; }
.topic-tag {
    font-size: .72rem; font-weight: 500;
    padding: .25rem .6rem; border-radius: 9999px;
    background: rgba(96,165,250,.1); color: var(--primary);
    border: 1px solid rgba(96,165,250,.2);
}

/* ── Main Panel ──────────────────────────────────────────── */
.main-panel {
    padding: 5rem 2rem 2rem;
    display: flex; flex-direction: column; gap: 1.5rem;
    overflow-y: auto;
}

/* ── Toolbar ─────────────────────────────────────────────── */
.toolbar {
    display: flex; align-items: center; justify-content: space-between;
    flex-wrap: wrap; gap: .75rem;
}
.toolbar-left h2 {
    font-size: 1.25rem; font-weight: 700;
    display: flex; align-items: center; gap: .6rem;
}
.count-badge {
    font-size: .8rem; font-weight: 600;
    background: rgba(96,165,250,.15); color: var(--primary);
    border: 1px solid rgba(96,165,250,.25);
    padding: .15rem .6rem; border-radius: 9999px;
}

.toolbar-right {
    display: flex; align-items: center; gap: .6rem; flex-wrap: wrap;
}
.search-wrap { position: relative; }
.search-wrap i {
    position: absolute; left: .8rem; top: 50%; transform: translateY(-50%);
    color: var(--muted); font-size: .85rem; pointer-events: none;
}
.search-wrap input {
    padding: .6rem .85rem .6rem 2.25rem;
    border-radius: 9999px; font-size: .875rem; width: 210px;
}
.toolbar-right select {
    padding: .6rem .85rem; border-radius: 9999px;
    font-size: .875rem; width: auto;
}

/* ── User Grid ───────────────────────────────────────────── */
.user-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
    gap: 1.25rem;
}

/* ── User Card ───────────────────────────────────────────── */
.user-card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 1.5rem 1.25rem 1.25rem;
    position: relative;
    display: flex; flex-direction: column; align-items: center;
    gap: .875rem; text-align: center;
    transition: transform .2s, box-shadow .2s, border-color .2s;
    animation: popIn .25s ease;
}
.user-card:hover {
    transform: translateY(-4px);
    box-shadow: 0 12px 30px rgba(0,0,0,.4);
    border-color: rgba(96,165,250,.3);
}

@keyframes popIn {
    from { opacity: 0; transform: scale(.95); }
    to   { opacity: 1; transform: scale(1); }
}

.delete-user-btn {
    position: absolute; top: .75rem; right: .75rem;
    background: none; border: none; cursor: pointer;
    color: var(--muted); font-size: .9rem; padding: .3rem;
    opacity: 0; transition: opacity .2s, color .2s;
    border-radius: 6px;
}
.user-card:hover .delete-user-btn { opacity: 1; }
.delete-user-btn:hover { color: var(--danger); background: rgba(248,113,113,.1); }

.user-avatar {
    width: 62px; height: 62px; border-radius: 50%;
    display: flex; align-items: center; justify-content: center;
    font-size: 1.3rem; font-weight: 700; color: #fff;
    box-shadow: 0 0 0 3px rgba(255,255,255,.08);
    flex-shrink: 0;
}

.user-info { width: 100%; display: flex; flex-direction: column; gap: .4rem; }
.user-name { font-size: 1rem; font-weight: 600; }
.user-email, .user-dept {
    font-size: .8rem; color: var(--muted);
    display: flex; align-items: center; justify-content: center; gap: .35rem;
    white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.user-meta {
    display: flex; align-items: center; justify-content: center;
    gap: .5rem; margin-top: .25rem; flex-wrap: wrap;
}

/* ── Role Badges ─────────────────────────────────────────── */
.role-badge {
    font-size: .7rem; font-weight: 700; letter-spacing: .05em;
    padding: .2rem .6rem; border-radius: 9999px; text-transform: capitalize;
}
.badge-admin  { background: rgba(167,139,250,.15); color: var(--purple); border: 1px solid rgba(167,139,250,.3); }
.badge-editor { background: rgba(96,165,250,.15);  color: var(--primary); border: 1px solid rgba(96,165,250,.3); }
.badge-viewer { background: rgba(52,211,153,.15);  color: var(--success); border: 1px solid rgba(52,211,153,.3); }

.join-date {
    font-size: .72rem; color: var(--muted);
    display: flex; align-items: center; gap: .3rem;
}

/* ── Empty State ─────────────────────────────────────────── */
.empty-state {
    flex-direction: column; align-items: center; justify-content: center;
    gap: 1rem; padding: 4rem 1rem; color: var(--muted);
    text-align: center;
}
.empty-state i { font-size: 3rem; color: var(--border); }

/* ── Responsive ──────────────────────────────────────────── */
@media (max-width: 820px) {
    .page-layout { grid-template-columns: 1fr; }
    .sidebar {
        position: static; height: auto;
        padding-top: 4rem;
    }
    .main-panel { padding-top: 1.5rem; }
    .toolbar { flex-direction: column; align-items: flex-start; }
    .toolbar-right { width: 100%; }
    .search-wrap { flex: 1; }
    .search-wrap input { width: 100%; }
}
