/* ============================================
   Tile Layout Planner — Refined Workshop Theme
   ============================================ */

:root {
    /* Surface */
    --bg: #F5F2EE;
    --surface: #FFFFFF;
    --surface-alt: #FAF8F6;
    --surface-raised: #FFFFFF;

    /* Borders */
    --border: #E7E3DE;
    --border-strong: #D4CFC8;
    --border-focus: #B45309;

    /* Text */
    --text-1: #1C1917;
    --text-2: #57534E;
    --text-3: #A8A29E;

    /* Accent — warm amber/copper */
    --accent: #B45309;
    --accent-hover: #92400E;
    --accent-subtle: #FEF3C7;
    --accent-text: #FFFFFF;

    /* Semantic */
    --success: #166534;
    --success-bg: #F0FDF4;
    --success-border: #BBF7D0;
    --warning: #854D0E;
    --warning-bg: #FEFCE8;
    --warning-border: #FEF08A;
    --error: #991B1B;
    --error-bg: #FEF2F2;
    --error-border: #FECACA;
    --info-bg: #EFF6FF;
    --info-border: #BFDBFE;

    /* Tiles */
    --tile-full: #DBEAFE;
    --tile-full-stroke: #93C5FD;
    --tile-cut: #FEF3C7;
    --tile-cut-stroke: #FCD34D;

    /* Layout */
    --header-bg: #1C1917;
    --header-text: #FAF8F6;
    --radius: 10px;
    --radius-sm: 6px;
    --shadow-sm: 0 1px 3px rgba(28, 25, 23, 0.06), 0 1px 2px rgba(28, 25, 23, 0.04);
    --shadow-md: 0 4px 12px rgba(28, 25, 23, 0.08), 0 1px 3px rgba(28, 25, 23, 0.06);
    --transition: 150ms ease;
}


/* ---- Reset & Base ---- */

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

body {
    font-family: 'Outfit', system-ui, sans-serif;
    font-weight: 400;
    line-height: 1.6;
    color: var(--text-1);
    background-color: var(--bg);
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}


/* ---- Header ---- */

.app-header {
    background: var(--header-bg);
    color: var(--header-text);
    padding: 0 24px;
    border-bottom: 3px solid var(--accent);
}

.header-inner {
    max-width: 1440px;
    margin: 0 auto;
    padding: 16px 0;
}

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

.header-icon {
    flex-shrink: 0;
    opacity: 0.7;
    stroke: var(--accent);
    opacity: 1;
}

.header-brand h1 {
    font-size: 1.3rem;
    font-weight: 700;
    letter-spacing: -0.02em;
    line-height: 1.2;
    color: var(--header-text);
}

.header-tagline {
    font-size: 0.8rem;
    font-weight: 300;
    color: var(--text-3);
    letter-spacing: 0.01em;
    margin-top: 1px;
}


/* ---- Main Layout ---- */

.app-main {
    max-width: 1440px;
    margin: 0 auto;
    padding: 24px;
}

.panel-grid {
    display: grid;
    grid-template-columns: minmax(0, 420px) 1fr;
    gap: 24px;
    align-items: start;
}

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

.panel-inputs {
    display: flex;
    flex-direction: column;
    gap: 16px;
    position: sticky;
    top: 24px;
    max-height: calc(100vh - 48px);
    overflow-y: auto;
    overflow-x: hidden;
    min-width: 0;
    scrollbar-width: thin;
    scrollbar-color: var(--border-strong) transparent;
}

.panel-inputs::-webkit-scrollbar {
    width: 5px;
}

.panel-inputs::-webkit-scrollbar-track {
    background: transparent;
}

.panel-inputs::-webkit-scrollbar-thumb {
    background: var(--border-strong);
    border-radius: 10px;
}

@media (max-width: 900px) {
    .panel-inputs {
        position: static;
        max-height: none;
        overflow-y: visible;
    }
}


/* ---- Cards ---- */

.card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow-sm);
    overflow: visible;
    transition: box-shadow var(--transition);
    min-width: 0;
}

.card:hover {
    box-shadow: var(--shadow-md);
}

.card-header {
    padding: 14px 20px 0;
}

.card-header h2 {
    font-size: 0.85rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    color: var(--text-2);
    border: none;
    margin: 0;
    padding: 0;
}

.card-body {
    padding: 16px 20px 20px;
}

