:root[data-theme="light"] {
    --bg-main: #f4f5f7;
    --bg-card: #ffffff;
    --bg-panel: #ffffff;
    --bg-input: #f9f9f9;
    --border-light: #e0e0e0;
    --border-dark: #cccccc;
    --text-main: #222222;
    --text-sub: #666666;
    --primary: #c99700;
    --primary-hover: #a67c00;
    --danger: #d32f2f;
    --danger-hover: #b71c1c;
    --success: #2e7d32;
    --shadow: 0 4px 12px rgba(0,0,0,0.08);
}

:root[data-theme="dark"] {
    --bg-main: #121212;
    --bg-card: #1e1e1e;
    --bg-panel: #181818;
    --bg-input: #2a2a2a;
    --border-light: #3d3d3d;
    --border-dark: #222;
    --text-main: #f0f0f0;
    --text-sub: #9e9e9e;
    --primary: #ffd700;
    --primary-hover: #e6c200;
    --danger: #ff4c4c;
    --danger-hover: #e63946;
    --success: #4caf50;
    --shadow: 0 4px 12px rgba(0,0,0,0.5);
}

* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Microsoft JhengHei", sans-serif;
    -webkit-tap-highlight-color: transparent;
}

body {
    background-color: var(--bg-main);
    color: var(--text-main);
    font-size: 16px;
    line-height: 1.5;
    transition: background-color 0.3s, color 0.3s;
}

