:root {
    --ink: #101814;
    --ink-soft: #24312a;
    --muted: #526258;
    --line: rgba(16, 24, 20, 0.12);
    --accent: #0f8a4b;
    --accent-deep: #0a5f34;
    --amber: #d97706;
    --amber-deep: #9a5b05;
    --danger: #b42318;
    --owe: #b42318;
    --owed: #0a5f34;
    --panel: rgba(255, 255, 255, 0.78);
    --panel-solid: #f7faf7;
    --shadow: 0 18px 40px rgba(16, 24, 20, 0.1);
    --max: 980px;
    --radius: 1.25rem;
}

* { box-sizing: border-box; }

body {
    margin: 0;
    min-height: 100vh;
    color: var(--ink);
    font-family: "Sora", sans-serif;
    background:
        radial-gradient(ellipse 70% 45% at 8% 0%, rgba(15, 138, 75, 0.16), transparent 55%),
        radial-gradient(ellipse 55% 40% at 95% 5%, rgba(217, 119, 6, 0.14), transparent 50%),
        linear-gradient(165deg, #f7faf7 0%, #e4eee7 45%, #d5e4da 100%);
}

body::before {
    content: "";
    position: fixed;
    inset: 0;
    pointer-events: none;
    z-index: -1;
    opacity: 0.28;
    background-image:
        linear-gradient(rgba(16, 24, 20, 0.045) 1px, transparent 1px),
        linear-gradient(90deg, rgba(16, 24, 20, 0.045) 1px, transparent 1px);
    background-size: 56px 56px;
    mask-image: linear-gradient(to bottom, black, transparent 75%);
}

a { color: inherit; text-decoration: none; }

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

.wrap {
    width: min(var(--max), calc(100% - 2rem));
    margin: 0 auto;
    padding: 1.5rem 0 4rem;
}

.top {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 1rem;
    margin-bottom: 1.5rem;
    animation: rise 0.5s ease both;
}

.brand {
    display: flex;
    align-items: center;
    gap: 0.75rem;
}

.brand-mark {
    width: 2.5rem;
    height: 2.5rem;
    display: grid;
    place-items: center;
    border-radius: 0.8rem;
    background: linear-gradient(145deg, var(--accent), var(--accent-deep));
    color: #fff;
    font-family: "Bricolage Grotesque", sans-serif;
    font-weight: 800;
    box-shadow: 0 8px 20px rgba(15, 138, 75, 0.28);
}

.brand h1 {
    margin: 0;
    font-family: "Bricolage Grotesque", sans-serif;
    font-size: clamp(1.55rem, 3.5vw, 2rem);
    font-weight: 800;
    letter-spacing: -0.04em;
    line-height: 1;
}

.brand p {
    margin: 0.25rem 0 0;
    color: var(--muted);
    font-size: 0.9rem;
}

.top-actions {
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem;
    justify-content: flex-end;
}

.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.4rem;
    padding: 0.65rem 1rem;
    border-radius: 0.85rem;
    border: 1px solid var(--line);
    background: var(--panel);
    color: var(--ink);
    font-weight: 600;
    cursor: pointer;
    transition: transform 0.15s ease, border-color 0.15s ease, background 0.15s ease;
}

.btn:hover { transform: translateY(-1px); border-color: rgba(15, 138, 75, 0.35); }
.btn:disabled { opacity: 0.5; cursor: not-allowed; transform: none; }

.btn-primary {
    background: linear-gradient(145deg, var(--accent), var(--accent-deep));
    color: #fff;
    border-color: transparent;
    box-shadow: 0 8px 18px rgba(15, 138, 75, 0.22);
}

.btn-primary:hover { border-color: transparent; }

.btn-ghost {
    background: transparent;
}

.btn-danger {
    color: var(--danger);
    border-color: rgba(180, 35, 24, 0.25);
    background: rgba(180, 35, 24, 0.06);
}

