:root {
    --text-dark: #1c1c1e;
    --text-secondary: #6c757d;
    --background-light: #f2f2f7;
    --card-background: #ffffff;
    --border-color: #e5e5ea;
    --primary-blue: #007aff;
    --status-green: #34c759;
    --status-yellow: #ffcc00;
    --status-red: #ff3b30;
}

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

html, body {
    width: 100%;
    overflow-x: hidden;
}

body {
    background-color: var(--background-light);
    color: var(--text-dark);
    font-family: -apple-system, BlinkMacSystemFont, "San Francisco", Helvetica, Arial, sans-serif;
    display: flex;
    flex-direction: column;
    min-height: 100vh;
}

main {
    flex: 1;
    max-width: 1200px;
    margin: 0 auto;
    padding: 2rem 1.5rem;
    width: 100%;
}

@media (max-width: 768px) {
    main {
        padding: 1rem;
    }
}

.title-container {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 2rem;
}
.main-title {
    font-size: 2rem;
    font-weight: 800;
    line-height: 1;
    text-transform: uppercase;
}
.main-title span { display: block; }
.back-link {
    width: 44px; height: 44px;
    background: white; border-radius: 50%;
    display: flex; align-items: center; justify-content: center;
    text-decoration: none; color: var(--text-dark);
    box-shadow: 0 2px 8px rgba(0,0,0,0.08);
}

/* Dashboard Grid */
.seo-dashboard {
    display: grid;
    grid-template-columns: 300px 1fr;
    gap: 1.5rem;
    align-items: start;
}

@media (max-width: 900px) {
    .seo-dashboard {
        grid-template-columns: 1fr;
    }
}

/* Sidebar */
.page-list-panel {
    background: var(--card-background);
    border-radius: 20px;
    padding: 1.2rem;
    box-shadow: 0 4px 12px rgba(0,0,0,0.03);
    height: calc(100vh - 200px);
    min-height: 400px;
    display: flex;
    flex-direction: column;
}

.page-list-panel h3 {
    margin-bottom: 1rem;
    font-size: 1.1rem;
}

#page-search {
    width: 100%;
    padding: 0.8rem;
    border: 1px solid var(--border-color);
    border-radius: 12px;
    margin-bottom: 1rem;
    background: #f9f9f9;
    font-size: 16px; /* Fixed to 16px to prevent iOS zoom */
}

.pages-list {
    flex: 1;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    gap: 8px; /* Spacing between items */
    padding-right: 4px; /* Space for scrollbar */
    padding-bottom: 10px; /* Extra bottom padding */
}

/* --- UPDATED PAGE ITEM STYLES (FIXED OVERFLOW) --- */
.page-item {
    position: relative;
    padding: 12px 14px;
    border-radius: 12px;
    cursor: pointer;
    transition: all 0.2s ease;
    font-size: 0.9rem;
    border: 1px solid transparent;
    
    /* Flex Layout */
    display: flex;
    flex-direction: row;
    align-items: flex-start;      /* ← Выравнивание от верха */
    justify-content: space-between;
    gap: 10px;
    
    /* Dimensions */
    width: 100%;
    min-height: auto;
    height: auto;
    background-color: #f9f9f9;
    
    /* Prevent overflow issues */
    box-sizing: border-box;
    overflow: visible;
}

.page-item-content {
    display: flex;
    flex-direction: column;
    justify-content: flex-start;
    gap: 6px; /* Space between URL and Badge */
    flex: 1 1 auto;
    min-width: 0; /* Critical for Flexbox to allowing shrinking/wrapping */
    padding-right: 4px;
}

.page-item-path {
    /* Force wrapping for long URLs */
    word-break: break-all; 
    overflow-wrap: break-word;
    white-space: normal;
    
    font-weight: 600;
    line-height: 1.3;
    color: var(--text-dark);
    font-size: 0.85rem;
    font-family: monospace;
}

.page-item:hover {
    background-color: #eef1f5;
    transform: translateY(-1px);
    z-index: 2; /* Bring to front on hover */
}
.page-item.active {
    background-color: var(--primary-blue);
    color: white;
    box-shadow: 0 4px 10px rgba(0, 122, 255, 0.2);
    z-index: 1;
}
.page-item.active .page-item-path {
    color: white;
}
.page-item.active .page-status-badge {
    background-color: rgba(255, 255, 255, 0.25);
    color: white;
}

