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

[hidden] {
    display: none !important;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
    background: #f5f5f5;
    color: #333;
    line-height: 1.5;
}

.header {
    background: #2c3e50;
    color: #fff;
    padding: 1rem 1.5rem;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.header h1 {
    font-size: 1.25rem;
    font-weight: 600;
}

.btn-link {
    color: #ecf0f1;
    text-decoration: none;
    font-size: 0.9rem;
}

.btn-link:hover {
    text-decoration: underline;
}

.container {
    max-width: 960px;
    margin: 1.5rem auto;
    padding: 0 1rem;
}

/* Alerts */
.alert {
    padding: 0.75rem 1rem;
    border-radius: 4px;
    margin-bottom: 1rem;
    font-size: 0.9rem;
}

.alert-error {
    background: #fdecea;
    color: #b71c1c;
    border: 1px solid #f5c6cb;
}

.alert-success {
    background: #e8f5e9;
    color: #1b5e20;
    border: 1px solid #c8e6c9;
}

/* Add form */
.add-form {
    background: #fff;
    padding: 1.25rem;
    border-radius: 6px;
    margin-bottom: 1.5rem;
    box-shadow: 0 1px 3px rgba(0,0,0,0.08);
}

.add-form h2 {
    font-size: 1rem;
    margin-bottom: 0.75rem;
    color: #555;
}

.form-inline .form-row {
    display: flex;
    gap: 0.5rem;
    flex-wrap: wrap;
}

.form-inline select,
.form-inline input[type="text"] {
    flex: 1;
    min-width: 120px;
    padding: 0.5rem 0.75rem;
    border: 1px solid #ccc;
    border-radius: 4px;
    font-size: 0.9rem;
}

.form-group {
    margin-bottom: 0.75rem;
}

.form-group label {
    display: block;
    margin-bottom: 0.25rem;
    font-weight: 500;
    font-size: 0.9rem;
}

.form-group input,
.form-group select {
    width: 100%;
    padding: 0.5rem 0.75rem;
    border: 1px solid #ccc;
    border-radius: 4px;
    font-size: 0.9rem;
}

/* Buttons */
.btn {
    padding: 0.5rem 1rem;
    border: none;
    border-radius: 4px;
    font-size: 0.9rem;
    cursor: pointer;
}

.btn-primary {
    background: #2c3e50;
    color: #fff;
}

.btn-primary:hover {
    background: #34495e;
}

.btn-secondary {
    background: #95a5a6;
    color: #fff;
}

.btn-secondary:hover {
    background: #7f8c8d;
}

.btn-full {
    width: 100%;
}

.btn-sm {
    padding: 0.25rem 0.5rem;
    font-size: 0.8rem;
    border: none;
    border-radius: 3px;
    cursor: pointer;
}

.btn-edit {
    background: #3498db;
    color: #fff;
}

.btn-edit:hover {
    background: #2980b9;
}

.btn-delete {
    background: #e74c3c;
    color: #fff;
}

.btn-delete:hover {
    background: #c0392b;
}

.inline-form {
    display: inline;
}

/* Budget columns */
.budget-columns {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 1.5rem;
    margin-bottom: 1.5rem;
}

.column {
    background: #fff;
    padding: 1.25rem;
    border-radius: 6px;
    box-shadow: 0 1px 3px rgba(0,0,0,0.08);
}

.column h2 {
    font-size: 1rem;
    margin-bottom: 0.75rem;
    color: #555;
    border-bottom: 2px solid #eee;
    padding-bottom: 0.5rem;
}

.empty-msg {
    color: #999;
    font-size: 0.9rem;
    font-style: italic;
}

.entry-list {
    list-style: none;
}

.entry {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 0.5rem;
    padding: 0.5rem 0;
    border-bottom: 1px solid #f0f0f0;
}

.entry:last-child {
    border-bottom: none;
}

.entry.dragging {
    opacity: 0.4;
}

.drag-handle {
    flex-shrink: 0;
    color: #bbb;
    font-size: 1.1rem;
    line-height: 1;
    cursor: grab;
    padding: 0.15rem 0.3rem;
    user-select: none;
    -webkit-user-select: none;
    border-radius: 3px;
}

.drag-handle:hover {
    color: #7f8c8d;
    background: #f0f0f0;
}

.drag-handle:active {
    cursor: grabbing;
}

.entry-info {
    display: flex;
    flex-direction: column;
    flex: 1 1 auto;
    min-width: 0;
    max-width: 100%;
}

.entry-desc {
    font-size: 0.9rem;
    word-break: break-word;
}

.entry-amount {
    font-size: 0.95rem;
    font-weight: 600;
    color: #2c3e50;
}

.entry-actions {
    display: flex;
    gap: 0.35rem;
    flex-shrink: 0;
    margin-left: 0.5rem;
}

.entry--pending {
    opacity: 0.65;
}

.entry--pending .entry-desc {
    font-style: italic;
}

.badge {
    display: inline-block;
    margin-left: 0.35rem;
    padding: 0.05rem 0.4rem;
    border-radius: 3px;
    font-size: 0.68rem;
    font-weight: 600;
    text-transform: uppercase;
    vertical-align: middle;
    letter-spacing: 0.03em;
}

.badge-pending {
    background: #fff3cd;
    color: #856404;
    border: 1px solid #ffeeba;
}

/* Totals */
.totals {
    background: #fff;
    padding: 1.25rem;
    border-radius: 6px;
    box-shadow: 0 1px 3px rgba(0,0,0,0.08);
    margin-bottom: 1.5rem;
    display: flex;
    flex-wrap: wrap;
    gap: 1.5rem;
}

.totals-group {
    flex: 1 1 300px;
    min-width: 260px;
}

.totals-group h3 {
    font-size: 0.95rem;
    margin-bottom: 0.5rem;
    color: #555;
}

.totals-group-note {
    font-weight: 400;
    font-size: 0.8rem;
    color: #999;
}

.totals-group-confirmed .balance .totals-value {
    color: #2c3e50;
    border-top-color: #2c3e50;
}

.totals-row {
    display: flex;
    justify-content: space-between;
    gap: 1rem;
    margin-bottom: 0.75rem;
}

.totals-item {
    flex: 1;
    display: flex;
    justify-content: space-between;
}

.totals-label {
    font-weight: 500;
    color: #555;
}

.totals-value {
    font-weight: 600;
}

.balance {
    display: flex;
    justify-content: space-between;
    padding-top: 0.75rem;
    border-top: 2px solid #eee;
    font-size: 1.1rem;
}

.balance .totals-value {
    color: #27ae60;
}

.balance .totals-value.negative {
    color: #e74c3c;
}

/* Modal */
.modal {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0,0,0,0.5);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1000;
}

