/* Build Your Garage — Stylesheet
   Designed for cross-browser compatibility (Chrome, Firefox, Safari, Edge, IE11+ with graceful degradation). */

* {
    box-sizing: border-box;
}

html, body {
    margin: 0;
    padding: 0;
    height: 100%;
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Oxygen, Ubuntu, Cantarell, "Helvetica Neue", Arial, sans-serif;
    background: #ecf0f1;
    color: #2c3e50;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

body {
    display: flex;
    flex-direction: column;
    min-height: 100vh;
    overflow: hidden;
}

/* === HEADER === */
.app-header {
    background: linear-gradient(135deg, #2c3e50 0%, #34495e 100%);
    color: #ecf0f1;
    padding: 12px 24px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    box-shadow: 0 2px 6px rgba(0,0,0,0.15);
    flex-shrink: 0;
}

.brand {
    display: flex;
    align-items: center;
    gap: 14px;
}

.brand-logo {
    background: #ecf0f1;
    border-radius: 8px;
    width: 44px;
    height: 44px;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 4px;
}

.brand h1 {
    margin: 0;
    font-size: 20px;
    font-weight: 600;
    letter-spacing: 0.3px;
}

.subtitle {
    margin: 2px 0 0;
    font-size: 12px;
    color: #bdc3c7;
    letter-spacing: 0.5px;
    text-transform: uppercase;
}

.toolbar {
    display: flex;
    gap: 8px;
    align-items: center;
}

.btn {
    background: #ecf0f1;
    color: #2c3e50;
    border: none;
    padding: 8px 16px;
    border-radius: 5px;
    font-size: 14px;
    font-weight: 500;
    cursor: pointer;
    transition: background 0.15s ease, transform 0.05s ease;
    font-family: inherit;
    display: inline-flex;
    align-items: center;
    gap: 6px;
}

.btn:hover {
    background: #ffffff;
}

.btn:active {
    transform: translateY(1px);
}

.btn-primary {
    background: #f39c12;
    color: #fff;
}

.btn-primary:hover {
    background: #e67e22;
}

.btn-secondary {
    background: rgba(255,255,255,0.12);
    color: #ecf0f1;
}

.btn-secondary:hover {
    background: rgba(255,255,255,0.22);
}

.btn-secondary.active {
    background: #e74c3c;
    color: #fff;
}

.btn-icon {
    font-size: 16px;
    line-height: 1;
}

/* === LAYOUT === */
.app-main {
    flex: 1;
    display: grid;
    grid-template-columns: 260px 1fr 280px;
    gap: 0;
    overflow: hidden;
    min-height: 0;
}

.sidebar {
    background: #ffffff;
    overflow-y: auto;
    padding: 16px;
    border-color: #d5dbdb;
    border-style: solid;
    border-width: 0;
}

.sidebar-left {
    border-right-width: 1px;
}

.sidebar-right {
    border-left-width: 1px;
}

.sidebar h2 {
    margin: 0 0 8px;
    font-size: 15px;
    text-transform: uppercase;
    letter-spacing: 0.6px;
    color: #34495e;
    font-weight: 600;
}

.hint {
    margin: 0 0 14px;
    font-size: 12px;
    color: #7f8c8d;
    line-height: 1.4;
}

/* === CATALOG === */
.catalog {
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.catalog-group {
    margin-bottom: 8px;
}

.catalog-group-title {
    font-size: 11px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.8px;
    color: #95a5a6;
    margin: 10px 0 6px;
    padding-bottom: 4px;
    border-bottom: 1px solid #ecf0f1;
}

.catalog-item {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 8px 10px;
    border: 1.5px solid #e0e6e8;
    border-radius: 6px;
    cursor: pointer;
    transition: all 0.15s ease;
    background: #fff;
    user-select: none;
    -webkit-user-select: none;
    -moz-user-select: none;
}

.catalog-item:hover {
    border-color: #f39c12;
    background: #fef9e7;
}

.catalog-item.selected {
    border-color: #f39c12;
    background: #fdebd0;
    box-shadow: 0 0 0 2px rgba(243, 156, 18, 0.25);
}

.catalog-swatch {
    width: 28px;
    height: 28px;
    border-radius: 4px;
    flex-shrink: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    color: #fff;
    font-size: 14px;
    font-weight: 700;
    text-shadow: 0 1px 2px rgba(0,0,0,0.3);
}

.catalog-info {
    flex: 1;
    min-width: 0;
}

.catalog-name {
    font-size: 13px;
    font-weight: 500;
    color: #2c3e50;
    line-height: 1.2;
}

.catalog-meta {
    font-size: 11px;
    color: #95a5a6;
    margin-top: 2px;
}

.catalog-required {
    color: #e74c3c;
    font-weight: 700;
}

/* === WORKSPACE === */
.workspace {
    display: flex;
    flex-direction: column;
    overflow: hidden;
    background: #ecf0f1;
    padding: 12px;
    min-width: 0;
}

.workspace-info {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 6px 12px;
    background: #fff;
    border-radius: 6px;
    margin-bottom: 10px;
    font-size: 13px;
    color: #34495e;
    box-shadow: 0 1px 2px rgba(0,0,0,0.05);
}

.coords {
    font-family: "SF Mono", Consolas, Monaco, monospace;
    color: #7f8c8d;
    font-size: 12px;
}

.canvas-wrapper {
    flex: 1;
    background: #ffffff;
    border-radius: 8px;
    box-shadow: 0 2px 8px rgba(0,0,0,0.08);
    overflow: hidden;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 8px;
    min-height: 0;
}

#garage-canvas {
    max-width: 100%;
    max-height: 100%;
    display: block;
    cursor: crosshair;
    image-rendering: -webkit-optimize-contrast;
    image-rendering: crisp-edges;
}

#garage-canvas.delete-mode {
    cursor: not-allowed;
}

.legend {
    display: flex;
    gap: 16px;
    margin-top: 10px;
    font-size: 12px;
    color: #7f8c8d;
    flex-wrap: wrap;
}

.legend-item {
    display: flex;
    align-items: center;
    gap: 6px;
}

.legend-swatch {
    display: inline-block;
    width: 14px;
    height: 14px;
    border-radius: 3px;
}

/* === REQUIREMENTS === */
.requirements {
    list-style: none;
    padding: 0;
    margin: 0 0 20px;
}

.requirements li {
    padding: 8px 10px;
    border-radius: 5px;
    font-size: 13px;
    line-height: 1.3;
    margin-bottom: 4px;
    background: #f8f9f9;
    border-left: 3px solid #bdc3c7;
    display: flex;
    align-items: flex-start;
    gap: 8px;
}

.requirements li.met {
    background: #eafaf1;
    border-left-color: #27ae60;
    color: #1e8449;
}

.requirements li.missing {
    background: #fdedec;
    border-left-color: #e74c3c;
    color: #c0392b;
}

.req-icon {
    flex-shrink: 0;
    font-weight: 700;
    width: 14px;
    text-align: center;
}

.score-card {
    background: linear-gradient(135deg, #34495e 0%, #2c3e50 100%);
    color: #ecf0f1;
    border-radius: 8px;
    padding: 16px;
    text-align: center;
}

.score-card h3 {
    margin: 0 0 6px;
    font-size: 12px;
    text-transform: uppercase;
    letter-spacing: 1px;
    color: #bdc3c7;
    font-weight: 600;
}

.score-value {
    font-size: 36px;
    font-weight: 700;
    color: #f39c12;
    line-height: 1;
    margin-bottom: 8px;
}

.score-feedback {
    font-size: 12px;
    color: #bdc3c7;
    line-height: 1.4;
}

/* === FOOTER === */
.app-footer {
    background: #2c3e50;
    color: #95a5a6;
    padding: 8px 24px;
    font-size: 12px;
    display: flex;
    justify-content: space-between;
    flex-shrink: 0;
}

kbd {
    background: #34495e;
    color: #ecf0f1;
    padding: 1px 6px;
    border-radius: 3px;
    font-family: "SF Mono", Consolas, monospace;
    font-size: 11px;
    border: 1px solid #1a252f;
}

/* === MODAL === */
.modal {
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.5);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1000;
    padding: 20px;
}

.modal.hidden {
    display: none;
}

.modal-content {
    background: #fff;
    border-radius: 10px;
    padding: 28px;
    max-width: 520px;
    width: 100%;
    box-shadow: 0 10px 40px rgba(0,0,0,0.3);
    max-height: 85vh;
    overflow-y: auto;
}

.modal-content h2 {
    margin: 0 0 16px;
    color: #2c3e50;
}

.modal-content .grade-banner {
    text-align: center;
    padding: 18px;
    border-radius: 8px;
    margin-bottom: 16px;
    color: #fff;
}

.modal-content .grade-banner h3 {
    margin: 0;
    font-size: 32px;
}

.modal-content .grade-banner p {
    margin: 4px 0 0;
    font-size: 14px;
    opacity: 0.95;
}

.modal-content ul {
    padding-left: 20px;
    line-height: 1.6;
    font-size: 14px;
}

.modal-content #modal-close {
    margin-top: 12px;
    width: 100%;
}

