/* style.css - СТИЛЬНЫЙ ДИЗАЙН */

/* --- Переменные для Цветов и Стилизации --- */
:root {
    --primary-color: #34495e; /* Темно-синий/Серый для заголовков и кнопок */
    --accent-green: #2ecc71; /* Ярко-зеленый для прибыли */
    --accent-red: #e74c3c; /* Красный для убытка/продажи */
    --background-color: #ecf0f1; /* Светло-серый фон */
    --white-color: #ffffff;
    --border-color: #bdc3c7;
    --shadow-light: 0 4px 15px rgba(0, 0, 0, 0.08); /* Мягкая тень */
}

/* --- Базовые стили и Сброс --- */
* {
    box-sizing: border-box;
}

body {
    font-family: 'Roboto', sans-serif; 
    margin: 0;
    padding: 0;
    background-color: var(--background-color); 
    color: #333;
    line-height: 1.6;
}

.container {
    max-width: 1200px;
    margin: 40px auto;
    padding: 0 20px;
}

/* --- Header Row с кнопкой выхода --- */
.header-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-wrap: wrap;
    gap: 15px;
    margin-bottom: 20px;
}

.header-row h1 {
    margin-bottom: 0;
}

.user-panel {
    display: flex;
    align-items: center;
    gap: 15px;
}

.user-panel #user-name {
    color: var(--primary-color);
    font-weight: 500;
    font-size: 14px;
}

.logout-btn {
    padding: 8px 20px;
    background-color: #95a5a6;
    color: white;
    border: none;
    border-radius: 5px;
    font-size: 14px;
    cursor: pointer;
    transition: background-color 0.3s;
}

.logout-btn:hover {
    background-color: #7f8c8d;
}

h1 {
    color: var(--primary-color);
    font-weight: 700;
    font-size: 32px;
    margin-bottom: 20px;
}

h2 {
    color: var(--primary-color);
    font-weight: 500;
    font-size: 24px;
    border-bottom: 2px solid var(--border-color);
    padding-bottom: 5px;
    margin-top: 40px;
    margin-bottom: 20px;
}

hr {
    border: none;
    border-top: 1px solid #dcdde1;
    margin: 30px 0;
}

/* --- Дашборд/Сводка --- */
.dashboard-container {
    display: flex; 
    gap: 20px; 
    margin-bottom: 30px;
    flex-wrap: wrap;
}

.card {
    background: var(--white-color); 
    padding: 25px;
    border-radius: 12px; 
    box-shadow: var(--shadow-light); 
    flex: 1; 
    min-width: 250px;
    transition: transform 0.3s;
}
.card:hover {
    transform: translateY(-3px); 
}

.card-title {
    margin: 0 0 10px 0; 
    font-size: 14px; 
    color: #7f8c8d;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.card-value {
    font-size: 36px; 
    font-weight: 700; 
    margin: 0;
    font-family: 'Consolas', monospace; /* Моноширинный для чисел */
}


/* --- Форма Сделок --- */
.form-wrapper {
    background-color: var(--white-color);
    padding: 30px;
    border-radius: 12px;
    box-shadow: var(--shadow-light);
}

#trade-form {
    display: grid;
    grid-template-columns: repeat(3, 1fr); 
    gap: 20px 30px; 
    align-items: end; 
}

.form-group {
    display: flex;
    flex-direction: column;
    width: 100%;
}

#trade-form label,
#dividend-form label {
    font-weight: 500;
    margin-bottom: 8px;
    color: #555;
    font-size: 14px;
}

#trade-form input, 
#trade-form select,
#dividend-form input,
#dividend-form select {
    padding: 12px;
    border: 1px solid var(--border-color);
    border-radius: 8px;
    transition: border-color 0.3s;
    font-size: 16px;
    background-color: #fcfdff;
    width: 100%;
    box-sizing: border-box;
}

