/*  Design tokens ─ */
:root {
    --bg: #0c0e12;
    --surf: #12151a;
    --surf2: #181c24;
    --surf3: #1e2330;
    --border: #232838;
    --border2: #2a3040;
    --text: #e6e9f0;
    --text2: #848ca0;
    --text3: #50576a;
    --accent: #3b82f6;
    --accent2: #2563eb;
    --green: #22c55e;
    --amber: #f59e0b;
    --red: #ef4444;
    --r: 8px;
    --r-sm: 5px;
    --font: 'DM Sans', system-ui, sans-serif;
    --mono: 'DM Mono', 'Fira Mono', monospace;
    --sidebar-w: 216px;
}

/*  Reset ─ */
*, *::before, *::after {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

html, body {
    height: 100%;
    background: var(--bg);
    color: var(--text);
    font-family: var(--font);
    font-size: 14px;
    line-height: 1.5;
}

a {
    color: var(--accent);
    text-decoration: none;
}

    a:hover {
        text-decoration: underline;
    }

button {
    font-family: var(--font);
}

/*  Fonts (loaded from App.razor via Google Fonts)  */
@import url('https://fonts.googleapis.com/css2?family=DM+Mono:wght@400;500&family=DM+Sans:wght@300;400;500;600&display=swap');

/*  Shell: sidebar + main ─ */
.ri-shell {
    display: flex;
    min-height: 100vh;
}

/*  Sidebar ─ */
.ri-sidebar {
    width: var(--sidebar-w);
    min-height: 100vh;
    background: var(--surf);
    border-right: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    position: fixed;
    top: 0;
    left: 0;
    bottom: 0;
    z-index: 10;
}

.ri-logo {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 22px 18px 18px;
    border-bottom: 1px solid var(--border);
}

.ri-logo-icon {
    font-size: 18px;
    background: var(--accent);
    width: 30px;
    height: 30px;
    border-radius: var(--r-sm);
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}

.ri-logo-text {
    font-weight: 600;
    font-size: 15px;
    letter-spacing: -.01em;
}

.ri-nav {
    padding: 10px 10px;
    display: flex;
    flex-direction: column;
    gap: 2px;
    flex: 1;
}

.ri-nav-item {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 9px 11px;
    border-radius: var(--r-sm);
    color: var(--text2);
    font-size: 13.5px;
    font-weight: 500;
    transition: all .13s;
    text-decoration: none;
}

    .ri-nav-item:hover {
        background: var(--surf2);
        color: var(--text);
        text-decoration: none;
    }

    .ri-nav-item.active {
        background: rgba(59,130,246,.13);
        color: var(--accent);
    }

.ri-nav-icon {
    font-size: 14px;
    width: 18px;
    text-align: center;
    flex-shrink: 0;
}

.ri-sidebar-footer {
    padding: 14px 10px;
    border-top: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    gap: 9px;
}

.ri-user {
    display: flex;
    align-items: center;
    gap: 9px;
}

.ri-avatar {
    width: 30px;
    height: 30px;
    border-radius: 50%;
    background: var(--accent2);
    color: #fff;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 12px;
    font-weight: 600;
    flex-shrink: 0;
}

.ri-user-name {
    font-size: 13px;
    font-weight: 500;
}

.ri-user-plan {
    font-size: 11px;
    color: var(--text3);
}

.ri-logout {
    background: none;
    border: 1px solid var(--border2);
    color: var(--text2);
    border-radius: var(--r-sm);
    padding: 6px 10px;
    font-size: 12.5px;
    cursor: pointer;
    transition: all .13s;
    text-align: left;
}

    .ri-logout:hover {
        border-color: var(--red);
        color: var(--red);
    }

/*  Main content area ─ */
.ri-main {
    margin-left: var(--sidebar-w);
    flex: 1;
    padding: 30px 34px;
    max-width: calc(var(--sidebar-w) + 900px);
}

/*  Page header ─ */
.ri-page-header {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    margin-bottom: 26px;
}

.ri-title {
    font-size: 21px;
    font-weight: 600;
    letter-spacing: -.02em;
}

.ri-subtitle {
    color: var(--text2);
    font-size: 13px;
    margin-top: 3px;
}

/*  Plan badge  */
.ri-plan-badge {
    padding: 3px 10px;
    border-radius: 20px;
    font-size: 11px;
    font-weight: 600;
    letter-spacing: .04em;
    text-transform: uppercase;
}

.ri-plan-free {
    background: rgba(132,140,160,.14);
    color: var(--text2);
}

.ri-plan-basic {
    background: rgba(59,130,246,.14);
    color: var(--accent);
}

.ri-plan-pro {
    background: rgba(34,197,94,.14);
    color: var(--green);
}

/*  Stat cards  */
.ri-stats-row {
    display: grid;
    grid-template-columns: repeat(3,1fr);
    gap: 14px;
    margin-bottom: 18px;
}

.ri-stat-card {
    background: var(--surf);
    border: 1px solid var(--border);
    border-radius: var(--r);
    padding: 18px;
    display: flex;
    align-items: center;
    gap: 14px;
}

.ri-stat-icon {
    width: 38px;
    height: 38px;
    border-radius: var(--r-sm);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 17px;
    flex-shrink: 0;
}

.ri-icon-blue {
    background: rgba(59,130,246,.12);
}

.ri-icon-green {
    background: rgba(34,197,94,.12);
}

.ri-icon-amber {
    background: rgba(245,158,11,.12);
}

.ri-stat-value {
    font-size: 22px;
    font-weight: 600;
    letter-spacing: -.02em;
}

.ri-stat-label {
    font-size: 11.5px;
    color: var(--text2);
    margin-top: 2px;
}

/*  Quota bar ─ */
.ri-quota-header, .ri-quota-foot {
    display: flex;
    justify-content: space-between;
    font-size: 12px;
    color: var(--text2);
}

.ri-quota-header {
    margin-bottom: 10px;
}

.ri-quota-foot {
    margin-top: 7px;
}

.ri-bar-track {
    height: 5px;
    background: var(--surf2);
    border-radius: 3px;
    overflow: hidden;
}

.ri-bar-fill {
    height: 100%;
    border-radius: 3px;
    transition: width .6s ease;
}

.ri-bar-green {
    background: var(--green);
}

.ri-bar-amber {
    background: var(--amber);
}

.ri-bar-red {
    background: var(--red);
}

.ri-warn {
    color: var(--amber);
}

/*  Generic card  */
.ri-card {
    background: var(--surf);
    border: 1px solid var(--border);
    border-radius: var(--r);
    padding: 22px;
    margin-bottom: 18px;
}

.ri-card-title {
    font-size: 14px;
    font-weight: 600;
    margin-bottom: 14px;
}

.ri-section-title {
    font-size: 14px;
    font-weight: 600;
    margin: 22px 0 12px;
    color: var(--text);
}

.ri-hint-card {
    margin-top: 6px;
}

/*  Table ─ */
.ri-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 13px;
}

    .ri-table th {
        text-align: left;
        padding: 7px 10px;
        color: var(--text3);
        font-weight: 500;
        font-size: 11px;
        letter-spacing: .03em;
        text-transform: uppercase;
        border-bottom: 1px solid var(--border);
    }

    .ri-table td {
        padding: 11px 10px;
        border-bottom: 1px solid var(--border);
        color: var(--text2);
    }

    .ri-table tr:last-child td {
        border-bottom: none;
    }

    .ri-table tr:hover td {
        background: var(--surf2);
    }

