:root {
    --background: var(--theme-bg);
    --card: var(--theme-surface);
    --card-light: var(--theme-surface-2);
    --border-color:var(--theme-border);
    --green: var(--theme-accent);
    --green-soft: var(--theme-accent-soft);
    --orange: var(--theme-orange);
    --orange-soft: var(--theme-orange-soft);
    --red: var(--theme-danger);
    --text: var(--theme-text);
    --text-soft: var(--theme-muted);
    --nav-height: 76px;
}

* {
    box-sizing: border-box;
}

html,
body {
    margin: 0;
    min-height: 100%;
    background:var(--theme-surface-2);
    color: var(--text);
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Arial, sans-serif;
}

body {
    min-height: 100dvh;
    padding-bottom: calc(var(--nav-height) + 18px + env(safe-area-inset-bottom));
}

button,
input {
    font: inherit;
}

button {
    -webkit-tap-highlight-color: transparent;
}

.app {
    width: 100%;
    max-width: 760px;
    min-height: 100dvh;
    margin: 0 auto;
    padding:
        calc(12px + env(safe-area-inset-top))
        clamp(12px,3vw,24px)
        24px;
}

.topbar {
    display: grid;
    grid-template-columns: 42px minmax(0,1fr) auto;
    gap: 11px;
    align-items: center;
    margin-bottom: 10px;
}

.brand-icon {
    width: 42px;
    height: 42px;
    display: grid;
    place-items: center;
    border:1px solid var(--theme-border);
    border-radius: 13px;
    background: var(--green-soft);
    color: var(--green);
    font-size: 20px;
    font-weight: 900;
}

.topbar-title {
    min-width: 0;
}

.topbar-title span,
.eyebrow {
    display: block;
    margin-bottom: 3px;
    color: var(--green);
    font-size: clamp(12px,1.55vw,12px);
    font-weight: 850;
    letter-spacing: .9px;
}

.topbar-title strong {
    display: block;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    font-size: clamp(18px,2.8vw,22px);
}

.today-box {
    min-width: 67px;
    padding: 7px 9px;
    border: 1px solid var(--border);
    border-radius: 11px;
    background: var(--card);
    text-align: right;
}

.today-box span {
    display: block;
    margin-bottom: 2px;
    color: var(--text-soft);
    font-size:13px;
    font-weight: 800;
}

.today-box strong {
    color: var(--green);
    font-size:13px;
}

.summary-grid {
    display: grid;
    grid-template-columns: repeat(2,minmax(0,1fr));
    gap: 7px;
    margin-bottom: 9px;
}

.summary-card {
    min-width: 0;
    padding: 11px 12px;
    border: 1px solid var(--border);
    border-radius: 13px;
    background:var(--theme-surface-2);
}

.summary-card > span {
    display: block;
    margin-bottom: 4px;
    color: var(--text-soft);
    font-size:13px;
}

.summary-card > strong {
    display: block;
    margin-bottom: 3px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    font-size: clamp(18px,3.2vw,23px);
}

.summary-card small {
    display: block;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    color: var(--text-soft);
    font-size:13px;
}

.warning-card {
    border-color:var(--theme-border);
}

.green {
    color: var(--green) !important;
}

.orange {
    color: var(--orange) !important;
}

.search-row {
    margin-bottom: 8px;
}

.search-box {
    height: 46px;
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 0 11px;
    border: 1px solid var(--border);
    border-radius: 12px;
    background: var(--theme-input);
}

.search-box > span {
    color: var(--green);
    font-size: 18px;
}

.search-box input {
    width: 100%;
    border: 0;
    outline: 0;
    background: transparent;
    color: var(--theme-text);
    font-size:13px;
}

.search-box input::placeholder {
    color: var(--theme-muted);
}

.filters {
    display: grid;
    grid-template-columns: repeat(4,minmax(0,1fr));
    gap: 6px;
    margin-bottom: 13px;
}

.filter-button {
    min-width: 0;
    height: 35px;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 4px;
    padding: 0 5px;
    border: 1px solid var(--border);
    border-radius: 10px;
    background: var(--card);
    color: var(--text-soft);
    font-size:13px;
    cursor: pointer;
}

.filter-button span {
    min-width: 17px;
    height: 17px;
    display: grid;
    place-items: center;
    padding: 0 4px;
    border-radius: 999px;
    background:var(--theme-surface-2);
    font-size:13px;
}

.filter-button.active {
    border-color:var(--theme-border);
    background: var(--green-soft);
    color: var(--green);
}

.agenda-heading {
    display: flex;
    align-items: flex-end;
    justify-content: space-between;
    gap: 12px;
    margin-bottom: 8px;
}

.agenda-heading h1 {
    margin: 0;
    font-size: clamp(16px,2.5vw,20px);
}

.agenda-total {
    color: var(--text-soft);
    font-size:13px;
}

.collection-list {
    display: flex;
    flex-direction: column;
    gap: 7px;
}

.collection-card {
    display: grid;
    grid-template-columns: 44px minmax(0,1fr) auto;
    gap: 10px;
    align-items: center;
    padding: 10px;
    border: 1px solid var(--border);
    border-radius: 14px;
    background:var(--theme-surface-2);
}

