:root {
    --bg-deep: #0f172a;
    --bg-mid: #12303b;
    --bg-accent: #1f6f78;
    --surface: #f8fafc;
    --card: #ffffff;
    --text: #0f172a;
    --muted: #5f6d7e;
    --primary: #00796b;
    --primary-dark: #00685b;
    --danger: #d64545;
    --danger-dark: #b53737;
    --warning: #a05a00;
    --border: #dbe3ec;
    --shadow-sm: 0 6px 14px rgba(8, 25, 45, 0.08);
    --shadow-lg: 0 20px 40px rgba(8, 25, 45, 0.16);
    --radius-sm: 8px;
    --radius-md: 12px;
    --radius-lg: 18px;
}

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: 'Manrope', sans-serif;
    color: var(--text);
    min-height: 100vh;
    background:
        radial-gradient(circle at 20% 20%, rgba(255, 196, 98, 0.15), transparent 28%),
        radial-gradient(circle at 85% 10%, rgba(96, 226, 212, 0.12), transparent 35%),
        linear-gradient(145deg, var(--bg-deep), var(--bg-mid) 45%, var(--bg-accent));
    line-height: 1.4;
}

button,
input,
select {
    font: inherit;
}

button {
    cursor: pointer;
    border: none;
    transition: transform 0.15s ease, background-color 0.2s ease, box-shadow 0.2s ease;
}

button:active {
    transform: translateY(1px);
}

button:disabled {
    opacity: 0.6;
    cursor: not-allowed;
    transform: none;
}

button:focus-visible,
input:focus-visible,
select:focus-visible {
    outline: 3px solid rgba(0, 121, 107, 0.3);
    outline-offset: 2px;
}

.navbar {
    position: sticky;
    top: 0;
    z-index: 50;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    padding: 10px 18px;
    background: rgba(13, 28, 46, 0.75);
    border-bottom: 1px solid rgba(255, 255, 255, 0.12);
    backdrop-filter: blur(10px);
}

.nav-items {
    display: flex;
    align-items: center;
    gap: 6px;
}

.nav-btn {
    background: transparent;
    color: #eef3f7;
    padding: 10px 12px;
    border-radius: 999px;
    font-size: 0.95rem;
    font-weight: 600;
}

.nav-btn:hover {
    background: rgba(255, 255, 255, 0.14);
}

.nav-btn.active {
    background: rgba(96, 226, 212, 0.22);
    color: #fff;
}

.brand-btn {
    font-size: 1.2rem;
    font-weight: 800;
    letter-spacing: 0.01em;
}

.nav-brand {
    display: flex;
    align-items: center;
    gap: 10px;
}

.mode-badge {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-height: 24px;
    padding: 4px 10px;
    border-radius: 999px;
    font-size: 0.75rem;
    font-weight: 800;
    letter-spacing: 0.04em;
    text-transform: uppercase;
}

.mode-badge-local {
    background: rgba(255, 196, 98, 0.22);
    color: #fef3c7;
    border: 1px solid rgba(255, 196, 98, 0.35);
}

.mode-badge-remote {
    background: rgba(96, 226, 212, 0.2);
    color: #d5fff8;
    border: 1px solid rgba(96, 226, 212, 0.34);
}

.hamburger {
    display: none;
    flex-direction: column;
    gap: 5px;
    padding: 4px;
    background: transparent;
}

.hamburger span {
    width: 24px;
    height: 2.5px;
    border-radius: 999px;
    background: #fff;
    transition: transform 0.2s ease, opacity 0.2s ease;
}

.hamburger.active span:nth-child(1) {
    transform: translateY(8px) rotate(45deg);
}

.hamburger.active span:nth-child(2) {
    opacity: 0;
}

.hamburger.active span:nth-child(3) {
    transform: translateY(-8px) rotate(-45deg);
}

.container {
    max-width: 980px;
    margin: 24px auto;
    padding: 0 14px;
}

