:root {
    --background-color: #0d1117;
    --surface-color: #161b22;
    --primary-color: #1f8bff;
    --text-color: #e6edf3;
    --text-secondary-color: #8b949e;
    --border-color: #30363d;
    --font-family: 'Roboto', sans-serif;

    --customer-color: #1f8bff;
    --supplier-color: #db6d28;
    --cross-relation-color: #eac54f;

    --risk-high-color: #da3633;
    --risk-medium-color: #db6d28;
    --risk-low-color: #238636;

    --swot-s-color: rgba(35, 134, 54, 0.15);
    --swot-w-color: rgba(218, 54, 51, 0.15);
    --swot-o-color: rgba(31, 139, 255, 0.15);
    --swot-t-color: rgba(219, 109, 40, 0.15);

    --sentiment-positive-color: #238636;
    --sentiment-negative-color: #da3633;
    --sentiment-neutral-color: #8b949e;

    --card-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
    --card-hover-shadow: 0 8px 24px rgba(0, 0, 0, 0.4);
    --primary-gradient: linear-gradient(90deg, #2796ff, #1f8bff);
}

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

html, body {
    height: 100%;
}

body {
    font-family: var(--font-family);
    background-color: var(--background-color);
    color: var(--text-color);
    line-height: 1.6;
    display: flex;
    flex-direction: column;
}

header {
    text-align: center;
    padding: 1.5rem 1rem;
    border-bottom: 1px solid var(--border-color);
    background-color: var(--surface-color);
}

header h1 {
    font-weight: 500;
    letter-spacing: 1px;
}

header p {
    color: var(--text-secondary-color);
    font-size: 1rem;
    margin-top: 0.25rem;
}

main {
    flex-grow: 1;
    padding: 2rem 1.5rem;
    width: 100%;
    max-width: 1800px;
    margin: 0 auto;
}

#search-section {
    max-width: 600px;
    margin: 0 auto 2.5rem;
}

#company-form {
    display: flex;
    gap: 10px;
    margin-top: 1rem;
}

.input-wrapper {
    position: relative;
    flex-grow: 1;
}

.search-icon {
    position: absolute;
    left: 1rem;
    top: 50%;
    transform: translateY(-50%);
    width: 1.2rem;
    height: 1.2rem;
    color: var(--text-secondary-color);
    pointer-events: none;
}

#company-input {
    width: 100%;
    padding: 0.75rem 1rem 0.75rem 3rem;
    font-size: 1rem;
    background-color: var(--background-color);
    border: 1px solid var(--border-color);
    border-radius: 6px;
    color: var(--text-color);
    transition: border-color 0.3s, box-shadow 0.3s;
}

#company-input:focus {
    outline: none;
    border-color: var(--primary-color);
    box-shadow: 0 0 0 4px rgba(31, 139, 255, 0.2);
}

#visualize-btn {
    padding: 0.75rem 1.5rem;
    font-size: 1rem;
    font-weight: 500;
    background-image: var(--primary-gradient);
    color: #ffffff;
    border: none;
    border-radius: 6px;
    cursor: pointer;
    transition: transform 0.2s ease, box-shadow 0.2s ease, background-image 0.2s ease;
    box-shadow: 0 2px 6px rgba(0,0,0,0.3);
}

#visualize-btn:hover {
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(31, 139, 255, 0.3);
}

.hidden {
    display: none !important;
}

#loading-section {
    text-align: center;
    padding: 2rem;
}

.spinner {
    width: 50px;
    height: 50px;
    border: 5px solid var(--border-color);
    border-top-color: var(--primary-color);
    border-radius: 50%;
    animation: spin 1s linear infinite;
    margin: 0 auto 1rem;
}

@keyframes spin {
    to {
        transform: rotate(360deg);
    }
}

#error-section {
    text-align: center;
    padding: 2rem;
    background-color: rgba(218, 54, 51, 0.1);
    border: 1px solid rgba(218, 54, 51, 0.3);
    border-radius: 6px;
    max-width: 600px;
    margin: 0 auto;
}

#dashboard-section {
    animation: fadeIn 0.5s ease-in-out;
}