.collection-card.late {
    border-color:var(--theme-border);
}

.client-avatar {
    width: 42px;
    height: 42px;
    display: grid;
    place-items: center;
    border:1px solid var(--theme-border);
    border-radius: 50%;
    background: var(--green-soft);
    color: var(--green);
    font-size:13px;
    font-weight: 900;
}

.collection-main {
    min-width: 0;
}

.collection-name-row {
    display: flex;
    align-items: center;
    gap: 6px;
    margin-bottom: 3px;
}

.collection-name-row strong {
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    font-size: 12.5px;
}

.due-badge {
    flex: 0 0 auto;
    padding: 3px 6px;
    border-radius: 999px;
    background: var(--green-soft);
    color: var(--green);
    font-size:13px;
    font-weight: 900;
}

.due-badge.late {
    background: var(--orange-soft);
    color: var(--orange);
}

.due-badge.upcoming {
    background:var(--theme-surface-2);
    color: var(--theme-info);
}

.collection-meta {
    display: flex;
    flex-wrap: wrap;
    gap: 4px 7px;
    margin-bottom: 6px;
    color: var(--text-soft);
    font-size:13px;
}

.collection-finance {
    display: grid;
    grid-template-columns: repeat(2,minmax(0,1fr));
    gap: 6px;
}

.collection-finance div {
    min-width: 0;
    padding: 6px 7px;
    border:1px solid var(--theme-border);
    border-radius: 8px;
    background:var(--theme-surface-2);
}

.collection-finance span {
    display: block;
    margin-bottom: 2px;
    color: var(--text-soft);
    font-size:13px;
}

.collection-finance strong {
    display: block;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    font-size:13px;
}

.collection-action {
    min-width: 86px;
    height: 38px;
    padding: 0 9px;
    border: 0;
    border-radius: 10px;
    background: var(--green);
    color: var(--theme-on-accent);
    font-size:13px;
    font-weight: 850;
    cursor: pointer;
}

.collection-card.late .collection-action {
    background:var(--theme-surface-2);
}

.empty-state {
    display: none;
    padding: 25px 16px;
    border:1px dashed var(--theme-border);
    border-radius: 15px;
    text-align: center;
}

.empty-state.visible {
    display: block;
}

.empty-icon {
    width: 46px;
    height: 46px;
    display: grid;
    place-items: center;
    margin: 0 auto 9px;
    border-radius: 13px;
    background: var(--green-soft);
    color: var(--green);
    font-size: 22px;
    font-weight: 900;
}

.empty-state strong {
    display: block;
    margin-bottom: 5px;
    font-size: 13px;
}

.empty-state p {
    max-width: 380px;
    margin: 0 auto;
    color: var(--text-soft);
    font-size:13px;
    line-height: 1.5;
}

.quick-menu {
    position: fixed;
    z-index: 120;
    left: 50%;
    bottom: calc(86px + env(safe-area-inset-bottom));
    width: min(calc(100% - 28px),420px);
    display: grid;
    gap: 6px;
    padding: 8px;
    opacity: 0;
    visibility: hidden;
    transform: translate(-50%,12px);
    border:1px solid var(--theme-border);
    border-radius: 15px;
    background:var(--theme-surface-2);
    box-shadow:none;
    backdrop-filter:none;
    transition: .18s ease;
}

.quick-menu.open {
    opacity: 1;
    visibility: visible;
    transform: translate(-50%,0);
}

.quick-menu button {
    min-height: 43px;
    display: flex;
    align-items: center;
    gap: 9px;
    padding: 0 10px;
    border: 0;
    border-radius: 10px;
    background:var(--theme-surface-2);
    color: var(--theme-text);
    text-align: left;
    cursor: pointer;
}

.quick-icon {
    width: 28px;
    height: 28px;
    display: grid;
    place-items: center;
    border-radius: 8px;
    background: var(--green-soft);
    color: var(--green);
}

.bottom-nav {
    position: fixed;
    z-index: 100;
    left: 50%;
    bottom: 0;
    width: min(100%,760px);
    min-height: calc(var(--nav-height) + env(safe-area-inset-bottom));
    display: grid;
    grid-template-columns: 1fr 1fr 72px 1fr 1fr;
    align-items: center;
    padding: 7px 14px calc(7px + env(safe-area-inset-bottom));
    transform: translateX(-50%);
    border-top: 1px solid var(--border);
    background:var(--theme-surface-2);
    backdrop-filter:none;
}

.nav-button {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 3px;
    border: 0;
    background: transparent;
    color: #737c78;
    font-size:13px;
    cursor: pointer;
}

.nav-button.active {
    color: var(--green);
}

.nav-icon {
    font-size: 21px;
}

.add-button {
    width: 56px;
    height: 56px;
    display: grid;
    place-items: center;
    margin: -23px auto 0;
    border: 5px solid var(--background);
    border-radius: 50%;
    background: var(--theme-accent);
    color: var(--theme-text);
    font-size: 34px;
    cursor: pointer;
    box-shadow:none;
}

