:root {
    --primary-color: #1e40af;
    --secondary-color: #2563eb;
    --accent-color: #3b82f6;
    --light-accent: #60a5fa;
    --light-color: #f8fafc;
    --dark-color: #1e293b;
    --card-bg: #ffffff;
    --tree-color: #2c5530;
    --shadow: 0 4px 6px rgba(30, 64, 175, 0.1);
    --transition: all 0.3s ease;
}

[data-theme="dark"] {
    --primary-color: #1e3a8a;
    --secondary-color: #1d4ed8;
    --accent-color: #2563eb;
    --light-accent: #3b82f6;
    --light-color: #0f172a;
    --dark-color: #f1f5f9;
    --card-bg: #1e293b;
    --tree-color: #3d6b47;
    --shadow: 0 4px 6px rgba(0, 0, 0, 0.3);
}

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

body {
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    background-color: var(--light-color);
    color: var(--dark-color);
    line-height: 1.6;
    transition: var(--transition);
    min-height: 100vh;
    overflow-x: hidden;
}

.container {
    max-width: 1200px;
    margin: 0 auto;
    padding: 0 20px;
}

/* ============ HEADER ============ */
header {
    background: linear-gradient(135deg, var(--primary-color) 0%, var(--accent-color) 100%);
    color: white;
    padding: 1rem 0;
    position: sticky;
    top: 0;
    z-index: 1000;
    box-shadow: var(--shadow);
}

.header-content {
    display: flex;
    justify-content: space-between;
    align-items: center;
    max-width: 1200px;
    margin: 0 auto;
    padding: 0 20px;
    flex-wrap: wrap;
}

header h1 {
    font-size: 1.8rem;
    display: flex;
    align-items: center;
    gap: 10px;
}

nav ul {
    display: flex;
    list-style: none;
    gap: 20px;
    flex-wrap: wrap;
}

nav a {
    color: white;
    text-decoration: none;
    padding: 8px 15px;
    border-radius: 6px;
    transition: var(--transition);
    display: flex;
    align-items: center;
    gap: 5px;
    white-space: nowrap;
}

nav a:hover {
    background-color: rgba(255, 255, 255, 0.15);
}

#toggle-mode {
    background: rgba(255, 255, 255, 0.1);
    border: 1px solid rgba(255, 255, 255, 0.3);
    color: white;
    padding: 8px 16px;
    border-radius: 20px;
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 8px;
    transition: var(--transition);
    white-space: nowrap;
}

#toggle-mode:hover {
    background-color: rgba(255, 255, 255, 0.2);
}

/* ============ ABOUT SECTION ============ */
#about {
    padding: 4rem 0;
    background: linear-gradient(135deg, #f0f9ff 0%, #e0f2fe 100%);
}

[data-theme="dark"] #about {
    background: linear-gradient(135deg, #0c4a6e 0%, #075985 100%);
}

.about-content {
    display: grid;
    grid-template-columns: 2fr 1fr;
    gap: 3rem;
    margin-top: 2rem;
}

.stats {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 1rem;
}

.stat-item {
    background: var(--card-bg);
    padding: 1.5rem;
    border-radius: 12px;
    text-align: center;
    box-shadow: var(--shadow);
    transition: var(--transition);
}

.stat-item:hover {
    transform: translateY(-5px);
}

.stat-item i {
    font-size: 2.5rem;
    color: var(--accent-color);
    margin-bottom: 1rem;
}

.stat-item span {
    display: block;
    font-size: 2.2rem;
    font-weight: bold;
    color: var(--primary-color);
    margin: 10px 0;
}

/* ============ TREE SECTION ============ */
#tree {
    padding: 4rem 0;
    min-height: 80vh;
}

.controls {
    display: flex;
    gap: 10px;
    margin: 1rem 0 2rem;
    flex-wrap: wrap;
    justify-content: center;
}

.controls button {
    padding: 10px 20px;
    border: none;
    background: var(--secondary-color);
    color: white;
    border-radius: 8px;
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    gap: 8px;
    transition: var(--transition);
    white-space: nowrap;
}

.controls button:hover {
    background: var(--primary-color);
}

/* ============ QR GRID (СЕТКА) ============ */
#qr-grid-container {
    background: var(--card-bg);
    border-radius: 12px;
    padding: 30px;
    box-shadow: var(--shadow);
    margin-top: 20px;
    width: 100%;
    box-sizing: border-box;
    overflow: hidden;
}

