/* public/css/app.css — Telegram Mini App + Bulma 1.0 */

/* =========================================
   1. CSS Custom Properties
   ========================================= */
:root {
    /* Telegram WebApp theme tokens (khởi tạo mặc định, JS sẽ ghi đè) */
    --tg-theme-bg-color: #ffffff;
    --tg-theme-text-color: #222222;
    --tg-theme-hint-color: #999999;
    --tg-theme-link-color: #007aff;
    --tg-theme-button-color: #007aff;
    --tg-theme-button-text-color: #ffffff;
    --tg-theme-secondary-bg-color: #f2f2f7;
    --tg-theme-app-bg: #f2f2f7;

    /* Brand & semantic */
    --brand-color: #007aff;
    --brand-color-hover: #0056b3;
    --danger-color: #ff3b30;
    --danger-bg: rgba(255, 59, 48, 0.1);
    --success-color: #34c759;
    --success-bg: rgba(52, 199, 89, 0.1);
    --warning-color: #ff9500;
    --warning-bg: rgba(255, 149, 0, 0.15);

    /* Surfaces */
    --surface-shadow: 0 4px 24px rgba(0, 0, 0, 0.06);
    --border-subtle: rgba(0, 0, 0, 0.05);

    /* Radii */
    --radius-xl: 20px;
    --radius-lg: 14px;
    --radius-md: 10px;
    --radius-sm: 6px;

    /* Spacing */
    --space-xs: 4px;
    --space-sm: 8px;
    --space-md: 16px;
    --space-lg: 24px;
    --space-xl: 32px;

    /* Legacy aliases (backward compat with inline styles) */
    --spacing-xs: var(--space-xs);
    --spacing-sm: var(--space-sm);
    --spacing-md: var(--space-md);
    --spacing-lg: var(--space-lg);
    --spacing-xl: var(--space-xl);
    --border-radius-lg: var(--radius-xl);
    --border-radius-md: var(--radius-lg);
    --border-radius-sm: var(--radius-md);
    --border-radius-xs: var(--radius-sm);

    /* Bulma 1.0 CSS-vars override (map to our brand) */
    --bulma-primary-h: 211;
    --bulma-primary-s: 100%;
    --bulma-primary-l: 50%; /* hsl(211,100%,50%) ≈ #007aff */
    --bulma-danger-h: 3;
    --bulma-danger-s: 100%;
    --bulma-danger-l: 59%; /* hsl(3,100%,59%) ≈ #ff3b30 */
    --bulma-success-h: 134;
    --bulma-success-s: 61%;
    --bulma-success-l: 50%; /* hsl(134,61%,50%) ≈ #34c759 */
    --bulma-warning-h: 36;
    --bulma-warning-s: 100%;
    --bulma-warning-l: 50%; /* hsl(36,100%,50%) ≈ #ff9500 */
}

/* =========================================
   2. Base
   ========================================= */
*,
*::before,
*::after {
    box-sizing: border-box;
}

html {
    font-size: 16px;
    /* Desktop: background nền cho vùng ngoài app */
    background-color: #e5e7eb;
}

body {
    font-family:
        "Manrope",
        -apple-system,
        BlinkMacSystemFont,
        "Segoe UI",
        Roboto,
        Helvetica,
        Arial,
        sans-serif;
    background-color: var(--tg-theme-app-bg);
    color: var(--tg-theme-text-color);
    min-height: 100vh;
    padding-bottom: 90px; /* room for bottom-nav */

    /* Desktop: giới hạn chiều rộng như mobile */
    max-width: 430px;
    margin-inline: auto;
    /* Viền nhẹ khi nhìn trên desktop */
    box-shadow: 0 0 0 1px rgba(0,0,0,0.06), 0 4px 40px rgba(0,0,0,0.1);
    position: relative;
}

body.telegram-theme {
    background-color: var(--tg-theme-bg-color);
    color: var(--tg-theme-text-color);
}

/* =========================================
   3. Bulma Component Theming
      (không dùng !important — tăng specificity đúng cách)
   ========================================= */

/* --- Container --- */
.container.is-app {
    max-width: 100%;
    margin-inline: auto;
    padding: var(--space-md);
}

/* --- Box (thay thế .card cũ) --- */
.box {
    background: var(--tg-theme-bg-color);
    border-radius: var(--radius-xl);
    box-shadow: var(--surface-shadow);
    border: none;
    margin-bottom: var(--space-md);
    padding: var(--space-lg);
}

