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

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    min-height: 100vh;
    color: #333;
    line-height: 1.6;
}

.container {
    max-width: 1400px;
    margin: 0 auto;
    padding: 20px;
}

/* ==================== HEADER ==================== */
header {
    text-align: center;
    margin-bottom: 30px;
    color: white;
}
header h1 {
    font-size: 2.5em;
    margin-bottom: 10px;
    text-shadow: 2px 2px 4px rgba(0,0,0,0.3);
}
header p {
    font-size: 1.1em;
    opacity: 0.9;
}

/* ==================== NAVIGATION ==================== */
.main-nav {
    display: flex;
    gap: 8px;
    margin-bottom: 25px;
    flex-wrap: wrap;
    justify-content: center;
}
.nav-btn {
    padding: 12px 20px;
    background: rgba(255,255,255,0.15);
    color: white;
    border: 2px solid rgba(255,255,255,0.3);
    border-radius: 8px;
    cursor: pointer;
    font-size: 14px;
    font-weight: 500;
    transition: all 0.3s ease;
}
.nav-btn:hover {
    background: rgba(255,255,255,0.25);
    border-color: rgba(255,255,255,0.5);
    transform: translateY(-1px);
}
.nav-btn.active {
    background: white;
    color: #667eea;
    border-color: white;
    box-shadow: 0 4px 15px rgba(0,0,0,0.2);
}

/* ==================== SECTIONS ==================== */
.content-section {
    display: none;
}
.content-section.active {
    display: block;
    animation: fadeIn 0.4s ease;
}
@keyframes fadeIn {
    from { opacity: 0; transform: translateY(10px); }
    to   { opacity: 1; transform: translateY(0); }
}

/* ==================== CONCEPT GRID / CARDS ==================== */
.concept-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
    gap: 20px;
    margin-bottom: 25px;
}
.concept-grid.two-col {
    grid-template-columns: repeat(auto-fit, minmax(400px, 1fr));
}
.concept-card {
    background: white;
    border-radius: 12px;
    padding: 24px;
    box-shadow: 0 4px 15px rgba(0,0,0,0.08);
    transition: transform 0.2s ease;
}
.concept-card:hover {
    transform: translateY(-2px);
    box-shadow: 0 8px 25px rgba(0,0,0,0.12);
}
.concept-card h3 {
    color: #667eea;
    margin-bottom: 12px;
    font-size: 1.2em;
}
.concept-card h4 {
    color: #764ba2;
    margin-bottom: 8px;
}
.concept-card p {
    color: #555;
    margin-bottom: 10px;
}
.concept-card ul {
    list-style: none;
    padding: 0;
    margin-top: 10px;
}
.concept-card ul li {
    padding: 4px 0 4px 20px;
    position: relative;
}
.concept-card ul li::before {
    content: "•";
    color: #667eea;
    font-weight: bold;
    position: absolute;
    left: 4px;
}

/* Danger / Warning cards */
.card-danger {
    border-left: 4px solid #f44336;
}
.card-warning {
    border-left: 4px solid #ff9800;
}
.card-danger h3, .card-warning h3 {
    color: #c62828;
}

.dont-example {
    background: #fff5f5;
    border-radius: 8px;
    padding: 12px;
    margin: 10px 0;
    font-size: 0.82em;
    overflow-x: auto;
}
.dont-example pre {
    margin: 0;
}
.dont-example code {
    color: #c62828;
    font-family: 'SF Mono', 'Fira Code', monospace;
}

/* ==================== DIAGRAM CONTAINER ==================== */
.diagram-container {
    background: white;
    border-radius: 15px;
    padding: 30px;
    margin-bottom: 25px;
    box-shadow: 0 8px 32px rgba(0,0,0,0.1);
    overflow-x: auto;
}
.diagram-container h3 {
    color: #2c3e50;
    margin-bottom: 20px;
    font-size: 1.3em;
}
.diagram-caption {
    text-align: center;
    color: #777;
    margin-top: 15px;
    font-size: 0.9em;
    font-style: italic;
}