.qr-grid-header {
    text-align: center;
    margin-bottom: 30px;
    padding-bottom: 20px;
    border-bottom: 2px solid var(--accent-color);
}

.qr-grid-header h3 {
    color: var(--primary-color);
    margin-bottom: 10px;
    font-size: 1.8rem;
}

.qr-grid-header p {
    color: var(--dark-color);
    opacity: 0.8;
    margin-bottom: 15px;
}

.qr-grid-stats {
    background: rgba(59, 130, 246, 0.1);
    padding: 10px 20px;
    border-radius: 20px;
    display: inline-block;
}

.qr-grid-stats span {
    color: var(--primary-color);
    font-weight: bold;
    display: flex;
    align-items: center;
    gap: 8px;
}

#qr-grid {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 15px;
    width: 100%;
    box-sizing: border-box;
    align-items: stretch;
}

.qr-grid-item {
    background: var(--light-color);
    border-radius: 12px;
    padding: 15px;
    text-align: center;
    cursor: pointer;
    transition: var(--transition);
    border: 2px solid transparent;
    box-shadow: 0 4px 12px rgba(0,0,0,0.1);
    height: 260px;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: space-between;
    position: relative;
    overflow: hidden;
    box-sizing: border-box;
}

.qr-grid-item:hover {
    transform: translateY(-8px);
    box-shadow: 0 12px 30px rgba(0,0,0,0.2);
    border-color: var(--accent-color);
}

.qr-grid-item.selected {
    border-color: var(--primary-color);
    background: rgba(59, 130, 246, 0.05);
}

.qr-grid-number {
    position: absolute;
    top: -12px;
    left: -12px;
    background: var(--primary-color);
    color: white;
    width: 35px;
    height: 35px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: bold;
    font-size: 16px;
    box-shadow: 0 3px 8px rgba(0,0,0,0.3);
    z-index: 1;
    border: 2px solid white;
}

.photo-container {
    width: 70px;
    height: 70px;
    margin: 5px auto 10px;
    border-radius: 50%;
    overflow: hidden;
    background: var(--accent-color);
    display: flex;
    align-items: center;
    justify-content: center;
    border: 3px solid white;
    box-shadow: 0 3px 10px rgba(0,0,0,0.2);
}

.photo-container img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.photo-initials {
    width: 100%;
    height: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
    color: white;
    font-size: 2.5rem;
    font-weight: bold;
    border-radius: 50%;
}

.qr-grid-code {
    margin: 10px auto;
    width: 90px;
    height: 90px;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}

.qr-grid-code canvas,
.qr-grid-code img {
    width: 100% !important;
    height: 100% !important;
    border-radius: 8px;
    border: 2px solid white;
    box-shadow: 0 3px 8px rgba(0,0,0,0.1);
}

.qr-grid-info {
    width: 100%;
    margin-top: auto;
    padding-top: 10px;
    border-top: 1px solid rgba(59, 130, 246, 0.1);
}

.qr-grid-info h4 {
    color: var(--primary-color);
    margin: 0 0 5px;
    font-size: 0.95rem;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    line-height: 1.2;
}

.qr-grid-info p {
    color: var(--dark-color);
    font-size: 0.8rem;
    margin: 2px 0;
    opacity: 0.9;
    line-height: 1.3;
}

.qr-years {
    font-weight: 600;
    color: var(--accent-color) !important;
}

/* ============ QR LIST (СПИСОК) ============ */
.qr-list {
    display: flex;
    flex-direction: column;
    gap: 15px;
}

.qr-list-item {
    display: grid;
    grid-template-columns: auto 80px 1fr 100px auto;
    gap: 20px;
    align-items: center;
    background: var(--light-color);
    padding: 15px 20px;
    border-radius: 10px;
    border: 1px solid rgba(59, 130, 246, 0.1);
    transition: var(--transition);
    cursor: pointer;
    max-width: 100%;
    overflow: hidden;
}

.qr-list-item:hover {
    transform: translateX(5px);
    border-color: var(--accent-color);
    background: rgba(59, 130, 246, 0.03);
}

.qr-list-item.selected {
    border-color: var(--primary-color);
    background: rgba(59, 130, 246, 0.08);
}