/* --- Buttons --- */
.button {
    font-family: inherit;
    font-weight: 600;
    border-radius: var(--radius-lg);
    transition: all 0.2s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}
.button:active {
    transform: scale(0.97);
}

/* --- Bulma Title sizes (thu nhỏ về scale ứng dụng) --- */
.title.is-1 {
    font-size: 28px;
}
.title.is-2 {
    font-size: 24px;
}
.title.is-3 {
    font-size: 20px;
}
.title.is-4 {
    font-size: 18px;
}
.title.is-5 {
    font-size: 16px;
}
.title.is-6 {
    font-size: 14px;
}
/* Bulma also resets margin on .title */
.title {
    color: var(--tg-theme-text-color);
}

.button.is-primary {
    background-color: var(--brand-color);
    border-color: transparent;
    color: #ffffff;
    box-shadow: 0 4px 14px rgba(0, 122, 255, 0.3);
}
.button.is-primary:hover,
.button.is-primary:focus {
    background-color: var(--brand-color-hover);
    color: #ffffff;
    border-color: transparent;
}

.button.is-danger {
    background-color: var(--danger-color);
    border-color: transparent;
    color: #ffffff;
}
.button.is-danger:hover {
    background-color: #e0352b;
    color: #ffffff;
}

.button.is-danger.is-outlined {
    background-color: transparent;
    border: 1.5px solid var(--danger-color);
    color: var(--danger-color);
}
.button.is-danger.is-outlined:hover {
    background-color: var(--danger-color);
    color: #ffffff;
}

.button.is-success {
    background-color: var(--success-color);
    border-color: transparent;
    color: #ffffff;
}

.button.is-light {
    background-color: var(--tg-theme-secondary-bg-color);
    border-color: transparent;
    color: var(--tg-theme-text-color);
}
.button.is-light:hover {
    filter: brightness(0.95);
}

/* --- Input / Select / Textarea --- */
.input,
.textarea,
.select select {
    font-family: inherit;
    background-color: var(--tg-theme-secondary-bg-color);
    border: 1.5px solid var(--tg-theme-secondary-bg-color);
    border-radius: var(--radius-lg);
    color: var(--tg-theme-text-color);
    font-size: 16px;
    padding: 12px var(--space-md);
    height: auto;
    transition: all 0.2s ease;
    box-shadow: none;
}
.input:focus,
.textarea:focus,
.select select:focus {
    background-color: var(--tg-theme-bg-color);
    border-color: var(--brand-color);
    box-shadow: 0 0 0 3px rgba(0, 122, 255, 0.15);
    outline: none;
}
.input::placeholder,
.textarea::placeholder {
    color: var(--tg-theme-hint-color);
}

/* Select wrapper — remove Bulma's default arrow styling interference */
.select:not(.is-multiple) {
    height: auto;
}
.select:not(.is-multiple)::after {
    border-color: var(--tg-theme-hint-color);
}

/* --- Label --- */
.label {
    color: var(--tg-theme-text-color);
    font-family: inherit;
    font-weight: 600;
    font-size: 14px;
}

/* --- Tag (badge) --- */
.tag {
    font-family: inherit;
    font-weight: 600;
    font-size: 12px;
    border-radius: var(--radius-md);
}
.tag.is-success {
    background-color: var(--success-bg);
    color: var(--success-color);
}
.tag.is-danger {
    background-color: var(--danger-bg);
    color: var(--danger-color);
}
.tag.is-warning {
    background-color: var(--warning-bg);
    color: var(--warning-color);
}
.tag.is-light {
    background-color: var(--tg-theme-secondary-bg-color);
    color: var(--tg-theme-text-color);
}

/* --- Notification --- */
.notification {
    border-radius: var(--radius-lg);
    font-family: inherit;
}
.notification.is-success.is-light {
    background: var(--success-bg);
    color: var(--success-color);
}
.notification.is-danger.is-light {
    background: var(--danger-bg);
    color: var(--danger-color);
}
.notification.is-warning.is-light {
    background: var(--warning-bg);
    color: var(--warning-color);
}
/* Solid variants */
.notification.is-success {
    background: var(--success-bg);
    color: var(--success-color);
    border: 1px solid rgba(52, 199, 89, 0.2);
}
.notification.is-danger {
    background: var(--danger-bg);
    color: var(--danger-color);
    border: 1px solid rgba(255, 59, 48, 0.2);
}
.notification.is-warning {
    background: var(--warning-bg);
    color: var(--warning-color);
    border: 1px solid rgba(255, 149, 0, 0.2);
}

