/* ==========================================================================
   金寶貝 CDSS 後台 — 馬偕主題
   主色 #990000 取自院方識別色，與原型 h.html / s.html 一致。
   所有顏色集中在這裡定義成 CSS 變數，改版型時不必翻遍各頁。
   ========================================================================== */

:root {
    --mk-red: #990000;
    --mk-red-dark: #7a0000;
    --mk-red-light: #fdf2f2;
    --mk-red-border: #f5c6c6;

    --mk-sidebar-bg: #1e293b;
    --mk-sidebar-hover: #334155;
    --mk-sidebar-active: var(--mk-red);
    --mk-sidebar-text: #cbd5e1;
    --mk-sidebar-text-active: #ffffff;
    --mk-sidebar-group: #64748b;

    --mk-body-bg: #f1f5f9;
    --mk-card-border: #e2e8f0;
    --mk-text: #1e293b;
    --mk-text-muted: #64748b;

    --mk-sidebar-width: 250px;
    --mk-topbar-height: 60px;

    /* 覆寫 Bootstrap 的主色，讓 btn-primary、表單 focus 等一併變成馬偕紅 */
    --bs-primary: #990000;
    --bs-primary-rgb: 153, 0, 0;
    --bs-link-color: #990000;
    --bs-link-color-rgb: 153, 0, 0;
    --bs-link-hover-color: #7a0000;
}

/* --------------------------------------------------------------------------
   Bootstrap 元件配色覆寫
   -------------------------------------------------------------------------- */
.btn-primary {
    --bs-btn-bg: var(--mk-red);
    --bs-btn-border-color: var(--mk-red);
    --bs-btn-hover-bg: var(--mk-red-dark);
    --bs-btn-hover-border-color: var(--mk-red-dark);
    --bs-btn-active-bg: var(--mk-red-dark);
    --bs-btn-active-border-color: var(--mk-red-dark);
    --bs-btn-disabled-bg: var(--mk-red);
    --bs-btn-disabled-border-color: var(--mk-red);
}

.btn-outline-primary {
    --bs-btn-color: var(--mk-red);
    --bs-btn-border-color: var(--mk-red);
    --bs-btn-hover-bg: var(--mk-red);
    --bs-btn-hover-border-color: var(--mk-red);
    --bs-btn-active-bg: var(--mk-red-dark);
    --bs-btn-active-border-color: var(--mk-red-dark);
}

.text-primary {
    color: var(--mk-red) !important;
}

.bg-primary {
    background-color: var(--mk-red) !important;
}

.form-control:focus,
.form-select:focus {
    border-color: var(--mk-red-border);
    box-shadow: 0 0 0 0.2rem rgba(153, 0, 0, 0.12);
}

.form-check-input:checked {
    background-color: var(--mk-red);
    border-color: var(--mk-red);
}

.page-item.active .page-link {
    background-color: var(--mk-red);
    border-color: var(--mk-red);
}

.page-link {
    color: var(--mk-red);
}

/* --------------------------------------------------------------------------
   版面骨架：固定側邊選單 + 固定頂部列
   純後台系統，不做行動版斷點（需求已明確排除行動版頁面）。
   -------------------------------------------------------------------------- */
body {
    background-color: var(--mk-body-bg);
    color: var(--mk-text);
    font-family: "Microsoft JhengHei", "微軟正黑體", -apple-system, "Segoe UI", sans-serif;
    font-size: 0.9rem;
}

.mk-sidebar {
    position: fixed;
    top: 0;
    left: 0;
    bottom: 0;
    width: var(--mk-sidebar-width);
    background-color: var(--mk-sidebar-bg);
    display: flex;
    flex-direction: column;
    z-index: 1030;
    transition: width 0.18s ease;
}

/* --------------------------------------------------------------------------
   側欄收合（html.mk-collapsed，由 _Layout 的切換鈕控制、localStorage 記憶）
   整個版型都吃 --mk-sidebar-width 變數，收合＝改寫變數，其餘自動跟隨
   -------------------------------------------------------------------------- */
html.mk-collapsed {
    --mk-sidebar-width: 60px;
}

html.mk-collapsed .mk-sidebar__brand-text,
html.mk-collapsed .mk-sidebar__group-label,
html.mk-collapsed .mk-sidebar__link span,
html.mk-collapsed .mk-sidebar__footer {
    display: none;
}

html.mk-collapsed .mk-sidebar__brand {
    justify-content: center;
    padding: 0;
}

html.mk-collapsed .mk-sidebar__link,
html.mk-collapsed .mk-sidebar__link--child {
    justify-content: center;
    padding-left: 0;
    padding-right: 0;
}

html.mk-collapsed .mk-sidebar__link i {
    font-size: 1.15rem;
    width: auto;
}

.mk-sidebar__brand {
    height: var(--mk-topbar-height);
    display: flex;
    align-items: center;
    gap: 0.625rem;
    padding: 0 1rem;
    border-bottom: 1px solid rgba(255, 255, 255, 0.08);
    flex-shrink: 0;
}

.mk-sidebar__brand img {
    width: 34px;
    height: 34px;
    object-fit: contain;
    background: #fff;
    border-radius: 6px;
    padding: 2px;
}

.mk-sidebar__brand-text {
    color: #fff;
    line-height: 1.15;
}

.mk-sidebar__brand-title {
    font-weight: 700;
    font-size: 1rem;
}

.mk-sidebar__brand-sub {
    font-size: 0.7rem;
    color: var(--mk-sidebar-group);
    letter-spacing: 0.04em;
}

