:root {
    --primary: #2E5C8A;
    --primary-light: #4A7CB8;
    --primary-dark: #1E4166;
    --accent: #5B8DBE;
    --accent-hover: #4A7CB8;
    
    --success: #2D8659;
    --success-light: #3FA76C;
    --danger: #B94A48;
    --danger-light: #D15B59;
    --warning: #C67605;
    --info: #3A87AD;
    
    --bg-primary: #E6EBF0;
    --bg-secondary: #FFFFFF;
    --bg-tertiary: #F5F7FA;
    --bg-panel: #FAFBFC;
    
    --text-primary: #333333;
    --text-secondary: #555555;
    --text-tertiary: #777777;
    --text-muted: #999999;
    
    --border-primary: #CCCCCC;
    --border-secondary: #DDDDDD;
    --border-light: #E5E5E5;
    --border-dark: #AAAAAA;
}

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

body {
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    background: var(--bg-primary);
    color: var(--text-primary);
    line-height: 1.5;
    font-size: 12px;
}

/* Header */
.header {
    background: linear-gradient(to bottom, #4A7CB8 0%, #2E5C8A 100%);
    color: white;
    padding: 0;
    box-shadow: 0 2px 3px rgba(0,0,0,0.2);
    position: sticky;
    top: 0;
    z-index: 100;
    border-bottom: 3px solid #1E4166;
}

.header-content {
    max-width: 1800px;
    margin: 0 auto;
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0.625rem 1.5rem;
}

.header-left {
    display: flex;
    align-items: center;
    gap: 0.75rem;
}

.logo-section {
    display: flex;
    align-items: center;
    gap: 0.75rem;
}

.logo-container {
    width: 48px;
    height: 48px;
    background: white;
    border: 2px solid #FFFFFF;
    border-radius: 4px;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 4px;
    box-shadow: 0 2px 4px rgba(0,0,0,0.2);
}

.logo-container img {
    width: 100%;
    height: 100%;
    object-fit: contain;
}

.header-title-group h1 {
    font-size: 1.125rem;
    font-weight: 600;
    text-shadow: 0 1px 1px rgba(0,0,0,0.3);
    margin-bottom: 0.125rem;
}

.header-subtitle {
    font-size: 0.6875rem;
    font-weight: 400;
    color: rgba(255, 255, 255, 0.9);
}

.header-right {
    display: flex;
    align-items: center;
    gap: 0.75rem;
}

.header-meta {
    font-size: 0.6875rem;
    color: white;
    font-weight: 500;
    padding: 0.375rem 0.75rem;
    background: rgba(255,255,255,0.15);
    border: 1px solid rgba(255,255,255,0.25);
    border-radius: 2px;
}

/* Container */
.container {
    max-width: 1800px;
    margin: 0 auto;
    padding: 1.25rem 1.5rem;
}

/* Panel Base Style */
.panel {
    background: var(--bg-secondary);
    border: 1px solid var(--border-primary);
    border-radius: 0;
    box-shadow: 0 1px 2px rgba(0,0,0,0.08);
}

.panel-header {
    background: linear-gradient(to bottom, #F5F7FA 0%, #E8ECF1 100%);
    padding: 0.625rem 1rem;
    border-bottom: 2px solid var(--border-primary);
    font-weight: 600;
    font-size: 0.8125rem;
    color: var(--text-primary);
}

.panel-body {
    padding: 1rem;
}

/* Controls Panel */
.controls-panel {
    background: var(--bg-secondary);
    border: 1px solid var(--border-primary);
    box-shadow: 0 1px 2px rgba(0,0,0,0.08);
    margin-bottom: 1.25rem;
}

.controls-header {
    background: linear-gradient(to bottom, #F5F7FA 0%, #E8ECF1 100%);
    padding: 0.625rem 1rem;
    border-bottom: 2px solid var(--border-primary);
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.controls-icon {
    width: 24px;
    height: 24px;
    background: var(--primary);
    display: flex;
    align-items: center;
    justify-content: center;
    color: white;
    font-size: 0.75rem;
    border: 1px solid var(--primary-dark);
}

.controls-header h2 {
    font-size: 0.8125rem;
    font-weight: 600;
    color: var(--text-primary);
}

.controls-grid {
    display: grid;
    grid-template-columns: 140px 180px 180px 1fr;
    gap: 1rem;
    align-items: end;
    padding: 1rem;
    background: var(--bg-panel);
}

.control-group label {
    display: block;
    font-size: 0.6875rem;
    font-weight: 600;
    color: var(--text-secondary);
    margin-bottom: 0.375rem;
}

select, input[type="text"], input[type="number"], input[type="date"] {
    width: 100%;
    padding: 0.375rem 0.5rem;
    border: 1px solid var(--border-primary);
    font-size: 0.75rem;
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    background: white;
    color: var(--text-primary);
    box-shadow: inset 0 1px 2px rgba(0,0,0,0.05);
}

select:hover, input:hover {
    border-color: var(--border-dark);
}

select:focus, input:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 3px rgba(46, 92, 138, 0.3), inset 0 1px 2px rgba(0,0,0,0.05);
}

select {
    cursor: pointer;
    appearance: none;
    background-image: url("data:image/svg+xml,%3Csvg width='10' height='6' viewBox='0 0 10 6' fill='none' xmlns='http://www.w3.org/2000/svg'%3E%3Cpath d='M1 1L5 5L9 1' stroke='%23555555' stroke-width='1.5' stroke-linecap='square'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 0.5rem center;
    padding-right: 1.75rem;
}

/* Analytics & Table Sections */
.analytics-section, .data-table-section {
    background: var(--bg-secondary);
    border: 1px solid var(--border-primary);
    box-shadow: 0 1px 2px rgba(0,0,0,0.08);
    margin-bottom: 1.25rem;
}

.section-header {
    background: linear-gradient(to bottom, #F5F7FA 0%, #E8ECF1 100%);
    padding: 0.75rem 1rem;
    border-bottom: 2px solid var(--border-primary);
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.section-title {
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.section-title-icon {
    width: 28px;
    height: 28px;
    background: var(--info);
    border: 1px solid #2A6A89;
    display: flex;
    align-items: center;
    justify-content: center;
    color: white;
    font-size: 0.875rem;
}

.section-title h2 {
    font-size: 0.875rem;
    font-weight: 600;
    color: var(--text-primary);
}

.chart-wrapper {
    background: var(--bg-panel);
    padding: 1rem;
    margin: 1rem;
    border: 1px solid var(--border-secondary);
}

.graph-canvas {
    height: 380px;
    position: relative;
    background: white;
    padding: 0.75rem;
    border: 1px solid var(--border-light);
}

/* Metrics Grid */
.metrics-grid {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 1rem;
    padding: 1rem;
    background: var(--bg-panel);
}

.metric-card {
    background: white;
    border: 1px solid var(--border-primary);
    box-shadow: 0 1px 2px rgba(0,0,0,0.05);
}

.metric-header {
    padding: 0.625rem 0.875rem;
    border-bottom: 1px solid var(--border-secondary);
    display: flex;
    justify-content: space-between;
    align-items: center;
    background: linear-gradient(to bottom, #FAFBFC 0%, #F5F7FA 100%);
}

.metric-label {
    font-size: 0.6875rem;
    font-weight: 600;
    color: var(--text-secondary);
    text-transform: uppercase;
}

.metric-icon {
    width: 28px;
    height: 28px;
    border: 1px solid;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 0.875rem;
    font-weight: bold;
    background: white;
}

.metric-card.danger .metric-icon {
    border-color: var(--danger);
    color: var(--danger);
}

.metric-card.success .metric-icon {
    border-color: var(--success);
    color: var(--success);
}

.metric-card.info .metric-icon {
    border-color: var(--info);
    color: var(--info);
}

.metric-value {
    padding: 1rem 0.875rem;
    font-size: 1.625rem;
    font-weight: 700;
    font-family: 'Courier New', Courier, monospace;
    line-height: 1;
}

.metric-card.danger .metric-value {
    color: var(--danger);
}

.metric-card.success .metric-value {
    color: var(--success);
}

.metric-card.info .metric-value {
    color: var(--info);
}

/* Data Table */
.table-header {
    padding: 0.75rem 1rem;
    background: linear-gradient(to bottom, #F5F7FA 0%, #E8ECF1 100%);
    border-bottom: 2px solid var(--border-primary);
}

.table-header h2 {
    font-size: 0.875rem;
    font-weight: 600;
    color: var(--text-primary);
}

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

.data-table {
    width: 100%;
    border-collapse: collapse;
    background: white;
}

.data-table thead {
    background: linear-gradient(to bottom, #F0F2F5 0%, #E5E8EC 100%);
}

.data-table th {
    padding: 0.5rem 0.75rem;
    text-align: left;
    font-size: 0.6875rem;
    font-weight: 700;
    color: var(--text-secondary);
    border-bottom: 2px solid var(--border-dark);
    border-right: 1px solid var(--border-secondary);
    white-space: nowrap;
}

.data-table th:last-child {
    border-right: none;
}

.data-table tbody tr {
    border-bottom: 1px solid var(--border-light);
    cursor: pointer;
}

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

.data-table td {
    padding: 0.625rem 0.75rem;
    font-size: 0.75rem;
    border-right: 1px solid var(--border-light);
}

.data-table td:last-child {
    border-right: none;
}

.company-info {
    display: flex;
    flex-direction: column;
    gap: 0.1875rem;
}

.company-name {
    font-weight: 600;
    color: var(--text-primary);
    font-size: 0.8125rem;
}

.company-code {
    font-family: 'Courier New', Courier, monospace;
    color: var(--text-tertiary);
    font-size: 0.6875rem;
}

.amount-cell {
    font-family: 'Courier New', Courier, monospace;
    font-weight: 600;
    font-size: 0.8125rem;
}

.balance-info {
    display: flex;
    flex-direction: column;
    align-items: flex-end;
    gap: 0.1875rem;
}

.balance-amount {
    font-family: 'Courier New', Courier, monospace;
    font-weight: 700;
    font-size: 0.875rem;
}

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

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

.balance-status {
    font-size: 0.625rem;
    font-weight: 600;
    text-transform: uppercase;
    padding: 0.125rem 0.375rem;
    border: 1px solid;
}

.balance-status.paid {
    background: #E8F5E9;
    color: #2D8659;
    border-color: #A5D6A7;
}

.balance-status.owes {
    background: #FFEBEE;
    color: #B94A48;
    border-color: #EF9A9A;
}

.balance-status.clear {
    background: #F5F5F5;
    color: var(--text-secondary);
    border-color: var(--border-secondary);
}

/* Modal */
.modal {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.5);
    z-index: 1000;
    align-items: center;
    justify-content: center;
    padding: 1.5rem;
}

.modal.active {
    display: flex;
}

.modal-content {
    background: var(--bg-secondary);
    max-width: 1600px;
    width: 100%;
    max-height: 90vh;
    overflow: hidden;
    box-shadow: 0 4px 12px rgba(0,0,0,0.3);
    display: flex;
    flex-direction: column;
    border: 2px solid var(--border-dark);
}

.modal-header {
    padding: 0.875rem 1.25rem;
    border-bottom: 2px solid var(--border-primary);
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    background: linear-gradient(to bottom, #F5F7FA 0%, #E8ECF1 100%);
}

.modal-title-section h2 {
    font-size: 1rem;
    font-weight: 600;
    color: var(--text-primary);
    margin-bottom: 0.25rem;
}

.modal-meta {
    font-family: 'Courier New', Courier, monospace;
    color: var(--text-secondary);
    font-size: 0.6875rem;
}

.close-btn {
    background: white;
    border: 1px solid var(--border-dark);
    width: 28px;
    height: 28px;
    cursor: pointer;
    font-size: 1rem;
    color: var(--text-secondary);
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 1px 2px rgba(0,0,0,0.1);
}

.close-btn:hover {
    background: #FFEBEE;
    border-color: var(--danger);
    color: var(--danger);
}

.close-btn:active {
    box-shadow: inset 0 1px 2px rgba(0,0,0,0.2);
}

.modal-body {
    padding: 1.25rem;
    overflow-y: auto;
    flex: 1;
    background: var(--bg-panel);
}

/* Financial Sections */
.financial-sections {
    display: grid;
    gap: 1.25rem;
}

.financial-section {
    border: 1px solid var(--border-primary);
    background: white;
    box-shadow: 0 1px 2px rgba(0,0,0,0.05);
}

.financial-section-header {
    padding: 0.75rem 1rem;
    display: flex;
    justify-content: space-between;
    align-items: center;
    border-bottom: 2px solid;
}

.financial-section-header.payables {
    background: linear-gradient(to bottom, #FFEBEE 0%, #FFCDD2 100%);
    border-bottom-color: var(--danger);
}

.financial-section-header.collections {
    background: linear-gradient(to bottom, #E8F5E9 0%, #C8E6C9 100%);
    border-bottom-color: var(--success);
}

.financial-section-header.receivables {
    background: linear-gradient(to bottom, #E3F2FD 0%, #BBDEFB 100%);
    border-bottom-color: var(--info);
}

.section-header-left {
    display: flex;
    align-items: center;
    gap: 0.625rem;
}

.section-header-icon {
    width: 32px;
    height: 32px;
    border: 1px solid;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 0.875rem;
    font-weight: bold;
}

.financial-section-header.payables .section-header-icon {
    background: var(--danger);
    color: white;
    border-color: var(--danger-light);
}

.financial-section-header.collections .section-header-icon {
    background: var(--success);
    color: white;
    border-color: var(--success-light);
}

.financial-section-header.receivables .section-header-icon {
    background: var(--info);
    color: white;
    border-color: #5BA4CF;
}

.section-header-left h3 {
    font-size: 0.8125rem;
    font-weight: 700;
    text-transform: uppercase;
}

.financial-section-header.payables h3 {
    color: var(--danger);
}

.financial-section-header.collections h3 {
    color: var(--success);
}

.financial-section-header.receivables h3 {
    color: var(--info);
}

.section-total {
    font-size: 1.125rem;
    font-weight: 700;
    font-family: 'Courier New', Courier, monospace;
}

.financial-section-header.payables .section-total {
    color: var(--danger);
}

.financial-section-header.collections .section-total {
    color: var(--success);
}

.financial-section-header.receivables .section-total {
    color: var(--info);
}

.section-content {
    padding: 1rem;
    background: var(--bg-panel);
}

/* Buttons */
.btn-primary {
    background: linear-gradient(to bottom, var(--primary-light) 0%, var(--primary) 100%);
    color: white;
    border: 1px solid var(--primary-dark);
    padding: 0.375rem 0.875rem;
    font-weight: 600;
    cursor: pointer;
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    font-size: 0.75rem;
    box-shadow: 0 1px 2px rgba(0,0,0,0.15);
    text-shadow: 0 -1px 0 rgba(0,0,0,0.2);
}

.btn-primary:hover {
    background: linear-gradient(to bottom, #5A8FCC 0%, var(--primary-light) 100%);
}

.btn-primary:active {
    box-shadow: inset 0 1px 3px rgba(0,0,0,0.3);
}

.btn-secondary {
    background: linear-gradient(to bottom, #FFFFFF 0%, #F0F0F0 100%);
    color: var(--text-primary);
    border: 1px solid var(--border-dark);
    padding: 0.375rem 0.875rem;
    font-weight: 600;
    cursor: pointer;
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    font-size: 0.75rem;
    box-shadow: 0 1px 2px rgba(0,0,0,0.1);
}

.btn-secondary:hover {
    background: linear-gradient(to bottom, #FFFFFF 0%, #E8E8E8 100%);
}

.btn-secondary:active {
    box-shadow: inset 0 1px 3px rgba(0,0,0,0.2);
}

/* Transactions */
.transactions-list {
    display: grid;
    gap: 0.625rem;
    margin-top: 1rem;
}

.transaction-item {
    background: white;
    padding: 0.75rem;
    border: 1px solid var(--border-secondary);
    display: grid;
    grid-template-columns: 1fr auto;
    gap: 0.875rem;
    align-items: start;
    box-shadow: 0 1px 1px rgba(0,0,0,0.05);
}

.transaction-item.overdue {
    border-left: 3px solid var(--danger);
    background: #FFF5F5;
}

.transaction-item.warning {
    border-left: 3px solid var(--warning);
    background: #FFFBF0;
}

.transaction-desc {
    font-weight: 600;
    font-size: 0.8125rem;
    margin-bottom: 0.375rem;
    color: var(--text-primary);
}

.transaction-meta {
    display: flex;
    gap: 1rem;
    font-size: 0.6875rem;
    color: var(--text-secondary);
    flex-wrap: wrap;
}

.transaction-amount {
    font-size: 1rem;
    font-weight: 700;
    font-family: 'Courier New', Courier, monospace;
    color: var(--text-primary);
}

.status-badge {
    display: inline-flex;
    align-items: center;
    padding: 0.1875rem 0.375rem;
    font-size: 0.625rem;
    font-weight: 700;
    text-transform: uppercase;
    border: 1px solid;
}

.status-badge.paid {
    background: var(--success);
    color: white;
    border-color: #267A4D;
}

.status-badge.overdue {
    background: var(--danger);
    color: white;
    border-color: #A03E3C;
}

.status-badge.warning {
    background: var(--warning);
    color: white;
    border-color: #B06504;
}

.status-badge.source {
    background: #E3F2FD;
    color: var(--info);
    border-color: #90CAF9;
}

/* Add Form */
.add-form {
    background: #FFFBF0;
    padding: 1rem;
    border: 2px solid var(--warning);
    margin-bottom: 0.875rem;
    display: none;
}

.add-form.active {
    display: block;
}

.form-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
    gap: 0.75rem;
    margin-bottom: 0.875rem;
}

.form-group label {
    display: block;
    font-size: 0.6875rem;
    font-weight: 700;
    color: var(--text-secondary);
    margin-bottom: 0.375rem;
}

.form-actions {
    display: flex;
    gap: 0.625rem;
    justify-content: flex-end;
}

/* Empty State */
.empty-state {
    text-align: center;
    padding: 2.5rem 1.5rem;
    color: var(--text-tertiary);
    border: 1px dashed var(--border-secondary);
    background: var(--bg-tertiary);
}

.empty-state-icon {
    font-size: 2.5rem;
    margin-bottom: 0.625rem;
    opacity: 0.4;
}

.empty-state p {
    font-size: 0.8125rem;
}

/* Responsive */
@media (max-width: 1400px) {
    .controls-grid {
        grid-template-columns: repeat(2, 1fr);
    }
}

@media (max-width: 1024px) {
    .container {
        padding: 1rem 1.25rem;
    }

    .metrics-grid {
        grid-template-columns: 1fr;
    }

    .controls-grid {
        grid-template-columns: 1fr;
    }
}

@media (max-width: 768px) {
    .header h1 {
        font-size: 1rem;
    }

    .data-table {
        min-width: 900px;
    }

    .logo-container {
        width: 40px;
        height: 40px;
    }
}