:root {
    --bg-color: #f4f7f6;
    --sidebar-bg: #ffffff;
    --text-color: #333;
    --primary-color: #007bff;
    --primary-hover: #0056b3;
    --border-color: #dee2e6;
    --success-color: #28a745;
    --danger-color: #dc3545;
    --warning-color: #ffc107;
    --info-color: #17a2b8;
    --rj45-blue: #2563eb;
    --dome-camera-color: #007fff;
    --router-color: #f39c12;
}

* { box-sizing: border-box; margin: 0; padding: 0; }

body {
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
    background-color: var(--bg-color);
    color: var(--text-color);
    overflow: hidden;
    height: 100vh;
}

/* --- АВТОРИЗАЦИЯ --- */
#auth-container {
    display: flex;
    justify-content: center;
    align-items: center;
    height: 100vh;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
}

.auth-box {
    background: white;
    padding: 2.5rem;
    border-radius: 12px;
    box-shadow: 0 10px 25px rgba(0,0,0,0.1);
    width: 100%;
    max-width: 400px;
}

.auth-box h2 { margin-top: 0; margin-bottom: 1.5rem; text-align: center; }
.auth-box input {
    width: 100%;
    padding: 12px;
    margin-bottom: 1rem;
    border: 1px solid var(--border-color);
    border-radius: 6px;
}
.auth-box button {
    width: 100%;
    padding: 12px;
    border: none;
    background-color: var(--primary-color);
    color: white;
    font-size: 16px;
    border-radius: 6px;
    cursor: pointer;
}

.auth-switch {
    text-align: center;
    margin-top: 1rem;
    font-size: 14px;
    color: #666;
}
.auth-switch a { color: var(--primary-color); cursor: pointer; }

.alert {
    padding: 10px;
    border-radius: 4px;
    margin-bottom: 1rem;
    font-size: 14px;
}
.alert-error { background: #fee; color: #c33; }
.alert-success { background: #efe; color: #3c3; }

/* --- ПЛАВАЮЩЕЕ ОКНО ПРОБНОГО ПЕРИОДА --- */
.trial-float-banner {
    position: fixed;
    top: 20px;
    left: 50%;
    transform: translateX(-50%);
    background: linear-gradient(90deg, #ff6b6b, #ee5a6f);
    color: white;
    padding: 12px 24px;
    border-radius: 30px;
    box-shadow: 0 4px 15px rgba(238, 90, 111, 0.4);
    z-index: 9999;
    font-weight: 600;
    font-size: 14px;
    cursor: pointer;
    white-space: nowrap;
    display: none;
    animation: pulse 2s infinite;
}

.trial-float-banner.active { display: block; }

@keyframes pulse {
    0% { box-shadow: 0 4px 15px rgba(238, 90, 111, 0.4); }
    50% { box-shadow: 0 4px 25px rgba(238, 90, 111, 0.7); }
    100% { box-shadow: 0 4px 15px rgba(238, 90, 111, 0.4); }
}

/* --- МОДАЛЬНОЕ ОКНО ПОДПИСКИ --- */
#subscription-modal {
    display: none;
    position: fixed;
    top: 0; left: 0;
    width: 100%; height: 100%;
    background: rgba(0,0,0,0.7);
    z-index: 10000;
    justify-content: center;
    align-items: center;
}

#subscription-modal.active { display: flex; }

.subscription-content {
    background: white;
    padding: 30px;
    border-radius: 16px;
    max-width: 800px;
    width: 90%;
    max-height: 90vh;
    overflow-y: auto;
}

.subscription-content h2 {
    text-align: center;
    margin-bottom: 10px;
    color: #333;
}

.subscription-content .subtitle {
    text-align: center;
    color: #666;
    margin-bottom: 30px;
}

.plans-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
    gap: 20px;
    margin-bottom: 20px;
}

.plan-card {
    border: 2px solid #e0e0e0;
    border-radius: 12px;
    padding: 20px;
    text-align: center;
    cursor: pointer;
    transition: all 0.3s;
    position: relative;
}

.plan-card:hover {
    border-color: var(--primary-color);
    transform: translateY(-5px);
    box-shadow: 0 10px 20px rgba(0,0,0,0.1);
}

.plan-card.popular {
    border-color: var(--warning-color);
    background: linear-gradient(to bottom, #fff, #fffaf0);
}

.plan-card.popular::before {
    content: 'ПОПУЛЯРНЫЙ';
    position: absolute;
    top: -10px;
    left: 50%;
    transform: translateX(-50%);
    background: var(--warning-color);
    color: #000;
    padding: 4px 12px;
    border-radius: 12px;
    font-size: 11px;
    font-weight: bold;
}

.plan-duration {
    font-size: 24px;
    font-weight: bold;
    color: #333;
    margin-bottom: 5px;
}

.plan-price {
    font-size: 32px;
    color: var(--primary-color);
    font-weight: bold;
    margin: 15px 0;
}

.plan-price span {
    font-size: 16px;
    color: #666;
}

.plan-features {
    list-style: none;
    padding: 0;
    margin: 0;
    font-size: 14px;
    color: #666;
}

.plan-features li {
    margin: 8px 0;
}

/* --- ЛИЧНЫЙ КАБИНЕТ --- */
#dashboard {
    display: none;
    padding: 20px;
    max-width: 1200px;
    margin: 0 auto;
}

#dashboard.active { display: block; }

.dashboard-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 20px;
    padding-bottom: 20px;
    border-bottom: 2px solid var(--border-color);
}