.mk-sidebar__nav {
    flex: 1;
    overflow-y: auto;
    padding: 0.75rem 0;
}

.mk-sidebar__group-label {
    padding: 0.75rem 1rem 0.35rem;
    font-size: 0.7rem;
    font-weight: 700;
    letter-spacing: 0.08em;
    color: var(--mk-sidebar-group);
    text-transform: uppercase;
}

.mk-sidebar__link {
    display: flex;
    align-items: center;
    gap: 0.6rem;
    padding: 0.55rem 1rem;
    color: var(--mk-sidebar-text);
    text-decoration: none;
    border-left: 3px solid transparent;
    transition: background-color .15s, color .15s;
}

.mk-sidebar__link:hover {
    background-color: var(--mk-sidebar-hover);
    color: #fff;
}

.mk-sidebar__link.is-active {
    background-color: rgba(153, 0, 0, 0.85);
    border-left-color: #fff;
    color: var(--mk-sidebar-text-active);
    font-weight: 600;
}

.mk-sidebar__link i {
    font-size: 1rem;
    width: 1.2rem;
    text-align: center;
}

.mk-sidebar__link--child {
    padding-left: 2.1rem;
    font-size: 0.85rem;
}

.mk-sidebar__footer {
    padding: 0.6rem 1rem;
    border-top: 1px solid rgba(255, 255, 255, 0.08);
    color: var(--mk-sidebar-group);
    font-size: 0.7rem;
    flex-shrink: 0;
}

.mk-topbar {
    position: fixed;
    top: 0;
    left: var(--mk-sidebar-width);
    right: 0;
    height: var(--mk-topbar-height);
    background: #fff;
    border-bottom: 1px solid var(--mk-card-border);
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 1.25rem;
    z-index: 1020;
    transition: left 0.18s ease;
}

.mk-topbar__burger {
    border: none;
    background: transparent;
    color: #475569;
    font-size: 1.35rem;
    line-height: 1;
    padding: 0.15rem 0.35rem;
    border-radius: 0.35rem;
}

.mk-topbar__burger:hover {
    background: #f1f5f9;
    color: #990000;
}

.mk-topbar__title {
    font-size: 1.05rem;
    font-weight: 700;
    margin: 0;
}

.mk-main {
    transition: margin-left 0.18s ease;
    margin-left: var(--mk-sidebar-width);
    padding: calc(var(--mk-topbar-height) + 1.25rem) 1.25rem 1.5rem;
    min-height: 100vh;
}

/* --------------------------------------------------------------------------
   卡片與表格
   -------------------------------------------------------------------------- */
.mk-card {
    background: #fff;
    border: 1px solid var(--mk-card-border);
    border-radius: 0.5rem;
    box-shadow: 0 1px 2px rgba(15, 23, 42, 0.04);
}

.mk-card__header {
    padding: 0.75rem 1rem;
    border-bottom: 1px solid var(--mk-card-border);
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.75rem;
    flex-wrap: wrap;
}

.mk-card__title {
    font-size: 0.95rem;
    font-weight: 700;
    margin: 0;
}

.mk-card__body {
    padding: 1rem;
}

table.dataTable thead th {
    background-color: #f8fafc;
    border-bottom: 2px solid var(--mk-card-border) !important;
    font-size: 0.82rem;
    font-weight: 700;
    white-space: nowrap;
}

table.dataTable tbody td {
    font-size: 0.85rem;
    vertical-align: middle;
}

/* DataTables 的處理中提示置中且不遮住表頭 */
.dataTables_wrapper .dataTables_processing {
    border: 1px solid var(--mk-card-border);
    border-radius: 0.375rem;
    box-shadow: 0 2px 8px rgba(15, 23, 42, .08);
}

/* --------------------------------------------------------------------------
   狀態標籤
   -------------------------------------------------------------------------- */
.mk-badge {
    display: inline-block;
    padding: 0.15rem 0.5rem;
    border-radius: 0.25rem;
    font-size: 0.75rem;
    font-weight: 600;
    white-space: nowrap;
}

.mk-badge--enabled {
    background: #dcfce7;
    color: #166534;
}

.mk-badge--disabled {
    background: #f1f5f9;
    color: #64748b;
}

.mk-badge--locked {
    background: var(--mk-red-light);
    color: var(--mk-red);
    border: 1px solid var(--mk-red-border);
}

/* --------------------------------------------------------------------------
   登入頁
   -------------------------------------------------------------------------- */
.mk-login {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    background: linear-gradient(135deg, #1e293b 0%, #4a1010 100%);
    padding: 1.5rem;
}

.mk-login__card {
    width: 100%;
    max-width: 400px;
    background: #fff;
    border-radius: 0.75rem;
    box-shadow: 0 20px 45px rgba(0, 0, 0, .3);
    padding: 2rem;
}

.mk-login__logo {
    width: 64px;
    height: 64px;
    object-fit: contain;
    margin: 0 auto 0.75rem;
    display: block;
}

.mk-login__title {
    text-align: center;
    font-weight: 700;
    font-size: 1.15rem;
    margin-bottom: 0.15rem;
}

.mk-login__sub {
    text-align: center;
    color: var(--mk-text-muted);
    font-size: 0.8rem;
    margin-bottom: 1.5rem;
}

/* --------------------------------------------------------------------------
   Toast 提示（ui.js 使用）
   -------------------------------------------------------------------------- */
.mk-toast-container {
    position: fixed;
    top: calc(var(--mk-topbar-height) + 0.75rem);
    right: 1rem;
    z-index: 1080;
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}
