/* 聚心醫療工單系統 */
:root {
    --c-primary: #0f766e;
    --c-primary-dark: #115e59;
    --c-primary-soft: #ccfbf1;
    --c-danger: #b91c1c;
    --c-danger-soft: #fef2f2;
    --c-warn: #b45309;
    --c-warn-soft: #fffbeb;
    --c-ok: #15803d;
    --c-ok-soft: #f0fdf4;
    --c-text: #1f2937;
    --c-muted: #6b7280;
    --c-border: #e5e7eb;
    --c-bg: #f3f4f6;
    --c-card: #ffffff;
    --radius: 8px;
    --shadow: 0 1px 2px rgba(0, 0, 0, .05);
    --font: "Microsoft JhengHei", "PingFang TC", "Noto Sans TC", system-ui, sans-serif;
}

* { box-sizing: border-box; }

html, body {
    margin: 0;
    font-family: var(--font);
    font-size: 15px;
    color: var(--c-text);
    background: var(--c-bg);
    line-height: 1.5;
}

a { color: var(--c-primary); text-decoration: none; }
a:hover { text-decoration: underline; }
h1 { font-size: 1.5rem; margin: 0; }
h1:focus { outline: none; }
.h2, h2 { font-size: 1.1rem; margin: 0 0 .75rem; }
code, .mono { font-family: Consolas, "Courier New", monospace; }

.muted { color: var(--c-muted); }
.small { font-size: .85rem; }
.danger { color: var(--c-danger); }
.nowrap { white-space: nowrap; }
.num { text-align: right; white-space: nowrap; }
.text-left { text-align: left; }

/* ── 版面 ── */
.shell { min-height: 100vh; display: flex; flex-direction: column; }

.topbar {
    display: flex;
    align-items: center;
    gap: 1.5rem;
    padding: 0 1.25rem;
    min-height: 56px;
    background: var(--c-card);
    border-bottom: 1px solid var(--c-border);
    flex-wrap: wrap;
    position: sticky;
    top: 0;
    z-index: 10;
}

.brand {
    display: flex;
    align-items: center;
    gap: .5rem;
    font-weight: 700;
    color: var(--c-text);
    white-space: nowrap;
}
.brand:hover { text-decoration: none; }

.brand-mark {
    width: 22px;
    height: 22px;
    border-radius: 6px;
    background: var(--c-primary);
    display: inline-block;
    position: relative;
}
.brand-mark::after {
    content: "";
    position: absolute;
    inset: 6px 5px;
    border-top: 2px solid #fff;
    border-bottom: 2px solid #fff;
}

.nav { display: flex; gap: .25rem; flex: 1; flex-wrap: wrap; }
.nav a {
    padding: .4rem .75rem;
    border-radius: 6px;
    color: var(--c-text);
    white-space: nowrap;
}
.nav a:hover { background: var(--c-bg); text-decoration: none; }
.nav a.active { background: var(--c-primary-soft); color: var(--c-primary-dark); font-weight: 600; }

.user { display: flex; align-items: center; gap: .5rem; }
.user form { margin: 0; }
.user-name { color: var(--c-text); }

.content { padding: 1.25rem; max-width: 1280px; width: 100%; margin: 0 auto; }

.page-head {
    display: flex;
    justify-content: space-between;
    align-items: flex-end;
    gap: 1rem;
    margin-bottom: 1rem;
    flex-wrap: wrap;
}
.page-head .actions { display: flex; gap: .5rem; flex-wrap: wrap; }
.crumb { font-size: .85rem; color: var(--c-muted); margin-bottom: .25rem; }
.head-meta { display: flex; gap: .5rem; align-items: center; margin-top: .4rem; flex-wrap: wrap; }

/* ── 卡片與區塊 ── */
.card {
    background: var(--c-card);
    border: 1px solid var(--c-border);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    padding: 1rem 1.25rem;
    margin-bottom: 1rem;
}
.card.empty { text-align: center; color: var(--c-muted); padding: 2.5rem; }

.section h2 { padding-bottom: .5rem; border-bottom: 1px solid var(--c-border); }
.section-active { border-color: var(--c-primary); box-shadow: 0 0 0 1px var(--c-primary); }
.section > label, .section .stack > label { margin-top: .75rem; }

.subpanel { margin-top: .75rem; padding-top: .75rem; border-top: 1px dashed var(--c-border); }

.grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
    gap: .75rem 1rem;
}
.span-2 { grid-column: span 2; }
@media (max-width: 560px) { .span-2 { grid-column: span 1; } }

