/**
 * PMN Auto Sitemap - Frontend Styles
 * Airbnb-inspired: clean, compact, proportional, beautiful
 */

/* CSS Variables */
.pmn-sitemap {
    --pmn-primary-color: #FF5A5F;
    --pmn-secondary-color: #484848;
    --pmn-text-color: #484848;
    --pmn-text-light: #767676;
    --pmn-bg-color: #FFFFFF;
    --pmn-border-color: #EBEBEB;
    --pmn-card-shadow: 0 2px 8px rgba(0, 0, 0, 0.08);
    --pmn-card-shadow-hover: 0 4px 16px rgba(0, 0, 0, 0.12);
    --pmn-radius: 12px;
    --pmn-radius-sm: 8px;
    --pmn-font: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
    --pmn-transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
    --pmn-gap: 16px;
}

/* Base Container */
.pmn-sitemap {
    font-family: var(--pmn-font);
    color: var(--pmn-text-color);
    line-height: 1.5;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
    margin: 0;
    padding: 0;
}

.pmn-sitemap *,
.pmn-sitemap *::before,
.pmn-sitemap *::after {
    box-sizing: border-box;
}

/* ================================
   GRID LAYOUT (Flat Display)
   ================================ */
.pmn-sitemap-grid {
    display: grid;
    gap: var(--pmn-gap);
    margin: 0;
    padding: 0;
}

.pmn-sitemap-cols-1 .pmn-sitemap-grid {
    grid-template-columns: 1fr;
}

.pmn-sitemap-cols-2 .pmn-sitemap-grid {
    grid-template-columns: repeat(2, 1fr);
}

.pmn-sitemap-cols-3 .pmn-sitemap-grid {
    grid-template-columns: repeat(3, 1fr);
}

.pmn-sitemap-cols-4 .pmn-sitemap-grid {
    grid-template-columns: repeat(4, 1fr);
}

/* Responsive Grid */
@media (max-width: 992px) {
    .pmn-sitemap-cols-4 .pmn-sitemap-grid {
        grid-template-columns: repeat(3, 1fr);
    }
}

@media (max-width: 768px) {
    .pmn-sitemap-cols-3 .pmn-sitemap-grid,
    .pmn-sitemap-cols-4 .pmn-sitemap-grid {
        grid-template-columns: repeat(2, 1fr);
    }
}

@media (max-width: 480px) {
    .pmn-sitemap-grid {
        grid-template-columns: 1fr !important;
    }
}

/* ================================
   HIERARCHICAL LIST
   ================================ */
.pmn-sitemap-list {
    margin: 0;
    padding: 0;
    list-style: none;
}

.pmn-sitemap-list .pmn-sitemap-item {
    margin: 0;
    padding: 0;
    list-style: none;
}

.pmn-sitemap-root {
    display: grid;
    gap: var(--pmn-gap);
}

.pmn-sitemap-cols-1 .pmn-sitemap-root {
    grid-template-columns: 1fr;
}

.pmn-sitemap-cols-2 .pmn-sitemap-root {
    grid-template-columns: repeat(2, 1fr);
}

.pmn-sitemap-cols-3 .pmn-sitemap-root {
    grid-template-columns: repeat(3, 1fr);
}

.pmn-sitemap-cols-4 .pmn-sitemap-root {
    grid-template-columns: repeat(4, 1fr);
}

/* Children hierarchy */
.pmn-sitemap-children {
    margin: 8px 0 0 0;
    padding: 0 0 0 20px;
    list-style: none;
    border-left: 2px solid var(--pmn-border-color);
}

.pmn-sitemap-children .pmn-sitemap-item {
    margin-top: 8px;
}

.pmn-sitemap-children .pmn-sitemap-card {
    padding: 12px 16px;
}

.pmn-sitemap-children .pmn-sitemap-icon {
    width: 32px;
    height: 32px;
}

.pmn-sitemap-children .pmn-sitemap-icon svg {
    width: 16px;
    height: 16px;
}

/* Responsive hierarchy */
@media (max-width: 768px) {
    .pmn-sitemap-cols-3 .pmn-sitemap-root,
    .pmn-sitemap-cols-4 .pmn-sitemap-root {
        grid-template-columns: repeat(2, 1fr);
    }
}

@media (max-width: 480px) {
    .pmn-sitemap-root {
        grid-template-columns: 1fr !important;
    }

    .pmn-sitemap-children {
        padding-left: 16px;
    }
}

/* ================================
   CARDS THEME (Modern)
   ================================ */
