.app {
    display: flex;
    flex-direction: column;
    height: 100%;
    width: 100%;
}

/* Mobile keyboard: the app is shrunk to the visible viewport instead of being
   covered by it, so the work area (and the text being edited) stays on screen.
   --kb-inset is written by the shell (main.js) from visualViewport while the
   on-canvas text editor or a control inside the sheet has focus. The height
   snaps: the keyboard is an OS event, animating it would only delay the
   focused control becoming visible. */
.app.kb-open {
    height: calc(100% - var(--kb-inset));
}

.app-header {
    flex: 0 0 auto;
    height: var(--header-height);
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 var(--space-4);
    background: var(--color-surface);
    border-bottom: 1px solid var(--color-border);
    box-shadow: var(--shadow-sm);
    position: relative;
    z-index: 40;
    padding-top: var(--safe-top);
}

.app-body {
    flex: 1 1 auto;
    display: flex;
    min-height: 0;
    position: relative;
    overflow: hidden;
    transition: padding-bottom var(--transition-med);
}

/* The open bottom sheet takes its space out of the work area, so the canvas
   shrinks and stays fully visible (with its object) above the sheet. */
.app.sheet-open .app-body {
    padding-bottom: var(--sheet-h);
}

/* Tools (desktop) */
.tools-panel {
    display: none;
    flex: 0 0 var(--tools-width);
    background: var(--color-surface);
    border-inline-end: 1px solid var(--color-border);
    padding: var(--space-3) var(--space-2);
    flex-direction: column;
    gap: var(--space-1);
    overflow-y: auto;
    z-index: 10;
}

.tool-btn {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 4px;
    padding: var(--space-3) var(--space-2);
    border-radius: var(--radius-md);
    color: var(--color-text-muted);
    transition: background var(--transition-fast), color var(--transition-fast);
    font-size: var(--font-size-xs);
    font-weight: 600;
}

.tool-btn svg {
    width: 22px;
    height: 22px;
}

.tool-btn:hover {
    background: var(--color-surface-muted);
    color: var(--color-text);
}

.tool-btn.active {
    background: var(--color-primary-soft);
    color: var(--color-primary);
}

/* Canvas area */
.canvas-wrap {
    flex: 1 1 auto;
    display: flex;
    flex-direction: column;
    min-width: 0;
    min-height: 0;
    position: relative;
    background:
        radial-gradient(circle at 20% 20%, rgba(37, 99, 235, 0.06), transparent 40%),
        radial-gradient(circle at 80% 80%, rgba(37, 99, 235, 0.05), transparent 40%),
        var(--color-bg);
    overflow: hidden;
    touch-action: none;
}

.canvas-stage {
    flex: 1 1 auto;
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 0;
    overflow: hidden;
    position: relative;
    touch-action: none;
}

/* While typing in the on-canvas text editor the whole app is shrunk to the
   visible viewport (.app.kb-open) so the canvas – and therefore the editor –
   stays above the mobile keyboard. */

.empty-state {
    position: absolute;
    inset: 0;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: var(--space-2);
    text-align: center;
    padding: var(--space-4);
    z-index: 5;
}

.empty-state.hidden {
    display: none;
}

.empty-icon {
    width: 64px;
    height: 64px;
    color: var(--color-text-faint);
    margin-bottom: var(--space-1);
}

.empty-icon svg {
    width: 100%;
    height: 100%;
}

.empty-state h2 {
    font-size: 22px;
    font-weight: 700;
    color: var(--color-text);
}

.empty-state p {
    color: var(--color-text-muted);
    max-width: 260px;
}

.empty-templates {
    width: 100%;
    max-width: 340px;
}

.empty-templates[hidden] {
    display: none;
}

.empty-templates-row {
    display: flex;
    gap: var(--space-2);
    overflow-x: auto;
    justify-content: center;
    padding: var(--space-1);
}

.empty-template {
    flex: 0 0 auto;
    width: 100px;
    display: flex;
    flex-direction: column;
    gap: var(--space-1);
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    border-radius: 12px;
    padding: var(--space-1);
    cursor: pointer;
}

.empty-template img {
    width: 100%;
    aspect-ratio: 3 / 4;
    object-fit: cover;
    border-radius: 8px;
    background: var(--color-bg);
}

.empty-template span {
    font-size: var(--font-size-xs);
    color: var(--color-text);
    text-align: center;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
    min-height: 2.4em;
    line-height: 1.2;
}

#btnEmptyTemplate {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: var(--space-2);
}

#btnEmptyTemplate svg {
    flex: 0 0 auto;
}

.empty-actions {
    display: flex;
    gap: var(--space-2);
    margin-top: var(--space-1);
}

/* Wael's fix: keep the primary button inside the card (btn-primary is
   width:100% for side panels; the overlay empty-state is wider). */
.empty-state .btn-primary {
    max-width: 340px;
}

/* Short landscape viewports (tablet rotate / small laptop screens): shrink
   the empty state so the actions stay inside the work area. */
@media (max-height: 600px) {
    .empty-state {
        gap: var(--space-2);
        padding: var(--space-4);
        justify-content: flex-start;
        padding-top: var(--space-5);
        overflow-y: auto;
    }

    .empty-state h2 {
        font-size: 18px;
    }

    .empty-state p {
        font-size: var(--font-size-sm);
    }

    .empty-template {
        width: 64px;
    }
}

/* Wide desktop viewports: let the suggestions breathe a little. */
@media (min-width: 1100px) {
    .empty-templates {
        max-width: 420px;
    }
}

/* Right properties (desktop) */
.props-panel {
    display: none;
    flex: 0 0 var(--props-width);
    background: var(--color-surface);
    border-inline-start: 1px solid var(--color-border);
    overflow-y: auto;
    z-index: 10;
}

.props-empty {
    padding: var(--space-8) var(--space-5);
    color: var(--color-text-muted);
    font-size: var(--font-size-sm);
    text-align: center;
}

/* Bottom toolbar (mobile) */
.bottom-toolbar {
    display: flex;
    flex: 0 0 auto;
    height: calc(var(--bottom-bar-height) + var(--safe-bottom));
    background: var(--color-surface);
    border-top: 1px solid var(--color-border);
    box-shadow: var(--shadow-md);
    z-index: 30;
    padding-bottom: var(--safe-bottom);
    /* Six tools have to share the width, so the label must be allowed to
       shrink and truncate rather than force a horizontal scroll. */
    min-width: 0;
}

/* Ad banner */
.ad-banner {
    flex: 0 0 auto;
    height: var(--ad-height);
    min-height: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--color-surface-muted);
    border-top: 1px dashed var(--color-border);
    color: var(--color-text-faint);
    font-size: var(--font-size-xs);
    letter-spacing: 1px;
    text-transform: uppercase;
    user-select: none;
        z-index: 5;
}

/* Template creator attribution: a quiet line under the work area.
   "تصميم القالب: صمم بنفسك" — the name links to the creator profile
   (the site today, the template owner's profile tomorrow). */
.template-attribution {
    flex: 0 0 auto;
    text-align: center;
    padding: var(--space-1) var(--space-3);
    font-size: var(--font-size-xs);
    color: var(--color-text-muted);
}

.template-attribution[hidden] {
    display: none;
}

.template-attribution a {
    color: var(--color-primary);
    font-weight: 700;
    text-decoration: none;
}

.template-attribution a:hover {
    text-decoration: underline;
}