/* Стили веб-приложения — светлая тема по макету диплома (рис. 2.4) */

:root {
    --bg: #F0F2F5;
    --surface: #FFFFFF;
    --surface-alt: #F8F9FB;
    --border: #E2E8F0;
    --text: #1E293B;
    --text-muted: #64748B;
    --primary: #2563EB;
    --primary-hover: #1D4ED8;
    --danger: #DC2626;
    --success: #16A34A;
    --demo: #7C3AED;
    --shadow: 0 1px 3px rgba(0,0,0,0.08);
    --radius: 10px;
}

* { box-sizing: border-box; margin: 0; padding: 0; }

body {
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
    background: var(--bg);
    color: var(--text);
    min-height: 100vh;
    display: flex;
    flex-direction: column;
}

/* Верхняя панель */
.topbar {
    background: var(--surface);
    border-bottom: 1px solid var(--border);
    padding: 10px 20px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
    flex-wrap: wrap;
    box-shadow: var(--shadow);
}

.topbar-left {
    display: flex;
    align-items: center;
    gap: 12px;
    min-width: 0;
}

.logo {
    width: 36px;
    height: 36px;
    background: linear-gradient(135deg, var(--primary), #3B82F6);
    border-radius: 8px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 18px;
    flex-shrink: 0;
}

.app-title {
    font-size: 0.95rem;
    font-weight: 600;
    line-height: 1.3;
}

.topnav {
    display: flex;
    gap: 4px;
    background: var(--surface-alt);
    padding: 4px;
    border-radius: 8px;
    border: 1px solid var(--border);
}

.nav-tab {
    border: none;
    background: transparent;
    padding: 8px 16px;
    border-radius: 6px;
    font-size: 0.85rem;
    cursor: pointer;
    color: var(--text-muted);
    transition: all 0.15s;
}

.nav-tab:hover { background: #EEF2FF; color: var(--primary); }
.nav-tab.active {
    background: var(--primary);
    color: white;
    font-weight: 500;
}

/* Рабочая область */
.workspace {
    flex: 1;
    padding: 12px;
    overflow: hidden;
}

.page { display: none; height: 100%; }
.page.active { display: block; }

.layout-three-col {
    display: grid;
    grid-template-columns: 280px 1fr 260px;
    gap: 12px;
    height: calc(100vh - 120px);
}

.panel {
    background: var(--surface);
    border-radius: var(--radius);
    border: 1px solid var(--border);
    box-shadow: var(--shadow);
    overflow: hidden;
}

.panel-left, .panel-right {
    overflow-y: auto;
    padding: 14px;
}

.panel-title {
    font-size: 0.8rem;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.04em;
    margin-bottom: 12px;
    font-weight: 600;
}

.panel-center {
    display: flex;
    flex-direction: column;
    padding: 16px;
    min-width: 0;
}

.center-header {
    margin-bottom: 12px;
}

.center-header h2 {
    font-size: 1rem;
    font-weight: 600;
}

.center-header .subtitle {
    font-size: 0.85rem;
    color: var(--text-muted);
}

/* Карточки в боковых панелях */
.card {
    background: var(--surface-alt);
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 12px;
    margin-bottom: 10px;
}

.card h3 {
    font-size: 0.85rem;
    font-weight: 600;
    margin-bottom: 10px;
    color: var(--text);
}

.field {
    margin-bottom: 10px;
}

.field label {
    display: block;
    font-size: 0.78rem;
    color: var(--text-muted);
    margin-bottom: 4px;
}

.field input, .field select {
    width: 100%;
    padding: 8px 10px;
    border: 1px solid var(--border);
    border-radius: 6px;
    font-size: 0.9rem;
    background: var(--surface);
}

.field input:focus, .field select:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(37,99,235,0.15);
}

.port-row {
    display: flex;
    gap: 8px;
    align-items: center;
}

.port-label {
    flex: 1;
    padding: 8px 10px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 6px;
    font-size: 0.85rem;
    color: var(--text-muted);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

/* Кнопки */
.btn {
    border: none;
    border-radius: 6px;
    padding: 9px 14px;
    font-size: 0.85rem;
    cursor: pointer;
    transition: background 0.15s;
    font-weight: 500;
}

.btn-block { width: 100%; margin-bottom: 6px; }
.btn-sm { padding: 6px 10px; font-size: 0.8rem; }
.btn-lg { padding: 12px; font-size: 0.95rem; }

.btn-primary { background: var(--primary); color: white; }
.btn-primary:hover:not(:disabled) { background: var(--primary-hover); }
.btn-secondary { background: #E2E8F0; color: var(--text); }
.btn-secondary:hover:not(:disabled) { background: #CBD5E1; }
.btn-danger { background: var(--danger); color: white; }
.btn-danger:hover:not(:disabled) { background: #B91C1C; }
.btn-demo { background: var(--demo); color: white; }
.btn-demo:hover { background: #6D28D9; }

.btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

/* Статус подключения */
.status-badge {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 8px 10px;
    border-radius: 6px;
    font-size: 0.82rem;
    margin-bottom: 10px;
}

.status-badge .dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
}

.status-badge.connected {
    background: #DCFCE7;
    color: #166534;
}
.status-badge.connected .dot { background: var(--success); }

.status-badge.disconnected {
    background: #FEE2E2;
    color: #991B1B;
}
.status-badge.disconnected .dot { background: var(--danger); }

/* Вкладки графиков */
.graph-tabs {
    display: flex;
    gap: 4px;
    margin-bottom: 12px;
    flex-wrap: wrap;
}

.graph-tab {
    border: 1px solid var(--border);
    background: var(--surface-alt);
    padding: 7px 14px;
    border-radius: 6px;
    font-size: 0.82rem;
    cursor: pointer;
    color: var(--text-muted);
}

.graph-tab:hover { border-color: var(--primary); color: var(--primary); }
.graph-tab.active {
    background: var(--primary);
    color: white;
    border-color: var(--primary);
}

.chart-container {
    flex: 1;
    position: relative;
    min-height: 0;
}

.chart-container canvas {
    width: 100% !important;
    height: 100% !important;
}

/* Правая панель — списки */
.info-list {
    font-size: 0.82rem;
}

.info-list dt {
    color: var(--text-muted);
    margin-top: 6px;
}

.info-list dd {
    font-weight: 500;
    margin-left: 0;
}

.info-list.results dd {
    color: var(--primary);
    font-size: 0.95rem;
}

.file-link {
    font-size: 0.82rem;
    color: var(--primary);
    word-break: break-all;
    margin-bottom: 4px;
}

.file-date {
    font-size: 0.78rem;
    color: var(--text-muted);
    margin-top: 8px;
}

/* Дополнительные страницы */
.page-inner {
    background: var(--surface);
    border-radius: var(--radius);
    border: 1px solid var(--border);
    padding: 24px;
    max-width: 1100px;
    margin: 0 auto;
    height: calc(100vh - 120px);
    overflow-y: auto;
}

.page-desc {
    color: var(--text-muted);
    margin-bottom: 16px;
    font-size: 0.9rem;
}

.table-wrap {
    overflow-x: auto;
    max-height: calc(100vh - 220px);
}

table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.85rem;
}

th, td {
    padding: 8px 12px;
    border-bottom: 1px solid var(--border);
    text-align: right;
}

th { background: var(--surface-alt); font-weight: 600; text-align: right; }
th:first-child, td:first-child { text-align: left; }
tbody tr:hover { background: #F8FAFC; }

/* Страница результатов */
.results-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
    gap: 16px;
    margin-bottom: 24px;
}

.result-card {
    background: var(--surface-alt);
    border: 1px solid var(--border);
    border-radius: 10px;
    padding: 20px;
    text-align: center;
}

.result-card.highlight {
    border-color: var(--primary);
    background: #EFF6FF;
}

.result-value {
    font-size: 1.8rem;
    font-weight: 700;
    color: var(--primary);
}

.result-label {
    font-size: 0.8rem;
    color: var(--text-muted);
    margin-top: 6px;
}

/* Математические формулы (KaTeX) */
.math-inline .katex { font-size: 1em; }
.math-display { overflow-x: auto; padding: 4px 0; }
.math-display .katex { font-size: 1.15em; }

.info-list dt .katex { font-size: 0.95em; }
.result-label .katex { font-size: 0.9em; }
.graph-tab .katex { font-size: 0.9em; color: inherit; }
.graph-tab.active .katex { color: white; }
.graph-tab.active { color: white; }
.field label .katex { font-size: 0.95em; }
table th .katex { font-size: 0.95em; }

.formula-block {
    background: var(--surface-alt);
    border-radius: 12px;
    padding: 20px 24px;
    border: 1px solid var(--border);
    margin-top: 8px;
}

.formula-block h3 {
    margin-bottom: 16px;
    font-size: 1rem;
    color: var(--text);
}

.formula-section {
    margin-bottom: 20px;
}

.formula-section h4 {
    font-size: 0.82rem;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    color: var(--text-muted);
    margin-bottom: 10px;
    font-weight: 600;
}

.formula-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
    gap: 12px;
}

.formula-grid-sub {
    margin-top: 10px;
}

.formula-item {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 14px 16px;
    text-align: center;
}

.formula-name {
    display: block;
    font-size: 0.78rem;
    color: var(--text-muted);
    margin-bottom: 8px;
    font-weight: 500;
}

.formula-wide {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 16px;
    text-align: center;
    margin-bottom: 4px;
}

.settings-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
    gap: 16px;
    margin-bottom: 20px;
}

.hint {
    font-size: 0.85rem;
    color: var(--text-muted);
    background: #FFFBEB;
    border: 1px solid #FDE68A;
    border-radius: 8px;
    padding: 12px;
}

/* Строка состояния */
.statusbar {
    background: var(--surface);
    border-top: 1px solid var(--border);
    padding: 8px 20px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    font-size: 0.85rem;
}

.status-left {
    display: flex;
    align-items: center;
    gap: 8px;
}

#statusIcon { font-size: 1rem; }
#statusIcon.ok { color: var(--success); }

.status-right {
    display: flex;
    align-items: center;
    gap: 10px;
}

.progress-wrap {
    width: 120px;
    height: 6px;
    background: #E2E8F0;
    border-radius: 3px;
    overflow: hidden;
}

.progress-bar {
    height: 100%;
    background: var(--primary);
    border-radius: 3px;
    transition: width 0.2s;
}

/* Адаптивность */
@media (max-width: 1100px) {
    .layout-three-col {
        grid-template-columns: 1fr;
        height: auto;
    }
    .panel-center { min-height: 400px; }
}