.qr-list-number {
    background: var(--primary-color);
    color: white;
    width: 35px;
    height: 35px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: bold;
    font-size: 14px;
    flex-shrink: 0;
}

.qr-list-photo {
    width: 60px;
    height: 60px;
    border-radius: 50%;
    overflow: hidden;
    border: 2px solid white;
    box-shadow: 0 2px 8px rgba(0,0,0,0.1);
    flex-shrink: 0;
}

.qr-list-info {
    min-width: 0;
    overflow: hidden;
}

.qr-list-info h4 {
    color: var(--primary-color);
    margin-bottom: 5px;
    font-size: 1.1rem;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    max-width: 100%;
}

.qr-list-info p {
    color: var(--dark-color);
    font-size: 0.9rem;
    margin: 2px 0;
    opacity: 0.9;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.qr-list-code {
    width: 80px;
    height: 80px;
    flex-shrink: 0;
}

.qr-list-code canvas,
.qr-list-code img {
    width: 100% !important;
    height: 100% !important;
    border-radius: 8px;
    border: 2px solid white;
    box-shadow: 0 3px 8px rgba(0,0,0,0.1);
}

.list-view-btn {
    background: var(--accent-color);
    color: white;
    border: none;
    padding: 8px 15px;
    border-radius: 6px;
    cursor: pointer;
    font-size: 0.9rem;
    display: flex;
    align-items: center;
    gap: 5px;
    transition: var(--transition);
    white-space: nowrap;
    flex-shrink: 0;
}

.list-view-btn:hover {
    background: var(--primary-color);
}

/* ============ TREE WRAPPER ============ */
#tree-wrapper {
    display: grid;
    grid-template-columns: 3fr 1fr;
    gap: 2rem;
    margin-top: 2rem;
}

#tree-area {
    background: var(--card-bg);
    border-radius: 12px;
    padding: 20px;
    box-shadow: var(--shadow);
    position: relative;
}

.tree-controls {
    position: absolute;
    top: 20px;
    right: 20px;
    display: flex;
    gap: 10px;
    z-index: 10;
}

#tree-container {
    position: relative;
    width: 100%;
    height: 600px;
    border-radius: 8px;
    overflow: hidden;
    background: #f8fafc;
}

#svg-container {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    z-index: 1;
}

#svg-container svg {
    width: 100%;
    height: 100%;
    object-fit: contain;
}

/* ============ INFO PANEL ============ */
#info-panel {
    background: var(--card-bg);
    padding: 1.5rem;
    border-radius: 12px;
    box-shadow: var(--shadow);
}

#selected-info {
    min-height: 300px;
    margin: 1rem 0;
    padding: 1.5rem;
    border-radius: 8px;
    background: rgba(59, 130, 246, 0.05);
    border: 1px solid rgba(59, 130, 246, 0.1);
}

.default-message {
    text-align: center;
    color: #64748b;
    padding: 2rem 0;
}

.default-message i {
    font-size: 3rem;
    margin-bottom: 1rem;
    color: #94a3b8;
}

.search-box {
    display: flex;
    gap: 10px;
    margin: 1.5rem 0;
}

#search-input {
    flex: 1;
    padding: 12px;
    border: 1px solid rgba(59, 130, 246, 0.3);
    border-radius: 8px;
    background: var(--light-color);
    color: var(--dark-color);
    font-size: 1rem;
}

#search-input:focus {
    outline: none;
    border-color: var(--accent-color);
}

#search-btn {
    padding: 12px 24px;
    background: var(--accent-color);
    color: white;
    border: none;
    border-radius: 8px;
    cursor: pointer;
}

.legend {
    margin-top: 1.5rem;
    padding-top: 1rem;
    border-top: 1px solid rgba(59, 130, 246, 0.2);
}

.legend h4 {
    margin-bottom: 10px;
    color: var(--primary-color);
    display: flex;
    align-items: center;
    gap: 8px;
}

.legend-color {
    display: inline-block;
    width: 12px;
    height: 12px;
    border-radius: 3px;
    margin-right: 8px;
}

/* ============ CONTACT SECTION ============ */
#contact {
    padding: 4rem 0;
    background: linear-gradient(135deg, var(--primary-color) 0%, var(--accent-color) 100%);
    color: white;
}