.modal-actions {
    display: flex;
    gap: 8px;
    margin-top: 12px;
}

.modal-actions .btn {
    flex: 1;
}

.modal-actions #modal-close {
    margin-top: 0;
    width: auto;
}

.modal-actions .btn-secondary {
    background: #ecf0f1;
    color: #2c3e50;
    border: 1px solid #bdc3c7;
}

.modal-actions .btn-secondary:hover {
    background: #d5dbdb;
}

/* === SHAPE PICKER === */
.shape-modal-content {
    max-width: 680px;
}

.shape-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 12px;
    margin: 16px 0;
}

.shape-card {
    border: 2px solid #e0e6e8;
    border-radius: 8px;
    padding: 14px;
    cursor: pointer;
    transition: all 0.15s ease;
    background: #f8f9f9;
    text-align: center;
    user-select: none;
    -webkit-user-select: none;
}

.shape-card:hover {
    border-color: #f39c12;
    background: #fef9e7;
}

.shape-card.selected {
    border-color: #f39c12;
    background: #fdebd0;
    box-shadow: 0 0 0 3px rgba(243, 156, 18, 0.25);
}

.shape-card canvas {
    display: block;
    margin: 0 auto 8px;
    background: #fff;
    border-radius: 4px;
}

.shape-card-name {
    font-weight: 600;
    color: #2c3e50;
    margin-bottom: 4px;
    font-size: 14px;
}

