/**
 * Component Styles
 * Buttons, forms, diagram, results table, and interactive elements
 */

/* Buttons */
.lang-switcher {
    position: relative;
}

#languageSelect {
    padding: 8px 32px 8px 12px;
    border: 1px solid var(--border);
    border-radius: 6px;
    background: var(--card-bg);
    cursor: pointer;
    font-size: 0.875rem;
    font-weight: 500;
    color: var(--text);
    transition: all 0.2s;
    appearance: none;
    -webkit-appearance: none;
    -moz-appearance: none;
    background-image: url('data:image/svg+xml;utf8,<svg fill="%2364748b" height="24" viewBox="0 0 24 24" width="24" xmlns="http://www.w3.org/2000/svg"><path d="M7 10l5 5 5-5z"/></svg>');
    background-repeat: no-repeat;
    background-position: right 6px center;
    background-size: 20px;
    min-width: 160px;
}

#languageSelect:hover {
    background-color: var(--hover-bg);
    border-color: var(--accent);
}

#languageSelect:focus {
    outline: none;
    border-color: var(--accent);
    box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.1);
}

.btn {
    padding: 8px 16px;
    border: 1px solid var(--border);
    background: var(--card-bg);
    border-radius: 6px;
    cursor: pointer;
    font-size: 0.875rem;
    font-weight: 500;
    transition: all 0.2s;
    color: var(--text);
    display: inline-flex;
    align-items: center;
    gap: 8px;
}

.btn:hover {
    background: var(--hover-bg);
    border-color: var(--accent);
}

.btn-primary {
    background: var(--accent);
    color: white;
    border-color: var(--accent);
}

.btn-primary:hover {
    background: var(--accent-hover);
    border-color: var(--accent-hover);
}

.calculate-btn {
    width: 100%;
    padding: 16px;
    background: var(--accent);
    color: white;
    border: none;
    border-radius: 6px;
    font-size: 1rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s;
    letter-spacing: -0.01em;
}

.calculate-btn:hover {
    background: var(--accent-hover);
    box-shadow: 0 4px 8px rgba(59, 130, 246, 0.3);
}

.calculate-btn:active {
    transform: translateY(1px);
}

/* Import/Export Actions */
.import-export-bar {
    display: flex;
    gap: 12px;
    align-items: center;
    margin-bottom: 24px;
}

.import-export-bar .btn {
    flex: 0 0 auto;
}

