/* styles.css - 共用樣式 */

:root {
    /* ===== Black 系列 ===== */
    --Black-500: #141314;
    --Black: #000000;
    --White: #FFFFFF;
    --bg: #FCFCFC;
    --announcements: #F8EFE4;
    --neutral-800: #242424;

    /* ===== Blue 系列 ===== */
    --Blue-100-bg: # #E5E9EE;
    --Blue-500-Primary: #17324F;
    --Blue-650-Deep: #1B3044;
    --Blue-purchase-check: #022D5A;

    /* ===== Yellow/Orange 系列 ===== */
    --Yellow-500: #CB6F00;

    /* ===== Grays 系列 ===== */
    --Gray-100: #F8F8F8;
    --Gray-200: #FAFAFD;
    --Gray-300: #E6E6E6;
    --Gray-400: #C4C4C4;
    --Gray-500: #D6D6D6;
    --Gray-600: #A5A5A5;
    --Gray-700: #555555;
    --Gray-800: #383538;
    --Gray-900: #222222;

    /* ===== Red 系列 ===== */
    --Red-600: #FC5555;
}

/* ===== Typography ===== */
/* Body Text / Medium */
.text-body-medium {
    font-family: 'Inter', sans-serif;
    font-style: normal;
    font-weight: 500;
    font-size: 14px;
    line-height: 17px;
}

/* 基本樣式 */
html {
    /* 防止 iOS 自動調整文字尺寸導致聚焦時放大 */
    -webkit-text-size-adjust: 100%;
    text-size-adjust: 100%;
}

body {
    background-color: var(--bg);
    font-family: 'Inter', 'Noto Sans TC', sans-serif;
    -webkit-tap-highlight-color: transparent;
    touch-action: pan-x pan-y;
    /* 禁止雙擊放大，只允許滾動 */
}

/* 禁止整個 PWA 縮放和雙擊放大 */
* {
    touch-action: pan-x pan-y;
    -webkit-touch-callout: none;
    -webkit-user-select: none;
    user-select: text;
}

.font-serif {
    font-family: 'Playfair Display', serif;
}

/* 頁面進入動畫 */
.page {
    animation: fadeIn 0.3s ease-in-out;
}

@keyframes fadeIn {
    from {
        opacity: 0;
    }

    to {
        opacity: 1;
    }
}

/* 隱藏滾動條但保留功能 */
.scrollbar-hide::-webkit-scrollbar {
    display: none;
}

.scrollbar-hide {
    -ms-overflow-style: none;
    scrollbar-width: none;
}

/* 表單字級統一：至少 16px，避免 iOS 聚焦放大 */

input[type="text"],
input[type="password"],
input[type="number"],
input[type="tel"],
input[type="search"],
input[type="date"],
textarea,
select {
    font-size: max(16px, 1em) !important;
}

/* 防止 date input 在 iPhone 上超出容器 */
input[type="date"] {
    max-width: 100%;
    box-sizing: border-box;
    -webkit-appearance: none;
    -moz-appearance: none;
    appearance: none;
    min-height: 38px;
    /* 防止空值時變扁 */
}

/* ===== API Toast 通知 ===== */
.api-toast {
    position: fixed;
    bottom: 100px;
    left: 50%;
    transform: translateX(-50%) translateY(20px);
    padding: 14px 24px;
    border-radius: 16px;
    font-size: 14px;
    font-weight: 500;
    z-index: 10000;
    opacity: 0;
    transition: all 0.4s cubic-bezier(0.34, 1.56, 0.64, 1);
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.12), 0 2px 8px rgba(0, 0, 0, 0.08);
    display: flex;
    align-items: center;
    gap: 10px;
    backdrop-filter: blur(8px);
    -webkit-backdrop-filter: blur(8px);
}

.api-toast.show {
    opacity: 1;
    transform: translateX(-50%) translateY(0);
}

.api-toast-success {
    background: linear-gradient(135deg, rgba(16, 185, 129, 0.95) 0%, rgba(5, 150, 105, 0.95) 100%);
    color: white;
    border: 1px solid rgba(255, 255, 255, 0.2);
}

