/* ========================================
   ROOT VARIABLES (Nord Theme)
   ======================================== */
:root {
    --nord0: #2e3440;
    --nord1: #3b4252;
    --nord2: #434c5e;
    --nord3: #4c566a;
    --nord4: #d8dee9;
    --nord5: #e5e9f0;
    --nord6: #eceff4;
    --nord7: #8fbcbb;
    --nord8: #88c0d0;
    --nord9: #81a1c1;
    --nord10: #5e81ac;
    --nord11: #bf616a;
    --nord12: #d08770;
    --nord13: #ebcb8b;
    --nord14: #a3be8c;
    --nord15: #b48ead;
}

/* ========================================
   RESET & BASE
   ======================================== */
* { margin: 0; padding: 0; box-sizing: border-box; }

body {
    font-family: system-ui, -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
    background: linear-gradient(135deg, var(--nord0) 0%, var(--nord1) 100%);
    min-height: 100vh;
    color: var(--nord4);
    padding: 20px;
}

.app-container { max-width: 1400px; margin: 0 auto; }

/* ========================================
   LOGIN PAGE
   ======================================== */
.login-page {
    display: flex;
    justify-content: center;
    align-items: center;
    min-height: 85vh;
}
.form-container {
    width: 100%;
    max-width: 400px;
    border-radius: 1rem;
    background-color: var(--nord1);
    padding: 2rem;
    color: var(--nord4);
    box-shadow: 0 25px 45px rgba(0,0,0,0.3);
    border: 1px solid var(--nord3);
}
.logo-header {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.75rem;
    margin-bottom: 1.5rem;
}
.logo-icon-large { width: 36px; height: 36px; color: var(--nord8); }
.logo-text-large {
    font-size: 1.8rem;
    font-weight: 700;
    background: linear-gradient(135deg, var(--nord8), var(--nord7));
    -webkit-background-clip: text;
    background-clip: text;
    color: transparent;
}
.input-group { margin-bottom: 1.2rem; }
.input-group label {
    display: block;
    color: var(--nord4);
    opacity: 0.8;
    margin-bottom: 0.3rem;
    font-size: 0.85rem;
}
.input-group input {
    width: 100%;
    border-radius: 0.5rem;
    border: 1px solid var(--nord3);
    outline: 0;
    background-color: var(--nord0);
    padding: 0.7rem 1rem;
    color: var(--nord5);
    font-size: 0.9rem;
    transition: all 0.3s ease;
}
.input-group input:focus {
    border-color: var(--nord8);
    box-shadow: 0 0 0 2px rgba(136,192,208,0.3);
}
.sign {
    display: block;
    width: 100%;
    background: linear-gradient(135deg, var(--nord8), var(--nord7));
    padding: 0.7rem;
    text-align: center;
    color: var(--nord0);
    border: none;
    border-radius: 0.5rem;
    font-weight: 600;
    font-size: 1rem;
    cursor: pointer;
    transition: all 0.3s ease;
}
.sign:hover { transform: translateY(-2px); filter: brightness(1.05); box-shadow: 0 4px 12px rgba(0,0,0,0.2); }
.error-message {
    background: rgba(191,97,106,0.1);
    border: 1px solid var(--nord11);
    color: var(--nord11);
    padding: 0.7rem;
    border-radius: 0.5rem;
    margin-top: 1rem;
    text-align: center;
    font-size: 0.85rem;
}

/* ========================================
   MAIN INTERFACE
   ======================================== */
.main-interface { animation: fadeIn 0.5s ease-out; }
@keyframes fadeIn {
    from { opacity: 0; transform: translateY(10px); }
    to { opacity: 1; transform: translateY(0); }
}

/* ========================================
   TOP BAR
   ======================================== */