.btn-sm {
    padding: 0.4rem 0.7rem;
    font-size: 0.85rem;
    border-radius: 0.7rem;
}

.identity {
    display: flex;
    align-items: center;
    gap: 0.45rem;
    padding: 0.45rem 0.7rem;
    border-radius: 0.85rem;
    border: 1px solid var(--line);
    background: var(--panel);
    font-size: 0.88rem;
}

.identity select {
    border: none;
    background: transparent;
    outline: none;
    font-weight: 600;
    max-width: 10rem;
}

.panel {
    border: 1px solid var(--line);
    background: var(--panel);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    backdrop-filter: blur(10px);
    padding: 1.15rem 1.25rem;
    animation: rise 0.55s ease both;
}

.panel + .panel { margin-top: 1rem; }

.panel-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.75rem;
    margin-bottom: 0.9rem;
}

.panel-head h2 {
    margin: 0;
    font-family: "Bricolage Grotesque", sans-serif;
    font-size: 1.25rem;
    letter-spacing: -0.03em;
}

.panel-head-actions {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: flex-end;
    gap: 0.45rem;
}

.muted { color: var(--muted); }
.small { font-size: 0.88rem; }

.event-list {
    display: flex;
    flex-direction: column;
    gap: 0.65rem;
}

.group-card {
    display: flex;
    flex-direction: row;
    align-items: center;
    gap: 0.85rem 1rem;
    padding: 0.9rem 1rem;
    border-radius: 1.1rem;
    border: 1px solid var(--line);
    background: rgba(255, 255, 255, 0.55);
    text-align: left;
    width: 100%;
    transition: border-color 0.18s ease, box-shadow 0.18s ease;
}

.group-card:hover {
    border-color: rgba(15, 138, 75, 0.4);
    box-shadow: 0 10px 24px rgba(15, 138, 75, 0.1);
}

.group-card.is-current {
    background: rgba(15, 138, 75, 0.1);
    border-color: rgba(15, 138, 75, 0.28);
}

.group-card.is-current:hover {
    border-color: rgba(15, 138, 75, 0.5);
    box-shadow: 0 10px 24px rgba(15, 138, 75, 0.14);
}

.group-card.is-past {
    background: rgba(16, 24, 20, 0.045);
    border-color: rgba(16, 24, 20, 0.1);
    color: var(--muted);
}

.group-card.is-past h3 {
    color: #5c6660;
}

.group-card.is-past:hover {
    border-color: rgba(16, 24, 20, 0.18);
    box-shadow: 0 8px 18px rgba(16, 24, 20, 0.06);
}

.group-card-link {
    flex: 1;
    min-width: 0;
    display: grid;
    grid-template-columns: minmax(11rem, 1.3fr) minmax(0, 1fr) auto;
    gap: 0.55rem 1rem;
    align-items: center;
    color: inherit;
    text-decoration: none;
}

.group-card-main { min-width: 0; }

.group-card-actions {
    flex-shrink: 0;
}

.joined-badge {
    display: inline-flex;
    align-items: center;
    padding: 0.35rem 0.7rem;
    border-radius: 999px;
    background: rgba(15, 138, 75, 0.14);
    color: var(--accent-deep);
    font-size: 0.82rem;
    font-weight: 700;
}

.group-card h3 {
    margin: 0;
    font-family: "Bricolage Grotesque", sans-serif;
    font-size: 1.15rem;
    letter-spacing: -0.03em;
}

.group-meta {
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem 0.85rem;
    color: var(--muted);
    font-size: 0.86rem;
}

.chips {
    display: flex;
    flex-wrap: wrap;
    gap: 0.35rem;
}

.chip {
    display: inline-flex;
    align-items: center;
    gap: 0.3rem;
    padding: 0.22rem 0.55rem;
    border-radius: 999px;
    background: rgba(15, 138, 75, 0.1);
    color: var(--accent-deep);
    font-size: 0.78rem;
    font-weight: 600;
}