/* ---- Form Fields ---- */

.input-grid {
    display: grid;
    gap: 12px;
}

.input-grid.cols-2 {
    grid-template-columns: repeat(2, minmax(0, 1fr));
}

.input-grid.cols-3 {
    grid-template-columns: repeat(3, minmax(0, 1fr));
}

.input-grid.cols-swap {
    grid-template-columns: minmax(0, 1fr) auto minmax(0, 1fr);
    align-items: end;
}

@media (max-width: 380px) {
    .input-grid.cols-3 {
        grid-template-columns: 1fr;
    }

    .input-grid.cols-swap {
        grid-template-columns: 1fr;
    }

    .input-grid.cols-swap .btn-swap {
        justify-self: center;
        transform: rotate(90deg);
    }
}

/* Swap Button */
.btn-swap {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 34px;
    height: 34px;
    margin-bottom: 3px;
    padding: 0;
    border: 1.5px solid var(--border);
    border-radius: var(--radius-sm);
    background: var(--surface);
    color: var(--text-3);
    cursor: pointer;
    transition: all var(--transition);
    flex-shrink: 0;
}

.btn-swap:hover {
    border-color: var(--accent);
    color: var(--accent);
    background: var(--accent-subtle);
}

.btn-swap:active {
    transform: scale(0.9) rotate(180deg);
    transition: transform 0.2s ease;
}

.field label {
    display: block;
    font-size: 0.78rem;
    font-weight: 600;
    color: var(--text-2);
    margin-bottom: 5px;
    text-transform: uppercase;
    letter-spacing: 0.04em;
}

.input-with-unit {
    position: relative;
    display: flex;
}

.input-with-unit input {
    flex: 1;
    padding-right: 38px;
}

.unit {
    position: absolute;
    right: 12px;
    top: 50%;
    transform: translateY(-50%);
    font-family: 'Space Mono', monospace;
    font-size: 0.75rem;
    color: var(--text-3);
    pointer-events: none;
    font-weight: 400;
}

/* Currency unit on the left side */
.input-with-unit .unit-left {
    right: auto;
    left: 12px;
}

.input-with-unit .unit-left ~ input,
.input-with-unit:has(.unit-left) input {
    padding-left: 28px;
    padding-right: 12px;
}

input[type="number"],
input[type="text"],
input[type="url"],
textarea,
select {
    width: 100%;
    padding: 10px 12px;
    border: 1.5px solid var(--border);
    border-radius: var(--radius-sm);
    font-family: 'Space Mono', monospace;
    font-size: 0.85rem;
    color: var(--text-1);
    background: var(--surface);
    transition: border-color var(--transition), box-shadow var(--transition);
    line-height: 1.4;
}

input[type="number"]:focus,
input[type="text"]:focus,
input[type="url"]:focus,
textarea:focus,
select:focus {
    outline: none;
    border-color: var(--accent);
    box-shadow: 0 0 0 3px rgba(180, 83, 9, 0.12);
}

input[type="number"]::placeholder,
input[type="url"]::placeholder,
textarea::placeholder {
    color: var(--text-3);
    font-family: 'Outfit', sans-serif;
    font-weight: 400;
}

textarea {
    min-height: 80px;
    resize: vertical;
}

/* Custom Select */
.select-wrapper {
    position: relative;
}

.select-wrapper select {
    appearance: none;
    padding-right: 36px;
    cursor: pointer;
    font-family: 'Outfit', sans-serif;
    font-weight: 500;
    font-size: 0.85rem;
}

.select-wrapper::after {
    content: '';
    position: absolute;
    right: 13px;
    top: 50%;
    transform: translateY(-50%);
    width: 0;
    height: 0;
    border-left: 5px solid transparent;
    border-right: 5px solid transparent;
    border-top: 5px solid var(--text-3);
    pointer-events: none;
}

/* Custom Checkbox */
.checkbox-field {
    display: flex;
    align-items: center;
    gap: 10px;
    cursor: pointer;
    margin-top: 16px;
    padding: 10px 12px;
    border-radius: var(--radius-sm);
    background: var(--surface-alt);
    border: 1px solid var(--border);
    transition: background var(--transition);
    font-weight: 400;
}

.checkbox-field:hover {
    background: var(--accent-subtle);
}