.api-toast-error {
    background: linear-gradient(135deg, rgba(239, 68, 68, 0.95) 0%, rgba(220, 38, 38, 0.95) 100%);
    color: white;
    border: 1px solid rgba(255, 255, 255, 0.2);
}

.api-toast-info {
    background: linear-gradient(135deg, rgba(13, 45, 116, 0.95) 0%, rgba(30, 64, 175, 0.95) 100%);
    color: white;
    border: 1px solid rgba(255, 255, 255, 0.15);
}

/* Toast 圖標與文字 */
.toast-icon {
    width: 18px;
    height: 18px;
    flex-shrink: 0;
}

.toast-message {
    letter-spacing: 0.3px;
}

/* 載入中旋轉動畫 */
.toast-spinner {
    width: 20px;
    height: 20px;
    position: relative;
    flex-shrink: 0;
}

.spinner-ring {
    width: 100%;
    height: 100%;
    border-radius: 50%;
    border: 2.5px solid rgba(255, 255, 255, 0.3);
    border-top-color: white;
    animation: spinner-rotate 0.9s cubic-bezier(0.5, 0.1, 0.5, 0.9) infinite;
    box-shadow: 0 0 12px rgba(255, 255, 255, 0.3);
}

@keyframes spinner-rotate {
    0% {
        transform: rotate(0deg);
    }

    100% {
        transform: rotate(360deg);
    }
}

/* 載入中脈衝光暈效果 */
.api-toast-info::before {
    content: '';
    position: absolute;
    inset: -1px;
    border-radius: 17px;
    background: linear-gradient(135deg, rgba(59, 130, 246, 0.5), rgba(147, 51, 234, 0.5));
    z-index: -1;
    animation: toast-pulse 2s ease-in-out infinite;
}

@keyframes toast-pulse {

    0%,
    100% {
        opacity: 0.5;
        transform: scale(1);
    }

    50% {
        opacity: 0.8;
        transform: scale(1.02);
    }
}

/* ===== 按鈕 Loading 狀態 ===== */
button:disabled {
    opacity: 0.6;
    cursor: not-allowed;
}

.api-loading {
    display: inline-block;
    width: 16px;
    height: 16px;
    border: 2px solid currentColor;
    border-top-color: transparent;
    border-radius: 50%;
    animation: api-spin 0.8s linear infinite;
}

@keyframes api-spin {
    to {
        transform: rotate(360deg);
    }
}

/* ===== 警告 Toast ===== */
.api-toast-warning {
    background: linear-gradient(135deg, rgba(245, 158, 11, 0.95) 0%, rgba(217, 119, 6, 0.95) 100%);
    color: white;
    border: 1px solid rgba(255, 255, 255, 0.2);
}

/* ===== 全頁 Loading Overlay ===== */
.loading-overlay {
    position: fixed;
    inset: 0;
    background: rgba(255, 255, 255, 0.85);
    backdrop-filter: blur(4px);
    -webkit-backdrop-filter: blur(4px);
    z-index: 9999;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 16px;
    opacity: 0;
    visibility: hidden;
    transition: opacity 0.3s ease, visibility 0.3s ease;
}

.loading-overlay.show {
    opacity: 1;
    visibility: visible;
}

.loading-overlay-spinner {
    width: 48px;
    height: 48px;
    border-radius: 50%;
    border: 4px solid #e5e7eb;
    border-top-color: #0D2D74;
    animation: api-spin 0.9s cubic-bezier(0.5, 0.1, 0.5, 0.9) infinite;
}

.loading-overlay-text {
    font-size: 14px;
    color: #6b7280;
    font-weight: 500;
}

/* ===== 統一按鈕 Loading 狀態 ===== */
.btn-loading {
    position: relative;
    pointer-events: none;
}

.btn-loading::after {
    content: '';
    position: absolute;
    width: 16px;
    height: 16px;
    top: 50%;
    left: 50%;
    margin-top: -8px;
    margin-left: -8px;
    border: 2px solid currentColor;
    border-top-color: transparent;
    border-radius: 50%;
    animation: api-spin 0.8s linear infinite;
}

