@font-face {
    font-family: "Poppins";
    src: url("fonts/Poppins-Regular.ttf") format("truetype");
    font-style: normal;
    font-weight: 400;
    font-display: swap;
}

@font-face {
    font-family: "Poppins";
    src: url("fonts/Poppins-Medium.ttf") format("truetype");
    font-style: normal;
    font-weight: 500;
    font-display: swap;
}

@font-face {
    font-family: "Poppins";
    src: url("fonts/Poppins-SemiBold.ttf") format("truetype");
    font-style: normal;
    font-weight: 600;
    font-display: swap;
}

:root {
    color-scheme: light;
    --navy-950: #030540;
    --navy-900: #030540;
    --navy-800: #2b2d5e;
    --blue-600: #0a2b8c;
    --blue-500: #314d9f;
    --blue-100: #eef1fb;
    --slate-900: #030540;
    --slate-700: #3d3845;
    --slate-500: #626488;
    --slate-300: #c7cadb;
    --slate-200: #e3e4ec;
    --slate-100: #f5f5f8;
    --white: #ffffff;
    --green: #0b9361;
    --green-soft: #ddf7ec;
    --red: #c33a44;
    --red-soft: #fff0f1;
    --shadow: 0 18px 48px rgba(3, 5, 64, 0.11);
    --radius: 14px;
}

* { box-sizing: border-box; }
html { min-height: 100%; background: var(--slate-100); }
body {
    min-height: 100vh;
    margin: 0;
    color: var(--slate-900);
    background:
        radial-gradient(circle at 88% 0%, rgba(10, 43, 140, 0.09), transparent 34rem),
        var(--slate-100);
    font-family: "Poppins", Arial, sans-serif;
    font-size: 16px;
    line-height: 1.5;
}

button, input, select { font: inherit; }
button { cursor: pointer; }
input, select {
    width: 100%;
    min-height: 48px;
    border: 1px solid var(--slate-300);
    border-radius: 11px;
    background: var(--white);
    color: var(--slate-900);
    outline: none;
    transition: border-color .16s ease, box-shadow .16s ease, background .16s ease;
}
input { padding: 0 14px; }
select { padding: 0 38px 0 13px; }
input:focus, select:focus {
    border-color: var(--blue-500);
    box-shadow: 0 0 0 4px rgba(10, 43, 140, 0.12);
}

