/* === Reset & Base === */
*, *::before, *::after {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

:root {
    --primary: #2563eb;
    --primary-dark: #1d4ed8;
    --bg: #f1f5f9;
    --surface: #ffffff;
    --text: #1e293b;
    --text-muted: #64748b;
    --border: #e2e8f0;
    --success: #16a34a;
    --success-bg: #dcfce7;
    --error: #dc2626;
    --error-bg: #fee2e2;
    --ca-color: #7c3aed;
    --cert-color: #0891b2;
    --sidebar-bg: #1e293b;
    --sidebar-text: #cbd5e1;
    --sidebar-width: 250px;
    --radius: 8px;
}

html, body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    background: var(--bg);
    color: var(--text);
    line-height: 1.6;
    min-height: 100vh;
}

h1 { font-size: 1.75rem; margin-bottom: 1.5rem; font-weight: 700; }
h3 { font-size: 1.1rem; margin-bottom: 0.75rem; font-weight: 600; }

/* === Layout === */
.app-container {
    display: flex;
    min-height: 100vh;
}

.sidebar {
    width: var(--sidebar-width);
    background: var(--sidebar-bg);
    color: var(--sidebar-text);
    position: fixed;
    top: 0;
    left: 0;
    bottom: 0;
    overflow-y: auto;
    z-index: 100;
}

.sidebar-header {
    padding: 1.25rem 1.5rem;
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.sidebar-header h2 {
    font-size: 1.25rem;
    font-weight: 700;
    color: #fff;
    margin: 0;
}

.menu-toggle {
    display: none;
    background: none;
    border: none;
    color: #fff;
    font-size: 1.5rem;
    cursor: pointer;
}

.nav-menu nav {
    display: flex;
    flex-direction: column;
    padding: 0.5rem 0;
}

.nav-link {
    display: block;
    padding: 0.75rem 1.5rem;
    color: var(--sidebar-text);
    text-decoration: none;
    transition: background 0.2s, color 0.2s;
    font-size: 0.95rem;
}

.nav-link:hover {
    background: rgba(255, 255, 255, 0.1);
    color: #fff;
}

.nav-link.active {
    background: var(--primary);
    color: #fff;
    font-weight: 600;
}

.main-content {
    margin-left: var(--sidebar-width);
    padding: 2rem;
    flex: 1;
    min-width: 0;
}

/* === Cards === */
.card {
    background: var(--surface);
    border-radius: var(--radius);
    padding: 1.5rem;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.08);
    margin-bottom: 1rem;
}

.card-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 1rem;
    margin-bottom: 1.5rem;
}

.stat-card {
    text-align: center;
}

.stat-value {
    font-size: 2.5rem;
    font-weight: 700;
    color: var(--primary);
    margin-top: 0.5rem;
}

/* === Tables === */
.table-responsive {
    overflow-x: auto;
}

table {
    width: 100%;
    border-collapse: collapse;
}

th, td {
    padding: 0.75rem 1rem;
    text-align: left;
    border-bottom: 1px solid var(--border);
}

th {
    font-weight: 600;
    color: var(--text-muted);
    font-size: 0.85rem;
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

/* === Badges === */
.badge {
    display: inline-block;
    padding: 0.2rem 0.6rem;
    border-radius: 1rem;
    font-size: 0.75rem;
    font-weight: 600;
    text-transform: uppercase;
}

.badge-ca {
    background: #ede9fe;
    color: var(--ca-color);
}

.badge-cert {
    background: #cffafe;
    color: var(--cert-color);
}

/* === Forms === */
.form-card {
    max-width: 700px;
}

.form-group {
    margin-bottom: 1rem;
    flex: 1;
}

.form-group label {
    display: block;
    font-weight: 600;
    font-size: 0.875rem;
    margin-bottom: 0.35rem;
    color: var(--text);
}

.form-row {
    display: flex;
    gap: 1rem;
}

input[type="text"],
input[type="number"],
select,
.form-group input,
.form-group select {
    width: 100%;
    padding: 0.6rem 0.75rem;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    font-size: 0.95rem;
    background: var(--surface);
    color: var(--text);
    transition: border-color 0.2s;
}

input:focus, select:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.15);
}

