/*
 * iOS-style Todo UI for Filament
 * 對應設計文件: docs/design/todos-ios-ui-design.md
 */

:root {
    --tios-blue: #007AFF;
    --tios-blue-hover: #0056CC;
    --tios-blue-tint: rgba(0, 122, 255, 0.08);
    --tios-blue-ring: rgba(0, 122, 255, 0.20);
    --tios-red: #FF3B30;
    --tios-orange: #FF9500;
    --tios-green: #34C759;
    --tios-gray: #8E8E93;
    --tios-secondary: #3c3c4399;
    --tios-page-bg: #f5f5f7;
    --tios-text: #1d1d1f;
    --tios-meta: #6b7280;
}

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

.todos-ios {
    font-family: system-ui, -apple-system, "PingFang TC", "Microsoft JhengHei", sans-serif;
    color: var(--tios-text);
    max-width: 980px;
    margin: 0 auto;
    padding-bottom: 80px;
}

/* ─── 工具列(顯示已完成 toggle + 天數 filter) ───────────────── */
.todos-ios__toolbar {
    display: flex;
    justify-content: flex-end;
    align-items: center;
    gap: 12px;
    margin-bottom: 12px;
    flex-wrap: wrap;
}

/* 天數範圍 pill 群組 */
.todos-ios__days-filter {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    padding: 3px;
    background: #fff;
    border: 1px solid #e5e7eb;
    border-radius: 999px;
}
.todos-ios__days-pill {
    padding: 4px 12px;
    border-radius: 999px;
    background: transparent;
    border: none;
    color: #475569;
    font-size: 12px;
    font-weight: 500;
    cursor: pointer;
    transition: all .15s ease;
}
.todos-ios__days-pill:hover { background: #f1f5f9; color: var(--tios-blue); }
.todos-ios__days-pill.is-active {
    background: var(--tios-blue);
    color: #fff;
}
.dark .todos-ios__days-filter {
    background: rgb(31, 41, 55);
    border-color: rgb(55, 65, 81);
}
.dark .todos-ios__days-pill { color: #cbd5e1; }
.dark .todos-ios__days-pill:hover { background: rgb(55, 65, 81); color: #60a5fa; }
.dark .todos-ios__days-pill.is-active { background: var(--tios-blue); color: #fff; }

.todos-ios__toggle {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 6px 14px;
    border-radius: 999px;
    background: #fff;
    border: 1px solid #e5e7eb;
    color: #475569;
    font-size: 13px;
    font-weight: 500;
    cursor: pointer;
    transition: all .15s ease;
}
.todos-ios__toggle:hover { background: #f8fafc; border-color: #cbd5e1; }
.todos-ios__toggle.is-on {
    background: var(--tios-blue-tint);
    border-color: rgba(0, 122, 255, .3);
    color: var(--tios-blue);
}
.todos-ios__toggle-icon { width: 16px; height: 16px; }

/* ─── 部門 Tab pills ────────────────────────────────────────── */
.todos-ios__tabs {
    display: flex;
    gap: 8px;
    margin-bottom: 16px;
    overflow-x: auto;
    overflow-y: hidden;
    scroll-snap-type: x mandatory;
    -webkit-overflow-scrolling: touch;
    padding-bottom: 4px;
}
.todos-ios__tabs::-webkit-scrollbar { height: 0; }

.todos-ios__tab {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 6px 14px;
    border-radius: 999px;
    background: transparent;
    border: 1px solid #d1d1d6;
    color: var(--tios-secondary);
    font-size: 14px;
    font-weight: 500;
    white-space: nowrap;
    cursor: pointer;
    scroll-snap-align: start;
    transition: all .15s ease;
}
.todos-ios__tab:hover {
    background: var(--tios-blue-tint);
    border-color: rgba(0, 122, 255, .3);
    color: var(--tios-blue);
}
.todos-ios__tab.is-active {
    background: rgba(0, 122, 255, .12);
    border-color: var(--tios-blue);
    color: var(--tios-blue);
}
.todos-ios__tab-count {
    display: inline-block;
    min-width: 22px;
    text-align: center;
    padding: 1px 7px;
    border-radius: 999px;
    background: #f1f5f9;
    color: #475569;
    font-size: 11px;
    font-weight: 600;
}
.todos-ios__tab.is-active .todos-ios__tab-count {
    background: rgba(0, 122, 255, .18);
    color: var(--tios-blue);
}

/* ─── Quick Add ────────────────────────────────────────────── */
.todos-ios__quickadd {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 10px 14px;
    background: #fff;
    border: 1px solid #e5e7eb;
    border-radius: 14px;
    margin-bottom: 14px;
    transition: all .15s ease;
}
.todos-ios__quickadd:focus-within {
    border-color: var(--tios-blue);
    box-shadow: 0 0 0 4px var(--tios-blue-ring);
}
.todos-ios__quickadd-icon {
    width: 22px; height: 22px;
    color: var(--tios-blue);
    flex-shrink: 0;
}
.todos-ios__quickadd-input {
    flex: 1;
    border: none;
    background: transparent;
    outline: none;
    font-size: 15px;
    color: var(--tios-text);
    padding: 4px 0;
    min-width: 0;
}
.todos-ios__quickadd-input::placeholder { color: #9ca3af; }
.todos-ios__quickadd-chip {
    border: 1px solid #e5e7eb;
    background: #f9fafb;
    border-radius: 999px;
    padding: 4px 10px;
    font-size: 13px;
    color: var(--tios-text);
    cursor: pointer;
    outline: none;
    transition: all .15s ease;
}
.todos-ios__quickadd-chip:hover { background: #f1f5f9; border-color: #cbd5e1; }
.todos-ios__quickadd-chip:focus { border-color: var(--tios-blue); }

/* 「全部」tab 時的提示版 Quick Add(不可輸入) */
.todos-ios__quickadd--disabled {
    background: #f8fafc;
    border-style: dashed;
    border-color: #cbd5e1;
    cursor: default;
}
.todos-ios__quickadd--disabled:focus-within { box-shadow: none; border-color: #cbd5e1; }
.todos-ios__quickadd-icon--muted { color: #94a3b8; }
.todos-ios__quickadd-hint {
    font-size: 14px;
    color: #64748b;
    flex: 1;
}
.dark .todos-ios__quickadd--disabled {
    background: rgba(31, 41, 55, .5);
    border-color: rgb(55, 65, 81);
}
.dark .todos-ios__quickadd-hint { color: #94a3b8; }

/* ─── 月份分隔(只在「顯示已完成」模式出現) ─────────────────── */
.todos-ios__month-header {
    display: flex;
    align-items: baseline;
    justify-content: space-between;
    padding: 14px 4px 6px;
    margin-top: 8px;
    border-bottom: 1px solid #e5e7eb;
    font-family: system-ui, -apple-system, sans-serif;
}
.todos-ios__month-header:first-child { margin-top: 0; padding-top: 0; }
.todos-ios__month-label {
    font-size: 13px;
    font-weight: 700;
    color: #475569;
    letter-spacing: .02em;
}
.todos-ios__month-count {
    font-size: 12px;
    color: #94a3b8;
}
.dark .todos-ios__month-header { border-color: rgb(55, 65, 81); }
.dark .todos-ios__month-label { color: #cbd5e1; }
.dark .todos-ios__month-count { color: #64748b; }

/* ─── 載入更多 / 清單結束 ────────────────────────────────── */
.todos-ios__load-more {
    display: block;
    width: 100%;
    margin-top: 12px;
    padding: 12px 16px;
    background: #fff;
    border: 1px dashed #cbd5e1;
    border-radius: 12px;
    color: var(--tios-blue);
    font-size: 13px;
    font-weight: 500;
    cursor: pointer;
    transition: all .15s ease;
}
.todos-ios__load-more:hover:not(:disabled) {
    background: var(--tios-blue-tint);
    border-color: var(--tios-blue);
    border-style: solid;
}
.todos-ios__load-more:disabled { cursor: not-allowed; opacity: .6; }
.todos-ios__list-end {
    text-align: center;
    padding: 16px;
    font-size: 12px;
    color: #94a3b8;
}
.dark .todos-ios__load-more {
    background: rgb(31, 41, 55);
    border-color: rgb(55, 65, 81);
    color: #60a5fa;
}
.dark .todos-ios__load-more:hover:not(:disabled) {
    background: rgba(0, 122, 255, .12);
    border-color: var(--tios-blue);
}
.dark .todos-ios__list-end { color: #64748b; }

/* ─── 卡片 ──────────────────────────────────────────────── */
.todos-ios__list {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.todos-ios__card {
    display: flex;
    align-items: flex-start;
    gap: 12px;
    background: #fff;
    border: 1px solid #e5e7eb;
    border-radius: 16px;
    padding: 14px 16px;
    box-shadow: 0 1px 2px rgba(0, 0, 0, .04);
    transition: box-shadow .15s ease, transform .15s ease, opacity .25s ease;
    position: relative;
}
.todos-ios__card:hover {
    box-shadow: 0 6px 16px rgba(0, 0, 0, .08);
    transform: translateY(-1px);
}
/* 已完成卡:淡出 + 略微右移,標題改用 background-image 模擬劃線(可動畫) */
.todos-ios__card.is-completed {
    opacity: .55;
    transform: translateX(4px);
}
.todos-ios__card.is-completed .todos-ios__title,
.todos-ios__card.is-completed .is-completed-text {
    color: var(--tios-gray);
}

/* 完成圓圈打勾的彈跳動畫(spring) */
@keyframes tios-check-pop {
    0%   { transform: scale(0); opacity: 0; }
    50%  { transform: scale(1.18); opacity: 1; }
    100% { transform: scale(1); opacity: 1; }
}
.todos-ios__check-checked {
    animation: tios-check-pop .28s cubic-bezier(0.34, 1.56, 0.64, 1) both;
}

/* 標題劃線從左到右掃出來 — 用 background-image 取代 text-decoration */
@keyframes tios-strikethrough-sweep {
    from { background-size: 0% 1.5px; }
    to   { background-size: 100% 1.5px; }
}
.todos-ios__card.is-completed .todos-ios__title {
    background-image: linear-gradient(currentColor, currentColor);
    background-repeat: no-repeat;
    background-position: 0 60%;
    background-size: 100% 1.5px;
    animation: tios-strikethrough-sweep .28s ease-out both;
}

/* 完成圓圈 */
.todos-ios__check {
    flex-shrink: 0;
    width: 26px; height: 26px;
    margin-top: 1px;
    background: none;
    border: none;
    cursor: pointer;
    padding: 0;
    display: flex; align-items: center; justify-content: center;
}
.todos-ios__check:disabled { cursor: not-allowed; opacity: .5; }
.todos-ios__check-circle {
    display: block;
    width: 22px; height: 22px;
    border: 2px solid #cbd5e1;
    border-radius: 50%;
    transition: all .15s ease;
}
.todos-ios__check:hover:not(:disabled) .todos-ios__check-circle {
    border-color: var(--tios-blue);
    background: var(--tios-blue-tint);
}
.todos-ios__check-checked {
    width: 24px; height: 24px;
    color: var(--tios-blue);
}

/* 主要內容 */
.todos-ios__main {
    flex: 1;
    min-width: 0;
}

.todos-ios__title-row {
    display: flex;
    align-items: center;
    gap: 8px;
}

.todos-ios__dot {
    flex-shrink: 0;
    width: 10px; height: 10px;
    border-radius: 50%;
    display: inline-block;
}
.todos-ios__dot--high   { background: var(--tios-red); }
.todos-ios__dot--medium { background: var(--tios-orange); }
.todos-ios__dot--low    { background: var(--tios-green); }

/* Inline 編輯標題 */
.todos-ios__title-wrap {
    flex: 1;
    min-width: 0;
}
.todos-ios__title {
    display: inline-block;
    font-size: 15px;
    font-weight: 600;
    color: var(--tios-text);
    line-height: 1.4;
    cursor: text;
    word-break: break-word;
    padding: 2px 4px;
    margin-left: -4px;
    border-radius: 4px;
}
.todos-ios__title:hover { background: #f5f5f7; }
.todos-ios__title-input {
    display: block;
    width: 100%;
    font-size: 15px;
    font-weight: 600;
    color: var(--tios-text);
    background: #f5f5f7;
    border: 1px solid var(--tios-blue);
    border-radius: 6px;
    padding: 4px 8px;
    margin: -5px -8px;
    outline: none;
    font-family: inherit;
}
.todos-ios__title-input:focus { box-shadow: 0 0 0 3px var(--tios-blue-ring); }

/* 描述 */
.todos-ios__description {
    font-size: 13px;
    color: var(--tios-meta);
    margin: 6px 0 0;
    line-height: 1.45;
    word-break: break-word;
}

/* meta 行 */
.todos-ios__meta {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 6px 12px;
    margin-top: 8px;
    font-size: 12px;
    color: var(--tios-meta);
}
.todos-ios__meta-item {
    display: inline-flex;
    align-items: center;
    gap: 4px;
}
.todos-ios__meta-item.is-overdue {
    color: var(--tios-red);
    font-weight: 600;
}
.todos-ios__meta-item.is-duesoon {
    color: var(--tios-orange);
    font-weight: 600;
}
.todos-ios__meta-icon {
    width: 13px; height: 13px;
    flex-shrink: 0;
}

/* 徽章 */
.todos-ios__badge-wrap {
    position: relative;
}
.todos-ios__badge {
    display: inline-flex;
    align-items: center;
    padding: 2px 10px;
    border-radius: 999px;
    font-size: 11px;
    font-weight: 500;
    color: #fff;
    border: none;
    cursor: pointer;
    transition: filter .15s ease;
}
.todos-ios__badge:hover:not(:disabled) { filter: brightness(.92); }
.todos-ios__badge:disabled { cursor: default; }

.todos-ios__badge--priority-high   { background: var(--tios-red); }
.todos-ios__badge--priority-medium { background: var(--tios-orange); }
.todos-ios__badge--priority-low    { background: var(--tios-green); }

.todos-ios__badge--status-pending     { background: var(--tios-gray); }
.todos-ios__badge--status-in_progress { background: var(--tios-blue); }
.todos-ios__badge--status-completed   { background: var(--tios-green); }

/* Popover */
.todos-ios__popover {
    position: absolute;
    top: calc(100% + 6px);
    left: 0;
    z-index: 50;
    min-width: 140px;
    background: #fff;
    border: 1px solid #e5e7eb;
    border-radius: 10px;
    box-shadow: 0 8px 24px rgba(0, 0, 0, .12);
    padding: 4px;
    display: flex;
    flex-direction: column;
}
.todos-ios__popover-item {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 6px 10px;
    background: none;
    border: none;
    text-align: left;
    color: var(--tios-text);
    font-size: 13px;
    cursor: pointer;
    border-radius: 6px;
}
.todos-ios__popover-item:hover { background: #f5f5f7; }
.todos-ios__popover-check {
    width: 14px; height: 14px;
    color: var(--tios-blue);
    margin-left: auto;
}

/* 右側動作 */
.todos-ios__actions {
    display: flex;
    gap: 4px;
    align-items: center;
    flex-shrink: 0;
    opacity: 0;
    transition: opacity .15s ease;
}
.todos-ios__card:hover .todos-ios__actions,
.todos-ios__card:focus-within .todos-ios__actions { opacity: 1; }

.todos-ios__icon-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 30px; height: 30px;
    border-radius: 8px;
    background: transparent;
    border: none;
    color: var(--tios-gray);
    cursor: pointer;
    transition: all .15s ease;
}
.todos-ios__icon-btn:hover {
    background: #f1f5f9;
    color: var(--tios-blue);
}
.todos-ios__icon-btn--danger:hover {
    background: #fef2f2;
    color: var(--tios-red);
}
.todos-ios__icon { width: 18px; height: 18px; }

/* ─── 拖曳排序 ────────────────────────────────────────── */

/* 拖把:預設 cursor grab,按下變 grabbing */
.todos-ios__drag-handle {
    cursor: grab;
    color: #94a3b8;
    touch-action: none; /* 手機:阻止瀏覽器把長按變成 scroll/selection */
}
.todos-ios__drag-handle:hover { color: var(--tios-blue); background: #f1f5f9; }
.todos-ios__drag-handle:active { cursor: grabbing; }
.dark .todos-ios__drag-handle { color: #64748b; }
.dark .todos-ios__drag-handle:hover { color: #60a5fa; background: rgb(55, 65, 81); }

/* 拖曳中:被拖那張的「原位佔位卡」(SortableJS 預設樣式) */
.todos-ios__card--ghost {
    opacity: .35;
    background: var(--tios-blue-tint);
    border-color: var(--tios-blue);
    border-style: dashed;
}
.todos-ios__card--ghost > * { opacity: 0; }

/* 拖曳中:被選中(剛按下)那張的樣式 */
.todos-ios__card--chosen {
    box-shadow: 0 12px 32px rgba(0, 122, 255, .25),
                0 4px 12px rgba(0, 0, 0, .08);
    transform: scale(1.01);
    border-color: var(--tios-blue);
    z-index: 10;
}

/* 拖曳中:正在移動的卡 */
.todos-ios__card--dragging {
    cursor: grabbing !important;
    opacity: .95;
}

/* 整個 list 在拖曳期間,讓非拖曳卡的 hover 行為暫停 */
.todos-ios__list:has(.todos-ios__card--chosen) .todos-ios__card:not(.todos-ios__card--chosen) {
    transition: transform .2s ease;
}

/* 手機:拖把預設可見 (沒有 hover 概念) */
@media (max-width: 767px) {
    .todos-ios__drag-handle { opacity: .7; }
}

/* 空狀態 */
.todos-ios__empty {
    text-align: center;
    padding: 60px 20px;
}
.todos-ios__empty-icon {
    width: 48px; height: 48px;
    color: #cbd5e1;
    margin: 0 auto 12px;
}
.dark .todos-ios__empty-icon { color: rgb(75, 85, 99); }
.todos-ios__empty-title {
    font-size: 16px;
    font-weight: 600;
    color: #475569;
    margin: 0 0 6px;
}
.todos-ios__empty-hint {
    font-size: 13px;
    color: #94a3b8;
    margin: 0 0 12px;
}
.todos-ios__empty-actions {
    display: flex;
    gap: 8px;
    justify-content: center;
    flex-wrap: wrap;
    margin-top: 16px;
}
.todos-ios__empty-btn {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 8px 16px;
    border-radius: 999px;
    border: 1px solid var(--tios-blue);
    background: transparent;
    color: var(--tios-blue);
    font-size: 13px;
    font-weight: 500;
    cursor: pointer;
    transition: all .15s ease;
}
.todos-ios__empty-btn:hover {
    background: var(--tios-blue-tint);
    transform: translateY(-1px);
}
.todos-ios__empty-btn-icon { width: 14px; height: 14px; }
.todos-ios__kbd {
    display: inline-block;
    padding: 1px 6px;
    border-radius: 4px;
    background: #f1f5f9;
    border: 1px solid #cbd5e1;
    font-family: ui-monospace, "SF Mono", Menlo, monospace;
    font-size: 11px;
    color: #475569;
    box-shadow: 0 1px 0 #cbd5e1;
}
.dark .todos-ios__kbd {
    background: rgb(55, 65, 81);
    border-color: rgb(75, 85, 99);
    color: #cbd5e1;
    box-shadow: 0 1px 0 rgb(75, 85, 99);
}
.dark .todos-ios__empty-btn:hover { background: rgba(0, 122, 255, .12); }

/* ─── 響應式 ──────────────────────────────────────────────── */
@media (max-width: 767px) {
    .todos-ios__card {
        padding: 12px 14px;
        gap: 10px;
    }
    .todos-ios__actions { opacity: 1; }
    .todos-ios__title { font-size: 14.5px; }
}

/* ─── 深色模式(Filament .dark) ────────────────────────────── */
.dark .todos-ios { color: #f1f5f9; }

.dark .todos-ios__toggle {
    background: rgb(31, 41, 55);
    border-color: rgb(55, 65, 81);
    color: #cbd5e1;
}
.dark .todos-ios__toggle:hover { background: rgb(55, 65, 81); }
.dark .todos-ios__toggle.is-on {
    background: rgba(0, 122, 255, .18);
    border-color: rgba(0, 122, 255, .5);
    color: #60a5fa;
}

.dark .todos-ios__tab {
    border-color: rgb(55, 65, 81);
    color: #94a3b8;
}
.dark .todos-ios__tab:hover {
    background: rgba(0, 122, 255, .12);
    color: #60a5fa;
}
.dark .todos-ios__tab.is-active {
    background: rgba(0, 122, 255, .22);
    border-color: #3b82f6;
    color: #93c5fd;
}
.dark .todos-ios__tab-count {
    background: rgb(55, 65, 81);
    color: #cbd5e1;
}
.dark .todos-ios__tab.is-active .todos-ios__tab-count {
    background: rgba(0, 122, 255, .35);
    color: #dbeafe;
}

.dark .todos-ios__quickadd {
    background: rgb(31, 41, 55);
    border-color: rgb(55, 65, 81);
}
.dark .todos-ios__quickadd-input { color: #f1f5f9; }
.dark .todos-ios__quickadd-input::placeholder { color: #64748b; }
.dark .todos-ios__quickadd-chip {
    background: rgb(55, 65, 81);
    border-color: rgb(75, 85, 99);
    color: #f1f5f9;
}

.dark .todos-ios__card {
    background: rgb(31, 41, 55);
    border-color: rgb(55, 65, 81);
}
.dark .todos-ios__card:hover { box-shadow: 0 6px 16px rgba(0, 0, 0, .3); }
.dark .todos-ios__title { color: #f1f5f9; }
.dark .todos-ios__title:hover { background: rgb(55, 65, 81); }
.dark .todos-ios__title-input {
    background: rgb(55, 65, 81);
    color: #f1f5f9;
}
.dark .todos-ios__description { color: #94a3b8; }
.dark .todos-ios__meta { color: #94a3b8; }
.dark .todos-ios__check-circle { border-color: rgb(75, 85, 99); }
.dark .todos-ios__icon-btn { color: #94a3b8; }
.dark .todos-ios__icon-btn:hover { background: rgb(55, 65, 81); color: #93c5fd; }
.dark .todos-ios__icon-btn--danger:hover { background: rgba(239, 68, 68, .15); color: #fca5a5; }

.dark .todos-ios__popover {
    background: rgb(31, 41, 55);
    border-color: rgb(55, 65, 81);
}
.dark .todos-ios__popover-item { color: #f1f5f9; }
.dark .todos-ios__popover-item:hover { background: rgb(55, 65, 81); }

.dark .todos-ios__empty-title { color: #cbd5e1; }
.dark .todos-ios__empty-hint { color: #64748b; }
