/* === Reset & Base === */
*, *::before, *::after {
    box-sizing: border-box;
}

:root {
    --primary: #7357FB;
    --primary-hover: #5e45d1;
    --primary-light: #ece8ff;
    --bg: #F0F2F5;
    --card-bg: #FFFFFF;
    --text: #1F2937;
    --text-muted: #6B7280;
    --border: #E5E7EB;
    --danger: #EF4444;
    --danger-bg: #FEF2F2;
    --danger-border: #FCA5A5;
    --success: #10B981;
    --shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.05), 0 2px 4px -1px rgba(0, 0, 0, 0.03);
    --shadow-hover: 0 10px 15px -3px rgba(0, 0, 0, 0.08), 0 4px 6px -2px rgba(0, 0, 0, 0.04);
}

body {
    font-family: 'Inter', sans-serif;
    background-color: var(--bg);
    margin: 0;
    padding: 0;
    color: var(--text);
    overflow-x: hidden;
    -webkit-font-smoothing: antialiased;
}

/* === Login Page === */
.login-bg {
    display: flex;
    justify-content: center;
    align-items: center;
    min-height: 100vh;
    background-color: #F3F4F6;
    padding: 20px;
}

.login-container {
    background: white;
    padding: 40px;
    border-radius: 16px;
    box-shadow: var(--shadow-hover);
    width: 100%;
    max-width: 400px;
    text-align: center;
}

.logo-area {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 12px;
    margin-bottom: 8px;
}

.logo-badge {
    background: var(--primary);
    color: white;
    font-weight: 700;
    padding: 6px 10px;
    border-radius: 8px;
    font-size: 13px;
    box-shadow: 0 4px 6px rgba(115, 87, 251, 0.3);
}
.logo-badge.sm { font-size: 11px; padding: 3px 8px; border-radius: 6px; }

h1 { font-size: 26px; margin: 0; font-weight: 700; letter-spacing: -0.5px; color: #111; }
.ai-badge { color: var(--primary); }
.subtitle { color: var(--text-muted); font-size: 15px; margin-bottom: 32px; }

.login-form label {
    display: block;
    text-align: left;
    font-size: 14px;
    font-weight: 500;
    color: #374151;
    margin-bottom: 8px;
}

.input-wrapper { margin-bottom: 24px; }

/* ОБНОВЛЕНО: Фиксированная высота для всех инпутов (кроме checkbox/radio/file) */
input:not([type="checkbox"]):not([type="radio"]):not([type="file"]),
select,
textarea {
    width: 100%;
    padding: 10px 16px;
    border: 1px solid var(--border);
    border-radius: 8px;
    font-size: 15px;
    font-family: inherit;
    background: #FAFAFA;
    transition: all 0.2s ease;
    color: var(--text);
    min-height: 46px; /* Фиксируем высоту */
}

textarea { min-height: 80px; } /* Исключение для текстового поля */

input:focus, select:focus, textarea:focus {
    border-color: var(--primary);
    background: #fff;
    outline: none;
    box-shadow: 0 0 0 3px rgba(115, 87, 251, 0.1);
}

/* ОБНОВЛЕНО: нормальный вид и центровка checkbox (убираем влияние общих input-стилей) */
input[type="checkbox"]{
    width: 16px;
    height: 16px;
    margin: 0;
    padding: 0;
    border: none;
    background: transparent;
    box-shadow: none;
    cursor: pointer;
    flex-shrink: 0;
    accent-color: var(--primary);
}

.btn-primary {
    background: var(--primary);
    color: white;
    border: none;
    width: 100%;
    padding: 14px;
    border-radius: 10px;
    font-weight: 600;
    cursor: pointer;
    font-size: 16px;
    transition: background 0.2s, transform 0.1s;
}
.btn-primary:hover { background: var(--primary-hover); transform: translateY(-1px); }
.btn-primary:active { transform: translateY(0); }

.error-msg { color: var(--danger); font-size: 14px; margin-bottom: 20px; background: var(--danger-bg); padding: 10px; border-radius: 8px; border: 1px solid var(--danger-border); }

/* === Dashboard === */
.navbar {
    background: white;
    border-bottom: 1px solid var(--border);
    padding: 16px 0;
    position: sticky;
    top: 0;
    z-index: 50;
    box-shadow: 0 1px 2px 0 rgba(0, 0, 0, 0.03);
}
.nav-content { display: flex; justify-content: space-between; align-items: center; }
.brand { display: flex; align-items: center; gap: 10px; font-weight: 700; font-size: 20px; letter-spacing: -0.5px;}
.user-menu { display: flex; gap: 16px; align-items: center; font-size: 14px; font-weight: 500; color: var(--text-muted); }
.user-menu i { color: var(--primary); }
.btn-logout { color: var(--text-muted); transition: 0.2s; font-size: 16px; }
.btn-logout:hover { color: var(--danger); }

.container { width: 92%; max-width: 1280px; margin: 0 auto; }
.main-content { padding-top: 40px; padding-bottom: 60px; }

.header-actions {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 30px;
}
.header-actions h2 { font-size: 24px; font-weight: 700; margin: 0; }
.header-actions .btn-primary { width: auto; padding: 10px 24px; font-size: 14px; }

/* Filter Bar */
.filter-bar {
    display: flex;
    gap: 12px;
    margin-bottom: 30px;
    overflow-x: auto;
    padding-bottom: 8px;
    scrollbar-width: thin;
    scrollbar-color: var(--border) transparent;
}
.filter-pill {
    background: white;
    border: 1px solid var(--border);
    padding: 8px 16px;
    border-radius: 50px;
    font-size: 13px;
    font-weight: 500;
    color: var(--text-muted);
    cursor: pointer;
    white-space: nowrap;
    transition: all 0.2s;
    user-select: none;
}
.filter-pill:hover { border-color: var(--primary); color: var(--primary); background: var(--primary-light); }
.filter-pill.active {
    background: var(--primary);
    color: white;
    border-color: var(--primary);
    box-shadow: 0 2px 5px rgba(115, 87, 251, 0.3);
}

/* Grid */
.access-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(320px, 1fr));
    gap: 24px;
}

