/* Codex maintenance note: comments, logging, and try/catch coverage are added without changing styles. */
/* =============================================
   全域設定
   ============================================= */

body:not(.login-page) {
    font-family: 'Segoe UI', 'Microsoft JhengHei', sans-serif;
    background-color: #f4f6f9;
}

/* =============================================
   登入頁（雙欄卡片、淺色漸層背景）
   ============================================= */
body.login-page {
    font-family: 'Segoe UI', 'Microsoft JhengHei', sans-serif;
    margin: 0;
    min-height: 100vh;
    background-color: #cfe5f8;
    background-image: linear-gradient(90deg, #b8daf5 0%, #f5f9fc 42%, #c5ebd8 100%);
    background-repeat: no-repeat;
    background-size: cover;
    background-attachment: fixed;
}

.login-layout {
    position: relative;
}

.login-shell {
    width: 100%;
    max-width: 56rem;
    border-radius: 0.75rem;
}

.login-shell__decor {
    position: relative;
    background: linear-gradient(180deg, #eef2f6 0%, #e4e9ef 100%);
    min-height: 22rem;
    overflow: hidden;
    isolation: isolate;
}

.login-shell__decor-inner {
    min-height: 22rem;
    overflow: hidden;
    position: relative;
}

.login-decor-line {
    position: absolute;
    bottom: 0;
    width: 3px;
    border-radius: 3px;
    opacity: 0.55;
}

.login-decor-line--a {
    left: 18%;
    height: 55%;
    background: linear-gradient(0deg, #1e9c6b, #7ec8a3);
}

.login-decor-line--b {
    left: 42%;
    height: 70%;
    background: linear-gradient(0deg, #2b7ce0, #8ab8f0);
}

.login-decor-line--c {
    left: 68%;
    height: 48%;
    background: linear-gradient(0deg, #1e9c6b, #5cb88a);
}

.login-decor-icon {
    position: absolute;
    display: flex;
    align-items: center;
    justify-content: center;
    width: 2.75rem;
    height: 2.75rem;
    border-radius: 50%;
    color: #fff;
    font-size: 1.1rem;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.12);
}

.login-decor-icon--1 {
    top: 12%;
    left: max(0.5rem, 8%);
    background: linear-gradient(145deg, #2b7ce0, #1a5fbf);
}

.login-decor-icon--2 {
    top: 28%;
    left: 48%;
    background: linear-gradient(145deg, #1e9c6b, #157a55);
}

.login-decor-icon--3 {
    top: 48%;
    left: max(0.5rem, 18%);
    background: linear-gradient(145deg, #2b7ce0, #1a5fbf);
}

.login-decor-icon--4 {
    top: 58%;
    left: 58%;
    background: linear-gradient(145deg, #1e9c6b, #157a55);
}

.login-decor-icon--5 {
    top: 72%;
    left: 32%;
    background: linear-gradient(145deg, #2b7ce0, #1a5fbf);
}

.login-decor-icon--6 {
    top: 18%;
    left: 68%;
    background: linear-gradient(145deg, #1e9c6b, #157a55);
}

.login-shell__form {
    background: #fff;
}

.login-shell__form-body {
    max-width: 28rem;
}

@media (max-width: 991.98px) {
    .login-shell__form-body {
        margin-left: auto;
        margin-right: auto;
    }
}

.login-form-grid {
    display: grid;
    grid-template-columns: minmax(4.5rem, auto) 1fr 4.25rem;
    grid-template-rows: auto auto auto auto auto;
    grid-template-areas:
        "li ii btn"
        "lu iu btn"
        "lp ip btn"
        "lc ic ."
        "ll il .";
    gap: 0.75rem 1rem;
    align-items: start;
}

.login-grid-label-inst {
    grid-area: li;
}

.login-grid-input-inst {
    grid-area: ii;
    min-width: 0;
}

.login-grid-label-user {
    grid-area: lu;
}

.login-grid-input-user {
    grid-area: iu;
    min-width: 0;
}

.login-grid-label-pwd {
    grid-area: lp;
}

.login-grid-input-pwd {
    grid-area: ip;
    min-width: 0;
}

.login-grid-label-captcha {
    grid-area: lc;
    align-self: center;
}

.login-grid-input-captcha {
    grid-area: ic;
    min-width: 0;
    flex-wrap: nowrap;
}

.login-grid-input-captcha .form-control {
    width: 11rem;
    min-width: 11rem;
}

.login-grid-label-lang {
    grid-area: ll;
    align-self: center;
}

.login-grid-input-lang {
    grid-area: il;
    min-width: 0;
}

.login-captcha-img {
    height: 2.75rem;
    width: auto;
    max-width: 9.5rem;
    border: 1px solid #dee2e6;
    border-radius: 0.25rem;
    background: #fff;
    vertical-align: middle;
    flex-shrink: 0;
}

@media (max-width: 575.98px) {
    .login-grid-input-captcha {
        flex-wrap: wrap;
    }
}

.login-grid-btn {
    grid-area: btn;
    align-self: center;
    justify-self: center;
    border-radius: 0.35rem;
    border: none;
    background: linear-gradient(180deg, #2b7ce0 0%, #1a5fbf 100%);
    color: #fff !important;
    padding: 0.45rem 0.25rem;
    width: 4rem;
    height: 5.5rem;
    min-height: 5.5rem;
    box-shadow: 0 2px 6px rgba(26, 95, 191, 0.35);
    margin-top: 0;
}

.login-grid-btn,
.login-grid-btn i,
.login-grid-btn span {
    color: #fff !important;
}

.login-grid-btn:hover,
.login-grid-btn:focus-visible {
    color: #fff !important;
    filter: brightness(1.06);
}

.login-grid-btn:focus-visible {
    box-shadow: 0 0 0 0.2rem rgba(43, 124, 224, 0.35);
}

.login-footer {
    background: transparent;
}

.login-lang-floater {
    display: flex;
    justify-content: flex-start;
    margin-top: 0.15rem;
}

.login-toast-wrap {
    z-index: 1080;
}

.login-error-toast {
    min-width: 20rem;
    max-width: min(92vw, 30rem);
    background-color: #1f1f1f;
    color: #fff;
    border-radius: 0.75rem;
}

.login-error-toast__header {
    background-color: #1f1f1f;
    border-bottom: 1px solid rgba(255, 255, 255, 0.16);
}

.login-error-toast .toast-body {
    color: #f8f9fa;
}

@media (max-width: 767.98px) {
    .login-form-grid {
        grid-template-columns: 1fr;
        grid-template-areas:
            "li"
            "ii"
            "lu"
            "iu"
            "lp"
            "ip"
            "btn"
            "lc"
            "ic"
            "ll"
            "il";
    }

    .login-grid-label-inst,
    .login-grid-label-user,
    .login-grid-label-pwd,
    .login-grid-label-captcha,
    .login-grid-label-lang {
        text-align: start !important;
    }

    .login-grid-btn {
        min-height: 3rem;
        width: 100%;
        flex-direction: row !important;
        justify-content: center !important;
        margin-top: 0;
    }

    .login-shell__form-body {
        max-width: none;
    }
}

/* =============================================
   主要佈局 (Sidebar + Content)
   ============================================= */
.wrapper {
    display: flex;
    width: 100%;
    min-height: 100vh;
}

/* =============================================
   側邊欄
   ============================================= */
#sidebar {
    width: 176px;
    min-height: 100vh;
    background: #ffffff;
    color: #000000;
    border-right: 1px solid #e2e8f0;
    transition: all 0.3s ease;
    flex-shrink: 0;
    position: sticky;
    top: 0;
    height: 100vh;
    overflow-y: auto;
}

#sidebar::-webkit-scrollbar {
    width: 8px;
}

#sidebar::-webkit-scrollbar-thumb {
    background: #cbd5e1;
    border-radius: 4px;
}

#sidebar::-webkit-scrollbar-track {
    background: transparent;
}

#sidebar.collapsed {
    width: 0;
    overflow: hidden;
    border-right: none;
}

.sidebar-header {
    padding: 1rem 1rem 0.85rem;
    border-bottom: 1px solid #e2e8f0;
}

.sidebar-header .logo {
    font-size: 1.125rem;
    font-weight: 600;
    color: #000000;
    letter-spacing: 0.02em;
    line-height: 1.35;
}

.sidebar-brand-panel {
    padding: 0.85rem 0.75rem 0.65rem;
    border-bottom: 1px solid #e2e8f0;
    background: #ffffff;
}

.sidebar-brand-image-wrap {
    margin-bottom: 0.65rem;
    display: flex;
    align-items: center;
    gap: 0.45rem;
    min-height: 2.8rem;
}

.sidebar-brand-icon {
    display: block;
    width: 1.6rem;
    height: 1.6rem;
    object-fit: contain;
    flex: 0 0 auto;
}

.sidebar-brand-text {
    font-size: 1.55rem;
    font-weight: 700;
    color: #111827;
    line-height: 1;
}

.sidebar-user-panel {
    display: flex;
    align-items: center;
    gap: 0.7rem;
    padding: 0.75rem;
    border-radius: 0.85rem;
    background: linear-gradient(135deg, #38bdf8, #0ea5e9);
    color: #ffffff;
}

.sidebar-user-avatar {
    width: 3rem;
    height: 3rem;
    object-fit: cover;
    border-radius: 999px;
    background: rgba(255, 255, 255, 0.2);
    border: 2px solid rgba(255, 255, 255, 0.45);
    flex: 0 0 auto;
}

.sidebar-user-name {
    font-size: 1rem;
    font-weight: 600;
    line-height: 1.25;
    word-break: break-word;
}

.sidebar-nav {
    padding: 0.5rem 0 1rem;
    margin: 0;
}

.sidebar-nav .nav-item > .nav-link {
    display: flex;
    align-items: center;
    padding: 0.4rem 0.7rem;
    margin: 0 0.35rem;
    color: #000000;
    text-decoration: none;
    font-size: 0.9rem;
    transition: background-color 0.15s, color 0.15s;
    gap: 0.5rem;
    border-radius: 0.375rem;
    border-left: none;
}

.sidebar-nav .nav-item > .nav-link:hover {
    background-color: #f1f5f9;
    color: #000000;
}

.sidebar-nav .nav-item > .nav-link.active {
    background-color: #e2e8f0;
    color: #000000;
    font-weight: 500;
}

.sidebar-nav .nav-item > .nav-link:not(.collapsed)[aria-expanded="true"] {
    background-color: #f8fafc;
    color: #000000;
}

.nav-icon {
    width: 1.1rem;
    text-align: center;
    flex-shrink: 0;
    color: #000000;
    font-size: 0.9rem;
}

.sidebar-nav .nav-item > .nav-link:hover .nav-icon,
.sidebar-nav .nav-item > .nav-link.active .nav-icon,
.sidebar-nav .nav-item > .nav-link:not(.collapsed)[aria-expanded="true"] .nav-icon {
    color: #000000;
}

.arrow {
    margin-left: auto;
    font-size: 0.7rem;
    color: #000000;
    transition: transform 0.2s;
}

.nav-link:not(.collapsed) .arrow {
    transform: rotate(180deg);
}

/* 子選單（圖二：縮排、無圖示、目前頁淺灰圓角底） */
.sub-menu {
    background-color: transparent;
    padding: 0.2rem 0 0.35rem;
}

.sub-menu .sub-link {
    display: flex;
    align-items: center;
    gap: 0;
    padding: 0.34rem 0.7rem 0.34rem 1.05rem;
    margin: 0.1rem 0.5rem;
    color: #000000;
    font-size: 0.9rem;
    text-decoration: none;
    transition: background-color 0.15s, color 0.15s;
    border-radius: 0.375rem;
    border-left: none;
}

.sub-menu .sub-link .nav-icon {
    display: none;
}

.sub-menu .sub-link:hover {
    color: #000000;
    background-color: #f1f5f9;
}

.sub-menu .sub-link.active {
    color: #000000;
    background-color: #e5e7eb;
    font-weight: 400;
}

/* =============================================
   主內容區
   ============================================= */
#content {
    flex: 1;
    min-width: 0;
    display: grid;
    grid-template-columns: minmax(0, 1fr) 3.2rem;
    grid-template-rows: auto 1fr auto;
}

.top-navbar {
    height: 60px;
    position: sticky;
    top: 0;
    z-index: 100;
    grid-column: 1 / -1;
    grid-row: 1;
}

.main-content {
    flex: 1;
    grid-column: 1;
    grid-row: 2;
}

.site-footer {
    grid-column: 1 / -1;
    grid-row: 3;
    padding: 0.6rem 1rem;
    border-top: 1px solid #e5e7eb;
    background: #f8fafc;
    color: #6b7280;
    font-size: 0.82rem;
    text-align: center;
}

.main-content-primary {
    min-width: 0;
}

.embedded-content {
    min-height: 100vh;
    background: #f3f4f6;
}

.main-content.favorite-preview-open {
    display: block;
}

.main-content.favorite-preview-open .main-content-primary {
    display: none;
}

/* =============================================
   卡片
   ============================================= */
.card {
    border-radius: 0.75rem;
    border: 1px solid #e2e8f0;
}

.card-header {
    border-radius: 0.75rem 0.75rem 0 0 !important;
    padding: 0.85rem 1.25rem;
}

/* =============================================
   表格
   ============================================= */

/* =============================================
   CaseList 篩選區字級（對齊雙層 small：0.875 * 0.875 = 0.7656rem）
   ============================================= */
.case-list-filters {
    font-size: 0.7656rem;
}

.case-list-filters .form-label.small {
    font-size: inherit;
}

.case-list-filters .form-control,
.case-list-filters .form-select,
.case-list-filters .input-group-text {
    font-size: inherit !important;
}

.case-list-filters .form-control-sm,
.case-list-filters .form-select-sm {
    font-size: inherit !important;
}

.case-list-filters .form-check-label {
    font-size: inherit;
    line-height: 1.2;
}

.case-list-filters .form-check-input {
    width: 0.9em;
    height: 0.9em;
    margin-top: 0;
}

.case-list-filters label.form-check-label.gap-2 {
    column-gap: 0.35rem !important;
}

/* 個案清單：縮小「篩檢項目」切換按鈕（字級/高度約縮小 2 倍） */
.case-list-page .case-list-screening-toggle.btn {
    font-size: 0.72rem;
    line-height: 1.05;
    padding: 0.18rem 0.45rem;
    border-radius: 0.45rem;
}

.case-list-page .case-list-screening-toggle .fas {
    font-size: 0.85em;
}

/* 個案清單：兩行篩選列更緊湊（對齊圖二） */
.case-list-page .case-list-query-panel .case-list-filters {
    font-size: 0.72rem;
    line-height: 1.1;
}

.case-list-page .case-list-query-panel .form-control-sm,
.case-list-page .case-list-query-panel .form-select-sm {
    padding-top: 0.15rem;
    padding-bottom: 0.15rem;
    min-height: 1.65rem;
    line-height: 1.1;
}

.case-list-page .case-list-query-panel .btn.btn-sm {
    padding: 0.22rem 0.55rem;
    line-height: 1.1;
}

.case-list-page .case-list-query-row {
    row-gap: 0.35rem;
}

/* 篩選區：左欄兩列篩選 + 右欄（上：筆數與第一列同高對齊；下：按鈕與查詢左緣與筆數左緣對齊） */
.case-list-page .case-list-filter-grid {
    display: grid;
    grid-template-columns: minmax(0, 1fr) max-content;
    column-gap: 1rem;
    align-items: stretch;
}

.case-list-page .case-list-filter-grid__main {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
    min-width: 0;
}

.case-list-page .case-list-filter-grid__rail {
    display: flex;
    flex-direction: column;
    justify-content: space-between;
    align-items: flex-start;
    min-width: 0;
}

.case-list-page .case-list-filter-grid__actions {
    flex-wrap: wrap;
}

@media (max-width: 767.98px) {
    .case-list-page .case-list-filter-grid {
        grid-template-columns: 1fr;
    }

    .case-list-page .case-list-filter-grid__rail {
        flex-direction: row;
        flex-wrap: wrap;
        align-items: center;
        width: 100%;
        justify-content: flex-start;
        column-gap: 0.75rem;
        row-gap: 0.35rem;
    }
}

.case-list-page .case-list-inline-label {
    white-space: nowrap;
    line-height: 1.05;
}

.case-list-page .case-list-query-control--date {
    width: 135px;
}

.case-list-page .case-list-query-control--dept,
.case-list-page .case-list-query-control--type,
.case-list-page .case-list-query-control--status {
    width: 160px;
}

.case-list-page .case-list-query-control--county {
    width: 140px;
}

.case-list-page .case-list-query-control--town {
    width: 160px;
}

.case-list-page .case-list-query-keyword {
    flex: 1 1 auto;
    min-width: 260px;
}

/* 列表筆數：右欄第一列、字級略大於篩選區預設小字（左緣與下方查詢同欄對齊） */
.case-list-page .case-list-filter-grid__rail .case-list-list-total__text {
    color: #212529;
    white-space: nowrap;
    font-size: 0.95rem;
    font-weight: 600;
    line-height: 1.35;
}

.case-list-page .case-list-grid .case-list-col-lastvisit {
    min-width: 7.5rem;
    max-width: 16rem;
}

.case-list-page .case-list-grid tbody tr.case-list-grid-row {
    cursor: pointer;
}

/* 個案清單：篩檢項目（checkbox）區塊底色 */
.case-list-page .case-list-screening-items-panel {
    background-color: var(--bs-tertiary-bg, #f8f9fa);
    border: 1px solid rgba(0, 0, 0, 0.06);
    border-radius: 0.6rem;
    padding: 0.35rem 0.5rem;
}
.table th {
    font-size: 0.85rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    color: #64748b;
    padding: 0.85rem 1rem;
}

.table td {
    padding: 0.75rem 1rem;
    vertical-align: middle;
}

/* =============================================
   篩檢項目維護：表頭藍底、單列
   ============================================= */
.table.screening-items-grid thead.table-head-screening th {
    white-space: nowrap;
    background-color: #0d6efd;
    color: #fff;
    font-size: 0.78rem;
    font-weight: 600;
    text-transform: none;
    letter-spacing: 0;
    border-color: rgba(255, 255, 255, 0.2);
    vertical-align: middle;
    padding: 0.65rem 0.75rem;
}

.table.screening-items-grid thead.table-head-screening th:first-child {
    border-top-left-radius: 0.35rem;
}

.table.screening-items-grid thead.table-head-screening th:last-child {
    border-top-right-radius: 0.35rem;
}

.table.screening-items-grid tbody td {
    white-space: nowrap;
    font-size: 0.74rem;
    line-height: 1.25;
    padding: 0.45rem 0.5rem;
}

.table.screening-items-grid tbody td .form-control,
.table.screening-items-grid tbody td .form-select,
.table.screening-items-grid tbody td .btn,
.table.screening-items-grid tbody td .badge {
    font-size: 0.72rem;
}

.table.screening-items-grid tbody td.grid-editor-cell {
    padding: 0.35rem 0.35rem;
}

.table.screening-items-grid tbody td.grid-editor-cell .grid-editor-box {
    min-height: 1.95rem;
    padding: 0.25rem 0.5rem;
    border: 1px solid #cbced4;
    border-radius: 0.4rem;
    background-color: #f3f3f5;
    display: flex;
    align-items: center;
    overflow: hidden;
}

.table.screening-items-grid tbody td.condition-icon-cell {
    background-color: #ffffff;
    padding: 0.35rem 0.35rem;
}

.table.screening-items-grid tbody td.condition-icon-cell .condition-icon-button {
    border: none;
    background: transparent;
    padding: 0;
    line-height: 1;
    cursor: pointer;
}

.table.screening-items-grid tbody td.condition-icon-cell .condition-gear-icon {
    width: 1rem;
    height: 1rem;
    display: inline-block;
    vertical-align: middle;
}

.table.screening-items-grid tbody td.text-flag-cell {
    background-color: #ffffff;
    padding: 0.35rem 0.35rem;
    white-space: nowrap;
}

.table.screening-items-grid tbody td.text-flag-cell .text-flag-row {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.45rem;
    min-height: 1.2rem;
}

.table.screening-items-grid tbody td.text-flag-cell .text-edit-icon-button {
    border: none;
    background: transparent;
    padding: 0;
    color: #212529;
    line-height: 1;
    cursor: pointer;
}

.table.screening-items-grid tbody td.text-flag-cell .text-edit-icon-button i {
    font-size: 0.95rem;
}

.screening-items-page .alert.screening-formula-hint {
    background-color: #e7f1ff;
    border-color: #b6d4fe;
    color: #084298;
}

/* 篩檢頁字級：對齊 Figma Make 常用 token（--text-base 1rem、--text-sm 0.875rem、--text-xs 0.75rem） */
.screening-items-page h4.screening-items-heading {
    font-size: 1rem;
    line-height: 1.45;
    font-weight: 700;
}

.screening-items-page .screening-items-heading-icon {
    font-size: 0.9em;
    vertical-align: -0.05em;
}

.screening-items-page p.screening-items-subtitle {
    font-size: 0.75rem;
    line-height: 1.45;
    font-weight: 400;
}

.screening-items-page .screening-items-formula-text {
    font-size: 0.75rem;
    line-height: 1.5;
}

.screening-items-page .alert.screening-formula-hint .fa-circle-info {
    font-size: 0.75rem;
}

.screening-items-page .screening-items-section-title {
    font-size: 0.875rem;
    line-height: 1.45;
}

.screening-items-page .screening-items-section-desc {
    font-size: 0.8125rem;
    line-height: 1.45;
}

.screening-items-page .screening-items-hint-title {
    font-size: 0.875rem;
    line-height: 1.45;
}

.screening-items-page .screening-items-hint-body {
    font-size: 0.8125rem;
    line-height: 1.5;
}

.screening-items-page .screening-items-hint-grid .col-md-4 {
    display: flex;
    align-items: flex-start;
}

.screening-items-page .screening-items-hint-card {
    background-color: #e7f1ff;
    border: 1px solid #b6d4fe;
    border-radius: 0.5rem;
}

.screening-condition-modal .modal-body {
    padding-top: 1rem;
}

.screening-condition-modal .screening-condition-modal-title {
    font-weight: 700;
}

.screening-condition-modal .screening-condition-modal-desc {
    font-size: 0.9rem;
    line-height: 1.45;
    margin-top: 0.15rem;
}

.screening-condition-modal .condition-row {
    display: flex;
    align-items: center;
    gap: 0.6rem;
}

.screening-condition-modal .condition-label {
    min-width: 110px;
    margin-bottom: 0;
    color: #495057;
    font-size: 1.05rem;
    font-weight: 500;
    white-space: nowrap;
}

.screening-condition-modal .condition-inline-input {
    width: 10rem;
    max-width: 10rem;
}

.screening-condition-modal .condition-mini-input {
    width: 5.6rem;
    max-width: 5.6rem;
}

.screening-condition-modal .condition-inline-text {
    color: #6c757d;
    white-space: nowrap;
}

.screening-condition-modal .condition-history-row {
    gap: 0.45rem;
}

.screening-condition-modal .form-control,
.screening-condition-modal .form-select,
.screening-condition-modal .input-group-text {
    background-color: #f3f3f5;
    border-color: #cbced4;
}

.screening-condition-modal .form-check-input {
    margin-top: 0;
}

.screening-condition-modal .form-check-label {
    color: #495057;
}

.screening-items-page #screeningModal .modal-body .form-label,
.screening-items-page #screeningModal .modal-body .form-check-label {
    font-size: 0.82rem;
    line-height: 1.3;
}

.screening-items-page #screeningModal .modal-body .form-control,
.screening-items-page #screeningModal .modal-body .form-select {
    min-height: 2rem;
    padding: 0.2rem 0.5rem;
    font-size: 0.8rem;
    background-color: #f3f3f5;
    border: 1px solid #cbced4;
    border-radius: 0.4rem;
}

.screening-items-page #screeningModal .modal-body .form-control:focus,
.screening-items-page #screeningModal .modal-body .form-select:focus {
    border-color: #86b7fe;
    box-shadow: 0 0 0 0.2rem rgba(13, 110, 253, 0.15);
}

.screening-items-page #screeningModal .screening-icon-btn {
    min-width: 2.1rem;
    min-height: 2rem;
    padding: 0.25rem 0.45rem;
}

.screening-items-page #screeningModal .screening-icon-btn .condition-gear-icon {
    width: 0.95rem;
    height: 0.95rem;
}

/* 服務方案 Modal：與篩檢列表 .grid-editor-cell / .grid-editor-box 同視覺（#f3f3f5、圓角框） */
.service-plans-page #servicePlanModal .modal-body .grid-editor-cell {
    padding: 0;
}

.service-plans-page #servicePlanModal .modal-body .grid-editor-cell .grid-editor-box {
    min-height: 1.95rem;
    padding: 0.25rem 0.5rem;
    border: 1px solid #cbced4;
    border-radius: 0.4rem;
    background-color: #f3f3f5;
    display: flex;
    align-items: center;
    overflow: hidden;
}

