:root {
    --bg: #0f172a;
    --panel: #ffffff;
    --panel-soft: #f8fafc;
    --text: #0f172a;
    --muted: #64748b;
    --border: #e2e8f0;
    --primary: #2563eb;
    --primary-dark: #1d4ed8;
    --success-bg: #dcfce7;
    --success-text: #166534;
    --danger-bg: #fee2e2;
    --danger-text: #991b1b;
    --shadow: 0 20px 45px rgba(15, 23, 42, 0.12);
    --radius: 20px;
}

* {
    box-sizing: border-box;
}

html {
    min-height: 100%;
    background: #eef2ff;
}

body {
    margin: 0;
    font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
    color: var(--text);
    background: linear-gradient(135deg, #eef2ff 0%, #f8fafc 45%, #e0f2fe 100%);
}

a {
    color: inherit;
    text-decoration: none;
}

code {
    font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", monospace;
    font-size: 0.9em;
}

.app-shell {
    display: grid;
    grid-template-columns: 280px minmax(0, 1fr);
    min-height: 100vh;
}

.sidebar {
    position: sticky;
    top: 0;
    height: 100vh;
    display: flex;
    flex-direction: column;
    gap: 24px;
    padding: 24px;
    color: #e5e7eb;
    background: radial-gradient(circle at top left, #1e40af 0%, #0f172a 42%, #020617 100%);
}

.brand {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 10px;
    border-radius: 18px;
    background: rgba(255, 255, 255, 0.08);
}

.brand-mark,
.login-logo {
    width: 46px;
    height: 46px;
    display: inline-grid;
    place-items: center;
    border-radius: 16px;
    color: #fff;
    background: linear-gradient(135deg, #3b82f6, #06b6d4);
    font-weight: 900;
    box-shadow: 0 12px 30px rgba(59, 130, 246, 0.3);
}

.brand strong,
.brand small {
    display: block;
}

.brand small {
    margin-top: 2px;
    color: #bfdbfe;
}

.nav {
    display: grid;
    gap: 8px;
}

.nav-link {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 12px 14px;
    border-radius: 14px;
    color: #cbd5e1;
    transition: 0.2s ease;
}

.nav-link:hover,
.nav-link.active {
    color: #fff;
    background: rgba(255, 255, 255, 0.12);
    transform: translateX(2px);
}

.sidebar-footer {
    margin-top: auto;
    display: grid;
    gap: 6px;
    padding: 16px;
    border-radius: 16px;
    background: rgba(15, 23, 42, 0.55);
    word-break: break-word;
}

.sidebar-footer small {
    color: #93c5fd;
}

.logout {
    margin-top: 6px;
    color: #fecaca;
    font-weight: 700;
}

.main {
    min-width: 0;
    padding: 28px;
}

.topbar {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 20px;
    margin-bottom: 24px;
}

.topbar h1 {
    margin: 0;
    font-size: clamp(1.7rem, 2.5vw, 2.5rem);
    letter-spacing: -0.04em;
}

.topbar p {
    margin: 6px 0 0;
    color: var(--muted);
}

.pill {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 10px 14px;
    border: 1px solid var(--border);
    border-radius: 999px;
    background: rgba(255, 255, 255, 0.8);
    color: #334155;
    font-weight: 700;
    white-space: nowrap;
}

.stats-grid {
    display: grid;
    grid-template-columns: repeat(4, minmax(0, 1fr));
    gap: 18px;
    margin-bottom: 18px;
}

.stat-card,
.panel {
    border: 1px solid rgba(226, 232, 240, 0.9);
    border-radius: var(--radius);
    background: rgba(255, 255, 255, 0.92);
    box-shadow: var(--shadow);
    backdrop-filter: blur(18px);
}

.stat-card {
    display: flex;
    align-items: center;
    gap: 14px;
    padding: 18px;
}

.stat-icon {
    width: 48px;
    height: 48px;
    display: grid;
    place-items: center;
    border-radius: 16px;
    background: #eff6ff;
    font-size: 1.4rem;
}

.stat-card span,
.stat-card small {
    display: block;
    color: var(--muted);
}

.stat-card strong {
    display: block;
    margin: 3px 0;
    font-size: 1.8rem;
    letter-spacing: -0.04em;
}

.grid-2 {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 18px;
    margin-bottom: 18px;
}

.panel {
    padding: 20px;
    overflow: hidden;
}

.panel-header {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 14px;
    margin-bottom: 16px;
}

.panel h2,
.panel-header h2 {
    margin: 0;
    font-size: 1.14rem;
    letter-spacing: -0.02em;
}

.panel p,
.panel-header p,
.muted {
    color: var(--muted);
}

.panel-header p {
    margin: 5px 0 0;
}

.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    padding: 11px 15px;
    border: 1px solid var(--border);
    border-radius: 13px;
    color: #0f172a;
    background: #fff;
    font-weight: 800;
    cursor: pointer;
    transition: 0.2s ease;
}

.btn:hover {
    transform: translateY(-1px);
    box-shadow: 0 12px 24px rgba(15, 23, 42, 0.1);
}

.btn.primary {
    border-color: var(--primary);
    color: #fff;
    background: var(--primary);
}

.btn.primary:hover {
    background: var(--primary-dark);
}

.btn.small {
    padding: 8px 11px;
    font-size: 0.88rem;
}

.btn.full {
    width: 100%;
}

.table-wrap {
    width: 100%;
    overflow-x: auto;
}

table {
    width: 100%;
    min-width: 760px;
    border-collapse: collapse;
}

th,
td {
    padding: 12px 10px;
    border-bottom: 1px solid var(--border);
    text-align: left;
    vertical-align: top;
}

th {
    color: #475569;
    font-size: 0.78rem;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    background: var(--panel-soft);
}

td small,
.rank-row small {
    display: block;
    margin-top: 3px;
    color: var(--muted);
}

.truncate {
    display: inline-block;
    max-width: 220px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.truncate.wide {
    max-width: 360px;
}

.rank-list,
.activity-list {
    display: grid;
    gap: 10px;
}

.rank-row,
.activity-item {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 14px;
    padding: 12px 14px;
    border: 1px solid var(--border);
    border-radius: 15px;
    background: #fff;
}

.rank-row strong {
    min-width: 42px;
    padding: 6px 10px;
    border-radius: 999px;
    text-align: center;
    color: #1d4ed8;
    background: #dbeafe;
}

.activity-item p {
    margin: 4px 0;
}

.activity-item time {
    color: var(--muted);
    font-size: 0.88rem;
    white-space: nowrap;
}

.empty-state {
    padding: 28px;
    border: 1px dashed #cbd5e1;
    border-radius: 18px;
    text-align: center;
    background: #f8fafc;
}

.empty-state p {
    margin-bottom: 0;
}

.alert {
    margin-bottom: 14px;
    padding: 14px;
    border-radius: 14px;
}

.alert.success {
    color: var(--success-text);
    background: var(--success-bg);
}

.alert.danger {
    color: var(--danger-text);
    background: var(--danger-bg);
}

.filters,
.inline-form,
.stack-form {
    display: grid;
    gap: 14px;
}

.filters {
    grid-template-columns: 1.2fr 1fr 1fr auto;
    align-items: end;
    margin-bottom: 18px;
}

.inline-form {
    display: flex;
    align-items: center;
}

label {
    display: grid;
    gap: 7px;
    color: #334155;
    font-weight: 800;
}

label small {
    color: var(--muted);
    font-weight: 500;
}

input,
select {
    width: 100%;
    min-height: 44px;
    padding: 10px 12px;
    border: 1px solid #cbd5e1;
    border-radius: 12px;
    color: var(--text);
    background: #fff;
    font: inherit;
}

input:focus,
select:focus {
    outline: 3px solid rgba(37, 99, 235, 0.17);
    border-color: var(--primary);
}

.copy-input,
.mini-input {
    font-size: 0.9rem;
    cursor: pointer;
}

.mini-input {
    min-width: 320px;
}

.code-box {
    overflow-x: auto;
    margin: 0;
    padding: 16px;
    border-radius: 16px;
    color: #e2e8f0;
    background: #020617;
    white-space: pre-wrap;
}

.login-body {
    min-height: 100vh;
    display: grid;
    place-items: center;
    padding: 24px;
    background: radial-gradient(circle at top left, #dbeafe 0%, #eff6ff 38%, #f8fafc 100%);
}

.login-card {
    width: min(100%, 430px);
    padding: 28px;
    border: 1px solid var(--border);
    border-radius: 26px;
    background: rgba(255, 255, 255, 0.94);
    box-shadow: var(--shadow);
}

.install-card {
    width: min(100%, 560px);
}

.login-card h1 {
    margin: 16px 0 6px;
    font-size: 1.65rem;
    letter-spacing: -0.04em;
}

.login-card p {
    color: var(--muted);
}

.login-card form {
    display: grid;
    gap: 14px;
    margin-top: 18px;
}

@media (max-width: 1100px) {
    .app-shell {
        grid-template-columns: 1fr;
    }

    .sidebar {
        position: relative;
        height: auto;
    }

    .nav {
        grid-template-columns: repeat(2, minmax(0, 1fr));
    }

    .stats-grid,
    .grid-2 {
        grid-template-columns: 1fr;
    }
}

@media (max-width: 720px) {
    .main,
    .sidebar {
        padding: 18px;
    }

    .topbar,
    .panel-header,
    .rank-row,
    .activity-item {
        flex-direction: column;
        align-items: stretch;
    }

    .stats-grid {
        gap: 12px;
    }

    .filters {
        grid-template-columns: 1fr;
    }

    .nav {
        grid-template-columns: 1fr;
    }

    .mini-input {
        min-width: 240px;
    }
}
