@import url('https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700&family=Outfit:wght@400;500;600;700&display=swap');

:root {
    --primary: #00e5ff;
    --primary-glow: rgba(0, 229, 255, 0.24);
    --secondary: #7000ff;

    --bg-dark: #0a0c10;
    --bg-elevated: #10141c;
    --bg-card: rgba(255, 255, 255, 0.05);

    --text-main: #f8faff;
    --text-muted: #8e99ab;

    --border: rgba(255, 255, 255, 0.1);
    --border-strong: rgba(255, 255, 255, 0.18);

    --glass-bg: rgba(15, 20, 30, 0.72);
    --glass-blur: blur(18px);

    --sidebar-width: 290px;
    --header-height: 76px;
    --radius-sm: 12px;
    --radius-md: 16px;
    --radius-lg: 20px;
    --radius-xl: 24px;

    --shadow-soft: 0 10px 30px rgba(0, 0, 0, 0.22);
    --transition: 180ms cubic-bezier(0.4, 0, 0.2, 1);

    --content-max: 1600px;
    --page-pad: 24px;
    --grid-min: 240px;
}

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

html {
    height: 100%;
    -webkit-text-size-adjust: 100%;
}

body {
    min-height: 100%;
    margin: 0;
    font-family: 'Inter', sans-serif;
    background:
        radial-gradient(circle at top right, rgba(112, 0, 255, 0.12), transparent 30%),
        radial-gradient(circle at top left, rgba(0, 229, 255, 0.08), transparent 28%),
        var(--bg-dark);
    color: var(--text-main);
    overflow: hidden;
    /* clave: evitamos scroll global y delegamos en main */
}

h1,
h2,
h3,
.brand {
    font-family: 'Outfit', sans-serif;
    margin: 0;
}

button,
input {
    font: inherit;
}

img,
svg {
    display: block;
    max-width: 100%;
}

.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;
}

/* App layout */
.app-container {
    height: 100dvh;
    display: grid;
    grid-template-columns: var(--sidebar-width) minmax(0, 1fr);
    overflow: hidden;
}

/* Sidebar */
.sidebar {
    min-width: 0;
    display: flex;
    flex-direction: column;
    background: rgba(8, 11, 17, 0.94);
    border-right: 1px solid var(--border);
    overflow: hidden;
    z-index: 30;
}

.sidebar.collapsed {
    transform: translateX(-100%);
}

.sidebar-header {
    min-height: var(--header-height);
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    padding: 18px 20px;
    border-bottom: 1px solid var(--border);
    background: rgba(10, 12, 16, 0.85);
    backdrop-filter: var(--glass-blur);
}

.brand {
    font-size: 1.35rem;
    font-weight: 700;
    line-height: 1.1;
    background: linear-gradient(135deg, var(--primary), var(--secondary));
    -webkit-background-clip: text;
    background-clip: text;
    -webkit-text-fill-color: transparent;
    letter-spacing: -0.03em;
}

.sidebar-nav {
    flex: 1;
    overflow-y: auto;
    overflow-x: hidden;
    padding: 10px 0 18px;
    scrollbar-width: thin;
    scrollbar-color: rgba(255, 255, 255, 0.18) transparent;
}

.sidebar-nav::-webkit-scrollbar {
    width: 8px;
}

.sidebar-nav::-webkit-scrollbar-thumb {
    background: rgba(255, 255, 255, 0.16);
    border-radius: 999px;
}

.nav-item {
    width: 100%;
    appearance: none;
    background: transparent;
    border: none;
    border-left: 3px solid transparent;
    color: var(--text-muted);
    display: flex;
    align-items: center;
    gap: 12px;
    text-align: left;
    padding: 14px 18px 14px 20px;
    cursor: pointer;
    transition:
        background-color var(--transition),
        color var(--transition),
        border-color var(--transition);
    font-weight: 500;
    font-size: 0.95rem;
}

.nav-item:hover {
    color: var(--text-main);
    background: rgba(255, 255, 255, 0.05);
}

.nav-item.active {
    color: var(--text-main);
    border-left-color: var(--primary);
    background: linear-gradient(90deg, rgba(0, 229, 255, 0.12), transparent 85%);
}

/* Main column */
.main-wrapper {
    min-width: 0;
    height: 100dvh;
    display: grid;
    grid-template-rows: auto 1fr;
    overflow: hidden;
}

/* Header */
.main-header {
    min-height: var(--header-height);
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
    padding: 14px var(--page-pad);
    border-bottom: 1px solid var(--border);
    background: rgba(10, 12, 16, 0.84);
    backdrop-filter: blur(12px);
    position: sticky;
    top: 0;
    z-index: 20;
}

