/* ============================================================================
   Fleet — piezas propias del panel. Solo tokens de _theme.css, nunca hex.
   What every screen shares lives in admin.css (ux-* library).
   ============================================================================ */

[x-cloak] { display: none !important; }

/* Theme icon: the sun in dark (switches to light), the moon in light. */
.fleet-light-only { display: none; }
[data-theme="light"] .fleet-light-only { display: inline-flex; }
[data-theme="light"] .fleet-dark-only { display: none; }

/* Server environment (local, glo-bak…), so tabs are never confused. */
.fleet-env {
    align-items: center;
    gap: 6px;
    padding: 4px 10px;
    border-radius: 999px;
    font-size: 0.72rem;
    font-weight: 600;
    letter-spacing: 0.04em;
    text-transform: uppercase;
    color: var(--color-text-secondary);
    border: 1px solid var(--color-border);
}

.fleet-badge-danger {
    background: var(--color-danger) !important;
    color: var(--color-text-inverse) !important;
}

.fleet-flashes { display: flex; flex-direction: column; gap: 8px; margin-bottom: 16px; }

/* Page intro inside the content: what the page does and its actions. */
.fleet-intro {
    display: flex;
    flex-wrap: wrap;
    align-items: flex-end;
    justify-content: space-between;
    gap: 12px 24px;
    margin-bottom: 20px;
}
.fleet-intro p { margin: 0; color: var(--color-text-secondary); max-width: 72ch; }
.fleet-intro-actions { display: flex; flex-wrap: wrap; gap: 8px; }

/* Home hero: greeting, overall status and the trackers' constellation. */
.fleet-hero {
    position: relative;
    overflow: hidden;
    padding: 24px;
    border-radius: var(--radius-card);
    border: 1px solid var(--color-card-border);
    background:
        radial-gradient(120% 140% at 100% 0%, var(--color-primary-light) 0%, transparent 55%),
        var(--color-card-translucent);
}
.fleet-hero h2 {
    margin: 0 0 4px;
    font-family: var(--font-family-heading);
    font-size: 1.6rem;
    letter-spacing: -0.02em;
    color: var(--color-text-primary);
}
.fleet-hero p { margin: 0; color: var(--color-text-secondary); }

/* Tracker grid: one chip per device with its status at a glance. */
.fleet-constellation { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 18px; }
.fleet-chip {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    padding: 6px 10px 6px 8px;
    border-radius: 10px;
    border: 1px solid var(--color-border);
    background: var(--color-panel-sunken);
    color: var(--color-text);
    font-size: 0.8rem;
    font-weight: 600;
    text-decoration: none;
    font-variant-numeric: tabular-nums;
}
.fleet-chip:hover { border-color: var(--color-border-strong); background: var(--color-pressed); }
.fleet-chip small { font-weight: 500; color: var(--color-text-muted); }

/* Status dot with a halo when alive. */
.fleet-dot {
    position: relative;
    width: 9px;
    height: 9px;
    border-radius: 50%;
    flex-shrink: 0;
    background: var(--color-text-muted);
}
.fleet-dot--ok { background: var(--color-success); }
.fleet-dot--warning { background: var(--color-warning); }
.fleet-dot--error { background: var(--color-danger); }
.fleet-dot--ok::after {
    content: "";
    position: absolute;
    inset: -4px;
    border-radius: 50%;
    border: 2px solid var(--color-success);
    opacity: 0;
    animation: fleet-heartbeat 2.4s ease-out infinite;
}
@keyframes fleet-heartbeat {
    0% { transform: scale(0.6); opacity: 0.7; }
    100% { transform: scale(1.6); opacity: 0; }
}
@media (prefers-reduced-motion: reduce) {
    .fleet-dot--ok::after { animation: none; }
}

