@import url('https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700&display=swap');

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

/* ============================================ */
/* Temas */
/* ============================================ */

:root {
    --bg: #1a1d29;
    --card: #242837;
    --input: #2d3142;
    --accent: #3b82f6;
    --accent-hover: #2563eb;
    --text: #e4e4e7;
    --muted: #9ca3af;
    --border: #3f4451;
    --danger: #ef4444;
    --success: #22c55e;
    --warning: #f59e0b;
}

.theme-dark {
    --bg: #1a1d29;
    --card: #242837;
    --input: #2d3142;
    --text: #e4e4e7;
    --muted: #9ca3af;
    --border: #3f4451;
}

.theme-light {
    --bg: #f3f4f6;
    --card: #ffffff;
    --input: #f9fafb;
    --text: #111827;
    --muted: #6b7280;
    --border: #e5e7eb;
}

body {
    font-family: 'Inter', sans-serif;
    background: var(--bg);
    color: var(--text);
    min-height: 100vh;
    transition: background 0.3s, color 0.3s;
}

/* ============================================ */
/* Header */
/* ============================================ */

header {
    background: var(--card);
    border-bottom: 1px solid var(--border);
    padding: 10px 16px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    z-index: 1100;
    height: 52px;
    transition: background 0.3s, border-color 0.3s;
}

.logo {
    display: flex;
    align-items: center;
    gap: 8px;
}

.logo-icon {
    width: 22px;
    height: 22px;
    color: var(--accent);
}

h1 {
    font-size: 1.1em;
    font-weight: 600;
}

.mapa-id {
    font-size: 0.75em;
    color: var(--muted);
    margin-left: 8px;
    padding: 2px 6px;
    background: var(--input);
    border-radius: 4px;
}

.header-actions {
    display: flex;
    gap: 6px;
}

.header-btns {
    display: flex;
    gap: 4px;
    align-items: center;
}

/* Tema toggle */
#btn-tema svg {
    width: 16px;
    height: 16px;
}

.theme-dark #btn-tema .icon-sun {
    display: none;
}

.theme-dark #btn-tema .icon-moon {
    display: block;
}

.theme-light #btn-tema .icon-sun {
    display: block;
}

.theme-light #btn-tema .icon-moon {
    display: none;
}

/* ============================================ */
/* Buttons */
/* ============================================ */

.btn {
    padding: 7px 12px;
    border-radius: 6px;
    font-size: 0.8em;
    font-weight: 500;
    cursor: pointer;
    border: 1px solid var(--border);
    background: var(--input);
    color: var(--text);
    display: flex;
    align-items: center;
    gap: 4px;
    transition: all 0.15s;
}

.btn:hover {
    background: var(--border);
}

.btn.primary {
    background: var(--accent);
    border-color: var(--accent);
    color: #fff;
}

.btn.primary:hover {
    background: var(--accent-hover);
}

.btn.active {
    background: var(--accent);
    border-color: var(--accent);
    color: #fff;
}

.btn.danger {
    background: var(--danger);
    border-color: var(--danger);
    color: #fff;
}

.btn-sm {
    padding: 4px 8px;
    font-size: 0.75em;
}

.btn-submit {
    width: 100%;
    padding: 10px;
    background: var(--accent);
    border: none;
    border-radius: 6px;
    color: #fff;
    font-size: 0.85em;
    font-weight: 600;
    cursor: pointer;
    margin-top: 10px;
    transition: background 0.15s;
}

.btn-submit:hover {
    background: var(--accent-hover);
}

.btn-submit.danger {
    background: var(--danger);
    margin-top: 8px;
}

.btn-close-sm {
    background: none;
    border: none;
    color: var(--muted);
    font-size: 1em;
    cursor: pointer;
    padding: 4px 8px;
}

.btn-close-sm:hover {
    color: var(--text);
}

/* ============================================ */
/* Map */
/* ============================================ */

#map {
    width: 100%;
    height: calc(100vh - 52px);
    margin-top: 52px;
}

.leaflet-control-attribution {
    display: none !important;
}

/* ============================================ */
/* Search Bar */
/* ============================================ */

.search-bar {
    position: fixed;
    top: 62px;
    left: 10px;
    z-index: 800;
    display: flex;
    gap: 6px;
    background: var(--card);
    border-radius: 8px;
    padding: 6px;
    border: 1px solid var(--border);
}

.search-bar input,
.search-bar select {
    padding: 6px 10px;
    background: var(--input);
    border: 1px solid var(--border);
    border-radius: 4px;
    color: var(--text);
    font-size: 0.8em;
    font-family: inherit;
}

.search-bar input {
    width: 160px;
}

.search-bar select {
    width: 130px;
}

/* ============================================ */
/* Map Controls */
/* ============================================ */

