/* ========================================
   NurmaanWiki Design System
   Style: Minimalism & Swiss Style
   Typography: Inter (UI) + JetBrains Mono (code)
   ======================================== */

/* --- CSS Custom Properties (Design Tokens) --- */
:root,
[data-theme="light"] {
    /* Primary */
    --color-primary: #2563EB;
    --color-primary-hover: #1D4ED8;
    --color-primary-light: #DBEAFE;
    --color-on-primary: #FFFFFF;

    /* Surfaces */
    --color-bg: #F8FAFC;
    --color-bg-secondary: #F1F5F9;
    --color-card: #FFFFFF;
    --color-card-hover: #F8FAFC;

    /* Text */
    --color-text: #1E293B;
    --color-text-secondary: #475569;
    --color-text-muted: #94A3B8;
    --color-text-inverse: #FFFFFF;

    /* Borders & Dividers */
    --color-border: #E2E8F0;
    --color-border-hover: #CBD5E1;
    --color-divider: #F1F5F9;

    /* Feedback */
    --color-success: #16A34A;
    --color-warning: #F59E0B;
    --color-error: #DC2626;
    --color-info: #2563EB;

    /* Sidebar */
    --color-sidebar-bg: #FFFFFF;
    --color-sidebar-hover: #F1F5F9;
    --color-sidebar-active: #DBEAFE;
    --color-sidebar-text: #334155;

    /* Shadows */
    --shadow-sm: 0 1px 2px 0 rgb(0 0 0 / 0.05);
    --shadow-md: 0 4px 6px -1px rgb(0 0 0 / 0.1), 0 2px 4px -2px rgb(0 0 0 / 0.1);
    --shadow-lg: 0 10px 15px -3px rgb(0 0 0 / 0.1), 0 4px 6px -4px rgb(0 0 0 / 0.1);

    /* Misc */
    --color-overlay: rgb(0 0 0 / 0.4);
    --color-focus-ring: #2563EB;
    --color-scrollbar: #CBD5E1;
    --color-scrollbar-hover: #94A3B8;
    --code-bg: #F1F5F9;
    --code-text: #1E293B;
}

[data-theme="dark"] {
    /* Primary */
    --color-primary: #3B82F6;
    --color-primary-hover: #60A5FA;
    --color-primary-light: #1E3A5F;
    --color-on-primary: #FFFFFF;

    /* Surfaces */
    --color-bg: #0F172A;
    --color-bg-secondary: #1E293B;
    --color-card: #1B2336;
    --color-card-hover: #243044;

    /* Text */
    --color-text: #F1F5F9;
    --color-text-secondary: #CBD5E1;
    --color-text-muted: #64748B;
    --color-text-inverse: #0F172A;

    /* Borders & Dividers */
    --color-border: #334155;
    --color-border-hover: #475569;
    --color-divider: #1E293B;

    /* Feedback */
    --color-success: #22C55E;
    --color-warning: #FBBF24;
    --color-error: #EF4444;
    --color-info: #3B82F6;

    /* Sidebar */
    --color-sidebar-bg: #0F172A;
    --color-sidebar-hover: #1E293B;
    --color-sidebar-active: #1E3A5F;
    --color-sidebar-text: #CBD5E1;

    /* Shadows */
    --shadow-sm: 0 1px 2px 0 rgb(0 0 0 / 0.3);
    --shadow-md: 0 4px 6px -1px rgb(0 0 0 / 0.4), 0 2px 4px -2px rgb(0 0 0 / 0.3);
    --shadow-lg: 0 10px 15px -3px rgb(0 0 0 / 0.5), 0 4px 6px -4px rgb(0 0 0 / 0.4);

    /* Misc */
    --color-overlay: rgb(0 0 0 / 0.6);
    --color-focus-ring: #3B82F6;
    --color-scrollbar: #334155;
    --color-scrollbar-hover: #475569;
    --code-bg: #1E293B;
    --code-text: #E2E8F0;
}

