/* =====================================================
   CSS Grid Area Designer — styles.css
   Sunset Orange palette, premium dark glassmorphism
   ===================================================== */

:root {
    --primary: #E17055;
    --secondary: #FAB1A0;
    --accent: #00CEC9;
    --bg: #1A0F0A;
    --surface: #221511;
    --surface2: #2C1C14;
    --border: rgba(225, 112, 85, 0.15);
    --text: #FFF1EE;
    --text-muted: #A07870;
    --radius: 12px;
    --transition: 0.2s cubic-bezier(0.4, 0, 0.2, 1);
    --shadow: 0 8px 32px rgba(0, 0, 0, 0.5);
}

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

html {
    scroll-behavior: smooth;
}

body {
    font-family: 'Inter', system-ui, sans-serif;
    background: var(--bg);
    color: var(--text);
    min-height: 100vh;
}

body::before {
    content: '';
    position: fixed;
    inset: 0;
    background: radial-gradient(ellipse at 20% 0%, rgba(225, 112, 85, 0.08) 0%, transparent 50%),
        radial-gradient(ellipse at 80% 100%, rgba(0, 206, 201, 0.04) 0%, transparent 50%);
    pointer-events: none;
    z-index: 0;
}

::-webkit-scrollbar {
    width: 5px;
}

::-webkit-scrollbar-track {
    background: transparent;
}

::-webkit-scrollbar-thumb {
    background: var(--border);
    border-radius: 3px;
}

.hidden {
    display: none !important;
}

.glass-card {
    background: rgba(34, 21, 17, 0.78);
    backdrop-filter: blur(14px);
    border: 1px solid var(--border);
    border-radius: var(--radius);
}

/* ── Header ───────────────────────────────────────── */
.header {
    position: sticky;
    top: 0;
    z-index: 100;
    background: rgba(26, 15, 10, 0.9);
    border-bottom: 1px solid var(--border);
    backdrop-filter: blur(20px);
}