/* Interactive Map/Diagram */
.diagram-container {
    padding: 60px 40px;
    background: linear-gradient(135deg, #f8fafc 0%, #f1f5f9 100%);
    border-radius: 8px;
    margin-bottom: 24px;
    border: 2px solid var(--border-light);
}

.diagram {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0;
    max-width: 1000px;
    margin: 0 auto;
}

.module {
    background: white;
    border: 3px solid var(--primary);
    border-radius: 8px;
    padding: 32px 24px;
    min-width: 180px;
    text-align: center;
    box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
    cursor: pointer;
    transition: all 0.3s;
    position: relative;
}

.module:hover {
    transform: translateY(-4px);
    box-shadow: 0 8px 12px rgba(0, 0, 0, 0.15);
    border-color: var(--accent);
}

.module.selected {
    border-color: var(--selected-border);
    background: var(--selected);
    box-shadow: 0 0 0 4px rgba(59, 130, 246, 0.2);
}

.module-icon {
    font-size: 3rem;
    margin-bottom: 12px;
    filter: grayscale(20%);
}

.module-label {
    font-size: 0.75rem;
    color: var(--text-muted);
    margin-bottom: 6px;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    font-weight: 600;
}

.module-name {
    font-weight: 600;
    color: var(--primary);
    font-size: 1rem;
}

.cable {
    flex: 1;
    position: relative;
    margin: 0 -3px;
    cursor: pointer;
    padding: 40px 0;
    transition: all 0.3s;
}

.cable:hover .cable-line {
    height: 6px;
    background: linear-gradient(90deg, var(--primary) 0%, var(--accent) 50%, var(--primary) 100%);
}

.cable.selected .cable-line {
    height: 6px;
    background: var(--accent);
    box-shadow: 0 0 0 4px rgba(59, 130, 246, 0.2);
}

.cable-line {
    height: 4px;
    background: var(--primary);
    position: relative;
    transition: all 0.3s;
}

.cable-info {
    position: absolute;
    top: -30px;
    left: 50%;
    transform: translateX(-50%);
    background: white;
    padding: 8px 16px;
    border-radius: 6px;
    font-size: 0.875rem;
    font-weight: 600;
    white-space: nowrap;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
    border: 1px solid var(--border-light);
    color: var(--text);
}

.cable-arrow {
    position: absolute;
    right: -10px;
    top: 50%;
    transform: translateY(-50%);
    width: 0;
    height: 0;
    border-left: 10px solid var(--primary);
    border-top: 8px solid transparent;
    border-bottom: 8px solid transparent;
}

/* Configuration Panel */
.config-section {
    margin-bottom: 24px;
}

.config-section:last-child {
    margin-bottom: 0;
}

.config-section h3 {
    font-size: 0.875rem;
    font-weight: 600;
    margin-bottom: 16px;
    color: var(--primary);
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

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

.form-group label {
    display: block;
    font-size: 0.875rem;
    font-weight: 500;
    margin-bottom: 8px;
    color: var(--text);
}

.form-group select,
.form-group input {
    width: 100%;
    padding: 10px 12px;
    border: 1px solid var(--border);
    border-radius: 6px;
    font-size: 0.9375rem;
    background: white;
    transition: all 0.2s;
    color: var(--text);
}

.form-group select:focus,
.form-group input:focus {
    outline: none;
    border-color: var(--accent);
    box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.1);
}

.form-group input[type="number"] {
    font-family: 'Courier New', monospace;
}

.form-hint {
    font-size: 0.8125rem;
    color: var(--text-muted);
    margin-top: 6px;
}

/* Info Box */
.info-box {
    background: #eff6ff;
    border: 1px solid #bfdbfe;
    border-radius: 6px;
    padding: 16px;
    margin-bottom: 24px;
}

.info-box-title {
    font-size: 0.875rem;
    font-weight: 600;
    color: var(--primary);
    margin-bottom: 8px;
}

.info-box-text {
    font-size: 0.8125rem;
    color: var(--text-light);
    line-height: 1.5;
}

/* Results */
.results {
    display: none;
    margin-top: 24px;
}

.results.show {
    display: block;
}

.status-banner {
    padding: 20px 24px;
    border-radius: 8px;
    margin-bottom: 24px;
    display: flex;
    align-items: flex-start;
    gap: 16px;
    border: 1px solid;
}

.status-banner.success {
    background: #ecfdf5;
    border-color: #a7f3d0;
    color: #065f46;
}

.status-banner.warning {
    background: #fffbeb;
    border-color: #fde68a;
    color: #92400e;
}

.status-banner.danger {
    background: #fef2f2;
    border-color: #fecaca;
    color: #991b1b;
}

.status-icon {
    font-size: 1.5rem;
    line-height: 1;
}

.status-content h3 {
    font-size: 1rem;
    font-weight: 600;
    margin-bottom: 6px;
}

.status-content p {
    font-size: 0.9375rem;
    line-height: 1.5;
}

/* Results Table */
.results-table {
    width: 100%;
    border-collapse: collapse;
    table-layout: fixed;
}

.results-table th,
.results-table td {
    padding: 14px 16px;
    text-align: left;
    border-bottom: 1px solid var(--border-light);
}

.results-table th:nth-child(1),
.results-table td:nth-child(1) {
    width: 20%;
}

.results-table th:nth-child(2),
.results-table td:nth-child(2) {
    width: 18%;
}

.results-table th:nth-child(3),
.results-table td:nth-child(3) {
    width: 12%;
}

.results-table th:nth-child(4),
.results-table td:nth-child(4) {
    width: 50%;
}

.results-table th {
    background: var(--light-bg);
    font-weight: 600;
    font-size: 0.8125rem;
    color: var(--primary);
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

.results-table td {
    font-size: 0.9375rem;
}

.results-table tr:hover {
    background: var(--hover-bg);
}

.results-table .value {
    font-family: 'Courier New', monospace;
    font-weight: 600;
    text-align: right;
}

.results-table .highlight {
    background: linear-gradient(to right, rgba(59, 130, 246, 0.04) 0%, rgba(255, 255, 255, 1) 100%);
    border-left: 4px solid #3b82f6 !important;
    border-top: 1px solid rgba(59, 130, 246, 0.15) !important;
    border-bottom: 1px solid rgba(59, 130, 246, 0.15) !important;
    border-right: 1px solid rgba(59, 130, 246, 0.1) !important;
    box-shadow: 0 1px 3px rgba(59, 130, 246, 0.06);
    font-weight: 600;
}

.results-table .highlight:hover {
    background: linear-gradient(to right, rgba(59, 130, 246, 0.08) 0%, rgba(255, 255, 255, 1) 100%);
    border-left-color: #2563eb !important;
    box-shadow: 0 2px 4px rgba(59, 130, 246, 0.1);
}

/* Green accent for positive highlighted rows (Link Budget, positive Available Budget) */
.results-table .highlight.positive {
    background: linear-gradient(to right, rgba(34, 197, 94, 0.04) 0%, rgba(255, 255, 255, 1) 100%);
    border-left: 4px solid #22c55e !important;
    border-top: 1px solid rgba(34, 197, 94, 0.15) !important;
    border-bottom: 1px solid rgba(34, 197, 94, 0.15) !important;
    border-right: 1px solid rgba(34, 197, 94, 0.1) !important;
    box-shadow: 0 1px 3px rgba(34, 197, 94, 0.06);
}

.results-table .highlight.positive:hover {
    background: linear-gradient(to right, rgba(34, 197, 94, 0.08) 0%, rgba(255, 255, 255, 1) 100%);
    border-left-color: #16a34a !important;
    box-shadow: 0 2px 4px rgba(34, 197, 94, 0.1);
}

/* Red accent for negative highlighted rows (Total Loss, negative Available Budget) */
.results-table .highlight.negative {
    background: linear-gradient(to right, rgba(239, 68, 68, 0.04) 0%, rgba(255, 255, 255, 1) 100%);
    border-left: 4px solid #ef4444 !important;
    border-top: 1px solid rgba(239, 68, 68, 0.15) !important;
    border-bottom: 1px solid rgba(239, 68, 68, 0.15) !important;
    border-right: 1px solid rgba(239, 68, 68, 0.1) !important;
    box-shadow: 0 1px 3px rgba(239, 68, 68, 0.06);
}

.results-table .highlight.negative:hover {
    background: linear-gradient(to right, rgba(239, 68, 68, 0.08) 0%, rgba(255, 255, 255, 1) 100%);
    border-left-color: #dc2626 !important;
    box-shadow: 0 2px 4px rgba(239, 68, 68, 0.1);
}

.positive {
    color: var(--success);
}

.negative {
    color: var(--danger);
}

/* Modal */
.modal {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 9999;
    display: flex;
    align-items: center;
    justify-content: center;
}

.modal-overlay {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.5);
    backdrop-filter: blur(4px);
}

.modal-content {
    position: relative;
    background: var(--card-bg);
    border-radius: 12px;
    box-shadow: 0 20px 25px -5px rgba(0, 0, 0, 0.1), 0 10px 10px -5px rgba(0, 0, 0, 0.04);
    max-width: 600px;
    width: 90%;
    max-height: 80vh;
    display: flex;
    flex-direction: column;
}

.modal-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 20px 24px;
    border-bottom: 1px solid var(--border);
}

