/* Shared styles for custom device widgets used in Filament dashboards. */

.sm-device-dashboard,
.sm-status-card {
    --sm-blue: #38bdf8;
    --sm-orange: #eab308;
    --sm-text: #ffffff;
    --sm-text-soft: #9ca3af;
    --sm-text-muted: #6b7280;
}

.sm-device-dashboard {
    --sm-dark-950: #080810;
    --sm-dark-900: #0f0f1a;
    --sm-dark-800: #1a1a2e;
    display: grid;
    gap: 0.75rem;
}

.sm-device-card,
.sm-device-empty,
.sm-device-stat {
    border: 1px solid rgba(255, 255, 255, 0.08);
    background: rgba(20, 20, 35, 0.5);
    box-shadow: none;
}

.sm-device-empty,
.sm-device-card {
    border-radius: 8px;
}

.sm-device-counter {
    display: inline-flex;
    align-items: center;
    border-radius: 6px;
    padding: 0.45rem 0.8rem;
    color: var(--sm-text-soft);
    background: rgba(20, 20, 35, 0.5);
    border: 1px solid rgba(255, 255, 255, 0.08);
    width: fit-content;
    font-size: 0.78rem;
    font-weight: 700;
    letter-spacing: 0.01em;
    cursor: default;
}

.sm-device-toolbar {
    margin-bottom: 1rem;
    display: grid;
    grid-template-columns: minmax(0, 1fr) minmax(300px, 500px);
    gap: 0.75rem;
    align-items: start;
}

.sm-device-filter-actions {
    display: flex;
    gap: 0.5rem;
    flex-wrap: wrap;
    padding: 0.4rem;
    border: 1px solid rgba(255, 255, 255, 0.08);
    border-radius: 10px;
    background: rgba(20, 20, 35, 0.34);
}

.sm-device-filter-button {
    padding: 0.5rem 1rem;
    border-radius: 6px;
    background: rgba(20, 20, 35, 0.5);
    border: 1px solid rgba(255, 255, 255, 0.08);
    color: var(--sm-text-soft);
    cursor: pointer;
    transition: border-color 180ms ease, color 180ms ease, background-color 180ms ease, box-shadow 180ms ease;
    font-weight: 600;
}

.sm-device-filter-button.is-active {
    color: #ffffff;
    border-color: rgba(56, 189, 248, 0.7);
    background: rgba(56, 189, 248, 0.2);
    box-shadow: inset 0 0 0 1px rgba(56, 189, 248, 0.28);
}

.sm-device-filter-button:hover {
    border-color: rgba(255, 255, 255, 0.18);
    color: var(--sm-text);
}

.sm-device-filter-button:focus-visible {
    outline: 2px solid rgba(56, 189, 248, 0.65);
    outline-offset: 2px;
}

.sm-device-form-wrap {
    margin-left: 0;
    width: 100%;
    padding: 0.4rem;
    border: 1px solid rgba(255, 255, 255, 0.08);
    border-radius: 10px;
    background: rgba(20, 20, 35, 0.34);
}

.sm-device-empty {
    padding: 1.5rem 1rem;
    text-align: center;
    color: var(--sm-text-soft);
}

.sm-device-empty strong {
    display: block;
    margin-bottom: 0.45rem;
    color: var(--sm-text);
    font-size: 0.95rem;
}

.sm-device-grid {
    display: grid;
    gap: 0.75rem;
    grid-template-columns: repeat(auto-fill, minmax(230px, 1fr));
}

.sm-device-card {
    position: relative;
    display: flex;
    flex-direction: column;
    gap: 0.65rem;
    min-height: 132px;
    padding: 0.85rem;
    color: inherit;
    text-decoration: none;
    overflow: hidden;
    transition: transform 180ms ease, border-color 180ms ease, box-shadow 180ms ease;
}

.sm-device-card::after {
    content: '';
    position: absolute;
    inset: 0;
    background: none;
    pointer-events: none;
}

