/* ========================================
   CSS Grid Layout Debugger — Styles
   Forest Moss Dark Theme
   ======================================== */

:root {
    --primary: #22C55E;
    --primary-dim: rgba(34, 197, 94, 0.25);
    --secondary: #86EFAC;
    --accent: #A3E635;
    --bg: #0A1A0D;
    --bg-panel: rgba(16, 38, 22, 0.7);
    --bg-card: rgba(34, 197, 94, 0.06);
    --border: rgba(134, 239, 172, 0.12);
    --text: #E8F5EC;
    --text-muted: rgba(232, 245, 236, 0.5);
    --radius: 12px;
    --gap-color: rgba(163, 230, 53, 0.25);
    --transition: 250ms ease;
    --font: 'Inter', system-ui, -apple-system, sans-serif;
}

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

html {
    font-size: 14px;
}

body {
    font-family: var(--font);
    background: var(--bg);
    color: var(--text);
    min-height: 100vh;
    overflow-x: hidden;
    background-image:
        radial-gradient(ellipse at 20% 0%, rgba(34, 197, 94, 0.08) 0%, transparent 60%),
        radial-gradient(ellipse at 80% 100%, rgba(163, 230, 53, 0.06) 0%, transparent 50%);
}

/* ---- Header ---- */
.app-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0.75rem 1.25rem;
    border-bottom: 1px solid var(--border);
    backdrop-filter: blur(16px);
    position: sticky;
    top: 0;
    z-index: 100;
    background: rgba(10, 26, 13, 0.85);
}

.header-left {
    display: flex;
    align-items: center;
    gap: 0.6rem;
}

.logo {
    font-size: 1.5rem;
    color: var(--primary);
    filter: drop-shadow(0 0 6px var(--primary-dim));
}

.app-header h1 {
    font-size: 1.15rem;
    font-weight: 700;
    background: linear-gradient(135deg, var(--primary), var(--accent));
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
}

.breakpoint-bar {
    display: flex;
    gap: 4px;
    background: var(--bg-panel);
    border-radius: var(--radius);
    padding: 3px;
    border: 1px solid var(--border);
}

.bp-btn {
    background: transparent;
    border: none;
    color: var(--text-muted);
    padding: 6px 14px;
    border-radius: 9px;
    cursor: pointer;
    font-family: var(--font);
    font-size: 0.8rem;
    font-weight: 500;
    transition: all var(--transition);
}

.bp-btn.active {
    background: var(--primary-dim);
    color: var(--primary);
    box-shadow: 0 0 12px rgba(34, 197, 94, 0.15);
}

.bp-btn:hover:not(.active) {
    color: var(--secondary);
}

/* ---- Layout ---- */
.app-main {
    display: grid;
    grid-template-columns: 280px 1fr 300px;
    height: calc(100vh - 52px);
    overflow: hidden;
}

/* ---- Glass Panels ---- */
.glass {
    background: var(--bg-panel);
    backdrop-filter: blur(18px);
    border-right: 1px solid var(--border);
}

.config-panel {
    overflow-y: auto;
    padding: 1rem;
}

.code-panel {
    overflow-y: auto;
    padding: 1rem;
    border-right: none;
    border-left: 1px solid var(--border);
}

.panel-title {
    font-size: 0.85rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    color: var(--secondary);
    margin-bottom: 1rem;
}

/* ---- Config Sections ---- */
.config-section {
    margin-bottom: 1.25rem;
    padding-bottom: 1.25rem;
    border-bottom: 1px solid var(--border);
}

.config-section:last-child {
    border-bottom: none;
}

.config-section h3 {
    font-size: 0.8rem;
    font-weight: 600;
    color: var(--text);
    margin-bottom: 0.6rem;
}

/* Track list items */
.track-item {
    display: flex;
    align-items: center;
    gap: 6px;
    margin-bottom: 6px;
    animation: fadeSlideIn 200ms ease;
}

