:root {
    --background: 0 0% 100%;
    --foreground: 240 10% 3.9%;
    --muted: 240 4.8% 95.9%;
    --muted-foreground: 240 3.8% 46.1%;
    --border: 240 5.9% 90%;
    --card: 0 0% 100%;
    --primary: 240 5.9% 10%;
    --primary-foreground: 0 0% 98%;
    --ring: 240 5.9% 10%;
    --radius: 0.75rem;
    --designer-header-h: 3.25rem;
    --designer-mobile-viewport-h: min(56vh, 480px);
    --safe-top: env(safe-area-inset-top, 0px);
    --safe-bottom: env(safe-area-inset-bottom, 0px);
    --safe-left: env(safe-area-inset-left, 0px);
    --safe-right: env(safe-area-inset-right, 0px);
}

/* Override legacy stil.css inside designer */
body.designer-body .tab-pane {
    height: auto !important;
    border: none !important;
}

body.designer-body .nav-pills {
    background: transparent !important;
}

body.designer-body .nav-pills .nav-link.active,
body.designer-body .nav-pills .show > .nav-link {
    color: hsl(var(--foreground)) !important;
    background: hsl(var(--muted)) !important;
    border-radius: calc(var(--radius) - 4px) !important;
}

body.designer-body .nav-link {
    padding: 0.5rem 0.625rem !important;
}

body.designer-body .desenx {
    position: relative;
    overflow: hidden;
    padding: 0 !important;
    border: 1px solid hsl(var(--border)) !important;
    background-size: cover !important;
    background-position: center !important;
    cursor: pointer;
}

body.designer-body .desenx p {
    position: absolute !important;
    left: 0 !important;
    right: 0 !important;
    bottom: 0 !important;
    width: 100% !important;
    height: auto !important;
    margin: 0 !important;
    border: 0 !important;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

body.designer-body {
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
    background: hsl(var(--background));
    color: hsl(var(--foreground));
    overflow: hidden;
    -webkit-font-smoothing: antialiased;
    -webkit-tap-highlight-color: transparent;
    height: 100dvh;
    height: 100vh;
}

#loading {
    position: fixed;
    inset: 0;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 1rem;
    background: hsl(var(--background) / 0.92);
    z-index: 9999;
    padding-top: var(--safe-top);
    padding-bottom: var(--safe-bottom);
}

#loading::before {
    content: 'Yükleniyor…';
    font-size: 0.875rem;
    font-weight: 500;
    color: hsl(var(--muted-foreground));
}

#loading::after {
    content: '';
    width: 1.75rem;
    height: 1.75rem;
    border: 2px solid hsl(var(--border));
    border-top-color: hsl(var(--foreground));
    border-radius: 9999px;
    animation: designer-spin 0.7s linear infinite;
}

#loading img {
    display: none;
}

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

.designer-app {
    height: 100dvh;
    height: 100vh;
    display: flex;
    flex-direction: column;
    padding-top: var(--safe-top);
    padding-left: var(--safe-left);
    padding-right: var(--safe-right);
}

.designer-header {
    height: var(--designer-header-h);
    min-height: var(--designer-header-h);
    border-bottom: 1px solid hsl(var(--border));
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 0 0.875rem;
    background: hsl(var(--background));
    flex-shrink: 0;
}

.designer-back {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.375rem;
    min-height: 2.75rem;
    min-width: 2.75rem;
    padding: 0 0.75rem;
    border-radius: calc(var(--radius) - 2px);
    border: 1px solid hsl(var(--border));
    background: hsl(var(--background));
    color: hsl(var(--foreground));
    font-size: 0.8125rem;
    font-weight: 500;
    text-decoration: none;
    transition: background 0.15s ease;
    flex-shrink: 0;
}

.designer-back-icon {
    display: none;
    font-size: 1.125rem;
    line-height: 1;
}

.designer-back:hover {
    background: hsl(var(--muted));
    color: hsl(var(--foreground));
    text-decoration: none;
}

.designer-logo {
    height: 1.5rem;
    width: auto;
    flex-shrink: 0;
}

