:root {
    --bg: #f4f7fb;
    --surface: #ffffff;
    --surface-soft: #f8fafc;
    --text: #152033;
    --muted: #667085;
    --border: #e4e9f1;
    --primary: #2457d6;
    --primary-dark: #1744b5;
    --green: #12805c;
    --green-bg: #e9f8f2;
    --red: #c43232;
    --red-bg: #fff0f0;
    --amber: #9b6500;
    --amber-bg: #fff7df;
    --shadow: 0 12px 35px rgba(33, 48, 76, .08);
    --radius: 16px;
}

* { box-sizing: border-box; }
html { scroll-behavior: smooth; }
body {
    margin: 0;
    font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
    background: var(--bg);
    color: var(--text);
    line-height: 1.5;
}
button, input, select, textarea { font: inherit; }
button { cursor: pointer; }
code { background: #eef2f7; padding: 2px 6px; border-radius: 6px; }
.container { width: min(1180px, calc(100% - 32px)); margin: 0 auto; }

.app-header {
    background: linear-gradient(125deg, #10224a, #2457d6 60%, #3674f4);
    color: white;
    padding: 34px 0 88px;
}
.header-inner { display: flex; align-items: center; justify-content: space-between; gap: 24px; }
.eyebrow { text-transform: uppercase; letter-spacing: .14em; font-size: .74rem; font-weight: 800; opacity: .75; }
h1 { margin: 5px 0 6px; font-size: clamp(2rem, 4vw, 3rem); line-height: 1.08; }
.app-header p { margin: 0; opacity: .82; }
.header-actions { display: flex; gap: 10px; flex-wrap: wrap; }

.main-content { margin-top: -54px; padding-bottom: 45px; }
.summary-grid { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 14px; }
.summary-card {
    background: var(--surface);
    border: 1px solid rgba(255,255,255,.7);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    padding: 20px;
}
.summary-card span { display: block; color: var(--muted); font-size: .86rem; margin-bottom: 7px; }
.summary-card strong { display: block; font-size: 1.45rem; letter-spacing: -.02em; }

.tabs {
    display: flex;
    gap: 6px;
    margin: 22px 0 16px;
    overflow-x: auto;
    padding: 4px;
    background: #e8edf5;
    border-radius: 12px;
    width: fit-content;
    max-width: 100%;
}
.tab {
    border: 0;
    background: transparent;
    color: #536076;
    padding: 10px 18px;
    border-radius: 9px;
    font-weight: 700;
    white-space: nowrap;
}
.tab.active { background: white; color: var(--primary); box-shadow: 0 2px 8px rgba(31, 45, 73, .08); }
.tab-panel { display: none; }
.tab-panel.active { display: block; }

.two-column { display: grid; grid-template-columns: 1.08fr .92fr; gap: 16px; margin-bottom: 16px; }
.panel {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: 0 6px 24px rgba(33, 48, 76, .045);
    overflow: hidden;
}
.panel-header { display: flex; justify-content: space-between; align-items: center; gap: 16px; padding: 20px 22px; border-bottom: 1px solid var(--border); }
.panel-header.wrap { flex-wrap: wrap; }
.panel h2 { margin: 0; font-size: 1.08rem; }
.panel p, .section-heading p { color: var(--muted); margin: 3px 0 0; font-size: .84rem; }
.toolbar { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.toolbar .input { min-width: 240px; }

.btn {
    border: 1px solid #d8dee9;
    background: white;
    color: #344054;
    padding: 10px 15px;
    border-radius: 10px;
    font-weight: 750;
    transition: .18s ease;
}
.btn:hover { transform: translateY(-1px); border-color: #bcc6d5; }
.btn-primary { background: var(--primary); border-color: var(--primary); color: white; }
.btn-primary:hover { background: var(--primary-dark); border-color: var(--primary-dark); }
.btn-light { background: rgba(255,255,255,.96); color: #1c3f91; border-color: transparent; }
.btn-small { padding: 7px 10px; font-size: .82rem; }
.btn-danger { color: var(--red); border-color: #f0c4c4; background: #fffafa; }
.link-btn { border: 0; padding: 3px; background: transparent; color: var(--primary); font-weight: 750; }
.icon-btn { border: 0; background: transparent; color: #667085; font-size: 1.8rem; line-height: 1; padding: 2px 5px; }
.action-row { display: flex; gap: 6px; justify-content: flex-end; flex-wrap: wrap; }

.balance-list { padding: 8px 22px 18px; }
.balance-item { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 13px 0; border-bottom: 1px solid var(--border); }
.balance-item:last-child { border-bottom: 0; }
.person { display: flex; align-items: center; gap: 11px; min-width: 0; }
.avatar { width: 40px; height: 40px; border-radius: 12px; display: grid; place-items: center; font-weight: 850; color: #23438f; background: #e9efff; flex: 0 0 auto; }
.person strong { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.person small { color: var(--muted); }
.balance-value { font-weight: 850; text-align: right; }
.balance-value.positive { color: var(--green); }
.balance-value.negative { color: var(--red); }
.balance-value.zero { color: var(--muted); }

.settlement-suggestions { padding: 16px 22px; }
.suggestion { display: grid; grid-template-columns: 1fr auto 1fr; align-items: center; gap: 8px; padding: 12px; background: var(--surface-soft); border: 1px solid var(--border); border-radius: 12px; margin-bottom: 9px; }
.suggestion:last-child { margin-bottom: 0; }
.suggestion .arrow { color: var(--muted); font-weight: 900; }
.suggestion .to { text-align: right; }
.suggestion .amount { grid-column: 1 / -1; text-align: center; color: var(--primary); font-weight: 850; margin-top: -3px; }

.activity-list { padding: 4px 22px 14px; }
.activity-item { display: flex; justify-content: space-between; gap: 16px; padding: 14px 0; border-bottom: 1px solid var(--border); }
.activity-item:last-child { border-bottom: 0; }
.activity-item strong { display: block; }
.activity-item small { color: var(--muted); }
.activity-amount { text-align: right; font-weight: 850; white-space: nowrap; }

.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; min-width: 720px; }
th, td { padding: 14px 18px; border-bottom: 1px solid var(--border); text-align: left; vertical-align: middle; }
th { background: #fbfcfe; color: #697386; text-transform: uppercase; font-size: .7rem; letter-spacing: .06em; }
tbody tr:last-child td { border-bottom: 0; }
tbody tr:hover { background: #fcfdff; }
.text-right { text-align: right; }
.empty-cell, .empty-state { color: var(--muted); text-align: center; padding: 30px; }
.badge { display: inline-flex; align-items: center; gap: 5px; padding: 4px 8px; border-radius: 999px; font-size: .75rem; font-weight: 800; }
.badge-green { color: var(--green); background: var(--green-bg); }
.badge-red { color: var(--red); background: var(--red-bg); }
.badge-gray { color: #667085; background: #eef1f5; }
.badge-amber { color: var(--amber); background: var(--amber-bg); }

.friends-grid { padding: 20px; display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 12px; text-align: left; }
.friend-card { border: 1px solid var(--border); background: white; border-radius: 14px; padding: 15px; }
.friend-card.inactive { opacity: .62; background: #fafafa; }
.friend-card-top { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.friend-card .person { margin-bottom: 14px; }
.friend-card-meta { color: var(--muted); font-size: .82rem; min-height: 38px; }
.friend-card-actions { display: flex; gap: 6px; flex-wrap: wrap; margin-top: 12px; }

.modal { position: fixed; inset: 0; display: none; z-index: 1000; }
.modal.open { display: block; }
.modal-backdrop { position: absolute; inset: 0; background: rgba(14, 25, 45, .62); backdrop-filter: blur(2px); }
.modal-dialog { position: relative; width: min(700px, calc(100% - 24px)); max-height: calc(100vh - 30px); overflow: auto; margin: 15px auto; background: white; border-radius: 18px; box-shadow: 0 30px 80px rgba(0,0,0,.28); }
.modal-small { width: min(560px, calc(100% - 24px)); }
.modal-large { width: min(1000px, calc(100% - 24px)); }
.modal-header, .modal-footer { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 17px 20px; }
.modal-header { border-bottom: 1px solid var(--border); }
.modal-footer { border-top: 1px solid var(--border); justify-content: flex-end; position: sticky; bottom: 0; background: white; z-index: 2; }
.modal-header h2 { margin: 0; font-size: 1.16rem; }
.modal-body { padding: 20px; }
body.modal-open { overflow: hidden; }

.form-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 15px; }
.field { display: flex; flex-direction: column; gap: 6px; }
.field.full { grid-column: 1 / -1; }
.field span { font-weight: 750; font-size: .84rem; }
.input { width: 100%; padding: 10px 12px; color: var(--text); border: 1px solid #d8dfeb; border-radius: 10px; background: white; outline: none; }
.input:focus { border-color: #6b91ef; box-shadow: 0 0 0 3px rgba(36,87,214,.1); }
textarea.input { resize: vertical; }
.section-heading { display: flex; align-items: flex-end; justify-content: space-between; gap: 12px; margin: 23px 0 10px; }
.section-heading h3 { margin: 0; font-size: 1rem; }
.quick-actions { display: flex; gap: 10px; }
.checkbox-col { width: 80px; }
.participant-check { width: 18px; height: 18px; }
.participant-wrap input[type="number"] { min-width: 110px; text-align: right; }
.participant-wrap .share-input:disabled { background: #f1f4f8; color: #667085; }
.expense-checks { display: flex; flex-wrap: wrap; gap: 16px; padding: 13px 2px 0; color: var(--muted); font-size: .82rem; }
.validation-text { margin-left: auto; font-weight: 800; }
.validation-text.valid { color: var(--green); }
.validation-text.invalid { color: var(--red); }

.detail-summary { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; margin-bottom: 16px; }
.detail-box { background: var(--surface-soft); border: 1px solid var(--border); border-radius: 12px; padding: 12px; }
.detail-box span { color: var(--muted); font-size: .76rem; display: block; }
.detail-box strong { display: block; margin-top: 4px; }
.detail-notes { background: #fffbea; border: 1px solid #f0e4a8; border-radius: 10px; padding: 11px; margin-top: 14px; }

.toast-container { position: fixed; right: 16px; top: 16px; z-index: 2000; display: grid; gap: 8px; }
.toast { min-width: 270px; max-width: 390px; padding: 12px 14px; border-radius: 11px; background: #1f2937; color: white; box-shadow: 0 14px 38px rgba(0,0,0,.22); animation: slideIn .2s ease; }
.toast.error { background: #a62020; }
.toast.success { background: #126443; }
@keyframes slideIn { from { transform: translateY(-8px); opacity: 0; } to { transform: translateY(0); opacity: 1; } }

.app-footer { color: var(--muted); text-align: center; padding: 0 0 28px; font-size: .82rem; }

@media (max-width: 900px) {
    .summary-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
    .two-column { grid-template-columns: 1fr; }
    .friends-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}
@media (max-width: 640px) {
    .container { width: min(100% - 20px, 1180px); }
    .app-header { padding-top: 25px; }
    .header-inner { align-items: flex-start; flex-direction: column; }
    .header-actions { width: 100%; }
    .header-actions .btn { flex: 1; }
    .summary-grid { gap: 9px; }
    .summary-card { padding: 15px; }
    .summary-card strong { font-size: 1.13rem; }
    .tabs { width: 100%; }
    .tab { flex: 1; padding: 9px 11px; }
    .panel-header { padding: 16px; }
    .toolbar { width: 100%; }
    .toolbar .input { min-width: 0; flex: 1; }
    .friends-grid { grid-template-columns: 1fr; padding: 14px; }
    .form-grid { grid-template-columns: 1fr; }
    .field.full { grid-column: auto; }
    .modal-body { padding: 15px; }
    .detail-summary { grid-template-columns: 1fr; }
    .expense-checks { gap: 8px 13px; }
    .validation-text { width: 100%; margin-left: 0; }
}