.btn-loading>* {
    visibility: hidden;
}

/* ===== 確認對話框 ===== */
.confirm-dialog-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.5);
    backdrop-filter: blur(4px);
    -webkit-backdrop-filter: blur(4px);
    z-index: 10001;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 20px;
    opacity: 0;
    visibility: hidden;
    transition: opacity 0.2s ease, visibility 0.2s ease;
}

.confirm-dialog-overlay.show {
    opacity: 1;
    visibility: visible;
}

.confirm-dialog {
    background: white;
    border-radius: 16px;
    padding: 24px;
    max-width: 320px;
    width: 100%;
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.15);
    transform: scale(0.95);
    transition: transform 0.2s ease;
}

.confirm-dialog-overlay.show .confirm-dialog {
    transform: scale(1);
}

.confirm-dialog-title {
    font-size: 18px;
    font-weight: 600;
    color: #18181b;
    margin-bottom: 8px;
}

.confirm-dialog-message {
    font-size: 14px;
    color: #71717a;
    margin-bottom: 20px;
    line-height: 1.5;
}

.confirm-dialog-actions {
    display: flex;
    gap: 12px;
    justify-content: flex-end;
}

.confirm-dialog-btn {
    padding: 10px 20px;
    border-radius: 10px;
    font-size: 14px;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s ease;
    border: none;
}

.confirm-dialog-btn-cancel {
    background: #f4f4f5;
    color: #71717a;
}

.confirm-dialog-btn-cancel:hover {
    background: #e4e4e7;
}

.confirm-dialog-btn-confirm {
    background: #0D2D74;
    color: white;
}

.confirm-dialog-btn-confirm:hover {
    background: #0a2460;
}

.confirm-dialog-btn-danger {
    background: #ef4444;
    color: white;
}

.confirm-dialog-btn-danger:hover {
    background: #dc2626;
}

/* ===== Alert 對話框圖標 ===== */
.alert-dialog {
    text-align: center;
}

.alert-dialog .confirm-dialog-title {
    margin-top: 8px;
}

.alert-icon {
    width: 56px;
    height: 56px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    margin: 0 auto 8px;
}

.alert-icon svg {
    width: 28px;
    height: 28px;
}

