/* Permanent owner: Shelly device, component, control, and pool-integration presentation. */

.shelly-device-toolbar {
    display: flex;
    justify-content: flex-end;
    margin-bottom: 14px;
}

.shelly-flow-message {
    margin-bottom: 14px;
}

.shelly-device-delete {
    min-height: 32px;
    padding: 0 10px;
    font-size: 0.78rem;
}

.shelly-device-expand {
    display: inline-grid;
    place-items: center;
    width: 32px;
    height: 32px;
    border: 1px solid var(--color-line);
    border-radius: 8px;
    background: var(--color-surface);
    color: var(--color-text);
    font-size: 1.15rem;
    font-weight: 700;
    line-height: 1;
    cursor: pointer;
}

.shelly-device-expand:hover {
    border-color: var(--color-line-strong);
    background: var(--color-bg-alt);
}

.shelly-device-tabs {
    display: inline-flex;
    gap: 4px;
    margin-bottom: 16px;
    padding: 4px;
    border: 1px solid var(--color-line);
    border-radius: 10px;
    background: var(--color-bg-soft);
}

.shelly-device-tab {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    min-height: 34px;
    padding: 0 12px;
    border: 1px solid transparent;
    border-radius: 8px;
    background: transparent;
    color: var(--color-text-muted);
    font: inherit;
    font-size: 0.82rem;
    font-weight: 800;
    cursor: pointer;
}

.shelly-device-tab:hover {
    color: var(--color-text);
}

.shelly-device-tab--active {
    border-color: var(--color-line);
    background: var(--color-surface-strong);
    color: var(--color-text);
    box-shadow: var(--shadow-soft);
}

.shelly-device-tab strong {
    min-width: 1.55rem;
    padding: 2px 7px;
    border-radius: var(--radius-pill);
    background: var(--color-line);
    color: var(--color-text-soft);
    font-size: 0.72rem;
    line-height: 1.25;
    text-align: center;
}

.shelly-device-tab--active strong {
    background: var(--color-energy-soft);
    color: var(--color-energy-text);
}

.shelly-device-list {
    display: grid;
    gap: 18px;
}

.device-card--muted {
    background: var(--color-surface);
}

.device-card--shelly .device-heading {
    display: flex;
    align-items: flex-start;
    gap: 12px;
    min-width: 0;
}

.device-card--shelly .device-name {
    overflow-wrap: anywhere;
}

.device-card--shelly .device-subtitle {
    margin-top: 4px;
    color: var(--color-text-muted);
    font-size: 0.82rem;
    line-height: 1.35;
    overflow-wrap: anywhere;
}

.shelly-device-header {
    align-items: flex-start;
    cursor: pointer;
    outline: none;
    border-radius: 10px;
}

.shelly-device-header:focus-visible {
    box-shadow: 0 0 0 3px var(--color-focus-ring);
}

.shelly-device-actions {
    display: flex;
    align-items: center;
    gap: 10px;
    justify-content: flex-end;
    flex-wrap: wrap;
    flex-shrink: 0;
}

.shelly-device-chip-row {
    display: none;
}

