:root {
    --ink: #15233b;
    --muted: #667085;
    --line: #e3e8f0;
    --bg: #f4f6fa;
    --card: #ffffff;
    --navy: #10213f;
    --navy-soft: #1b3158;
    --primary: #315dca;
    --primary-dark: #244ba9;
    --gold: #d4a84f;
    --green: #087a55;
    --red: #bf3f4a;
    --orange: #c56a13;
    --settled: #667085;
    --shadow: 0 12px 34px rgba(20, 36, 65, .075);
    --shadow-strong: 0 18px 45px rgba(20, 36, 65, .14);
}

* { box-sizing: border-box; }

html { min-height: 100%; background: var(--bg); }

body {
    min-height: 100vh;
    margin: 0;
    color: var(--ink);
    background:
        radial-gradient(circle at 12% 0, rgba(49, 93, 202, .07), transparent 28rem),
        linear-gradient(180deg, #f8f9fc 0, var(--bg) 32rem);
    font-family: Inter, ui-sans-serif, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
    line-height: 1.5;
    -webkit-font-smoothing: antialiased;
}

button, input, select, textarea { font: inherit; }

.container { width: min(1120px, calc(100% - 40px)); margin: 0 auto; }

.topbar {
    position: sticky;
    z-index: 100;
    top: 0;
    color: #fff;
    background: linear-gradient(118deg, #0d1b34 0%, var(--navy) 58%, #183461 100%);
    border-bottom: 1px solid rgba(255, 255, 255, .09);
    box-shadow: 0 7px 26px rgba(7, 18, 38, .18);
}

.nav-wrap { display: flex; align-items: center; justify-content: space-between; min-height: 76px; gap: 28px; }
.nav-top { display: flex; align-items: center; }

.brand {
    display: inline-flex;
    align-items: center;
    gap: 11px;
    color: #fff;
    text-decoration: none;
}

.brand-mark {
    display: grid;
    flex: 0 0 42px;
    width: 42px;
    height: 42px;
    place-items: center;
    color: var(--navy);
    background: linear-gradient(145deg, #f4d88d, var(--gold));
    border: 1px solid rgba(255, 255, 255, .35);
    border-radius: 13px;
    box-shadow: 0 8px 18px rgba(0, 0, 0, .2);
    font-family: Georgia, serif;
    font-size: 1.45rem;
    font-weight: 800;
}

.brand-copy, .brand-copy strong, .brand-copy small { display: block; }
.brand-copy strong { font-size: 1.08rem; letter-spacing: .01em; line-height: 1.15; }
.brand-copy small { margin-top: 3px; color: #bfcbe0; font-size: .72rem; letter-spacing: .055em; text-transform: uppercase; }

.topbar nav { display: flex; align-items: center; gap: 5px; flex-wrap: wrap; }
.topbar nav a, .nav-button {
    min-height: 40px;
    padding: 9px 12px;
    color: #dce5f5;
    background: transparent;
    border: 0;
    border-radius: 9px;
    font: inherit;
    font-size: .92rem;
    font-weight: 600;
    text-decoration: none;
    cursor: pointer;
    transition: background .18s ease, color .18s ease, transform .18s ease;
}

.topbar nav a:hover, .nav-button:hover, .topbar nav a.active {
    color: #fff;
    background: rgba(255, 255, 255, .105);
}

.topbar nav a.active { box-shadow: inset 0 -2px 0 var(--gold); }
.topbar nav a:active, .nav-button:active { transform: translateY(1px); }

.menu-toggle {
    display: none;
    width: 44px;
    height: 44px;
    padding: 9px;
    border: 1px solid rgba(255, 255, 255, .25);
    border-radius: 11px;
    background: rgba(255, 255, 255, .06);
    cursor: pointer;
}

.menu-toggle span { display: block; width: 23px; height: 2px; margin: 4px auto; border-radius: 2px; background: #fff; }

main { min-height: calc(100vh - 164px); padding: 34px 0 56px; }
h1, h2, h3 { color: #14213a; line-height: 1.2; }
h1 { letter-spacing: -.035em; }
h2 { margin-top: 0; font-size: 1.2rem; letter-spacing: -.015em; }
.muted { color: var(--muted); }
.eyebrow { display: block; margin-bottom: 7px; color: var(--primary); font-size: .75rem; font-weight: 800; letter-spacing: .1em; text-transform: uppercase; }

.page-head { display: flex; align-items: center; justify-content: space-between; gap: 20px; margin-bottom: 22px; }
.page-head h1 { margin: 0 0 5px; font-size: clamp(1.75rem, 3vw, 2.3rem); }

.card {
    margin-bottom: 20px;
    padding: 23px;
    background: rgba(255, 255, 255, .96);
    border: 1px solid var(--line);
    border-radius: 17px;
    box-shadow: var(--shadow);
}

.grid { display: grid; grid-template-columns: repeat(12, minmax(0, 1fr)); gap: 18px; }
.col-12 { grid-column: span 12; }
.col-8 { grid-column: span 8; }
.col-6 { grid-column: span 6; }
.col-4 { grid-column: span 4; }

.stat { position: relative; overflow: hidden; }
.stat::after { position: absolute; top: -28px; right: -24px; width: 90px; height: 90px; border-radius: 50%; background: rgba(49, 93, 202, .045); content: ""; }
.stat strong { position: relative; z-index: 1; display: block; margin-top: 5px; font-size: 1.72rem; letter-spacing: -.025em; }
.stat span { color: var(--muted); font-size: .9rem; font-weight: 650; }
.stat small { position: relative; z-index: 1; color: #8a93a2; }

label { display: block; margin-bottom: 7px; color: #293750; font-size: .9rem; font-weight: 700; }
input, select, textarea {
    width: 100%;
    min-height: 46px;
    padding: 11px 13px;
    color: var(--ink);
    background: #fff;
    border: 1px solid #cfd6e2;
    border-radius: 10px;
    transition: border-color .18s ease, box-shadow .18s ease, background .18s ease;
}

input:hover, select:hover, textarea:hover { border-color: #abb8ca; }
input:focus, select:focus, textarea:focus { outline: 0; border-color: var(--primary); box-shadow: 0 0 0 4px rgba(49, 93, 202, .12); }
textarea { min-height: 100px; resize: vertical; }

.actions { display: flex; align-items: center; flex-wrap: wrap; gap: 10px; margin-top: 20px; }
.btn {
    display: inline-flex;
    min-height: 44px;
    align-items: center;
    justify-content: center;
    padding: 10px 17px;
    color: #fff;
    background: linear-gradient(135deg, #3768dc, var(--primary));
    border: 1px solid transparent;
    border-radius: 10px;
    box-shadow: 0 7px 16px rgba(49, 93, 202, .19);
    font-weight: 700;
    text-decoration: none;
    cursor: pointer;
    transition: transform .16s ease, box-shadow .16s ease, background .16s ease;
}

.btn:hover { background: linear-gradient(135deg, var(--primary), var(--primary-dark)); box-shadow: 0 9px 20px rgba(49, 93, 202, .26); transform: translateY(-1px); }
.btn:active { transform: translateY(0); }
.btn.secondary { color: #34445f; background: #f4f6fa; border-color: #dce2eb; box-shadow: none; }
.btn.secondary:hover { color: var(--navy); background: #e9edf4; }
.btn.danger { background: var(--red); box-shadow: none; }
.inline { display: inline; }

.search { display: grid; grid-template-columns: 1fr auto; gap: 10px; }
.table-wrap { overflow: auto; }
table { width: 100%; border-collapse: separate; border-spacing: 0; }
th, td { padding: 13px 11px; text-align: left; vertical-align: top; border-bottom: 1px solid var(--line); }
th { color: #657086; background: #f7f9fc; font-size: .76rem; letter-spacing: .045em; text-transform: uppercase; }
th:first-child { border-radius: 9px 0 0 9px; }
th:last-child { border-radius: 0 9px 9px 0; }
tbody tr:last-child td { border-bottom: 0; }
tbody tr { transition: background .15s ease; }
tbody tr:hover { background: #fafbfe; }
.amount { text-align: right; white-space: nowrap; }
.positive { color: var(--green); font-weight: 750; }
.received { color: var(--green); font-weight: 750; }
.payable { color: var(--orange); font-weight: 750; }
.paid-out { color: var(--orange); font-weight: 750; }
.settled { color: var(--settled); font-weight: 750; }
.badge { display: inline-block; padding: 4px 9px; border-radius: 999px; font-size: .76rem; font-weight: 750; }
.badge.given { color: #9a5000; background: #fff4e5; }
.badge.received { color: var(--green); background: #e9f8f2; }
.alert { margin-bottom: 18px; padding: 13px 15px; border-radius: 11px; }
.alert.success { color: #096548; background: #eaf8f1; border: 1px solid #b8e5d2; }
.alert.error { color: #a12c2c; background: #fff0f0; border: 1px solid #f0c4c4; }

.login-shell { width: min(440px, calc(100% - 28px)); margin: 52px auto; }
.login-shell .card { padding: 34px; border-top: 4px solid var(--gold); box-shadow: var(--shadow-strong); }
.login-shell h1 { margin: 0 0 7px; font-size: 2rem; }
.login-shell form { margin-top: 24px; }
.login-shell .btn { width: 100%; margin-top: 5px; }

.footer { display: flex; justify-content: center; flex-wrap: wrap; gap: 7px; padding: 0 18px 32px; color: #80899a; font-size: .84rem; text-align: center; }
.footer strong { color: #59657a; }
.empty { padding: 30px; color: var(--muted); text-align: center; }
.person-title { display: flex; align-items: center; gap: 12px; }
.balance-box { border-left: 4px solid var(--primary); }
.collect-tone { border-top-color: rgba(8, 122, 85, .5); }
.payable-tone { border-top-color: rgba(197, 106, 19, .55); }
.balance-box.collect-tone { border-left-color: var(--green); }
.balance-box.payable-tone { border-left-color: var(--orange); }
.balance-box.settled-tone { border-left-color: var(--settled); }
.help { margin-top: 5px; color: var(--muted); font-size: .88rem; }
.danger-text { color: var(--red); }
.settlement-linker { margin-top: 18px; padding: 16px; background: #f8faff; border: 1px solid #dce5f6; border-radius: 13px; }
.settlement-linker summary { color: var(--primary-dark); font-weight: 750; cursor: pointer; }
.settlement-linker > .muted { margin: 10px 0; font-size: .88rem; }
.settlement-options { display: grid; gap: 9px; }
.settlement-option { display: grid; grid-template-columns: auto minmax(0,1fr) minmax(110px,150px); align-items: center; gap: 10px; margin: 0; padding: 11px; background: #fff; border: 1px solid var(--line); border-radius: 11px; }
.settlement-option[hidden] { display: none; }
.settlement-option > input[type="checkbox"] { width: 20px; min-height: 20px; }
.settlement-option span, .settlement-option strong, .settlement-option small { display: block; }
.settlement-option small { color: var(--muted); font-weight: 500; }
.allocation-amount { min-height: 40px; }
.settlement-note { color: var(--primary-dark); font-weight: 700; }
.settlement-available { margin: 12px 0; padding: 10px 12px; color: #34445f; background: #eef3fd; border-radius: 9px; }
.mobile-quick-nav { display: none; }

.ios-install-guide {
    position: fixed;
    z-index: 1000;
    left: 50%;
    bottom: max(14px, env(safe-area-inset-bottom));
    display: flex;
    width: min(430px, calc(100% - 24px));
    align-items: center;
    gap: 12px;
    padding: 14px 42px 14px 14px;
    color: var(--ink);
    background: #fff;
    border: 1px solid #d9e0ec;
    border-radius: 16px;
    box-shadow: var(--shadow-strong);
    transform: translateX(-50%);
}

.ios-install-guide[hidden] { display: none; }
.ios-install-guide img { flex: 0 0 54px; border-radius: 13px; }
.ios-install-guide strong, .ios-install-guide span { display: block; }
.ios-install-guide span { margin-top: 2px; color: var(--muted); font-size: .87rem; line-height: 1.35; }
.ios-install-guide b { color: var(--ink); }
.ios-install-close { position: absolute; top: 5px; right: 8px; padding: 6px; color: #667085; background: transparent; border: 0; font-size: 1.65rem; line-height: 1; cursor: pointer; }

@media (max-width: 760px) {
    body { padding-bottom: calc(74px + env(safe-area-inset-bottom)); font-size: 15px; }
    .container { width: min(100% - 22px, 1120px); }
    .topbar { position: sticky; }
    .nav-wrap { min-height: 68px; align-items: flex-start; flex-direction: column; gap: 0; padding: 12px 0; }
    .nav-top { width: 100%; justify-content: space-between; }
    .brand-mark { width: 40px; height: 40px; flex-basis: 40px; border-radius: 12px; }
    .brand-copy small { display: none; }
    .menu-toggle { display: block; flex: 0 0 44px; }
    .topbar nav { display: none; width: 100%; padding-top: 10px; }
    .topbar nav.open { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 6px; }
    .topbar nav a, .topbar nav .inline, .nav-button { width: 100%; text-align: center; }
    .topbar nav a.active { box-shadow: none; background: rgba(255, 255, 255, .12); }
    main { min-height: 0; padding: 22px 0 34px; }
    .page-head { align-items: flex-start; flex-direction: column; margin-bottom: 17px; }
    .page-head h1 { font-size: 1.75rem; }
    .page-head > .btn { width: 100%; }
    .card { padding: 17px; margin-bottom: 14px; border-radius: 15px; box-shadow: 0 8px 24px rgba(20, 36, 65, .065); }
    .grid { display: block; }
    .grid > [class^="col-"] { margin-bottom: 15px; }
    input, select, textarea, .btn, .nav-button { min-height: 46px; font-size: 16px; }
    .search { grid-template-columns: 1fr; }
    .table-wrap { overflow: visible; }
    .footer { padding-bottom: 14px; }

    .mobile-quick-nav {
        position: fixed;
        z-index: 150;
        right: 0;
        bottom: 0;
        left: 0;
        display: grid;
        grid-template-columns: repeat(3, 1fr);
        min-height: 66px;
        padding: 5px max(8px, env(safe-area-inset-right)) calc(5px + env(safe-area-inset-bottom)) max(8px, env(safe-area-inset-left));
        background: rgba(255, 255, 255, .97);
        border-top: 1px solid #dfe4ec;
        box-shadow: 0 -9px 28px rgba(16, 33, 63, .1);
        backdrop-filter: blur(16px);
    }

    .mobile-quick-nav a { display: flex; align-items: center; justify-content: center; flex-direction: column; gap: 1px; color: #7a8495; text-decoration: none; }
    .mobile-quick-nav a > span { display: grid; width: 29px; height: 29px; place-items: center; border-radius: 10px; font-size: 1.35rem; font-weight: 700; line-height: 1; }
    .mobile-quick-nav a small { font-size: .69rem; font-weight: 750; }
    .mobile-quick-nav a.active { color: var(--primary); }
    .mobile-quick-nav .quick-add > span { color: #fff; background: var(--primary); box-shadow: 0 5px 12px rgba(49, 93, 202, .24); }
    .mobile-quick-nav .quick-add.active > span { background: var(--navy); }

    .ios-install-guide { bottom: calc(78px + env(safe-area-inset-bottom)); }
    .settlement-option { grid-template-columns: auto 1fr; }
    .settlement-option .allocation-amount { grid-column: 2; }
}

@media print {
    .topbar, .footer, .mobile-quick-nav, .ios-install-guide, .no-print, .mobile-action { display: none !important; }
    body { padding: 0; color: #000; background: #fff; }
    main.container { width: 100%; padding: 0; }
    .card { box-shadow: none; border-color: #bbb; break-inside: avoid; }
    table { font-size: 11pt; }
}

.login-support { margin: 18px 0 0; text-align: center; }
.login-support a { color: var(--primary); font-weight: 700; text-decoration: none; }
.login-support a:hover { text-decoration: underline; }