.ri-mono {
    font-family: var(--mono);
    font-size: 12px;
}

code {
    font-family: var(--mono);
    font-size: 12px;
    background: var(--surf2);
    padding: 2px 5px;
    border-radius: 3px;
    color: var(--accent);
}

/*  Badges  */
.ri-badge {
    display: inline-flex;
    padding: 2px 7px;
    border-radius: 4px;
    font-size: 11px;
    font-weight: 600;
}

.ri-badge-green {
    background: rgba(34,197,94,.12);
    color: var(--green);
}

.ri-badge-amber {
    background: rgba(245,158,11,.12);
    color: var(--amber);
}

.ri-badge-red {
    background: rgba(239,68,68,.12);
    color: var(--red);
}

/*  Buttons ─ */
.ri-btn {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 8px 16px;
    border-radius: var(--r-sm);
    font-size: 13.5px;
    font-weight: 500;
    cursor: pointer;
    border: none;
    transition: all .13s;
}

    .ri-btn:disabled {
        opacity: .5;
        cursor: not-allowed;
    }

.ri-btn-primary {
    background: var(--accent);
    color: #fff;
}

    .ri-btn-primary:hover:not(:disabled) {
        background: var(--accent2);
    }

.ri-btn-ghost {
    background: var(--surf2);
    color: var(--text2);
    border: 1px solid var(--border2);
}

    .ri-btn-ghost:hover:not(:disabled) {
        color: var(--text);
        border-color: var(--text3);
    }

