/* Design system cho giao diện kiểu mobile-app, đè lên Pico.css.
   Class prefix "app-" để không đụng class của Pico. */

:root {
    --app-nav-height: 64px;
    --app-card-radius: 14px;
    --app-card-shadow: 0 1px 3px rgba(0, 0, 0, 0.08);
    --app-card-gap: 0.6rem;
    --app-accent: var(--pico-primary);
    --app-danger: var(--pico-del-color);
    --app-success: var(--pico-ins-color);
}

[x-cloak] {
    display: none !important;
}

/* ---------- Layout chung ---------- */

body {
    margin: 0;
}

main.app-content {
    max-width: 640px;
    margin: 0 auto;
    padding: 1rem 1rem calc(var(--app-nav-height) + env(safe-area-inset-bottom) + 1.5rem) 1rem;
}

/* Màn hình rộng (desktop/tablet lớn): nới container ra để bảng nhiều cột (P&L, cân đối)
   không phải cuộn ngang chỉ vì khung quá hẹp — thiết kế gốc là mobile-first (640px). */
@media (min-width: 900px) {
    main.app-content {
        max-width: 1100px;
    }
}

@media (min-width: 1280px) {
    main.app-content {
        max-width: 1320px;
    }
}

/* ---------- Bottom navigation ---------- */

.app-bottom-nav {
    position: fixed;
    left: 0;
    right: 0;
    bottom: 0;
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    background: var(--pico-background-color);
    border-top: 1px solid var(--pico-muted-border-color);
    padding-bottom: env(safe-area-inset-bottom);
    z-index: 100;
}

.app-bottom-nav__item {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 2px;
    padding: 0.5rem 0.25rem;
    height: var(--app-nav-height);
    text-decoration: none;
    color: var(--pico-muted-color);
    font-size: 0.75rem;
}

.app-bottom-nav__item--active {
    color: var(--app-accent);
    font-weight: 600;
}

.app-bottom-nav__icon {
    font-size: 1.35rem;
    line-height: 1;
}

.app-bottom-nav__label {
    line-height: 1;
}

/* ---------- Top bar (search + filter, kiểu AppSheet) ---------- */

.app-topbar {
    position: sticky;
    top: 0;
    z-index: 10;
    background: var(--pico-background-color);
    padding: 0.6rem 1rem 0.5rem;
    margin: 0 -1rem 0.5rem;
    border-bottom: 1px solid var(--pico-muted-border-color);
}

.app-topbar__row {
    display: flex;
    align-items: stretch;
    gap: 0.5rem;
}

.app-topbar__search {
    flex: 1;
    min-width: 0;
    margin: 0;
}

.app-topbar__search input {
    margin: 0;
    height: 42px;
    min-height: 42px;
}

.app-topbar__icon {
    flex-shrink: 0;
    background: none;
    border: 1px solid var(--pico-muted-border-color);
    font-size: 1.1rem;
    line-height: 1;
    width: 42px;
    height: 42px;
    min-height: 42px;
    padding: 0;
    cursor: pointer;
    border-radius: var(--pico-border-radius);
    display: flex;
    align-items: center;
    justify-content: center;
}

.app-topbar__icon:hover {
    background: var(--pico-code-background-color);
}

/* ---------- Nhóm theo ngày (Nhật ký) ---------- */

.app-day-group {
    margin-top: 1.1rem;
}

.app-day-group:first-child {
    margin-top: 0.5rem;
}

.app-day-group__header {
    position: sticky;
    top: 0;
    z-index: 5;
    display: flex;
    justify-content: space-between;
    align-items: baseline;
    background: var(--pico-background-color);
    padding: 0.4rem 0.1rem;
    border-bottom: 1px solid var(--pico-muted-border-color);
    margin-bottom: 0.5rem;
}

.app-day-group__date {
    font-weight: 700;
    font-size: 0.95rem;
    color: var(--pico-color);
}

.app-day-group__totals {
    display: flex;
    gap: 0.6rem;
    font-size: 0.95rem;
    font-weight: 700;
    font-variant-numeric: tabular-nums;
    color: var(--pico-color);
}