.custom-scrollbar::-webkit-scrollbar { height: 6px; width: 6px; }
.custom-scrollbar::-webkit-scrollbar-track { background: transparent; }
.custom-scrollbar::-webkit-scrollbar-thumb { background: #888; border-radius: 4px; }

.login-container { display: flex; justify-content: center; align-items: center; min-height: 100vh; background: var(--bg-main); padding: 20px; }
.login-box { background: var(--bg-card); border: 1px solid var(--border-light); border-radius: 12px; padding: 40px 30px; width: 100%; max-width: 400px; box-shadow: var(--shadow); text-align: center; }
.login-brand h2 { color: var(--primary); font-size: 1.5rem; letter-spacing: 1px; margin-top:10px; }
.login-brand p { color: var(--text-sub); font-size: 0.9rem; margin-top: 5px; margin-bottom: 25px; }
.form-field { margin-bottom: 20px; text-align: left; }
.form-field label { display: block; color: var(--text-sub); font-size: 0.85rem; margin-bottom: 8px; }
.form-field input { width: 100%; background: var(--bg-input); border: 1px solid var(--border-light); color: var(--text-main); padding: 12px 15px; border-radius: 8px; font-size: 1rem; outline: none; }
.form-field input:focus { border-color: var(--primary); }

.btn { border: none; border-radius: 6px; padding: 8px 16px; font-size: 0.95rem; font-weight: bold; cursor: pointer; display: inline-flex; align-items: center; justify-content: center; transition: 0.2s; }
.btn-primary { background: var(--primary); color: #000; }
.btn-secondary { background: var(--bg-input); color: var(--text-main); border: 1px solid var(--border-light); }
.btn-danger { background: var(--danger); color: #fff; }
.btn-text { background: transparent; color: var(--text-sub); padding: 8px; }
.btn-text:hover { color: var(--text-main); }
.btn-small { padding: 4px 10px; font-size: 0.85rem; background: var(--bg-input); color: var(--primary); border: 1px solid var(--primary); border-radius: 4px; }
.btn-login { width: 100%; padding: 12px; font-size: 1.1rem; margin-top: 10px; }
.role-badge { font-size: 0.75rem; padding: 3px 8px; border-radius: 12px; border: 1px solid; margin-left: 10px; white-space: nowrap; }

.btn-copy { background: transparent; border: 1px solid var(--border-light); color: var(--text-sub); border-radius: 4px; padding: 2px 8px; font-size: 0.8rem; cursor: pointer; margin-left: 10px; vertical-align: middle; transition: all 0.2s; }
.btn-copy:hover { color: var(--primary); border-color: var(--primary); background: rgba(255, 215, 0, 0.1); }

/* 通知系統樣式 */
.notification-wrapper { position: relative; display: inline-block; }
.notif-badge { position: absolute; top: 4px; right: 4px; width: 10px; height: 10px; background: var(--danger); border-radius: 50%; border: 1px solid var(--bg-panel); }
.notif-badge.blink { animation: blinker 1s linear infinite; }
@keyframes blinker { 50% { opacity: 0; } }

.notification-panel {
    position: absolute; top: 120%; right: 0; width: 280px;
    background: var(--bg-card); border: 1px solid var(--border-light);
    border-radius: 8px; box-shadow: var(--shadow); z-index: 1000;
    display: flex; flex-direction: column; max-height: 350px; overflow-y: auto; text-align: left;
}
.notif-header { padding: 10px 15px; font-weight: bold; border-bottom: 1px solid var(--border-light); color: var(--primary); font-size: 0.95rem; }
.notif-item { padding: 12px 15px; border-bottom: 1px solid var(--border-light); cursor: pointer; transition: 0.2s; font-size: 0.85rem; line-height: 1.4; color: var(--text-main); }
.notif-item:hover { background: var(--bg-input); }
.notif-item.unread { background: rgba(0, 0, 0, 0.08); border-left: 3px solid var(--primary); }
[data-theme="dark"] .notif-item.unread { background: rgba(255, 255, 255, 0.1); border-left: 3px solid var(--primary); }
.notif-time { font-size: 0.75rem; color: var(--text-sub); margin-top: 4px; }

.app-header { position: sticky; top: 0; z-index: 100; background: var(--bg-panel); border-bottom: 2px solid var(--border-light); padding: 12px 16px; display: flex; justify-content: space-between; align-items: center; }
.header-left { display: flex; align-items: center; gap: 10px; }
.app-logo { width: 32px; height: 32px; border-radius: 6px; }
.app-title { font-size: 1.25rem; color: var(--primary); }
.header-right { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; justify-content: flex-end;}
.filter-panel { background: var(--bg-panel); padding: 12px 16px; border-bottom: 1px solid var(--border-light); display: flex; flex-direction: column; gap: 12px; }
.search-row input, .filter-select { width: 100%; background: var(--bg-input); border: 1px solid var(--border-light); color: var(--text-main); padding: 10px 15px; border-radius: 8px; outline: none; }
.quick-tags-bar { display: flex; gap: 10px; overflow-x: auto; white-space: nowrap; padding-bottom: 4px; }
.tag-chip { background: var(--bg-input); color: var(--text-sub); border: 1px solid var(--border-light); border-radius: 20px; padding: 5px 14px; font-size: 0.85rem; cursor: pointer; }
.tag-chip.active { background: var(--primary); color: #000; font-weight: bold; border-color: var(--primary); }
.filter-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(140px, 1fr)); gap: 10px; }

.memo-container { padding: 16px; display: flex; flex-direction: column; gap: 16px; max-width: 800px; margin: 0 auto; padding-bottom: 100px; }
.memo-card { background: var(--bg-card); border: 1px solid var(--border-light); border-radius: 10px; padding: 16px; cursor: pointer; box-shadow: var(--shadow); }
.memo-card h2 { word-break: break-word; white-space: normal; }

.modal-backdrop { 
    position: fixed; top: 0; left: 0; width: 100%; height: 100%; 
    background: rgba(0, 0, 0, 0.6); backdrop-filter: blur(4px); 
    z-index: 200; display: flex; justify-content: center; 
    align-items: flex-start; padding: 20px 10px; overflow-y: auto;
}
@media (min-width: 768px) { .modal-backdrop { padding: 40px 20px; } }

/* 全螢幕上傳鎖定遮罩 */
.global-lock-overlay {
    position: fixed; top: 0; left: 0; width: 100%; height: 100%;
    background: rgba(0,0,0,0.5); z-index: 9999; display: flex;
    justify-content: center; align-items: center; backdrop-filter: blur(2px);
}

.modal-card { 
    background: var(--bg-card); width: 100%; max-width: 750px; 
    max-height: calc(100dvh - 40px); border-radius: 12px; 
    display: flex; flex-direction: column; box-shadow: var(--shadow); 
    margin: auto;
}
.modal-header { padding: 16px 20px; background: var(--bg-panel); border-bottom: 1px solid var(--border-light); display: flex; justify-content: space-between; align-items: center; border-radius: 12px 12px 0 0; }
.modal-header h3 { color: var(--primary); font-size: 1.15rem; word-break: break-word; white-space: normal; }
.header-actions { display: flex; align-items: center; gap: 15px; }
.modal-close-btn { background: none; border: none; font-size: 1.8rem; color: var(--text-sub); cursor: pointer; line-height: 1; }
.modal-body { padding: 20px; overflow-y: auto; display: flex; flex-direction: column; gap: 20px; }
.modal-footer { padding: 16px 20px; background: var(--bg-panel); border-top: 1px solid var(--border-light); display: flex; justify-content: flex-end; gap: 12px; }

.form-group { display: flex; flex-direction: column; gap: 8px; }
.form-group label { font-size: 0.9rem; color: var(--text-sub); }
.required-label { color: var(--primary) !important; font-weight: bold; }
.form-group input, .form-group select { background: var(--bg-input); border: 1px solid var(--border-light); color: var(--text-main); padding: 10px 12px; border-radius: 6px; font-size: 1rem; outline: none; }
.form-row-three { display: grid; grid-template-columns: repeat(3, 1fr); gap: 12px; }
.form-row-two { display: grid; grid-template-columns: repeat(2, 1fr); gap: 12px; }
@media (max-width: 600px) { .form-row-three, .form-row-two { grid-template-columns: 1fr; } }
.btn-toggle-expand { width: 100%; background: var(--bg-input); border: 1px dashed var(--border-dark); color: var(--primary); padding: 12px; border-radius: 6px; text-align: left; font-size: 0.95rem; font-weight: bold; cursor: pointer; }
.expand-content { padding: 16px; background: var(--bg-panel); border: 1px solid var(--border-light); border-top: none; border-radius: 0 0 6px 6px; display: flex; flex-direction: column; gap: 12px; }
.section-title-bar { display: flex; justify-content: space-between; align-items: center; border-bottom: 1px solid var(--border-light); padding-bottom: 8px; margin-bottom: 8px; }
.section-title-bar h4 { color: var(--primary); font-size: 1rem; }
.scrap-row { display: flex; align-items: center; gap: 10px; margin-top: 10px; }
.align-start { align-items: flex-start; }
.multi-in-container { display: flex; flex-direction: column; gap: 8px; margin-top: 8px; margin-left: 24px; }
.preserve-box { margin-top: 20px; border-top: 1px dashed var(--border-light); padding-top: 12px; }
.media-actions { display: flex; gap: 10px; margin-bottom: 12px; }
.media-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(80px, 1fr)); gap: 10px; max-height: 200px; overflow-y: auto; }

.rendered-tag { display: inline-block; padding: 2px 8px; border-radius: 12px; border: 1px solid currentColor; font-size: 0.85em; font-weight: bold; margin: 0 4px; vertical-align: middle; background: var(--bg-panel); }
.view-subtask { display: flex; align-items: flex-start; gap: 10px; padding: 12px; border: 1px solid var(--border-light); border-radius: 8px; margin-bottom: 8px; background: var(--bg-input); cursor: pointer; transition: 0.2s; }
.view-subtask:hover { border-color: var(--primary); }
.view-subtask.done { opacity: 0.6; }
.view-subtask.done .st-text { text-decoration: line-through; }
.st-text { flex: 1; line-height: 1.4; color: var(--text-main); word-break: break-word; white-space: normal; }
.info-row { display: flex; margin-bottom: 8px; font-size: 0.95rem; }
.info-row .label { width: 100px; color: var(--text-sub); }
.info-row .value { flex: 1; color: var(--text-main); font-weight: bold; word-break: break-word; white-space: normal; }