/* Structural layout: global header, container, sidebar, canvas area.
   Typography and surfaces align with the bcstiles.com design system. */

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

html, body {
    /* Prevent accidental horizontal scroll on mobile when content would otherwise overflow the viewport */
    overflow-x: hidden;
    max-width: 100vw;
}

body {
    font-family: 'Inter', 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
    background: var(--bg-app);
    color: var(--text-primary);
    overflow: hidden;
    letter-spacing: -0.005em;
}

/* ── Global header ───────────────────────────────────────────────────────────
   Spans full viewport width. Always white — intentionally immune to dark mode
   so the bcstiles wordmark renders correctly on its natural background. */

.app-header {
    height: 58px;
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 0 20px;
    flex-shrink: 0;

    /* Hard-coded light values — not CSS variables, so dark mode cannot override */
    background: #ffffff;
    border-bottom: 1px solid #dde2ea;
    box-shadow: 0 1px 3px rgba(20, 30, 50, 0.06);
    z-index: 20;
}

/* Dark-mode explicit reset so the header stays light even when the rest of the
   UI switches to dark palette. */
[data-theme="dark"] .app-header {
    background: #ffffff;
    border-bottom-color: #dde2ea;
    box-shadow: 0 1px 3px rgba(20, 30, 50, 0.06);
}


/* Logo container: exactly 320px wide — aligns its right border with the
   control panel's right border, creating one continuous vertical divider. */
.header-brand {
    width: 320px;
    flex-shrink: 0;
    height: 100%;
    display: flex;
    align-items: center;
    padding: 0 20px;
    margin-right: 12px;
}

.brand-link {
    display: flex;
    align-items: center;
    opacity: 0.88;
    transition: opacity 0.18s ease;
    text-decoration: none;
}

.brand-link:hover,
.brand-link:focus-visible {
    opacity: 1;
    outline: none;
}

.brand-logo {
    height: 26px;
    display: block;
}

/* Toolbar buttons inside the always-light header — hard-coded light colors */
.app-header .toolbar-btn {
    padding: 7px 13px;
    border: 1px solid #dde2ea;
    background: #ffffff;
    color: #2d333b;
    border-radius: 8px;
    cursor: pointer;
    font-size: 13px;
    font-weight: 500;
    font-family: inherit;
    transition: all 0.15s ease;
    white-space: nowrap;
}

.app-header .toolbar-btn:hover:not(:disabled) {
    border-color: #2196F3;
    color: #1565C0;
    background: #e8f4fd;
}

.app-header .toolbar-btn:disabled {
    opacity: 0.4;
    cursor: not-allowed;
}

[data-theme="dark"] .app-header .toolbar-btn {
    background: #ffffff;
    color: #2d333b;
    border-color: #dde2ea;
}

[data-theme="dark"] .app-header .toolbar-btn:hover:not(:disabled) {
    border-color: #2196F3;
    color: #1565C0;
    background: #e8f4fd;
}

/* Autosave indicator in the header */
.app-header .autosave-indicator {
    font-size: 12px;
    color: #9ca3af;
    white-space: nowrap;
}

/* Dropdowns inside the always-light header use hard-coded light values */
.app-header .menu-dropdown {
    background: #ffffff;
    border: 1px solid #dde2ea;
    box-shadow: 0 10px 28px rgba(20, 30, 50, 0.14);
}

.app-header .menu-item {
    color: #2d333b;
}

.app-header .menu-item:hover {
    background: #e8f4fd;
    color: #1565C0;
}

