/* ============================================================
   GastosCompartidos — Design System
   Aesthetic: Refined minimalism · Warm editorial · Family-first
   Fonts: Cormorant Garamond (display) + DM Sans (UI)
   ============================================================ */

/* ── Variables ──────────────────────────────────────────── */
:root {
    --bg:           #f2ece2;
    --surface:      #ffffff;
    --surface-2:    #faf8f4;
    --primary:      #1e3a2f;
    --primary-h:    #16302500;
    --primary-lt:   #2d5442;
    --accent:       #b8622a;
    --text:         #1a1714;
    --text-muted:   #6b6257;
    --border:       #ddd4c5;
    --border-lt:    #ede8e0;
    --danger:       #9e2a2b;
    --danger-lt:    #fdf0f0;
    --success:      #1e5631;
    --success-lt:   #eef6f0;
    --sidebar-w:    240px;
    --radius:       6px;
    --radius-lg:    10px;
    --shadow:       0 1px 4px rgba(30,20,10,.08), 0 4px 16px rgba(30,20,10,.06);
    --shadow-lg:    0 8px 32px rgba(30,20,10,.14);
    --font-display: 'Cormorant Garamond', Georgia, serif;
    --font-ui:      'DM Sans', system-ui, sans-serif;
    --transition:   .18s ease;
}

/* ── Reset ──────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html { font-size: 16px; -webkit-text-size-adjust: 100%; }
body {
    font-family: var(--font-ui);
    font-size: .9375rem;
    line-height: 1.6;
    color: var(--text);
    background: var(--bg);
    min-height: 100vh;
}
a { color: inherit; text-decoration: none; }
button, input, select, textarea { font: inherit; }
img { max-width: 100%; display: block; }

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

/* ── Sidebar ────────────────────────────────────────────── */
.sidebar {
    width: var(--sidebar-w);
    background: var(--primary);
    color: #fff;
    display: flex;
    flex-direction: column;
    position: fixed;
    top: 0; left: 0; bottom: 0;
    z-index: 100;
    padding: 0;
}

.sidebar__brand {
    display: flex;
    align-items: center;
    gap: .75rem;
    padding: 1.5rem 1.25rem 1.25rem;
    border-bottom: 1px solid rgba(255,255,255,.1);
}

.sidebar__logo {
    width: 34px; height: 34px;
    background: var(--accent);
    border-radius: var(--radius);
    display: flex; align-items: center; justify-content: center;
    font-family: var(--font-display);
    font-size: 1rem;
    font-weight: 600;
    color: #fff;
    flex-shrink: 0;
}

.sidebar__name {
    font-family: var(--font-display);
    font-size: 1.15rem;
    font-weight: 600;
    letter-spacing: .01em;
    color: #fff;
}

.sidebar__nav {
    flex: 1;
    padding: 1rem .75rem;
    display: flex;
    flex-direction: column;
    gap: .25rem;
}

.nav-link {
    display: flex;
    align-items: center;
    gap: .75rem;
    padding: .6rem .75rem;
    border-radius: var(--radius);
    color: rgba(255,255,255,.72);
    font-size: .875rem;
    font-weight: 500;
    transition: background var(--transition), color var(--transition);
}

.nav-link svg { width: 16px; height: 16px; flex-shrink: 0; }

.nav-link:hover {
    background: rgba(255,255,255,.1);
    color: #fff;
}

.nav-link--active {
    background: rgba(255,255,255,.15);
    color: #fff;
}

.sidebar__footer {
    padding: 1rem .75rem 1.25rem;
    border-top: 1px solid rgba(255,255,255,.1);
    display: flex;
    align-items: center;
    gap: .5rem;
}

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

.sidebar__avatar {
    width: 32px; height: 32px;
    background: rgba(255,255,255,.15);
    border-radius: 50%;
    display: flex; align-items: center; justify-content: center;
    font-size: .8125rem;
    font-weight: 600;
    color: #fff;
    flex-shrink: 0;
    text-transform: uppercase;
}

.sidebar__user-info {
    display: flex;
    flex-direction: column;
    min-width: 0;
}

.sidebar__user-name {
    font-size: .8125rem;
    font-weight: 500;
    color: #fff;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.sidebar__user-role {
    font-size: .75rem;
    color: rgba(255,255,255,.55);
}

.btn-logout {
    width: 30px; height: 30px;
    display: flex; align-items: center; justify-content: center;
    color: rgba(255,255,255,.5);
    border-radius: var(--radius);
    transition: background var(--transition), color var(--transition);
    flex-shrink: 0;
}

