:root {
    --bg: #f6f8fc;
    --card: #ffffff;
    --muted: #6b7280;
    --text: #111827;
    --accent: #2563eb;
    --accent-2: #1d4ed8;
    --border: #e6eaf2;
    --green-bg: #ecfdf3;
    --green-text: #166534;
    --red-bg: #fef2f2;
    --red-text: #991b1b;
    --highlight: #eef4ff;
    --radius: 12px;
    --shadow: 0 10px 30px rgba(15, 23, 42, 0.07);
}

* {
    box-sizing: border-box;
}

body {
    margin: 0;
    font-family: Inter, ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, Arial, sans-serif;
    background: linear-gradient(180deg, #f9fbff 0%, var(--bg) 100%);
    color: var(--text);
    overflow-x: hidden;
}

h1, h2, h3, h4, p {
    margin: 0;
}

.muted {
    color: var(--muted);
}

.container {
    max-width: 1040px;
    margin: 0 auto;
    padding: 20px 14px 26px;
}

.dashboard {
    display: grid;
    gap: 14px;
}

.dashboard > * {
    min-width: 0;
}

.setup-wrap {
    min-height: 100dvh;
    display: grid;
    place-items: center;
    padding: 24px 14px;
}

.setup-card,
.modern-panel {
    background: var(--card);
    border-radius: var(--radius);
    border: 1px solid var(--border);
    box-shadow: var(--shadow);
    min-width: 0;
}

.setup-card {
    width: 100%;
    max-width: 620px;
    padding: 22px;
}

.setup-title {
    font-size: clamp(1.5rem, 4vw, 2rem);
    margin-bottom: 8px;
}

.setup-subtitle {
    color: var(--muted);
    margin-bottom: 18px;
}

.modern-form {
    display: grid;
    gap: 12px;
}

.label {
    display: block;
    font-size: 0.9rem;
    color: #374151;
    margin-bottom: 6px;
}

.input,
select,
input[type="text"],
input[type="number"] {
    width: 100%;
    border: 1px solid var(--border);
    border-radius: 10px;
    padding: 11px 12px;
    background: #fff;
    transition: border-color 0.18s ease, box-shadow 0.18s ease, transform 0.18s ease;
}

.input:focus,
select:focus,
input:focus {
    outline: none;
    border-color: #bfdbfe;
    box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.12);
}

.person-cards {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 10px;
}

.person-card {
    position: relative;
    display: grid;
    gap: 4px;
    padding: 12px;
    border: 1px solid var(--border);
    border-radius: 12px;
    cursor: pointer;
    transition: all 0.2s ease;
}

.person-card input[type="radio"] {
    position: absolute;
    top: 10px;
    right: 10px;
    width: auto;
}

.person-card:has(input:checked) {
    border-color: #93c5fd;
    box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.14);
    background: #f8fbff;
}

.person-name {
    font-weight: 600;
}

.person-meta {
    font-size: 0.85rem;
    color: var(--muted);
}

.custom-input {
    margin-top: 2px;
    padding: 7px 9px;
}

.btn {
    border: 0;
    border-radius: 10px;
    cursor: pointer;
    text-decoration: none;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    font-weight: 600;
    transition: transform 0.16s ease, box-shadow 0.18s ease, background-color 0.18s ease;
}

.btn:active {
    transform: translateY(1px);
}

.btn-primary {
    background: linear-gradient(180deg, var(--accent), var(--accent-2));
    color: #fff;
    box-shadow: 0 8px 18px rgba(37, 99, 235, 0.26);
}

.btn-primary:hover {
    filter: brightness(1.02);
}

.btn-ghost {
    background: #fff;
    border: 1px solid var(--border);
    color: #374151;
    padding: 9px 12px;
}

.btn-lg {
    width: 100%;
    padding: 12px 14px;
    font-size: 1rem;
}

.btn-xs {
    padding: 7px 10px;
    font-size: 0.84rem;
    min-height: 34px;
}

.existing-trips {
    margin-top: 18px;
    padding: 14px;
    border: 1px solid var(--border);
    border-radius: 12px;
    background: #fafcff;
}

.existing-trips .trip-list {
    gap: 8px;
    margin-top: 8px;
}

.existing-trips .trip-list li {
    padding: 12px;
    border: 1px solid var(--border);
    border-radius: 10px;
    background: #fff;
}

.modern-list {
    margin: 0;
    padding: 0;
    list-style: none;
    display: grid;
}

.trip-list li,
.member-list li,
.expense-list li,
.tx-list li {
    padding: 10px 0;
    border-bottom: 1px dashed var(--border);
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
}

.trip-list li:last-child,
.member-list li:last-child,
.expense-list li:last-child,
.tx-list li:last-child {
    border-bottom: 0;
}

.topbar {
    padding: 16px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 12px;
}

.topbar-main-trigger {
    position: relative;
    min-width: 0;
}

.dash-title {
    font-size: clamp(1.25rem, 3vw, 1.8rem);
    margin-bottom: 6px;
}

.topbar-actions {
    display: flex;
    align-items: center;
    gap: 8px;
}

