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

body {
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    min-height: 100vh;
    padding: 20px;
}

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

/* Шапка и навигация */
.site-header {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
    padding: 16px 0 24px;
    margin-bottom: 24px;
    border-bottom: 1px solid rgba(255,255,255,0.3);
}

.site-title {
    font-size: 1.5rem;
    font-weight: bold;
    color: white;
    text-decoration: none;
}

.site-title:hover {
    color: white;
    opacity: 0.9;
}

.site-nav {
    display: flex;
    flex-wrap: wrap;
    gap: 6px 20px;
    align-items: center;
}

.site-nav a {
    color: rgba(255,255,255,0.9);
    text-decoration: none;
    font-size: 0.95rem;
    padding: 6px 10px;
    border-radius: 8px;
}

.site-nav a:hover {
    background: rgba(255,255,255,0.2);
    color: white;
}

.nav-logout {
    margin-left: 8px;
    opacity: 0.85;
}

.main-content {
    min-height: 50vh;
}

.site-footer {
    text-align: center;
    color: rgba(255,255,255,0.7);
    font-size: 0.9rem;
    margin-top: 40px;
    padding: 20px;
}

/* Заголовок страницы (внутренней) */
.page-title {
    color: white;
    font-size: 1.6rem;
    margin-bottom: 20px;
    font-weight: 600;
}

/* Блок контента (форма или таблица) */
.block {
    background: white;
    border-radius: 12px;
    box-shadow: 0 4px 20px rgba(0,0,0,0.12);
    margin-bottom: 20px;
    padding: 24px;
}

.block-title {
    font-size: 1.1rem;
    color: #333;
    margin-bottom: 16px;
    padding-bottom: 8px;
    border-bottom: 1px solid #eee;
}

/* Форма в одну строку (компактная) */
.form-row {
    display: flex;
    flex-wrap: wrap;
    gap: 12px;
    align-items: flex-end;
}

.form-row .field {
    flex: 1;
    min-width: 120px;
}

.form-row .field label {
    display: block;
    font-size: 0.85rem;
    color: #555;
    margin-bottom: 4px;
}

.form-row .field input,
.form-row .field select {
    width: 100%;
    padding: 10px 12px;
    border: 1px solid #ddd;
    border-radius: 8px;
    font-size: 1rem;
}

.form-row .btn {
    padding: 10px 20px;
    white-space: nowrap;
    border-radius: 8px;
    font-size: 1rem;
    font-weight: 500;
    cursor: pointer;
    border: none;
}

.page-desc {
    color: rgba(255,255,255,0.9);
    font-size: 0.95rem;
    margin-bottom: 24px;
    max-width: 560px;
}

.btn-primary {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
}

.btn-primary:hover {
    opacity: 0.95;
}

.btn-danger {
    background: #c0392b;
    color: white;
}

.btn-danger:hover {
    background: #a93226;
}

.btn-sm {
    padding: 6px 12px;
    font-size: 0.85rem;
}

.table-wrap {
    overflow-x: auto;
}

.data-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.95rem;
}

.data-table th,
.data-table td {
    padding: 10px 14px;
    text-align: left;
    border-bottom: 1px solid #eee;
}

.data-table th {
    background: #f8f9fa;
    color: #555;
    font-weight: 600;
}

.data-table tbody tr:hover {
    background: #fafafa;
}

/* Группировка маршрутов по поездам */
.routes-by-train {
    display: flex;
    flex-direction: column;
    gap: 24px;
}

.route-group {
    border: 1px solid #e8e8e8;
    border-radius: 10px;
    overflow: hidden;
    background: #fafafa;
}

.route-group-title {
    margin: 0;
    padding: 12px 16px;
    font-size: 1.05rem;
    background: #eee;
    color: #333;
    border-bottom: 1px solid #e8e8e8;
}

.route-group .data-table {
    margin: 0;
}

.route-group .data-table th {
    background: #f5f5f5;
}

/* Отчёт: группировка по поездам */
.report-by-train {
    display: flex;
    flex-direction: column;
    gap: 20px;
}