.sm-device-card:hover {
    transform: none;
    border-color: rgba(255, 255, 255, 0.12);
    box-shadow: none;
}

.sm-device-card--online {
    border-width: 1.5px;
    border-color: rgba(34, 197, 94, 0.35);
}

.sm-device-card--delayed {
    border-width: 1.5px;
    border-color: rgba(250, 204, 21, 0.4);
}

.sm-device-card--offline {
    border-width: 1.5px;
    border-color: rgba(248, 113, 113, 0.4);
}

.sm-device-card--muted {
    border-color: rgba(255, 255, 255, 0.08);
}

.sm-device-card-head {
    display: flex;
    justify-content: space-between;
    gap: 0.5rem;
    align-items: flex-start;
    min-width: 0;
}

.sm-device-card-head > div:first-child {
    min-width: 0;
    flex: 1;
}

.sm-device-card-head > div:last-child {
    display: flex;
    align-items: center;
    gap: 0.45rem;
    flex-shrink: 0;
}


.sm-device-name {
    margin: 0;
    color: var(--sm-text);
    font-size: 0.96rem;
    font-weight: 800;
    line-height: 1.2;
    white-space: normal;
    overflow-wrap: anywhere;
}

.sm-device-context {
    margin: 0;
    color: var(--sm-text-soft);
    font-size: 0.65rem;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

@media (max-width: 500px) {
    .sm-device-context {
        font-size: 0.6rem;
    }
}

.sm-device-alert-dot {
    width: 0.4rem;
    height: 0.4rem;
    border-radius: 2px;
    background: #fbbf24;
    box-shadow: none;
}

.sm-device-alert-button {
    position: relative;
    z-index: 2;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 0.15rem;
    border: 0;
    background: transparent;
    cursor: pointer;
}

.sm-device-alert-button:focus-visible {
    outline: 2px solid rgba(251, 191, 36, 0.7);
    outline-offset: 2px;
    border-radius: 4px;
}

.sm-device-stats {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 0.55rem;
}

.sm-device-stat {
    border-radius: 6px;
    padding: 0.65rem;
    display: flex;
    flex-direction: column;
}

.sm-device-label {
    margin: 0;
    color: var(--sm-text-muted);
    font-size: 0.58rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    word-break: break-word;
    white-space: normal;
}

.sm-device-value {
    margin: 0.22rem 0 0;
    margin-top: auto;
    color: var(--sm-text);
    font-size: 0.92rem;
    font-weight: 800;
    line-height: 1.1;
}

.sm-device-value--success {
    color: #38bdf8;
}

.sm-device-value--danger {
    color: #f87171;
}

.sm-device-value--muted {
    color: #ffffff;
}

.sm-device-last-seen {
    margin: 0;
    color: var(--sm-text-soft);
    font-size: 0.7rem;
    line-height: 1.35;
}

.sm-device-last-seen strong {
    color: var(--sm-text-muted);
    font-weight: 600;
}

.sm-device-link-cover {
    margin-top: auto;
    position: absolute;
    inset: 0;
    z-index: 1;
}

.sm-status-card {
    border: 1px solid rgba(255, 255, 255, 0.08);
    background: rgba(20, 20, 35, 0.5);
    border-radius: 8px;
    padding: 1rem;
    display: grid;
    gap: 1rem;
}

@media (max-width: 500px) {
    .sm-status-card {
        padding: 0.75rem;
        gap: 0.75rem;
    }
}

.sm-status-header {
    display: flex;
    flex-direction: column;
    gap: 0.35rem;
}

@media (max-width: 500px) {
    .sm-status-header {
        gap: 0.25rem;
    }
}

.sm-status-header-left {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 0.45rem;
}

.sm-status-name {
    margin: 0;
    font-size: 0.95rem;
    font-weight: 800;
    color: var(--sm-text);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    width: 100%;
}

@media (max-width: 500px) {
    .sm-status-name {
        font-size: 0.85rem;
    }
}

.sm-status-badge {
    display: inline-flex;
    align-items: center;
    gap: 0.4rem;
    padding: 0.3rem 0.7rem;
    border-radius: 999px;
    font-size: 0.72rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    flex-shrink: 0;
}

.sm-status-dot {
    width: 0.45rem;
    height: 0.45rem;
    border-radius: 50%;
}

.sm-badge--online {
    background: rgba(134, 239, 172, 0.12);
    border: 1px solid rgba(134, 239, 172, 0.35);
    color: #86efac;
}

.sm-badge--online .sm-status-dot {
    background: #86efac;
}

.sm-badge--offline {
    background: rgba(251, 191, 36, 0.1);
    border: 1px solid rgba(251, 191, 36, 0.3);
    color: #fbbf24;
}

.sm-badge--offline .sm-status-dot {
    background: #fbbf24;
}

.sm-badge--alert {
    background: rgba(248, 113, 113, 0.12);
    border: 1px solid rgba(248, 113, 113, 0.35);
    color: #f87171;
}

.sm-badge--alert .sm-status-dot {
    background: #f87171;
    animation: sm-pulse 1.5s ease-in-out infinite;
}

@keyframes sm-pulse {
    0%,
    100% {
        opacity: 1;
    }

    50% {
        opacity: 0.35;
    }
}

.sm-status-last-update {
    font-size: 0.65rem;
    color: var(--sm-text-muted);
}

@media (max-width: 500px) {
    .sm-status-last-update {
        font-size: 0.6rem;
    }
}

.sm-status-grid {
    display: grid;
    grid-template-columns: 1fr;
    gap: 1rem;
}

@media (max-width: 500px) {
    .sm-status-grid {
        gap: 0.75rem;
    }
}

.sm-stat-tile {
    border: 1px solid rgba(255, 255, 255, 0.08);
    background: rgba(255, 255, 255, 0.03);
    border-radius: 8px;
    padding: 0.6rem 0.65rem;
    display: flex;
    flex-direction: column;
    gap: 0.2rem;
}

@media (max-width: 500px) {
    .sm-stat-tile {
        padding: 0.5rem 0.6rem;
        gap: 0.15rem;
    }
}

.sm-stat-tile--temp {
    border-color: rgba(234, 179, 8, 0.25);
    background: rgba(234, 179, 8, 0.06);
}

.sm-stat-tile--humidity {
    border-color: rgba(56, 189, 248, 0.25);
    background: rgba(56, 189, 248, 0.06);
}

.sm-stat-tile--danger {
    border-color: rgba(248, 113, 113, 0.35);
    background: rgba(248, 113, 113, 0.08);
}

.sm-stat-label {
    font-size: 0.6rem;
    font-weight: 600;
    color: var(--sm-text-muted);
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

@media (max-width: 500px) {
    .sm-stat-label {
        font-size: 0.55rem;
        letter-spacing: 0.04em;
    }
}

.sm-stat-value {
    font-size: 1.4rem;
    font-weight: 800;
    line-height: 1;
    color: var(--sm-text);
}

@media (max-width: 500px) {
    .sm-stat-value {
        font-size: 1.1rem;
    }
}

.sm-stat-tile--temp .sm-stat-value {
    color: #eab308;
    font-size: 1.4rem;
}

.sm-stat-tile--humidity .sm-stat-value {
    color: #38bdf8;
    font-size: 1.4rem;
}

@media (max-width: 500px) {
    .sm-stat-tile--temp .sm-stat-value,
    .sm-stat-tile--humidity .sm-stat-value {
        font-size: 1.1rem;
    }
}

.sm-stat-hint {
    font-size: 0.6rem;
    color: var(--sm-text-muted);
    display: flex;
    align-items: center;
    gap: 0.2rem;
}

@media (max-width: 500px) {
    .sm-stat-hint {
        font-size: 0.55rem;
    }
}

.sm-stat-hint--danger {
    color: #f87171;
}

.sm-stat-hint--success {
    color: #86efac;
}

/* Light mode tuning for device widgets */
:root:not(.dark) .sm-device-dashboard,
:root:not(.dark) .sm-status-card {
    --sm-text: #111827;
    --sm-text-soft: #4b5563;
    --sm-text-muted: #6b7280;
}

:root:not(.dark) .sm-device-card,
:root:not(.dark) .sm-device-empty,
:root:not(.dark) .sm-status-card {
    border: 1px solid #e2e8f0;
    background: #f1f5f9;
    box-shadow: 0 1px 3px rgba(15, 23, 42, 0.08);
}

:root:not(.dark) .sm-device-filter-button {
    border: 1px solid #e2e8f0;
    background: #ffffff;
    box-shadow: 0 1px 2px rgba(15, 23, 42, 0.05);
}

:root:not(.dark) .sm-device-stat {
    border: 1px solid #e2e8f0;
    background: #ffffff;
    box-shadow: 0 1px 3px rgba(15, 23, 42, 0.07);
}

:root:not(.dark) .sm-device-filter-actions,
:root:not(.dark) .sm-device-form-wrap {
    border-color: #dbe3ee;
    background: #f8fafc;
}

.dark .sm-device-counter {
    border: 1px solid rgba(79, 70, 229, 0.4);
    background: rgba(79, 70, 229, 0.15);
    color: #a5b4fc;
    box-shadow: none;
}

:root:not(.dark) .sm-device-counter {
    border: 1px solid #c7d2fe;
    background: #eef2ff;
    color: #3730a3;
    box-shadow: none;
}

:root:not(.dark) .sm-device-filter-button {
    border-color: #cbd5e1;
    background: #ffffff;
    color: #1f2937;
    box-shadow: 0 1px 2px rgba(15, 23, 42, 0.06);
}

:root:not(.dark) .sm-device-filter-button.is-active {
    color: #0f172a;
    border-color: #93c5fd;
    background: #eff6ff;
    box-shadow: inset 0 0 0 1px #bfdbfe;
}

:root:not(.dark) .sm-device-card:hover {
    border-color: #d1d5db;
    box-shadow: 0 4px 12px rgba(15, 23, 42, 0.08);
}

:root:not(.dark) .sm-device-card--online {
    border-width: 2px;
    border-style: solid;
    border-color: #86efac;
}

:root:not(.dark) .sm-device-card--delayed {
    border-width: 2px;
    border-style: solid;
    border-color: #fde68a;
}

:root:not(.dark) .sm-device-card--offline {
    border-width: 2px;
    border-style: solid;
    border-color: #fecaca;
}

:root:not(.dark) .sm-device-card--muted {
    border-color: #e5e7eb;
}

:root:not(.dark) .sm-device-filter-button:hover {
    border-color: #94a3b8;
    color: #111827;
    background: #f8fafc;
    box-shadow: 0 4px 10px rgba(15, 23, 42, 0.08);
}

:root:not(.dark) .sm-device-alert-dot {
    background: #f59e0b;
}

:root:not(.dark) .sm-device-value--success {
    color: #0284c7;
}

:root:not(.dark) .sm-device-value--danger {
    color: #dc2626;
}

:root:not(.dark) .sm-device-value--muted {
    color: #111827;
}

:root:not(.dark) .sm-badge--online {
    background: #ecfdf5;
    border-color: #a7f3d0;
    color: #065f46;
}

:root:not(.dark) .sm-badge--online .sm-status-dot {
    background: #10b981;
}

:root:not(.dark) .sm-badge--offline {
    background: #fffbeb;
    border-color: #fde68a;
    color: #92400e;
}

:root:not(.dark) .sm-badge--offline .sm-status-dot {
    background: #f59e0b;
}

:root:not(.dark) .sm-badge--alert {
    background: #fef2f2;
    border-color: #fecaca;
    color: #991b1b;
}

:root:not(.dark) .sm-badge--alert .sm-status-dot {
    background: #ef4444;
}

:root:not(.dark) .sm-stat-tile {
    border-color: #e5e7eb;
    background: #f3f4f6 !important;
}

:root:not(.dark) .sm-stat-tile--temp {
    border-color: #fde68a;
    background: #fffbeb !important;
}

:root:not(.dark) .sm-stat-tile--humidity {
    border-color: #bae6fd;
    background: #f0f9ff !important;
}

:root:not(.dark) .sm-stat-tile--danger {
    border-color: #fecaca;
    background: #fef2f2 !important;
}

@media (max-width: 720px) {
    .sm-device-dashboard {
        gap: 0.6rem;
    }

    .sm-device-counter {
        width: 100%;
        justify-content: center;
    }

    .sm-device-toolbar {
        margin-bottom: 0.65rem;
        grid-template-columns: 1fr;
        align-items: stretch;
    }

    .sm-device-filter-actions {
        width: 100%;
    }

    .sm-device-filter-button {
        flex: 1 1 160px;
        min-height: 2.35rem;
    }

    .sm-device-form-wrap {
        margin-left: 0;
        width: 100%;
    }

    .sm-device-grid {
        grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
        gap: 0.6rem;
    }

    .sm-device-card {
        min-height: 0;
        padding: 0.72rem;
    }

    .sm-device-card-head {
        flex-direction: column;
        gap: 0.45rem;
    }

    .sm-device-card-head > div:last-child {
        width: 100%;
        justify-content: space-between;
    }

}

@media (max-width: 430px) {
    .sm-device-grid {
        grid-template-columns: 1fr;
    }

    .sm-device-stats {
        grid-template-columns: 1fr;
    }

    .sm-device-name {
        font-size: 0.9rem;
    }
}

/* Device Details Widget Styles */
.sm-details-container {
    padding: 0.75rem;
    height: 100%;
    display: flex;
    flex-direction: column;
    justify-content: space-between;
}

.sm-details-header {
    margin-bottom: 0.75rem;
}

.sm-details-title {
    margin: 0;
    font-size: 0.95rem;
    font-weight: 700;
    color: var(--sm-text);
}

.sm-details-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 0.5rem;
}

.sm-details-item {
    border-radius: 6px;
    padding: 0.5rem;
    background: rgba(255, 255, 255, 0.03);
    border: 1px solid rgba(255, 255, 255, 0.08);
}

.sm-details-label {
    display: block;
    font-size: 0.6rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--sm-text-muted);
    margin-bottom: 0.2rem;
}

.sm-details-value {
    display: block;
    font-size: 0.8rem;
    font-weight: 600;
    color: var(--sm-text);
    line-height: 1.3;
    word-break: break-word;
}

.sm-details-value--small {
    font-size: 0.7rem;
    font-family: monospace;
}

.sm-details-notes {
    margin-top: 1rem;
    padding-top: 0.5rem;
    border-top: 1px solid rgba(255, 255, 255, 0.08);
}

.sm-details-notes-title {
    margin: 0 0 0.2rem 0;
    color: var(--sm-text-muted);
    font-size: 0.6rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

.sm-details-notes-text {
    margin: 0;
    color: var(--sm-text-soft);
    font-size: 0.75rem;
    white-space: pre-wrap;
    word-break: break-word;
    line-height: 1.4;
}

/* Light mode for device details */
:root:not(.dark) .sm-details-item {
    background: rgba(15, 23, 42, 0.03);
    border: 1px solid #e5e7eb;
}

:root:not(.dark) .sm-details-value {
    color: #111827;
}

:root:not(.dark) .sm-details-notes-text {
    color: #4b5563;
}