.map-controls {
    position: fixed;
    top: 62px;
    right: 10px;
    z-index: 800;
    display: flex;
    flex-direction: column;
    gap: 4px;
    background: var(--card);
    border-radius: 8px;
    padding: 4px;
    border: 1px solid var(--border);
}

.map-control-btn {
    width: 34px;
    height: 34px;
    background: transparent;
    border: none;
    border-radius: 4px;
    color: var(--muted);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.15s;
}

.map-control-btn svg {
    width: 18px;
    height: 18px;
}

.map-control-btn:hover {
    background: var(--input);
    color: var(--text);
}

.map-control-btn.active {
    background: var(--accent);
    color: #fff;
}

.control-divider {
    height: 1px;
    background: var(--border);
    margin: 2px 0;
}

/* ============================================ */
/* Sidebar */
/* ============================================ */

.sidebar {
    position: fixed;
    right: -360px;
    top: 52px;
    width: 350px;
    height: calc(100vh - 52px);
    background: var(--card);
    border-left: 1px solid var(--border);
    transition: right 0.25s ease, background 0.3s;
    z-index: 1000;
    overflow-y: auto;
}

.sidebar.open {
    right: 0;
}

.sidebar-wide {
    width: 420px;
    right: -430px;
}

.sidebar-wide.open {
    right: 0;
}

.sidebar-header {
    padding: 14px 16px;
    border-bottom: 1px solid var(--border);
    display: flex;
    justify-content: space-between;
    align-items: center;
    font-weight: 600;
    position: sticky;
    top: 0;
    background: var(--card);
    z-index: 10;
}

.close-btn {
    background: none;
    border: none;
    color: var(--muted);
    font-size: 1.4em;
    cursor: pointer;
    line-height: 1;
}

.close-btn:hover {
    color: var(--text);
}

.sidebar-content {
    padding: 14px;
}

/* ============================================ */
/* Overlay */
/* ============================================ */

.overlay {
    position: fixed;
    top: 52px;
    left: 0;
    width: 100%;
    height: calc(100vh - 52px);
    background: rgba(0, 0, 0, 0.5);
    z-index: 999;
    display: none;
}

.overlay.active {
    display: block;
}

/* ============================================ */
/* Tabs */
/* ============================================ */

.tabs {
    display: flex;
    border-bottom: 1px solid var(--border);
    margin-bottom: 12px;
}

.tab {
    flex: 1;
    padding: 8px;
    background: none;
    border: none;
    color: var(--muted);
    font-size: 0.8em;
    font-weight: 500;
    cursor: pointer;
    border-bottom: 2px solid transparent;
    transition: all 0.15s;
}

.tab:hover {
    color: var(--text);
}

.tab.active {
    color: var(--accent);
    border-bottom-color: var(--accent);
}

.tab-content {
    display: none;
}

.tab-content.active {
    display: block;
}

/* ============================================ */
/* Forms */
/* ============================================ */

.form-group {
    margin-bottom: 10px;
}

.form-group label {
    display: block;
    font-size: 0.75em;
    color: var(--muted);
    margin-bottom: 4px;
    font-weight: 500;
}

.form-group input,
.form-group select,
.form-group textarea {
    width: 100%;
    padding: 8px 10px;
    background: var(--input);
    border: 1px solid var(--border);
    border-radius: 5px;
    color: var(--text);
    font-size: 0.85em;
    font-family: inherit;
    transition: background 0.3s, border-color 0.15s;
}

.form-group input:focus,
.form-group select:focus,
.form-group textarea:focus {
    outline: none;
    border-color: var(--accent);
}

.form-row {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 8px;
}

.form-divider {
    font-size: 0.75em;
    color: var(--muted);
    margin: 14px 0 10px;
    padding-top: 10px;
    border-top: 1px solid var(--border);
    font-weight: 500;
}

.color-input {
    height: 38px;
    padding: 4px;
    cursor: pointer;
}

.color-input::-webkit-color-swatch-wrapper {
    padding: 0;
}

.color-input::-webkit-color-swatch {
    border: none;
    border-radius: 4px;
}

/* Custom Color Picker */
.color-picker-custom {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    padding: 8px;
    background: var(--input);
    border: 1px solid var(--border);
    border-radius: 6px;
}

.color-swatch {
    width: 28px;
    height: 28px;
    border-radius: 6px;
    cursor: pointer;
    border: 2px solid transparent;
    transition: all 0.15s ease;
    position: relative;
}

.color-swatch:hover {
    transform: scale(1.15);
    z-index: 1;
}

.color-swatch.selected {
    border-color: #fff;
    box-shadow: 0 0 0 2px var(--accent), 0 2px 8px rgba(0, 0, 0, 0.3);
}