.chip-amber {
    background: rgba(217, 119, 6, 0.14);
    color: var(--amber-deep);
}

.chip.is-you {
    background: rgba(15, 138, 75, 0.22);
    box-shadow: inset 0 0 0 1px rgba(15, 138, 75, 0.45);
}

.empty {
    padding: 1.5rem 0.5rem;
    text-align: center;
    color: var(--muted);
}

.person-list, .expense-list, .balance-list, .transfer-list, .comment-list {
    display: flex;
    flex-direction: column;
    gap: 0.55rem;
}

.row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.75rem;
    padding: 0.75rem 0.85rem;
    border-radius: 0.9rem;
    border: 1px solid transparent;
    background: rgba(255, 255, 255, 0.45);
}

.row.clickable {
    cursor: pointer;
    width: 100%;
    text-align: left;
    border: 1px solid var(--line);
    transition: border-color 0.15s ease, transform 0.15s ease;
}

a.row.clickable {
    color: inherit;
    text-decoration: none;
}

.row.clickable:hover {
    border-color: rgba(15, 138, 75, 0.35);
    transform: translateY(-1px);
}

.row.clickable.is-new {
    background: rgba(15, 138, 75, 0.18);
    border-color: rgba(15, 138, 75, 0.5);
    transition: background 0.7s ease, border-color 0.7s ease;
}

.row.is-you,
.check-item.is-you {
    background: rgba(15, 138, 75, 0.14);
    border-color: rgba(15, 138, 75, 0.28);
    box-shadow: inset 3px 0 0 var(--accent);
}

.row-main { min-width: 0; flex: 1; }
.row-main strong { display: block; }
.row-main span { display: block; margin-top: 0.15rem; color: var(--muted); font-size: 0.84rem; }

.amount {
    font-weight: 700;
    font-variant-numeric: tabular-nums;
    white-space: nowrap;
}

.amount.pos { color: var(--owed); }
.amount.neg { color: var(--owe); }

.tabs {
    display: flex;
    flex-wrap: wrap;
    gap: 0.4rem;
    margin-bottom: 0.85rem;
}

.tab {
    padding: 0.45rem 0.8rem;
    border-radius: 999px;
    border: 1px solid var(--line);
    background: transparent;
    cursor: pointer;
    font-weight: 600;
    font-size: 0.88rem;
    color: var(--muted);
}

.tab.active {
    background: rgba(15, 138, 75, 0.12);
    color: var(--accent-deep);
    border-color: rgba(15, 138, 75, 0.28);
}

.back-link {
    display: inline-flex;
    align-items: center;
    gap: 0.35rem;
    margin-bottom: 0.85rem;
    color: var(--muted);
    font-weight: 600;
    font-size: 0.9rem;
    background: none;
    border: none;
    cursor: pointer;
    padding: 0;
}

.back-link:hover { color: var(--accent-deep); }

.hero-group h2 {
    margin: 0 0 0.35rem;
    font-family: "Bricolage Grotesque", sans-serif;
    font-size: clamp(1.6rem, 4vw, 2.1rem);
    letter-spacing: -0.04em;
}

.stat-row {
    display: flex;
    flex-wrap: nowrap;
    align-items: baseline;
    gap: 0.85rem 1.15rem;
    margin: 0.65rem 0 0.15rem;
    overflow-x: auto;
}

.stat {
    display: flex;
    align-items: baseline;
    gap: 0.35rem;
    padding: 0;
    border: none;
    background: none;
    white-space: nowrap;
}

.stat .label { color: var(--muted); font-size: 0.75rem; }
.stat .value {
    margin: 0;
    font-family: "Bricolage Grotesque", sans-serif;
    font-size: 1rem;
    letter-spacing: -0.03em;
}

.stat-icons {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 0.45rem 0.85rem;
    margin: 0.75rem 0 0.15rem;
}