/* --- Reset & Base --- */
*,
*::before,
*::after {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

html {
    font-size: 16px;
    scroll-behavior: smooth;
    -webkit-text-size-adjust: 100%;
}

body {
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    font-size: 1rem;
    line-height: 1.6;
    color: var(--color-text);
    background-color: var(--color-bg);
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
    transition: background-color 0.2s ease, color 0.2s ease;
}

/* --- Typography --- */
h1, h2, h3, h4, h5, h6 {
    font-weight: 600;
    line-height: 1.3;
    color: var(--color-text);
}

h1 { font-size: 2rem; }
h2 { font-size: 1.5rem; }
h3 { font-size: 1.25rem; }
h4 { font-size: 1.125rem; }
h5 { font-size: 1rem; }
h6 { font-size: 0.875rem; }

p {
    margin-bottom: 1rem;
    line-height: 1.7;
}

a {
    color: var(--color-primary);
    text-decoration: none;
    transition: color 0.2s ease;
}

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

code, pre, .font-mono {
    font-family: 'JetBrains Mono', 'Fira Code', 'Cascadia Code', monospace;
}

code {
    font-size: 0.875em;
    padding: 0.15em 0.4em;
    background: var(--code-bg);
    color: var(--code-text);
    border-radius: 4px;
}

pre {
    background: var(--code-bg);
    color: var(--code-text);
    padding: 1rem;
    border-radius: 8px;
    overflow-x: auto;
    line-height: 1.5;
    font-size: 0.875rem;
}

pre code {
    padding: 0;
    background: none;
    border-radius: 0;
}

/* --- Focus States --- */
:focus-visible {
    outline: 2px solid var(--color-focus-ring);
    outline-offset: 2px;
}

/* --- Scrollbar --- */
::-webkit-scrollbar {
    width: 8px;
    height: 8px;
}

::-webkit-scrollbar-track {
    background: transparent;
}

::-webkit-scrollbar-thumb {
    background: var(--color-scrollbar);
    border-radius: 4px;
}

::-webkit-scrollbar-thumb:hover {
    background: var(--color-scrollbar-hover);
}

/* --- Buttons --- */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
    padding: 0.5rem 1rem;
    font-size: 0.875rem;
    font-weight: 500;
    line-height: 1.5;
    border: 1px solid transparent;
    border-radius: 8px;
    cursor: pointer;
    transition: all 0.2s ease;
    white-space: nowrap;
    min-height: 40px;
}

.btn:active {
    transform: scale(0.98);
}

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

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

.btn-secondary {
    background: transparent;
    color: var(--color-text);
    border-color: var(--color-border);
}

.btn-secondary:hover {
    background: var(--color-bg-secondary);
    border-color: var(--color-border-hover);
}

.btn-ghost {
    background: transparent;
    color: var(--color-text-secondary);
    border: none;
    padding: 0.5rem;
}

.btn-ghost:hover {
    background: var(--color-bg-secondary);
    color: var(--color-text);
}

.btn-danger {
    background: var(--color-error);
    color: #FFFFFF;
    border-color: var(--color-error);
}

.btn-danger:hover {
    opacity: 0.9;
}

.btn-sm {
    padding: 0.25rem 0.75rem;
    font-size: 0.8125rem;
    min-height: 32px;
}

.btn-lg {
    padding: 0.75rem 1.5rem;
    font-size: 1rem;
    min-height: 48px;
}

.btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
    transform: none;
}

/* --- Inputs --- */
.input {
    width: 100%;
    padding: 0.5rem 0.75rem;
    font-size: 0.875rem;
    line-height: 1.5;
    color: var(--color-text);
    background: var(--color-card);
    border: 1px solid var(--color-border);
    border-radius: 8px;
    transition: border-color 0.2s ease, box-shadow 0.2s ease;
    min-height: 40px;
}

.input:focus {
    border-color: var(--color-primary);
    box-shadow: 0 0 0 3px rgb(37 99 235 / 0.15);
    outline: none;
}

.input::placeholder {
    color: var(--color-text-muted);
}

.input-error {
    border-color: var(--color-error);
}

.input-error:focus {
    box-shadow: 0 0 0 3px rgb(220 38 38 / 0.15);
}

label {
    display: block;
    font-size: 0.875rem;
    font-weight: 500;
    color: var(--color-text);
    margin-bottom: 0.375rem;
}

.form-group {
    margin-bottom: 1.25rem;
}

.form-error {
    font-size: 0.8125rem;
    color: var(--color-error);
    margin-top: 0.25rem;
}

