/* ---------- Base Design System (spark-widget-shell) ---------- */
:root {
    --primary: #0b57d0;
    --on-primary: #fff;
    --primary-container: #d3e3fd;
    --surface: #fff;
    --surface-container: #f0f4f9;
    --surface-container-high: #e9ebf0;
    --on-surface-default: #1b1c1d;
    --on-surface-de-emphasis: #444746;
    --outline: #747775;
    --stroke-default: #dcdfe5;
    --ff-sans: "Google Sans", "Roboto", sans-serif;
    --ff-mono: "Google Code", "SF Mono", monospace;
    --control-label-width: 130px;
    --component-height-default: 36px;
    --radius-m: 12px;
}

@media (prefers-color-scheme: dark) {
    :root {
        --primary: #a8c7fa;
        --surface: #101218;
        --surface-container: #282a2c;
        --surface-container-high: #2a2b36;
        --on-surface-default: #fff;
        --on-surface-de-emphasis: #c4c7c5;
        --outline: #9a9b9c;
        --stroke-default: #2d2f38;
    }
}

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

/* Normal scrolling layout */
body, html {
    min-height: 100%;
    overflow: auto;
    font-family: var(--ff-sans);
    background: var(--surface-container);
}

.app-layout {
    min-height: 100vh;
    display: flex;
    flex-direction: column;
    background: var(--surface);
}

.widget-container {
    display: flex;
    flex-direction: column;
    width: 100%;
}

.widget-header {
    padding: 0.75rem 1rem;
    background: var(--surface);
    border-bottom: 1px solid var(--stroke-default);
}

.header-top {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 1rem;
    flex-wrap: wrap;
}

.widget-title {
    font-size: 1.3rem;
    font-weight: 500;
    color: var(--on-surface-default);
    margin: 0;
}

.widget-title a {
    text-decoration: none;
    color: inherit;
}

.action-buttons-top {
    display: flex;
    gap: 0.75rem;
}

.button {
    font-family: var(--ff-sans);
    font-size: 0.85rem;
    font-weight: 500;
    padding: 0.4rem 1rem;
    border-radius: 2rem;
    border: none;
    cursor: pointer;
    background: var(--surface-container-high);
    color: var(--on-surface-default);
    transition: 0.2s;
}

.button.primary-action {
    background: var(--primary);
    color: var(--on-primary);
}

.button:hover {
    filter: brightness(0.95);
}

.full-width {
    width: 100%;
}

.editorial-layout {
    flex: 1;
    display: flex;
    flex-direction: column;
    overflow: visible;
}

.editorial-viz-panel {
    flex: 1;
    background: var(--surface-container-lowest);
    min-height: 250px;
}

.split-panels {
    display: flex;
    gap: 1rem;
    padding: 1rem;
    min-height: 400px;
    box-sizing: border-box;
}

.panel {
    flex: 1;
    display: flex;
    flex-direction: column;
    background: var(--surface);
    border-radius: var(--radius-m);
    border: 1px solid var(--stroke-default);
    overflow: hidden;
    transition: all 0.2s;
}

.panel-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0.5rem 1rem;
    background: var(--surface-container);
    border-bottom: 1px solid var(--stroke-default);
    font-size: 0.7rem;
    font-weight: 500;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    color: var(--on-surface-de-emphasis);
}

.output-stats {
    display: flex;
    gap: 1rem;
    font-size: 0.7rem;
}

textarea {
    flex: 1;
    background: var(--surface);
    border: none;
    padding: 1rem;
    font-family: var(--ff-mono);
    font-size: 0.8rem;
    line-height: 1.5;
    resize: none;
    outline: none;
    color: var(--on-surface-default);
}

.controls-root {
    background: var(--surface);
    border-top: 1px solid var(--stroke-default);
    padding: 1rem;
}

.controls-grid {
    display: flex;
    flex-wrap: wrap;
    gap: 1rem;
}

.controls-row {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    flex: 1 1 240px;
    min-width: 200px;
}

.controls-label {
    width: var(--control-label-width);
    font-size: 0.8rem;
    font-weight: 500;
    color: var(--on-surface-de-emphasis);
}

.row-findreplace {
    flex: 1 1 100%;
    flex-wrap: wrap;
}

.findreplace-wrapper {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    flex: 1;
}

.findreplace-wrapper .input-field {
    flex: 1;
}

.arrow-icon {
    font-size: 1.2rem;
    font-weight: bold;
    color: var(--on-surface-de-emphasis);
}

.small-button {
    background: var(--surface-container-high);
    border: none;
    padding: 0.3rem 0.8rem;
    border-radius: 1.5rem;
    cursor: pointer;
    font-size: 0.75rem;
}

.input-field {
    height: var(--component-height-default);
    background: var(--surface-container-high);
    border: 1px solid transparent;
    border-radius: 0.5rem;
    padding: 0 0.75rem;
    font-family: var(--ff-sans);
    font-size: 0.8rem;
    color: var(--on-surface-default);
    outline: none;
}

