*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html { -webkit-text-size-adjust: 100%; }
body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
    background: #0f1923;
    color: #e0e0e0;
    min-height: 100vh;
    padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left);
}
.container { max-width: 1200px; margin: 0 auto; padding: 12px; }

.header {
    background: linear-gradient(135deg, #1a2a3a 0%, #0f1923 100%);
    padding: 16px 20px;
    border-radius: 16px;
    margin-bottom: 12px;
    border: 1px solid #2a3a4a;
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-wrap: wrap;
    gap: 8px;
}
.header h1 { font-size: 20px; font-weight: 700; color: #fff; letter-spacing: 0.5px; }
.header h1 span { color: #4fc3f7; }
.header-actions { display: flex; gap: 8px; flex-wrap: wrap; }
.header-actions .save-indicator {
    font-size: 11px; color: #78909c;
    display: flex; align-items: center; gap: 4px;
}
.header-actions .save-indicator .dot {
    width: 6px; height: 6px; border-radius: 50%; display: inline-block;
}
.header-actions .save-indicator .dot.saved { background: #66bb6a; }
.header-actions .save-indicator .dot.dirty { background: #ffa726; animation: pulse 1s infinite; }
@keyframes pulse { 0%, 100% { opacity: 1; } 50% { opacity: 0.4; } }

.toolbar {
    display: flex; gap: 8px; margin-bottom: 12px; flex-wrap: wrap;
}
.toolbar button, .btn {
    background: #1e2d3d; color: #b0bec5;
    border: 1px solid #2a3a4a; padding: 8px 14px;
    border-radius: 10px; font-size: 13px; font-weight: 600;
    cursor: pointer; transition: all 0.2s;
    touch-action: manipulation; -webkit-tap-highlight-color: transparent;
    white-space: nowrap;
}
.toolbar button:hover, .btn:hover { background: #2a3a4a; color: #fff; }
.toolbar button:active, .btn:active { transform: scale(0.96); }
.btn-primary {
    background: linear-gradient(135deg, #1565c0, #1976d2);
    color: #fff; border-color: #1976d2;
}
.btn-primary:hover { background: linear-gradient(135deg, #1976d2, #2196f3); }
.btn-danger {
    background: linear-gradient(135deg, #c62828, #e53935);
    color: #fff; border-color: #e53935;
}
.btn-danger:hover { background: linear-gradient(135deg, #e53935, #ef5350); }
.btn-warning {
    background: linear-gradient(135deg, #e65100, #f57c00);
    color: #fff; border-color: #f57c00;
}
.btn-success {
    background: linear-gradient(135deg, #2e7d32, #43a047);
    color: #fff; border-color: #43a047;
}

.stats-row {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
    gap: 8px; margin-bottom: 16px;
}
.stat-card {
    background: #1a2a3a; border-radius: 14px;
    padding: 14px 12px; border: 1px solid #2a3a4a;
    text-align: center;
}
.stat-card .label {
    font-size: 11px; color: #78909c;
    text-transform: uppercase; letter-spacing: 0.5px;
    margin-bottom: 4px;
}
.stat-card .value { font-size: 18px; font-weight: 700; color: #fff; }
.stat-card .value.positive { color: #66bb6a; }
.stat-card .value.negative { color: #ef5350; }
.stat-card .value.neutral { color: #90a4ae; }

.stat-card.editable {
    cursor: pointer; border-color: #3a5a7a; position: relative;
}
.stat-card.editable:active { transform: scale(0.97); }
.stat-card.editable::after {
    content: 'tap to edit'; position: absolute;
    top: 4px; right: 8px; font-size: 8px;
    color: #546e7a; text-transform: uppercase; letter-spacing: 0.5px;
}

.tabs-container {
    display: flex; gap: 4px; overflow-x: auto;
    -webkit-overflow-scrolling: touch; padding-bottom: 4px;
    margin-bottom: 12px; scrollbar-width: none;
}
.tabs-container::-webkit-scrollbar { display: none; }
.tab {
    flex: 0 0 auto; background: #1e2d3d; color: #90a4ae;
    border: 1px solid #2a3a4a; padding: 8px 16px;
    border-radius: 20px; font-size: 13px; font-weight: 600;
    cursor: pointer; transition: all 0.2s;
    touch-action: manipulation; -webkit-tap-highlight-color: transparent;
    white-space: nowrap; display: flex; align-items: center; gap: 6px;
}
.tab.active {
    background: linear-gradient(135deg, #1565c0, #1976d2);
    color: #fff; border-color: #1976d2;
}
.tab .close {
    width: 16px; height: 16px; border-radius: 50%;
    background: rgba(255,255,255,0.15); border: none;
    color: inherit; font-size: 11px; cursor: pointer;
    display: flex; align-items: center; justify-content: center;
    line-height: 1; padding: 0;
}
.tab .close:hover { background: rgba(255,255,255,0.3); }

.panel {
    background: #1a2a3a; border-radius: 16px;
    padding: 16px; margin-bottom: 12px; border: 1px solid #2a3a4a;
}
.panel h2 {
    font-size: 16px; font-weight: 600; color: #fff; margin-bottom: 12px;
}
.panel h2 .sub {
    font-size: 12px; font-weight: 400; color: #78909c;
}

.input-grid {
    display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-bottom: 12px;
}
.input-group { display: flex; flex-direction: column; gap: 4px; }
.input-group label { font-size: 12px; font-weight: 600; color: #90a4ae; }
.input-group input, .input-group select {
    background: #0f1923; border: 1px solid #2a3a4a;
    border-radius: 10px; padding: 10px 12px; font-size: 15px;
    color: #fff; transition: border-color 0.2s;
    width: 100%; -webkit-appearance: none; appearance: none;
}
.input-group input:focus, .input-group select:focus {
    outline: none; border-color: #1976d2;
}
.input-group select {
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 12 12'%3E%3Cpath fill='%2390a4ae' d='M6 8L1 3h10z'/%3E%3C/svg%3E");
    background-repeat: no-repeat; background-position: right 10px center;
    padding-right: 30px;
}
.input-group input[type="date"] { min-height: 42px; }
.input-group input::placeholder { color: #546e7a; }
.btn-full { width: 100%; padding: 12px; font-size: 15px; }

.chart-container {
    display: flex; align-items: center; justify-content: center;
    gap: 16px; flex-wrap: wrap;
}
.chart-container canvas { max-width: 180px; max-height: 180px; }
.chart-legend { display: flex; flex-direction: column; gap: 6px; font-size: 12px; }
.chart-legend .legend-item { display: flex; align-items: center; gap: 6px; }
.chart-legend .legend-color {
    width: 10px; height: 10px; border-radius: 3px; flex-shrink: 0;
}
.chart-legend .legend-label { color: #b0bec5; }
.chart-legend .legend-value { color: #fff; font-weight: 600; margin-left: auto; }

.table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; margin: 0 -16px; padding: 0 16px; }
table { width: 100%; border-collapse: collapse; font-size: 13px; min-width: 600px; }
th {
    background: #0f1923; color: #78909c; font-weight: 600;
    font-size: 11px; text-transform: uppercase; letter-spacing: 0.5px;
    padding: 10px 8px; text-align: left; border-bottom: 1px solid #2a3a4a;
    white-space: nowrap;
}
td {
    padding: 10px 8px; border-bottom: 1px solid #1e2d3d; color: #cfd8dc;
}
tr:last-child td { border-bottom: none; }
.action-buy { color: #66bb6a; font-weight: 600; }
.action-sell { color: #ef5350; font-weight: 600; }
.td-actions { white-space: nowrap; }
.td-actions button {
    background: none; border: 1px solid #2a3a4a;
    color: #90a4ae; padding: 4px 8px; border-radius: 6px;
    font-size: 11px; cursor: pointer; margin-right: 4px; touch-action: manipulation;
}
.td-actions button:hover { background: #2a3a4a; color: #fff; }
.td-actions button.del:hover { border-color: #ef5350; color: #ef5350; }

.summary-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(130px, 1fr));
    gap: 8px;
}
.summary-item {
    background: #0f1923; border-radius: 12px; padding: 12px; text-align: center;
}
.summary-item h3 {
    font-size: 11px; color: #78909c; font-weight: 500; margin-bottom: 4px;
}
.summary-item .val { font-size: 16px; font-weight: 700; color: #fff; }
.summary-item .val.positive { color: #66bb6a; }
.summary-item .val.negative { color: #ef5350; }

.modal-overlay {
    display: none; position: fixed; inset: 0;
    background: rgba(0,0,0,0.7); z-index: 1000;
    align-items: flex-end; justify-content: center;
    -webkit-backdrop-filter: blur(4px); backdrop-filter: blur(4px);
}
.modal-overlay.show { display: flex; }
.modal-overlay .modal {
    background: #1a2a3a; border-radius: 20px 20px 0 0;
    padding: 24px 20px env(safe-area-inset-bottom, 20px);
    width: 100%; max-width: 500px; max-height: 85vh;
    overflow-y: auto; animation: slideUp 0.3s ease;
}
@keyframes slideUp {
    from { transform: translateY(100%); }
    to { transform: translateY(0); }
}
.modal-overlay:not(.show) .modal { animation: none; }
.modal h2 { font-size: 18px; font-weight: 700; color: #fff; margin-bottom: 16px; }
.modal .modal-actions { display: flex; gap: 8px; margin-top: 16px; }
.modal .modal-actions button { flex: 1; }

.empty-state {
    text-align: center; padding: 40px 20px; color: #546e7a;
}
.empty-state h3 { font-size: 16px; margin-bottom: 6px; color: #78909c; }
.empty-state p { font-size: 13px; }

.toast {
    position: fixed; bottom: 20px; left: 50%;
    transform: translateX(-50%) translateY(100px);
    background: #1e2d3d; color: #fff;
    padding: 10px 20px; border-radius: 10px;
    font-size: 13px; font-weight: 500; z-index: 2000;
    transition: transform 0.3s ease, opacity 0.3s ease;
    opacity: 0; border: 1px solid #2a3a4a;
    max-width: 90%; text-align: center; pointer-events: none;
}
.toast.show { transform: translateX(-50%) translateY(0); opacity: 1; }

@media (min-width: 768px) {
    .container { padding: 20px; }
    .btn-full { padding: 10px 24px; }
    .input-grid { grid-template-columns: repeat(4, 1fr); }
}
@media (max-width: 480px) {
    .header { padding: 12px 14px; }
    .header h1 { font-size: 17px; }
    .stats-row { grid-template-columns: repeat(2, 1fr); }
    .stat-card { padding: 10px 8px; }
    .stat-card .value { font-size: 16px; }
    .input-grid { grid-template-columns: 1fr 1fr; gap: 8px; }
    .input-group input, .input-group select { padding: 10px; font-size: 14px; }
    .summary-grid { grid-template-columns: repeat(2, 1fr); }
    .panel { padding: 12px; border-radius: 12px; }
    .chart-container canvas { max-width: 140px; max-height: 140px; }
    .toolbar button, .btn { padding: 8px 12px; font-size: 12px; }
}

::-webkit-scrollbar { width: 4px; height: 4px; }
::-webkit-scrollbar-track { background: #0f1923; }
::-webkit-scrollbar-thumb { background: #2a3a4a; border-radius: 2px; }
#fileInput, #csvFileInput { display: none; }