#trade-form input:focus, 
#trade-form select:focus,
#dividend-form input:focus,
#dividend-form select:focus {
    border-color: var(--primary-color);
    outline: none;
    box-shadow: 0 0 5px rgba(52, 73, 94, 0.3);
}

/* Кнопка "Добавить сделку" */
#trade-form button[type="submit"],
#dividend-form button[type="submit"] {
    background-color: var(--primary-color); 
    color: var(--white-color);
    padding: 12px 20px;
    border: none;
    border-radius: 8px;
    cursor: pointer;
    font-size: 17px;
    font-weight: 600;
    transition: background-color 0.3s, transform 0.1s;
    margin-top: 10px;
    width: 100%;
}

#trade-form button[type="submit"]:hover,
#dividend-form button[type="submit"]:hover {
    background-color: #2c3e50; 
}

#trade-form button[type="submit"]:active,
#dividend-form button[type="submit"]:active {
    transform: translateY(1px);
}

/* --- Таблицы --- */
.table-wrapper {
    overflow-x: auto; 
}

#positions-table, #history-table {
    width: 100%;
    border-collapse: collapse;
    box-shadow: var(--shadow-light);
    background-color: var(--white-color);
    border-radius: 12px;
    overflow: hidden; 
}

#positions-table th, #history-table th {
    background-color: var(--primary-color); 
    color: white;
    font-weight: 600;
    padding: 15px 12px;
    text-align: left;
    text-transform: uppercase;
    font-size: 14px;
}

#positions-table td, #history-table td {
    padding: 12px;
    text-align: left;
    border-bottom: 1px solid #f2f4f6;
}

/* Зебра для читаемости */
#positions-table tbody tr:nth-child(even),
#history-table tbody tr:nth-child(even) {
    background-color: #f9f9f9;
}
#positions-table tbody tr:hover,
#history-table tbody tr:hover {
    background-color: #f5f5f5;
}


/* Выравнивание чисел */
.table-wrapper td:nth-child(2),
.table-wrapper td:nth-child(3),
#history-table td:nth-child(3),
#history-table td:nth-child(4),
#history-table td:nth-child(6) {
    text-align: right; 
    font-family: 'Consolas', 'Courier New', monospace; 
}


/* --- Индикаторы Статуса/Прибыли --- */
.profit-positive { color: var(--accent-green); font-weight: 700; } 
.profit-negative { color: var(--accent-red); font-weight: 700; } 
.type-buy { color: #3498db; font-weight: 500; } 
.type-sell { color: var(--accent-red); font-weight: 500; } 

.delete-btn {
    background-color: var(--accent-red);
    color: white;
    border: none;
    padding: 6px 12px;
    border-radius: 5px;
    cursor: pointer;
    font-size: 12px;
    font-weight: 500;
    transition: background-color 0.3s;
}
.delete-btn:hover {
    background-color: #c0392b;
}

/* --- Сообщения (Messages) --- */
.status-message {
    padding: 15px;
    margin-bottom: 20px;
    border-radius: 8px;
    font-weight: 600;
    text-align: center;
    border: 1px solid transparent;
    transition: all 0.3s ease-in-out;
}

/* Теперь JS будет устанавливать классы .status-success, .status-error и т.д. */
.status-success { 
    background-color: #d4edda; 
    color: #155724; 
    border-color: #c3e6cb;
}
.status-error { 
    background-color: #f8d7da; 
    color: #721c24; 
    border-color: #f5c6cb;
}
.status-warning { 
    background-color: #fff3cd; 
    color: #856404; 
    border-color: #ffeeba;
}

/* --- Графики --- */
.charts-container {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(400px, 1fr));
    gap: 25px;
    margin-bottom: 30px;
}

.chart-wrapper {
    background: var(--white-color);
    padding: 25px;
    border-radius: 12px;
    box-shadow: var(--shadow-light);
}

.chart-wrapper h3 {
    margin: 0 0 20px 0;
    color: var(--primary-color);
    font-size: 16px;
    font-weight: 600;
}

