:root {
    --bg: #0f1115;
    --panel: #171a21;
    --panel-border: #262a33;
    --text: #e6e8ec;
    --muted: #8a90a0;
    --accent: #4f8cff;
    --ok: #2ecc71;
    --alert: #e74c3c;
}

* {
    box-sizing: border-box;
}

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

.auth-body {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 100vh;
    padding: 16px;
}

.auth-card {
    width: 100%;
    max-width: 360px;
    background: var(--panel);
    border: 1px solid var(--panel-border);
    border-radius: 12px;
    padding: 28px;
    text-align: center;
}

.auth-card h1 {
    margin: 0 0 4px;
    font-size: 22px;
}

.auth-subtitle {
    margin: 0 0 20px;
    color: var(--muted);
    font-size: 14px;
}

.auth-form {
    display: flex;
    flex-direction: column;
    gap: 8px;
    text-align: left;
}

.auth-form label {
    font-size: 13px;
    color: var(--muted);
}

.auth-form input {
    padding: 10px 12px;
    border-radius: 8px;
    border: 1px solid var(--panel-border);
    background: var(--bg);
    color: var(--text);
    font-size: 15px;
}

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

button {
    padding: 10px 14px;
    border: none;
    border-radius: 8px;
    background: var(--accent);
    color: #fff;
    font-size: 15px;
    font-weight: 600;
    cursor: pointer;
}

button:hover {
    filter: brightness(1.1);
}

.btn-secondary {
    display: block;
    width: 100%;
    margin-top: 10px;
    padding: 10px 14px;
    border: 1px solid var(--panel-border);
    border-radius: 8px;
    background: transparent;
    color: var(--muted);
    font-size: 15px;
    font-weight: 600;
    text-align: center;
    text-decoration: none;
}

.btn-secondary:hover {
    color: var(--text);
    border-color: var(--accent);
}

.auth-error {
    margin: 14px 0 0;
    color: var(--alert);
    font-size: 14px;
}

.auth-hint {
    margin: 16px 0 0;
    color: var(--muted);
    font-size: 13px;
    line-height: 1.5;
}

.auth-hint a {
    color: var(--accent);
}

.qr-wrap {
    margin: 20px 0 0;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 8px;
}

.qr-wrap svg {
    background: #fff;
    padding: 8px;
    border-radius: 8px;
}

.hidden {
    display: none !important;
}

.auth-status {
    margin: 14px 0 0;
    color: var(--alert);
    font-size: 14px;
}

.topbar {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 12px 20px;
    background: var(--panel);
    border-bottom: 1px solid var(--panel-border);
}

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

.device-chip {
    font-family: ui-monospace, monospace;
    font-size: 12px;
    background: var(--bg);
    border: 1px solid var(--panel-border);
    padding: 4px 10px;
    border-radius: 999px;
    color: var(--muted);
}

.inline-form {
    margin: 0;
}

.topbar-link {
    color: var(--accent);
    font-size: 14px;
    font-weight: 600;
    text-decoration: none;
    border: 1px solid var(--panel-border);
    padding: 6px 12px;
    border-radius: 8px;
    white-space: nowrap;
}

.topbar-link:hover {
    border-color: var(--accent);
    color: var(--text);
}

button.topbar-link {
    background: transparent;
    cursor: pointer;
    font-family: inherit;
    line-height: 1.2;
}

