/* style.css — Budget Tracker */

:root {
    --bg: #0a0a0a;
    --surface: #141414;
    --surface-hover: #1e1e1e;
    --border: #252525;
    --border-light: #333;

    --text: #e0e0e0;
    --text-2: #999;
    --text-3: #666;

    --blue: #4e8ef7;
    --green: #34c759;
    --red: #f85149;
    --yellow: #e8b339;

    --radius: 4px;
    --gap: 12px;
}

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

input[type="number"]::-webkit-inner-spin-button,
input[type="number"]::-webkit-outer-spin-button {
    -webkit-appearance: none;
    margin: 0;
}

input[type="number"] {
    -moz-appearance: textbox;
    appearance: textbox;
}

body {
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
    background: var(--bg);
    color: var(--text);
    height: 100vh;
    padding: var(--gap);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    line-height: 1.4;
    font-size: 16px;
}

/* ── Layout ─────────────────────────────────────────────── */

.app-container {
    max-width: 1800px;
    margin: 0 auto;
    width: 100%;
    display: flex;
    flex-direction: column;
    gap: var(--gap);
    flex: 1;
    min-height: 0;
}

header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 8px 16px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
}

header h1 {
    font-size: 18px;
    font-weight: 600;
    letter-spacing: -0.01em;
}

.debt-summary {
    text-align: right;
}

.debt-summary .label {
    font-size: 13px;
    color: var(--text-2);
    text-transform: uppercase;
    letter-spacing: 0.03em;
}

.debt-summary .amount {
    font-size: 20px;
    font-weight: 700;
    font-variant-numeric: tabular-nums;
}

.main-content {
    display: grid;
    grid-template-columns: 5fr 2fr;
    gap: var(--gap);
    flex: 1;
    min-height: 0;
}

@media (max-width: 800px) {
    .main-content {
        grid-template-columns: 1fr;
    }
}

/* ── Panels ─────────────────────────────────────────────── */

.panel {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: var(--gap) 16px;
    display: flex;
    flex-direction: column;
    min-width: 0;
    min-height: 0;
}

.panel-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: var(--gap);
}

.panel-header h2 {
    font-size: 15px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    color: var(--text-2);
}

.subtitle {
    font-size: 13px;
    color: var(--text-3);
}

/* ── Buttons ────────────────────────────────────────────── */

.btn {
    background: transparent;
    border: 1px solid var(--border);
    color: var(--text);
    padding: 5px 12px;
    border-radius: var(--radius);
    font-size: 15px;
    font-weight: 500;
    cursor: pointer;
    font-family: inherit;
    transition: background 0.1s;
}

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

.btn:disabled {
    opacity: 0.4;
    cursor: not-allowed;
}

.btn-primary {
    background: var(--blue);
    border-color: transparent;
    color: #fff;
}

.btn-primary:hover {
    background: #5c96f7;
}

.btn-secondary {
    background: var(--surface-hover);
    border-color: var(--border);
}

.btn-secondary:hover {
    background: var(--border);
}

.w-full {
    width: 100%;
}

/* ── Inline Add Form ────────────────────────────────────── */

.inline-form {
    display: flex;
    gap: 6px;
    padding: 6px 0;
    border-bottom: 1px solid var(--border);
    margin-bottom: 2px;
    align-items: center;
}

.inline-form input,
.inline-form select {
    background: var(--bg);
    border: 1px solid var(--border);
    color: var(--text);
    padding: 5px 8px;
    border-radius: var(--radius);
    font-family: inherit;
    font-size: 15px;
}

.inline-form input:focus,
.inline-form select:focus {
    border-color: var(--blue);
    outline: none;
}

.inline-form .f-desc {
    flex: 2;
    min-width: 0;
}

.inline-form .f-amt {
    width: 90px;
}

.inline-form .f-cat {
    width: 140px;
}

.inline-form .f-select {
    width: 90px;
}

.inline-form .f-submit {
    padding: 5px 14px;
    white-space: nowrap;
    flex-shrink: 0;
}

.inline-form .error-msg {
    color: var(--red);
    font-size: 14px;
    white-space: nowrap;
}

/* ── Expense Table ──────────────────────────────────────── */

.table-header {
    display: flex;
    padding: 6px 8px;
    border-bottom: 1px solid var(--border);
    font-size: 13px;
    color: var(--text-3);
    text-transform: uppercase;
    font-weight: 600;
    letter-spacing: 0.05em;
}

.expenses-list {
    flex: 1;
    overflow-y: auto;
}

.expenses-list::-webkit-scrollbar {
    width: 4px;
}

.expenses-list::-webkit-scrollbar-track {
    background: transparent;
}

.expenses-list::-webkit-scrollbar-thumb {
    background: var(--border);
    border-radius: 2px;
}

.expense-row {
    display: flex;
    padding: 6px 8px;
    font-size: 15px;
    align-items: center;
    cursor: pointer;
    border-radius: 2px;
    transition: background 0.08s;
}