.checkbox-field input[type="checkbox"] {
    position: absolute;
    opacity: 0;
    width: 0;
    height: 0;
}

.checkmark {
    width: 18px;
    height: 18px;
    border: 2px solid var(--border-strong);
    border-radius: 4px;
    flex-shrink: 0;
    position: relative;
    transition: all var(--transition);
    background: var(--surface);
}

.checkbox-field input[type="checkbox"]:checked ~ .checkmark {
    background: var(--accent);
    border-color: var(--accent);
}

.checkbox-field input[type="checkbox"]:checked ~ .checkmark::after {
    content: '';
    position: absolute;
    left: 5px;
    top: 1px;
    width: 5px;
    height: 10px;
    border: solid white;
    border-width: 0 2px 2px 0;
    transform: rotate(45deg);
}

.checkbox-field input[type="checkbox"]:focus ~ .checkmark {
    box-shadow: 0 0 0 3px rgba(180, 83, 9, 0.12);
}

.checkbox-text {
    font-size: 0.85rem;
    color: var(--text-2);
    user-select: none;
}


/* ---- Import Trigger Button ---- */

.btn-import-trigger {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    width: 100%;
    padding: 12px 16px;
    border: 1.5px dashed var(--border-strong);
    border-radius: var(--radius);
    background: var(--surface-alt);
    color: var(--text-2);
    font-family: 'Outfit', sans-serif;
    font-size: 0.85rem;
    font-weight: 500;
    cursor: pointer;
    transition: all var(--transition);
}

.btn-import-trigger:hover {
    border-color: var(--accent);
    color: var(--accent);
    background: var(--accent-subtle);
}

.btn-import-trigger:active {
    transform: scale(0.98);
}


/* ---- Modal ---- */

.modal {
    border: none;
    border-radius: var(--radius);
    padding: 0;
    max-width: 520px;
    width: calc(100% - 32px);
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.3), 0 0 0 1px rgba(0, 0, 0, 0.05);
    animation: modalIn 0.2s ease-out;
    overflow: visible;
}

.modal::backdrop {
    background: rgba(28, 25, 23, 0.5);
    backdrop-filter: blur(4px);
    -webkit-backdrop-filter: blur(4px);
    animation: fadeIn 0.15s ease-out;
}

@keyframes modalIn {
    from {
        opacity: 0;
        transform: translateY(12px) scale(0.97);
    }
    to {
        opacity: 1;
        transform: translateY(0) scale(1);
    }
}

.modal-content {
    display: flex;
    flex-direction: column;
    max-height: calc(100vh - 80px);
}

.modal-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 20px 24px 0;
    flex-shrink: 0;
}

.modal-header h2 {
    font-size: 1rem;
    font-weight: 700;
    color: var(--text-1);
    letter-spacing: -0.01em;
    margin: 0;
    padding: 0;
    border: none;
}

.btn-modal-close {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 32px;
    height: 32px;
    padding: 0;
    border: none;
    border-radius: var(--radius-sm);
    background: transparent;
    color: var(--text-3);
    cursor: pointer;
    transition: all var(--transition);
}

.btn-modal-close:hover {
    background: var(--bg);
    color: var(--text-1);
}

.modal-body {
    padding: 16px 24px 24px;
    overflow-y: auto;
}


/* ---- Import Section ---- */

.import-instructions {
    font-size: 0.82rem;
    color: var(--text-3);
    margin-bottom: 14px;
    line-height: 1.5;
}

