:root {
    --bg: #0f1117;
    --bg-card: #1a1d27;
    --bg-input: #252830;
    --border: #2d3140;
    --accent: #6c63ff;
    --accent-hover: #5a52e0;
    --green: #10b981;
    --red: #ef4444;
    --yellow: #f59e0b;
    --text: #e4e4e7;
    --text-dim: #71717a;
    --text-bright: #fafafa;
}

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

body {
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
    background: var(--bg);
    color: var(--text);
    line-height: 1.6;
    min-height: 100vh;
}

/* Top Navigation */
.top-nav {
    background: var(--bg-card);
    border-bottom: 1px solid var(--border);
    padding: 0 20px;
    position: sticky;
    top: 0;
    z-index: 100;
}

.top-nav-inner {
    max-width: 1100px;
    margin: 0 auto;
    display: flex;
    align-items: center;
    justify-content: space-between;
    height: 48px;
}

.nav-brand {
    font-size: 16px;
    font-weight: 700;
    color: var(--text-bright);
    text-decoration: none;
}

.nav-brand span { color: var(--accent); }

.top-nav-right {
    display: flex;
    align-items: center;
    gap: 20px;
}

.top-nav-right a {
    font-size: 13px;
    color: var(--text-dim);
    text-decoration: none;
    transition: color 0.15s;
}

.top-nav-right a:hover { color: var(--text-bright); }

/* Ethics banner */
.ethics-banner {
    background: rgba(245, 158, 11, 0.08);
    border-bottom: 1px solid rgba(245, 158, 11, 0.15);
    padding: 8px 20px;
    text-align: center;
    font-size: 12px;
    color: var(--yellow);
}

.ethics-banner strong {
    color: var(--yellow);
}

/* Modal */
.modal-overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.6);
    z-index: 200;
    align-items: center;
    justify-content: center;
    padding: 20px;
}

.modal-overlay.open {
    display: flex;
}

.modal-box {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: 12px;
    max-width: 640px;
    width: 100%;
    max-height: 80vh;
    overflow-y: auto;
}

.modal-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 16px 20px;
    border-bottom: 1px solid var(--border);
}

.modal-header h3 {
    font-size: 16px;
    font-weight: 600;
    color: var(--text-bright);
}

.modal-close {
    font-size: 22px;
    color: var(--text-dim);
    cursor: pointer;
    line-height: 1;
}

.modal-close:hover { color: var(--text-bright); }

.modal-body {
    padding: 20px;
    font-size: 13px;
    color: var(--text);
    line-height: 1.7;
}

.modal-body h4 {
    font-size: 14px;
    font-weight: 600;
    color: var(--text-bright);
    margin-top: 16px;
    margin-bottom: 6px;
}

.modal-body h4:first-child { margin-top: 0; }

.modal-body p { margin-bottom: 8px; }

.modal-body ul {
    margin: 0 0 8px 20px;
}

.modal-body li { margin-bottom: 4px; }

.modal-body pre {
    background: var(--bg-input);
    border: 1px solid var(--border);
    border-radius: 6px;
    padding: 12px;
    overflow-x: auto;
    margin: 8px 0;
}

.modal-body code {
    font-family: 'JetBrains Mono', monospace;
    font-size: 12px;
    color: var(--accent);
}

.modal-body pre code {
    color: var(--text);
}

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

/* Header */
.header {
    text-align: center;
    margin-bottom: 40px;
}

.header h1 {
    font-size: 28px;
    font-weight: 700;
    color: var(--text-bright);
    margin-bottom: 8px;
}

.header h1 span { color: var(--accent); }

.header p {
    color: var(--text-dim);
    font-size: 14px;
}

/* (header-links moved to top-nav) */

/* Input Section */
.input-section {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: 12px;
    padding: 24px;
    margin-bottom: 24px;
}

.input-group {
    flex: 1;
}

.input-group label {
    display: block;
    font-size: 13px;
    font-weight: 600;
    color: var(--text-dim);
    margin-bottom: 6px;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.input-group input[type="text"],
.input-group input[type="password"] {
    width: 100%;
    padding: 12px 16px;
    background: var(--bg-input);
    border: 1px solid var(--border);
    border-radius: 8px;
    color: var(--text-bright);
    font-size: 14px;
    font-family: 'JetBrains Mono', 'Fira Code', monospace;
    transition: border-color 0.2s;
}

.input-group input:focus {
    outline: none;
    border-color: var(--accent);
}

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

/* Buttons */
.btn {
    padding: 12px 24px;
    border: none;
    border-radius: 8px;
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s;
    white-space: nowrap;
}

.btn-primary {
    background: var(--accent);
    color: white;
}

.btn-primary:hover { background: var(--accent-hover); }
.btn-primary:disabled { opacity: 0.5; cursor: not-allowed; }

.btn-outline {
    background: transparent;
    border: 1px solid var(--border);
    color: var(--text);
}

.btn-outline:hover {
    background: var(--bg-input);
    border-color: var(--accent);
}

.btn-xs {
    padding: 3px 10px !important;
    font-size: 11px !important;
}

/* Toolbar */
.toolbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-top: 12px;
    padding-top: 12px;
    border-top: 1px solid var(--border);
}