/* =========================================
   4. App-specific Components
   ========================================= */

body.is-subpage {
    padding-bottom: 0;
}

/* --- Page Header --- */
.page-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: var(--space-lg);
    gap: var(--space-md);

    /* Sticky Header logic */
    position: sticky;
    top: 0;
    z-index: 100;
    background: var(--tg-theme-bg-color);
    /* Offset container padding to touch edges */
    margin-left: calc(var(--space-md) * -1);
    margin-right: calc(var(--space-md) * -1);
    margin-top: calc(var(--space-md) * -1);
    padding: var(--space-md);
    border-bottom: 1px solid var(--border-subtle);
}
.page-header .header-left {
    display: flex;
    align-items: center;
    gap: var(--space-sm);
    flex: 1;
    min-width: 0;
}

.btn-header-action {
    background: var(--brand-color);
    color: #fff;
    border: none;
    border-radius: var(--radius-md);
    padding: 6px 16px;
    font-size: 14px;
    font-weight: 700;
    cursor: pointer;
    transition: opacity 0.2s;
    white-space: nowrap;
}
.btn-header-action:active {
    opacity: 0.8;
}
.btn-header-action:disabled {
    background: var(--tg-theme-hint-color);
    cursor: not-allowed;
}

.page-header h1,
.page-header h2 {
    margin-bottom: 0;
}
.header-actions {
    display: flex;
    gap: var(--space-sm);
    flex-shrink: 0;
}

.btn-back {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 36px;
    height: 36px;
    border: none;
    background: var(--tg-theme-secondary-bg-color);
    border-radius: 50%;
    color: var(--tg-theme-text-color);
    cursor: pointer;
    font-size: 18px;
    transition: all 0.2s;
    line-height: 1;
    text-decoration: none;
}
.btn-back:active {
    transform: scale(0.9);
    background: rgba(0, 0, 0, 0.05);
}

/* --- Avatar --- */
.avatar {
    width: 40px;
    height: 40px;
    min-width: 40px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    color: #ffffff;
    font-weight: 600;
    font-size: 15px;
    flex-shrink: 0;
}
.avatar-sm {
    width: 32px;
    height: 32px;
    min-width: 32px;
    font-size: 13px;
}
.avatar-1 {
    background-color: #a78bfa;
}
.avatar-2 {
    background-color: #34d399;
}
.avatar-3 {
    background-color: #fb7185;
}
.avatar-4 {
    background-color: #fbbf24;
}
.avatar-5 {
    background-color: #60a5fa;
}

/* --- List cards --- */
.list-group {
    display: flex;
    flex-direction: column;
    gap: var(--space-sm);
}
.list-item {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: var(--space-md);
    background: var(--tg-theme-bg-color);
    border-radius: var(--radius-lg);
    border: 1px solid var(--border-subtle);
    text-decoration: none;
    color: inherit;
    transition: all 0.2s;
}
.list-item:hover,
.list-item:focus {
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.06);
    border-color: rgba(0, 122, 255, 0.2);
    color: inherit;
    text-decoration: none;
}

/* Status-based list item styles */
.list-item.is-pending {
    border-left: 4px solid var(--warning-color);
}
.list-item.is-completed {
    border-left: 4px solid var(--success-color);
    background-color: var(--tg-theme-bg-color);
    opacity: 0.85;
}
.list-item.is-completed .text-bold {
    color: var(--tg-theme-hint-color);
    text-decoration: line-through;
    text-decoration-thickness: 1px;
}
.list-item.is-completed .avatar {
    filter: grayscale(1) opacity(0.6);
}
.list-item.is-completed .tag.is-success {
    background-color: var(--success-color);
    color: #ffffff;
    font-size: 10px;
    padding: 0 8px;
    height: 20px;
    border-radius: 10px;
}

/* --- Amount input (bills/show) --- */
.amount-input-group {
    display: flex;
    align-items: center;
    gap: var(--space-sm);
}
.amount-input {
    width: 120px;
    text-align: right;
    font-weight: 700;
    font-size: 16px;
    border: none;
    background: transparent;
    padding: 0;
    color: var(--tg-theme-text-color);
}
.amount-input:focus {
    outline: none;
    border-bottom: 2px solid var(--brand-color);
}

