:root {
    --bg: #ffffff;
    --secondary-bg: #f4f5f7;
    --text: #14151a;
    --hint: #8a8f98;
    --link: #2481cc;
    --button: #2481cc;
    --button-text: #ffffff;
    --border: rgba(20, 21, 26, 0.08);
    --danger: #e5484d;
    --success: #30a46c;

    --radius-sm: 10px;
    --radius-md: 14px;
    --radius-lg: 20px;
    --shadow-sm: 0 1px 2px rgba(20, 21, 26, 0.04), 0 1px 1px rgba(20, 21, 26, 0.03);
    --shadow-md: 0 6px 20px rgba(20, 21, 26, 0.10);
    --shadow-lg: 0 -8px 24px rgba(20, 21, 26, 0.10);
    --ease: cubic-bezier(.4, 0, .2, 1);
}

@media (prefers-color-scheme: dark) {
    :root {
        --bg: #14181f;
        --secondary-bg: #1f242e;
        --text: #f2f3f5;
        --hint: #8992a3;
        --link: #6ab3f3;
        --button: #4d92d9;
        --button-text: #ffffff;
        --border: rgba(255, 255, 255, 0.08);
        --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.3);
        --shadow-md: 0 8px 24px rgba(0, 0, 0, 0.4);
        --shadow-lg: 0 -8px 24px rgba(0, 0, 0, 0.4);
    }
}

* { box-sizing: border-box; }

html, body {
    margin: 0;
    padding: 0;
    background: var(--secondary-bg);
    color: var(--text);
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
    font-size: 15px;
    -webkit-tap-highlight-color: transparent;
}

#app {
    min-height: 100vh;
    padding-bottom: 84px;
}

.loading, .empty-state {
    padding: 48px 24px;
    text-align: center;
    color: var(--hint);
    font-size: 14px;
}

.screen {
    padding: 14px 16px 8px;
    animation: fadeSlideIn 220ms var(--ease);
}

@keyframes fadeSlideIn {
    from { opacity: 0; transform: translateY(6px); }
    to { opacity: 1; transform: none; }
}

h1 {
    font-size: 22px;
    font-weight: 700;
    letter-spacing: -0.01em;
    margin: 6px 0 16px;
}

h2 {
    font-size: 16px;
    font-weight: 600;
    margin: 22px 0 10px;
}

.screen-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
}

.screen-header h1 {
    margin: 6px 0 16px;
}

.btn-fab {
    flex: none;
    width: 38px;
    height: 38px;
    border-radius: 50%;
    border: none;
    background: var(--button);
    color: var(--button-text);
    font-size: 20px;
    line-height: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    box-shadow: var(--shadow-md);
    transition: transform 120ms var(--ease), box-shadow 120ms var(--ease);
}

.btn-fab:active {
    transform: scale(0.92);
    box-shadow: var(--shadow-sm);
}

.btn-fab.small {
    width: 28px;
    height: 28px;
    font-size: 15px;
    box-shadow: none;
}

.section-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin: 22px 0 10px;
}

.section-header h2 {
    margin: 0;
}

.card-actions {
    display: flex;
    gap: 2px;
    flex: none;
}

.icon-btn {
    background: none;
    border: none;
    font-size: 15px;
    line-height: 1;
    cursor: pointer;
    color: var(--hint);
    padding: 6px;
    border-radius: 50%;
    transition: background 120ms var(--ease), transform 120ms var(--ease);
}

.icon-btn:active {
    background: var(--border);
    transform: scale(0.92);
}

.card-top-row {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 8px;
}

.card {
    background: var(--bg);
    border-radius: var(--radius-md);
    padding: 14px 16px;
    margin-bottom: 10px;
    box-shadow: var(--shadow-sm);
    transition: transform 120ms var(--ease), box-shadow 120ms var(--ease);
}

.card.clickable {
    cursor: pointer;
}

.card.clickable:active {
    transform: scale(0.985);
    box-shadow: none;
}

.card-title {
    font-weight: 600;
    margin-bottom: 4px;
    letter-spacing: -0.005em;
}