.toolbar-left, .toolbar-right {
    display: flex;
    align-items: center;
    gap: 12px;
}

.toolbar-divider {
    width: 1px;
    height: 16px;
    background: var(--border);
}

.toolbar-link {
    font-size: 12px;
    color: var(--text-dim);
    cursor: pointer;
    transition: color 0.15s;
    user-select: none;
}

.toolbar-link:hover { color: var(--accent); }
.toolbar-link .arrow { font-size: 9px; }

/* Toggle switch */
.toggle-switch {
    display: flex;
    align-items: center;
    gap: 8px;
    cursor: pointer;
}

.toggle-switch input { display: none !important; }

.toggle-track {
    width: 32px;
    height: 18px;
    background: var(--bg-input);
    border: 1px solid var(--border);
    border-radius: 9px;
    position: relative;
    transition: all 0.2s;
}

.toggle-thumb {
    width: 12px;
    height: 12px;
    background: var(--text-dim);
    border-radius: 50%;
    position: absolute;
    top: 2px;
    left: 2px;
    transition: all 0.2s;
}

.toggle-switch input:checked ~ .toggle-track {
    background: rgba(245, 158, 11, 0.2);
    border-color: var(--yellow);
}

.toggle-switch input:checked ~ .toggle-track .toggle-thumb {
    left: 16px;
    background: var(--yellow);
}

.toggle-label {
    font-size: 12px;
    color: var(--text-dim);
    font-weight: 500;
}

.toggle-switch input:checked ~ .toggle-label { color: var(--yellow); }

/* Collapsible sections */
.collapsible {
    display: none;
    margin-top: 12px;
    padding-top: 12px;
    border-top: 1px solid var(--border);
}

.collapsible.open { display: block; }

.modules-grid-inner {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
}

/* Module chips — no inputs, just styled spans */
.module-chip {
    display: inline-block;
    padding: 5px 12px;
    border-radius: 6px;
    font-size: 12px;
    font-family: 'JetBrains Mono', monospace;
    background: var(--bg-input);
    border: 1px solid var(--border);
    color: var(--text-dim);
    cursor: pointer;
    transition: all 0.15s;
    user-select: none;
}

.module-chip.active {
    background: rgba(108, 99, 255, 0.15);
    border-color: var(--accent);
    color: var(--accent);
}

.module-chip:hover {
    border-color: var(--accent);
}

.modules-actions {
    display: flex;
    gap: 6px;
    margin-left: auto;
}

/* Status */
.status {
    text-align: center;
    padding: 20px;
    color: var(--text-dim);
    font-size: 14px;
}

.status.error { color: var(--red); }

.spinner {
    display: inline-block;
    width: 20px;
    height: 20px;
    border: 2px solid var(--border);
    border-top-color: var(--accent);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
    margin-right: 8px;
    vertical-align: middle;
}

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

/* Results */
.results { display: none; }

.key-badge {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    padding: 10px 16px;
    border-radius: 8px;
    font-size: 14px;
    font-weight: 600;
    margin-bottom: 20px;
}

.key-badge.live { background: rgba(239, 68, 68, 0.15); color: var(--red); border: 1px solid rgba(239, 68, 68, 0.3); }
.key-badge.test { background: rgba(245, 158, 11, 0.15); color: var(--yellow); border: 1px solid rgba(245, 158, 11, 0.3); }

.permissions-bar {
    display: flex;
    gap: 16px;
    margin-bottom: 24px;
    font-size: 13px;
}

.perm-item { display: flex; align-items: center; gap: 4px; }
.perm-item.allowed { color: var(--green); }
.perm-item.denied { color: var(--red); }
.perm-item.errors { color: var(--yellow); }

/* Module Cards */
.module-card {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: 12px;
    margin-bottom: 16px;
    overflow: hidden;
}

.module-header {
    padding: 14px 20px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    cursor: pointer;
    transition: background 0.15s;
}

.module-header:hover { background: rgba(255,255,255,0.02); }