@keyframes fadeIn {
    from {
        opacity: 0;
        transform: translateY(20px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.dashboard-grid {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    grid-auto-rows: min-content;
    gap: 1.5rem;
    grid-template-areas:
        "profile profile profile financials"
        "network network network dependency"
        "geographics geographics swot swot"
        "customers customers suppliers suppliers"
        "competitors competitors news news";
}

.card {
    background-color: var(--surface-color);
    border: 1px solid var(--border-color);
    border-radius: 8px;
    padding: 1.5rem;
    overflow: hidden;
    display: flex;
    flex-direction: column;
    box-shadow: var(--card-shadow);
    transition: transform 0.3s ease, box-shadow 0.3s ease;
}

.card:hover {
    transform: translateY(-4px);
    box-shadow: var(--card-hover-shadow);
}

.card-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 1rem;
    border-bottom: 1px solid var(--border-color);
    padding-bottom: 0.75rem;
}

.card h3 {
    color: var(--text-color);
    font-weight: 500;
    font-size: 1.2rem;
    margin: 0;
    padding: 0;
    border: none;
}
.card h4 {
    color: var(--text-color);
    font-weight: 500;
    margin-bottom: 0.5rem;
    font-size: 1rem;
}

#profile-card { 
    grid-area: profile;
    background-color: transparent;
    border: none;
    padding: 0;
    gap: 1rem;
    box-shadow: none;
}
#profile-card:hover {
    transform: none;
    box-shadow: none;
}
#profile-header h2 {
    font-size: 2.5rem;
    font-weight: 600;
}
#profile-header strong {
    font-size: 1.2rem;
    color: var(--text-secondary-color);
    display: block;
    margin-bottom: 1rem;
    font-weight: 400;
}
#profile-header p {
    font-size: 1rem;
    max-width: 90%;
    color: var(--text-secondary-color);
}
#profile-details {
    padding-top: 1rem;
    border-top: 1px solid var(--border-color);
}
#profile-details dl {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 0.75rem 2rem;
}
#profile-details dt {
    font-size: 0.8rem;
    color: var(--text-secondary-color);
    text-transform: uppercase;
}
#profile-details dd {
    font-size: 1rem;
    font-weight: 500;
}
#profile-details a {
    color: var(--primary-color);
    text-decoration: none;
}
#profile-details a:hover {
    text-decoration: underline;
}

#network-card { grid-area: network; min-height: 450px; position: relative; }
#financials-card { grid-area: financials; }
#dependency-card { grid-area: dependency; }
#geographics-card { grid-area: geographics; }
#swot-card { grid-area: swot; }
#customers-card { grid-area: customers; }
#suppliers-card { grid-area: suppliers; }
#competitors-card { grid-area: competitors; }
#news-card { grid-area: news; }

.filter-controls {
    display: flex;
    align-items: center;
    gap: 0.5rem;
}
.filter-controls span {
    font-size: 0.8rem;
    color: var(--text-secondary-color);
}
.filter-btn {
    background-color: var(--surface-color);
    border: 1px solid var(--border-color);
    color: var(--text-secondary-color);
    padding: 0.35rem 1rem;
    border-radius: 20px;
    cursor: pointer;
    font-size: 0.85rem;
    font-weight: 500;
    transition: all 0.2s ease;
}
.filter-btn:hover {
    background-color: var(--border-color);
    color: var(--text-color);
}
.filter-btn.active {
    background-image: var(--primary-gradient);
    border-color: var(--primary-color);
    color: #ffffff;
    box-shadow: 0 2px 8px rgba(31, 139, 255, 0.2);
}

#connections-graph {
    width: 100%;
    height: 100%;
    flex-grow: 1;
}

#network-legend {
    position: absolute;
    bottom: 1.5rem;
    left: 1.5rem;
    z-index: 10;
    background: rgba(22, 27, 34, 0.85);
    backdrop-filter: blur(4px);
    padding: 0.75rem;
    border-radius: 8px;
    border: 1px solid var(--border-color);
    display: flex;
    flex-direction: column;
    gap: 0.6rem;
    pointer-events: none;
    font-size: 0.85rem;
}

.legend-item {
    display: flex;
    align-items: center;
    gap: 0.6rem;
}

.legend-icon {
    width: 24px;
    height: 24px;
    display: flex;
    align-items: center;
    justify-content: center;
}
.legend-icon svg, .legend-icon .vis-network-legend-star {
    width: 100%;
    height: 100%;
}


.financials-metrics {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(80px, 1fr));
    margin-bottom: 1.5rem;
    text-align: center;
    gap: 1rem;
}

.financials-metrics span {
    display: block;
    color: var(--text-secondary-color);
    font-size: 0.8rem;
}

.financials-metrics strong {
    font-size: 1.5rem;
    font-weight: 600;
    color: var(--text-color);
    display: block;
    line-height: 1.2;
}

.chart-container {
    position: relative;
    height: 100%;
    min-height: 200px;
    flex-grow: 1;
}

#dependency-analysis-content ul { list-style: none; padding-left: 0; font-size: 0.9rem; }
#dependency-analysis-content li { margin-bottom: 0.75rem; padding-left: 1.2rem; position: relative; }
#dependency-analysis-content li::before { content: '▪'; position: absolute; left: 0; color: var(--primary-color); }
#dependency-analysis-content strong { display: block; color: var(--text-color); font-weight: 500; margin-bottom: 0.25rem; }
#dependency-analysis-content p { font-size: 0.85rem; color: var(--text-secondary-color); }
#dependency-analysis-content h4 { color: var(--text-color); font-weight: 500; margin-top: 1rem; margin-bottom: 0.25rem; border-top: 1px solid var(--border-color); padding-top: 0.75rem; }

