/* ── Reset & base ─────────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
[hidden] { display: none !important; }

:root {
    --bg:        #f1f5f9;
    --surface:   #ffffff;
    --border:    #e2e8f0;
    --primary:   #4f46e5;
    --primary-h: #4338ca;
    --danger:    #ef4444;
    --danger-h:  #dc2626;
    --success:   #22c55e;
    --text:      #1e293b;
    --muted:     #64748b;
    --radius:    8px;
    --shadow:    0 1px 3px rgba(0,0,0,.08), 0 1px 2px rgba(0,0,0,.06);
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    background: var(--bg);
    color: var(--text);
    font-size: 14px;
    line-height: 1.5;
}

/* ── Buttons ──────────────────────────────────────────────────────────── */
.btn {
    display: inline-flex; align-items: center; gap: 6px;
    padding: 8px 16px; border-radius: var(--radius);
    font-size: 14px; font-weight: 500; cursor: pointer;
    border: none; transition: background .15s, opacity .15s;
    text-decoration: none;
}
.btn:disabled { opacity: .6; cursor: not-allowed; }
.btn-primary  { background: var(--primary); color: #fff; }
.btn-primary:hover:not(:disabled)  { background: var(--primary-h); }
.btn-danger   { background: var(--danger);  color: #fff; }
.btn-danger:hover:not(:disabled)   { background: var(--danger-h); }
.btn-ghost    { background: transparent; color: var(--muted); border: 1px solid var(--border); }
.btn-ghost:hover:not(:disabled)    { background: var(--bg); }
.btn-full     { width: 100%; justify-content: center; padding: 10px 16px; font-size: 15px; }
.btn-sm       { padding: 5px 10px; font-size: 12px; }

/* ── Forms ────────────────────────────────────────────────────────────── */
.form-group { margin-bottom: 16px; }
.form-group label { display: block; font-size: 13px; font-weight: 500; margin-bottom: 5px; }
.form-group input {
    width: 100%; padding: 9px 12px;
    border: 1px solid var(--border); border-radius: var(--radius);
    font-size: 16px; font-family: inherit;
    transition: border-color .15s;
    background: var(--surface);
}
.form-group input:focus { outline: none; border-color: var(--primary); }
.form-error {
    font-size: 13px; color: var(--danger);
    background: #fef2f2; border: 1px solid #fecaca;
    border-radius: var(--radius); padding: 8px 12px;
    margin-bottom: 12px;
}
.form-success {
    font-size: 13px; color: #15803d;
    background: #f0fdf4; border: 1px solid #bbf7d0;
    border-radius: var(--radius); padding: 8px 12px;
    margin-bottom: 12px;
}

/* ── Auth page ────────────────────────────────────────────────────────── */
.auth-page {
    min-height: 100vh;
    display: flex; align-items: center; justify-content: center;
    padding: 24px 16px;
}
.auth-card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 12px;
    padding: 36px 32px;
    width: 100%; max-width: 400px;
    box-shadow: 0 4px 24px rgba(0,0,0,.08);
}
.auth-logo {
    font-size: 22px; font-weight: 800;
    color: var(--primary); margin-bottom: 6px;
}
.auth-title {
    font-size: 20px; font-weight: 700;
    margin-bottom: 24px; color: var(--text);
}
.auth-form { margin-top: 20px; }
.auth-footer {
    text-align: center; margin-top: 20px;
    color: var(--muted); font-size: 13px;
}
.auth-footer a { color: var(--primary); text-decoration: none; font-weight: 500; }
.auth-footer a:hover { text-decoration: underline; }

/* ── Role badge ───────────────────────────────────────────────────────── */
.role-badge {
    display: inline-block;
    padding: 1px 8px;
    border-radius: 999px;
    font-size: 11px; font-weight: 600;
    text-transform: uppercase; letter-spacing: .04em;
    vertical-align: middle; margin-left: 6px;
}
.role-user  { background: #e0f2fe; color: #0369a1; }
.role-admin { background: #fef3c7; color: #92400e; }
.you-badge  {
    display: inline-block;
    padding: 1px 8px; border-radius: 999px;
    font-size: 11px; font-weight: 600;
    text-transform: uppercase; letter-spacing: .04em;
    vertical-align: middle; margin-left: 8px;
    background: #f0fdf4; color: #15803d;
    border: 1px solid #bbf7d0;
}

/* ── App header ───────────────────────────────────────────────────────── */
.app-header {
    position: fixed; top: 0; left: 0; right: 0; height: 56px;
    display: flex; align-items: center; gap: 16px;
    padding: 0 20px;
    background: var(--surface);
    border-bottom: 1px solid var(--border);
    z-index: 200;
}
.header-logo {
    font-size: 17px; font-weight: 800;
    color: var(--primary); flex-shrink: 0;
}
.header-nav { display: flex; gap: 4px; flex: 1; }
.header-nav-item {
    display: inline-flex; align-items: center; gap: 7px;
    padding: 6px 12px; border-radius: var(--radius);
    color: var(--muted); font-size: 14px; font-weight: 500;
    text-decoration: none; transition: background .15s, color .15s;
}
.header-nav-item:hover  { background: var(--bg); color: var(--text); }
.header-nav-item.active { background: #eef2ff; color: var(--primary); }
.header-user {
    display: flex; align-items: center;
    margin-left: auto; flex-shrink: 0;
}
.header-avatar-wrap { position: relative; }
.header-avatar {
    width: 34px; height: 34px; border-radius: 50%;
    display: flex; align-items: center; justify-content: center;
    font-size: 14px; font-weight: 700; color: #fff;
    background: var(--primary);
    border: none; cursor: pointer;
    transition: opacity .15s;
}
.header-avatar:hover { opacity: .85; }


.header-menu {
    position: absolute; top: calc(100% + 8px); right: 0;
    background: var(--surface); border: 1px solid var(--border);
    border-radius: var(--radius); min-width: 190px;
    box-shadow: 0 4px 16px rgba(0,0,0,.1);
    z-index: 300; overflow: hidden;
}
.header-menu-info {
    padding: 12px 14px 10px;
    display: flex; align-items: center; gap: 8px; overflow: hidden;
}
.header-menu-name { font-size: 13px; font-weight: 600; color: var(--text); min-width: 0; max-width: 150px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.header-menu-divider { height: 1px; background: var(--border); margin: 0; }
.header-menu-item {
    display: flex; align-items: center; gap: 9px;
    width: 100%; padding: 10px 14px;
    font-size: 13px; font-weight: 500; color: var(--text);
    text-decoration: none; background: none; border: none;
    cursor: pointer; text-align: left;
    transition: background .12s;
}
.header-menu-item:hover { background: var(--bg); }

/* ── App shell (post-login layout) ───────────────────────────────────── */
.app-shell { display: flex; min-height: 100vh; padding-top: 56px; }

.main {
    padding: 28px 32px;
    flex: 1; min-height: 100vh;
    max-width: 1200px; margin: 0 auto; width: 100%;
}

/* ── Profile page ─────────────────────────────────────────────────────── */
.profile-page   { max-width: 560px; display: flex; flex-direction: column; gap: 24px; }
.profile-card   {
    display: flex; align-items: center; gap: 20px;
    background: var(--surface); border: 1px solid var(--border);
    border-radius: var(--radius); padding: 24px;
    box-shadow: var(--shadow);
}
.profile-avatar {
    width: 64px; height: 64px; border-radius: 50%; flex-shrink: 0;
    display: flex; align-items: center; justify-content: center;
    font-size: 22px; font-weight: 700; color: #fff;
    background: var(--primary);
}
.profile-info     { min-width: 0; }
.profile-name-row { display: flex; align-items: center; gap: 8px; min-width: 0; }
.profile-name-row .role-badge,
.profile-name-row .you-badge  { vertical-align: unset; margin-left: 0; flex-shrink: 0; }
.profile-name     { font-size: 18px; font-weight: 700; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; min-width: 0; }
.profile-email    { font-size: 13px; color: var(--muted); margin-top: 2px; }
.profile-meta-row { display: flex; align-items: center; gap: 10px; margin-top: 8px; flex-wrap: wrap; }
.profile-meta     { font-size: 12px; color: var(--muted); }
.profile-section  {
    background: var(--surface); border: 1px solid var(--border);
    border-radius: var(--radius); padding: 24px;
    box-shadow: var(--shadow);
}
.section-title    { font-size: 15px; font-weight: 600; margin-bottom: 16px; }
.danger-zone      { border-color: var(--danger); }
.danger-zone .section-title { color: var(--danger); }
.danger-zone-desc { font-size: 13px; color: var(--muted); margin-bottom: 16px; }

/* ── Admin section (profile page) ────────────────────────────────────── */
.admin-section    { border-color: #f97316; }
.admin-section > .section-title { color: #c2410c; }
.admin-subsection {
    background: var(--surface); border: 1px solid var(--border);
    border-radius: var(--radius); padding: 20px 24px;
    box-shadow: var(--shadow); margin-top: 16px;
}
.admin-subsection:first-of-type { margin-top: 0; }
.subsection-title { font-size: 14px; font-weight: 600; margin-bottom: 14px; color: var(--text); }
.danger-title     { color: var(--danger); }
.admin-delete-error { margin-top: 10px; }

/* ── Section card (shared) ────────────────────────────────────────────── */
.section-card {
    background: var(--surface); border: 1px solid var(--border);
    border-radius: var(--radius); box-shadow: var(--shadow);
    overflow: hidden;
}

/* ── Users page ───────────────────────────────────────────────────────── */
.users-page   { max-width: 800px; }
.users-header {
    display: flex; align-items: center; justify-content: space-between;
    padding: 20px 24px; border-bottom: 1px solid var(--border);
}
.users-total  { font-size: 13px; color: var(--muted); }
.users-title  { margin: 0; }

.users-table  { width: 100%; border-collapse: collapse; }
.users-table th {
    text-align: left; padding: 10px 24px;
    font-size: 12px; font-weight: 600; color: var(--muted);
    text-transform: uppercase; letter-spacing: .04em;
    background: var(--bg); border-bottom: 1px solid var(--border);
}
.users-table th.sortable { cursor: pointer; user-select: none; white-space: nowrap; }
.users-table th.sortable:hover { color: var(--text); }
.users-table th.sort-asc::after  { content: ' ↓'; color: var(--primary); }
.users-table th.sort-desc::after { content: ' ↑'; color: var(--primary); }
.users-table th.sort-invert.sort-asc::after  { content: ' ↑'; color: var(--primary); }
.users-table th.sort-invert.sort-desc::after { content: ' ↓'; color: var(--primary); }
.users-table td { padding: 12px 24px; border-bottom: 1px solid var(--border); vertical-align: middle; }
.users-table tr:last-child td { border-bottom: none; }
.users-table tbody tr.users-row { cursor: pointer; }
.users-table tbody tr:hover td { background: var(--bg); }

.users-username { font-size: 14px; font-weight: 500; color: var(--text); display: inline-block; max-width: 180px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; vertical-align: middle; }
.users-email    { font-size: 13px; color: var(--muted); }
.users-date     { font-size: 13px; color: var(--muted); white-space: nowrap; }
.users-state    { text-align: center; padding: 40px 24px; color: var(--muted); font-size: 14px; }

.users-pagination {
    display: flex; align-items: center; justify-content: center; gap: 16px;
    padding: 16px 24px; border-top: 1px solid var(--border);
}
.users-page-info { font-size: 13px; color: var(--muted); }

/* ── Dashboard placeholder ────────────────────────────────────────────── */
.dashboard-placeholder {
    display: flex; flex-direction: column; align-items: center; justify-content: center;
    min-height: 360px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    color: var(--muted);
    box-shadow: var(--shadow);
}
.dashboard-placeholder svg { margin-bottom: 16px; opacity: .35; }
.dashboard-placeholder p   { font-size: 15px; }

/* ── Throbber ─────────────────────────────────────────────────────────── */
.throbber {
    display: flex; align-items: center; justify-content: center;
    padding: 48px 0;
}
.throbber::after {
    content: '';
    width: 28px; height: 28px;
    border: 3px solid var(--border);
    border-top-color: var(--primary);
    border-radius: 50%;
    animation: spin .7s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ── Splash / loading ─────────────────────────────────────────────────── */
.splash {
    min-height: 100vh;
    display: flex; align-items: center; justify-content: center;
    color: var(--muted); font-size: 15px;
}

/* ── Toast ────────────────────────────────────────────────────────────── */
#toast {
    position: fixed; bottom: 24px; right: 24px;
    padding: 12px 20px; border-radius: var(--radius);
    color: #fff; font-size: 14px; font-weight: 500;
    box-shadow: 0 4px 12px rgba(0,0,0,.2);
    transform: translateY(80px); opacity: 0;
    transition: transform .25s ease, opacity .25s ease;
    z-index: 500; pointer-events: none;
}
#toast.show    { transform: translateY(0); opacity: 1; }
#toast.success { background: var(--success); }
#toast.error   { background: var(--danger); }

/* ── Responsive ───────────────────────────────────────────────────────── */
@media (max-width: 768px) {
    .main            { padding: 20px 16px; }
    .auth-card       { padding: 28px 20px; }

    /* Hide Email + Joined columns on small screens */
    .users-table th:nth-child(2),
    .users-table td:nth-child(2),
    .users-table th:nth-child(4),
    .users-table td:nth-child(4) { display: none; }
}