.modal-header h3 {
    margin: 0;
    font-size: 1.25rem;
    color: var(--text);
}

.modal-close {
    background: none;
    border: none;
    font-size: 28px;
    line-height: 1;
    color: var(--text-muted);
    cursor: pointer;
    padding: 0;
    width: 32px;
    height: 32px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 4px;
    transition: all 0.2s;
}

.modal-close:hover {
    background: var(--hover-bg);
    color: var(--text);
}

.modal-body {
    padding: 24px;
    overflow-y: auto;
    flex: 1;
}

.modal-body textarea {
    width: 100%;
    min-height: 300px;
    padding: 12px;
    border: 1px solid var(--border);
    border-radius: 6px;
    font-family: 'Courier New', monospace;
    font-size: 13px;
    background: var(--light-bg);
    color: var(--text);
    resize: vertical;
}

.modal-body textarea:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.1);
}

.modal-footer {
    display: flex;
    gap: 12px;
    justify-content: flex-end;
    padding: 20px 24px;
    border-top: 1px solid var(--border);
}

/* Configuration Grid - 3 Columns */
.config-grid {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 24px;
    margin-bottom: 24px;
}

/* System Settings Grid */
.system-settings-grid {
    display: grid;
    grid-template-columns: 1fr 300px;
    gap: 24px;
    align-items: start;
}