@keyframes fadeSlideIn {
    from {
        opacity: 0;
        transform: translateY(-6px);
    }

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

.track-item input[type="number"] {
    width: 60px;
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 6px 8px;
    color: var(--text);
    font-family: var(--font);
    font-size: 0.85rem;
    transition: border-color var(--transition);
}

.track-item input[type="number"]:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 2px var(--primary-dim);
}

.track-item select {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 6px 8px;
    color: var(--text);
    font-family: var(--font);
    font-size: 0.8rem;
    cursor: pointer;
    transition: border-color var(--transition);
}

.track-item select:focus {
    outline: none;
    border-color: var(--primary);
}

.track-number {
    font-size: 0.7rem;
    color: var(--text-muted);
    width: 18px;
    text-align: center;
    flex-shrink: 0;
}

.btn-remove {
    background: transparent;
    border: none;
    color: var(--text-muted);
    cursor: pointer;
    padding: 4px;
    border-radius: 6px;
    transition: all var(--transition);
    font-size: 0.9rem;
    flex-shrink: 0;
}

.btn-remove:hover {
    color: #EF4444;
    background: rgba(239, 68, 68, 0.12);
}

.btn-add {
    display: block;
    width: 100%;
    padding: 7px;
    background: var(--bg-card);
    border: 1px dashed var(--border);
    border-radius: 8px;
    color: var(--primary);
    cursor: pointer;
    font-family: var(--font);
    font-size: 0.8rem;
    font-weight: 500;
    transition: all var(--transition);
}

.btn-add:hover {
    background: var(--primary-dim);
    border-color: var(--primary);
}

/* Gap inputs */
.gap-inputs {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 10px;
}

.gap-inputs label span {
    display: block;
    font-size: 0.75rem;
    color: var(--text-muted);
    margin-bottom: 4px;
}

.input-unit {
    display: flex;
    align-items: center;
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: 8px;
    overflow: hidden;
    transition: border-color var(--transition);
}

.input-unit:focus-within {
    border-color: var(--primary);
    box-shadow: 0 0 0 2px var(--primary-dim);
}

.input-unit input {
    flex: 1;
    width: 100%;
    border: none;
    background: transparent;
    padding: 6px 8px;
    color: var(--text);
    font-family: var(--font);
    font-size: 0.85rem;
}

.input-unit input:focus {
    outline: none;
}

.input-unit .unit {
    padding: 6px 8px;
    background: rgba(134, 239, 172, 0.06);
    color: var(--text-muted);
    font-size: 0.75rem;
    font-weight: 600;
}

/* Item controls */
.item-controls {
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.item-controls label span {
    display: block;
    font-size: 0.75rem;
    color: var(--text-muted);
    margin-bottom: 4px;
}

.item-controls input[type="number"] {
    width: 100%;
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 6px 8px;
    color: var(--text);
    font-family: var(--font);
    font-size: 0.85rem;
}

.item-controls input[type="number"]:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 2px var(--primary-dim);
}

/* Toggle */
.toggle-label {
    display: flex;
    align-items: center;
    gap: 8px;
    cursor: pointer;
    font-size: 0.8rem;
    color: var(--text);
}

.toggle-label input {
    display: none;
}

.toggle-switch {
    width: 36px;
    height: 20px;
    background: var(--border);
    border-radius: 10px;
    position: relative;
    transition: background var(--transition);
}

.toggle-switch::after {
    content: '';
    position: absolute;
    top: 2px;
    left: 2px;
    width: 16px;
    height: 16px;
    border-radius: 50%;
    background: var(--text-muted);
    transition: all var(--transition);
}

.toggle-label input:checked~.toggle-switch {
    background: var(--primary);
}

.toggle-label input:checked~.toggle-switch::after {
    left: 18px;
    background: var(--bg);
}