.expense-row:nth-child(even) {
    background: rgba(255, 255, 255, 0.02);
}

.expense-row:hover {
    background: var(--surface-hover);
}

.expense-row.pinned {
    background: rgba(232, 179, 57, 0.08);
}

.expense-row.pinned:hover {
    background: rgba(232, 179, 57, 0.14);
}

.col-pin {
    flex: 0 0 18px;
    text-align: center;
    cursor: pointer;
    font-size: 14px;
    line-height: 1;
    opacity: 0;
    transition: opacity 0.1s;
    margin-left: -4px;
    color: var(--text-2);
}

.col-pin.is-pinned {
    opacity: 1;
}

.expense-row:hover .col-pin {
    opacity: 0.4;
}

.expense-row:hover .col-pin.is-pinned,
.col-pin:hover {
    opacity: 1;
}


.col-date {
    flex: 0 0 72px;
    color: var(--text-3);
    font-variant-numeric: tabular-nums;
}

.col-desc {
    flex: 2;
    min-width: 0;
    font-weight: 500;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    padding-right: 8px;
}

.col-cat {
    flex: 0 0 150px;
    padding-right: 12px;
}

.col-people {
    flex: 0 0 130px;
    min-width: 0;
    font-size: 14px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.person-andres {
    color: #5b9bd5;
    font-weight: 500;
}

.person-anna {
    color: #e07cc5;
    font-weight: 500;
}

.person-sep {
    color: var(--text-3);
}

.person-both {
    color: #b07ed8;
    font-weight: 500;
}

.col-amt {
    flex: 0 0 90px;
    text-align: right;
    font-weight: 600;
    font-variant-numeric: tabular-nums;
}

.tag {
    display: inline-block;
    padding: 1px 7px;
    border-radius: 3px;
    font-size: 13px;
    font-weight: 500;
    letter-spacing: 0.01em;
    max-width: 100%;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    vertical-align: middle;
}

.amt-positive {
    color: var(--red);
}

.amt-negative {
    color: var(--green);
}

.amt-neutral {
    color: var(--text);
}

/* ── Budget Cards ───────────────────────────────────────── */

.budget-list {
    flex: 1;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    gap: 3px;
}

.budget-list::-webkit-scrollbar {
    width: 4px;
}

.budget-list::-webkit-scrollbar-track {
    background: transparent;
}

.budget-list::-webkit-scrollbar-thumb {
    background: var(--border);
    border-radius: 2px;
}

.budget-card {
    background: var(--bg);
    border: 1px solid var(--border);
    border-left: 3px solid var(--blue);
    border-radius: var(--radius);
    padding: 7px 10px;
}

.budget-card-header {
    display: flex;
    justify-content: space-between;
    align-items: baseline;
    margin-bottom: 3px;
    font-size: 15px;
    gap: 8px;
}

.budget-cat {
    font-weight: 500;
    min-width: 0;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.budget-amt {
    color: var(--text-2);
    font-size: 14px;
    font-variant-numeric: tabular-nums;
    flex-shrink: 0;
}

.progress-bar-container {
    height: 3px;
    background: var(--border);
    border-radius: 2px;
    margin-bottom: 3px;
    overflow: hidden;
}

.progress-bar {
    height: 100%;
    transition: width 0.3s;
}

.progress-bar.ok {
    background: var(--blue);
}

.progress-bar.warning {
    background: var(--yellow);
}

.progress-bar.danger {
    background: var(--red);
}

.budget-stats {
    display: flex;
    justify-content: space-between;
    font-size: 14px;
    font-variant-numeric: tabular-nums;
}

.budget-spent {
    color: var(--text-3);
}

.budget-rem {
    font-weight: 600;
}

.budget-rem.positive {
    color: var(--green);
}

.budget-rem.negative {
    color: var(--red);
}

.budget-card.total-card {
    margin-top: 6px;
    border-left-color: var(--text-3);
    background: rgba(255, 255, 255, 0.02);
}

.budget-card.total-card .budget-cat {
    font-weight: 700;
    font-size: 13px;
    text-transform: uppercase;
    letter-spacing: 0.03em;
}

.budget-card.total-card .budget-amt {
    font-weight: 700;
    color: var(--text);
}

.budget-card.negative-box {
    background: rgba(248, 81, 73, 0.1);
    border-color: rgba(248, 81, 73, 0.3);
}

/* ── Modals ─────────────────────────────────────────────── */

.modal-backdrop {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.6);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 100;
}

.modal-backdrop.hidden {
    display: none;
}

.modal {
    background: var(--surface);
    border: 1px solid var(--border);
    width: 100%;
    max-width: 400px;
    padding: 20px;
    border-radius: var(--radius);
}

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

.modal-header h2 {
    font-size: 18px;
    font-weight: 600;
}

.btn-close {
    background: none;
    border: none;
    color: var(--text-3);
    font-size: 18px;
    cursor: pointer;
    padding: 0 4px;
}

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

/* ── Form inputs (modal) ────────────────────────────────── */

.form-group {
    flex: 1;
    margin-bottom: 10px;
}

.form-group label {
    display: block;
    font-size: 13px;
    color: var(--text-2);
    margin-bottom: 3px;
    text-transform: uppercase;
    letter-spacing: 0.03em;
}

.form-group input,
.form-group select {
    background: var(--bg);
    border: 1px solid var(--border);
    color: var(--text);
    padding: 6px 8px;
    border-radius: var(--radius);
    font-family: inherit;
    font-size: 15px;
    width: 100%;
}

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

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

.modal-actions {
    margin-top: 4px;
}

.error-msg {
    color: var(--red);
    font-size: 14px;
    margin-top: 6px;
    text-align: center;
}

/* ── Misc ───────────────────────────────────────────────── */

.loading {
    opacity: 0.5;
}

.skeleton-row {
    height: 30px;
    background: var(--border);
    margin: 4px 0;
    border-radius: 2px;
    opacity: 0.4;
}

.skeleton-card {
    height: 54px;
    background: var(--border);
    margin-bottom: 4px;
    border-radius: var(--radius);
    opacity: 0.4;
}

/* ── Login Screen ───────────────────────────────────────── */

.login-screen {
    display: flex;
    align-items: center;
    justify-content: center;
    height: 100vh;
}

.login-box {
    text-align: center;
    width: 280px;
}

.login-box h1 {
    font-size: 24px;
    font-weight: 600;
    margin-bottom: 4px;
}

.login-box p {
    font-size: 15px;
    color: var(--text-3);
    margin-bottom: 16px;
}

.login-box form {
    display: flex;
    gap: 6px;
}

.login-box input {
    flex: 1;
    background: var(--surface);
    border: 1px solid var(--border);
    color: var(--text);
    padding: 7px 10px;
    border-radius: var(--radius);
    font-family: inherit;
    font-size: 15px;
}

.login-box input:focus {
    border-color: var(--blue);
    outline: none;
}

/* ── Mobile Responsive ─────────────────────────────────── */

@media (max-width: 600px) {
    body {
        overflow: auto;
        padding: 8px;
        height: auto;
        min-height: 100vh;
    }

    .app-container {
        min-height: auto;
    }

    header {
        flex-direction: column;
        gap: 4px;
        padding: 10px 12px;
    }

    header h1 {
        font-size: 18px;
    }

    .debt-summary {
        text-align: center;
    }

    /* Stack panels vertically */
    .main-content {
        grid-template-columns: 1fr;
    }

    /* Inline form → wrapped grid */
    .inline-form {
        flex-wrap: wrap;
        gap: 6px;
    }

    .inline-form .f-desc {
        flex: 1 1 100%;
        min-width: 0;
    }

    .inline-form .f-amt {
        flex: 1 1 calc(50% - 3px);
        width: auto;
    }

    .inline-form .f-cat {
        flex: 1 1 calc(50% - 3px);
        width: auto;
    }

    .inline-form .f-select {
        flex: 1 1 calc(50% - 3px);
        width: auto;
    }

    .inline-form .f-submit {
        flex: 1 1 100%;
    }

    /* Hide desktop table header */
    .table-header {
        display: none;
    }

    /* Card-style expense rows (Grid Layout) */
    .expense-row {
        display: grid;
        grid-template-columns: 16px auto 1fr auto;
        gap: 4px 8px;
        padding: 10px;
        border-bottom: 1px solid var(--border);
        border-radius: 0;
        align-items: center;
    }

    .col-pin {
        grid-column: 1 / 2;
        grid-row: 1 / 2;
        opacity: 1;
        margin-left: 0;
    }

    .col-desc {
        grid-column: 2 / 4;
        grid-row: 1 / 2;
        font-size: 15px;
        padding: 0;
        min-width: 0;
    }

    .col-amt {
        grid-column: 4 / 5;
        grid-row: 1 / 2;
        text-align: right;
    }

    .col-date {
        grid-column: 2 / 3;
        grid-row: 2 / 3;
        font-size: 13px;
    }

    .col-cat {
        grid-column: 3 / 4;
        grid-row: 2 / 3;
        text-align: left;
    }

    .col-people {
        grid-column: 4 / 5;
        grid-row: 2 / 3;
        font-size: 12px;
        text-align: right;
    }

    /* Let expenses list scroll naturally */
    .expenses-list {
        overflow-y: visible;
        flex: none;
    }

    /* Panel adjustments */
    .panel {
        padding: 10px 12px;
    }

    /* Modals full-width on mobile */
    .modal {
        max-width: calc(100vw - 32px);
        margin: 16px;
    }
}

.mobile-hidden {
    display: none !important;
}

.show-more-btn {
    width: 100%;
    margin-top: 8px;
    padding: 10px;
    text-align: center;
    font-size: 14px;
}