@media (min-width: 1101px) {
    .device-card--shelly {
        gap: 12px;
        padding: 14px 16px;
        border-radius: 20px;
    }

    .device-card--shelly .shelly-device-header {
        align-items: center;
        padding-bottom: 0;
        border-bottom: 0;
    }

    .device-card--shelly .shelly-device-actions {
        align-items: center;
        gap: 8px;
        max-width: 70%;
    }

    .device-card--shelly .shelly-device-chip-row {
        display: flex;
        align-items: center;
        justify-content: flex-end;
        gap: 8px;
        flex-wrap: wrap;
    }

    .shelly-device-chip {
        display: inline-flex;
        align-items: baseline;
        gap: 8px;
        min-height: 30px;
        padding: 0 10px;
        border: 1px solid color-mix(in srgb, var(--color-line-strong) 58%, transparent);
        border-radius: 999px;
        background: color-mix(in srgb, var(--color-bg-alt) 54%, transparent);
        color: var(--color-text-soft);
        font-size: 0.76rem;
        white-space: nowrap;
    }

    .shelly-device-chip span {
        color: var(--color-text-muted);
    }

    .shelly-device-chip strong {
        color: var(--color-text);
        font-weight: 800;
        font-variant-numeric: tabular-nums;
    }

    .device-card--shelly .device-metrics--shelly {
        gap: 10px;
        padding-top: 12px;
        border-top: 1px solid var(--color-line);
    }

    .device-card--shelly .device-metrics--shelly .device-metric {
        min-height: 58px;
        padding: 10px 12px 9px;
        border: 1px solid color-mix(in srgb, var(--color-line-strong) 58%, transparent);
        border-radius: 14px;
        background: color-mix(in srgb, var(--color-bg-alt) 50%, transparent);
    }

    .device-card--shelly .device-metrics--shelly .device-metric-value {
        margin-top: 5px;
        font-size: clamp(1rem, 0.48vw + 0.9rem, 1.2rem);
    }

    .device-card--shelly .shelly-component {
        min-height: 42px;
        padding: 8px 10px;
    }
}

.shelly-badge {
    display: inline-flex;
    align-items: center;
    min-height: 28px;
    padding: 0 9px;
    border-radius: 8px;
    border: 1px solid var(--color-line);
    font-size: 0.68rem;
    font-weight: 800;
    letter-spacing: 0.04em;
    text-transform: uppercase;
}

.shelly-badge--online {
    border-color: var(--color-success-soft);
    background: var(--color-success-soft);
    color: var(--color-success);
}

.shelly-badge--warn {
    border-color: var(--color-warning-soft);
    background: var(--color-warning-soft);
    color: var(--color-warning);
}

.shelly-badge--offline {
    border-color: var(--color-warning-soft);
    background: transparent;
    color: var(--color-warning);
}

.device-metrics--shelly {
    grid-template-columns: repeat(4, minmax(0, 1fr));
}

.shelly-components {
    display: grid;
    gap: 8px;
}

.shelly-component {
    display: grid;
    gap: 10px;
    min-height: 48px;
    padding: 9px 10px;
    border: 1px solid var(--color-line);
    border-radius: 12px;
    background: var(--color-card);
}

.shelly-component-summary {
    display: flex;
    align-items: center;
    gap: 10px;
    min-width: 0;
}

.shelly-component--active {
    border-color: var(--color-success-soft);
}

.shelly-component--meter {
    border-color: var(--color-water-soft);
}

.shelly-component--script {
    border-color: var(--color-line-strong);
}

.shelly-component--script .shelly-component-icon {
    background: var(--color-energy-soft);
    color: var(--color-energy);
}

.shelly-component--offline {
    background: var(--color-surface);
    color: var(--color-text-muted);
}

.shelly-component-icon {
    display: grid;
    place-items: center;
    width: 32px;
    height: 32px;
    border-radius: 10px;
    background: var(--color-surface);
    color: var(--color-text-soft);
    flex-shrink: 0;
}

.shelly-component-icon svg {
    width: 18px;
    height: 18px;
}

.shelly-component-main {
    min-width: 0;
    display: grid;
    gap: 2px;
    flex: 1;
}

.shelly-component-name {
    color: var(--color-text-muted);
    font-size: 0.72rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.04em;
}

.shelly-component-main strong {
    color: var(--color-text);
    font-size: 0.95rem;
}

.shelly-component-energy {
    color: var(--color-text-muted);
    font-size: 0.78rem;
    font-variant-numeric: tabular-nums;
    flex-shrink: 0;
}

.shelly-component-details,
.shelly-component-controls {
    display: flex;
    align-items: center;
    flex-wrap: wrap;
    gap: 8px;
    padding-left: 42px;
}

.shelly-component-details span {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    min-height: 24px;
    padding: 0 8px;
    border: 1px solid var(--color-line);
    border-radius: 8px;
    background: var(--color-surface);
    font-size: 0.75rem;
}

.shelly-component-details em {
    color: var(--color-text-muted);
    font-style: normal;
}

.shelly-component-details strong {
    color: var(--color-text);
    font-weight: 700;
}