.import-controls {
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.import-divider {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 4px 0;
}

.import-divider::before,
.import-divider::after {
    content: '';
    flex: 1;
    height: 1px;
    background: var(--border);
}

.import-divider span {
    font-size: 0.75rem;
    color: var(--text-3);
    text-transform: uppercase;
    letter-spacing: 0.05em;
    font-weight: 500;
    white-space: nowrap;
}

.import-buttons {
    display: flex;
    gap: 8px;
}

.import-status {
    min-height: 0;
    padding: 0;
    border-radius: var(--radius-sm);
    font-size: 0.82rem;
    font-weight: 500;
    transition: all 0.2s ease;
}

.import-status:not(:empty) {
    min-height: 36px;
    padding: 8px 12px;
    display: flex;
    align-items: center;
}

.import-status.success {
    background: var(--success-bg);
    color: var(--success);
    border: 1px solid var(--success-border);
}

.import-status.error {
    background: var(--error-bg);
    color: var(--error);
    border: 1px solid var(--error-border);
}

.import-status.loading {
    background: var(--info-bg);
    color: var(--text-2);
    border: 1px solid var(--info-border);
}

.import-status.loading::before {
    content: '';
    display: inline-block;
    width: 14px;
    height: 14px;
    border: 2px solid var(--border);
    border-top-color: var(--accent);
    border-radius: 50%;
    animation: spin 0.6s linear infinite;
    margin-right: 8px;
    flex-shrink: 0;
}

@keyframes spin {
    to { transform: rotate(360deg); }
}

.tile-info-display {
    background: var(--success-bg);
    padding: 14px 16px;
    margin-top: 14px;
    border-radius: var(--radius-sm);
    border: 1px solid var(--success-border);
    display: none;
    animation: fadeIn 0.25s ease-out;
}

.tile-info-display.visible {
    display: block;
}

.tile-info-display h4 {
    margin: 0 0 8px 0;
    color: var(--success);
    font-size: 0.82rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.04em;
}

.tile-info-display p {
    margin: 4px 0;
    font-size: 0.85rem;
    color: var(--text-2);
}

.tile-info-display strong {
    color: var(--text-1);
    font-weight: 600;
}


/* ---- Buttons ---- */

.btn-primary,
.btn-accent,
.btn-ghost,
.btn-secondary {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    padding: 10px 20px;
    border: none;
    border-radius: var(--radius-sm);
    font-family: 'Outfit', sans-serif;
    font-size: 0.88rem;
    font-weight: 600;
    cursor: pointer;
    transition: all var(--transition);
    line-height: 1.2;
}

.btn-sm {
    padding: 8px 16px;
    font-size: 0.82rem;
}

.btn-primary {
    background: var(--text-1);
    color: var(--surface);
}

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

.btn-primary:active {
    transform: scale(0.97);
}

.btn-accent {
    background: var(--accent);
    color: var(--accent-text);
}

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

.btn-accent:active {
    transform: scale(0.97);
}

.btn-ghost {
    background: transparent;
    color: var(--text-2);
    border: 1.5px solid var(--border);
}

.btn-ghost:hover {
    background: var(--surface-alt);
    border-color: var(--border-strong);
    color: var(--text-1);
}

.btn-ghost:active {
    transform: scale(0.97);
}

.btn-secondary {
    background: var(--surface-alt);
    color: var(--text-2);
    border: 1.5px solid var(--border);
}

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


/* ---- Action Bar ---- */

.action-bar {
    display: flex;
    gap: 10px;
}

.btn-generate {
    flex: 1;
    padding: 14px 24px;
    font-size: 0.95rem;
    border-radius: var(--radius);
    box-shadow: 0 2px 8px rgba(180, 83, 9, 0.25);
}

.btn-generate:hover {
    box-shadow: 0 4px 16px rgba(180, 83, 9, 0.3);
    transform: translateY(-1px);
}

.btn-generate:active {
    transform: translateY(0) scale(0.98);
}

.action-bar .btn-ghost {
    white-space: nowrap;
}


/* ---- Results / Output Panel ---- */

.panel-output {
    min-width: 0;
    overflow: hidden;
}

.results-section {
    min-height: 200px;
}


/* ---- Summary ---- */

.summary {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 20px 24px;
    margin-bottom: 20px;
    box-shadow: var(--shadow-sm);
    animation: fadeIn 0.3s ease-out;
}

.summary h3 {
    font-size: 0.85rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    color: var(--text-2);
    margin-bottom: 12px;
    padding-bottom: 10px;
    border-bottom: 1px solid var(--border);
}

.summary p {
    margin: 6px 0;
    font-size: 0.9rem;
    color: var(--text-2);
    line-height: 1.6;
}

.summary p strong {
    color: var(--text-1);
    font-weight: 600;
    margin-right: 4px;
}

.summary-cost {
    margin-top: 12px;
    padding: 12px 16px;
    background: var(--accent-subtle);
    border-radius: var(--radius-sm);
    border: 1px solid #FCD34D;
}

.summary-cost p strong {
    color: var(--accent-hover);
}

.summary-cost .cost-breakdown {
    font-size: 0.82rem;
    color: var(--text-3);
    margin-top: 2px;
}


/* ---- Pattern Info ---- */

.pattern-info {
    background: var(--success-bg);
    padding: 10px 16px;
    border-radius: var(--radius-sm);
    margin-bottom: 16px;
    border: 1px solid var(--success-border);
    font-size: 0.85rem;
    color: var(--success);
    font-weight: 500;
}


/* ---- Wall Detail ---- */

.wall-detail {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 24px;
    margin-bottom: 20px;
    box-shadow: var(--shadow-sm);
    animation: slideUp 0.35s ease-out both;
}

.wall-detail:nth-child(3) { animation-delay: 0.06s; }
.wall-detail:nth-child(4) { animation-delay: 0.12s; }
.wall-detail:nth-child(5) { animation-delay: 0.18s; }

.wall-detail:last-child {
    border-bottom: 1px solid var(--border);
}

.wall-detail h3 {
    font-size: 1.05rem;
    font-weight: 700;
    color: var(--text-1);
    margin-bottom: 12px;
    letter-spacing: -0.01em;
}


/* ---- Wall Info ---- */

.wall-info {
    background: var(--info-bg);
    padding: 12px 16px;
    border-radius: var(--radius-sm);
    margin-bottom: 16px;
    border: 1px solid var(--info-border);
}

.wall-info p {
    margin: 3px 0;
    font-size: 0.85rem;
    color: var(--text-2);
}

.wall-info p strong {
    color: var(--text-1);
    font-weight: 600;
}


/* ---- Tile Grid (SVG Container) ---- */

.tile-grid {
    margin: 16px 0;
    padding: 24px;
    background: var(--surface-alt);
    border-radius: var(--radius);
    border: 1px solid var(--border);
    overflow-x: auto;
    background-image: radial-gradient(circle, var(--border) 0.6px, transparent 0.6px);
    background-size: 16px 16px;
}

.tile-grid svg {
    max-width: 100%;
    height: auto;
    display: block;
    margin: 0 auto;
}


/* ---- SVG Tile Styles ---- */

.tile {
    stroke: var(--border-strong);
    stroke-width: 0.5;
    transition: opacity 0.15s ease;
}

.tile-full {
    fill: var(--tile-full);
    stroke: var(--tile-full-stroke);
}

.tile-cut {
    fill: var(--tile-cut);
    stroke: var(--tile-cut-stroke);
}

.tile-edge-cut {
    fill: #FECACA;
}


/* ---- Cut Tiles List ---- */

.cuts {
    background: var(--warning-bg);
    padding: 12px 16px;
    border-radius: var(--radius-sm);
    margin: 12px 0;
    border: 1px solid var(--warning-border);
    font-size: 0.85rem;
}

.cuts strong {
    color: var(--warning);
    font-size: 0.82rem;
    text-transform: uppercase;
    letter-spacing: 0.03em;
}

.cuts ul {
    margin: 8px 0 0 18px;
    color: var(--text-2);
}

.cuts li {
    margin-bottom: 3px;
    line-height: 1.5;
}

.corner-pair {
    color: var(--accent);
    font-weight: 700;
    font-size: 0.82rem;
}


/* ---- Error ---- */

.error {
    background: var(--error-bg);
    color: var(--error);
    padding: 14px 18px;
    border-radius: var(--radius-sm);
    border: 1px solid var(--error-border);
    font-weight: 500;
    font-size: 0.9rem;
}


/* ---- Animations ---- */

@keyframes fadeIn {
    from { opacity: 0; }
    to   { opacity: 1; }
}

@keyframes slideUp {
    from {
        opacity: 0;
        transform: translateY(12px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}


/* ---- Responsive ---- */

@media (max-width: 480px) {
    .app-main {
        padding: 12px;
    }

    .input-grid.cols-3,
    .input-grid.cols-2 {
        grid-template-columns: 1fr;
    }

    .input-grid.cols-swap {
        grid-template-columns: 1fr;
    }

    .input-grid.cols-swap .btn-swap {
        justify-self: center;
        transform: rotate(90deg);
    }

    .action-bar {
        flex-direction: column;
    }

    .btn-generate {
        width: 100%;
    }

    .wall-detail {
        padding: 16px;
    }

    .header-brand h1 {
        font-size: 1.1rem;
    }

    .card-body {
        padding: 14px 14px 16px;
    }

    .card-header {
        padding: 12px 14px 0;
    }
}
