:root {
    --navy: #063956;
    --navy-dark: #03283f;
    --blue: #0b5e87;
    --teal: #0b8f82;
    --teal-dark: #087368;
    --orange: #f97316;
    --background: #f3f7f9;
    --card: #ffffff;
    --text: #183243;
    --muted: #64748b;
    --border: #e4edf1;
    --danger: #dc3545;
    --shadow: 0 12px 35px rgba(15, 63, 89, .10);
}

* {
    box-sizing: border-box;
}

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

.topbar {
    min-height: 78px;
    background: linear-gradient(110deg, var(--navy-dark), #075985 58%, #0f766e);
    box-shadow: 0 8px 30px rgba(6, 59, 92, .18);
}

.navbar-brand {
    color: #fff;
}

.navbar-brand:hover {
    color: #fff;
}

.brand-logo {
    width: 62px;
    height: 62px;
    object-fit: contain;
    flex: 0 0 auto;
}

.brand-logo-transparent {
    padding: 6px;
    background: #ffffff;
    border: 1px solid rgba(255, 255, 255, .72);
    border-radius: 14px;
    box-shadow: 0 6px 18px rgba(0, 22, 35, .20);
}

.navbar-brand span {
    line-height: 1.05;
}

.navbar-brand b {
    font-size: 1.25rem;
    letter-spacing: .04em;
}

.system-name {
    display: flex;
    flex-direction: column;
    justify-content: center;
    line-height: 1.05;
}

.system-name b,
.system-name strong {
    display: block;
    color: #fff;
    font-size: 1rem;
    font-weight: 800;
    letter-spacing: .055em;
}

.system-name strong {
    margin-top: 4px;
    font-size: 1.12rem;
}

.system-name small {
    margin-top: 5px;
}

.navbar-brand small {
    display: block;
    max-width: 500px;
    margin-top: 5px;
    font-size: .73rem;
    font-weight: 400;
    line-height: 1.25;
    opacity: .82;
    white-space: normal;
}

.btn {
    border-radius: 11px;
    font-weight: 700;
    transition: transform .18s ease, box-shadow .18s ease, background .18s ease;
}

.btn:hover {
    transform: translateY(-1px);
}

.btn i {
    margin-right: 6px;
}

.btn-glass {
    padding: .58rem .95rem;
    color: #fff;
    background: rgba(255, 255, 255, .12);
    border: 1px solid rgba(255, 255, 255, .32);
    backdrop-filter: blur(8px);
}

.btn-glass:hover {
    color: #fff;
    background: rgba(255, 255, 255, .22);
    border-color: rgba(255, 255, 255, .55);
}

.btn-action-primary {
    padding: .68rem 1.05rem;
    color: #fff;
    border: 0;
    background: linear-gradient(135deg, #0b8f82, #087368);
    box-shadow: 0 8px 18px rgba(11, 143, 130, .22);
}

.btn-action-primary:hover {
    color: #fff;
    background: linear-gradient(135deg, #0aa596, #087368);
    box-shadow: 0 11px 24px rgba(11, 143, 130, .30);
}

.btn-action-secondary {
    padding: .68rem 1.05rem;
    color: #fff;
    border: 0;
    background: linear-gradient(135deg, #0b5e87, #063956);
    box-shadow: 0 8px 18px rgba(6, 59, 92, .20);
}

.btn-action-secondary:hover {
    color: #fff;
    background: linear-gradient(135deg, #1479a9, #063956);
}

.btn-action-light {
    padding: .68rem 1.05rem;
    color: #39556a;
    background: #edf3f6;
    border: 1px solid #dbe7ec;
}

.btn-action-light:hover {
    color: #183243;
    background: #e1ecef;
}

.panel {
    overflow: hidden;
    border: 0;
    border-radius: 20px;
    box-shadow: var(--shadow);
}

.panel .card-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 1rem;
    min-height: 64px;
    padding: 1rem 1.2rem;
    background: #fff;
    border-bottom: 1px solid var(--border);
}

.panel .card-header b {
    color: #12384d;
}

.panel .card-header small {
    display: block;
    margin-top: 3px;
    color: var(--muted);
    font-size: .76rem;
    font-weight: 400;
}

.metric {
    position: relative;
    overflow: hidden;
    padding: 1rem 1.15rem;
    background: #fff;
    border-radius: 18px;
    box-shadow: var(--shadow);
}

.metric span {
    color: var(--muted);
    font-size: .77rem;
    letter-spacing: .04em;
    text-transform: uppercase;
}

.metric strong {
    display: block;
    font-size: 1.75rem;
}

.metric i {
    position: absolute;
    right: 16px;
    bottom: 12px;
    color: rgba(13, 148, 136, .18);
    font-size: 2rem;
}

#map {
    height: 550px;
}

.station-list {
    max-height: 550px;
    overflow: auto;
}

.station-row {
    display: block;
    width: 100%;
    margin-bottom: .65rem;
    padding: .85rem;
    cursor: pointer;
    border: 1px solid var(--border);
    border-left: 5px solid var(--status);
    border-radius: 14px;
    transition: .2s;
}

.station-row:hover {
    transform: translateY(-2px);
    box-shadow: 0 6px 20px rgba(15, 63, 89, .09);
}

.station-values {
    display: flex;
    gap: 1.2rem;
    margin-top: .5rem;
}

.station-values b {
    font-size: 1.05rem;
}

.station-values small {
    display: block;
    color: var(--muted);
}

.status-pill {
    padding: .45rem .8rem;
    color: #08796f;
    background: #e6f7f4;
    border-radius: 100px;
    font-size: .8rem;
}

.pulse {
    display: inline-block;
    width: 8px;
    height: 8px;
    margin-right: 6px;
    background: #10b981;
    border-radius: 50%;
    animation: pulse 2s infinite;
}

@keyframes pulse {
    70% { box-shadow: 0 0 0 9px rgba(16, 185, 129, 0); }
}

.chart-wrap {
    height: 340px;
}

.chart-range {
    width: 165px;
}

.legend-item {
    padding: .4rem .7rem;
    background: #fff;
    border-radius: 100px;
    box-shadow: 0 3px 12px rgba(15, 63, 89, .06);
    font-size: .78rem;
}

.legend-dot {
    display: inline-block;
    width: 10px;
    height: 10px;
    margin-right: 5px;
    border-radius: 50%;
}

footer {
    padding: 1.5rem;
    color: var(--muted);
    text-align: center;
    font-size: .8rem;
}

/* Panel de administración */

.admin-user {
    color: rgba(255, 255, 255, .88);
    font-size: .86rem;
}

.admin-heading {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 1rem;
    margin-bottom: 1.25rem;
}

.admin-heading h1 {
    margin: 0 0 .2rem;
    font-size: 1.6rem;
    font-weight: 800;
}

.admin-heading p {
    margin: 0;
    color: var(--muted);
}

.admin-tabs {
    gap: .55rem;
    padding: .45rem;
    background: #fff;
    border-radius: 16px;
    box-shadow: 0 5px 20px rgba(15, 63, 89, .08);
}

.admin-tabs .nav-link {
    padding: .72rem 1rem;
    color: #516a7a;
    border-radius: 12px;
    font-weight: 700;
}

.admin-tabs .nav-link i {
    margin-right: 7px;
}

.admin-tabs .nav-link.active {
    color: #fff;
    background: linear-gradient(135deg, #0b5e87, #0b8f82);
    box-shadow: 0 7px 17px rgba(11, 94, 135, .20);
}

.admin-stations-layout > div {
    display: flex;
}

.admin-map-card,
.stations-panel {
    width: 100%;
    min-height: 785px;
}

#adminMap {
    width: 100%;
    height: 510px;
    background: #dbe7ec;
}

.btn-map-center {
    color: #0b5e87;
    background: #edf7fb;
    border: 1px solid #cae7f2;
    font-size: .78rem;
}

.btn-map-center:hover {
    color: #fff;
    background: #0b5e87;
}

.station-form-area {
    padding: 1.25rem;
    border-top: 1px solid var(--border);
}

.form-section-title {
    display: flex;
    align-items: center;
    gap: .8rem;
    margin-bottom: 1.2rem;
}

.form-section-title > span {
    display: grid;
    width: 42px;
    height: 42px;
    color: #fff;
    place-items: center;
    background: linear-gradient(135deg, #0b5e87, #0b8f82);
    border-radius: 13px;
}

.form-section-title b,
.form-section-title small {
    display: block;
}

.form-section-title small {
    color: var(--muted);
    font-size: .75rem;
}

.form-label {
    margin-bottom: .38rem;
    color: #345367;
    font-size: .79rem;
    font-weight: 700;
}

.field-help {
    display: inline-grid;
    width: 18px;
    height: 18px;
    margin-left: 5px;
    color: #0b5e87;
    cursor: help;
    place-items: center;
    background: #e4f2f7;
    border: 1px solid #bedce8;
    border-radius: 50%;
    font-size: .68rem;
    font-weight: 900;
    line-height: 1;
}

.field-help:hover,
.field-help:focus {
    color: #fff;
    outline: none;
    background: #0b5e87;
}

.tooltip-inner {
    max-width: 290px;
    padding: .65rem .75rem;
    text-align: left;
    font-size: .75rem;
}

.form-control,
.form-select,
.input-group-text {
    min-height: 43px;
    border-color: #dce7ec;
    border-radius: 10px;
}

.form-control:focus,
.form-select:focus {
    border-color: #39a99f;
    box-shadow: 0 0 0 .22rem rgba(11, 143, 130, .12);
}

.input-group .form-control {
    border-radius: 10px 0 0 10px;
}

.input-group-text {
    border-radius: 0 10px 10px 0;
}

.station-switch {
    padding: .75rem .9rem .75rem 3.2rem;
    background: #f1f7f7;
    border: 1px solid #deeceb;
    border-radius: 12px;
}

.station-switch .form-check-input {
    width: 2.3rem;
    height: 1.2rem;
}

.station-cards {
    display: grid;
    grid-template-columns: 1fr;
    align-content: start;
    max-height: none;
    padding: 1rem;
    overflow: visible;
}

.station-total {
    display: grid;
    width: 38px;
    height: 38px;
    color: #fff;
    place-items: center;
    background: linear-gradient(135deg, #0b5e87, #0b8f82);
    border-radius: 12px;
    font-weight: 800;
}

.admin-station-card {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 1rem;
    margin-bottom: .8rem;
    padding: 1rem;
    background: linear-gradient(135deg, #fff, #fbfdfe);
    border: 1px solid var(--border);
    border-radius: 16px;
    transition: .2s;
}

.admin-station-card > * {
    position: relative;
    z-index: 1;
}

.admin-station-card:hover {
    transform: translateY(-2px);
    border-color: #c7dce4;
    box-shadow: 0 9px 24px rgba(15, 63, 89, .09);
}

.station-card-main {
    display: flex;
    align-items: center;
    gap: .85rem;
    min-width: 0;
}

.station-icon {
    display: grid;
    width: 46px;
    height: 46px;
    flex: 0 0 auto;
    place-items: center;
    border-radius: 14px;
}

.station-icon.real {
    color: #087368;
    background: #ddf5f1;
}

.station-icon.simulated {
    color: #0b5e87;
    background: #e3f1f7;
}

.station-card-info {
    min-width: 0;
}

.station-card-info h3 {
    margin: 0;
    font-size: .98rem;
    font-weight: 800;
}

.station-card-info p {
    margin: .28rem 0;
    color: var(--muted);
    font-size: .77rem;
}

.station-card-info small {
    color: #718697;
    font-size: .72rem;
}

.status-badge {
    padding: .25rem .5rem;
    border-radius: 100px;
    font-size: .66rem;
    font-weight: 800;
}

.status-badge.active {
    color: #087368;
    background: #dcf7f0;
}

.status-badge.inactive {
    color: #64748b;
    background: #edf1f3;
}

.station-card-actions {
    display: flex;
    flex: 0 0 auto;
    gap: .45rem;
}

.station-card-actions form {
    display: inline-flex;
    margin: 0;
}

.btn-edit-station,
.btn-delete-station {
    padding: .5rem .7rem;
    border: 1px solid;
    font-size: .75rem;
}

.btn-edit-station {
    color: #0b5e87;
    background: #edf7fb;
    border-color: #cce6f1;
}

.btn-edit-station:hover {
    color: #fff;
    background: #0b5e87;
}

.btn-delete-station {
    color: #c73746;
    background: #fff0f1;
    border-color: #f4cbd0;
}

.btn-delete-station:hover {
    color: #fff;
    background: #dc3545;
}

.empty-state {
    padding: 4rem 1rem;
    color: var(--muted);
    text-align: center;
}

.empty-state i {
    margin-bottom: .8rem;
    color: #b4c7d0;
    font-size: 3rem;
}

.empty-state h3 {
    color: #36566a;
    font-size: 1.05rem;
}

.threshold-card {
    border-top: 4px solid var(--threshold-color, #0b8f82);
}

.threshold-type {
    display: inline-block;
    padding: .35rem .65rem;
    color: #fff;
    background: var(--threshold-color);
    border-radius: 100px;
    font-size: .72rem;
    font-weight: 800;
    text-transform: uppercase;
}

/* Acceso */

.login-page {
    display: grid;
    min-height: 100vh;
    place-items: center;
    background: linear-gradient(135deg, #052f4c, #0f766e);
}

.login-card {
    width: min(92vw, 420px);
    padding: 2rem;
    background: #fff;
    border-radius: 24px;
    box-shadow: 0 20px 60px rgba(0, 27, 43, .40);
}

.login-card img {
    display: block;
    width: 150px;
    height: 125px;
    margin: auto;
    object-fit: contain;
}

.login-card h1 {
    margin-top: 1rem;
    text-align: center;
    font-size: 1.4rem;
}

.login-card p {
    color: var(--muted);
    text-align: center;
}

.leaflet-control-layers {
    overflow: hidden;
    padding: 0;
    border: 0 !important;
    border-radius: 13px;
    box-shadow: 0 7px 24px rgba(6, 59, 92, .18) !important;
}

.leaflet-control-layers-expanded {
    padding: .65rem .75rem;
    color: #244658;
    background: rgba(255, 255, 255, .94);
    backdrop-filter: blur(8px);
}

.leaflet-control-layers label {
    margin: .18rem 0;
    cursor: pointer;
    font-size: .76rem;
    font-weight: 700;
}

.leaflet-control-layers input {
    accent-color: var(--teal);
}

.isotherm-label {
    padding: 2px 6px;
    color: #15384c;
    background: rgba(255, 255, 255, .88);
    border: 1px solid rgba(8, 77, 110, .20);
    border-radius: 100px;
    box-shadow: 0 2px 8px rgba(6, 59, 92, .12);
    font-size: .66rem;
    font-weight: 800;
}

.isotherm-label::before {
    display: none;
}

.thermal-risk-tooltip {
    min-width: 275px;
    padding: 0;
    color: #17394c;
    background: rgba(255, 255, 255, .97);
    border: 0;
    border-radius: 14px;
    box-shadow: 0 10px 32px rgba(6, 59, 92, .22);
}

.thermal-risk-tooltip::before {
    display: none;
}

.thermal-tooltip-content {
    padding: .75rem;
}

.thermal-tooltip-content > b {
    display: block;
    margin-bottom: .55rem;
    color: #0b405d;
    font-size: .78rem;
}

.thermal-tooltip-values {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: .4rem;
    margin-bottom: .6rem;
}

.thermal-tooltip-values span {
    padding: .42rem;
    text-align: center;
    background: #f1f7f9;
    border-radius: 9px;
}

.thermal-tooltip-values small,
.thermal-tooltip-values strong {
    display: block;
}

.thermal-tooltip-values small {
    color: #718797;
    font-size: .58rem;
}

.thermal-tooltip-values strong {
    font-size: .76rem;
}

.risk-comparison {
    display: grid;
    gap: .35rem;
}

.risk-comparison span {
    font-size: .7rem;
}

.risk-comparison i {
    display: inline-block;
    width: 9px;
    height: 9px;
    margin-right: 5px;
    border-radius: 50%;
}

.risk-legend-group {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: .45rem;
    width: 100%;
    padding: .6rem;
    background: rgba(255, 255, 255, .62);
    border-radius: 14px;
}

.risk-legend-group > b {
    min-width: 120px;
    color: #23475a;
    font-size: .78rem;
}

.thermal-map-legend {
    min-width: 190px;
    padding: .7rem .8rem;
    color: #244658;
    background: rgba(255, 255, 255, .94);
    border-radius: 13px;
    box-shadow: 0 7px 24px rgba(6, 59, 92, .18);
    backdrop-filter: blur(8px);
}

.thermal-map-legend b {
    display: block;
    margin-bottom: .45rem;
    font-size: .74rem;
}

.ith-risk-scale {
    display: grid;
    gap: 5px;
    margin: 9px 0 7px;
}

.ith-risk-scale span {
    display: flex;
    align-items: center;
    gap: 7px;
    font-size: .76rem;
    font-weight: 700;
}

.ith-risk-scale span span {
    display: inline;
    font-size: inherit;
    font-weight: inherit;
}

.ith-risk-scale i {
    width: 24px;
    height: 10px;
    flex: 0 0 24px;
    border-radius: 999px;
    background: var(--risk-color);
    box-shadow: inset 0 0 0 1px rgba(0, 0, 0, .08);
}

.thermal-map-legend > small {
    display: block;
    max-width: 230px;
    line-height: 1.25;
    color: #617989;
}

.cattle-risk-selector {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 5px;
    margin: 6px 0 10px;
}

.map-metric-selector {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 5px;
    margin: 6px 0 10px;
}

.map-metric-selector button,
.cattle-risk-selector button {
    min-height: 34px;
}

.map-metric-selector button {
    border: 1px solid #c8d9e2;
    border-radius: 9px;
    padding: 6px 7px;
    color: #345367;
    background: #f6fafc;
    font-size: .69rem;
    font-weight: 800;
    cursor: pointer;
    transition: .18s ease;
}

.map-metric-selector button:hover {
    border-color: #0b5e87;
    color: #0b5e87;
}

.map-metric-selector button.active {
    border-color: #0b5e87;
    color: #fff;
    background: #0b5e87;
    box-shadow: 0 4px 10px rgba(11, 94, 135, .22);
}

.legend-section-title {
    margin: 4px 0 2px;
    color: #617989;
    font-size: .66rem;
    font-weight: 800;
    text-transform: uppercase;
    letter-spacing: .04em;
}

.temperature-map-scale {
    margin: 10px 0 8px;
}

.cattle-risk-selector button {
    border: 1px solid #c8d9e2;
    border-radius: 9px;
    padding: 6px 8px;
    color: #345367;
    background: #f6fafc;
    font-size: .72rem;
    font-weight: 800;
    cursor: pointer;
    transition: .18s ease;
}

.cattle-risk-selector button:hover {
    border-color: #0d9488;
    color: #087368;
}

.cattle-risk-selector button.active {
    border-color: #0d9488;
    color: #fff;
    background: #0d9488;
    box-shadow: 0 4px 10px rgba(13, 148, 136, .22);
}

.thermal-gradient {
    height: 10px;
    background: linear-gradient(90deg, #1769ff, #00c7c7, #63d34f, #ffd534, #ff7200, #e60026);
    border-radius: 100px;
}

.thermal-scale {
    display: flex;
    justify-content: space-between;
    margin-top: .25rem;
    color: #617989;
    font-size: .64rem;
    font-weight: 700;
}

@media (max-width: 1199px) {
    .admin-map-card,
    .stations-panel {
        min-height: auto;
    }

    .stations-panel {
        max-height: none;
    }

    .station-cards {
        max-height: none;
    }
}

@media (max-width: 768px) {
    .topbar {
        min-height: 68px;
    }

    .brand-logo {
        width: 48px;
        height: 48px;
    }

    .navbar-brand small {
        max-width: 205px;
    }

    .system-name b,
    .system-name strong {
        font-size: .72rem;
    }

    .system-name strong {
        margin-top: 3px;
    }

    #map {
        height: 430px;
    }

    #adminMap {
        height: 420px;
    }

    .metric strong {
        font-size: 1.35rem;
    }

    .admin-heading {
        align-items: flex-start;
        flex-direction: column;
    }

    .admin-tabs {
        flex-wrap: nowrap;
        overflow-x: auto;
    }

    .admin-tabs .nav-link {
        white-space: nowrap;
    }

    .admin-station-card {
        align-items: flex-start;
        flex-direction: column;
    }

    .station-card-main {
        width: 100%;
    }

    .station-card-actions {
        width: 100%;
    }

    .station-card-actions .btn,
    .station-card-actions form {
        flex: 1;
    }

    .station-card-actions form .btn {
        width: 100%;
    }
}