.btn-logout:hover { background: rgba(255,255,255,.1); color: #fff; }
.btn-logout svg   { width: 15px; height: 15px; }

/* ── Main ───────────────────────────────────────────────── */
.main {
    margin-left: var(--sidebar-w);
    flex: 1;
    min-height: 100vh;
}

.main__inner {
    max-width: 1080px;
    padding: 2rem 2.5rem 4rem;
}

/* ── Page header ────────────────────────────────────────── */
.page-header {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 1rem;
    margin-bottom: 1.75rem;
}

.page-title {
    font-family: var(--font-display);
    font-size: 2rem;
    font-weight: 600;
    line-height: 1.2;
    color: var(--text);
    letter-spacing: -.01em;
}

.page-subtitle {
    font-size: .875rem;
    color: var(--text-muted);
    margin-top: .2rem;
}

.page-header__actions {
    display: flex;
    gap: .5rem;
    flex-wrap: wrap;
    align-items: center;
}

.breadcrumb {
    color: var(--text-muted);
    font-size: .875rem;
    transition: color var(--transition);
}
.breadcrumb:hover { color: var(--primary); }

/* ── Buttons ────────────────────────────────────────────── */
.btn {
    display: inline-flex;
    align-items: center;
    gap: .4rem;
    padding: .5rem 1rem;
    border-radius: var(--radius);
    font-size: .875rem;
    font-weight: 500;
    border: 1px solid transparent;
    cursor: pointer;
    transition: background var(--transition), color var(--transition), border-color var(--transition), box-shadow var(--transition);
    white-space: nowrap;
    text-decoration: none;
}
.btn svg { width: 14px; height: 14px; }

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

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

.btn--danger {
    background: var(--danger);
    color: #fff;
    border-color: var(--danger);
}
.btn--danger:hover { opacity: .88; }

.btn--danger-ghost { color: var(--danger); }
.btn--danger-ghost:hover { background: var(--danger-lt); color: var(--danger); border-color: #f5c6c6; }

.btn--sm  { padding: .35rem .7rem; font-size: .8125rem; }
.btn--full { width: 100%; justify-content: center; }

/* ── Cards ──────────────────────────────────────────────── */
.card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    overflow: hidden;
    box-shadow: var(--shadow);
}

.card--form {
    padding: 1.75rem;
}

/* ── Tables ─────────────────────────────────────────────── */
.table {
    width: 100%;
    border-collapse: collapse;
    font-size: .875rem;
}

.table thead th {
    text-align: left;
    padding: .75rem 1rem;
    font-size: .75rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: .06em;
    color: var(--text-muted);
    background: var(--surface-2);
    border-bottom: 1px solid var(--border);
}

.table tbody td {
    padding: .75rem 1rem;
    border-bottom: 1px solid var(--border-lt);
    vertical-align: middle;
}

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

.table tbody tr:hover td { background: var(--surface-2); }

.table__actions {
    text-align: right;
    white-space: nowrap;
}

/* ── Forms ──────────────────────────────────────────────── */
.form-group {
    display: flex;
    flex-direction: column;
    gap: .375rem;
}

.form-row {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 1rem;
    margin-bottom: 1rem;
}

.form-group + .form-group,
.form-group + .form-row,
.form-row + .form-group {
    margin-top: 1rem;
}

.form-label {
    font-size: .8125rem;
    font-weight: 600;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: .05em;
}

.form-input, .form-select, .form-textarea {
    padding: .55rem .75rem;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    background: var(--surface);
    color: var(--text);
    font-size: .9375rem;
    transition: border-color var(--transition), box-shadow var(--transition);
    width: 100%;
}

.form-input:focus, .form-select:focus, .form-textarea:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(30,58,47,.1);
}

.form-textarea { resize: vertical; min-height: 80px; }

.form-input--sm, .form-select--sm {
    padding: .35rem .6rem;
    font-size: .8125rem;
}

.form-hint {
    font-size: .8rem;
    color: var(--text-muted);
}

.form-actions {
    display: flex;
    justify-content: flex-end;
    gap: .5rem;
    margin-top: 1.5rem;
    padding-top: 1.25rem;
    border-top: 1px solid var(--border-lt);
}

.required { color: var(--accent); }

/* ── Alerts ─────────────────────────────────────────────── */
.alert {
    padding: .8rem 1rem;
    border-radius: var(--radius);
    font-size: .875rem;
    margin-bottom: 1.25rem;
    border: 1px solid transparent;
}

.alert--success {
    background: var(--success-lt);
    color: var(--success);
    border-color: #b8dfc5;
}

.alert--error {
    background: var(--danger-lt);
    color: var(--danger);
    border-color: #f5c6c6;
}