.contact-content {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-top: 2rem;
    flex-wrap: wrap;
    gap: 2rem;
}

.contact-info p {
    margin: 0.5rem 0;
    display: flex;
    align-items: center;
    gap: 10px;
}

.contact-info a {
    color: white;
    text-decoration: none;
}

.social-links {
    display: flex;
    gap: 1.5rem;
}

.social-links a {
    color: white;
    font-size: 1.8rem;
    transition: var(--transition);
}

.social-links a:hover {
    color: #bfdbfe;
    transform: translateY(-3px);
}

/* ============ FOOTER ============ */
footer {
    background: var(--dark-color);
    color: white;
    padding: 2rem 0;
    text-align: center;
}

.footer-note {
    margin-top: 1rem;
    opacity: 0.8;
    font-size: 0.9rem;
    color: #bfdbfe;
}

/* ============ LOADER ============ */
#loader {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: var(--light-color);
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    z-index: 10000;
    transition: opacity 0.3s ease;
}

.spinner {
    width: 60px;
    height: 60px;
    border: 5px solid var(--light-color);
    border-top: 5px solid var(--accent-color);
    border-radius: 50%;
    animation: spin 1s linear infinite;
    margin-bottom: 1.5rem;
}

@keyframes spin {
    0% { transform: rotate(0deg); }
    100% { transform: rotate(360deg); }
}

@keyframes fadeIn {
    from { opacity: 0; transform: translateY(10px); }
    to { opacity: 1; transform: translateY(0); }
}

/* ============ MODAL ============ */
.modal {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.7);
    z-index: 10000;
    animation: fadeIn 0.3s ease;
}

.modal-content {
    position: relative;
    background: var(--light-color);
    margin: 50px auto;
    padding: 0;
    width: 90%;
    max-width: 800px;
    max-height: 85vh;
    border-radius: 15px;
    overflow: hidden;
    animation: slideIn 0.3s ease;
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.3);
}

@keyframes slideIn {
    from { transform: translateY(-50px); opacity: 0; }
    to { transform: translateY(0); opacity: 1; }
}

