:root {
    --primary: #c4a96a;
    --primary-hover: #b59a57;
    --secondary: #8c938c;
    --accent: #e5c158;
    --bg-dark: #0a1211;
    --bg-gradient: radial-gradient(circle at center, #101f1d 0%, #050a09 100%);
    --glass-bg: rgba(10, 18, 17, 0.75);
    --glass-border: rgba(196, 169, 106, 0.25);
    --text-main: #f3f5f3;
    --text-muted: #808c87;
    --input-bg: rgba(0, 0, 0, 0.45);
    --success: #2e7d32;
}

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

html {
    max-width: 100vw;
    overflow-x: hidden;
}

body {
    font-family: 'Inter', sans-serif;
    background: var(--bg-gradient);
    color: var(--text-main);
    min-height: 100vh;
    min-height: 100dvh; /* iOS Safari: динамічна висота без перекриття нижньою панеллю */
    display: flex;
    align-items: center;
    justify-content: center;
    max-width: 100vw;
    position: relative;
    -webkit-tap-highlight-color: transparent;
    /* НЕ ставимо overflow-x: hidden на body — це робить overflow-y: auto за специфікацією
       і додає другий скрол поверх html. Натомість max-width: 100vw тримає горизонталь. */
}

/* Фонове зображення — окремий КОМПОЗИТНИЙ шар (position:fixed), а не background-attachment:fixed.
   Фон лишається статичним при скролі, але БЕЗ перемальовок щокадру (саме fixed-bg спричиняв
   лаги скролу, особливо в парі з backdrop-filter і на iOS, де fixed-bg фактично не підтримується). */
body::before {
    content: '';
    position: fixed;
    inset: 0;
    background: url('bg.png') no-repeat center center;
    background-size: cover;
    z-index: -2;
    pointer-events: none;
}

/* iOS Safari: не зумити при тапі на input (font-size ≥ 16px), прибрати тап-підсвітку */
input, select, textarea, button {
    -webkit-tap-highlight-color: transparent;
}
@media (max-width: 768px) {
    input, select, textarea {
        font-size: 16px !important;
    }
}

h1,
h2,
.btn-primary {
    font-family: 'Outfit', sans-serif;
}

/* Background Animated Blobs */
.background-blob {
    position: absolute;
    border-radius: 50%;
    filter: blur(80px);
    z-index: -1;
    opacity: 0.25;
}

.blob-1 {
    width: 400px;
    height: 400px;
    background: #0d2a23;
    top: -100px;
    left: -100px;
}

.blob-2 {
    width: 350px;
    height: 350px;
    background: #1a2618;
    bottom: -50px;
    right: -50px;
    animation-delay: -5s;
}

.blob-3 {
    width: 300px;
    height: 300px;
    background: #1a302a;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    animation-delay: -10s;
}

@keyframes move {
    0% {
        transform: translate(0, 0) scale(1);
    }

    100% {
        transform: translate(50px, 100px) scale(1.1);
    }
}

/* Container & Card */
.app-container {
    width: 100%;
    max-width: 1000px;
    padding: 20px;
    display: flex;
    flex-direction: column;
    align-items: center;
}

.glass-card {
    width: 100%;
    max-width: 550px;
    background: var(--glass-bg);
    backdrop-filter: none;
    -webkit-backdrop-filter: none;
    border: 1px solid var(--glass-border);
    border-radius: 24px;
    padding: 40px;
    box-shadow: 0 25px 50px -12px rgba(0, 0, 0, 0.7);
    position: relative;
    overflow: hidden;
}

.form-header {
    text-align: center;
    margin-bottom: 32px;
}

.form-header h1 {
    font-size: 2rem;
    margin-bottom: 8px;
    background: linear-gradient(to right, #fff, #c4a96a);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
}

.form-header p {
    color: var(--text-muted);
    font-size: 0.95rem;
}

/* Progress Bar */
.progress-bar {
    width: 100%;
    height: 4px;
    background: rgba(255, 255, 255, 0.05);
    border-radius: 2px;
    margin-top: 24px;
}

.progress-fill {
    height: 100%;
    width: 50%;
    background: var(--primary);
    border-radius: 2px;
    transition: width 0.5s cubic-bezier(0.4, 0, 0.2, 1);
}

/* Forms */
.registration-form {
    display: none;
    flex-direction: column;
    gap: 20px;
    animation: fadeIn 0.4s ease-out;
}

.registration-form.active {
    display: flex;
}

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

    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.radio-group {
    display: flex;
    flex-wrap: wrap;
    gap: 16px;
    background: var(--input-bg);
    padding: 8px;
    border-radius: 12px;
    border: 1px solid var(--glass-border);
}

.radio-label {
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    padding: 10px;
    border-radius: 8px;
    cursor: pointer;
    transition: all 0.2s ease;
}

.radio-label:has(input:checked) {
    background: var(--primary);
    color: #050a09;
    font-weight: 600;
}

.checkbox-group {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 12px;
    background: var(--input-bg);
    padding: 16px;
    border-radius: 12px;
    border: 1px solid var(--glass-border);
}

.checkbox.audit-section-title {
    font-size: 1.2rem;
    font-weight: 700;
    color: var(--primary);
    margin-bottom: 24px;
    padding-bottom: 12px;
    border-bottom: 1px solid var(--glass-border);
    text-transform: uppercase;
    letter-spacing: 1px;
}

.input-group {
    display: flex;
    flex-direction: column;
    gap: 10px;
    width: 100%;
}

.input-row {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 16px;
}
.input-row:has(.vpn-names) {
    grid-template-columns: repeat(3, 1fr);
}
.input-row .vpn-names {
    grid-column: span 2;
}

.input-group label {
    display: flex;
    align-items: center;
    gap: 8px;
    color: var(--text-main);
    cursor: pointer;
    font-size: 0.9rem;
    font-weight: 500;
}

.checkbox-group label {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    color: var(--text-main);
    cursor: pointer;
    background: rgba(255, 255, 255, 0.04);
    border: 1px solid var(--glass-border);
    border-radius: 10px;
    padding: 10px 12px;
}

.input-grid-checks {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 16px;
}

.glass-card:has(#audit-form.active),
.glass-card:has(#audit-android-form.active),
.glass-card:has(#audit-ios-form.active) {
    max-width: 780px;
}

@media (max-width: 600px) {
    .input-grid-checks { grid-template-columns: 1fr 1fr; }
}

textarea {
    background: var(--input-bg);
    border: 1px solid var(--glass-border);
    border-radius: 12px;
    padding: 14px 16px;
    color: white;
    font-size: 1rem;
    font-family: inherit;
    resize: vertical;
    min-height: 56px;
}

textarea:focus {
    outline: none;
    border-color: var(--primary);
}

input,
select {
    width: 100%;
    max-width: 100%;
    box-sizing: border-box;
    background: var(--input-bg);
    border: 1px solid var(--glass-border);
    border-radius: 12px;
    padding: 14px 16px;
    color: white;
    font-size: 1rem;
    font-family: inherit;
    transition: all 0.2s ease;
    text-overflow: ellipsis;
    white-space: nowrap;
    overflow: hidden;
}

input[type="checkbox"],
input[type="radio"] {
    width: auto;
    max-width: none;
    padding: 0;
    margin: 0;
    flex: 0 0 auto;
    accent-color: var(--primary);
    cursor: pointer;
}

.registration-form select {
    min-height: 52px;
}

input:focus,
select:focus {
    outline: none;
    border-color: var(--primary);
    background: rgba(255, 255, 255, 0.08);
    box-shadow: 0 0 0 4px rgba(196, 169, 106, 0.15);
}

input::placeholder {
    color: rgba(255, 255, 255, 0.25);
}

select option {
    background: #0a1211;
    color: white;
}

/* Buttons */
.btn-primary {
    background: var(--primary);
    color: #050a09;
    border: none;
    border-radius: 12px;
    padding: 16px;
    font-size: 1rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s ease;
    margin-top: 10px;
}

.btn-primary:hover {
    background: var(--primary-hover);
    transform: translateY(-1px);
    box-shadow: 0 10px 15px -3px rgba(196, 169, 106, 0.35);
}

.btn-primary:active {
    transform: translateY(0);
}

.btn-secondary {
    background: transparent;
    border: 1px solid var(--glass-border);
    color: var(--text-main);
    border-radius: 12px;
    padding: 16px;
    font-size: 1rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s ease;
    flex: 1;
}

.btn-secondary:hover {
    background: rgba(255, 255, 255, 0.05);
}

.btn-group {
    display: flex;
    gap: 12px;
    margin-top: 10px;
}

.btn-group .btn-primary {
    flex: 2;
    margin-top: 0;
}

/* Success State */
.success-message {
    display: none;
    flex-direction: column;
    align-items: center;
    text-align: center;
    padding: 20px 0;
    animation: scaleIn 0.5s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}

@keyframes scaleIn {
    from {
        opacity: 0;
        transform: scale(0.8);
    }

    to {
        opacity: 1;
        transform: scale(1);
    }
}

.success-icon {
    width: 80px;
    height: 80px;
    background: var(--success);
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 2.5rem;
    margin-bottom: 24px;
    box-shadow: 0 0 20px rgba(46, 125, 50, 0.4);
}

.success-message h2 {
    font-size: 1.75rem;
    margin-bottom: 12px;
}

.success-message p {
    color: var(--text-muted);
    margin-bottom: 32px;
    line-height: 1.6;
}

/* Responsive */
.btn-group-vertical {
    display: flex;
    flex-direction: column;
    gap: 12px;
    width: 100%;
}

.admin-section {
    margin-top: 60px;
    background: var(--glass-bg);
    backdrop-filter: none;
    border: 1px solid var(--glass-border);
    border-radius: 24px;
    padding: 30px;
    width: 100%;
    max-width: 800px;
}

.admin-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 20px;
}

.table-container {
    overflow-x: auto;
}

table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.9rem;
}

th,
td {
    padding: 12px;
    text-align: left;
    border-bottom: 1px solid var(--glass-border);
}

th {
    color: var(--text-muted);
    font-weight: 500;
}

.btn-text {
    background: transparent;
    border: none;
    color: var(--primary);
    cursor: pointer;
    font-weight: 600;
    text-decoration: underline;
}

.action-btns {
    display: flex;
    gap: 12px;
}

.edit-btn {
    color: #60a5fa;
    cursor: pointer;
    background: none;
    border: none;
    font: inherit;
    text-decoration: underline;
}

.delete-btn {
    color: #f87171;
    cursor: pointer;
    background: none;
    border: none;
    font: inherit;
    text-decoration: underline;
}

.cards-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
    gap: 20px;
}

.user-card {
    background: rgba(255, 255, 255, 0.03);
    border: 1px solid var(--glass-border);
    border-radius: 16px;
    padding: 20px;
    transition: transform 0.2s ease;
}

.user-card:hover {
    transform: translateY(-5px);
    background: rgba(255, 255, 255, 0.05);
}

.user-card-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 15px;
    border-bottom: 1px solid var(--glass-border);
    padding-bottom: 10px;
}