.top-bar {
    background: var(--nord1);
    border-radius: 1rem;
    padding: 1rem 1.5rem;
    margin-bottom: 1.5rem;
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-wrap: wrap;
    gap: 1rem;
    border: 1px solid var(--nord3);
    box-shadow: 0 4px 6px rgba(0,0,0,0.1);
}
.logo-area {
    display: flex;
    align-items: center;
    gap: 0.75rem;
}
.logo-icon { width: 32px; height: 32px; color: var(--nord8); }
.logo-text h1 {
    color: var(--nord8);
    font-size: 1.5rem;
    margin-bottom: 0.2rem;
}
.logo-text .subtitle {
    color: var(--nord4);
    opacity: 0.8;
    text-align: left;
    margin-bottom: 0;
    font-size: 0.75rem;
}
.search-group {
    flex: 1;
    max-width: 400px;
    margin: 0 1rem;
}
.search-wrapper { position: relative; width: 100%; }
.search-input {
    width: 100%;
    height: 42px;
    padding: 0 1rem 0 2.5rem;
    border: 1px solid var(--nord3);
    border-radius: 0.5rem;
    outline: none;
    background-color: var(--nord0);
    color: var(--nord4);
    font-size: 0.9rem;
}
.search-input:focus {
    border-color: var(--nord8);
    box-shadow: 0 0 0 2px rgba(136,192,208,0.2);
}
.search-icon {
    position: absolute;
    left: 0.8rem;
    top: 50%;
    transform: translateY(-50%);
    width: 1rem;
    height: 1rem;
    fill: var(--nord3);
}
.stats-group {
    display: flex;
    gap: 0.5rem;
}
.stat-card {
    background: var(--nord0);
    border-radius: 0.5rem;
    padding: 0.4rem 0.8rem;
    display: flex;
    align-items: center;
    gap: 0.5rem;
    border: 1px solid var(--nord3);
    height: 38px;
}
.stat-icon { width: 18px; height: 18px; color: var(--nord8); }
.stat-icon-green { color: var(--nord14); }
.stat-info { display: flex; gap: 0.25rem; align-items: baseline; }
.stat-value { font-size: 1rem; font-weight: 600; color: var(--nord4); }
.stat-label { font-size: 0.7rem; color: var(--nord3); }
.action-buttons {
    display: flex;
    gap: 0.5rem;
}
.btn-action {
    background: linear-gradient(135deg, var(--nord10), var(--nord9));
    color: var(--nord6);
    padding: 0.5rem 1rem;
    border-radius: 0.5rem;
    font-size: 0.85rem;
    font-weight: 500;
    cursor: pointer;
    text-decoration: none;
    display: inline-flex;
    align-items: center;
    gap: 0.4rem;
    border: none;
    transition: all 0.2s;
}
.btn-action:hover { transform: translateY(-2px); filter: brightness(1.1); }
.btn-icon-only { padding: 0.5rem; min-width: 38px; justify-content: center; }

/* ========================================
   TWO-COLUMN LAYOUT (Sections + Cards)
   ======================================== */
.main-layout {
    display: flex;
    gap: 1.5rem;
}

/* ========================================
   SECTIONS SIDEBAR
   ======================================== */
.sections-sidebar {
    width: 240px;
    flex-shrink: 0;
    background: var(--nord1);
    border-radius: 1rem;
    border: 1px solid var(--nord3);
    overflow: hidden;
    align-self: flex-start;
    position: sticky;
    top: 20px;
}
.sections-header {
    padding: 0.8rem 1rem;
    background: var(--nord1);
    border-bottom: 1px solid var(--nord3);
    display: flex;
    align-items: center;
    gap: 0.5rem;
    font-weight: 600;
    color: var(--nord8);
    font-size: 0.85rem;
}
.sections-list {
    padding: 0.5rem;
    display: flex;
    flex-direction: column;
    gap: 0.2rem;
    max-height: calc(100vh - 200px);
    overflow-y: auto;
}
.section-item {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.5rem 0.8rem;
    border-radius: 0.5rem;
    text-decoration: none;
    color: var(--nord4);
    font-size: 0.85rem;
    transition: all 0.2s;
}
.section-item:hover { background: var(--nord2); }
.section-item.active {
    background: linear-gradient(135deg, var(--nord10), var(--nord9));
    color: var(--nord6);
}
.section-child { padding-left: 2rem; }
.section-icon {
    width: 14px;
    height: 14px;
    min-width: 14px;
    flex-shrink: 0;
    color: var(--nord8);
}
.section-icon-home {
    width: 16px;
    height: 16px;
    min-width: 16px;
    flex-shrink: 0;
    color: var(--nord8);
}
.section-icon-unassigned {
    width: 16px;
    height: 16px;
    min-width: 16px;
    flex-shrink: 0;
    color: var(--nord8);
}
.section-item.active .section-icon-home,
.section-item.active .section-icon-unassigned {
    color: var(--nord6);
}
.section-item:hover .section-icon-home,
.section-item:hover .section-icon-unassigned {
    color: var(--nord6);
}
.section-name { flex: 1; }
.add-section-btn {
    margin: 0.5rem;
    padding: 0.5rem;
    background: var(--nord2);
    border: 1px solid var(--nord3);
    border-radius: 0.5rem;
    color: var(--nord8);
    font-size: 0.8rem;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.3rem;
    transition: all 0.2s;
    width: calc(100% - 1rem);
}
.add-section-btn:hover { background: var(--nord3); }