.module-title {
    font-size: 14px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.module-badge {
    font-size: 11px;
    padding: 3px 8px;
    border-radius: 4px;
    font-weight: 600;
}

.module-badge.success { background: rgba(16, 185, 129, 0.15); color: var(--green); }
.module-badge.failed { background: rgba(239, 68, 68, 0.15); color: var(--red); }

.module-body {
    padding: 0 20px 20px;
    display: none;
}

.module-card.open .module-body { display: block; }

/* Scrollable table wrapper */
.table-scroll {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    margin: 0 -4px;
    padding: 0 4px;
}

/* Data Table */
.data-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 13px;
}

.data-table th {
    text-align: left;
    padding: 8px 12px;
    font-size: 11px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    color: var(--text-dim);
    border-bottom: 1px solid var(--border);
}

.data-table td {
    padding: 8px 12px;
    border-bottom: 1px solid rgba(255,255,255,0.04);
    color: var(--text);
    max-width: 250px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.data-table tr:last-child td { border-bottom: none; }
.data-table tr:hover td { background: rgba(255,255,255,0.02); }

/* Key-Value pairs */
.kv-row {
    display: flex;
    padding: 6px 0;
    border-bottom: 1px solid rgba(255,255,255,0.04);
    font-size: 13px;
}

.kv-row:last-child { border-bottom: none; }
.kv-key { width: 200px; color: var(--text-dim); font-weight: 500; flex-shrink: 0; }
.kv-val { color: var(--text); word-break: break-all; }

/* Actions bar */
.actions-bar {
    display: flex;
    gap: 8px;
    margin: 24px 0;
    padding: 16px 0;
    border-top: 1px solid var(--border);
    border-bottom: 1px solid var(--border);
}

/* GitHub Corner */
.github-corner {
    position: fixed;
    top: 0;
    right: 0;
    z-index: 999;
}

.github-corner svg {
    fill: var(--accent);
    color: var(--bg);
}

.github-corner:hover .octo-arm {
    animation: octocat-wave 560ms ease-in-out;
}

@keyframes octocat-wave {
    0%, 100% { transform: rotate(0); }
    20%, 60% { transform: rotate(-25deg); }
    40%, 80% { transform: rotate(10deg); }
}

@keyframes notif-pulse {
    0%, 100% { transform: scale(1); opacity: 1; }
    50% { transform: scale(1.6); opacity: 0.5; }
}

@media (max-width: 480px) {
    .github-corner svg { width: 60px; height: 60px; }
    .github-corner::after { top: 5px; right: 5px; width: 9px; height: 9px; }
}

/* Floating Social Icons */
.floating-socials {
    position: fixed;
    bottom: 24px;
    left: 24px;
    display: flex;
    flex-direction: column;
    gap: 10px;
    z-index: 80;
}

.social-fab {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    background: var(--bg-card);
    border: 1px solid var(--border);
    color: var(--text-dim);
    display: flex;
    align-items: center;
    justify-content: center;
    text-decoration: none;
    box-shadow: 0 2px 8px rgba(0,0,0,0.2);
    transition: all 0.2s;
}

.social-fab:hover {
    color: var(--text-bright);
    border-color: var(--accent);
    transform: scale(1.1);
}

.social-fab.github {
    animation: notif-bounce 2s ease-in-out infinite;
}

.social-fab.github::after {
    content: '';
    position: absolute;
    top: -2px;
    right: -2px;
    width: 10px;
    height: 10px;
    background: var(--red);
    border-radius: 50%;
    animation: notif-pulse 1.5s ease-in-out infinite;
    box-shadow: 0 0 4px var(--red);
}

/* GitHub bubble message */
.gh-bubble {
    position: absolute;
    left: 52px;
    bottom: 8px;
    background: var(--accent);
    color: #fff;
    font-size: 12px;
    font-weight: 600;
    padding: 6px 12px;
    border-radius: 8px;
    white-space: nowrap;
    opacity: 0;
    transform: translateX(-8px);
    pointer-events: none;
    animation: bubble-in 0.4s ease forwards;
    animation-delay: 5s;
    box-shadow: 0 4px 12px rgba(108, 99, 255, 0.3);
}

.gh-bubble::before {
    content: '';
    position: absolute;
    left: -6px;
    bottom: 10px;
    border: 6px solid transparent;
    border-right-color: var(--accent);
    border-left: none;
}

@keyframes bubble-in {
    0% { opacity: 0; transform: translateX(-8px); }
    100% { opacity: 1; transform: translateX(0); }
}

@keyframes notif-bounce {
    0%, 85%, 100% { transform: translateY(0); }
    90% { transform: translateY(-6px); }
    95% { transform: translateY(0); }
}

/* Floating History Button */
.history-fab {
    position: fixed;
    bottom: 24px;
    right: 24px;
    width: 48px;
    height: 48px;
    border-radius: 50%;
    background: var(--bg-card);
    border: 1px solid var(--border);
    color: var(--text);
    font-size: 20px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 4px 12px rgba(0,0,0,0.3);
    transition: all 0.2s;
    z-index: 80;
}

.history-fab:hover {
    border-color: var(--accent);
    transform: scale(1.08);
}

.history-fab span:not(:empty) {
    position: absolute;
    top: -4px;
    right: -4px;
    background: var(--accent);
    color: #fff;
    font-size: 10px;
    font-weight: 700;
    min-width: 18px;
    height: 18px;
    border-radius: 9px;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0 4px;
}

/* History Panel */
.history-panel {
    position: fixed;
    top: 48px;
    right: -320px;
    width: 300px;
    height: calc(100vh - 48px);
    background: var(--bg-card);
    border-left: 1px solid var(--border);
    z-index: 90;
    transition: right 0.25s ease;
    overflow-y: auto;
}

.history-panel.open { right: 0; }

.history-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 14px 16px;
    font-size: 14px;
    font-weight: 600;
    color: var(--text-bright);
    border-bottom: 1px solid var(--border);
}

