:root {
    --primary-color: #1E1E1E;
    --secondary-color: #121212;
    --highlight-color: #42A5F5;
    --highlight-hover: #5DADE2;
    --text-color: #E0E0E0;
    --muted-text: rgba(224, 224, 224, 0.75);
    --border-color: #333333;
    --shadow: 0 2px 5px rgba(0, 0, 0, 0.3);
    --sidebar-width: 250px;
    --header-height: 40px;
    --status-color: #81C784;
    --card-bg: rgba(255, 255, 255, 0.05);
    --input-bg: rgba(255, 255, 255, 0.04);
    --radius: 10px;
    --app-height: 100vh;
}

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

html,
body {
    min-height: 100%;
}

html {
    height: 100%;
    -webkit-text-size-adjust: 100%;
    text-size-adjust: 100%;
}

body {
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    background-color: var(--secondary-color);
    color: var(--text-color);
    line-height: 1.6;
    overflow-x: hidden;
    min-height: var(--app-height);
}

@media (display-mode: standalone) {
    .pwa-hide-home {
        display: none !important;
    }
}

.header {
    background-color: var(--primary-color);
    color: white;
    padding: 0.5rem 1rem;
    height: var(--header-height);
    text-align: center;
    box-shadow: var(--shadow);
    display: flex;
    align-items: center;
    justify-content: center;
    position: relative;
}

.header h1 {
    margin: 0;
    font-size: 1.4rem;
    font-weight: 500;
}

.header-brand {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.55rem;
    min-width: 0;
}

.header-brand img {
    width: 24px;
    height: 24px;
    border-radius: 7px;
    flex: 0 0 auto;
}

.header-actions {
    position: absolute;
    right: 12px;
    top: 50%;
    transform: translateY(-50%);
    display: flex;
    align-items: center;
    gap: 10px;
}

.logout-btn {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 6px 10px;
    border-radius: 6px;
    background-color: rgba(255, 255, 255, 0.08);
    color: var(--text-color);
    text-decoration: none;
    font-size: 0.85rem;
    transition: background-color 0.2s ease;
    position: static;
    transform: none;
    right: auto;
    top: auto;
    border: none;
    cursor: pointer;
}

.logout-btn:hover {
    background-color: rgba(255, 255, 255, 0.18);
}

.logout-icon {
    display: none;
}

.menu-label-short {
    display: none;
}

.container {
    display: flex;
    min-height: calc(100vh - var(--header-height));
}

.somfy-container {
    display: block;
    width: min(1120px, calc(100% - 32px));
    margin: 0 auto;
    padding: 1rem 0;
}

.panel {
    background-color: var(--primary-color);
    border: 1px solid var(--border-color);
    border-radius: 8px;
    box-shadow: var(--shadow);
    margin-bottom: 1rem;
    padding: 1rem;
}

.eyebrow {
    margin: 0 0 0.35rem;
    color: var(--highlight-color);
    font-size: 0.78rem;
    font-weight: 700;
    text-transform: uppercase;
}

h1,
h2 {
    color: var(--text-color);
}

h2 {
    margin: 0;
    font-size: 1rem;
    font-weight: 500;
}

.section-subtitle,
.action-status {
    color: var(--muted-text);
    font-size: 0.9rem;
}

.section-subtitle {
    margin-top: 0.2rem;
}

.action-status {
    margin-bottom: 1rem;
    min-height: 1.25rem;
}

button {
    background-color: var(--highlight-color);
    color: white;
    border: none;
    border-radius: 4px;
    cursor: pointer;
    transition: background-color 0.3s;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    font: inherit;
    font-size: 0.9rem;
    font-weight: 600;
    min-height: 38px;
    padding: 0.6rem;
}

[hidden] {
    display: none !important;
}

.passkey-action[hidden] {
    display: none !important;
}

button:hover {
    background-color: var(--highlight-hover);
}

button:disabled {
    cursor: wait;
    opacity: 0.6;
}

.button-row {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
    justify-content: flex-end;
}

.button-row button {
    gap: 0.45rem;
}

.section-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 1rem;
    margin-bottom: 1rem;
}

.summary-grid {
    display: grid;
    grid-template-columns: repeat(4, minmax(0, 1fr));
    gap: 0.75rem;
    margin-bottom: 1rem;
}

.metric {
    background-color: rgba(255, 255, 255, 0.05);
    border-radius: 5px;
    border: 1px solid var(--border-color);
    min-height: 78px;
    padding: 0.65rem;
    overflow: hidden;
}

.metric strong {
    color: var(--text-color);
    display: block;
    font-size: 1rem;
    font-weight: 600;
    overflow-wrap: anywhere;
}

.metric span {
    color: var(--muted-text);
    display: block;
    font-size: 0.8rem;
    margin-top: 0.25rem;
}

.table-wrap {
    overflow-x: auto;
}

table {
    border-collapse: collapse;
    min-width: 760px;
    width: 100%;
}

th,
td {
    border-bottom: 1px solid var(--border-color);
    padding: 0.6rem 0.5rem;
    text-align: left;
    white-space: nowrap;
}

th {
    color: var(--muted-text);
    font-size: 0.76rem;
    font-weight: 700;
    text-transform: uppercase;
}

.badge {
    border-radius: 999px;
    display: inline-block;
    font-size: 0.76rem;
    font-weight: 700;
    padding: 0.22rem 0.5rem;
}

.badge-ok {
    background: rgba(129, 199, 132, 0.16);
    color: var(--status-color);
}

.badge-warning {
    background: rgba(255, 202, 40, 0.16);
    color: #ffca28;
}

.badge-error {
    background: rgba(239, 83, 80, 0.16);
    color: #ef5350;
}

.password-form {
    display: grid;
    gap: 0.75rem;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    margin-top: 0.8rem;
}

.password-form input {
    width: 100%;
    padding: 0.6rem;
    border: 1px solid var(--border-color);
    border-radius: 4px;
    font-size: 0.9rem;
    background-color: rgba(255, 255, 255, 0.05);
    color: var(--text-color);
    min-width: 0;
}

.password-form button {
    grid-column: 3;
    justify-self: stretch;
}

.password-form input:focus {
    border-color: var(--highlight-color);
    outline: none;
}

.login-page {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 24px;
    background:
        radial-gradient(circle at top, rgba(66, 165, 245, 0.12), transparent 35%),
        var(--secondary-color);
    line-height: 1.5;
}

.login-shell {
    width: 100%;
    max-width: 420px;
}

.login-card {
    background: var(--primary-color);
    border: 1px solid var(--border-color);
    border-radius: var(--radius);
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.35);
    overflow: hidden;
}

.login-header {
    padding: 20px 24px 16px;
    border-bottom: 1px solid var(--border-color);
    text-align: center;
}

.login-brand {
    display: grid;
    justify-items: center;
    gap: 10px;
    margin-bottom: 6px;
}

.login-brand img {
    width: 78px;
    height: 78px;
    border-radius: 20px;
    box-shadow: 0 14px 34px rgba(0, 0, 0, 0.34);
}

.login-header h1 {
    font-size: 1.5rem;
    font-weight: 600;
    margin-bottom: 6px;
    color: #ffffff;
}

.login-header p {
    font-size: 0.95rem;
    color: var(--muted-text);
}

.login-body {
    padding: 24px;
}

.form-group {
    margin-bottom: 16px;
}

.form-group label {
    display: block;
    margin-bottom: 6px;
    font-size: 0.92rem;
}

.form-group input {
    width: 100%;
    padding: 12px 14px;
    border: 1px solid var(--border-color);
    border-radius: 8px;
    background: var(--input-bg);
    color: var(--text-color);
    font-size: 0.95rem;
    outline: none;
}

.form-group input:focus {
    border-color: var(--highlight-color);
    box-shadow: 0 0 0 3px rgba(66, 165, 245, 0.18);
}

.submit-btn {
    width: 100%;
    padding: 12px 16px;
    margin-top: 8px;
    border: none;
    border-radius: 8px;
    background: var(--highlight-color);
    color: white;
    font-weight: 600;
    cursor: pointer;
}

.submit-btn:hover {
    background: var(--highlight-hover);
}

.passkey-btn {
    width: 100%;
    padding: 12px 16px;
    margin-bottom: 16px;
    border: 1px solid rgba(126, 220, 139, 0.42);
    border-radius: 8px;
    background: rgba(126, 220, 139, 0.12);
    color: #b9f3bd;
    font-weight: 700;
    cursor: pointer;
}

.passkey-btn:hover {
    background: rgba(126, 220, 139, 0.18);
}

.passkey-btn[hidden],
.login-separator[hidden] {
    display: none;
}

.login-separator {
    display: flex;
    align-items: center;
    gap: 10px;
    margin: 2px 0 16px;
    color: var(--muted-text);
    font-size: 0.8rem;
}

.login-separator::before,
.login-separator::after {
    content: "";
    flex: 1 1 auto;
    border-top: 1px solid var(--border-color);
}

