:root {
    --bg: #f4f5f7;
    --panel-bg: #ffffff;
    --text: #1a1d21;
    --text-muted: #6b7280;
    --border: #e2e4e8;
    --accent: #2563eb;
    --accent-text: #ffffff;
    --ok: #16a34a;
    --warn: #d97706;
    --bad: #dc2626;
    --unknown: #9ca3af;
}

@media (prefers-color-scheme: dark) {
    :root {
        --bg: #14161a;
        --panel-bg: #1d2025;
        --text: #e7e9ec;
        --text-muted: #9aa0aa;
        --border: #2c2f36;
        --accent: #3b82f6;
        --accent-text: #ffffff;
        --ok: #22c55e;
        --warn: #f59e0b;
        --bad: #ef4444;
        --unknown: #6b7280;
    }
}

* { box-sizing: border-box; }

html, body {
    margin: 0;
    padding: 0;
    height: 100%;
    background: var(--bg);
    color: var(--text);
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Arial, sans-serif;
}

a { color: var(--accent); }

.topbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 10px 18px;
    background: var(--panel-bg);
    border-bottom: 1px solid var(--border);
}

.topbar h1 {
    font-size: 18px;
    margin: 0;
}

.topbar-actions {
    display: flex;
    align-items: center;
    gap: 16px;
    font-size: 13px;
    color: var(--text-muted);
}

.conn-status::before {
    content: '●';
    margin-right: 5px;
}
.conn-status.conn-ok { color: var(--ok); }
.conn-status.conn-bad { color: var(--bad); }

.btn-link {
    text-decoration: none;
    font-weight: 600;
}

.layout {
    display: flex;
    height: calc(100vh - 53px);
}

#map {
    flex: 1 1 auto;
    height: 100%;
}

.sidebar {
    width: 360px;
    flex: 0 0 360px;
    max-width: 45vw;
    background: var(--panel-bg);
    border-left: 1px solid var(--border);
    overflow-y: auto;
    display: flex;
    flex-direction: column;
}

.device-list {
    display: flex;
    flex-direction: column;
}

.device-item {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px 14px;
    border-bottom: 1px solid var(--border);
    cursor: pointer;
}

.device-item:hover {
    background: var(--bg);
}

.device-item.selected {
    background: var(--bg);
    box-shadow: inset 3px 0 0 var(--accent);
}

.device-item .dot {
    width: 10px;
    height: 10px;
    border-radius: 50%;
    flex: 0 0 auto;
    background: var(--unknown);
}

.device-item.health-ok .dot { background: var(--ok); }
.device-item.health-warn .dot { background: var(--warn); }
.device-item.health-bad .dot { background: var(--bad); }
.device-item.health-unknown .dot { background: var(--unknown); }

.device-item-name {
    font-weight: 600;
    font-size: 14px;
}

.device-item-sub {
    font-size: 12px;
    color: var(--text-muted);
    margin-top: 2px;
}

.device-item-badges {
    margin-top: 4px;
    display: flex;
    gap: 4px;
    flex-wrap: wrap;
}

.detail-badges {
    display: flex;
    gap: 6px;
    flex-wrap: wrap;
    margin: 0 0 10px 0;
}

.badge {
    display: inline-block;
    font-size: 11px;
    font-weight: 600;
    padding: 2px 8px;
    border-radius: 10px;
    color: var(--accent-text);
}
.badge-warn { background: var(--warn); }
.badge-bad { background: var(--bad); }

.device-detail {
    position: relative;
    border-top: 2px solid var(--border);
    padding: 16px 14px;
}

.btn-close {
    position: absolute;
    top: 10px;
    right: 10px;
    background: none;
    border: none;
    font-size: 20px;
    line-height: 1;
    cursor: pointer;
    color: var(--text-muted);
}

.device-detail h2 {
    margin: 0 24px 10px 0;
    font-size: 16px;
    word-break: break-word;
}

.device-detail h3 {
    display: flex;
    align-items: center;
    justify-content: space-between;
    font-size: 13px;
    margin: 18px 0 8px 0;
}

.btn-clear {
    padding: 3px 10px;
    border-radius: 10px;
    border: 1px solid var(--border);
    background: none;
    color: var(--text-muted);
    font-size: 11px;
    cursor: pointer;
}

.btn-clear:hover {
    background: var(--bg);
    color: var(--text);
}

