/* ------------------------------
   THEME VARIABLES
------------------------------ */
:root {
    --bg: #f3f4f6;
    --card: #ffffff;
    --text: #1f2937;
    --accent: #2563eb;
    --accent-hov: #1d4ed8;
}

:root.dark {
    --bg: oklch(20.768% 0.03985 265.767);
    --card: #1e293b;
    --text: #e2e8f0;
    --accent: #38bdf8;
    --accent-hov: #0ea5e9;
}

/* ------------------------------
   BASE
------------------------------ */
* { box-sizing:border-box; }

body {
    background: var(--bg);
    color: var(--text);
    font-family: Inter, Arial, sans-serif;
    margin:0;
    padding:0;
    transition: 0.3s background, 0.3s color;
}

/* ------------------------------
   HEADER
------------------------------ */
header {
    background: var(--card);
    padding: 15px 20px;
    display: flex;
    justify-content: space-between;
    align-items:center;
    box-shadow:0 2px 10px rgba(0,0,0,0.1);
    position:sticky;
    top:0;
    z-index:10;
}

header h1 {
    margin:0;
    font-size:22px;
    font-weight:700;
}

.header-actions {
    display:flex;
    align-items:center;
    gap:15px;
}

#monitor-btn {
    background: var(--accent);
    padding: 8px 14px;
    border-radius: 6px;
    color:white;
    text-decoration:none;
    font-size:14px;
    font-weight:500;
    transition:0.2s;
}
#monitor-btn:hover { background: var(--accent-hov); }

#dark-toggle {
    font-size:20px;
    cursor:pointer;
    user-select:none;
}

/* ------------------------------
   GRID LAYOUT
------------------------------ */
.grid {
    display:grid;
    gap:20px;
    padding:20px;
}

@media (min-width:600px) {
    .grid { grid-template-columns: repeat(2,1fr); }
}

@media (min-width:1024px) {
    .grid { grid-template-columns: repeat(3,1fr); }
}

/* ------------------------------
   BOUTON AJOUT
------------------------------ */
.add-card {
    margin:20px;
    background:var(--accent);
    color:white;
    padding:12px 18px;
    font-size:16px;
    border:none;
    border-radius:8px;
    cursor:pointer;
    font-weight:600;
    transition:0.2s;
}
.add-card:hover {
    background:var(--accent-hov);
    transform:scale(1.03);
}

/* ------------------------------
   PANEL / CARTE INTERRUPTEUR
------------------------------ */
.panel {
    position:relative;
    background: var(--card);
    padding:20px;
    border-radius:14px;
    box-shadow:0 3px 12px rgba(0,0,0,0.08);
    transition:0.2s transform, 0.2s box-shadow, 0.2s background;
    display:flex;
    flex-direction:column;
    align-items:flex-start;
    gap:10px;
}
.panel:hover {
    transform:translateY(-4px);
    box-shadow:0 6px 18px rgba(0,0,0,0.12);
}
.panel.removing {
    opacity:0;
    transform:scale(0.9);
}

/* infos */
.label {
    width:100%;
}
.label p {
    margin:0;
    font-size:14px;
    color:var(--text);
}

/* ------------------------------
   BOUTON SUPPRESSION
------------------------------ */
.delete-btn {
    position:absolute;
    top:8px;
    right:8px;
    background:transparent;
    border:none;
    font-size:20px;
    cursor:pointer;
    color:var(--text);
}