.service-plans-page #servicePlanModal .modal-body .grid-editor-cell .grid-editor-box.grid-editor-box--multiline {
    display: block;
    align-items: stretch;
    overflow: visible;
    min-height: auto;
}

.service-plans-page #servicePlanModal .modal-body .grid-editor-box:focus-within {
    border-color: #86b7fe;
    box-shadow: 0 0 0 0.2rem rgba(13, 110, 253, 0.15);
}

.service-plans-page #servicePlanModal .modal-body .grid-editor-box .form-control,
.service-plans-page #servicePlanModal .modal-body .grid-editor-box .form-select {
    flex: 1 1 auto;
    min-width: 0;
    border: none;
    background-color: transparent;
    box-shadow: none;
    min-height: calc(1.95rem - 0.5rem);
    padding-top: 0.15rem;
    padding-bottom: 0.15rem;
}

.service-plans-page #servicePlanModal .modal-body .grid-editor-box--multiline .form-control {
    width: 100%;
    min-height: 4.5rem;
    resize: vertical;
}

.service-plans-page #servicePlanModal .modal-body .grid-editor-box .form-control:focus,
.service-plans-page #servicePlanModal .modal-body .grid-editor-box .form-select:focus {
    box-shadow: none;
}

.service-plans-page #servicePlanModal .modal-body .grid-editor-box .form-control:read-only {
    background-color: transparent;
}