.app-header .menu-item.menu-danger { color: #ef4444; }
.app-header .menu-item.menu-danger:hover {
    background: rgba(239, 68, 68, 0.08);
    color: #dc2626;
}

.app-header .menu-divider { background: #e5e9ef; }

[data-theme="dark"] .app-header .menu-dropdown {
    background: #ffffff;
    border-color: #dde2ea;
}

[data-theme="dark"] .app-header .menu-item { color: #2d333b; }
[data-theme="dark"] .app-header .menu-item:hover {
    background: #e8f4fd;
    color: #1565C0;
}
[data-theme="dark"] .app-header .menu-item.menu-danger { color: #ef4444; }
[data-theme="dark"] .app-header .menu-divider { background: #e5e9ef; }

/* ── Main workspace ──────────────────────────────────────────────────────────
   Fills the remainder of the viewport below the header. */

.container {
    display: flex;
    height: calc(100vh - 58px);
}

/* ── Left Control Panel ──────────────────────────────────────────────────────*/

.control-panel {
    width: 320px;
    background: var(--bg-panel);
    border-right: 1px solid var(--border-panel);
    display: flex;
    flex-direction: column;
    box-shadow: var(--shadow-panel);
    z-index: 10;
}

/* Blue title block at the top of the left panel */
.panel-header {
    padding: 16px 20px 18px;
    background: linear-gradient(135deg, var(--brand-start) 0%, var(--brand-end) 100%);
    color: var(--text-on-brand);
    flex-shrink: 0;
}

.panel-header h1 {
    font-size: 19px;
    font-weight: 700;
    letter-spacing: -0.015em;
    margin-bottom: 3px;
}

.panel-header p {
    font-size: 12px;
    color: rgba(255, 255, 255, 0.80);
    font-weight: 400;
}

.mode-selector {
    display: grid;
    grid-template-columns: 1fr 1fr;
    padding: 14px 16px;
    gap: 8px;
    border-bottom: 1px solid var(--border-soft);
    background: var(--bg-panel);
    flex-shrink: 0;
}

.panel-content {
    flex: 1;
    overflow-y: auto;
    padding: 20px;
}

.section {
    margin-bottom: 24px;
}

.section-title {
    font-size: 11px;
    font-weight: 700;
    color: var(--brand-start);
    margin-bottom: 12px;
    text-transform: uppercase;
    letter-spacing: 0.12em;
}

/* ── Canvas Area ─────────────────────────────────────────────────────────────*/

.canvas-container {
    flex: 1;
    display: flex;
    flex-direction: column;
    background: var(--bg-canvas);
}

.canvas-wrapper {
    flex: 1;
    position: relative;
    overflow: hidden;
    background: var(--canvas-bg);
}

canvas {
    position: absolute;
    top: 0;
    left: 0;
    cursor: crosshair;
    touch-action: none;
}

.info-overlay {
    position: absolute;
    bottom: 20px;
    left: 20px;
    background: var(--bg-overlay);
    color: var(--text-secondary);
    padding: 10px 14px;
    border-radius: var(--radius-btn);
    border: 1px solid var(--border-soft);
    font-size: 12px;
    box-shadow: var(--shadow-overlay);
    backdrop-filter: blur(4px);
}

.zoom-controls {
    position: absolute;
    bottom: 20px;
    right: 20px;
    display: flex;
    flex-direction: column;
    gap: 8px;
}

/* Scrollbar styling */
.panel-content::-webkit-scrollbar { width: 6px; }
.panel-content::-webkit-scrollbar-track { background: var(--scrollbar-track); }
.panel-content::-webkit-scrollbar-thumb {
    background: var(--scrollbar-thumb);
    border-radius: 3px;
}
.panel-content::-webkit-scrollbar-thumb:hover { background: var(--scrollbar-thumb-hover); }

/* ── Mobile bottom-sheet layout (below 768px) ──────────────────────────────
   Canvas takes the viewport; the control panel docks to the bottom as a
   compact sheet with the mode tabs visible. Tapping the handle toggles the
   content section between collapsed (tabs only) and expanded (~50vh). */

@media (max-width: 768px) {
    .app-header {
        height: 50px;
        padding: 0 6px;
        gap: 4px;
        /* Guarantee the header never exceeds the viewport even if content is wide. */
        max-width: 100vw;
        overflow: hidden;
    }
    /* Logo is a wide wordmark (≈5.4:1 aspect ratio) — hide on phones so the toolbar fits. */
    .header-brand { display: none; }

    .app-header .toolbar-btn {
        padding: 8px 10px;
        font-size: 13px;
        min-width: 40px;
        min-height: 36px;
    }
    /* Hide descriptive text inside header buttons; the leading emoji/symbol stays as a compact icon. */
    .app-header .btn-label { display: none; }

    /* Shortcuts button is keyboard-only — not useful on touch devices. */
    .app-header #shortcuts-btn { display: none; }

    .app-header .autosave-indicator { display: none; }

    .container {
        flex-direction: column;
        height: calc(100vh - 50px);
    }

    .canvas-container {
        flex: 1 1 auto;
        order: 1;
        min-height: 0;
    }

    .control-panel {
        order: 2;
        width: 100%;
        max-height: 50vh;
        border-right: none;
        border-top: 1px solid var(--border-panel);
        box-shadow: 0 -2px 12px rgba(20, 30, 50, 0.08);
        flex-shrink: 0;
    }

    /* Drag handle strip at the top of the sheet — taps toggle .panel-collapsed */
    .control-panel::before {
        content: '';
        display: block;
        width: 44px;
        height: 4px;
        background: var(--border-input);
        border-radius: 2px;
        margin: 6px auto 0;
    }

    .panel-header {
        display: none;
    }

    .mode-selector {
        grid-template-columns: repeat(4, 1fr);
        padding: 8px;
        gap: 6px;
        position: sticky;
        top: 0;
        z-index: 2;
        background: var(--bg-panel);
    }

    .mode-btn {
        padding: 10px 4px;
        font-size: 11px;
        min-height: 44px;
    }

    .panel-content {
        padding: 14px 16px 20px;
        max-height: 38vh;
    }

    /* Collapsed state: only the mode tabs are visible; tap handle to reopen. */
    .control-panel.panel-collapsed .panel-content {
        display: none;
    }

    /* Touch-friendly tap targets on mobile */
    .btn { min-height: 44px; }
    .icon-btn { min-width: 36px; min-height: 36px; }

    .zoom-controls {
        bottom: 12px;
        right: 12px;
    }
    .info-overlay {
        bottom: 12px;
        left: 12px;
        max-width: calc(100vw - 110px);
        font-size: 11px;
    }

    /* Context menu: full-width sheet-style popup on narrow screens */
    .context-menu {
        min-width: 220px;
    }
    .context-menu-item {
        min-height: 48px;
        font-size: 15px;
    }
}