.sections-actions {
    display: flex;
    justify-content: flex-end;
    gap: 0.5rem;
    padding: 0.5rem;
    border-top: 1px solid var(--nord3);
    margin-top: 0.5rem;
}
.section-action-btn {
    background: var(--nord2);
    border: 1px solid var(--nord3);
    border-radius: 0.5rem;
    color: var(--nord8);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.3rem;
    transition: all 0.2s;
    width: 36px;
    height: 36px;
}
.section-action-btn:hover {
    background: var(--nord3);
    color: var(--nord6);
    transform: translateY(-1px);
}

/* ========================================
   CLIENTS GRID
   ======================================== */
.clients-area { flex: 1; min-width: 0; }
.clients-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(320px, 1fr));
    gap: 1rem;
    justify-items: center;
}

/* ========================================
   CARD STYLES
   ======================================== */
.card {
    display: flex;
    flex-direction: column;
    border-radius: 1rem;
    overflow: hidden;
    background-color: var(--nord1);
    box-shadow: 0 4px 6px rgba(0,0,0,0.1);
    transition: all 0.3s ease;
    border: 1px solid var(--nord3);
    width: 100%;
    max-width: 320px;
    min-height: 280px;
    height: auto;
}
.card:hover {
    transform: translateY(-4px);
    border-color: var(--nord8);
}
.card-header-gradient {
    background: linear-gradient(135deg, var(--nord10) 0%, var(--nord9) 100%);
    padding: 0.6rem 0.8rem;
    display: flex;
    justify-content: space-between;
    align-items: center;
}
.card-header-left {
    display: flex;
    flex-direction: column;
    gap: 0.2rem;
}
.card-header-right {
    display: flex;
    align-items: center;
    gap: 0.5rem;
}
.rustdesk-info { display: flex; flex-direction: column; }
.rustdesk-id-label {
    font-size: 0.55rem;
    text-transform: uppercase;
    color: rgba(0,0,0,0.6);
}
.rustdesk-id-value {
    font-size: 1rem;
    font-family: monospace;
    color: var(--nord6);
    font-weight: 700;
}
.client-type-badge {
    font-size: 1.2rem;
    line-height: 1;
    margin-top: 2px;
}
.online-status-dot { position: relative; }
.status-dot-circle {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    display: inline-block;
}
.status-dot-circle.online {
    background-color: var(--nord14);
    box-shadow: 0 0 4px var(--nord14);
    animation: pulse 2s infinite;
}
.status-dot-circle.offline { background-color: var(--nord11); }
@keyframes pulse {
    0% { box-shadow: 0 0 0 0 rgba(163,190,140,0.4); }
    70% { box-shadow: 0 0 0 4px rgba(163,190,140,0); }
    100% { box-shadow: 0 0 0 0 rgba(163,190,140,0); }
}

.pin-btn {
    color: var(--nord6);
    transition: transform 0.2s;
    display: inline-flex;
}
.pin-btn:hover { transform: scale(1.2); }

.card-content {
    padding: 0.6rem;
    display: flex;
    flex-direction: column;
    gap: 0.4rem;
    flex: 1;
}
.card-header-actions {
    display: flex;
    align-items: flex-start;
    gap: 0.5rem;
    flex-wrap: wrap;
}
.client-avatar {
    flex-shrink: 0;
    width: 40px;
    height: 40px;
    border-radius: 50%;
    overflow: hidden;
    background: var(--nord2);
    display: flex;
    align-items: center;
    justify-content: center;
}
.avatar-img { width: 100%; height: 100%; object-fit: cover; }
.avatar-placeholder { width: 100%; height: 100%; color: var(--nord8); }
.client-name {
    font-size: 1rem;
    font-weight: 700;
    color: var(--nord4);
    word-break: break-word;
    flex: 1;
}
.action-icons {
    display: flex;
    gap: 0.2rem;
    flex-wrap: wrap;
}
.quick-action-btn,
.icon-btn {
    text-decoration: none;
    width: 24px;
    height: 24px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    border-radius: 0.3rem;
    color: var(--nord4);
    transition: all 0.2s;
}
.quick-action-btn:hover,
.icon-btn:hover {
    background: var(--nord2);
    color: var(--nord6);
}
.edit-btn:hover { color: var(--nord14); }
.delete-btn:hover { color: var(--nord11); }
.active-toggle { color: var(--nord14); }
.inactive-toggle { color: var(--nord11); }