.topbar {
    position: sticky;
    z-index: 10;
    top: 0;
    border-bottom: 1px solid rgba(255,255,255,.09);
    background: rgba(3, 5, 64, 0.97);
    color: var(--white);
    backdrop-filter: blur(12px);
}
.topbar-inner {
    display: grid;
    grid-template-columns: auto 1fr auto;
    align-items: center;
    gap: 24px;
    width: min(1240px, calc(100% - 40px));
    min-height: 90px;
    margin: 0 auto;
}
.brand { display: inline-flex; align-items: center; }
.brand-logo-topbar {
    display: block;
    width: 84px;
    height: auto;
}
.main-nav {
    display: inline-flex;
    justify-self: center;
    gap: 4px;
    padding: 4px;
    border: 1px solid rgba(255,255,255,.14);
    border-radius: 11px;
    background: rgba(255,255,255,.06);
}
.nav-link {
    min-width: 112px;
    border-radius: 8px;
    padding: 9px 15px;
    color: #c7cadb;
    font-size: 14px;
    font-weight: 500;
    text-align: center;
    text-decoration: none;
    transition: color .16s ease, background .16s ease;
}
.nav-link:hover { color: var(--white); background: rgba(255,255,255,.08); }
.nav-link.active { color: var(--navy-950); background: var(--white); }
.header-actions { display: flex; align-items: center; justify-self: end; gap: 18px; }
.header-actions form { margin: 0; }
.saved-state { color: #c7cadb; font-size: 14px; }
.saved-state.dirty { color: #ffd47e; }

.page-shell { width: min(1240px, calc(100% - 40px)); margin: 0 auto; padding: 42px 0 72px; }
.page-intro { display: flex; align-items: end; justify-content: space-between; gap: 32px; margin-bottom: 28px; }
.page-intro h1 { margin: 4px 0 0; font-size: clamp(30px, 4vw, 42px); font-weight: 600; line-height: 1.14; letter-spacing: -.025em; }
.page-intro > p { max-width: 560px; margin: 0 0 5px; color: var(--slate-700); }
.eyebrow { margin: 0; color: var(--blue-600); font-size: 13px; font-weight: 600; letter-spacing: .12em; text-transform: uppercase; }

.workspace-grid { display: grid; grid-template-columns: minmax(0, 1fr) 390px; align-items: start; gap: 24px; }
.input-column { display: grid; gap: 18px; }
.form-card, .summary-card {
    border: 1px solid var(--slate-200);
    border-radius: var(--radius);
    background: var(--white);
    box-shadow: 0 6px 24px rgba(3,5,64,.06);
}
.form-card { padding: 25px; }
.section-heading, .section-heading-main { display: flex; align-items: flex-start; gap: 14px; }
.section-heading { margin-bottom: 22px; }
.section-heading-action { justify-content: space-between; }
.section-number {
    display: inline-grid;
    flex: 0 0 40px;
    height: 32px;
    place-items: center;
    border-radius: 9px;
    background: var(--blue-100);
    color: var(--blue-600);
    font-size: 13px;
    font-weight: 600;
}
.section-heading h2, .subsection-head h3 { margin: 0; line-height: 1.2; }
.section-heading h2 { font-size: 20px; font-weight: 600; }
.section-heading p, .subsection-head p { margin: 4px 0 0; color: var(--slate-500); font-size: 14px; }

.field-grid { display: grid; gap: 16px; }
.two-columns { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.money-field { display: grid; gap: 8px; color: var(--slate-700); font-size: 14px; font-weight: 500; }
.money-input {
    display: flex;
    align-items: center;
    min-height: 48px;
    overflow: hidden;
    border: 1px solid var(--slate-300);
    border-radius: 11px;
    background: var(--white);
    transition: border-color .16s ease, box-shadow .16s ease;
}
.money-input:focus-within { border-color: var(--blue-500); box-shadow: 0 0 0 4px rgba(10,43,140,.12); }
.money-input > span { display: grid; align-self: stretch; min-width: 42px; place-items: center; border-right: 1px solid var(--slate-200); background: var(--slate-100); color: var(--slate-700); }
.money-input input { min-height: 46px; border: 0; border-radius: 0; box-shadow: none; text-align: right; font-variant-numeric: tabular-nums; }
.money-input input:focus { box-shadow: none; }
.money-input.compact { min-width: 170px; }

.subsection-head { display: flex; align-items: center; justify-content: space-between; gap: 16px; margin: 26px 0 12px; padding-top: 23px; border-top: 1px solid var(--slate-200); }
.subsection-head h3 { font-size: 16px; }
.dynamic-list { display: grid; gap: 10px; }
.dynamic-row { display: grid; align-items: center; gap: 10px; }
.pending-row { grid-template-columns: minmax(150px, 1fr) 148px 175px 42px; }
.investment-row { grid-template-columns: minmax(200px, 1fr) 190px 42px; }
.dynamic-row label { min-width: 0; }
.icon-button {
    width: 42px;
    height: 42px;
    border: 1px solid #f1cbd0;
    border-radius: 10px;
    background: var(--red-soft);
    color: var(--red);
    font-size: 24px;
    line-height: 1;
}
.icon-button:hover { background: #ffe3e6; }

.summary-card { position: sticky; top: 114px; overflow: hidden; box-shadow: var(--shadow); }
.summary-top { padding: 28px 28px 25px; background: var(--navy-950); color: var(--white); }
.summary-top .eyebrow { color: #b8c6ee; }
.summary-top h2 { margin: 7px 0 18px; font-size: 18px; font-weight: 650; }
.forecast-amount { font-size: clamp(33px, 4vw, 46px); font-weight: 600; line-height: 1.08; letter-spacing: -.035em; font-variant-numeric: tabular-nums; overflow-wrap: anywhere; }
.forecast-amount.positive { color: #5fe0a7; }
.forecast-amount.negative { color: #ff8991; }
.forecast-status { margin: 10px 0 0; color: #bbcadb; font-size: 14px; }
.summary-breakdown { padding: 22px 28px 10px; }
.summary-row { display: flex; justify-content: space-between; gap: 20px; padding: 13px 0; border-bottom: 1px solid var(--slate-200); font-size: 14px; }
.summary-row span { color: var(--slate-700); }
.summary-row strong { white-space: nowrap; font-variant-numeric: tabular-nums; }
.summary-row.incoming strong { color: var(--green); }
.summary-row.outgoing strong { color: var(--red); }
.calculation-strip { display: flex; flex-wrap: wrap; justify-content: center; gap: 7px; margin: 10px 28px 20px; padding: 11px; border-radius: 10px; background: var(--slate-100); color: var(--slate-500); font-size: 12px; }
.summary-card .button-save { width: calc(100% - 56px); margin: 0 28px; }
.summary-note { margin: 14px 28px 24px; color: var(--slate-500); font-size: 12px; text-align: center; }

.loans-shell { max-width: 1240px; }
.loan-summary-grid {
    display: grid;
    grid-template-columns: 1.25fr 1fr 1fr;
    gap: 16px;
    margin-bottom: 18px;
}
.loan-summary-card {
    display: grid;
    min-height: 142px;
    align-content: center;
    gap: 7px;
    border: 1px solid var(--slate-200);
    border-radius: var(--radius);
    padding: 24px;
    background: var(--white);
    box-shadow: 0 6px 24px rgba(3,5,64,.06);
}
.loan-summary-card span { color: var(--slate-500); font-size: 14px; }
.loan-summary-card strong { color: var(--navy-950); font-size: clamp(25px, 3vw, 34px); font-weight: 600; line-height: 1.15; font-variant-numeric: tabular-nums; }
.loan-summary-card small { color: var(--slate-500); font-size: 12px; }
.loan-summary-card.primary { border-color: var(--navy-950); background: var(--navy-950); }
.loan-summary-card.primary span, .loan-summary-card.primary small { color: #c7cadb; }
.loan-summary-card.primary strong { color: var(--white); }

.loan-add-card { margin-bottom: 38px; }
.loan-add-form {
    display: grid;
    grid-template-columns: 1.2fr 1.1fr .7fr 1fr auto;
    align-items: end;
    gap: 14px;
}
.standard-field { display: grid; gap: 8px; color: var(--slate-700); font-size: 14px; font-weight: 500; }
.loan-add-button { min-height: 48px; white-space: nowrap; }

.loans-list-section { display: grid; gap: 16px; }
.list-heading { display: flex; align-items: end; justify-content: space-between; gap: 20px; }
.list-heading h2 { margin: 4px 0 0; font-size: 26px; font-weight: 600; }
.count-badge { border-radius: 999px; padding: 7px 12px; background: var(--blue-100); color: var(--blue-600); font-size: 13px; font-weight: 600; }
.loans-list { display: grid; gap: 14px; }
.loan-card {
    border: 1px solid var(--slate-200);
    border-radius: var(--radius);
    padding: 24px;
    background: var(--white);
    box-shadow: 0 6px 24px rgba(3,5,64,.05);
}
.loan-card.is-paid { border-color: #b9dfcf; }
.loan-card-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 20px; }
.loan-category { display: inline-block; margin-bottom: 7px; color: var(--blue-600); font-size: 12px; font-weight: 600; letter-spacing: .08em; text-transform: uppercase; }
.loan-card h3 { margin: 0; color: var(--navy-950); font-size: 21px; font-weight: 600; }
.loan-card-head p { margin: 4px 0 0; color: var(--slate-500); font-size: 14px; }
.loan-status { flex: 0 0 auto; border-radius: 999px; padding: 7px 11px; font-size: 12px; font-weight: 600; }
.loan-status.open { background: var(--blue-100); color: var(--blue-600); }
.loan-status.paid { background: var(--green-soft); color: var(--green); }

.loan-amount-grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 12px; margin-top: 22px; }
.loan-amount-grid > div { display: grid; gap: 5px; border-left: 2px solid var(--slate-200); padding-left: 14px; }
.loan-amount-grid span { color: var(--slate-500); font-size: 13px; }
.loan-amount-grid strong { color: var(--slate-900); font-size: 18px; font-weight: 600; font-variant-numeric: tabular-nums; }
.loan-amount-grid .remaining { border-color: var(--blue-600); }
.loan-amount-grid .remaining strong { color: var(--blue-600); }

.loan-progress {
    display: block;
    width: 100%;
    height: 9px;
    margin: 21px 0 0;
    overflow: hidden;
    border: 0;
    border-radius: 999px;
    background: var(--slate-200);
    color: var(--blue-600);
}
.loan-progress::-webkit-progress-bar { border-radius: 999px; background: var(--slate-200); }
.loan-progress::-webkit-progress-value { border-radius: 999px; background: var(--blue-600); }
.loan-progress::-moz-progress-bar { border-radius: 999px; background: var(--blue-600); }
.loan-card.is-paid .loan-progress::-webkit-progress-value { background: var(--green); }
.loan-card.is-paid .loan-progress::-moz-progress-bar { background: var(--green); }

.loan-edit-panel { margin-top: 18px; border-top: 1px solid var(--slate-200); padding-top: 15px; }
.loan-edit-panel > summary { color: var(--blue-600); font-size: 13px; font-weight: 600; cursor: pointer; }
.loan-edit-panel[open] > summary { margin-bottom: 14px; }
.loan-edit-content { display: grid; gap: 18px; border-radius: 11px; padding: 18px; background: var(--slate-100); }
.loan-edit-form {
    display: grid;
    grid-template-columns: 1.1fr 1.1fr .7fr 1fr;
    align-items: end;
    gap: 12px;
}
.loan-edit-save { grid-column: 1 / -1; justify-self: start; min-height: 46px; }
.loan-delete-form { display: flex; align-items: center; justify-content: space-between; gap: 18px; border-top: 1px solid var(--slate-200); padding-top: 17px; }
.delete-confirmation { display: flex; align-items: center; gap: 10px; color: var(--slate-700); font-size: 13px; cursor: pointer; }
.delete-confirmation input { flex: 0 0 auto; width: 18px; height: 18px; min-height: 0; margin: 0; accent-color: var(--red); }
.button-danger { min-height: 44px; border: 1px solid #e4aab0; background: var(--red-soft); color: var(--red); white-space: nowrap; }
.button-danger:hover { background: #ffe3e6; }

.repayment-form {
    display: grid;
    grid-template-columns: minmax(230px, 1fr) auto auto;
    align-items: end;
    gap: 10px;
    margin-top: 22px;
    padding-top: 21px;
    border-top: 1px solid var(--slate-200);
}
.repayment-form .button { min-height: 48px; white-space: nowrap; }
.repayment-amount { max-width: 360px; }
.repayment-history { margin-top: 18px; border-top: 1px solid var(--slate-200); padding-top: 15px; }
.repayment-history summary { color: var(--blue-600); font-size: 13px; font-weight: 600; cursor: pointer; }
.repayment-history ul { display: grid; gap: 8px; margin: 13px 0 0; padding: 0; list-style: none; }
.repayment-history li { display: flex; justify-content: space-between; gap: 20px; padding: 8px 10px; border-radius: 8px; background: var(--slate-100); color: var(--slate-500); font-size: 13px; }
.repayment-history li strong { color: var(--slate-900); font-weight: 600; font-variant-numeric: tabular-nums; }
.empty-state { border: 1px dashed var(--slate-300); border-radius: var(--radius); padding: 40px 24px; background: rgba(255,255,255,.6); text-align: center; }
.empty-state h3 { margin: 0; font-size: 19px; font-weight: 600; }
.empty-state p { margin: 7px 0 0; color: var(--slate-500); }

.button {
    display: inline-flex;
    min-height: 42px;
    align-items: center;
    justify-content: center;
    border: 0;
    border-radius: 10px;
    padding: 0 16px;
    font-weight: 600;
    text-decoration: none;
    transition: transform .14s ease, background .14s ease, opacity .14s ease;
}
.button:hover { transform: translateY(-1px); }
.button:disabled { cursor: wait; opacity: .7; transform: none; }
.button-primary { background: var(--blue-600); color: var(--white); box-shadow: 0 8px 20px rgba(10,43,140,.22); }
.button-primary:hover { background: var(--navy-950); }
.button-secondary { border: 1px solid #7184bc; background: #eef1fb; color: var(--blue-600); }
.button-quiet { border: 1px solid rgba(255,255,255,.18); background: rgba(255,255,255,.08); color: var(--white); }
.button-small { min-height: 38px; padding: 0 13px; font-size: 14px; white-space: nowrap; }
.button-full { width: 100%; min-height: 50px; }

.alert { margin-bottom: 18px; border: 1px solid; border-radius: 12px; padding: 13px 15px; font-size: 14px; }
.alert-success { border-color: #a9e3ca; background: var(--green-soft); color: #076b49; }
.alert-error { border-color: #f1bdc2; background: var(--red-soft); color: #9d2730; }

.login-page { display: grid; place-items: center; padding: 24px; background: radial-gradient(circle at 70% 10%, #2b2d5e 0, transparent 35rem), var(--navy-950); }
.login-shell { width: min(100%, 450px); }
.login-card { border: 1px solid rgba(255,255,255,.09); border-radius: 24px; padding: 34px; background: var(--white); box-shadow: 0 28px 80px rgba(0,0,0,.3); }
.brand-login { display: flex; justify-content: center; margin: -8px auto 28px; }
.brand-logo-login { display: block; width: 205px; height: auto; }
.login-heading h1 { margin: 5px 0 8px; font-size: 31px; font-weight: 600; line-height: 1.15; letter-spacing: -.025em; }
.login-heading > p:last-child { margin: 0 0 24px; color: var(--slate-500); }
.login-form { display: grid; gap: 17px; }
.login-form label { display: grid; gap: 7px; color: var(--slate-700); font-size: 14px; font-weight: 500; }
.login-form .button { margin-top: 4px; }

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

@media (max-width: 980px) {
    .workspace-grid { grid-template-columns: 1fr; }
    .summary-card { position: static; grid-row: 1; }
    .summary-card .button-save { width: calc(100% - 48px); margin: 0 24px; }
    .summary-note { margin-left: 24px; margin-right: 24px; }
    .loan-add-form { grid-template-columns: repeat(2, minmax(0, 1fr)); }
    .loan-add-button { grid-column: 1 / -1; width: 100%; }
    .loan-edit-form { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}

@media (max-width: 700px) {
    .topbar-inner, .page-shell { width: min(100% - 24px, 1240px); }
    .topbar-inner { grid-template-columns: 1fr auto; gap: 8px 12px; min-height: 78px; padding-top: 10px; }
    .brand { grid-column: 1; grid-row: 1; }
    .header-actions { grid-column: 2; grid-row: 1; }
    .main-nav { grid-column: 1 / -1; grid-row: 2; justify-self: stretch; margin-top: 2px; border: 0; border-top: 1px solid rgba(255,255,255,.12); border-radius: 0; padding: 7px 0; background: transparent; }
    .nav-link { flex: 1; min-width: 0; padding-top: 7px; padding-bottom: 7px; }
    .saved-state { display: none; }
    .brand-logo-topbar { width: 68px; }
    .page-shell { padding-top: 25px; }
    .page-intro { display: block; margin-bottom: 20px; }
    .page-intro > p { margin-top: 12px; }
    .page-intro h1 { font-size: 34px; }
    .form-card { padding: 20px 16px; }
    .two-columns { grid-template-columns: 1fr; }
    .section-heading-action { display: grid; }
    .section-heading-action > .button { justify-self: start; margin-left: 54px; }
    .pending-row, .investment-row { grid-template-columns: minmax(0, 1fr) 42px; padding: 13px; border: 1px solid var(--slate-200); border-radius: 13px; background: #fbfcfe; }
    .pending-row > label:first-child, .investment-row > label:first-child { grid-column: 1 / -1; }
    .pending-row > label:nth-child(2) { grid-column: 1 / 2; }
    .pending-row .money-input { grid-column: 1 / 2; }
    .pending-row .icon-button { grid-column: 2; grid-row: 2 / span 2; align-self: center; }
    .investment-row .icon-button { grid-column: 2; grid-row: 2; }
    .money-input.compact { min-width: 0; }
    .summary-top, .summary-breakdown { padding-left: 22px; padding-right: 22px; }
    .calculation-strip { margin-left: 22px; margin-right: 22px; }
    .loan-summary-grid { grid-template-columns: 1fr; }
    .loan-summary-card { min-height: 118px; }
    .loan-add-form { grid-template-columns: 1fr; }
    .loan-add-button { min-height: 50px; }
    .loan-amount-grid { grid-template-columns: 1fr; }
    .repayment-form { grid-template-columns: 1fr; }
    .repayment-amount { max-width: none; }
    .repayment-form .button { width: 100%; }
    .loan-edit-form { grid-template-columns: 1fr; }
    .loan-edit-save { width: 100%; }
    .loan-delete-form { display: grid; }
    .button-danger { width: 100%; }
}

@media (max-width: 430px) {
    .header-actions { gap: 8px; }
    .button-quiet { padding: 0 12px; }
    .login-card { padding: 27px 22px; }
    .subsection-head { align-items: flex-start; }
    .subsection-head { display: grid; }
    .subsection-head .button { justify-self: start; }
    .loan-card { padding: 19px 16px; }
    .loan-card-head { display: grid; }
    .loan-status { justify-self: start; }
}

@media print {
    .topbar, .button, .icon-button, .page-intro > p { display: none !important; }
    body { background: white; }
    .page-shell { width: 100%; padding: 0; }
    .workspace-grid { grid-template-columns: 1fr 330px; }
    .form-card, .summary-card { break-inside: avoid; box-shadow: none; }
    .summary-card { position: static; }
}