.search-container {
    flex: 1;
    min-width: 0;
    max-width: 720px;
    position: relative;
}

.search-input {
    width: 100%;
    min-height: 46px;
    padding: 0.8rem 1rem 0.8rem 2.9rem;
    border-radius: var(--radius-sm);
    border: 1px solid var(--border);
    background: var(--bg-card);
    color: var(--text-main);
    font-size: 0.95rem;
    outline: none;
    transition:
        border-color var(--transition),
        box-shadow var(--transition),
        background-color var(--transition);
}

.search-input::placeholder {
    color: #9ca8ba;
}

.search-input:focus {
    border-color: var(--primary);
    box-shadow: 0 0 0 4px var(--primary-glow);
    background: rgba(255, 255, 255, 0.07);
}

.search-icon {
    position: absolute;
    left: 0.95rem;
    top: 50%;
    transform: translateY(-50%);
    color: var(--text-muted);
    pointer-events: none;
}

.header-actions {
    display: flex;
    align-items: center;
    gap: 10px;
    flex-shrink: 0;
}

.btn-icon {
    width: 44px;
    height: 44px;
    flex-shrink: 0;
    border-radius: var(--radius-sm);
    border: 1px solid var(--border);
    background: var(--bg-card);
    color: var(--text-main);
    display: inline-flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition:
        background-color var(--transition),
        border-color var(--transition),
        transform var(--transition);
}

.btn-icon:hover {
    background: rgba(255, 255, 255, 0.1);
    border-color: var(--border-strong);
    transform: translateY(-1px);
}

.btn-icon:focus-visible,
.nav-item:focus-visible,
.card:focus-visible,
.search-input:focus-visible {
    outline: none;
    box-shadow: 0 0 0 4px var(--primary-glow);
}

/* Main content: único scroll principal */
.content-body {
    min-width: 0;
    min-height: 0;
    overflow-y: auto;
    overflow-x: hidden;
    padding: 24px var(--page-pad) 32px;
    scrollbar-width: thin;
    scrollbar-color: rgba(255, 255, 255, 0.18) transparent;
}

.content-body::-webkit-scrollbar {
    width: 10px;
}

.content-body::-webkit-scrollbar-thumb {
    background: rgba(255, 255, 255, 0.16);
    border-radius: 999px;
}

.content-body>* {
    max-width: var(--content-max);
    margin-left: auto;
    margin-right: auto;
}

.breadcrumb {
    color: var(--text-muted);
    font-size: 0.8rem;
    margin-bottom: 10px;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    line-height: 1.4;
    word-break: break-word;
}

.view-header {
    margin-bottom: 24px;
}

.view-title {
    font-size: clamp(1.7rem, 3vw, 2.5rem);
    line-height: 1.08;
    font-weight: 700;
    letter-spacing: -0.03em;
}

.view-description {
    margin-top: 8px;
    max-width: 70ch;
    color: var(--text-muted);
    line-height: 1.55;
    font-size: 0.98rem;
}

/* Grid */
.region-grid,
.technique-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(min(var(--grid-min), 100%), 1fr));
    gap: 16px;
    align-items: stretch;
}

/* Card */
.card {
    position: relative;
    overflow: hidden;
    min-width: 0;
    min-height: 160px;
    background: linear-gradient(180deg, rgba(255, 255, 255, 0.055), rgba(255, 255, 255, 0.04));
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    padding: 20px;
    cursor: pointer;
    transition:
        transform var(--transition),
        border-color var(--transition),
        background-color var(--transition),
        box-shadow var(--transition);
    box-shadow: var(--shadow-soft);
}

.card:hover {
    transform: translateY(-3px);
    border-color: rgba(0, 229, 255, 0.4);
    background: rgba(255, 255, 255, 0.08);
}

.card::before {
    content: '';
    position: absolute;
    inset: 0;
    background: radial-gradient(circle at top right, rgba(0, 229, 255, 0.1), transparent 40%);
    opacity: 0;
    transition: opacity var(--transition);
    pointer-events: none;
}

.card:hover::before {
    opacity: 1;
}

.card-icon {
    width: 48px;
    height: 48px;
    border-radius: 14px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    margin-bottom: 16px;
    color: var(--primary);
    background: rgba(0, 229, 255, 0.12);
    border: 1px solid rgba(0, 229, 255, 0.16);
}

.card-title {
    font-size: 1.02rem;
    font-weight: 600;
    color: var(--text-main);
    line-height: 1.35;
    margin-bottom: 6px;
    text-wrap: balance;
}

.card-subtitle {
    font-size: 0.92rem;
    line-height: 1.45;
    color: var(--text-muted);
}

/* Template Layout via Iframe */
.template-wrapper {
    height: 100%;
    display: flex;
    flex-direction: column;
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius-xl);
    overflow: hidden;
    box-shadow: var(--shadow-soft);
}

