/* ═══════════════════════════════════════════════════
   Condominium Financial System — Shared Stylesheet
   ═══════════════════════════════════════════════════ */

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

:root {
    --primary:       #2563eb;
    --primary-hover: #1d4ed8;
    --danger:        #dc2626;
    --success:       #16a34a;
    --warning:       #d97706;
    --bg:            #f1f5f9;
    --surface:       #ffffff;
    --border:        #e2e8f0;
    --text:          #1e293b;
    --text-muted:    #64748b;
    --radius:        10px;
    --shadow:        0 4px 24px rgba(0,0,0,.08);
}

/* ── Base ── */
body {
    font-family: 'Segoe UI', system-ui, -apple-system, sans-serif;
    background: var(--bg);
    color: var(--text);
    min-height: 100vh;
    padding: 0;
    display: flex;
    flex-direction: column;
}

/* Everything between navbar and footer grows to fill available space */
body > *:not(nav):not(.dev-footer) {
    flex: 1 0 auto;
}

a {
    text-decoration: none;
    color: inherit;
}

/* ── Card ── */
.card {
    background: var(--surface);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    width: 100%;
    overflow: hidden;
}

.card-header {
    background: var(--primary);
    padding: 1.75rem 2rem;
    color: white;
}

.card-header-content {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 1rem;
}

.card-header h1 {
    font-size: 1.4rem;
    font-weight: 600;
    letter-spacing: -.01em;
}

.card-header p {
    margin-top: .35rem;
    font-size: .875rem;
    opacity: .85;
}

.card-header-actions {
    display: flex;
    align-items: center;
    gap: 1rem;
}

.building-thumb {
    width: 144px;
    height: 144px;
    object-fit: cover;
    border-radius: 8px;
    border: 2px solid rgba(255,255,255,.3);
    flex-shrink: 0;
}

.card-body {
    padding: 2rem;
}

.card-footer {
    display: flex;
    gap: .75rem;
    justify-content: flex-end;
}

/* ── Divider ── */
.divider {
    border: none;
    border-top: 1px solid var(--border);
    margin: 1.75rem 0;
}

/* ── Buttons ── */
.btn {
    display: inline-flex;
    align-items: center;
    gap: .4rem;
    padding: .65rem 1.5rem;
    min-height: 44px;
    border-radius: var(--radius);
    font-size: .9rem;
    font-weight: 500;
    cursor: pointer;
    border: none;
    transition: background .2s, transform .1s;
    text-decoration: none;
}

.btn:active { transform: scale(.98); }

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

.btn-secondary {
    background: var(--bg);
    color: var(--text-muted);
    border: 1.5px solid var(--border);
}
.btn-secondary:hover { background: var(--border); }

