:root {
    --bg: #0a0a0f;
    --bg2: #12121a;
    --bg3: #1a1a2e;
    --bg4: #222240;
    --border: #2a2a4a;
    --text: #e8e8f0;
    --text2: #9999bb;
    --primary: #6c5ce7;
    --primary2: #a29bfe;
    --green: #00b894;
    --green2: #55efc4;
    --red: #d63031;
    --red2: #ff7675;
    --orange: #e17055;
    --yellow: #fdcb6e;
    --blue: #0984e3;
    --pink: #e84393;
    --radius: 12px;
    --shadow: 0 4px 24px rgba(0,0,0,0.3);
}

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: 'Inter', -apple-system, sans-serif;
    background: var(--bg);
    color: var(--text);
    min-height: 100vh;
    line-height: 1.6;
}

.app {
    max-width: 1400px;
    margin: 0 auto;
    padding: 20px;
}

/* Header */
.header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 20px 24px;
    background: var(--bg2);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    margin-bottom: 24px;
    flex-wrap: wrap;
    gap: 16px;
}

.header-left {
    display: flex;
    align-items: center;
    gap: 12px;
}

.header h1 {
    font-size: 1.8rem;
    font-weight: 800;
    background: linear-gradient(135deg, var(--primary2), var(--green2));
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
}

.badge {
    background: var(--primary);
    color: white;
    padding: 4px 10px;
    border-radius: 20px;
    font-size: 0.7rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 1px;
}

.header-right {
    display: flex;
    align-items: center;
    gap: 12px;
    flex-wrap: wrap;
}

.rate-display {
    display: flex;
    align-items: center;
    gap: 6px;
    background: var(--bg3);
    padding: 8px 14px;
    border-radius: 8px;
    font-size: 0.85rem;
}

.rate-label { color: var(--text2); }
.rate-value { font-weight: 700; color: var(--yellow); font-size: 1rem; }
.rate-status { font-size: 0.8rem; }

/* Buttons */
.btn {
    padding: 8px 16px;
    border: 1px solid var(--border);
    border-radius: 8px;
    background: var(--bg3);
    color: var(--text);
    cursor: pointer;
    font-family: inherit;
    font-size: 0.85rem;
    font-weight: 500;
    transition: all 0.2s;
}

.btn:hover { background: var(--bg4); transform: translateY(-1px); }

.btn-primary {
    background: var(--primary);
    border-color: var(--primary);
    color: white;
}

.btn-primary:hover { background: #5a4bd6; }

.btn-sm { padding: 6px 12px; font-size: 0.8rem; }

.btn-danger { border-color: var(--red); color: var(--red); }
.btn-danger:hover { background: var(--red); color: white; }

/* KPI Grid */
.kpi-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 16px;
    margin-bottom: 24px;
}

.kpi-card {
    background: var(--bg2);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 20px;
    display: flex;
    align-items: center;
    gap: 16px;
    transition: all 0.3s;
    position: relative;
    overflow: hidden;
}

.kpi-card::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    height: 3px;
}

.kpi-revenue::before { background: var(--blue); }
.kpi-cost::before { background: var(--orange); }
.kpi-profit::before { background: var(--green); }
.kpi-annual::before { background: var(--green2); }
.kpi-margin::before { background: var(--yellow); }
.kpi-best::before { background: var(--pink); }

.kpi-card:hover { transform: translateY(-2px); box-shadow: var(--shadow); }

.kpi-icon { font-size: 2rem; }

.kpi-content { display: flex; flex-direction: column; }

.kpi-label { font-size: 0.75rem; color: var(--text2); text-transform: uppercase; letter-spacing: 0.5px; font-weight: 600; }

.kpi-value { font-size: 1.4rem; font-weight: 800; }

.kpi-profit .kpi-value { color: var(--green2); }
.kpi-annual .kpi-value { color: var(--green); }
.kpi-cost .kpi-value { color: var(--orange); }

/* Sections */
.section {
    margin-bottom: 24px;
}

.section-title {
    font-size: 1.2rem;
    font-weight: 700;
    margin-bottom: 16px;
    padding-bottom: 8px;
    border-bottom: 1px solid var(--border);
}

/* Account Grid */
.account-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(300px, 1fr));
    gap: 16px;
}

.account-card {
    background: var(--bg2);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 16px 20px;
}