.shelly-component-controls {
    padding-top: 2px;
}

.shelly-component-controls .btn.active {
    border-color: var(--color-success-soft);
    color: var(--color-success);
}

.pool-shelly-components {
    margin-bottom: 18px;
}

.pool-shelly-icon {
    color: var(--color-pool);
}

.pool-shelly-logic-card {
    display: grid;
    gap: 10px;
    margin-bottom: 18px;
    padding: 12px;
    border: 1px solid var(--color-line);
    border-radius: 8px;
    background: var(--color-card);
}

.pool-shelly-switch-grid {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 10px;
}

.pool-shelly-switch-tile {
    position: relative;
    display: grid;
    grid-template-columns: 36px minmax(0, 1fr);
    align-items: center;
    gap: 10px;
    min-height: 88px;
    padding: 11px 12px;
    border: 1px solid var(--color-line);
    border-radius: 8px;
    background: color-mix(in srgb, var(--color-surface) 80%, transparent);
    color: var(--color-text-soft);
}

.pool-shelly-switch-tile::after {
    content: "";
    position: absolute;
    top: 11px;
    right: 11px;
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: var(--color-text-muted);
    opacity: 0.55;
}

.pool-shelly-switch-tile--active {
    border-color: color-mix(in srgb, var(--color-pool) 48%, var(--color-line-strong));
    background: color-mix(in srgb, var(--color-pool) 12%, var(--color-bg-alt));
    box-shadow: inset 0 0 0 1px color-mix(in srgb, var(--color-pool) 18%, transparent);
}

.pool-shelly-switch-tile--active::after {
    background: var(--color-pool);
    opacity: 1;
    box-shadow: 0 0 0 3px color-mix(in srgb, var(--color-pool) 16%, transparent);
}

.pool-shelly-switch-icon,
.pool-shelly-summary-icon {
    display: grid;
    place-items: center;
    width: 36px;
    height: 36px;
    border-radius: 8px;
    background: color-mix(in srgb, var(--color-pool) 12%, var(--color-surface));
    color: var(--color-pool);
    flex-shrink: 0;
}

.pool-shelly-switch-icon svg,
.pool-shelly-summary-icon svg {
    width: 19px;
    height: 19px;
}

.pool-shelly-switch-copy,
.pool-shelly-summary-copy {
    display: grid;
    gap: 3px;
    min-width: 0;
}

.pool-shelly-switch-label,
.pool-shelly-summary-copy span {
    overflow: hidden;
    color: var(--color-text-muted);
    font-size: 0.72rem;
    font-weight: 800;
    letter-spacing: 0;
    text-overflow: ellipsis;
    text-transform: uppercase;
    white-space: nowrap;
}

