/* ===== CSS Variables ===== */
:root {
    --color-bg: #0a0f1a;
    --color-bg-card: rgba(22, 33, 62, 0.8);
    --color-bg-hover: rgba(30, 45, 80, 0.9);
    --color-border: rgba(99, 122, 159, 0.2);
    --color-text: #e8edf5;
    --color-text-muted: #7a8ba8;
    --color-gold: #f0c14b;
    --color-green: #34d399;
    --color-red: #f87171;
    --color-blue: #60a5fa;
    --font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
    --radius: 16px;
    --radius-sm: 12px;
    --shadow: 0 4px 24px rgba(0, 0, 0, 0.4);
}

*,
*::before,
*::after {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

html {
    font-size: 16px;
    scroll-behavior: smooth;
}

body {
    font-family: var(--font-family);
    background: var(--color-bg);
    color: var(--color-text);
    line-height: 1.6;
    min-height: 100vh;
    -webkit-font-smoothing: antialiased;
}

.app {
    max-width: 900px;
    margin: 0 auto;
    padding: 24px 16px;
}

/* ===== Header ===== */
.header {
    text-align: center;
    margin-bottom: 24px;
    padding-top: 20px;
}

.logo {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 12px;
    margin-bottom: 8px;
}

.logo-icon {
    font-size: 2rem;
}

.logo-text {
    font-size: 2rem;
    font-weight: 800;
    letter-spacing: -0.02em;
}

.text-gold {
    color: var(--color-gold);
}

.text-white {
    color: #fff;
}

.text-red {
    color: var(--color-red) !important;
}

.subtitle {
    color: var(--color-text-muted);
    font-size: 0.95rem;
}

/* ===== Tab Navigation ===== */
.tab-nav {
    display: flex;
    gap: 8px;
    margin-bottom: 24px;
    background: var(--color-bg-card);
    border-radius: var(--radius);
    padding: 6px;
    border: 1px solid var(--color-border);
}

.tab-btn {
    flex: 1;
    padding: 12px 16px;
    border: none;
    background: transparent;
    color: var(--color-text-muted);
    font-size: 0.9rem;
    font-weight: 600;
    font-family: inherit;
    border-radius: var(--radius-sm);
    cursor: pointer;
    transition: all 0.2s;
}

.tab-btn:hover {
    color: var(--color-text);
}

.tab-btn.active {
    background: linear-gradient(135deg, var(--color-gold), #d4a844);
    color: #0a0f1a;
}

.tab-content {
    display: none;
}

.tab-content.active {
    display: block;
}

/* ===== Section Titles ===== */
.section-title {
    font-size: 1.1rem;
    font-weight: 700;
    margin-bottom: 12px;
    text-align: center;
}

.section-subtitle {
    font-size: 0.85rem;
    color: var(--color-text-muted);
    text-align: center;
    margin-bottom: 20px;
}

/* ===== KPI Section ===== */
.kpi-section {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 12px;
    margin-bottom: 28px;
}

.kpi-card {
    background: var(--color-bg-card);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-sm);
    padding: 20px;
    display: flex;
    align-items: center;
    gap: 14px;
    transition: transform 0.2s, border-color 0.2s;
}

.kpi-card:hover {
    transform: translateY(-2px);
    border-color: var(--color-gold);
}

.kpi-balance {
    grid-column: 1 / -1;
    background: linear-gradient(135deg, rgba(52, 211, 153, 0.15), rgba(22, 33, 62, 0.8));
    border-color: rgba(52, 211, 153, 0.3);
}

.kpi-icon {
    font-size: 1.75rem;
    flex-shrink: 0;
}

.kpi-content {
    display: flex;
    flex-direction: column;
}

.kpi-label {
    font-size: 0.7rem;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    color: var(--color-text-muted);
    margin-bottom: 4px;
}

.kpi-value {
    font-size: 1.5rem;
    font-weight: 700;
    color: var(--color-text);
}

.kpi-balance .kpi-value {
    color: var(--color-green);
    font-size: 1.75rem;
}

.kpi-clickable {
    cursor: pointer;
}

.kpi-clickable:hover {
    background: var(--color-bg-hover);
    border-color: var(--color-gold);
}

.kpi-hint {
    font-size: 0.65rem;
    color: var(--color-gold);
    margin-top: 4px;
    opacity: 0.8;
}

/* ===== Highlights ===== */
.highlights-section {
    margin-bottom: 28px;
}

.highlights-list {
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.highlight-card {
    background: linear-gradient(135deg, rgba(240, 193, 75, 0.15), rgba(22, 33, 62, 0.8));
    border: 1px solid rgba(240, 193, 75, 0.3);
    border-radius: var(--radius-sm);
    padding: 14px 16px;
}

.highlight-top {
    display: flex;
    align-items: center;
    gap: 12px;
    margin-bottom: 8px;
}

.highlight-icon {
    font-size: 1.5rem;
}

.highlight-content {
    flex: 1;
}

.highlight-text {
    font-size: 0.9rem;
    font-weight: 500;
}

.highlight-meta {
    font-size: 0.75rem;
    color: var(--color-text-muted);
}

.highlight-amount {
    font-size: 1rem;
    font-weight: 700;
    color: var(--color-gold);
}

.highlight-hinweis {
    font-size: 0.8rem;
    color: var(--color-text-muted);
    font-style: italic;
    padding-left: 36px;
}

/* ===== Month Selector ===== */
.month-selector-section {
    margin-bottom: 28px;
}

.month-grid {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 10px;
}

.month-card {
    background: var(--color-bg-card);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-sm);
    padding: 16px;
    text-align: center;
    cursor: pointer;
    transition: all 0.2s;
}

.month-card:hover {
    background: var(--color-bg-hover);
    border-color: var(--color-gold);
    transform: translateY(-2px);
}

.month-name {
    font-size: 0.85rem;
    font-weight: 600;
    margin-bottom: 4px;
}

.month-amount {
    font-size: 1.1rem;
    font-weight: 700;
    color: var(--color-green);
    margin-bottom: 8px;
}

.month-payers {
    display: flex;
    justify-content: space-between;
    gap: 8px;
    font-size: 0.7rem;
    color: var(--color-text-muted);
}

.month-top,
.month-bottom {
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

/* ===== Monthly Detail ===== */
.monthly-detail {
    margin-bottom: 28px;
}

.monthly-header {
    display: flex;
    align-items: center;
    gap: 16px;
    margin-bottom: 20px;
}

.back-btn {
    background: var(--color-bg-card);
    border: 1px solid var(--color-border);
    color: var(--color-text);
    padding: 8px 16px;
    border-radius: var(--radius-sm);
    cursor: pointer;
    font-family: inherit;
    font-size: 0.85rem;
    transition: all 0.2s;
}

.back-btn:hover {
    border-color: var(--color-gold);
}

.monthly-title {
    font-size: 1.25rem;
    font-weight: 700;
}

.monthly-kpis {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 12px;
    margin-bottom: 20px;
}

.monthly-kpi {
    background: var(--color-bg-card);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-sm);
    padding: 16px;
    text-align: center;
}

.monthly-kpi-label {
    display: block;
    font-size: 0.7rem;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    color: var(--color-text-muted);
    margin-bottom: 4px;
}

.monthly-kpi-value {
    font-size: 1.5rem;
    font-weight: 700;
    color: var(--color-green);
}

.monthly-top-bottom {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 12px;
    margin-bottom: 20px;
}

.top-payer,
.bottom-payer {
    background: var(--color-bg-card);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-sm);
    padding: 16px;
}