.designer-title {
    font-size: 0.875rem;
    font-weight: 600;
    letter-spacing: -0.01em;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    min-width: 0;
    flex: 1;
}

.designer-panel-toggle {
    display: none;
    align-items: center;
    justify-content: center;
    min-height: 2.75rem;
    padding: 0 0.75rem;
    border-radius: calc(var(--radius) - 2px);
    border: 1px solid hsl(var(--border));
    background: hsl(var(--muted));
    color: hsl(var(--foreground));
    font-size: 0.75rem;
    font-weight: 600;
    cursor: pointer;
    flex-shrink: 0;
    white-space: nowrap;
}

.designer-panel-toggle[aria-expanded="false"] {
    background: hsl(var(--primary));
    color: hsl(var(--primary-foreground));
    border-color: hsl(var(--primary));
}

.designer-main {
    flex: 1;
    min-height: 0;
    overflow: hidden;
    display: grid;
    grid-template-columns: 1fr 20rem;
}

.designer-stage {
    position: relative;
    min-width: 0;
    min-height: 0;
    height: 100%;
    display: flex;
    flex-direction: column;
}

.designer-viewport {
    position: relative;
    flex: 1;
    min-width: 0;
    min-height: 0;
    height: 100%;
    align-self: stretch;
    background: hsl(var(--muted));
}

.designer-viewport #c {
    position: absolute !important;
    inset: 0 !important;
    width: 100% !important;
    height: 100% !important;
    top: 0 !important;
    left: 0 !important;
    display: block;
    touch-action: none;
}

.designer-viewport-hint {
    display: none;
}

.designer-regions-bar {
    position: absolute;
    left: 1rem;
    top: 50%;
    transform: translateY(-50%);
    z-index: 5;
    pointer-events: none;
}

.designer-regions-bar .designer-parts {
    pointer-events: auto;
    position: static;
    transform: none;
    left: auto;
    top: auto;
}

.designer-part-label {
    display: none;
}

.designer-parts {
    display: flex;
    flex-direction: column;
    gap: 0.375rem;
    max-width: calc(100% - 2rem);
}

.designer-parts .options {
    display: flex;
    flex-direction: column;
    gap: 0.375rem;
}

.designer-parts .option {
    width: 3rem;
    height: 3rem;
    margin: 0;
    padding: 0.375rem;
    border: 1px solid hsl(var(--border));
    border-radius: calc(var(--radius) - 2px);
    background: hsl(var(--background));
    box-shadow: 0 1px 2px rgb(0 0 0 / 0.04);
    cursor: pointer;
    transition: border-color 0.15s ease, transform 0.15s ease;
}

.designer-parts .option:hover {
    border-left: 1px solid hsl(var(--border));
    width: 3rem;
}

.designer-parts .option.--is-active {
    border: 2px solid hsl(var(--foreground));
    background: hsl(var(--background));
    width: 3rem;
}

.designer-parts .option img {
    height: 100%;
    width: 100%;
    object-fit: contain;
    pointer-events: none;
}

.designer-panel {
    border-left: 1px solid hsl(var(--border));
    background: hsl(var(--background));
    display: flex;
    flex-direction: column;
    min-height: 0;
}

.designer-panel .tab-pane {
    border: none !important;
    height: auto !important;
}

.designer-panel .designer-tabs.nav-pills {
    display: flex;
    flex-direction: column;
    align-items: stretch;
    gap: 0.125rem;
    padding: 1rem 1rem 0.75rem;
    flex-shrink: 0;
    list-style: none;
    margin: 0;
    overflow: visible;
    background: transparent;
    border-bottom: 1px solid hsl(var(--border));
}

.designer-panel .designer-tabs .nav-item {
    flex: none;
    width: 100%;
}