.pool-shelly-switch-copy strong,
.pool-shelly-summary-copy strong {
    overflow: hidden;
    color: var(--color-text);
    font-size: 0.98rem;
    line-height: 1.2;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.pool-shelly-switch-copy em {
    overflow: hidden;
    color: var(--color-text-soft);
    font-size: 0.78rem;
    font-style: normal;
    line-height: 1.25;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.pool-shelly-summary-strip {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 10px;
}

.pool-shelly-summary-item {
    position: relative;
    overflow: hidden;
    display: grid;
    grid-template-columns: 40px minmax(0, 1fr) auto;
    align-items: center;
    gap: 12px;
    min-height: 72px;
    padding: 12px 14px;
    border: 1px solid var(--color-line);
    border-radius: 8px;
    background:
        linear-gradient(135deg, color-mix(in srgb, var(--color-pool) 10%, transparent), transparent 48%),
        color-mix(in srgb, var(--color-bg) 76%, transparent);
    color: inherit;
    text-align: left;
}

.pool-shelly-summary-item::before {
    content: "";
    position: absolute;
    inset: 10px auto 10px 0;
    width: 3px;
    border-radius: 0 999px 999px 0;
    background: color-mix(in srgb, var(--color-text-muted) 58%, transparent);
}

.pool-shelly-summary-item--active {
    border-color: color-mix(in srgb, var(--color-pool) 42%, var(--color-line-strong));
    background:
        linear-gradient(135deg, color-mix(in srgb, var(--color-pool) 16%, transparent), transparent 54%),
        color-mix(in srgb, var(--color-bg) 68%, transparent);
}

.pool-shelly-summary-item--active::before {
    background: var(--color-pool);
    box-shadow: 0 0 18px color-mix(in srgb, var(--color-pool) 44%, transparent);
}

.pool-shelly-summary-item--output .pool-shelly-summary-icon {
    width: 40px;
    height: 40px;
    border-radius: 10px;
    background: color-mix(in srgb, var(--color-pool) 18%, var(--color-surface));
}

.pool-shelly-summary-item--script .pool-shelly-summary-icon {
    width: 40px;
    height: 40px;
    border-radius: 10px;
    background: color-mix(in srgb, var(--color-energy) 18%, var(--color-surface));
    color: var(--color-energy);
}

.pool-shelly-summary-meta {
    overflow: hidden;
    color: var(--color-text-soft);
    font-size: 0.78rem;
    font-style: normal;
    line-height: 1.25;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.pool-shelly-summary-state {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-height: 28px;
    padding: 0 10px;
    border: 1px solid var(--color-line);
    border-radius: 999px;
    background: color-mix(in srgb, var(--color-bg-soft) 72%, transparent);
    color: var(--color-text-soft);
    font-size: 0.76rem;
    font-weight: 800;
    white-space: nowrap;
}

.pool-shelly-summary-item--active .pool-shelly-summary-state {
    border-color: color-mix(in srgb, var(--color-pool) 38%, var(--color-line-strong));
    background: color-mix(in srgb, var(--color-pool) 13%, transparent);
    color: var(--color-pool);
}

.shelly-control-field {
    display: inline-grid;
    grid-template-columns: auto minmax(100px, 150px);
    align-items: center;
    gap: 8px;
    min-height: 32px;
    padding: 0 8px;
    border: 1px solid var(--color-line);
    border-radius: 8px;
    background: var(--color-surface);
    color: var(--color-text-muted);
    font-size: 0.75rem;
    font-weight: 700;
}

.shelly-control-field input[type="range"] {
    width: 100%;
    accent-color: var(--accent);
}

.shelly-control-field input[type="number"] {
    width: 82px;
    border: 1px solid var(--color-line);
    border-radius: 6px;
    background: var(--color-bg);
    color: var(--color-text);
    padding: 4px 6px;
}

.shelly-device-empty {
    padding: 14px;
    border: 1px dashed var(--color-line);
    border-radius: 12px;
    color: var(--color-text-muted);
    font-size: 0.82rem;
}

@media (max-width: 640px) {
    .shelly-device-header,
    .shelly-device-actions {
        flex-direction: column;
        align-items: stretch;
    }

    .shelly-device-tabs {
        display: grid;
        grid-template-columns: repeat(2, minmax(0, 1fr));
        width: 100%;
    }

    .shelly-device-tab {
        justify-content: center;
    }

    .device-metrics--shelly {
        grid-template-columns: repeat(2, minmax(0, 1fr));
    }

    .shelly-component-details,
    .shelly-component-controls {
        padding-left: 0;
    }

    .pool-shelly-logic-card {
        padding: 10px;
    }

    .pool-shelly-switch-grid,
    .pool-shelly-summary-strip {
        grid-template-columns: 1fr;
    }

    .pool-shelly-switch-tile {
        min-height: 72px;
        grid-template-columns: 34px minmax(0, 1fr);
        padding: 10px;
    }

    .pool-shelly-switch-icon,
    .pool-shelly-summary-icon {
        width: 34px;
        height: 34px;
    }

    .pool-shelly-summary-item {
        grid-template-columns: 34px minmax(0, 1fr) auto;
        min-height: 66px;
        padding: 10px;
    }

    .pool-shelly-summary-item--output .pool-shelly-summary-icon,
    .pool-shelly-summary-item--script .pool-shelly-summary-icon {
        width: 34px;
        height: 34px;
    }

    .shelly-control-field {
        grid-template-columns: 1fr;
        align-items: stretch;
        width: 100%;
        padding: 8px;
    }
}