/* 服務方案列表：各欄位統一字型與字級（含方案代碼/徽章） */
.service-plans-page .service-plans-grid th,
.service-plans-page .service-plans-grid td,
.service-plans-page .service-plans-grid .badge {
    font-family: 'Segoe UI', 'Microsoft JhengHei', sans-serif;
    font-size: 0.85rem;
    font-weight: 400;
}

/* 個案清單：列表字級與服務方案一致 */
.case-list-page .case-list-grid th,
.case-list-page .case-list-grid td,
.case-list-page .case-list-grid .badge {
    font-family: 'Segoe UI', 'Microsoft JhengHei', sans-serif;
    font-size: 0.85rem;
    font-weight: 400;
}

/* 個案清單：表頭文字改深（table-light 預設偏灰） */
.case-list-page .case-list-grid > thead > tr > th {
    color: #212529;
}

/* 個案清單：縮小頁首（讓 DBGrid 可視列數更多） */
.case-list-page .case-list-title-card .card-body {
    padding-top: 0.5rem;
    padding-bottom: 0.5rem;
    padding-left: 0.75rem;
    padding-right: 0.75rem;
}

.case-list-page .case-list-title-card h4 {
    font-size: 1.05rem;
    line-height: 1.15;
    margin-bottom: 0.15rem !important;
}