.stack { display: flex; flex-direction: column; gap: .75rem; }

/* ── 表單 ── */
label { display: block; font-size: .9rem; color: var(--c-muted); }
label > input, label > select, label > textarea, label > .hint { display: block; margin-top: .25rem; }
label.check { display: inline-flex; align-items: center; gap: .35rem; color: var(--c-text); font-size: .95rem; }
label.check > input { display: inline-block; margin: 0; }
.req { color: var(--c-danger); }
.hint { font-size: .8rem; color: var(--c-muted); }
p.hint { margin: .5rem 0; }

input:not([type=checkbox]):not([type=radio]):not([type=file]), select, textarea {
    font: inherit;
    color: var(--c-text);
    padding: .45rem .6rem;
    border: 1px solid #d1d5db;
    border-radius: 6px;
    background: #fff;
    width: 100%;
    min-width: 0;
}
textarea { resize: vertical; }
input:focus, select:focus, textarea:focus {
    outline: 2px solid var(--c-primary-soft);
    border-color: var(--c-primary);
}
input[type=checkbox], input[type=radio] { width: 1rem; height: 1rem; accent-color: var(--c-primary); }

.checks { display: flex; flex-wrap: wrap; gap: .5rem 1.25rem; padding: .25rem 0; }

.field-label { font-size: .85rem; color: var(--c-muted); margin-bottom: .2rem; }
.field-value { min-height: 1.5rem; }
.field-value.multiline { white-space: pre-wrap; }
.field { margin-bottom: .25rem; }
.field-wide { grid-column: 1 / -1; margin-top: .75rem; }

.inline-form { display: flex; gap: .5rem; align-items: center; flex-wrap: wrap; }
.inline-form input, .inline-form select { width: auto; flex: 1 1 160px; }

