:root {
    --pm-sidebar: #1f3a5a;
    --pm-sidebar-hover: #2b4d75;
    --pm-bg: #f3f5f8;
}

html, body {
    font-family: "Noto Sans TC", "Microsoft JhengHei", "PingFang TC", system-ui, sans-serif;
    background: var(--pm-bg);
    font-size: 15px;
}

/* ---------- 版面 ---------- */
.app-shell { display: flex; min-height: 100vh; }

.app-sidebar {
    width: 220px;
    flex-shrink: 0;
    background: var(--pm-sidebar);
    color: #fff;
    position: sticky;
    top: 0;
    height: 100vh;
    overflow-y: auto;
}

.app-sidebar .brand {
    display: flex; align-items: center; gap: .6rem;
    height: 56px; padding: 0 1rem;
    background: #fff; color: var(--pm-sidebar); text-decoration: none;
    font-weight: 700; font-size: 1.02rem;
    border-bottom: 1px solid #e3e7ed;
}
.app-sidebar .brand img { height: 38px; width: auto; }

.app-sidebar .nav { padding: .75rem .5rem; }
.app-sidebar .nav-link {
    color: rgba(255,255,255,.8);
    border-radius: .4rem;
    padding: .55rem .9rem;
    display: flex; align-items: center; gap: .65rem;
}
.app-sidebar .nav-link:hover { background: var(--pm-sidebar-hover); color: #fff; }
.app-sidebar .nav-link.active { background: #fff; color: var(--pm-sidebar); font-weight: 600; }
.app-sidebar .nav-section { font-size: .75rem; color: rgba(255,255,255,.45); padding: 1rem .9rem .3rem; }

.app-main { flex-grow: 1; min-width: 0; display: flex; flex-direction: column; }
.app-topbar {
    height: 56px; background: #fff;
    border-bottom: 1px solid #e3e7ed;
    display: flex; align-items: center;
    padding: 0 1rem;
    position: sticky; top: 0; z-index: 100;
}
.app-content { padding: 1.5rem; }

@media (max-width: 991.98px) {
    .app-sidebar { position: fixed; left: -240px; z-index: 1050; transition: left .2s; }
    .app-sidebar.open { left: 0; box-shadow: 0 0 30px rgba(0,0,0,.3); }
    .app-content { padding: 1rem; }
}

.page-title { font-size: 1.4rem; font-weight: 700; margin-bottom: 1rem; }
.page-narrow { max-width: 520px; }
.page-medium { max-width: 980px; }
.card { border-color: #e3e7ed; }
.form-label.required::after { content: " *"; color: #dc3545; }
.validation-message { color: #dc3545; margin-top: .25rem; }
.form-control.invalid, .form-select.invalid { border-color: #dc3545; }
.form-control.invalid:focus, .form-select.invalid:focus { border-color: #dc3545; box-shadow: 0 0 0 .2rem rgba(220, 53, 69, .2); }
.table > thead th { white-space: nowrap; }
.table-danger-subtle > td { background-color: #fff3f3 !important; }

/* ---------- 登入 ---------- */
.login-page {
    min-height: 100vh;
    display: flex; align-items: center; justify-content: center;
    background: linear-gradient(135deg, #1f3a5a 0%, #36628f 100%);
    padding: 1rem;
}
.login-card {
    width: 100%; max-width: 400px;
    background: #fff; border-radius: 1rem;
    padding: 2.25rem 2rem;
    box-shadow: 0 20px 50px rgba(0,0,0,.25);
}
.login-page { flex-direction: column; }
.login-logo { width: 150px; height: auto; }
.login-footer { margin-top: 1.25rem; color: rgba(255,255,255,.75); font-size: .8rem; text-align: center; }

/* ---------- 儀表板 ---------- */
.stat-card {
    display: flex; align-items: center; gap: .9rem;
    background: #fff; border: 1px solid #e3e7ed; border-left-width: 4px !important;
    border-radius: .5rem; padding: .9rem 1rem;
    text-decoration: none; color: inherit;
    transition: box-shadow .15s;
}
.stat-card:hover { box-shadow: 0 4px 14px rgba(0,0,0,.08); color: inherit; }
.stat-icon { font-size: 1.8rem; }
.stat-value { font-size: 1.6rem; font-weight: 700; line-height: 1.1; }
.stat-title { font-size: .82rem; color: #6c757d; }

/* ---------- 通知 ---------- */
.notification-menu { width: 360px; max-height: 480px; overflow-y: auto; }
.notification-item {
    display: block; width: 100%; text-align: left;
    border: 0; background: #fff;
    padding: .6rem 1rem; border-bottom: 1px solid #f0f0f0;
}
.notification-item:hover { background: #f6f8fb; }
.notification-item.unread { background: #eef5ff; border-left: 3px solid #0d6efd; }

/* ---------- 上傳 ---------- */
.dropzone {
    position: relative;
    border: 2px dashed #b9c4d1; border-radius: .6rem;
    background: #fafbfd;
    padding: 1.4rem 1rem;
    text-align: center; color: #5b6b7d;
    transition: all .15s;
}
.dropzone.compact { padding: .6rem 1rem; }
.dropzone.compact .dropzone-text i { display: inline !important; font-size: 1rem !important; margin-right: .3rem; }
.dropzone:hover, .dropzone.dragging { border-color: #0d6efd; background: #f0f6ff; color: #0d6efd; }
.dropzone-input { position: absolute; inset: 0; opacity: 0; cursor: pointer; width: 100%; height: 100%; }
.dropzone-text { pointer-events: none; }
.pending-files { max-height: 220px; overflow-y: auto; }
.upload-progress { height: 6px; }
.upload-progress .progress-bar { transition: width .2s linear; }

/* ---------- 附件 ---------- */
.attachment-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(190px, 1fr)); gap: .75rem; }
.attachment-card { border: 1px solid #e3e7ed; border-radius: .5rem; overflow: hidden; background: #fff; }
.attachment-thumb {
    display: flex; align-items: center; justify-content: center;
    width: 100%; height: 110px; border: 0;
    background: #f4f6f9; cursor: zoom-in;
}
.attachment-thumb img { max-width: 100%; max-height: 100%; object-fit: contain; }
.attachment-thumb i { font-size: 2.8rem; }
.attachment-meta { padding: .5rem .6rem; }

/* ---------- 預覽 ---------- */
.preview-backdrop { position: fixed; inset: 0; background: rgba(15,20,30,.75); z-index: 1060; }
.preview-dialog {
    position: fixed; inset: 2.5vh 2.5vw; z-index: 1061;
    background: #2b2f36; border-radius: .6rem; overflow: hidden;
    display: flex; flex-direction: column; outline: none;
}
.preview-header { display: flex; align-items: center; padding: .55rem .9rem; background: #fff; }
.preview-body { position: relative; flex-grow: 1; min-height: 0; }
.preview-body iframe { position: relative; z-index: 1; width: 100%; height: 100%; border: 0; }
.preview-loading { position: absolute; inset: 0; display: flex; align-items: center; justify-content: center; color: #ddd; z-index: 0; }
.preview-image { width: 100%; height: 100%; display: flex; align-items: center; justify-content: center; padding: 1rem; }
.preview-image img { max-width: 100%; max-height: 100%; object-fit: contain; background: #fff; }

/* ---------- 報修單 ---------- */
.ticket-header h1 { font-weight: 700; }
.ticket-description, .comment-content { white-space: pre-wrap; word-break: break-word; }
.ticket-props { display: grid; grid-template-columns: 90px 1fr; row-gap: .55rem; margin: 0; font-size: .9rem; }
.ticket-props dt { color: #6c757d; font-weight: 500; }
.ticket-props dd { margin: 0; }

/* ---------- 專案 ---------- */
.pre-wrap { white-space: pre-wrap; word-break: break-word; }
.work-important > td { --bs-table-bg: #fff8e1; }
.work-important > td:first-child { box-shadow: inset 4px 0 0 #dc3545; }
.props { display: grid; grid-template-columns: 110px 1fr; row-gap: .55rem; margin: 0; font-size: .9rem; }
.props dt { color: #6c757d; font-weight: 500; }
.props dd { margin: 0; }
.project-header .project-code { font-family: var(--bs-font-monospace); color: #6c757d; font-size: .95rem; }

.timeline-item { display: flex; gap: .75rem; padding: .4rem 0; }
.timeline-item.comment { padding: .75rem 0; border-bottom: 1px solid #f0f2f5; }
.timeline-avatar {
    width: 34px; height: 34px; flex-shrink: 0; border-radius: 50%;
    background: #dbe7f5; color: #1f3a5a; font-weight: 700;
    display: flex; align-items: center; justify-content: center;
}
.timeline-body { flex-grow: 1; min-width: 0; }
.timeline-item.history { align-items: center; padding-left: 12px; }
.timeline-dot { width: 10px; height: 10px; border-radius: 50%; background: #c3ccd7; flex-shrink: 0; }

#blazor-error-ui {
    background: #fff3cd; bottom: 0; box-shadow: 0 -1px 2px rgba(0,0,0,.2);
    display: none; left: 0; padding: .6rem 1.25rem .7rem; position: fixed; width: 100%; z-index: 2000;
}
#blazor-error-ui .dismiss { cursor: pointer; position: absolute; right: .75rem; top: .5rem; }

/* 專案下拉：機關（optgroup）以藍色粗體顯示。
   Windows 的原生選單可直接套用；macOS 原生選單不吃樣式，需 Chrome/Edge 135+ 的 base-select，其他瀏覽器維持原生外觀。 */
.project-select optgroup { color: #1d4ed8; font-weight: 700; font-style: normal; }
.project-select option { color: #212529; font-weight: 400; }

@supports (appearance: base-select) {
    select.project-select,
    select.project-select::picker(select) { appearance: base-select; }

    select.project-select::picker-icon { display: none; }

    select.project-select::picker(select) {
        max-height: min(70vh, 32rem);
        overflow-y: auto;
        padding: .25rem 0;
        border: 1px solid #d0d7e2;
        border-radius: .5rem;
        background: #fff;
        box-shadow: 0 .5rem 1.5rem rgba(15, 35, 70, .15);
    }

    select.project-select optgroup {
        padding: .15rem 0;
        font-size: .82rem;
        letter-spacing: .02em;
    }
    select.project-select optgroup + optgroup { border-top: 1px solid #eef1f5; }

    select.project-select option {
        padding: .3rem .75rem .3rem 1.25rem;
        font-size: .9rem;
    }
    select.project-select > option { color: #6c757d; padding-left: .75rem; }
    select.project-select option:hover,
    select.project-select option:focus-visible { background: #e8f0fe; outline: none; }
    select.project-select option:checked { background: #dbe7fd; font-weight: 600; }
    select.project-select option::checkmark { display: none; }
}

/* EditForm 包住 header/body/footer 時，讓 form 接手 modal-content 的 flex 版面，內容區捲動、按鈕列固定在底部 */
.modal-content > form {
    display: flex;
    flex-direction: column;
    flex: 1 1 auto;
    min-height: 0;
}

.modal-dialog-scrollable .modal-content > form {
    overflow: hidden;
}

/* 下一個到期的項目 */
.text-orange {
    color: #fd7e14 !important;
}