/* Textarea */
#area-names {
    width: 100%;
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 8px;
    color: var(--text);
    font-family: 'Courier New', monospace;
    font-size: 0.8rem;
    resize: vertical;
    transition: border-color var(--transition);
    margin-bottom: 8px;
}

#area-names:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 2px var(--primary-dim);
}

.btn-secondary {
    width: 100%;
    padding: 7px;
    background: var(--primary-dim);
    border: 1px solid rgba(34, 197, 94, 0.3);
    border-radius: 8px;
    color: var(--primary);
    cursor: pointer;
    font-family: var(--font);
    font-size: 0.8rem;
    font-weight: 600;
    transition: all var(--transition);
}

.btn-secondary:hover {
    background: rgba(34, 197, 94, 0.35);
}

/* ---- Grid Preview Area ---- */
.grid-preview-wrapper {
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 2rem;
    overflow: auto;
    background:
        radial-gradient(circle at 50% 50%, rgba(34, 197, 94, 0.04) 0%, transparent 70%),
        repeating-linear-gradient(0deg, transparent, transparent 19px, rgba(134, 239, 172, 0.04) 19px, rgba(134, 239, 172, 0.04) 20px),
        repeating-linear-gradient(90deg, transparent, transparent 19px, rgba(134, 239, 172, 0.04) 19px, rgba(134, 239, 172, 0.04) 20px);
}

.preview-container {
    position: relative;
    width: 100%;
    max-width: 800px;
    transition: max-width var(--transition);
}

.preview-container.bp-tablet {
    max-width: 768px;
}

.preview-container.bp-mobile {
    max-width: 375px;
}

.grid-canvas {
    display: grid;
    width: 100%;
    min-height: 400px;
    border: 2px solid var(--primary);
    border-radius: var(--radius);
    overflow: hidden;
    position: relative;
    box-shadow:
        0 0 30px rgba(34, 197, 94, 0.08),
        inset 0 0 40px rgba(34, 197, 94, 0.03);
}

/* Grid items */
.grid-item {
    display: flex;
    align-items: center;
    justify-content: center;
    flex-direction: column;
    gap: 4px;
    background: linear-gradient(135deg, rgba(34, 197, 94, 0.15), rgba(163, 230, 53, 0.08));
    border: 1px solid rgba(34, 197, 94, 0.25);
    border-radius: 8px;
    padding: 12px;
    color: var(--secondary);
    font-size: 0.8rem;
    font-weight: 600;
    transition: all var(--transition);
    cursor: default;
    position: relative;
    overflow: hidden;
}

.grid-item::before {
    content: '';
    position: absolute;
    inset: 0;
    background: linear-gradient(135deg, transparent 40%, rgba(163, 230, 53, 0.06));
    opacity: 0;
    transition: opacity var(--transition);
}

.grid-item:hover {
    border-color: var(--primary);
    box-shadow: 0 0 20px rgba(34, 197, 94, 0.15);
    transform: scale(1.02);
}

.grid-item:hover::before {
    opacity: 1;
}

.grid-item .item-number {
    font-size: 1.1rem;
    font-weight: 700;
    color: var(--primary);
}