.access-card {
    background: var(--card-bg);
    border-radius: 16px;
    padding: 24px;
    box-shadow: var(--shadow);
    border: 1px solid transparent;
    transition: all 0.3s ease;
    display: flex;
    flex-direction: column;
    position: relative;
    overflow: hidden;
}

.access-card:hover { transform: translateY(-4px); box-shadow: var(--shadow-hover); border-color: rgba(115, 87, 251, 0.2); }

.access-card.expiring { border: 1px solid var(--danger-border); box-shadow: 0 0 0 1px var(--danger-border); }
.access-card.expiring::before {
    content: ''; position: absolute; top: 0; left: 0; width: 4px; height: 100%; background: var(--danger);
}

.card-header {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    margin-bottom: 20px;
}
.card-icon-area {
    display: flex;
    gap: 16px;
    align-items: center;
    flex: 1;
    min-width: 0;
}
.card-icon {
    width: 48px;
    height: 48px;
    object-fit: contain;
    border-radius: 12px;
    background: #F8FAFC;
    padding: 6px;
    box-sizing: border-box;
    flex-shrink: 0;
    border: 1px solid #F1F5F9;
}
.card-title-wrap { flex: 1; min-width: 0; }
.card-title-wrap h3 {
    margin: 0 0 6px 0;
    font-size: 18px;
    font-weight: 700;
    color: var(--text);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    line-height: 1.2;
    cursor: default;
}