.ri-btn-danger:hover {
    border-color: var(--red) !important;
    color: var(--red) !important;
}

.ri-btn-full {
    width: 100%;
    justify-content: center;
}

.ri-btn-sm {
    padding: 4px 9px;
    font-size: 12px;
}

/*  Forms ─ */
.ri-field {
    margin-bottom: 14px;
}

    .ri-field label {
        display: block;
        font-size: 12.5px;
        font-weight: 500;
        color: var(--text2);
        margin-bottom: 5px;
    }

.ri-optional {
    color: var(--text3);
    font-weight: 400;
}

.ri-input {
    width: 100%;
    background: var(--surf2);
    border: 1px solid var(--border2);
    border-radius: var(--r-sm);
    color: var(--text);
    font-family: var(--font);
    font-size: 13.5px;
    padding: 9px 12px;
    outline: none;
    transition: border-color .13s;
}

    .ri-input:focus {
        border-color: var(--accent);
    }

    .ri-input::placeholder {
        color: var(--text3);
    }

/*  Alerts  */
.ri-alert {
    padding: 11px 14px;
    border-radius: var(--r-sm);
    font-size: 13px;
    margin-bottom: 14px;
}

.ri-alert-error {
    background: rgba(239,68,68,.09);
    border: 1px solid rgba(239,68,68,.28);
    color: #fca5a5;
}

.ri-alert-success {
    background: rgba(34,197,94,.09);
    border: 1px solid rgba(34,197,94,.28);
    color: #86efac;
}

.ri-newkey-row {
    display: flex;
    align-items: center;
    gap: 8px;
    background: var(--surf2);
    border-radius: var(--r-sm);
    padding: 8px 10px;
    margin-top: 8px;
}

    .ri-newkey-row code {
        flex: 1;
        background: none;
        padding: 0;
        word-break: break-all;
    }

/*  Auth pages  */
.ri-auth-page {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--bg);
    padding: 24px;
}

.ri-auth-card {
    background: var(--surf);
    border: 1px solid var(--border);
    border-radius: 12px;
    padding: 34px 38px;
    width: 100%;
    max-width: 390px;
}

.ri-auth-header {
    text-align: center;
    margin-bottom: 26px;
}

.ri-auth-logo {
    font-size: 26px;
    display: block;
    margin-bottom: 10px;
}

.ri-auth-header h1 {
    font-size: 21px;
    font-weight: 600;
    letter-spacing: -.02em;
    margin-bottom: 5px;
}

.ri-auth-header p {
    color: var(--text2);
    font-size: 13px;
}

.ri-auth-links {
    display: flex;
    gap: 7px;
    justify-content: center;
    margin-top: 18px;
    font-size: 13px;
    color: var(--text2);
}

/*  Modal ─ */
.ri-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,.65);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 50;
}

.ri-modal {
    background: var(--surf);
    border: 1px solid var(--border2);
    border-radius: 12px;
    padding: 26px 30px;
    width: 100%;
    max-width: 400px;
}

.ri-modal-title {
    font-size: 16px;
    font-weight: 600;
    margin-bottom: 18px;
}

.ri-modal-actions {
    display: flex;
    justify-content: flex-end;
    gap: 8px;
    margin-top: 18px;
}

/*  Quick actions row ─ */
.ri-actions-row {
    display: grid;
    grid-template-columns: repeat(3,1fr);
    gap: 12px;
    margin-top: 18px;
}

.ri-action-card {
    background: var(--surf);
    border: 1px solid var(--border);
    border-radius: var(--r);
    padding: 16px;
    display: flex;
    align-items: center;
    gap: 12px;
    color: var(--text2);
    text-decoration: none;
    transition: all .13s;
}

    .ri-action-card:hover {
        border-color: var(--accent);
        color: var(--text);
        text-decoration: none;
    }

.ri-action-icon {
    font-size: 20px;
}

