@font-face {
    font-family: 'Patrick Hand';
    font-style: normal;
    font-weight: 400;
    font-display: swap;
    src: url('/fonts/PatrickHand-Regular.ttf') format('truetype');
}

@font-face {
    font-family: 'Open Sans';
    font-style: normal;
    font-weight: 400;
    font-display: swap;
    src: url('/fonts/OpenSans-Regular.ttf') format('truetype');
}

.studio-hub-page {
    max-width: 1100px;
    margin: 0 auto;
    padding: 1rem;
}

.studio-create-client-list {
    max-height: min(50vh, 320px);
    overflow-y: auto;
}

.studio-tab-bar {
    display: flex;
    flex-wrap: wrap;
    gap: 0;
    border-bottom: 1px solid var(--bs-border-color);
    margin-bottom: 1rem;
}

.studio-tab {
    appearance: none;
    background: transparent;
    border: 1px solid transparent;
    border-bottom: none;
    border-top-left-radius: var(--bs-border-radius);
    border-top-right-radius: var(--bs-border-radius);
    margin: 0 0 -1px;
    padding: 0.5rem 1rem;
    line-height: 1.25;
    font-size: 1rem;
    font-weight: 400;
    color: var(--bs-link-color);
    cursor: pointer;
}

.studio-tab:hover {
    border-color: var(--bs-border-color) var(--bs-border-color) transparent;
    color: var(--bs-link-hover-color, var(--bs-link-color));
}

.studio-tab.active {
    color: var(--bs-body-color);
    background-color: var(--bs-body-bg);
    border-color: var(--bs-border-color) var(--bs-border-color) transparent;
}

.studio-doc-list .list-group-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 0.75rem;
}

.studio-doc-actions {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 0.35rem;
    flex-shrink: 0;
}

.studio-snippets-admin .studio-snippet-list {
    max-height: min(70vh, 640px);
    overflow-y: auto;
}

.studio-snippets-admin .studio-snippet-category-header {
    background: var(--bs-tertiary-bg, rgba(0, 0, 0, 0.03));
    border-top-width: 0;
    pointer-events: none;
}

.studio-snippets-admin .studio-snippet-list-item {
    text-align: left;
}