/* =========================================
   5. Utilities
      (subset — Bulma handles most spacing/display)
   ========================================= */
.flex {
    display: flex;
}
.flex-col {
    flex-direction: column;
}
.items-center {
    align-items: center;
}
.justify-between {
    justify-content: space-between;
}
.justify-center {
    justify-content: center;
}
.gap-xs {
    gap: var(--space-xs);
}
.gap-sm {
    gap: var(--space-sm);
}
.gap-md {
    gap: var(--space-md);
}
.gap-lg {
    gap: var(--space-lg);
}

.mt-xs {
    margin-top: var(--space-xs);
}
.mt-sm {
    margin-top: var(--space-sm);
}
.mt-md {
    margin-top: var(--space-md);
}
.mt-lg {
    margin-top: var(--space-lg);
}
.mt-xl {
    margin-top: var(--space-xl);
}
.mb-0 {
    margin-bottom: 0;
}
.mb-xs {
    margin-bottom: var(--space-xs);
}
.mb-sm {
    margin-bottom: var(--space-sm);
}
.mb-md {
    margin-bottom: var(--space-md);
}
.mb-lg {
    margin-bottom: var(--space-lg);
}

.w-full {
    width: 100%;
}

.text-hint {
    color: var(--tg-theme-hint-color);
    font-size: 14px;
}
.text-danger {
    color: var(--danger-color);
}
.text-success {
    color: var(--success-color);
}
.text-warning {
    color: var(--warning-color);
}
.text-bold {
    font-weight: 600;
}
.text-xs {
    font-size: 12px;
}
.text-sm {
    font-size: 14px;
}
.text-md {
    font-size: 16px;
}
.text-lg {
    font-size: 20px;
    font-weight: 700;
}
.text-xl {
    font-size: 28px;
    font-weight: 700;
}

/* =========================================
   6. Toast Notifications
   ========================================= */
.toast-container {
    position: fixed;
    top: var(--space-md);
    right: var(--space-md);
    z-index: 9999;
    display: flex;
    flex-direction: column;
    gap: var(--space-xs);
    max-width: 380px;
}
.toast {
    background: var(--tg-theme-bg-color);
    border-left: 4px solid var(--brand-color);
    border-radius: var(--radius-lg);
    padding: var(--space-sm) var(--space-md);
    box-shadow: 0 8px 30px rgba(0, 0, 0, 0.15);
    display: flex;
    align-items: center;
    gap: var(--space-sm);
    animation: toastIn 0.4s ease;
}
.toast.toast-out {
    animation: toastOut 0.3s ease forwards;
}
@keyframes toastIn {
    from {
        transform: translateX(100px);
        opacity: 0;
    }
    to {
        transform: translateX(0);
        opacity: 1;
    }
}
@keyframes toastOut {
    from {
        transform: translateX(0);
        opacity: 1;
    }
    to {
        transform: translateX(100px);
        opacity: 0;
    }
}
.toast-icon {
    font-size: 20px;
    flex-shrink: 0;
}
.toast-text {
    font-size: 14px;
    font-weight: 600;
}

/* =========================================
   7. Bottom Navigation
   ========================================= */
.bottom-nav {
    position: fixed;
    bottom: 0;
    /* căn giữa và giới hạn bằng body max-width */
    left: 50%;
    transform: translateX(-50%);
    width: 100%;
    max-width: 430px;
    height: 72px;
    background: var(--tg-theme-bg-color);
    border-top: 1px solid var(--border-subtle);
    display: flex;
    justify-content: space-around;
    align-items: stretch;
    padding-bottom: env(safe-area-inset-bottom, 0px);
    z-index: 1000;
    overflow: visible;
}

/* Tất cả anchor trong bottom-nav: xoá padding/margin của Bulma */
.bottom-nav a.nav-item {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    width: 20%;
    height: 100%;
    color: var(--tg-theme-hint-color);
    text-decoration: none;
    padding: 6px 0 4px;
    margin: 0;
    gap: 3px;
    transition: color 0.2s;
    overflow: visible;
    line-height: 1;
}
.bottom-nav a.nav-item:hover,
.bottom-nav a.nav-item:focus {
    color: var(--tg-theme-hint-color);
    text-decoration: none;
}
.bottom-nav a.nav-item.active {
    color: var(--brand-color);
}

