﻿/* ============================================================
   1. 基礎變數與 15 種風格定義
   ============================================================ */
:root { 
    --fs-main: 18px; --fs-set: 16px; --fs-edit: 16px; 
    --bg: #e1f5fe; --btn: #0277bd; 
}

.theme-ocean { --bg: #e1f5fe; --btn: #0277bd; }
.theme-forest { --bg: #e8f5e9; --btn: #2e7d32; }
.theme-sakura { --bg: #fce4ec; --btn: #d81b60; }
.theme-sunset { --bg: #fff3e0; --btn: #ef6c00; }
.theme-lavender { --bg: #f3e5f5; --btn: #8e24aa; }
.theme-lemon { --bg: #fffde7; --btn: #fbc02d; }
.theme-slate { --bg: #eceff1; --btn: #546e7a; }
.theme-mint { --bg: #f1f8e9; --btn: #7cb342; }
.theme-rose { --bg: #ffebee; --btn: #e53935; }
.theme-cocoa { --bg: #efebe9; --btn: #6d4c41; }
.theme-deepsea { --bg: #e8eaf6; --btn: #3949ab; }
.theme-cream { --bg: #fff8e1; --btn: #ffa000; }
.theme-grape { --bg: #ede7f6; --btn: #5e35b1; }
.theme-silver { --bg: #fafafa; --btn: #757575; }
.theme-fire { --bg: #fbe9e7; --btn: #d84315; }

/* ============================================================
   2. 全局基礎樣式
   ============================================================ */
* { box-sizing: border-box; }
body, html { 
    height: 100vh; margin: 0; display: flex; flex-direction: column; 
    overflow: hidden; font-family: "Microsoft JhengHei", sans-serif; 
}

/* ============================================================
   3. 主頁面導航列
   ============================================================ */
.header-bar { 
    flex: 0 0 auto; min-height: 70px; background: #1a252f; 
    display: flex; align-items: center; justify-content: space-between; 
    padding: 10px 20px; position: relative; border-bottom: 5px solid var(--btn);
    flex-wrap: wrap;
}
.logo-large { font-size: 2rem; font-weight: 900; color: white; margin-right: 15px; }

.nav-center { display: flex; align-items: center; gap: 10px; }
.nav-label { color: white; font-size: 1.4rem; font-weight: bold; }

.nav-right { display: flex; gap: 6px; flex-wrap: wrap; }
.nav-right button[onclick*="resetApp"] {
    margin-left: 50px;  
    margin-right: 50px; 
    background-color: #fff1f0; 
    border-color: #ffa39e;     
}

.small-btn { 
    padding: 6px 12px; 
    font-size: 20px; 
    cursor: pointer; 
    border-radius: 4px; 
    border: 1px solid #ccc; 
    background: #fff; 
    min-width: 60px;
    height: auto;
    transition: 0.2s;
}
.small-btn:hover { background: #eee; }

.footer-bar { position: fixed; bottom: 0; left: 0; width: 100%; background: #fff; border-top: 1px solid #eee; padding: 2px 0; text-align: center; z-index: 1000; }

/* ============================================================
   4. 主內容區 (卡片) - 移除所有項目符號與縮排
   ============================================================ */
.main-content { 
    flex: 1; overflow-y: auto; padding: 25px; background: var(--bg); 
    display: grid; gap: 20px; align-content: start;
    grid-template-columns: repeat(auto-fill, minmax(320px, 1fr));
}

.day-card { 
    background: #fff; border: 3px solid var(--btn); border-radius: 10px; 
    padding: 20px; min-height: 400px; height: var(--card-height, 500px); 
    width: 100%; min-width: 100px; 
    display: flex; flex-direction: column; box-shadow: 0 4px 6px rgba(0,0,0,0.1); 
}

[dir="rtl"] .day-card h3 {
    unicode-bidi: bidi-override; 
    direction: ltr !important; /* 強制日期內部維持左到右順序 */
    text-align: center;         /* 保持標題置中 */
}


.day-card h3 { 
    font-size: var(--fs-main); text-align: center; margin: 0 0 10px 0; 
    border-bottom: 2px solid #eee; padding-bottom: 5px; color: var(--btn); 
}

/* 清單容器：移除 padding */
.day-card ul { 
    list-style-type: none !important; 
    flex: 1; overflow-y: auto; 
    font-size: var(--fs-main); line-height: 1.4; margin: 10px 0 0 0; 
    padding: 0; 
}

/* 列表項目：移除 padding-left */
.day-card li { 
    margin-bottom: 5px; 
    position: relative; 
    padding-left: 0; 
    text-align: left; 
}

/* 強制移除所有可能的項目符號偽元素 */
.day-card li::before, 
.day-card li::after,
[dir="rtl"] .day-card li::before { 
    display: none !important; 
    content: none !important; 
}

.author-link { text-decoration: none; }

/* ============================================================
   5. 彈窗與設定
   ============================================================ */
.modal { display: none; position: fixed; z-index: 1000; left: 0; top: 0; width: 100%; height: 100%; background: rgba(0,0,0,0.7); }
.modal-content { background: white; margin: 2% auto; border-radius: 12px; display: flex; flex-direction: column; overflow: hidden; }
.size-80 { width: 95%; height: 95%; }
.full { width: 96%; height: 96%; margin: 1% auto; }

.modal-header-zone { flex: 0 0 65px; display: flex; justify-content: space-between; align-items: center; padding: 0 20px; background: #eee; border-bottom: 1px solid #ccc; position: relative; }
.modal-body-zone { flex: 1; padding: 20px; overflow-y: auto; }

.modal-header-zone button, .prompt-btn-group button { 
    font-size: calc(var(--fs-set) * 0.95); 
    padding: 8px 16px; 
    min-width: 80px; 
    cursor: pointer; 
    border-radius: 6px; 
    border: 1px solid #ccc; 
    background: #fff;
}
.confirm-btn { background: var(--btn) !important; color: white !important; font-weight: bold; border: none !important; }

.settings-five-cols { display: flex; gap: 15px; height: 100%; }
.col-a, .col-b { flex: 1.5; min-width: 0; }
.col-c, .col-d, .col-e, .col-f { flex: 1; min-width: 0; display: flex; flex-direction: column; font-size: var(--fs-set); }
.col-f { flex: 1.5; }

.settings-five-cols textarea { flex: 1; margin-top: 8px; font-size: var(--fs-set); padding: 10px; resize: none; border: 1px solid #ccc; border-radius: 4px; }
.s-row { display: flex; align-items: center; margin-bottom: 2px; font-size: var(--fs-set); }
.s-row span { min-width: 90px; flex-shrink: 0; }
.s-row select { width: 110px; height: calc(var(--fs-set) * 2); border-radius: 4px; font-size: var(--fs-set); }

/* ============================================================
   6. 編修管理區
   ============================================================ */
.edit-grid-area { display: grid; gap: 15px; grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); }
.edit-card { border: 2px dashed var(--btn); padding: 10px; background: #fff; border-radius: 8px; height: 320px; display: flex; flex-direction: column; }
.edit-header { 
    background: var(--btn); color: white; padding: 8px 12px; cursor: move; border-radius: 4px; 
    display: flex; align-items: center; justify-content: flex-start; 
    position: relative; font-size: var(--fs-edit); 
}
.edit-header-title { font-weight: bold; margin-right: auto; }
.edit-del-btn { position: absolute; right: 8px; cursor: pointer !important; font-size: 1.3rem; color: white; opacity: 0.8; }

.task-box { background: #f1f1f1; border: 1px solid #ddd; margin-top: 5px; padding: 8px; cursor: grab; display: flex; justify-content: space-between; font-size: var(--fs-edit); border-radius: 4px; }
.edit-card button { font-size: calc(var(--fs-edit) * 0.9); padding: 6px 0; margin-top: 5px; cursor: pointer; border: 1px solid var(--btn); background: #fff; color: var(--btn); border-radius: 4px; }

/* 確保智慧預排視窗永遠在最上層 */
#smartScheduleModal {
    z-index: 2000 !important; /* 比一般的 modal (1000) 更高 */
}

/* 讓預覽列表的輸入框更好看點 */
.preview-item {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 8px;
    border-bottom: 1px solid #eee;
}
.preview-item input {
    border: 1px solid #ccc;
    padding: 4px 8px;
    border-radius: 4px;
}

/* ============================================================
   7. 新增作業項目
   ============================================================ */
.prompt-row { display: flex; align-items: flex-start; margin-bottom: 15px; gap: 15px; }
.prompt-label { flex: 0 0 100px; font-weight: bold; font-size: var(--fs-set); padding-top: 10px; color: var(--btn); text-align: right; }
.tag-row { flex: 1; display: flex; flex-wrap: wrap; gap: 8px; background: #f5f5f5; padding: 10px; border-radius: 5px; max-height: 200px; overflow-y: auto; }
.clickable-tag { padding: 0 15px; height: 40px; line-height: 40px; border: 1px solid #999; background: #fff; cursor: pointer; border-radius: 4px; white-space: nowrap; font-size: var(--fs-edit); }
.clickable-tag.active { background: var(--btn) !important; color: white; }

.prompt-final-row { position: sticky; bottom: 0; background: white; padding: 15px 20px; border-top: 2px solid #eee; width: 100%; }
.final-input-container { display: flex; align-items: center; gap: 15px; width: 100%; }
#taskFinalInput { flex: 0 0 75%; height: 50px; font-size: 1.3rem; padding: 0 15px; border: 2px solid var(--btn); border-radius: 8px; }
.prompt-btn-group { flex: 1; display: flex; gap: 8px; justify-content: flex-end; }
.prompt-btn-group button { flex: 1; height: 50px; white-space: nowrap; padding: 0 5px; }

/* ============================================================
   8. 直書與注音模式修正 - 確保從上到下輸出
   ============================================================ */
.writing-vertical {
    writing-mode: vertical-rl;
    text-orientation: upright;
    height: 100%;
    padding: 10px;
    display: block;            /* 改回 block，不使用 flex 避免軸向反轉 */
    letter-spacing: 0.1em;
    direction: ltr !important; /* 核心：內部強制 LTR 確保 1, 2, 3 順序由上而下 */
    text-align: inherit;
    overflow-x: auto;          /* 內容過多時可橫向滾動 */
    
    margin-left: auto;        /* 將剩餘空間推向左側 */
    margin-right: 0;          /* 緊貼右側 */
    width: fit-content;       /* 寬度隨內容伸縮，margin-left 才能生效 */
    min-width: 100%;          /* 確保高度撐開時，內部對齊邏輯正確 */
    text-align: left;         /* 在 ltr 直書下，這代表垂直方向的「靠上」 */
}

[dir="rtl"] .writing-vertical {
    /* 當日期反轉時，讓整塊內容靠卡片右邊，但內部文字依然靠上 */
    margin-left: auto;
    margin-right: 0;
}

.writing-vertical li {
    margin-bottom: 1.5rem; 
    list-style: none;
    display: block;            /* 每一項作業佔據一列（直書的一行） */
    line-height: 1.2;
    padding: 0; 
    position: relative;
    min-height: 3.5em;
    text-align: inherit;
    float: none;               /* 確保不會飄走 */
    clear: both;
}

/* 確保直書模式完全沒有項目符號 */
.writing-vertical li::before, 
.writing-vertical li::after {
    display: none !important;
    content: none !important;
}

/* 內部注音元件的排列 */
.writing-vertical .bopo-vertical-item,
.writing-vertical .plain-char {
    display: inline-flex;      /* 維持注音與聲調的組合 */
    align-items: center;
    justify-content: center;
    vertical-align: top;
}

.writing-vertical .plain-char {
    display: inline-flex; 
    writing-mode: horizontal-tb;
    align-items: center;
    justify-content: center;
    width: 2.2em;
    height: 1.5em; 
    text-align: center;
    vertical-align: top;
}



/* ============================================================
   聲調位置精細調整 (針對 1個、2個、3個注音符號分別設定)
   ============================================================ */

.bopo-vertical-item {
    writing-mode: horizontal-tb; 
    display: inline-flex;
    flex-direction: row-reverse; 
    align-items: center;
    justify-content: center;
    width: 2.2em; 
    height: 3.5em; 
    vertical-align: top;
}


.bopo-chars { display: flex; flex-direction: column; align-items: center; line-height: 1; }

/* 1. 基礎設定：這是通用樣式 */
.bopo-tone {
    font-size: 2em;
    width: 0.1em;
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--btn);
    /* 預設值 (通常給予 2 個音的數值) */
    transform: translateY(2px); 
    margin-right: -1px;
}

/* 2. 當只有 1 個注音符號時 (例如：一、ㄚ) */
/* 判斷條件：第一個 span 同時也是最後一個 span */
.bopo-vertical-item:has(.bopo-chars span:nth-child(1):last-child) .bopo-tone {
    transform: translateY(0.1em); /* 往上移一點，靠近正中間 */
}

/* 3. 當有 2 個注音符號時 (例如：ㄎㄨ、ㄋㄧ) */
/* 判斷條件：第二個 span 是最後一個 span */
.bopo-vertical-item:has(.bopo-chars span:nth-child(2):last-child) .bopo-tone {
    transform: translateY(0.4em); /* 維持在中間偏下的位置 */
}

/* 4. 當有 3 個注音符號時 (例如：ㄍㄨㄛ、ㄑㄧㄤ) */
/* 判斷條件：第三個 span 是最後一個 span */
.bopo-vertical-item:has(.bopo-chars span:nth-child(3):last-child) .bopo-tone {
    transform: translateY(0.6em); /* 往下移，確保不會壓到第一個音 */
}

/* 額外修正：如果前綴符號 (1. 或 ●) 產生了空的聲調容器，將其隱藏 */
.bopo-vertical-item:has(.plain-char) .bopo-tone,
.bopo-tone:empty {
    display: none !important;
}

/* ============================================================
   9. RTL 與 手機版修正
   ============================================================ */
[dir="rtl"] .day-card li {
    padding-left: 0;
    padding-right: 0; 
    text-align: left; 
    margin-left: 0;
}

.tcy {
    -webkit-text-combine: horizontal;
    text-combine-upright: all;
    display: inline-block;
    /* 調整數值，負值越大越往左偏 */
    margin-right: 14px; 
    /* 有時候也需要微調垂直位置 */
    vertical-align: middle; 
}

/* 確保直書容器樣式正確 */
.writing-vertical {
    writing-mode: vertical-rl;
    text-orientation: mixed; /* 這是關鍵，讓英數默認旋轉或保持直立 */
}

@media (max-width: 768px) {
    .modal-content { width: 100% !important; height: 100% !important; margin: 0 !important; border-radius: 0; }
    .header-bar { justify-content: center; text-align: center; }
    .logo-large { margin-bottom: 10px; }
    .nav-center { width: 100%; justify-content: center; margin-bottom: 10px; }
    .nav-right { width: 100%; justify-content: center; }
    .nav-right button[onclick*="resetApp"] { margin-left: 10px; margin-right: 10px; }
    .settings-five-cols { flex-direction: column; overflow-y: auto; }
    .final-input-container { flex-direction: column; align-items: stretch; }
    #taskFinalInput { flex: none; width: 100%; }
    .prompt-btn-group { flex: none; width: 100%; }
}

/* 滾動條樣式 */
::-webkit-scrollbar { width: 8px; }
::-webkit-scrollbar-thumb { background: #ccc; border-radius: 4px; }
::-webkit-scrollbar-thumb:hover { background: #aaa; }

/* 彈窗按鈕區 */
.modal-footer-zone {
    display: flex;
    gap: 10px;
    justify-content: flex-end; 
    padding-right: 20px;   
    padding-bottom: 20px;  
    padding-top: 15px;     
    border-top: 1px solid #eee; 
    width: 100%;
    box-sizing: border-box;
}

.dropdown { position: relative; display: inline-block; }
.dropdown-content {
    display: none;
    position: absolute;
    right: 0;
    background-color: #f9f9f9;
    min-width: 120px;
    box-shadow: 0px 8px 16px rgba(0,0,0,0.2);
    z-index: 100;
}
.dropdown-content button {
    width: 100%;
    display: block;
    padding: 10px;
    border: none;
    background: none;
    text-align: left;
    cursor: pointer;
}

/* 修正 RTL 模式下作業項目的數字與標點跑位 */
[dir="rtl"] .day-card li {
    direction: ltr !important;   /* 強制讓 2.簽名... 維持左到右 */
    text-align: left;
    unicode-bidi: plaintext;      /* 確保數字不會被鏡像 */
}

/* 如果是直排模式下的 RTL 修正 */
[dir="rtl"] .writing-vertical li {
    direction: ltr !important;
    text-align: inherit;
}

.dropdown-content button:hover { background-color: #ddd; }
.show { display: block; }