.user-card-header h3 {
    font-size: 1.1rem;
    color: var(--text-main);
}

.user-tag {
    font-size: 0.75rem;
    background: var(--primary);
    color: #050a09;
    padding: 4px 8px;
    border-radius: 20px;
    font-weight: 600;
}

.user-card-body p {
    font-size: 0.85rem;
    color: var(--text-muted);
    margin-bottom: 8px;
}

.device-list {
    margin-top: 15px;
}

.device-list h4 {
    font-size: 0.9rem;
    margin-bottom: 10px;
    color: var(--text-main);
}

.device-item-complex {
    background: rgba(255, 255, 255, 0.02);
    border-radius: 12px;
    padding: 12px;
    margin-bottom: 12px;
    border: 1px solid rgba(255, 255, 255, 0.05);
}

.device-info {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 8px;
}

.device-actions {
    display: flex;
    gap: 8px;
}

.device-actions button {
    background: rgba(255, 255, 255, 0.05);
    border: 1px solid var(--glass-border);
    color: var(--text-main);
    padding: 4px 10px;
    border-radius: 6px;
    font-size: 0.75rem;
    cursor: pointer;
    transition: all 0.2s;
}

.device-actions button:hover {
    background: var(--primary);
    border-color: var(--primary);
    color: #050a09;
    font-weight: 600;
}