.designer-panel .designer-tabs .nav-link {
    display: block;
    width: 100%;
    min-height: 2.75rem;
    padding: 0.5rem 0.625rem !important;
    border: none;
    border-radius: calc(var(--radius) - 4px);
    font-size: 0.8125rem;
    font-weight: 500;
    letter-spacing: -0.01em;
    text-transform: none;
    text-align: left;
    line-height: 1.4;
    color: hsl(var(--muted-foreground));
    background: transparent;
    text-decoration: none;
    white-space: normal;
    word-break: normal;
    transition: color 0.15s ease, background 0.15s ease;
}

.designer-panel .designer-tabs .nav-link:hover {
    color: hsl(var(--foreground));
    background: hsl(var(--muted) / 0.6);
}

.designer-panel .designer-tabs .nav-link.active {
    color: hsl(var(--foreground));
    background: hsl(var(--muted));
    border: none;
    font-weight: 600;
}

.designer-subnav {
    display: flex;
    flex-direction: column;
    align-items: stretch;
    gap: 0.125rem;
    padding: 0.75rem 1rem;
    background: hsl(var(--background));
    flex-shrink: 0;
}

.designer-subnav-btn {
    min-height: 2.75rem;
    height: auto;
    padding: 0.4375rem 0.625rem;
    border: none;
    border-radius: calc(var(--radius) - 4px);
    background: transparent;
    color: hsl(var(--muted-foreground));
    font-size: 0.8125rem;
    font-weight: 500;
    text-align: left;
    cursor: pointer;
    transition: color 0.15s ease, background 0.15s ease;
}

.designer-subnav-btn:hover {
    background: hsl(var(--muted) / 0.6);
    color: hsl(var(--foreground));
}

.designer-subnav-btn.active {
    background: hsl(var(--muted));
    color: hsl(var(--foreground));
    font-weight: 600;
}

.designer-swatch-panel {
    flex: 1;
    min-height: 0;
    overflow-y: auto;
    overflow-x: hidden;
    padding: 0 1rem 1rem;
    padding-bottom: calc(1rem + var(--safe-bottom));
    -webkit-overflow-scrolling: touch;
}

.designer-swatch-grid {
    display: grid !important;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 0.5rem;
    margin: 0;
    width: 100%;
}

.designer-swatch-grid.row {
    display: grid !important;
}

.designer-swatch-hidden {
    display: none !important;
}

.designer-tab-content {
    flex: 1;
    min-height: 0;
    overflow: hidden;
    display: flex;
    flex-direction: column;
}

.designer-tab-content > .tab-pane {
    display: none !important;
    flex: 1;
    min-height: 0;
    height: auto;
    border: none;
    overflow-y: auto;
}

.designer-tab-content > .tab-pane.active.show {
    display: flex !important;
    flex-direction: column;
}

.designer-tab-content > .tab-pane[data-category-tab].active.show {
    overflow: hidden;
}

.designer-search {
    padding: 0.75rem 1rem;
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
}

.designer-field label {
    display: block;
    font-size: 0.75rem;
    font-weight: 500;
    margin-bottom: 0.375rem;
    color: hsl(var(--foreground));
}

.designer-input {
    width: 100%;
    height: 2.75rem;
    padding: 0 0.75rem;
    border: 1px solid hsl(var(--border));
    border-radius: calc(var(--radius) - 2px);
    background: hsl(var(--background));
    font-size: 1rem;
    color: hsl(var(--foreground));
}

.designer-input:focus {
    outline: 2px solid hsl(var(--ring));
    outline-offset: 1px;
}

.designer-btn {
    min-height: 2.75rem;
    padding: 0 0.875rem;
    border: 1px solid hsl(var(--primary));
    border-radius: calc(var(--radius) - 2px);
    background: hsl(var(--primary));
    color: hsl(var(--primary-foreground));
    font-size: 0.8125rem;
    font-weight: 500;
    cursor: pointer;
    transition: opacity 0.15s ease;
}

.designer-btn:hover {
    opacity: 0.9;
}

.designer-search-row {
    display: grid;
    grid-template-columns: 1fr auto;
    gap: 0.5rem;
    align-items: end;
}

.designer-color-grid {
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem;
    padding: 0.75rem;
    border: 1px solid hsl(var(--border));
    border-radius: calc(var(--radius) - 2px);
    background: hsl(var(--muted) / 0.35);
}