.chart-wrapper canvas {
    max-height: 300px;
}

/* --- Табы --- */
.tabs {
    display: flex;
    gap: 10px;
    margin-bottom: 0;
}

.tab-btn {
    padding: 12px 25px;
    background-color: #dfe6e9;
    border: none;
    border-radius: 8px 8px 0 0;
    cursor: pointer;
    font-size: 15px;
    font-weight: 500;
    color: #636e72;
    transition: all 0.3s;
}

.tab-btn:hover {
    background-color: #b2bec3;
}

.tab-btn.active {
    background-color: var(--white-color);
    color: var(--primary-color);
    box-shadow: 0 -2px 10px rgba(0,0,0,0.05);
}

.tab-content {
    display: none;
}

.tab-content.active {
    display: block;
}

.tab-content .form-wrapper {
    border-radius: 0 12px 12px 12px;
}

/* --- Форма с рядами --- */
.form-row {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 20px;
    margin-bottom: 15px;
}

/* Мобильная форма - сетка на десктопе, колонка на мобильных */
.mobile-form {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 15px;
}

.mobile-form .form-group {
    margin-bottom: 0;
    width: 100%;
}

.mobile-form .form-group input,
.mobile-form .form-group select {
    width: 100%;
    box-sizing: border-box;
}

.mobile-form button[type="submit"] {
    grid-column: 1 / -1;
    margin-top: 10px;
    width: 100%;
}

.form-wrapper form {
    display: flex;
    flex-direction: column;
}

.form-wrapper label {
    font-weight: 500;
    margin-bottom: 8px;
    color: #555;
    font-size: 14px;
}

.form-wrapper input, 
.form-wrapper select {
    padding: 12px;
    border: 1px solid var(--border-color);
    border-radius: 8px;
    transition: border-color 0.3s;
    font-size: 16px;
    background-color: #fcfdff;
}

.form-wrapper input:focus, 
.form-wrapper select:focus {
    border-color: var(--primary-color);
    outline: none;
    box-shadow: 0 0 5px rgba(52, 73, 94, 0.3);
}

.form-wrapper button[type="submit"] {
    background-color: var(--primary-color); 
    color: var(--white-color);
    padding: 12px 20px;
    border: none;
    border-radius: 8px;
    cursor: pointer;
    font-size: 17px;
    font-weight: 600;
    transition: background-color 0.3s, transform 0.1s;
    margin-top: 15px;
}

.form-wrapper button[type="submit"]:hover {
    background-color: #2c3e50;
}

/* --- Карточки с цветом --- */
.card-value.positive {
    color: var(--accent-green);
}

.card-value.negative {
    color: var(--accent-red);
}

/* --- Таблица дивидендов --- */
#dividends-table {
    width: 100%;
    border-collapse: collapse;
    box-shadow: var(--shadow-light);
    background-color: var(--white-color);
    border-radius: 12px;
    overflow: hidden;
}

#dividends-table th {
    background-color: var(--primary-color);
    color: white;
    font-weight: 600;
    padding: 15px 12px;
    text-align: left;
    text-transform: uppercase;
    font-size: 14px;
}

#dividends-table td {
    padding: 12px;
    text-align: left;
    border-bottom: 1px solid #f2f4f6;
}

#dividends-table tbody tr:nth-child(even) {
    background-color: #f9f9f9;
}

#dividends-table tbody tr:hover {
    background-color: #f5f5f5;
}

/* --- Сообщения улучшенные --- */
.status-message.success {
    background-color: #d4edda;
    color: #155724;
    border-color: #c3e6cb;
}

.status-message.error {
    background-color: #f8d7da;
    color: #721c24;
    border-color: #f5c6cb;
}

/* --- Текст ошибки в таблицах --- */
.error-text {
    color: var(--accent-red);
    font-weight: 600;
}

