:root {
    --bg: #f4efe7;
    --bg-soft: #fbf8f3;
    --surface: #ffffff;
    --surface-strong: #f8f2e8;
    --text: #2f241d;
    --muted: #78685b;
    --line: #dccfbe;
    --primary: #1f7a6d;
    --primary-strong: #175e54;
    --danger: #a94438;
    --danger-strong: #86372d;
    --shadow: 0 18px 40px rgba(70, 45, 24, 0.08);
    --radius: 18px;
}

* {
    box-sizing: border-box;
}

body {
    margin: 0;
    font-family: "Segoe UI", Tahoma, Geneva, Verdana, sans-serif;
    color: var(--text);
    background:
        radial-gradient(circle at top left, #fff7ea 0, transparent 30%),
        linear-gradient(180deg, #efe5d6 0%, var(--bg) 22%, #f7f2ea 100%);
    line-height: 1.45;
}

html,
body {
    max-width: 100%;
    overflow-x: hidden;
}

h1,
h2,
h3 {
    line-height: 1.15;
    overflow-wrap: anywhere;
}

a {
    color: var(--primary-strong);
    text-decoration: none;
}

a:hover {
    text-decoration: underline;
}

.page-shell {
    width: min(1180px, calc(100% - 24px));
    margin: 0 auto;
    padding: 18px 0 40px;
}

.home-treasure {
    position: fixed;
    top: 14px;
    right: 14px;
    z-index: 20;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 42px;
    height: 42px;
    border: 1px solid rgba(220, 207, 190, 0.92);
    border-radius: 999px;
    background: rgba(255, 253, 249, 0.92);
    box-shadow: 0 10px 24px rgba(70, 45, 24, 0.12);
    font-size: 1.25rem;
    text-decoration: none;
    backdrop-filter: blur(8px);
}

.home-treasure:hover {
    transform: translateY(-1px);
    background: #fff8ea;
    text-decoration: none;
}

.overview-card {
    min-width: 0;
    max-width: 100%;
    position: relative;
    background: linear-gradient(135deg, #fff9f0, #f3ede3);
    border: 1px solid rgba(255, 255, 255, 0.8);
    border-radius: calc(var(--radius) + 6px);
    box-shadow: var(--shadow);
    padding: 22px 20px;
    margin-bottom: 18px;
}

.index-hero {
    display: grid;
    grid-template-columns: minmax(0, 1fr) minmax(210px, 280px);
    gap: 20px;
    align-items: center;
    background:
        linear-gradient(135deg, rgba(31, 122, 109, 0.14), transparent 42%),
        linear-gradient(160deg, #fff9f0 0%, #eef7f5 48%, #fff3de 100%);
}

.hero-kicker {
    margin: 0 0 8px;
    color: var(--primary-strong);
    font-size: 0.8rem;
    font-weight: 800;
    letter-spacing: 0.05em;
    text-transform: uppercase;
}

.index-hero h1 {
    margin-bottom: 8px;
    font-size: clamp(2.3rem, 7vw, 4.2rem);
}

.hero-copy {
    max-width: 660px;
    margin-bottom: 18px;
    color: var(--muted);
    font-size: 1.05rem;
}

.hero-actions {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
}

.hero-stat-card {
    display: grid;
    gap: 6px;
    padding: 16px;
    border: 1px solid rgba(31, 122, 109, 0.18);
    border-radius: 16px;
    background: rgba(255, 253, 249, 0.82);
    box-shadow: 0 12px 28px rgba(31, 122, 109, 0.1);
}

.hero-stat-card strong {
    font-size: 1.7rem;
}

.overview-section {
    margin-top: 18px;
}

.overview-subsection {
    margin-top: 18px;
}

.overview-card h1,
.card h2,
.card h3 {
    margin-top: 0;
}

.overview-card p:last-child,
.card p:last-child {
    margin-bottom: 0;
}

.card-stack {
    display: grid;
    gap: 18px;
}

.card {
    min-width: 0;
    max-width: 100%;
    background: var(--surface);
    border: 1px solid var(--line);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    padding: 18px;
}

.card-title-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
    margin-bottom: 12px;
}

.card-title-row h2 {
    margin-bottom: 0;
}

.card-soft {
    background: var(--surface-strong);
}

.feature-grid {
    display: grid;
    grid-template-columns: repeat(4, minmax(0, 1fr));
    gap: 12px;
    margin-bottom: 18px;
}

.feature-card {
    min-height: 150px;
    padding: 16px;
    border: 1px solid var(--line);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
}

.feature-card strong {
    display: block;
    margin-bottom: 8px;
}

.feature-card p {
    margin: 0;
    color: var(--muted);
    font-size: 0.92rem;
}

.feature-card-green {
    background: #edf8f3;
    border-color: #c7e5d8;
}

.feature-card-blue {
    background: #edf4ff;
    border-color: #c9d9ef;
}

.feature-card-yellow {
    background: #fff7df;
    border-color: #ecd99d;
}

.feature-card-red {
    background: #fff0ed;
    border-color: #ecc6bd;
}

.index-create-card {
    border-color: rgba(31, 122, 109, 0.22);
}

.meta-list {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
    gap: 12px;
}

.meta-item {
    background: rgba(255, 255, 255, 0.7);
    border: 1px solid var(--line);
    border-radius: 14px;
    padding: 10px 12px;
}

.meta-label {
    display: block;
    font-size: 0.8rem;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--muted);
    margin-bottom: 4px;
}

.meta-secondary {
    display: inline-block;
    margin-left: 8px;
    color: var(--muted);
    font-size: 0.9rem;
}

.badge {
    display: inline-flex;
    align-items: center;
    padding: 4px 10px;
    border-radius: 999px;
    font-size: 0.88rem;
    font-weight: 600;
}

.badge-open,
.badge-approved {
    background: rgba(31, 122, 109, 0.12);
    color: var(--primary-strong);
}

.badge-closed,
.badge-rejected {
    background: rgba(169, 68, 56, 0.12);
    color: var(--danger);
}

.badge-pending {
    background: rgba(185, 134, 29, 0.14);
    color: #8a6511;
}

.badge-frozen {
    background: rgba(185, 134, 29, 0.14);
    color: #8a6511;
}

.status-row {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    align-items: center;
}

.status-action-form {
    display: inline-flex;
}

button.status-action-button {
    min-height: auto;
    width: auto;
    border: 1px solid currentColor;
    cursor: pointer;
}

button.status-action-button:hover {
    background: var(--primary);
    color: white;
}

.session-actions,
.form-actions,
.inline-actions,
.payer-selector {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
    align-items: center;
}

.actions-cell .inline-actions {
    gap: 2px;
}

form {
    margin: 0;
}

label,
legend {
    font-weight: 600;
}

input,
button,
select {
    font: inherit;
}

input[type="text"],
input[type="password"],
input[type="number"] {
    width: 100%;
    border: 1px solid var(--line);
    border-radius: 12px;
    background: #fffdf9;
    color: var(--text);
    padding: 12px 14px;
}

select,
.table-input,
.table-select {
    width: 100%;
    border: 1px solid var(--line);
    border-radius: 10px;
    background: #fffdf9;
    color: var(--text);
    padding: 8px 10px;
}

.concerned-selector {
    display: flex;
    flex-wrap: wrap;
    gap: 10px 14px;
    margin-bottom: 14px;
}

.concerned-selector label {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    font-weight: 500;
    color: var(--muted);
}

.concerned-selector input {
    width: 16px;
    height: 16px;
}

.field-label-row {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-bottom: 8px;
}

.field-label-row label {
    margin: 0;
}

.toggle-checks-button,
button.toggle-checks-button {
    width: 28px;
    min-width: 28px;
    height: 28px;
    min-height: 28px;
    font-size: 0.95rem;
}

.expense-top-row {
    display: grid;
    grid-template-columns: minmax(88px, 1fr) minmax(0, 2fr) minmax(112px, 1fr);
    gap: 12px;
    align-items: start;
}

.expense-top-row p {
    margin-top: 0;
}

.expense-amount-field,
.expense-name-field,
.expense-date-field {
    margin-bottom: 14px;
}

button,
.button-link {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-height: 42px;
    padding: 10px 14px;
    border: 0;
    border-radius: 12px;
    background: var(--primary);
    color: white;
    font-weight: 600;
    cursor: pointer;
    text-decoration: none;
}

button:hover,
.button-link:hover {
    background: var(--primary-strong);
    text-decoration: none;
}

button:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

.button-secondary {
    background: #ddd2c3;
    color: var(--text);
}

.button-secondary:hover {
    background: #d2c5b4;
}

.button-danger {
    background: var(--danger);
}

.button-danger:hover {
    background: var(--danger-strong);
}

.action-icon-button,
button.action-icon-button {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 30px;
    min-width: 30px;
    height: 30px;
    min-height: 30px;
    padding: 0 2px;
    border-radius: 999px;
    background: transparent;
    color: var(--text);
    font-size: 1rem;
    text-decoration: none;
}

.action-icon-button:hover,
button.action-icon-button:hover {
    background: rgba(31, 122, 109, 0.1);
    color: var(--primary-strong);
    text-decoration: none;
}

.action-icon-danger {
    color: var(--danger);
}

.action-icon-danger:hover,
button.action-icon-danger:hover {
    background: rgba(169, 68, 56, 0.1);
    color: var(--danger-strong);
}

.action-icon-approve:hover,
button.action-icon-approve:hover {
    background: rgba(31, 122, 109, 0.1);
    color: var(--primary-strong);
}

.action-status-icon {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 30px;
    min-width: 30px;
    height: 30px;
    color: var(--muted);
    font-size: 1rem;
}

.payer-original {
    background: #d8ece8;
    color: #144c44;
}

.payer-original:hover {
    background: #c7e4de;
}

.hint,
.muted {
    color: var(--muted);
    font-size: 0.92rem;
}

.alert {
    padding: 12px 14px;
    border-radius: 14px;
    margin-bottom: 14px;
}

.alert-error {
    background: rgba(169, 68, 56, 0.12);
    color: var(--danger-strong);
    border: 1px solid rgba(169, 68, 56, 0.2);
}

.alert-info {
    background: rgba(31, 122, 109, 0.1);
    color: var(--primary-strong);
    border: 1px solid rgba(31, 122, 109, 0.18);
}

.balance-visualization {
    display: grid;
    gap: 8px;
    margin-top: 8px;
}

.balance-bar {
    display: flex;
    flex-wrap: wrap;
    gap: 4px;
    min-width: 0;
    max-width: 100%;
    min-height: 38px;
    padding: 4px;
    overflow: visible;
    border: 1px solid rgba(220, 207, 190, 0.78);
    border-radius: 16px;
    background: rgba(255, 250, 243, 0.86);
}

.balance-segment {
    position: relative;
    display: inline-flex;
    flex: var(--segment-weight, 1) 1 96px;
    align-items: center;
    justify-content: center;
    gap: 5px;
    min-width: min(96px, 100%);
    max-width: 100%;
    padding: 7px 30px 7px 8px;
    border-radius: 12px;
    color: #fffdf9;
    font-size: 0.82rem;
    line-height: 1.1;
    overflow: hidden;
    text-align: center;
    white-space: nowrap;
}

.balance-segment + .balance-segment {
    border-left: 0;
}

.balance-segment-info {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 5px;
    min-width: 0;
    width: 100%;
    overflow: hidden;
}

.balance-segment-info span {
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
}

.balance-segment-info strong {
    flex: 0 0 auto;
    font-size: 0.78rem;
}

.balance-segment-negative {
    background: linear-gradient(135deg, #c74b3f, var(--danger));
}

.balance-segment-positive {
    background: linear-gradient(135deg, #2c987f, var(--primary));
}

.balance-delete-form,
.balance-neutral-participant form {
    display: inline-flex;
    margin: 0;
}

.balance-delete-form {
    position: absolute;
    top: 50%;
    right: 4px;
    transform: translateY(-50%);
}

.balance-delete-button {
    min-width: 22px;
    width: 22px;
    min-height: 22px;
    height: 22px;
    padding: 0;
    border: 0;
    border-radius: 999px;
    background: rgba(255, 255, 255, 0.18);
    box-shadow: none;
    color: #fffdf9;
    font-size: 0.82rem;
    line-height: 1;
}

.balance-delete-button:hover {
    background: rgba(255, 255, 255, 0.28);
}

.balance-delete-button:disabled {
    cursor: not-allowed;
    opacity: 0.45;
}

.balance-settled {
    display: inline-flex;
    align-items: center;
    margin: 0;
    padding: 9px 12px;
    border: 1px solid rgba(31, 122, 109, 0.18);
    border-radius: 999px;
    background: rgba(31, 122, 109, 0.08);
    color: var(--primary-strong);
    font-size: 0.88rem;
    font-weight: 700;
}

.balance-neutral-list {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(138px, 1fr));
    gap: 8px;
}

.balance-neutral-participant {
    display: inline-flex;
    align-items: center;
    justify-content: space-between;
    gap: 6px;
    min-width: 0;
    width: 100%;
    padding: 8px 10px;
    border: 1px solid var(--line);
    border-radius: 12px;
    background: #fffaf3;
    color: var(--muted);
    font-size: 0.84rem;
}

.balance-neutral-participant strong {
    font-size: 0.78rem;
}

.balance-delete-button-neutral {
    background: transparent;
    color: var(--danger);
}

.balance-delete-button-neutral:hover {
    background: transparent;
    color: var(--danger-strong);
}

.icon-button {
    min-height: auto;
    width: auto;
    padding: 0;
    border-radius: 0;
    background: transparent;
    color: var(--danger);
    font-size: 1rem;
}

.icon-button:hover {
    background: transparent;
    color: var(--danger-strong);
}

.payer-label {
    display: inline-flex;
    align-items: center;
    gap: 6px;
}

.payer-badge {
    display: inline-flex;
    align-items: center;
    padding: 2px 8px;
    border-radius: 999px;
    background: rgba(20, 76, 68, 0.12);
    color: #144c44;
    font-size: 0.75rem;
    font-weight: 700;
}

.participant-expense-cell.not-concerned {
    color: var(--muted);
}

.table-amount-input {
    max-width: 96px;
}

.table-date-input {
    margin-top: 6px;
    max-width: 132px;
}

.expense-date-text {
    display: block;
    margin-top: 3px;
    color: var(--muted);
    font-size: 0.82rem;
}

.table-checkbox {
    width: 18px;
    height: 18px;
}

.table-edit-actions {
    margin-top: 12px;
}

.reimbursements-body {
    padding: 14px 16px;
    border: 1px solid var(--line);
    border-radius: 14px;
    background: var(--bg-soft);
}

.reimbursement-line {
    display: inline;
}

.reimbursement-line form {
    display: inline-flex;
    margin-left: 10px;
    vertical-align: middle;
}

.reimbursement-done-button,
button.reimbursement-done-button {
    width: 30px;
    min-width: 30px;
    height: 30px;
    min-height: 30px;
    padding: 0;
    border-radius: 999px;
    background: transparent;
    color: var(--primary-strong);
    font-size: 1rem;
}

.reimbursement-done-button:hover,
button.reimbursement-done-button:hover {
    background: rgba(31, 122, 109, 0.1);
}

.table-wrap {
    overflow-x: auto;
    margin: 0 -4px;
    padding-bottom: 4px;
}

table {
    width: 100%;
    border-collapse: collapse;
    min-width: 760px;
    background: white;
}

th,
td {
    border-bottom: 1px solid var(--line);
    padding: 12px 10px;
    text-align: left;
    vertical-align: top;
}

thead th {
    position: sticky;
    top: 0;
    background: #f6efe5;
    z-index: 1;
}

tbody tr:nth-child(even) {
    background: #fcfaf6;
}

.cell-center {
    text-align: center;
}

.actions-cell {
    min-width: 170px;
}

.link-box {
    display: block;
    padding: 12px 14px;
    background: var(--bg-soft);
    border: 1px solid var(--line);
    border-radius: 14px;
    overflow-wrap: anywhere;
}

.app-footer {
    display: flex;
    flex-wrap: wrap;
    gap: 8px 14px;
    align-items: center;
    justify-content: space-between;
    margin-top: 22px;
    padding: 14px 16px;
    background: var(--bg-soft);
    box-shadow: none;
    color: var(--muted);
    font-size: 0.86rem;
}

.app-footer p {
    margin: 0;
}

.footer-links {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
}

@media (max-width: 900px) {
    .page-shell {
        width: min(100% - 18px, 1180px);
    }

    .card,
    .overview-card {
        padding: 16px;
    }

    .index-hero,
    .feature-grid {
        grid-template-columns: 1fr 1fr;
    }

}

@media (max-width: 720px) {
    body {
        font-size: 15px;
        background: var(--bg-soft);
    }

    .page-shell {
        width: 100%;
        padding: 8px 10px 28px;
    }

    .home-treasure {
        top: 8px;
        right: 8px;
        width: 38px;
        height: 38px;
        font-size: 1.12rem;
    }

    .overview-card,
    .card {
        border-radius: 14px;
        box-shadow: 0 8px 22px rgba(70, 45, 24, 0.06);
        padding: 14px;
    }

    .overview-card {
        margin-bottom: 10px;
    }

    .index-hero,
    .feature-grid {
        grid-template-columns: 1fr;
    }

    .index-hero h1 {
        font-size: 2.4rem;
    }

    .hero-copy {
        font-size: 1rem;
    }

    .hero-stat-card {
        padding: 12px;
    }

    .feature-grid {
        gap: 10px;
        margin-bottom: 10px;
    }

    .feature-card {
        min-height: auto;
        padding: 14px;
        border-radius: 14px;
    }

    .overview-card h1 {
        font-size: 1.45rem;
    }

    .index-hero h1 {
        font-size: 2.4rem;
    }

    .card h2,
    .card h3,
    .overview-section h2 {
        font-size: 1.08rem;
    }

    .card-stack {
        gap: 10px;
    }

    .meta-list {
        grid-template-columns: repeat(2, minmax(0, 1fr));
        gap: 8px;
    }

    .meta-item {
        border-radius: 12px;
        padding: 9px 10px;
    }

    .meta-label {
        font-size: 0.72rem;
        margin-bottom: 3px;
    }

    .meta-secondary {
        display: block;
        margin-left: 0;
        margin-top: 2px;
        font-size: 0.82rem;
    }

    .overview-section,
    .overview-subsection {
        margin-top: 12px;
    }

    .balance-visualization {
        gap: 7px;
        margin-top: 10px;
    }

    .balance-bar {
        min-height: 34px;
        border-radius: 14px;
    }

    .balance-segment {
        flex-basis: 108px;
        min-width: min(96px, 100%);
    }

    .balance-segment {
        padding: 6px 26px 6px 5px;
        font-size: 0.72rem;
    }

    .balance-segment-info {
        flex-direction: column;
        gap: 1px;
    }

    .balance-segment-info strong {
        font-size: 0.7rem;
    }

    .balance-delete-button {
        width: 20px;
        min-width: 20px;
        height: 20px;
        min-height: 20px;
        font-size: 0.74rem;
    }

    .icon-button {
        min-height: 32px;
        width: auto;
        padding: 0 6px;
    }

    input[type="text"],
    input[type="password"],
    input[type="number"],
    select,
    .table-input,
    .table-select {
        border-radius: 10px;
        padding: 11px 12px;
    }

    .expense-top-row {
        grid-template-columns: minmax(76px, 1fr) minmax(0, 2fr) minmax(98px, 1fr);
        gap: 8px;
    }

    .expense-amount-field,
    .expense-name-field,
    .expense-date-field {
        margin-bottom: 10px;
    }

    .concerned-selector {
        display: grid;
        grid-template-columns: repeat(auto-fit, minmax(138px, 1fr));
        gap: 8px;
        margin-bottom: 12px;
    }

    .concerned-selector label {
        justify-content: space-between;
        border: 1px solid var(--line);
        border-radius: 10px;
        background: #fffdf9;
        padding: 9px 10px;
    }

    .concerned-selector input {
        width: 18px;
        height: 18px;
        flex: 0 0 auto;
    }

    .payer-selector {
        display: grid;
        grid-template-columns: repeat(auto-fit, minmax(138px, 1fr));
        gap: 8px;
    }

    button,
    .button-link {
        width: 100%;
        min-height: 44px;
        border-radius: 10px;
    }

    .action-icon-button,
    button.action-icon-button {
        width: 34px;
        min-width: 34px;
        height: 34px;
        min-height: 34px;
    }

    .balance-delete-form .balance-delete-button,
    .balance-neutral-participant .balance-delete-button {
        width: 20px;
        min-width: 20px;
        height: 20px;
        min-height: 20px;
        border-radius: 999px;
    }

    .payer-label {
        justify-content: center;
        width: 100%;
    }

    .session-actions,
    .form-actions,
    .inline-actions {
        flex-direction: column;
        align-items: stretch;
    }

    .reimbursements-body {
        padding: 10px 12px;
        border-radius: 12px;
    }

    .reimbursement-line {
        display: inline;
    }

    .reimbursement-line form {
        display: inline-flex;
        margin: 0 0 0 6px;
        vertical-align: middle;
    }

    .reimbursement-line button.reimbursement-done-button {
        width: 28px;
        min-width: 28px;
        height: 28px;
        min-height: 28px;
        padding: 0;
    }

    .table-wrap {
        overflow: visible;
        margin: 0;
        padding: 0;
    }

    table,
    thead,
    tbody,
    tr,
    th,
    td {
        display: block;
    }

    table {
        min-width: 0;
        background: transparent;
    }

    thead {
        display: none;
    }

    tbody tr,
    tbody tr:nth-child(even) {
        background: #fffdf9;
    }

    tbody tr {
        border: 1px solid var(--line);
        border-radius: 12px;
        margin-bottom: 10px;
        padding: 10px;
    }

    td {
        display: grid;
        grid-template-columns: minmax(92px, 34%) minmax(0, 1fr);
        gap: 10px;
        align-items: center;
        border-bottom: 1px solid rgba(220, 207, 190, 0.65);
        padding: 7px 0;
        overflow-wrap: anywhere;
    }

    td:last-child {
        border-bottom: 0;
    }

    td::before {
        content: attr(data-label);
        color: var(--muted);
        font-size: 0.74rem;
        font-weight: 700;
        text-transform: uppercase;
    }

    .cell-center {
        text-align: left;
    }

    .participant-expense-cell.not-concerned {
        display: none;
    }

    .expenses-edit-table .participant-expense-cell.not-concerned {
        display: grid;
    }

    .table-amount-input {
        max-width: none;
    }

    .table-date-input {
        max-width: none;
    }

    .actions-cell {
        min-width: 0;
    }

    .actions-cell .inline-actions {
        display: flex;
        flex-direction: row;
        flex-wrap: wrap;
        gap: 4px;
    }

    .actions-cell .inline-actions form {
        width: auto;
    }

    .app-footer {
        display: grid;
        gap: 8px;
        text-align: center;
        justify-content: center;
    }

    .footer-links {
        justify-content: center;
    }
}

@media (max-width: 480px) {
    .meta-list {
        grid-template-columns: 1fr;
    }
}

@media (max-width: 390px) {
    .meta-list {
        grid-template-columns: 1fr;
    }

    .expense-top-row {
        grid-template-columns: minmax(70px, 1fr) minmax(0, 2fr) minmax(92px, 1fr);
    }

    .actions-cell .inline-actions {
        display: flex;
    }
}