/* ==================== CONTROLS ==================== */
.controls {
    background: white;
    padding: 16px 20px;
    border-radius: 12px;
    margin-bottom: 20px;
    box-shadow: 0 4px 12px rgba(0,0,0,0.08);
    display: flex;
    align-items: center;
    gap: 15px;
    flex-wrap: wrap;
}
.btn-primary {
    padding: 10px 24px;
    background: #667eea;
    color: white;
    border: none;
    border-radius: 6px;
    cursor: pointer;
    font-size: 15px;
    font-weight: 500;
    transition: background 0.3s, transform 0.2s;
}
.btn-primary:hover {
    background: #5a6fd8;
    transform: translateY(-1px);
}
.btn-secondary {
    padding: 10px 24px;
    background: #f0f0f0;
    color: #555;
    border: none;
    border-radius: 6px;
    cursor: pointer;
    font-size: 15px;
    font-weight: 500;
    transition: background 0.3s;
}
.btn-secondary:hover {
    background: #e0e0e0;
}
.step-indicator {
    margin-left: auto;
    padding: 6px 16px;
    border-radius: 20px;
    font-size: 13px;
    font-weight: 600;
    background: #e3f2fd;
    color: #1565c0;
}

/* ==================== KEYCLOAK ROLE DIAGRAM ==================== */
.keycloak-role {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 20px;
    padding: 30px;
    flex-wrap: wrap;
}
.role-browser, .role-keycloak, .role-backend, .role-arrow {
    padding: 16px 24px;
    border-radius: 10px;
    text-align: center;
    font-weight: 600;
}
.role-browser {
    background: #e3f2fd;
    color: #1565c0;
    border: 2px solid #90caf9;
}
.role-keycloak {
    background: linear-gradient(135deg, #667eea, #764ba2);
    color: white;
}
.role-keycloak small {
    font-weight: 400;
    opacity: 0.9;
    display: block;
    margin-top: 4px;
}
.role-backend {
    background: #e8f5e9;
    color: #2e7d32;
    border: 2px solid #a5d6a7;
}
.role-arrow {
    font-size: 1.5em;
    color: #667eea;
    background: none;
    padding: 0;
}

/* ==================== FLOW PICKER ==================== */
.flow-picker {
    display: flex;
    gap: 30px;
    flex-wrap: wrap;
}
.picker-question { flex: 1; min-width: 300px; }
.picker-result { flex: 0 0 300px; }

.picker-steps {
    display: flex;
    flex-direction: column;
    gap: 16px;
    margin-top: 16px;
}
.picker-step {
    background: #f8f9ff;
    border-radius: 10px;
    padding: 16px;
    border: 2px solid #e0e0ff;
}
.picker-step.answered {
    border-color: #a5d6a7;
    background: #f1f8e9;
}
.picker-step h4 {
    color: #667eea;
    margin-bottom: 10px;
    font-size: 0.95em;
}
.picker-options {
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
}
.picker-opt {
    padding: 8px 16px;
    border-radius: 20px;
    border: 2px solid #ddd;
    background: white;
    cursor: pointer;
    font-size: 0.9em;
    font-weight: 500;
    transition: all 0.2s;
}
.picker-opt:hover {
    border-color: #667eea;
}
.picker-opt.selected {
    background: #667eea;
    color: white;
    border-color: #667eea;
}

.result-card {
    background: linear-gradient(135deg, #667eea, #764ba2);
    color: white;
    border-radius: 14px;
    padding: 30px;
    text-align: center;
    min-height: 200px;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 12px;
}
.result-icon { font-size: 3em; }
.result-flow-name { font-size: 1.3em; font-weight: 700; }
.result-flow-desc { font-size: 0.9em; opacity: 0.9; }

/* ==================== AUTH CODE FLOW DIAGRAM ==================== */
.auth-flow-diagram {
    display: flex;
    align-items: flex-start;
    justify-content: center;
    gap: 20px;
    min-height: 300px;
    flex-wrap: wrap;
    padding: 10px;
}

.flow-party {
    flex: 0 0 150px;
    text-align: center;
    padding: 16px 12px;
    border-radius: 12px;
    border: 2px solid #e0e0e0;
    transition: all 0.4s ease;
    position: relative;
}
.flow-party.highlighted {
    border-color: #667eea;
    box-shadow: 0 0 20px rgba(102,126,234,0.3);
}
.party-icon { font-size: 2em; }
.party-label {
    font-weight: 600;
    font-size: 0.9em;
    margin-top: 6px;
}
.party-label small {
    font-weight: 400;
    color: #888;
    display: block;
}
.code-verifier, .auth-code-display, .challenge-store, .token-display {
    margin-top: 10px;
    padding: 8px;
    background: #f8f9ff;
    border-radius: 6px;
    font-size: 0.75em;
    text-align: left;
}
.code-verifier code, .auth-code-display code,
.challenge-store code, .token-display code {
    display: block;
    word-break: break-all;
    color: #667eea;
    font-family: 'SF Mono', monospace;
    font-size: 0.85em;
    margin-top: 2px;
}

.flow-messages {
    flex: 0 0 150px;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 8px;
    min-height: 200px;
}
.flow-msg {
    padding: 10px 14px;
    border-radius: 8px;
    font-size: 0.78em;
    font-weight: 500;
    text-align: center;
    animation: msgSlide 0.5s ease;
    max-width: 150px;
    word-break: break-word;
    overflow-wrap: break-word;
}
.flow-msg.to-keycloak { background: #e3f2fd; color: #1565c0; }
.flow-msg.to-backend { background: #e8f5e9; color: #2e7d32; }
.flow-msg.to-browser { background: #f3e5f5; color: #6a1b9a; }

@keyframes msgSlide {
    from { opacity: 0; transform: translateX(-15px); }
    to   { opacity: 1; transform: translateX(0); }
}

/* ==================== CLIENT CREDENTIALS FLOW ==================== */
.cc-flow {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 25px;
    flex-wrap: wrap;
    padding: 30px 10px;
}
.cc-party {
    flex: 0 0 160px;
    text-align: center;
    padding: 20px 14px;
    border-radius: 12px;
    border: 2px solid #e0e0e0;
    transition: all 0.4s ease;
}
.cc-party.highlighted {
    border-color: #667eea;
    box-shadow: 0 0 20px rgba(102,126,234,0.3);
}
.cc-credential {
    margin-top: 10px;
    padding: 8px;
    background: #f8f9ff;
    border-radius: 6px;
    font-size: 0.75em;
    text-align: left;
}
.cc-credential code {
    display: block;
    color: #667eea;
    font-family: 'SF Mono', monospace;
    font-size: 0.85em;
}
.cc-arrow {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 6px;
    min-width: 100px;
}
.cc-request, .cc-response {
    padding: 8px 12px;
    border-radius: 8px;
    font-size: 0.8em;
    font-weight: 500;
    text-align: center;
    animation: msgSlide 0.5s ease;
}
.cc-request {
    background: #e3f2fd;
    color: #1565c0;
}
.cc-response {
    background: #e8f5e9;
    color: #2e7d32;
}
.cc-request code, .cc-response code {
    display: block;
    font-family: 'SF Mono', monospace;
    font-size: 0.8em;
    margin-top: 4px;
}

/* ==================== ARCHITECTURE ==================== */
.arch-full {
    display: flex;
    flex-direction: column;
    gap: 8px;
}
.arch-row {
    display: flex;
    justify-content: center;
}
.arch-layer {
    width: 100%;
    max-width: 750px;
    border-radius: 12px;
    padding: 20px;
    border: 2px solid #e0e0e0;
    text-align: center;
}
.arch-users {
    background: #e3f2fd;
    border-color: #90caf9;
}
.arch-keycloak-core {
    background: linear-gradient(135deg, #f8f9ff, #ede7f6);
    border-color: #667eea;
}
.arch-backend {
    background: #e8f5e9;
    border-color: #a5d6a7;
}
.layer-title {
    font-weight: 700;
    font-size: 1.1em;
    margin-bottom: 12px;
}
.layer-items {
    display: flex;
    gap: 8px;
    justify-content: center;
    flex-wrap: wrap;
}
.layer-items span {
    padding: 6px 14px;
    background: white;
    border-radius: 20px;
    font-size: 0.85em;
    font-weight: 500;
    border: 2px solid #e0e0e0;
}
.arch-arrow-down {
    text-align: center;
    color: #999;
    font-size: 1.1em;
    padding: 4px 0;
}
.arch-subgrid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 10px;
}
.arch-sub {
    background: white;
    border-radius: 8px;
    padding: 12px;
    border: 1px solid #e0e0e0;
    text-align: left;
}
.arch-sub strong {
    display: block;
    color: #667eea;
    margin-bottom: 4px;
    font-size: 0.9em;
}
.arch-sub small {
    color: #777;
    font-size: 0.8em;
}

/* ==================== BADGES ==================== */
.badge {
    padding: 4px 10px;
    border-radius: 12px;
    font-size: 0.8em;
    font-weight: 600;
    white-space: nowrap;
}
.badge-good {
    background: #e8f5e9;
    color: #2e7d32;
}
.badge-bad {
    background: #ffebee;
    color: #c62828;
}

/* ==================== COMPARISON TABLE ==================== */
.comparison-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.95em;
}
.comparison-table thead th {
    background: #667eea;
    color: white;
    padding: 14px 16px;
    text-align: left;
    font-weight: 600;
}
.comparison-table thead th:first-child { border-radius: 8px 0 0 0; }
.comparison-table thead th:last-child { border-radius: 0 8px 0 0; }
.comparison-table tbody td {
    padding: 12px 16px;
    border-bottom: 1px solid #eee;
}
.comparison-table tbody tr:nth-child(even) { background: #f8f9ff; }
.comparison-table tbody tr:hover { background: #f0f0ff; }

/* ==================== CODE BLOCKS ==================== */
.code-snippet {
    background: #2c3e50;
    border-radius: 8px;
    padding: 16px;
    margin-top: 12px;
    overflow-x: auto;
}
.code-snippet pre { margin: 0; }
.code-snippet code {
    color: #a8d8a8;
    font-family: 'SF Mono', 'Fira Code', monospace;
    font-size: 0.85em;
    line-height: 1.5;
}
.code-comparison {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(320px, 1fr));
    gap: 16px;
}
.code-block {
    background: #2c3e50;
    border-radius: 10px;
    padding: 20px;
}
.code-block h4 {
    color: #a8d8a8;
    margin-bottom: 12px;
    font-size: 1em;
}
.code-block pre {
    margin: 0;
    overflow-x: auto;
}
.code-block code {
    color: #c5c8c6;
    font-family: 'SF Mono', 'Fira Code', monospace;
    font-size: 0.82em;
    line-height: 1.6;
}

/* ==================== STATUS LOG ==================== */
.status-log {
    background: #1e1e2e;
    border-radius: 12px;
    overflow: hidden;
    margin-top: 20px;
}
.log-header {
    background: #2c2c3e;
    color: #a8d8a8;
    padding: 10px 16px;
    font-weight: 600;
    font-size: 0.9em;
}
.log-content {
    padding: 12px 16px;
    max-height: 180px;
    overflow-y: auto;
    font-family: 'SF Mono', 'Fira Code', monospace;
    font-size: 0.8em;
    color: #c5c8c6;
    line-height: 1.8;
}
.log-content .log-entry { padding: 2px 0; }
.log-content .log-time { color: #888; margin-right: 8px; }
.log-content .log-success { color: #4caf50; }
.log-content .log-warning { color: #ff9800; }
.log-content .log-error { color: #f44336; }
.log-content .log-info { color: #64b5f6; }
.log-content .log-keycloak { color: #ce93d8; }

/* ==================== RESPONSIVE ==================== */
@media (max-width: 768px) {
    header h1 { font-size: 1.8em; }
    .auth-flow-diagram { flex-direction: column; align-items: center; }
    .flow-party { flex: auto; width: 100%; max-width: 300px; }
    .flow-messages { flex-direction: row; min-height: auto; flex-wrap: wrap; }
    .arch-subgrid { grid-template-columns: 1fr; }
    .concept-grid.two-col { grid-template-columns: 1fr; }
    .code-comparison { grid-template-columns: 1fr; }
    .flow-picker { flex-direction: column; }
    .picker-result { flex: auto; }
}