.device-actions .delete-btn:hover {
    background: #ef4444;
    border-color: #ef4444;
    color: white;
}

.device-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 10px;
}

.add-device-btn {
    background: transparent;
    border: 1px dashed var(--primary);
    color: var(--primary);
    padding: 4px 12px;
    border-radius: 6px;
    font-size: 0.8rem;
    cursor: pointer;
}

.audit-history {
    margin-top: 8px;
    border-top: 1px solid rgba(255, 255, 255, 0.05);
    padding-top: 8px;
}

.audit-history summary {
    font-size: 0.75rem;
    color: var(--text-muted);
    cursor: pointer;
    list-style: none;
}

.audit-history ul {
    list-style: none;
    padding-left: 0;
    margin-top: 8px;
}

.messenger-audit-grid {
    background: rgba(255, 255, 255, 0.03);
    border-radius: 12px;
    padding: 10px;
    border: 1px solid var(--glass-border);
}

.messenger-header-row {
    display: grid;
    grid-template-columns: 1fr 1fr 1fr 1fr;
    padding: 8px;
    font-size: 0.75rem;
    color: var(--text-muted);
    font-weight: 600;
    text-align: center;
}

.messenger-row {
    display: grid;
    grid-template-columns: 1fr 1fr 1fr 1fr;
    align-items: center;
    gap: 8px;
    padding: 8px;
    border-top: 1px solid rgba(255, 255, 255, 0.05);
}