.color-swatch.selected::after {
    content: '✓';
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    color: #fff;
    font-size: 12px;
    font-weight: bold;
    text-shadow: 0 1px 2px rgba(0, 0, 0, 0.5);
}

.color-picker-custom input[type="color"] {
    width: 28px;
    height: 28px;
    padding: 0;
    border: 2px dashed var(--border);
    border-radius: 6px;
    cursor: pointer;
    background: transparent;
}

.color-picker-custom input[type="color"]::-webkit-color-swatch-wrapper {
    padding: 2px;
}

.color-picker-custom input[type="color"]::-webkit-color-swatch {
    border: none;
    border-radius: 3px;
}

/* ============================================ */
/* Comentários */
/* ============================================ */

.comentarios-section {
    margin-top: 16px;
}

.comentario-item {
    background: var(--input);
    border-radius: 6px;
    padding: 10px;
    margin-bottom: 8px;
}

.comentario-header {
    display: flex;
    justify-content: space-between;
    margin-bottom: 4px;
}

.comentario-header strong {
    font-size: 0.85em;
    color: var(--text);
}

.comentario-header small {
    font-size: 0.7em;
    color: var(--muted);
}

.comentario-item p {
    font-size: 0.8em;
    color: var(--muted);
    margin: 0;
}

.comentario-form {
    display: flex;
    flex-direction: column;
    gap: 6px;
    margin-top: 10px;
}

.comentario-form input,
.comentario-form textarea {
    padding: 8px 10px;
    background: var(--input);
    border: 1px solid var(--border);
    border-radius: 5px;
    color: var(--text);
    font-size: 0.8em;
    font-family: inherit;
}

.no-comments {
    text-align: center;
    color: var(--muted);
    padding: 12px;
    font-size: 0.8em;
}

/* ============================================ */
/* List Items */
/* ============================================ */

.item-card {
    background: var(--input);
    border: 1px solid var(--border);
    border-radius: 6px;
    padding: 10px;
    margin-bottom: 8px;
    transition: border-color 0.15s;
}

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

.item-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 6px;
}

.item-name {
    font-weight: 600;
    font-size: 0.9em;
}

.item-badge {
    padding: 2px 6px;
    border-radius: 8px;
    font-size: 0.65em;
    color: #fff;
    font-weight: 600;
}

.item-info {
    display: flex;
    gap: 10px;
    font-size: 0.75em;
    color: var(--muted);
    margin-bottom: 8px;
}

.item-actions {
    display: flex;
    gap: 4px;
}

.item-actions .btn {
    flex: 1;
    justify-content: center;
}

/* ============================================ */
/* Stats */
/* ============================================ */

.stats-section {
    margin-bottom: 16px;
}

.stats-title {
    font-size: 0.8em;
    font-weight: 600;
    color: var(--muted);
    margin-bottom: 10px;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.stats-grid-3 {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 8px;
    margin-bottom: 10px;
}

.stat-box {
    background: var(--input);
    border: 1px solid var(--border);
    border-radius: 6px;
    padding: 12px 8px;
    text-align: center;
}

.stat-box.sm {
    padding: 8px 6px;
}

.stat-num {
    font-size: 1.3em;
    font-weight: 700;
    color: var(--accent);
}

.stat-box.sm .stat-num {
    font-size: 1.1em;
}

.stat-txt {
    font-size: 0.7em;
    color: var(--muted);
    margin-top: 2px;
}

.stat-bar-row {
    display: grid;
    grid-template-columns: 80px 1fr 60px;
    align-items: center;
    gap: 8px;
    margin-bottom: 8px;
    font-size: 0.8em;
}

.stat-bar {
    height: 8px;
    background: var(--bg);
    border-radius: 4px;
    overflow: hidden;
}

.stat-bar-fill {
    height: 100%;
    border-radius: 4px;
    transition: width 0.3s;
}

.stats-empty {
    text-align: center;
    color: var(--muted);
    padding: 40px 0;
}

/* Compass Grid */
.compass-grid {
    display: grid;
    grid-template-columns: repeat(8, 1fr);
    gap: 4px;
    padding: 10px;
    background: var(--input);
    border-radius: 6px;
}

.compass-item {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 2px;
}

.compass-bar {
    width: 100%;
    min-height: 4px;
    max-height: 40px;
    background: var(--accent);
    border-radius: 2px;
    transition: height 0.3s;
}

.compass-item span {
    font-size: 0.7em;
    font-weight: 600;
    color: var(--text);
}

.compass-item small {
    font-size: 0.65em;
    color: var(--muted);
}

/* ============================================ */
/* Popup */
/* ============================================ */

.leaflet-popup-content-wrapper {
    background: var(--card);
    border: 1px solid var(--border);
    border-radius: 8px;
    color: var(--text);
}

.leaflet-popup-content {
    margin: 12px;
    font-family: 'Inter', sans-serif;
}

.leaflet-popup-tip {
    background: var(--card);
}

.popup-title {
    font-weight: 600;
    font-size: 1em;
    margin-bottom: 8px;
}

.popup-info {
    font-size: 0.8em;
    color: var(--muted);
    line-height: 1.5;
}

.popup-info strong {
    color: var(--text);
}

.popup-actions {
    margin-top: 10px;
    display: flex;
    gap: 4px;
}

.popup-btn {
    flex: 1;
    padding: 6px;
    border: none;
    border-radius: 4px;
    font-size: 0.75em;
    font-weight: 600;
    cursor: pointer;
    transition: opacity 0.15s;
}

.popup-btn:hover {
    opacity: 0.9;
}

.popup-btn.edit {
    background: var(--accent);
    color: #fff;
}

.popup-btn.delete {
    background: var(--danger);
    color: #fff;
}

.popup-btn.measure {
    background: var(--input);
    color: var(--text);
    border: 1px solid var(--border);
}

/* ============================================ */
/* Map Labels */
/* ============================================ */

.map-label {
    padding: 2px 6px;
    border-radius: 3px;
    font-size: 10px;
    font-weight: 600;
    color: #fff;
    white-space: nowrap;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.3);
}