.card-meta {
    color: var(--hint);
    font-size: 13px;
    line-height: 1.5;
}

.debt-group {
    margin-bottom: 14px;
}

.debt-group:last-child {
    margin-bottom: 0;
}

.debt-group-name {
    font-weight: 600;
    margin-bottom: 2px;
}

.debt-branch {
    color: var(--hint);
    font-size: 13.5px;
    padding: 2px 0 2px 4px;
}

.debt-branch-glyph {
    display: inline-block;
    width: 18px;
    color: var(--border);
    font-family: monospace;
}

.debt-branch b {
    color: var(--text);
    font-weight: 600;
}

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

.row.wrap { flex-wrap: wrap; }

.split-row {
    min-width: 0;
    cursor: pointer;
}

.split-name {
    display: block;
    flex: 1;
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.split-amount {
    flex: none;
    width: 90px;
    margin: 0;
    border-color: var(--border);
}

.split-amount:disabled {
    opacity: 0.5;
}

.btn {
    display: inline-block;
    background: var(--button);
    color: var(--button-text);
    border: none;
    border-radius: var(--radius-sm);
    padding: 11px 18px;
    font-size: 15px;
    font-weight: 600;
    cursor: pointer;
    text-align: center;
    text-decoration: none;
    transition: transform 120ms var(--ease), opacity 120ms var(--ease), filter 120ms var(--ease);
}

.btn:active {
    transform: scale(0.97);
    filter: brightness(0.95);
}

.btn:disabled { opacity: 0.45; }
.btn:disabled:active { transform: none; }

.btn.secondary {
    background: var(--secondary-bg);
    color: var(--text);
    border: 1px solid var(--border);
    box-shadow: none;
}

.btn.small {
    padding: 7px 12px;
    font-size: 13px;
    border-radius: 9px;
    font-weight: 500;
}

.btn.danger { background: var(--danger); }
.btn.success { background: var(--success); }

.btn-group { display: flex; gap: 8px; margin: 10px 0; }
.btn-group .btn { flex: 1; }

input, select, textarea {
    width: 100%;
    background: var(--secondary-bg);
    color: var(--text);
    border: 1px solid transparent;
    border-radius: var(--radius-sm);
    padding: 11px 13px;
    font-size: 15px;
    margin-bottom: 8px;
    font-family: inherit;
    transition: border-color 120ms var(--ease), box-shadow 120ms var(--ease);
}

/* Checkboxes/radios are also <input> elements — without this they inherit width:100% above and
   balloon to fill their flex row, squeezing or hiding whatever sits next to them (this was the
   actual cause of names/amounts "disappearing" in the expense-split rows). */
input[type="checkbox"], input[type="radio"] {
    width: auto;
    flex: none;
    padding: 0;
    margin: 0;
    accent-color: var(--link);
}

input::placeholder, textarea::placeholder {
    color: var(--hint);
}

input:focus, select:focus, textarea:focus {
    outline: none;
    border-color: var(--link);
    box-shadow: 0 0 0 3px rgba(36, 129, 204, 0.2);
    box-shadow: 0 0 0 3px color-mix(in srgb, var(--link) 20%, transparent);
}

.field-label {
    font-size: 12px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.03em;
    color: var(--hint);
    margin-bottom: 6px;
}

.tag {
    display: inline-block;
    font-size: 12px;
    font-weight: 600;
    padding: 3px 10px;
    border-radius: 20px;
    background: var(--secondary-bg);
    color: var(--hint);
}

.tag.yes { background: rgba(48, 164, 108, 0.15); background: color-mix(in srgb, var(--success) 15%, transparent); color: var(--success); }
.tag.no { background: rgba(229, 72, 77, 0.15); background: color-mix(in srgb, var(--danger) 15%, transparent); color: var(--danger); }
.tag.maybe { background: rgba(217, 164, 0, 0.18); background: color-mix(in srgb, #d9a400 18%, transparent); color: #b8860b; }

.checklist-item {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 11px 0;
    border-bottom: 1px solid var(--border);
    cursor: pointer;
}

.checklist-item:last-child { border-bottom: none; }

.checklist-item.done .checklist-text {
    text-decoration: line-through;
    color: var(--hint);
}

.checklist-text {
    flex: 1;
}

.checkbox {
    width: 22px;
    height: 22px;
    border-radius: 7px;
    border: 2px solid var(--hint);
    flex: none;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 13px;
    transition: background 150ms var(--ease), border-color 150ms var(--ease), transform 150ms var(--ease);
}

.checkbox.done {
    background: var(--success);
    border-color: var(--success);
    color: #fff;
    transform: scale(1.05);
}

.poll-option {
    padding: 12px 14px;
    border-radius: var(--radius-sm);
    border: 1px solid var(--border);
    background: var(--bg);
    margin-bottom: 8px;
    cursor: pointer;
    position: relative;
    overflow: hidden;
    transition: border-color 150ms var(--ease), transform 120ms var(--ease);
}

.poll-option:active {
    transform: scale(0.985);
}

.poll-option .bar {
    position: absolute;
    inset: 0;
    background: rgba(36, 129, 204, 0.14);
    background: color-mix(in srgb, var(--link) 14%, transparent);
    z-index: 0;
    transition: width 300ms var(--ease);
}

.poll-option .content {
    position: relative;
    z-index: 1;
    display: flex;
    justify-content: space-between;
    font-weight: 500;
}

.poll-option.voted {
    border-color: var(--link);
    box-shadow: 0 0 0 1px var(--link);
}

.photo-grid {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 6px;
}

.photo-thumb {
    position: relative;
    aspect-ratio: 1 / 1;
    border-radius: var(--radius-sm);
    overflow: hidden;
    background: var(--bg);
    box-shadow: var(--shadow-sm);
    cursor: pointer;
    transition: transform 120ms var(--ease);
}

.photo-thumb:active {
    transform: scale(0.96);
}

.photo-thumb-check {
    position: absolute;
    top: 6px;
    right: 6px;
    width: 22px;
    height: 22px;
    border-radius: 50%;
    border: 2px solid #fff;
    background: rgba(0, 0, 0, 0.35);
    display: none;
    align-items: center;
    justify-content: center;
    color: #fff;
    font-size: 12px;
    z-index: 2;
    transition: background 120ms var(--ease), transform 120ms var(--ease);
}

.photo-grid.selecting .photo-thumb-check {
    display: flex;
}

.photo-thumb.selected .photo-thumb-check {
    background: var(--link);
    border-color: var(--link);
    transform: scale(1.1);
}

.photo-thumb.selected img {
    opacity: 0.6;
}

.selection-bar {
    position: fixed;
    left: 12px;
    right: 12px;
    bottom: 82px;
    z-index: 500;
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    padding: 10px 14px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    box-shadow: var(--shadow-md);
    animation: fadeSlideIn 180ms var(--ease);
}

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

.photo-thumb-loading {
    width: 100%;
    height: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--hint);
    font-size: 12px;
}

.modal[hidden] {
    display: none;
}

.modal {
    position: fixed;
    inset: 0;
    z-index: 900;
    display: flex;
    align-items: flex-end;
    justify-content: center;
}

.modal-backdrop {
    position: absolute;
    inset: 0;
    background: rgba(10, 11, 15, 0.5);
    -webkit-backdrop-filter: blur(2px);
    backdrop-filter: blur(2px);
    animation: fadeIn 180ms var(--ease);
}

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

.modal-sheet {
    position: relative;
    z-index: 1;
    width: 100%;
    max-width: 480px;
    max-height: 85vh;
    overflow-y: auto;
    background: var(--bg);
    border-radius: var(--radius-lg) var(--radius-lg) 0 0;
    padding: 10px 18px calc(18px + env(safe-area-inset-bottom));
    box-shadow: var(--shadow-lg);
    animation: sheetSlideUp 240ms var(--ease);
}

@keyframes sheetSlideUp {
    from { transform: translateY(24px); opacity: 0; }
    to { transform: none; opacity: 1; }
}

.modal-sheet::before {
    content: "";
    display: block;
    width: 36px;
    height: 4px;
    border-radius: 4px;
    background: var(--border);
    margin: 6px auto 14px;
}

.modal-sheet-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 14px;
}

.modal-sheet-header h2 {
    margin: 0;
    font-size: 17px;
}

.modal-close-btn {
    background: var(--secondary-bg);
    border: none;
    width: 28px;
    height: 28px;
    border-radius: 50%;
    font-size: 14px;
    color: var(--hint);
    cursor: pointer;
    padding: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: transform 120ms var(--ease);
}

.modal-close-btn:active {
    transform: scale(0.9);
}

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

.photo-modal {
    position: fixed;
    inset: 0;
    z-index: 1000;
    display: flex;
    align-items: center;
    justify-content: center;
}

.photo-modal-backdrop {
    position: absolute;
    inset: 0;
    background: rgba(4, 5, 8, 0.9);
    animation: fadeIn 180ms var(--ease);
}

.photo-modal-content {
    position: relative;
    z-index: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 16px;
    max-width: 100%;
    max-height: 100%;
    padding: 16px;
    animation: fadeIn 200ms var(--ease);
}

.photo-modal-content img {
    max-width: 100%;
    max-height: 70vh;
    border-radius: var(--radius-md);
    object-fit: contain;
    box-shadow: 0 20px 50px rgba(0, 0, 0, 0.4);
}

.photo-modal-image-wrap {
    position: relative;
    display: flex;
    align-items: center;
    justify-content: center;
    max-width: 100%;
    touch-action: pan-y;
}

.photo-nav {
    position: absolute;
    top: 50%;
    transform: translateY(-50%);
    width: 40px;
    height: 40px;
    border-radius: 50%;
    border: none;
    background: rgba(255, 255, 255, 0.12);
    -webkit-backdrop-filter: blur(6px);
    backdrop-filter: blur(6px);
    color: #fff;
    font-size: 22px;
    line-height: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    z-index: 2;
    transition: transform 120ms var(--ease), background 120ms var(--ease);
}

.photo-nav:active {
    transform: translateY(-50%) scale(0.9);
    background: rgba(255, 255, 255, 0.2);
}

.photo-nav.prev {
    left: 4px;
}

.photo-nav.next {
    right: 4px;
}

.photo-nav:disabled {
    opacity: 0.2;
    cursor: default;
}

.photo-modal-actions {
    display: flex;
    gap: 8px;
}

.tabbar {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    display: flex;
    background: var(--bg);
    border-top: 1px solid var(--border);
    box-shadow: var(--shadow-lg);
    padding: 6px 8px calc(6px + env(safe-area-inset-bottom));
    gap: 4px;
}

.tabbar a {
    flex: 1;
    text-align: center;
    padding: 7px 0;
    color: var(--hint);
    text-decoration: none;
    font-size: 11px;
    font-weight: 500;
    border-radius: var(--radius-sm);
    transition: background 150ms var(--ease), color 150ms var(--ease);
}

.tabbar a.active {
    color: var(--link);
    font-weight: 700;
    background: rgba(36, 129, 204, 0.12);
    background: color-mix(in srgb, var(--link) 12%, transparent);
}

.tabbar .tab-icon {
    display: block;
    font-size: 19px;
    margin-bottom: 3px;
}

.chat-switch {
    display: inline-block;
    font-size: 13px;
    font-weight: 500;
    color: var(--link);
    text-decoration: none;
    margin-bottom: 4px;
}

.error-banner {
    background: color-mix(in srgb, var(--danger) 12%, transparent);
    color: var(--danger);
    border-radius: var(--radius-sm);
    padding: 12px 14px;
    margin-bottom: 12px;
    font-size: 14px;
    font-weight: 500;
}

.section-empty {
    color: var(--hint);
    padding: 16px 0;
    font-size: 14px;
    text-align: center;
}
