:root {
    --bg: #0f1117;
    --bg-card: #1a1b23;
    --bg-card-hover: #22232d;
    --bg-sidebar: #13141b;
    --border: #2a2b35;
    --text: #e4e4e7;
    --text-muted: #71717a;
    --accent: #3b82f6;
    --accent-hover: #2563eb;
    --green: #22c55e;
    --red: #ef4444;
    --yellow: #eab308;
    --sidebar-width: 240px;
}

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

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    background: var(--bg);
    color: var(--text);
    min-height: 100vh;
}

/* ---- Login Page ---- */
.login-page {
    display: flex;
    align-items: center;
    justify-content: center;
}

.login-container {
    width: 100%;
    max-width: 400px;
    padding: 20px;
}

.login-card {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: 16px;
    padding: 40px 32px;
}

.login-header {
    text-align: center;
    margin-bottom: 32px;
}

.login-header h1 {
    font-size: 1.8rem;
    margin-bottom: 8px;
}

.login-header p {
    color: var(--text-muted);
    font-size: 0.9rem;
}

/* ---- Layout ---- */
.layout {
    display: flex;
    min-height: 100vh;
}

/* ---- Sidebar ---- */
.sidebar {
    width: var(--sidebar-width);
    background: var(--bg-sidebar);
    border-right: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    position: fixed;
    top: 0;
    left: 0;
    bottom: 0;
    z-index: 100;
}

.sidebar-header {
    padding: 24px 20px;
    border-bottom: 1px solid var(--border);
}

.sidebar-header h2 {
    font-size: 1.2rem;
    font-weight: 700;
}

