:root {
    --bg: #f7f8fb;
    --panel: #ffffff;
    --ink: #18202f;
    --muted: #687386;
    --line: #dce2ea;
    --blue: #2f6fed;
    --blue-strong: #1f55ba;
    --green: #0f8f68;
    --red: #c43b45;
    --shadow: 0 18px 45px rgba(24, 32, 47, 0.12);
}

* {
    box-sizing: border-box;
}

body {
    margin: 0;
    min-height: 100vh;
    background: var(--bg);
    color: var(--ink);
    font-family: Arial, Helvetica, sans-serif;
}

button,
input,
select,
.button-link {
    font: inherit;
}

button,
.button-link {
    align-items: center;
    border: 0;
    border-radius: 7px;
    background: var(--blue);
    color: #fff;
    cursor: pointer;
    display: inline-flex;
    font-weight: 700;
    justify-content: center;
    min-height: 42px;
    padding: 0 16px;
    text-decoration: none;
}

button:hover,
.button-link:hover {
    background: var(--blue-strong);
}

button.ghost,
.button-link.ghost {
    background: #eef3ff;
    color: var(--blue-strong);
}

button.ghost:hover,
.button-link.ghost:hover {
    background: #dfe8ff;
}

button.danger {
    color: var(--red);
}

button.icon-button {
    width: 38px;
    min-height: 38px;
    padding: 0;
}

input,
select {
    border: 1px solid var(--line);
    border-radius: 7px;
    color: var(--ink);
    min-height: 42px;
    padding: 0 12px;
    width: 100%;
}

label {
    color: var(--muted);
    display: grid;
    font-size: 0.82rem;
    font-weight: 700;
    gap: 7px;
}

.shell {
    display: grid;
    gap: 18px;
    margin: 0 auto;
    max-width: 1180px;
    min-height: 100vh;
    padding: 20px;
}

.topbar {
    align-items: center;
    display: flex;
    gap: 16px;
    justify-content: space-between;
}

.topbar h1 {
    font-size: clamp(1.7rem, 2.5vw, 2.3rem);
    line-height: 1.1;
    margin: 4px 0 0;
}

.user-badge {
    color: var(--muted);
    font-size: 0.84rem;
    font-weight: 700;
    margin: 7px 0 0;
}

.eyebrow {
    color: var(--green);
    font-size: 0.78rem;
    font-weight: 800;
    letter-spacing: 0;
    margin: 0;
    text-transform: uppercase;
}

.topbar-actions {
    display: flex;
    flex-wrap: wrap;
    gap: 9px;
    justify-content: flex-end;
}

.auth-panel {
    align-items: center;
    display: grid;
    min-height: 65vh;
}

.auth-card {
    background: var(--panel);
    border: 1px solid var(--line);
    border-radius: 8px;
    box-shadow: var(--shadow);
    display: grid;
    gap: 16px;
    margin: auto;
    max-width: 420px;
    padding: 26px;
    width: 100%;
}

.auth-card h2,
.auth-card p {
    margin: 0;
}

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

.download-full {
    width: 100%;
}

.auth-tabs {
    background: #eef3ff;
    border-radius: 8px;
    display: grid;
    gap: 4px;
    grid-template-columns: 1fr 1fr;
    padding: 4px;
}

.auth-tabs button {
    background: transparent;
    color: var(--blue-strong);
}

.auth-tabs button.active {
    background: var(--panel);
    color: var(--ink);
    box-shadow: 0 3px 12px rgba(24, 32, 47, 0.08);
}

.dashboard {
    display: grid;
    gap: 18px;
    grid-template-columns: 290px minmax(0, 1fr);
    min-height: 0;
}

.device-panel,
.message-panel {
    background: var(--panel);
    border: 1px solid var(--line);
    border-radius: 8px;
    min-width: 0;
}

.device-panel {
    padding: 14px;
}

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

.panel-title h2 {
    font-size: 1rem;
    margin: 0;
}

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

.install-card {
    background: #f4faf7;
    border: 1px solid #bde8d8;
    border-radius: 8px;
    color: var(--ink);
    display: grid;
    gap: 4px;
    margin-bottom: 10px;
    padding: 12px;
    text-decoration: none;
}

.install-card:hover {
    background: #e9f7f0;
}