/* ------------------------------
   SWITCH ON / OFF
------------------------------ */
.switch {
    --w: 90px;
    --h: 46px;
    --pad: 5px;
    --knob: 40px;

    width: var(--w);
    height: var(--h);
    border-radius: 14px;
    background: linear-gradient(180deg,#cbd5e1,#dce6f5);
    border: none;
    cursor: pointer;
    padding: var(--pad);
    position: relative;
    transition: background 0.25s ease;
    display: flex;
    align-items: center;
}

.switch.on {
    background: linear-gradient(180deg,#ffd166,#ffc75a);
}

.knob {
    width: var(--knob);
    height: calc(var(--h) - (var(--pad) * 2));
    border-radius: 10px;
    background: var(--card);
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 700;
    font-size: 12px;
    box-shadow: 0 4px 10px rgba(0,0,0,0.2);
    transition: transform 0.25s cubic-bezier(.25,.8,.25,1), background 0.2s;
    position: absolute;
    left: var(--pad);
    top: var(--pad);
}

.switch.on .knob {
    transform: translateX(calc(var(--w) - (var(--pad)*2) - var(--knob)));
}

.knob .state {
    letter-spacing:0.6px;
}

/* ------------------------------
   COLOR PICKER
------------------------------ */
.color-picker-btn {
    width:40px;
    height:20px;
    border-radius:6px;
    cursor:pointer;
    background:#ccc;
}

.color-picker {
    width:40px;
    height:20px;
    opacity:0;
    position:absolute;
    margin-top:-20px;
    cursor:pointer;
}

/* ------------------------------
   MODAL
------------------------------ */
.modal {
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.55);
    display:flex;
    align-items:center;
    justify-content:center;
    z-index:999;
    transition:0.25s ease;
}

.modal.hidden {
    opacity:0;
    pointer-events:none;
}

.modal-content {
    background: var(--card);
    padding:25px;
    border-radius:12px;
    width:320px;
    display:flex;
    flex-direction:column;
    gap:12px;
    box-shadow:0 6px 20px rgba(0,0,0,0.25);
}

.modal-content label {
    font-size:14px;
}

.modal-content input,
.modal-content select {
    padding:8px;
    border-radius:6px;
    border:1px solid #9993;
    background: var(--bg);
    color:var(--text);
}

.modal-actions {
    display:flex;
    justify-content:space-between;
    margin-top:10px;
}

.modal-actions button {
    padding:8px 14px;
    border-radius:6px;
    border:none;
    cursor:pointer;
    font-weight:600;
}

#confirm-modal {
    background: var(--accent);
    color:white;
}

#cancel-modal {
    background:#888;
    color:white;
}

/* ------------------------------
   DIVERS
------------------------------ */
.hidden {
    display:none;
}

/* bouton poussoir */
.action-btn {
    padding:8px 16px;
    border-radius:8px;
    border:none;
    background:var(--accent);
    color:white;
    font-weight:600;
    cursor:pointer;
}
.action-btn:hover {
    background:var(--accent-hov);
}

/* bouton config */
.config-btn {
    align-self:flex-end;
    margin-top:4px;
    padding:4px 10px;
    border:none;
    border-radius:6px;
    font-size:12px;
    cursor:pointer;
    background:transparent;
    color:var(--text);
    opacity:0.7;
}
.config-btn:hover {
    opacity:1;
}
/* Icône de type */
.type-icon {
    margin-right: 6px;
}

