:root {
    --bg: #f3f7fb;
    --panel: #ffffff;
    --panel-soft: #f8fbff;
    --text: #102033;
    --muted: #66758a;
    --brand: #1e62ad;
    --brand-dark: #123f78;
    --brand-soft: #e7f1fc;
    --red: #c92836;
    --red-soft: #fdebed;
    --blue-soft: #dfeeff;
    --border: #d9e3ef;
    --shadow: 0 16px 36px rgba(24, 53, 88, 0.09);
}

* { box-sizing: border-box; }

body {
    margin: 0;
    min-height: 100vh;
    font-family: Arial, sans-serif;
    color: var(--text);
    background:
        radial-gradient(circle at 16% 0%, rgba(30, 98, 173, 0.08), transparent 32%),
        linear-gradient(180deg, #ffffff 0%, var(--bg) 44%);
}

.topbar {
    height: 68px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 clamp(16px, 4vw, 48px);
    background: rgba(255, 255, 255, 0.94);
    border-bottom: 1px solid var(--border);
    position: sticky;
    top: 0;
    z-index: 5;
    backdrop-filter: blur(10px);
}

.topbar strong { display: block; font-size: 1.05rem; color: var(--brand-dark); }
.topbar span { color: var(--muted); font-size: 0.9rem; }

.page-shell {
    width: min(1180px, calc(100% - 32px));
    margin: 0 auto;
    padding: 20px 0 48px;
}

.hero-strip {
    background: linear-gradient(135deg, var(--brand), #f8fbff);
    color: #ffffff;
    border-radius: 8px;
    padding: 18px 22px;
    margin-bottom: 14px;
    box-shadow: var(--shadow);
    position: relative;
    overflow: hidden;
}

.hero-strip::after {
    content: "";
    position: absolute;
    inset: 0;
    background: linear-gradient(90deg, transparent 0%, rgba(255,255,255,0.7) 100%);
    opacity: 0.28;
    pointer-events: none;
}

.hero-strip h1 {
    margin: 0;
    font-size: clamp(1.45rem, 3vw, 2rem);
    position: relative;
    z-index: 1;
}

.view-toolbar {
    display: flex;
    justify-content: space-between;
    gap: 16px;
    align-items: center;
    margin-bottom: 16px;
}

.view-toolbar strong { display: block; color: var(--brand-dark); }

.segmented-control {
    display: inline-flex;
    padding: 4px;
    border: 1px solid var(--border);
    border-radius: 8px;
    background: var(--panel);
    box-shadow: 0 8px 20px rgba(16, 32, 51, 0.05);
}

.segmented-control button {
    border: 0;
    background: transparent;
    color: var(--muted);
    border-radius: 6px;
    padding: 9px 13px;
    font-weight: 700;
    cursor: pointer;
}

.segmented-control button.active {
    background: var(--brand);
    color: #ffffff;
}

.objects-grid.view-tiles {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(280px, 340px));
    gap: 18px;
    justify-content: start;
}

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

.object-card {
    display: flex;
    flex-direction: column;
    background: var(--panel);
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 16px;
    box-shadow: var(--shadow);
    cursor: pointer;
    transition: transform 0.16s ease, border-color 0.16s ease, box-shadow 0.16s ease;
}

.object-card:hover {
    transform: translateY(-2px);
    border-color: rgba(30, 98, 173, 0.38);
    box-shadow: 0 20px 44px rgba(24, 53, 88, 0.13);
}

.object-head {
    display: flex;
    justify-content: space-between;
    gap: 12px;
}

.object-card h2,
.object-row h2 {
    margin: 0 0 6px;
    font-size: 1.05rem;
    line-height: 1.22;
}

.address {
    color: var(--muted);
    min-height: 20px;
}

.synonym {
    flex: 0 0 auto;
    align-self: flex-start;
    border-radius: 999px;
    background: var(--brand-soft);
    color: var(--brand-dark);
    padding: 5px 9px;
    font-size: 0.78rem;
    font-weight: 800;
}

.empty-state {
    grid-column: 1 / -1;
    background: var(--panel);
    border: 1px dashed var(--border);
    border-radius: 8px;
    padding: 24px;
    color: var(--muted);
}

.empty-state h2 { margin: 0 0 8px; color: var(--text); }
.empty-state p { margin: 0; }

.status-line {
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
    margin: 14px 0 10px;
}

.pill {
    border-radius: 999px;
    padding: 5px 10px;
    font-size: 0.8rem;
    background: #eef2f6;
    color: var(--muted);
    max-width: 100%;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.pill.online { background: #e8f7ef; color: #0b7444; }
.pill.offline { background: #eef2f6; color: #687487; }
.pill.fault { background: var(--red-soft); color: var(--red); }
.pill.neutral { background: var(--brand-soft); color: var(--brand-dark); }

.action-row {
    display: flex;
    gap: 12px;
    align-items: center;
    margin: 6px 0 10px;
}

.circle-action {
    width: 42px;
    height: 42px;
    border-radius: 999px;
    border: none;
    color: white;
    cursor: pointer;
    box-shadow: inset 0 -3px 0 rgba(0,0,0,0.12), 0 5px 12px rgba(16,32,51,0.12);
    display: grid;
    place-items: center;
    align-content: center;
    gap: 2px;
}

.circle-action span {
    font-size: 1rem;
    font-weight: 900;
    line-height: 1;
}

.circle-action.disarm { background: #2fb56b; }
.circle-action.arm { background: var(--red); }

.section-dots {
    display: flex;
    gap: 6px;
    padding-top: 2px;
}

.section-dot {
    width: 10px;
    height: 10px;
    border-radius: 999px;
    background: #c7d1de;
}

.section-dot.armed { background: var(--red); }
.section-dot.disarmed { background: var(--brand); }

.object-row {
    display: grid;
    grid-template-columns: minmax(240px, 1fr) auto auto;
    align-items: center;
    gap: 16px;
    background: var(--panel);
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 14px 16px;
    box-shadow: 0 8px 24px rgba(24, 53, 88, 0.06);
    cursor: pointer;
}

.row-status,
.row-counts {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    justify-content: flex-end;
}

.mini-state {
    border-radius: 999px;
    padding: 6px 10px;
    font-size: 0.82rem;
    font-weight: 800;
}

.mini-state.disarm { background: var(--brand-soft); color: var(--brand-dark); }
.mini-state.arm { background: var(--red-soft); color: var(--red); }

.ghost-btn,
.ghost-link {
    border: 1px solid var(--border);
    background: transparent;
    color: var(--text);
    border-radius: 6px;
    padding: 9px 13px;
    text-decoration: none;
    cursor: pointer;
}

.login-page {
    display: grid;
    place-items: center;
    padding: 24px;
    background: radial-gradient(circle at top, var(--brand-soft), var(--bg) 45%);
}

.embedded-login { min-height: 100vh; }
.cloud-app-view { display: none; }
.cloud-app-view.active { display: block; }
.embedded-login.hidden { display: none; }

.login-card {
    width: min(420px, 100%);
    background: var(--panel);
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 28px;
    box-shadow: 0 18px 50px rgba(15, 23, 42, 0.12);
}

label {
    display: block;
    margin-top: 14px;
    font-size: 0.85rem;
    color: var(--muted);
}

input {
    width: 100%;
    border: 1px solid var(--border);
    border-radius: 6px;
    padding: 12px;
    font: inherit;
    margin-top: 6px;
}

button[type="submit"] {
    width: 100%;
    margin-top: 18px;
    padding: 12px;
    border: none;
    border-radius: 6px;
    background: var(--brand);
    color: #ffffff;
    font-weight: 800;
    cursor: pointer;
}

.form-error { color: var(--red); min-height: 20px; margin-top: 12px; }
.form-note { color: var(--muted); min-height: 20px; margin-top: 12px; }

.object-layout {
    display: grid;
    grid-template-columns: 360px 1fr;
    gap: 18px;
}

.object-panel,
.history-panel {
    background: var(--panel);
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 18px;
}

.object-state {
    display: flex;
    justify-content: center;
    gap: 24px;
    padding: 28px 0;
}

.object-state .circle-action {
    width: 76px;
    height: 76px;
    font-weight: 800;
}

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

.history-item {
    display: grid;
    grid-template-columns: 86px 1fr;
    gap: 12px;
    border-bottom: 1px solid var(--border);
    padding: 10px 0;
}

.history-time { color: var(--muted); }

.command-modal {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(15, 23, 42, 0.55);
    align-items: center;
    justify-content: center;
    padding: 20px;
    z-index: 20;
}

.command-modal.open { display: flex; }

.command-card {
    width: min(440px, 100%);
    background: var(--panel);
    border-radius: 8px;
    padding: 22px;
    position: relative;
}

.modal-close {
    position: absolute;
    top: 12px;
    right: 12px;
    width: 34px;
    height: 34px;
    border: 1px solid var(--border);
    border-radius: 999px;
    background: var(--panel-soft);
    color: var(--muted);
    cursor: pointer;
    font-size: 1.25rem;
}

@media (max-width: 760px) {
    .topbar {
        height: auto;
        gap: 12px;
        padding-block: 14px;
    }

    .view-toolbar,
    .object-row {
        grid-template-columns: 1fr;
        align-items: stretch;
    }

    .view-toolbar {
        display: grid;
    }

    .segmented-control { width: 100%; }
    .segmented-control button { flex: 1; }
    .object-layout { grid-template-columns: 1fr; }
    .circle-action { width: 42px; height: 42px; }
    .objects-grid.view-tiles { grid-template-columns: 1fr; }
    .row-status,
    .row-counts { justify-content: flex-start; }
}