.ri-action-title {
    font-size: 13px;
    font-weight: 600;
    color: var(--text);
}

.ri-action-desc {
    font-size: 12px;
    color: var(--text3);
    margin-top: 1px;
}

/*  Subscription  */
.ri-current-plan {
}

.ri-plan-top {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    margin-bottom: 18px;
}

.ri-plan-label {
    font-size: 11px;
    color: var(--text3);
    text-transform: uppercase;
    letter-spacing: .04em;
}

.ri-plan-name {
    font-size: 20px;
    font-weight: 600;
    margin-top: 3px;
}

.ri-features {
    display: flex;
    flex-direction: column;
    gap: 9px;
    margin-bottom: 18px;
}

.ri-feature {
    display: flex;
    align-items: center;
    gap: 9px;
    font-size: 13.5px;
    color: var(--text2);
}

.ri-feat-yes {
    color: var(--green);
    font-weight: 600;
}

.ri-feat-no {
    color: var(--red);
    font-weight: 600;
}

.ri-plans-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit,minmax(210px,1fr));
    gap: 14px;
}

.ri-plan-card {
    background: var(--surf);
    border: 1px solid var(--border);
    border-radius: var(--r);
    padding: 22px;
    position: relative;
}

.ri-plan-card-featured {
    border-color: var(--accent);
    background: rgba(59,130,246,.04);
}

.ri-plan-card-badge {
    position: absolute;
    top: -1px;
    right: 18px;
    background: var(--accent);
    color: #fff;
    font-size: 10px;
    font-weight: 600;
    padding: 3px 9px;
    border-radius: 0 0 5px 5px;
}

.ri-plan-card-name {
    font-size: 15px;
    font-weight: 600;
    margin-bottom: 4px;
}

.ri-plan-card-price {
    font-size: 22px;
    font-weight: 600;
    margin-bottom: 14px;
}

    .ri-plan-card-price span {
        font-size: 13px;
        font-weight: 400;
        color: var(--text2);
    }

.ri-plan-feats {
    list-style: none;
    display: flex;
    flex-direction: column;
    gap: 7px;
    margin-bottom: 18px;
    font-size: 13px;
    color: var(--text2);
}

.ri-feat-locked {
    opacity: .5;
}

/*  Code block  */
.ri-code {
    background: var(--surf2);
    border-radius: var(--r-sm);
    padding: 14px;
    overflow-x: auto;
}

    .ri-code code {
        background: none;
        padding: 0;
        font-size: 12px;
        color: var(--text2);
        line-height: 1.65;
    }

/*  Empty state ─ */
.ri-empty {
    display: flex;
    flex-direction: column;
    align-items: center;
    text-align: center;
    padding: 56px 24px;
    color: var(--text2);
    gap: 8px;
}

.ri-empty-icon {
    font-size: 34px;
    opacity: .35;
    margin-bottom: 6px;
}

.ri-empty h3 {
    font-size: 15px;
    font-weight: 600;
    color: var(--text);
}

.ri-empty p {
    font-size: 13px;
    margin-bottom: 8px;
}

/*  Skeleton loader ─ */
.ri-skeleton {
    background: var(--surf);
    border: 1px solid var(--border);
    border-radius: var(--r);
    margin-bottom: 14px;
    min-height: 72px;
    animation: ri-pulse 1.4s ease-in-out infinite;
}

.ri-skeleton-grid {
    display: grid;
    grid-template-columns: repeat(3,1fr);
    gap: 14px;
}

@keyframes ri-pulse {
    0%,100% {
        opacity: 1
    }

    50% {
        opacity: .35
    }
}

/*  Spinner ─ */
.ri-spinner {
    width: 13px;
    height: 13px;
    border: 2px solid rgba(255,255,255,.25);
    border-top-color: #fff;
    border-radius: 50%;
    animation: ri-spin .65s linear infinite;
}

@keyframes ri-spin {
    to {
        transform: rotate(360deg);
    }
}

/*  Blazor error UI ─ */
#blazor-error-ui {
    display: none;
    background: #b32121;
    color: #fff;
    padding: 10px 16px;
    font-size: 13px;
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    z-index: 100;
}

    #blazor-error-ui .reload {
        color: #fff;
        text-decoration: underline;
    }