.page {
    display: none;
    background: linear-gradient(180deg, rgba(255, 255, 255, 0.98), #ffffff);
    border: 1px solid rgba(255, 255, 255, 0.6);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-lg);
    padding: 28px;
    animation: fade-in 0.25s ease;
}

.page.active {
    display: block;
}

@keyframes fade-in {
    from {
        opacity: 0;
        transform: translateY(6px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

h1 {
    color: #083447;
    font-size: 2.2rem;
    letter-spacing: -0.02em;
    text-align: center;
}

h2 {
    color: #0e4f60;
    font-size: 1.45rem;
    margin-bottom: 18px;
    letter-spacing: -0.01em;
}

.subtitle,
.welcome-text {
    text-align: center;
    color: var(--muted);
}

.subtitle {
    font-weight: 600;
    margin-top: 6px;
}

.welcome-text {
    margin: 14px auto 24px;
    max-width: 56ch;
}

.stats-grid {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 12px;
    margin: 10px 0 22px;
}

.stat-card {
    background: linear-gradient(155deg, #f0f8f8, #fdfdfd);
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    padding: 14px;
}

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

.stat-value {
    margin-top: 6px;
    color: #06313b;
    font-size: 1.4rem;
    font-weight: 800;
}

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

.btn-home,
.input-group button,
.btn-primary {
    background: var(--primary);
    color: #fff;
    font-weight: 700;
    border-radius: var(--radius-sm);
    box-shadow: var(--shadow-sm);
}

.btn-home {
    min-height: 48px;
    padding: 12px 16px;
}

.btn-home:hover,
.input-group button:hover,
.btn-primary:hover {
    background: var(--primary-dark);
}

.home-footer {
    text-align: center;
    margin-top: 28px;
}

.auth-card {
    margin: 18px 0;
    padding: 14px;
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    background: linear-gradient(180deg, #f6fbfb, #ffffff);
}

.btn-clear {
    padding: 10px 16px;
    background: var(--danger);
    color: #fff;
    border-radius: var(--radius-sm);
    font-weight: 700;
}

.btn-clear:hover,
.btn-delete:hover,
.btn-remove:hover {
    background: var(--danger-dark);
}

.input-group {
    display: grid;
    grid-template-columns: 1fr auto;
    gap: 10px;
    margin-bottom: 16px;
}

#people .input-group {
    padding: 14px;
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    background: linear-gradient(180deg, #f6fbfb, #ffffff);
    box-shadow: var(--shadow-sm);
}

#people #personInput {
    border-color: #cfdbe7;
    font-weight: 600;
}

#peopleList {
    margin-top: 12px;
}

#people .list-item {
    background: linear-gradient(180deg, #ffffff, #f8fcff);
    border-left: 4px solid #1b7fab;
}

#addPersonBtn {
    font-size: 1rem;
    padding: 12px 22px;
    min-height: 48px;
}

input,
select {
    width: 100%;
    padding: 12px;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    background: #fff;
}

.form-group {
    margin-bottom: 16px;
}

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

.form-group label {
    display: block;
    margin-bottom: 8px;
    font-weight: 700;
    color: #1b3248;
}

.helper-actions,
.form-actions,
.btn-group,
.toggle-group {
    display: flex;
    gap: 10px;
}

.helper-actions {
    margin-bottom: 10px;
}

.allocation-list {
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.allocation-item {
    display: grid;
    grid-template-columns: minmax(0, 1fr) 140px;
    gap: 10px;
    align-items: center;
    padding: 12px;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    background: #f8fbfd;
}

.allocation-meta {
    display: flex;
    flex-direction: column;
    gap: 3px;
}

.allocation-title {
    font-weight: 700;
    color: #1b3248;
}

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

.fx-preview {
    padding: 12px;
    border-radius: var(--radius-sm);
    border: 1px dashed rgba(0, 121, 107, 0.35);
    background: rgba(0, 121, 107, 0.06);
}

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

.text-small {
    font-size: 0.9rem;
}

.divider {
    height: 1px;
    background: rgba(15, 23, 42, 0.12);
    margin: 22px 0;
}

.subheading {
    color: #0e4f60;
    font-size: 1.05rem;
    margin: 18px 0 12px;
    letter-spacing: -0.01em;
}

details summary {
    cursor: pointer;
}

.fx-breakdown {
    margin: 10px 0 0;
    padding-left: 18px;
}

.fx-breakdown li {
    margin: 6px 0;
    color: #20364a;
}

.btn-helper {
    background: #2f4858;
    color: #fff;
    padding: 8px 12px;
    border-radius: var(--radius-sm);
    font-weight: 600;
}

.btn-helper:hover {
    background: #263c4a;
}

#authSignedInView {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.form-actions {
    align-items: stretch;
}

.btn-primary,
.btn-cancel {
    width: 100%;
    margin-top: 6px;
    padding: 12px 16px;
    border-radius: var(--radius-sm);
    font-weight: 700;
}

.btn-cancel {
    background: #6b7280;
    color: #fff;
}

.btn-cancel:hover {
    background: #525866;
}

.list {
    list-style: none;
}

.list-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 12px;
    padding: 12px;
    margin-bottom: 10px;
    border-radius: var(--radius-sm);
    border: 1px solid var(--border);
    background: #fff;
}

.list-item span {
    font-weight: 600;
    color: #20364a;
}

.btn-remove,
.btn-delete,
.btn-edit {
    padding: 7px 12px;
    color: #fff;
    border-radius: 7px;
    font-size: 0.86rem;
    min-width: 70px;
}

.btn-remove,
.btn-delete {
    background: var(--danger);
}

.btn-edit {
    background: #147f95;
}

.btn-edit:hover {
    background: #0f6b7d;
}

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

.checkbox-group {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
    gap: 10px;
}

.checkbox-label {
    display: flex;
    gap: 8px;
    align-items: center;
    padding: 10px;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    background: #f8fbfd;
    font-weight: 600;
}

.checkbox-label input[type='checkbox'] {
    width: 18px;
    height: 18px;
    accent-color: var(--primary);
}

.expense-table {
    width: 100%;
    border-collapse: collapse;
    margin-top: 12px;
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    overflow: hidden;
}

.expense-table thead {
    background: #eef5fa;
}

.expense-table th,
.expense-table td {
    padding: 12px;
    text-align: left;
    border-bottom: 1px solid #ecf1f6;
}

.expense-table th {
    color: #24546e;
    font-size: 0.92rem;
}

.expense-table tbody tr:hover {
    background: #f6fafc;
}

.balance-item,
.settlement-item {
    border-radius: var(--radius-sm);
    padding: 12px;
    margin-bottom: 10px;
    border: 1px solid var(--border);
}

.balance-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    font-weight: 700;
}

