/* ==========================================================================
   style.css - Estils de l'aplicació dt14-web
   Bessó digital de la placa IoT-02
   Projecte docent - Formació Professional
   ========================================================================== */

/* --------------------------------------------------------------------------
   Reset i base
   -------------------------------------------------------------------------- */
*, *::before, *::after {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

html, body {
    height: 100%;
    overflow: hidden;
    font-family: 'Segoe UI', Arial, sans-serif;
    font-size: 14px;
    color: #e0e0e0;
    background: #1a1a2e;
}

/* --------------------------------------------------------------------------
   Estructura principal de l'aplicació
   -------------------------------------------------------------------------- */
#app {
    display: flex;
    flex-direction: column;
    height: 100vh;
    width: 100vw;
    position: relative;
}

/* --------------------------------------------------------------------------
   Barra d'eines (ToolBar)
   -------------------------------------------------------------------------- */
#toolbar {
    display: flex;
    align-items: center;
    background: #16213e;
    color: #ffffff;
    padding: 0 16px;
    height: 48px;
    flex-shrink: 0;
    box-shadow: 0 2px 4px rgba(0,0,0,0.4);
    z-index: 10;
}

#toolbar .app-title {
    font-size: 18px;
    font-weight: bold;
    letter-spacing: 1px;
    flex-grow: 1;
    color: #90caf9;
}

#btn-settings {
    background: none;
    border: none;
    color: #ffffff;
    font-size: 22px;
    cursor: pointer;
    padding: 6px 10px;
    border-radius: 6px;
    transition: background 0.2s;
}

#btn-settings:hover {
    background: rgba(255, 255, 255, 0.1);
}

/* --------------------------------------------------------------------------
   Panell de connexió MQTT
   -------------------------------------------------------------------------- */
#connection-panel-container {
    flex-shrink: 0;
}

#connection-panel {
    display: flex;
    align-items: center;
    gap: 12px;
    background: #0f3460;
    padding: 6px 16px;
    border-bottom: 1px solid #1a4a7a;
    flex-wrap: wrap;
}

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

.conn-dot {
    width: 12px;
    height: 12px;
    border-radius: 50%;
    display: inline-block;
    transition: background 0.3s;
    box-shadow: 0 0 6px currentColor;
}

.conn-text {
    font-weight: 600;
    font-size: 13px;
}

.conn-info {
    flex-grow: 1;
    font-size: 12px;
    color: #90a4ae;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.conn-sep {
    margin: 0 6px;
}

.conn-btn {
    background: #1565c0;
    color: white;
    border: none;
    padding: 5px 14px;
    border-radius: 4px;
    cursor: pointer;
    font-size: 13px;
    font-weight: 600;
    transition: background 0.2s;
    white-space: nowrap;
}

.conn-btn:hover {
    background: #1976d2;
}

/* --------------------------------------------------------------------------
   Contenidor de la placa (board-container)
   La imatge IoT-02.png fa de fons.
   Tots els components es posicionen en absolute sobre aquest contenidor.
   -------------------------------------------------------------------------- */
#board-container {
    flex-grow: 1;
    position: relative;
    overflow: hidden;
    background: #12122a;
}

#board-image {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    object-fit: contain;  /* Preserva aspect ratio, centra la imatge */
    pointer-events: none; /* La imatge no intercepta els clics */
    user-select: none;
}

/* --------------------------------------------------------------------------
   Component: Botó interactiu
   Rectangle transparent posicionat sobre la imatge
   -------------------------------------------------------------------------- */
.interactive-button {
    position: absolute;
    cursor: pointer;
    border: 2px solid rgba(255, 255, 255, 0.3);
    border-radius: 4px;
    background: rgba(255, 255, 255, 0.05);
    transition: background 0.1s, opacity 0.1s;
    z-index: 20;
}

.interactive-button:hover {
    background: rgba(255, 255, 255, 0.15);
    border-color: rgba(255, 255, 255, 0.6);
}

.interactive-button.pressed {
    background: rgba(255, 255, 255, 0.35);
    opacity: 0.8;
}

/* --------------------------------------------------------------------------
   Component: LED interactiu
   -------------------------------------------------------------------------- */
.interactive-led {
    position: absolute;
    border-radius: 3px;
    transition: filter 0.2s, box-shadow 0.2s;
    z-index: 20;
    pointer-events: none; /* El LED no és clicable */
}

/* --------------------------------------------------------------------------
   Component: Pantalla OLED
   -------------------------------------------------------------------------- */
.interactive-oled {
    position: absolute;
    background: #000000;
    border: 1px solid #00FFFF;
    overflow: hidden;
    z-index: 20;
    pointer-events: none;
}

.oled-text {
    position: absolute;
    color: #00FFFF;
    font-family: 'Courier New', Courier, monospace;
    font-weight: normal;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: clip;
    text-shadow: 0 0 6px #00FFFF, 0 0 10px #00FFFF80;
    line-height: 1.2;
}

/* --------------------------------------------------------------------------
   Component: Sensor circular (base comú per LDR i BME280)
   -------------------------------------------------------------------------- */
.interactive-sensor {
    position: absolute;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    z-index: 20;
    transition: opacity 0.2s;
}

.interactive-sensor:hover {
    opacity: 0.85;
}

.sensor-label {
    color: white;
    font-weight: bold;
    text-align: center;
    line-height: 1.2;
    pointer-events: none;
    font-size: 12px;
    text-shadow: 0 1px 3px rgba(0,0,0,0.8);
}

/* LDR: cercle gris */
.ldr-sensor {
    background: rgba(128, 128, 128, 0.45);
    border: 2px solid rgba(150, 150, 150, 0.7);
}