.modal-header {
    background: linear-gradient(135deg, var(--primary-color) 0%, var(--accent-color) 100%);
    color: white;
    padding: 20px 30px;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.modal-header h3 {
    margin: 0;
    font-size: 1.5rem;
}

.close-modal {
    background: none;
    border: none;
    color: white;
    font-size: 2rem;
    cursor: pointer;
    line-height: 1;
    padding: 0;
    width: 30px;
    height: 30px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.modal-body {
    padding: 30px;
    max-height: calc(85vh - 100px);
    overflow-y: auto;
}

.modal-person-info {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 30px;
}

.modal-person-details {
    display: flex;
    flex-direction: column;
    gap: 20px;
}

.modal-detail-item {
    background: rgba(59, 130, 246, 0.05);
    padding: 15px;
    border-radius: 8px;
    border-left: 4px solid var(--accent-color);
}

.modal-detail-item h4 {
    color: var(--primary-color);
    margin-bottom: 10px;
    display: flex;
    align-items: center;
    gap: 10px;
}

.modal-footer {
    padding: 20px;
    background: rgba(59, 130, 246, 0.05);
    border-top: 1px solid rgba(59, 130, 246, 0.2);
}

.share-section {
    text-align: center;
    padding: 20px;
    background: rgba(59, 130, 246, 0.05);
    border-radius: 12px;
    margin-top: 20px;
}

.share-section h4 {
    color: var(--primary-color);
    margin-bottom: 15px;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 10px;
}

.share-qr {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 15px;
}

.share-qr canvas,
.share-qr img {
    width: 150px !important;
    height: 150px !important;
    border: 3px solid var(--accent-color);
    border-radius: 10px;
    box-shadow: 0 6px 20px rgba(0,0,0,0.15);
}

.share-qr p {
    color: #666;
    font-size: 0.9rem;
    max-width: 300px;
}

/* ============ PERSON PAGE ============ */
.person-page {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: var(--light-color);
    z-index: 10000;
    overflow-y: auto;
    animation: fadeIn 0.3s ease;
}

.person-page-container {
    max-width: 1200px;
    margin: 0 auto;
    padding: 20px;
    min-height: 100vh;
    display: flex;
    flex-direction: column;
}

.back-button {
    background: var(--primary-color);
    color: white;
    border: none;
    padding: 12px 24px;
    border-radius: 8px;
    cursor: pointer;
    font-size: 1rem;
    display: flex;
    align-items: center;
    gap: 10px;
    margin-bottom: 30px;
    transition: var(--transition);
    align-self: flex-start;
}

.back-button:hover {
    background: var(--secondary-color);
    transform: translateX(-5px);
}

.person-page-content {
    flex: 1;
}

.person-page-header {
    text-align: center;
    margin-bottom: 40px;
    padding-bottom: 20px;
    border-bottom: 3px solid var(--accent-color);
}

.person-page-header h1 {
    color: var(--primary-color);
    font-size: 2.5rem;
    margin-bottom: 15px;
}

.person-page-meta {
    display: flex;
    justify-content: center;
    gap: 20px;
    flex-wrap: wrap;
}

.years-badge {
    background: var(--accent-color);
    color: white;
    padding: 8px 20px;
    border-radius: 25px;
    font-weight: bold;
    font-size: 1.1rem;
}

.type-badge {
    background: var(--secondary-color);
    color: white;
    padding: 8px 20px;
    border-radius: 25px;
    font-weight: bold;
    font-size: 1.1rem;
}

.person-page-body {
    display: grid;
    grid-template-columns: 1fr 2fr;
    gap: 40px;
    margin-bottom: 40px;
}

.person-photo-section {
    text-align: center;
}

.person-photo {
    width: 250px;
    height: 250px;
    border-radius: 50%;
    background: var(--accent-color);
    margin: 0 auto 20px;
    display: flex;
    align-items: center;
    justify-content: center;
    color: white;
    font-size: 4rem;
    font-weight: bold;
    box-shadow: 0 10px 30px rgba(0,0,0,0.2);
    overflow: hidden;
    border: 5px solid white;
}

.person-photo img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.person-initials {
    font-size: 1.2rem;
    color: var(--dark-color);
    margin-top: 10px;
    font-weight: 500;
}

.person-page-qr {
    width: 200px;
    height: 200px;
    margin: 20px auto;
    padding: 15px;
    background: white;
    border-radius: 12px;
    box-shadow: 0 5px 20px rgba(0,0,0,0.15);
    display: flex;
    align-items: center;
    justify-content: center;
}

.person-page-qr canvas,
.person-page-qr img {
    width: 100% !important;
    height: 100% !important;
    border-radius: 8px;
    border: 3px solid var(--accent-color);
}

.qr-hint {
    text-align: center;
    color: #666;
    font-size: 0.9rem;
    margin-top: 10px;
    max-width: 200px;
    margin-left: auto;
    margin-right: auto;
}

.info-section {
    background: var(--card-bg);
    padding: 25px;
    border-radius: 12px;
    margin-bottom: 25px;
    box-shadow: var(--shadow);
    border-left: 5px solid var(--accent-color);
    transition: var(--transition);
}

.info-section:hover {
    transform: translateY(-5px);
    box-shadow: 0 8px 25px rgba(0,0,0,0.15);
}

.info-section h2 {
    color: var(--primary-color);
    margin-bottom: 15px;
    display: flex;
    align-items: center;
    gap: 10px;
    font-size: 1.4rem;
}

.info-section p {
    color: var(--dark-color);
    line-height: 1.6;
    font-size: 1.1rem;
}

.wishes-text {
    font-style: italic;
    color: var(--primary-color);
    font-size: 1.2rem;
    line-height: 1.5;
}

.person-page-footer {
    margin-top: 50px;
    padding-top: 30px;
    border-top: 2px solid var(--accent-color);
}

.share-box {
    text-align: center;
    background: rgba(59, 130, 246, 0.05);
    padding: 30px;
    border-radius: 12px;
}

.share-box h3 {
    color: var(--primary-color);
    margin-bottom: 20px;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 10px;
}

.share-buttons {
    display: flex;
    gap: 20px;
    justify-content: center;
    flex-wrap: wrap;
}

.share-btn {
    background: var(--accent-color);
    color: white;
    border: none;
    padding: 12px 25px;
    border-radius: 8px;
    cursor: pointer;
    font-size: 1rem;
    display: flex;
    align-items: center;
    gap: 10px;
    transition: var(--transition);
}

.share-btn:hover {
    background: var(--secondary-color);
    transform: translateY(-3px);
}

/* ============ UTILITY CLASSES ============ */
.text-center { text-align: center; }
.mt-20 { margin-top: 20px; }
.mb-20 { margin-bottom: 20px; }
.hidden { display: none !important; }

.no-data {
    text-align: center;
    padding: 60px 20px;
    color: #666;
    grid-column: 1 / -1;
}

.no-data i {
    font-size: 4rem;
    color: #94a3b8;
    margin-bottom: 20px;
}

.no-data h3 {
    color: var(--primary-color);
    margin-bottom: 10px;
}

.no-data p {
    color: var(--dark-color);
    opacity: 0.8;
}

/* ============ АНИМАЦИИ ============ */
@keyframes slideUp {
    from { opacity: 0; transform: translateY(20px); }
    to { opacity: 1; transform: translateY(0); }
}

.qr-grid-item, .qr-list-item {
    animation: slideUp 0.5s ease forwards;
}

.qr-grid-item:nth-child(1) { animation-delay: 0.1s; }
.qr-grid-item:nth-child(2) { animation-delay: 0.2s; }
.qr-grid-item:nth-child(3) { animation-delay: 0.3s; }
.qr-grid-item:nth-child(4) { animation-delay: 0.4s; }
.qr-grid-item:nth-child(5) { animation-delay: 0.5s; }

html {
    scroll-behavior: smooth;
}

/* ============ АДАПТИВ ДЛЯ ПЛАНШЕТОВ ============ */
@media (max-width: 1200px) {
    #qr-grid {
        grid-template-columns: repeat(3, 1fr);
        gap: 12px;
    }
    
    .qr-grid-item {
        height: 250px;
        padding: 12px;
    }
    
    .qr-list-item {
        grid-template-columns: auto 60px 1fr 80px auto;
        gap: 15px;
        padding: 12px 15px;
    }
}

@media (max-width: 992px) {
    #qr-grid {
        grid-template-columns: repeat(2, 1fr);
        gap: 15px;
    }
    
    .qr-grid-item {
        height: 240px;
    }
    
    .about-content {
        grid-template-columns: 1fr;
    }
    
    #tree-wrapper {
        grid-template-columns: 1fr;
    }
    
    .contact-content {
        flex-direction: column;
        text-align: center;
    }
}