.alert-icon-success {
    background: linear-gradient(135deg, #d1fae5 0%, #a7f3d0 100%);
    color: #059669;
}

.alert-icon-error {
    background: linear-gradient(135deg, #fee2e2 0%, #fecaca 100%);
    color: #dc2626;
}

.alert-icon-warning {
    background: linear-gradient(135deg, #fef3c7 0%, #fde68a 100%);
    color: #d97706;
}

.alert-icon-info {
    background: linear-gradient(135deg, #dbeafe 0%, #bfdbfe 100%);
    color: #2563eb;
}

/* ===== 公告區塊 ===== */
.announcement-section {
    margin: 0 20px 16px;
    border-radius: 12px;
    overflow: hidden;
    background-color: var(--announcements, #FFF8E7);
}

.announcement-list {
    max-height: 113px;
    overflow-y: auto;
    scroll-snap-type: y mandatory;
    scroll-behavior: smooth;
    scrollbar-width: none;
    -ms-overflow-style: none;
}

.announcement-list::-webkit-scrollbar {
    display: none;
}

.announcement-item {
    padding: 16px;
    min-height: 113px;
    box-sizing: border-box;
    scroll-snap-align: start;
    background-color: var(--announcements, #FFF8E7);
    position: relative;
}

.announcement-item:not(:last-child) {
    border-bottom: 4px solid var(--bg, #F5F5F5);
}

.announcement-header {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-bottom: 6px;
}

.announcement-tag {
    flex-shrink: 0;
    padding: 2px 8px;
    border-radius: 99px;
    font-size: 11px;
    font-weight: 700;
    color: var(--White);
    background-color: var(--Yellow-500);
}

.announcement-title {
    font-size: 14px;
    font-weight: 700;
    color: var(--Yellow-500);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.announcement-desc {
    font-size: 12px;
    line-height: 1.6;
    color: var(--Gray-700);
    display: -webkit-box;
    -webkit-line-clamp: 2;
    line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
    padding-bottom: 20px;
}

.announcement-date {
    font-size: 11px;
    color: var(--Gray-500);
    position: absolute;
    bottom: 11px;
    left: 16px;
}

/* ===== Avatar ===== */
.avatar {
    width: 30px;
    height: 30px;
    border-radius: 50%;
    overflow: hidden;
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--White);
    font-weight: 600;
    font-size: 12px;
    border: 2px solid var(--White);
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
}

/* 載入中與空狀態 */
.loading-skeleton {
    height: 68px;
    background-color: var(--White);
    border-radius: 12px;
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--Gray-400);
    font-size: 14px;
    width: 100%;
    animation: pulse 1.5s infinite;
}

.empty-state {
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 40px 20px;
    width: 100%;
    text-align: center;
}

/* ===== 確認 Modal（刪除、取消等確認對話框）===== */
.confirm-modal {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.5);
    z-index: 1000;
    align-items: center;
    justify-content: center;
}

.confirm-modal.show {
    display: flex;
}

.confirm-modal-content {
    background: var(--White);
    border-radius: 16px;
    padding: 24px;
    width: calc(100% - 48px);
    max-width: 320px;
    text-align: center;
    transform: scale(0.9);
    transition: transform 0.3s;
}

.confirm-modal.show .confirm-modal-content {
    transform: scale(1);
}

.confirm-modal-title {
    font-size: 18px;
    font-weight: 600;
    color: var(--Gray-900);
    margin-bottom: 8px;
}

.confirm-modal-desc {
    font-size: 14px;
    color: var(--Gray-500);
    margin-bottom: 24px;
}

.confirm-modal-actions {
    display: flex;
    gap: 12px;
}

.confirm-modal-btn {
    flex: 1;
    padding: 12px 16px;
    font-size: 15px;
    font-weight: 500;
    border-radius: 24px;
    cursor: pointer;
    transition: all 0.2s;
}

.confirm-modal-btn.cancel {
    background: var(--White);
    color: var(--Gray-700);
    border: 1px solid var(--Gray-300);
}

.confirm-modal-btn.confirm,
.confirm-modal-btn.delete {
    background: var(--Blue-500-Primary);
    color: var(--White);
    border: none;
}

.confirm-modal-btn:hover {
    opacity: 0.9;
}

/* ===== 共用 Modal 樣式（新增/編輯表單）===== */
.modal-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.5);
    display: none;
    align-items: flex-end;
    justify-content: center;
    z-index: 1000;
}

.modal-overlay.show {
    display: flex;
}

.modal-content {
    background: var(--White);
    width: 100%;
    max-width: 430px;
    border-radius: 20px 20px 0 0;
    max-height: 90vh;
    overflow-y: auto;
    transform: translateY(100%);
    transition: transform 0.3s ease-out;
}

.modal-body {
    padding: 20px 24px;
}

.modal-overlay.show .modal-content {
    transform: translateY(0);
}

@keyframes modalSlideUp {
    from {
        transform: translateY(100%);
    }

    to {
        transform: translateY(0);
    }
}

.modal-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 16px 24px;
    border-bottom: 1px solid var(--Gray-300);
    flex-shrink: 0;
}

.modal-back-btn {
    width: 36px;
    height: 36px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    border-radius: 50%;
    color: var(--Gray-600);
    transition: background 0.2s;
    margin-left: -8px;
}

.modal-back-btn:hover {
    background: var(--Gray-100);
}

.modal-title {
    font-size: 16px;
    font-weight: 700;
    color: var(--Black-500);
}

.modal-spacer {
    width: 36px;
}

/* ===== 共用表單樣式 ===== */
.form-group {
    margin-bottom: 16px;
}

.form-label {
    display: block;
    font-size: 14px;
    font-weight: 500;
    color: var(--Gray-700);
    margin-bottom: 8px;
}

.form-label .required {
    color: #EF4444;
    margin-left: 2px;
}

.form-input,
.form-select,
.form-textarea {
    width: 100%;
    padding: 12px 16px;
    border: 1px solid var(--Gray-300);
    border-radius: 10px;
    font-size: 16px;
    color: var(--Gray-900);
    outline: none;
    background: var(--White);
    transition: border-color 0.2s;
    box-sizing: border-box;
}

.form-input:focus,
.form-select:focus,
.form-textarea:focus {
    border-color: var(--Blue-500-Primary);
}

.form-input::placeholder,
.form-textarea::placeholder {
    color: var(--Gray-400);
}

.form-textarea {
    min-height: 120px;
    resize: vertical;
}

/* ===== 共用按鈕樣式 ===== */
.submit-btn {
    width: 100%;
    padding: 14px;
    background: var(--Blue-500-Primary);
    color: var(--White);
    font-size: 16px;
    font-weight: 600;
    border: none;
    border-radius: 12px;
    cursor: pointer;
    margin-top: 24px;
}

.submit-btn:hover {
    opacity: 0.9;
}

/* 固定底部按鈕容器 - 常駐畫面底部 */

.add-btn-container {
    position: fixed;
    bottom: 0;
    left: 50%;
    transform: translateX(-50%);
    width: 100%;
    max-width: 430px;
    padding: 16px 20px;
    padding-bottom: calc(16px + env(safe-area-inset-bottom));
    background: var(--White);
    z-index: 40;
    box-sizing: border-box;
}

.add-btn {
    width: 100%;
    padding: 14px;
    background: var(--Blue-500-Primary);
    color: var(--White);
    font-size: 16px;
    font-weight: 600;
    border: none;
    border-radius: 12px;
    cursor: pointer;
}

.add-btn:hover {
    opacity: 0.9;
}

/* ===== 設定頁面共用 Header ===== */
.settings-header,
.page-header {
    display: flex;
    align-items: center;
    padding: 16px 20px;
    background: var(--White);
    position: sticky;
    top: 0;
    z-index: 100;
}

.back-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 32px;
    height: 32px;
    cursor: pointer;
}

.header-title {
    flex: 1;
    text-align: center;
    font-size: 18px;
    font-weight: 600;
    color: var(--Gray-900);
    margin-right: 32px;
}

/* ===== Tab 按鈕樣式 ===== */
.tabs-container {
    display: flex;
    gap: 8px;
    padding: 0 20px 16px;
    background: var(--White);
}

.tab-btn {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    padding: 8px 16px;
    border-radius: 9999px;
    font-size: 13px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s;
    border: 1px solid transparent;
}

.tab-btn.active {
    background-color: var(--Blue-500-Primary);
    color: #FFFFFF;
    box-shadow: 0 2px 8px rgba(23, 50, 79, 0.3);
}

.tab-btn:not(.active) {
    background-color: var(--White);
    color: #64748b;
    border: 1px solid var(--Gray-300);
}

/* ===== Purchase Check 樣式 ===== */
.purchase-check {
    width: 14px;
    height: 14px;
    flex-shrink: 0;
    color: var(--Gray-400);
    background: rgba(2, 45, 90, 0.1);
    padding: 3px;
    border-radius: 4px;
}

.purchase-check.checked,
.purchase-item.completed .purchase-check {
    color: var(--Blue-purchase-check);
    background: rgba(2, 45, 90, 0.1);
}

/* ===== Checkbox Group 樣式 ===== */
.checkbox-group {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-top: 16px;
    cursor: pointer;
}

.checkbox-group .check-icon {
    width: 20px;
    height: 20px;
    flex-shrink: 0;
    color: var(--Gray-400);
    background: rgba(2, 45, 90, 0.1);
    padding: 3px;
    border-radius: 4px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.checkbox-group .check-icon.checked {
    color: var(--Blue-purchase-check);
}

.checkbox-group label {
    font-size: 14px;
    color: var(--Gray-700);
    cursor: pointer;
}

/* 隱藏 Number Input 的 Spin Buttons */
input[type=number]::-webkit-inner-spin-button,
input[type=number]::-webkit-outer-spin-button {
    -webkit-appearance: none;
    appearance: none;
    margin: 0;
}

input[type=number] {
    -moz-appearance: textfield;
    appearance: textfield;
}