.grid-item .item-area {
    font-size: 0.65rem;
    color: var(--accent);
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

/* Gap overlay */
.gap-overlay {
    position: absolute;
    inset: 0;
    pointer-events: none;
    z-index: 2;
}

.gap-line {
    position: absolute;
    background: var(--gap-color);
    display: flex;
    align-items: center;
    justify-content: center;
}

.gap-line.horizontal {
    left: 0;
    right: 0;
    height: var(--gap-size);
}

.gap-line.vertical {
    top: 0;
    bottom: 0;
    width: var(--gap-size);
}

.gap-label {
    font-size: 0.6rem;
    font-weight: 600;
    color: var(--accent);
    background: rgba(10, 26, 13, 0.85);
    padding: 1px 5px;
    border-radius: 4px;
    white-space: nowrap;
}

/* Track labels */
.track-labels {
    display: flex;
    position: absolute;
    pointer-events: auto;
}

.track-labels-cols {
    top: -24px;
    left: 0;
    right: 0;
    flex-direction: row;
}

.track-labels-rows {
    left: -44px;
    top: 0;
    bottom: 0;
    flex-direction: column;
}

.track-label {
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 0.65rem;
    font-weight: 600;
    color: var(--text-muted);
    padding: 2px 6px;
    border-radius: 4px;
    cursor: pointer;
    transition: all var(--transition);
    white-space: nowrap;
}

.track-label:hover {
    color: var(--accent);
    background: rgba(163, 230, 53, 0.12);
}

/* ---- Code Panel ---- */
.code-actions {
    display: flex;
    gap: 6px;
    margin-bottom: 0.75rem;
}

.btn-copy {
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 4px;
    padding: 8px;
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: 8px;
    color: var(--primary);
    cursor: pointer;
    font-family: var(--font);
    font-size: 0.78rem;
    font-weight: 600;
    transition: all var(--transition);
}

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

.btn-copy.copied {
    background: var(--primary);
    color: var(--bg);
    border-color: var(--primary);
}

.code-output {
    background: rgba(10, 26, 13, 0.6);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 1rem;
    overflow-x: auto;
    font-family: 'Courier New', monospace;
    font-size: 0.78rem;
    line-height: 1.6;
    color: var(--secondary);
    white-space: pre-wrap;
    word-break: break-all;
    margin-bottom: 1rem;
}

/* Track inspector */
.track-inspector h3 {
    font-size: 0.8rem;
    font-weight: 600;
    color: var(--text);
    margin-bottom: 0.5rem;
}

.track-info {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 10px;
    font-size: 0.78rem;
    line-height: 1.5;
}

.track-info .muted {
    color: var(--text-muted);
    font-style: italic;
}

.track-info .info-row {
    display: flex;
    justify-content: space-between;
    padding: 3px 0;
    border-bottom: 1px solid var(--border);
}

.track-info .info-row:last-child {
    border-bottom: none;
}

.track-info .info-label {
    color: var(--text-muted);
}

.track-info .info-value {
    color: var(--accent);
    font-weight: 600;
}

/* ---- Toast ---- */
.toast {
    position: fixed;
    bottom: 24px;
    left: 50%;
    transform: translateX(-50%) translateY(100px);
    background: var(--primary);
    color: var(--bg);
    padding: 10px 24px;
    border-radius: var(--radius);
    font-weight: 600;
    font-size: 0.85rem;
    box-shadow: 0 8px 32px rgba(34, 197, 94, 0.3);
    transition: transform 300ms cubic-bezier(0.34, 1.56, 0.64, 1);
    z-index: 1000;
    pointer-events: none;
}

.toast.show {
    transform: translateX(-50%) translateY(0);
}

/* ---- Scrollbar ---- */
::-webkit-scrollbar {
    width: 6px;
}

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

::-webkit-scrollbar-thumb {
    background: rgba(134, 239, 172, 0.15);
    border-radius: 3px;
}

::-webkit-scrollbar-thumb:hover {
    background: rgba(134, 239, 172, 0.3);
}

/* ---- Responsive ---- */
@media (max-width: 1024px) {
    .app-main {
        grid-template-columns: 1fr;
        grid-template-rows: auto 1fr auto;
        height: auto;
    }

    .config-panel,
    .code-panel {
        border-right: none;
        border-left: none;
        border-bottom: 1px solid var(--border);
    }

    .grid-preview-wrapper {
        min-height: 400px;
    }

    .track-labels-rows {
        display: none;
    }
}

@media (max-width: 640px) {
    .breakpoint-bar {
        display: none;
    }

    .app-header h1 {
        font-size: 1rem;
    }

    .config-panel,
    .code-panel {
        padding: 0.75rem;
    }

    .gap-inputs {
        grid-template-columns: 1fr;
    }
}