/* ===== CSS 變數定義 ===== */
:root {
    --bg-color: #f5e6c8;
    --container-bg: #ffffff;
    --border-color: #333333;
    --delete-btn-color: #ef4444;
    --text-color: #333333;
    --placeholder-color: #999999;
    --shadow: 0 2px 10px rgba(0, 0, 0, 0.1);
}

/* ===== 重置與基礎樣式 ===== */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    background-color: var(--bg-color);
    min-height: 100vh;
    display: flex;
    justify-content: center;
    padding: 20px;
}

/* ===== 主容器 ===== */
.app-container {
    width: 100%;
    max-width: 600px;
    display: flex;
    flex-direction: column;
    height: calc(100vh - 40px);
}

/* ===== 固定區域：標題和輸入 ===== */
.header {
    background-color: var(--bg-color);
    padding-bottom: 20px;
    flex-shrink: 0;
}

.title-row {
    display: flex;
    justify-content: center;
    align-items: center;
    gap: 10px;
    margin-bottom: 20px;
}

.title {
    font-size: 2rem;
    font-weight: bold;
    color: var(--text-color);
    text-align: center;
    margin-bottom: 0;
}

.settings-btn {
    background: transparent;
    border: none;
    font-size: 1.2rem;
    cursor: pointer;
    padding: 5px;
    opacity: 0.6;
    transition: opacity 0.2s;
}

.settings-btn:hover {
    opacity: 1;
}

/* ===== 設定面板 ===== */
.settings-panel {
    background-color: var(--container-bg);
    border: 2px solid var(--border-color);
    border-radius: 8px;
    padding: 15px;
    margin-bottom: 15px;
}