input::placeholder {
    color: var(--text-muted);
}

/* === Checkboxes === */
.checkbox-group {
    display: flex;
    flex-direction: column;
    gap: 0.4rem;
}

.checkbox-label {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    font-weight: 400;
    font-size: 0.9rem;
    cursor: pointer;
}

.checkbox-label input[type="checkbox"] {
    width: auto;
    accent-color: var(--primary);
}

/* === Advanced toggle === */
.btn-toggle {
    display: flex;
    align-items: center;
    gap: 0.4rem;
    background: none;
    border: none;
    color: var(--primary);
    font-size: 0.9rem;
    font-weight: 600;
    cursor: pointer;
    padding: 0.5rem 0;
    margin-bottom: 0.75rem;
}

.btn-toggle:hover {
    color: var(--primary-dark);
}

.toggle-arrow {
    display: inline-block;
    transition: transform 0.2s;
    font-size: 0.75rem;
}

.toggle-arrow.open {
    transform: rotate(180deg);
}

.advanced-section {
    border-top: 1px solid var(--border);
    padding-top: 1rem;
    margin-bottom: 0.5rem;
}

/* === Buttons === */
.btn {
    display: inline-block;
    padding: 0.6rem 1.25rem;
    border: none;
    border-radius: var(--radius);
    font-size: 0.95rem;
    font-weight: 600;
    cursor: pointer;
    transition: background 0.2s, transform 0.1s;
    text-decoration: none;
}

.btn:active {
    transform: scale(0.98);
}

.btn-primary {
    background: var(--primary);
    color: #fff;
}

.btn-primary:hover {
    background: var(--primary-dark);
}

.btn-primary:disabled {
    background: #93c5fd;
    cursor: not-allowed;
}

.btn-sm {
    padding: 0.4rem 0.85rem;
    font-size: 0.85rem;
    background: var(--primary);
    color: #fff;
}

.btn-sm:hover {
    background: var(--primary-dark);
}

/* === Alerts === */
.alert {
    padding: 1rem;
    border-radius: var(--radius);
    margin-top: 1rem;
    font-size: 0.95rem;
}

.alert-success {
    background: var(--success-bg);
    color: #166534;
    border: 1px solid #bbf7d0;
}

.alert-error {
    background: var(--error-bg);
    color: #991b1b;
    border: 1px solid #fecaca;
}

/* === Toolbar === */
.toolbar {
    display: flex;
    gap: 0.75rem;
    margin-bottom: 1rem;
    flex-wrap: wrap;
}

.btn-secondary {
    background: #64748b;
    color: #fff;
}

.btn-secondary:hover {
    background: #475569;
}

/* === Certificate cards === */
.certificates-grid {
    grid-template-columns: repeat(auto-fill, minmax(320px, 1fr));
}

.cert-card {
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
    position: relative;
}

.cert-delete {
    position: absolute;
    top: 0.5rem;
    right: 0.5rem;
    background: none;
    border: none;
    color: var(--text-muted);
    font-size: 1.1rem;
    font-weight: 700;
    cursor: pointer;
    width: 28px;
    height: 28px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 50%;
    transition: background 0.2s, color 0.2s;
    line-height: 1;
}

.cert-delete:hover {
    background: var(--error-bg);
    color: var(--error);
}

.cert-header {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    font-size: 1.05rem;
}

.cert-details {
    font-size: 0.875rem;
    color: var(--text-muted);
    display: flex;
    flex-direction: column;
    gap: 0.25rem;
}

.cert-details .label {
    font-weight: 600;
    color: var(--text);
}

.thumbprint {
    font-size: 0.75rem;
    word-break: break-all;
}

code {
    background: #f1f5f9;
    padding: 0.15rem 0.4rem;
    border-radius: 4px;
    font-size: 0.85em;
    color: var(--primary-dark);
}

/* === Dashboard Info === */
.hero-card {
    border-left: 4px solid var(--primary);
}

