/**
 * Phoenix UX: sticky-таблицы, прогресс, toast, лента, skeleton, tablet.
 */

/* --- 21 Sticky tables --- */
.phx-sticky-table thead th,
.phx-mon-stations-table thead th {
    position: sticky;
    top: 0;
    z-index: 2;
    background: var(--phx-bg-card-head, #f4f6f9);
    box-shadow: 0 1px 0 var(--phx-border, #e2e6ee);
}

.phx-mon-stations-table-scroll {
    max-height: 320px;
}

.phx-crud-table-wrap .fixed-table-container thead th {
    position: sticky;
    top: 0;
    z-index: 3;
}

/* --- 22 Row semantics --- */
.phx-mon-stations-table tr.is-filled {
    background: rgba(46, 125, 50, 0.06);
}

.phx-mon-stations-table tr.is-approved {
    background: rgba(25, 118, 210, 0.07);
}

.phx-mon-stations-table tr.is-online td:nth-child(6) {
    font-weight: 600;
    color: #2e7d32;
}

.phx-mon-stations-table tr.is-draft {
    background: rgba(255, 193, 7, 0.08);
}

.phx-mon-stations-table tr.is-problem {
    background: rgba(255, 183, 77, 0.14);
}

/* --- 23 Inline note --- */
.phx-mon-inline-note {
    min-width: 120px;
    max-width: 200px;
    height: 28px;
    padding: 2px 8px;
    font-size: 11px;
}

.phx-mon-note-cell {
    vertical-align: middle !important;
}

/* --- 24 Fill progress --- */
.phx-fill-progress {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 10px 16px;
    margin: 12px 0 4px;
    padding: 10px 12px;
    border: 1px solid var(--phx-border, #e2e6ee);
    border-radius: var(--phx-radius-sm, 4px);
    background: var(--phx-bg-card, #fff);
}

.phx-fill-progress__item {
    display: grid;
    grid-template-columns: 72px 1fr auto;
    align-items: center;
    gap: 8px;
    font-size: 12px;
}

.phx-fill-progress__label {
    font-weight: 600;
    color: var(--phx-text-muted, #6b7280);
}

.phx-fill-progress__bar {
    height: 8px;
    background: var(--phx-bg-muted, #eef1f6);
    border-radius: 4px;
    overflow: hidden;
}

.phx-fill-progress__bar > span {
    display: block;
    height: 100%;
    width: 0;
    border-radius: 4px;
    transition: width 0.35s ease;
}

#phx-fill-presence-bar {
    background: linear-gradient(90deg, #66bb6a, #2e7d32);
}

#phx-fill-protocol-bar {
    background: linear-gradient(90deg, #64b5f6, #1976d2);
}

#phx-fill-problems-bar {
    background: linear-gradient(90deg, #ffb74d, #f57c00);
}

.phx-fill-progress__text {
    font-size: 11px;
    white-space: nowrap;
    color: var(--phx-text-muted, #6b7280);
}

/* --- 25 Autosave --- */
.phx-autosave-status {
    font-size: 11px;
    color: var(--phx-text-muted, #8b90a1);
    margin-left: 8px;
}

.phx-autosave-status.is-pending {
    color: #f57c00;
}

.phx-autosave-status.is-saved {
    color: #2e7d32;
}

/* --- 26 Live feed --- */
.phx-live-feed {
    position: fixed;
    right: 12px;
    bottom: 12px;
    width: 300px;
    max-height: 360px;
    z-index: 1040;
    display: flex;
    flex-direction: column;
    border: 1px solid var(--phx-border, #e2e6ee);
    border-radius: var(--phx-radius-md, 6px);
    background: var(--phx-bg-card, #fff);
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.12);
    transform: translateY(110%);
    opacity: 0;
    pointer-events: none;
    transition: transform 0.25s ease, opacity 0.25s ease;
}

.phx-live-feed.is-open {
    transform: translateY(0);
    opacity: 1;
    pointer-events: auto;
}

.phx-live-feed__head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 8px 12px;
    border-bottom: 1px solid var(--phx-border, #e2e6ee);
    font-size: 13px;
    font-weight: 600;
}

.phx-live-feed__list {
    list-style: none;
    margin: 0;
    padding: 8px 0;
    overflow-y: auto;
    flex: 1;
    font-size: 12px;
}

.phx-live-feed__item {
    padding: 6px 12px;
    border-bottom: 1px solid var(--phx-border-light, #f0f2f5);
}

.phx-live-feed__time {
    display: block;
    font-size: 10px;
    color: var(--phx-text-muted, #8b90a1);
}

.phx-live-feed__empty {
    padding: 16px 12px;
    color: var(--phx-text-muted, #8b90a1);
    text-align: center;
}

/* --- 27 Toast --- */
.phx-toast-root {
    position: fixed;
    top: 56px;
    right: 16px;
    z-index: 11000;
    display: flex;
    flex-direction: column;
    gap: 8px;
    max-width: 360px;
    pointer-events: none;
}

.phx-toast {
    display: flex;
    align-items: flex-start;
    gap: 8px;
    padding: 10px 12px;
    border-radius: var(--phx-radius-sm, 4px);
    background: var(--phx-bg-card, #fff);
    border: 1px solid var(--phx-border, #e2e6ee);
    box-shadow: 0 4px 16px rgba(0, 0, 0, 0.1);
    font-size: 13px;
    opacity: 0;
    transform: translateX(12px);
    transition: opacity 0.2s ease, transform 0.2s ease;
    pointer-events: auto;
}

.phx-toast.is-visible {
    opacity: 1;
    transform: translateX(0);
}

.phx-toast--success {
    border-left: 3px solid #2e7d32;
}

.phx-toast--error {
    border-left: 3px solid #c62828;
}

.phx-toast--warn {
    border-left: 3px solid #f57c00;
}

.phx-toast--info {
    border-left: 3px solid #1976d2;
}

.phx-toast__text {
    flex: 1;
    line-height: 1.35;
}

.phx-toast__close {
    border: 0;
    background: transparent;
    color: var(--phx-text-muted, #8b90a1);
    font-size: 18px;
    line-height: 1;
    padding: 0;
    cursor: pointer;
}

/* --- 28 Map skeleton --- */
.phx-mon-map-canvas.is-skeleton {
    position: relative;
    min-height: 220px;
    background: linear-gradient(90deg, #eef1f6 25%, #f8f9fb 50%, #eef1f6 75%);
    background-size: 200% 100%;
    animation: phx-skeleton-shimmer 1.2s ease-in-out infinite;
    border-radius: var(--phx-radius-sm, 4px);
}

.phx-mon-map-canvas.is-skeleton > * {
    visibility: hidden;
}

@keyframes phx-skeleton-shimmer {
    0% { background-position: 200% 0; }
    100% { background-position: -200% 0; }
}

/* --- 29 Empty state --- */
.phx-empty-state {
    text-align: center;
    padding: 28px 20px;
    border: 1px dashed var(--phx-border, #e2e6ee);
    border-radius: var(--phx-radius-md, 6px);
    background: var(--phx-bg-card-head, #f8f9fb);
    margin: 12px 0;
}

.phx-empty-state__icon {
    font-size: 32px;
    color: var(--phx-text-muted, #b0b5c3);
    margin-bottom: 8px;
}

.phx-empty-state__title {
    margin: 0 0 6px;
    font-size: 15px;
    font-weight: 600;
}

.phx-empty-state__text {
    margin: 0 0 14px;
    font-size: 13px;
    color: var(--phx-text-muted, #6b7280);
}

/* --- 30 Tablet mode --- */
html.phx-tablet-mode .phx-ctl-btn--icon,
html.phx-tablet-mode .phx-mon-station-link {
    min-height: 40px;
    min-width: 40px;
    padding: 8px 14px;
    font-size: 14px;
}

html.phx-tablet-mode .phx-stat-chip,
html.phx-tablet-mode .phx-ctl-seg--scroll .phx-ctl-btn {
    min-height: 40px;
    min-width: auto;
    flex-shrink: 0;
    padding: 8px 16px;
    font-size: 14px;
    white-space: nowrap;
}

html.phx-tablet-mode .phx-ms-control-panel__grid {
    grid-template-columns: 1fr;
}

html.phx-tablet-mode .phx-ms-control-block--wide {
    grid-column: auto;
}

html.phx-tablet-mode .phx-mon-maps-grid--polygons {
    grid-template-columns: 1fr;
}

html.phx-tablet-mode .phx-mon-maps-grid {
    grid-template-columns: 1fr;
}

html.phx-tablet-mode .phx-mon-stations-table-scroll {
    max-height: 420px;
}

html.phx-tablet-mode .phx-mon-inline-note {
    min-width: 160px;
    height: 36px;
    font-size: 13px;
}

html.phx-tablet-mode .phx-userbar__tablet.is-active {
    color: var(--phx-accent, #1976d2);
}

@media (min-width: 768px) and (max-width: 1024px) {
    .phx-mon-maps-grid--polygons {
        grid-template-columns: 1fr 1fr;
    }

    .phx-mon-map-cell--online {
        grid-column: 1 / -1;
    }
}

html[data-phx-theme="dark"] .phx-fill-progress,
html[data-phx-theme="dark"] .phx-live-feed,
html[data-phx-theme="dark"] .phx-toast {
    background: var(--phx-bg-card, #1e2433);
}

html[data-phx-theme="dark"] .phx-mon-map-canvas.is-skeleton {
    background: linear-gradient(90deg, #2a3142 25%, #343d52 50%, #2a3142 75%);
    background-size: 200% 100%;
}
