:root {
    --bg-color: #050a0f;
    --accent-cyan: #30d5ed;
    --accent-red: #ff4d4d;
    --accent-yellow: #f1c40f;
    --accent-green: #2ecc71;
    --text-white: #ffffff;
    --text-gray: #a0aec0;
    --card-bg: rgba(255, 255, 255, 0.03);
    --border-color: rgba(48, 213, 237, 0.2);
    --block-bg: rgba(48, 213, 237, 0.05);
    --edit-bg: #000000;
}

* { margin: 0; padding: 0; box-sizing: border-box; }

body {
    font-family: 'Inter', sans-serif;
    background-color: var(--bg-color);
    color: var(--text-white);
    /* Градиент перенесен в body::before */
    min-height: 100vh;
    overflow-x: hidden;
    user-select: none;
    -webkit-user-select: none;
    cursor: default;
    position: relative;
}

body::before {
    content: "";
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: radial-gradient(circle at 80% 50%, #0a1f2e 0%, #050a0f 100%);
    z-index: -2;
    pointer-events: none;
}

.service-name, .account-name, .value, .filter-input, .creation-input {
    user-select: text;
    -webkit-user-select: text;
    cursor: text;
}

.value.password-field:not([contenteditable="true"]) {
    user-select: none;
    cursor: default;
}

.bg-lines {
    position: fixed; top: 0; right: 0; width: 100%; height: 100%;
    background-image:
            linear-gradient(rgba(48, 213, 237, 0.05) 1px, transparent 1px),
            linear-gradient(90deg, rgba(48, 213, 237, 0.05) 1px, transparent 1px);
    background-size: 50px 50px;
    mask-image: radial-gradient(circle at 80% 60%, black, transparent 70%);
    z-index: -1;
    pointer-events: none;
}

.container { max-width: 900px; margin: 0 auto; padding: 0 40px 80px; position: relative; z-index: 1; }

header { padding: 40px 0; }
.logo { display: flex; align-items: center; gap: 15px; text-decoration: none; color: white; transition: 0.3s; }
.logo:hover { opacity: 0.8; }
.logo-img { width: 40px; height: 40px; }
.logo-text { font-weight: 900; font-size: 22px; letter-spacing: 2px; text-transform: uppercase; }

/* --- CONTROLS SECTION --- */
.controls-section { margin-bottom: 40px; display: flex; flex-direction: column; gap: 15px; }

.filter-input {
    width: 100%; background: rgba(255, 255, 255, 0.05); border: 1px solid var(--border-color);
    border-radius: 12px; padding: 18px 25px; color: white; font-size: 18px; outline: none; transition: 0.3s;
    font-weight: 700;
}
.filter-input:focus { border-color: var(--accent-cyan); box-shadow: 0 0 15px rgba(48, 213, 237, 0.2); }

/* --- CREATION PANEL --- */
.creation-panel {
    display: flex; gap: 10px; width: 100%;
    animation: fadeIn 0.3s ease-out;
}

.creation-input {
    flex-grow: 1;
    background: rgba(48, 213, 237, 0.1);
    border: 1px solid var(--accent-cyan);
    border-radius: 12px; padding: 15px 25px; color: white; font-size: 16px; outline: none;
    font-weight: 700;
}
.creation-input::placeholder { color: rgba(48, 213, 237, 0.5); font-weight: 400; }

.btn-create-confirm {
    background: var(--accent-cyan); color: #000; border: none; padding: 0 30px;
    border-radius: 12px; font-weight: 900; text-transform: uppercase; cursor: pointer;
}
.btn-create-confirm:hover { background: #fff; box-shadow: 0 0 15px rgba(48, 213, 237, 0.4); }

.btn-create-cancel {
    background: transparent; border: 1px solid var(--accent-red); color: var(--accent-red);
    padding: 0 20px; border-radius: 12px; font-weight: 700; text-transform: uppercase; cursor: pointer;
}
.btn-create-cancel:hover { background: var(--accent-red); color: #fff; }

button { transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1); cursor: pointer; outline: none; }
button:active { transform: scale(0.95); }

.btn-main {
    background: var(--accent-cyan); color: #000; border: none; padding: 15px;
    border-radius: 12px; font-weight: 900; text-transform: uppercase;
}
.btn-main:hover { background: #fff; box-shadow: 0 0 20px rgba(48, 213, 237, 0.5); transform: translateY(-2px); }
.btn-main.hidden { display: none; }

.services-grid { display: grid; gap: 30px; }
.service-card {
    background: var(--card-bg); border: 1px solid var(--border-color);
    border-radius: 20px; padding: 30px; backdrop-filter: blur(10px);
    animation: fadeIn 0.4s ease-out;
}

@keyframes fadeIn {
    from { opacity: 0; transform: translateY(10px); }
    to { opacity: 1; transform: translateY(0); }
}

.service-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 25px; gap: 10px; }

.service-name {
    font-size: 24px; font-weight: 900; color: var(--accent-cyan); text-transform: uppercase; flex-grow: 1;
    padding: 8px 12px; border-radius: 10px; border: 1px solid transparent; transition: 0.3s;
    white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.service-name[contenteditable="true"] {
    background-color: var(--edit-bg) !important; border-color: var(--accent-cyan); outline: none; white-space: normal;
}

.account-block {
    background: var(--block-bg); border-radius: 12px; padding: 15px;
    margin-bottom: 15px; border: 1px solid rgba(255,255,255,0.05); position: relative;
}

.account-title-row {
    display: flex; align-items: center; gap: 15px; margin-bottom: 12px;
    padding-bottom: 12px; border-bottom: 1px solid rgba(255,255,255,0.1); margin-right: 25px;
}

.account-name {
    flex-grow: 1; font-size: 13px; font-weight: 700; color: var(--text-gray);
    text-transform: uppercase; letter-spacing: 1px; outline: none;
    padding: 8px 12px; border-radius: 6px; border: 1px solid transparent;
    transition: 0.3s; white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}

.account-name[contenteditable="true"] {
    background: var(--edit-bg); color: var(--accent-cyan); border-color: var(--accent-cyan); white-space: normal;
}

.btn-delete-acc {
    position: absolute; top: 10px; right: 10px; background: transparent;
    border: none; color: var(--text-gray); font-size: 18px;
}
.btn-delete-acc:hover { color: var(--accent-red); transform: rotate(90deg) scale(1.2); }

.data-row { display: flex; align-items: center; padding: 10px 0; margin-right: 25px; gap: 15px; }

.label {
    color: var(--text-gray);
    font-size: 12px;
    width: 60px;
    text-transform: uppercase;
    font-weight: 700;
    flex-shrink: 0;
}

.btn-copy-icon {
    background: transparent; border: none; display: flex; align-items: center; justify-content: center; padding: 5px;
}
.btn-copy-icon svg {
    fill: none; stroke: var(--accent-cyan); stroke-width: 2; width: 18px; height: 18px; transition: 0.2s;
}
.btn-copy-icon:hover svg { stroke: #fff; filter: drop-shadow(0 0 5px var(--accent-cyan)); }

.field-wrapper { display: flex; flex-direction: column; flex-grow: 1; gap: 4px; min-width: 150px; overflow: hidden; }

.value {
    font-family: 'Courier New', monospace;
    font-size: 18px;
    font-weight: 600;
    outline: none;
    padding: 8px 12px;
    border-radius: 6px;
    transition: 0.3s;
    border: 1px solid transparent;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    width: 100%;
}

.value.password-field { -webkit-text-security: disc; }

.value[contenteditable="true"] {
    background-color: var(--edit-bg) !important; border-color: var(--accent-cyan);
    color: var(--accent-cyan); white-space: normal; -webkit-text-security: none !important;
}

.btn-action {
    background: transparent; border: 1px solid var(--border-color);
    color: var(--accent-cyan); padding: 6px 12px; border-radius: 6px;
    font-size: 10px; text-transform: uppercase; font-weight: 700; flex-shrink: 0;
}
.btn-action:hover { background: rgba(48, 213, 237, 0.1); border-color: var(--accent-cyan); color: #fff; }
.btn-action.save { background: var(--accent-green); border-color: var(--accent-green); color: #fff; }

.btn-gen {
    background: rgba(48, 213, 237, 0.1); border: 1px dashed var(--accent-cyan);
    color: var(--accent-cyan); font-size: 9px; display: none;
}
.btn-gen:hover { background: var(--accent-cyan); color: #000; }

.btn-gen:disabled {
    border-color: var(--text-gray);
    color: var(--text-gray);
    background: transparent;
    cursor: not-allowed;
    opacity: 0.5;
}

.btn-action.delete-service { border-color: var(--accent-red); color: var(--accent-red); }
.btn-action.delete-service:hover { background: var(--accent-red); color: #fff; }

.btn-add-acc {
    width: 100%; padding: 12px; background: transparent;
    border: 1px dashed var(--border-color); color: var(--text-gray);
    border-radius: 10px; text-transform: uppercase; font-size: 12px;
}
.btn-add-acc:hover { border-color: var(--accent-cyan); color: var(--accent-cyan); background: rgba(48, 213, 237, 0.05); }

/* --- TOAST NOTIFICATION --- */
.copy-toast {
    position: fixed; bottom: 50px; left: 50%; transform: translateX(-50%);
    background: var(--accent-cyan); color: #000; padding: 12px 25px;
    border-radius: 50px; font-weight: 900; text-transform: uppercase;
    font-size: 12px; z-index: 2000; opacity: 0; visibility: hidden;
    box-shadow: 0 0 20px rgba(48, 213, 237, 0.4);
}
.copy-toast.animate { visibility: visible; animation: toastFlyReset 1.5s ease-in-out forwards; }

@keyframes toastFlyReset {
    0% { opacity: 0; transform: translate(-50%, 20px); }
    20% { opacity: 1; transform: translate(-50%, 0); }
    80% { opacity: 1; transform: translate(-50%, 0); }
    100% { opacity: 0; transform: translate(-50%, -20px); }
}

.modal-overlay {
    position: fixed; top: 0; left: 0; width: 100%; height: 100%;
    background: rgba(0,0,0,0.85); backdrop-filter: blur(8px);
    display: none; justify-content: center; align-items: center; z-index: 1000;
}
.modal { background: var(--bg-color); border: 2px solid var(--accent-cyan); padding: 40px; border-radius: 24px; text-align: center; max-width: 400px; }
.modal-buttons { display: flex; gap: 15px; justify-content: center; margin-top: 25px; }
.btn-confirm { background: var(--accent-red); color: white; border: none; padding: 12px 25px; border-radius: 10px; font-weight: 700; }
.btn-cancel { background: #2d3748; color: white; border: none; padding: 12px 25px; border-radius: 10px; font-weight: 700; }

.hidden { display: none !important; }

/* --- LOADING STATES --- */
@keyframes spin {
    0% { transform: rotate(0deg); }
    100% { transform: rotate(360deg); }
}

.loader-icon {
    display: inline-block;
    width: 12px;
    height: 12px;
    border: 2px solid rgba(255,255,255,0.3);
    border-radius: 50%;
    border-top-color: #fff;
    animation: spin 0.8s linear infinite;
    margin-right: 5px;
}

button:disabled, .btn-disabled {
    opacity: 0.6;
    cursor: not-allowed !important;
    pointer-events: none;
    filter: grayscale(0.8);
}

.saving-state {
    color: var(--text-gray);
    opacity: 0.6;
    pointer-events: none;
}

/* --- ERROR POPUP --- */
.error-popup {
    position: fixed;
    top: 20px;
    left: 50%;
    transform: translate(-50%, -20px);
    background-color: var(--accent-red);
    color: #ffffff;
    padding: 15px 30px;
    border-radius: 12px;
    z-index: 9999;
    font-weight: 700;
    box-shadow: 0 5px 20px rgba(255, 77, 77, 0.4);
    display: flex;
    align-items: center;
    justify-content: center;
    opacity: 0;
    visibility: hidden;
    transition: opacity 0.3s ease, visibility 0.3s ease, transform 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275);

    max-width: 80vw;
    text-align: center;
}

.error-popup.show {
    opacity: 1;
    visibility: visible;
    transform: translate(-50%, 0);
}

.error-text {

    display: block;
    white-space: pre-wrap;
    word-break: break-word;
    line-height: 1.4;
}

/* --- APP LOADING STATE --- */
.loading-container {

    position: fixed;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    z-index: 2000;

    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;

    background: rgba(10, 31, 46, 0.8);
    padding: 40px;
    border-radius: 20px;
    border: 1px solid rgba(48, 213, 237, 0.2);
    width: 100%;
    max-width: 450px;
    backdrop-filter: blur(10px);
    box-shadow: 0 20px 50px rgba(0,0,0,0.5);
}

.spinner {
    display: block;
    width: 50px;
    height: 50px;
    border: 4px solid rgba(48, 213, 237, 0.2);
    border-radius: 50%;
    border-top-color: var(--accent-cyan);
    animation: spin 1s linear infinite;
    margin: 20px auto;
}

.loading-text {
    color: var(--text-gray);
    font-size: 14px;
    font-weight: 700;
    white-space: pre-wrap;
    text-align: center;
    margin-top: 20px;
    margin-bottom: 25px;
    opacity: 1;
}

.loading-text.error {
    font-weight: 700;
    white-space: pre-wrap;
}

/* --- USER PROFILE --- */
header {
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.user-profile {
    position: relative;
    cursor: pointer;
}

.user-profile-trigger {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 8px 12px;
    border-radius: 12px;
    transition: background 0.3s;
}

.user-profile-trigger:hover {
    background: rgba(255, 255, 255, 0.05);
}

.user-email {
    color: var(--text-gray);
    font-weight: 700;
    transition: color 0.3s;
}

.user-menu-icon {
    width: 20px;
    height: 20px;
    color: var(--text-gray);
    transition: color 0.3s;
}

.user-profile-trigger:hover .user-email,
.user-profile-trigger:hover .user-menu-icon {
    color: var(--accent-cyan);
}

.user-dropdown {
    position: absolute;
    top: 100%;
    right: 0;
    margin-top: 15px;
    background: rgba(10, 31, 46, 0.98);
    backdrop-filter: blur(15px);
    border: 1px solid rgba(48, 213, 237, 0.15);
    border-radius: 28px;
    padding: 20px;
    box-shadow: 0 10px 40px rgba(0, 0, 0, 0.8);
    z-index: 100;
    width: 320px;
    min-height: 260px;
    display: flex;
    flex-direction: column;
    cursor: default;
}

.dropdown-header {
    display: flex;
    flex-direction: column;
    align-items: center;
    margin-top: 15px;
}

.dropdown-avatar {
    width: 70px;
    height: 70px;
    background: rgba(48, 213, 237, 0.08);
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    margin-bottom: 15px;
    color: var(--accent-cyan);
}

.dropdown-avatar svg {
    width: 35px;
    height: 35px;
}

.dropdown-email-large {
    color: var(--text-white);
    font-size: 15px;
    font-weight: 700;
    text-align: center;
    word-break: break-all;
}

.btn-logout {
    width: 100%;
    background: rgba(255, 255, 255, 0.03);
    color: var(--text-gray);
    border: 1px solid rgba(255, 255, 255, 0.05);
    padding: 14px 15px;
    border-radius: 14px;
    font-weight: 700;
    font-size: 13px;
    cursor: pointer;
    transition: 0.3s;
    text-align: center;
    margin-top: auto;
}

.btn-logout:hover {
    background: rgba(255, 77, 77, 0.1);
    color: var(--accent-red);
    border-color: rgba(255, 77, 77, 0.3);
}

/* --- READONLY MODE --- */
body.readonly-mode .js-edit-btn,
body.readonly-mode .js-delete-card,
body.readonly-mode .js-add-acc-btn,
body.readonly-mode .js-delete-acc,
body.readonly-mode .js-gen-pass,
body.readonly-mode #addServiceBtn {
    display: none !important;
}

.readonly-badge {
    color: #9ca3af;
    font-size: 0.95rem;
    font-weight: 700;
    cursor: pointer;
    user-select: none;
    transition: color 0.2s;
    margin-left: 20px;
}

.readonly-badge:hover {
    color: #d1d5db;
}