.template-header {
    padding: 1.5rem 2rem;
    border-bottom: 1px solid var(--border);
    display: flex;
    justify-content: space-between;
    align-items: center;
    background: rgba(255, 255, 255, 0.02);
}

.template-info h2 {
    font-size: 1.4rem;
    margin-bottom: 4px;
}

.tech-badge {
    font-size: 0.75rem;
    background: var(--primary-glow);
    color: var(--primary);
    padding: 3px 10px;
    border-radius: 99px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.iframe-container {
    flex: 1;
    min-height: 700px;
    background: white;
    /* Important for existing light-mode templates to look good */
    position: relative;
}

.iframe-container iframe {
    width: 100%;
    height: 100%;
    border: none;
    background: white;
}

.placeholder-text {
    color: var(--text-muted);
    text-align: center;
    line-height: 1.6;
    margin-top: 0;
}

/* Utilities */
.no-js-message {
    padding: 16px;
    background: #2b1220;
    color: #ffd5e3;
    text-align: center;
    font-size: 0.95rem;
}

/* Animations */
@keyframes fadeIn {
    from {
        opacity: 0;
        transform: translateY(8px);
    }

    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.animate-fade {
    animation: fadeIn 0.25s ease forwards;
}

/* Tablet landscape / portátiles pequeños */
@media (max-width: 1180px) {
    :root {
        --sidebar-width: 250px;
        --page-pad: 20px;
        --grid-min: 220px;
    }

    .sidebar-header {
        padding: 16px 16px;
    }

    .nav-item {
        padding: 13px 14px 13px 16px;
        font-size: 0.92rem;
    }

    .content-body {
        padding-top: 20px;
    }

    .card {
        min-height: 150px;
        padding: 18px;
    }
}

/* Tablet vertical y móvil grande */
@media (max-width: 900px) {
    :root {
        --header-height: auto;
        --page-pad: 16px;
        --grid-min: 210px;
    }

    .app-container {
        grid-template-columns: 1fr;
    }

    .sidebar {
        position: fixed;
        inset: 0 auto 0 0;
        width: min(82vw, 320px);
        max-width: 320px;
        height: 100dvh;
        transform: translateX(-100%);
        transition: transform var(--transition);
        box-shadow: 20px 0 50px rgba(0, 0, 0, 0.35);
    }

    .sidebar.is-open {
        transform: translateX(0);
    }

    .main-wrapper {
        grid-template-rows: auto 1fr;
        height: 100dvh;
    }

    .main-header {
        padding: 12px var(--page-pad);
        flex-wrap: wrap;
        align-items: stretch;
    }

    .search-container {
        order: 2;
        width: 100%;
        max-width: none;
    }

    .header-actions {
        order: 1;
        width: 100%;
        justify-content: flex-end;
    }

    .content-body {
        padding: 18px var(--page-pad) 28px;
    }

    .region-grid,
    .technique-grid {
        grid-template-columns: repeat(2, minmax(0, 1fr));
    }

    .template-container {
        min-height: auto;
    }
}

/* Móvil */
@media (max-width: 640px) {
    :root {
        --page-pad: 14px;
        --grid-min: 100%;
    }

    .main-header {
        gap: 12px;
    }

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

    .header-actions {
        gap: 8px;
    }

    .btn-icon {
        width: 42px;
        height: 42px;
    }

    .view-header {
        margin-bottom: 18px;
    }

    .breadcrumb {
        font-size: 0.74rem;
        margin-bottom: 8px;
    }

    .view-title {
        font-size: 1.55rem;
    }

    .view-description {
        font-size: 0.94rem;
    }

    .region-grid,
    .technique-grid {
        grid-template-columns: 1fr;
        gap: 12px;
    }

    .card {
        min-height: 132px;
        padding: 16px;
        border-radius: 18px;
    }

    .card-icon {
        width: 42px;
        height: 42px;
        margin-bottom: 14px;
    }

    .card-title {
        font-size: 0.98rem;
    }

    .card-subtitle {
        font-size: 0.88rem;
    }

    .template-container {
        border-radius: 20px;
        padding: 16px;
    }
}

/* Pantallas bajas: evitar sensación de doble scroll vertical */
@media (max-height: 760px) {

    .sidebar-header,
    .main-header {
        min-height: 64px;
    }

    .content-body {
        padding-top: 16px;
    }

    .view-header {
        margin-bottom: 16px;
    }

    .card {
        min-height: 128px;
    }
}

/* Reduce motion */
@media (prefers-reduced-motion: reduce) {
    * {
        animation: none !important;
        transition: none !important;
        scroll-behavior: auto !important;
    }
}