.project-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(250px, 1fr));
    gap: 20px;
    margin-top: 20px;
}

.project-card {
    background: white;
    border: 1px solid var(--border-color);
    border-radius: 8px;
    padding: 20px;
    cursor: pointer;
    transition: transform 0.2s;
}

.project-card:hover {
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(0,0,0,0.1);
}

.new-project-card {
    border: 2px dashed var(--border-color);
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    min-height: 150px;
    color: var(--primary-color);
}

/* --- ОСНОВНОЕ ПРИЛОЖЕНИЕ --- */
#app { 
    display: none; 
    height: 100vh;
}
#app.active { display: flex; }

/* --- САЙДБАР --- */
#sidebar { 
    width: 350px; 
    background-color: var(--sidebar-bg); 
    border-right: 1px solid var(--border-color); 
    padding: 20px; 
    overflow-y: auto;
    display: flex;
    flex-direction: column;
}

.sidebar-section { 
    border-bottom: 1px solid var(--border-color); 
    padding-bottom: 20px; 
    margin-bottom: 20px;
}
.sidebar-section:last-child { border-bottom: none; }
.sidebar-section h3 { margin-top: 0; }

.project-name-input {
    width: 100%;
    padding: 10px;
    border: 1px solid var(--border-color);
    border-radius: 4px;
    font-size: 16px;
    font-weight: bold;
    margin-bottom: 10px;
}

.btn {
    width: 100%;
    padding: 10px;
    margin-bottom: 10px;
    border: none;
    border-radius: 4px;
    cursor: pointer;
    font-size: 14px;
    transition: all 0.2s;
}
.btn-primary { background: var(--primary-color); color: white; }
.btn-success { background: var(--success-color); color: white; }
.btn-danger { background: var(--danger-color); color: white; }
.btn-warning { background: var(--warning-color); color: #000; }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }

/* --- КНОПКА ЗАГРУЗКИ --- */
.file-upload-wrapper {
    position: relative;
    overflow: hidden;
    display: inline-block;
    width: 100%;
}

.file-upload-wrapper input[type=file] {
    position: absolute;
    left: -9999px;
}

.file-upload-label {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 10px;
    width: 100%;
    padding: 12px 20px;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
    border-radius: 8px;
    cursor: pointer;
    font-weight: 600;
    font-size: 14px;
    transition: all 0.3s;
    box-shadow: 0 4px 6px rgba(0,0,0,0.1);
    border: 2px dashed rgba(255,255,255,0.3);
}

.file-upload-label:hover {
    transform: translateY(-2px);
    box-shadow: 0 6px 12px rgba(0,0,0,0.15);
    background: linear-gradient(135deg, #5568d3 0%, #653e9a 100%);
}

.file-upload-label i {
    font-size: 20px;
}

/* --- КАНВАС --- */
#canvas-container { 
    flex-grow: 1; 
    position: relative; 
    overflow: hidden; 
    background-color: #e0e0e0; 
}

#canvas-wrapper { 
    position: absolute;
    box-shadow: 0 0 20px rgba(0,0,0,0.2); 
}

#plan-canvas-bg, #plan-canvas-overlay { 
    position: absolute; 
    top: 0; 
    left: 0; 
}
#plan-canvas-bg { z-index: 1; }
#plan-canvas-overlay { 
    z-index: 2; 
    cursor: grab; 
}
#plan-canvas-overlay:active { cursor: grabbing; }
#plan-canvas-overlay.panning { cursor: move; }
#plan-canvas-overlay.drawing-mode, 
#plan-canvas-overlay.calibration-mode, 
#plan-canvas-overlay.cable-mode { cursor: crosshair; }