.account-card h3 {
    font-size: 0.85rem;
    color: var(--primary2);
    margin-bottom: 8px;
    word-break: break-all;
}

.account-stats {
    display: flex;
    gap: 16px;
    flex-wrap: wrap;
}

.account-stat {
    display: flex;
    flex-direction: column;
}

.account-stat-label { font-size: 0.7rem; color: var(--text2); text-transform: uppercase; }
.account-stat-value { font-size: 1.1rem; font-weight: 700; }

/* Platform Grid */
.platform-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
    gap: 16px;
}

.platform-card {
    background: var(--bg2);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 16px 20px;
    text-align: center;
}

.platform-card h3 { font-size: 1rem; margin-bottom: 8px; color: var(--primary2); }
.platform-card .platform-count { font-size: 2rem; font-weight: 800; }
.platform-card .platform-detail { font-size: 0.8rem; color: var(--text2); margin-top: 4px; }

/* Charts */
.charts-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(320px, 1fr));
    gap: 16px;
}

.chart-card {
    background: var(--bg2);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 20px;
}

.chart-card h3 {
    font-size: 0.9rem;
    color: var(--text2);
    margin-bottom: 16px;
    font-weight: 600;
}

.chart-container {
    position: relative;
    min-height: 200px;
}

/* Bar chart */
.bar-chart {
    display: flex;
    align-items: flex-end;
    gap: 8px;
    height: 180px;
    padding-top: 20px;
}

.bar-item {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 4px;
    min-width: 0;
}

.bar {
    width: 100%;
    max-width: 60px;
    border-radius: 6px 6px 0 0;
    min-height: 4px;
    transition: all 0.5s ease;
    position: relative;
}

.bar:hover {
    opacity: 0.8;
    transform: scaleX(1.1);
}

.bar-label {
    font-size: 0.65rem;
    color: var(--text2);
    text-align: center;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    max-width: 80px;
}

.bar-value {
    font-size: 0.7rem;
    font-weight: 700;
    color: var(--text);
}

/* Donut chart */
.donut-container {
    display: flex;
    align-items: center;
    gap: 20px;
    flex-wrap: wrap;
    justify-content: center;
}

.donut-svg {
    width: 140px;
    height: 140px;
    transform: rotate(-90deg);
}