/* Battery: short bar with the percentage next to it. */
.fleet-battery { display: inline-flex; align-items: center; gap: 6px; font-variant-numeric: tabular-nums; white-space: nowrap; }
.fleet-battery-bar {
    position: relative;
    width: 28px;
    height: 12px;
    border-radius: 3px;
    border: 1.5px solid var(--color-text-muted);
    overflow: hidden;
}
.fleet-battery-bar > span { position: absolute; inset: 1px auto 1px 1px; border-radius: 1px; background: var(--color-success); }
.fleet-battery-bar.is-medium > span { background: var(--color-warning); }
.fleet-battery-bar.is-low > span { background: var(--color-danger); }

/* Signal: four bars. */
.fleet-signal { display: inline-flex; align-items: flex-end; gap: 2px; height: 14px; }
.fleet-signal > span { width: 3px; border-radius: 1px; background: var(--color-border-strong); }
.fleet-signal > span:nth-child(1) { height: 25%; }
.fleet-signal > span:nth-child(2) { height: 50%; }
.fleet-signal > span:nth-child(3) { height: 75%; }
.fleet-signal > span:nth-child(4) { height: 100%; }
.fleet-signal > span.on { background: var(--color-primary-text); }

/* Timeline (commands, assignments, setup). */
.fleet-timeline { list-style: none; margin: 0; padding: 0; }
.fleet-timeline > li {
    position: relative;
    display: flex;
    gap: 14px;
    padding: 0 0 18px 0;
}
.fleet-timeline > li::before {
    content: "";
    position: absolute;
    left: 17px;
    top: 36px;
    bottom: 0;
    width: 2px;
    background: var(--color-separator);
}
.fleet-timeline > li:last-child::before { display: none; }
.fleet-timeline-icon {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    width: 36px;
    height: 36px;
    border-radius: 50%;
    background: var(--color-panel-sunken);
    border: 2px solid var(--color-border);
    color: var(--color-text-muted);
    z-index: 1;
}
.fleet-timeline-icon.is-ok { border-color: var(--color-success); color: var(--color-success-text); background: var(--color-success-light); }
.fleet-timeline-icon.is-aviso { border-color: var(--color-warning); color: var(--color-warning-text); background: var(--color-warning-light); }
.fleet-timeline-icon.is-error { border-color: var(--color-danger); color: var(--color-danger-text); background: var(--color-danger-light); }
.fleet-timeline-icon.is-current { border-color: var(--color-primary); color: var(--color-primary-text); background: var(--color-primary-light); }
.fleet-timeline-text { flex: 1; min-width: 0; padding-top: 6px; }
.fleet-timeline-text strong { color: var(--color-text-primary); }
.fleet-timeline-text p { margin: 2px 0 0; color: var(--color-text-secondary); font-size: 0.86rem; }

/* Thin progress bar. */
.fleet-progress { height: 6px; border-radius: 99px; background: var(--color-panel-sunken); overflow: hidden; }
.fleet-progress > span { display: block; height: 100%; border-radius: 99px; background: var(--color-primary); }
.fleet-progress.is-ok > span { background: var(--color-success); }

/* Code, commands and tracker answers. */
.fleet-code {
    display: block;
    padding: 10px 12px;
    border-radius: var(--radius-tile);
    background: var(--color-panel-sunken);
    border: 1px solid var(--color-border);
    font-family: var(--font-family-mono);
    font-size: 0.8rem;
    color: var(--color-text);
    white-space: pre-wrap;
    word-break: break-all;
}

/* Secret shown only once. */
.fleet-secret {
    padding: 16px;
    border-radius: var(--radius-tile);
    border: 1px dashed var(--color-warning);
    background: var(--color-warning-light);
}

/* Permission matrix. */
.fleet-yes { color: var(--color-success-text); font-weight: 700; }
.fleet-no { color: var(--color-text-muted); }

/* Map on the device detail. */
.fleet-map { height: 260px; border-radius: var(--radius-tile); overflow: hidden; border: 1px solid var(--color-border); background: var(--color-panel-sunken); }