.settings-content {
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.settings-label {
    font-size: 0.9rem;
    color: var(--text-color);
    font-weight: 500;
}

.settings-input {
    padding: 10px 15px;
    font-size: 0.9rem;
    border: 2px solid var(--border-color);
    border-radius: 4px;
    outline: none;
    width: 100%;
    box-sizing: border-box;
}

.settings-input:focus {
    border-color: #666666;
}

.settings-actions {
    display: flex;
    gap: 10px;
    justify-content: flex-end;
}

.save-settings-btn {
    padding: 8px 20px;
    background-color: #22c55e;
    color: white;
    border: none;
    border-radius: 4px;
    cursor: pointer;
    font-size: 0.9rem;
}

.save-settings-btn:hover {
    background-color: #16a34a;
}

.cancel-settings-btn {
    padding: 8px 20px;
    background-color: #9ca3af;
    color: white;
    border: none;
    border-radius: 4px;
    cursor: pointer;
    font-size: 0.9rem;
}

.cancel-settings-btn:hover {
    background-color: #6b7280;
}

.input-section {
    background-color: var(--container-bg);
    border: 2px solid var(--border-color);
    border-radius: 8px;
    padding: 15px;
    display: grid;
    grid-template-columns: 1fr auto auto;
    grid-template-rows: auto auto;
    gap: 10px;
}

/* 桌面版佈局 */
.input-section .todo-input {
    grid-column: 1;
    grid-row: 1;
}

.input-section .priority-select {
    grid-column: 2;
    grid-row: 1;
}

.input-section .add-btn {
    grid-column: 3;
    grid-row: 1;
}

.input-section .description-wrapper {
    grid-column: 1 / -1;
    grid-row: 2;
}

.new-todo-row {
    display: flex;
    gap: 10px;
    margin-bottom: 10px;
}

.todo-input {
    flex: 1;
    padding: 10px 15px;
    font-size: 1rem;
    border: 2px solid var(--border-color);
    border-radius: 4px;
    outline: none;
    transition: border-color 0.2s;
}

.priority-select {
    padding: 10px 10px;
    font-size: 1rem;
    border: 2px solid var(--border-color);
    border-radius: 4px;
    outline: none;
    background-color: white;
    cursor: pointer;
    color: var(--text-color);
}

.priority-select:focus,
.todo-input:focus {
    border-color: #666666;
}

.todo-input:focus {
    border-color: #666666;
}

.todo-input::placeholder {
    color: var(--placeholder-color);
}

.add-btn {
    padding: 10px 25px;
    font-size: 1rem;
    background-color: var(--container-bg);
    border: 2px solid var(--border-color);
    border-radius: 4px;
    cursor: pointer;
    transition: background-color 0.2s, transform 0.1s;
}

.add-btn:hover {
    background-color: #f0f0f0;
}

.add-btn:active {
    transform: scale(0.98);
}

.description-input {
    width: 100%;
    padding: 10px 15px;
    font-size: 1rem;
    border: 2px solid var(--border-color);
    border-radius: 4px;
    outline: none;
    resize: vertical;
    min-height: 60px;
    font-family: inherit;
    transition: border-color 0.2s;
}

.description-input:focus {
    border-color: #666666;
}

.description-input::placeholder {
    color: var(--placeholder-color);
}

/* ===== Description 區域包裝與快捷鍵提示 ===== */
.description-wrapper {
    position: relative;
}

.shortcut-hint {
    position: absolute;
    bottom: 8px;
    right: 10px;
    font-size: 0.75rem;
    color: #999999;
    pointer-events: none;
    user-select: none;
}

/* ===== 可捲動區域：Todo 列表 ===== */
.todo-list-container {
    flex: 1;
    overflow-y: auto;
    background-color: var(--container-bg);
    border: 2px solid var(--border-color);
    border-radius: 8px;
    padding: 0;
}

.todo-list {
    list-style: none;
}

/* ===== Todo Item 樣式 ===== */
.todo-item {
    border-bottom: 1px solid #e0e0e0;
}

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

.todo-item-main {
    display: flex;
    align-items: center;
    padding: 15px;
    cursor: pointer;
    transition: background-color 0.2s;
}

.todo-item-main:hover {
    background-color: #f9f9f9;
}

.todo-checkbox {
    width: 20px;
    height: 20px;
    margin-right: 15px;
    cursor: pointer;
    accent-color: var(--text-color);
}

.todo-name {
    flex: 1;
    font-size: 1rem;
    color: var(--text-color);
}

.delete-btn {
    padding: 8px 16px;
    font-size: 0.9rem;
    color: white;
    background-color: var(--delete-btn-color);
    border: none;
    border-radius: 4px;
    cursor: pointer;
    transition: background-color 0.2s, transform 0.1s;
}

.delete-btn:hover {
    background-color: #dc2626;
}

.delete-btn:active {
    transform: scale(0.98);
}

/* ===== Description 展開區域 ===== */
.todo-description {
    max-height: 0;
    overflow: hidden;
    background-color: #f8f8f8;
    transition: max-height 0.3s ease-out, padding 0.3s ease-out;
}

.todo-description.expanded {
    max-height: 500px;
    padding: 15px;
    padding-left: 50px;
}

.todo-description p {
    font-size: 0.95rem;
    color: #555555;
    line-height: 1.5;
}

/* ===== Description 內的優先權調整 ===== */
.desc-content {
    margin-bottom: 12px;
}

.priority-edit {
    display: flex;
    align-items: center;
    gap: 8px;
    padding-top: 10px;
    border-top: 1px solid #e0e0e0;
}

.priority-edit-label {
    font-size: 0.9rem;
    color: #666;
    font-weight: 500;
}

.priority-edit-select {
    padding: 6px 12px;
    font-size: 0.9rem;
    border: 2px solid var(--border-color);
    border-radius: 4px;
    background-color: white;
    cursor: pointer;
    outline: none;
    transition: border-color 0.2s;
}

.priority-edit-select:hover {
    border-color: #666;
}

.priority-edit-select:focus {
    border-color: #3b82f6;
}

.priority-edit-select:disabled {
    background-color: #f0f0f0;
    cursor: not-allowed;
    opacity: 0.7;
}

.priority-loading {
    font-size: 0.85rem;
    color: #3b82f6;
    font-style: italic;
}

/* ===== 捲動條樣式 ===== */
.todo-list-container::-webkit-scrollbar {
    width: 8px;
}

.todo-list-container::-webkit-scrollbar-track {
    background: #f1f1f1;
    border-radius: 4px;
}

.todo-list-container::-webkit-scrollbar-thumb {
    background: #cccccc;
    border-radius: 4px;
}

.todo-list-container::-webkit-scrollbar-thumb:hover {
    background: #999999;
}

/* ===== 狀態樣式 ===== */
.todo-item.deleting {
    opacity: 0.5;
    pointer-events: none;
}

.todo-item.updating {
    opacity: 0.7;
}

.add-btn:disabled {
    opacity: 0.6;
    cursor: not-allowed;
}

.delete-btn:disabled {
    opacity: 0.6;
    cursor: not-allowed;
}

/* ===== 完成按鈕樣式 ===== */
.complete-btn {
    background-color: #22c55e;
    color: white;
    border: none;
    padding: 8px 16px;
    border-radius: 4px;
    cursor: pointer;
    font-size: 0.9rem;
    margin-right: 8px;
    transition: background-color 0.2s, transform 0.1s;
}

.complete-btn:hover {
    background-color: #16a34a;
}

.complete-btn:active {
    transform: scale(0.98);
}

.complete-btn:disabled {
    background-color: #86efac;
    cursor: not-allowed;
}

/* ===== 自訂確認對話框 Modal ===== */
.confirm-modal {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    z-index: 2000;
    display: flex;
    justify-content: center;
    align-items: center;
}

.confirm-modal-backdrop {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(0, 0, 0, 0.5);
}

.confirm-modal-content {
    position: relative;
    background-color: white;
    border-radius: 12px;
    padding: 24px 32px;
    box-shadow: 0 10px 40px rgba(0, 0, 0, 0.3);
    max-width: 400px;
    width: 90%;
    text-align: center;
    animation: modalSlideIn 0.2s ease-out;
}

@keyframes modalSlideIn {
    from {
        transform: translateY(-20px);
        opacity: 0;
    }

    to {
        transform: translateY(0);
        opacity: 1;
    }
}

.confirm-message {
    font-size: 1.1rem;
    color: #333;
    margin-bottom: 24px;
    line-height: 1.5;
}

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

.confirm-yes-btn {
    padding: 10px 24px;
    font-size: 1rem;
    background-color: #22c55e;
    color: white;
    border: none;
    border-radius: 6px;
    cursor: pointer;
    transition: background-color 0.2s;
}

.confirm-yes-btn:hover {
    background-color: #16a34a;
}

.confirm-no-btn {
    padding: 10px 24px;
    font-size: 1rem;
    background-color: #9ca3af;
    color: white;
    border: none;
    border-radius: 6px;
    cursor: pointer;
    transition: background-color 0.2s;
}

.confirm-no-btn:hover {
    background-color: #6b7280;
}

/* ===== 錯誤提示動畫 ===== */
@keyframes slideIn {
    from {
        transform: translateX(100%);
        opacity: 0;
    }

    to {
        transform: translateX(0);
        opacity: 1;
    }
}

@keyframes slideOut {
    from {
        transform: translateX(0);
        opacity: 1;
    }

    to {
        transform: translateX(100%);
        opacity: 0;
    }
}

/* ===== RWD 響應式設計 ===== */
@media (max-width: 480px) {
    body {
        padding: 10px;
    }

    .title {
        font-size: 1.5rem;
    }

    /* 手機版使用 flex 容器，控制子元素順序 */
    .input-section {
        display: flex;
        flex-direction: column;
    }

    /* 調整手機版順序：todo-input → description → priority → add-btn */
    .input-section .todo-input {
        order: 1;
    }

    .input-section .description-wrapper {
        order: 2;
    }

    .input-section .priority-select {
        order: 3;
    }

    .input-section .add-btn {
        order: 4;
        width: 100%;
    }

    .todo-item-main {
        padding: 12px;
    }

    .delete-btn {
        padding: 6px 12px;
        font-size: 0.85rem;
    }
}