.shape-card-desc {
    font-size: 12px;
    color: #7f8c8d;
    line-height: 1.3;
}

#shape-confirm:disabled {
    opacity: 0.4;
    cursor: not-allowed;
}

.shape-actions {
    display: flex;
    gap: 10px;
    margin-top: 8px;
}

.shape-actions .btn-secondary {
    background: #ecf0f1;
    color: #2c3e50;
    flex: 0 0 auto;
}

.shape-actions .btn-secondary:hover {
    background: #d5dbdb;
}

#shape-confirm {
    flex: 1;
    padding: 12px;
    font-size: 15px;
}

#shape-confirm:disabled {
    opacity: 0.4;
    cursor: not-allowed;
}

.modal-content {
    position: relative;
}

.modal-close-x {
    position: absolute;
    top: 10px;
    right: 14px;
    background: transparent;
    border: none;
    font-size: 28px;
    line-height: 1;
    cursor: pointer;
    color: #95a5a6;
    padding: 4px 10px;
    border-radius: 4px;
    font-family: inherit;
}

.modal-close-x:hover {
    color: #34495e;
    background: #ecf0f1;
}

/* === PANNELLO CONSIGLI === */
.tips-panel {
    margin-top: 10px;
    background: linear-gradient(135deg, #2c3e50 0%, #34495e 100%);
    color: #ecf0f1;
    border-radius: 8px;
    padding: 10px 14px;
    display: flex;
    align-items: center;
    gap: 10px;
    box-shadow: 0 2px 8px rgba(0,0,0,0.12);
    min-height: 68px;
    position: relative;
}

.tip-card {
    flex: 1;
    display: flex;
    align-items: center;
    gap: 12px;
    min-width: 0;
    transition: opacity 0.3s ease;
}

.tip-card.fading {
    opacity: 0;
}

.tip-swatch {
    width: 44px;
    height: 44px;
    border-radius: 8px;
    flex-shrink: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    color: #fff;
    font-size: 16px;
    font-weight: 700;
    text-shadow: 0 1px 2px rgba(0,0,0,0.4);
    background: #f39c12;
}

.tip-body {
    flex: 1;
    min-width: 0;
}

.tip-title {
    font-size: 14px;
    font-weight: 700;
    color: #f39c12;
    margin-bottom: 3px;
    line-height: 1.2;
}

.tip-text {
    font-size: 13px;
    color: #ecf0f1;
    line-height: 1.4;
}

.tips-nav-btn {
    background: rgba(255,255,255,0.12);
    border: none;
    color: #ecf0f1;
    width: 32px;
    height: 32px;
    border-radius: 50%;
    cursor: pointer;
    font-size: 18px;
    line-height: 1;
    font-family: inherit;
    flex-shrink: 0;
    transition: background 0.15s ease;
}

.tips-nav-btn:hover {
    background: rgba(255,255,255,0.25);
}

.tips-counter {
    position: absolute;
    bottom: 4px;
    right: 12px;
    font-size: 10px;
    color: #95a5a6;
    font-family: "SF Mono", Consolas, monospace;
}

@media (max-width: 700px) {
    .tip-text { font-size: 12px; }
    .tip-title { font-size: 13px; }
    .tip-swatch { width: 36px; height: 36px; font-size: 14px; }
}

/* === RESPONSIVE === */
@media (max-width: 1100px) {
    .app-main {
        grid-template-columns: 220px 1fr 240px;
    }
}

@media (max-width: 900px) {
    .app-main {
        grid-template-columns: 1fr;
        grid-template-rows: auto 1fr auto;
        overflow-y: auto;
    }
    body {
        overflow: auto;
    }
    .sidebar {
        max-height: 280px;
        border-width: 0 0 1px 0;
    }
    .sidebar-right {
        border-width: 1px 0 0 0;
    }
    .app-header {
        flex-direction: column;
        gap: 10px;
    }
}