/* Option card lists (send profiles). */
.fleet-options { display: grid; grid-template-columns: repeat(auto-fill, minmax(170px, 1fr)); gap: 10px; }
.fleet-option {
    display: flex;
    flex-direction: column;
    gap: 4px;
    width: 100%;
    padding: 12px 14px;
    text-align: left;
    border-radius: var(--radius-control);
    border: 1px solid var(--color-border);
    background: var(--color-panel-sunken);
    color: var(--color-text);
    cursor: pointer;
}
.fleet-option:hover { border-color: var(--color-primary); }
.fleet-option:focus-visible { outline: none; box-shadow: 0 0 0 3px rgba(var(--color-primary-rgb), 0.25); }
.fleet-option strong { color: var(--color-text-primary); font-family: var(--font-family-heading); }
.fleet-option span { font-size: 0.8rem; color: var(--color-text-secondary); }
.fleet-option.is-current { border-color: var(--color-success); background: var(--color-success-light); }

/* Django forms with the panel look (templates/panel/_field.html). */
.form-group { display: flex; flex-direction: column; gap: 6px; min-width: 0; }
.form-group .form-label { margin: 0; }
.form-error { margin: 2px 0 0; font-size: 0.8rem; font-weight: 600; color: var(--color-danger-text); }
.admin-form textarea { width: 100%; }
.fleet-form-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(260px, 1fr)); gap: 18px 20px; }
.fleet-form-grid .ux-toggle, .fleet-form-grid .fleet-wide { grid-column: 1 / -1; }
.fleet-form-errors { margin-bottom: 16px; }

/* «Your turn» icon tinted by urgency. */
.fleet-todo-error { background: var(--color-danger-light); color: var(--color-danger-text); }
.fleet-todo-warning, .fleet-todo-no_response { background: var(--color-warning-light); color: var(--color-warning-text); }
.fleet-todo-info { background: var(--color-info-light); color: var(--color-info-text); }

/* Four figures in a row when they fit; two per row on mobile. */
.ux-stats.fleet-stats-4 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
@media (min-width: 640px) { .ux-stats.fleet-stats-4 { grid-template-columns: repeat(4, minmax(0, 1fr)); } }

/* Check tile: left border in its status colour (plus the pill with text). */
.fleet-check { border-left: 4px solid var(--color-border); }
.fleet-check--ok { border-left-color: var(--color-success); }
.fleet-check--warning { border-left-color: var(--color-warning); }
.fleet-check--error, .fleet-check--no_response { border-left-color: var(--color-danger); }
.fleet-option:disabled { opacity: 0.45; cursor: not-allowed; border-style: dashed; }
.fleet-option:disabled:hover { border-color: var(--color-border); }
/* Careful: .form-help has display:block !important in admin.css and overrides x-show; for texts
   that Alpine shows and hides, use another class (known trap of the shared panel). */

/* --- Live map ------------------------------------------------------------------ */
.fleet-map-screen { display: grid; grid-template-columns: 1fr; gap: 16px; }
@media (min-width: 1024px) {
    .fleet-map-screen { grid-template-columns: 340px minmax(0, 1fr); height: calc(100vh - var(--header-height) - 56px); min-height: 520px; }
}
.fleet-map-list { display: flex; flex-direction: column; overflow: hidden; min-height: 0; }
.fleet-map-rows { list-style: none; margin: 0; padding: 6px; overflow-y: auto; flex: 1; max-height: 50vh; }
@media (min-width: 1024px) { .fleet-map-rows { max-height: none; } }
.fleet-map-row {
    display: flex; align-items: center; gap: 10px; width: 100%; padding: 10px; border-radius: var(--radius-tile);
    background: none; border: 1px solid transparent; color: var(--color-text); cursor: pointer;
}
.fleet-map-row:hover { background: var(--color-pressed); }
.fleet-map-row.is-selected { border-color: var(--color-primary); background: var(--color-primary-subtle); }
.fleet-map-row:focus-visible { outline: none; box-shadow: 0 0 0 3px rgba(var(--color-primary-rgb), 0.25); }
.fleet-map-color { width: 4px; align-self: stretch; border-radius: 4px; flex-shrink: 0; }
.fleet-map-area { position: relative; overflow: hidden; min-height: 60vh; padding: 0; }
.fleet-map-canvas { position: absolute; inset: 0; }
.fleet-map-controls { position: absolute; z-index: 500; top: 12px; right: 12px; display: flex; flex-wrap: wrap; gap: 6px; justify-content: flex-end; }
.ux-chip.is-active { border-color: var(--color-primary); background: var(--color-primary-light); color: var(--color-text-primary); }