.input-field:focus {
    border-color: var(--primary);
}

/* Toggle Switch - smooth animation */
.toggle-switch {
    width: 44px;
    height: 24px;
    background: var(--surface-container-high);
    border-radius: 999px;
    position: relative;
    cursor: pointer;
    border: 1px solid var(--outline);
    transition: background 0.2s cubic-bezier(0.2, 0.9, 0.4, 1.1);
}

.toggle-switch:focus-visible {
    outline: none;
    box-shadow: 0 0 0 2px var(--surface), 0 0 0 4px var(--primary);
}

.toggle-knob {
    width: 18px;
    height: 18px;
    background: var(--on-surface-de-emphasis);
    border-radius: 50%;
    position: absolute;
    top: 2px;
    left: 2px;
    transition: transform 0.2s cubic-bezier(0.2, 0.9, 0.4, 1.1), background 0.2s;
    box-shadow: 0 1px 2px rgba(0,0,0,0.2);
}

.toggle-switch.active {
    background: var(--primary);
    border-color: var(--primary);
}

.toggle-switch.active .toggle-knob {
    background: var(--on-primary);
    transform: translateX(20px);
}

.button-bar-bottom {
    margin-top: 1rem;
}

.icon-btn {
    background: transparent;
    border: none;
    cursor: pointer;
    font-size: 1rem;
    padding: 0.25rem 0.5rem;
    border-radius: 1rem;
    color: var(--on-surface-de-emphasis);
}

.icon-btn:hover {
    background: var(--surface-container-high);
}

/* ---------- Navigation Bar (centered) ---------- */
.nav-bar {
    background: var(--surface);
    border-bottom: 1px solid var(--stroke-default);
    padding: 0.5rem 1rem;
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-wrap: nowrap;
    gap: 1rem;
}

.nav-brand {
    font-weight: 600;
    font-size: 1.1rem;
    color: var(--primary);
    flex-shrink: 0;
}

.nav-links {
    display: flex;
    gap: 1.5rem;
    margin: 0 auto;
}

.nav-links a {
    color: var(--on-surface-default);
    text-decoration: none;
    padding: 0.25rem 0.5rem;
    border-radius: 0.5rem;
    transition: background 0.2s;
    white-space: nowrap;
}

.nav-links a:hover {
    background: var(--surface-container-high);
}

.nav-links a.active {
    background: var(--primary-container);
    color: var(--on-surface-primary);
}

/* ---------- Footer ---------- */
.site-footer {
    background: var(--surface);
    border-top: 1px solid var(--stroke-default);
    text-align: center;
    padding: 0.8rem 1rem;
    font-size: 0.75rem;
    color: var(--on-surface-de-emphasis);
}
.footer-links {
    display: flex;
    justify-content: center;
    font-size: 0.9rem;
    gap: 1.5rem;
    flex-wrap: wrap;
    margin-bottom: 0.5rem;
}
.footer-links a {
    color: var(--on-surface-de-emphasis);
    text-decoration: none;
    transition: color 0.2s;
}
.footer-links a:hover {
    color: var(--primary);
}
.footer-copyright {
    opacity: 0.6;
    font-size: 0.9rem;
}

/* ---------- MOBILE FIXES (scrolling + layout) ---------- */
@media (max-width: 768px) {
    /* Allow scrolling on mobile */
    html, body {
        overflow: auto !important;
        height: auto !important;
        min-height: 100%;
    }
    .app-layout {
        overflow: auto !important;
        height: auto !important;
        min-height: 100vh;
        display: flex;
        flex-direction: column;
    }
    .widget-container {
        height: auto !important;
        min-height: 100vh;
        display: flex;
        flex-direction: column;
    }
    .editorial-layout {
        overflow: visible !important;
        flex: 1 0 auto;
    }
    .controls-root {
        overflow: visible !important;
    }

    /* Stack input/output panels */
    .split-panels {
        flex-direction: column;
        height: auto !important;
        padding-bottom: 1rem;
    }
    .panel {
        height: auto !important;
        min-height: 200px;
    }
    textarea {
        min-height: 150px;
    }

    /* Adjust header */
    .header-top {
        flex-direction: column;
        align-items: flex-start;
        gap: 0.5rem;
    }
    .action-buttons-top {
        width: 100%;
        justify-content: flex-start;
    }

    /* Controls become single column */
    .controls-grid {
        flex-direction: column;
        gap: 0.75rem;
    }
    .controls-row {
        flex: 1 1 100%;
        min-width: 0;
        flex-wrap: wrap;
    }
    .controls-label {
        width: 100%;
        margin-bottom: 0.25rem;
    }
    .input-field {
        width: 100%;
    }
    .row-toggle {
        flex-direction: column;
        align-items: flex-start;
    }
    .toggle-switch {
        margin-left: 0;
    }

    /* Find & Replace wrapper */
    .findreplace-wrapper {
        flex-wrap: wrap;
        gap: 0.5rem;
    }
    .findreplace-wrapper .input-field {
        flex: 1 1 100%;
    }
    .arrow-icon {
        font-size: 1rem;
    }

    /* Footer */
    .footer-links {
        gap: 1rem;
        font-size: 0.8rem;
    }

    /* Stats */
    .output-stats {
        flex-wrap: wrap;
        gap: 0.75rem;
        font-size: 0.7rem;
    }

    /* Larger touch targets */
    .button, .icon-btn, .toggle-switch {
        min-height: 24px;
    }
    .icon-btn {
        padding: 0.5rem;
    }

    /* Navigation wrap (if used) */
    .nav-bar {
        flex-wrap: wrap;
        justify-content: center;
        gap: 0.5rem;
    }
    .nav-links {
        margin: 0;
        width: 100%;
        justify-content: center;
    }
}