.client-details {
    display: flex;
    flex-direction: column;
    gap: 0.3rem;
    flex: 1;
}
.detail-item {
    display: flex;
    align-items: center;
    gap: 0.3rem;
    font-size: 0.8rem;
}
.detail-icon {
    width: 14px;
    height: 14px;
    flex-shrink: 0;
    color: var(--nord8);
}
.detail-text { word-break: break-word; }
.notes-item { align-items: flex-start; }

/* Теги */
.tags-container {
    display: flex;
    flex-wrap: wrap;
    gap: 0.3rem;
    margin-bottom: 0.2rem;
}
.tag {
    display: inline-block;
    padding: 0.1rem 0.5rem;
    border-radius: 1rem;
    font-size: 0.65rem;
    font-weight: 500;
    text-transform: lowercase;
}
.tag-частый { background: #5e81ac; color: #eceff4; }
.tag-важный { background: #bf616a; color: #eceff4; }
.tag-избранный { background: #b48ead; color: #eceff4; }
.tag-тестовый { background: #d08770; color: #eceff4; }
.tag-в_работе { background: #a3be8c; color: #2e3440; }

/* Контакты */
.contact-info {
    display: flex;
    flex-wrap: wrap;
    gap: 0.3rem 0.6rem;
    font-size: 0.7rem;
    color: var(--nord4);
    margin-top: 0.2rem;
}
.contact-item {
    display: inline-flex;
    align-items: center;
    gap: 0.2rem;
    background: var(--nord0);
    padding: 0.05rem 0.4rem;
    border-radius: 0.3rem;
}

/* Кнопка подключения */
.connect-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.3rem;
    background: linear-gradient(135deg, var(--nord8), var(--nord7));
    text-decoration: none;
    padding: 0.4rem;
    border-radius: 0.4rem;
    font-weight: 600;
    color: var(--nord0);
    font-size: 0.75rem;
    transition: all 0.2s;
}
.connect-btn:hover { transform: translateY(-1px); filter: brightness(1.05); }
.connect-icon { width: 10px; height: 10px; }

/* Мета-информация */
.card-meta {
    display: flex;
    justify-content: space-between;
    font-size: 0.55rem;
    color: var(--nord8);
    padding-top: 0.3rem;
    margin-top: 0.2rem;
    border-top: 1px solid var(--nord2);
    flex-wrap: wrap;
    gap: 0.2rem;
}
.meta-icon {
    width: 8px;
    height: 8px;
    vertical-align: middle;
    margin-right: 0.15rem;
    color: var(--nord8);
}
.meta-item {
    display: inline-flex;
    align-items: center;
    gap: 0.15rem;
}

/* Обнаруженные устройства */
.discovered-card { border: 2px solid var(--nord14); }
.add-from-discovered {
    background: var(--nord2);
    border-radius: 0.5rem;
    padding: 0.3rem;
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--nord14);
    transition: all 0.2s;
}
.add-from-discovered:hover {
    background: var(--nord3);
    transform: scale(1.05);
}

/* Пустое состояние */
.empty-state {
    text-align: center;
    padding: 2rem;
    background: var(--nord1);
    border-radius: 1rem;
    border: 1px solid var(--nord3);
}
.empty-icon { font-size: 2.5rem; margin-bottom: 0.8rem; }

/* ========================================
   MODAL WINDOWS (Add/Edit, Settings, 2FA)
   ======================================== */
.modal-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0,0,0,0.7);
    backdrop-filter: blur(4px);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1000;
}
.modal-container {
    background: var(--nord1);
    border-radius: 1rem;
    max-width: 600px;
    width: 90%;
    border: 1px solid var(--nord3);
    max-height: 90vh;
    overflow-y: auto;
}
.modal-header {
    background: linear-gradient(135deg, var(--nord10), var(--nord9));
    padding: 1rem 1.5rem;
    display: flex;
    justify-content: space-between;
    align-items: center;
}
.modal-header h2 { color: var(--nord6); font-size: 1.2rem; }
.modal-form { padding: 1.2rem; }
.form-group { margin-bottom: 1rem; }
.form-group label {
    display: block;
    color: var(--nord4);
    margin-bottom: 0.3rem;
    font-size: 0.8rem;
}
.form-group input,
.form-group select,
.form-group textarea {
    width: 100%;
    padding: 0.5rem;
    border: 1px solid var(--nord3);
    border-radius: 0.5rem;
    background: var(--nord0);
    color: var(--nord4);
    font-size: 0.85rem;
    font-family: inherit;
}
.form-group input:focus,
.form-group select:focus,
.form-group textarea:focus {
    outline: none;
    border-color: var(--nord8);
    box-shadow: 0 0 0 2px rgba(136,192,208,0.2);
}
.form-group textarea { resize: vertical; }
.field-hint.small {
    font-size: 0.65rem;
    color: var(--nord3);
    margin-top: 0.2rem;
    font-style: italic;
}
.form-row.two-columns {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 0.8rem;
    margin-bottom: 0.8rem;
}
.form-row.two-columns .form-group { margin-bottom: 0; }
.form-group.full-width { grid-column: span 2; }

/* Чекбоксы тегов */
.tags-checkboxes {
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem 1rem;
    padding: 0.3rem 0;
}
.tags-checkboxes label {
    display: inline-flex;
    align-items: center;
    gap: 0.3rem;
    font-size: 0.8rem;
    color: var(--nord4);
    cursor: pointer;
}
.tags-checkboxes input[type="checkbox"] {
    width: auto;
    accent-color: var(--nord8);
}

/* Кнопки форм */
.form-actions {
    display: flex;
    gap: 1rem;
    margin-top: 1rem;
}
.btn-save,
.btn-cancel {
    flex: 1;
    padding: 0.5rem;
    border-radius: 0.5rem;
    font-size: 0.85rem;
    font-weight: 600;
    cursor: pointer;
    border: none;
    text-align: center;
    text-decoration: none;
}
.btn-save {
    background: linear-gradient(135deg, var(--nord14), var(--nord7));
    color: var(--nord0);
}
.btn-cancel {
    background: var(--nord2);
    color: var(--nord4);
}
.btn-save:hover, .btn-cancel:hover { transform: translateY(-2px); }

/* ========================================
   SETTINGS PAGE (специфичные стили)
   ======================================== */
.settings-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 1rem;
}
@media (max-width: 768px) { .settings-grid { grid-template-columns: 1fr; } }