/* ============================================ */
/* Context Menu */
/* ============================================ */

.context-menu {
    position: fixed;
    background: var(--card);
    border: 1px solid var(--border);
    border-radius: 6px;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.4);
    z-index: 2000;
    min-width: 160px;
    padding: 4px 0;
    display: none;
}

.context-menu.active {
    display: block;
}

.context-menu-header {
    padding: 6px 12px;
    font-size: 0.7em;
    color: var(--muted);
    border-bottom: 1px solid var(--border);
}

.context-menu-item {
    padding: 8px 12px;
    font-size: 0.8em;
    cursor: pointer;
    transition: background 0.1s;
}

.context-menu-item:hover {
    background: var(--input);
}

/* ============================================ */
/* Modal */
/* ============================================ */

.modal {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.7);
    z-index: 3000;
    display: none;
    align-items: center;
    justify-content: center;
}

.modal.active {
    display: flex;
}

.modal-content {
    background: var(--card);
    border: 1px solid var(--border);
    border-radius: 10px;
    width: 90%;
    max-width: 500px;
}

.modal-header {
    padding: 14px 16px;
    border-bottom: 1px solid var(--border);
    display: flex;
    justify-content: space-between;
    align-items: center;
    font-weight: 600;
}

.modal-body {
    padding: 16px;
}

/* Share Modal */
.share-link-box {
    display: flex;
    gap: 8px;
    margin: 12px 0;
}

.share-link-box input {
    flex: 1;
    padding: 10px;
    background: var(--input);
    border: 1px solid var(--border);
    border-radius: 6px;
    color: var(--text);
    font-size: 0.85em;
}

.share-note {
    font-size: 0.75em;
    color: var(--muted);
    margin-top: 8px;
}

/* ============================================ */
/* Medição Info */
/* ============================================ */

.medicao-info {
    position: fixed;
    bottom: 20px;
    left: 50%;
    transform: translateX(-50%);
    background: var(--card);
    border: 2px solid var(--accent);
    border-radius: 8px;
    padding: 10px 16px;
    display: none;
    align-items: center;
    gap: 12px;
    z-index: 900;
    font-size: 0.9em;
    font-weight: 500;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.3);
}

.medicao-info.active {
    display: flex;
}

/* ============================================ */
/* Animação de Sinal - Lightweight */
/* ============================================ */

.onda-sinal {
    pointer-events: none;
    will-change: opacity;
    animation: pulse-ring 2.5s ease-out infinite;
}

.onda-delay-1 {
    animation-delay: 1.25s;
}

@keyframes pulse-ring {
    0% {
        opacity: 0.5;
    }

    100% {
        opacity: 0;
    }
}

/* ============================================ */
/* Responsive */
/* ============================================ */

@media (max-width: 640px) {
    .search-bar {
        left: 50%;
        transform: translateX(-50%);
        top: 58px;
    }

    .search-bar input {
        width: 120px;
    }

    .search-bar select {
        width: 100px;
    }
}

@media (max-width: 480px) {
    .sidebar {
        width: 100%;
        right: -100%;
    }

    .sidebar-wide {
        width: 100%;
        right: -100%;
    }

    .header-actions .btn span {
        display: none;
    }

    h1 {
        font-size: 0.95em;
    }

    .stats-grid-3 {
        grid-template-columns: repeat(2, 1fr);
    }

    .search-bar {
        display: none;
    }
}