/* DIP Practical — Design System (WCAG 2.2 AAA) */

*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

/* --- Tokens: Light (AAA contrast ratios: 7:1 normal text, 4.5:1 large) --- */
:root {
    --bg: #f5f7fa;
    --surface-1: #ffffff;
    --surface-2: #edf0f5;
    --surface-3: #e2e6ed;
    --border: #d1d5db;
    --border-hover: #9ca3af;
    --text: #111827;
    --text-secondary: #1f2937;
    --text-muted: #4b5563;
    --accent: #3730a3;
    --accent-hover: #312e81;
    --accent-light: #eef2ff;
    --accent-text: #312e81;
    --success: #065f46;
    --error: #991b1b;
    --warning: #92400e;
    --font-sans: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', system-ui, sans-serif;
    --font-mono: 'JetBrains Mono', 'Fira Code', ui-monospace, 'Cascadia Code', monospace;
    --radius-sm: 0.375rem;
    --radius-md: 0.5rem;
    --radius-lg: 0.75rem;
    --radius-xl: 1rem;
    --radius-full: 9999px;
    --shadow-sm: 0 1px 2px rgba(0,0,0,0.05);
    --shadow-md: 0 4px 6px -1px rgba(0,0,0,0.07), 0 2px 4px -2px rgba(0,0,0,0.05);
    --shadow-lg: 0 10px 25px -5px rgba(0,0,0,0.1), 0 8px 10px -6px rgba(0,0,0,0.04);
    --shadow-xl: 0 20px 40px -8px rgba(0,0,0,0.12);
    --ease-spring: cubic-bezier(0.34, 1.56, 0.64, 1);
    --ease-out: cubic-bezier(0.16, 1, 0.3, 1);
}

/* --- Tokens: Dark (AAA contrast ratios) --- */
[data-theme="dark"] {
    --bg: #0f1117;
    --surface-1: #1a1d2e;
    --surface-2: #252836;
    --surface-3: #2f3344;
    --border: #374151;
    --border-hover: #4b5563;
    --text: #f3f4f6;
    --text-secondary: #e5e7eb;
    --text-muted: #d1d5db;
    --accent: #c7d2fe;
    --accent-hover: #e0e7ff;
    --accent-light: rgba(129,140,248,0.12);
    --accent-text: #e0e7ff;
    --success: #6ee7b7;
    --error: #fca5a5;
    --warning: #fcd34d;
    --shadow-sm: 0 1px 2px rgba(0,0,0,0.3);
    --shadow-md: 0 4px 6px rgba(0,0,0,0.4);
    --shadow-lg: 0 10px 25px rgba(0,0,0,0.5);
    --shadow-xl: 0 20px 40px rgba(0,0,0,0.6);
}

/* Theme transition */
.theme-transitioning, .theme-transitioning *, .theme-transitioning *::before, .theme-transitioning *::after {
    transition: background-color 0.3s ease, color 0.3s ease, border-color 0.3s ease, box-shadow 0.3s ease !important;
}

/* --- Typography --- */
html { scroll-behavior: smooth; }
body {
    font-family: var(--font-sans);
    background: var(--bg);
    color: var(--text);
    font-size: 1rem;
    line-height: 1.65;
    min-height: 100vh;
    -webkit-font-smoothing: antialiased;
}
h1, h2, h3, h4, h5, h6 { font-family: var(--font-sans); color: var(--text); font-weight: 700; letter-spacing: -0.025em; line-height: 1.25; }
h1 { font-size: clamp(1.875rem, 1.5rem + 1.5vw, 2.75rem); }
h2 { font-size: clamp(1.5rem, 1.25rem + 1vw, 2rem); margin-bottom: 1.5rem; }
h3 { font-size: clamp(1.125rem, 1rem + 0.5vw, 1.375rem); }
h4 { font-size: 1.125rem; }
a { color: var(--accent); text-decoration: underline; text-underline-offset: 2px; transition: color 0.15s; }
a:hover { color: var(--accent-hover); }
code, pre { font-family: var(--font-mono); font-size: 0.875em; }
code { background: var(--surface-2); padding: 0.125em 0.375em; border-radius: var(--radius-sm); }
p { max-width: 72ch; }

/* --- Layout --- */
.container { width: 100%; max-width: 1200px; margin: 0 auto; padding: 0 1.5rem; }
#main-content { padding: 2rem 0 4rem; }
#main-content > .container > h2:first-child {
    padding-bottom: 0.75rem;
    border-bottom: 3px solid var(--accent);
    display: inline-block;
    margin-bottom: 2rem;
}