.sidebar-nav {
    flex: 1;
    padding: 12px 8px;
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.nav-item {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px 12px;
    border-radius: 8px;
    color: var(--text-muted);
    text-decoration: none;
    font-size: 0.9rem;
    transition: all 0.15s;
}

.nav-item svg {
    width: 18px;
    height: 18px;
    flex-shrink: 0;
}

.nav-item:hover {
    background: var(--bg-card);
    color: var(--text);
}

.nav-item.active {
    background: var(--bg-card);
    color: var(--accent);
}

.sidebar-footer {
    padding: 12px 8px;
    border-top: 1px solid var(--border);
}

.user-info {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px 12px;
    color: var(--text);
    font-size: 0.85rem;
    font-weight: 500;
}

/* ---- Main Content ---- */
.main-content {
    flex: 1;
    margin-left: var(--sidebar-width);
}

.topbar {
    padding: 20px 32px;
    border-bottom: 1px solid var(--border);
    display: flex;
    align-items: center;
    gap: 16px;
}

.menu-toggle {
    display: none;
    background: none;
    border: none;
    color: var(--text);
    cursor: pointer;
    padding: 4px;
}

.menu-toggle svg {
    width: 24px;
    height: 24px;
}

.page-title {
    font-size: 1.3rem;
    font-weight: 600;
}

.content {
    padding: 32px;
}

/* ---- Debt Card ---- */
.debt-card {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: 16px;
    padding: 32px;
    text-align: center;
    margin-bottom: 24px;
}

.debt-status {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.debt-label {
    color: var(--text-muted);
    font-size: 0.95rem;
}

.debt-amount {
    font-size: 2.2rem;
    font-weight: 700;
}

.debt-amount.positive { color: var(--red); }
.debt-amount.negative { color: var(--green); }
.debt-amount.zero { color: var(--text-muted); }

/* ---- Period Toggle ---- */
.period-toggle {
    display: flex;
    gap: 8px;
    margin-bottom: 24px;
}

.period-btn {
    background: var(--bg-card);
    border: 1px solid var(--border);
    color: var(--text-muted);
}

.period-btn.active {
    background: var(--accent);
    border-color: var(--accent);
    color: white;
}

/* ---- Quick Actions ---- */
.quick-actions {
    display: flex;
    gap: 12px;
    margin-bottom: 32px;
    flex-wrap: wrap;
}

/* ---- Section ---- */
.section {
    margin-bottom: 32px;
}

.section-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 16px;
}

.section-header h2 {
    font-size: 1.1rem;
    font-weight: 600;
}

/* ---- Breakdown List ---- */
.breakdown-list {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.breakdown-item {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: 10px;
    padding: 14px 18px;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.breakdown-info {
    display: flex;
    flex-direction: column;
    gap: 2px;
}

.breakdown-desc {
    font-size: 0.9rem;
    font-weight: 500;
}

.breakdown-meta {
    font-size: 0.8rem;
    color: var(--text-muted);
}

.breakdown-amount {
    font-weight: 600;
    font-size: 0.95rem;
}

.breakdown-amount.positive { color: var(--red); }
.breakdown-amount.negative { color: var(--green); }

/* ---- Receipt Tabs (Multi-receipt scan) ---- */
.receipt-tabs {
    display: flex;
    gap: 8px;
    align-items: center;
    flex-wrap: wrap;
    margin-bottom: 20px;
    padding: 12px 16px;
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: 12px;
}

.receipt-tab {
    background: var(--bg);
    border: 1px solid var(--border);
    color: var(--text-muted);
}

.receipt-tab.active {
    background: var(--accent);
    border-color: var(--accent);
    color: white;
}

.receipt-tab.saved {
    background: rgba(34, 197, 94, 0.15);
    border-color: rgba(34, 197, 94, 0.3);
    color: var(--green);
}

.receipt-tab.saved.active {
    background: var(--green);
    color: white;
}

.receipt-count {
    font-size: 0.8rem;
    color: var(--text-muted);
    margin-left: auto;
}

.receipt-panel {
    margin-bottom: 16px;
}

.save-status {
    display: inline-flex;
}

/* ---- Expense List (History & Recent) ---- */
.expense-list {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.expense-item {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: 10px;
    padding: 16px 18px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    text-decoration: none;
    color: var(--text);
    transition: border-color 0.15s;
    cursor: pointer;
}

.expense-item:hover {
    border-color: var(--accent);
}

.expense-info {
    display: flex;
    align-items: center;
    gap: 14px;
    flex: 1;
    min-width: 0;
}

.expense-receipt-thumb {
    width: 40px;
    height: 40px;
    border-radius: 6px;
    object-fit: cover;
    flex-shrink: 0;
}

.expense-details {
    display: flex;
    flex-direction: column;
    gap: 2px;
    min-width: 0;
}

.expense-desc {
    font-size: 0.9rem;
    font-weight: 500;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.expense-meta {
    font-size: 0.8rem;
    color: var(--text-muted);
}

.expense-amount {
    font-weight: 600;
    font-size: 1rem;
    flex-shrink: 0;
    margin-left: 16px;
}

/* ---- Upload Zone ---- */
.upload-zone {
    border: 2px dashed var(--border);
    border-radius: 16px;
    padding: 48px 24px;
    text-align: center;
    cursor: pointer;
    transition: border-color 0.2s;
    margin-bottom: 16px;
}

.upload-zone:hover, .upload-zone.dragover {
    border-color: var(--accent);
}

.upload-content {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 12px;
    color: var(--text-muted);
}

.upload-content p {
    font-size: 1rem;
    color: var(--text);
}

.scan-preview {
    text-align: center;
    margin-bottom: 16px;
}

.scan-preview img {
    max-width: 300px;
    max-height: 200px;
    border-radius: 12px;
    border: 1px solid var(--border);
    margin-bottom: 8px;
}

/* ---- Receipt Preview (Detail) ---- */
.receipt-preview-large {
    text-align: center;
    margin-bottom: 24px;
}

.receipt-preview-large img {
    max-width: 100%;
    max-height: 300px;
    border-radius: 12px;
    border: 1px solid var(--border);
    cursor: pointer;
    transition: max-height 0.3s;
}

.receipt-preview-large img.expanded {
    max-height: none;
}

/* ---- Loading State ---- */
.loading-state {
    text-align: center;
    padding: 32px;
    color: var(--text-muted);
}

.spinner {
    width: 32px;
    height: 32px;
    border: 3px solid var(--border);
    border-top-color: var(--accent);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
    margin: 0 auto 12px;
}

@keyframes spin {
    to { transform: rotate(360deg); }
}

/* ---- Items Table ---- */
.items-table-wrap {
    overflow-x: auto;
    margin-bottom: 16px;
}

table {
    width: 100%;
    border-collapse: collapse;
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: 12px;
    overflow: hidden;
}

th, td {
    text-align: left;
    padding: 10px 12px;
    border-bottom: 1px solid var(--border);
    font-size: 0.85rem;
}

th {
    background: var(--bg-sidebar);
    color: var(--text-muted);
    font-weight: 600;
    font-size: 0.75rem;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    white-space: nowrap;
}

tr:last-child td {
    border-bottom: none;
}

table input, table select {
    width: 100%;
    padding: 6px 8px;
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: 6px;
    color: var(--text);
    font-size: 0.85rem;
    outline: none;
}

table input:focus, table select:focus {
    border-color: var(--accent);
}

table input[type="number"] {
    width: 90px;
}

td:last-child {
    width: 40px;
    text-align: center;
}

/* ---- Filters ---- */
.filters {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: 12px;
    padding: 16px 20px;
    margin-bottom: 24px;
}

.filter-btn-group {
    display: flex;
    align-items: flex-end;
    gap: 8px;
    padding-bottom: 2px;
}

/* ---- Form ---- */
.form-group {
    margin-bottom: 16px;
}

.form-group label {
    display: block;
    font-size: 0.85rem;
    color: var(--text-muted);
    margin-bottom: 6px;
}

.form-group input,
.form-group select,
.form-group textarea {
    width: 100%;
    padding: 10px 14px;
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: 8px;
    color: var(--text);
    font-size: 0.9rem;
    outline: none;
    transition: border-color 0.15s;
}

.form-group input:focus,
.form-group select:focus {
    border-color: var(--accent);
}

.form-group input::placeholder {
    color: var(--text-muted);
}

.form-row {
    display: flex;
    gap: 16px;
    flex-wrap: wrap;
}

.form-row .form-group {
    min-width: 150px;
}

.flex-1 {
    flex: 1;
}

.form-actions {
    display: flex;
    gap: 8px;
    margin-top: 16px;
}

/* ---- Modal ---- */
.modal-overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.6);
    z-index: 200;
    align-items: center;
    justify-content: center;
    padding: 20px;
}

.modal-overlay.active {
    display: flex;
}

.modal {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: 16px;
    width: 100%;
    max-width: 480px;
    max-height: 90vh;
    overflow-y: auto;
}

.modal-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 20px 24px;
    border-bottom: 1px solid var(--border);
}

.modal-header h2 {
    font-size: 1.1rem;
}

.modal form {
    padding: 24px;
}

.modal-actions {
    display: flex;
    justify-content: flex-end;
    gap: 8px;
    margin-top: 20px;
}

/* ---- Buttons ---- */
.btn {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 10px 18px;
    border: none;
    border-radius: 8px;
    font-size: 0.9rem;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.15s;
    text-decoration: none;
    color: var(--text);
}

.btn-primary {
    background: var(--accent);
    color: white;
}

.btn-primary:hover {
    background: var(--accent-hover);
}

.btn-outline {
    background: transparent;
    border: 1px solid var(--border);
    color: var(--text);
}

.btn-outline:hover {
    border-color: var(--accent);
    color: var(--accent);
}

.btn-danger {
    background: rgba(239, 68, 68, 0.15);
    color: var(--red);
    border: 1px solid rgba(239, 68, 68, 0.3);
}

.btn-danger:hover {
    background: rgba(239, 68, 68, 0.25);
}

.btn-ghost {
    background: transparent;
    color: var(--text-muted);
}

.btn-ghost:hover {
    color: var(--text);
}

.btn-sm {
    padding: 6px 12px;
    font-size: 0.8rem;
}

.btn-full {
    width: 100%;
    justify-content: center;
}

.btn-icon {
    background: none;
    border: none;
    color: var(--text-muted);
    cursor: pointer;
    padding: 6px;
    border-radius: 6px;
    display: inline-flex;
    transition: all 0.15s;
}

.btn-icon svg {
    width: 16px;
    height: 16px;
}

.btn-icon:hover {
    background: var(--bg);
    color: var(--text);
}

.btn-icon.btn-danger-icon:hover {
    color: var(--red);
}

/* ---- Alert ---- */
.alert {
    padding: 12px 16px;
    border-radius: 8px;
    font-size: 0.85rem;
    margin-bottom: 20px;
}

.alert-error {
    background: rgba(239, 68, 68, 0.15);
    color: var(--red);
    border: 1px solid rgba(239, 68, 68, 0.3);
}

.alert-success {
    background: rgba(34, 197, 94, 0.15);
    color: var(--green);
    border: 1px solid rgba(34, 197, 94, 0.3);
}

/* ---- Badges ---- */
.badge {
    font-size: 0.7rem;
    padding: 3px 8px;
    border-radius: 6px;
    font-weight: 600;
}

.badge-shared {
    background: rgba(59, 130, 246, 0.15);
    color: var(--accent);
}

.badge-personal {
    background: rgba(234, 179, 8, 0.15);
    color: var(--yellow);
}

.badge-payment {
    background: rgba(34, 197, 94, 0.15);
    color: var(--green);
}

/* ---- Empty State ---- */
.empty-state {
    text-align: center;
    color: var(--text-muted);
    padding: 40px 20px;
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: 12px;
}

/* ---- Text Utility ---- */
.text-muted { color: var(--text-muted); }
.text-green { color: var(--green); }
.text-red { color: var(--red); }

/* ---- Hidden ---- */
.hidden {
    display: none !important;
}

/* ---- Sidebar Overlay (mobile) ---- */
.sidebar-overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.4);
    z-index: 99;
}

/* ---- Responsive ---- */
@media (max-width: 768px) {
    .sidebar {
        transform: translateX(-100%);
        transition: transform 0.2s;
    }

    .sidebar.open {
        transform: translateX(0);
    }

    .sidebar.open ~ .sidebar-overlay {
        display: block;
    }

    .main-content {
        margin-left: 0;
    }

    .menu-toggle {
        display: block;
    }

    .content {
        padding: 20px 16px;
    }

    .topbar {
        padding: 16px;
    }

    .form-row {
        flex-direction: column;
    }

    .quick-actions {
        flex-direction: column;
    }

    .quick-actions .btn {
        justify-content: center;
    }

    .debt-amount {
        font-size: 1.6rem;
    }

    .expense-item {
        flex-direction: column;
        align-items: flex-start;
        gap: 8px;
    }

    .expense-amount {
        margin-left: 0;
    }

    table {
        font-size: 0.75rem;
    }

    th, td {
        padding: 8px 6px;
    }

    table input[type="number"] {
        width: 70px;
    }
}