.pmn-sitemap-theme-cards .pmn-sitemap-card {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 16px 20px;
    background: var(--pmn-bg-color);
    border: 1px solid var(--pmn-border-color);
    border-radius: var(--pmn-radius);
    box-shadow: var(--pmn-card-shadow);
    text-decoration: none;
    color: var(--pmn-text-color);
    transition: var(--pmn-transition);
    overflow: hidden;
}

.pmn-sitemap-theme-cards .pmn-sitemap-card:hover {
    border-color: var(--pmn-primary-color);
    box-shadow: var(--pmn-card-shadow-hover);
    transform: translateY(-2px);
}

.pmn-sitemap-theme-cards .pmn-sitemap-card:focus {
    outline: none;
    border-color: var(--pmn-primary-color);
    box-shadow: 0 0 0 3px rgba(255, 90, 95, 0.15);
}

/* Card Icon */
.pmn-sitemap-icon {
    flex-shrink: 0;
    width: 40px;
    height: 40px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: linear-gradient(135deg, #f7f7f7 0%, #ffffff 100%);
    border: 1px solid var(--pmn-border-color);
    border-radius: var(--pmn-radius-sm);
    color: var(--pmn-primary-color);
    transition: var(--pmn-transition);
}

.pmn-sitemap-icon svg {
    width: 20px;
    height: 20px;
}

.pmn-sitemap-card:hover .pmn-sitemap-icon {
    background: var(--pmn-primary-color);
    border-color: var(--pmn-primary-color);
    color: #fff;
}

/* Card Content */
.pmn-sitemap-content {
    flex: 1;
    min-width: 0;
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.pmn-sitemap-title {
    font-size: 15px;
    font-weight: 500;
    color: var(--pmn-secondary-color);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    transition: var(--pmn-transition);
}

.pmn-sitemap-card:hover .pmn-sitemap-title {
    color: var(--pmn-primary-color);
}

.pmn-sitemap-desc {
    font-size: 13px;
    color: var(--pmn-text-light);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

/* Card Arrow */
.pmn-sitemap-arrow {
    flex-shrink: 0;
    width: 20px;
    height: 20px;
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--pmn-text-light);
    opacity: 0;
    transform: translateX(-8px);
    transition: var(--pmn-transition);
}

.pmn-sitemap-arrow svg {
    width: 16px;
    height: 16px;
}

.pmn-sitemap-card:hover .pmn-sitemap-arrow {
    opacity: 1;
    transform: translateX(0);
    color: var(--pmn-primary-color);
}

/* ================================
   LIST THEME
   ================================ */
.pmn-sitemap-theme-list .pmn-sitemap-grid,
.pmn-sitemap-theme-list .pmn-sitemap-root {
    display: flex;
    flex-direction: column;
    gap: 0;
}

.pmn-sitemap-theme-list .pmn-sitemap-card {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 14px 16px;
    text-decoration: none;
    color: var(--pmn-text-color);
    background: var(--pmn-bg-color);
    border-bottom: 1px solid var(--pmn-border-color);
    transition: var(--pmn-transition);
}

.pmn-sitemap-theme-list .pmn-sitemap-item:first-child .pmn-sitemap-card {
    border-top: 1px solid var(--pmn-border-color);
    border-radius: var(--pmn-radius-sm) var(--pmn-radius-sm) 0 0;
}

.pmn-sitemap-theme-list .pmn-sitemap-item:last-child > .pmn-sitemap-card {
    border-radius: 0 0 var(--pmn-radius-sm) var(--pmn-radius-sm);
}

.pmn-sitemap-theme-list .pmn-sitemap-item:only-child > .pmn-sitemap-card {
    border-radius: var(--pmn-radius-sm);
}

.pmn-sitemap-theme-list .pmn-sitemap-card:hover {
    background: #f7f7f7;
}

.pmn-sitemap-theme-list .pmn-sitemap-card:focus {
    outline: none;
    background: #f7f7f7;
    box-shadow: inset 0 0 0 2px var(--pmn-primary-color);
}

.pmn-sitemap-theme-list .pmn-sitemap-icon {
    width: 36px;
    height: 36px;
    background: transparent;
    border: none;
}

.pmn-sitemap-theme-list .pmn-sitemap-icon svg {
    width: 18px;
    height: 18px;
}

.pmn-sitemap-theme-list .pmn-sitemap-card:hover .pmn-sitemap-icon {
    background: transparent;
    color: var(--pmn-primary-color);
}

/* List children */
.pmn-sitemap-theme-list .pmn-sitemap-children {
    margin: 0;
    padding: 0 0 0 24px;
    border-left: 2px solid var(--pmn-border-color);
    margin-left: 18px;
}

.pmn-sitemap-theme-list .pmn-sitemap-children .pmn-sitemap-card {
    padding: 10px 16px;
}

.pmn-sitemap-theme-list .pmn-sitemap-children .pmn-sitemap-item:first-child .pmn-sitemap-card {
    border-top: none;
    border-radius: 0;
}

/* ================================
   MINIMAL THEME
   ================================ */
.pmn-sitemap-theme-minimal .pmn-sitemap-grid,
.pmn-sitemap-theme-minimal .pmn-sitemap-root {
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.pmn-sitemap-theme-minimal .pmn-sitemap-card {
    display: inline-flex;
    align-items: center;
    padding: 6px 0;
    text-decoration: none;
    color: var(--pmn-primary-color);
    font-size: 15px;
    transition: var(--pmn-transition);
    border-radius: 4px;
}

.pmn-sitemap-theme-minimal .pmn-sitemap-card:hover {
    color: var(--pmn-secondary-color);
    padding-left: 8px;
}

.pmn-sitemap-theme-minimal .pmn-sitemap-card:focus {
    outline: none;
    color: var(--pmn-secondary-color);
    background: rgba(0, 0, 0, 0.04);
    padding: 6px 8px;
}

.pmn-sitemap-theme-minimal .pmn-sitemap-icon,
.pmn-sitemap-theme-minimal .pmn-sitemap-arrow,
.pmn-sitemap-theme-minimal .pmn-sitemap-desc {
    display: none;
}

.pmn-sitemap-theme-minimal .pmn-sitemap-content {
    display: inline;
}

.pmn-sitemap-theme-minimal .pmn-sitemap-title {
    font-size: inherit;
    font-weight: 400;
    color: inherit;
}

/* Minimal children */
.pmn-sitemap-theme-minimal .pmn-sitemap-children {
    margin: 0 0 0 20px;
    padding: 0;
    border: none;
}

/* ================================
   ANIMATIONS
   ================================ */
.pmn-sitemap-animated .pmn-sitemap-item {
    opacity: 0;
    transform: translateY(10px);
    animation: pmnSitemapFadeIn 0.4s ease forwards;
}

.pmn-sitemap-animated .pmn-sitemap-item:nth-child(1) { animation-delay: 0.05s; }
.pmn-sitemap-animated .pmn-sitemap-item:nth-child(2) { animation-delay: 0.1s; }
.pmn-sitemap-animated .pmn-sitemap-item:nth-child(3) { animation-delay: 0.15s; }
.pmn-sitemap-animated .pmn-sitemap-item:nth-child(4) { animation-delay: 0.2s; }
.pmn-sitemap-animated .pmn-sitemap-item:nth-child(5) { animation-delay: 0.25s; }
.pmn-sitemap-animated .pmn-sitemap-item:nth-child(6) { animation-delay: 0.3s; }
.pmn-sitemap-animated .pmn-sitemap-item:nth-child(7) { animation-delay: 0.35s; }
.pmn-sitemap-animated .pmn-sitemap-item:nth-child(8) { animation-delay: 0.4s; }
.pmn-sitemap-animated .pmn-sitemap-item:nth-child(9) { animation-delay: 0.45s; }
.pmn-sitemap-animated .pmn-sitemap-item:nth-child(10) { animation-delay: 0.5s; }
.pmn-sitemap-animated .pmn-sitemap-item:nth-child(n+11) { animation-delay: 0.55s; }

@keyframes pmnSitemapFadeIn {
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

/* Child items animation */
.pmn-sitemap-animated .pmn-sitemap-children .pmn-sitemap-item {
    animation-delay: 0s;
}

/* ================================
   EMPTY STATE
   ================================ */
.pmn-sitemap-empty {
    text-align: center;
    padding: 40px 20px;
    color: var(--pmn-text-light);
    font-size: 14px;
    font-family: var(--pmn-font);
    background: var(--pmn-bg-color);
    border: 1px dashed var(--pmn-border-color);
    border-radius: var(--pmn-radius);
}

/* ================================
   ACCESSIBILITY
   ================================ */
@media (prefers-reduced-motion: reduce) {
    .pmn-sitemap-animated .pmn-sitemap-item {
        animation: none;
        opacity: 1;
        transform: none;
    }

    .pmn-sitemap-card,
    .pmn-sitemap-icon,
    .pmn-sitemap-arrow,
    .pmn-sitemap-title {
        transition: none;
    }
}

/* High contrast mode */
@media (prefers-contrast: high) {
    .pmn-sitemap-theme-cards .pmn-sitemap-card {
        border-width: 2px;
    }

    .pmn-sitemap-card:focus {
        outline: 3px solid var(--pmn-primary-color);
        outline-offset: 2px;
    }
}

/* Print styles */
@media print {
    .pmn-sitemap-card {
        box-shadow: none !important;
        border: 1px solid #ddd !important;
    }

    .pmn-sitemap-arrow {
        display: none !important;
    }
}

/* ================================
   DRAG & DROP SORTING
   ================================ */

/* Toolbar */
.pmn-sitemap-toolbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 12px 16px;
    margin-bottom: 16px;
    background: linear-gradient(135deg, #f8f9fa 0%, #fff 100%);
    border: 1px solid var(--pmn-border-color);
    border-radius: var(--pmn-radius-sm);
    font-size: 13px;
}

.pmn-sort-hint {
    display: flex;
    align-items: center;
    gap: 8px;
    color: var(--pmn-text-light);
}

.pmn-sort-hint svg {
    color: var(--pmn-primary-color);
}

.pmn-sort-status {
    font-size: 12px;
    padding: 4px 12px;
    border-radius: 20px;
    transition: var(--pmn-transition);
}

.pmn-sort-status.saving {
    background: #fff3cd;
    color: #856404;
}

.pmn-sort-status.saved {
    background: #d4edda;
    color: #155724;
}

.pmn-sort-status.error {
    background: #f8d7da;
    color: #721c24;
}

/* Drag Handle */
.pmn-drag-handle {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 28px;
    height: 28px;
    flex-shrink: 0;
    cursor: grab;
    color: var(--pmn-text-light);
    opacity: 0.5;
    transition: var(--pmn-transition);
    border-radius: 4px;
}

.pmn-drag-handle:hover {
    opacity: 1;
    color: var(--pmn-primary-color);
    background: rgba(255, 90, 95, 0.08);
}

.pmn-drag-handle:active {
    cursor: grabbing;
}

/* Sortable container styles */
.pmn-sitemap-sortable .pmn-sitemap-item {
    position: relative;
}

/* Grid sortable - item wrapper */
.pmn-sitemap-sortable .pmn-sitemap-grid > .pmn-sitemap-item {
    display: flex;
    align-items: stretch;
    gap: 0;
}

.pmn-sitemap-sortable .pmn-sitemap-grid > .pmn-sitemap-item > .pmn-drag-handle {
    position: absolute;
    left: 8px;
    top: 50%;
    transform: translateY(-50%);
    z-index: 10;
    background: var(--pmn-bg-color);
    border: 1px solid var(--pmn-border-color);
    border-radius: 4px;
    opacity: 0;
}

.pmn-sitemap-sortable .pmn-sitemap-grid > .pmn-sitemap-item:hover > .pmn-drag-handle {
    opacity: 1;
}

.pmn-sitemap-sortable .pmn-sitemap-grid > .pmn-sitemap-item > .pmn-sitemap-card {
    flex: 1;
}

/* List sortable - item wrapper */
.pmn-sitemap-sortable .pmn-sitemap-item-content {
    display: flex;
    align-items: center;
    gap: 0;
}

.pmn-sitemap-sortable .pmn-sitemap-item-content > .pmn-drag-handle {
    margin-right: 8px;
    opacity: 0.3;
}

.pmn-sitemap-sortable .pmn-sitemap-item-content:hover > .pmn-drag-handle {
    opacity: 1;
}

.pmn-sitemap-sortable .pmn-sitemap-item-content > .pmn-sitemap-card {
    flex: 1;
}

/* Dragging state */
.pmn-sitemap-item.sortable-chosen {
    z-index: 100;
}

.pmn-sitemap-item.sortable-chosen > .pmn-sitemap-card,
.pmn-sitemap-item.sortable-chosen > .pmn-sitemap-item-content > .pmn-sitemap-card {
    box-shadow: 0 8px 25px rgba(0, 0, 0, 0.15) !important;
    border-color: var(--pmn-primary-color) !important;
    transform: scale(1.02);
}

.pmn-sitemap-item.sortable-chosen .pmn-drag-handle {
    opacity: 1;
    color: var(--pmn-primary-color);
    cursor: grabbing;
}

/* Ghost (placeholder) state */
.pmn-sitemap-item.sortable-ghost {
    opacity: 0.4;
}

.pmn-sitemap-item.sortable-ghost > .pmn-sitemap-card,
.pmn-sitemap-item.sortable-ghost > .pmn-sitemap-item-content > .pmn-sitemap-card {
    background: var(--pmn-border-color);
    border-style: dashed;
}

/* Drag state - body cursor */
body.pmn-dragging {
    cursor: grabbing !important;
}

body.pmn-dragging * {
    cursor: grabbing !important;
}

/* Animation when items settle */
.pmn-sitemap-sortable .pmn-sitemap-item {
    transition: transform 0.15s ease;
}

/* Disable text selection during drag */
.pmn-sitemap-sortable.is-sorting {
    user-select: none;
}

.pmn-sitemap-sortable.is-sorting .pmn-sitemap-card {
    pointer-events: none;
}

.pmn-sitemap-sortable.is-sorting .pmn-drag-handle {
    pointer-events: auto;
}

/* Drop indicator line */
.pmn-sitemap-sortable .sortable-drag {
    opacity: 1 !important;
}

/* Cards theme specific sorting styles */
.pmn-sitemap-theme-cards.pmn-sitemap-sortable .pmn-sitemap-grid > .pmn-sitemap-item {
    padding-left: 0;
}

.pmn-sitemap-theme-cards.pmn-sitemap-sortable .pmn-sitemap-grid > .pmn-sitemap-item > .pmn-drag-handle {
    left: 4px;
    width: 24px;
    height: 24px;
    box-shadow: 0 1px 3px rgba(0,0,0,0.1);
}

/* List theme specific sorting styles */
.pmn-sitemap-theme-list.pmn-sitemap-sortable .pmn-sitemap-item-content {
    padding-left: 4px;
}

.pmn-sitemap-theme-list.pmn-sitemap-sortable .pmn-sitemap-item-content > .pmn-drag-handle {
    margin-left: 4px;
}

/* Minimal theme specific sorting styles */
.pmn-sitemap-theme-minimal.pmn-sitemap-sortable .pmn-drag-handle {
    width: 20px;
    height: 20px;
}

.pmn-sitemap-theme-minimal.pmn-sitemap-sortable .pmn-drag-handle svg {
    width: 14px;
    height: 14px;
}

/* Responsive adjustments for sorting */
@media (max-width: 768px) {
    .pmn-sitemap-toolbar {
        flex-direction: column;
        gap: 8px;
        text-align: center;
    }

    .pmn-sitemap-sortable .pmn-sitemap-grid > .pmn-sitemap-item > .pmn-drag-handle {
        opacity: 0.5;
    }
}

/* Touch device adjustments */
@media (hover: none) and (pointer: coarse) {
    .pmn-drag-handle {
        opacity: 0.7;
        width: 36px;
        height: 36px;
    }

    .pmn-sitemap-sortable .pmn-sitemap-grid > .pmn-sitemap-item > .pmn-drag-handle {
        opacity: 0.7;
    }
}

/* ================================
   STATS WIDGET
   ================================ */

.pmn-stats-widget {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    max-width: 220px;
    height: auto;
    background: #fff;
    border: 1px solid #e8e8e8;
    border-radius: 8px;
    overflow: hidden;
    text-decoration: none;
    color: inherit;
    transition: all 0.2s ease;
    box-shadow: 0 1px 2px rgba(0, 0, 0, 0.03);
}

.pmn-stats-widget:hover {
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.06);
    border-color: #d0d0d0;
}

/* Header */
.pmn-stats-header {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 5px;
    width: 100%;
    padding: 8px 12px;
    border-bottom: 1px solid #f0f0f0;
}

.pmn-stats-icon {
    display: flex;
    align-items: center;
    color: #888;
}

.pmn-stats-title {
    font-size: 12px;
    font-weight: 500;
    color: #555;
}

/* Content - single line */
.pmn-stats-content {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    padding: 12px 16px;
}

.pmn-stats-text {
    font-size: 13px;
    color: #666;
    font-weight: 400;
}

.pmn-stats-number {
    font-size: 18px;
    font-weight: 700;
    color: #333;
}

/* Responsive */
@media (max-width: 480px) {
    .pmn-stats-widget {
        max-width: 100%;
    }

    .pmn-stats-text {
        font-size: 12px;
    }

    .pmn-stats-number {
        font-size: 16px;
    }
}
