* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
    font-family: system-ui, -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
}

body {
    background: radial-gradient(circle at top, #111827 0, #020617 45%, #020617 100%);
    color: #e5ecff;
}

/* --- Chat flotante de IA --- */
.ai-chat-toggle {
    position: fixed;
    right: 16px;
    bottom: 16px;
    background: #0f172a;
    color: #e5e7eb;
    border-radius: 999px;
    padding: 8px 14px;
    font-size: 13px;
    cursor: pointer;
    box-shadow: 0 4px 10px rgba(15, 23, 42, 0.6);
    z-index: 1000;
}

.ai-chat-panel {
    position: fixed;
    right: 16px;
    bottom: 64px;
    width: 320px;
    max-height: 420px;
    background: #020617;
    border: 1px solid #1e293b;
    border-radius: 10px;
    display: none;
    flex-direction: column;
    box-shadow: 0 8px 24px rgba(15, 23, 42, 0.9);
    z-index: 1000;
}

.ai-chat-panel.open {
    display: flex;
}

.ai-chat-header {
    padding: 8px 10px;
    border-bottom: 1px solid #1e293b;
    display: flex;
    justify-content: space-between;
    align-items: center;
    font-size: 13px;
    color: #e5e7eb;
}

.ai-chat-close {
    background: transparent;
    border: none;
    color: #9ca3af;
    font-size: 16px;
    cursor: pointer;
}

.ai-chat-messages {
    flex: 1;
    padding: 8px;
    overflow-y: auto;
    font-size: 12px;
}

.ai-chat-message {
    margin-bottom: 6px;
    padding: 6px 8px;
    border-radius: 6px;
    max-width: 90%;
}

.ai-chat-message.from-user {
    background: #1d4ed8;
    color: #e5e7eb;
    margin-left: auto;
}

.ai-chat-message.from-ai {
    background: #020617;
    border: 1px solid #1e293b;
    color: #e5e7eb;
}

.ai-chat-form {
    display: flex;
    border-top: 1px solid #1e293b;
}

.ai-chat-form input {
    flex: 1;
    border: none;
    padding: 6px 8px;
    font-size: 12px;
    background: #020617;
    color: #e5e7eb;
}

.ai-chat-form button {
    border: none;
    background: #22c55e;
    color: #022c22;
    font-size: 12px;
    padding: 0 10px;
    cursor: pointer;
}


.topbar {
    background: rgba(15, 23, 42, 0.85);
    backdrop-filter: blur(14px);
    padding: 14px 24px;
    border-bottom: 1px solid rgba(55, 65, 81, 0.6);
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.topbar h1 {
    font-size: 20px;
}

.badge {
    padding: 4px 10px;
    border-radius: 999px;
    font-size: 11px;
    background: linear-gradient(90deg, #22c55e, #22d3ee);
    color: #020617;
    font-weight: 600;
}

.layout {
    display: grid;
    grid-template-columns: 280px minmax(0, 1.4fr) 320px;
    gap: 14px;
    padding: 16px;
    height: calc(100vh - 60px);
}

.left-panel,
.right-panel,
.canvas-panel {
    background: radial-gradient(circle at top left, #111827 0, #020617 55%);
    border-radius: 18px;
    padding: 14px 14px 12px;
    border: 1px solid rgba(31, 41, 55, 0.9);
    display: flex;
    flex-direction: column;
    gap: 12px;
    box-shadow: 0 18px 45px rgba(15, 23, 42, 0.85);
}

.left-panel h2,
.right-panel h2 {
    font-size: 13px;
    margin-bottom: 2px;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    color: #9ca3af;
}

.section-label {
    font-size: 11px;
    text-transform: uppercase;
    letter-spacing: 0.16em;
    color: #6b7280;
}

.tool-group {
    display: flex;
    gap: 6px;
    flex-wrap: wrap;
}

.tool-btn {
    flex: 1;
    min-width: 72px;
    border-radius: 999px;
    border: 1px solid rgba(55, 65, 81, 0.8);
    background: radial-gradient(circle at top, #020617 0, #020617 60%, #020617 100%);
    color: #e5ecff;
    padding: 7px 10px;
    font-size: 11px;
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    transition: background 0.15s ease, border-color 0.15s ease, transform 0.08s ease;
}

.tool-btn::before {
    content: '';
    width: 8px;
    height: 8px;
    border-radius: 999px;
    background: radial-gradient(circle, #60a5fa 0, #1d4ed8 60%, #020617 100%);
}

.tool-btn[data-tool="ap"]::before {
    background: radial-gradient(circle, #6ee7b7 0, #16a34a 60%, #022c22 100%);
}

.tool-btn[data-tool="select"]::before {
    background: radial-gradient(circle, #facc15 0, #f97316 60%, #451a03 100%);
}

.tool-btn:hover {
    border-color: #60a5fa;
    transform: translateY(-1px);
}

.tool-btn.active {
    background: radial-gradient(circle at top, #1d4ed8 0, #1e3a8a 55%, #020617 100%);
    border-color: #60a5fa;
    box-shadow: 0 0 0 1px rgba(37, 99, 235, 0.6);
}

input[type="file"],
input[type="number"] {
    width: 100%;
    margin-top: 4px;
    margin-bottom: 8px;
    font-size: 12px;
    padding: 5px 8px;
    border-radius: 999px;
    border: 1px solid rgba(55, 65, 81, 0.85);
    background: rgba(15, 23, 42, 0.85);
    color: #e5ecff;
}

button {
    cursor: pointer;
}

.btn-primary {
    width: 100%;
    border-radius: 999px;
    border: 1px solid #22c55e;
    background: radial-gradient(circle at top, #22c55e 0, #16a34a 55%, #052e16 100%);
    color: #ecfdf5;
    padding: 7px 10px;
    font-size: 12px;
    margin-top: 4px;
    transition: filter 0.12s ease, transform 0.08s ease;
}

.btn-primary:hover {
    filter: brightness(1.06);
    transform: translateY(-1px);
}

.btn-secondary {
    width: 100%;
    border-radius: 999px;
    border: 1px solid rgba(59, 130, 246, 0.9);
    background: radial-gradient(circle at top, #1e40af 0, #1d4ed8 55%, #020617 100%);
    color: #e5ecff;
    padding: 7px 10px;
    font-size: 12px;
    margin-top: 4px;
    transition: filter 0.12s ease, transform 0.08s ease;
}

.btn-secondary:hover {
    filter: brightness(1.06);
    transform: translateY(-1px);
}

/* Botón específico para limpiar elementos, a juego con las herramientas */
#clear-elements {
    width: 100%;
    border-radius: 999px;
    border: 1px solid rgba(248, 113, 113, 0.9);
    background: radial-gradient(circle at top, #991b1b 0, #b91c1c 50%, #450a0a 100%);
    color: #fee2e2;
    padding: 7px 10px;
    font-size: 12px;
    margin: 6px 0 4px;
    transition: filter 0.12s ease, transform 0.08s ease;
}

#clear-elements:hover {
    filter: brightness(1.08);
    transform: translateY(-1px);
}

.canvas-panel {
    position: relative;
}

.canvas-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    font-size: 12px;
    color: #9ca3af;
}

.canvas-header label {
    display: inline-flex;
    align-items: center;
    gap: 6px;
}

.canvas-header input[type="checkbox"] {
    accent-color: #22c55e;
}

.canvas-wrapper {
    flex: 1;
    position: relative;
    margin-top: 10px;
    border-radius: 16px;
    overflow: hidden;
    background: radial-gradient(circle at top, #020617 0, #020617 60%, #000000 100%);
    border: 1px solid rgba(31, 41, 55, 0.9);
}

/* reglas simples en bordes del lienzo */
.canvas-wrapper::before,
.canvas-wrapper::after {
    content: '';
    position: absolute;
    pointer-events: none;
}

.canvas-wrapper::before {
    /* regla horizontal superior */
    left: 0;
    top: 0;
    right: 0;
    height: 16px;
    background: linear-gradient(to right, rgba(15,23,42,0.95), transparent 60%);
    border-bottom: 1px solid rgba(55,65,81,0.7);
}

.canvas-wrapper::after {
    /* regla vertical izquierda */
    top: 0;
    left: 0;
    bottom: 0;
    width: 18px;
    background: linear-gradient(to bottom, rgba(15,23,42,0.95), transparent 60%);
    border-right: 1px solid rgba(55,65,81,0.7);
}

#floorplan-canvas,
#heatmap-canvas {
    position: absolute;
    left: 0;
    top: 0;
    /* no forzamos width/height por CSS para que coincidan con el tamaño interno */
}

#heatmap-canvas {
    pointer-events: none;
}

.materials-list {
    font-size: 12px;
    max-height: 160px;
    overflow: auto;
    padding: 6px 8px;
    border-radius: 10px;
    background: radial-gradient(circle at top left, #020617 0, #020617 60%, #020617 100%);
    border: 1px solid rgba(31, 41, 55, 0.95);
}

.report-fields label {
    display: block;
    margin-top: 4px;
}

.report-fields input[type="text"],
.report-fields textarea {
    width: 100%;
    box-sizing: border-box;
}

.material-select {
    width: 100%;
    margin: 4px 0 10px;
    font-size: 12px;
    padding: 4px 8px;
    border-radius: 999px;
    border: 1px solid rgba(55, 65, 81, 0.9);
    background: rgba(15, 23, 42, 0.9);
    color: #e5ecff;
}

.material-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 4px 0;
    border-bottom: 1px dashed rgba(55, 65, 81, 0.5);
}

.material-item:last-child {
    border-bottom: none;
}

.material-name {
    color: #e5e7eb;
}

.material-loss {
    font-size: 11px;
    color: #9ca3af;
}

#properties-panel,
#coverage-summary {
    flex: 1;
    font-size: 12px;
    border-radius: 12px;
    background: radial-gradient(circle at top left, #020617 0, #020617 65%, #020617 100%);
    border: 1px solid rgba(31, 41, 55, 0.95);
    padding: 8px 10px;
    overflow: auto;
}

.property-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 6px;
}

.property-row input,
.property-row select {
    width: 52%;
    font-size: 12px;
    padding: 3px 6px;
    border-radius: 999px;
    border: 1px solid rgba(55, 65, 81, 0.9);
    background: rgba(15, 23, 42, 0.9);
    color: #e5ecff;
}

.coverage-pill {
    padding: 3px 8px;
    border-radius: 999px;
    font-size: 11px;
    display: inline-block;
    margin-bottom: 4px;
}

.coverage-good { background: rgba(34, 197, 94, 0.2); color: #bbf7d0; }
.coverage-ok { background: rgba(250, 204, 21, 0.18); color: #fef9c3; }
.coverage-poor { background: rgba(239, 68, 68, 0.2); color: #fecaca; }