.header-inner {
    max-width: 1440px;
    margin: 0 auto;
    padding: 11px 24px;
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.logo {
    display: flex;
    align-items: center;
    gap: 12px;
}

.logo-icon {
    width: 38px;
    height: 38px;
    background: rgba(225, 112, 85, 0.12);
    border: 1px solid rgba(225, 112, 85, 0.3);
    border-radius: 10px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.logo-title {
    font-size: 1rem;
    font-weight: 700;
}

.logo-sub {
    font-size: 0.65rem;
    color: var(--primary);
    text-transform: uppercase;
    letter-spacing: 0.08em;
}

.header-actions {
    display: flex;
    align-items: center;
    gap: 7px;
}

/* Buttons */
.btn-primary {
    background: linear-gradient(135deg, var(--primary), #C56B4E);
    border: none;
    border-radius: 8px;
    color: white;
    font-size: 0.84rem;
    font-weight: 600;
    padding: 8px 18px;
    cursor: pointer;
    transition: box-shadow var(--transition), transform var(--transition);
}

.btn-primary:hover {
    box-shadow: 0 0 16px rgba(225, 112, 85, 0.4);
    transform: translateY(-1px);
}

.btn-ghost {
    background: transparent;
    border: 1px solid var(--border);
    border-radius: 8px;
    color: var(--text-muted);
    font-size: 0.82rem;
    padding: 7px 14px;
    cursor: pointer;
    transition: all var(--transition);
}

.btn-ghost:hover {
    color: var(--primary);
    border-color: var(--primary);
}

.btn-icon {
    width: 34px;
    height: 34px;
    background: var(--surface2);
    border: 1px solid var(--border);
    border-radius: 8px;
    color: var(--text-muted);
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    font-size: 1rem;
    transition: all var(--transition);
}

.btn-icon:hover {
    color: var(--text);
    background: var(--border);
}

.btn-icon:disabled {
    opacity: 0.3;
    cursor: not-allowed;
}

/* ── Main Layout ──────────────────────────────────── */
.main {
    max-width: 1440px;
    margin: 0 auto;
    padding: 20px 24px;
    display: grid;
    grid-template-columns: 260px 1fr 340px;
    gap: 18px;
    align-items: start;
    position: relative;
    z-index: 1;
}

/* ── Controls Panel ───────────────────────────────── */
.controls-panel {
    position: sticky;
    top: 70px;
    max-height: calc(100vh - 90px);
    overflow-y: auto;
    overflow-x: hidden;
    padding: 0;
}

.ctrl-section {
    padding: 14px 16px;
    border-bottom: 1px solid var(--border);
}

.ctrl-title {
    font-size: 0.72rem;
    font-weight: 700;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.07em;
    margin-bottom: 10px;
    display: flex;
    align-items: center;
    gap: 8px;
}

.ctrl-label {
    font-size: 0.72rem;
    color: var(--text-muted);
    flex: 1;
}

.ctrl-hint {
    font-size: 0.68rem;
    color: var(--text-muted);
    font-style: italic;
    margin-top: 6px;
}

.val {
    color: var(--primary);
    font-family: 'JetBrains Mono', monospace;
    font-size: 0.7rem;
}

.ctrl-row {
    display: flex;
    align-items: center;
    gap: 10px;
    margin-bottom: 8px;
}

.range-field {
    flex: 1;
    -webkit-appearance: none;
    appearance: none;
    height: 3px;
    background: var(--border);
    border-radius: 2px;
    outline: none;
    cursor: pointer;
}

.range-field::-webkit-slider-thumb {
    -webkit-appearance: none;
    width: 14px;
    height: 14px;
    border-radius: 50%;
    background: var(--primary);
    cursor: pointer;
}

.size-input {
    background: var(--surface2);
    border: 1px solid var(--border);
    border-radius: 6px;
    color: var(--text);
    font-size: 0.72rem;
    font-family: 'JetBrains Mono', monospace;
    padding: 4px 7px;
    outline: none;
    width: 72px;
    transition: border-color var(--transition);
}

.size-input:focus {
    border-color: var(--primary);
}

.size-row {
    display: flex;
    align-items: center;
    gap: 6px;
    margin-bottom: 5px;
}

.size-row-label {
    font-size: 0.68rem;
    color: var(--text-muted);
    width: 28px;
}

/* Area Palette */
.add-area-btn {
    background: transparent;
    border: none;
    color: var(--accent);
    font-size: 0.72rem;
    cursor: pointer;
    margin-left: auto;
    transition: opacity var(--transition);
}

.add-area-btn:hover {
    opacity: 0.7;
}

.area-palette {
    display: flex;
    flex-direction: column;
    gap: 5px;
}

.palette-item {
    display: flex;
    align-items: center;
    gap: 8px;
    background: var(--surface2);
    border: 1px solid transparent;
    border-radius: 8px;
    padding: 7px 10px;
    cursor: pointer;
    transition: all var(--transition);
}

.palette-item.selected {
    border-color: white;
}

.palette-item:hover {
    border-color: var(--border);
}

.palette-swatch {
    width: 18px;
    height: 18px;
    border-radius: 4px;
    flex-shrink: 0;
}

.palette-name-input {
    flex: 1;
    background: transparent;
    border: none;
    color: var(--text);
    font-size: 0.8rem;
    font-family: 'JetBrains Mono', monospace;
    outline: none;
    cursor: text;
    min-width: 0;
}

.palette-name-input:focus {
    outline: none;
}

.palette-del {
    background: none;
    border: none;
    color: var(--text-muted);
    cursor: pointer;
    font-size: 0.85rem;
    padding: 0 2px;
    transition: color var(--transition);
}

.palette-del:hover {
    color: #FF6B6B;
}

.eraser-btn {
    display: flex;
    align-items: center;
    gap: 8px;
    background: var(--surface2);
    border: 1px solid transparent;
    border-radius: 8px;
    padding: 7px 10px;
    cursor: pointer;
    font-size: 0.8rem;
    color: var(--text-muted);
    transition: all var(--transition);
}

.eraser-btn.selected {
    border-color: white;
    color: var(--text);
}

/* Templates */
.template-grid {
    display: flex;
    flex-wrap: wrap;
    gap: 7px;
}

.template-btn {
    background: var(--surface2);
    border: 1px solid var(--border);
    border-radius: 8px;
    color: var(--text-muted);
    font-size: 0.7rem;
    padding: 6px 10px;
    cursor: pointer;
    transition: all var(--transition);
}

.template-btn:hover {
    border-color: var(--accent);
    color: var(--accent);
}

/* ── Grid Canvas Area ─────────────────────────────── */
.grid-area {
    display: flex;
    flex-direction: column;
    gap: 14px;
}

.canvas-toolbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
}

.canvas-label {
    font-size: 0.8rem;
    font-weight: 600;
    color: var(--text-muted);
    display: flex;
    align-items: center;
    gap: 8px;
}

.grid-size-badge {
    background: rgba(225, 112, 85, 0.15);
    border: 1px solid rgba(225, 112, 85, 0.2);
    border-radius: 12px;
    padding: 2px 10px;
    font-size: 0.67rem;
    font-family: 'JetBrains Mono', monospace;
    color: var(--primary);
}

.canvas-toolbar-right {
    display: flex;
    gap: 6px;
}

.btn-tiny {
    background: var(--surface2);
    border: 1px solid var(--border);
    border-radius: 6px;
    color: var(--text-muted);
    font-size: 0.7rem;
    padding: 5px 10px;
    cursor: pointer;
    transition: all var(--transition);
}

.btn-tiny[aria-pressed="true"] {
    color: var(--accent);
    border-color: var(--accent);
}

.grid-canvas-wrap {
    position: relative;
    overflow: auto;
}

.grid-canvas {
    display: grid;
    gap: 2px;
    user-select: none;
    cursor: crosshair;
    min-width: 320px;
}

.grid-cell {
    height: 72px;
    background: var(--surface2);
    border: 1px solid var(--border);
    border-radius: 6px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 0.65rem;
    font-family: 'JetBrains Mono', monospace;
    color: var(--text-muted);
    letter-spacing: 0.05em;
    transition: background var(--transition), border var(--transition);
    position: relative;
    overflow: hidden;
}

.grid-cell.assigned {
    border: 1px solid rgba(255, 255, 255, 0.2);
}

.grid-cell.hover {
    border-color: white;
    filter: brightness(1.2);
}

.grid-cell.drag-over {
    filter: brightness(1.3);
}

.cell-label {
    position: absolute;
    bottom: 4px;
    right: 6px;
    font-size: 0.6rem;
    opacity: 0.8;
    color: white;
    font-family: 'JetBrains Mono', monospace;
}

/* Live preview */
.live-preview {
    padding: 14px;
}

.live-preview-title {
    font-size: 0.72rem;
    font-weight: 700;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.07em;
    margin-bottom: 10px;
}

.preview-grid {
    min-height: 120px;
    background: var(--surface2);
    border-radius: 8px;
    overflow: hidden;
    padding: 4px;
}

.preview-area-block {
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 6px;
    font-size: 0.7rem;
    font-family: 'JetBrains Mono', monospace;
    color: white;
    font-weight: 600;
    border: 1px solid rgba(255, 255, 255, 0.15);
    min-height: 40px;
}

/* ── Code Section ─────────────────────────────────── */
.code-section {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.code-tabs {
    display: flex;
    border-radius: 8px;
    overflow: hidden;
    border: 1px solid var(--border);
}

.code-tab {
    flex: 1;
    background: transparent;
    border: none;
    padding: 9px;
    font-size: 0.78rem;
    color: var(--text-muted);
    cursor: pointer;
    border-right: 1px solid var(--border);
    transition: all var(--transition);
}

.code-tab:last-child {
    border-right: none;
}

.code-tab.active {
    background: rgba(225, 112, 85, 0.12);
    color: var(--primary);
}

.code-tab:hover:not(.active) {
    background: var(--surface2);
}

.code-card {
    overflow: hidden;
}

.code-header {
    display: flex;
    justify-content: flex-end;
    padding: 8px 12px;
    border-bottom: 1px solid var(--border);
}

.btn-copy {
    background: var(--surface2);
    border: 1px solid var(--border);
    border-radius: 6px;
    color: var(--text-muted);
    font-size: 0.72rem;
    padding: 4px 10px;
    cursor: pointer;
    transition: all var(--transition);
}

.btn-copy:hover {
    color: var(--primary);
    border-color: var(--primary);
}

.code-output {
    background: transparent;
    padding: 12px 14px;
    font-family: 'JetBrains Mono', monospace;
    font-size: 0.73rem;
    color: var(--text);
    line-height: 1.7;
    white-space: pre;
    overflow-x: auto;
    max-height: 350px;
    overflow-y: auto;
}

/* Inspector */
.inspector-card {
    overflow: hidden;
}

.area-inspector {
    padding: 10px 14px;
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.inspector-row {
    display: flex;
    align-items: center;
    gap: 8px;
    background: var(--surface2);
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 8px 12px;
    font-size: 0.8rem;
    font-family: 'JetBrains Mono', monospace;
}

.inspector-swatch {
    width: 16px;
    height: 16px;
    border-radius: 3px;
    flex-shrink: 0;
}

.inspector-name {
    flex: 1;
}

.inspector-span {
    color: var(--text-muted);
    font-size: 0.72rem;
}

/* ── Modal ────────────────────────────────────────── */
.modal-overlay {
    position: fixed;
    inset: 0;
    z-index: 400;
    background: rgba(0, 0, 0, 0.65);
    backdrop-filter: blur(5px);
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 24px;
}

.modal {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    width: 100%;
    max-width: 620px;
    box-shadow: var(--shadow);
    animation: modal-in 0.2s ease;
}

@keyframes modal-in {
    from {
        opacity: 0;
        transform: scale(0.95);
    }

    to {
        opacity: 1;
        transform: none;
    }
}

.modal-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 14px 18px;
    border-bottom: 1px solid var(--border);
}

.modal-title {
    font-size: .95rem;
    font-weight: 700;
}

.modal-close {
    background: none;
    border: none;
    color: var(--text-muted);
    font-size: 1.3rem;
    cursor: pointer;
}

.modal-body {
    padding: 16px;
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.export-code {
    max-height: 360px;
    overflow-y: auto;
}

/* ── Responsive ───────────────────────────────────── */
@media (max-width: 1200px) {
    .main {
        grid-template-columns: 220px 1fr 300px;
    }
}

@media (max-width: 900px) {
    .main {
        grid-template-columns: 1fr;
    }

    ;

    .controls-panel {
        position: static;
        max-height: none;
    }
}

@media (max-width: 640px) {
    .main {
        padding: 14px;
    }
}