.case-list-page .case-list-title-card p {
    font-size: 0.82rem;
    line-height: 1.15;
}

.case-list-page .case-list-title-card .fa-clipboard-list {
    font-size: 0.95em;
}

.case-list-page #caseListModal .modal-body .grid-editor-cell {
    padding: 0;
}

.case-list-page #caseListModal .modal-body .grid-editor-cell .grid-editor-box {
    min-height: 1.95rem;
    padding: 0.25rem 0.5rem;
    border: 1px solid #cbced4;
    border-radius: 0.4rem;
    background-color: #f3f3f5;
    display: flex;
    align-items: center;
    overflow: hidden;
}

.case-list-page #caseListModal .modal-body .grid-editor-cell .grid-editor-box.grid-editor-box--multiline {
    display: block;
    align-items: stretch;
    overflow: visible;
    min-height: auto;
}

.case-list-page #caseListModal .modal-body .grid-editor-box:focus-within {
    border-color: #86b7fe;
    box-shadow: 0 0 0 0.2rem rgba(13, 110, 253, 0.15);
}

.case-list-page #caseListModal .modal-body .grid-editor-box .form-control,
.case-list-page #caseListModal .modal-body .grid-editor-box .form-select {
    flex: 1 1 auto;
    min-width: 0;
    border: none;
    background-color: transparent;
    box-shadow: none;
    min-height: calc(1.95rem - 0.5rem);
    padding-top: 0.15rem;
    padding-bottom: 0.15rem;
}