.modal-content {
    background: #fff;
    padding: 1.5rem;
    border-radius: 6px;
    width: 90%;
    max-width: 400px;
    box-shadow: 0 4px 20px rgba(0,0,0,0.2);
}

.modal-content h2 {
    font-size: 1.1rem;
    margin-bottom: 1rem;
}

/* Login page */
.login-page {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 100vh;
}

.login-container {
    background: #fff;
    padding: 2rem;
    border-radius: 6px;
    box-shadow: 0 2px 10px rgba(0,0,0,0.1);
    width: 90%;
    max-width: 360px;
}

.login-container h1 {
    text-align: center;
    margin-bottom: 1.5rem;
    color: #2c3e50;
}

/* Dashboard */
.header-nav {
    display: flex;
    gap: 1rem;
}

.visually-hidden {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0 0 0 0);
    white-space: nowrap;
    border: 0;
}

.budget-table {
    width: 100%;
    border-collapse: collapse;
    background: #fff;
    border-radius: 6px;
    overflow: hidden;
    box-shadow: 0 1px 4px rgba(0,0,0,0.08);
    font-size: 0.95rem;
}

.budget-table th,
.budget-table td {
    padding: 0.7rem 0.9rem;
    text-align: left;
    border-bottom: 1px solid #eceff1;
}

.budget-table thead th {
    background: #fafbfc;
    font-size: 0.8rem;
    text-transform: uppercase;
    letter-spacing: 0.03em;
    color: #7f8c8d;
}

.budget-table .num {
    text-align: right;
    white-space: nowrap;
}

.budget-table tfoot th,
.budget-table tfoot td {
    background: #fafbfc;
    font-weight: 600;
    border-bottom: none;
}

.budget-table tbody tr:last-child td {
    border-bottom: none;
}

.budget-link {
    color: #2c3e50;
    font-weight: 600;
    text-decoration: none;
}

.budget-link:hover {
    text-decoration: underline;
}

.budget-cell {
    min-width: 200px;
}

.budget-rename {
    margin-top: 0.5rem;
    gap: 0.4rem;
}

.budget-rename input[type="text"] {
    flex: 1 1 auto;
    min-width: 0;
    padding: 0.35rem 0.5rem;
    border: 1px solid #d5d8dc;
    border-radius: 4px;
    font: inherit;
}

.negative {
    color: #c0392b;
}

.budget-currency {
    margin-top: 0.5rem;
    font-size: 0.8rem;
    color: #7f8c8d;
}

.btn-open {
    text-decoration: none;
}

/* Responsive */
@media (max-width: 640px) {
    .budget-columns {
        grid-template-columns: 1fr;
    }

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

    .form-inline input[type="text"] {
        min-width: unset;
    }

    .totals-row {
        flex-direction: column;
        gap: 0.5rem;
    }

    .budget-table {
        font-size: 0.85rem;
    }

    .budget-table th,
    .budget-table td {
        padding: 0.5rem 0.4rem;
    }
}