#swot-card .swot-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 1rem;
    height: 100%;
}
#swot-card .swot-item {
    padding: 1rem;
    border-radius: 6px;
}
#swot-card .swot-item:nth-child(1) { background-color: var(--swot-s-color); }
#swot-card .swot-item:nth-child(2) { background-color: var(--swot-w-color); }
#swot-card .swot-item:nth-child(3) { background-color: var(--swot-o-color); }
#swot-card .swot-item:nth-child(4) { background-color: var(--swot-t-color); }
#swot-card ul {
    list-style: none;
    padding-left: 0.75rem;
    font-size: 0.9rem;
}
#swot-card li {
    position: relative;
    margin-bottom: 0.25rem;
}
#swot-card li::before {
    content: '•';
    position: absolute;
    left: -0.75rem;
}

.table-wrapper {
    overflow-x: auto;
    flex-grow: 1;
}

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

table th, table td {
    padding: 0.85rem 1rem;
    text-align: left;
    border-bottom: 1px solid var(--border-color);
    white-space: nowrap;
}
table td:nth-child(4) {
    white-space: normal;
    min-width: 200px;
}
#competitors-table td:last-child {
    white-space: normal;
    min-width: 200px;
}

table th {
    font-weight: 500;
    color: var(--text-secondary-color);
    font-size: 0.8rem;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    cursor: pointer;
    user-select: none;
    background-color: rgba(0,0,0,0.2);
}
table th:hover {
    color: var(--text-color);
}
table th.sort-asc::after, table th.sort-desc::after {
    content: '';
    display: inline-block;
    width: 0.8em;
    height: 0.8em;
    margin-left: 0.4em;
    background-repeat: no-repeat;
    background-size: contain;
    vertical-align: middle;
}
table th.sort-asc::after { content: ' ▲'; color: var(--primary-color); }
table th.sort-desc::after { content: ' ▼'; color: var(--primary-color); }

table tbody tr {
    transition: background-color 0.2s ease;
}

table tbody tr:nth-child(odd) {
    background-color: rgba(255, 255, 255, 0.02);
}

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

table tbody tr:hover {
    background-color: #2a3038;
}

table a {
    color: var(--primary-color);
    text-decoration: none;
    font-weight: 500;
}
table a:hover {
    text-decoration: underline;
}

.risk-flag { display: flex; align-items: center; gap: 0.5rem; }
.credit-rating { padding: 0.1rem 0.5rem; border-radius: 4px; font-weight: 500; font-size: 0.8rem; color: #ffffff; }
.credit-rating.risk-high { background-color: var(--risk-high-color); }
.credit-rating.risk-medium { background-color: var(--risk-medium-color); }
.credit-rating.risk-low { background-color: var(--risk-low-color); }
.cross-relation-flag { color: var(--cross-relation-color); font-size: 1.2rem; font-weight: bold; cursor: help; }

.export-btn { background-color: transparent; border: 1px solid var(--border-color); color: var(--text-secondary-color); padding: 0.25rem 0.75rem; border-radius: 6px; cursor: pointer; font-size: 0.8rem; transition: all 0.2s ease; }
.export-btn:hover { border-color: var(--primary-color); color: var(--primary-color); }

#news-list {
    list-style: none;
    padding-left: 0;
    display: flex;
    flex-direction: column;
    gap: 0;
}

.news-item {
    padding: 1rem 0.5rem;
    border-bottom: 1px solid var(--border-color);
    transition: background-color 0.2s ease;
    border-radius: 4px;
}
.news-item:last-child {
    border-bottom: none;
}
.news-item:hover {
    background-color: var(--background-color);
}
.news-header {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    margin-bottom: 0.5rem;
}

.news-sentiment {
    width: 10px;
    height: 10px;
    border-radius: 50%;
    flex-shrink: 0;
}

.sentiment-positive { background-color: var(--sentiment-positive-color); }
.sentiment-negative { background-color: var(--sentiment-negative-color); }
.sentiment-neutral { background-color: var(--sentiment-neutral-color); }

.news-category {
    font-size: 0.75rem;
    background-color: var(--border-color);
    padding: 2px 8px;
    border-radius: 10px;
    color: var(--text-secondary-color);
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.news-title {
    color: var(--text-color);
    text-decoration: none;
    font-weight: 500;
    transition: color 0.3s;
    font-size: 1rem;
    display: inline-block;
    margin-bottom: 0.25rem;
}

.news-title:hover {
    color: var(--primary-color);
    text-decoration: underline;
}

.news-summary {
    font-size: 0.9rem;
    color: var(--text-secondary-color);
    margin: 0;
}

@media (max-width: 1400px) {
    .dashboard-grid {
        grid-template-columns: repeat(2, 1fr);
        grid-template-areas:
            "profile profile"
            "financials dependency"
            "network network"
            "geographics swot"
            "customers customers"
            "suppliers suppliers"
            "competitors news";
    }
}


@media (max-width: 768px) {
    main { padding: 1rem; }
    .dashboard-grid {
        grid-template-columns: 1fr;
        grid-template-areas:
            "profile"
            "financials"
            "dependency"
            "network"
            "geographics"
            "swot"
            "customers"
            "suppliers"
            "competitors"
            "news";
        gap: 1rem;
    }
    #profile-header h2 { font-size: 1.75rem; }
    #profile-details dl { grid-template-columns: 1fr; }
    .card-header { flex-direction: column; align-items: flex-start; gap: 0.5rem; }
}