.topbar-toggle-icon {
    display: none;
}

.summary-grid {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 10px;
}

.metric-card {
    background: #fff;
    border: 1px solid var(--border);
    border-radius: 12px;
    padding: 14px;
    box-shadow: var(--shadow);
}

.metric-card p {
    color: var(--muted);
    font-size: 0.86rem;
    margin-bottom: 8px;
}

.metric-card h3 {
    font-size: clamp(1.1rem, 4vw, 1.45rem);
    font-weight: 700;
}

.modern-panel {
    padding: 14px;
}

.section-title-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 8px;
}

.calc-tabs {
    display: flex;
    gap: 8px;
    flex-wrap: nowrap;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    margin-bottom: 12px;
    padding-bottom: 4px;
}

.tab-btn {
    border: 1px solid var(--border);
    background: #fff;
    color: #374151;
    border-radius: 999px;
    padding: 8px 12px;
    cursor: pointer;
    font-weight: 600;
    white-space: nowrap;
    flex: 0 0 auto;
}

.tab-btn.active {
    border-color: #93c5fd;
    background: #eff6ff;
    color: #1d4ed8;
}

.calc-tab-content {
    display: none;
    gap: 12px;
    min-width: 0;
}

.calc-tab-content.active {
    display: grid;
}

.tab-inner-panel {
    margin-top: 6px;
}

.member-form {
    margin: 0;
}

.setup-trip-item,
.member-row-card,
.expense-card,
.tx-card {
    background: #fff;
    border: 1px solid var(--border);
    border-radius: 12px;
    padding: 10px 12px;
    box-shadow: 0 4px 14px rgba(15, 23, 42, 0.05);
    transition: transform 0.18s ease, box-shadow 0.18s ease;
}

.setup-trip-item:hover,
.member-row-card:hover,
.expense-card:hover,
.tx-card:hover {
    transform: translateY(-1px);
    box-shadow: 0 8px 20px rgba(15, 23, 42, 0.08);
}

.chip-btn {
    border: 1px solid var(--border);
    border-radius: 999px;
    background: #fff;
    padding: 7px 11px;
    color: #1f2937;
    cursor: pointer;
    transition: all 0.16s ease;
}

.chip-btn.active {
    border-color: #93c5fd;
    background: #eff6ff;
    color: #1d4ed8;
}

.balance-tag {
    font-size: 0.84rem;
    font-weight: 600;
    padding: 6px 10px;
    border-radius: 999px;
}

.balance-tag.pos {
    background: #ecfdf5;
    color: #047857;
}

.balance-tag.neg {
    background: #fef2f2;
    color: #b91c1c;
}

.expander summary {
    display: flex;
    justify-content: space-between;
    align-items: center;
    cursor: pointer;
    list-style: none;
}

.expander summary::-webkit-details-marker {
    display: none;
}

.expense-form {
    margin-top: 12px;
    display: grid;
    gap: 12px;
}

.form-grid {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 10px;
}

.amount-input {
    font-size: 1.1rem;
    font-weight: 700;
}

.split-toggle {
    display: inline-flex;
    border: 1px solid var(--border);
    border-radius: 999px;
    padding: 4px;
    gap: 4px;
    width: fit-content;
}

.toggle-option {
    position: relative;
    cursor: pointer;
}

.toggle-option input {
    position: absolute;
    inset: 0;
    opacity: 0;
}

.toggle-option span {
    display: block;
    padding: 7px 12px;
    border-radius: 999px;
    font-size: 0.9rem;
}

.toggle-option input:checked + span {
    background: #eff6ff;
    color: #1d4ed8;
    font-weight: 600;
}

.chip-wrap {
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
}

.chip-check {
    position: relative;
    cursor: pointer;
}

.chip-check input {
    position: absolute;
    opacity: 0;
}

.chip-check span {
    display: inline-block;
    padding: 7px 10px;
    border: 1px solid var(--border);
    border-radius: 999px;
    font-size: 0.85rem;
}

.chip-check input:checked + span {
    background: #eff6ff;
    border-color: #93c5fd;
    color: #1d4ed8;
}

.hidden {
    display: none;
}

.expense-item {
    display: grid;
    gap: 4px;
    align-items: flex-start;
}

.expense-top-line {
    width: 100%;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
}

.expense-desc {
    color: #374151;
    font-size: 0.92rem;
}

.expense-actions {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-top: 4px;
}

.expense-table-wrap {
    width: 100%;
    max-width: 100%;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    border: 1px solid var(--border);
    border-radius: 12px;
    background: #fff;
}

.expense-table {
    width: 100%;
    border-collapse: collapse;
    min-width: 760px;
}

.expense-table th,
.expense-table td {
    padding: 10px;
    border-bottom: 1px solid var(--border);
    text-align: left;
    vertical-align: top;
    font-size: 0.9rem;
}

.expense-table th {
    background: #f8fafc;
    color: #374151;
    font-weight: 700;
}

.expense-table tr:last-child td {
    border-bottom: 0;
}