/* ── Badges ─────────────────────────────────────────────── */
.badge {
    display: inline-flex;
    align-items: center;
    padding: .2rem .55rem;
    border-radius: 999px;
    font-size: .75rem;
    font-weight: 600;
    letter-spacing: .03em;
    white-space: nowrap;
}

.badge--admin    { background: #e8f0eb; color: var(--primary); }
.badge--member   { background: #f0ece6; color: var(--text-muted); }
.badge--active   { background: var(--success-lt); color: var(--success); }
.badge--inactive { background: #f5f5f5; color: #999; }
.badge--currency { background: #fdf3e8; color: var(--accent); font-size: .7rem; padding: .15rem .45rem; }

/* ── Avatars ────────────────────────────────────────────── */
.avatar {
    border-radius: 50%;
    display: flex; align-items: center; justify-content: center;
    font-weight: 600;
    text-transform: uppercase;
    flex-shrink: 0;
    background: var(--primary);
    color: #fff;
}
.avatar--sm { width: 28px; height: 28px; font-size: .8rem; }
.avatar--xs { width: 22px; height: 22px; font-size: .7rem; }

.user-cell    { display: flex; align-items: center; gap: .5rem; }
.user-cell--sm { gap: .375rem; }

/* ── Tables grid (index page) ───────────────────────────── */
.tables-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
    gap: 1rem;
}

.table-card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    padding: 1.25rem;
    display: block;
    transition: box-shadow var(--transition), transform var(--transition), border-color var(--transition);
    cursor: pointer;
    box-shadow: var(--shadow);
}

.table-card:hover {
    box-shadow: var(--shadow-lg);
    transform: translateY(-2px);
    border-color: var(--primary);
}

.table-card__header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: .875rem;
}

.table-card__icon {
    width: 40px; height: 40px;
    background: var(--primary);
    border-radius: var(--radius);
    display: flex; align-items: center; justify-content: center;
    font-family: var(--font-display);
    font-size: 1rem;
    font-weight: 600;
    color: #fff;
    text-transform: uppercase;
}

.table-card__name {
    font-family: var(--font-display);
    font-size: 1.25rem;
    font-weight: 600;
    color: var(--text);
    margin-bottom: .25rem;
    line-height: 1.25;
}

.table-card__desc {
    font-size: .8125rem;
    color: var(--text-muted);
    margin-bottom: .75rem;
    line-height: 1.4;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
}

.table-card__meta {
    display: flex;
    justify-content: space-between;
    font-size: .75rem;
    color: var(--text-muted);
    margin-top: .875rem;
    padding-top: .75rem;
    border-top: 1px solid var(--border-lt);
}

/* ── Members bar ────────────────────────────────────────── */
.section-row { margin-bottom: 1rem; }

.members-bar {
    display: flex;
    align-items: center;
    gap: .5rem;
    flex-wrap: wrap;
}

.member-chip {
    display: inline-flex;
    align-items: center;
    gap: .4rem;
    padding: .3rem .65rem .3rem .4rem;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 999px;
    font-size: .8125rem;
    color: var(--text);
}

.member-chip--add {
    color: var(--primary);
    border-color: var(--primary);
    cursor: pointer;
    background: transparent;
    transition: background var(--transition);
    padding: .3rem .7rem;
}

.member-chip--add:hover { background: #e8f0eb; }

.member-chip__remove {
    background: none;
    border: none;
    cursor: pointer;
    color: var(--text-muted);
    font-size: 1rem;
    line-height: 1;
    padding: 0 0 0 .25rem;
    transition: color var(--transition);
}
.member-chip__remove:hover { color: var(--danger); }

/* ── Totals row ─────────────────────────────────────────── */
.totals-row {
    display: flex;
    gap: .75rem;
    flex-wrap: wrap;
    margin-bottom: 1.25rem;
}

.total-chip {
    display: flex;
    align-items: baseline;
    gap: .375rem;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: .5rem .875rem;
}

.total-chip__currency {
    font-size: .75rem;
    font-weight: 600;
    color: var(--accent);
    text-transform: uppercase;
}

.total-chip__amount {
    font-family: var(--font-display);
    font-size: 1.25rem;
    font-weight: 600;
    color: var(--text);
}

/* ── Filters bar ────────────────────────────────────────── */
.filters-bar {
    display: flex;
    align-items: center;
    gap: .5rem;
    flex-wrap: wrap;
    margin-bottom: 1rem;
}

/* ── Pagination ─────────────────────────────────────────── */
.pagination {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 1rem;
    margin-top: 1.25rem;
    font-size: .875rem;
}

.pagination__btn {
    color: var(--primary);
    font-weight: 500;
    transition: opacity var(--transition);
}
.pagination__btn:hover { opacity: .7; }

.pagination__info { color: var(--text-muted); }

/* ── Empty state ────────────────────────────────────────── */
.empty-state {
    text-align: center;
    padding: 4rem 2rem;
}

.empty-state__icon {
    width: 64px; height: 64px;
    margin: 0 auto 1.25rem;
    color: var(--border);
}
.empty-state__icon svg { width: 100%; height: 100%; }

.empty-state__title {
    font-family: var(--font-display);
    font-size: 1.5rem;
    font-weight: 600;
    color: var(--text);
    margin-bottom: .5rem;
}

.empty-state__text {
    font-size: .9375rem;
    color: var(--text-muted);
    max-width: 360px;
    margin: 0 auto 1.5rem;
}

.empty-state--sm {
    padding: 2rem;
    color: var(--text-muted);
    font-size: .875rem;
}

/* ── Modals ─────────────────────────────────────────────── */
.modal {
    display: none;
    position: fixed;
    inset: 0;
    z-index: 200;
    align-items: center;
    justify-content: center;
}

.modal--open { display: flex; }

.modal__backdrop {
    position: fixed;
    inset: 0;
    background: rgba(20,12,5,.45);
    backdrop-filter: blur(2px);
}

.modal__box {
    position: relative;
    z-index: 201;
    background: var(--surface);
    border-radius: var(--radius-lg);
    width: 100%;
    max-width: 540px;
    box-shadow: var(--shadow-lg);
    animation: modal-in .2s ease;
    max-height: 90vh;
    overflow-y: auto;
}

.modal__box--sm { max-width: 380px; }

@keyframes modal-in {
    from { opacity: 0; transform: translateY(-12px) scale(.97); }
    to   { opacity: 1; transform: translateY(0) scale(1); }
}

.modal__header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 1.25rem 1.5rem 1rem;
    border-bottom: 1px solid var(--border-lt);
}

.modal__title {
    font-family: var(--font-display);
    font-size: 1.3rem;
    font-weight: 600;
    color: var(--text);
}

.modal__close {
    background: none;
    border: none;
    font-size: 1.4rem;
    color: var(--text-muted);
    cursor: pointer;
    line-height: 1;
    padding: .2rem .4rem;
    border-radius: var(--radius);
    transition: background var(--transition), color var(--transition);
}
.modal__close:hover { background: var(--surface-2); color: var(--text); }

.modal__body {
    padding: 1.25rem 1.5rem;
}

.modal__footer {
    display: flex;
    justify-content: flex-end;
    gap: .5rem;
    padding: 1rem 1.5rem 1.25rem;
    border-top: 1px solid var(--border-lt);
}

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

.danger-zone { }

.danger-zone__title {
    font-size: .875rem;
    font-weight: 600;
    color: var(--danger);
    margin-bottom: .375rem;
    text-transform: uppercase;
    letter-spacing: .05em;
}

.danger-zone__text {
    font-size: .875rem;
    color: var(--text-muted);
    margin-bottom: .875rem;
}

/* ── Utility ────────────────────────────────────────────── */
.text-right  { text-align: right; }
.text-muted  { color: var(--text-muted); }
.text-sm     { font-size: .8125rem; }
.text-nowrap { white-space: nowrap; }
.text-mono   { font-family: 'SF Mono', 'Fira Mono', monospace; font-size: .875rem; }

/* ── Login page ─────────────────────────────────────────── */
body.login-page {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 100vh;
    background: var(--primary);
}

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

.login-card {
    background: var(--surface);
    border-radius: var(--radius-lg);
    padding: 2.5rem;
    box-shadow: var(--shadow-lg);
}

.login-brand {
    text-align: center;
    margin-bottom: 2rem;
}

.login-logo {
    width: 52px; height: 52px;
    background: var(--primary);
    border-radius: var(--radius-lg);
    display: flex; align-items: center; justify-content: center;
    font-family: var(--font-display);
    font-size: 1.25rem;
    font-weight: 600;
    color: #fff;
    margin: 0 auto .875rem;
}

.login-title {
    font-family: var(--font-display);
    font-size: 1.75rem;
    font-weight: 600;
    color: var(--text);
    margin-bottom: .25rem;
}

.login-subtitle {
    font-size: .875rem;
    color: var(--text-muted);
}

.login-form .form-group + .form-group { margin-top: 1rem; }
.login-form .btn--full { margin-top: 1.5rem; padding: .7rem; font-size: 1rem; }