/* --- Navbar --- */
.dip-navbar {
    position: sticky; top: 0; z-index: 100;
    background: var(--surface-1);
    border-bottom: 1px solid var(--border);
    box-shadow: var(--shadow-sm);
}
[data-theme="dark"] .dip-navbar { background: rgba(15,17,23,0.95); backdrop-filter: blur(12px); -webkit-backdrop-filter: blur(12px); }
.dip-navbar .navbar-brand { font-weight: 800; font-size: 1.1rem; color: var(--accent) !important; letter-spacing: -0.03em; text-decoration: none; }
.dip-navbar .nav-link {
    color: var(--text-muted) !important; font-weight: 500; font-size: 0.9rem;
    padding: 0.5rem 0.85rem !important; border-radius: var(--radius-md);
    transition: all 0.15s ease; text-decoration: none;
    min-height: 44px; display: inline-flex; align-items: center;
}
.dip-navbar .nav-link:hover { color: var(--text) !important; background: var(--surface-2); }
.dip-navbar .nav-link.active { color: var(--accent) !important; background: var(--accent-light); font-weight: 600; }
.dip-navbar .nav-link:focus-visible { outline: 2px solid var(--accent); outline-offset: -2px; }
.dip-navbar .navbar-toggler { border: 1px solid var(--border); padding: 0.5rem 0.75rem; min-width: 44px; min-height: 44px; }
.dip-navbar .navbar-toggler-icon { width: 1.2em; height: 1.2em; }
[data-theme="dark"] .dip-navbar .navbar-toggler-icon { filter: invert(1); }

/* --- Theme Toggle --- */
.theme-toggle {
    padding: 0.5rem 1rem; margin-left: 0.75rem;
    border: 1px solid var(--border); border-radius: var(--radius-full);
    background: var(--surface-2); color: var(--text-muted);
    font-size: 0.8rem; font-weight: 600; cursor: pointer;
    transition: all 0.15s ease; text-decoration: none;
    min-width: 44px; min-height: 44px;
    display: inline-flex; align-items: center; justify-content: center;
}
.theme-toggle:hover { border-color: var(--accent); color: var(--accent); background: var(--accent-light); }

/* --- Footer --- */
.site-footer { border-top: 1px solid var(--border); padding: 1.25rem 0; text-align: center; font-size: 0.8rem; color: var(--text-muted); }
.site-footer p { margin: 0; }

/* --- Toast --- */
.toast {
    position: fixed; bottom: 1.5rem; right: 1.5rem;
    background: var(--surface-1); color: var(--text);
    padding: 0.875rem 1.25rem; border-radius: var(--radius-lg);
    border: 1px solid var(--border); border-left: 4px solid var(--accent);
    box-shadow: var(--shadow-lg); font-size: 0.875rem; z-index: 1000;
    transform: translateY(120%); opacity: 0;
    transition: transform 0.35s var(--ease-spring), opacity 0.2s ease;
}
.toast.visible { transform: translateY(0); opacity: 1; }

/* --- Loading --- */
.loading-spinner { display: inline-flex; align-items: center; gap: 0.5rem; color: var(--text-muted); font-size: 0.875rem; }
.loading-spinner::before {
    content: ''; width: 18px; height: 18px;
    border: 2px solid var(--border); border-top-color: var(--accent);
    border-radius: 50%; animation: spin 0.7s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
.loading-overlay {
    position: absolute; inset: 0; background: rgba(255,255,255,0.8);
    display: flex; align-items: center; justify-content: center;
    z-index: 10; border-radius: var(--radius-lg);
}
[data-theme="dark"] .loading-overlay { background: rgba(15,17,23,0.8); }

/* --- Utilities --- */
.hidden { display: none !important; }
.text-center { text-align: center; }
.mt-1 { margin-top: 0.5rem; }
.mt-2 { margin-top: 1rem; }
.mb-1 { margin-bottom: 0.5rem; }
.mb-2 { margin-bottom: 1rem; }

/* --- Accessibility --- */
.skip-link {
    position: absolute; top: -100%; left: 1rem; z-index: 10000;
    background: var(--accent); color: #fff; padding: 1rem 1.5rem;
    border-radius: 0 0 var(--radius-md) var(--radius-md);
    font-weight: 600; font-size: 0.875rem; text-decoration: none;
    min-height: 44px; display: inline-flex; align-items: center;
}
.skip-link:focus { top: 0; color: #fff; }
:focus-visible { outline: 3px solid var(--accent); outline-offset: 2px; }
[data-theme="dark"] :focus-visible { outline-color: #c7d2fe; }
.sr-only { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0,0,0,0); white-space: nowrap; border: 0; }

/* --- Reduced Motion --- */
@media (prefers-reduced-motion: reduce) {
    *, *::before, *::after { animation-duration: 0.01ms !important; transition-duration: 0.01ms !important; scroll-behavior: auto !important; }
    .btn-run:hover, .btn-run:active { transform: none !important; }
    .theme-toggle:hover { transform: none !important; }
}

/* --- Print --- (all print styles are in base.html inline <style>) */
.print-front-page, .print-header { display: none; }
