@import url('https://fonts.googleapis.com/css2?family=Noto+Sans+KR:wght@400;500;600;700&display=swap');

:root {
    --navy: #123047;
    --navy-deep: #0c2538;
    --teal: #16857d;
    --teal-soft: #e7f5f2;
    --orange: #e47745;
    --orange-soft: #fff0e8;
    --ink: #24343e;
    --muted: #71808a;
    --line: #dfe7e9;
    --surface: #ffffff;
    --canvas: #f4f7f6;
    --danger: #c94f4f;
    --shadow: 0 12px 30px rgba(24, 54, 67, .07);
}

* { box-sizing: border-box; }
html { min-height: 100%; }
body {
    min-height: 100vh;
    margin: 0;
    color: var(--ink);
    background: var(--canvas);
    font-family: "Noto Sans KR", "Malgun Gothic", sans-serif;
    font-size: 15px;
    line-height: 1.55;
}
a { color: var(--teal); text-decoration: none; }
a:hover { color: #0d6c66; }
button, input, select, textarea { font: inherit; }
button { cursor: pointer; }

.topbar {
    position: sticky;
    z-index: 10;
    top: 0;
    display: flex;
    align-items: center;
    min-height: 72px;
    padding: 0 max(24px, calc((100vw - 1220px) / 2));
    color: #fff;
    background: var(--navy-deep);
    box-shadow: 0 4px 16px rgba(8, 27, 40, .14);
}
.brand, .auth-brand {
    display: inline-flex;
    align-items: center;
    gap: 10px;
    color: inherit;
    font-size: 19px;
    font-weight: 700;
    letter-spacing: -.5px;
}
.brand:hover { color: #fff; }
.brand-mark {
    display: inline-grid;
    place-items: center;
    width: 36px;
    height: 36px;
    color: #fff;
    border-radius: 12px 12px 12px 3px;
    background: var(--teal);
    font-size: 16px;
}
.nav { display: flex; align-self: stretch; gap: 8px; margin-left: 58px; }
.nav a {
    display: flex;
    position: relative;
    align-items: center;
    padding: 0 16px;
    color: #aec0ca;
    font-weight: 500;
}
.nav a:hover, .nav a.active { color: #fff; }
.nav a.active::after {
    position: absolute;
    right: 14px;
    bottom: 0;
    left: 14px;
    height: 3px;
    border-radius: 3px 3px 0 0;
    background: #43bdb2;
    content: "";
}
.user-menu { display: flex; align-items: center; gap: 18px; margin-left: auto; }
.user-menu > span { display: flex; flex-direction: column; text-align: right; }
.user-menu small { color: #91a7b3; font-size: 11px; }
.user-menu form { margin: 0; }
.link-button {
    padding: 7px 10px;
    color: #b9c9d1;
    border: 1px solid #496172;
    border-radius: 7px;
    background: transparent;
    font-size: 12px;
}

.container { width: min(1220px, calc(100% - 40px)); margin: 0 auto; padding: 48px 0 72px; }
.page-title { display: flex; align-items: flex-end; justify-content: space-between; gap: 24px; margin-bottom: 28px; }
.page-title h1 { margin: 4px 0 5px; color: var(--navy); font-size: 30px; line-height: 1.3; letter-spacing: -1.2px; }
.page-title p { margin: 0; color: var(--muted); }
.eyebrow { color: var(--teal) !important; font-size: 11px; font-weight: 700; letter-spacing: 1.8px; }

.button {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-height: 42px;
    padding: 0 18px;
    border: 1px solid transparent;
    border-radius: 8px;
    font-weight: 600;
    transition: .15s ease;
}
.button.primary { color: #fff; background: var(--teal); box-shadow: 0 5px 12px rgba(22, 133, 125, .18); }
.button.primary:hover { color: #fff; background: #10766f; transform: translateY(-1px); }
.button.secondary { color: var(--ink); border-color: #cad7da; background: #fff; }
.button.secondary:hover { color: var(--navy); border-color: #9fb6bb; background: #f9fbfb; }
.button.full { width: 100%; min-height: 48px; }

.stats-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 18px; margin-bottom: 24px; }
.stat-card {
    display: flex;
    align-items: flex-start;
    gap: 15px;
    min-width: 0;
    padding: 24px 20px;
    border: 1px solid #e4ebec;
    border-radius: 12px;
    background: var(--surface);
    box-shadow: var(--shadow);
}
.stat-icon {
    display: grid;
    flex: 0 0 42px;
    place-items: center;
    width: 42px;
    height: 42px;
    color: var(--teal);
    border-radius: 12px;
    background: var(--teal-soft);
    font-size: 20px;
    font-weight: 700;
}
.stat-card.expense .stat-icon { color: var(--orange); background: var(--orange-soft); }
.stat-card.members .stat-icon { color: #6d70aa; background: #eeeeff; }
.stat-card small { display: block; margin-bottom: 4px; color: var(--muted); }
.stat-card strong { display: block; overflow: hidden; color: var(--navy); font-size: 21px; letter-spacing: -.8px; text-overflow: ellipsis; white-space: nowrap; }
.stat-card p { margin: 4px 0 0; color: #9aa5ab; font-size: 11px; }

.panel {
    overflow: hidden;
    margin-top: 20px;
    border: 1px solid #e0e8ea;
    border-radius: 12px;
    background: var(--surface);
    box-shadow: var(--shadow);
}
.panel-head { display: flex; align-items: center; justify-content: space-between; padding: 23px 25px 18px; }
.panel-head h2 { margin: 0 0 3px; color: var(--navy); font-size: 18px; }
.panel-head p { margin: 0; color: var(--muted); font-size: 13px; }
.panel-head > a { font-size: 13px; font-weight: 600; }
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
th {
    padding: 12px 20px;
    color: #6c7c85;
    border-top: 1px solid var(--line);
    border-bottom: 1px solid var(--line);
    background: #f8fafa;
    font-size: 12px;
    font-weight: 600;
    text-align: left;
    white-space: nowrap;
}
td { padding: 15px 20px; border-bottom: 1px solid #edf1f2; vertical-align: middle; }
tbody tr:last-child td { border-bottom: 0; }
tbody tr:hover { background: #fbfdfd; }
td b { color: #30434e; font-weight: 600; }
.right { text-align: right; }
.block { display: block; margin-top: 2px; color: var(--muted); font-size: 11px; }
.amount { font-weight: 700; white-space: nowrap; }
.amount.income, .mini-stats strong.income { color: var(--teal); }
.amount.expense, .mini-stats strong.expense { color: var(--orange); }
.badge, .role-badge, .count-pill {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 4px 9px;
    border-radius: 999px;
    font-size: 11px;
    font-weight: 700;
}
.badge.income { color: #08746d; background: var(--teal-soft); }
.badge.expense { color: #c25b2b; background: var(--orange-soft); }
.role-badge { color: #596073; background: #f0f1f5; }
.count-pill { padding: 8px 14px; color: #08746d; background: var(--teal-soft); }
.empty { padding: 52px 20px; color: var(--muted); text-align: center; }
.actions { white-space: nowrap; }
.actions form { display: inline; margin-left: 10px; }
.danger-link { padding: 0; color: var(--danger); border: 0; background: transparent; }
.receipt-link { display: inline-block; margin-top: 5px; font-size: 12px; font-weight: 600; }

.mini-stats { display: grid; grid-template-columns: repeat(3, 1fr); margin-bottom: 20px; border: 1px solid var(--line); border-radius: 10px; background: #fff; }
.mini-stats div { padding: 18px 24px; border-right: 1px solid var(--line); }
.mini-stats div:last-child { border-right: 0; }
.mini-stats small { display: block; color: var(--muted); font-size: 12px; }
.mini-stats strong { display: block; margin-top: 3px; color: var(--navy); font-size: 19px; }
.filters { display: flex; align-items: flex-end; gap: 12px; padding: 20px 24px; }
.filters label { min-width: 160px; }
.filters .button { min-height: 40px; }
.text-link { padding: 10px 5px; color: var(--muted); font-size: 12px; }

label { display: flex; flex-direction: column; gap: 7px; color: #43545e; font-size: 13px; font-weight: 600; }
label small { display: inline; color: var(--muted); font-weight: 400; }
input, select, textarea {
    width: 100%;
    min-height: 43px;
    padding: 10px 12px;
    color: var(--ink);
    border: 1px solid #cdd9dc;
    border-radius: 7px;
    outline: none;
    background: #fff;
    transition: border-color .15s, box-shadow .15s;
}
textarea { resize: vertical; }
input:focus, select:focus, textarea:focus { border-color: var(--teal); box-shadow: 0 0 0 3px rgba(22, 133, 125, .1); }
.form-panel { max-width: 820px; margin-right: auto; margin-left: auto; padding: 30px; }
.stack-form { display: flex; flex-direction: column; gap: 19px; }
.form-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 18px; }
.form-actions { display: flex; justify-content: flex-end; gap: 10px; padding-top: 8px; }
.form-note { margin: 0; padding: 12px 14px; color: #65747c; border-radius: 7px; background: #f5f8f8; font-size: 12px; }
.receipt-current { display: flex; align-items: center; justify-content: space-between; gap: 15px; padding: 13px 15px; border-radius: 8px; background: #f5f8f8; }
.receipt-current > a { overflow: hidden; font-size: 13px; font-weight: 600; text-overflow: ellipsis; white-space: nowrap; }
.receipt-current label { align-items: center; flex-direction: row; flex: 0 0 auto; font-size: 12px; font-weight: 500; }
.receipt-current input { width: auto; min-height: 0; }
.type-picker { display: flex; gap: 10px; margin: 0; padding: 0; border: 0; }
.type-picker legend { margin-bottom: 8px; color: #43545e; font-size: 13px; font-weight: 600; }
.type-picker label { flex: 1; }
.type-picker input { position: absolute; width: 1px; height: 1px; opacity: 0; }
.type-picker span { display: grid; place-items: center; min-height: 50px; border: 1px solid #ccd8db; border-radius: 8px; background: #fff; }
.type-picker input:checked + span { color: var(--teal); border-color: var(--teal); background: var(--teal-soft); box-shadow: 0 0 0 2px rgba(22, 133, 125, .08); }
.type-picker label:last-child input:checked + span { color: var(--orange); border-color: var(--orange); background: var(--orange-soft); }
.category-add-panel { max-width: none; }
.category-add-panel h2 { margin: 0 0 18px; color: var(--navy); font-size: 18px; }
.category-add-form { display: grid; grid-template-columns: minmax(140px, .6fr) minmax(220px, 1.8fr) auto; align-items: end; gap: 14px; }
.category-name-input { min-width: 220px; }
.transfer-fee-block { margin-top: -4px; }
.fee-total {
    display: flex;
    flex-direction: column;
    justify-content: center;
    min-height: 76px;
    padding: 12px 14px;
    border: 1px solid #dbe7e6;
    border-radius: 8px;
    background: #f5fafa;
}
.fee-total small { color: var(--muted); font-size: 12px; font-weight: 600; }
.fee-total strong { margin-top: 3px; color: var(--orange); font-size: 20px; letter-spacing: -.5px; }
.fee-total p { margin: 3px 0 0; color: #9aa5ab; font-size: 11px; }

.member-cell, .profile-summary { display: flex; align-items: center; gap: 11px; }
.member-cell small { display: block; color: var(--muted); font-size: 11px; }
.avatar {
    display: grid;
    flex: 0 0 35px;
    place-items: center;
    width: 35px;
    height: 35px;
    color: var(--teal);
    border-radius: 50%;
    background: var(--teal-soft);
    font-weight: 700;
}
.avatar.large { flex-basis: 54px; width: 54px; height: 54px; font-size: 20px; }
.status { display: inline-flex; align-items: center; gap: 6px; color: #54716e; font-size: 12px; }
.status i { width: 7px; height: 7px; border-radius: 50%; background: #4ab09f; }
.status.inactive { color: #899399; }
.status.inactive i { background: #b6bec1; }
.profile-summary { margin: -5px 0 5px; padding: 17px; border-radius: 9px; background: #f5f9f8; }
.profile-summary strong { color: var(--navy); font-size: 17px; }
.profile-summary p { margin: 2px 0 0; color: var(--muted); font-size: 12px; }

.alert { margin: 0 0 20px; padding: 13px 16px; border: 1px solid; border-radius: 8px; font-size: 13px; }
.alert.success { color: #176c61; border-color: #b8ded8; background: #edf9f6; }
.alert.error { color: #934444; border-color: #eccaca; background: #fff3f3; }
.alert ul { margin: 0; padding-left: 20px; }

.auth-body {
    display: flex;
    flex-direction: column;
    background:
        radial-gradient(circle at 17% 18%, rgba(41, 158, 148, .20), transparent 28%),
        radial-gradient(circle at 84% 78%, rgba(228, 119, 69, .12), transparent 25%),
        var(--navy-deep);
}
.auth-container { display: grid; flex: 1; place-items: center; width: 100%; padding: 45px 20px; }
.auth-card {
    width: min(440px, 100%);
    padding: 38px 42px;
    border: 1px solid rgba(255,255,255,.16);
    border-radius: 16px;
    background: rgba(255,255,255,.98);
    box-shadow: 0 25px 70px rgba(1, 15, 24, .3);
}
.auth-card.wide { width: min(580px, 100%); }
.auth-brand { color: var(--navy); }
.auth-heading { margin: 30px 0 25px; }
.auth-heading h1 { margin: 5px 0 7px; color: var(--navy); font-size: 27px; letter-spacing: -1px; }
.auth-heading > p:last-child { margin: 0; color: var(--muted); font-size: 13px; }
.auth-switch { margin: 23px 0 0; color: var(--muted); font-size: 13px; text-align: center; }
.auth-switch a { font-weight: 700; }
.auth-body .footer { color: #8298a5; border: 0; background: transparent; }
.footer { padding: 18px; color: #8a979e; border-top: 1px solid #e2e8ea; background: #fff; font-size: 11px; text-align: center; }
.empty-page { padding: 60px; text-align: center; }

@media (max-width: 920px) {
    .stats-grid { grid-template-columns: repeat(2, 1fr); }
    .nav { margin-left: 25px; }
    .user-menu > span { display: none; }
}
@media (max-width: 680px) {
    .topbar { flex-wrap: wrap; padding: 12px 18px 0; }
    .brand { margin-bottom: 12px; }
    .user-menu { margin: 0 0 12px auto; }
    .nav { order: 3; width: 100%; height: 44px; margin: 0; overflow-x: auto; }
    .nav a { flex: 1; justify-content: center; padding: 0 8px; font-size: 13px; white-space: nowrap; }
    .container { width: min(100% - 28px, 1220px); padding: 30px 0 50px; }
    .page-title { align-items: flex-start; flex-direction: column; }
    .page-title .button { width: 100%; }
    .stats-grid, .mini-stats, .form-grid { grid-template-columns: 1fr; }
    .mini-stats div { border-right: 0; border-bottom: 1px solid var(--line); }
    .mini-stats div:last-child { border-bottom: 0; }
    .filters { align-items: stretch; flex-direction: column; }
    .filters label { min-width: 0; }
    .filters .button { width: 100%; }
    .form-panel { padding: 22px 18px; }
    .category-add-form { grid-template-columns: 1fr; }
    .category-name-input { min-width: 180px; }
    .receipt-current { align-items: flex-start; flex-direction: column; }
    .auth-card, .auth-card.wide { padding: 30px 22px; }
    th, td { padding-right: 14px; padding-left: 14px; }
}