.donut-legend {
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.legend-item {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 0.75rem;
}

.legend-dot {
    width: 10px;
    height: 10px;
    border-radius: 50%;
    flex-shrink: 0;
}

/* Horizontal bar */
.h-bar-chart {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.h-bar-item {
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.h-bar-header {
    display: flex;
    justify-content: space-between;
    font-size: 0.75rem;
}

.h-bar-name { color: var(--text); font-weight: 500; }
.h-bar-val { color: var(--text2); }

.h-bar-track {
    height: 24px;
    background: var(--bg);
    border-radius: 6px;
    overflow: hidden;
    display: flex;
}

.h-bar-fill {
    height: 100%;
    border-radius: 6px;
    transition: width 0.6s ease;
    display: flex;
    align-items: center;
    justify-content: flex-end;
    padding-right: 6px;
    font-size: 0.65rem;
    font-weight: 700;
    color: white;
    min-width: fit-content;
}

/* Table */
.table-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-wrap: wrap;
    gap: 12px;
    margin-bottom: 16px;
}

.table-header .section-title { margin-bottom: 0; border-bottom: none; padding-bottom: 0; }

.table-controls {
    display: flex;
    gap: 8px;
}

.select-filter {
    padding: 6px 12px;
    background: var(--bg3);
    border: 1px solid var(--border);
    border-radius: 8px;
    color: var(--text);
    font-family: inherit;
    font-size: 0.8rem;
    cursor: pointer;
}

.table-wrapper {
    overflow-x: auto;
    background: var(--bg2);
    border: 1px solid var(--border);
    border-radius: var(--radius);
}

table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.85rem;
}

thead th {
    background: var(--bg3);
    padding: 12px 14px;
    text-align: left;
    font-weight: 600;
    font-size: 0.75rem;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    color: var(--text2);
    white-space: nowrap;
    position: sticky;
    top: 0;
}

tbody td {
    padding: 10px 14px;
    border-top: 1px solid var(--border);
    white-space: nowrap;
}

tbody tr:hover { background: var(--bg3); }

tbody tr.inactive { opacity: 0.5; }

.rank-badge {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 28px;
    height: 28px;
    border-radius: 50%;
    font-weight: 800;
    font-size: 0.8rem;
}

.rank-1 { background: linear-gradient(135deg, #f9ca24, #f0932b); color: #000; }
.rank-2 { background: linear-gradient(135deg, #dfe6e9, #b2bec3); color: #000; }
.rank-3 { background: linear-gradient(135deg, #e17055, #d63031); color: white; }
.rank-other { background: var(--bg4); color: var(--text2); }

.profit-positive { color: var(--green2); font-weight: 700; }
.profit-zero { color: var(--text2); }
.profit-negative { color: var(--red2); font-weight: 700; }

.margin-badge {
    display: inline-block;
    padding: 2px 8px;
    border-radius: 12px;
    font-size: 0.75rem;
    font-weight: 600;
}

.margin-high { background: rgba(0,184,148,0.2); color: var(--green2); }
.margin-mid { background: rgba(253,203,110,0.2); color: var(--yellow); }
.margin-low { background: rgba(214,48,49,0.2); color: var(--red2); }

.action-btns { display: flex; gap: 4px; }
.action-btns button {
    padding: 4px 8px;
    border: none;
    background: var(--bg4);
    border-radius: 6px;
    cursor: pointer;
    font-size: 0.8rem;
    transition: all 0.2s;
}
.action-btns button:hover { background: var(--primary); }

/* Modal */
.modal-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.7);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1000;
    backdrop-filter: blur(4px);
}

.modal {
    background: var(--bg2);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    width: 90%;
    max-width: 600px;
    max-height: 90vh;
    overflow-y: auto;
    box-shadow: 0 20px 60px rgba(0,0,0,0.5);
}

.modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 20px 24px;
    border-bottom: 1px solid var(--border);
}

.modal-header h2 { font-size: 1.1rem; }

.modal-close {
    background: none;
    border: none;
    color: var(--text2);
    font-size: 1.5rem;
    cursor: pointer;
    padding: 4px 8px;
    border-radius: 6px;
}

.modal-close:hover { background: var(--bg4); color: var(--text); }

.modal-form { padding: 24px; }

.form-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 16px;
    margin-bottom: 20px;
}

.form-group {
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.form-group label {
    font-size: 0.75rem;
    font-weight: 600;
    color: var(--text2);
    text-transform: uppercase;
    letter-spacing: 0.3px;
}

.form-group input,
.form-group select {
    padding: 10px 12px;
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: 8px;
    color: var(--text);
    font-family: inherit;
    font-size: 0.9rem;
}

.form-group input:focus,
.form-group select:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(108,92,231,0.2);
}

.form-actions {
    display: flex;
    justify-content: flex-end;
    gap: 8px;
}

/* Footer */
.footer {
    text-align: center;
    padding: 20px;
    color: var(--text2);
    font-size: 0.8rem;
    border-top: 1px solid var(--border);
    margin-top: 20px;
    display: flex;
    flex-direction: column;
    gap: 12px;
    align-items: center;
}

.footer-actions {
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
    justify-content: center;
}

/* Responsive */
@media (max-width: 768px) {
    .app { padding: 12px; }
    .header { flex-direction: column; align-items: flex-start; }
    .header h1 { font-size: 1.4rem; }
    .kpi-grid { grid-template-columns: repeat(2, 1fr); }
    .form-grid { grid-template-columns: 1fr; }
    .charts-grid { grid-template-columns: 1fr; }
    .kpi-value { font-size: 1.1rem; }
}

@media (max-width: 480px) {
    .kpi-grid { grid-template-columns: 1fr; }
}

/* Animations */
@keyframes fadeIn {
    from { opacity: 0; transform: translateY(10px); }
    to { opacity: 1; transform: translateY(0); }
}

.kpi-card, .chart-card, .account-card, .platform-card {
    animation: fadeIn 0.4s ease forwards;
}

.kpi-card:nth-child(2) { animation-delay: 0.05s; }
.kpi-card:nth-child(3) { animation-delay: 0.1s; }
.kpi-card:nth-child(4) { animation-delay: 0.15s; }
.kpi-card:nth-child(5) { animation-delay: 0.2s; }
.kpi-card:nth-child(6) { animation-delay: 0.25s; }