/* --- Адаптивность --- */
@media (max-width: 768px) {
    .charts-container {
        grid-template-columns: 1fr;
    }
    
    .mobile-form {
        display: flex !important;
        flex-direction: column !important;
        width: 100%;
    }
    
    .mobile-form .form-group {
        margin-bottom: 12px;
        width: 100%;
    }
    
    .mobile-form .form-group input,
    .mobile-form .form-group select {
        width: 100%;
        box-sizing: border-box;
    }
    
    .dashboard-container {
        flex-direction: column;
    }
    
    .card {
        min-width: auto;
    }
    
    .tabs {
        flex-wrap: wrap;
    }
    
    .header-row {
        flex-direction: column;
        align-items: flex-start;
    }
    
    .import-export-section {
        grid-template-columns: 1fr;
    }
}

/* --- Мобильная адаптация (телефоны) --- */
@media (max-width: 600px) {
    body {
        padding: 10px;
        font-size: 14px;
    }
    
    .container {
        padding: 15px;
        border-radius: 10px;
    }
    
    h1 {
        font-size: 20px;
        margin-bottom: 15px;
    }
    
    h2 {
        font-size: 16px;
        flex-wrap: wrap;
        gap: 8px;
    }
    
    /* Хедер */
    .header-row {
        flex-direction: column;
        gap: 10px;
        align-items: stretch;
    }
    
    .user-panel {
        justify-content: space-between;
        width: 100%;
    }
    
    .install-btn {
        padding: 6px 12px;
        font-size: 12px;
    }
    
    /* Табы */
    .tabs {
        gap: 5px;
    }
    
    .tab-btn {
        padding: 10px 15px;
        font-size: 13px;
        flex: 1;
        text-align: center;
    }
    
    /* Формы - стили уже заданы выше */
    
    .form-group label {
        font-size: 13px;
        margin-bottom: 4px;
    }
    
    .form-group input,
    .form-group select {
        padding: 12px;
        font-size: 16px; /* Предотвращает зум на iOS */
        border-radius: 8px;
    }
    
    .submit-btn {
        padding: 14px;
        font-size: 15px;
        margin-top: 10px;
    }
    
    /* Дашборд */
    .dashboard-container {
        gap: 10px;
    }
    
    .card {
        padding: 15px;
        min-width: auto;
    }
    
    .card-title {
        font-size: 12px;
    }
    
    .card-value {
        font-size: 18px;
    }
    
    .card-value small {
        font-size: 12px;
    }
    
    /* Котировки */
    .refresh-btn {
        padding: 6px 10px;
        font-size: 12px;
        margin-left: 8px;
    }
    
    .auto-refresh-label {
        font-size: 11px;
        margin-left: 5px;
        display: block;
        margin-top: 5px;
    }
    
    .quotes-status {
        font-size: 11px;
        display: block;
        margin-top: 5px;
        margin-left: 0;
    }
    
    /* Таблицы - горизонтальный скролл */
    .table-wrapper {
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
        margin: 0 -15px;
        padding: 0 15px;
    }
    
    table {
        font-size: 12px;
        min-width: 600px;
    }
    
    th, td {
        padding: 8px 6px;
        white-space: nowrap;
    }
    
    .delete-btn {
        padding: 4px 8px;
        font-size: 11px;
    }
    
    /* Графики */
    .charts-container {
        gap: 15px;
    }
    
    .chart-wrapper {
        padding: 15px;
    }
    
    .chart-wrapper h3 {
        font-size: 14px;
    }
    
    .chart-wrapper canvas {
        max-height: 250px !important;
    }
    
    /* Импорт/Экспорт */
    .import-export-section {
        gap: 15px;
    }
    
    .export-block,
    .import-block {
        padding: 15px;
    }
    
    .export-block h3,
    .import-block h3 {
        font-size: 14px;
    }
    
    .export-buttons {
        flex-direction: column;
    }
    
    .export-btn {
        text-align: center;
        padding: 12px;
    }
    
    .import-row {
        flex-direction: column;
    }
    
    .import-row select,
    .import-row input[type="file"] {
        width: 100%;
    }
    
    .import-btn {
        width: 100%;
        padding: 12px;
    }
    
    /* Офлайн индикатор */
    .offline-indicator {
        bottom: 10px;
        padding: 10px 20px;
        font-size: 13px;
        border-radius: 6px;
    }
}

