:root {
    --bg: #f3f5f8;
    --surface: #ffffff;
    --text: #18212f;
    --muted: #5d6b7d;
    --accent: #1f7a8c;
    --accent-dark: #175f6d;
    --line: #dde4ee;
    --success: #1f9d73;
    --danger: #cf4c4c;
    --warning: #d18e22;
    --info: #4a6fa5;
    --shadow: 0 14px 30px rgba(17, 41, 67, 0.09);
    --radius-lg: 20px;
    --radius-md: 14px;
}

html,
body {
    max-width: 100%;
    overflow-x: hidden;
}
* {
    box-sizing: border-box;
}

body {
    margin: 0;
    font-family: "Manrope", sans-serif;
    color: var(--text);
    background:
        radial-gradient(circle at 15% 10%, #e8f4f6 0, transparent 45%),
        radial-gradient(circle at 90% 5%, #f7f8fc 0, transparent 42%),
        var(--bg);
    min-height: 100vh;
    overflow-x: hidden;
}

a {
    color: inherit;
    text-decoration: none;
}

.public-shell,
.main-content {
    padding: 24px;
    min-width: 0;
    width: 100%;
    max-width: 100%;
}

.hero {
    min-height: calc(100vh - 48px);
    display: grid;
    place-items: center;
}

.hero-card {
    width: min(760px, 100%);
    background: var(--surface);
    border-radius: 28px;
    padding: 40px;
    box-shadow: var(--shadow);
}

.badge {
    display: inline-block;
    padding: 6px 12px;
    border-radius: 999px;
    background: #eaf4f7;
    color: var(--accent);
    font-weight: 700;
    font-size: 0.8rem;
    margin-bottom: 14px;
}

h1,
h2,
h3 {
    margin-top: 0;
}

.hero-card h1 {
    font-size: clamp(1.8rem, 4vw, 2.8rem);
    margin-bottom: 14px;
}

.lead {
    color: var(--muted);
    line-height: 1.6;
    max-width: 580px;
}

.hero-actions {
    display: flex;
    gap: 12px;
    margin-top: 24px;
}

.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    border: 0;
    border-radius: 12px;
    padding: 12px 18px;
    font-weight: 700;
    cursor: pointer;
    transition: transform 0.2s ease, box-shadow 0.2s ease, background 0.2s ease;
}

.btn:hover {
    transform: translateY(-1px);
}

.btn-primary {
    color: #fff;
    background: linear-gradient(135deg, var(--accent), #2a9fb6);
    box-shadow: 0 10px 18px rgba(31, 122, 140, 0.22);
}

.btn-primary:hover {
    background: linear-gradient(135deg, var(--accent-dark), #1f8ea3);
}

.btn-secondary {
    color: var(--text);
    background: #eef3f8;
}

.btn-secondary:hover {
    background: #e4ebf3;
}

.auth-section {
    min-height: calc(100vh - 48px);
    display: grid;
    place-items: center;
}

.auth-card {
    width: min(440px, 100%);
    background: var(--surface);
    padding: 32px;
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow);
}

.auth-card p {
    margin-top: -8px;
    margin-bottom: 20px;
    color: var(--muted);
}

label {
    font-size: 0.9rem;
    font-weight: 700;
    display: block;
    margin: 14px 0 8px;
}

input,
select {
    width: 100%;
    border: 1px solid var(--line);
    border-radius: 10px;
    padding: 12px;
    font: inherit;
    background: #fff;
}

input:focus,
select:focus {
    outline: none;
    border-color: var(--accent);
    box-shadow: 0 0 0 3px rgba(31, 122, 140, 0.14);
}

.full {
    width: 100%;
    margin-top: 18px;
}

.auth-link {
    display: block;
    margin-top: 14px;
    text-align: center;
    color: var(--accent-dark);
    font-weight: 600;
}

.flash-wrap {
    display: grid;
    gap: 10px;
    margin-bottom: 16px;
}

.flash {
    padding: 12px 14px;
    border-radius: 12px;
    font-weight: 600;
}

.flash.success { background: #e8f7f1; color: var(--success); }
.flash.danger { background: #fdeaea; color: var(--danger); }
.flash.warning { background: #fef5e6; color: var(--warning); }
.flash.info { background: #ecf1f8; color: var(--info); }

.app-shell {
    display: grid;
    grid-template-columns: 260px 1fr;
    min-height: 100vh;
    min-width: 0;
    width: 100%;
    max-width: 100%;
    overflow-x: clip;
}

.sidebar {
    background: #131f2b;
    color: #d5dbe5;
    padding: 26px 18px;
    min-width: 0;
    width: 100%;
    max-width: 100%;
}

.brand {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    font-size: 1.2rem;
    font-weight: 800;
    color: #fff;
    margin-bottom: 24px;
}

.brand span {
    color: #81c3d0;
}

.sidebar-head {
    display: block;
}

.menu-toggle {
    display: none;
}

.menu {
    display: grid;
    gap: 8px;
}

.menu-item {
    padding: 10px 12px;
    border-radius: 10px;
    color: #c9d1db;
    transition: background 0.2s ease, color 0.2s ease;
    min-width: 0;
}

.menu-item:hover,
.menu-item.active {
    background: #1f2f40;
    color: #fff;
}

.topbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 18px;
    min-width: 0;
}

.topbar h1 {
    min-width: 0;
    overflow-wrap: anywhere;
}

.user-pill {
    background: var(--surface);
    border-radius: 999px;
    padding: 8px 14px;
    box-shadow: var(--shadow);
    font-weight: 700;
}

.cards-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
    gap: 16px;
    min-width: 0;
}

.devices-grid {
    grid-template-columns: repeat(auto-fill, minmax(360px, 420px));
    justify-content: start;
    align-items: start;
}

.cards-grid.single {
    grid-template-columns: minmax(260px, 680px);
}

.card {
    background: var(--surface);
    border-radius: var(--radius-md);
    padding: 20px;
    box-shadow: var(--shadow);
    position: relative;
    min-width: 0;
}

.card p {
    color: var(--muted);
    line-height: 1.6;
}

.section-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
    margin-bottom: 18px;
}

.hidden {
    display: none;
}

.modal-backdrop {
    position: fixed;
    inset: 0;
    background: rgba(13, 23, 33, 0.45);
    display: none;
    align-items: center;
    justify-content: center;
    padding: 16px;
    z-index: 30;
}

.modal-backdrop.show {
    display: flex;
}

.modal-card {
    width: min(520px, 100%);
    background: var(--surface);
    border-radius: var(--radius-lg);
    padding: 22px;
    box-shadow: var(--shadow);
}

.modal-head {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 10px;
}

.modal-close {
    border: 0;
    background: transparent;
    font-size: 1.6rem;
    line-height: 1;
    cursor: pointer;
    color: #7a8798;
}

.modal-form {
    display: grid;
}

.device-card-topline {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 12px;
    padding-right: 42px;
}

.device-card h3 {
    margin: 0;
}

.device-serial {
    margin: 0;
    white-space: nowrap;
}

.device-type {
    font-weight: 700;
    color: var(--accent-dark);
    margin-top: 6px;
    margin-bottom: 0;
}

.device-props {
    margin-top: 8px;
    border-top: 1px solid var(--line);
    padding-top: 10px;
}

.device-props p {
    margin: 7px 0;
}

.device-controls-row {
    display: flex;
    gap: 12px;
    margin-top: 10px;
    align-items: center;
}

.fireplace-toolbar {
    margin-bottom: 6px;
    justify-content: space-between;
    width: 100%;
}

.power-circle-btn {
    width: 56px;
    height: 56px;
    border-radius: 50%;
    border: 1px solid #cfd8e5;
    background: radial-gradient(circle at 30% 25%, #ffffff 0, #eef3f8 55%, #dbe5f0 100%);
    display: inline-flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    box-shadow: inset 0 2px 4px rgba(255, 255, 255, 0.9), 0 5px 12px rgba(42, 63, 90, 0.16);
    transition: transform 0.2s ease, background 0.2s ease, border-color 0.2s ease, box-shadow 0.2s ease;
}

.power-circle-btn:hover {
    transform: translateY(-1px) scale(1.02);
}

.power-circle-btn svg {
    width: 24px;
    height: 24px;
    color: #58708a;
    filter: drop-shadow(0 1px 0 rgba(255, 255, 255, 0.6));
}

.power-circle-btn svg * {
    fill: none;
    stroke: currentColor;
    stroke-width: 2.4;
    stroke-linecap: round;
    stroke-linejoin: round;
}

.power-circle-btn.is-active {
    background: radial-gradient(circle at 30% 25%, #ebfff6 0, #c7f0dd 55%, #a8e2c7 100%);
    border-color: #8fd0b0;
    box-shadow: inset 0 2px 5px rgba(255, 255, 255, 0.95), 0 0 0 4px rgba(45, 161, 115, 0.14), 0 8px 18px rgba(31, 157, 115, 0.26);
}

.power-circle-btn.is-active svg {
    color: #1f9d73;
}

.rgb-palette-wrap {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-left: auto;
}

.rgb-palette-wrap label {
    margin: 0;
}

.rgb-picker {
    width: 56px;
    height: 34px;
    border-radius: 10px;
    border: 1px solid var(--line);
    padding: 3px;
    cursor: pointer;
}

.fireplace-form {
    margin-top: 10px;
    padding-top: 10px;
    border-top: 1px solid var(--line);
}

.fireplace-form label {
    margin-top: 12px;
}

.toggle-row {
    margin-top: 2px;
    margin-bottom: 12px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
}

.toggle-row > label:first-child {
    margin: 0;
    font-size: 1rem;
}

.toggle-switch {
    margin: 0;
    position: relative;
    display: inline-block;
    width: 52px;
    height: 30px;
    flex: 0 0 auto;
}

.toggle-switch input {
    position: absolute;
    opacity: 0;
    width: 0;
    height: 0;
}

.toggle-slider {
    position: absolute;
    cursor: pointer;
    inset: 0;
    background: #d1d7e0;
    border-radius: 999px;
    transition: background 0.2s ease;
}

.toggle-slider::before {
    content: "";
    position: absolute;
    width: 22px;
    height: 22px;
    left: 4px;
    top: 4px;
    border-radius: 50%;
    background: #fff;
    box-shadow: 0 2px 8px rgba(20, 34, 53, 0.24);
    transition: transform 0.2s ease;
}

.toggle-switch input:checked + .toggle-slider {
    background: #55bf67;
}

.toggle-switch input:checked + .toggle-slider::before {
    transform: translateX(22px);
}

.brightness-slider {
    padding: 0;
    height: 8px;
    accent-color: var(--accent);
    cursor: pointer;
}

.delete-device-btn {
    position: absolute;
    top: 14px;
    right: 14px;
    width: 34px;
    height: 34px;
    border-radius: 50%;
    border: 1px solid #f1d2d2;
    background: #fff3f3;
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    justify-content: center;
}

.delete-device-btn svg {
    width: 18px;
    height: 18px;
    color: #c15151;
}

.delete-device-btn svg * {
    fill: none;
    stroke: currentColor;
    stroke-width: 1.9;
    stroke-linecap: round;
    stroke-linejoin: round;
}

.device-card.is-busy {
    opacity: 0.7;
    pointer-events: none;
}

.status-dot {
    margin-top: 16px;
    display: inline-flex;
    align-items: center;
    gap: 8px;
    font-weight: 700;
}

.status-dot span {
    width: 10px;
    height: 10px;
    border-radius: 50%;
    background: #f2a900;
    box-shadow: 0 0 0 5px rgba(242, 169, 0, 0.18);
}

.profile-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    border-top: 1px solid var(--line);
    padding: 14px 0;
}

.profile-row span {
    color: var(--muted);
}

.profile-form {
    margin-top: 16px;
    border-top: 1px solid var(--line);
    padding-top: 4px;
}

@media (max-width: 900px) {
    .app-shell {
        display: block;
        min-height: 0;
    }

    .sidebar {
        padding: 16px;
    }

    .sidebar-head {
        display: flex;
        align-items: center;
        justify-content: space-between;
        gap: 12px;
    }

    .brand {
        margin-bottom: 0;
    }

    .menu-toggle {
        display: inline-flex;
        flex-direction: column;
        justify-content: center;
        gap: 4px;
        width: 38px;
        height: 38px;
        padding: 0;
        border: 1px solid rgba(201, 209, 219, 0.35);
        border-radius: 10px;
        background: #1a2a3a;
        cursor: pointer;
    }

    .menu-toggle span {
        display: block;
        width: 18px;
        height: 2px;
        margin: 0 auto;
        background: #d5dbe5;
        border-radius: 2px;
        transition: transform 0.2s ease, opacity 0.2s ease;
    }

    .sidebar.menu-open .menu-toggle span:nth-child(1) {
        transform: translateY(6px) rotate(45deg);
    }

    .sidebar.menu-open .menu-toggle span:nth-child(2) {
        opacity: 0;
    }

    .sidebar.menu-open .menu-toggle span:nth-child(3) {
        transform: translateY(-6px) rotate(-45deg);
    }

    .menu {
        display: none;
    }

    .sidebar.menu-open .menu {
        display: grid;
        margin-top: 14px;
        grid-template-columns: repeat(2, minmax(0, 1fr));
    }

    .main-content {
        padding-top: 10px;
        min-width: 0;
    }
}

.status-card code {
    display: block;
    max-width: 100%;
    white-space: normal;
    overflow-wrap: anywhere;
    word-break: break-word;
}

.token-row {
    margin-bottom: 14px;
    max-width: 100%;
    overflow: hidden;
}

.token-code {
    display: block;
    width: 100%;
    max-width: 100%;
    white-space: normal;
    overflow-wrap: anywhere;
    word-break: break-all;
    line-height: 1.45;
}

@media (max-width: 640px) {
    .hero-card,
    .auth-card,
    .card {
        padding: 18px;
    }

    .hero-actions,
    .section-head {
        flex-direction: column;
        align-items: stretch;
    }

    .topbar {
        flex-direction: column;
        align-items: flex-start;
        gap: 10px;
    }

    .sidebar.menu-open .menu {
        grid-template-columns: 1fr;
    }

    .menu-item {
        overflow-wrap: anywhere;
        word-break: break-word;
    }

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

    .device-card-topline {
        display: grid;
        grid-template-columns: 1fr;
        gap: 4px;
        padding-right: 44px;
    }

    .device-serial {
        white-space: normal;
        overflow-wrap: anywhere;
    }
}