/* Extra small devices */
@media (max-width: 480px) {
    .widget-title {
        font-size: 1.1rem;
    }
    .panel-header {
        flex-wrap: wrap;
        gap: 0.5rem;
    }
    .output-stats span {
        font-size: 0.65rem;
    }
    .button {
        padding: 0.4rem 0.8rem;
        font-size: 0.8rem;
    }
    .footer-links {
        gap: 0.75rem;
        font-size: 0.75rem;
    }
}
/* ---------- Mini navigation (Simple / Advanced) ---------- */
.mini-nav {
    display: flex;
    justify-content: center;
    gap: 1rem;
    margin: 0.5rem 1rem 0 1rem;
    padding-bottom: 0.5rem;
    border-bottom: 1px solid var(--stroke-default);
}
.mini-nav-link {
    font-size: 0.85rem;
    font-weight: 500;
    padding: 0.3rem 1rem;
    border-radius: 2rem;
    text-decoration: none;
    color: var(--on-surface-de-emphasis);
    background: transparent;
    transition: all 0.2s;
}
.mini-nav-link.active {
    background: var(--primary-container);
    color: var(--on-surface-primary);
    font-weight: 600;
}
.mini-nav-link:hover:not(.active) {
    background: var(--surface-container-high);
}
/* ---------- Help / How to use section ---------- */
.help-section {
    border-top: 1px solid var(--stroke-default);
    background: var(--surface);
}

.help-section-title {
    padding: 0.75rem 1rem;
    font-size: 0.85rem;
    font-weight: 500;
    color: var(--on-surface-de-emphasis);
}

.help-body {
    padding: 0 1rem 1.25rem;
}

.help-intro {
    font-size: 0.82rem;
    color: var(--on-surface-de-emphasis);
    margin-bottom: 1rem;
    line-height: 1.5;
}

.help-grid {
    display: flex;
    flex-wrap: wrap;
    gap: 0.75rem;
    margin-bottom: 1rem;
}

.help-card {
    flex: 1 1 280px;
    background: var(--surface-container);
    border-radius: var(--radius-m);
    padding: 0.85rem 1rem;
    border: 1px solid var(--stroke-default);
}

.help-card-title {
    font-size: 0.8rem;
    font-weight: 600;
    color: var(--on-surface-default);
    margin-bottom: 0.4rem;
    display: flex;
    align-items: center;
    gap: 0.4rem;
    flex-wrap: wrap;
}

.help-badge {
    font-size: 0.68rem;
    font-weight: 500;
    background: var(--primary-container);
    color: var(--primary);
    padding: 0.1rem 0.45rem;
    border-radius: 1rem;
}

.help-card p {
    font-size: 0.78rem;
    color: var(--on-surface-de-emphasis);
    line-height: 1.55;
    margin-bottom: 0.6rem;
}

.help-example {
    background: var(--surface);
    border: 1px solid var(--stroke-default);
    border-radius: 0.5rem;
    padding: 0.55rem 0.75rem;
    font-size: 0.75rem;
    color: var(--on-surface-default);
    line-height: 1.6;
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 0.4rem;
}

.help-example code {
    font-family: var(--ff-mono);
    font-size: 0.73rem;
    background: none;
}

.help-ex-label {
    font-size: 0.68rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.4px;
    color: var(--outline);
    width: 100%;
}

.help-ex-arrow {
    font-weight: bold;
    color: var(--primary);
    font-size: 1rem;
    margin: 0 0.25rem;
}

.help-tip {
    font-size: 0.78rem;
    color: var(--on-surface-de-emphasis);
    background: var(--surface-container);
    border-left: 3px solid var(--primary);
    padding: 0.6rem 0.9rem;
    border-radius: 0 0.5rem 0.5rem 0;
    line-height: 1.5;
}

@media (max-width: 768px) {
    .help-grid {
        flex-direction: column;
    }
    .help-card {
        flex: 1 1 100%;
    }
}