.messenger-row .m-name {
    font-size: 0.85rem;
    color: var(--text-main);
}

.messenger-row select {
    padding: 6px;
    font-size: 0.8rem;
    text-align: center;
    min-height: 0;
}

/* Responsive Design */
@media (max-width: 1024px) {
    .app-container {
        padding: 15px;
    }

    .admin-section {
        max-width: 100%;
    }
}

@media (max-width: 768px) {
    .glass-card {
        padding: 32px 24px;
        max-width: 100%;
    }

    .cards-grid {
        grid-template-columns: 1fr;
    }

    .form-header h1 {
        font-size: 1.75rem;
    }
}

@media (max-width: 480px) {
    body {
        padding: 10px 0;
        padding-bottom: max(10px, env(safe-area-inset-bottom));
        align-items: flex-start;
    }

    .glass-card {
        padding: 24px 16px;
        border-radius: 20px;
        border: none;
        box-shadow: none;
        background: transparent;
        backdrop-filter: none;
    }

    .form-header h1 {
        font-size: 1.5rem;
    }

    .input-row,
    .input-grid-checks {
        grid-template-columns: 1fr;
        gap: 12px;
    }

    .btn-group {
        flex-direction: column;
        gap: 10px;
    }

    .btn-group .btn-primary,
    .btn-secondary {
        width: 100%;
        padding: 14px;
    }

    .admin-section {
        padding: 20px 15px;
        border-radius: 0;
        border-left: none;
        border-right: none;
    }

    .admin-header {
        flex-direction: column;
        gap: 15px;
        align-items: center;
        text-align: center;
    }

    .admin-header h2 {
        font-size: 1.4rem;
    }

    select,
    input {
        font-size: 16px;
    }

    .messenger-audit-grid {
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
        margin: 0 -5px;
    }

    .messenger-header-row,
    .messenger-row {
        min-width: 450px;
    }
}

/* Guest Mode (Hides admin elements) */
body.guest-mode .admin-section,
body.guest-mode #export-all-link,
body.guest-mode #import-users-btn,
body.guest-mode #clear-db-btn,
body.guest-mode #existing-user-group,
body.guest-mode #bind-user-group,
body.guest-mode #goto-audit-btn,
body.guest-mode #registration-reload {
    display: none !important;
}

.file-input-wrapper {
    background: rgba(255, 255, 255, 0.05);
    border: 1px dashed rgba(255, 255, 255, 0.2);
    border-radius: 10px;
    padding: 12px;
    display: flex;
    flex-direction: column;
    gap: 8px;
    transition: all 0.2s;
}

.file-input-wrapper:hover {
    border-color: var(--primary);
    background: rgba(255, 255, 255, 0.08);
}

.file-input-wrapper label {
    font-size: 0.85rem;
    color: var(--text-main);
    font-weight: 600;
    cursor: pointer;
}

/* Logo Styling */
.logo-wrapper {
    display: flex;
    justify-content: center;
    align-items: center;
    margin-bottom: 20px;
}

.main-logo {
    width: 90px;
    height: auto;
    filter: drop-shadow(0 0 10px rgba(196, 169, 106, 0.4));
    transition: transform 0.3s ease;
}

.main-logo:hover {
    transform: scale(1.05) rotate(2deg);
}

.admin-logo-img {
    width: 48px;
    height: 48px;
    object-fit: contain;
    filter: drop-shadow(0 0 5px rgba(196, 169, 106, 0.3));
    transition: transform 0.3s ease;
}

