/* SplitBill responsive UX polish — loaded after main.css. */

:root {
    --app-touch-target: 44px;
    --app-mobile-gutter: 14px;
    --app-surface-raised: color-mix(in srgb, var(--bg-secondary) 92%, transparent);
}

/* Accessibility and interaction ------------------------------------------------ */
:where(a, button, input, select, textarea, [tabindex]):focus-visible {
    outline: 2px solid var(--accent-secondary);
    outline-offset: 2px;
}

button, select, input, textarea {
    max-width: 100%;
}

input[type="date"] {
    min-width: 0;
}

.btn-action-edit,
.btn-action-delete {
    width: 36px;
    height: 36px;
    padding: 0 !important;
    justify-content: center;
}

@media (hover: none), (pointer: coarse) {
    .card:hover,
    .dashboard-card:hover,
    .expense-item:hover,
    .settlement-row:hover,
    .fab:hover {
        transform: none !important;
    }

    .btn,
    .nav-btn,
    .tab,
    .page-link,
    .dropdown-item,
    .btn-action-edit,
    .btn-action-delete {
        min-height: var(--app-touch-target);
    }

    .btn-icon,
    .btn-action-edit,
    .btn-action-delete {
        min-width: var(--app-touch-target);
    }
}

/* App frame ------------------------------------------------------------------- */
.main-content {
    width: 100%;
}

.breadcrumb {
    min-width: 0;
}

.breadcrumb > * {
    flex: 0 0 auto;
}

.page-header-info {
    min-width: 0;
}

.page-header-info > div:last-child {
    min-width: 0;
}

.page-title {
    overflow-wrap: anywhere;
}

.page-subtitle {
    line-height: 1.45;
}

/* Summary tiles --------------------------------------------------------------- */
.stats-row {
    grid-template-columns: repeat(4, minmax(0, 1fr));
}

.stat-card {
    min-width: 0;
    text-align: left;
    padding: 18px;
}

.stat-card-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
    margin-bottom: 12px;
}

.stat-card-icon {
    width: 34px;
    height: 34px;
    display: inline-grid;
    place-items: center;
    flex: 0 0 34px;
    border: 1px solid var(--border-color);
    border-radius: 10px;
    background: var(--bg-glass);
    color: var(--text-accent);
}

.stat-card-icon svg {
    width: 17px;
    height: 17px;
}

.stat-card .stat-label {
    margin-top: 0;
    color: var(--text-secondary);
    font-size: 12px;
    font-weight: 650;
}

.stat-card .stat-value {
    min-width: 0;
    font-size: clamp(1.25rem, 2.2vw, 1.65rem);
    line-height: 1.25;
    overflow-wrap: anywhere;
}

/* Tabs ------------------------------------------------------------------------ */
.tabs-wrapper {
    min-width: 0;
}

.tabs {
    scrollbar-width: none;
}

.tabs::-webkit-scrollbar {
    display: none;
}

.tab {
    min-height: 46px;
    flex: 0 0 auto;
}

.tab[aria-selected="true"] {
    color: var(--text-accent);
}

.tab-container.tab-loading {
    min-height: 180px;
    opacity: .55;
    pointer-events: none;
    transition: opacity .15s ease;
}

/* Expense toolbar and rows ---------------------------------------------------- */
.expense-toolbar-main,
.settlements-header,
.tab-pane-header {
    align-items: flex-end;
}

.expense-toolbar-summary {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-top: 3px;
    color: var(--text-muted);
    font-size: 12px;
}

.expense-filter-bar {
    background: color-mix(in srgb, var(--bg-card) 76%, transparent);
}

.expense-filter-control select {
    appearance: none;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' fill='none' stroke='%238B8BA3' stroke-width='2' viewBox='0 0 24 24'%3E%3Cpath d='m6 9 6 6 6-6'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 12px center;
}

.expense-item {
    display: grid;
    grid-template-columns: 42px minmax(0, 1fr) auto;
    align-items: center;
    gap: 14px;
    padding: 14px 16px;
}

.expense-info {
    min-width: 0;
}

.expense-title-row {
    min-width: 0;
}

.expense-desc {
    min-width: 0;
    font-weight: 650;
}

.expense-meta-row {
    row-gap: 4px;
}

.expense-meta-row > span {
    min-width: 0;
}

.expense-right-wrap {
    min-width: 138px;
}

.expense-actions {
    width: auto;
}