/* ============ АДАПТИВ ДЛЯ МОБИЛОК (ВСЁ ПИЗДАТОЕ!) ============ */
@media (max-width: 768px) {
    /* HEADER */
    .header-content {
        flex-direction: column;
        align-items: flex-start;
        padding: 0 15px;
        gap: 15px;
    }
    
    header h1 {
        font-size: 1.5rem;
    }
    
    nav ul {
        width: 100%;
        justify-content: center;
        gap: 10px;
        margin-top: 10px;
    }
    
    nav a {
        padding: 6px 12px;
        font-size: 0.9rem;
    }
    
    #toggle-mode {
        position: absolute;
        top: 15px;
        right: 15px;
        padding: 6px 12px;
        font-size: 0.9rem;
    }
    
    /* ABOUT */
    #about {
        padding: 2rem 0;
    }
    
    .stats {
        grid-template-columns: 1fr;
    }
    
    .stat-item {
        padding: 1.2rem;
    }
    
    .stat-item span {
        font-size: 1.8rem;
    }
    
    /* CONTROLS */
    .controls {
        flex-direction: column;
        align-items: stretch;
        gap: 8px;
    }
    
    .controls button {
        width: 100%;
        justify-content: center;
    }
    
    /* QR GRID - ОДНА КОЛОНКА */
    #qr-grid-container {
        padding: 20px 15px;
        margin-top: 15px;
        border-radius: 8px;
    }
    
    #qr-grid {
        grid-template-columns: 1fr !important;
        gap: 12px;
        max-width: 100%;
        margin: 0;
    }
    
    .qr-grid-item {
        height: auto;
        min-height: 120px;
        flex-direction: row;
        padding: 12px;
        text-align: left;
        align-items: center;
        justify-content: flex-start;
    }
    
    .photo-container {
        width: 50px;
        height: 50px;
        margin: 0 12px 0 0;
        flex-shrink: 0;
    }
    
    .photo-initials {
        font-size: 1.5rem;
    }
    
    .qr-grid-code {
        width: 60px;
        height: 60px;
        margin: 0 12px 0 0;
        flex-shrink: 0;
    }
    
    .qr-grid-info {
        flex: 1;
        margin-top: 0;
        padding-top: 0;
        border-top: none;
        padding-left: 0;
        text-align: left;
    }
    
    .qr-grid-info h4 {
        font-size: 1rem;
        white-space: normal;
    }
    
    .qr-grid-info p {
        font-size: 0.85rem;
    }
    
    .qr-grid-number {
        top: 8px;
        left: 8px;
        width: 28px;
        height: 28px;
        font-size: 14px;
    }
    
    /* QR LIST - УПРОЩЕННЫЙ ВИД */
    .qr-list-item {
        grid-template-columns: auto 1fr auto;
        grid-template-rows: auto auto;
        gap: 10px;
        padding: 10px;
    }
    
    .qr-list-number {
        grid-column: 1;
        grid-row: 1;
        width: 30px;
        height: 30px;
        font-size: 12px;
    }
    
    .qr-list-photo {
        grid-column: 2;
        grid-row: 1;
        width: 50px;
        height: 50px;
    }
    
    .qr-list-info {
        grid-column: 1 / span 3;
        grid-row: 2;
        margin-top: 10px;
    }
    
    .qr-list-code {
        grid-column: 1;
        grid-row: 3;
        width: 60px;
        height: 60px;
    }
    
    .list-view-btn {
        grid-column: 2 / span 2;
        grid-row: 3;
        justify-self: end;
        padding: 8px 12px;
        font-size: 0.85rem;
    }
    
    /* TREE */
    #tree-container {
        height: 300px;
    }
    
    .tree-controls {
        position: relative;
        top: 0;
        right: 0;
        justify-content: center;
        margin-bottom: 15px;
    }
    
    /* MODAL */
    .modal-content {
        width: 95%;
        margin: 20px auto;
        max-height: 90vh;
    }
    
    .modal-body {
        padding: 20px;
    }
    
    .modal-person-info {
        grid-template-columns: 1fr;
    }
    
    /* PERSON PAGE */
    .person-page-body {
        grid-template-columns: 1fr;
    }
    
    .person-photo {
        width: 150px;
        height: 150px;
    }
    
    .person-page-header h1 {
        font-size: 1.6rem;
    }
    
    /* CONTACT */
    .contact-info p {
        justify-content: center;
    }
    
    .social-links {
        justify-content: center;
    }
}