.login-footer {
    padding: 0 24px 20px;
    text-align: center;
    font-size: 0.82rem;
    color: var(--muted-text);
}

.login-error {
    display: none;
    margin-bottom: 14px;
    padding: 10px 12px;
    border: 1px solid rgba(217, 85, 85, 0.38);
    border-radius: 8px;
    background: rgba(217, 85, 85, 0.12);
    color: #ffb8b8;
    font-size: 0.9rem;
}

.login-error.is-visible {
    display: block;
}

.home-layout {
    display: grid;
    grid-template-columns: var(--sidebar-width) minmax(0, 1fr);
    min-height: calc(100vh - var(--header-height));
}

.somfy-menu {
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
    width: var(--sidebar-width);
    min-height: calc(100vh - var(--header-height));
    padding: 1rem;
    background-color: var(--primary-color);
    box-shadow: var(--shadow);
    border-right: 1px solid var(--border-color);
}

.menu-action {
    justify-content: flex-start;
    gap: 0.7rem;
    width: 100%;
    min-height: 46px;
    padding: 0.7rem 0.8rem;
    border: 1px solid var(--border-color);
    background-color: rgba(255, 255, 255, 0.05);
    color: var(--text-color);
}

.menu-action:hover {
    background-color: rgba(66, 165, 245, 0.18);
}

.icon,
.shutter-icon {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    flex: 0 0 auto;
}

.icon svg,
.icon i,
.shutter-icon svg,
.shutter-icon i {
    width: 1.1rem;
    height: 1.1rem;
    line-height: 1;
}

.icon svg,
.shutter-icon svg {
    fill: none;
    stroke: currentColor;
    stroke-linecap: round;
    stroke-linejoin: round;
    stroke-width: 2;
}

.shutters-workspace {
    min-width: 0;
    padding: 1rem;
    padding-bottom: calc(1rem + env(safe-area-inset-bottom));
}

.house-workspace {
    position: relative;
    min-height: calc(100vh - var(--header-height));
    overflow: hidden;
    background:
        linear-gradient(90deg, rgba(8, 13, 20, 0.22) 0%, rgba(8, 13, 20, 0.16) 48%, rgba(8, 13, 20, 0.08) 100%),
        linear-gradient(180deg, rgba(8, 13, 20, 0.00), rgba(8, 13, 20, 0.16)),
        url("images/house-background-crop.png") center center / cover no-repeat;
}

.home-view,
.pieces-view,
.shutters-view,
.sensors-view,
.room-view,
.security-view,
.sync-view {
    width: min(980px, 100%);
    min-height: calc(100vh - var(--header-height) - 2rem);
    padding: 1.2rem;
}

.home-copy,
.page-copy {
    margin: 2rem 0 2rem;
}

.home-copy h2,
.room-heading h2,
.page-copy h2 {
    color: #ffffff;
    font-size: clamp(1.45rem, 3vw, 2rem);
    font-weight: 750;
}

.quick-panel,
.rooms-section,
.pieces-config-grid {
    margin-top: 1.25rem;
}

.quick-panel h3,
.rooms-section h3 {
    margin-bottom: 0.75rem;
    color: #ffffff;
    font-size: 1rem;
    font-weight: 750;
}

.quick-actions {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 0.8rem;
}

.quick-action {
    align-items: center;
    flex-direction: column;
    gap: 0.2rem;
    min-height: 108px;
    padding: 0.95rem;
    border: 1px solid rgba(255, 255, 255, 0.18);
    border-radius: 8px;
    background: rgba(16, 31, 48, 0.72);
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.28), inset 0 1px 0 rgba(255, 255, 255, 0.08);
    backdrop-filter: blur(14px);
    text-align: center;
}

.quick-action .icon i {
    width: auto;
    height: auto;
    font-size: 2rem;
}

.quick-action strong {
    margin-top: 0.25rem;
    color: #ffffff;
    font-size: 0.92rem;
}

.quick-action small {
    color: var(--muted-text);
    font-size: 0.72rem;
}

.quick-open {
    border-color: rgba(52, 211, 153, 0.55);
    background: linear-gradient(180deg, rgba(16, 128, 104, 0.48), rgba(13, 68, 63, 0.58));
    color: #58dca8;
}

.quick-stop {
    border-color: rgba(250, 178, 63, 0.62);
    background: linear-gradient(180deg, rgba(122, 82, 25, 0.52), rgba(62, 47, 25, 0.62));
    color: #ffbd4a;
}

.quick-close {
    border-color: rgba(66, 165, 245, 0.68);
    background: linear-gradient(180deg, rgba(31, 94, 169, 0.58), rgba(20, 49, 103, 0.66));
    color: #42A5F5;
}

.rooms-grid {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 0.75rem;
}

.pieces-config-layout {
    display: grid;
    grid-template-columns: 240px minmax(0, 1fr);
    gap: 0.65rem;
    width: min(1220px, 100%);
}

.shutters-config-layout {
    display: grid;
    grid-template-columns: minmax(620px, 1fr) minmax(420px, 0.72fr);
    gap: 0.65rem;
    width: min(1220px, 100%);
}

.sensors-config-layout {
    display: grid;
    grid-template-columns: minmax(320px, 0.55fr) minmax(520px, 1fr);
    gap: 0.65rem;
    width: min(1120px, 100%);
}

.shutters-config-panel,
.shutter-editor,
.shutter-editor-header,
.sensors-config-panel,
.sensor-editor,
.sensor-editor-header {
    border: 1px solid rgba(66, 165, 245, 0.2);
    border-radius: 8px;
    background: rgba(12, 27, 43, 0.74);
    box-shadow: 0 18px 38px rgba(0, 0, 0, 0.28), inset 0 1px 0 rgba(255, 255, 255, 0.05);
    backdrop-filter: blur(14px);
}

.shutters-config-panel {
    display: grid;
    align-content: start;
    gap: 0.55rem;
    padding: 0.65rem;
}

.sensors-config-panel {
    display: grid;
    align-content: start;
    gap: 0.55rem;
    padding: 0.65rem;
}

.sensors-config-list {
    display: grid;
    gap: 0.45rem;
}

.shutters-config-grid {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 0.45rem;
}

.shutter-config-card {
    display: grid;
    grid-template-columns: 38px minmax(0, 1fr);
    align-items: center;
    gap: 0.42rem;
    min-height: 78px;
    padding: 0.5rem;
    border: 1px solid rgba(255, 255, 255, 0.12);
    border-radius: 8px;
    background: rgba(19, 31, 43, 0.78);
    color: var(--text-color);
    text-align: left;
}

.sensor-config-card {
    display: grid;
    grid-template-columns: 42px minmax(0, 1fr);
    align-items: center;
    gap: 0.5rem;
    min-height: 78px;
    padding: 0.55rem;
    border: 1px solid rgba(255, 255, 255, 0.12);
    border-radius: 8px;
    background: rgba(19, 31, 43, 0.78);
    color: var(--text-color);
    text-align: left;
}

.sensor-config-card.is-active,
.sensor-config-card:hover {
    border-color: rgba(66, 165, 245, 0.86);
    background: rgba(20, 58, 100, 0.74);
}

.shutter-config-card.is-active,
.shutter-config-card:hover {
    border-color: rgba(66, 165, 245, 0.86);
    background: rgba(20, 58, 100, 0.74);
}

.shutter-config-icon,
.shutter-editor-icon,
.sensor-config-icon,
.sensor-editor-icon {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    border-radius: 8px;
    background: rgba(66, 165, 245, 0.16);
    color: #42A5F5;
}

.shutter-config-icon {
    width: 38px;
    height: 38px;
    font-size: 1rem;
}

.sensor-config-icon {
    width: 42px;
    height: 42px;
    font-size: 1.05rem;
}

.shutter-config-main,
.shutter-editor-title,
.sensor-config-main,
.sensor-editor-title {
    display: grid;
    gap: 0.12rem;
    min-width: 0;
}