/* --- СПИСКИ --- */
#camera-list, #socket-list, #cabinet-list, #router-list { list-style: none; padding: 0; margin: 0; }
.camera-item, .socket-item, .cabinet-item, .router-item { 
    background: #f8f9fa; 
    border: 1px solid var(--border-color); 
    padding: 10px; 
    margin-bottom: 8px; 
    border-radius: 4px; 
    cursor: move; 
    display: flex;
    align-items: center;
    gap: 12px;
}

/* --- SVG ИКОНКИ --- */
.camera-icon-svg, .socket-icon-svg, .cabinet-icon-svg, .router-icon-svg {
    width: 40px;
    height: 40px;
    flex-shrink: 0;
}

.camera-icon-svg path, .socket-icon-svg path, .cabinet-icon-svg path, .router-icon-svg path {
    stroke: #0066cc;
}

/* --- ИНФО ПАНЕЛЬ --- */
#info-panel { 
    position: absolute; 
    top: 60px; 
    left: 10px; 
    background: rgba(255,255,255,0.95); 
    padding: 10px 15px; 
    border-radius: 6px; 
    font-size: 14px; 
    font-weight: 600;
    pointer-events: none; 
    z-index: 10; 
    box-shadow: 0 2px 8px rgba(0,0,0,0.1);
    border: 1px solid var(--border-color);
}

/* --- БЛОК ПОЛЬЗОВАТЕЛЯ И СПРАВКИ --- */
.user-menu {
    position: absolute;
    top: 60px;
    right: 10px;
    background: white;
    padding: 15px;
    border-radius: 8px;
    box-shadow: 0 2px 12px rgba(0,0,0,0.15);
    z-index: 100;
    min-width: 240px;
    max-width: 280px;
    border: 1px solid var(--border-color);
    max-height: calc(100vh - 80px);
    overflow-y: auto;
}

/* Блок справки */
.help-block {
    margin-top: 10px;
}

.help-block h4 {
    font-size: 13px;
    color: #495057;
    margin-bottom: 10px;
    padding-bottom: 6px;
    border-bottom: 1px solid #e9ecef;
    font-weight: 600;
}

.help-section-title {
    font-size: 11px;
    font-weight: bold;
    color: #495057;
    margin-top: 12px;
    margin-bottom: 6px;
    padding: 4px 6px;
    background: #f8f9fa;
    border-radius: 4px;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.help-item {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    margin-bottom: 5px;
    font-size: 12px;
    gap: 8px;
}

.help-key {
    background: #e9ecef;
    border: 1px solid #ced4da;
    border-radius: 4px;
    padding: 2px 6px;
    font-weight: 600;
    color: #495057;
    font-family: monospace;
    font-size: 11px;
    white-space: nowrap;
    flex-shrink: 0;
}

.help-desc {
    color: #6c757d;
    text-align: right;
    line-height: 1.3;
    font-size: 11px;
}

/* --- ВЫДЕЛЕНИЕ --- */
.selection-active {
    outline: 2px solid #007bff;
    outline-offset: -2px;
}

.close-modal {
    float: right;
    font-size: 28px;
    cursor: pointer;
    color: #999;
}
.close-modal:hover { color: #333; }

/* --- ФОРМЫ --- */
.form-label {
    font-size: 12px;
    color: #555;
    margin-bottom: 4px;
    display: block;
    font-weight: 600;
}

/* --- ПОЛЗУНКИ --- */
.size-value {
    text-align: center;
    font-weight: bold;
    color: var(--primary-color);
    margin-top: 5px;
    font-size: 13px;
}

[data-tooltip] {
    position: relative;
    cursor: help;
}

[data-tooltip]:hover::after {
    content: attr(data-tooltip);
    position: absolute;
    bottom: calc(100% + 8px);
    left: 50%;
    transform: translateX(-50%);
    background: rgba(0, 0, 0, 0.9);
    color: white;
    padding: 8px 12px;
    border-radius: 6px;
    font-size: 12px;
    white-space: nowrap;
    z-index: 10000;
    pointer-events: none;
    box-shadow: 0 2px 8px rgba(0,0,0,0.2);
    max-width: 250px;
    white-space: normal;
    line-height: 1.4;
}

[data-tooltip]:hover::before {
    content: '';
    position: absolute;
    bottom: calc(100% + 2px);
    left: 50%;
    transform: translateX(-50%);
    border: 6px solid transparent;
    border-top-color: rgba(0, 0, 0, 0.9);
    z-index: 10000;
}

/* --- ПАНЕЛИ СВОЙСТВ --- */
#cabinet-properties {
    border-color: #e74c3c !important;
}

#cabinet-properties h3 {
    color: #e74c3c;
}

#router-properties {
    border-color: #f39c12 !important;
}

#router-properties h3 {
    color: #f39c12;
}