/* ---------- Card / danh sách dạng card ---------- */

.app-card-list {
    display: flex;
    flex-direction: column;
    gap: var(--app-card-gap);
    margin: 0;
}

a.app-card,
div.app-card {
    display: block;
    background: var(--pico-card-background-color, var(--pico-background-color));
    border: 1px solid var(--pico-muted-border-color);
    border-radius: var(--app-card-radius);
    box-shadow: var(--app-card-shadow);
    padding: 0.85rem 1rem;
    text-decoration: none;
    color: inherit;
}

.app-card--warning {
    border-left: 4px solid var(--app-danger);
    background: color-mix(in srgb, var(--app-danger) 8%, var(--pico-background-color));
}

.app-card__row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 0.75rem;
}

.app-card__title {
    font-weight: 400;
    font-size: 0.95rem;
}

.app-card--no-attachment {
    border-left: 3px solid var(--app-danger);
}

.app-card__flag {
    font-size: 0.7rem;
    margin-left: 0.5rem;
}

.app-card__subtitle {
    color: var(--pico-muted-color);
    font-size: 0.85rem;
    margin-top: 2px;
}

.app-card__meta {
    color: var(--pico-muted-color);
    font-size: 0.78rem;
    margin-top: 2px;
}

.app-card__trailing {
    display: flex;
    align-items: center;
    gap: 0.4rem;
    flex-shrink: 0;
    white-space: nowrap;
}

.app-card__amount {
    font-variant-numeric: tabular-nums;
    font-weight: 600;
}

.app-card__chevron {
    color: var(--pico-muted-color);
}

.app-card__actions {
    margin-top: 0.6rem;
    display: flex;
    gap: 0.5rem;
}

/* ---------- Segmented control (thay radio button) ---------- */

.app-segmented {
    display: flex;
    border: 1px solid var(--pico-muted-border-color);
    border-radius: 10px;
    overflow: hidden;
    margin-bottom: 0.75rem;
}

.app-segmented__option {
    flex: 1;
    text-align: center;
    padding: 0.75rem 0.5rem;
    cursor: pointer;
    font-size: 0.95rem;
    min-height: 48px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-right: 1px solid var(--pico-muted-border-color);
    user-select: none;
}

.app-segmented__option:last-child {
    border-right: none;
}

.app-segmented__option input {
    position: absolute;
    opacity: 0;
    pointer-events: none;
}

.app-segmented__option--active {
    background: var(--app-accent);
    color: var(--pico-primary-inverse, #fff);
    font-weight: 600;
}

.app-segmented__option--disabled {
    opacity: 0.4;
    cursor: not-allowed;
    color: var(--pico-muted-color);
}

/* ---------- Type search (dropdown lọc "Loại giao dịch" trong form nhập giao dịch) ---------- */
.app-type-search {
    position: relative;
}

.app-type-search__list {
    position: absolute;
    z-index: 20;
    top: 100%;
    left: 0;
    right: 0;
    margin: 2px 0 0;
    padding: 4px 0;
    max-height: 320px;
    overflow-y: auto;
    list-style: none;
    background: var(--pico-card-background-color, var(--pico-background-color));
    border: 1px solid var(--pico-muted-border-color);
    border-radius: var(--pico-border-radius);
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.12);
}

.app-type-search__list li {
    padding: 0.6rem 0.9rem;
    cursor: pointer;
    font-size: 0.95rem;
    line-height: 1.35;
}

.app-type-search__list li:hover,
.app-type-search__item--active {
    background: color-mix(in srgb, var(--app-accent) 12%, transparent);
}

.app-type-search__empty {
    margin: 0.35rem 0 0;
    font-size: 0.85rem;
    color: var(--pico-muted-color);
}

/* ---------- Tab strip (chip ngang cho Báo cáo / Thuế) ---------- */

.app-tabstrip {
    display: flex;
    gap: 0.5rem;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    padding-bottom: 0.5rem;
    margin-bottom: 0.75rem;
}

.app-tabstrip::-webkit-scrollbar {
    height: 4px;
}