/* ── 按鈕 ── */
.btn {
    font: inherit;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: .25rem;
    padding: .45rem .9rem;
    border-radius: 6px;
    border: 1px solid #d1d5db;
    background: #fff;
    color: var(--c-text);
    cursor: pointer;
    white-space: nowrap;
    text-decoration: none;
}
.btn:hover { background: var(--c-bg); text-decoration: none; }
.btn:disabled { opacity: .55; cursor: not-allowed; }
.btn-primary { background: var(--c-primary); border-color: var(--c-primary); color: #fff; }
.btn-primary:hover { background: var(--c-primary-dark); }
.btn-danger { background: var(--c-danger); border-color: var(--c-danger); color: #fff; }
.btn-danger:hover { background: #991b1b; }
.btn-danger-outline { color: var(--c-danger); border-color: #fca5a5; }
.btn-default { }
.btn-link { border: none; background: none; color: var(--c-primary); padding: .25rem .4rem; }
.btn-link:hover { background: none; text-decoration: underline; }
.btn-link.danger { color: var(--c-danger); }
.btn-block { width: 100%; }

.action-bar { position: sticky; top: 64px; z-index: 5; }
.action-buttons { display: flex; gap: .5rem; flex-wrap: wrap; margin: .25rem 0; }

/* ── 提示 ── */
.alert { padding: .75rem 1rem; border-radius: var(--radius); margin-bottom: 1rem; border: 1px solid; }
.alert ul { margin: 0; padding-left: 1.25rem; }
.alert-error { background: var(--c-danger-soft); border-color: #fecaca; color: #991b1b; }
.alert-success { background: var(--c-ok-soft); border-color: #bbf7d0; color: #166534; }

/* ── 標籤 ── */
.badge, .tag {
    display: inline-block;
    padding: .1rem .55rem;
    border-radius: 999px;
    font-size: .8rem;
    white-space: nowrap;
    background: #f3f4f6;
    color: #374151;
    border: 1px solid transparent;
}
.badge-draft { background: #f3f4f6; color: #4b5563; }
.badge-default { background: #e0f2fe; color: #075985; }
.badge-approval { background: #fef3c7; color: #92400e; }
.badge-dev { background: #dbeafe; color: #1e40af; }
.badge-uat { background: #ede9fe; color: #5b21b6; }
.badge-release { background: var(--c-primary-soft); color: var(--c-primary-dark); }
.badge-closed { background: #dcfce7; color: #166534; }
.badge-rejected { background: #f3f4f6; color: #6b7280; text-decoration: line-through; }
.tag-danger { background: var(--c-danger-soft); color: var(--c-danger); border-color: #fecaca; }
.tag-warn { background: var(--c-warn-soft); color: var(--c-warn); border-color: #fde68a; }
.tag-ok { background: var(--c-ok-soft); color: var(--c-ok); }

/* ── 篩選 ── */
.filters { display: flex; gap: .5rem; align-items: center; flex-wrap: wrap; }
.filters > input[type=search] { flex: 1 1 200px; width: auto; }
.filters > select { width: auto; }
.filter-more {
    flex-basis: 100%;
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
    gap: .5rem 1rem;
    align-items: end;
    padding-top: .5rem;
    border-top: 1px dashed var(--c-border);
}

.segmented { display: inline-flex; border: 1px solid #d1d5db; border-radius: 6px; overflow: hidden; margin-bottom: .5rem; }
.filters .segmented { margin-bottom: 0; }
.segmented button {
    font: inherit;
    border: none;
    background: #fff;
    padding: .4rem .9rem;
    cursor: pointer;
    border-right: 1px solid #d1d5db;
}
.segmented button:last-child { border-right: none; }
.segmented button.active { background: var(--c-primary); color: #fff; }

/* ── 表格 ── */
.table-wrap { padding: 0; overflow-x: auto; }
.table { width: 100%; border-collapse: collapse; font-size: .92rem; }
.table th, .table td { padding: .55rem .75rem; border-bottom: 1px solid var(--c-border); text-align: left; vertical-align: top; }
.table th { background: #f9fafb; font-weight: 600; color: #374151; white-space: nowrap; }
.table th.num, .table td.num { text-align: right; }
.table tbody tr:hover { background: #f9fafb; }
.table tr.overdue td:first-child { box-shadow: inset 3px 0 0 var(--c-danger); }
.table tr.inactive td { color: var(--c-muted); }
.title-link { color: var(--c-text); }

/* ── 富文字 ── */
.rich-field { margin-top: .75rem; }
.rich-field > .hint { display: block; margin-bottom: .25rem; }
.rich-editor { margin-top: .25rem; color: var(--c-text); font-size: .95rem; }
.rich-editor .ck-editor__editable_inline { min-height: 140px; max-height: 70vh; }
.rich-editor .ck.ck-editor__main > .ck-editor__editable { border-radius: 0 0 6px 6px; }
.rich-editor .ck.ck-toolbar { border-radius: 6px 6px 0 0; }
.rich-content { line-height: 1.6; overflow-wrap: anywhere; }
.rich-content > :first-child { margin-top: 0; }
.rich-content > :last-child { margin-bottom: 0; }
.rich-content p { margin: 0 0 .5rem; }
.rich-content img { max-width: 100%; height: auto; border: 1px solid var(--c-border); border-radius: 4px; }
.rich-content figure { margin: .5rem 0; }
.rich-content figure.image_resized img { width: 100%; }
.rich-content table { border-collapse: collapse; margin: .5rem 0; }
.rich-content th, .rich-content td { border: 1px solid var(--c-border); padding: .3rem .5rem; }
.rich-content blockquote { margin: .5rem 0; padding-left: .75rem; border-left: 3px solid var(--c-border); color: var(--c-muted); }
.ck.ck-powered-by { opacity: .6; }

/* ── 附件 ── */
.files { list-style: none; padding: 0; margin: 0 0 .75rem; }
.files li { display: flex; gap: .5rem; align-items: center; flex-wrap: wrap; padding: .35rem 0; border-bottom: 1px solid var(--c-border); }
.upload { display: flex; align-items: center; gap: .75rem; flex-wrap: wrap; }
.upload > input, .upload > .hint { display: inline-block; margin: 0; }

/* ── 歷程 ── */
.timeline { list-style: none; margin: 0; padding: 0 0 0 1rem; border-left: 2px solid var(--c-border); }
.timeline li { position: relative; padding: 0 0 1rem .75rem; }
.timeline li::before {
    content: "";
    position: absolute;
    left: -1.42rem;
    top: .35rem;
    width: .7rem;
    height: .7rem;
    border-radius: 50%;
    background: #d1d5db;
    border: 2px solid #fff;
}
.timeline li.tl-statuschanged::before { background: var(--c-primary); }
.timeline li.tl-reassigned::before { background: var(--c-warn); }
.tl-head { display: flex; gap: .5rem; align-items: baseline; }
.tl-reason {
    margin-top: .25rem;
    padding: .35rem .6rem;
    background: var(--c-warn-soft);
    border-left: 3px solid #f59e0b;
    border-radius: 4px;
    white-space: pre-wrap;
}

/* ── 儀表板 ── */
.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); gap: 1rem; margin-bottom: 1rem; }
.stats .card { margin: 0; }
.stat-label { color: var(--c-muted); font-size: .9rem; }
.stat-value { font-size: 2rem; font-weight: 700; }
.stat-danger .stat-value { color: var(--c-danger); }
.stat-warn .stat-value { color: var(--c-warn); }

.dash-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(360px, 1fr)); gap: 0 1rem; }
.dash-grid .span-all { grid-column: 1 / -1; }
@media (max-width: 760px) { .dash-grid { grid-template-columns: 1fr; } }

.bars { display: flex; flex-direction: column; gap: .4rem; }
.bar-row { display: grid; grid-template-columns: 8.5rem 1fr 2.5rem; gap: .5rem; align-items: center; }
.bar-label { font-size: .9rem; }
.bar-track { background: var(--c-bg); border-radius: 4px; height: .8rem; overflow: hidden; }
.bar-fill { display: block; height: 100%; background: var(--c-primary); border-radius: 4px; }
.bar-value { text-align: right; font-variant-numeric: tabular-nums; }

.month-chart { display: grid; grid-template-columns: repeat(12, 1fr); gap: .25rem; align-items: end; min-height: 180px; }
.month { display: flex; flex-direction: column; align-items: center; gap: .2rem; }
.month-bars { display: flex; gap: 2px; align-items: flex-end; height: 140px; }
.mb { width: 10px; border-radius: 3px 3px 0 0; min-height: 1px; }
.mb-created { background: #94a3b8; }
.mb-closed { background: var(--c-primary); }
.month-label { font-size: .75rem; color: var(--c-muted); }
.month-nums { font-size: .7rem; color: var(--c-muted); font-variant-numeric: tabular-nums; }
.legend { display: flex; gap: .5rem; align-items: center; font-size: .85rem; color: var(--c-muted); margin-top: .5rem; }
.sw { display: inline-block; width: .8rem; height: .8rem; border-radius: 2px; }
.sw-created { background: #94a3b8; }
.sw-closed { background: var(--c-primary); margin-left: .75rem; }

/* ── 登入 ── */
.account-shell { min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: 1rem; }
.account-card {
    width: 100%;
    max-width: 400px;
    background: var(--c-card);
    border: 1px solid var(--c-border);
    border-radius: 12px;
    box-shadow: 0 10px 30px rgba(0, 0, 0, .06);
    padding: 2rem;
}
.account-brand { display: flex; align-items: center; gap: .5rem; font-weight: 700; font-size: 1.15rem; margin-bottom: 1.5rem; }
.divider { display: flex; align-items: center; gap: .75rem; color: var(--c-muted); margin: 1.25rem 0; font-size: .85rem; }
.divider::before, .divider::after { content: ""; flex: 1; border-top: 1px solid var(--c-border); }

/* ── 預覽視窗 ── */
.modal-backdrop { position: fixed; inset: 0; background: rgba(0, 0, 0, .4); display: flex; align-items: center; justify-content: center; z-index: 100; padding: 1rem; }
.modal { background: #fff; border-radius: var(--radius); width: min(820px, 100%); height: min(85vh, 900px); display: flex; flex-direction: column; overflow: hidden; }
.modal-head { display: flex; justify-content: space-between; align-items: center; padding: .5rem 1rem; border-bottom: 1px solid var(--c-border); }
.modal iframe { border: none; flex: 1; width: 100%; }

/* ── Blazor ── */
#blazor-error-ui {
    background: var(--c-warn-soft);
    border-top: 1px solid #fde68a;
    bottom: 0;
    box-shadow: 0 -1px 2px rgba(0, 0, 0, 0.1);
    display: none;
    left: 0;
    padding: .6rem 1.25rem .7rem 1.25rem;
    position: fixed;
    width: 100%;
    z-index: 1000;
}
#blazor-error-ui .dismiss { cursor: pointer; position: absolute; right: .75rem; top: .5rem; }

.blazor-error-boundary { background: #b32121; padding: 1rem; color: white; border-radius: var(--radius); }
.blazor-error-boundary::after { content: "發生錯誤。"; }

.table .title-cell { min-width: 14em; }

@media (max-width: 640px) {
    .nav { order: 3; flex-basis: 100%; flex-wrap: nowrap; overflow-x: auto; padding-bottom: .25rem; }
    .user { margin-left: auto; }
    .content { padding: .75rem; }
    .card { padding: .85rem; }
    .action-bar { top: 0; position: relative; }
    .topbar { gap: .5rem; padding: .5rem .75rem; }
}