/* --- Очень маленькие экраны --- */
@media (max-width: 360px) {
    body {
        padding: 5px;
    }
    
    .container {
        padding: 10px;
    }
    
    h1 {
        font-size: 18px;
    }
    
    .tab-btn {
        padding: 8px 10px;
        font-size: 12px;
    }
    
    .card {
        padding: 12px;
    }
    
    .card-value {
        font-size: 16px;
    }
    
    table {
        font-size: 11px;
    }
}

/* --- Котировки и кнопка обновления --- */
.refresh-btn {
    background-color: #3498db;
    color: white;
    border: none;
    padding: 6px 14px;
    border-radius: 5px;
    cursor: pointer;
    font-size: 13px;
    font-weight: 500;
    margin-left: 15px;
    transition: all 0.3s;
    vertical-align: middle;
}

.refresh-btn:hover {
    background-color: #2980b9;
}

.refresh-btn:disabled {
    background-color: #95a5a6;
    cursor: not-allowed;
}

.quotes-status {
    font-size: 12px;
    margin-left: 10px;
    padding: 4px 10px;
    border-radius: 4px;
    vertical-align: middle;
}

.quotes-status.loading {
    color: #f39c12;
}

.quotes-status.success {
    color: #27ae60;
}

.quotes-status.warning {
    color: #e67e22;
}

.quotes-status.error {
    color: #e74c3c;
}

/* --- Индикаторы изменения цены за день --- */
.day-up {
    color: var(--accent-green);
    font-weight: 500;
}

.day-down {
    color: var(--accent-red);
    font-weight: 500;
}

/* --- Карточки дашборда улучшенные --- */
.card-value small {
    font-size: 14px;
    font-weight: 500;
    opacity: 0.9;
}

/* --- Таблица позиций расширенная --- */
#positions-table th,
#positions-table td {
    white-space: nowrap;
    font-size: 13px;
}

#positions-table td:nth-child(3),
#positions-table td:nth-child(4),
#positions-table td:nth-child(5),
#positions-table td:nth-child(6),
#positions-table td:nth-child(7),
#positions-table td:nth-child(8) {
    text-align: right;
    font-family: 'Consolas', 'Courier New', monospace;
}

/* --- Маленькая кнопка удаления --- */
#positions-table .delete-btn {
    padding: 4px 8px;
    font-size: 11px;
}

/* --- Автообновление --- */
.auto-refresh-label {
    font-size: 13px;
    font-weight: normal;
    margin-left: 15px;
    color: #636e72;
    cursor: pointer;
    vertical-align: middle;
}

.auto-refresh-label input {
    margin-right: 5px;
    vertical-align: middle;
}

/* --- Импорт/Экспорт --- */
.import-export-section {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(350px, 1fr));
    gap: 25px;
}

.export-block,
.import-block {
    background: var(--white-color);
    padding: 25px;
    border-radius: 12px;
    box-shadow: var(--shadow-light);
}

.export-block h3,
.import-block h3 {
    margin: 0 0 15px 0;
    color: var(--primary-color);
    font-size: 16px;
}

.export-buttons {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
}

.export-btn {
    display: inline-block;
    padding: 10px 18px;
    background-color: #3498db;
    color: white;
    text-decoration: none;
    border-radius: 6px;
    font-size: 14px;
    font-weight: 500;
    transition: background-color 0.3s;
}

.export-btn:hover {
    background-color: #2980b9;
}

.export-btn-primary {
    background-color: #27ae60;
}

.export-btn-primary:hover {
    background-color: #1e8449;
}

.import-row {
    display: flex;
    gap: 10px;
    align-items: center;
    flex-wrap: wrap;
}