.shutter-config-main strong,
.shutter-editor-title strong,
.sensor-config-main strong,
.sensor-editor-title strong {
    overflow: hidden;
    color: #ffffff;
    font-size: 0.82rem;
    line-height: 1.1;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.shutter-config-main small,
.shutter-editor-title small,
.sensor-config-main small,
.sensor-editor-title small {
    overflow: hidden;
    color: var(--muted-text);
    font-size: 0.58rem;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.shutter-config-badges {
    display: flex;
    flex-wrap: wrap;
    gap: 0.2rem;
}

.shutter-config-badges .badge {
    padding: 0.12rem 0.3rem;
    font-size: 0.52rem;
}

.shutter-editor {
    display: grid;
    align-content: start;
    gap: 0.55rem;
    padding: 0.65rem;
}

.sensor-editor {
    display: grid;
    align-content: start;
    gap: 0.55rem;
    padding: 0.65rem;
}

.shutter-editor-header {
    display: grid;
    grid-template-columns: 52px minmax(0, 1fr) auto;
    align-items: center;
    gap: 0.6rem;
    padding: 0.55rem;
}

.sensor-editor-header {
    display: grid;
    grid-template-columns: 52px minmax(0, 1fr) auto;
    align-items: center;
    gap: 0.6rem;
    padding: 0.55rem;
}

.shutter-editor-icon {
    width: 50px;
    height: 50px;
    font-size: 1.45rem;
}

.sensor-editor-icon {
    width: 50px;
    height: 50px;
    font-size: 1.35rem;
}

.shutter-editor-title strong,
.sensor-editor-title strong {
    font-size: 1rem;
}

.shutter-config-form,
.sensor-config-form {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 0.5rem;
}

.sensor-metrics {
    grid-column: 1 / -1;
    display: grid;
    grid-template-columns: repeat(4, minmax(0, 1fr));
    gap: 0.45rem;
}

.sensor-metrics .metric {
    min-height: 70px;
}

.config-field,
.config-toggle,
.config-readonly {
    display: grid;
    gap: 0.28rem;
    min-width: 0;
    padding: 0.55rem;
    border: 1px solid rgba(255, 255, 255, 0.1);
    border-radius: 8px;
    background: rgba(11, 25, 41, 0.58);
    overflow: hidden;
}

.config-field span,
.config-readonly span,
.config-toggle span {
    color: var(--muted-text);
    font-size: 0.68rem;
    font-weight: 800;
}

.config-field input,
.config-field select {
    width: 100%;
    min-width: 0;
    max-width: 100%;
    box-sizing: border-box;
    min-height: 34px;
    border: 1px solid rgba(255, 255, 255, 0.12);
    border-radius: 7px;
    background: rgba(16, 31, 48, 0.78);
    color: var(--text-color);
    font: inherit;
    font-size: 0.72rem;
}

.config-field input {
    padding: 0 0.5rem;
}

.config-field select {
    padding: 0 0.35rem;
}

.config-toggle {
    grid-template-columns: auto minmax(0, 1fr);
    align-items: center;
    align-content: center;
}

.config-toggle input {
    width: 18px;
    height: 18px;
    accent-color: #42A5F5;
}

.config-readonly strong {
    overflow: visible;
    color: #ffffff;
    font-size: 0.75rem;
    line-height: 1.28;
    overflow-wrap: anywhere;
    white-space: normal;
}

.technical-field {
    grid-column: 1 / -1;
}

.shutter-config-actions {
    grid-column: 1 / -1;
    display: flex;
    justify-content: flex-end;
}

.shutter-pairing-actions {
    grid-column: 1 / -1;
    display: flex;
    justify-content: flex-end;
    gap: 0.6rem;
    padding-top: 0.4rem;
    border-top: 1px solid rgba(255, 255, 255, 0.08);
}

.shutter-config-actions .primary-btn,
.sensor-config-actions .primary-btn {
    min-width: 160px;
}

.sensor-config-actions {
    grid-column: 1 / -1;
    display: flex;
    justify-content: flex-end;
}

.pieces-config-sidebar,
.piece-editor,
.piece-editor-header,
.piece-column,
.piece-editor-footer,
.piece-create-modal-card {
    border: 1px solid rgba(66, 165, 245, 0.2);
    border-radius: 8px;
    background: rgba(12, 27, 43, 0.74);
    box-shadow: 0 18px 38px rgba(0, 0, 0, 0.28), inset 0 1px 0 rgba(255, 255, 255, 0.05);
    backdrop-filter: blur(14px);
}

.pieces-config-sidebar {
    display: grid;
    align-content: start;
    gap: 0.45rem;
    padding: 0.6rem;
}

.pieces-config-title h2 {
    color: #ffffff;
    font-size: 1.1rem;
    line-height: 1.1;
}

.pieces-config-title p,
.piece-column-heading p {
    color: var(--muted-text);
    font-size: 0.68rem;
}

.piece-add-button {
    gap: 0.35rem;
    min-height: 34px;
    padding: 0.35rem 0.55rem;
    border: 1px solid rgba(66, 165, 245, 0.72);
    background: rgba(21, 81, 152, 0.28);
    color: #42A5F5;
    font-size: 0.74rem;
}

.pieces-config-list {
    display: grid;
    gap: 0.22rem;
}

.piece-list-card {
    display: grid;
    grid-template-columns: 30px minmax(0, 1fr) 14px;
    align-items: center;
    gap: 0.35rem;
    min-height: 44px;
    padding: 0.32rem 0.4rem;
    border: 1px solid rgba(255, 255, 255, 0.12);
    border-radius: 8px;
    background: rgba(19, 31, 43, 0.78);
    color: var(--text-color);
    text-align: left;
}

.piece-list-card.is-active,
.piece-list-card:hover {
    border-color: rgba(66, 165, 245, 0.86);
    background: rgba(20, 58, 100, 0.74);
}

.piece-list-icon,
.piece-editor-icon {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    color: #ffffff;
}

.piece-list-icon {
    font-size: 0.95rem;
}

.piece-list-main {
    display: grid;
    gap: 0.08rem;
    min-width: 0;
}

.piece-list-main strong,
.piece-shutter-main strong {
    color: #ffffff;
    font-size: 0.78rem;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.piece-list-main small,
.piece-shutter-main small {
    color: var(--muted-text);
    font-size: 0.58rem;
}

.piece-list-arrow {
    color: rgba(255, 255, 255, 0.72);
}

.piece-editor {
    display: grid;
    gap: 0.55rem;
    padding: 0;
    border: 0;
    background: transparent;
    box-shadow: none;
    backdrop-filter: none;
}

.piece-editor-header {
    display: grid;
    grid-template-columns: 54px minmax(0, 1fr) auto auto;
    align-items: center;
    gap: 0.6rem;
    min-height: 78px;
    padding: 0.6rem;
}

.piece-editor-icon {
    width: 50px;
    height: 50px;
    border: 1px solid rgba(255, 255, 255, 0.12);
    border-radius: 8px;
    background: rgba(16, 31, 48, 0.72);
    font-size: 1.55rem;
}

.piece-editor-title {
    display: grid;
    gap: 0.16rem;
}

.piece-editor-title strong {
    color: #ffffff;
    font-size: 1.15rem;
    line-height: 1.1;
}

.piece-editor-title small {
    color: var(--muted-text);
    font-size: 0.72rem;
}

.piece-editor-actions {
    display: flex;
    gap: 0.4rem;
}

.outline-btn,
.danger-btn,
.ghost-btn,
.primary-btn,
.piece-shutter-transfer {
    gap: 0.35rem;
    min-height: 32px;
    padding: 0.34rem 0.6rem;
    border-radius: 7px;
    font-size: 0.72rem;
}

.outline-btn {
    border: 1px solid rgba(66, 165, 245, 0.58);
    background: rgba(21, 81, 152, 0.18);
    color: #42A5F5;
}

.danger-btn {
    border: 1px solid rgba(239, 68, 68, 0.55);
    background: rgba(127, 29, 29, 0.18);
    color: #ff7272;
}

.primary-btn {
    border: 1px solid rgba(66, 165, 245, 0.72);
    background: linear-gradient(180deg, #4aa9ef, #0b64d8);
    color: #ffffff;
}

.ghost-btn {
    border: 1px solid rgba(255, 255, 255, 0.14);
    background: rgba(255, 255, 255, 0.04);
    color: var(--text-color);
}

.piece-columns {
    display: grid;
    grid-template-columns: minmax(0, 1fr) 42px minmax(0, 1fr);
    gap: 0.55rem;
}

.piece-column {
    display: flex;
    flex-direction: column;
    min-height: 300px;
    padding: 0.55rem;
}

.piece-column-heading {
    margin-bottom: 0.45rem;
}

.piece-column-heading h3 {
    color: #ffffff;
    font-size: 0.86rem;
}

.piece-transfer-controls {
    display: grid;
    align-content: center;
    gap: 0.5rem;
}

.transfer-hint {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 36px;
    height: 40px;
    border: 1px solid rgba(255, 255, 255, 0.12);
    border-radius: 8px;
    background: rgba(19, 31, 43, 0.78);
    color: #ffffff;
    font-size: 0.95rem;
}

.piece-shutter-list {
    display: flex;
    flex-direction: column;
    gap: 0.22rem;
    overflow: auto;
}

.piece-shutter-card {
    display: grid;
    grid-template-columns: 14px 28px minmax(0, 1fr) 32px;
    align-items: center;
    gap: 0.38rem;
    flex: 0 0 58px;
    height: 58px;
    min-height: 58px;
    max-height: 58px;
    padding: 0.35rem 0.5rem;
    border: 1px solid rgba(66, 165, 245, 0.22);
    border-radius: 8px;
    background: rgba(11, 25, 41, 0.7);
}

.piece-shutter-handle {
    color: rgba(255, 255, 255, 0.64);
    text-align: center;
}

.piece-shutter-icon {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 28px;
    height: 28px;
    border-radius: 6px;
    background: rgba(66, 165, 245, 0.12);
    color: #42A5F5;
    font-size: 0.92rem;
}

.piece-shutter-main {
    display: grid;
    gap: 0.08rem;
    min-width: 0;
}

.piece-shutter-main .badge {
    justify-self: start;
    padding: 0.13rem 0.32rem;
    font-size: 0.56rem;
}

.piece-shutter-transfer {
    justify-content: center;
    width: 30px;
    padding: 0;
    border: 1px solid rgba(66, 165, 245, 0.48);
    background: rgba(21, 81, 152, 0.22);
    color: #42A5F5;
}

.piece-drop-zone {
    display: grid;
    place-items: center;
    gap: 0.35rem;
    min-height: 62px;
    border: 1px dashed rgba(66, 165, 245, 0.44);
    border-radius: 8px;
    color: var(--muted-text);
    text-align: center;
}

.piece-editor-footer {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0.5rem;
}

.piece-create-modal-card {
    width: min(1180px, calc(100% - 2rem));
    padding: 1rem;
}

.piece-create-form {
    display: grid;
    grid-template-columns: minmax(260px, 0.9fr) minmax(520px, 1.6fr);
    align-items: end;
    gap: 0.9rem;
}

.piece-name-field,
.piece-icon-picker {
    display: grid;
    gap: 0.45rem;
    min-width: 0;
}

.piece-name-field span,
.piece-icon-picker legend {
    color: var(--muted-text);
    font-size: 0.8rem;
}

.piece-name-field input {
    min-height: 48px;
    padding: 0.7rem 0.85rem;
    border: 1px solid rgba(255, 255, 255, 0.14);
    border-radius: 8px;
    background: rgba(11, 25, 41, 0.7);
    color: var(--text-color);
    font: inherit;
}

.piece-icon-picker {
    grid-template-columns: repeat(8, 48px);
    border: 0;
}

.piece-icon-picker legend {
    grid-column: 1 / -1;
}

.piece-icon-picker label {
    cursor: pointer;
}

.piece-icon-picker input {
    position: absolute;
    opacity: 0;
}

.piece-icon-picker span {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 48px;
    height: 48px;
    border: 1px solid rgba(255, 255, 255, 0.14);
    border-radius: 8px;
    background: rgba(16, 31, 48, 0.72);
    color: #ffffff;
    font-size: 1.2rem;
}

.piece-icon-picker input:checked + span {
    border-color: #42A5F5;
    background: rgba(21, 81, 152, 0.52);
    color: #42A5F5;
}

.piece-create-submit {
    grid-column: 2;
    justify-self: end;
    width: min(260px, 100%);
    min-height: 48px;
}

@media (min-width: 1181px) {
    body:not(.login-page) {
        height: var(--app-height);
        overflow: hidden;
    }

    .header {
        position: relative;
        z-index: 1300;
        flex: 0 0 var(--header-height);
    }

    .home-layout {
        height: calc(var(--app-height) - var(--header-height));
        min-height: 0;
        overflow: hidden;
    }

    .somfy-menu {
        height: calc(var(--app-height) - var(--header-height));
        min-height: 0;
        overflow-y: auto;
        overscroll-behavior: contain;
    }

    .shutters-workspace {
        height: calc(var(--app-height) - var(--header-height));
        min-height: 0;
        overflow-x: hidden;
        overflow-y: auto;
        overscroll-behavior: contain;
    }

    .house-workspace {
        min-height: 0;
    }
}

.room-card {
    display: grid;
    grid-template-columns: 54px minmax(0, 1fr) 22px;
    align-items: center;
    gap: 0.75rem;
    min-height: 92px;
    padding: 0.85rem;
    border: 1px solid rgba(255, 255, 255, 0.14);
    border-radius: 8px;
    background: rgba(19, 31, 43, 0.78);
    box-shadow: 0 12px 26px rgba(0, 0, 0, 0.28);
    color: var(--text-color);
    text-align: left;
    backdrop-filter: blur(12px);
}

.room-card:hover {
    border-color: rgba(66, 165, 245, 0.72);
    background: rgba(30, 52, 76, 0.82);
}

.room-card-icon {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 54px;
    height: 54px;
    color: #ffffff;
    font-size: 1.75rem;
}

.room-card-main {
    display: grid;
    gap: 0.2rem;
    min-width: 0;
}

.room-card-main strong {
    color: #ffffff;
    font-size: 0.95rem;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.room-card-main small {
    color: var(--muted-text);
    font-size: 0.72rem;
}

.room-card-main .badge {
    justify-self: start;
    margin-top: 0.1rem;
}

.room-card-arrow {
    color: rgba(255, 255, 255, 0.72);
}

.room-view {
    display: flex;
    flex-direction: column;
    gap: 1rem;
}

.room-view[hidden],
.home-view[hidden],
.pieces-view[hidden],
.shutters-view[hidden],
.sensors-view[hidden],
.security-view[hidden],
.sync-view[hidden] {
    display: none;
}

.page-card {
    width: min(760px, 100%);
    padding: 1rem;
    border: 1px solid rgba(255, 255, 255, 0.14);
    border-radius: 8px;
    background: rgba(19, 31, 43, 0.78);
    box-shadow: 0 12px 26px rgba(0, 0, 0, 0.28);
    backdrop-filter: blur(12px);
}

.page-card-header {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 1rem;
    margin-bottom: 1rem;
}

.page-card-header h3 {
    color: #ffffff;
    font-size: 1.05rem;
    margin: 0 0 0.25rem;
}

.page-card-header p {
    color: var(--muted-text);
    font-size: 0.86rem;
}

.page-card-icon {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 52px;
    height: 52px;
    border-radius: 8px;
    background: rgba(66, 165, 245, 0.14);
    color: var(--highlight-color);
    font-size: 1.45rem;
    flex: 0 0 auto;
}

.sync-card {
    width: min(980px, 100%);
}

.security-card {
    width: min(980px, 100%);
}

.security-actions,
.password-section {
    display: grid;
    gap: 0.75rem;
    padding-top: 1rem;
    margin-top: 1rem;
    border-top: 1px solid rgba(255, 255, 255, 0.12);
}

.security-actions {
    grid-template-columns: minmax(220px, 1fr) minmax(320px, 1.35fr);
    align-items: center;
}

.security-section-title {
    display: grid;
    gap: 0.16rem;
}

.security-section-title strong {
    color: #ffffff;
    font-size: 0.95rem;
}

.security-section-title span {
    color: var(--muted-text);
    font-size: 0.8rem;
}

.security-button-row {
    justify-content: flex-end;
}

.security-button-row button {
    flex: 1 1 190px;
}

.room-topbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 1rem;
}

.back-link {
    gap: 0.45rem;
    min-height: 38px;
    padding: 0.4rem 0.65rem;
    border: 1px solid rgba(255, 255, 255, 0.14);
    background: rgba(12, 21, 31, 0.62);
}

.room-actions {
    display: flex;
    gap: 0.55rem;
}

.mini-command {
    gap: 0.35rem;
    min-height: 38px;
    padding: 0.42rem 0.75rem;
    border-radius: 7px;
    border: 1px solid rgba(255, 255, 255, 0.16);
    background: rgba(255, 255, 255, 0.07);
}

.mini-up {
    border-color: rgba(52, 211, 153, 0.48);
    background: rgba(25, 109, 79, 0.38);
    color: #8de7b8;
}

.mini-stop {
    border-color: rgba(250, 178, 63, 0.55);
    background: rgba(118, 79, 23, 0.36);
    color: #ffd27a;
}

.mini-down {
    border-color: rgba(66, 165, 245, 0.6);
    background: rgba(26, 80, 156, 0.38);
    color: #73bdff;
}

.room-heading {
    display: flex;
    align-items: center;
    gap: 0.8rem;
}

.room-heading-icon {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 46px;
    height: 46px;
    color: #ffffff;
    font-size: 1.6rem;
}

.room-shutters-grid {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 0.8rem;
}

.room-shutter-card {
    display: grid;
    gap: 0.8rem;
    min-height: 300px;
    padding: 0.9rem;
    border: 1px solid rgba(255, 255, 255, 0.14);
    border-radius: 8px;
    background: rgba(27, 39, 50, 0.86);
    box-shadow: 0 12px 26px rgba(0, 0, 0, 0.28);
    backdrop-filter: blur(12px);
}

.room-shutter-header {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 0.75rem;
}

.room-shutter-header strong {
    display: block;
    color: #ffffff;
    font-size: 0.96rem;
}

.room-shutter-header small {
    color: var(--muted-text);
    font-size: 0.72rem;
}

.roller-preview {
    display: grid;
    justify-items: center;
    gap: 0.55rem;
    min-height: 170px;
    padding: 0;
    background: transparent;
    color: var(--muted-text);
}

.roller-preview:hover {
    background: transparent;
    color: #ffffff;
}

.roller-box {
    position: relative;
    display: block;
    width: min(170px, 78%);
    aspect-ratio: 0.82;
    border-bottom: 4px solid #b9c6d3;
}

.roller-top {
    position: absolute;
    left: -8px;
    right: -8px;
    top: 0;
    height: 18px;
    background: linear-gradient(180deg, #edf1f5, #b9c2ca);
    box-shadow: 0 2px 7px rgba(0, 0, 0, 0.38);
}

.roller-curtain {
    position: absolute;
    left: 0;
    right: 0;
    top: 18px;
    bottom: 0;
    background:
        repeating-linear-gradient(180deg, #eef2f6 0 9px, #c9d0d8 10px 13px),
        linear-gradient(180deg, #f7f8f9, #d3d9df);
    border: 1px solid rgba(255, 255, 255, 0.55);
    box-shadow: inset 0 0 18px rgba(34, 56, 78, 0.2);
}

.roller-side {
    position: absolute;
    top: 18px;
    bottom: 0;
    width: 5px;
    background: #c4cbd2;
}

.roller-side-left {
    left: -6px;
}

.roller-side-right {
    right: -6px;
}

.room-shutter-actions {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 0.55rem;
}

.room-shutter-actions .mini-command {
    min-height: 44px;
    padding: 0.45rem;
}

.workspace-header {
    display: flex;
    align-items: flex-end;
    justify-content: space-between;
    gap: 1rem;
    margin-bottom: 1rem;
}

.shutters-grid {
    display: grid;
    grid-template-columns: repeat(4, minmax(0, 1fr));
    gap: 0.75rem;
}

.shutter-card {
    position: relative;
    align-items: stretch;
    justify-content: flex-start;
    gap: 0.55rem;
    min-height: 96px;
    padding: 0.85rem 4.1rem 0.75rem 0.75rem;
    border: 1px solid var(--border-color);
    border-radius: 8px;
    background-color: var(--primary-color);
    box-shadow: var(--shadow);
    color: var(--text-color);
    flex-direction: column;
    text-align: left;
}

.shutter-card:hover,
.shutter-card.is-selected {
    background-color: rgba(66, 165, 245, 0.12);
    border-color: rgba(66, 165, 245, 0.7);
}

.shutter-icon {
    position: absolute;
    top: 0.75rem;
    right: 0.75rem;
    width: 44px;
    height: 44px;
    border-radius: 8px;
    background-color: rgba(66, 165, 245, 0.14);
    color: var(--highlight-color);
}

.shutter-icon svg,
.shutter-icon i {
    width: 1.7rem;
    height: 1.7rem;
    font-size: 1.7rem;
}

.shutter-main,
.shutter-state {
    display: grid;
    gap: 0.32rem;
    min-width: 0;
}

.shutter-state .badge {
    justify-self: start;
    width: auto;
    max-width: max-content;
}

.shutter-main strong {
    color: #ffffff;
    font-size: 0.98rem;
    font-weight: 650;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.shutter-main small,
.shutter-state small {
    color: var(--muted-text);
    font-size: 0.76rem;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.control-buttons {
    display: grid;
    grid-template-columns: repeat(3, minmax(86px, 1fr));
    gap: 0.6rem;
}

.control-btn {
    min-height: 52px;
    gap: 0.45rem;
    padding: 0.7rem 0.8rem;
    border-radius: 8px;
    color: white;
    font-weight: 800;
    box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.18);
}

.control-up {
    background: linear-gradient(180deg, #6DA04D, #4F8236);
}

.control-stop {
    background: linear-gradient(180deg, #DA9028, #C4771F);
}

.control-down {
    background: linear-gradient(180deg, #426ED0, #3159AF);
}

.control-up:hover {
    background: linear-gradient(180deg, #79AE58, #5B9141);
}

.control-stop:hover {
    background: linear-gradient(180deg, #E7A13A, #D08324);
}

.control-down:hover {
    background: linear-gradient(180deg, #527DDD, #3A66C0);
}

.modal[hidden] {
    display: none;
}

.modal {
    position: fixed;
    inset: 0;
    z-index: 2000;
    display: grid;
    place-items: center;
    padding: 1.2rem;
}

.modal-backdrop {
    position: absolute;
    inset: 0;
    background:
        linear-gradient(90deg, rgba(8, 13, 20, 0.34), rgba(8, 13, 20, 0.12)),
        linear-gradient(180deg, rgba(8, 13, 20, 0.06), rgba(8, 13, 20, 0.18));
    backdrop-filter: blur(4px);
}

.modal-card {
    position: relative;
    width: min(860px, 100%);
    max-height: min(760px, calc(100dvh - 2rem));
    overflow: auto;
    margin: 0;
    border-color: rgba(255, 255, 255, 0.16);
    background: rgba(19, 31, 43, 0.78);
    box-shadow: 0 22px 60px rgba(0, 0, 0, 0.38), inset 0 1px 0 rgba(255, 255, 255, 0.08);
    backdrop-filter: blur(18px);
}

.modal-header {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 1rem;
    margin-bottom: 1rem;
}

.shutter-modal-card {
    width: min(520px, calc(100% - 2rem));
}

.shutter-modal .control-buttons {
    margin-top: 1rem;
}

.shutter-modal .action-status {
    margin: 0.8rem 0 0;
}

.icon-btn {
    width: 40px;
    min-height: 40px;
    padding: 0;
    border-radius: 8px;
    background-color: rgba(255, 255, 255, 0.08);
}

.modal-open {
    overflow: hidden;
}

@media (max-width: 1180px) {
    :root {
        --header-height: 54px;
    }

    body {
        overflow: hidden;
    }

    .header {
        height: var(--header-height);
        justify-content: flex-start;
        padding: 0 10px;
    }

    .header h1 {
        font-size: 1.1rem;
        max-width: calc(100% - 118px);
        overflow: hidden;
        text-overflow: ellipsis;
        white-space: nowrap;
    }

    .header-brand {
        justify-content: flex-start;
        max-width: calc(100% - 118px);
    }

    .header-brand h1 {
        max-width: none;
    }

    .header-brand img {
        width: 28px;
        height: 28px;
        border-radius: 8px;
    }

    .header-actions {
        right: 8px;
    }

    .logout-btn {
        width: 42px;
        min-height: 42px;
        padding: 0;
        border-radius: 6px;
        font-size: 0.78rem;
        background: transparent;
    }

    .logout-icon {
        display: inline-flex;
    }

    .logout-icon svg,
    .logout-icon i {
        width: 1.35rem;
        height: 1.35rem;
        font-size: 1.35rem;
    }

    .logout-label {
        display: none;
    }

    .home-layout {
        display: block;
        min-height: calc(var(--app-height) - var(--header-height));
    }

    .somfy-menu {
        position: fixed;
        left: 0;
        right: 0;
        top: auto;
        bottom: 0;
        z-index: 1200;
        display: grid;
        grid-template-columns: repeat(6, minmax(0, 1fr));
        gap: 8px;
        width: 100%;
        min-height: 0;
        height: calc(64px + env(safe-area-inset-bottom));
        padding: 8px 14px calc(14px + env(safe-area-inset-bottom));
        border: 0;
        border-radius: 0;
        background: rgba(22, 26, 31, 0.96);
        box-shadow: 0 -10px 28px rgba(0, 0, 0, 0.32);
        backdrop-filter: blur(14px);
    }

    .somfy-menu::before {
        content: "";
        position: absolute;
        left: 0;
        right: 0;
        top: 0;
        height: 1px;
        background: rgba(255, 255, 255, 0.16);
    }

    .menu-action {
        position: relative;
        flex-direction: column;
        gap: 2px;
        min-height: 0;
        padding: 4px 6px;
        border: 0;
        border-radius: 9px;
        background: rgba(35, 55, 91, 0.88);
        color: rgba(255, 255, 255, 0.78);
        font-size: 0.58rem;
        font-weight: 850;
        line-height: 1;
    }

    .menu-action .menu-label-full {
        display: none;
    }

    .menu-action .menu-label-short {
        display: inline;
    }

    .menu-action:first-child {
        color: #8DDB6D;
    }

    .menu-action:last-child {
        color: #7DCBF1;
    }

    .menu-action:hover {
        background: rgba(78, 120, 212, 0.34);
        color: #7FB0FF;
    }

    .menu-action .icon svg,
    .menu-action .icon i {
        width: 1.1rem;
        height: 1.1rem;
        font-size: 1.1rem;
    }

    .shutters-workspace {
        height: calc(var(--app-height) - var(--header-height));
        overflow-y: auto;
        padding: 0.7rem 10px calc(82px + env(safe-area-inset-bottom));
    }

    .house-workspace {
        min-height: calc(var(--app-height) - var(--header-height));
        background:
            linear-gradient(180deg, rgba(8, 13, 20, 0.08) 0%, rgba(8, 13, 20, 0.20) 42%, rgba(8, 13, 20, 0.36) 100%),
            url("images/house-background-crop.png") center center / cover no-repeat;
    }

    .home-view,
    .pieces-view,
    .shutters-view,
    .sensors-view,
    .room-view,
    .security-view,
    .sync-view {
        width: 100%;
        min-height: auto;
        padding: 0.65rem 0.1rem;
    }

    .home-copy,
    .page-copy {
        margin: 1.5rem 0 1.25rem;
    }

    .home-copy h2,
    .room-heading h2,
    .page-copy h2 {
        font-size: 1.35rem;
        line-height: 1.18;
    }

    .page-card {
        padding: 0.85rem;
    }

    .page-card-header {
        align-items: center;
    }

    .quick-actions {
        grid-template-columns: repeat(3, minmax(0, 1fr));
        gap: 0.45rem;
    }

    .quick-action {
        gap: 0.2rem;
        min-height: 92px;
        padding: 0.55rem 0.35rem;
        text-align: center;
    }

    .quick-action .icon i {
        font-size: 1.65rem;
    }

    .quick-action strong {
        margin: 0.15rem 0 0;
        font-size: 0.72rem;
        line-height: 1.05;
    }

    .quick-action small {
        display: none;
    }

    .rooms-grid {
        grid-template-columns: repeat(3, minmax(0, 1fr));
        gap: 0.45rem;
    }

    .pieces-config-layout {
        grid-template-columns: 1fr;
        gap: 0.5rem;
    }

    .shutters-config-layout {
        grid-template-columns: 1fr;
        gap: 0.5rem;
    }

    .sensors-config-layout {
        grid-template-columns: 1fr;
        gap: 0.5rem;
    }

    .sensor-editor-header {
        grid-template-columns: 42px minmax(0, 1fr);
    }

    .sensor-editor-header .badge {
        grid-column: 2;
        justify-self: start;
    }

    .sensor-editor-icon {
        width: 40px;
        height: 40px;
        font-size: 1.05rem;
    }

    .sensor-config-form {
        grid-template-columns: 1fr;
    }

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

    .shutters-config-grid {
        grid-template-columns: repeat(2, minmax(0, 1fr));
        gap: 0.32rem;
    }

    .shutter-config-card {
        grid-template-columns: 30px minmax(0, 1fr);
        min-height: 60px;
        padding: 0.38rem;
    }

    .shutter-config-icon {
        width: 30px;
        height: 30px;
        font-size: 0.86rem;
    }

    .shutter-editor-header {
        grid-template-columns: 42px minmax(0, 1fr);
    }

    .shutter-editor-header .badge {
        grid-column: 2;
        justify-self: start;
    }

    .shutter-editor-icon {
        width: 40px;
        height: 40px;
        font-size: 1.1rem;
    }

    .shutter-config-form {
        grid-template-columns: 1fr;
    }

    .pieces-config-sidebar {
        gap: 0.4rem;
        padding: 0.55rem;
    }

    .pieces-config-list {
        grid-template-columns: repeat(2, minmax(0, 1fr));
        gap: 0.3rem;
    }

    .piece-list-card {
        grid-template-columns: 28px minmax(0, 1fr) 12px;
        min-height: 42px;
        padding: 0.3rem 0.35rem;
    }

    .piece-list-main strong {
        font-size: 0.72rem;
        white-space: normal;
    }

    .piece-editor-header {
        grid-template-columns: 46px minmax(0, 1fr);
        gap: 0.5rem;
        min-height: auto;
        padding: 0.55rem;
    }

    .piece-editor-header .badge {
        grid-column: 2;
        justify-self: start;
    }

    .piece-editor-icon {
        width: 44px;
        height: 44px;
        font-size: 1.3rem;
    }

    .piece-editor-title strong {
        font-size: 1rem;
    }

    .piece-editor-actions {
        grid-column: 1 / -1;
        width: 100%;
    }

    .piece-editor-actions button {
        flex: 1 1 0;
    }

    .piece-columns {
        grid-template-columns: 1fr;
    }

    .piece-transfer-controls {
        display: none;
    }

    .piece-column {
        min-height: auto;
        padding: 0.5rem;
    }

    .piece-shutter-card {
        grid-template-columns: 14px 28px minmax(0, 1fr) 32px;
        height: 58px;
        min-height: 58px;
        max-height: 58px;
        padding: 0.32rem;
    }

    .piece-editor-footer {
        align-items: stretch;
        flex-direction: column;
        gap: 0.5rem;
    }

    .piece-create-form {
        grid-template-columns: 1fr;
    }

    .piece-icon-picker {
        grid-template-columns: repeat(5, 48px);
    }

    .piece-create-submit {
        grid-column: 1;
        justify-self: stretch;
        width: 100%;
    }

    .room-card {
        display: flex;
        flex-direction: column;
        align-items: center;
        justify-content: center;
        gap: 0.28rem;
        min-height: 108px;
        padding: 0.55rem 0.35rem;
        text-align: center;
    }

    .room-card-icon {
        width: 34px;
        height: 30px;
        font-size: 1.35rem;
    }

    .room-card-main {
        justify-items: center;
        gap: 0.12rem;
        width: 100%;
    }

    .room-card-main strong {
        width: 100%;
        font-size: 0.68rem;
        line-height: 1.08;
        white-space: normal;
    }

    .room-card-main small {
        font-size: 0.58rem;
    }

    .room-card-main .badge {
        max-width: 100%;
        padding: 0.12rem 0.28rem;
        font-size: 0.52rem;
    }

    .room-card-arrow {
        display: none;
    }

    .room-topbar {
        align-items: stretch;
        flex-direction: column;
        gap: 0.65rem;
    }

    .room-actions {
        display: grid;
        grid-template-columns: repeat(3, minmax(0, 1fr));
        gap: 0.45rem;
    }

    .room-actions .mini-command {
        flex-direction: column;
        gap: 3px;
        min-height: 56px;
        padding: 0.45rem 0.35rem;
        font-size: 0.72rem;
    }

    .room-shutters-grid {
        grid-template-columns: 1fr;
        gap: 0.65rem;
    }

    .room-shutter-card {
        min-height: 250px;
        padding: 0.75rem;
    }

    .roller-box {
        width: min(150px, 68%);
    }

    .section-header {
        align-items: flex-start;
        flex-direction: column;
    }

    .button-row {
        justify-content: flex-start;
        width: 100%;
    }

    .button-row button {
        flex: 1 1 210px;
    }

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

    .workspace-header {
        align-items: flex-end;
        flex-direction: row;
        gap: 0.75rem;
        margin-bottom: 0.65rem;
    }

    .workspace-header h2 {
        font-size: 1rem;
    }

    .workspace-header .section-subtitle {
        font-size: 0.78rem;
        white-space: nowrap;
    }

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

    .shutter-card {
        min-height: 78px;
        gap: 0.35rem;
        padding: 0.65rem 3.65rem 0.6rem 0.6rem;
        background-color: #202020;
        border-color: rgba(255, 255, 255, 0.12);
    }

    .shutter-icon {
        top: 0.6rem;
        right: 0.6rem;
        width: 40px;
        height: 40px;
    }

    .shutter-icon svg,
    .shutter-icon i {
        width: 1.55rem;
        height: 1.55rem;
        font-size: 1.55rem;
    }

    .shutter-main strong {
        font-size: 0.9rem;
        line-height: 1.15;
    }

    .shutter-main small,
    .shutter-state small {
        font-size: 0.68rem;
        line-height: 1.1;
    }

    .badge {
        font-size: 0.66rem;
        padding: 0.16rem 0.4rem;
    }

    .control-buttons {
        grid-template-columns: repeat(3, minmax(0, 1fr));
    }

    .control-btn {
        min-height: 58px;
        flex-direction: column;
        gap: 4px;
        font-size: 0.78rem;
    }

    .modal {
        align-items: center;
        padding: 0.75rem;
    }

    .shutter-modal {
        align-items: center;
        padding: 1rem;
    }

    .modal-card {
        width: min(520px, 100%);
        max-height: calc(100dvh - 1.5rem);
        border: 1px solid rgba(255, 255, 255, 0.16);
        border-radius: 8px;
        padding: 0.9rem;
    }

    .shutter-modal-card {
        width: min(420px, 100%);
        border: 1px solid var(--border-color);
        border-radius: 8px;
    }

    .sync-card {
        display: flex;
        flex-direction: column;
        max-height: calc(100dvh - var(--header-height) - 100px - env(safe-area-inset-bottom));
        overflow: hidden;
    }

    .password-form {
        grid-template-columns: 1fr;
    }

    .password-form button {
        grid-column: auto;
    }

    .security-actions {
        grid-template-columns: 1fr;
        align-items: stretch;
    }

    .security-button-row {
        justify-content: stretch;
    }

    .sync-card .table-wrap {
        flex: 1 1 auto;
        min-height: 0;
        margin-top: 0.85rem;
        overflow-y: auto;
        overflow-x: hidden;
        padding-right: 0.15rem;
        -webkit-overflow-scrolling: touch;
    }

    .sync-card table,
    .sync-card thead,
    .sync-card tbody,
    .sync-card tr,
    .sync-card td {
        display: block;
        width: 100%;
    }

    .sync-card table {
        min-width: 0;
    }

    .sync-card thead {
        display: none;
    }

    .sync-card tbody {
        display: grid;
        gap: 0.6rem;
    }

    .sync-card tr {
        border: 1px solid var(--border-color);
        border-radius: 8px;
        background: rgba(255, 255, 255, 0.05);
        padding: 0.65rem;
    }

    .sync-card td {
        display: grid;
        grid-template-columns: 98px minmax(0, 1fr);
        gap: 0.75rem;
        align-items: center;
        border: 0;
        padding: 0.32rem 0;
        white-space: normal;
        overflow-wrap: anywhere;
        font-size: 0.82rem;
    }

    .sync-card td::before {
        content: attr(data-label);
        color: var(--muted-text);
        font-size: 0.72rem;
        font-weight: 800;
        text-transform: uppercase;
    }

    .sync-card td .badge {
        justify-self: start;
        width: auto;
        max-width: max-content;
    }
}

@media (max-width: 420px) {
    .summary-grid {
        grid-template-columns: 1fr;
    }

    .login-page {
        padding: 16px;
    }
}

.security-link-button {
    align-items: center;
    background: var(--highlight-color);
    border-radius: 8px;
    color: #fff;
    display: inline-flex;
    font-weight: 700;
    gap: 8px;
    min-height: 42px;
    padding: 0 16px;
    text-decoration: none;
}

.security-link-button:hover {
    filter: brightness(1.05);
}

/* HomeIdentity */
.auth-shell {
    align-items: center;
    background: var(--secondary-color);
    display: grid;
    min-height: 100vh;
    padding: 24px;
    place-items: center;
}

.auth-card {
    background-color: var(--primary-color);
    border: 1px solid var(--border-color);
    border-radius: 8px;
    box-shadow: var(--shadow);
    padding: 28px;
    width: min(420px, 100%);
}

.auth-card.wide {
    width: min(560px, 100%);
}

.brand-mark {
    align-items: center;
    background-color: var(--highlight-color);
    border-radius: 7px;
    color: #fff;
    display: flex;
    font-size: 0.95rem;
    font-weight: 800;
    height: 44px;
    justify-content: center;
    margin-bottom: 12px;
    width: 44px;
}

.auth-card h1,
.auth-card h2 {
    margin: 0 0 0.5rem;
}

.muted {
    color: var(--muted-text);
}

.separator {
    color: var(--muted-text);
    margin: 16px 0;
    text-align: center;
}

.error {
    background-color: rgba(192, 54, 44, 0.15);
    border: 1px solid rgba(192, 54, 44, 0.55);
    border-radius: 6px;
    color: #ffb4aa;
    display: none;
    margin-bottom: 14px;
    padding: 10px;
}

.error.is-visible {
    display: block;
}

label {
    color: var(--text-color);
    display: grid;
    font-weight: 600;
    gap: 6px;
    margin: 14px 0;
}

input {
    background-color: var(--input-bg);
    border: 1px solid var(--border-color);
    border-radius: 6px;
    color: var(--text-color);
    font: inherit;
    height: 44px;
    padding: 0 12px;
}

input::placeholder {
    color: var(--muted-text);
}

.primary,
.passkey-btn,
.secondary {
    height: 40px;
    padding: 0 14px;
}

.primary,
.passkey-btn {
    width: 100%;
}

.secondary {
    background-color: rgba(255, 255, 255, 0.08);
    color: var(--text-color);
}

.secondary:hover {
    background-color: rgba(255, 255, 255, 0.18);
}

.topbar {
    align-items: center;
    background: rgba(30, 30, 30, 0.92);
    border-bottom: 1px solid rgba(255, 255, 255, 0.08);
    box-shadow: var(--shadow);
    color: var(--text-color);
    display: flex;
    height: 56px;
    justify-content: space-between;
    padding: 0 24px;
}

.topbar h1 {
    font-size: 1.25rem;
    font-weight: 500;
    margin: 0;
}

.topbar-brand {
    align-items: baseline;
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    min-width: 0;
}

.topbar-brand span {
    color: var(--muted-text);
    font-size: 0.9rem;
    font-weight: 600;
    white-space: nowrap;
}

.topbar nav {
    align-items: center;
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
    justify-content: flex-end;
}

.topbar a {
    background-color: rgba(255, 255, 255, 0.08);
    border-radius: 6px;
    color: var(--text-color);
    font-size: 0.9rem;
    padding: 6px 10px;
    text-decoration: none;
}

.topbar a:hover {
    background-color: rgba(255, 255, 255, 0.18);
}

.topbar-button {
    background-color: rgba(66, 165, 245, 0.16);
    border: 1px solid rgba(66, 165, 245, 0.42);
    border-radius: 6px;
    color: var(--highlight-color);
    min-height: 34px;
    padding: 6px 10px;
}

.layout {
    display: grid;
    gap: 1rem;
    margin: 0 auto;
    max-width: 1120px;
    padding: 1rem;
    width: 100%;
}

.panel-title {
    font-family: inherit;
    font-size: 1.45rem;
    font-weight: 800;
    line-height: 1.15;
    margin: 0 0 0.8rem;
}

.actions {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
    margin-top: 1rem;
}

.actions .primary,
.actions .secondary {
    width: auto;
}

.chips,
.scope-row {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
}

.chips span {
    background-color: rgba(66, 165, 245, 0.15);
    border: 1px solid rgba(66, 165, 245, 0.45);
    border-radius: 6px;
    color: var(--text-color);
    padding: 6px 10px;
}

.scope-button {
    border-radius: 6px;
    height: 34px;
    padding: 0 10px;
}

.scope-button.is-allowed {
    background: rgba(129, 199, 132, 0.16);
    border: 1px solid rgba(129, 199, 132, 0.42);
    color: var(--status-color);
}

.scope-button.is-denied {
    background: rgba(239, 83, 80, 0.16);
    border: 1px solid rgba(239, 83, 80, 0.42);
    color: #ef5350;
}

.scope-button:disabled {
    cursor: default;
    opacity: 0.9;
}

.user-list {
    display: grid;
    gap: 10px;
}

.user-row,
.table-list article {
    background-color: rgba(255, 255, 255, 0.03);
    border: 1px solid var(--border-color);
    border-radius: 6px;
    padding: 12px;
}

.user-row {
    align-items: center;
    display: grid;
    gap: 12px;
    grid-template-columns: minmax(160px, 240px) 1fr;
}

.user-row small,
.table-list small,
.audit-row small {
    color: var(--muted-text);
}

.table-list {
    display: grid;
    gap: 8px;
}

.table-list article {
    align-items: center;
    display: grid;
    gap: 4px 12px;
    grid-template-columns: 1fr auto;
}

.audit-list {
    display: grid;
    gap: 4px;
    overflow-x: auto;
}

.audit-header {
    align-items: center;
    display: flex;
    gap: 12px;
    justify-content: space-between;
    margin-bottom: 10px;
}

.audit-filter {
    display: inline-flex;
    gap: 6px;
}

.audit-filter a {
    border: 1px solid var(--border-color);
    border-radius: 6px;
    color: var(--muted-text);
    font-size: 0.78rem;
    font-weight: 700;
    padding: 5px 9px;
    text-decoration: none;
    white-space: nowrap;
}

.audit-filter a.is-active {
    background: rgba(66, 165, 245, 0.16);
    border-color: rgba(66, 165, 245, 0.42);
    color: var(--highlight-color);
}

.audit-row {
    align-items: center;
    border-bottom: 1px solid var(--border-color);
    display: grid;
    font-size: 0.78rem;
    gap: 8px;
    grid-template-columns: 132px 168px 86px 178px 116px 120px minmax(130px, 1fr);
    min-width: 980px;
    padding: 6px 0;
}

.audit-row > * {
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.audit-row time {
    color: var(--muted-text);
    font-variant-numeric: tabular-nums;
}

.audit-action {
    border-radius: 999px;
    display: inline-block;
    font-size: 0.72rem;
    font-weight: 800;
    letter-spacing: 0;
    padding: 4px 10px;
    text-align: center;
    width: max-content;
    max-width: 100%;
}

.audit-action.is-ok {
    background: rgba(129, 199, 132, 0.16);
    border: 1px solid rgba(129, 199, 132, 0.42);
    color: var(--status-color);
}

.audit-action.is-denied {
    background: rgba(239, 83, 80, 0.16);
    border: 1px solid rgba(239, 83, 80, 0.42);
    color: #ef5350;
}

.token-box {
    background-color: rgba(129, 199, 132, 0.16);
    border: 1px solid rgba(129, 199, 132, 0.42);
    border-radius: 6px;
    margin: 12px 0;
    padding: 12px;
}

@media (max-width: 760px) {
    .user-row,
    .table-list article {
        grid-template-columns: 1fr;
    }
}

@media (max-width: 640px) {
    .topbar {
        align-items: flex-start;
        flex-direction: column;
        gap: 10px;
        height: auto;
        padding: 16px;
    }

    .topbar nav {
        justify-content: flex-start;
    }
}

.dashboard-page {
    height: auto;
    min-height: 100vh;
    overflow-x: hidden;
    overflow-y: auto !important;
}

html:has(body.dashboard-page) {
    height: auto !important;
    min-height: 100%;
    overflow-y: auto !important;
}

body.dashboard-page {
    height: auto !important;
    font-size: 0.92rem;
}

.dashboard-page .layout {
    padding-bottom: 72px;
}

.dashboard-page h2 {
    font-size: 0.95rem;
}

.dashboard-page h1.panel-title,
.dashboard-page h2.panel-title {
    font-size: 0.95rem;
    font-weight: 800;
    line-height: 1.15;
    margin: 0 0 0.8rem;
}

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

.device-row {
    align-items: center;
    background-color: rgba(255, 255, 255, 0.03);
    border: 1px solid var(--border-color);
    border-radius: 6px;
    display: grid;
    gap: 8px 12px;
    grid-template-columns: minmax(220px, 1fr) minmax(220px, 0.8fr) auto;
    padding: 12px;
}

.device-main {
    display: grid;
    gap: 2px;
    min-width: 0;
}

.device-main strong {
    color: var(--text-color);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.device-main small,
.device-meta {
    color: var(--muted-text);
}

.device-meta {
    display: flex;
    flex-wrap: wrap;
    gap: 6px 12px;
    font-size: 0.82rem;
}

.device-token-scopes {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    grid-column: 1 / 3;
}

.device-token-scopes span {
    background-color: rgba(66, 165, 245, 0.15);
    border: 1px solid rgba(66, 165, 245, 0.42);
    border-radius: 6px;
    color: var(--text-color);
    font-size: 0.78rem;
    font-weight: 700;
    padding: 3px 8px;
}

.device-revoke-button {
    justify-self: end;
    min-height: 34px;
    min-width: 94px;
    padding: 0 12px;
    width: auto;
}

.users-modal-card {
    width: min(980px, calc(100% - 24px));
    padding: 1.1rem;
}

.users-modal-layout {
    display: grid;
    gap: 14px;
    grid-template-columns: 260px minmax(0, 1fr);
}

.users-modal-list {
    display: grid;
    gap: 10px;
    align-content: start;
}

#users-picker,
#scopes-picker {
    display: grid;
    gap: 6px;
}

.user-picker-button {
    align-items: flex-start;
    background-color: rgba(255, 255, 255, 0.04);
    border: 1px solid var(--border-color);
    border-radius: 6px;
    color: var(--text-color);
    display: grid;
    justify-content: stretch;
    min-height: 54px;
    padding: 8px 10px;
    text-align: left;
}

.user-picker-button.is-active {
    background: rgba(66, 165, 245, 0.16);
    border-color: rgba(66, 165, 245, 0.42);
}

.user-picker-button small {
    color: var(--muted-text);
    font-size: 0.75rem;
}

.user-editor-form {
    display: grid;
    gap: 12px;
    align-content: start;
}

.user-editor-form h3 {
    font-size: 0.9rem;
    margin: 0 0 8px;
}

.checkbox-row {
    align-items: center;
    display: flex;
    gap: 8px;
}

.checkbox-row input {
    height: auto;
    width: auto;
}

.user-editor-actions {
    display: flex;
    gap: 10px;
    justify-content: flex-end;
    margin-top: 8px;
    padding: 8px 8px 4px 0;
}

.user-editor-action-button,
.danger-button {
    min-width: 128px;
    width: 128px;
}

.modal-close-button {
    align-items: center;
    background-color: rgba(255, 255, 255, 0.08);
    border: 1px solid var(--border-color);
    border-radius: 6px;
    color: var(--text-color);
    display: inline-flex;
    font-size: 1.25rem;
    font-weight: 700;
    height: 34px;
    justify-content: center;
    line-height: 1;
    min-height: 34px;
    padding: 0;
    width: 34px;
}

.modal-close-button:hover {
    background-color: rgba(255, 255, 255, 0.18);
}

.danger-button {
    background: rgba(239, 83, 80, 0.16);
    border: 1px solid rgba(239, 83, 80, 0.42);
    color: #ef5350;
}

.danger-button:hover {
    background: rgba(239, 83, 80, 0.24);
}

.danger-button:disabled {
    cursor: not-allowed;
    opacity: 0.45;
}

.portal-page {
    background:
        linear-gradient(90deg, rgba(8, 13, 20, 0.22) 0%, rgba(8, 13, 20, 0.16) 48%, rgba(8, 13, 20, 0.08) 100%),
        linear-gradient(180deg, rgba(8, 13, 20, 0.00), rgba(8, 13, 20, 0.16)),
        url("images/house-background.png") center / cover fixed,
        var(--secondary-color);
    min-height: 100vh;
    overflow-x: hidden;
    overflow-y: auto;
}

.portal-topbar {
    min-height: 58px;
}

.portal-shell {
    align-items: center;
    display: grid;
    gap: 34px;
    justify-items: center;
    min-height: calc(100vh - 58px);
    padding: 38px 22px;
}

.portal-hero {
    display: grid;
    gap: 8px;
    text-align: center;
}

.portal-hero h1 {
    color: var(--text-color);
    font-size: clamp(2rem, 5vw, 4rem);
    line-height: 1;
}

.portal-hero p {
    color: var(--muted-text);
    font-size: 1rem;
}

.portal-apps {
    display: grid;
    gap: 18px;
    grid-template-columns: repeat(3, minmax(180px, 260px));
    justify-content: center;
    width: min(920px, 100%);
}

.portal-app-card {
    align-items: center;
    backdrop-filter: blur(18px);
    background: rgba(18, 18, 18, 0.68);
    border: 1px solid rgba(66, 165, 245, 0.28);
    border-radius: 8px;
    box-shadow: 0 18px 42px rgba(0, 0, 0, 0.22);
    color: var(--text-color);
    display: grid;
    gap: 16px;
    justify-items: center;
    min-height: 220px;
    padding: 24px 18px;
    text-align: center;
    text-decoration: none;
    transition: border-color 160ms ease, transform 160ms ease, background-color 160ms ease;
}

.portal-app-card:hover {
    background: rgba(66, 165, 245, 0.12);
    border-color: rgba(66, 165, 245, 0.62);
    transform: translateY(-2px);
}

.portal-app-card.is-disabled {
    border-color: rgba(239, 83, 80, 0.32);
    opacity: 0.62;
}

.portal-app-card.is-disabled:hover {
    background: rgba(255, 255, 255, 0.055);
    transform: none;
}

.portal-app-icon {
    align-items: center;
    background: rgba(66, 165, 245, 0.14);
    border: 1px solid rgba(66, 165, 245, 0.42);
    border-radius: 8px;
    color: #42A5F5;
    display: inline-flex;
    font-size: 1.35rem;
    font-weight: 900;
    height: 86px;
    justify-content: center;
    letter-spacing: 0;
    width: 86px;
}

.portal-app-text {
    display: grid;
    gap: 4px;
}

.portal-app-text strong {
    font-size: 1.18rem;
    line-height: 1.15;
}

.portal-app-text small {
    color: var(--muted-text);
    font-size: 0.84rem;
}

@media (max-width: 760px) {
    html,
    body.portal-page {
        height: auto;
        min-height: 100dvh;
    }

    body.portal-page {
        background:
            linear-gradient(90deg, rgba(8, 13, 20, 0.22) 0%, rgba(8, 13, 20, 0.16) 48%, rgba(8, 13, 20, 0.08) 100%),
            linear-gradient(180deg, rgba(8, 13, 20, 0.00), rgba(8, 13, 20, 0.16)),
            url("images/house-background.png") center / cover scroll,
            var(--secondary-color);
        overflow-y: auto !important;
    }

    .portal-shell {
        align-items: start;
        min-height: auto;
        padding-bottom: calc(34px + env(safe-area-inset-bottom));
    }

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

    .device-token-scopes {
        grid-column: 1;
    }

    .device-revoke-button {
        justify-self: start;
    }

    .users-modal-layout {
        grid-template-columns: 1fr;
    }

    .user-editor-actions {
        align-items: stretch;
        flex-direction: column;
        padding-right: 0;
    }

    .user-editor-action-button,
    .danger-button {
        width: 100%;
    }

    .portal-apps {
        grid-template-columns: 1fr;
        max-width: 360px;
    }

    .portal-app-card {
        grid-template-columns: 74px minmax(0, 1fr);
        justify-items: start;
        min-height: 120px;
        text-align: left;
    }

    .portal-app-icon {
        height: 68px;
        width: 68px;
    }
}