.balance-positive {
    background: #e9f7ee;
    color: #1f7a3c;
    border-left: 4px solid #2a9c4d;
}

.balance-negative {
    background: #fdeeee;
    color: #8b1e1e;
    border-left: 4px solid #d64545;
}

.settlement-controls {
    background: #f5f9fc;
    border: 1px solid var(--border);
    border-left: 4px solid #147f95;
    border-radius: var(--radius-md);
    padding: 16px;
    margin-bottom: 16px;
}

.toggle-label {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    font-weight: 600;
}

.toggle-checkbox {
    width: 18px;
    height: 18px;
    accent-color: var(--primary);
}

.mode-indicator {
    color: #4f5f6d;
    font-size: 0.9rem;
}

.settlement-item {
    background: #eef8ff;
    color: #13405e;
    border-left: 4px solid #1b7fab;
}

.settlement-amount {
    font-weight: 800;
}

.empty-message {
    text-align: center;
    color: #6b7280;
    padding: 18px;
    font-style: italic;
}

.modal-backdrop {
    position: fixed;
    inset: 0;
    z-index: 120;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 16px;
    background: rgba(15, 23, 42, 0.58);
}

.modal-backdrop[hidden] {
    display: none;
}

.modal-card {
    width: min(520px, 100%);
    max-height: 90vh;
    overflow: auto;
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    background: #fff;
    box-shadow: var(--shadow-lg);
    padding: 18px;
}