.case-list-page #caseListModal .modal-body .grid-editor-box--multiline .form-control {
    width: 100%;
    min-height: 4.5rem;
    resize: vertical;
}

.case-list-page #caseListModal .modal-body .grid-editor-box .form-control:focus,
.case-list-page #caseListModal .modal-body .grid-editor-box .form-select:focus {
    box-shadow: none;
}

.case-list-page #caseListModal .modal-body .grid-editor-box .form-control:read-only {
    background-color: transparent;
}

@media (max-width: 991.98px) {
    .screening-condition-modal .condition-inline-input {
        width: 100%;
        max-width: 100%;
    }
    .screening-condition-modal .condition-mini-input {
        width: 5rem;
        max-width: 5rem;
    }
}

/* =============================================
   個人系統設定（全頁主內容）
   ============================================= */
.personal-settings-page {
    width: 100%;
    max-width: 100%;
}

.personal-settings-table thead th {
    white-space: nowrap;
}

.ps-icon-preview {
    position: relative;
    z-index: 0;
    width: 2rem;
    height: 2rem;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    color: #334155;
    font-size: 0.95rem;
}

.ps-icon-preview::after {
    content: "";
    position: absolute;
    inset: 0;
    border-radius: 0.55rem;
    z-index: -1;
    background: transparent;
    transition: background-color 0.15s ease-in-out;
}