.admin-logo-img:hover {
    transform: scale(1.1);
}

.user-files-existing {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    margin-top: 10px;
}

.user-file-chip {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    background: rgba(255, 255, 255, 0.06);
    border: 1px solid var(--glass-border);
    border-radius: 8px;
    padding: 4px 6px 4px 10px;
    font-size: 0.82rem;
    max-width: 100%;
}

.user-file-chip a {
    color: #cbd5e1;
    text-decoration: none;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    max-width: 200px;
}

.user-file-x {
    background: rgba(239, 68, 68, 0.15);
    color: #fca5a5;
    border: none;
    border-radius: 6px;
    width: 20px;
    height: 20px;
    line-height: 1;
    cursor: pointer;
    font-size: 1rem;
}

.profile-files {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
}

.profile-file-img img {
    width: 72px;
    height: 72px;
    object-fit: cover;
    border-radius: 10px;
    border: 1px solid var(--glass-border);
    display: block;
}

.profile-file-link {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    background: rgba(255, 255, 255, 0.06);
    border: 1px solid var(--glass-border);
    border-radius: 8px;
    padding: 6px 10px;
    color: #cbd5e1;
    text-decoration: none;
    font-size: 0.85rem;
}

.dp-wrap { position: relative; }
.dp-input { cursor: pointer; }

.dp-panel {
    position: absolute;
    right: 0;
    left: auto;
    top: calc(100% + 6px);
    z-index: 70;
    width: 320px;
    max-width: min(320px, 88vw);
    padding: 14px;
    background: #0f1a18;
    border: 1px solid rgba(196, 169, 106, 0.35);
    border-radius: 14px;
    box-shadow: 0 18px 44px rgba(0, 0, 0, 0.6);
}

.dp-head {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-bottom: 12px;
}

.dp-head .dp-mo { flex: 1; min-width: 0; }
.dp-head .dp-yr { width: 76px; flex: 0 0 auto; }

.dp-mo, .dp-yr {
    background: rgba(255, 255, 255, 0.06);
    color: #f3f5f3;
    border: 1px solid var(--glass-border);
    border-radius: 8px;
    padding: 6px 8px;
    font-size: 0.9rem;
    font-family: inherit;
    cursor: pointer;
}

.dp-nav {
    background: rgba(255, 255, 255, 0.06);
    color: var(--accent);
    border: 1px solid var(--glass-border);
    border-radius: 8px;
    width: 32px;
    height: 32px;
    font-size: 1.2rem;
    line-height: 1;
    cursor: pointer;
    flex: 0 0 auto;
    transition: all 0.15s;
}
.dp-nav:hover { background: rgba(196, 169, 106, 0.18); border-color: rgba(196, 169, 106, 0.45); }

.dp-wd {
    display: grid;
    grid-template-columns: repeat(7, 1fr);
    gap: 2px;
    margin-bottom: 6px;
}
.dp-wd span {
    text-align: center;
    font-size: 0.72rem;
    color: var(--text-muted);
    font-weight: 600;
    padding: 4px 0;
}

.dp-grid {
    display: grid;
    grid-template-columns: repeat(7, 1fr);
    gap: 3px;
}
.dp-empty { visibility: hidden; }

.dp-day {
    aspect-ratio: 1;
    border: 1px solid transparent;
    background: rgba(255, 255, 255, 0.04);
    color: #e8eceb;
    border-radius: 8px;
    font-size: 0.85rem;
    cursor: pointer;
    transition: all 0.12s;
}
.dp-day:hover { background: rgba(196, 169, 106, 0.18); }
.dp-day.today { border-color: rgba(196, 169, 106, 0.5); }
.dp-day.sel {
    background: var(--accent);
    color: #050a09;
    font-weight: 700;
    box-shadow: 0 2px 10px rgba(196, 169, 106, 0.35);
}

.dp-foot {
    margin-top: 12px;
    display: flex;
    justify-content: flex-end;
}
.dp-clear {
    background: transparent;
    color: var(--text-muted);
    border: 1px solid var(--glass-border);
    border-radius: 8px;
    padding: 5px 12px;
    font-size: 0.82rem;
    cursor: pointer;
    transition: color 0.15s;
}
.dp-clear:hover { color: #fca5a5; border-color: rgba(239, 68, 68, 0.4); }