.expense-amount-block {
    min-width: 78px;
}

.expense-amount {
    font-variant-numeric: tabular-nums;
}

.expense-currency {
    text-transform: uppercase;
}

.expense-category-chip {
    max-width: 160px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.fab-label {
    display: none;
}

/* Balances -------------------------------------------------------------------- */
.tab-pane-header {
    display: flex;
    justify-content: space-between;
    gap: var(--space-md);
    margin-bottom: var(--space-lg);
}

.tab-pane-title {
    margin: 0;
    font-size: var(--font-lg);
}

.tab-pane-subtitle {
    max-width: 680px;
    margin-top: 3px;
    color: var(--text-muted);
    font-size: 12px;
}

.balance-item {
    min-width: 0;
}

.balance-avatars-flow {
    flex: 0 0 auto;
}

.balance-info {
    min-width: 0;
}

.balance-amount {
    font-variant-numeric: tabular-nums;
}

.balance-actions .btn {
    justify-content: center;
}

/* Settlements ----------------------------------------------------------------- */
.settlement-row {
    box-shadow: none;
}

.settlement-primary-amount strong {
    font-variant-numeric: tabular-nums;
}

.settlement-detail-line {
    line-height: 1.4;
}

.settlement-count-badge {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    padding: 3px 8px;
    border: 1px solid var(--border-color);
    border-radius: var(--radius-full);
    background: var(--bg-glass);
    color: var(--text-secondary);
    font-size: 11px;
    font-weight: 650;
}

/* Overview and workspace lists ------------------------------------------------ */
.trip-overview-grid {
    display: grid;
    grid-template-columns: minmax(0, 1fr);
}

.member-panel {
    border: 1px solid var(--border-color);
    border-radius: var(--radius-lg);
    background: var(--bg-card);
    padding: var(--space-lg);
}

.member-panel .section-title-md {
    margin-bottom: 12px;
}

.member-panel .member-item {
    border-bottom: 1px solid var(--border-color);
    border-radius: 0;
    padding-left: 0;
    padding-right: 0;
}

.member-panel .member-item:last-child {
    border-bottom: 0;
}

.card-link:focus-visible .card {
    border-color: var(--accent-primary);
    box-shadow: 0 0 0 3px var(--accent-glow);
}

/* Modals and forms ------------------------------------------------------------- */
.modal-container {
    scrollbar-width: thin;
    scrollbar-color: var(--border-hover) transparent;
}

.modal-header {
    gap: 12px;
}

.modal-title {
    min-width: 0;
}

.modal-title span {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.form-submit-bar {
    position: sticky;
    bottom: -28px;
    z-index: 6;
    margin: 18px -28px -28px;
    padding: 14px 28px 18px;
    border-top: 1px solid var(--border-color);
    background: color-mix(in srgb, var(--bg-secondary) 94%, transparent);
    backdrop-filter: blur(14px);
}

.form-submit-bar .btn {
    width: 100%;
    justify-content: center;
    min-height: 46px;
    margin-top: 0 !important;
}

.expense-form .form-submit-bar {
    margin-top: var(--space-lg);
}

.expense-form .expense-member-row {
    min-width: 0;
}

.expense-form .expense-member-name,
.expense-form .expense-participant-label span {
    min-width: 0;
    overflow-wrap: anywhere;
}

/* Light theme: forms should not paint every inline form purple. */
[data-theme="light"] .expense-filter-bar,
[data-theme="light"] .inline-form,
[data-theme="light"] .dashboard-logout-form,
[data-theme="light"] .lang-switcher-form,
[data-theme="light"] .user-dropdown-logout-form {
    background: transparent !important;
    border: 0 !important;
    box-shadow: none !important;
}

[data-theme="light"] .member-panel,
[data-theme="light"] .expense-item,
[data-theme="light"] .settlement-row,
[data-theme="light"] .balance-item {
    background: #FFFFFF;
}

/* Desktop/tablet --------------------------------------------------------------- */
@media (max-width: 980px) {
    .stats-row {
        grid-template-columns: repeat(2, minmax(0, 1fr));
    }

    .page-header-actions {
        flex-wrap: wrap !important;
        justify-content: flex-end;
    }
}

/* Mobile ----------------------------------------------------------------------- */
@media (max-width: 768px) {
    .main-content {
        padding-top: calc(var(--navbar-height) + 20px);
        padding-left: var(--app-mobile-gutter);
        padding-right: var(--app-mobile-gutter);
        padding-bottom: 92px;
    }

    .navbar {
        padding-left: 12px;
        padding-right: 12px;
    }

    .navbar-logo {
        font-size: 1.08rem;
    }

    .navbar-actions {
        gap: 5px;
    }

    .breadcrumb {
        overflow-x: auto;
        white-space: nowrap;
        padding-bottom: 2px;
        scrollbar-width: none;
    }

    .breadcrumb::-webkit-scrollbar {
        display: none;
    }

    .page-header {
        align-items: stretch;
        margin-bottom: 18px;
    }

    .page-header-info {
        align-items: flex-start !important;
        width: 100%;
    }

    .page-header-icon,
    .card-icon.page-header-icon {
        width: 46px !important;
        height: 46px !important;
        min-width: 46px !important;
        min-height: 46px !important;
    }

    .page-title {
        font-size: clamp(1.4rem, 7vw, 1.75rem);
        line-height: 1.18;
    }

    .page-header-actions {
        width: 100%;
        display: grid !important;
        grid-template-columns: repeat(2, minmax(0, 1fr));
        gap: 8px !important;
    }

    .page-header-actions .btn {
        width: 100%;
        min-height: 42px;
        justify-content: center;
    }

    .stats-row {
        gap: 10px;
        margin-bottom: 18px;
    }

    .stat-card {
        padding: 13px;
    }

    .stat-card-head {
        margin-bottom: 8px;
    }

    .stat-card-icon {
        width: 30px;
        height: 30px;
        flex-basis: 30px;
    }

    .stat-card .stat-label {
        font-size: 11px;
    }

    .stat-card .stat-value {
        font-size: 1.12rem;
    }

    .tabs {
        position: sticky;
        top: var(--navbar-height);
        z-index: 40;
        margin-left: calc(var(--app-mobile-gutter) * -1);
        margin-right: calc(var(--app-mobile-gutter) * -1);
        margin-bottom: 18px;
        padding: 0 var(--app-mobile-gutter);
        overflow-x: auto;
        background: color-mix(in srgb, var(--bg-primary) 92%, transparent);
        backdrop-filter: blur(16px);
        scroll-snap-type: x proximity;
    }

    .tab {
        min-height: 48px;
        padding: 10px 13px;
        scroll-snap-align: start;
    }

    .expense-toolbar-main,
    .settlements-header,
    .tab-pane-header {
        align-items: stretch;
        flex-direction: column;
        gap: 10px;
    }

    .expense-toolbar-actions,
    .tab-pane-actions {
        width: 100%;
    }

    .expense-toolbar-actions .dropdown,
    .expense-toolbar-actions .btn,
    .tab-pane-actions .btn,
    .settlements-header > .btn {
        width: 100%;
    }

    .expense-toolbar-actions .btn,
    .tab-pane-actions .btn,
    .settlements-header > .btn {
        justify-content: center;
        min-height: 42px;
    }

    .expense-filter-bar {
        grid-template-columns: repeat(2, minmax(0, 1fr));
        gap: 9px;
        padding: 10px;
    }

    .expense-filter-control select {
        min-height: 44px;
        padding-left: 10px;
        font-size: 14px;
    }

    .expense-page-size-control,
    .expense-filter-reset {
        grid-column: 1 / -1;
    }

    .expense-filter-reset {
        min-height: 40px;
    }

    .expense-item {
        grid-template-columns: 38px minmax(0, 1fr);
        align-items: start;
        gap: 10px 12px;
        padding: 13px;
    }

    .expense-icon {
        width: 38px;
        height: 38px;
    }

    .expense-title-row {
        align-items: flex-start;
        gap: 5px;
    }

    .expense-category-chip {
        max-width: 100%;
    }

    .expense-meta-row {
        gap: 5px 12px;
    }

    .expense-meta-row > span:first-child {
        width: 100%;
    }

    .expense-right-wrap {
        grid-column: 1 / -1;
        width: 100%;
        min-width: 0;
        margin: 0;
        padding-top: 10px;
        border-top: 1px solid var(--border-color);
        justify-content: space-between;
    }

    .expense-amount-block {
        min-width: 0;
        text-align: left;
    }

    .expense-amount {
        font-size: 1.1rem;
    }

    .expense-actions {
        gap: 6px;
    }

    .pagination-container {
        justify-content: flex-start;
        overflow-x: auto;
        margin-left: -2px;
        margin-right: -2px;
        scrollbar-width: none;
    }

    .pagination-container::-webkit-scrollbar {
        display: none;
    }

    .pagination {
        margin: 0 auto !important;
        overflow: visible !important;
    }

    .page-link {
        min-width: 42px !important;
        height: 42px !important;
    }

    .balance-item {
        align-items: stretch;
        text-align: left;
        gap: 12px;
        padding: 14px;
    }

    .balance-avatars-flow {
        justify-content: flex-start;
    }

    .balance-actions {
        width: 100%;
    }

    .balance-actions .btn,
    .balance-actions .cursor-default {
        width: 100%;
        min-height: 44px;
    }

    .settlement-row {
        gap: 14px;
        padding: 14px;
    }

    .settlement-route {
        grid-template-columns: minmax(0, 1fr) 30px minmax(0, 1fr);
        gap: 6px;
    }

    .settlement-person {
        flex-direction: column;
        gap: 6px;
    }

    .settlement-person-copy strong {
        white-space: normal;
        line-height: 1.25;
    }

    .settlement-primary-amount strong {
        font-size: 1.25rem;
    }

    .settlement-actions .btn {
        min-width: 44px;
        min-height: 44px;
    }

    .member-panel {
        padding: 12px 14px;
    }

    .member-panel .member-item {
        gap: 10px;
    }

    .dashboard-container {
        padding: 18px 0 !important;
    }

    .dashboard-grid {
        gap: 12px !important;
        margin-top: 20px !important;
    }

    .dashboard-card {
        padding: 18px !important;
        gap: 14px !important;
    }

    .dashboard-card-icon-wrapper {
        width: 46px !important;
        height: 46px !important;
    }

    .dashboard-card-desc {
        display: -webkit-box;
        -webkit-line-clamp: 2;
        -webkit-box-orient: vertical;
        overflow: hidden;
    }

    .card-grid {
        gap: 12px;
    }

    .workspace-card-cover {
        min-height: 110px;
    }

    .fab {
        right: 14px;
        bottom: calc(14px + env(safe-area-inset-bottom));
        width: auto;
        min-width: 56px;
        height: 52px;
        padding: 0 17px;
        gap: 8px;
        border-radius: 16px;
    }

    .fab-label {
        display: inline;
        font-size: 13px;
        font-weight: 700;
    }

    .modal-overlay {
        align-items: flex-end !important;
        padding: 8px 8px 0 !important;
    }

    .modal-container {
        width: 100% !important;
        max-width: none !important;
        max-height: calc(100dvh - 8px) !important;
        padding: 18px !important;
        border-radius: 18px 18px 0 0 !important;
        overscroll-behavior: contain;
    }

    .modal-header {
        position: sticky !important;
        top: -18px;
        z-index: 10;
        margin: -18px -18px 16px !important;
        padding: 16px 18px !important;
        background: color-mix(in srgb, var(--bg-secondary) 96%, transparent);
        backdrop-filter: blur(16px);
    }

    .modal-close-btn {
        width: 42px !important;
        height: 42px !important;
        flex: 0 0 42px;
    }

    .form-submit-bar {
        bottom: -18px;
        margin: 16px -18px -18px;
        padding: 12px 18px calc(12px + env(safe-area-inset-bottom));
    }

    .expense-form .expense-amount-currency-row {
        grid-template-columns: minmax(0, 1fr) 104px;
    }

    .settlement-mode-btn,
    .settlement-swap-btn {
        min-height: 44px;
    }

    .toast-messages-floating {
        top: 72px !important;
        right: 12px !important;
        width: calc(100vw - 24px) !important;
    }
}

@media (max-width: 420px) {
    .stats-row {
        grid-template-columns: 1fr 1fr;
    }

    .stat-card {
        padding: 11px;
    }

    .stat-card-head {
        align-items: flex-start;
    }

    .stat-card-icon {
        display: none;
    }

    .expense-filter-bar {
        grid-template-columns: 1fr;
    }

    .expense-page-size-control,
    .expense-filter-reset {
        grid-column: auto;
    }

    .expense-form .expense-member-row {
        grid-template-columns: 1fr;
        align-items: stretch;
    }

    .expense-form .expense-split-value,
    .expense-form .expense-value-with-addon {
        width: 100%;
    }

    .settlement-party-grid {
        grid-template-columns: minmax(0, 1fr) 32px minmax(0, 1fr) !important;
    }

    .settlement-party-grid select {
        font-size: 12px !important;
    }
}

@media (prefers-reduced-motion: reduce) {
    *, *::before, *::after {
        scroll-behavior: auto !important;
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
    }
}

/* Additional whole-app polish ------------------------------------------------- */
.analytics-controls {
    width: min(100%, 300px);
}

.analytics-controls .form-select {
    min-height: 44px;
}

.modal-loading,
.modal-load-error {
    min-height: 150px;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 10px;
    color: var(--text-secondary);
    text-align: center;
}

.modal-load-error {
    flex-direction: column;
}

.modal-loading-spinner {
    width: 20px;
    height: 20px;
    flex: 0 0 20px;
    border: 2px solid var(--border-color);
    border-top-color: var(--accent-primary);
    border-radius: 50%;
    animation: spin .75s linear infinite;
}

.invitation-info,
.notif-text-group,
.notif-content-left {
    min-width: 0;
}

.invitation-trip,
.notif-title,
.notif-message {
    overflow-wrap: anywhere;
}

.profile-action-row .btn,
.profile-modal-actions .btn {
    justify-content: center;
}

@media (max-width: 640px) {
    .auth-card {
        padding: 22px 18px !important;
        border-radius: 18px !important;
    }

    .profile-wrap {
        padding-left: 0;
        padding-right: 0;
    }

    .profile-header-row {
        gap: 14px;
    }

    .profile-name-heading {
        font-size: 1.55rem;
    }

    .profile-section-card {
        padding: 16px;
    }

    .profile-grid-names {
        grid-template-columns: 1fr;
    }

    .profile-action-row {
        align-items: stretch;
        flex-direction: column;
    }

    .profile-locked-field {
        width: 100%;
        min-width: 0;
    }

    .profile-action-row .btn,
    .profile-modal-actions .btn {
        width: 100%;
    }

    .profile-modal-actions {
        flex-direction: column-reverse;
    }

    .invitation-item {
        display: grid;
        grid-template-columns: minmax(0, 1fr);
        align-items: start;
        gap: 10px;
        padding: 14px;
    }

    .invitation-actions {
        width: 100%;
        display: grid;
        grid-template-columns: repeat(2, minmax(0, 1fr));
    }

    .invitation-actions form,
    .invitation-actions .btn {
        width: 100%;
    }

    .notification-item {
        align-items: flex-start;
        gap: 10px;
        padding: 14px;
    }

    .notif-content-left {
        align-items: flex-start;
    }

    .notif-header-actions {
        width: 100%;
        display: grid;
        grid-template-columns: repeat(2, minmax(0, 1fr));
    }

    .notif-header-actions form,
    .notif-header-actions .btn {
        width: 100%;
    }
}

@media (max-width: 420px) {
    .invitation-actions,
    .notif-header-actions {
        grid-template-columns: 1fr;
    }

    .notification-item {
        display: grid;
        grid-template-columns: 1fr;
    }

    .notif-content-left {
        width: 100%;
    }
}

.settlement-edit-details-grid {
    margin-top: 14px;
}

.notif-msg {
    overflow-wrap: anywhere;
}

@media (max-width: 640px) {
    .notif-actions-right {
        flex: 0 0 auto;
        align-self: flex-start;
    }

    .theme-setting-row {
        align-items: stretch;
        flex-direction: column;
        gap: 14px;
    }

    .theme-toggle-group {
        width: 100%;
        display: grid;
        grid-template-columns: repeat(2, minmax(0, 1fr));
    }

    .theme-toggle-group .theme-btn {
        width: 100%;
        justify-content: center;
        min-height: 44px;
    }
}

@media (max-width: 420px) {
    .notif-actions-right {
        width: 100%;
        justify-content: flex-end;
    }
}

/* Native controls should match the selected theme, including opened menus. */
[data-theme="dark"] .form-select,
[data-theme="dark"] select.form-input,
[data-theme="dark"] .modal-container select {
    color-scheme: dark;
}

[data-theme="light"] .form-select,
[data-theme="light"] select.form-input,
[data-theme="light"] .modal-container select {
    color-scheme: light;
}

@media (max-width: 420px) {
    .settlement-route {
        grid-template-columns: minmax(0, 1fr);
        gap: 7px;
    }

    .settlement-route-arrow {
        margin-left: 4px;
        transform: rotate(90deg);
    }

    .settlement-person {
        flex-direction: row;
        align-items: center;
    }
}