/* --- HIDDEN PAGE STYLE (Deleted/Archived look) --- */
.page-item.hidden {
    background-color: #f2f2f7;
    border: 1px dashed #c7c7cc; /* Dotted gray border */
    opacity: 0.7;
}
.page-item.hidden .page-item-path {
    color: #8a8a8e;
}

/* --- Visibility Toggle Button --- */
.page-visibility-btn {
    width: 30px;
    height: 30px;
    background: transparent;
    border: none;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0;
    border-radius: 50%;
    transition: background-color 0.2s;
    flex-shrink: 0; /* Don't shrink the button */
    margin-top: 0;
    margin-left: auto;            /* ← НОВОЕ: прижимает кнопку вправо */
}
.page-visibility-btn:hover {
    background-color: rgba(0,0,0,0.05);
}
.page-visibility-icon {
    width: 18px;
    height: 18px;
    background-color: #8a8a8e;
    -webkit-mask-size: contain; mask-size: contain;
    -webkit-mask-repeat: no-repeat; mask-repeat: no-repeat;
    -webkit-mask-position: center; mask-position: center;
}
/* Active Item - invert icon color */
.page-item.active .page-visibility-icon {
    background-color: rgba(255,255,255,0.9);
}

.page-visibility-btn[data-status="visible"] .page-visibility-icon {
    -webkit-mask-image: url(/components/svg/svg_ui/visible.svg);
    mask-image: url(/components/svg/svg_ui/visible.svg);
}
.page-visibility-btn[data-status="hidden"] .page-visibility-icon {
    -webkit-mask-image: url(/components/svg/svg_ui/hide.svg);
    mask-image: url(/components/svg/svg_ui/hide.svg);
}

/* --- Page Status Stickers --- */
.page-status-badge {
    display: inline-flex;        
    align-items: center;         
    justify-content: center;     
    width: fit-content;
    font-size: 0.65rem;
    font-weight: 700;
    padding: 4px 8px;
    border-radius: 6px;
    text-transform: uppercase;
    letter-spacing: 0.3px;
    flex-shrink: 0;
    margin-top: 0;
    white-space: nowrap;         /* ← стикер не переносится */
}
.status-loading {
    background-color: #e0e0e0;
    color: #8a8a8e;
}
.status-good {
    background-color: rgba(52, 199, 89, 0.15);
    color: #166534; /* Darker Green */
}
.status-warn {
    background-color: rgba(255, 204, 0, 0.15);
    color: #854d0e; /* Darker Yellow/Orange */
}
.status-bad {
    background-color: rgba(255, 59, 48, 0.15);
    color: #991b1b; /* Darker Red */
}


/* Report Panel */
.report-panel {
    background: var(--card-background);
    border-radius: 20px;
    padding: 2rem;
    box-shadow: 0 4px 12px rgba(0,0,0,0.03);
    overflow-x: hidden; /* Ensure content doesn't spill */
}

@media (max-width: 768px) {
    .report-panel {
        padding: 1.5rem;
    }
}

.empty-state {
    background: var(--card-background);
    border-radius: 20px;
    padding: 4rem 2rem;
    text-align: center;
    color: var(--text-secondary);
    box-shadow: 0 4px 12px rgba(0,0,0,0.03);
}

.report-header {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    margin-bottom: 2rem;
    border-bottom: 1px solid var(--border-color);
    padding-bottom: 1rem;
    flex-wrap: wrap;
    gap: 1rem;
}

#current-page-url {
    font-size: 1.5rem;
    word-break: break-all;
}

.report-meta {
    display: flex;
    align-items: center;
    gap: 1rem;
    color: var(--text-secondary);
    font-size: 0.9rem;
}

.btn-icon {
    background: #f0f0f0;
    width: 32px; height: 32px;
    border-radius: 50%;
    display: flex; align-items: center; justify-content: center;
    text-decoration: none;
    color: inherit;
}