.stat-icon {
    display: inline-flex;
    align-items: center;
    gap: 0.35rem;
    color: var(--ink-soft);
    text-decoration: none;
    font-family: "Bricolage Grotesque", sans-serif;
    font-size: 0.98rem;
    letter-spacing: -0.03em;
    font-variant-numeric: tabular-nums;
}

a.stat-icon:hover { color: var(--accent-deep); }

.stat-icon svg {
    width: 1.05rem;
    height: 1.05rem;
    flex-shrink: 0;
    color: var(--muted);
}

a.stat-icon:hover svg { color: var(--accent-deep); }

.icon-actions {
    display: flex;
    align-items: center;
    gap: 0.25rem;
    flex-shrink: 0;
}

.icon-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 2rem;
    height: 2rem;
    padding: 0;
    border: none;
    border-radius: 0.55rem;
    background: transparent;
    color: var(--muted);
    cursor: pointer;
}

.icon-btn svg { width: 1.05rem; height: 1.05rem; }
.icon-btn:hover { background: rgba(16, 24, 20, 0.06); color: var(--ink); }
.icon-btn-danger:hover { background: rgba(180, 35, 24, 0.1); color: var(--danger); }

/* Modal */
.modal-backdrop {
    position: fixed;
    inset: 0;
    background: rgba(16, 24, 20, 0.42);
    backdrop-filter: blur(4px);
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 1.5rem 1rem;
    z-index: 90;
    animation: fade 0.2s ease both;
}

.modal {
    width: min(560px, 100%);
    max-height: min(90vh, 820px);
    overflow: auto;
    background: #f8fbf8;
    border-radius: 1.25rem;
    border: 1px solid var(--line);
    box-shadow: 0 24px 60px rgba(16, 24, 20, 0.28);
    padding: 1.25rem;
    animation: fade 0.2s ease both;
}

.modal.modal-expense {
    width: min(400px, 100%);
    max-height: min(88vh, 680px);
    padding: 0.85rem 0.9rem 0.95rem;
}

.modal h3 {
    margin: 0 0 1rem;
    font-family: "Bricolage Grotesque", sans-serif;
    font-size: 1.35rem;
    letter-spacing: -0.03em;
}

.modal-expense h3 {
    margin: 0;
    font-size: 1.1rem;
}

.modal-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.5rem;
}

.modal-head-actions { display: flex; gap: 0.35rem; }

.form-grid {
    display: grid;
    gap: 0.85rem;
}

.form-grid.compact { gap: 0.5rem; }

.form-grid.compact input:not([type="checkbox"]):not([type="file"]):not([type="radio"]),
.form-grid.compact select {
    width: 100%;
    padding: 0.5rem 0.65rem;
    border-radius: 0.65rem;
    border: 1px solid var(--line);
    background: #fff;
    outline: none;
    font-size: 0.9rem;
}

.form-grid.compact input:not([type="checkbox"]):not([type="file"]):focus,
.form-grid.compact select:focus {
    border-color: rgba(15, 138, 75, 0.55);
    box-shadow: 0 0 0 3px rgba(15, 138, 75, 0.12);
}

.form-grid.compact .note-input { padding: 0.4rem 0.65rem; font-size: 0.84rem; }

.field-row {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 0.45rem;
}

.join-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.75rem;
    flex-wrap: wrap;
    margin: 0.7rem 0 0.15rem;
}

.maps-link {
    color: var(--accent-deep);
    font-weight: 600;
    text-decoration: none;
}

.maps-link:hover { text-decoration: underline; }

.sr-hint {
    display: block;
    margin-bottom: 0.3rem;
    font-size: 0.75rem;
    font-weight: 600;
    color: var(--muted);
}

.check-item.pay-row,
.pay-row {
    display: grid;
    grid-template-columns: 1.1rem 1fr 5.4rem;
    gap: 0.35rem;
    align-items: center;
    padding: 0.32rem 0.45rem;
    font-size: 0.85rem;
}

.pay-row input[type="checkbox"] {
    width: 1rem;
    height: 1rem;
    margin: 0;
    padding: 0;
    flex: none;
    justify-self: center;
}