.studio-snippets-admin .studio-snippet-list-item.active {
    border-left: 3px solid var(--ads-color-primary, #198754);
}

.studio-design-page {
    --studio-accent: var(--ads-color-primary, #198754);
    --studio-accent-soft: rgba(25, 135, 84, 0.14);
    --studio-bar-bg: #1e2228;
    --studio-bar-border: #3a424d;
    --studio-bar-text: #f1f3f5;
    --studio-bar-muted: #adb5bd;
    --studio-rail-bg: #181b20;
    --studio-rail-border: #3a424d;
    --studio-panel-bg: #1a1d21;
    --studio-panel-surface: #232830;
    --studio-panel-border: #3a424d;
    --studio-panel-text: #e9ecef;
    --studio-panel-muted: #adb5bd;
    --studio-canvas-bg: #525a65;
    --studio-thumb-bg: #2b3038;
    --studio-stage-bg: #121416;
    display: flex;
    flex-direction: column;
    height: calc(100vh - 3.5rem);
    margin: -0.5rem -0.75rem 0;
    background: var(--studio-stage-bg);
    overflow: hidden;
}

.page[data-theme="light"] .studio-design-page {
    --studio-bar-bg: #ffffff;
    --studio-bar-border: var(--ads-border-light, #ced4da);
    --studio-bar-text: var(--ads-text-light, #212529);
    --studio-bar-muted: #6c757d;
    --studio-rail-bg: #f8f9fa;
    --studio-rail-border: var(--ads-border-light, #ced4da);
    --studio-panel-bg: #ffffff;
    --studio-panel-surface: #f8f9fa;
    --studio-panel-border: var(--ads-border-light, #ced4da);
    --studio-panel-text: var(--ads-text-light, #212529);
    --studio-panel-muted: #6c757d;
    --studio-canvas-bg: #b0b8c1;
    --studio-thumb-bg: #ffffff;
    --studio-stage-bg: #e9ecef;
    --studio-accent-soft: rgba(25, 135, 84, 0.1);
}

.studio-editor-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.75rem;
    flex-wrap: wrap;
    padding: 0.55rem 0.85rem;
    background: var(--studio-bar-bg);
    border-bottom: 1px solid var(--studio-bar-border);
    color: var(--studio-bar-text);
}

.studio-editor-header-start {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    min-width: 0;
    flex: 1;
}

.studio-editor-header-end {
    display: flex;
    align-items: center;
    gap: 0.45rem;
    flex-shrink: 0;
}

.studio-editor-back {
    appearance: none;
    display: inline-flex;
    align-items: center;
    gap: 0.35rem;
    border: 1px solid var(--studio-bar-border);
    border-radius: 6px;
    background: transparent;
    color: var(--studio-bar-muted);
    font-size: 0.82rem;
    padding: 0.35rem 0.55rem;
    cursor: pointer;
    white-space: nowrap;
}

.studio-editor-back:hover {
    color: var(--studio-bar-text);
    border-color: var(--studio-accent);
}

.studio-editor-title-wrap {
    display: flex;
    flex-direction: column;
    gap: 0.15rem;
    min-width: 0;
    flex: 1;
}

.studio-editor-title {
    border: none;
    background: transparent;
    color: var(--studio-bar-text);
    font-size: 1rem;
    font-weight: 600;
    line-height: 1.2;
    padding: 0;
    min-width: 0;
    width: min(420px, 100%);
}

.studio-editor-title:focus {
    outline: none;
    box-shadow: 0 1px 0 0 var(--studio-accent);
}

.studio-editor-kind {
    font-size: 0.68rem;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    color: var(--studio-bar-muted);
}

.studio-editor-btn {
    appearance: none;
    display: inline-flex;
    align-items: center;
    gap: 0.35rem;
    border-radius: 6px;
    font-size: 0.82rem;
    font-weight: 500;
    padding: 0.4rem 0.75rem;
    cursor: pointer;
    border: 1px solid transparent;
    white-space: nowrap;
}

.studio-editor-btn:disabled {
    opacity: 0.55;
    cursor: not-allowed;
}

.studio-editor-btn-ghost {
    background: transparent;
    border-color: var(--studio-bar-border);
    color: var(--studio-bar-text);
    text-decoration: none;
}

.studio-editor-btn-ghost:hover {
    border-color: var(--studio-accent);
    color: var(--studio-accent);
}

.studio-editor-btn-secondary {
    background: transparent;
    border-color: var(--studio-bar-border);
    color: var(--studio-bar-text);
}

.studio-editor-btn-secondary:hover:not(:disabled) {
    border-color: var(--studio-accent);
}

.studio-editor-btn-primary {
    background: var(--studio-accent);
    border-color: var(--studio-accent);
    color: #fff;
}

.studio-editor-btn-primary:hover:not(:disabled) {
    filter: brightness(1.06);
}

.studio-editor-banner {
    padding: 0.4rem 0.85rem;
    font-size: 0.8rem;
    border-bottom: 1px solid transparent;
}

.studio-editor-banner-info {
    background: rgba(13, 202, 240, 0.12);
    border-bottom-color: rgba(13, 202, 240, 0.25);
    color: var(--studio-bar-text);
}

.studio-editor-banner-error {
    background: rgba(244, 67, 54, 0.12);
    border-bottom-color: rgba(244, 67, 54, 0.25);
    color: var(--studio-bar-text);
}

.studio-editor-body {
    display: flex;
    flex: 1;
    min-height: 0;
    overflow: hidden;
}

.studio-editor-rail {
    width: 5.75rem;
    flex-shrink: 0;
    display: flex;
    flex-direction: column;
    gap: 0.65rem;
    padding: 0.65rem 0.45rem;
    background: var(--studio-rail-bg);
    border-right: 1px solid var(--studio-rail-border);
    overflow-y: auto;
}

.studio-rail-section {
    display: flex;
    flex-direction: column;
    gap: 0.35rem;
}

.studio-rail-label {
    font-size: 0.62rem;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--studio-bar-muted);
    padding: 0 0.15rem;
}

.studio-rail-tools {
    display: flex;
    flex-direction: column;
    gap: 0.3rem;
}

.studio-rail-btn {
    appearance: none;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 0.2rem;
    width: 100%;
    min-height: 3.25rem;
    border: 1px solid var(--studio-rail-border);
    border-radius: 8px;
    background: var(--studio-bar-bg);
    color: var(--studio-bar-text);
    font-size: 0.62rem;
    line-height: 1.1;
    cursor: pointer;
    padding: 0.35rem 0.2rem;
}

.studio-rail-btn i {
    font-size: 1rem;
}

.studio-rail-btn:hover:not(:disabled) {
    border-color: var(--studio-accent);
    background: var(--studio-accent-soft);
}

.studio-rail-btn.active {
    border-color: var(--studio-accent);
    background: var(--studio-accent-soft);
    color: var(--studio-accent);
}

.studio-rail-btn-danger:hover:not(:disabled) {
    border-color: var(--ads-color-danger, #f44336);
    background: rgba(244, 67, 54, 0.12);
    color: var(--ads-color-danger, #f44336);
}

.studio-rail-btn-upload {
    position: relative;
    margin: 0;
}

.studio-rail-file-input {
    position: absolute;
    inset: 0;
    opacity: 0;
    cursor: pointer;
    width: 100%;
    height: 100%;
}

.studio-rail-publish {
    border-top: 1px solid var(--studio-rail-border);
    padding-top: 0.65rem;
}

.studio-rail-check {
    display: flex;
    align-items: flex-start;
    gap: 0.35rem;
    font-size: 0.65rem;
    line-height: 1.25;
    color: var(--studio-bar-muted);
    cursor: pointer;
    padding: 0 0.1rem;
}

.studio-rail-check input {
    margin-top: 0.1rem;
    flex-shrink: 0;
}

.studio-rail-color {
    width: 100%;
    height: 2rem;
    padding: 0.12rem;
    border: 1px solid var(--studio-rail-border);
    border-radius: 6px;
    background: var(--studio-bar-bg);
    cursor: pointer;
}

.studio-rail-color:disabled {
    opacity: 0.45;
    cursor: not-allowed;
}

.studio-font-select {
    width: 100%;
    font-size: 0.8rem;
    border-radius: 6px;
    border: 1px solid var(--studio-rail-border);
    background: var(--studio-bar-bg);
    color: inherit;
}

.studio-color-swatches {
    display: grid;
    grid-template-columns: repeat(5, 1fr);
    gap: 0.25rem;
    margin-top: 0.35rem;
}

.studio-color-swatch {
    appearance: none;
    width: 100%;
    aspect-ratio: 1;
    border: 2px solid transparent;
    border-radius: 4px;
    cursor: pointer;
    padding: 0;
}

.studio-color-swatch:hover:not(:disabled) {
    border-color: var(--studio-accent);
}

.studio-color-swatch.active {
    border-color: var(--studio-accent);
    box-shadow: 0 0 0 1px var(--studio-accent);
}

.studio-color-swatch:disabled {
    opacity: 0.45;
    cursor: not-allowed;
}

.studio-rail-hint {
    font-size: 0.58rem;
    color: var(--studio-bar-muted);
    line-height: 1.25;
    margin: 0.3rem 0 0;
}

.studio-canvas-stage {
    flex: 1;
    min-width: 0;
    display: flex;
    flex-direction: column;
    min-height: 0;
    background: var(--studio-stage-bg);
}

.studio-design-body {
    display: flex;
    flex: 1;
    min-height: 0;
    gap: 0;
    overflow: hidden;
}

.studio-graphics-panel {
    width: min(380px, 36vw);
    flex-shrink: 0;
    display: flex;
    flex-direction: column;
    border-right: 1px solid var(--studio-panel-border);
    background: var(--studio-panel-bg);
    color: var(--studio-panel-text);
    overflow: hidden;
}

.studio-graphics-panel-header {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    gap: 0.5rem;
    padding: 0.75rem 0.85rem;
    border-bottom: 1px solid var(--studio-panel-border);
    background: var(--studio-panel-surface);
}

.studio-graphics-title {
    font-size: 0.95rem;
    font-weight: 600;
    line-height: 1.2;
}

.studio-graphics-subtitle {
    font-size: 0.72rem;
    color: var(--studio-panel-muted);
    margin-top: 0.15rem;
}

.studio-graphics-close {
    appearance: none;
    border: 1px solid var(--studio-panel-border);
    background: transparent;
    color: var(--studio-panel-muted);
    width: 1.75rem;
    height: 1.75rem;
    border-radius: 6px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    flex-shrink: 0;
}

.studio-graphics-close:hover {
    color: var(--studio-panel-text);
    border-color: var(--studio-accent);
}

.studio-graphics-loading {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: 1rem 0.85rem;
    font-size: 0.82rem;
    color: var(--studio-panel-muted);
}

.studio-graphics-search-wrap {
    position: relative;
    padding: 0.65rem 0.75rem 0.5rem;
    border-bottom: 1px solid var(--studio-panel-border);
}

.studio-graphics-search-icon {
    position: absolute;
    left: 1.25rem;
    top: 50%;
    transform: translateY(-35%);
    font-size: 0.8rem;
    color: var(--studio-panel-muted);
    pointer-events: none;
}

.studio-graphics-search {
    width: 100%;
    border: 1px solid var(--studio-panel-border);
    border-radius: 6px;
    background: var(--studio-panel-surface);
    color: var(--studio-panel-text);
    font-size: 0.82rem;
    padding: 0.4rem 0.55rem 0.4rem 1.85rem;
}

.studio-graphics-search:focus {
    outline: none;
    border-color: var(--studio-accent);
    box-shadow: 0 0 0 2px var(--studio-accent-soft);
}

.studio-graphics-body {
    display: flex;
    flex: 1;
    min-height: 0;
}

.studio-graphics-nav {
    width: 7.5rem;
    flex-shrink: 0;
    display: flex;
    flex-direction: column;
    gap: 0.2rem;
    padding: 0.5rem;
    border-right: 1px solid var(--studio-panel-border);
    overflow-y: auto;
}

.studio-graphics-nav-item {
    appearance: none;
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    gap: 0.15rem;
    width: 100%;
    border: 1px solid transparent;
    border-radius: 6px;
    background: transparent;
    color: var(--studio-panel-muted);
    font-size: 0.72rem;
    line-height: 1.2;
    padding: 0.45rem 0.5rem;
    cursor: pointer;
    text-align: left;
}

.studio-graphics-nav-item:hover {
    background: var(--studio-accent-soft);
    color: var(--studio-panel-text);
}

.studio-graphics-nav-item.active {
    background: var(--studio-accent-soft);
    border-color: rgba(25, 135, 84, 0.35);
    color: var(--studio-panel-text);
    font-weight: 600;
}

.studio-graphics-count {
    font-size: 0.65rem;
    opacity: 0.75;
}

.studio-graphics-content {
    flex: 1;
    min-width: 0;
    display: flex;
    flex-direction: column;
    min-height: 0;
}

.studio-graphics-content-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0.5rem 0.65rem 0.35rem;
    font-size: 0.75rem;
    font-weight: 600;
    border-bottom: 1px solid var(--studio-panel-border);
}

.studio-graphics-muted {
    font-weight: 400;
    color: var(--studio-panel-muted);
    font-size: 0.68rem;
}

.studio-graphics-empty {
    padding: 1rem 0.75rem;
    margin: 0;
    font-size: 0.8rem;
    color: var(--studio-panel-muted);
}

.studio-graphics-grid {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    grid-auto-rows: 8rem;
    gap: 0.45rem;
    padding: 0.55rem;
    overflow-y: auto;
    flex: 1;
}

.studio-graphic-item {
    appearance: none;
    display: flex;
    flex-direction: column;
    align-items: stretch;
    gap: 0.35rem;
    height: 100%;
    min-height: 0;
    padding: 0.4rem;
    border: 1px solid var(--studio-panel-border);
    border-radius: 8px;
    background: var(--studio-panel-surface);
    color: var(--studio-panel-text);
    cursor: pointer;
    text-align: center;
    transition: border-color 0.15s ease, box-shadow 0.15s ease;
}

.studio-graphic-item:hover:not(:disabled) {
    border-color: var(--studio-accent);
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.12);
}

.studio-graphic-item:disabled {
    opacity: 0.55;
    cursor: not-allowed;
}

.studio-graphic-thumb {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 100%;
    flex: 1 1 0;
    min-height: 0;
    border-radius: 6px;
    background: var(--studio-thumb-bg);
    padding: 0.35rem;
    overflow: hidden;
}

.studio-graphic-thumb img {
    display: block;
    width: 100%;
    height: 100%;
    object-fit: contain;
    object-position: center;
    pointer-events: none;
}

.studio-graphic-label {
    font-size: 0.68rem;
    line-height: 1.25;
    color: var(--studio-panel-muted);
    flex-shrink: 0;
    height: 2.5em;
    overflow: hidden;
    display: -webkit-box;
    -webkit-box-orient: vertical;
    -webkit-line-clamp: 2;
}

.studio-text-block-preview {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 0.25rem;
    width: 100%;
    flex: 1 1 0;
    min-height: 0;
    border-radius: 6px;
    background: var(--studio-thumb-bg);
    padding: 0.35rem;
    overflow: hidden;
}

.studio-text-block-preview .bi {
    font-size: 1.15rem;
    color: var(--studio-panel-muted);
    flex-shrink: 0;
}

.studio-text-block-excerpt {
    font-size: 0.58rem;
    line-height: 1.25;
    color: var(--studio-panel-muted);
    text-align: center;
    overflow: hidden;
    display: -webkit-box;
    -webkit-box-orient: vertical;
    -webkit-line-clamp: 3;
    width: 100%;
}

.studio-page-count-input {
    max-width: 5.5rem;
    margin-top: 0.25rem;
}

.studio-canvas-wrap {
    flex: 1;
    min-width: 0;
    overflow: auto;
    background: var(--studio-canvas-bg);
    display: flex;
    justify-content: center;
    align-items: flex-start;
    padding: 1.5rem;
}

/* Fabric.js sets explicit canvas dimensions — global `canvas { max-width:100%; height:auto }` breaks the page preview. */
.studio-canvas-wrap .canvas-container {
    max-width: 100%;
    box-shadow: none;
}

.studio-canvas-wrap .canvas-container canvas {
    max-width: none !important;
    height: unset !important;
}

.studio-canvas-wrap canvas {
    box-shadow: none;
    border-radius: 0;
}

.page[data-theme="light"] .studio-canvas-wrap .canvas-container,
.page[data-theme="light"] .studio-canvas-wrap canvas {
    box-shadow: none;
}

/* Mobile / in-app WebView (embed=1) */
.page.studio-embed {
    display: block;
}

.page.studio-embed .sidebar {
    display: none !important;
}

.page.studio-embed .main,
.page.studio-embed .studio-embed-main {
    margin-left: 0 !important;
    width: 100% !important;
    max-width: none !important;
}

.page.studio-embed .studio-embed-content {
    padding: 0 !important;
    max-width: none !important;
}

.page.studio-embed .studio-design-page {
    height: 100dvh;
    height: 100vh;
    margin: 0;
    padding-bottom: env(safe-area-inset-bottom, 0);
}

.page.studio-embed .studio-hub-page {
    padding: 0.75rem;
    padding-bottom: calc(0.75rem + env(safe-area-inset-bottom, 0));
}

@media (max-width: 900px) {
    .studio-design-page {
        height: calc(100vh - 3.5rem);
        margin: -0.5rem -0.75rem 0;
    }

    .page.studio-embed .studio-design-page {
        height: 100dvh;
        margin: 0;
    }

    .studio-editor-header {
        padding: 0.45rem 0.55rem;
        gap: 0.45rem;
    }

    .studio-editor-back span {
        display: none;
    }

    .studio-editor-title {
        font-size: 0.9rem;
        width: 100%;
    }

    .studio-editor-header-end {
        width: 100%;
        justify-content: flex-end;
    }

    .studio-editor-btn {
        padding: 0.35rem 0.55rem;
        font-size: 0.75rem;
    }

    .studio-editor-btn i {
        margin: 0;
    }

    .studio-editor-body {
        flex-direction: column;
        min-height: 0;
    }

    .studio-canvas-stage {
        order: 1;
        flex: 1;
        min-height: 0;
    }

    .studio-canvas-wrap {
        padding: 0.65rem;
    }

    .studio-editor-rail {
        order: 2;
        width: 100%;
        flex-direction: row;
        flex-wrap: nowrap;
        overflow-x: auto;
        overflow-y: hidden;
        gap: 0.5rem;
        padding: 0.45rem 0.5rem;
        padding-bottom: calc(0.45rem + env(safe-area-inset-bottom, 0));
        border-right: none;
        border-top: 1px solid var(--studio-rail-border);
        -webkit-overflow-scrolling: touch;
    }

    .studio-rail-section {
        flex-direction: row;
        align-items: center;
        gap: 0.35rem;
        flex-shrink: 0;
        padding-right: 0.5rem;
        border-right: 1px solid var(--studio-rail-border);
    }

    .studio-rail-section:last-child {
        border-right: none;
    }

    .studio-rail-label {
        display: none;
    }

    .studio-rail-tools {
        flex-direction: row;
        gap: 0.3rem;
    }

    .studio-rail-btn {
        min-height: 2.85rem;
        width: 3.1rem;
        font-size: 0.58rem;
        padding: 0.25rem 0.15rem;
    }

    .studio-rail-btn i {
        font-size: 0.95rem;
    }

    .studio-rail-color {
        width: 2.85rem;
        height: 2.85rem;
        flex-shrink: 0;
    }

    .studio-color-swatches {
        grid-template-columns: repeat(5, 1.35rem);
        margin-top: 0;
    }

    .studio-rail-hint {
        display: none;
    }

    .studio-rail-publish {
        border-top: none;
        padding-top: 0;
        flex-direction: row;
        gap: 0.5rem;
    }

    .studio-rail-check {
        white-space: nowrap;
        font-size: 0.62rem;
    }

    .studio-graphics-panel {
        position: fixed;
        inset: 0;
        z-index: 2000;
        width: 100%;
        max-width: none;
        padding-bottom: env(safe-area-inset-bottom, 0);
    }

    .studio-graphics-nav {
        width: 6.5rem;
    }

    .studio-graphics-grid {
        grid-template-columns: repeat(2, minmax(0, 1fr));
    }

    .studio-hub-page {
        padding: 0.65rem;
    }

    .studio-doc-list .list-group-item {
        flex-direction: column;
        align-items: stretch;
        gap: 0.5rem;
    }

    .studio-doc-actions {
        width: 100%;
        justify-content: flex-end;
    }

    .studio-tab {
        font-size: 0.88rem;
        padding: 0.45rem 0.75rem;
    }
}

@media (max-width: 480px) {
    .studio-editor-header-start {
        flex-wrap: wrap;
    }

    .studio-editor-btn span {
        display: none;
    }

    .studio-editor-btn {
        min-width: 2.25rem;
        justify-content: center;
    }

    .studio-graphics-grid {
        grid-template-columns: repeat(2, minmax(0, 1fr));
        grid-auto-rows: 7.25rem;
    }
}