.device-list {
    list-style: none;
    margin: 0;
    padding: 0;
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.device-group {
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.device-group-title {
    display: flex;
    align-items: center;
    justify-content: space-between;
    font-size: 12px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--muted);
    padding: 0 2px;
}

.device-group-count {
    font-family: ui-monospace, monospace;
    font-weight: 600;
    font-size: 11px;
    padding: 1px 8px;
    border-radius: 999px;
    background: var(--panel);
    border: 1px solid var(--panel-border);
    color: var(--muted);
}

.device-group-count.alerta {
    color: var(--alert);
    border-color: rgba(231, 76, 60, 0.5);
}

.device-group-count.online {
    color: var(--ok);
    border-color: rgba(46, 204, 113, 0.5);
}

.device-group-list {
    list-style: none;
    margin: 0;
    padding: 0;
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.device-item {
    display: flex;
    flex-direction: column;
    gap: 6px;
    font-size: 13px;
    padding: 8px;
    border-radius: 6px;
    background: var(--panel);
    border: 1px solid transparent;
    cursor: pointer;
}

.device-item:hover {
    border-color: var(--accent);
}

.device-item.alerta {
    border-color: rgba(231, 76, 60, 0.35);
}

.device-head {
    display: flex;
    align-items: center;
    gap: 8px;
    min-width: 0;
}

.device-head .device-name {
    font-weight: 600;
    flex: 1;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.device-head .device-seen {
    font-size: 11px;
    text-align: right;
    white-space: nowrap;
}

.device-meta {
    display: flex;
    align-items: center;
    gap: 8px;
    min-width: 0;
}

.device-detail {
    font-family: ui-monospace, monospace;
    font-size: 11px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.settings-details {
    border-top: 1px solid var(--panel-border);
    padding-top: 6px;
}

.settings-details summary {
    cursor: pointer;
    color: var(--muted);
    font-size: 12px;
    user-select: none;
}

.settings-details summary:hover {
    color: var(--text);
}

.settings-details .settings-form {
    margin-top: 6px;
}

.settings-form {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.settings-row {
    display: grid;
    grid-template-columns: 1fr auto;
    align-items: center;
    gap: 10px;
    font-size: 12px;
}

.settings-label {
    color: var(--muted);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.settings-row input[type="checkbox"] {
    accent-color: var(--accent);
    width: 16px;
    height: 16px;
    justify-self: end;
    cursor: pointer;
}

.settings-row select {
    justify-self: end;
    padding: 4px 6px;
    border-radius: 6px;
    border: 1px solid var(--panel-border);
    background: var(--bg);
    color: var(--text);
    font-size: 13px;
}

.settings-row select:focus {
    outline: none;
    border-color: var(--accent);
}

.settings-actions {
    display: flex;
    justify-content: center;
    gap: 8px;
}

.monitor-save {
    padding: 4px 10px;
    font-size: 12px;
    border-radius: 6px;
}

.form-msg {
    color: var(--alert);
    font-size: 11px;
    text-align: right;
}

.monitor-save.danger {
    background: transparent;
    border: 1px solid rgba(231, 76, 60, 0.5);
    color: var(--alert);
}

.monitor-save.danger:hover {
    background: rgba(231, 76, 60, 0.12);
    filter: none;
}

.btn-plain {
    background: transparent;
    border: 1px solid var(--panel-border);
    color: var(--muted);
}

.layout {
    display: grid;
    grid-template-columns: 1fr 340px;
    gap: 0;
    height: calc(100vh - 57px);
}

.map-panel {
    position: relative;
}

#map {
    position: absolute;
    inset: 0;
    background: #1a1d24;
}

#map .leaflet-tile-pane {
    filter: invert(1) hue-rotate(180deg) brightness(0.9) contrast(0.9);
}

.side-panel {
    background: var(--panel);
    border-left: 1px solid var(--panel-border);
    overflow-y: auto;
    padding: 16px;
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.status-card {
    background: var(--bg);
    border: 1px solid var(--panel-border);
    border-radius: 10px;
    padding: 14px;
}

.status-card h2 {
    margin: 0 0 10px;
    font-size: 13px;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--muted);
}

.status-dot {
    display: inline-block;
    width: 10px;
    height: 10px;
    border-radius: 50%;
    background: var(--muted);
    margin-right: 6px;
}

.status-dot.online {
    background: var(--ok);
}

.status-dot.alert {
    background: var(--alert);
}

.status-dot.offline {
    background: var(--muted);
}

.muted {
    color: var(--muted);
    font-size: 13px;
}

.tag.confirmar {
    background: rgba(46, 204, 113, 0.15);
    color: var(--ok);
}

.tag.alerta {
    background: rgba(231, 76, 60, 0.15);
    color: var(--alert);
}

.event-history,
.location-history {
    border-top: 1px solid var(--panel-border);
    padding-top: 8px;
}

.event-history summary,
.location-history summary {
    cursor: pointer;
    color: var(--muted);
    font-size: 12px;
    user-select: none;
}

.event-history summary:hover,
.location-history summary:hover {
    color: var(--text);
}

.event-history-list,
.location-history-list {
    list-style: none;
    margin: 8px 0 0;
    padding: 0;
    display: flex;
    flex-direction: column;
    gap: 4px;
    max-height: 220px;
    overflow-y: auto;
}

.event-history-list li,
.location-history-list li {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 12px;
    padding: 4px 6px;
    border-radius: 6px;
    background: var(--bg);
}

.location-history-list li {
    cursor: pointer;
}

.location-history-list li:hover {
    border: 1px solid var(--accent);
    padding: 3px 5px;
}

.loc-history-coords {
    flex: 1;
    font-family: ui-monospace, monospace;
    font-size: 11px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.event-history-list .event-device {
    flex: 1;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.event-history-list .tag {
    font-weight: 600;
    text-transform: uppercase;
    font-size: 10px;
    padding: 1px 6px;
    border-radius: 999px;
    flex-shrink: 0;
}

.audio-controls {
    margin-top: 10px;
    display: flex;
    align-items: center;
    gap: 6px;
    flex-wrap: wrap;
}

.audio-label {
    font-size: 12px;
    color: var(--muted);
    min-width: 36px;
}

.audio-btn {
    background: var(--accent);
    color: #fff;
    border: none;
    border-radius: 4px;
    padding: 3px 12px;
    font-size: 12px;
    cursor: pointer;
    font-weight: 600;
}

.audio-btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

.audio-indicator {
    display: inline-block;
    width: 10px;
    height: 10px;
    border-radius: 50%;
    background: var(--muted);
    flex-shrink: 0;
}

.audio-indicator.recording {
    background: var(--alert);
    animation: audio-pulse 1s infinite;
}

@keyframes audio-pulse {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.3; }
}

.audio-error {
    font-size: 11px;
    color: var(--alert);
    width: 100%;
}

@media (max-width: 800px) {
    .layout {
        grid-template-columns: 1fr;
        grid-template-rows: 1fr auto;
        height: calc(100vh - 57px);
    }

    .side-panel {
        border-left: none;
        border-top: 1px solid var(--panel-border);
        max-height: 45vh;
    }
}