.history-item {
    padding: 10px 16px;
    border-bottom: 1px solid var(--border);
    cursor: pointer;
    transition: background 0.15s;
}

.history-item:hover { background: rgba(108, 99, 255, 0.06); }

/* Light Theme */
body.light-theme {
    --bg: #f5f5f7;
    --bg-card: #ffffff;
    --bg-input: #f0f0f2;
    --border: #d4d4d8;
    --text: #27272a;
    --text-dim: #71717a;
    --text-bright: #09090b;
}

body.light-theme .top-nav { background: #fff; border-color: #e4e4e7; }
body.light-theme .ethics-banner { background: rgba(245,158,11,0.06); border-color: rgba(245,158,11,0.12); }
body.light-theme .module-card { border-color: #e4e4e7; }
body.light-theme .modal-box { background: #fff; border-color: #e4e4e7; }
body.light-theme .modal-header { border-color: #e4e4e7; }
body.light-theme .modal-body pre { background: #f4f4f5; border-color: #e4e4e7; }
body.light-theme .data-table th { border-color: #e4e4e7; }
body.light-theme .data-table td { border-color: #f4f4f5; }
body.light-theme .toolbar { border-color: #e4e4e7; }
body.light-theme .collapsible { border-color: #e4e4e7; }
body.light-theme .toggle-track { background: #e4e4e7; border-color: #d4d4d8; }
body.light-theme .toggle-thumb { background: #a1a1aa; }

/* Responsive */
@media (max-width: 768px) {
    .container { padding: 20px 12px; }

    .header h1 { font-size: 22px; }
    .header p { font-size: 12px; }

    .input-section { padding: 16px; }

    .top-nav-right { gap: 12px; padding-right: 50px; }
    .top-nav-right a { font-size: 12px; }

    .toolbar { flex-wrap: wrap; gap: 8px; }
    .toolbar-left, .toolbar-right { gap: 8px; }

    .permissions-bar { flex-wrap: wrap; gap: 8px; }

    .kv-row { flex-direction: column; gap: 2px; }
    .kv-key { width: auto; }

    .actions-bar { flex-wrap: wrap; }
    .actions-bar .btn { flex: 1; min-width: 120px; text-align: center; }

    .module-header { padding: 12px 14px; }
    .module-body { padding: 0 14px 14px; }
    .module-title { font-size: 12px; }

    .data-table td { font-size: 11px; padding: 6px 8px; }
    .data-table th { font-size: 10px; padding: 6px 8px; }

    .modal-box { max-width: 95vw; max-height: 90vh; }

    .history-panel { width: 85vw; right: -85vw; }

    .history-fab { bottom: 16px; right: 16px; width: 44px; height: 44px; font-size: 18px; }
    .floating-socials { bottom: 16px; left: 16px; gap: 8px; }
    .social-fab { width: 36px; height: 36px; }
    .social-fab svg { width: 16px; height: 16px; }

    .ethics-banner { font-size: 11px; padding: 6px 12px; }
}

@media (max-width: 480px) {
    .top-nav-inner { height: 42px; }
    .nav-brand { font-size: 14px; }
    .top-nav-right { gap: 8px; padding-right: 40px; }
    .top-nav-right a { font-size: 11px; }

    .header { margin-bottom: 20px; }
    .header h1 { font-size: 20px; }

    .input-section { padding: 12px; }
    .input-group label { font-size: 11px; }
    .input-group input[type="text"],
    .input-group input[type="password"] { font-size: 12px; padding: 10px 12px; }
    .btn-primary { padding: 10px 18px; font-size: 13px; }

    .module-chip { font-size: 11px; padding: 4px 8px; }

    .actions-bar .btn { font-size: 11px; padding: 8px 10px; min-width: 0; flex: 1; }
}