.report-train-group {
    border: 1px solid #e8e8e8;
    border-radius: 10px;
    overflow: hidden;
    background: #fafafa;
}

.report-train-title {
    margin: 0;
    padding: 12px 16px;
    font-size: 1.05rem;
    background: #eee;
    color: #333;
    border-bottom: 1px solid #e8e8e8;
}

.report-train-group .data-table {
    margin: 0;
}

.report-train-group .data-table th {
    background: #f5f5f5;
}

.badge {
    display: inline-block;
    padding: 4px 10px;
    border-radius: 6px;
    font-size: 0.85rem;
    font-weight: 500;
}

.badge-load { background: #d5f4e6; color: #1e7b4d; }
.badge-unload { background: #fadbd8; color: #922b21; }

/* Страница входа */
.header-simple {
    text-align: center;
    color: white;
    margin-bottom: 32px;
}

.header-simple h1 {
    font-size: 2rem;
    margin-bottom: 8px;
}

.header-simple p {
    opacity: 0.9;
    font-size: 1rem;
}

.login-box {
    max-width: 380px;
    margin: 0 auto;
}

.login-box .form-group {
    margin-bottom: 16px;
}

.login-box label {
    display: block;
    margin-bottom: 6px;
    color: #555;
}

.login-box input {
    width: 100%;
    padding: 12px;
    border: 1px solid #ddd;
    border-radius: 8px;
    font-size: 1rem;
}

.login-box button {
    width: 100%;
    padding: 12px;
    margin-top: 8px;
    border: none;
    border-radius: 8px;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
    font-weight: 500;
    cursor: pointer;
}

.logout-link {
    color: rgba(255,255,255,0.85);
    font-size: 0.95em;
    text-decoration: underline;
}

.logout-link:hover {
    color: white;
}

.login-box {
    max-width: 400px;
    margin-left: auto;
    margin-right: auto;
}

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

.card {
    background: white;
    padding: 30px;
    border-radius: 15px;
    box-shadow: 0 10px 30px rgba(0,0,0,0.2);
    text-align: center;
    transition: transform 0.3s, box-shadow 0.3s;
    text-decoration: none;
    color: #333;
}

.card:hover {
    transform: translateY(-5px);
    box-shadow: 0 15px 40px rgba(0,0,0,0.3);
}

.card i {
    font-size: 3em;
    margin-bottom: 15px;
}

.card.train { color: #e74c3c; }
.card.station { color: #3498db; }
.card.cargo { color: #2ecc71; }
.card.report { color: #f39c12; }
.card.info { color: #9b59b6; }

.card h3 {
    font-size: 1.5em;
    margin-bottom: 10px;
}

.card p {
    color: #666;
    font-size: 0.9em;
}

.form-container, .data-container {
    background: white;
    padding: 30px;
    border-radius: 15px;
    box-shadow: 0 10px 30px rgba(0,0,0,0.2);
    margin-bottom: 30px;
}

h2 {
    color: #333;
    margin-bottom: 20px;
    text-align: center;
}

.form-group {
    margin-bottom: 20px;
}

.form-group label {
    display: block;
    margin-bottom: 8px;
    color: #555;
    font-weight: bold;
}

.form-group input,
.form-group select,
.form-group button {
    width: 100%;
    padding: 12px;
    border: 2px solid #ddd;
    border-radius: 8px;
    font-size: 1em;
    transition: border-color 0.3s;
}

.form-group input:focus,
.form-group select:focus {
    outline: none;
    border-color: #667eea;
}

.form-group button {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
    border: none;
    cursor: pointer;
    font-weight: bold;
    margin-top: 10px;
}

.form-group button:hover {
    opacity: 0.9;
}

table {
    width: 100%;
    border-collapse: collapse;
    margin-top: 20px;
}

table th,
table td {
    padding: 12px;
    text-align: left;
    border-bottom: 1px solid #ddd;
}

table th {
    background: #f8f9fa;
    font-weight: bold;
    color: #555;
}

table tr:hover {
    background: #f5f5f5;
}

.alert {
    padding: 12px 16px;
    border-radius: 8px;
    margin-bottom: 16px;
}

.alert-success, .success {
    background: #d4edda;
    color: #155724;
}

.alert-error, .error {
    background: #f8d7da;
    color: #721c24;
}

.back-btn {
    display: inline-block;
    background: #6c757d;
    color: white;
    padding: 10px 20px;
    border-radius: 8px;
    text-decoration: none;
    margin-bottom: 20px;
    transition: background 0.3s;
}

.back-btn:hover {
    background: #5a6268;
}

.btn-delete {
    padding: 6px 12px;
    font-size: 0.9em;
    background: #c0392b;
    color: white;
    border: none;
    border-radius: 6px;
    cursor: pointer;
    transition: background 0.2s;
}

.btn-delete:hover {
    background: #a93226;
}

.empty-msg {
    text-align: center;
    color: #999;
}

.form-hint {
    color: #666;
    font-size: 0.95em;
    margin-bottom: 15px;
}

.op-load { color: #27ae60; font-weight: bold; }
.op-unload { color: #c0392b; font-weight: bold; }

/* Общая информация */
.info-section {
    margin-bottom: 35px;
}

.info-form .form-row {
    display: flex;
    flex-wrap: wrap;
    gap: 15px;
    align-items: flex-end;
}

.info-form .form-row .form-group {
    flex: 1;
    min-width: 180px;
    margin-bottom: 0;
}

.info-form .form-row button {
    padding: 12px 24px;
    flex-shrink: 0;
}

.station-ops-result h3 {
    margin: 20px 0 15px;
    font-size: 1.2em;
    color: #333;
}

.ops-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 20px;
}

@media (max-width: 600px) {
    .ops-grid { grid-template-columns: 1fr; }
}

.ops-block {
    background: #f8f9fa;
    padding: 15px;
    border-radius: 10px;
    border-left: 4px solid #ddd;
}

.ops-block.ops-load { border-left-color: #27ae60; }
.ops-block.ops-unload { border-left-color: #c0392b; }

.ops-block h4 {
    margin-bottom: 10px;
    font-size: 1em;
}

.ops-table {
    margin: 0;
    font-size: 0.95em;
}

.ops-table th, .ops-table td {
    padding: 6px 10px;
}

.routes-list {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.route-card {
    background: #f8f9fa;
    padding: 15px 20px;
    border-radius: 10px;
    border-left: 4px solid #9b59b6;
}

.route-train {
    font-weight: bold;
    margin-bottom: 8px;
    color: #333;
}

.route-stations {
    color: #555;
    font-size: 0.95em;
}

.route-station {
    white-space: nowrap;
}

/* Страница «Общая информация» */
.info-intro {
    color: rgba(255,255,255,0.95);
    font-size: 1.05em;
    margin-bottom: 24px;
    max-width: 560px;
}

.info-block {
    background: white;
    border-radius: 12px;
    box-shadow: 0 4px 15px rgba(0,0,0,0.1);
    margin-bottom: 24px;
    padding: 20px 24px;
}

.info-block-title {
    font-size: 1.15em;
    margin-bottom: 16px;
    color: #333;
    padding-bottom: 8px;
    border-bottom: 2px solid #9b59b6;
}

.trains-list {
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.train-card {
    background: #f8f9fa;
    border-radius: 10px;
    border-left: 4px solid #9b59b6;
    overflow: hidden;
}

.train-card-summary {
    padding: 12px 16px;
    font-weight: bold;
    cursor: pointer;
    list-style: none;
    user-select: none;
}

.train-card-summary::-webkit-details-marker { display: none; }

.train-card-summary::before {
    content: '▸ ';
    display: inline-block;
    margin-right: 6px;
    transition: transform 0.2s;
}

.train-card[open] .train-card-summary::before {
    transform: rotate(90deg);
}

.train-card-body {
    padding: 12px 16px 16px;
    border-top: 1px solid #e0e0e0;
}

/* Дропдауны по поездам на странице Поезда */
.trains-detail-list {
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.train-detail-card {
    background: #f8f9fa;
    border-radius: 10px;
    border-left: 4px solid #e74c3c;
    overflow: hidden;
}

.train-detail-summary {
    padding: 12px 16px;
    font-weight: bold;
    cursor: pointer;
    list-style: none;
    user-select: none;
}

.train-detail-summary::-webkit-details-marker { display: none; }

.train-detail-summary::before {
    content: '▸ ';
    display: inline-block;
    margin-right: 6px;
    transition: transform 0.2s;
}

.train-detail-card[open] .train-detail-summary::before {
    transform: rotate(90deg);
}

.train-detail-body {
    padding: 12px 16px 16px;
    border-top: 1px solid #e0e0e0;
}

.train-detail-station {
    background: white;
    padding: 10px 14px;
    margin-bottom: 8px;
    border-radius: 8px;
    border-left: 3px solid #3498db;
}

.train-detail-station-name {
    font-weight: bold;
    margin-bottom: 6px;
    color: #333;
}

.train-detail-station-ops {
    font-size: 0.9em;
    color: #555;
    line-height: 1.6;
}

.train-detail-station-ops .op-tag {
    display: inline-block;
    background: #eee;
    padding: 2px 8px;
    border-radius: 4px;
    margin: 2px 4px 2px 0;
    font-size: 0.9em;
}

/* Сводка по станциям на Обзоре */
.stations-summary-list {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.station-summary-card {
    background: #f8f9fa;
    border-radius: 10px;
    border-left: 4px solid #3498db;
    padding: 14px 18px;
}

.station-summary-name {
    font-weight: bold;
    font-size: 1.05rem;
    margin-bottom: 10px;
    color: #333;
}

.station-summary-ops {
    display: flex;
    flex-wrap: wrap;
    gap: 16px 24px;
}

.station-summary-block {
    font-size: 0.9em;
    color: #555;
    line-height: 1.6;
}

.station-summary-block .op-tag {
    display: inline-block;
    background: #eee;
    padding: 3px 8px;
    border-radius: 4px;
    margin: 2px 4px 2px 0;
    font-size: 0.88em;
}

.train-route-line {
    margin-bottom: 14px;
    font-size: 0.95em;
    color: #555;
}

.train-route-line .route-station {
    font-weight: 500;
    color: #333;
}

.train-station-block {
    background: white;
    padding: 10px 14px;
    margin-bottom: 8px;
    border-radius: 8px;
    border-left: 3px solid #3498db;
}

.train-station-name {
    font-weight: bold;
    margin-bottom: 6px;
    color: #333;
}

.train-station-ops {
    font-size: 0.9em;
    color: #555;
    line-height: 1.6;
}

.train-station-ops .op-tag {
    display: inline-block;
    background: #eee;
    padding: 2px 8px;
    border-radius: 4px;
    margin: 2px 4px 2px 0;
    font-size: 0.9em;
}

/* Таблица грузов: где погружен — где выгружен */
.cargo-flows-table-wrap {
    overflow-x: auto;
    margin-top: 10px;
}

.cargo-flows-table {
    width: 100%;
    min-width: 520px;
    border-collapse: collapse;
    font-size: 0.95em;
}

.cargo-flows-table th,
.cargo-flows-table td {
    padding: 10px 12px;
    text-align: left;
    border-bottom: 1px solid #eee;
}

.cargo-flows-table th {
    background: #f0f0f0;
    font-weight: bold;
    color: #333;
}

.cargo-flows-table .station-list {
    vertical-align: top;
}

.station-tag {
    display: inline-block;
    padding: 3px 8px;
    border-radius: 6px;
    margin: 2px 4px 2px 0;
    font-size: 0.9em;
}

.station-tag.load-tag {
    background: #d5f4e6;
    color: #1e7b4d;
}

.station-tag.unload-tag {
    background: #fadbd8;
    color: #922b21;
}

@media (max-width: 768px) {
    .menu {
        grid-template-columns: 1fr;
    }
    
    .site-header {
        flex-direction: column;
        align-items: flex-start;
    }
    
    .site-nav {
        width: 100%;
    }
    
    .form-row {
        flex-direction: column;
    }
    
    .form-row .field {
        min-width: 100%;
    }
    
    .form-row .btn {
        width: 100%;
    }
}