:root {
    --bg: #1d1a14;
    --panel: rgba(42, 28, 15, .88);
    --panel-solid: #2a1c0f;
    --text: #f8ead0;
    --muted: #c9a66d;
    --line: rgba(198, 146, 61, .24);
    --brand: #c6923d;
    --brand-dark: #8a4f1f;
    --accent: #7b1f12;
    --gold: #e0b15a;
    --ink-soft: #352313;
    --success: #4f6b34;
    --success-soft: #2f3a22;
    --danger-soft: #3b1710;
    --shadow: 0 18px 52px rgba(0, 0, 0, .34);
    --shadow-soft: 0 8px 22px rgba(0, 0, 0, .24);
    color-scheme: dark;
    font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* {
    box-sizing: border-box;
    -webkit-tap-highlight-color: transparent;
}

html {
    min-height: 100%;
}

html:has(body.login-page) {
    height: 100%;
    overflow: hidden;
}

body {
    margin: 0;
    min-height: 100vh;
    padding-bottom: calc(92px + env(safe-area-inset-bottom));
    background:
        radial-gradient(circle at 18% -8%, rgba(224, 177, 90, .17), transparent 34%),
        radial-gradient(circle at 92% 12%, rgba(123, 31, 18, .26), transparent 30%),
        linear-gradient(180deg, #2a1c0f 0%, var(--bg) 46%, #120f0b 100%);
    color: var(--text);
    -webkit-font-smoothing: antialiased;
}

body.login-page {
    position: fixed;
    inset: 0;
    width: 100%;
    height: 100%;
    min-height: 100%;
    overflow: hidden;
    padding-bottom: 0;
    overscroll-behavior: none;
    touch-action: manipulation;
}

a {
    color: inherit;
    text-decoration: none;
    -webkit-tap-highlight-color: transparent;
}

.app {
    width: min(100%, 560px);
    margin: 0 auto;
    min-height: 100vh;
}

.topbar {
    position: sticky;
    top: 0;
    z-index: 10;
    padding: 18px 16px 14px;
    background: rgba(29, 26, 20, .84);
    border-bottom: 1px solid rgba(198, 146, 61, .18);
    backdrop-filter: blur(22px);
}

.topbar-row {
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto;
    align-items: flex-start;
    gap: 12px;
    min-width: 0;
}

.topbar h1 {
    margin: 0;
    font-size: 24px;
    line-height: 1.12;
    letter-spacing: 0;
    font-weight: 850;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.welcome-text {
    min-width: 0;
    max-width: min(58vw, 260px);
    padding-top: 4px;
    color: var(--muted);
    font-size: clamp(8px, 2.25vw, 12px);
    line-height: 1.1;
    font-weight: 850;
    text-align: right;
    white-space: nowrap;
    overflow: visible;
    text-wrap: nowrap;
}

.topbar p {
    margin: 5px 0 0;
    color: var(--muted);
    font-size: clamp(11px, 3vw, 13px);
    line-height: 1.25;
    white-space: nowrap;
    overflow: visible;
}

.content {
    padding: 14px 14px 30px;
}

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

.table-grid,
.grid:has(.table-tile) {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr)) !important;
    gap: 9px;
}

.table-tile,
.card,
.list-row {
    background: var(--panel);
    border: 1px solid var(--line);
    box-shadow: var(--shadow-soft);
    backdrop-filter: blur(18px);
}

.table-tile {
    position: relative;
    overflow: hidden;
    min-width: 0;
    min-height: 118px;
    border-radius: 16px;
    padding: 10px;
    display: flex;
    flex-direction: column;
    justify-content: space-between;
    transform: translateY(0);
    transition: transform .18s ease, box-shadow .18s ease, border-color .18s ease;
    animation: rise .34s ease both;
}

.table-tile.empty {
    background: linear-gradient(145deg, #2f3a22 0%, #4f6b34 100%) !important;
    border-color: rgba(224, 177, 90, .38) !important;
}

.table-tile.busy {
    background: linear-gradient(145deg, #3b1710 0%, #7b1f12 100%) !important;
    border-color: rgba(224, 177, 90, .42) !important;
}

.table-tile:has(.badge.busy) {
    background: linear-gradient(145deg, #3b1710 0%, #7b1f12 100%) !important;
    border-color: rgba(224, 177, 90, .42) !important;
}

.table-tile:has(.badge:not(.busy)) {
    background: linear-gradient(145deg, #2f3a22 0%, #4f6b34 100%) !important;
    border-color: rgba(224, 177, 90, .38) !important;
}

.table-tile::after {
    content: "";
    position: absolute;
    inset: auto -30px -42px auto;
    width: 70px;
    height: 70px;
    border-radius: 50%;
    background: rgba(224, 177, 90, .16);
}

.table-tile.busy::after {
    background: rgba(198, 146, 61, .2);
}

.table-tile:active {
    transform: scale(.985);
}

.table-number {
    position: relative;
    z-index: 1;
    font-size: 36px;
    font-weight: 900;
    line-height: 1;
}

.table-label {
    position: relative;
    z-index: 1;
    color: var(--muted);
    font-size: 12px;
    margin-top: 5px;
    text-transform: capitalize;
}

.badge {
    position: relative;
    z-index: 1;
    display: inline-flex;
    align-items: center;
    width: max-content;
    min-height: 25px;
    padding: 0 8px;
    border-radius: 999px;
    font-size: 11px;
    font-weight: 800;
    background: rgba(248, 234, 208, .16);
    color: var(--gold);
}

.badge.busy {
    background: rgba(224, 177, 90, .18);
    color: #ffd985;
}

.card {
    border-radius: 18px;
    padding: 15px;
    margin-bottom: 12px;
    animation: rise .28s ease both;
}

.section-title {
    margin: 20px 4px 10px;
    font-size: 12px;
    color: var(--muted);
    font-weight: 850;
    text-transform: uppercase;
}

.list {
    display: grid;
    gap: 10px;
}

.list-row {
    border-radius: 16px;
    padding: 13px;
    display: flex;
    gap: 12px;
    align-items: center;
    justify-content: space-between;
    transition: transform .18s ease, box-shadow .18s ease;
    animation: rise .3s ease both;
}

button.list-row {
    width: 100%;
    border: 1px solid var(--line);
    color: var(--text);
    text-align: left;
}

.user-row i,
.entity-row i {
    color: var(--muted);
}

.entity-row .amount {
    margin-left: auto;
}

.list-row:active {
    transform: scale(.985);
}

.row-main {
    min-width: 0;
}

.row-main strong,
.card strong {
    display: block;
    font-size: 15px;
    line-height: 1.25;
}

.meta {
    color: var(--muted);
    font-size: 12px;
    margin-top: 4px;
}

.amount {
    font-weight: 900;
    white-space: nowrap;
}

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

.btn,
button,
input,
select,
textarea {
    font: inherit;
    -webkit-tap-highlight-color: transparent;
}

.btn,
button {
    appearance: none;
    -webkit-appearance: none;
    outline: none;
    min-height: 46px;
    border: 0;
    border-radius: 14px;
    padding: 0 15px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    background: linear-gradient(135deg, var(--brand), var(--brand-dark));
    color: #1d1a14;
    font-weight: 830;
    cursor: pointer;
    box-shadow: 0 10px 22px rgba(198, 146, 61, .24);
    transition: transform .16s ease, box-shadow .16s ease, filter .16s ease;
}

.btn:focus,
button:focus,
a:focus {
    outline: none;
}

.btn:active,
button:active {
    transform: scale(.975);
    filter: saturate(1.08);
}

.btn.secondary,
button.secondary {
    background: rgba(248, 234, 208, .12);
    color: var(--text);
    box-shadow: none;
}

.btn.danger,
button.danger {
    background: linear-gradient(135deg, var(--accent), #4d130b);
    color: #f8ead0;
    box-shadow: 0 10px 22px rgba(123, 31, 18, .28);
}

.btn.full,
button.full {
    width: 100%;
}

.icon-btn {
    width: 42px;
    min-height: 42px;
    padding: 0;
    border-radius: 13px;
    flex: 0 0 auto;
}

.form {
    display: grid;
    gap: 11px;
}

.field {
    display: grid;
    gap: 6px;
}

label {
    color: var(--muted);
    font-size: 13px;
    font-weight: 800;
}

input,
select,
textarea {
    width: 100%;
    min-height: 48px;
    border-radius: 14px;
    border: 1px solid var(--line);
    background: rgba(248, 234, 208, .08);
    padding: 11px 13px;
    color: var(--text);
    outline: none;
    box-shadow: inset 0 1px 0 rgba(248, 234, 208, .08);
}

select {
    appearance: none;
    -webkit-appearance: none;
    min-height: 52px;
    padding-right: 44px;
    background-color: rgba(248, 234, 208, .08);
    background-image:
        linear-gradient(45deg, transparent 50%, var(--gold) 50%),
        linear-gradient(135deg, var(--gold) 50%, transparent 50%);
    background-position:
        calc(100% - 23px) 50%,
        calc(100% - 16px) 50%;
    background-size: 7px 7px, 7px 7px;
    background-repeat: no-repeat;
    color: var(--text);
    font-weight: 750;
}

select option {
    background: var(--panel-solid);
    color: var(--text);
}

select:disabled {
    opacity: .6;
}

.native-select-hidden {
    position: absolute;
    width: 1px;
    height: 1px;
    opacity: 0;
    pointer-events: none;
}

.select-control {
    width: 100%;
    min-height: 52px;
    border-radius: 14px;
    border: 1px solid var(--line);
    background: rgba(248, 234, 208, .08);
    color: var(--text);
    box-shadow: inset 0 1px 0 rgba(248, 234, 208, .08);
    justify-content: space-between;
    padding: 0 14px;
    text-align: left;
}

.select-control span {
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.select-control i {
    color: var(--gold);
    font-size: 13px;
    flex: 0 0 auto;
}

body.toast-open .select-control {
    visibility: hidden;
}

.select-sheet {
    position: fixed;
    inset: 0;
    z-index: 80;
    display: grid;
    align-items: end;
}

.select-sheet-backdrop {
    position: absolute;
    inset: 0;
    background: rgba(0, 0, 0, .58);
    backdrop-filter: blur(12px);
}

.select-sheet-panel {
    position: relative;
    width: min(100%, 560px);
    max-height: min(72vh, 520px);
    margin: 0 auto;
    padding: 14px;
    padding-bottom: calc(14px + env(safe-area-inset-bottom));
    border-radius: 22px 22px 0 0;
    background: rgba(42, 28, 15, .98);
    border: 1px solid rgba(224, 177, 90, .26);
    box-shadow: var(--shadow);
    animation: modalUp .2s ease both;
}

.select-sheet-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    margin-bottom: 10px;
}

.select-sheet-header strong {
    color: var(--gold);
    font-size: 16px;
}

.select-sheet-options {
    display: grid;
    gap: 8px;
    max-height: calc(min(72vh, 520px) - 82px);
    overflow: auto;
    overscroll-behavior: contain;
}

.select-option {
    min-height: 50px;
    border-radius: 14px;
    border: 1px solid rgba(224, 177, 90, .18);
    background: rgba(248, 234, 208, .08);
    color: var(--text);
    box-shadow: none;
    justify-content: space-between;
    text-align: left;
}

.select-option i {
    color: var(--gold);
}

.select-option:disabled {
    opacity: .45;
}

textarea {
    resize: vertical;
    min-height: 82px;
}

input:focus,
select:focus,
textarea:focus {
    border-color: rgba(224, 177, 90, .66);
    box-shadow: 0 0 0 4px rgba(224, 177, 90, .14);
}

.totals {
    display: grid;
    gap: 9px;
}

.total-line {
    display: flex;
    align-items: center;
    justify-content: space-between;
    color: var(--muted);
}

.total-line.final {
    color: var(--text);
    font-size: 21px;
    font-weight: 900;
}

.flash {
    margin-bottom: 12px;
    border-radius: 14px;
    padding: 12px;
    background: rgba(224, 177, 90, .16);
    color: var(--gold);
    font-weight: 800;
}

.flash.err {
    background: rgba(123, 31, 18, .34);
    color: #ffd1c9;
}

.bottom-nav {
    position: fixed;
    left: 50%;
    bottom: 0;
    transform: translateX(-50%);
    width: min(100%, 560px);
    height: calc(76px + env(safe-area-inset-bottom));
    padding: 8px 8px calc(8px + env(safe-area-inset-bottom));
    background: rgba(29, 26, 20, .88);
    backdrop-filter: blur(24px);
    border-top: 1px solid rgba(198, 146, 61, .2);
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(64px, 1fr));
    z-index: 20;
    box-shadow: 0 -16px 36px rgba(20, 30, 24, .08);
}

.nav-item {
    border-radius: 16px;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 5px;
    color: var(--muted);
    font-size: 11px;
    font-weight: 850;
    transition: background .18s ease, color .18s ease, transform .18s ease;
}

.nav-item i {
    font-size: 19px;
}

.nav-item.active {
    color: var(--gold);
    background: rgba(224, 177, 90, .14);
}

.nav-item:active {
    transform: scale(.96);
}

.login-screen {
    position: fixed;
    inset: 0;
    height: 100vh;
    height: 100dvh;
    width: 100%;
    display: grid;
    justify-items: center;
    align-items: center;
    overflow: hidden;
    padding: max(14px, env(safe-area-inset-top)) 18px max(14px, env(safe-area-inset-bottom));
    background:
        radial-gradient(circle at 20% 14%, rgba(224, 177, 90, .2), transparent 25%),
        radial-gradient(circle at 88% 24%, rgba(123, 31, 18, .32), transparent 34%),
        linear-gradient(155deg, #2a1c0f 0%, #1d1a14 56%, #100d09 100%);
}

.login-card {
    position: relative;
    overflow: hidden;
    width: min(100%, 420px);
    max-height: calc(100svh - 28px - env(safe-area-inset-top) - env(safe-area-inset-bottom));
    background: rgba(42, 28, 15, .88);
    border: 1px solid rgba(224, 177, 90, .24);
    border-radius: 24px;
    padding: 22px;
    box-shadow: var(--shadow);
    backdrop-filter: none;
    animation: none;
}

.login-card::before {
    content: "";
    position: absolute;
    top: -80px;
    right: -80px;
    width: 180px;
    height: 180px;
    border-radius: 50%;
    background: rgba(224, 177, 90, .11);
}

.login-mark {
    width: min(62vw, 220px, 32svh);
    height: auto;
    aspect-ratio: 1;
    display: grid;
    place-items: center;
    margin: 0 auto 18px;
    overflow: visible;
    background: transparent;
    border: 0;
    box-shadow: none;
}

.login-mark.compact {
    width: 64px;
    height: 64px;
    border-radius: 18px;
    margin: 0 0 16px;
    background: linear-gradient(135deg, var(--brand), var(--brand-dark));
    color: #1d1a14;
    font-size: 27px;
}

.login-logo {
    width: 100%;
    height: 100%;
    display: block;
    object-fit: contain;
}

.login-card h1 {
    position: relative;
    margin: 0 0 6px;
    font-size: 30px;
    letter-spacing: 0;
    font-weight: 900;
}

.login-card p {
    position: relative;
    margin: 0 0 18px;
    color: var(--muted);
}

.biometric-login {
    position: relative;
    margin-top: 14px;
    padding: 12px;
    border-radius: 18px;
    border: 1px solid rgba(224, 177, 90, .24);
    background: rgba(248, 234, 208, .08);
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
}

.biometric-login[hidden] {
    display: none;
}

.biometric-login strong,
.biometric-login span {
    display: block;
}

.biometric-login strong {
    color: var(--gold);
    font-size: 15px;
}

.biometric-login span {
    margin-top: 3px;
    color: var(--muted);
    font-size: 12px;
    line-height: 1.25;
}

.biometric-login button {
    min-height: 42px;
    padding: 0 13px;
    flex: 0 0 auto;
}

.privacy-link {
    position: relative;
    display: block;
    margin-top: 14px;
    color: var(--muted);
    font-size: 12px;
    font-weight: 800;
    text-align: center;
}

.legal-page {
    padding-bottom: 20px;
}

.legal-card {
    line-height: 1.58;
}

.legal-card h2 {
    margin: 22px 0 8px;
    color: var(--gold);
    font-size: 18px;
    line-height: 1.25;
}

.legal-card p {
    margin: 0 0 12px;
    color: var(--text);
}

.legal-card ul {
    margin: 0 0 12px;
    padding-left: 20px;
    color: var(--text);
}

.legal-card li {
    margin: 6px 0;
}

.swal2-popup {
    border-radius: 22px !important;
    background: rgba(42, 28, 15, .98) !important;
    color: var(--text) !important;
    border: 1px solid rgba(224, 177, 90, .26) !important;
    box-shadow: var(--shadow) !important;
    font-family: inherit !important;
}

.swal2-container.swal2-backdrop-show {
    background: rgba(0, 0, 0, .58) !important;
    backdrop-filter: blur(12px);
}

.swal2-title {
    color: var(--gold) !important;
    font-size: 21px !important;
    line-height: 1.2 !important;
}

.swal2-html-container {
    color: var(--muted) !important;
    font-size: 14px !important;
}

.swal2-icon.swal2-question {
    border-color: var(--gold) !important;
    color: var(--gold) !important;
}

.swal2-icon.swal2-success {
    border-color: var(--success) !important;
    color: var(--success) !important;
}

.swal2-icon.swal2-error {
    border-color: var(--accent) !important;
    color: var(--accent) !important;
}

.swal2-confirm {
    border-radius: 14px !important;
    background: var(--brand) !important;
    color: #1d1a14 !important;
    min-height: 44px !important;
    font-weight: 850 !important;
    box-shadow: 0 10px 22px rgba(198, 146, 61, .24) !important;
}

.swal2-cancel {
    border-radius: 14px !important;
    background: rgba(248, 234, 208, .12) !important;
    color: var(--text) !important;
    min-height: 44px !important;
    font-weight: 850 !important;
}

.swal2-actions {
    gap: 8px !important;
}

.swal2-timer-progress-bar {
    background: var(--gold) !important;
}

.app-toast {
    width: min(94vw, 390px) !important;
    padding: 12px 14px !important;
    border-radius: 16px !important;
}

.app-toast .swal2-title {
    color: var(--text) !important;
    font-size: 14px !important;
}

.app-toast .swal2-icon {
    margin: 0 8px 0 0 !important;
    width: 24px !important;
    height: 24px !important;
    min-width: 24px !important;
    font-size: 12px !important;
}

.modal[hidden] {
    display: none;
}

.modal {
    position: fixed;
    inset: 0;
    z-index: 50;
    display: grid;
    align-items: end;
    padding: 14px;
}

.modal-backdrop {
    position: absolute;
    inset: 0;
    background: rgba(0, 0, 0, .58);
    backdrop-filter: blur(12px);
}

.modal-panel {
    position: relative;
    width: min(100%, 560px);
    max-height: calc(100vh - 28px - env(safe-area-inset-top));
    overflow: auto;
    margin: 0 auto;
    padding: 16px;
    border-radius: 22px;
    background: rgba(42, 28, 15, .96);
    border: 1px solid rgba(224, 177, 90, .26);
    box-shadow: var(--shadow);
    animation: modalUp .22s ease both;
}

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

.modal-header h2 {
    margin: 0;
    font-size: 20px;
    line-height: 1.15;
}

.modal-header p {
    margin: 4px 0 0;
    color: var(--muted);
    font-size: 12px;
}

.modal-delete-form {
    margin-top: 10px;
}

.modal-split-actions {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 10px;
    margin-top: 10px;
}

.modal-split-actions form {
    min-width: 0;
}

body.modal-open {
    overflow: hidden;
}

@keyframes rise {
    from {
        opacity: 0;
        transform: translateY(10px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

@keyframes modalUp {
    from {
        opacity: 0;
        transform: translateY(18px) scale(.98);
    }
    to {
        opacity: 1;
        transform: translateY(0) scale(1);
    }
}

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

    .table-grid,
    .grid:has(.table-tile) {
        grid-template-columns: repeat(3, minmax(0, 1fr)) !important;
        gap: 7px;
    }

    .table-tile {
        min-height: 104px;
        padding: 8px;
    }

    .table-number {
        font-size: 31px;
    }

    .table-label {
        font-size: 11px;
    }

    .badge {
        min-height: 23px;
        font-size: 10px;
        padding: 0 7px;
    }

    .topbar h1 {
        font-size: 21px;
    }

    .welcome-text {
        max-width: 56vw;
        font-size: clamp(7px, 2.15vw, 10px);
    }

    .nav-item span {
        font-size: 10px;
    }
}