.modal-card h3 {
    color: #0e4f60;
    margin-bottom: 8px;
}

.modal-list {
    display: flex;
    flex-direction: column;
    gap: 8px;
    margin: 14px 0;
}

.modal-option {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 10px;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    background: #f8fbfd;
    font-weight: 600;
}

.modal-option input[type='radio'] {
    width: 18px;
    height: 18px;
    accent-color: var(--primary);
}

.modal-actions {
    margin-top: 6px;
}

@media (max-width: 860px) {
    .container {
        margin: 12px auto;
    }

    .page {
        padding: 20px;
    }

    .stats-grid,
    .home-buttons {
        grid-template-columns: 1fr;
    }

    .form-row {
        grid-template-columns: 1fr;
    }

    .allocation-item {
        grid-template-columns: 1fr;
    }

    .modal-card {
        padding: 16px;
    }
}

@media (max-width: 760px) {
    .container {
        margin: 8px auto;
        padding: 0 10px;
    }

    .page {
        padding: 16px;
        border-radius: 14px;
    }

    h2 {
        margin-bottom: 14px;
    }

    .hamburger {
        display: flex;
    }

    .nav-items {
        position: absolute;
        top: 62px;
        left: 10px;
        right: 10px;
        flex-direction: column;
        align-items: stretch;
        background: rgba(13, 28, 46, 0.97);
        border-radius: var(--radius-md);
        border: 1px solid rgba(255, 255, 255, 0.14);
        max-height: 0;
        overflow: hidden;
        transition: max-height 0.2s ease;
    }

    .nav-items.active {
        max-height: 400px;
        padding: 6px;
    }

    .nav-items .nav-btn {
        width: 100%;
        text-align: left;
    }

    .input-group,
    .form-actions,
    .helper-actions {
        grid-template-columns: 1fr;
        flex-direction: column;
        gap: 8px;
    }

    #people .input-group {
        padding: 8px;
    }

    #addPersonBtn {
        font-size: 0.93rem;
        padding: 10px 14px;
        min-height: 42px;
    }

    input,
    select {
        padding: 10px;
    }

    .list-item,
    .balance-item,
    .settlement-item {
        padding: 10px;
        margin-bottom: 8px;
    }

    .list-item {
        flex-direction: column;
        align-items: flex-start;
    }

    .list-item .btn-remove {
        width: 100%;
    }

    .expense-table thead {
        display: none;
    }

    .expense-table,
    .expense-table tbody,
    .expense-table tr,
    .expense-table td {
        display: block;
        width: 100%;
    }

    .expense-table {
        border: none;
    }

    .expense-table tbody tr {
        border: 1px solid var(--border);
        border-radius: var(--radius-sm);
        margin-bottom: 10px;
        background: #fff;
        padding: 8px;
    }

    .expense-table td {
        border: none;
        border-bottom: 1px dashed #e4ebf3;
        padding: 8px 0;
    }

    .expense-table td:last-child {
        border-bottom: none;
        padding-top: 10px;
    }

    .expense-table td::before {
        content: attr(data-label);
        display: inline-block;
        width: 96px;
        color: #35596f;
        font-weight: 700;
    }

    .expense-table td:last-child::before {
        content: '';
        width: 0;
    }

    .btn-group {
        width: 100%;
    }

    .btn-group button {
        width: 100%;
    }
}

@media (prefers-reduced-motion: reduce) {
    * {
        animation: none !important;
        transition: none !important;
        scroll-behavior: auto !important;
    }
}