.hero-title {
    font-size: 1.25rem;
    margin-bottom: 0.5rem;
}

.hero-text {
    color: var(--text-muted);
    font-size: 0.95rem;
    line-height: 1.7;
}

.info-grid {
    grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
}

.info-card {
    text-align: center;
    padding-top: 2rem;
}

.info-card p {
    color: var(--text-muted);
    font-size: 0.9rem;
    line-height: 1.6;
}

.info-icon {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    background: var(--primary);
    color: #fff;
    font-weight: 700;
    font-size: 1.1rem;
    display: flex;
    align-items: center;
    justify-content: center;
    margin: 0 auto 0.75rem;
}

.notice-card {
    background: #fffbeb;
    border: 1px solid #fde68a;
}

.notice-card h3 {
    color: #92400e;
}

.notice-card p {
    color: #78350f;
    font-size: 0.9rem;
    line-height: 1.6;
}

.info-link {
    color: var(--primary);
    font-weight: 600;
    text-decoration: none;
}

.info-link:hover {
    text-decoration: underline;
}

/* === Section headings === */
.section-heading {
    font-size: 1.25rem;
    font-weight: 700;
    margin: 1.5rem 0 1rem;
    color: var(--text);
}

/* === Security card === */
.security-card {
    border-left: 4px solid #f59e0b;
}

.security-section {
    margin-bottom: 1.25rem;
}

.security-section:last-child {
    margin-bottom: 0;
}

.security-section h3 {
    font-size: 1rem;
    color: #92400e;
}

.security-section p {
    color: var(--text-muted);
    font-size: 0.9rem;
    line-height: 1.6;
    margin-bottom: 0.5rem;
}

.security-section ul {
    padding-left: 1.25rem;
    color: var(--text-muted);
    font-size: 0.9rem;
    line-height: 1.8;
}

/* === Built-by card === */
.built-by-card {
    border-left: 4px solid var(--text-muted);
    margin-top: 2rem;
}

.built-by-card p {
    color: var(--text-muted);
    font-size: 0.9rem;
    line-height: 1.6;
}

/* === Dashboard stat warning === */
.stat-warning {
    color: #d97706;
}

/* === Misc === */
.loading {
    display: flex;
    justify-content: center;
    align-items: center;
    height: 100vh;
    font-size: 1.2rem;
    color: var(--text-muted);
}

#blazor-error-ui {
    background: lightyellow;
    bottom: 0;
    box-shadow: 0 -1px 2px rgba(0, 0, 0, 0.2);
    display: none;
    left: 0;
    padding: 0.6rem 1.25rem 0.7rem 1.25rem;
    position: fixed;
    width: 100%;
    z-index: 1000;
}

#blazor-error-ui .dismiss {
    cursor: pointer;
    position: absolute;
    right: 0.75rem;
    top: 0.5rem;
}

.blazor-error-boundary {
    background: #b32121;
    padding: 1rem;
    color: white;
}

.blazor-error-boundary::after {
    content: "An error has occurred.";
}

/* === Responsive === */
@media (max-width: 768px) {
    .sidebar {
        position: fixed;
        width: 100%;
        height: auto;
        bottom: auto;
    }

    .sidebar-header {
        padding: 0.75rem 1rem;
    }

    .menu-toggle {
        display: block;
    }

    .nav-menu {
        max-height: 0;
        overflow: hidden;
        transition: max-height 0.3s ease;
    }

    .nav-menu:not(.collapse) {
        max-height: 300px;
    }

    .nav-menu.collapse {
        max-height: 0;
    }

    .main-content {
        margin-left: 0;
        margin-top: 60px;
        padding: 1rem;
    }

    .form-row {
        flex-direction: column;
        gap: 0;
    }

    .card-grid {
        grid-template-columns: 1fr;
    }

    .certificates-grid {
        grid-template-columns: 1fr;
    }

    h1 {
        font-size: 1.4rem;
    }
}

@media (min-width: 769px) {
    .nav-menu.collapse {
        max-height: none;
    }
}