.pay-row .payer-amt,
.pay-row .split-amt {
    padding: 0.3rem 0.4rem;
    font-size: 0.82rem;
}

.file-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 0.5rem 0.65rem;
    border-radius: 0.65rem;
    border: 1px dashed var(--line);
    background: #fff;
    font-size: 0.84rem;
    font-weight: 600;
    color: var(--ink-soft);
    cursor: pointer;
}

.file-btn input { display: none; }
.file-name { margin: 0; }

.field > label:not(.check-item):not(.pay-row):not(.split-all):not(.file-btn) {
    display: block;
    margin-bottom: 0.35rem;
    font-size: 0.84rem;
    font-weight: 600;
    color: var(--ink-soft);
}

.field input:not([type="checkbox"]):not([type="file"]):not([type="radio"]),
.field select,
.field textarea {
    width: 100%;
    padding: 0.7rem 0.8rem;
    border-radius: 0.75rem;
    border: 1px solid var(--line);
    background: #fff;
    outline: none;
}

.field input:focus,
.field select:focus,
.field textarea:focus {
    border-color: rgba(15, 138, 75, 0.55);
    box-shadow: 0 0 0 3px rgba(15, 138, 75, 0.12);
}

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

.check-grid {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 0.4rem;
}

.check-item {
    display: flex;
    align-items: center;
    gap: 0.45rem;
    padding: 0.55rem 0.65rem;
    border-radius: 0.7rem;
    border: 1px solid var(--line);
    background: #fff;
    cursor: pointer;
    font-size: 0.9rem;
}

.check-item input { accent-color: var(--accent); }

.split-rows {
    display: flex;
    flex-direction: column;
    gap: 0.45rem;
}

.split-all-item {
    background: rgba(15, 138, 75, 0.08);
    border-color: rgba(15, 138, 75, 0.28);
    font-weight: 600;
}

.split-all {
    display: inline-flex;
    align-items: center;
    gap: 0.4rem;
    margin-bottom: 0.35rem;
    padding: 0;
    border: none;
    background: none;
    cursor: pointer;
    font-size: 0.82rem;
    font-weight: 600;
    color: var(--ink-soft);
}

.split-all input { accent-color: var(--accent); }

.split-row {
    display: grid;
    grid-template-columns: 1fr 7rem;
    gap: 0.5rem;
    align-items: center;
}

.modal-actions {
    display: flex;
    flex-wrap: wrap;
    justify-content: flex-end;
    gap: 0.5rem;
    margin-top: 1.1rem;
}

.modal-expense .modal-actions { margin-top: 0.35rem; }

.error-banner {
    padding: 0.7rem 0.85rem;
    border-radius: 0.75rem;
    background: rgba(180, 35, 24, 0.08);
    color: var(--danger);
    font-size: 0.9rem;
    margin-bottom: 0.85rem;
}

.toast {
    position: fixed;
    bottom: 1.25rem;
    left: 50%;
    transform: translateX(-50%);
    z-index: 80;
    padding: 0.75rem 1.1rem;
    border-radius: 999px;
    background: var(--ink);
    color: #fff;
    font-size: 0.9rem;
    font-weight: 600;
    box-shadow: 0 12px 30px rgba(16, 24, 20, 0.25);
    animation: rise 0.25s ease both;
}

.images {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(96px, 1fr));
    gap: 0.5rem;
    margin-top: 0.75rem;
}

.images a, .images .img-wrap {
    position: relative;
    aspect-ratio: 1;
    border-radius: 0.75rem;
    overflow: hidden;
    border: 1px solid var(--line);
    background: #fff;
}

.images img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    display: block;
}

.images .img-del {
    position: absolute;
    top: 0.3rem;
    right: 0.3rem;
    width: 1.5rem;
    height: 1.5rem;
    border: none;
    border-radius: 999px;
    background: rgba(16, 24, 20, 0.7);
    color: #fff;
    cursor: pointer;
    font-size: 0.85rem;
    line-height: 1;
}