.nav-icon {
    font-size: 22px;
    line-height: 1;
    display: block;
    flex-shrink: 0;
}
.nav-label {
    display: block;
    font-size: 10px;
    font-weight: 500;
    line-height: 1;
    white-space: nowrap;
    flex-shrink: 0;
}

.nav-fab-container {
    position: relative;
    top: -18px;
    width: 20%;
    display: flex;
    align-items: flex-start;
    justify-content: center;
    overflow: visible;
    flex-shrink: 0;
}
.nav-fab {
    width: 58px;
    height: 58px;
    border-radius: 50%;
    background: var(--brand-color);
    color: #ffffff;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 28px;
    font-weight: 400;
    box-shadow: 0 4px 16px rgba(0, 122, 255, 0.35);
    text-decoration: none;
    transition: transform 0.2s;
    line-height: 1;
}
.nav-fab:hover {
    color: #ffffff;
    text-decoration: none;
}
/* --- Form Footer & Sticky Input --- */
.form-footer {
    margin-top: var(--space-xl);
    padding-bottom: var(--space-xl);
}

.sticky-input-wrap {
    background: var(--tg-theme-bg-color);
    transition: all 0.25s cubic-bezier(0.4, 0, 0.2, 1);
}

.sticky-input-wrap:focus-within {
    position: sticky;
    bottom: 0;
    padding: var(--space-md);
    background: var(--tg-theme-bg-color);
    border-top: 1px solid var(--border-subtle);
    box-shadow: 0 -8px 24px rgba(0, 0, 0, 0.08);
    z-index: 1000;
    margin-left: calc(var(--space-md) * -1);
    margin-right: calc(var(--space-md) * -1);
    margin-bottom: 0 !important;
}

.avatar-xs {
    width: 32px !important;
    height: 32px !important;
    min-width: 32px !important;
    min-height: 32px !important;
    font-size: 11px;
    flex-shrink: 0;
    aspect-ratio: 1/1;
    border-radius: 50%;
    object-fit: cover;
    display: flex;
    align-items: center;
    justify-content: center;
}

/* Fix large button font size */
.button.is-large {
    font-size: 1.15rem;
    font-weight: 700;
    height: 3.5rem;
}

/* ── Logout Button ── */
.btn-logout {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 34px;
    height: 34px;
    border-radius: 50%;
    background: var(--tg-theme-secondary-bg-color);
    border: none;
    color: var(--tg-theme-hint-color);
    font-size: 15px;
    cursor: pointer;
    transition: all 0.2s;
    flex-shrink: 0;
}
.btn-logout:hover {
    background: var(--danger-bg);
    color: var(--danger-color);
}
.btn-logout:active {
    transform: scale(0.9);
}

/* ── Global Sticky Header (các trang Tab) ── */
.global-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: var(--space-sm);
    position: sticky;
    top: 0;
    z-index: 200;
    background: var(--tg-theme-bg-color);
    margin-left: calc(var(--space-md) * -1);
    margin-right: calc(var(--space-md) * -1);
    padding: 10px var(--space-md);
    border-bottom: 1px solid var(--border-subtle);
    backdrop-filter: blur(8px);
    -webkit-backdrop-filter: blur(8px);
    margin-bottom: var(--space-md);
}

.global-header__left,
.global-header__right {
    display: flex;
    align-items: center;
    gap: var(--space-sm);
    min-width: 0;
}

.global-header__user-info {
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    line-height: 1.3;
    min-width: 0;
}

.global-header__greeting {
    font-size: 11px;
    color: var(--tg-theme-hint-color);
    white-space: nowrap;
}

.global-header__name {
    font-size: 13px;
    font-weight: 700;
    color: var(--tg-theme-text-color);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    max-width: 120px;
}

.global-header__avatar-wrap {
    display: flex;
    align-items: center;
}

.global-header__avatar {
    width: 38px;
    height: 38px;
    border-radius: 50%;
    object-fit: cover;
    border: 2px solid rgba(82, 136, 193, 0.25);
    flex-shrink: 0;
}

.global-header__avatar--fallback {
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--tg-theme-secondary-bg-color);
    color: var(--tg-theme-hint-color);
    font-size: 22px;
    border: none;
}