/* BME280: cercle blau clar */
.bme-sensor {
    background: rgba(64, 128, 160, 0.45);
    border: 2px solid rgba(96, 144, 176, 0.7);
}

/* --------------------------------------------------------------------------
   Display de valors dels sensors (sempre visible)
   -------------------------------------------------------------------------- */
.sensor-value-display {
    position: absolute;
    background: rgba(0, 0, 0, 0.85);
    color: white;
    font-family: 'Courier New', monospace;
    padding: 4px 8px;
    border-radius: 4px;
    border: 1px solid #606060;
    white-space: nowrap;
    pointer-events: none;
    z-index: 30;
    line-height: 1.4;
    font-size: 12px; /* S'escala dinàmicament des de JS */
}

/* --------------------------------------------------------------------------
   Popups dels sensors (LDR i BME280)
   -------------------------------------------------------------------------- */
.sensor-popup {
    position: fixed;  /* fixed per aparèixer per sobre de tot, coordenades de getBoundingClientRect */
    background: #ffffff;
    color: #212121;
    border-radius: 8px;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.4);
    padding: 16px;
    z-index: 100;
    min-width: 260px;
}

.popup-section {
    margin-bottom: 14px;
}

.popup-section:last-child {
    margin-bottom: 0;
}

.popup-title {
    font-size: 13px;
    font-weight: 600;
    margin-bottom: 6px;
    color: #333;
}

.popup-hint {
    font-size: 11px;
    color: #888;
    margin-top: 6px;
    text-align: center;
}

/* Slider personalitzat */
.sensor-popup input[type="range"] {
    width: 100%;
    margin: 0;
    accent-color: #1565c0;
    cursor: pointer;
}

/* --------------------------------------------------------------------------
   Pàgina de configuració (overlay complet)
   -------------------------------------------------------------------------- */
#config-page {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(10, 10, 30, 0.92);
    z-index: 200;
    display: flex;
    align-items: flex-start;
    justify-content: center;
    overflow-y: auto;
    padding: 20px;
}

.config-card {
    background: #1e2a4a;
    border: 1px solid #2a3a60;
    border-radius: 12px;
    padding: 28px;
    width: 100%;
    max-width: 600px;
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.6);
    margin: auto;
}

.config-title {
    font-size: 20px;
    font-weight: bold;
    color: #90caf9;
    margin-bottom: 24px;
    text-align: center;
}

/* Seccions del formulari */
.config-section {
    border: 1px solid #2a3a60;
    border-radius: 8px;
    padding: 16px;
    margin-bottom: 20px;
}

.config-section legend {
    color: #90caf9;
    font-weight: 600;
    font-size: 14px;
    padding: 0 8px;
}

/* Camps del formulari */
.config-field {
    margin-bottom: 14px;
}

.config-field:last-child {
    margin-bottom: 0;
}

.config-field label {
    display: block;
    font-size: 12px;
    color: #b0bec5;
    margin-bottom: 5px;
    font-weight: 500;
}

.config-field input[type="text"],
.config-field input[type="password"],
.config-field input[type="number"] {
    width: 100%;
    background: #0f1a30;
    border: 1px solid #3a4a70;
    border-radius: 5px;
    padding: 8px 10px;
    color: #e0e0e0;
    font-size: 13px;
    transition: border-color 0.2s;
    outline: none;
}

.config-field input:focus {
    border-color: #90caf9;
    box-shadow: 0 0 0 2px rgba(144, 202, 249, 0.2);
}

.config-field small {
    display: block;
    font-size: 11px;
    color: #607d8b;
    margin-top: 4px;
}

/* Camp inline (checkbox) */
.config-inline label {
    display: flex;
    align-items: center;
    gap: 8px;
    cursor: pointer;
    font-size: 13px;
    color: #e0e0e0;
}

.config-inline input[type="checkbox"] {
    width: 16px;
    height: 16px;
    accent-color: #1976d2;
    cursor: pointer;
}

/* Rangs amb dos valors */
.config-range label {
    display: block;
    font-size: 12px;
    color: #b0bec5;
    margin-bottom: 6px;
}

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

.range-inputs span {
    font-size: 12px;
    color: #90a4ae;
    white-space: nowrap;
}

.range-inputs input[type="number"] {
    width: 80px;
    background: #0f1a30;
    border: 1px solid #3a4a70;
    border-radius: 5px;
    padding: 6px 8px;
    color: #e0e0e0;
    font-size: 13px;
    outline: none;
    text-align: center;
}

.range-inputs input[type="number"]:focus {
    border-color: #90caf9;
}

/* Botons d'acció */
.config-actions {
    display: flex;
    justify-content: flex-end;
    gap: 12px;
    margin-top: 8px;
}

.btn-primary {
    background: #1565c0;
    color: white;
    border: none;
    padding: 10px 20px;
    border-radius: 6px;
    cursor: pointer;
    font-size: 14px;
    font-weight: 600;
    transition: background 0.2s;
}

.btn-primary:hover {
    background: #1976d2;
}

.btn-secondary {
    background: #37474f;
    color: #e0e0e0;
    border: none;
    padding: 10px 20px;
    border-radius: 6px;
    cursor: pointer;
    font-size: 14px;
    transition: background 0.2s;
}

.btn-secondary:hover {
    background: #455a64;
}

/* Missatge d'error */
.config-error {
    background: #b71c1c;
    color: white;
    border-radius: 6px;
    padding: 10px 14px;
    margin-top: 12px;
    font-size: 13px;
}
