/* static/style.css (最終整合版) */
body {
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
    background-color: #f8f9fa;
    color: #343a40;
    line-height: 1.6;
    margin: 0;
    padding: 20px;
}
.container {
    max-width: 1200px;
    margin: auto;
    background: #fff;
    padding: 20px 30px;
    border-radius: 8px;
    border: 1px solid #dee2e6;
}
h1, h2, h3 {
    color: #0056b3;
    border-bottom: 2px solid #eee;
    padding-bottom: 10px;
    margin-top: 20px;
}
input[type="text"], input[type="password"], input[type="email"], input[type="date"], input[type="number"], input[type="url"], input[type="datetime-local"], textarea, select {
    width: 100%;
    padding: 10px;
    margin-bottom: 15px;
    border: 1px solid #ccc;
    border-radius: 4px;
    box-sizing: border-box;
}
input[type="submit"], a.button, .button-danger, .button-secondary {
    background-color: #007bff;
    color: #fff;
    padding: 10px 18px;
    border: none;
    border-radius: 4px;
    cursor: pointer;
    text-decoration: none;
    display: inline-block;
    font-size: 14px;
    margin-right: 5px;
    transition: background-color 0.2s;
}
.button-danger { background-color: #dc3545; }
.button-secondary { background-color: #6c757d; }
input[type="submit"]:hover, a.button:hover, .button-danger:hover, .button-secondary:hover { opacity: 0.85; }
.flashes { padding: 15px; background-color: #d1ecf1; border: 1px solid #bee5eb; border-radius: 4px; color: #0c5460; margin-bottom: 20px; }
a { color: #007bff; text-decoration: none; }
a:hover { text-decoration: underline; }
hr { border: 0; border-top: 1px solid #eee; margin: 2rem 0; }

/* --- 導覽列 (視覺升級版) --- */
.main-nav {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 12px; /* 統一項目間距 */
    background-color: #ffffff; /* 改為白色以突顯外框 */
    padding: 12px;
    border-radius: 8px;
    border: 1px solid #dee2e6;
    margin-bottom: 25px;
}
.main-nav a {
    font-weight: 500;
    color: #0056b3; /* 恢復成您原本喜歡的藍色 */
    white-space: nowrap;
    padding: 8px 15px; /* 增加內邊距 */
    border-radius: 6px; /* 圓弧的角 */
    background-color: #f1f3f5; /* 淺灰色背景，製造框線感 */
    text-decoration: none;
    transition: all 0.2s ease-in-out;
    box-shadow: 0 1px 2px rgba(0,0,0,0.05); /* 稍微有點立體感 */
}
.main-nav a:hover {
    transform: translateY(-2px); /* 滑鼠移上去時稍微上浮 */
    box-shadow: 0 4px 8px rgba(0,0,0,0.1); /* 立體感更強 */
    color: #003d82;
    text-decoration: none;
}

/* --- 案件卡片 --- */
.dashboard-header { display: flex; justify-content: space-between; align-items: center; }
.dashboard-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(320px, 1fr)); gap: 20px; margin-top: 20px; }
a.case-card-link { text-decoration: none; color: inherit; }
.case-card { position: relative; background: #fff; border-left: 5px solid #ccc; border-radius: 5px; box-shadow: 0 2px 5px rgba(0,0,0,0.05); padding: 15px; transition: transform 0.2s, box-shadow 0.2s; border: 1px solid #eee; height: 100%; }
.case-card:hover { transform: translateY(-5px); box-shadow: 0 4px 10px rgba(0,0,0,0.1); }
.card-top-right { position: absolute; top: 10px; right: 10px; }
.payment-icon-status { font-size: 14px; color: white; width: 24px; height: 24px; border-radius: 50%; display: flex; align-items: center; justify-content: center; font-weight: bold; }
.payment-icon-status.pending { background-color: #6c757d; }
.payment-icon-status.issued { background-color: #007bff; }
.payment-icon-status.received { background-color: #28a745; }
.card-header { display: flex; justify-content: space-between; align-items: flex-start; border-bottom: 1px solid #eee; padding-bottom: 10px; margin-bottom: 10px; }
.card-header h3 { margin: 0; font-size: 1.2em; }
.card-status { background-color: #eee; color: #555; padding: 3px 8px; border-radius: 12px; font-size: 0.8em; font-weight: bold; white-space: nowrap; }
.card-body p { margin: 8px 0; }
p.due-date { font-size: 0.9em; font-weight: bold; color: #c82333; }
.card-footer { margin-top: 15px; padding-top: 10px; border-top: 1px solid #eee; font-size: 0.9em; color: #555; }
.member-list span { background: #eee; padding: 2px 6px; border-radius: 4px; margin-right: 5px; display: inline-block; margin-bottom: 3px; }
.status-洽談中 { border-left-color: #007bff; } .status-洽談中 .card-status { background-color: #007bff; color: white; }
.status-執行中, .status-已簽約 { border-left-color: #28a745; } .status-執行中 .card-status, .status-已簽約 .card-status { background-color: #28a745; color: white; }
.status-已結案 { border-left-color: #6c757d; } .status-已結案 .card-status { background-color: #6c757d; color: white; }
.status-取消 { border-left-color: #dc3545; } .status-取消 .card-status { background-color: #dc3545; color: white; }
/* --- 案件詳情/聯絡人/表單 --- */
.detail-header { display: flex; justify-content: space-between; align-items: center; }
.detail-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(250px, 1fr)); gap: 20px; margin: 20px 0; }
.detail-item, .detail-item-full { padding: 15px; background-color: #f9f9f9; border-radius: 5px; }
.detail-item-full { margin-bottom: 15px; }
.assignment-list-detail { display: grid; grid-template-columns: repeat(auto-fill, minmax(400px, 1fr)); gap: 15px; margin-top: 15px; }
.assignment-card-detail details { background: #fff; border: 1px solid #dee2e6; border-radius: 5px; overflow: hidden; }
.assignment-card-detail summary { display: flex; justify-content: space-between; align-items: center; padding: 12px 18px; cursor: pointer; list-style: none; transition: background-color 0.2s; }
.assignment-card-detail summary::-webkit-details-marker { display: none; }
.assignment-card-detail summary.type-internal { background-color: #e7f5ff; }
.assignment-card-detail summary.type-external { background-color: #f1f3f5; }
.assignment-card-detail summary:hover { background-color: #dee2e6; }
.assignment-card-detail .summary-content { display: flex; align-items: center; gap: 20px; }
.assignee-name { font-size: 1.1em; font-weight: 500; }
.assignee-amount { font-size: 1em; color: #495057; }
.assignment-card-detail .details-content { padding: 15px 20px; border-top: 1px solid #dee2e6; }
.assignment-card-detail .details-content p { margin: 8px 0; }
.payment-status { font-weight: bold; font-size: 0.85em; padding: 4px 10px; border-radius: 12px; color: #fff; text-align: center; }
.payment-status.paid { background-color: #28a745; }
.payment-status.unpaid { background-color: #dc3545; }
.profit-positive { color: #28a745; font-weight: bold; }
.profit-negative { color: #dc3545; font-weight: bold; }
.status-badge { font-weight: bold; font-size: 0.9em; padding: 3px 10px; border-radius: 12px; color: #fff; }
.status-badge.status-paid { background-color: #28a745; }
.status-badge.status-unpaid { background-color: #dc3545; }
/* --- 待辦清單 --- */
.task-list { list-style-type: none; padding: 0; }
.task-item { display: flex; align-items: center; padding: 10px; border: 1px solid #ddd; border-radius: 4px; margin-bottom: 8px; background-color: #fff; }
.task-item.completed { background-color: #f0f0f0; opacity: 0.7; }
.task-item.completed .task-description { text-decoration: line-through; color: #888; }
.drag-handle { cursor: grab; margin-right: 15px; color: #aaa; font-weight: bold; }
.task-checkbox { margin-right: 10px; }
.task-description { flex-grow: 1; }
.task-assignee { margin: 0 15px; font-size: 0.9em; color: #555; background-color: #eee; padding: 2px 6px; border-radius: 4px; white-space: nowrap; max-width: 200px; overflow: hidden; text-overflow: ellipsis; }
.task-due-date { font-size: 0.9em; color: #888; white-space: nowrap; }
.delete-task-btn { background: none; border: none; color: #dc3545; font-size: 1.5em; cursor: pointer; margin-left: 10px; padding: 0 5px; }
.edit-task-btn { font-size: 0.8em; padding: 4px 8px; margin-left: auto; }
#add-task-area { margin-top: 20px; }
#add-task-form, #edit-task-form { background-color: #f8f9fa; padding: 15px; border-radius: 5px; border: 1px solid #dee2e6; }
select[multiple] { height: 120px; padding: 5px; }
select[multiple] option { padding: 5px; }
/* --- 編輯待辦 Modal --- */
.modal-overlay { position: fixed; top: 0; left: 0; width: 100%; height: 100%; background-color: rgba(0,0,0,0.5); display: flex; justify-content: center; align-items: center; z-index: 1000; }
.modal-content { background-color: #fff; padding: 20px 30px; border-radius: 8px; width: 90%; max-width: 500px; box-shadow: 0 5px 15px rgba(0,0,0,0.3); }
.modal-actions { margin-top: 20px; text-align: right; }
/* --- 名單頁面樣式 --- */
.internal-user-list { display: grid; grid-template-columns: repeat(auto-fill, minmax(250px, 1fr)); gap: 15px; }
.user-card { display: flex; justify-content: space-between; align-items: center; padding: 12px 15px; background-color: #f8f9fa; border: 1px solid #dee2e6; border-radius: 5px; }
.user-name { font-weight: 500; }
.user-role-badge { font-size: 0.8em; font-weight: bold; padding: 3px 8px; border-radius: 10px; background-color: #6c757d; color: white; }
.contact-list { display: grid; grid-template-columns: repeat(auto-fill, minmax(350px, 1fr)); gap: 15px; }
.contact-card details { background: #f9f9f9; border: 1px solid #dee2e6; border-radius: 5px; overflow: hidden; }
.contact-card summary { display: flex; justify-content: space-between; align-items: center; padding: 15px 20px; cursor: pointer; list-style: none; transition: background-color 0.2s; }
.contact-card summary::-webkit-details-marker { display: none; }
.contact-card summary:hover { background-color: #f1f3f5; }
.contact-card .summary-content { display: flex; flex-direction: column; }
.contact-name { font-weight: bold; font-size: 1.2em; color: #343a40; }
.contact-tagline { color: #868e96; font-size: 0.9em; margin-top: 2px; }
.contact-card .details-content { padding: 0 20px 20px 20px; border-top: 1px solid #dee2e6; }
.contact-card .details-content p { margin: 10px 0; line-height: 1.5; }
.contact-card .details-content strong { color: #495057; }
.card-hr { border: 0; border-top: 1px solid #e9ecef; margin: 15px 0; }
.contact-actions { margin-top: 15px; text-align: right; }
.filter-controls { display: flex; gap: 15px; margin-bottom: 20px; }
.contact-badge { padding: 2px 8px; border-radius: 10px; color: white; font-size: 0.8em; }
.badge-接案者 { background-color: #007bff; } .badge-客戶 { background-color: #28a745; } .badge-中性 { background-color: #6c757d; }
/* --- 日曆頁面樣式 --- */
.calendar-layout { display: grid; grid-template-columns: 1fr 300px; gap: 25px; }
@media (max-width: 992px) { .calendar-layout { grid-template-columns: 1fr; } #mini-calendar { order: -1; } }
#mini-calendar { border: 1px solid #ddd; padding: 10px; border-radius: 5px; background: #fff; }
#main-calendar { border: 1px solid #ddd; padding: 20px; border-radius: 5px; background: #fff; }
.has-event-day { background-color: #ffeedd !important; font-weight: bold; }
.fc-event { cursor: pointer; }
#mini-calendar .fc-toolbar-title { text-align: center; line-height: 1.2; }
#mini-calendar .fc-col-header-cell-cushion { padding: 5px 0; line-height: 1.3; text-align: center; }
/* --- 編輯案件頁面的樣式 --- */
.assignment-list { display: grid; grid-template-columns: repeat(auto-fill, minmax(400px, 1fr)); gap: 15px; margin-bottom: 20px; }
.assignment-card details { background: #fff; border: 1px solid #dee2e6; border-radius: 5px; overflow: hidden; }
.assignment-card summary { display: flex; justify-content: space-between; align-items: center; padding: 12px 18px; cursor: pointer; list-style: none; transition: background-color 0.2s; }
.assignment-card summary::-webkit-details-marker { display: none; }
.assignment-card summary.type-internal { background-color: #e7f5ff; }
.assignment-card summary.type-external { background-color: #f1f3f5; }
.assignment-card summary:hover { background-color: #dee2e6; }
.assignment-card .summary-content { display: flex; align-items: center; gap: 20px; }
.assignee-name { font-size: 1.1em; font-weight: 500; }
.assignee-amount { font-size: 1em; color: #495057; }
.assignment-card .details-content { padding: 20px; background-color: #fdfdfd; border-top: 1px solid #dee2e6; }
.assignment-card .detail-grid.compact-grid { grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 20px; margin-bottom: 10px; }
.assignment-card .detail-item { padding: 0; background: none; }
.assignment-card .detail-item label { margin-bottom: 6px; display: block; font-size: 0.9em; color: #6c757d; }
.assignment-card textarea[name^="assignment_notes"] { min-height: 40px; }
.checkbox-item { display: flex; align-items: center; gap: 8px; padding-top: 25px; }
.checkbox-item input[type="checkbox"] { width: auto; margin-bottom: 0; }
#selected-assignees-container { margin-top: 10px; display: flex; flex-wrap: wrap; gap: 8px; }
.selected-assignee-tag { background-color: #007bff; color: white; padding: 5px 10px; border-radius: 15px; font-size: 0.9em; display: flex; align-items: center; }
.selected-assignee-tag button { background: none; border: none; color: white; margin-left: 8px; font-size: 1.2em; cursor: pointer; padding: 0; line-height: 1; }
#assignee-search-container { position: relative; }
#assignee-search-results { position: absolute; width: 100%; background-color: #fff; border: 1px solid #ccc; border-top: none; border-radius: 0 0 4px 4px; z-index: 10; max-height: 200px; overflow-y: auto; display: none; }
.search-result-item { padding: 10px; cursor: pointer; }
.search-result-item:hover { background-color: #f0f0f0; }
/* --- 溝通紀錄 (Comments) --- */
#comment-section { margin-top: 20px; }
#comment-list {
    margin-bottom: 20px;
    max-height: 400px;
    overflow-y: auto;
    border: 1px solid #e9ecef;
    padding: 15px;
    border-radius: 5px;
    background-color: #f8f9fa;
}
.comment-item {
    padding-bottom: 10px;
    margin-bottom: 10px;
    border-bottom: 1px solid #dee2e6;
}
.comment-item:last-child {
    border-bottom: none;
    margin-bottom: 0;
    padding-bottom: 0;
}
.comment-meta {
    font-size: 0.9em;
    color: #6c757d;
    margin-bottom: 5px;
}
.comment-meta strong {
    color: #343a40;
}
.comment-timestamp {
    float: right;
}
.comment-content {
    line-height: 1.5;
    margin-top: 5px;
    padding-left: 5px; /* 增加一點內縮，讓視覺更清晰 */
    word-wrap: break-word; /* 確保長單字或連結能自動換行 */
}
#add-comment-area textarea {
    min-height: 80px;
}
/* --- 儀表板佈局和資訊區塊樣式 --- */
.dashboard-container {
    display: grid;
    grid-template-columns: 1fr; /* Default to single column */
    gap: 25px;
}
@media (min-width: 992px) {
    .dashboard-container {
        grid-template-columns: 1fr 320px; /* Main content and sidebar */
    }
}
.dashboard-main {
    grid-column: 1 / -1; /* Span all columns by default */
}
@media (min-width: 992px) {
    .dashboard-main {
        grid-column: 1 / 2;
    }
}
.dashboard-sidebar {
    grid-column: 1 / -1; /* Span all columns by default */
    display: flex;
    flex-direction: column;
    gap: 20px;
}
@media (min-width: 992px) {
    .dashboard-sidebar {
        grid-column: 2 / 3;
    }
}
.widget {
    background-color: #fff;
    border: 1px solid #e9ecef;
    border-radius: 5px;
    padding: 15px 20px;
}
.widget h3 {
    margin-top: 0;
    font-size: 1.2em;
    border-bottom: 1px solid #eee;
    padding-bottom: 10px;
    margin-bottom: 15px;
}
.widget ul {
    list-style-type: none;
    padding: 0;
    margin: 0;
}
.widget li {
    padding: 10px 0;
    border-bottom: 1px solid #f1f3f5;
}
.widget li:last-child {
    border-bottom: none;
    padding-bottom: 0;
}
.widget a {
    text-decoration: none;
    color: #343a40;
    font-weight: 500;
}
.widget a:hover {
    color: #0056b3;
}
.widget .meta {
    font-size: 0.85em;
    color: #6c757d;
    display: block;
    margin-top: 4px;
}
.kpi-widget .kpi-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    font-size: 1.05em;
    padding: 10px 0;
}
.kpi-widget .kpi-value {
    font-weight: bold;
    font-family: monospace;
    font-size: 1.1em;
}

/* --- RWD (Responsive Web Design) --- */
@media (max-width: 768px) {
    .filter-controls {
        flex-direction: column; /* 將篩選器改為垂直堆疊 */
        align-items: stretch; /* 讓子項目填滿寬度 */
    }
    .dashboard-header {
        flex-direction: column; /* 將儀表板標題也改為垂直堆疊 */
        align-items: flex-start;
        gap: 15px;
    }
    /* 讓案件卡片在更窄的螢幕上也能正常顯示 */
    .dashboard-grid {
        grid-template-columns: 1fr;
    }
    /* --- 導覽列手機版樣式 --- */
    .main-nav {
        flex-direction: column; /* 將連結改為垂直堆疊 */
        align-items: flex-start; /* 讓連結從左邊對齊 */
        padding: 10px;
    }
    .main-nav a {
        width: 100%; /* 讓每個連結佔滿整行寬度 */
        padding: 8px 5px; /* 增加點擊區域和上下間距 */
        border-bottom: 1px solid #f1f3f5; /* 在連結之間增加分隔線 */
        margin: 0; /* 清除舊的 margin */
        border-radius: 4px;
        box-sizing: border-box; /* 確保 padding 不會讓寬度超標 */
        text-align: center; /* 文字置中 */
    }
    .main-nav a:last-child {
        border-bottom: none; /* 最後一個連結不需要分隔線 */
    }
    .main-nav a:hover {
        background-color: #f8f9fa; /* 增加觸控/滑鼠懸停效果 */
        text-decoration: none;
    }
}