.top-payer h3,
.bottom-payer h3 {
    font-size: 0.85rem;
    font-weight: 600;
    margin-bottom: 12px;
    text-align: center;
}

.payer-card {
    display: flex;
    align-items: center;
    gap: 10px;
}

.payer-avatar {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 700;
    font-size: 0.9rem;
    color: #fff;
}

.payer-name {
    flex: 1;
    font-weight: 500;
    font-size: 0.9rem;
}

.payer-amount {
    font-weight: 700;
    font-size: 0.9rem;
    color: var(--color-green);
}

.monthly-all-payers {
    background: var(--color-bg-card);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-sm);
    padding: 16px;
}

.monthly-all-payers h3 {
    font-size: 0.85rem;
    font-weight: 600;
    margin-bottom: 12px;
}

.all-payers-list {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.all-payer-item {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 8px;
    background: rgba(10, 15, 26, 0.4);
    border-radius: 8px;
}

.all-payer-rank {
    width: 24px;
    font-weight: 700;
    font-size: 0.8rem;
    color: var(--color-text-muted);
}

.all-payer-avatar {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 600;
    font-size: 0.75rem;
    color: #fff;
}

.all-payer-name {
    flex: 1;
    font-size: 0.85rem;
}

.all-payer-amount {
    font-weight: 600;
    font-size: 0.85rem;
    color: var(--color-green);
}

/* ===== Charts ===== */
.charts-section {
    display: flex;
    flex-direction: column;
    gap: 16px;
    margin-bottom: 28px;
}

.chart-card {
    background: var(--color-bg-card);
    border: 1px solid var(--color-border);
    border-radius: var(--radius);
    padding: 20px;
    margin-bottom: 20px;
    width: 100%;
}

.chart-title {
    font-size: 0.95rem;
    font-weight: 600;
    margin-bottom: 16px;
    color: var(--color-text);
}

.chart-container {
    width: 100%;
    height: 280px;
}

/* ===== Leaderboard ===== */
.leaderboard-section {
    margin-bottom: 28px;
}

.leaderboard {
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.leaderboard-item {
    display: flex;
    align-items: center;
    gap: 14px;
    padding: 14px 16px;
    background: var(--color-bg-card);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-sm);
    transition: border-color 0.2s;
}

.leaderboard-item:hover {
    border-color: var(--color-gold);
}

.leaderboard-item.rank-1 {
    background: linear-gradient(135deg, rgba(240, 193, 75, 0.2), var(--color-bg-card));
    border-color: rgba(240, 193, 75, 0.4);
}

.leaderboard-item.rank-2 {
    background: linear-gradient(135deg, rgba(192, 192, 192, 0.15), var(--color-bg-card));
    border-color: rgba(192, 192, 192, 0.3);
}

.leaderboard-item.rank-3 {
    background: linear-gradient(135deg, rgba(205, 127, 50, 0.15), var(--color-bg-card));
    border-color: rgba(205, 127, 50, 0.3);
}

.leaderboard-rank {
    font-size: 1.25rem;
    font-weight: 800;
    width: 32px;
    text-align: center;
}

.rank-1 .leaderboard-rank {
    color: #f0c14b;
}

.rank-2 .leaderboard-rank {
    color: #c0c0c0;
}

.rank-3 .leaderboard-rank {
    color: #cd7f32;
}

.leaderboard-avatar {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 700;
    font-size: 0.9rem;
    color: #fff;
}

.leaderboard-name {
    flex: 1;
    font-weight: 500;
}

.leaderboard-role {
    font-size: 0.75rem;
    color: var(--color-text-muted);
}

.leaderboard-amount {
    font-weight: 700;
    color: var(--color-green);
}

/* ===== Persons ===== */
.persons-section {
    margin-bottom: 28px;
}

.persons-group {
    margin-bottom: 24px;
}

.group-title {
    font-size: 1rem;
    font-weight: 600;
    margin-bottom: 14px;
    text-align: center;
}

.group-count {
    color: var(--color-text-muted);
    font-weight: 400;
    font-size: 0.85rem;
}

.persons-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(100px, 1fr));
    gap: 12px;
}