/* Statut IP */
.ip-status {
    display:inline-block;
    width:10px;
    height:10px;
    border-radius:50%;
    margin-left:8px;
    vertical-align:middle;
    background:#9ca3af;
}
.ip-status-online { background:#22c55e; }
.ip-status-offline { background:#ef4444; }
.ip-status-unknown { background:#9ca3af; }

/* Bouton Tester */
.ip-test-btn {
    margin-left:8px;
    padding:2px 8px;
    border-radius:6px;
    border:none;
    font-size:11px;
    cursor:pointer;
    background:transparent;
    color:var(--text);
    opacity:0.7;
}
.ip-test-btn:hover {
    opacity:1;
    text-decoration:underline;
}

/* Ajustements carte compacte */
.panel {
    padding:15px !important;
}
.switch-name {
    margin: 4px 0 8px 0;
}
/* ------------------------------
   UTILITAIRES
------------------------------ */
.hidden {
    display: none;
}

/* ------------------------------
   AVANCÉ DANS LE MODAL
------------------------------ */
.advanced-toggle {
    margin-top: 10px;
    padding: 6px 10px;
    border-radius: 6px;
    border: 1px solid #9993;
    background: transparent;
    cursor: pointer;
    font-size: 13px;
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.advanced-section {
    margin-top: 8px;
    padding: 8px;
    border-radius: 8px;
    background-color: rgba(148, 163, 184, 0.15);
    font-size: 13px;
}

.advanced-section label {
    font-size: 13px;
}

.advanced-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 6px;
}

.advanced-section small {
    display: block;
    margin-top: 4px;
    opacity: 0.8;
    font-size: 11px;
}

/* Ligne affichage état récupéré */
.remote-state-line {
    margin: 4px 0 8px 0;
    font-size: 13px;
}
.remote-state-line .remote-state {
    font-weight: 600;
}
/* ------------------------------
   API POPUP STACK
------------------------------ */
#api-popup-container {
    position: fixed;
    top: 20px;
    right: 20px;
    display: flex;
    flex-direction: column;
    gap: 12px;
    z-index: 10000;
    pointer-events: none;
}

.api-popup {
    display: flex;
    align-items: center;
    gap: 10px;
    min-width: 240px;
    max-width: 340px;
    padding: 12px 16px;
    border-radius: 12px;
    font-size: 14px;
    font-weight: 600;
    color: white;
    box-shadow: 0 10px 30px rgba(0,0,0,0.25);
    opacity: 0;
    transform: translateY(-10px);
    transition: opacity 0.3s ease, transform 0.3s ease;
}

.api-popup.show {
    opacity: 1;
    transform: translateY(0);
}

.api-popup-icon {
    font-size: 18px;
    line-height: 1;
}

/* Types */
.api-popup.ok {
    background: linear-gradient(135deg,#22c55e,#16a34a);
}

.api-popup.on {
    background: linear-gradient(135deg,#22c55e,#16a34a);
}

.api-popup.off {
    background: linear-gradient(135deg,#f59e0b,#d97706);
}

.api-popup.error {
    background: linear-gradient(135deg,#ef4444,#b91c1c);
}
.api-popup.info {
    background: linear-gradient(135deg,#3b82f6,#2563eb);
}
/* ------------------------------
   NOTIFICATION TOGGLE
------------------------------ */
#notif-toggle {
    background: transparent;
    border: none;
    font-size: 20px;
    cursor: pointer;
    opacity: 0.8;
    transition: 0.2s;
}

#notif-toggle:hover {
    opacity: 1;
}

#notif-toggle.off {
    opacity: 0.3;
}
html.dark body {
    background: var(--bg);
}
/* ============================================================
   RELAY CONFIG INPUTS – DA COMPATIBLE
============================================================ */

.relay-card label {
    display: flex;
    flex-direction: column;
    gap: 4px;
    font-size: 12px;
    font-weight: 600;
    opacity: 0.85;
}

/* Input / Select */
.relay-card input,
.relay-card select {
    appearance: none;
    background: var(--card);
    color: var(--text);

    border: 1px solid rgba(148, 163, 184, 0.35);
    border-radius: 10px;

    padding: 8px 10px;
    font-size: 13px;
    font-weight: 500;

    transition:
        border-color 0.2s,
        box-shadow 0.2s,
        background 0.2s;
}

/* Focus */
.relay-card input:focus,
.relay-card select:focus {
    outline: none;
    border-color: var(--accent);
    box-shadow: 0 0 0 2px rgba(37, 99, 235, 0.25);
}

/* Select flèche custom */
.relay-card select {
    background-image:
        linear-gradient(45deg, transparent 50%, var(--text) 50%),
        linear-gradient(135deg, var(--text) 50%, transparent 50%);
    background-position:
        calc(100% - 16px) calc(50% - 3px),
        calc(100% - 11px) calc(50% - 3px);
    background-size: 5px 5px;
    background-repeat: no-repeat;
    padding-right: 32px;
}

/* Input number plus compact */
.relay-card input[type="number"] {
    max-width: 120px;
}

/* Bouton enregistrer aligné DA */
.relay-card .save-btn {
    margin-top: auto;              /* 🔥 pousse le bouton en bas */
    width: 100%;                   /* pleine largeur */
    margin-top: 12px;              /* espace avec le champ au-dessus */
    padding: 10px 0;               /* plus confortable */
    border-radius: 10px;
    text-align: center;
}
.relay-delay-row.hidden {
    display: none;
}
.relay-card {
    height: 100%;                 /* 🔥 indispensable */
    display: flex;
    flex-direction: column;
}