/* ========================================
   CSS Grid Area Painter — Blueprint Theme
   ======================================== */
:root {
    --primary: #0C4A6E;
    --primary-light: #0E7490;
    --accent: #38BDF8;
    --accent-glow: rgba(56, 189, 248, 0.25);
    --success: #34D399;

    --bg-base: #0C4A6E;
    --bg-surface: #0A3B5C;
    --bg-elevated: #0D5480;
    --bg-input: #083348;
    --bg-hover: #0E6090;

    --text-primary: #E0F2FE;
    --text-secondary: #7DD3FC;
    --text-muted: #38BDF8;

    --border: rgba(56, 189, 248, 0.2);
    --border-active: rgba(56, 189, 248, 0.5);
    --radius: 12px;
    --radius-sm: 8px;
    --font: 'Inter', system-ui, -apple-system, sans-serif;
    --font-mono: 'JetBrains Mono', monospace;
    --transition: 200ms ease;

    --grid-line: rgba(56, 189, 248, 0.25);
    --grid-cell: rgba(56, 189, 248, 0.05);
    --grid-cell-hover: rgba(56, 189, 248, 0.15);
}

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

body {
    font-family: var(--font);
    background: var(--bg-base);
    color: var(--text-primary);
    line-height: 1.6;
    min-height: 100vh;
    background-image:
        linear-gradient(rgba(56, 189, 248, 0.03) 1px, transparent 1px),
        linear-gradient(90deg, rgba(56, 189, 248, 0.03) 1px, transparent 1px);
    background-size: 20px 20px;
}

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

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

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

.app-container {
    max-width: 1400px;
    margin: 0 auto;
    padding: 0 1rem;
}

/* Header */
.app-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0.75rem 0;
    border-bottom: 1px solid var(--border);
    margin-bottom: 1rem;
}

.logo {
    display: flex;
    align-items: center;
    gap: 0.75rem;
}

.logo h1 {
    font-size: 1.15rem;
    font-weight: 700;
    color: var(--accent);
}

.header-actions {
    display: flex;
    gap: 0.5rem;
}

/* Buttons */
.btn {
    display: inline-flex;
    align-items: center;
    gap: 0.4rem;
    padding: 0.45rem 0.9rem;
    border: none;
    border-radius: var(--radius-sm);
    font-family: var(--font);
    font-size: 0.82rem;
    font-weight: 600;
    cursor: pointer;
    transition: all var(--transition);
    white-space: nowrap;
}

.btn-primary {
    background: var(--primary-light);
    color: white;
    border: 1px solid var(--border-active);
}

.btn-primary:hover {
    background: var(--bg-elevated);
}

.btn-secondary {
    background: var(--bg-input);
    color: var(--text-primary);
    border: 1px solid var(--border);
}

.btn-secondary:hover {
    background: var(--bg-hover);
}

.btn-accent {
    background: var(--accent);
    color: var(--bg-base);
    font-weight: 700;
}

.btn-accent:hover {
    transform: translateY(-1px);
    box-shadow: 0 4px 12px var(--accent-glow);
}

.btn-ghost {
    background: transparent;
    color: var(--text-secondary);
}

.btn-ghost:hover {
    color: var(--text-primary);
    background: rgba(56, 189, 248, 0.1);
}

.btn-sm {
    padding: 0.3rem 0.6rem;
    font-size: 0.78rem;
}

.btn-full {
    width: 100%;
    justify-content: center;
}

.hidden {
    display: none !important;
}

/* Layout */
.main-layout {
    display: grid;
    grid-template-columns: 220px 1fr 300px;
    gap: 1rem;
    height: calc(100vh - 70px);
}

/* Controls Panel */
.controls-panel {
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
    overflow-y: auto;
    padding-right: 0.5rem;
}

.ctrl-group {
    background: var(--bg-surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    padding: 0.75rem;
}

.ctrl-group h3 {
    font-size: 0.72rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    color: var(--text-muted);
    margin-bottom: 0.5rem;
}

.ctrl-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 0.4rem;
}

.ctrl-row label {
    font-size: 0.82rem;
    color: var(--text-secondary);
}

.ctrl-input {
    font-family: var(--font-mono);
    font-size: 0.82rem;
    width: 60px;
    padding: 0.3rem 0.5rem;
    border-radius: 6px;
    border: 1px solid var(--border);
    background: var(--bg-input);
    color: var(--text-primary);
    text-align: center;
    outline: none;
    transition: border-color var(--transition);
}

.ctrl-input:focus {
    border-color: var(--accent);
}

.input-unit {
    display: flex;
    align-items: center;
    gap: 0.25rem;
}

.unit {
    font-size: 0.75rem;
    color: var(--text-muted);
}

/* Size List */
.size-list {
    display: flex;
    flex-direction: column;
    gap: 0.3rem;
}

.size-row {
    display: flex;
    align-items: center;
    gap: 0.35rem;
}

.size-row .size-label {
    font-size: 0.72rem;
    color: var(--text-muted);
    min-width: 20px;
}

.size-row input {
    width: 45px;
}

.size-row select {
    font-size: 0.75rem;
    padding: 0.2rem;
    border-radius: 4px;
    border: 1px solid var(--border);
    background: var(--bg-input);
    color: var(--text-primary);
    cursor: pointer;
}