.blazor-error-boundary {
    background: #b32121;
    padding: 12px 16px 12px 3.5rem;
    color: #fff;
}

    .blazor-error-boundary::after {
        content: "An error has occurred.";
    }

/*  Remove Bootstrap default remnants  */
.page, .sidebar, .main, .top-row {
    all: unset;
}

/*  Loading screen (shown while WASM boots) ─ */
.ri-loading {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--bg);
}

.ri-spinner-lg {
    width: 36px;
    height: 36px;
    border: 3px solid rgba(59,130,246,.2);
    border-top-color: var(--accent);
    border-radius: 50%;
    animation: ri-spin .7s linear infinite;
}

/* ═══════════════════════════════════════════════════════════════════════
   MOBILE RESPONSIVE
   ═══════════════════════════════════════════════════════════════════════ */

/* Hamburger button  HIDDEN by default on desktop */
.ri-menu-btn {
    display: none;
}

/* Dark overlay behind sidebar on mobile */
.ri-overlay-backdrop {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,.55);
    z-index: 99;
}

@media (max-width: 768px) {
    /* Show hamburger on mobile */
    .ri-menu-btn {
        display: flex;
        align-items: center;
        justify-content: center;
        position: fixed;
        top: 12px;
        left: 12px;
        z-index: 200;
        background: var(--surf);
        border: 1px solid var(--border2);
        border-radius: var(--r-sm);
        padding: 8px 12px;
        cursor: pointer;
        color: var(--text);
        font-size: 20px;
        line-height: 1;
        box-shadow: 0 2px 10px rgba(0,0,0,.3);
    }

    /* Backdrop is visible as a block when rendered (AppShell only renders it when open) */
    .ri-overlay-backdrop {
        display: block;
    }

    /* Sidebar: slides off-screen by default, slides in when .open is added */
    .ri-sidebar {
        position: fixed;
        top: 0;
        left: 0;
        bottom: 0;
        transform: translateX(-100%);
        transition: transform .25s ease;
        z-index: 100;
    }

        .ri-sidebar.open {
            transform: translateX(0);
        }

    /* Main content fills full width, with padding-top for hamburger button */
    .ri-main {
        margin-left: 0 !important;
        padding: 56px 16px 16px !important;
        max-width: 100% !important;
    }

    /* Stack grids to single column */
    .ri-stats-row {
        grid-template-columns: 1fr;
    }

    .ri-actions-row {
        grid-template-columns: 1fr;
    }

    .ri-plans-grid {
        grid-template-columns: 1fr;
    }

    /* Compact tables */
    .ri-table {
        font-size: 12px;
    }

        .ri-table th, .ri-table td {
            padding: 8px 6px;
        }

    /* Auth card */
    .ri-auth-card {
        padding: 24px 20px;
    }

    /* Page header stacks vertically */
    .ri-page-header {
        flex-direction: column;
        gap: 10px;
    }
}

/* ═══════════════════════════════════════════════════════════════════════
   LIGHT THEME    applied via html.light class by JS riSetTheme()
   ═══════════════════════════════════════════════════════════════════════ */
html.light {
    --bg: #f3f4f8;
    --surf: #ffffff;
    --surf2: #f0f1f5;
    --surf3: #e8eaf0;
    --border: #dde0e8;
    --border2: #c8ccda;
    --text: #111827;
    --text2: #4b5563;
    --text3: #9ca3af;
    --accent: #2563eb;
    --accent2: #1d4ed8;
    --green: #16a34a;
    --amber: #d97706;
    --red: #dc2626;
}

    html.light .ri-alert-error {
        color: #991b1b;
    }

    html.light .ri-alert-success {
        color: #166534;
    }

/*  Theme toggle button ─ */
.ri-theme-toggle {
    background: var(--surf2);
    border: 1px solid var(--border2);
    color: var(--text2);
    border-radius: var(--r-sm);
    padding: 6px 10px;
    font-size: 12px;
    cursor: pointer;
    transition: all .13s;
    text-align: left;
    width: 100%;
    font-family: var(--font);
}

    .ri-theme-toggle:hover {
        color: var(--accent);
        border-color: var(--accent);
    }

/*  Blazor error banner  hidden on startup, shown only on real errors ─ */
#blazor-error-ui {
    display: none;
    background: #b32121;
    color: #fff;
    padding: 10px 18px;
    font-size: 13px;
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    z-index: 9999;
}