.person-card {
    background: var(--color-bg-card);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-sm);
    padding: 16px 12px;
    text-align: center;
    cursor: pointer;
    transition: all 0.2s;
}

.person-card:hover {
    background: var(--color-bg-hover);
    border-color: var(--color-gold);
    transform: translateY(-3px);
}

.person-avatar {
    width: 48px;
    height: 48px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 700;
    font-size: 1rem;
    color: #fff;
    margin: 0 auto 10px;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
}

.person-name {
    font-size: 0.8rem;
    font-weight: 500;
    color: var(--color-text);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    margin-bottom: 4px;
}

.person-amount {
    font-size: 0.75rem;
    color: var(--color-text-muted);
}

/* ===== Footer ===== */
.footer {
    text-align: center;
    padding: 24px;
    color: var(--color-text-muted);
    font-size: 0.85rem;
}

/* ===== Modal ===== */
.modal-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.75);
    backdrop-filter: blur(4px);
    display: none;
    align-items: center;
    justify-content: center;
    padding: 16px;
    z-index: 1000;
}

.modal-overlay.active {
    display: flex;
}

.modal {
    background: #16213e;
    border: 1px solid var(--color-border);
    border-radius: var(--radius);
    width: 100%;
    max-width: 480px;
    max-height: 80vh;
    overflow: hidden;
    display: flex;
    flex-direction: column;
    box-shadow: var(--shadow);
}

