/* ==========================================
   Travel Spend v2 — 設計系統
   ========================================== */

:root {
    --primary: #2563eb;
    --secondary: #7c3aed;
    --gradient: linear-gradient(135deg, #2563eb 0%, #7c3aed 100%);
    --success: #10b981;
    --warning: #f59e0b;
    --danger: #ef4444;
    --bg: #f0f4ff;
    --card: #ffffff;
    --text: #1e293b;
    --muted: #64748b;
    --border: #e2e8f0;
    --radius: 16px;
    --shadow: 0 2px 16px rgba(37, 99, 235, 0.08);
    --shadow-lg: 0 8px 32px rgba(37, 99, 235, 0.14);
}

/* ── 基礎 ── */
* { margin: 0; padding: 0; box-sizing: border-box; }

body {
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
    background: var(--bg);
    color: var(--text);
    font-size: 15px;
    line-height: 1.6;
    -webkit-font-smoothing: antialiased;
}

.container {
    max-width: 480px;
    margin: 0 auto;
    padding: 0 16px 88px;
}

/* ── 頁面頂部漸層 Header ── */
.page-header {
    background: var(--gradient);
    color: white;
    padding: 24px 20px 32px;
    margin: 0 -16px 20px;
    position: relative;
    overflow: hidden;
}

.page-header::after {
    content: '';
    position: absolute;
    bottom: -1px;
    left: 0;
    right: 0;
    height: 20px;
    background: var(--bg);
    border-radius: 20px 20px 0 0;
}

.page-header h1 {
    font-size: 22px;
    font-weight: 700;
    letter-spacing: -0.3px;
    position: relative;
    z-index: 1;
    margin: 0;
    text-align: left;
}

.page-header .subtitle {
    font-size: 13px;
    opacity: 0.85;
    margin-top: 4px;
    position: relative;
    z-index: 1;
}

/* ── 卡片 ── */
.card {
    background: var(--card);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    padding: 20px;
    margin-bottom: 16px;
}

/* ── 按鈕 ── */
.btn {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    width: 100%;
    min-height: 48px;
    border-radius: 12px;
    font-size: 15px;
    font-weight: 600;
    border: none;
    cursor: pointer;
    text-decoration: none;
    transition: transform 0.15s, box-shadow 0.15s, opacity 0.15s;
    padding: 0 20px;
}

.btn:active { transform: scale(0.97); }

.btn-primary {
    background: var(--gradient);
    color: white;
    box-shadow: 0 4px 12px rgba(37, 99, 235, 0.3);
}

.btn-primary:hover { box-shadow: 0 6px 16px rgba(37, 99, 235, 0.4); }

.btn-secondary {
    background: #eff6ff;
    color: var(--primary);
}

.btn-secondary:hover { background: #dbeafe; }

.btn-danger {
    background: #fef2f2;
    color: var(--danger);
}

.btn-danger:hover { background: #fee2e2; }

.btn-sm {
    min-height: 36px;
    font-size: 13px;
    border-radius: 8px;
    padding: 0 14px;
    width: auto;
    display: inline-flex;
}

button {
    font-family: inherit;
    cursor: pointer;
}

/* ── 徽章 ── */
.badge {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    padding: 3px 10px;
    border-radius: 20px;
    font-size: 12px;
    font-weight: 600;
    white-space: nowrap;
}

.badge-open    { background: #dcfce7; color: #16a34a; }
.badge-closed  { background: #fee2e2; color: #dc2626; }
.badge-edit-open  { background: #dbeafe; color: #2563eb; }
.badge-edit-add   { background: #fef3c7; color: #d97706; }
.badge-edit-view  { background: #fee2e2; color: #dc2626; }

/* ── 狀態通知欄 ── */
.status-bar {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 10px 16px;
    border-radius: 10px;
    font-size: 13px;
    font-weight: 500;
    margin-bottom: 16px;
}

.status-bar.open    { background: #dcfce7; color: #16a34a; }
.status-bar.warning { background: #fef3c7; color: #d97706; }

/* ── 時間軸 ── */
.timeline { padding: 4px 0; }

.timeline-item {
    display: flex;
    gap: 14px;
    padding-bottom: 20px;
    position: relative;
}

.timeline-item:not(:last-child)::before {
    content: '';
    position: absolute;
    left: 7px;
    top: 16px;
    bottom: 0;
    width: 2px;
    background: var(--border);
}

.timeline-dot {
    width: 16px;
    height: 16px;
    border-radius: 50%;
    background: var(--gradient);
    flex-shrink: 0;
    margin-top: 2px;
    box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.15);
}

.timeline-content { flex: 1; min-width: 0; }

.timeline-row {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    gap: 8px;
}

.timeline-desc {
    font-size: 15px;
    font-weight: 600;
    color: var(--text);
    flex: 1;
    min-width: 0;
    word-break: break-word;
}

.timeline-amount {
    font-size: 15px;
    font-weight: 700;
    white-space: nowrap;
    flex-shrink: 0;
}

.timeline-amount.twd     { color: var(--success); }
.timeline-amount.foreign { color: var(--warning); }

.timeline-meta {
    font-size: 12px;
    color: var(--muted);
    margin-top: 3px;
}

.timeline-actions {
    display: flex;
    gap: 6px;
    margin-top: 6px;
}

.timeline-btn {
    background: none;
    border: 1px solid var(--border);
    padding: 4px 10px;
    border-radius: 8px;
    font-size: 12px;
    cursor: pointer;
    color: var(--muted);
    transition: all 0.15s;
    min-height: 30px;
}

.timeline-btn:hover { background: var(--border); color: var(--text); }
.timeline-btn.danger { color: var(--danger); border-color: #fecaca; }
.timeline-btn.danger:hover { background: #fef2f2; }

/* ── 表單元素 ── */
.form-group { margin-bottom: 16px; }

.form-label {
    display: block;
    font-size: 12px;
    font-weight: 700;
    color: var(--muted);
    margin-bottom: 6px;
    text-transform: uppercase;
    letter-spacing: 0.6px;
}

input[type="text"],
input[type="number"],
input[type="date"],
select,
textarea {
    width: 100%;
    padding: 12px 14px;
    border: 1.5px solid var(--border);
    border-radius: 10px;
    font-size: 15px;
    background: white;
    color: var(--text);
    font-family: inherit;
    transition: border-color 0.2s, box-shadow 0.2s;
    appearance: none;
    -webkit-appearance: none;
}

input:focus,
select:focus,
textarea:focus {
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.12);
    outline: none;
}

select {
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='8' viewBox='0 0 12 8'%3E%3Cpath fill='%2364748b' d='M1 1l5 5 5-5'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 14px center;
    padding-right: 36px;
}

/* ── 複選框 ── */
.checkbox-group {
    background: #f8fafc;
    border: 1.5px solid var(--border);
    border-radius: 12px;
    padding: 12px;
    margin-bottom: 16px;
}

.checkbox-label {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 8px 10px;
    border-radius: 8px;
    cursor: pointer;
    font-size: 15px;
    transition: background 0.15s;
}

.checkbox-label:hover { background: #eff6ff; }

.checkbox-label input[type="checkbox"] {
    width: 20px;
    height: 20px;
    accent-color: var(--primary);
    flex-shrink: 0;
    border-radius: 4px;
    cursor: pointer;
    margin: 0;
    padding: 0;
    border: none;
    box-shadow: none;
}

/* ── 行程卡片 ── */
.trip-card {
    background: var(--card);
    border-radius: var(--radius);
    overflow: hidden;
    box-shadow: var(--shadow);
    margin-bottom: 16px;
    transition: transform 0.2s, box-shadow 0.2s;
}

.trip-card:hover {
    transform: translateY(-2px);
    box-shadow: var(--shadow-lg);
}

.trip-card-header {
    background: var(--gradient);
    padding: 20px;
    color: white;
    display: flex;
    align-items: flex-start;
    gap: 14px;
}

.trip-icon { font-size: 32px; line-height: 1; flex-shrink: 0; }

.trip-title { font-size: 18px; font-weight: 700; line-height: 1.3; }

.trip-date-text { font-size: 12px; opacity: 0.8; margin-top: 3px; }

.trip-card-body { padding: 16px 20px 20px; }

.trip-stats-row {
    display: flex;
    gap: 10px;
    flex-wrap: wrap;
    align-items: center;
    margin-bottom: 14px;
}

.trip-stat {
    display: flex;
    align-items: center;
    gap: 4px;
    font-size: 13px;
    color: var(--muted);
}

/* 新增旅程卡 */
.new-trip-card {
    background: var(--card);
    border-radius: var(--radius);
    padding: 20px;
    margin-bottom: 20px;
    box-shadow: var(--shadow);
    border: 2px dashed var(--border);
}

.new-trip-title {
    font-size: 14px;
    font-weight: 600;
    color: var(--muted);
    margin-bottom: 12px;
    display: flex;
    align-items: center;
    gap: 6px;
}

/* ── 匯率 Modal（bottom sheet）── */
.modal {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.45);
    z-index: 2000;
    align-items: flex-end;
}

.modal.active { display: flex; }

.modal-sheet {
    background: white;
    width: 100%;
    border-radius: 24px 24px 0 0;
    padding: 0 20px 32px;
    animation: slideUp 0.3s ease-out;
    max-height: 80vh;
    overflow-y: auto;
}

.modal-handle {
    width: 40px;
    height: 4px;
    background: var(--border);
    border-radius: 2px;
    margin: 16px auto 20px;
}

.modal-title {
    font-size: 17px;
    font-weight: 700;
    color: var(--text);
    margin-bottom: 20px;
}

@keyframes slideUp {
    from { transform: translateY(100%); opacity: 0; }
    to   { transform: translateY(0);    opacity: 1; }
}

/* 匯率行 */
.rate-row {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 12px;
    background: #f8fafc;
    border-radius: 10px;
    margin-bottom: 10px;
}

.rate-row label { flex: 1; font-size: 14px; color: var(--text); }

.rate-input {
    width: 110px !important;
    padding: 8px 12px !important;
    font-size: 14px !important;
    border-radius: 8px !important;
}

.rate-unit { font-size: 13px; color: var(--muted); white-space: nowrap; }

.modal-buttons {
    display: flex;
    gap: 10px;
    margin-top: 20px;
}

.modal-save {
    flex: 1;
    min-height: 44px;
    background: var(--gradient);
    color: white;
    border: none;
    border-radius: 10px;
    font-size: 15px;
    font-weight: 600;
    cursor: pointer;
    transition: opacity 0.2s;
}

.modal-save:hover { opacity: 0.9; }

.modal-cancel {
    flex: 1;
    min-height: 44px;
    background: #f1f5f9;
    color: var(--muted);
    border: none;
    border-radius: 10px;
    font-size: 15px;
    font-weight: 600;
    cursor: pointer;
}

/* ── 底部導覽列 ── */
.bottom-nav {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    display: flex;
    height: 64px;
    background: white;
    border-top: 1px solid var(--border);
    box-shadow: 0 -4px 20px rgba(0, 0, 0, 0.06);
    z-index: 1000;
    padding-bottom: env(safe-area-inset-bottom);
}

.nav-item {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    text-decoration: none;
    color: var(--muted);
    font-size: 11px;
    font-weight: 500;
    gap: 3px;
    transition: color 0.2s;
    position: relative;
    padding-bottom: 2px;
}

.nav-item.active { color: var(--primary); }

.nav-item.active::before {
    content: '';
    position: absolute;
    top: 0;
    left: 20%;
    right: 20%;
    height: 3px;
    background: var(--gradient);
    border-radius: 0 0 4px 4px;
}

.nav-icon { font-size: 22px; line-height: 1; }
.nav-label { line-height: 1; }

/* ── FAB ── */
.fab {
    position: fixed;
    bottom: 80px;
    right: 20px;
    width: 56px;
    height: 56px;
    border-radius: 50%;
    background: var(--gradient);
    color: white;
    font-size: 28px;
    font-weight: 300;
    border: none;
    cursor: pointer;
    box-shadow: 0 4px 16px rgba(37, 99, 235, 0.45);
    display: flex;
    align-items: center;
    justify-content: center;
    text-decoration: none;
    z-index: 999;
    transition: transform 0.15s, box-shadow 0.2s;
    line-height: 1;
}

.fab:hover { box-shadow: 0 6px 20px rgba(37, 99, 235, 0.55); transform: scale(1.05); }
.fab:active { transform: scale(0.92); }

/* ── Section 標題 ── */
.section-title {
    font-size: 12px;
    font-weight: 700;
    color: var(--muted);
    text-transform: uppercase;
    letter-spacing: 0.8px;
    margin-bottom: 14px;
}

/* ── List items ── */
.list { margin-top: 8px; }

.list-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 12px 0;
    border-bottom: 1px solid var(--border);
    gap: 8px;
}

.list-item:last-child { border-bottom: none; }

/* ── 空狀態 ── */
.empty-state {
    text-align: center;
    padding: 48px 24px;
    color: var(--muted);
}

.empty-icon { font-size: 48px; margin-bottom: 12px; }

.empty-title { font-size: 16px; font-weight: 600; margin-bottom: 6px; }

.empty-desc { font-size: 14px; }

/* ── 分享代碼 ── */
.access-code-display {
    margin-top: 12px;
    padding: 10px 14px;
    background: #f0f4ff;
    border-radius: 10px;
    text-align: center;
    font-size: 13px;
    color: var(--muted);
    cursor: pointer;
    transition: background 0.15s;
    border: 1.5px dashed #c7d7f8;
}

.access-code-display:hover { background: #dbeafe; }

.access-code-display strong {
    font-family: monospace;
    font-size: 15px;
    color: var(--primary);
    font-weight: 700;
    letter-spacing: 1px;
}

/* ── 錯誤訊息 ── */
.error-message {
    background: #fef2f2;
    border: 1.5px solid #fecaca;
    border-radius: 10px;
    color: var(--danger);
    padding: 12px 16px;
    margin-bottom: 16px;
    font-size: 14px;
    display: flex;
    align-items: center;
    gap: 8px;
}

/* ── inline edit 修正 ── */
.form-controls {
    display: flex;
    gap: 5px;
    flex-wrap: wrap;
    align-items: center;
}

/* ── toggle 按鈕（設定頁） ── */
.toggle-btn {
    min-height: 40px;
    padding: 0 16px;
    border: 2px solid var(--border);
    border-radius: 10px;
    cursor: pointer;
    font-size: 14px;
    font-weight: 600;
    font-family: inherit;
    background: white;
    color: var(--muted);
    transition: all 0.2s;
}

.toggle-btn.on {
    background: var(--gradient);
    color: white;
    border-color: transparent;
    box-shadow: 0 2px 8px rgba(37, 99, 235, 0.3);
}

.toggle-btn:hover:not(.on) { border-color: var(--primary); color: var(--primary); }

.permission-buttons {
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
    margin-top: 10px;
}

.viewable-toggle {
    background: var(--card);
    border-radius: var(--radius);
    padding: 16px 20px;
    margin-bottom: 16px;
    box-shadow: var(--shadow);
}

.viewable-toggle h3 {
    font-size: 14px;
    color: var(--muted);
    text-transform: uppercase;
    letter-spacing: 0.6px;
    margin-bottom: 8px;
}

.viewable-toggle p {
    font-size: 14px;
    color: var(--text);
    margin-bottom: 10px;
}

/* ── 小按鈕（inline 編輯用）── */
.save-btn {
    min-height: 36px;
    padding: 0 12px;
    background: var(--success);
    color: white;
    border: none;
    border-radius: 8px;
    font-size: 13px;
    font-weight: 600;
    cursor: pointer;
    transition: opacity 0.15s;
}

.save-btn:hover { opacity: 0.85; }

.cancel-btn {
    min-height: 36px;
    padding: 0 12px;
    background: #f1f5f9;
    color: var(--muted);
    border: none;
    border-radius: 8px;
    font-size: 13px;
    font-weight: 600;
    cursor: pointer;
}

.delete-btn {
    min-height: 36px;
    padding: 0 12px;
    background: #fef2f2;
    color: var(--danger);
    border: none;
    border-radius: 8px;
    font-size: 13px;
    font-weight: 600;
    cursor: pointer;
    transition: background 0.15s;
}

.delete-btn:hover { background: #fee2e2; }

/* ── edit hint ── */
.edit-hint {
    font-size: 12px;
    color: var(--muted);
    background: #f8fafc;
    border-radius: 8px;
    padding: 8px 12px;
    margin-bottom: 12px;
    border: 1px dashed var(--border);
}

/* ── inline 編輯表單 ── */
.edit-rate-form,
.edit-name-form,
.edit-currency-form { display: none; }

.rate-display,
.name-display,
.currency-display {
    cursor: pointer;
    padding: 4px 8px;
    border-radius: 6px;
    transition: background 0.15s;
    font-size: 14px;
}

.rate-display:hover,
.name-display:hover,
.currency-display:hover { background: #eff6ff; color: var(--primary); }

.rate-input, .name-input, .currency-input {
    padding: 6px 10px !important;
    font-size: 14px !important;
    border-radius: 6px !important;
    width: auto !important;
    min-width: 80px;
}

/* ── 回首頁連結（設定頁） ── */
.back-link {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    color: rgba(255,255,255,0.85);
    font-size: 13px;
    text-decoration: none;
    margin-bottom: 8px;
}

/* ── 提示文字 ── */
.hint-text {
    font-size: 13px;
    color: var(--primary);
    padding: 8px 12px;
    background: #eff6ff;
    border-radius: 8px;
    margin-bottom: 8px;
    border-left: 3px solid var(--primary);
}

/* ── 響應式 ── */
@media (max-width: 768px) {
    .menu-grid { grid-template-columns: 1fr; }
    .trips-grid { grid-template-columns: 1fr; }
}

@media (min-width: 481px) {
    .container { padding: 0 24px 96px; }
    .page-header { margin: 0 -24px 20px; padding: 28px 24px 36px; }
}

@media (prefers-reduced-motion: reduce) {
    * { animation: none !important; transition: none !important; }
}