/* Responsive table wrapper */
.table-responsive {
    width: 100%;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
}

/* Results table - enhanced for responsive */
.results-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.9375rem;
    min-width: 800px; /* Enables horizontal scroll on small screens */
}

.results-table thead {
    background: var(--light-bg);
}

.results-table th {
    text-align: left;
    padding: 14px 16px;
    font-weight: 600;
    color: var(--text);
    border-bottom: 2px solid var(--border);
    position: sticky;
    top: 0;
    background: var(--light-bg);
    z-index: 10;
}

.results-table td {
    padding: 14px 16px;
    border-bottom: 1px solid var(--border-light);
    vertical-align: top;
}

.results-table tbody tr:hover {
    background: var(--hover-bg);
    transition: background 0.2s ease;
}

.results-table tbody tr:last-child td {
    border-bottom: none;
}

/* Table column widths */
.results-table th:nth-child(1),
.results-table td:nth-child(1) {
    width: 20%;
    font-weight: 600;
    color: var(--primary);
}

.results-table th:nth-child(2),
.results-table td:nth-child(2) {
    width: 25%;
    font-family: 'Courier New', monospace;
    font-size: 0.875rem;
    color: var(--text-light);
}

.results-table th:nth-child(3),
.results-table td:nth-child(3) {
    width: 15%;
    font-weight: 600;
    text-align: right;
}

.results-table th:nth-child(4),
.results-table td:nth-child(4) {
    width: 40%;
    color: var(--text-light);
    font-size: 0.875rem;
}

/* Mobile-specific responsive styles */
@media (max-width: 1024px) {
    .config-grid {
        grid-template-columns: 1fr;
        gap: 16px;
    }

    .system-settings-grid {
        grid-template-columns: 1fr;
    }

    .results-table {
        min-width: 600px;
    }

    .results-table th,
    .results-table td {
        padding: 12px;
        font-size: 0.875rem;
    }
}

@media (max-width: 768px) {
    .config-grid {
        gap: 12px;
    }

    .card {
        padding: 20px;
    }

    .results-table {
        min-width: 500px;
    }

    .results-table th,
    .results-table td {
        padding: 10px 8px;
        font-size: 0.8125rem;
    }

    /* Simplified column widths on mobile */
    .results-table th:nth-child(1),
    .results-table td:nth-child(1) {
        width: 25%;
    }

    .results-table th:nth-child(2),
    .results-table td:nth-child(2) {
        width: 30%;
    }

    .results-table th:nth-child(3),
    .results-table td:nth-child(3) {
        width: 15%;
    }

    .results-table th:nth-child(4),
    .results-table td:nth-child(4) {
        width: 30%;
    }
}