.designer-color-grid .colorSege {
    width: 2.75rem;
    height: 2.75rem;
    border-radius: 9999px;
    border: 2px solid hsl(var(--background));
    box-shadow: 0 0 0 1px hsl(var(--border));
    cursor: pointer;
    transition: transform 0.15s ease;
}

.designer-color-grid .colorSege:hover {
    transform: scale(1.08);
}

.designer-swatches .desenx,
.designer-swatches .desenx.col-lg-4,
.designer-swatch-grid .desenx,
.designer-swatch-grid .desenx.col-lg-4,
body.designer-body .designer-swatch-grid .desenx {
    height: 5.25rem;
    width: 100% !important;
    max-width: 100% !important;
    min-width: 0;
    flex: none !important;
    border: 1px solid hsl(var(--border));
    border-radius: calc(var(--radius) - 2px);
    background-size: cover;
    background-position: center;
    overflow: hidden;
    position: relative;
    cursor: pointer;
}

.designer-swatches .desenx p,
.designer-swatch-grid .desenx p {
    position: absolute;
    left: 0;
    right: 0;
    bottom: 0;
    margin: 0;
    padding: 0.375rem 0.5rem;
    font-size: 0.6875rem;
    font-weight: 500;
    background: hsl(var(--background) / 0.92);
    color: hsl(var(--foreground));
    border-top: 1px solid hsl(var(--border));
    height: auto;
    width: 100%;
    pointer-events: none;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.designer-swatches .row,
.designer-swatch-grid.row {
    display: grid !important;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 0.5rem;
    margin: 0;
}

#desengel {
    min-height: 12rem;
    max-height: calc(100vh - 18rem);
    overflow-y: auto;
}

@media (max-width: 1024px) {
    .designer-main {
        grid-template-columns: 1fr 17rem;
    }
}