.import-row select {
    padding: 10px;
    border: 1px solid var(--border-color);
    border-radius: 6px;
    font-size: 14px;
    background: white;
}

.import-row input[type="file"] {
    flex: 1;
    min-width: 150px;
}

.import-btn {
    padding: 10px 20px;
    background-color: #9b59b6;
    color: white;
    border: none;
    border-radius: 6px;
    cursor: pointer;
    font-size: 14px;
    font-weight: 500;
    transition: background-color 0.3s;
}

.import-btn:hover {
    background-color: #8e44ad;
}

.import-result {
    margin-top: 15px;
    padding: 10px 15px;
    border-radius: 6px;
    font-size: 14px;
    display: none;
}

.import-result.loading {
    display: block;
    background-color: #ffeaa7;
    color: #856404;
}

.import-result.success {
    display: block;
    background-color: #d4edda;
    color: #155724;
}

.import-result.error {
    display: block;
    background-color: #f8d7da;
    color: #721c24;
}

.import-help {
    margin-top: 15px;
    font-size: 13px;
    color: #636e72;
}

.import-help summary {
    cursor: pointer;
    font-weight: 500;
    color: var(--primary-color);
}

.import-help p {
    margin: 8px 0;
    font-family: 'Consolas', monospace;
    background: #f5f5f5;
    padding: 5px 10px;
    border-radius: 4px;
}

/* --- PWA: Кнопка установки --- */
.install-btn {
    padding: 8px 16px;
    background: linear-gradient(135deg, #27ae60, #2ecc71);
    color: white;
    border: none;
    border-radius: 5px;
    font-size: 13px;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.3s;
    animation: pulse 2s infinite;
}

.install-btn:hover {
    transform: scale(1.05);
    box-shadow: 0 4px 15px rgba(39, 174, 96, 0.4);
}

@keyframes pulse {
    0%, 100% { box-shadow: 0 0 0 0 rgba(39, 174, 96, 0.4); }
    50% { box-shadow: 0 0 0 8px rgba(39, 174, 96, 0); }
}

/* --- PWA: Офлайн индикатор --- */
.offline-indicator {
    position: fixed;
    bottom: 20px;
    left: 50%;
    transform: translateX(-50%);
    background: #e74c3c;
    color: white;
    padding: 12px 24px;
    border-radius: 8px;
    font-weight: 500;
    box-shadow: 0 4px 15px rgba(0,0,0,0.2);
    z-index: 9999;
    display: none;
}

.offline-indicator.show {
    display: block;
    animation: slideUp 0.3s ease;
}

@keyframes slideUp {
    from { 
        opacity: 0;
        transform: translateX(-50%) translateY(20px);
    }
    to {
        opacity: 1;
        transform: translateX(-50%) translateY(0);
    }
}

/* --- PWA: Standalone mode (установленное приложение) --- */
@media (display-mode: standalone) {
    .install-btn {
        display: none !important;
    }
    
    body {
        /* Добавляем отступ для системных элементов iOS */
        padding-top: env(safe-area-inset-top);
        padding-bottom: env(safe-area-inset-bottom);
    }
}

/* --- Touch-friendly элементы --- */
@media (hover: none) and (pointer: coarse) {
    /* Увеличиваем область касания */
    .tab-btn,
    .submit-btn,
    .delete-btn,
    .refresh-btn,
    .export-btn,
    .import-btn,
    .logout-btn,
    .install-btn {
        min-height: 44px;
    }
    
    input, select {
        min-height: 44px;
    }
    
    /* Убираем hover эффекты на touch устройствах */
    #positions-table tbody tr:hover,
    #history-table tbody tr:hover,
    #dividends-table tbody tr:hover {
        background-color: transparent;
    }
    
    /* Активное состояние вместо hover */
    .tab-btn:active,
    .submit-btn:active,
    .delete-btn:active,
    .refresh-btn:active {
        transform: scale(0.98);
        opacity: 0.9;
    }
}