.expense-table .edit-row td {
    background: #fcfdff;
}

.member-manage-wrap {
    margin-top: 14px;
}

.danger-outline {
    border-color: #fecaca;
    color: #b91c1c;
}

.danger-outline:hover {
    background: #fff5f5;
}

.inline-actions {
    display: flex;
    align-items: center;
    gap: 8px;
    flex-wrap: wrap;
}

.person-summary-grid {
    display: grid;
    gap: 10px;
    grid-template-columns: repeat(2, minmax(0, 1fr));
}

.simple-table-wrap {
    width: 100%;
    max-width: 100%;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    border: 1px solid var(--border);
    border-radius: 12px;
    background: #fff;
}

.simple-calc-table {
    width: 100%;
    border-collapse: collapse;
    min-width: 680px;
}

.simple-calc-table th,
.simple-calc-table td {
    padding: 9px 10px;
    border-bottom: 1px solid var(--border);
    text-align: left;
    font-size: 0.9rem;
}

.simple-calc-table th {
    background: #f8fafc;
    color: #374151;
    font-weight: 700;
}

.simple-calc-table tr:last-child td {
    border-bottom: 0;
}

.person-summary-card {
    background: #fff;
    border: 1px solid var(--border);
    border-radius: 12px;
    padding: 12px;
    box-shadow: 0 4px 14px rgba(15, 23, 42, 0.05);
    display: grid;
    gap: 4px;
}

.share-box {
    margin-top: 8px;
    min-height: 190px;
    resize: vertical;
    font-size: 0.9rem;
    line-height: 1.45;
    white-space: pre-wrap;
}

.edit-form {
    margin-top: 8px;
    width: 100%;
    border-top: 1px dashed var(--border);
    padding-top: 10px;
}

.settlement-grid {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 10px;
}

.settle-card {
    border-radius: 12px;
    border: 1px solid transparent;
    padding: 14px;
    box-shadow: var(--shadow);
}

.settle-positive {
    background: var(--green-bg);
    border-color: #bbf7d0;
    color: var(--green-text);
}

.settle-negative {
    background: var(--red-bg);
    border-color: #fecaca;
    color: var(--red-text);
}

.settle-amount {
    margin-top: 8px;
    font-size: 1.5rem;
    font-weight: 800;
}

.highlight-panel {
    background: var(--highlight);
    border-color: #dbe7ff;
    padding: 18px;
}

.highlight-panel .tx-list {
    margin-top: 10px;
}

.highlight-panel .tx-card {
    padding: 12px 14px;
    overflow-wrap: anywhere;
}

.alert {
    background: #fff5f5;
    border: 1px solid #fecaca;
    padding: 10px;
    border-radius: 10px;
    color: #7f1d1d;
    margin-bottom: 10px;
}

.notice {
    background: #effaf2;
    border: 1px solid #bbf7d0;
    padding: 10px;
    border-radius: 10px;
    color: #166534;
    margin-bottom: 10px;
}

@media (max-width: 840px) {
    .person-cards {
        grid-template-columns: 1fr;
    }
}

@media (min-width: 900px) {
    .summary-grid {
        grid-template-columns: repeat(4, minmax(0, 1fr));
    }
}

@media (max-width: 640px) {
    .container {
        padding: 12px 10px 20px;
    }
    .topbar,
    .section-title-row {
        flex-direction: column;
        align-items: flex-start;
    }
    .topbar-main-trigger {
        width: 100%;
        cursor: pointer;
        padding-right: 24px;
    }
    .topbar-toggle-icon {
        display: inline-block;
        position: absolute;
        right: 0;
        top: 6px;
        font-size: 1rem;
        line-height: 1;
        transition: transform 0.2s ease;
    }
    .topbar-toggle-icon.open {
        transform: rotate(180deg);
    }
    .topbar-actions {
        width: 100%;
        display: none;
        grid-template-columns: 1fr;
        gap: 8px;
    }
    .topbar-actions.open {
        display: grid;
    }
    .topbar-actions form,
    .topbar-actions .btn {
        width: 100%;
    }
    .topbar-actions form .btn {
        width: 100%;
    }
    .form-grid,
    .settlement-grid,
    .summary-grid {
        grid-template-columns: 1fr;
    }
    .person-summary-grid {
        grid-template-columns: 1fr;
    }
    .simple-calc-table th,
    .simple-calc-table td {
        font-size: 0.86rem;
        padding: 8px;
    }
    .setup-card,
    .modern-panel {
        padding: 12px;
    }
    .chip-btn,
    .btn {
        min-height: 42px;
    }
    .calc-tabs {
        margin-right: -2px;
        padding-right: 2px;
    }
    .dash-title {
        font-size: 1.2rem;
    }
    .metric-card h3 {
        font-size: 1.2rem;
    }
    .expense-actions {
        width: 100%;
        justify-content: flex-start;
    }
    .expense-top-line {
        flex-direction: column;
        align-items: flex-start;
    }
    .expense-table th,
    .expense-table td {
        padding: 8px;
        font-size: 0.86rem;
    }
}