/* SEO Edit Form */
.seo-edit-form {
    background-color: #f8f9fa;
    border-radius: 16px;
    padding: 1.5rem;
    margin-bottom: 2rem;
    border: 1px solid var(--border-color);
}

.seo-form-title {
    font-size: 1.1rem;
    font-weight: 700;
    margin-bottom: 1rem;
    color: var(--text-dark);
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.form-group {
    margin-bottom: 1rem;
}

.form-group label {
    display: block;
    font-size: 0.85rem;
    font-weight: 600;
    color: var(--text-secondary);
    margin-bottom: 0.4rem;
    margin-left: 4px;
}

.seo-input, .seo-textarea {
    width: 100%;
    padding: 0.8rem 1rem;
    border: 1px solid #e0e0e0;
    border-radius: 12px;
    font-size: 0.95rem;
    background-color: white;
    transition: border-color 0.2s, box-shadow 0.2s;
    font-family: inherit;
}
.seo-input:focus, .seo-textarea:focus {
    outline: none;
    border-color: var(--primary-blue);
    box-shadow: 0 0 0 3px rgba(0, 122, 255, 0.1);
}

.seo-textarea {
    resize: vertical;
    min-height: 80px;
}

.form-actions {
    display: flex;
    justify-content: flex-end;
    margin-top: 1rem;
}

.btn-save {
    background-color: var(--primary-blue);
    color: white;
    border: none;
    padding: 0.8rem 1.5rem;
    border-radius: 50px;
    font-weight: 600;
    cursor: pointer;
    transition: opacity 0.2s;
    font-size: 0.9rem;
}
.btn-save:hover {
    opacity: 0.9;
}
.btn-save:disabled {
    background-color: #b0b0b0;
    cursor: not-allowed;
}


/* Summary Cards */
.status-summary {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
    gap: 1rem;
    margin-bottom: 2rem;
}
.summary-card {
    background: #f9f9f9;
    padding: 1rem;
    border-radius: 12px;
    text-align: center;
}
.summary-label {
    display: block;
    font-size: 0.85rem;
    color: var(--text-secondary);
    margin-bottom: 0.5rem;
}
.summary-value {
    font-size: 1.5rem;
    font-weight: 700;
}
.error-text { color: var(--status-red); }
.warn-text { color: var(--status-yellow); }

/* Table Wrapper for Scroll */
.audit-table-wrapper {
    width: 100%;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
}

/* Table */
.audit-table {
    width: 100%;
    border-collapse: collapse;
    margin-bottom: 2rem;
    min-width: 500px; /* Force scroll on very small screens if needed */
}

.audit-table th {
    text-align: left;
    padding: 0.8rem;
    color: var(--text-secondary);
    font-size: 0.85rem;
    text-transform: uppercase;
    border-bottom: 1px solid var(--border-color);
}

.audit-table td {
    padding: 1rem 0.8rem;
    border-bottom: 1px solid var(--border-color);
    font-size: 0.95rem;
}

.status-badge {
    padding: 4px 10px;
    border-radius: 6px;
    font-weight: 600;
    font-size: 0.8rem;
    display: inline-block;
    white-space: nowrap;
}
.status-green { background: rgba(52, 199, 89, 0.15); color: #166534; }
.status-yellow { background: rgba(255, 204, 0, 0.15); color: #854d0e; }
.status-red { background: rgba(255, 59, 48, 0.15); color: #991b1b; }

.param-comment {
    font-size: 0.9rem;
    color: #333;
    word-break: break-word;
}
.param-hint {
    display: block;
    font-size: 0.8rem;
    color: var(--text-secondary);
    margin-top: 4px;
}

/* External Tools */
.external-tools h4 {
    margin-bottom: 1rem;
    font-size: 1rem;
}
.tools-buttons {
    display: flex;
    flex-wrap: wrap;
    gap: 0.8rem;
}
.btn-tool {
    background: #eef1f5;
    color: var(--text-dark);
    text-decoration: none;
    padding: 0.6rem 1rem;
    border-radius: 8px;
    font-size: 0.9rem;
    font-weight: 500;
    transition: background 0.2s;
}
.btn-tool:hover {
    background: #dfe3eb;
}