.install-card strong {
    color: var(--green);
    font-size: 0.94rem;
}

.install-card span {
    color: var(--muted);
    font-size: 0.8rem;
    font-weight: 700;
    line-height: 1.35;
}

.device-row {
    display: grid;
    gap: 7px;
    grid-template-columns: minmax(0, 1fr) 74px;
}

.device-button {
    align-items: start;
    background: #f5f7fb;
    border: 1px solid transparent;
    color: var(--ink);
    display: grid;
    gap: 4px;
    justify-items: start;
    min-height: 74px;
    padding: 10px;
    text-align: left;
    width: 100%;
}

.device-button:hover,
.device-button.active {
    background: #eef5ff;
    border-color: #bad2ff;
    color: var(--ink);
}

.device-button strong {
    font-size: 0.95rem;
}

.device-button span {
    color: var(--muted);
    font-size: 0.78rem;
    font-weight: 600;
}

.device-delete {
    align-self: stretch;
    background: #fff0f2;
    color: var(--red);
    min-height: 74px;
    padding: 0 8px;
}

.device-delete:hover {
    background: #ffe0e4;
}

.message-panel {
    display: grid;
    grid-template-rows: auto minmax(0, 1fr);
    overflow: hidden;
}

.filters {
    align-items: end;
    border-bottom: 1px solid var(--line);
    display: grid;
    gap: 12px;
    grid-template-columns: minmax(0, 1fr) 120px;
    padding: 14px;
}

.messages {
    display: grid;
    gap: 10px;
    max-height: calc(100vh - 184px);
    overflow: auto;
    padding: 14px;
}

.message {
    border: 1px solid var(--line);
    border-left: 4px solid #9ebaf5;
    border-radius: 8px;
    display: grid;
    gap: 8px;
    padding: 12px;
}

.message.sent {
    border-left-color: var(--green);
}

.message.failed,
.message.queued {
    border-left-color: var(--red);
}

.message-header {
    align-items: start;
    display: flex;
    gap: 12px;
    justify-content: space-between;
}

.message-meta {
    color: var(--muted);
    display: flex;
    flex-wrap: wrap;
    font-size: 0.78rem;
    font-weight: 700;
    gap: 8px;
}

.message-body {
    line-height: 1.5;
    margin: 0;
    overflow-wrap: anywhere;
    white-space: pre-wrap;
}

.empty {
    align-items: center;
    color: var(--muted);
    display: grid;
    min-height: 260px;
    place-items: center;
    text-align: center;
}

.small-action {
    background: transparent;
    color: var(--red);
    min-height: 30px;
    padding: 0 8px;
}

.small-action:hover {
    background: #ffecee;
}

.modal-backdrop {
    align-items: center;
    background: rgba(24, 32, 47, 0.46);
    display: grid;
    inset: 0;
    padding: 18px;
    position: fixed;
    z-index: 20;
}

.modal {
    background: var(--panel);
    border-radius: 8px;
    box-shadow: var(--shadow);
    display: grid;
    gap: 16px;
    margin: auto;
    max-width: 520px;
    padding: 22px;
    width: min(100%, 520px);
}

.modal h2,
.modal p {
    margin: 0;
}

.modal p {
    color: var(--muted);
    line-height: 1.5;
}

.pairing-code {
    background: #101828;
    border-radius: 8px;
    color: #fff;
    font-size: 2.4rem;
    font-weight: 800;
    letter-spacing: 0.1em;
    padding: 16px;
    text-align: center;
}

.copy-line {
    background: #f5f7fb;
    border: 1px solid var(--line);
    border-radius: 8px;
    color: var(--ink);
    overflow-wrap: anywhere;
    padding: 10px;
}

.modal-actions {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    justify-content: flex-end;
}

[hidden] {
    display: none !important;
}

@media (max-width: 820px) {
    .shell {
        padding: 14px;
    }

    .topbar {
        align-items: stretch;
        flex-direction: column;
    }

    .topbar-actions {
        justify-content: start;
    }

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

    .messages {
        max-height: none;
    }
}

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

    .topbar-actions button {
        flex: 1 1 130px;
    }

    .message-header {
        display: grid;
    }

    .device-row {
        grid-template-columns: minmax(0, 1fr) 68px;
    }
}