/* Marker: dot in the tracker's colour with a status ring and its name below. */
.fleet-pin { position: relative; display: block; width: 30px; height: 30px; }
.fleet-pin-dot {
    position: absolute; inset: 6px; border-radius: 50%; background: var(--c);
    border: 3px solid #fff; box-shadow: 0 0 0 3px var(--anillo, #8a97ad), 0 2px 8px rgba(0, 0, 0, .45);
}
.fleet-pin--ok { --anillo: #34d399; }
.fleet-pin--warning { --anillo: #fbbf24; }
.fleet-pin--error { --anillo: #f87171; }
.fleet-pin.has-alert .fleet-pin-dot { animation: fleet-alert 1.2s ease-in-out infinite; }
.fleet-pin.is-selected .fleet-pin-dot { inset: 2px; }
.fleet-pin-name {
    position: absolute; top: 30px; left: 50%; transform: translateX(-50%); white-space: nowrap;
    padding: 1px 6px; border-radius: 6px; font: 600 11px/1.4 var(--font-family-base);
    background: rgba(6, 42, 31, .85); color: #ffffff;
}
@keyframes fleet-alert { 50% { box-shadow: 0 0 0 7px rgba(248, 113, 113, .45), 0 2px 8px rgba(0, 0, 0, .45); } }
@media (prefers-reduced-motion: reduce) { .fleet-pin.has-alert .fleet-pin-dot { animation: none; } }
.fleet-popup { display: flex; flex-direction: column; gap: 2px; font-size: 12.5px; min-width: 190px; }
.fleet-popup strong { font-size: 14px; }
.fleet-popup-alert { color: #b91c1c; font-weight: 600; }
.fleet-popup-links { display: flex; gap: 12px; margin-top: 6px; font-weight: 600; }

.fleet-map-controls .btn-secondary { background: var(--color-card); border-color: var(--color-border-strong); box-shadow: 0 2px 8px rgba(0, 0, 0, .25); }
.fleet-map-controls .btn-secondary:disabled { opacity: .55; }

/* Language switcher on the login page */
.fleet-lang { background: none; border: 0; padding: 4px 10px; border-radius: 999px; font-size: 13px; font-weight: 600; color: var(--color-text-secondary); cursor: pointer; }
.fleet-lang:hover { color: var(--color-text-primary); background: var(--color-pressed); }
.fleet-lang.is-current { color: var(--color-primary); background: rgba(var(--color-primary-rgb), .12); }
.fleet-lang:focus-visible { outline: 2px solid var(--color-primary); outline-offset: 2px; }

/* admin.css makes .btn-xs a 28 px square (icon buttons); with text it must grow. */
.btn-xs { width: auto; min-width: 28px; padding-inline: 8px; }

/* Leaflet panes use z-index 400+: keep them inside their own stacking context so the
   map never paints over the sidebar or the header when the page scrolls. */
.leaflet-container { isolation: isolate; z-index: 0; }

/* File picker of the packing list import */
.fleet-drop, .admin-form .fleet-drop { display: flex !important; flex-direction: column; align-items: center; gap: 6px; padding: 32px 16px; border: 2px dashed var(--color-border); border-radius: 16px; cursor: pointer; text-align: center; color: var(--color-text-secondary); }
.fleet-drop:hover, .fleet-drop:focus-within { border-color: var(--color-primary); }
.fleet-drop strong { color: var(--color-text-primary); }
.fleet-drop.has-file { border-style: solid; border-color: var(--color-primary); }

/* Concept map of Home (_p/flow_map.html): nodes and links in a row, a column on a phone. */
.fleet-flow-lane { display: flex; align-items: center; gap: 8px; margin: 0; font-size: .8125rem; font-weight: 600; color: var(--color-text-secondary); }
.fleet-flow-lane-dot { width: 10px; height: 10px; border-radius: 999px; background: var(--color-primary); }
.fleet-flow-lane-dot.is-out { background: var(--color-secondary); }
.fleet-flow { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; align-items: stretch; gap: 4px; }
.fleet-flow-node { flex: 1 1 0; min-width: 0; display: flex; }
.fleet-flow-node--core { flex-grow: 1.4; }
.fleet-flow-box {
    flex: 1; display: flex; flex-direction: column; gap: 6px; padding: 14px 16px; border-radius: 14px;
    border: 1px solid var(--color-border-light); background: var(--color-surface-elevated); color: var(--color-text);
    text-decoration: none; transition: border-color .15s, transform .15s;
}
a.fleet-flow-box:hover, a.fleet-flow-box:focus-visible { border-color: var(--color-primary); transform: translateY(-1px); }
.fleet-flow-node--core .fleet-flow-box { border-color: rgba(var(--color-primary-rgb), .55); background: var(--color-primary-subtle); }
.fleet-flow-box--flat { background: transparent; border-style: dashed; }
.fleet-flow-box strong { font-family: var(--font-family-heading, inherit); font-size: 1rem; color: var(--color-text-primary); }
.fleet-flow-icon { display: inline-flex; width: 34px; height: 34px; align-items: center; justify-content: center; border-radius: 10px; background: var(--color-primary-light); color: var(--color-primary-text); }
.fleet-flow--back .fleet-flow-icon { background: var(--color-secondary-light); color: var(--color-secondary-text); }
.fleet-flow-role { font-size: .8125rem; line-height: 1.45; color: var(--color-text-secondary); }
.fleet-flow-figure { margin-top: auto; font-size: .8125rem; font-weight: 600; color: var(--color-text-primary); font-variant-numeric: tabular-nums; }
.fleet-flow-steps { margin: 0; padding-left: 18px; font-size: .8125rem; line-height: 1.45; color: var(--color-text-secondary); }
.fleet-flow-steps li + li { margin-top: 2px; }
/* Link: label + arrow; vertical on a phone, horizontal from 1024 px. */
.fleet-flow-link { display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px; padding: 2px 0; color: var(--color-text-muted); }
.fleet-flow-link span { font-size: .6875rem; font-weight: 600; text-align: center; letter-spacing: .01em; }
.fleet-flow-link i { position: relative; width: 2px; height: 18px; background: currentColor; opacity: .7; }
.fleet-flow-link i::after { content: ""; position: absolute; left: 50%; bottom: -2px; width: 8px; height: 8px; border-right: 2px solid currentColor; border-bottom: 2px solid currentColor; transform: translateX(-50%) rotate(45deg); }
@media (min-width: 1024px) {
    .fleet-flow { flex-direction: row; align-items: stretch; gap: 0; }
    .fleet-flow-link { flex: 0 0 104px; padding: 0 6px; }
    .fleet-flow-link i { width: 100%; height: 2px; }
    .fleet-flow-link i::after { left: auto; right: -1px; bottom: auto; top: 50%; transform: translateY(-50%) rotate(-45deg); }
}

/* Live map status (live_map.html): state in words + a dot that beats once per refresh. */
.fleet-live { display: inline-flex; align-items: center; gap: 8px; min-width: 0; font-size: .8125rem; color: var(--color-text-secondary); }
.fleet-live-text { display: flex; flex-wrap: wrap; column-gap: 6px; min-width: 0; }
.fleet-live-text strong { color: var(--color-text-primary); font-weight: 600; }
.fleet-live-dot { position: relative; width: 10px; height: 10px; flex: 0 0 10px; border-radius: 999px; background: var(--color-success); }
.fleet-live-dot::after { content: ""; position: absolute; inset: 0; border-radius: inherit; background: inherit; opacity: 0; }
.fleet-live-dot.is-beat::after { animation: fleet-beat .7s ease-out; }
@keyframes fleet-beat { from { opacity: .7; transform: scale(1); } to { opacity: 0; transform: scale(2.6); } }
.fleet-live.is-paused .fleet-live-dot { background: var(--color-text-muted); }
.fleet-live.is-stale .fleet-live-dot { background: var(--color-warning); }
.fleet-live.is-error .fleet-live-dot { background: var(--color-danger); }
.fleet-live.is-error strong { color: var(--color-danger-text); }
@media (prefers-reduced-motion: reduce) { .fleet-live-dot.is-beat::after { animation: none; } }

/* «Custom periods» of the device page: three columns with stepper and quick chips, one on a phone. */
.fleet-periods { margin-top: 12px; display: flex; flex-direction: column; gap: 16px; }
.fleet-periods-grid { display: grid; grid-template-columns: 1fr; gap: 16px; }
@media (min-width: 720px) { .fleet-periods-grid { grid-template-columns: repeat(3, minmax(0, 1fr)); } }
.fleet-period { display: flex; flex-direction: column; gap: 8px; min-width: 0; }
.fleet-period .form-label { margin: 0; }
.fleet-stepper { display: flex; align-items: center; gap: 0; border: 1px solid var(--color-border-light); border-radius: 12px; background: var(--color-panel-sunken, transparent); overflow: hidden; }
.fleet-stepper:focus-within { border-color: var(--color-primary); }
.admin-form .fleet-stepper input { flex: 1; min-width: 0; border: 0; background: transparent; box-shadow: none; text-align: center; font-size: 1.125rem; font-weight: 600; font-variant-numeric: tabular-nums; padding: 8px 0; -moz-appearance: textfield; }
.fleet-stepper input::-webkit-outer-spin-button, .fleet-stepper input::-webkit-inner-spin-button { -webkit-appearance: none; margin: 0; }
.fleet-stepper-unit { padding-right: 6px; font-size: .8125rem; color: var(--color-text-muted); }
.fleet-stepper-btn { width: 42px; height: 42px; flex: 0 0 42px; border: 0; background: transparent; color: var(--color-text-secondary); font-size: 1.25rem; line-height: 1; cursor: pointer; }
.fleet-stepper-btn:hover { background: var(--color-primary-light); color: var(--color-primary-text); }
.fleet-stepper-btn:focus-visible { outline: 2px solid var(--color-primary); outline-offset: -2px; }
.fleet-period-chips { display: flex; flex-wrap: wrap; gap: 6px; }
.fleet-period-chips .ux-chip { font-variant-numeric: tabular-nums; }
.fleet-periods-foot { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 12px; padding-top: 12px; border-top: 1px solid var(--color-separator, var(--color-border-light)); }
.fleet-periods-foot p { flex: 1 1 320px; }

/* Version at the foot of the sidebar, next to the collapse button; collapsed, only the number. */
.sidebar-footer { display: flex; align-items: center; gap: 8px; }
.sidebar-footer .sidebar-toggle { width: auto; flex: 0 0 auto; margin-left: auto; }
.sidebar-version { min-width: 0; padding-left: 6px; font-size: .75rem; color: var(--color-text-muted); font-variant-numeric: tabular-nums; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.sidebar-version-name { font-weight: 600; }
.sidebar-collapsed .sidebar-footer { flex-direction: column; gap: 4px; }
.sidebar-collapsed .sidebar-footer .sidebar-toggle { margin-left: 0; }
.sidebar-collapsed .sidebar-version { padding-left: 0; font-size: .6875rem; }
.sidebar-collapsed .sidebar-version-name { display: none; }
