/* ------- Design tokens ------- */
:root {
    --c-bg: #f4f5fb;
    --c-surface: #ffffff;
    --c-surface-soft: #fbfbfd;
    --c-border: #e6e7ee;
    --c-border-soft: #eef0f6;
    --c-text: #0f172a;
    --c-text-muted: #6b7280;
    --c-text-soft: #9ca3af;

    --c-primary: #4f46e5;
    --c-primary-700: #4338ca;
    --c-primary-50: #eef2ff;
    --c-accent: #ec4899;
    --c-teal: #14b8a6;
    --c-amber: #f59e0b;
    --c-success: #10b981;
    --c-success-50: #ecfdf5;
    --c-danger: #ef4444;
    --c-danger-50: #fef2f2;
    --c-slate: #64748b;

    --grad-primary: linear-gradient(135deg, #6366f1 0%, #8b5cf6 50%, #ec4899 100%);
    --grad-soft: linear-gradient(135deg, #eef2ff 0%, #fdf2f8 100%);
    --grad-card: linear-gradient(180deg, #ffffff 0%, #fbfbfd 100%);

    --shadow-xs: 0 1px 2px rgba(15, 23, 42, 0.04);
    --shadow-sm: 0 1px 3px rgba(15, 23, 42, 0.06), 0 1px 2px rgba(15, 23, 42, 0.04);
    --shadow-md: 0 4px 16px -2px rgba(15, 23, 42, 0.08), 0 2px 4px -2px rgba(15, 23, 42, 0.04);
    --shadow-lg: 0 20px 40px -16px rgba(79, 70, 229, 0.18);

    --radius-sm: 8px;
    --radius: 14px;
    --radius-lg: 20px;
}

/* ------- Base ------- */
* {
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

body {
    font-family: "Inter", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
    font-feature-settings: "cv11", "ss01";
    background: var(--c-bg);
    color: var(--c-text);
    background-image:
        radial-gradient(at 0% 0%, rgba(99, 102, 241, 0.08) 0px, transparent 50%),
        radial-gradient(at 100% 0%, rgba(236, 72, 153, 0.05) 0px, transparent 50%);
    background-attachment: fixed;
    min-height: 100vh;
}

a { color: var(--c-primary); }
a:hover { color: var(--c-primary-700); }

/* ------- Navbar ------- */
.app-nav {
    background: rgba(255, 255, 255, 0.85);
    backdrop-filter: saturate(180%) blur(14px);
    -webkit-backdrop-filter: saturate(180%) blur(14px);
    border-bottom: 1px solid var(--c-border-soft);
}
.app-nav .navbar-brand {
    font-weight: 700;
    letter-spacing: -0.01em;
    font-size: 1.1rem;
}
.brand-mark {
    width: 34px;
    height: 34px;
    border-radius: 10px;
    background: var(--grad-primary);
    color: white;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    font-weight: 700;
    margin-right: 10px;
    box-shadow: 0 4px 14px rgba(99, 102, 241, 0.35);
}
.app-nav .nav-link {
    color: var(--c-text-muted);
    font-weight: 500;
    border-radius: 10px;
    padding: 0.45rem 0.9rem;
    transition: all 0.15s ease;
}
.app-nav .nav-link:hover {
    color: var(--c-primary-700);
    background: var(--c-primary-50);
}
.app-nav .nav-link.active {
    color: var(--c-primary-700);
    background: var(--c-primary-50);
}
.app-nav .nav-link i {
    margin-right: 4px;
}

.user-chip {
    display: inline-flex;
    align-items: center;
    gap: 10px;
    padding: 4px 12px 4px 4px;
    border: 1px solid var(--c-border);
    border-radius: 999px;
    background: var(--c-surface);
}
.user-chip .avatar {
    width: 30px;
    height: 30px;
    border-radius: 50%;
    background: var(--grad-primary);
    color: white;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    font-weight: 700;
    font-size: 0.78rem;
}

/* ------- Cards ------- */
.card {
    border: 1px solid var(--c-border-soft);
    border-radius: var(--radius);
    background: var(--grad-card);
    box-shadow: var(--shadow-xs);
}
.card-header {
    background: transparent;
    border-bottom: 1px solid var(--c-border-soft);
    font-weight: 600;
    padding: 0.9rem 1.1rem;
    letter-spacing: -0.005em;
}
.card-header i { color: var(--c-primary); margin-right: 6px; }

/* ------- Buttons ------- */
.btn {
    border-radius: 10px;
    font-weight: 500;
    letter-spacing: -0.005em;
    transition: all 0.15s ease;
}
.btn-primary {
    background: var(--c-primary);
    border-color: var(--c-primary);
    box-shadow: 0 1px 2px rgba(79, 70, 229, 0.2);
}
.btn-primary:hover {
    background: var(--c-primary-700);
    border-color: var(--c-primary-700);
    transform: translateY(-1px);
    box-shadow: 0 4px 12px rgba(79, 70, 229, 0.35);
}
.btn-outline-primary {
    color: var(--c-primary);
    border-color: var(--c-primary);
}
.btn-outline-primary:hover {
    background: var(--c-primary);
    border-color: var(--c-primary);
}
.btn-outline-secondary {
    color: var(--c-text-muted);
    border-color: var(--c-border);
    background: var(--c-surface);
}
.btn-outline-secondary:hover {
    background: var(--c-surface-soft);
    color: var(--c-text);
    border-color: var(--c-border);
}

/* ------- Forms ------- */
.form-control, .form-select {
    border-radius: 10px;
    border-color: var(--c-border);
    background-color: var(--c-surface);
    color: var(--c-text);
    transition: all 0.15s ease;
}
.form-control:focus, .form-select:focus {
    border-color: var(--c-primary);
    box-shadow: 0 0 0 3px rgba(79, 70, 229, 0.15);
}
.input-group-text {
    background: var(--c-surface-soft);
    border-color: var(--c-border);
    color: var(--c-text-muted);
}
.form-label {
    font-weight: 500;
    color: var(--c-text);
    font-size: 0.85rem;
    margin-bottom: 0.35rem;
}

/* ------- Tables ------- */
.table {
    margin-bottom: 0;
    color: var(--c-text);
}
.table > :not(caption) > * > * {
    padding: 0.95rem 1rem;
}
.table thead th {
    background: var(--c-surface-soft);
    color: var(--c-text-soft);
    font-weight: 600;
    font-size: 0.72rem;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    border-bottom: 1px solid var(--c-border-soft);
}
.table tbody tr {
    border-bottom: 1px solid var(--c-border-soft);
}
.table tbody tr:last-child { border-bottom: none; }
.table-hover tbody tr:hover {
    background: var(--c-primary-50);
}

/* ------- Avatars ------- */
.avatar-square {
    width: 40px;
    height: 40px;
    border-radius: 10px;
    color: white;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    font-weight: 700;
    font-size: 0.92rem;
    text-transform: uppercase;
    letter-spacing: -0.02em;
    flex: 0 0 auto;
    box-shadow: 0 2px 6px rgba(15, 23, 42, 0.08);
}
.avatar-lg {
    width: 64px;
    height: 64px;
    border-radius: 16px;
    font-size: 1.6rem;
}

/* Avatar gradient variants */
.avg-1 { background: linear-gradient(135deg, #6366f1, #8b5cf6); }
.avg-2 { background: linear-gradient(135deg, #ec4899, #f43f5e); }
.avg-3 { background: linear-gradient(135deg, #14b8a6, #06b6d4); }
.avg-4 { background: linear-gradient(135deg, #f59e0b, #ef4444); }
.avg-5 { background: linear-gradient(135deg, #8b5cf6, #ec4899); }
.avg-6 { background: linear-gradient(135deg, #06b6d4, #6366f1); }
.avg-7 { background: linear-gradient(135deg, #10b981, #14b8a6); }
.avg-8 { background: linear-gradient(135deg, #f43f5e, #f59e0b); }

/* ------- Status pills ------- */
.status-pill {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 4px 12px;
    border-radius: 999px;
    font-size: 0.78rem;
    font-weight: 600;
    border: 1px solid transparent;
}
.status-pill::before {
    content: "";
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: currentColor;
    flex: 0 0 auto;
}
.status-active {
    background: var(--c-success-50);
    color: #047857;
    border-color: rgba(16, 185, 129, 0.2);
}
.status-danger {
    background: var(--c-danger-50);
    color: #b91c1c;
    border-color: rgba(239, 68, 68, 0.2);
}
.status-neutral {
    background: #f1f5f9;
    color: #475569;
    border-color: #e2e8f0;
}

/* ------- Code badges ------- */
.ciiu-chip {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    padding: 3px 9px;
    border-radius: 6px;
    background: var(--c-primary-50);
    color: var(--c-primary-700);
    font-family: "JetBrains Mono", ui-monospace, SFMono-Regular, Menlo, monospace;
    font-size: 0.78rem;
    font-weight: 600;
    text-decoration: none;
    border: 1px solid rgba(79, 70, 229, 0.12);
    transition: all 0.15s ease;
}
.ciiu-chip:hover {
    background: var(--c-primary);
    color: white;
    transform: translateY(-1px);
}
.ciiu-chip-lg {
    padding: 6px 14px;
    font-size: 0.95rem;
    border-radius: 10px;
}

code {
    color: var(--c-text);
    background: var(--c-surface-soft);
    border: 1px solid var(--c-border-soft);
    padding: 2px 8px;
    border-radius: 6px;
    font-size: 0.85em;
    font-family: "JetBrains Mono", ui-monospace, SFMono-Regular, Menlo, monospace;
}

/* ------- Stat cards ------- */
.stat-card {
    border-radius: var(--radius);
    border: 1px solid var(--c-border-soft);
    background: var(--c-surface);
    padding: 1.1rem 1.2rem;
    display: flex;
    align-items: center;
    gap: 14px;
    box-shadow: var(--shadow-xs);
    transition: all 0.15s ease;
}
.stat-card:hover {
    transform: translateY(-2px);
    box-shadow: var(--shadow-md);
}
.stat-card .stat-icon {
    width: 44px;
    height: 44px;
    border-radius: 12px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    color: white;
    font-size: 1.2rem;
    flex: 0 0 auto;
}
.stat-card .stat-label {
    font-size: 0.78rem;
    color: var(--c-text-muted);
    text-transform: uppercase;
    letter-spacing: 0.05em;
    font-weight: 600;
}
.stat-card .stat-value {
    font-size: 1.5rem;
    font-weight: 700;
    color: var(--c-text);
    letter-spacing: -0.02em;
    line-height: 1.1;
}

/* ------- Page hero ------- */
.page-hero {
    background: var(--c-surface);
    border: 1px solid var(--c-border-soft);
    border-radius: var(--radius-lg);
    padding: 1.6rem 1.8rem;
    box-shadow: var(--shadow-xs);
    margin-bottom: 1.25rem;
    position: relative;
    overflow: hidden;
}
.page-hero::before {
    content: "";
    position: absolute;
    inset: 0;
    background: var(--grad-soft);
    opacity: 0.6;
    z-index: 0;
}
.page-hero > * { position: relative; z-index: 1; }
.page-hero h1 {
    font-weight: 700;
    letter-spacing: -0.02em;
    margin-bottom: 0.2rem;
}
.page-hero .lead-text {
    color: var(--c-text-muted);
    font-size: 0.95rem;
    margin: 0;
}

/* ------- Detail hero ------- */
.detail-hero {
    background: var(--c-surface);
    border: 1px solid var(--c-border-soft);
    border-radius: var(--radius-lg);
    padding: 1.6rem;
    box-shadow: var(--shadow-sm);
    position: relative;
    overflow: hidden;
    margin-bottom: 1rem;
}
.detail-hero::before {
    content: "";
    position: absolute;
    top: -120px;
    right: -120px;
    width: 320px;
    height: 320px;
    background: var(--grad-primary);
    opacity: 0.08;
    border-radius: 50%;
    z-index: 0;
}
.detail-hero > * { position: relative; z-index: 1; }
.detail-hero h1 {
    font-weight: 700;
    letter-spacing: -0.02em;
}

/* ------- Definition lists ------- */
dl.row dt {
    font-weight: 500;
    color: var(--c-text-muted);
    font-size: 0.8rem;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    padding-top: 6px;
}
dl.row dd {
    margin-bottom: 0.75rem;
    color: var(--c-text);
    font-size: 0.94rem;
}

/* ------- Pagination ------- */
.pagination .page-link {
    color: var(--c-text);
    border: 1px solid var(--c-border-soft);
    margin: 0 2px;
    border-radius: 10px;
    min-width: 38px;
    text-align: center;
    background: var(--c-surface);
}
.pagination .page-item.active .page-link {
    background: var(--c-primary);
    border-color: var(--c-primary);
    color: white;
}
.pagination .page-item.disabled .page-link {
    background: transparent;
    color: var(--c-text-soft);
}

/* ------- Breadcrumb ------- */
.breadcrumb {
    font-size: 0.85rem;
    margin-bottom: 0.5rem;
}
.breadcrumb-item a {
    color: var(--c-text-muted);
    text-decoration: none;
}
.breadcrumb-item.active { color: var(--c-text); font-weight: 500; }

/* ------- Alerts ------- */
.alert {
    border: none;
    border-radius: var(--radius);
    box-shadow: var(--shadow-xs);
}
.alert-success {
    background: var(--c-success-50);
    color: #047857;
}
.alert-danger {
    background: var(--c-danger-50);
    color: #b91c1c;
}

/* ------- Login split-screen ------- */
.login-shell {
    min-height: 100vh;
    display: grid;
    grid-template-columns: 1fr;
}
@media (min-width: 992px) {
    .login-shell { grid-template-columns: 5fr 4fr; }
}
.login-side {
    display: none;
    position: relative;
    background: var(--grad-primary);
    color: white;
    padding: 3rem;
    overflow: hidden;
}
@media (min-width: 992px) {
    .login-side { display: flex; flex-direction: column; justify-content: space-between; }
}
.login-side::before {
    content: "";
    position: absolute;
    top: -160px;
    right: -160px;
    width: 460px;
    height: 460px;
    background: rgba(255, 255, 255, 0.12);
    border-radius: 50%;
}
.login-side::after {
    content: "";
    position: absolute;
    bottom: -220px;
    left: -100px;
    width: 480px;
    height: 480px;
    background: rgba(255, 255, 255, 0.08);
    border-radius: 50%;
}
.login-side > * { position: relative; z-index: 1; }
.login-side h2 {
    font-size: 2.2rem;
    font-weight: 700;
    letter-spacing: -0.02em;
    line-height: 1.15;
}
.login-side .features li {
    display: flex;
    align-items: center;
    gap: 12px;
    margin-bottom: 12px;
    opacity: 0.95;
}
.login-side .features i {
    width: 32px;
    height: 32px;
    background: rgba(255, 255, 255, 0.18);
    border-radius: 8px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    flex: 0 0 auto;
}
.login-form-wrap {
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 2rem;
}
.login-card {
    width: 100%;
    max-width: 400px;
}
.login-card h1 {
    font-size: 1.6rem;
    font-weight: 700;
    letter-spacing: -0.02em;
}

/* ------- Empty state ------- */
.empty-state {
    text-align: center;
    padding: 4rem 2rem;
}
.empty-state .empty-icon {
    width: 84px;
    height: 84px;
    border-radius: 50%;
    background: var(--c-primary-50);
    color: var(--c-primary);
    display: inline-flex;
    align-items: center;
    justify-content: center;
    font-size: 2rem;
    margin-bottom: 1rem;
}

/* ------- Misc ------- */
.text-soft { color: var(--c-text-soft); }
.divider { height: 1px; background: var(--c-border-soft); margin: 1rem 0; }

footer.app-footer {
    color: var(--c-text-soft);
    font-size: 0.82rem;
    padding: 2rem 0 3rem;
    text-align: center;
}

@media (max-width: 768px) {
    .page-hero { padding: 1.2rem; }
    .detail-hero { padding: 1.2rem; }
    .stat-card { padding: 0.9rem 1rem; }
    .stat-card .stat-value { font-size: 1.2rem; }
}