/* Area Chips */
.area-chips {
    display: flex;
    flex-wrap: wrap;
    gap: 0.3rem;
    margin-bottom: 0.5rem;
}

.area-chip {
    display: flex;
    align-items: center;
    gap: 0.3rem;
    padding: 0.25rem 0.6rem;
    border-radius: 16px;
    font-size: 0.75rem;
    font-weight: 600;
    cursor: pointer;
    transition: all var(--transition);
    border: 2px solid transparent;
}

.area-chip.active {
    border-color: white;
    box-shadow: 0 0 8px var(--accent-glow);
}

.area-chip .chip-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
}

.area-chip .chip-remove {
    font-size: 0.85rem;
    opacity: 0.6;
    cursor: pointer;
    margin-left: 0.15rem;
    background: none;
    border: none;
    color: inherit;
}

.area-chip .chip-remove:hover {
    opacity: 1;
}

.add-area-row {
    display: flex;
    gap: 0.3rem;
}

.add-area-row .ctrl-input {
    flex: 1;
    width: unset;
    text-align: left;
}

/* Breakpoint Tabs */
.breakpoint-tabs {
    display: flex;
    gap: 0.25rem;
}

.bp-tab {
    flex: 1;
    padding: 0.3rem;
    font-size: 0.72rem;
    font-weight: 600;
    border: 1px solid var(--border);
    border-radius: 6px;
    background: transparent;
    color: var(--text-muted);
    cursor: pointer;
    transition: all var(--transition);
    text-align: center;
}

.bp-tab:hover {
    border-color: var(--border-active);
}

.bp-tab.active {
    background: var(--accent);
    color: var(--bg-base);
    border-color: var(--accent);
}

/* Grid Canvas */
.grid-canvas-wrap {
    display: flex;
    flex-direction: column;
    min-height: 0;
}

.grid-canvas {
    flex: 1;
    display: grid;
    background: var(--bg-surface);
    border: 2px solid var(--border);
    border-radius: var(--radius);
    overflow: hidden;
    min-height: 400px;
    user-select: none;
}

.grid-cell {
    border: 1px solid var(--grid-line);
    background: var(--grid-cell);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 0.72rem;
    font-weight: 600;
    color: rgba(255, 255, 255, 0.8);
    cursor: pointer;
    transition: background 0.15s ease;
    position: relative;
    min-height: 60px;
}

.grid-cell:hover {
    background: var(--grid-cell-hover);
}

.grid-cell .cell-coord {
    position: absolute;
    bottom: 2px;
    right: 4px;
    font-size: 0.6rem;
    color: rgba(56, 189, 248, 0.3);
    font-family: var(--font-mono);
}

.canvas-footer {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0.5rem 0;
}

.paint-hint {
    font-size: 0.78rem;
    color: var(--text-muted);
}

/* Output Panel */
.output-panel {
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.output-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 0.5rem;
}

.output-header h3 {
    font-size: 0.72rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    color: var(--text-muted);
}

.badge {
    font-size: 0.68rem;
    font-weight: 600;
    padding: 0.15rem 0.5rem;
    border-radius: 12px;
    background: var(--accent-glow);
    color: var(--accent);
}

.css-output {
    flex: 1;
    background: var(--bg-surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    padding: 1rem;
    overflow: auto;
    margin: 0;
    font-family: var(--font-mono);
    font-size: 0.78rem;
    line-height: 1.7;
    color: var(--accent);
}

.css-output code {
    white-space: pre-wrap;
}

/* Toast */
.toast-container {
    position: fixed;
    bottom: 1.5rem;
    right: 1.5rem;
    z-index: 2000;
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

.toast {
    padding: 0.65rem 1rem;
    border-radius: var(--radius-sm);
    font-size: 0.82rem;
    font-weight: 500;
    box-shadow: 0 4px 16px rgba(0, 0, 0, 0.5);
    animation: slideIn 0.3s ease, fadeOut 0.3s ease 2.5s forwards;
}

.toast-success {
    background: rgba(52, 211, 153, 0.15);
    color: var(--success);
    border: 1px solid rgba(52, 211, 153, 0.3);
}

.toast-info {
    background: rgba(56, 189, 248, 0.15);
    color: var(--accent);
    border: 1px solid rgba(56, 189, 248, 0.3);
}

@keyframes slideIn {
    from {
        opacity: 0;
        transform: translateX(40px);
    }

    to {
        opacity: 1;
        transform: translateX(0);
    }
}

@keyframes fadeOut {
    from {
        opacity: 1;
    }

    to {
        opacity: 0;
        pointer-events: none;
    }
}

@media (max-width: 1024px) {
    .main-layout {
        grid-template-columns: 200px 1fr 250px;
    }
}

@media (max-width: 768px) {
    .main-layout {
        grid-template-columns: 1fr;
        grid-template-rows: auto 1fr auto;
        height: auto;
    }

    .controls-panel {
        flex-direction: row;
        flex-wrap: wrap;
        overflow-x: auto;
        padding-right: 0;
    }

    .ctrl-group {
        min-width: 180px;
    }

    .grid-canvas {
        min-height: 300px;
    }
}