.modal-header {
    display: flex;
    align-items: center;
    gap: 14px;
    padding: 20px;
    border-bottom: 1px solid var(--color-border);
}

.modal-avatar {
    width: 56px;
    height: 56px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 700;
    font-size: 1.25rem;
    color: #fff;
    flex-shrink: 0;
}

.modal-info {
    flex: 1;
}

.modal-name {
    font-size: 1.1rem;
    font-weight: 700;
    margin-bottom: 2px;
}

.modal-role {
    font-size: 0.8rem;
    color: var(--color-text-muted);
}

.modal-close {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    background: rgba(255, 255, 255, 0.1);
    border: none;
    color: var(--color-text-muted);
    font-size: 1.5rem;
    cursor: pointer;
    transition: all 0.2s;
}

.modal-close:hover {
    background: rgba(255, 255, 255, 0.2);
    color: #fff;
}

.modal-stats {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 12px;
    padding: 16px 20px;
    border-bottom: 1px solid var(--color-border);
}

.modal-stat {
    padding: 14px;
    border-radius: var(--radius-sm);
    text-align: center;
}

.stat-income {
    background: rgba(52, 211, 153, 0.1);
    border: 1px solid rgba(52, 211, 153, 0.2);
}

.stat-expense {
    background: rgba(248, 113, 113, 0.1);
    border: 1px solid rgba(248, 113, 113, 0.2);
}

.stat-label {
    display: block;
    font-size: 0.7rem;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    color: var(--color-text-muted);
    margin-bottom: 6px;
}

.stat-income .stat-value {
    color: var(--color-green);
}

.stat-expense .stat-value {
    color: var(--color-red);
}

.stat-value {
    font-size: 1.25rem;
    font-weight: 700;
}

.modal-transactions {
    flex: 1;
    overflow-y: auto;
    padding: 16px 20px;
}

.transaction-group {
    margin-bottom: 20px;
}

.transaction-group-title {
    font-size: 0.8rem;
    font-weight: 600;
    margin-bottom: 10px;
}

.transaction-group-title.income {
    color: var(--color-green);
}

.transaction-group-title.expense {
    color: var(--color-red);
}

.transaction-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 10px 12px;
    background: rgba(10, 15, 26, 0.5);
    border-radius: 8px;
    margin-bottom: 6px;
}

.transaction-category {
    font-size: 0.85rem;
    color: var(--color-text);
}

.transaction-date {
    font-size: 0.7rem;
    color: var(--color-text-muted);
}

.transaction-info {
    flex: 1;
}

.transaction-hinweis {
    font-size: 0.75rem;
    color: var(--color-text-muted);
    font-style: italic;
    margin-top: 4px;
    padding-top: 4px;
    border-top: 1px solid rgba(99, 122, 159, 0.15);
}

.transaction-amount {
    font-weight: 600;
    font-size: 0.9rem;
}

.transaction-amount.positive {
    color: var(--color-green);
}

.transaction-amount.negative {
    color: var(--color-red);
}

.modal-month-context {
    text-align: center;
    padding: 12px;
    margin-bottom: 16px;
    background: rgba(240, 193, 75, 0.1);
    border-radius: var(--radius-sm);
    border: 1px solid rgba(240, 193, 75, 0.2);
}