/* ============ МАЛЕНЬКИЕ МОБИЛКИ ============ */
@media (max-width: 480px) {
    .container {
        padding: 0 12px;
    }
    
    header h1 {
        font-size: 1.3rem;
    }
    
    nav a {
        padding: 5px 8px;
        font-size: 0.85rem;
    }
    
    #toggle-mode {
        padding: 5px 10px;
        font-size: 0.8rem;
    }
    
    .qr-grid-item {
        padding: 10px;
    }
    
    .photo-container {
        width: 45px;
        height: 45px;
        margin-right: 10px;
    }
    
    .qr-grid-code {
        width: 55px;
        height: 55px;
        margin-right: 10px;
    }
    
    .qr-grid-info h4 {
        font-size: 0.9rem;
    }
    
    .person-photo {
        width: 120px;
        height: 120px;
        font-size: 3rem;
    }
    
    .share-buttons {
        flex-direction: column;
        align-items: center;
    }
    
    .share-btn {
        width: 100%;
        max-width: 250px;
    }
}

/* ============ FIX FOR TOUCH DEVICES ============ */
@media (hover: none) and (pointer: coarse) {
    .qr-grid-item:hover,
    .qr-list-item:hover,
    .stat-item:hover {
        transform: none;
    }
    
    .qr-grid-item:active,
    .qr-list-item:active {
        transform: scale(0.98);
        opacity: 0.9;
    }
    
    button, a, .qr-grid-item, .qr-list-item {
        min-height: 44px;
    }
}

/* ============ iOS SAFARI FIX ============ */
@supports (-webkit-touch-callout: none) {
    .modal-content,
    .person-page {
        -webkit-overflow-scrolling: touch;
    }
}