.btn-danger {
    background: var(--danger);
    color: white;
}
.btn-danger:hover { background: #b91c1c; }

.btn-success {
    background: var(--success);
    color: white;
}
.btn-success:hover { background: #15803d; }

.btn-warning {
    background: var(--warning);
    color: white;
}
.btn-warning:hover { background: #b45309; }

.btn-ghost {
    background: rgba(255,255,255,.15);
    color: white;
    border: 1px solid rgba(255,255,255,.3);
}
.btn-ghost:hover { background: rgba(255,255,255,.25); }

.btn-sm {
    padding: .4rem 1rem;
    min-height: 36px;
    font-size: .82rem;
}

/* ── Form elements ── */
.form-group { margin-bottom: 1.4rem; }

label {
    display: block;
    font-size: .875rem;
    font-weight: 500;
    margin-bottom: .45rem;
    color: var(--text);
}

label .required {
    color: var(--danger);
    margin-left: .2rem;
}

input[type="text"],
input[type="email"],
input[type="tel"],
input[type="password"],
select {
    width: 100%;
    padding: .65rem 1rem;
    min-height: 44px;
    border: 1.5px solid var(--border);
    border-radius: var(--radius);
    font-size: .95rem;
    color: var(--text);
    background: var(--surface);
    transition: border-color .2s, box-shadow .2s;
    outline: none;
}

input:focus,
select:focus {
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(37, 99, 235, .15);
}

input.input-error { border-color: var(--danger); }

.hint {
    font-size: .78rem;
    color: var(--text-muted);
    margin-top: .35rem;
}

.field-error {
    font-size: .78rem;
    color: var(--danger);
    margin-top: .35rem;
}

/* ── Alert banners ── */
.alert-error {
    background: #fef2f2;
    border: 1px solid #fecaca;
    color: var(--danger);
    border-radius: var(--radius);
    padding: .85rem 1rem;
    font-size: .875rem;
    margin-bottom: 1.5rem;
}

.alert-success {
    background: #f0fdf4;
    border: 1px solid #bbf7d0;
    color: var(--success);
    border-radius: var(--radius);
    padding: .85rem 1rem;
    font-size: .875rem;
    margin-bottom: 1.5rem;
}

/* ── Apartment list ── */
.apt-list {
    display: flex;
    flex-direction: column;
    gap: .75rem;
}

.apt-item {
    border: 1.5px solid var(--border);
    border-radius: var(--radius);
    overflow: hidden;
    transition: border-color .2s;
}

.apt-item:hover { border-color: var(--primary); }

.apt-summary {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 1rem 1.25rem;
    cursor: pointer;
    gap: 1rem;
    user-select: none;
}

.apt-summary:hover { background: var(--bg); }

.apt-main {
    display: flex;
    align-items: center;
    gap: 1rem;
    flex: 1;
    min-width: 0;
}

.apt-number {
    background: var(--primary);
    color: white;
    font-weight: 700;
    font-size: .85rem;
    padding: .3rem .7rem;
    border-radius: 6px;
    flex-shrink: 0;
    min-width: 52px;
    text-align: center;
}

.apt-owner {
    font-weight: 500;
    font-size: .95rem;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.apt-chevron {
    width: 20px;
    height: 20px;
    flex-shrink: 0;
    color: var(--text-muted);
    transition: transform .25s;
}

.apt-item.open .apt-chevron { transform: rotate(180deg); }

.apt-details {
    display: none;
    padding: 1rem 1.25rem 1.25rem;
    border-top: 1px solid var(--border);
    background: var(--bg);
}

.apt-item.open .apt-details { display: block; }

.apt-fields {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
    gap: .65rem 1.5rem;
    margin-bottom: 1rem;
}

.apt-field label {
    font-size: .75rem;
    text-transform: uppercase;
    letter-spacing: .05em;
    color: var(--text-muted);
    margin-bottom: .15rem;
}

.apt-field span {
    font-size: .9rem;
    font-weight: 500;
    color: var(--text);
}

.apt-actions {
    display: flex;
    justify-content: flex-end;
    gap: .5rem;
}

.empty-state {
    text-align: center;
    padding: 3rem 1rem;
    color: var(--text-muted);
}

.empty-state p { margin-top: .5rem; font-size: .9rem; }

/* ── Transaction list ── */
.tx-list {
    display: flex;
    flex-direction: column;
    gap: .6rem;
}

.tx-item {
    border: 1.5px solid var(--border);
    border-radius: var(--radius);
    overflow: hidden;
    transition: border-color .2s;
}

.tx-item:hover { border-color: var(--primary); }

.tx-summary {
    display: flex;
    align-items: center;
    gap: 1rem;
    padding: .85rem 1.25rem;
    cursor: pointer;
    user-select: none;
}

.tx-summary:hover { background: var(--bg); }

.tx-date {
    font-size: .8rem;
    color: var(--text-muted);
    white-space: nowrap;
    flex-shrink: 0;
    min-width: 76px;
}

.tx-concept {
    flex: 1;
    font-size: .9rem;
    font-weight: 500;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.tx-amount {
    font-size: .95rem;
    font-weight: 700;
    white-space: nowrap;
    flex-shrink: 0;
}

.tx-amount.income { color: var(--success); }
.tx-amount.expense { color: var(--danger); }

.tx-chevron {
    width: 18px;
    height: 18px;
    color: var(--text-muted);
    flex-shrink: 0;
    transition: transform .25s;
}

.tx-item.open .tx-chevron { transform: rotate(180deg); }

.tx-edit-panel {
    display: none;
    padding: 1.25rem;
    border-top: 1px solid var(--border);
    background: var(--bg);
}

.tx-item.open .tx-edit-panel { display: block; }

.tx-edit-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: .9rem 1.5rem;
    margin-bottom: 1rem;
}

.tx-edit-reason {
    margin-bottom: 1rem;
}

.tx-edit-actions {
    display: flex;
    justify-content: flex-end;
    gap: .5rem;
}

.badge-income  { background: #dcfce7; color: #15803d; }
.badge-expense { background: #fee2e2; color: #dc2626; }

.period-selector {
    display: flex;
    align-items: center;
    gap: .75rem;
    flex-wrap: wrap;
    margin-bottom: 1.5rem;
    padding: 1rem 1.25rem;
    background: var(--bg);
    border-radius: var(--radius);
    border: 1px solid var(--border);
}

.period-selector label {
    font-size: .875rem;
    font-weight: 500;
    white-space: nowrap;
    margin-bottom: 0;
}

.period-selector input[type="month"] {
    width: auto;
}

@media (max-width: 480px) {
    .tx-edit-grid { grid-template-columns: 1fr; }
    .tx-concept { max-width: 120px; }
}

/* ── Badges ── */
.badge {
    display: inline-flex;
    align-items: center;
    padding: .2rem .65rem;
    border-radius: 999px;
    font-size: .72rem;
    font-weight: 600;
    letter-spacing: .02em;
    flex-shrink: 0;
}

.badge-admin    { background: #ede9fe; color: #6d28d9; }
.badge-resident { background: #dbeafe; color: #1d4ed8; }
.badge-active   { background: #dcfce7; color: #15803d; }
.badge-inactive { background: #fee2e2; color: #dc2626; }

/* ── User list (mirrors the apartment list pattern) ── */
.user-list {
    display: flex;
    flex-direction: column;
    gap: .75rem;
}

.user-item {
    border: 1.5px solid var(--border);
    border-radius: var(--radius);
    overflow: hidden;
    transition: border-color .2s;
}

.user-item:hover { border-color: var(--primary); }

.user-summary {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 1rem 1.25rem;
    cursor: pointer;
    gap: 1rem;
    user-select: none;
}

.user-summary:hover { background: var(--bg); }

.user-main {
    display: flex;
    align-items: center;
    gap: .75rem;
    flex: 1;
    min-width: 0;
}

.user-username {
    font-weight: 500;
    font-size: .95rem;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.user-meta {
    display: flex;
    align-items: center;
    gap: .5rem;
    flex-shrink: 0;
}

.user-chevron {
    width: 20px;
    height: 20px;
    flex-shrink: 0;
    color: var(--text-muted);
    transition: transform .25s;
}

.user-item.open .user-chevron { transform: rotate(180deg); }

.user-details {
    display: none;
    padding: 1rem 1.25rem 1.25rem;
    border-top: 1px solid var(--border);
    background: var(--bg);
}

.user-item.open .user-details { display: block; }

.user-fields {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
    gap: .65rem 1.5rem;
    margin-bottom: 1rem;
}

.user-field label {
    font-size: .75rem;
    text-transform: uppercase;
    letter-spacing: .05em;
    color: var(--text-muted);
    margin-bottom: .15rem;
}

.user-field span {
    font-size: .9rem;
    font-weight: 500;
    color: var(--text);
}

.user-actions {
    display: flex;
    flex-wrap: wrap;
    gap: .5rem;
    align-items: center;
}

/* Inline password-change form inside user details */
.pwd-form {
    display: flex;
    gap: .5rem;
    align-items: center;
    flex-wrap: wrap;
    margin-top: .75rem;
    padding-top: .75rem;
    border-top: 1px dashed var(--border);
}

.pwd-form input[type="password"] {
    width: auto;
    flex: 1;
    min-width: 130px;
}

/* ── Top Navigation Bar ── */
.navbar {
    position: sticky;
    top: 0;
    z-index: 100;
    background: var(--surface);
    border-bottom: 1px solid var(--border);
    box-shadow: 0 1px 6px rgba(0,0,0,.06);
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 1rem;
    padding: 0 1.5rem;
    height: 58px;
}

.nav-brand {
    display: flex;
    align-items: center;
    gap: .6rem;
    font-weight: 700;
    font-size: .9rem;
    color: var(--primary);
    text-decoration: none;
    flex-shrink: 0;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    max-width: 220px;
}

.nav-logo {
    width: 30px;
    height: 30px;
    object-fit: cover;
    border-radius: 6px;
    flex-shrink: 0;
}

.nav-links {
    display: flex;
    align-items: center;
    gap: .15rem;
    flex: 1;
    padding: 0 .75rem;
}

.nav-link {
    padding: .4rem .85rem;
    border-radius: 6px;
    font-size: .875rem;
    font-weight: 500;
    color: var(--text-muted);
    text-decoration: none;
    transition: background .15s, color .15s;
    white-space: nowrap;
}

.nav-link:hover { background: var(--bg); color: var(--text); }
.nav-link.active { background: #eff6ff; color: var(--primary); font-weight: 600; }

.nav-user {
    display: flex;
    align-items: center;
    gap: .65rem;
    flex-shrink: 0;
}

.nav-username {
    font-size: .8rem;
    color: var(--text-muted);
    max-width: 110px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

/* ── Navbar — two-row mobile layout ── */
@media (max-width: 700px) {
    .navbar {
        height: auto;
        flex-wrap: wrap;       /* allow children to wrap onto a second row */
        padding: 0;
        gap: 0;
        align-items: stretch;
    }

    /* Row 1 — brand (left) + user/logout (right) */
    .nav-brand {
        order: 1;
        flex: 1 1 0;
        min-width: 0;
        max-width: none;
        padding: .55rem 1rem;
        white-space: nowrap;
        overflow: hidden;
        text-overflow: ellipsis;
    }

    .nav-user {
        order: 2;
        flex-shrink: 0;
        padding: .45rem .75rem;
        align-items: center;
    }

    /* Row 2 — navigation links span full width, scrollable */
    .nav-links {
        order: 3;
        flex: 0 0 100%;        /* force onto its own row */
        width: 100%;
        border-top: 1px solid var(--border);
        background: var(--bg);
        padding: .3rem .75rem;
        gap: .1rem;
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
        scrollbar-width: none;
    }

    .nav-links::-webkit-scrollbar { display: none; }

    .nav-link {
        padding: .38rem .7rem;
        font-size: .82rem;
        flex-shrink: 0;
    }

    .nav-username { display: none; }
}

/* ── Page layout helper ── */
.page-wrapper {
    max-width: 860px;
    margin: 0 auto;
    padding: 2rem 1rem;
}

/* ── Form page layout (used when a navbar is present) ── */
.page-with-form {
    display: flex;
    flex-direction: column;
    min-height: 100vh;
}

.form-content {
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 2rem 1rem;
}

.form-content .card { max-width: 560px; width: 100%; }

/* ── Responsive — cards, forms, layout ── */
@media (max-width: 640px) {
    .card-header { padding: 1.25rem; }
    .card-header h1 { font-size: 1.2rem; }
    .card-body { padding: 1.25rem; }
    .card { max-width: 100%; }

    .page-wrapper { padding: 1rem .75rem; }
}

@media (max-width: 480px) {
    .card {
        border-radius: 0;
        box-shadow: none;
    }

    .card-header { padding: 1.25rem 1rem; border-radius: 0; }
    .card-body { padding: 1rem; }

    .card-footer {
        flex-direction: column-reverse;
        gap: .6rem;
    }

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

    .apt-fields { grid-template-columns: 1fr; }
    .form-content { padding: 1rem .75rem; align-items: flex-start; }
}

/* ── Form helpers ── */
.hint {
    display: block;
    font-size: .78rem;
    color: var(--text-muted);
    margin-top: .25rem;
}

/* ── Small button variant ── */
.btn-sm {
    padding: .3rem .75rem;
    font-size: .8rem;
    border-radius: 6px;
}

/* ── Primary-dark colour var fallback ── */
:root {
    --primary-dark: #1d4ed8;
}

/* ── Shared pagination bar ── */
.pagination-bar {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: .75rem;
    margin-top: 1.5rem;
    flex-wrap: wrap;
}
.pag-btn {
    display: inline-flex;
    align-items: center;
    padding: .4rem 1rem;
    border: 1.5px solid var(--border);
    border-radius: 8px;
    background: var(--surface);
    color: var(--primary);
    font-size: .85rem;
    font-weight: 600;
    text-decoration: none;
    transition: background .15s, border-color .15s;
}
.pag-btn:hover { background: #eff6ff; border-color: var(--primary); }
.pag-info {
    font-size: .85rem;
    color: var(--text-muted);
    padding: .3rem .5rem;
}
.pag-info strong { color: var(--text); }

/* ── Dev-by footer ── */
.dev-footer {
    margin-top: auto;
    padding: 1.1rem 1rem;
    text-align: center;
    border-top: 1px solid var(--border);
    background: var(--surface);
}
.dev-footer-inner {
    display: inline-flex;
    align-items: center;
    gap: .5rem;
    font-size: .72rem;
    color: var(--text-muted);
    text-decoration: none;
    transition: opacity .15s;
}
.dev-footer-inner:hover { opacity: .75; }
.dev-footer-logo {
    height: 20px;
    width: auto;
    object-fit: contain;
    border-radius: 3px;
}