.detail-meta {
    display: grid;
    grid-template-columns: auto 1fr;
    gap: 4px 10px;
    font-size: 13px;
    margin: 0 0 14px 0;
}

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

.detail-meta dd {
    margin: 0;
}

.command-buttons {
    display: flex;
    flex-direction: column;
    gap: 6px;
    margin-bottom: 6px;
}

.command-buttons button {
    padding: 8px 10px;
    border-radius: 6px;
    border: 1px solid var(--border);
    background: var(--accent);
    color: var(--accent-text);
    font-size: 13px;
    cursor: pointer;
}

.command-buttons button:hover {
    opacity: 0.9;
}

.command-hint {
    font-size: 12px;
    color: var(--text-muted);
    margin: 4px 0 14px 0;
}

.raw-command-form {
    display: flex;
    gap: 6px;
    margin-bottom: 4px;
}

.raw-command-form input {
    flex: 1 1 auto;
    padding: 8px 10px;
    border-radius: 6px;
    border: 1px solid var(--border);
    background: var(--bg);
    color: var(--text);
    font-size: 13px;
    min-width: 0;
}

.raw-command-form button {
    padding: 8px 14px;
    border-radius: 6px;
    border: 1px solid var(--border);
    background: var(--accent);
    color: var(--accent-text);
    font-size: 13px;
    cursor: pointer;
}

.command-history {
    margin-bottom: 14px;
}

.cmd-entry {
    border: 1px solid var(--border);
    border-radius: 6px;
    padding: 8px 10px;
    margin-bottom: 8px;
    font-size: 12px;
}

.cmd-entry-head {
    display: flex;
    align-items: center;
    flex-wrap: wrap;
    gap: 6px;
}

.cmd-time {
    color: var(--text-muted);
    font-family: "SFMono-Regular", Consolas, Menlo, monospace;
}

.cmd-status {
    font-size: 11px;
    padding: 1px 7px;
    border-radius: 10px;
    margin-left: auto;
}

.cmd-status-pending {
    background: var(--warn);
    color: var(--accent-text);
}

.cmd-status-done {
    background: var(--ok);
    color: var(--accent-text);
}

.cmd-response {
    margin: 8px 0 0 0;
}

.cmd-response .log-list {
    max-height: 160px;
}

.log-list {
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: 6px;
    padding: 4px 10px;
    font-size: 11px;
    max-height: 260px;
    overflow-y: auto;
}

.log-line {
    display: flex;
    gap: 8px;
    padding: 3px 0;
    border-bottom: 1px solid var(--border);
}

.log-line:last-child {
    border-bottom: none;
}

.log-time {
    flex: 0 0 auto;
    color: var(--text-muted);
    font-family: "SFMono-Regular", Consolas, Menlo, monospace;
    font-variant-numeric: tabular-nums;
}

.log-text {
    font-family: "SFMono-Regular", Consolas, Menlo, monospace;
    word-break: break-all;
}

.toast {
    position: fixed;
    bottom: 20px;
    left: 50%;
    transform: translateX(-50%);
    background: var(--text);
    color: var(--bg);
    padding: 10px 18px;
    border-radius: 6px;
    font-size: 13px;
    box-shadow: 0 2px 10px rgba(0, 0, 0, 0.2);
    z-index: 1000;
}

.login-body {
    display: flex;
    align-items: center;
    justify-content: center;
    height: 100%;
}

.login-box {
    background: var(--panel-bg);
    border: 1px solid var(--border);
    border-radius: 10px;
    padding: 28px 26px;
    width: 280px;
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.login-box h1 {
    font-size: 17px;
    margin: 0 0 8px 0;
    text-align: center;
}

.login-box label {
    font-size: 13px;
    color: var(--text-muted);
}

.login-box input {
    padding: 8px 10px;
    border-radius: 6px;
    border: 1px solid var(--border);
    background: var(--bg);
    color: var(--text);
    font-size: 14px;
}

.login-box button {
    margin-top: 6px;
    padding: 9px 10px;
    border-radius: 6px;
    border: none;
    background: var(--accent);
    color: var(--accent-text);
    font-size: 14px;
    cursor: pointer;
}

.login-error {
    color: var(--bad);
    font-size: 13px;
    margin: 0;
}

@media (max-width: 720px) {
    .layout {
        flex-direction: column;
    }
    #map {
        height: 45vh;
    }
    .sidebar {
        width: 100%;
        max-width: 100%;
        flex: 1 1 auto;
    }
}