.app-tabstrip__item {
    flex-shrink: 0;
    white-space: nowrap;
    padding: 0.4rem 0.9rem;
    border-radius: 999px;
    border: 1px solid var(--pico-muted-border-color);
    text-decoration: none;
    color: var(--pico-color);
    font-size: 0.85rem;
}

.app-tabstrip__item--active {
    background: var(--app-accent);
    color: var(--pico-primary-inverse, #fff);
    border-color: var(--app-accent);
    font-weight: 600;
}

/* ---------- Form fields to, dễ chạm ---------- */

.app-field {
    margin-bottom: 1rem;
}

.app-field label {
    font-weight: 600;
    font-size: 0.9rem;
    margin-bottom: 0.3rem;
    display: block;
}

.app-field input,
.app-field select,
.app-field textarea {
    min-height: 48px;
    font-size: 1rem;
}

.app-field--amount input {
    font-size: 1.4rem;
    font-weight: 600;
    text-align: right;
}

/* ---------- Menu items (tab Khác) ---------- */

.app-menu-list {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
    margin: 1rem 0;
}

.app-menu-item {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 1rem;
    border-radius: var(--app-card-radius);
    border: 1px solid var(--pico-muted-border-color);
    text-decoration: none;
    color: inherit;
    background: var(--pico-background-color);
}

.app-menu-item__icon {
    font-size: 1.4rem;
}

/* ---------- Trang chi tiết giao dịch ---------- */

.app-detail-hero {
    background: var(--pico-card-background-color, var(--pico-background-color));
    border: 1px solid var(--pico-muted-border-color);
    border-radius: var(--app-card-radius);
    box-shadow: var(--app-card-shadow);
    padding: 1.1rem 1.25rem;
    margin-bottom: 1rem;
    text-align: center;
}

.app-detail-hero__amount {
    font-size: 2rem;
    font-weight: 700;
    font-variant-numeric: tabular-nums;
    line-height: 1.2;
}

.app-detail-hero__type {
    color: var(--pico-muted-color);
    font-size: 0.9rem;
    margin-top: 0.3rem;
}

.app-detail-posting {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.6rem;
    margin-top: 0.75rem;
    font-size: 0.95rem;
}

.app-detail-posting__box {
    background: var(--pico-code-background-color);
    border-radius: 8px;
    padding: 0.35rem 0.7rem;
}

.app-detail-posting__arrow {
    color: var(--pico-muted-color);
}

.app-badge {
    display: inline-block;
    padding: 0.15rem 0.6rem;
    border-radius: 999px;
    font-size: 0.75rem;
    font-weight: 600;
    background: var(--pico-code-background-color);
    color: var(--pico-muted-color);
}

.app-detail-section {
    background: var(--pico-card-background-color, var(--pico-background-color));
    border: 1px solid var(--pico-muted-border-color);
    border-radius: var(--app-card-radius);
    box-shadow: var(--app-card-shadow);
    padding: 0.9rem 1.1rem;
    margin-bottom: 0.75rem;
}

.app-detail-row {
    display: flex;
    justify-content: space-between;
    align-items: baseline;
    gap: 1rem;
    padding: 0.5rem 0;
    border-bottom: 1px solid var(--pico-muted-border-color);
}

.app-detail-row:last-child {
    border-bottom: none;
    padding-bottom: 0;
}

.app-detail-row:first-child {
    padding-top: 0;
}

.app-detail-row__label {
    color: var(--pico-muted-color);
    font-size: 0.85rem;
    flex-shrink: 0;
}

.app-detail-row__value {
    text-align: right;
    overflow-wrap: anywhere;
}

.app-detail-attachment {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    background: var(--pico-code-background-color);
    padding: 0.55rem 0.8rem;
    border-radius: var(--pico-border-radius);
    text-decoration: none;
    color: inherit;
}

.app-detail-attachment + .app-detail-attachment {
    margin-top: 0.4rem;
}

/* ---------- Bảng cuộn ngang trên di động (Lãi/lỗ, Thuế) ---------- */

.app-table-scroll {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    border-radius: var(--app-card-radius);
    border: 1px solid var(--pico-muted-border-color);
}

.app-table-scroll table {
    margin: 0;
    font-size: 0.85rem;
}

.app-table-scroll th,
.app-table-scroll td {
    padding: 0.5rem 0.6rem;
    font-weight: 400;
    white-space: nowrap;
}

.app-table-scroll thead th {
    font-size: 0.75rem;
    font-weight: 600;
    color: var(--pico-muted-color);
    text-transform: uppercase;
    letter-spacing: 0.02em;
}

.app-table-scroll tbody tr:last-child th,
.app-table-scroll tbody tr:last-child td {
    font-weight: 700;
    border-top: 2px solid var(--pico-muted-border-color);
}

.app-table-scroll tbody tr:hover {
    background: var(--pico-code-background-color);
}

/* ---------- Section title chuẩn hóa (báo cáo nhiều phần: P&L, cân đối, dòng tiền) ---------- */

.app-section-title {
    font-size: 0.95rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.03em;
    color: var(--pico-muted-color);
    margin: 1.75rem 0 0.5rem;
}

.app-section-title:first-of-type {
    margin-top: 1.25rem;
}

.app-section-note {
    font-size: 0.78rem;
    color: var(--pico-muted-color);
    margin-top: 0.4rem;
}

/* ---------- Floating action button (nút Mới, kiểu AppSheet) ---------- */

.app-fab {
    position: fixed;
    right: 1.25rem;
    bottom: calc(var(--app-nav-height) + env(safe-area-inset-bottom) + 1rem);
    z-index: 20;
    width: 56px;
    height: 56px;
    border-radius: 50%;
    background: var(--app-accent);
    color: var(--pico-primary-inverse, #fff);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.8rem;
    line-height: 1;
    box-shadow: 0 4px 14px rgba(0, 0, 0, 0.3);
    text-decoration: none;
}

.app-fab:hover,
.app-fab:focus {
    color: var(--pico-primary-inverse, #fff);
    filter: brightness(1.1);
}

/* ---------- Chart expand-to-fullscreen (Dòng tiền theo tháng) ---------- */

.app-chart-expand {
    background: none;
    border: 1px solid var(--pico-muted-border-color);
    color: var(--pico-muted-color);
    font-size: 0.8rem;
    padding: 0.3rem 0.7rem;
    min-height: auto;
    border-radius: var(--pico-border-radius);
    cursor: pointer;
}

.app-chart-expand:hover {
    background: var(--pico-code-background-color);
}

.app-chart-modal {
    width: 100vw;
    height: 100vh;
    max-width: 100vw;
    max-height: 100vh;
    margin: 0;
    padding: 1rem;
    padding-top: calc(1rem + env(safe-area-inset-top));
    border: none;
    background: var(--pico-background-color);
    color: var(--pico-color);
}

.app-chart-modal::backdrop {
    background: rgba(0, 0, 0, 0.6);
}

.app-chart-modal__close {
    position: absolute;
    top: calc(1rem + env(safe-area-inset-top));
    right: 1rem;
    z-index: 1;
    width: 40px;
    height: 40px;
    min-height: auto;
    padding: 0;
    border-radius: 50%;
    border: 1px solid var(--pico-muted-border-color);
    background: var(--pico-background-color);
    color: var(--pico-color);
    font-size: 1.1rem;
    cursor: pointer;
}

/* ---------- Filter row gọn (Báo cáo lãi/lỗ) ---------- */

.app-filter-row {
    display: flex;
    gap: 0.75rem;
    align-items: flex-end;
    flex-wrap: wrap;
}

.app-filter-row .app-field {
    margin-bottom: 0;
    flex: 1;
    min-width: 140px;
}

.app-filter-row__submit {
    margin: 0;
    width: auto;
    padding: 0 1.5rem;
    min-height: 48px;
}

/* ---------- Hero cards (tổng quan lãi/lỗ, thay bảng thô) ---------- */

.app-hero-row {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
    gap: 0.75rem;
    margin: 0.75rem 0;
}

.app-hero-card {
    background: var(--pico-card-background-color, var(--pico-background-color));
    border: 1px solid var(--pico-muted-border-color);
    border-radius: var(--app-card-radius);
    box-shadow: var(--app-card-shadow);
    padding: 1rem 1.1rem;
}

.app-hero-card--accent {
    border-color: var(--app-accent);
    border-width: 2px;
}

.app-hero-card__label {
    font-size: 0.78rem;
    font-weight: 600;
    color: var(--pico-muted-color);
    text-transform: uppercase;
    letter-spacing: 0.02em;
}

.app-hero-card__profit {
    font-size: 1.6rem;
    font-weight: 700;
    font-variant-numeric: tabular-nums;
    margin: 0.3rem 0 0.6rem;
}

.app-hero-card__profit--pos {
    color: var(--pico-ins-color);
}

.app-hero-card__profit--neg {
    color: var(--pico-del-color);
}

.app-hero-card__lines {
    display: flex;
    flex-direction: column;
    gap: 0.25rem;
    font-size: 0.85rem;
}

.app-hero-card__lines a {
    color: inherit;
    text-decoration: none;
}

.app-hero-card__lines a:hover {
    text-decoration: underline;
}

.app-hero-card__lines strong {
    font-variant-numeric: tabular-nums;
}

.app-hero-card__warning {
    margin-top: 0.6rem;
    padding: 0.5rem 0.6rem;
    border-radius: var(--pico-border-radius);
    background: color-mix(in srgb, #f59e0b 12%, var(--pico-background-color));
    border: 1px solid color-mix(in srgb, #f59e0b 40%, transparent);
    font-size: 0.72rem;
    line-height: 1.4;
    text-align: left;
    color: var(--pico-color);
}

.app-hero-card__fx {
    margin-top: 0.5rem;
    font-size: 0.8rem;
    color: var(--pico-muted-color);
    font-variant-numeric: tabular-nums;
}

/* ---------- 3 Ví AMZ (dòng chảy tiền: Amazon -> WorldFirst -> MB) ---------- */

.app-wallet-flow {
    display: flex;
    align-items: stretch;
    gap: 0.5rem;
    margin: 0.75rem 0;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
}

.app-wallet-card {
    flex: 1;
    min-width: 150px;
    background: var(--pico-card-background-color, var(--pico-background-color));
    border: 1px solid var(--pico-muted-border-color);
    border-radius: var(--app-card-radius);
    box-shadow: var(--app-card-shadow);
    padding: 1rem 0.85rem;
    text-align: center;
}

.app-wallet-card__icon {
    font-size: 1.5rem;
    line-height: 1;
}

.app-wallet-card__label {
    font-size: 0.78rem;
    font-weight: 600;
    color: var(--pico-muted-color);
    margin-top: 0.4rem;
}

.app-wallet-card__amount {
    font-size: 1.3rem;
    font-weight: 700;
    font-variant-numeric: tabular-nums;
    margin-top: 0.3rem;
    color: var(--pico-color);
}

.app-wallet-card__amount--neg {
    color: var(--pico-del-color);
}

.app-wallet-card__note {
    font-size: 0.72rem;
    color: var(--pico-muted-color);
    margin-top: 0.2rem;
}

.app-wallet-card__fx {
    font-size: 0.78rem;
    color: var(--pico-muted-color);
    font-variant-numeric: tabular-nums;
    margin-top: 0.15rem;
}

.app-wallet-flow__arrow {
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    font-size: 1.3rem;
    color: var(--pico-muted-color);
    padding: 0 0.2rem;
}

/* ---------- <details> thu gọn (chi tiết Amazon USD, tránh trang quá dài) ---------- */

.app-details {
    margin: 0.6rem 0;
    border: 1px solid var(--pico-muted-border-color);
    border-radius: var(--app-card-radius);
    padding: 0.2rem 0.9rem;
    background: var(--pico-card-background-color, var(--pico-background-color));
}

.app-details summary {
    padding: 0.6rem 0;
    font-size: 0.85rem;
    font-weight: 600;
    cursor: pointer;
    color: var(--pico-color);
}

.app-details[open] summary {
    border-bottom: 1px solid var(--pico-muted-border-color);
    margin-bottom: 0.6rem;
}

.app-details .app-table-scroll {
    border: none;
    margin-bottom: 0.6rem;
}
