* { margin: 0; padding: 0; box-sizing: border-box; }
body { font-family: 'Segoe UI', Tahoma, sans-serif; margin: 0; color: #1a1a1a; background: #f0f2f5; line-height: 1.5; padding-top: 60px; }

.section-nav { position: fixed; top: 0; left: 0; right: 0; z-index: 100; background: #1a3a5c; color: white; padding: 10px 20px; display: flex; flex-wrap: wrap; gap: 6px; font-size: 13px; align-items: center; box-shadow: 0 2px 8px rgba(0,0,0,0.3); }
.section-nav a { color: #bee3f8; text-decoration: none; padding: 4px 10px; border-radius: 3px; }
.section-nav a:hover { background: #2d5282; }
.section-nav .nav-title { font-weight: bold; margin-right: 10px; font-size: 14px; }

h1 { text-align: center; color: #1a3a5c; border-bottom: 3px solid #1a3a5c; padding: 15px 0; margin: 0 20px 20px; }
h1 small { font-size: 14px; font-weight: normal; color: #4a5568; }
h2 { color: #2c5282; background: #e8edf3; padding: 10px 15px; border-radius: 5px; margin: 30px 20px 15px; }
h3 { color: #2d3748; padding: 8px 0; border-left: 4px solid #48bb78; padding-left: 12px; margin: 0 0 12px 0; }
h4 { color: #4a5568; margin: 15px 20px 5px; }

table { width: 100%; border-collapse: collapse; margin: 10px 0 20px 0; font-size: 13px; }
th { background: #2d3748; color: white; padding: 10px 8px; text-align: left; font-weight: 600; cursor: pointer; user-select: none; position: relative; }
th:hover { background: #3d4a5c; }
th .sort-indicator { margin-left: 4px; font-size: 10px; }
td { padding: 7px 8px; border-bottom: 1px solid #e2e8f0; }
tr:hover { background: #f7fafc; }
.amount { text-align: right; font-family: 'Consolas', 'Courier New', monospace; white-space: nowrap; font-size: 15px; font-weight: 700; }
.total-row { font-weight: bold; background: #edf2f7; }
.income { color: #38a169; }
.expense { color: #e53e3e; }
.category-header { background: #e8edf3; padding: 8px 12px; font-weight: bold; border-radius: 4px; margin: 10px 0; }

.controls { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; margin: 15px 20px; }
.controls label { font-weight: 600; font-size: 14px; }
.controls select, .controls button { padding: 6px 12px; border-radius: 4px; border: 1px solid #cbd5e0; font-size: 14px; background: white; }
.controls button { background: #2c5282; color: white; border: none; cursor: pointer; }
.controls button:hover { background: #1a3a5c; }
.controls button.danger { background: #c53030; }
.controls button.danger:hover { background: #9b2c2c; }

.debt-box { padding: 15px; border-radius: 5px; font-size: 16px; font-weight: bold; margin: 15px 0; }
.debt-positive { background: #fff5f5; border: 2px solid #e53e3e; color: #e53e3e; }
.debt-negative { background: #f0fff4; border: 2px solid #38a169; color: #38a169; }

.empty-state { text-align: center; padding: 40px; color: #a0aec0; font-size: 16px; }
.loading { text-align: center; padding: 40px; font-size: 18px; color: #4a5568; }
.error { background: #fed7d7; color: #c53030; padding: 15px; border-radius: 5px; margin: 15px 20px; }

.collapsible { margin: 8px 0; }
.collapsible-header { display: flex; justify-content: space-between; align-items: center; cursor: pointer; user-select: none; padding: 6px 0; }
.collapsible-header:hover { opacity: 0.8; }
.collapsible-header .toggle-icon { font-size: 12px; margin-left: 10px; color: #718096; flex-shrink: 0; }
.collapsible-body { display: none; overflow: hidden; }

.summary-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 15px; margin: 15px 20px; }
.summary-item { background: white; padding: 20px; border-radius: 8px; box-shadow: 0 2px 8px rgba(0,0,0,0.1); text-align: center; }
.summary-item .label { font-size: 13px; color: #718096; }
.summary-item .value { font-size: 22px; font-weight: bold; font-family: 'Consolas', monospace; margin-top: 5px; }

/* ======== TABS ======== */
.tab-nav { display: flex; gap: 0; margin: 0 20px; border-bottom: 2px solid #cbd5e0; }
.tab-btn { padding: 10px 24px; background: #e2e8f0; border: none; cursor: pointer; border-radius: 6px 6px 0 0; font-size: 15px; font-weight: 600; color: #4a5568; transition: all 0.15s; }
.tab-btn.active { background: white; color: #1a3a5c; border-bottom: 3px solid #1a3a5c; }
.tab-panel { display: none; }
.tab-panel.active { display: block; }

/* ======== DASHBOARD ======== */
.chart-row { display: flex; gap: 20px; margin: 0 20px 20px 20px; flex-wrap: wrap; }
.chart-card { background: white; border-radius: 8px; padding: 20px; box-shadow: 0 2px 8px rgba(0,0,0,0.1); flex: 1 1 48%; min-width: 400px; }
.chart-card-half { flex: 1 1 45%; min-width: 340px; }
.chart-card h3 { display: flex; justify-content: space-between; align-items: center; }
.chart-select { font-size: 13px; padding: 4px 8px; border-radius: 4px; border: 1px solid #cbd5e0; background: white; color: #4a5568; }
.chart-wrap { position: relative; height: 300px; width: 100%; }
.chart-wrap-sm { height: 280px; }

/* Top counterparties list */
.top-cp-list { max-height: 280px; overflow-y: auto; }
.top-cp-item { display: flex; align-items: center; padding: 8px 0; border-bottom: 1px solid #edf2f7; }
.top-cp-rank { width: 28px; font-weight: bold; color: #a0aec0; text-align: center; }
.top-cp-name { flex: 1; font-size: 13px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.top-cp-bar-wrap { width: 120px; height: 6px; background: #edf2f7; border-radius: 3px; margin: 0 10px; overflow: hidden; }
.top-cp-bar { height: 100%; background: #e53e3e; border-radius: 3px; transition: width 0.3s; }
.top-cp-amount { font-size: 13px; font-weight: 600; font-family: 'Consolas', monospace; color: #e53e3e; white-space: nowrap; min-width: 90px; text-align: right; }

/* Client debts table */
#client-debts table { margin: 0; }
#client-debts .debt-row td { vertical-align: middle; }
.debt-indicator { display: inline-block; width: 10px; height: 10px; border-radius: 50%; margin-right: 6px; }
.debt-indicator.pos { background: #e53e3e; }
.debt-indicator.neg { background: #38a169; }

@media print {
  .section-nav, .controls, .tab-nav { display: none; }
  body { padding-top: 0; }
  .tab-panel { display: block !important; }
}

@media (max-width: 768px) {
  .chart-row { flex-direction: column; }
  .chart-card { min-width: auto; }
  .tab-nav { margin: 0 10px; }
  .tab-btn { padding: 8px 14px; font-size: 13px; }
  .modal-box { width: 95%; margin: 20px; max-height: 90vh; }
  .widget-card { flex: 1 1 100% !important; min-width: auto !important; }
}

/* ======== SETTINGS BUTTON ======== */
.settings-btn { margin-left: auto; background: rgba(255,255,255,0.15); color: white; border: 1px solid rgba(255,255,255,0.3); padding: 4px 12px; border-radius: 4px; cursor: pointer; font-size: 13px; transition: background 0.15s; }
.settings-btn:hover { background: rgba(255,255,255,0.25); }

/* ======== MODAL ======== */
.modal-overlay { position: fixed; top: 0; left: 0; right: 0; bottom: 0; background: rgba(0,0,0,0.5); z-index: 200; display: flex; align-items: flex-start; justify-content: center; padding-top: 60px; }
.modal-box { background: white; border-radius: 10px; width: 650px; max-width: 95vw; max-height: 80vh; overflow-y: auto; box-shadow: 0 10px 40px rgba(0,0,0,0.3); display: flex; flex-direction: column; }
.modal-header { display: flex; justify-content: space-between; align-items: center; padding: 16px 20px; border-bottom: 1px solid #e2e8f0; }
.modal-header h2 { margin: 0; background: none; padding: 0; font-size: 18px; }
.modal-close { background: none; border: none; font-size: 20px; cursor: pointer; color: #a0aec0; padding: 4px 8px; }
.modal-close:hover { color: #e53e3e; }
.modal-body { padding: 20px; flex: 1; }
.modal-footer { padding: 12px 20px; border-top: 1px solid #e2e8f0; display: flex; gap: 8px; justify-content: flex-end; }

/* ======== BUTTONS ======== */
.btn { padding: 8px 16px; border-radius: 5px; border: none; cursor: pointer; font-size: 14px; font-weight: 600; }
.btn-primary { background: #2c5282; color: white; }
.btn-primary:hover { background: #1a3a5c; }
.btn-secondary { background: #e2e8f0; color: #4a5568; }
.btn-secondary:hover { background: #cbd5e0; }
.btn-danger { background: #fc8181; color: white; }
.btn-danger:hover { background: #e53e3e; }

/* ======== WIDGET EDITOR ======== */
.widget-editor { background: #f7fafc; border: 1px solid #e2e8f0; border-radius: 8px; padding: 14px; margin-bottom: 12px; position: relative; }
.widget-editor-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 10px; }
.widget-editor-header .widget-label { font-weight: 600; font-size: 14px; color: #2d3748; }
.widget-editor-row { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.widget-editor-row label { font-size: 13px; color: #4a5568; font-weight: 500; }
.widget-editor-row select { padding: 5px 8px; border-radius: 4px; border: 1px solid #cbd5e0; font-size: 13px; background: white; }
.widget-remove { background: none; border: 1px solid #e2e8f0; padding: 3px 8px; border-radius: 3px; cursor: pointer; font-size: 16px; color: #a0aec0; }
.widget-remove:hover { color: #e53e3e; border-color: #fc8181; }

/* ======== CUSTOM WIDGETS ON DASHBOARD ======== */
#custom-widgets { margin: 0 20px 20px 20px; }
.widget-card { background: white; border-radius: 8px; padding: 16px; box-shadow: 0 2px 8px rgba(0,0,0,0.1); flex: 1 1 48%; min-width: 400px; position: relative; }
.widget-card h3 { padding-right: 30px; }
.widget-card .widget-card-close { position: absolute; top: 12px; right: 14px; background: none; border: none; font-size: 16px; cursor: pointer; color: #cbd5e0; padding: 2px 6px; border-radius: 3px; }
.widget-card .widget-card-close:hover { color: #e53e3e; background: #fff5f5; }
.widget-card-full { flex: 1 1 100%; min-width: auto; }
.widget-total { font-size: 13px; color: #718096; margin-top: 8px; padding-top: 8px; border-top: 1px solid #e2e8f0; }
.widget-total b { color: #2d3748; }
.widget-total .inc { color: #38a169; }
.widget-total .exp { color: #e53e3e; }

/* ======== SATURN MUTUAL SETTLEMENTS REPORT ======== */
.saturn-report { background: white; border-radius: 8px; padding: 30px; margin: 20px 20px 40px 20px; box-shadow: 0 2px 8px rgba(0,0,0,0.1); }
.saturn-report h2 { text-align: center; color: #1a3a5c; border-bottom: 3px solid #1a3a5c; padding-bottom: 12px; margin: 0 0 8px 0; background: none; font-size: 20px; }
.saturn-report h3 { margin: 24px 0 10px 0; }
.saturn-report h4 { color: #2c5282; margin: 20px 0 8px 0; font-size: 16px; }
.saturn-report table { width: 100%; font-size: 13px; margin: 8px 0 16px 0; }
.saturn-report th { background: #2d3748; color: white; padding: 10px 8px; text-align: left; font-weight: 600; cursor: default; }
.saturn-report th:hover { background: #2d3748; }
.saturn-report td { padding: 7px 8px; border-bottom: 1px solid #e2e8f0; }
.saturn-subtitle { text-align: center; color: #4a5568; font-size: 14px; margin-bottom: 16px; line-height: 1.6; }
.saturn-turnover { background: #f0f4ff; border: 1px solid #bee3f8; border-radius: 6px; padding: 12px 18px; margin: 12px 0 20px 0; text-align: center; font-size: 15px; color: #2d3748; }
.saturn-highlight { color: #1a3a5c; font-family: 'Consolas', monospace; font-size: 16px; }
.saturn-final { background: #fff5f5; border: 2px solid #e53e3e; border-radius: 8px; padding: 20px; text-align: center; margin: 24px 0 16px 0; }
.saturn-final p { margin: 6px 0; }
.saturn-debt-amount { font-size: 28px; font-weight: bold; font-family: 'Consolas', monospace; color: #e53e3e; }
.saturn-debt-text { font-size: 14px; color: #718096; font-style: italic; }
.saturn-note { background: #fffbeb; border: 1px solid #f6e05e; border-radius: 6px; padding: 14px 18px; font-size: 14px; color: #744210; line-height: 1.6; }

.login-page { display: flex; align-items: center; justify-content: center; min-height: 100vh; background: #1a3a5c; padding-top: 0; }
.login-box { background: white; border-radius: 10px; padding: 40px; width: 380px; max-width: 90vw; box-shadow: 0 10px 40px rgba(0,0,0,0.3); }
.login-header { text-align: center; margin-bottom: 30px; }
.login-header h1 { color: #1a3a5c; font-size: 22px; border: none; margin: 0; padding: 0; }
.login-header p { color: #718096; font-size: 14px; margin-top: 6px; }
.login-error { background: #fed7d7; color: #c53030; padding: 10px 14px; border-radius: 5px; margin-bottom: 16px; font-size: 14px; text-align: center; }
.login-field { margin-bottom: 16px; }
.login-field label { display: block; font-size: 13px; font-weight: 600; color: #4a5568; margin-bottom: 4px; }
.login-field select,
.login-field input { width: 100%; padding: 10px 12px; border: 1px solid #cbd5e0; border-radius: 5px; font-size: 15px; color: #2d3748; background: white; box-sizing: border-box; }
.login-field select:focus,
.login-field input:focus { outline: none; border-color: #2c5282; box-shadow: 0 0 0 3px rgba(44,82,130,0.15); }
.login-btn { width: 100%; padding: 12px; background: #2c5282; color: white; border: none; border-radius: 5px; font-size: 16px; font-weight: 600; cursor: pointer; margin-top: 8px; transition: background 0.15s; }
.login-btn:hover { background: #1a3a5c; }