.card-actions {
    display: flex;
    gap: 4px;
    opacity: 0;
    transition: opacity 0.2s;
    margin-left: 8px;
    z-index: 2;
}
.access-card:hover .card-actions { opacity: 1; }
.action-btn {
    background: transparent;
    border: none;
    cursor: pointer;
    color: #9CA3AF;
    padding: 6px;
    border-radius: 6px;
    font-size: 15px;
    transition: 0.2s;
}
.action-btn:hover { background: #F3F4F6; color: var(--primary); }
.action-btn.del:hover { background: #FEF2F2; color: var(--danger); }

.card-tags { display: flex; flex-wrap: wrap; gap: 6px; }
.tag {
    font-size: 11px;
    font-weight: 600;
    color: var(--primary);
    background: var(--primary-light);
    padding: 4px 10px;
    border-radius: 20px;
    cursor: pointer;
    transition: 0.2s;
}
.tag:hover { background: var(--primary); color: white; }

.card-body { flex-grow: 1; display: flex; flex-direction: column; }

.card-link-btn {
    display: flex;
    justify-content: center;
    align-items: center;
    gap: 8px;
    width: 100%;
    padding: 10px;
    background: #F5F3FF;
    color: var(--primary);
    text-decoration: none;
    border-radius: 8px;
    font-weight: 600;
    font-size: 14px;
    margin-bottom: 20px;
    transition: 0.2s;
    border: 1px solid rgba(115, 87, 251, 0.1);
    box-sizing: border-box;
}
.card-link-btn:hover { background: var(--primary); color: white; }

.credentials-group {
    background: #FAFAFA;
    border-radius: 8px;
    padding: 4px 12px;
    border: 1px solid #F1F5F9;
}
.field-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 10px 0;
    border-bottom: 1px solid #E5E7EB;
}
.field-row:last-child { border-bottom: none; }
.field-label { color: var(--text-muted); font-size: 12px; font-weight: 500; text-transform: uppercase; letter-spacing: 0.5px; }
.field-val-container { display: flex; align-items: center; gap: 8px; }
.field-val {
    font-family: 'Monaco', 'Consolas', monospace;
    font-size: 13px;
    color: var(--text);
    font-weight: 600;
    max-width: 140px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}
.copy-btn { cursor: pointer; color: #9CA3AF; font-size: 14px; padding: 4px; transition: 0.2s; }
.copy-btn:hover { color: var(--primary); transform: scale(1.1); }

/* === Комментарий в карточке: 1 строка + разворот === */
.card-comment {
    margin-top: 16px;
    background: #FFFBEB;
    border: 1px solid #FEF3C7;
    color: #92400E;
    padding: 12px;
    border-radius: 8px;
    font-size: 13px;
    line-height: 1.5;
    display: flex;
    gap: 10px;
    align-items: flex-start;
}

/* Только иконка "комментарий" слева */
.card-comment > i {
    margin-top: 3px;
    opacity: 0.7;
    flex-shrink: 0;
}

.comment-content {
    flex: 1;
    min-width: 0; /* важно для ellipsis внутри flex */
}

.comment-collapsed {
    display: block;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.comment-expanded {
    display: none;
    white-space: normal;
    word-break: break-word;
}

/* Кнопка разворота справа */
.comment-toggle {
    display: none; /* включаем только если реально нужно */
    background: transparent;
    border: none;
    cursor: pointer;
    color: #9CA3AF;
    padding: 4px;
    border-radius: 6px;
    transition: 0.2s;
    flex-shrink: 0;
    align-self: flex-start;
    line-height: 1;
}

.comment-toggle:hover { background: rgba(0,0,0,0.06); color: var(--primary); }

/* показываем кнопку только если нужно */
.card-comment.has-toggle .comment-toggle { display: inline-flex; }

/* разворот/сворачивание */
.card-comment.expanded .comment-collapsed { display: none; }
.card-comment.expanded .comment-expanded { display: block; }
.card-comment.expanded .comment-toggle i { transform: rotate(180deg); }
.comment-toggle i { transition: transform 0.2s ease; }

.card-expiry-section {
    margin-top: 20px;
    padding-top: 12px;
    border-top: 1px dashed var(--border);
    display: flex;
    justify-content: flex-end;
}

.expiry-badge {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 6px 12px;
    border-radius: 6px;
    font-size: 12px;
    font-weight: 600;
}
.expiry-badge.normal { color: var(--text-muted); background: #F3F4F6; }
.expiry-badge.lifetime { color: var(--success); background: #ECFDF5; }
.expiry-badge.expiring { color: #B91C1C; background: #FEF2F2; border: 1px solid #FECACA; animation: pulse 2s infinite; }
.expiry-badge.expired { color: white; background: var(--text-muted); }

@keyframes pulse {
    0% { box-shadow: 0 0 0 0 rgba(239, 68, 68, 0.4); }
    70% { box-shadow: 0 0 0 6px rgba(239, 68, 68, 0); }
    100% { box-shadow: 0 0 0 0 rgba(239, 68, 68, 0); }
}

/* === MODAL STYLES === */
/* ОБНОВЛЕНО: центрирование модалки по вертикали */
.modal {
    display: none;
    position: fixed;
    z-index: 1000;
    left: 0;
    top: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(0,0,0,0.5);
    backdrop-filter: blur(2px);

    /* центр */
    justify-content: center;
    align-items: center;

    /* отступы от краёв */
    padding: 40px 20px;
}

/* ОБНОВЛЕНО: чтобы модалка не вылезала за экран — скролл внутри контента */
.modal-content {
    background-color: #fefefe;
    margin: 0;
    padding: 30px;
    border: none;
    width: 90%;
    max-width: 700px;
    border-radius: 16px;
    box-shadow: 0 25px 50px -12px rgba(0, 0, 0, 0.25);
    position: relative;

    max-height: calc(100vh - 80px);
    overflow-y: auto;

    /* чтобы sticky-close работал корректно */
    display: flex;
    flex-direction: column;
}

/* ОБНОВЛЕНО: close теперь sticky (всегда доступен при скролле внутри модалки) */
.close {
    position: sticky;
    top: 10px;
    align-self: flex-end;

    font-size: 28px;
    cursor: pointer;
    color: #9CA3AF;
    transition: 0.2s;
    line-height: 1;
    z-index: 10;
}
.close:hover { color: var(--danger); transform: rotate(90deg); }

.modal-header h3 { margin: 0 0 25px 0; font-size: 22px; font-weight: 700; color: #111; }

.row { display: flex; gap: 20px; }
.col { flex: 1; min-width: 0; }
.flex-2 { flex: 2; }
.flex-1 { flex: 1; }

.form-group { margin-bottom: 20px; }
.form-group label { display: block; margin-bottom: 8px; font-weight: 600; font-size: 13px; color: #4B5563; }
.modal-footer { display: flex; justify-content: flex-end; gap: 10px; margin-top: 30px; }
.btn-secondary { background: #F3F4F6; color: var(--text); border: none; padding: 12px 24px; border-radius: 8px; cursor: pointer; font-weight: 600; transition: 0.2s;}
.btn-secondary:hover { background: #E5E7EB; }

/* === Исправление выравнивания даты и галочки === */
.date-input-group {
    display: flex;
    gap: 15px;
    align-items: center; /* Выравнивание по центру */
}
.date-input-group input[type="date"] {
    flex: 1;
    min-height: 46px; /* Такая же высота */
}

.checkbox-wrapper {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 13px;
    white-space: nowrap;
    cursor: pointer;
    background: #F9FAFB;
    padding: 0 15px;
    border: 1px solid var(--border);
    border-radius: 8px;
    height: 46px; /* Такая же высота как у инпута */
    box-sizing: border-box;
    min-height: 46px;
    line-height: 1; /* ОБНОВЛЕНО: чтобы текст не "плавал" по вертикали */
}

/* Icon selector inside modal */
.icon-selector { display: flex; flex-direction: column; gap: 10px; border: 1px dashed var(--border); padding: 15px; border-radius: 8px; background: #F9FAFB; }
.existing-icons { display: flex; gap: 10px; overflow-x: auto; padding-bottom: 5px; }
.selectable-icon { width: 36px; height: 36px; cursor: pointer; border: 2px solid transparent; border-radius: 6px; object-fit: contain; background: white; padding: 2px; }
.selectable-icon:hover { border-color: var(--primary); }
.selectable-icon.selected { border-color: var(--primary); background: #ece8ff; }
.btn-outline { background: white; border: 1px solid var(--border); padding: 8px 12px; border-radius: 6px; cursor: pointer; font-size: 13px; font-weight: 500; transition: 0.2s;}
.btn-outline:hover { border-color: var(--primary); color: var(--primary); }
.upload-btn-wrapper { position: relative; overflow: hidden; display: inline-block; }
.upload-btn-wrapper input[type=file] { position: absolute; left: 0; top: 0; opacity: 0; width: 100%; height: 100%; cursor: pointer; }
.or-divider { font-size: 12px; text-align: center; color: #9CA3AF; }
.icon-preview-box { margin-top: 5px; font-size: 13px; display: flex; align-items: center; gap: 10px; background: #ECFDF5; padding: 10px; border-radius: 6px; color: #047857;}
.icon-preview-box img { width: 30px; height: 30px; object-fit: contain; }
.remove-icon { cursor: pointer; color: #EF4444; font-size: 18px; font-weight: bold; margin-left: auto; }

/* Toast */
#toast {
    visibility: hidden;
    min-width: 200px;
    background-color: var(--text);
    color: #fff;
    text-align: center;
    border-radius: 50px;
    padding: 12px 24px;
    position: fixed;
    z-index: 2000;
    left: 50%;
    bottom: 30px;
    transform: translateX(-50%);
    font-size: 14px;
    font-weight: 500;
    box-shadow: 0 10px 15px -3px rgba(0,0,0,0.1);
}
#toast.show { visibility: visible; animation: fadein 0.5s, fadeout 0.5s 2.5s; }

@media (max-width: 650px) {
    .row { flex-direction: column; gap: 0; }
    .col, .flex-2, .flex-1 { width: 100%; }
    .modal-content { width: 95%; padding: 20px; }
    .close { top: 8px; }
}