.ps-icon-preview--bg-1::after {
    background: linear-gradient(145deg, #dbeafe, #bfdbfe);
}

.ps-icon-preview--bg-2::after {
    background: linear-gradient(145deg, #dcfce7, #bbf7d0);
}

.ps-icon-preview--bg-3::after {
    background: linear-gradient(145deg, #ede9fe, #ddd6fe);
}

.ps-icon-preview--bg-4::after {
    background: linear-gradient(145deg, #ffedd5, #fed7aa);
}

.ps-icon-preview--bg-5::after {
    background: linear-gradient(145deg, #e2e8f0, #cbd5e1);
}

.ps-icon-preview--bg-6::after {
    background: linear-gradient(145deg, #fef3c7, #fde68a);
}

.ps-icon-preview--bg-7::after {
    background: linear-gradient(145deg, #ffe4e6, #fecdd3);
}

.personal-settings-color-swatch {
    cursor: pointer;
    margin: 0;
    padding: 0;
    border-radius: 50%;
    width: 1.35rem;
    height: 1.35rem;
    display: inline-flex;
    align-items: center;
    justify-content: center;
}

.personal-settings-color-swatch input {
    margin: 0;
    accent-color: inherit;
}

.ps-color-radios-readonly {
    pointer-events: none;
}

.ps-color-radios-readonly .personal-settings-color-swatch {
    cursor: default;
}

.personal-settings-color-swatch--1 {
    background: linear-gradient(145deg, #2b7ce0, #1a5fbf);
}

.personal-settings-color-swatch--2 {
    background: linear-gradient(145deg, #1e9c6b, #157a55);
}

.personal-settings-color-swatch--3 {
    background: linear-gradient(145deg, #5b21b6, #4c1d95);
}

.personal-settings-color-swatch--4 {
    background: linear-gradient(145deg, #ea580c, #c2410c);
}

.personal-settings-color-swatch--5 {
    background: linear-gradient(145deg, #475569, #334155);
}

.personal-settings-color-swatch--6 {
    background: linear-gradient(145deg, #f59e0b, #d97706);
}

.personal-settings-color-swatch--7 {
    background: linear-gradient(145deg, #f43f5e, #e11d48);
}

.ps-icon-choice span {
    font-size: 0.65rem;
    line-height: 1.15;
}

/* 個人設定：圖示選取（全螢幕 Modal） */
#ps-icon-modal .ps-icon-choice {
    min-height: 5.5rem;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 0.35rem;
}

#ps-icon-modal .ps-icon-choice span {
    font-size: 0.7rem;
    line-height: 1.2;
    max-width: 100%;
}

/* =============================================
   右側最愛功能列 / 抽屜 / 預覽
   ============================================= */
.favorite-dock {
    position: sticky;
    top: 6.25rem;
    z-index: 1020;
}

.right-function-rail {
    grid-column: 2;
    grid-row: 2;
    padding-top: 1rem;
    padding-right: 0.35rem;
    display: flex;
    justify-content: flex-end;
    align-items: flex-start;
}

.favorite-dock-list {
    display: flex;
    flex-direction: column;
    gap: 0.35rem;
}

.favorite-dock-toggle {
    width: 2.6rem;
    min-height: 4.2rem;
    padding: 0.35rem 0.15rem;
    display: inline-flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 0.2rem;
    font-size: 0.65rem;
    line-height: 1.15;
    white-space: normal;
    border-top-right-radius: 0;
    border-bottom-right-radius: 0;
}

.favorite-dock-toggle i {
    font-size: 0.78rem;
}

.favorite-drawer {
    position: fixed;
    right: -19rem;
    top: 4rem;
    width: 18.5rem;
    height: calc(100vh - 4.5rem);
    background: #fff;
    border-left: 1px solid #dee2e6;
    z-index: 1045;
    transition: right 0.2s ease;
    display: flex;
    flex-direction: column;
}

.favorite-drawer.show {
    right: 0;
}

.favorite-drawer-header,
.favorite-preview-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.5rem;
    padding: 0.75rem;
    background: #f8f9fa;
}

.favorite-drawer-body {
    overflow: auto;
    padding: 0.5rem;
}

.favorite-drawer-list {
    display: flex;
    flex-direction: column;
    gap: 0.35rem;
}

.favorite-drawer-item {
    width: 100%;
    text-align: left;
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.favorite-drawer-icon {
    width: 1.8rem;
    height: 1.8rem;
    border-radius: 0.45rem;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    color: #334155;
    flex: 0 0 auto;
}

.favorite-preview {
    display: none;
    min-width: 0;
    width: 100%;
    height: calc(100vh - 8.6rem);
    background: #fff;
    border: 1px solid #dee2e6;
    border-radius: 0.5rem;
    flex-direction: column;
    overflow: hidden;
}

.favorite-preview.show {
    display: flex;
}

.favorite-preview-frame {
    width: 100%;
    height: 100%;
    border: 0;
    background: #fff;
}

/* =============================================
   RWD
   ============================================= */
@media (max-width: 768px) {
    #content {
        display: flex;
        flex-direction: column;
    }
    .right-function-rail {
        display: none;
    }
    #sidebar {
        position: fixed;
        z-index: 999;
        left: -176px;
        width: 176px;
    }
    #sidebar.show {
        left: 0;
    }
    .favorite-drawer {
        width: min(85vw, 18.5rem);
    }
    .favorite-preview {
        width: 100%;
        height: calc(100vh - 8.6rem);
    }
    .favorite-preview.show {
        right: auto;
    }
    .main-content.favorite-preview-open {
        display: flex;
        flex-direction: column;
        gap: 0;
    }
}

/* =============================================
   Professional Theme — Dark Sidebar
   ============================================= */

#sidebar {
    background: #1e293b;
    color: #94a3b8;
    border-right: none;
    box-shadow: 2px 0 8px rgba(0, 0, 0, 0.18);
}

#sidebar::-webkit-scrollbar-thumb {
    background: #2d3f55;
}

.sidebar-brand-panel {
    background: #ffffff;
    border-bottom: 1px solid #e2e8f0;
}

.sidebar-brand-text {
    color: #111827;
}

.sidebar-nav .nav-item > .nav-link {
    color: #94a3b8;
}

.sidebar-nav .nav-item > .nav-link:hover {
    background-color: rgba(255, 255, 255, 0.07);
    color: #e2e8f0;
}

.sidebar-nav .nav-item > .nav-link.active {
    background-color: rgba(59, 130, 246, 0.15);
    color: #93c5fd;
    font-weight: 600;
    box-shadow: inset 3px 0 0 0 #3b82f6;
}

.sidebar-nav .nav-item > .nav-link:not(.collapsed)[aria-expanded="true"] {
    background-color: rgba(255, 255, 255, 0.05);
    color: #cbd5e1;
}

.nav-icon {
    color: inherit;
}

.sidebar-nav .nav-item > .nav-link:hover .nav-icon,
.sidebar-nav .nav-item > .nav-link.active .nav-icon,
.sidebar-nav .nav-item > .nav-link:not(.collapsed)[aria-expanded="true"] .nav-icon {
    color: inherit;
}

.arrow {
    color: #475569;
}

.sub-menu .sub-link {
    color: #64748b;
}

.sub-menu .sub-link:hover {
    color: #e2e8f0;
    background-color: rgba(255, 255, 255, 0.06);
}

.sub-menu .sub-link.active {
    color: #93c5fd;
    background-color: rgba(59, 130, 246, 0.1);
    font-weight: 500;
}

/* =============================================
   Professional Theme — Top Navbar
   ============================================= */

.top-navbar {
    border-bottom: 1px solid #e5e7eb;
    background: #ffffff !important;
}

/* =============================================
   Professional Theme — Case List Table
   ============================================= */

.case-list-page .case-list-grid > thead > tr > th {
    color: #374151;
    background-color: #f1f5f9;
    border-bottom: 2px solid #dde3ed;
}

.case-list-page .case-list-grid tbody tr.case-list-grid-row:hover {
    background-color: #f0f7ff;
}

/* =============================================
   Professional Theme — Card Refinements
   ============================================= */

.card.shadow-sm {
    box-shadow: 0 1px 4px rgba(15, 23, 42, 0.07), 0 1px 2px rgba(15, 23, 42, 0.04) !important;
    border-color: #e5eaf0;
}

.site-footer {
    background: #f1f5f9;
    border-top-color: #dde3ed;
    color: #94a3b8;
}