.add-button.open {
    transform: rotate(45deg);
}

.toast {
    position: fixed;
    z-index: 300;
    left: 50%;
    bottom: calc(92px + env(safe-area-inset-bottom));
    max-width: calc(100% - 32px);
    padding: 10px 14px;
    opacity: 0;
    visibility: hidden;
    transform: translate(-50%,10px);
    border:1px solid var(--theme-border);
    border-radius: 999px;
    background: var(--theme-surface-3);
    color: var(--theme-text);
    font-size:13px;
    transition: .2s ease;
}

.toast.show {
    opacity: 1;
    visibility: visible;
    transform: translate(-50%,0);
}

@media (min-width: 650px) {
    .summary-grid {
        grid-template-columns: repeat(4,minmax(0,1fr));
    }

    .collection-list {
        display: grid;
        grid-template-columns: repeat(2,minmax(0,1fr));
    }

    .collection-card {
        grid-template-columns: 44px minmax(0,1fr);
    }

    .collection-action {
        grid-column: 1 / -1;
        width: 100%;
    }
}

@media (max-width: 390px) {
    .collection-card {
        grid-template-columns: 40px minmax(0,1fr);
    }

    .collection-action {
        grid-column: 1 / -1;
        width: 100%;
    }

    .today-box {
        min-width: 61px;
    }
}

@media (max-width: 340px) {
    .filters {
        grid-template-columns: repeat(2,minmax(0,1fr));
    }

    .summary-grid {
        grid-template-columns: 1fr 1fr;
    }
}


/* PASO 14 — tarjeta de cobro abre detalle del préstamo */
.collection-card {
    cursor: pointer;
}

.collection-card:focus-visible {
    outline:2px solid var(--theme-accent);
    outline-offset: 2px;
}


/* =========================================================
   PASO 23 — PROMESAS DE PAGO EN AGENDA
========================================================= */
.promise-summary-card {
    border-color:var(--theme-border);
}

.promise-card {
    border-color:var(--theme-border);
    cursor: pointer;
}

.promise-card.today {
    border-color:var(--theme-border);
}

.promise-card.overdue {
    border-color:var(--theme-border);
    background:var(--theme-danger-soft);
}

.promise-icon {
    width: 40px;
    height: 40px;
    display: grid;
    place-items: center;
    border-radius: 12px;
    background:var(--theme-surface-2);
    color: var(--theme-info);
    font-size: 16px;
    font-weight: 900;
}

.promise-card.today .promise-icon {
    background: var(--green-soft);
    color: var(--green);
}

.promise-card.overdue .promise-icon {
    background:var(--theme-danger-soft);
    color: var(--theme-danger);
}

.promise-detail {
    margin-top: 6px;
    padding: 7px 8px;
    border:1px solid var(--theme-border);
    border-radius: 8px;
    background:var(--theme-surface-2);
    color: var(--text-soft);
    font-size:13px;
    line-height: 1.42;
}

.promise-progress {
    margin-top: 6px;
}

.promise-progress-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
    margin-bottom: 4px;
    color: var(--text-soft);
    font-size:13px;
}

.promise-progress-track {
    height: 5px;
    overflow: hidden;
    border-radius: 999px;
    background:var(--theme-surface-2);
}

.promise-progress-track span {
    display: block;
    height: 100%;
    border-radius: inherit;
    background: var(--green);
}

.promise-actions {
    display: grid;
    grid-template-columns: repeat(2,minmax(0,1fr));
    gap: 6px;
    margin-top: 8px;
}

.promise-action-secondary,
.promise-action-primary {
    min-height: 35px;
    border-radius: 9px;
    font-size:13px;
    font-weight: 850;
    cursor: pointer;
}

.promise-action-secondary {
    border:1px solid var(--theme-border);
    background:var(--theme-surface-2);
    color: var(--theme-info);
}

.promise-action-primary {
    border: 0;
    background: var(--green);
    color: var(--theme-on-accent);
}

.promise-card.overdue .promise-action-primary {
    background:var(--theme-surface-2);
}

.filters {
    grid-template-columns: repeat(5,minmax(0,1fr));
}

@media (max-width:430px) {
    .filters {
        grid-template-columns: repeat(3,minmax(0,1fr));
    }
}

@media (min-width:650px) {
    .summary-grid {
        grid-template-columns: repeat(3,minmax(0,1fr));
    }
}


/* PASO 24 — mora en tarjetas de cobro */
.collection-finance {
    grid-template-columns: repeat(3,minmax(0,1fr));
}

.late-fee-finance strong {
    color: var(--theme-danger) !important;
}

@media (max-width:430px) {
    .collection-finance {
        grid-template-columns: repeat(2,minmax(0,1fr));
    }

    .late-fee-finance {
        grid-column: 1 / -1;
    }
}


/* PASO 26 — pago esperado real */
.collection-finance {
    grid-template-columns: repeat(4,minmax(0,1fr));
}

@media (max-width:520px) {
    .collection-finance {
        grid-template-columns: repeat(2,minmax(0,1fr));
    }

    .late-fee-finance {
        grid-column: auto;
    }
}