.detail-block {
    margin-top: 1rem;
    padding-top: 1rem;
    border-top: 1px solid var(--line);
}

.detail-block h4 {
    margin: 0 0 0.55rem;
    font-size: 0.95rem;
    font-family: "Bricolage Grotesque", sans-serif;
}

.comment {
    padding: 0.65rem 0.75rem;
    border-radius: 0.75rem;
    background: rgba(255, 255, 255, 0.55);
    border: 1px solid var(--line);
}

.comment .meta {
    display: flex;
    justify-content: space-between;
    gap: 0.5rem;
    margin-bottom: 0.25rem;
    font-size: 0.8rem;
    color: var(--muted);
}

.comment-form {
    display: grid;
    grid-template-columns: 1fr auto;
    gap: 0.45rem;
    margin-top: 0.65rem;
}

.hidden { display: none !important; }

.settle-panel {
    margin-top: 1rem;
}

.settle-card {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 1rem;
    padding: 1.15rem 1.2rem;
    border-radius: 1.1rem;
    border: 1px solid rgba(15, 138, 75, 0.28);
    background:
        linear-gradient(145deg, rgba(15, 138, 75, 0.1), rgba(217, 119, 6, 0.08)),
        rgba(255, 255, 255, 0.65);
}

.settle-label {
    font-size: 0.82rem;
    font-weight: 600;
    color: var(--muted);
    text-transform: uppercase;
    letter-spacing: 0.04em;
}

.settle-who {
    margin-top: 0.2rem;
    font-family: "Bricolage Grotesque", sans-serif;
    font-size: 1.55rem;
    letter-spacing: -0.03em;
}

.settle-amount {
    margin-top: 0.15rem;
    font-size: 1.35rem;
    font-weight: 700;
    color: var(--accent-deep);
    font-variant-numeric: tabular-nums;
}

.settle-pay-btn {
    flex-shrink: 0;
    min-width: 7.5rem;
    padding: 0.9rem 1.2rem;
    font-size: 1.05rem;
}

.settle-done {
    padding: 1rem;
    text-align: center;
    font-weight: 600;
    color: var(--accent-deep);
    background: rgba(15, 138, 75, 0.08);
    border-radius: 0.9rem;
}

.settle-waiting {
    padding: 0.25rem 0;
}

.settle-others {
    margin-top: 0.9rem;
    color: var(--muted);
    font-size: 0.9rem;
}

.settle-others summary {
    cursor: pointer;
    font-weight: 600;
}

.settle-row-actions {
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

@media (max-width: 720px) {
    .modal-backdrop {
        align-items: flex-end;
        padding: 1rem;
    }

    .modal {
        border-radius: 1.25rem 1.25rem 1rem 1rem;
        animation: slide-up 0.25s ease both;
    }

    .settle-card {
        flex-direction: column;
        align-items: stretch;
        text-align: center;
    }

    .settle-pay-btn { width: 100%; }
    .grid-2, .check-grid { grid-template-columns: 1fr; }
    .group-card {
        flex-wrap: wrap;
    }
    .group-card-link {
        grid-template-columns: 1fr;
        width: 100%;
    }
    .group-card-actions {
        width: 100%;
    }
    .group-card-actions .btn,
    .group-card-actions .joined-badge {
        width: 100%;
        justify-content: center;
    }
    .top { flex-direction: column; }
    .top-actions { width: 100%; }
    .comment-form { grid-template-columns: 1fr; }
    .split-row { grid-template-columns: 1fr 5.5rem; }
}

@keyframes rise {
    from { opacity: 0; transform: translateY(10px); }
    to { opacity: 1; transform: translateY(0); }
}

@keyframes fade {
    from { opacity: 0; }
    to { opacity: 1; }
}

@keyframes slide-up {
    from { opacity: 0; transform: translateY(18px); }
    to { opacity: 1; transform: translateY(0); }
}