.form-hint {
    font-size: 0.8125rem;
    color: var(--color-text-muted);
    margin-top: 0.25rem;
}

/* --- Cards --- */
.card {
    background: var(--color-card);
    border: 1px solid var(--color-border);
    border-radius: 12px;
    padding: 1.5rem;
    transition: box-shadow 0.2s ease, border-color 0.2s ease;
}

.card-hover:hover {
    box-shadow: var(--shadow-md);
    border-color: var(--color-border-hover);
}

/* --- Badge --- */
.badge {
    display: inline-flex;
    align-items: center;
    padding: 0.125rem 0.625rem;
    font-size: 0.75rem;
    font-weight: 500;
    border-radius: 9999px;
    line-height: 1.5;
}

.badge-primary {
    background: var(--color-primary-light);
    color: var(--color-primary);
}

.badge-success {
    background: rgb(22 163 74 / 0.1);
    color: var(--color-success);
}

.badge-warning {
    background: rgb(245 158 11 / 0.1);
    color: var(--color-warning);
}

.badge-error {
    background: rgb(220 38 38 / 0.1);
    color: var(--color-error);
}

/* --- Toast --- */
.toast-container {
    position: fixed;
    top: 1rem;
    right: 1rem;
    z-index: 9999;
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

.toast {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 0.75rem 1rem;
    background: var(--color-card);
    border: 1px solid var(--color-border);
    border-radius: 8px;
    box-shadow: var(--shadow-lg);
    animation: slide-in-right 0.3s ease-out;
    min-width: 300px;
    max-width: 450px;
}

/* --- Animations --- */
@@keyframes fade-in {
    from { opacity: 0; }
    to { opacity: 1; }
}

@@keyframes fade-out {
    from { opacity: 1; }
    to { opacity: 0; }
}

@@keyframes slide-in-right {
    from { transform: translateX(100%); opacity: 0; }
    to { transform: translateX(0); opacity: 1; }
}

@@keyframes slide-in-left {
    from { transform: translateX(-100%); opacity: 0; }
    to { transform: translateX(0); opacity: 1; }
}

@@keyframes slide-up {
    from { transform: translateY(8px); opacity: 0; }
    to { transform: translateY(0); opacity: 1; }
}

@@keyframes spin {
    to { transform: rotate(360deg); }
}

.animate-fade-in {
    animation: fade-in 0.2s ease-out;
}

.animate-slide-up {
    animation: slide-up 0.25s ease-out;
}

/* --- Utilities --- */
.sr-only {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border-width: 0;
}

.text-center { text-align: center; }
.text-right { text-align: right; }
.text-muted { color: var(--color-text-muted); }
.text-secondary { color: var(--color-text-secondary); }
.text-primary { color: var(--color-primary); }
.text-error { color: var(--color-error); }
.text-success { color: var(--color-success); }
.text-sm { font-size: 0.875rem; }
.text-xs { font-size: 0.75rem; }
.text-lg { font-size: 1.125rem; }

.font-medium { font-weight: 500; }
.font-semibold { font-weight: 600; }
.font-bold { font-weight: 700; }

.flex { display: flex; }
.flex-col { flex-direction: column; }
.items-center { align-items: center; }
.justify-center { justify-content: center; }
.justify-between { justify-content: space-between; }
.gap-1 { gap: 0.25rem; }
.gap-2 { gap: 0.5rem; }
.gap-3 { gap: 0.75rem; }
.gap-4 { gap: 1rem; }
.gap-6 { gap: 1.5rem; }

.w-full { width: 100%; }
.h-full { height: 100%; }
.min-h-screen { min-height: 100dvh; }

.mt-1 { margin-top: 0.25rem; }
.mt-2 { margin-top: 0.5rem; }
.mt-4 { margin-top: 1rem; }
.mt-6 { margin-top: 1.5rem; }
.mt-8 { margin-top: 2rem; }
.mb-2 { margin-bottom: 0.5rem; }
.mb-4 { margin-bottom: 1rem; }
.mb-6 { margin-bottom: 1.5rem; }
.ml-auto { margin-left: auto; }

.p-2 { padding: 0.5rem; }
.p-4 { padding: 1rem; }
.p-6 { padding: 1.5rem; }
.px-4 { padding-left: 1rem; padding-right: 1rem; }
.px-6 { padding-left: 1.5rem; padding-right: 1.5rem; }
.py-2 { padding-top: 0.5rem; padding-bottom: 0.5rem; }
.py-4 { padding-top: 1rem; padding-bottom: 1rem; }

.rounded { border-radius: 8px; }
.rounded-lg { border-radius: 12px; }
.rounded-full { border-radius: 9999px; }

.overflow-hidden { overflow: hidden; }
.overflow-auto { overflow: auto; }
.truncate { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.relative { position: relative; }
.absolute { position: absolute; }
.fixed { position: fixed; }
.sticky { position: sticky; }

.hidden { display: none; }
.block { display: block; }
.inline-flex { display: inline-flex; }
.grid { display: grid; }

.cursor-pointer { cursor: pointer; }
.select-none { user-select: none; }

.opacity-0 { opacity: 0; }
.opacity-50 { opacity: 0.5; }

.transition { transition: all 0.2s ease; }

/* --- Blazor Error Boundary --- */
.blazor-error-boundary {
    background: var(--color-error);
    padding: 1rem 1.5rem;
    color: white;
    border-radius: 8px;
    margin: 1rem;
}

.blazor-error-boundary::after {
    content: "An error has occurred.";
}

/* --- Selection --- */
::selection {
    background: var(--color-primary);
    color: white;
}

/* --- Skeleton Loading --- */
@@keyframes shimmer {
    0% { background-position: -200% 0; }
    100% { background-position: 200% 0; }
}

.skeleton {
    background: linear-gradient(90deg, var(--color-bg-secondary) 25%, var(--color-divider) 50%, var(--color-bg-secondary) 75%);
    background-size: 200% 100%;
    animation: shimmer 1.5s ease-in-out infinite;
    border-radius: 6px;
}

.skeleton-text {
    height: 0.875rem;
    margin-bottom: 0.5rem;
}

.skeleton-text-sm {
    height: 0.75rem;
    margin-bottom: 0.375rem;
}

.skeleton-heading {
    height: 1.5rem;
    margin-bottom: 0.75rem;
    width: 60%;
}

.skeleton-avatar {
    width: 36px;
    height: 36px;
    border-radius: 50%;
}

.skeleton-block {
    height: 100px;
    margin-bottom: 1rem;
}

/* --- Page Transitions --- */
@@keyframes page-enter {
    from {
        opacity: 0;
        transform: translateY(6px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.page-transition {
    animation: page-enter 0.25s ease-out;
}

/* --- Tooltip --- */
[data-tooltip] {
    position: relative;
}

[data-tooltip]::after {
    content: attr(data-tooltip);
    position: absolute;
    bottom: calc(100% + 6px);
    left: 50%;
    transform: translateX(-50%);
    padding: 0.25rem 0.5rem;
    background: var(--color-text);
    color: var(--color-bg);
    font-size: 0.75rem;
    font-weight: 500;
    border-radius: 4px;
    white-space: nowrap;
    pointer-events: none;
    opacity: 0;
    transition: opacity 0.15s ease;
    z-index: 100;
}

[data-tooltip]:hover::after {
    opacity: 1;
}

/* --- Mobile Specific --- */
@@media (max-width: 768px) {
    .hide-mobile { display: none !important; }

    .btn {
        min-height: 44px;
    }

    .btn-sm {
        min-height: 36px;
    }

    .input {
        min-height: 44px;
        font-size: 16px; /* Prevents iOS auto-zoom */
    }

    select.input {
        font-size: 16px;
    }
}

@@media (min-width: 769px) {
    .hide-desktop { display: none !important; }
}

/* --- Empty State --- */
.empty-state {
    text-align: center;
    padding: 3rem 2rem;
}

.empty-state svg {
    color: var(--color-text-muted);
    margin-bottom: 1rem;
}

/* --- Scroll Shadow --- */
.scroll-shadow-top {
    box-shadow: inset 0 8px 6px -6px rgb(0 0 0 / 0.08);
}

.scroll-shadow-bottom {
    box-shadow: inset 0 -8px 6px -6px rgb(0 0 0 / 0.08);
}

/* --- Reduced Motion --- */
@@media (prefers-reduced-motion: reduce) {
    *,
    *::before,
    *::after {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
    }
}
