/* ===== Hộp Thư Thời Gian — Lời nhắn gửi tương lai ===== */
.fm-page {
    position: relative;
    overflow: hidden;
    font-family: 'Quicksand', sans-serif;
    color: #4a3f3a;
}

/* --- Nền trang trí chuyển động --- */
.fm-bg { position: absolute; inset: 0; z-index: 0; pointer-events: none; overflow: hidden; }
.fm-blob {
    position: absolute;
    border-radius: 50%;
    filter: blur(60px);
    opacity: 0.55;
    animation: fmDrift 18s ease-in-out infinite;
}
.fm-blob-1 { width: 320px; height: 320px; background: #fad0c4; top: -80px; left: -60px; }
.fm-blob-2 { width: 260px; height: 260px; background: #ffe1c4; bottom: -60px; right: -40px; animation-delay: -6s; }
.fm-blob-3 { width: 220px; height: 220px; background: #f7c9d9; top: 40%; left: 55%; animation-delay: -11s; opacity: 0.4; }

@keyframes fmDrift {
    0%, 100% { transform: translate(0, 0) scale(1); }
    33% { transform: translate(30px, -24px) scale(1.08); }
    66% { transform: translate(-22px, 18px) scale(0.96); }
}

.fm-wrap {
    position: relative;
    z-index: 1;
    width: 92%;
    max-width: 1080px;
    margin: 0 auto;
    padding: 46px 0 70px;
}

/* --- Hero --- */
.fm-hero {
    text-align: center;
    margin-bottom: 34px;
    animation: fmFadeUp 0.8s cubic-bezier(0.22, 1, 0.36, 1) both;
}
.fm-eyebrow {
    display: inline-block;
    font-size: 12px;
    font-weight: 700;
    letter-spacing: 4px;
    text-transform: uppercase;
    color: #c08a64;
    padding-bottom: 4px;
}
.fm-title {
    font-family: Georgia, 'Times New Roman', serif;
    font-weight: 600;
    font-size: 2.6rem;
    line-height: 1.25;
    color: #3d332e;
    margin: 12px 0 16px;
    letter-spacing: 0.3px;
}
.fm-lead {
    max-width: 600px;
    margin: 0 auto;
    color: #8a7468;
    font-size: 1rem;
    line-height: 1.8;
}
.fm-divider {
    display: block;
    width: 0;
    height: 2px;
    margin: 22px auto 0;
    background: linear-gradient(90deg, transparent, #e0b896, transparent);
    animation: fmGrow 1.2s 0.5s cubic-bezier(0.22, 1, 0.36, 1) forwards;
}
@keyframes fmGrow { to { width: 120px; } }

/* --- Grid --- */
.fm-grid {
    display: grid;
    grid-template-columns: 1.55fr 1fr;
    gap: 24px;
    align-items: start;
}
@media (max-width: 880px) { .fm-grid { grid-template-columns: 1fr; } }

.fm-card {
    background: rgba(255, 255, 255, 0.78);
    backdrop-filter: blur(16px);
    -webkit-backdrop-filter: blur(16px);
    border-radius: 24px;
    border: 1px solid rgba(255, 255, 255, 0.8);
    box-shadow: 0 16px 48px rgba(196, 154, 120, 0.22);
    padding: 28px;
    animation: fmFadeUp 0.8s cubic-bezier(0.22, 1, 0.36, 1) both;
}
.fm-compose { animation-delay: 0.12s; }
.fm-list { animation-delay: 0.22s; }

.fm-card-title {
    font-family: Georgia, 'Times New Roman', serif;
    font-size: 1.3rem;
    font-weight: 600;
    color: #3d332e;
    margin: 0 0 20px;
    padding-bottom: 14px;
    position: relative;
}
.fm-card-title::after {
    content: '';
    position: absolute;
    left: 0; bottom: 0;
    width: 42px; height: 2px;
    background: #e0b896;
}

/* --- Fields --- */
.fm-field { display: flex; flex-direction: column; gap: 7px; margin-bottom: 18px; }
.fm-field > span, .fm-field-label { font-size: 0.82rem; font-weight: 700; color: #6e5c52; letter-spacing: 0.2px; }
.fm-field i, .fm-field-label i { color: #d8896a; font-style: normal; }
.fm-field-row { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
@media (max-width: 520px) { .fm-field-row { grid-template-columns: 1fr; } }

.fm-input {
    padding: 13px 15px;
    border-radius: 14px;
    border: 1.5px solid #efe1d6;
    background: rgba(255, 253, 251, 0.9);
    font-family: inherit;
    font-size: 0.95rem;
    color: #4a3f3a;
    outline: none;
    transition: border-color 0.3s, box-shadow 0.3s, transform 0.2s;
}
.fm-input:focus {
    border-color: #e0b896;
    box-shadow: 0 0 0 4px rgba(224, 184, 150, 0.18);
    background: #fff;
}

/* --- Quill editor --- */
#fm-editor { height: 240px; background: rgba(255, 253, 251, 0.9); border-radius: 0 0 16px 16px; font-size: 1rem; }
.ql-toolbar.ql-snow {
    border: 1.5px solid #efe1d6 !important;
    border-bottom: none !important;
    border-radius: 16px 16px 0 0;
    background: #faf1e9;
}
.ql-container.ql-snow { border: 1.5px solid #efe1d6 !important; border-radius: 0 0 16px 16px; font-family: 'Quicksand', sans-serif; }
.ql-editor { line-height: 1.8; color: #4a3f3a; }
.ql-editor.ql-blank::before { color: #b7a294; font-style: normal; }
.ql-snow .ql-stroke { stroke: #8a7468; }
.ql-snow .ql-fill { fill: #8a7468; }
.ql-snow.ql-toolbar button:hover .ql-stroke { stroke: #c08a64; }
.ql-snow.ql-toolbar button.ql-active .ql-stroke { stroke: #d8896a; }
.ql-snow.ql-toolbar button.ql-active .ql-fill { fill: #d8896a; }
.ql-snow .ql-picker { color: #8a7468; }

/* --- Presets --- */
.fm-presets { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 6px; }
.fm-preset {
    font-family: inherit;
    font-size: 0.82rem;
    font-weight: 600;
    color: #8a6a5a;
    background: #faf1e9;
    border: 1.5px solid #efe1d6;
    border-radius: 999px;
    padding: 8px 16px;
    cursor: pointer;
    transition: all 0.25s cubic-bezier(0.22, 1, 0.36, 1);
}
.fm-preset:hover { border-color: #e0b896; background: #fbe9dc; transform: translateY(-2px); box-shadow: 0 6px 16px rgba(224, 184, 150, 0.3); }
.fm-preset.active { border-color: #d8896a; background: linear-gradient(135deg, #fdeee4, #fbe0d2); color: #c0603e; }

.fm-hint { font-size: 0.78rem; color: #a7948a; margin-top: 3px; }

/* --- Mẫu thư gợi ý --- */
.fm-templates { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 6px; }
.fm-template {
    font-family: inherit;
    font-size: 0.82rem;
    font-weight: 600;
    color: #8a6a5a;
    background: #faf1e9;
    border: 1.5px dashed #e6cdb8;
    border-radius: 999px;
    padding: 8px 16px;
    cursor: pointer;
    transition: all 0.25s cubic-bezier(0.22, 1, 0.36, 1);
}
.fm-template:hover { border-style: solid; border-color: #e0b896; background: #fbe9dc; transform: translateY(-2px); box-shadow: 0 6px 16px rgba(224, 184, 150, 0.3); }

/* --- Chân trình soạn thảo: đếm ký tự + nút AI --- */
.fm-editor-foot {
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-wrap: wrap;
    gap: 10px;
    margin-top: 8px;
}
.fm-counter { font-size: 0.78rem; color: #a7948a; font-variant-numeric: tabular-nums; }
.fm-counter-over { color: #c25640; font-weight: 700; }

.fm-ai-btn {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    font-family: inherit;
    font-size: 0.84rem;
    font-weight: 700;
    color: #9a5fae;
    background: linear-gradient(135deg, #f6ecfb, #fbe9f3);
    border: 1.5px solid #e8d0f0;
    border-radius: 999px;
    padding: 9px 16px;
    cursor: pointer;
    transition: all 0.25s cubic-bezier(0.22, 1, 0.36, 1);
}
.fm-ai-btn:hover { transform: translateY(-2px); border-color: #d9b3e8; box-shadow: 0 8px 20px rgba(154, 95, 174, 0.25); }
.fm-ai-btn:disabled { opacity: 0.6; cursor: not-allowed; transform: none; box-shadow: none; }

.fm-cost-note {
    background: #faf1e9;
    border: 1.5px solid #efe1d6;
    border-radius: 14px;
    padding: 12px 16px;
    font-size: 0.88rem;
    color: #8a6a5a;
    text-align: center;
    margin-bottom: 16px;
}
.fm-cost-note strong { color: #c0603e; }
.fm-cost-sep { color: #d9c2b7; margin: 0 5px; }

/* --- Button --- */
.fm-btn {
    position: relative;
    overflow: hidden;
    width: 100%;
    padding: 15px 22px;
    border-radius: 999px;
    font-family: inherit;
    font-size: 1.02rem;
    font-weight: 700;
    border: none;
    cursor: pointer;
    transition: transform 0.25s, box-shadow 0.25s;
}
.fm-btn-primary {
    background: linear-gradient(135deg, #f3b69a 0%, #e89b7c 100%);
    color: #fff;
    box-shadow: 0 10px 26px rgba(214, 137, 106, 0.45);
}
.fm-btn-primary:hover { transform: translateY(-3px); box-shadow: 0 16px 32px rgba(214, 137, 106, 0.55); }
.fm-btn-primary:active { transform: translateY(-1px); }
.fm-btn-primary:disabled { opacity: 0.6; cursor: not-allowed; transform: none; box-shadow: none; }
.fm-btn-label { position: relative; z-index: 1; }
/* hiệu ứng ánh sáng quét qua nút */
.fm-btn-primary::before {
    content: '';
    position: absolute;
    top: 0; left: -120%;
    width: 60%; height: 100%;
    background: linear-gradient(120deg, transparent, rgba(255, 255, 255, 0.5), transparent);
    transform: skewX(-20deg);
}
.fm-btn-primary:hover::before { animation: fmShine 0.9s ease; }
@keyframes fmShine { to { left: 140%; } }

/* --- Guest banner --- */
.fm-guest {
    margin-bottom: 16px;
    padding: 13px 16px;
    border-radius: 14px;
    background: linear-gradient(135deg, #fdeee4, #fbe0d2);
    border: 1.5px solid #f0cdb6;
    color: #9a6a4f;
    font-size: 0.9rem;
    line-height: 1.6;
    text-align: center;
}
.fm-guest a { color: #c0603e; font-weight: 800; text-decoration: underline; }

/* --- Alert --- */
.fm-alert {
    margin-bottom: 16px;
    padding: 13px 16px;
    border-radius: 14px;
    font-size: 0.9rem;
    line-height: 1.55;
    text-align: center;
    font-weight: 600;
    animation: fmFadeUp 0.4s ease both;
}
.fm-alert-ok { background: #ecf7ef; color: #3a8a5e; border: 1.5px solid #bfe6cc; }
.fm-alert-err { background: #fdeeea; color: #c25640; border: 1.5px solid #f4cabb; }

/* --- List --- */
.fm-empty { color: #a7948a; text-align: center; padding: 30px 12px; line-height: 1.7; }
.fm-item {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 15px 16px;
    border: 1.5px solid #f0e4da;
    border-radius: 16px;
    background: rgba(255, 255, 255, 0.7);
    margin-bottom: 12px;
    transition: transform 0.25s, box-shadow 0.25s, border-color 0.25s;
    animation: fmFadeUp 0.5s cubic-bezier(0.22, 1, 0.36, 1) both;
}
.fm-item:hover { transform: translateY(-2px); border-color: #e8d3c2; box-shadow: 0 8px 20px rgba(196, 154, 120, 0.2); }
.fm-item-main { flex: 1; min-width: 0; }
.fm-item-subject { font-weight: 700; color: #3d332e; margin-bottom: 6px; word-break: break-word; }
.fm-item-meta { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; font-size: 0.82rem; }
.fm-item-to { color: #8a7468; }
.fm-item-time { font-size: 0.8rem; color: #a7948a; margin-top: 4px; }

.fm-status {
    display: inline-block;
    padding: 3px 11px;
    border-radius: 999px;
    font-size: 0.74rem;
    font-weight: 700;
    letter-spacing: 0.3px;
}
.fm-status-pending { background: #fcf2dd; color: #b9851f; }
.fm-status-pending::after { content: 'Đang chờ'; }
.fm-status-sending { background: #e9f0fb; color: #4a73c7; }
.fm-status-sending::after { content: 'Đang gửi'; }
.fm-status-sent { background: #ecf7ef; color: #3a8a5e; }
.fm-status-sent::after { content: 'Đã gửi'; }
.fm-status-failed { background: #fdeeea; color: #c0392b; }
.fm-status-failed::after { content: 'Gửi lỗi'; }
.fm-status-cancelled { background: #f1ece8; color: #8a7468; }
.fm-status-cancelled::after { content: 'Đã huỷ'; }

.fm-cancel {
    flex-shrink: 0;
    background: #fdeeea;
    border: 1.5px solid #f4cabb;
    color: #c25640;
    padding: 8px 14px;
    border-radius: 12px;
    cursor: pointer;
    font-family: inherit;
    font-size: 0.82rem;
    font-weight: 700;
    transition: all 0.2s;
}
.fm-cancel:hover { background: #c25640; color: #fff; border-color: #c25640; }

/* --- Entrance --- */
@keyframes fmFadeUp {
    from { opacity: 0; transform: translateY(18px); }
    to { opacity: 1; transform: translateY(0); }
}

@media (max-width: 880px) {
    .fm-grid { gap: 18px; }
}

@media (max-width: 600px) {
    /* main đã có padding 10px hai bên trên mobile -> wrap dùng full chiều ngang */
    .fm-wrap { width: 100%; padding: 18px 0 44px; }

    .fm-hero { margin-bottom: 22px; }
    .fm-eyebrow { letter-spacing: 2.5px; font-size: 11px; }
    .fm-title { font-size: 1.75rem; line-height: 1.3; margin: 10px 0 12px; }
    .fm-lead { font-size: 0.92rem; line-height: 1.7; }
    .fm-divider { margin-top: 16px; }

    .fm-grid { gap: 14px; }
    .fm-card { padding: 18px 15px; border-radius: 20px; }
    .fm-card-title { font-size: 1.15rem; margin-bottom: 16px; padding-bottom: 12px; }

    /* font-size >= 16px để iOS không tự phóng to khi focus */
    .fm-input { font-size: 16px; padding: 12px 14px; }
    .fm-field { margin-bottom: 15px; }

    #fm-editor { height: 200px; }

    .fm-editor-foot { gap: 8px; }
    .fm-ai-btn { flex: 1 1 100%; justify-content: center; order: 2; padding: 11px 16px; }
    .fm-counter { order: 1; }

    .fm-cost-note { padding: 11px 14px; font-size: 0.85rem; }
    .fm-btn { font-size: 0.98rem; padding: 14px 18px; }

    .fm-item { padding: 13px 14px; gap: 10px; }
}

@media (max-width: 380px) {
    .fm-title { font-size: 1.55rem; }
    .fm-card { padding: 16px 13px; }
}

@media (prefers-reduced-motion: reduce) {
    .fm-hero, .fm-card, .fm-item, .fm-alert, .fm-blob, .fm-divider { animation: none !important; }
    .fm-divider { width: 120px; }
    .fm-btn-primary:hover::before { animation: none; }
}