@media (max-width: 900px) {
    .designer-main {
        display: flex;
        flex-direction: column;
        min-height: 0;
    }

    .designer-stage {
        flex: 0 0 54vh;
        min-height: 260px;
        max-height: none;
    }

    .designer-panel-toggle {
        display: inline-flex;
    }

    .designer-back-text {
        display: none;
    }

    .designer-back-icon {
        display: inline;
    }

    .designer-back {
        padding: 0;
    }

    .designer-viewport {
        flex: 1 1 auto;
        min-height: 210px;
        max-height: none;
    }

    .designer-regions-bar {
        position: static;
        transform: none;
        left: auto;
        top: auto;
        pointer-events: auto;
        display: block;
        flex-shrink: 0;
        border-top: 1px solid hsl(var(--border));
        background: hsl(var(--background));
        padding: 0.25rem 0.375rem;
    }

    .designer-stage .designer-parts,
    .designer-regions-bar .designer-parts {
        position: static;
        transform: none;
        left: auto;
        top: auto;
        max-width: none;
    }

    .designer-parts .options {
        flex-direction: row;
        justify-content: flex-start;
        gap: 0.375rem;
        overflow-x: auto;
        overflow-y: hidden;
        -webkit-overflow-scrolling: touch;
        scrollbar-width: none;
        padding-bottom: 0.125rem;
    }

    .designer-parts .options::-webkit-scrollbar {
        display: none;
    }

    .designer-parts .option,
    .designer-parts .option:hover,
    .designer-parts .option.--is-active {
        width: auto;
        min-width: 3rem;
        height: auto;
        min-height: 3rem;
        flex-shrink: 0;
        display: flex;
        flex-direction: column;
        align-items: center;
        justify-content: center;
        gap: 0.125rem;
        padding: 0.25rem 0.375rem;
    }

    .designer-parts .option img {
        width: 1.5rem;
        height: 1.5rem;
    }

    .designer-part-label {
        display: block;
        font-size: 0.5625rem;
        font-weight: 600;
        line-height: 1.1;
        color: hsl(var(--muted-foreground));
        text-align: center;
        max-width: 3.25rem;
        overflow: hidden;
        text-overflow: ellipsis;
        white-space: nowrap;
    }

    .designer-parts .option.--is-active {
        transform: none;
        border-color: hsl(var(--foreground));
        background: hsl(var(--muted));
    }

    .designer-parts .option.--is-active .designer-part-label {
        color: hsl(var(--foreground));
    }

    .designer-panel {
        flex: 0 1 auto;
        min-height: 0;
        max-height: 30vh;
        border-left: none;
        border-top: 1px solid hsl(var(--border));
        overflow: hidden;
    }

    .designer-panel .designer-tabs.nav-pills {
        flex-direction: row;
        flex-wrap: nowrap;
        overflow-x: auto;
        overflow-y: hidden;
        gap: 0.25rem;
        padding: 0.375rem 0.5rem;
        -webkit-overflow-scrolling: touch;
        scrollbar-width: none;
        overscroll-behavior-x: contain;
    }

    .designer-panel .designer-tabs.nav-pills::-webkit-scrollbar {
        display: none;
    }

    .designer-panel .designer-tabs .nav-item {
        width: auto;
        flex-shrink: 0;
    }

    .designer-panel .designer-tabs .nav-link {
        white-space: nowrap;
        text-align: center;
        padding: 0.3125rem 0.625rem !important;
        min-height: 1.875rem;
        font-size: 0.75rem;
        flex-shrink: 0;
    }

    .designer-subnav {
        flex-direction: row;
        flex-wrap: nowrap;
        overflow-x: auto;
        overflow-y: hidden;
        gap: 0.25rem;
        padding: 0.25rem 0.5rem;
        -webkit-overflow-scrolling: touch;
        scrollbar-width: none;
    }

    .designer-subnav::-webkit-scrollbar {
        display: none;
    }

    .designer-subnav-btn {
        flex-shrink: 0;
        white-space: nowrap;
        text-align: center;
        padding: 0.3125rem 0.5rem;
        min-height: 1.75rem;
        font-size: 0.6875rem;
        border: 1px solid hsl(var(--border));
        background: hsl(var(--background));
    }

    .designer-subnav-btn.active {
        border-color: hsl(var(--foreground));
    }

    .designer-swatch-panel {
        flex: 1;
        min-height: 0;
        padding: 0 0.375rem 0.375rem;
        padding-bottom: calc(0.375rem + var(--safe-bottom));
    }

    .designer-swatch-grid,
    .designer-swatch-grid.row {
        grid-template-columns: repeat(3, minmax(0, 1fr));
        gap: 0.375rem;
    }

    .designer-swatches .desenx,
    .designer-swatches .desenx.col-lg-4,
    .designer-swatch-grid .desenx,
    .designer-swatch-grid .desenx.col-lg-4 {
        height: 3.5rem;
    }

    .designer-swatch-grid .desenx p {
        font-size: 0.5625rem;
        padding: 0.2rem 0.35rem;
    }

    .designer-main.designer-main--panel-collapsed .designer-panel {
        flex: 0 0 0;
        max-height: 0;
        overflow: hidden;
        border-top: none;
        pointer-events: none;
        opacity: 0;
    }

    .designer-main.designer-main--panel-collapsed .designer-stage {
        min-height: calc(100dvh - var(--designer-header-h) - var(--safe-top) - var(--safe-bottom));
    }
}

@media (max-width: 480px) {
    :root {
        --designer-header-h: 3rem;
    }

    .designer-header {
        gap: 0.375rem;
        padding: 0 0.5rem;
    }

    .designer-logo {
        height: 1.125rem;
    }

    .designer-title {
        font-size: 0.75rem;
    }

    .designer-panel-toggle {
        font-size: 0.625rem;
        padding: 0 0.45rem;
        min-height: 2.5rem;
    }

    .designer-stage {
        flex: 0 0 57vh;
        min-height: 280px;
    }

    .designer-viewport {
        min-height: 230px;
    }

    .designer-panel {
        max-height: 28vh;
    }

    .designer-swatches .desenx,
    .designer-swatch-grid .desenx {
        height: 3.25rem;
    }
}