.month-badge {
    font-size: 0.9rem;
    font-weight: 600;
    color: var(--color-gold);
}

.expand-all-btn {
    width: 100%;
    padding: 14px 20px;
    margin-top: 16px;
    background: var(--color-bg-card);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-sm);
    color: var(--color-text);
    font-family: inherit;
    font-size: 0.9rem;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s;
}

.expand-all-btn:hover {
    background: var(--color-bg-hover);
    border-color: var(--color-gold);
}

/* ===== Transactions View ===== */
.transactions-view {
    margin-bottom: 28px;
}

.transactions-header {
    display: flex;
    align-items: center;
    gap: 16px;
    margin-bottom: 24px;
}

.transactions-header .section-title {
    margin-bottom: 0;
    text-align: left;
}

.filters-container {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 12px;
    margin-bottom: 20px;
    background: var(--color-bg-card);
    border: 1px solid var(--color-border);
    border-radius: var(--radius);
    padding: 16px;
}

.filter-group {
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.filter-label {
    font-size: 0.7rem;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    color: var(--color-text-muted);
}

.filter-select,
.filter-input {
    padding: 10px 12px;
    background: rgba(10, 15, 26, 0.5);
    border: 1px solid var(--color-border);
    border-radius: 8px;
    color: var(--color-text);
    font-family: inherit;
    font-size: 0.85rem;
}

.filter-select:focus,
.filter-input:focus {
    outline: none;
    border-color: var(--color-gold);
}

.results-count {
    font-size: 0.85rem;
    color: var(--color-text-muted);
    margin-bottom: 12px;
}

.table-container {
    background: var(--color-bg-card);
    border: 1px solid var(--color-border);
    border-radius: var(--radius);
    overflow: hidden;
    overflow-x: auto;
}

.transactions-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.85rem;
}

.transactions-table th {
    background: rgba(10, 15, 26, 0.5);
    padding: 12px 16px;
    text-align: left;
    font-weight: 600;
    color: var(--color-text-muted);
    font-size: 0.75rem;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    border-bottom: 1px solid var(--color-border);
}

.transactions-table td {
    padding: 12px 16px;
    border-bottom: 1px solid var(--color-border);
    vertical-align: top;
}

.transactions-table tr:last-child td {
    border-bottom: none;
}

.transactions-table tr:hover {
    background: rgba(255, 255, 255, 0.02);
}

.transactions-table .text-right {
    text-align: right;
}

.transactions-table .amount-positive {
    color: var(--color-green);
    font-weight: 600;
}

.transactions-table .amount-negative {
    color: var(--color-red);
    font-weight: 600;
}

.transactions-table .hinweis-cell {
    color: var(--color-text-muted);
    font-size: 0.8rem;
    max-width: 200px;
}

@media (min-width: 640px) {
    .filters-container {
        grid-template-columns: repeat(4, 1fr);
    }
}

/* ===== Responsive ===== */
@media (min-width: 640px) {
    .app {
        padding: 40px 24px;
    }

    .logo-text {
        font-size: 2.5rem;
    }

    .logo-icon {
        font-size: 2.5rem;
    }

    .kpi-section {
        grid-template-columns: repeat(4, 1fr);
        gap: 16px;
    }

    .kpi-balance {
        grid-column: span 1;
    }

    .kpi-card {
        flex-direction: column;
        text-align: center;
        padding: 24px 16px;
    }

    .kpi-icon {
        font-size: 2rem;
        margin-bottom: 8px;
    }

    .persons-grid {
        grid-template-columns: repeat(auto-fill, minmax(110px, 1fr));
    }

    .month-grid {
        grid-template-columns: repeat(4, 1fr);
    }
}

::-webkit-scrollbar {
    width: 6px;
}

::-webkit-scrollbar-track {
    background: transparent;
}

::-webkit-scrollbar-thumb {
    background: var(--color-border);
    border-radius: 3px;
}

::-webkit-scrollbar-thumb:hover {
    background: var(--color-text-muted);
}