/* ========================================
   TOAST NOTIFICATION
   ======================================== */
.custom-toast {
    position: fixed;
    bottom: 30px;
    left: 50%;
    transform: translateX(-50%) translateY(100px);
    background: var(--nord1);
    color: var(--nord4);
    padding: 10px 20px;
    border-radius: 0.5rem;
    font-size: 0.85rem;
    z-index: 1000;
    opacity: 0;
    transition: all 0.3s ease;
    border: 1px solid var(--nord3);
    white-space: nowrap;
}
.custom-toast.show {
    opacity: 1;
    transform: translateX(-50%) translateY(0);
}

/* ========================================
   RESPONSIVE
   ======================================== */
@media (max-width: 1200px) {
    .clients-grid { grid-template-columns: repeat(3, 1fr); gap: 0.8rem; }
}
@media (max-width: 900px) {
    .clients-grid { grid-template-columns: repeat(2, 1fr); gap: 0.8rem; }
}
@media (max-width: 768px) {
    body { padding: 10px; }
    .main-layout { flex-direction: column; }
    .sections-sidebar { width: 100%; position: static; }
    .sections-list { max-height: 300px; }
    .top-bar { flex-direction: column; align-items: stretch; }
    .search-group { max-width: 100%; margin: 0; }
    .stats-group { justify-content: center; }
    .action-buttons { justify-content: center; }
    .clients-grid { grid-template-columns: 1fr; gap: 0.6rem; }
    .card-meta { flex-direction: column; align-items: center; gap: 0.2rem; }
    .form-row.two-columns { grid-template-columns: 1fr; gap: 0.8rem; }
    .form-group.full-width { grid-column: span 1; }
    .custom-toast { white-space: normal; text-align: center; max-width: 90%; }
    .settings-grid { grid-template-columns: 1fr; }
}
@media (max-width: 600px) {
    .clients-grid { grid-template-columns: 1fr; gap: 0.6rem; }
}