:root {
    --primary: #1a3a5c;
    --primary-light: #2d5a87;
    --primary-dark: #0f2438;
    --accent: #d4a838;
    --bg: #f0f2f5;
    --surface: #ffffff;
    --border: #e0e3e8;
    --text: #1f2933;
    --text-sub: #6b7785;
    --text-light: #9aa5b1;
    --success: #28a745;
    --warning: #ffc107;
    --danger: #dc3545;
    --info: #17a2b8;
    --sidebar-w: 240px;
    --sidebar-collapsed-w: 64px;
    --radius: 8px;
    --radius-sm: 4px;
    --shadow-sm: 0 1px 3px rgba(0,0,0,.08);
    --shadow-md: 0 4px 12px rgba(0,0,0,.1);
    --shadow-lg: 0 8px 24px rgba(0,0,0,.12);
    --font: "Microsoft YaHei", "PingFang SC", "Noto Sans TC", "Helvetica Neue", Arial, sans-serif;
}

* { margin:0; padding:0; box-sizing:border-box; }

body {
    font-family: var(--font);
    background: var(--bg);
    color: var(--text);
    font-size: 14px;
    line-height: 1.6;
}

/* ===== Sidebar ===== */
.sidebar {
    position: fixed;
    top: 0; left: 0; bottom: 0;
    width: var(--sidebar-w);
    height: 100vh;
    background: linear-gradient(180deg, var(--primary-dark) 0%, var(--primary) 100%);
    color: #fff;
    z-index: 1000;
    overflow-y: auto;
    overflow-x: hidden;
    display: flex;
    flex-direction: column;
    transition: width .25s ease;
}

/* 桌面端折叠状态：只显示图标 */
.sidebar.collapsed {
    width: var(--sidebar-collapsed-w);
}
.sidebar.collapsed .sidebar-brand {
    padding: 16px 0;
    text-align: center;
}
.sidebar.collapsed .sidebar-brand .logo {
    font-size: 13px;
    letter-spacing: 0;
    padding: 0 4px;
    line-height: 1.2;
}
.sidebar.collapsed .sidebar-brand .sub {
    display: none;
}
.sidebar.collapsed .nav-menu a {
    justify-content: center;
    padding: 12px 0;
}
.sidebar.collapsed .nav-menu a .nav-label {
    display: none;
}
.sidebar.collapsed .nav-menu a .icon {
    width: 22px;
    height: 22px;
}
.sidebar.collapsed ~ .main {
    margin-left: var(--sidebar-collapsed-w);
}

/* 折叠/展开切换按钮（侧边栏底部） */
.sidebar-toggle {
    padding: 12px 20px;
    border-top: 1px solid rgba(255,255,255,.1);
    color: rgba(255,255,255,.6);
    cursor: pointer;
    font-size: 13px;
    display: flex;
    align-items: center;
    gap: 10px;
    transition: all .15s;
    user-select: none;
    flex-shrink: 0;
}
.sidebar-toggle:hover {
    color: #fff;
    background: rgba(255,255,255,.06);
}
.sidebar-toggle .icon {
    width: 18px;
    height: 18px;
    flex-shrink: 0;
    transition: transform .25s;
}
.sidebar.collapsed .sidebar-toggle {
    justify-content: center;
    padding: 12px 0;
}
.sidebar.collapsed .sidebar-toggle .toggle-label {
    display: none;
}
.sidebar.collapsed .sidebar-toggle .icon {
    transform: rotate(180deg);
}

/* 折疊狀態 hover tooltip */
.sidebar.collapsed .nav-menu a {
    position: relative;
}
.sidebar.collapsed .nav-menu a::after {
    content: attr(data-tooltip);
    position: absolute;
    left: calc(100% + 8px);
    top: 50%;
    transform: translateY(-50%);
    background: var(--primary-dark);
    color: #fff;
    padding: 6px 12px;
    border-radius: 4px;
    font-size: 12px;
    white-space: nowrap;
    opacity: 0;
    visibility: hidden;
    transition: opacity .15s, visibility .15s;
    z-index: 1002;
    pointer-events: none;
    box-shadow: 0 2px 8px rgba(0,0,0,.2);
}
.sidebar.collapsed .nav-menu a::before {
    content: '';
    position: absolute;
    left: calc(100% + 2px);
    top: 50%;
    transform: translateY(-50%);
    border: 5px solid transparent;
    border-right-color: var(--primary-dark);
    opacity: 0;
    visibility: hidden;
    transition: opacity .15s, visibility .15s;
    z-index: 1002;
    pointer-events: none;
}
.sidebar.collapsed .nav-menu a:hover::after,
.sidebar.collapsed .nav-menu a:hover::before {
    opacity: 1;
    visibility: visible;
}

.sidebar-brand {
    padding: 20px 18px 16px;
    border-bottom: 1px solid rgba(255,255,255,.1);
    flex-shrink: 0;
}

.sidebar-brand .logo {
    font-size: 18px;
    font-weight: 700;
    letter-spacing: 0.5px;
}

.sidebar-brand .sub {
    font-size: 11px;
    color: rgba(255,255,255,.5);
    margin-top: 2px;
    letter-spacing: 1px;
}

.nav-menu {
    padding: 8px 0;
    flex: 1;
    overflow-y: auto;
    overflow-x: hidden;
}

.nav-menu a {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 10px 20px;
    color: rgba(255,255,255,.65);
    text-decoration: none;
    font-size: 14px;
    transition: all .15s;
    border-left: 3px solid transparent;
    white-space: nowrap;
}

.nav-menu a:hover {
    color: #fff;
    background: rgba(255,255,255,.06);
}

.nav-menu a.active {
    color: #fff;
    background: rgba(212,168,56,.12);
    border-left-color: var(--accent);
}

.nav-menu a .icon {
    width: 18px;
    height: 18px;
    flex-shrink: 0;
    opacity: 0.7;
}

.nav-menu a.active .icon { opacity: 1; color: var(--accent); }

.nav-menu .nav-label {
    flex: 1;
    overflow: hidden;
}

.nav-menu .nav-label .en {
    display: block;
    font-size: 10px;
    color: rgba(255,255,255,.4);
    margin-top: 1px;
}

/* ===== Main content ===== */
.main {
    margin-left: var(--sidebar-w);
    min-height: 100vh;
}

.topbar {
    background: var(--surface);
    border-bottom: 1px solid var(--border);
    padding: 0 24px;
    height: 56px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    box-shadow: var(--shadow-sm);
    position: sticky;
    top: 0;
    z-index: 100;
}

.topbar .page-title {
    font-size: 17px;
    font-weight: 600;
    color: var(--primary-dark);
}

.topbar .page-title .en {
    font-size: 11px;
    color: var(--text-sub);
    font-weight: 400;
    margin-left: 8px;
}

.topbar .user-area {
    display: flex;
    align-items: center;
    gap: 16px;
}

.topbar .user-area .badge {
    background: var(--bg);
    padding: 4px 10px;
    border-radius: 20px;
    font-size: 12px;
    color: var(--text-sub);
}

.topbar .user-area .user-info {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 13px;
}

.topbar .avatar {
    width: 32px; height: 32px;
    border-radius: 50%;
    background: var(--primary);
    color: #fff;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 13px;
    font-weight: 600;
}

.content {
    padding: 24px;
}

/* ===== Cards ===== */
.card {
    background: var(--surface);
    border-radius: var(--radius);
    box-shadow: var(--shadow-sm);
    border: 1px solid var(--border);
}

.card-header {
    padding: 16px 20px;
    border-bottom: 1px solid var(--border);
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.card-header h3 {
    font-size: 15px;
    font-weight: 600;
    color: var(--primary-dark);
}

.card-body { padding: 20px; }

/* ===== Stat cards ===== */
.stat-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
    gap: 16px;
    margin-bottom: 24px;
}

.stat-card {
    background: var(--surface);
    border-radius: var(--radius);
    padding: 18px 20px;
    box-shadow: var(--shadow-sm);
    border: 1px solid var(--border);
    position: relative;
    overflow: hidden;
    transition: transform .15s, box-shadow .15s;
}

.stat-card:hover {
    transform: translateY(-2px);
    box-shadow: var(--shadow-md);
}

.stat-card .stat-icon {
    position: absolute;
    right: 14px; top: 14px;
    width: 36px; height: 36px;
    border-radius: var(--radius-sm);
    display: flex;
    align-items: center;
    justify-content: center;
}

.stat-card .stat-label {
    font-size: 12px;
    color: var(--text-sub);
    margin-bottom: 6px;
}

.stat-card .stat-label .en {
    display: block;
    font-size: 10px;
    color: var(--text-light);
    margin-top: 1px;
}

.stat-card .stat-value {
    font-size: 28px;
    font-weight: 700;
    color: var(--text);
}

.stat-card .stat-sub {
    font-size: 11px;
    color: var(--text-sub);
    margin-top: 4px;
}

/* ===== Tables ===== */
.table-wrap {
    background: var(--surface);
    border-radius: var(--radius);
    box-shadow: var(--shadow-sm);
    border: 1px solid var(--border);
    overflow: hidden;
}

.table-toolbar {
    padding: 14px 20px;
    display: flex;
    align-items: center;
    gap: 12px;
    flex-wrap: wrap;
    border-bottom: 1px solid var(--border);
}

table {
    width: 100%;
    border-collapse: collapse;
    font-size: 13px;
}

table th {
    background: #f7f8fa;
    padding: 10px 14px;
    text-align: left;
    font-weight: 600;
    color: var(--text-sub);
    border-bottom: 1px solid var(--border);
    white-space: nowrap;
}

table td {
    padding: 10px 14px;
    border-bottom: 1px solid #f0f1f3;
    color: var(--text);
    vertical-align: middle;
}

table tr:hover td { background: #f9fafb; }

table tr:last-child td { border-bottom: none; }

/* ===== Badges / Tags ===== */
.tag {
    display: inline-flex;
    align-items: center;
    padding: 2px 10px;
    border-radius: 20px;
    font-size: 11px;
    font-weight: 500;
    white-space: nowrap;
}

.tag-success { background: #d4edda; color: #155724; }
.tag-warning { background: #fff3cd; color: #856404; }
.tag-danger { background: #f8d7da; color: #721c24; }
.tag-info { background: #d1ecf1; color: #0c5460; }
.tag-default { background: #e9ecef; color: #495057; }
.tag-accent { background: #fce8b5; color: #8a6d10; }

/* ===== Buttons ===== */
.btn {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 6px 16px;
    border-radius: var(--radius-sm);
    font-size: 13px;
    font-weight: 500;
    border: none;
    cursor: pointer;
    text-decoration: none;
    transition: all .15s;
    white-space: nowrap;
}

.btn-primary {
    background: var(--primary);
    color: #fff;
}

.btn-primary:hover { background: var(--primary-light); }

.btn-outline {
    background: transparent;
    border: 1px solid var(--border);
    color: var(--text-sub);
}

.btn-outline:hover { border-color: var(--primary); color: var(--primary); }

.btn-accent {
    background: var(--accent);
    color: #fff;
}

.btn-sm { padding: 4px 10px; font-size: 12px; }

/* ===== Inputs ===== */
input, select {
    font-family: var(--font);
    font-size: 13px;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    padding: 6px 12px;
    background: var(--surface);
    color: var(--text);
    outline: none;
    transition: border-color .15s;
}

input:focus, select:focus { border-color: var(--primary-light); box-shadow: 0 0 0 3px rgba(45,90,135,.1); }

.search-box {
    position: relative;
    min-width: 200px;
}

.search-box input { width: 100%; padding-left: 32px; }

.search-box::before {
    content: "";
    position: absolute;
    left: 10px; top: 50%;
    transform: translateY(-50%);
    width: 14px; height: 14px;
    border: 2px solid var(--text-light);
    border-radius: 50%;
}

.search-box::after {
    content: "";
    position: absolute;
    left: 20px; top: 22px;
    width: 7px; height: 2px;
    background: var(--text-light);
    transform: rotate(45deg);
}

/* ===== Progress ===== */
.progress-bar {
    width: 100%;
    height: 8px;
    background: #e9ecef;
    border-radius: 4px;
    overflow: hidden;
}

.progress-bar .fill {
    height: 100%;
    background: var(--primary);
    border-radius: 4px;
    transition: width .3s;
}

/* ===== Status flow ===== */
.status-flow {
    display: flex;
    align-items: center;
    gap: 0;
    margin: 8px 0;
}

.status-step {
    display: flex;
    align-items: center;
    gap: 6px;
    flex-shrink: 0;
}

.status-step .dot {
    width: 12px; height: 12px;
    border-radius: 50%;
    border: 2px solid var(--border);
    background: var(--surface);
}

.status-step.active .dot {
    border-color: var(--primary);
    background: var(--primary);
}

.status-step.done .dot {
    border-color: var(--success);
    background: var(--success);
}

.status-step .label {
    font-size: 11px;
    color: var(--text-sub);
}

.status-step.active .label { color: var(--primary); font-weight: 600; }
.status-step.done .label { color: var(--success); }

.status-line {
    flex: 1;
    height: 2px;
    background: var(--border);
    margin: 0 4px;
    min-width: 20px;
}

.status-line.done { background: var(--success); }

/* ===== Grid layouts ===== */
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 20px; }
.grid-3 { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 20px; }
.grid-2-1 { display: grid; grid-template-columns: 2fr 1fr; gap: 20px; }
.grid-1-2 { display: grid; grid-template-columns: 1fr 2fr; gap: 20px; }

/* ===== Misc ===== */
.text-sub { color: var(--text-sub); }
.text-danger { color: var(--danger); }
.text-success { color: var(--success); }
.text-warning { color: var(--warning); }
.text-right { text-align: right; }
.text-center { text-align: center; }
.font-bold { font-weight: 600; }
.mt-0 { margin-top: 0; }
.mb-16 { margin-bottom: 16px; }
.mt-16 { margin-top: 16px; }
.mb-24 { margin-bottom: 24px; }
.py-8 { padding-top: 8px; padding-bottom: 8px; }

.list-group { list-style: none; }
.list-group-item {
    padding: 12px 20px;
    border-bottom: 1px solid #f0f1f3;
    display: flex;
    align-items: center;
    justify-content: space-between;
}
.list-group-item:last-child { border-bottom: none; }

.alert {
    padding: 10px 16px;
    border-radius: var(--radius-sm);
    font-size: 13px;
    margin-bottom: 12px;
}
.alert-warning { background: #fff3cd; color: #856404; border: 1px solid #ffeaa7; }
.alert-danger { background: #f8d7da; color: #721c24; border: 1px solid #f5c2c7; }
.alert-info { background: #d1ecf1; color: #0c5460; border: 1px solid #bee5eb; }

.empty-state {
    text-align: center;
    padding: 40px 20px;
    color: var(--text-light);
}

/* ===== 漢堡菜單按鈕 ===== */
.menu-toggle {
    display: none;
    background: none;
    border: none;
    cursor: pointer;
    color: var(--primary-dark);
    padding: 4px;
    align-items: center;
    justify-content: center;
}

/* ===== 側邊欄遮罩 ===== */
.sidebar-overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,.5);
    z-index: 999;
    opacity: 0;
    transition: opacity .25s ease;
}
.sidebar-overlay.show {
    display: block;
    opacity: 1;
}

/* responsive */
@media (max-width: 768px) {
    /* 佈局 */
    .sidebar {
        transform: translateX(-100%);
        transition: transform .25s ease;
        z-index: 1001;
        box-shadow: 2px 0 12px rgba(0,0,0,.15);
    }
    .sidebar.open {
        transform: translateX(0);
    }
    .main { margin-left: 0; }
    .menu-toggle { display: inline-flex; }

    /* 頂部欄 */
    .topbar {
        padding: 0 12px;
        height: 52px;
    }
    .topbar .page-title {
        font-size: 15px;
    }
    .topbar .page-title .en {
        display: none;
    }
    .topbar .user-area {
        gap: 8px;
    }
    .topbar .user-area .badge {
        display: none;
    }
    .topbar .user-info span:not(.avatar) {
        display: none;
    }

    /* 內容區 */
    .content { padding: 12px; }

    /* Grid 佈局 */
    .grid-2, .grid-3, .grid-2-1, .grid-1-2 {
        grid-template-columns: 1fr;
        gap: 12px;
    }
    .mb-24 { margin-bottom: 12px !important; }
    .mb-16 { margin-bottom: 10px !important; }

    /* 卡片 */
    .card { border-radius: 6px; }
    .card-header {
        padding: 12px 14px;
        flex-wrap: wrap;
        gap: 8px;
    }
    .card-header h3 { font-size: 15px; }
    .card-body { padding: 14px; }

    /* 統計卡片 */
    .stat-card { padding: 14px; }
    .stat-card .stat-value { font-size: 20px; }
    .stat-card .stat-icon { width: 36px; height: 36px; font-size: 18px; }

    /* 表格：允許橫向滾動 */
    .table-wrap { overflow-x: auto; }
    table { min-width: 600px; font-size: 12px; }
    table th, table td { padding: 8px 10px; }

    /* 表格工具欄 */
    .table-toolbar {
        padding: 10px 12px;
        gap: 8px;
    }
    .table-toolbar input[type="text"],
    .table-toolbar select {
        font-size: 13px;
        padding: 6px 10px;
        min-height: 36px;
    }

    /* 按鈕：增大點擊區域 */
    .btn {
        padding: 8px 14px;
        font-size: 13px;
        min-height: 36px;
        align-items: center;
    }
    .btn-sm {
        padding: 6px 10px;
        font-size: 12px;
        min-height: 30px;
    }

    /* 分頁 */
    .pagination-bar {
        padding: 10px 12px;
        gap: 8px;
    }
    .page-btn {
        min-width: 34px;
        height: 34px;
    }

    /* 狀態流程圖 */
    .status-flow {
        flex-wrap: wrap;
        gap: 4px;
    }
    .status-step {
        flex: 1 1 auto;
        min-width: 50px;
        font-size: 10px;
    }
    .status-step .dot {
        width: 20px;
        height: 20px;
    }

    /* 彈窗 */
    .modal-box {
        width: 92vw;
        max-width: 400px;
    }

    /* 提示訊息 */
    .alert {
        padding: 10px 12px;
        font-size: 13px;
    }

    /* 空狀態 */
    .empty-state { padding: 24px 12px; }
}

/* 更小屏幕（手機） */
@media (max-width: 480px) {
    .topbar .page-title { font-size: 14px; }

    .card-header h3 { font-size: 14px; }

    .stat-card .stat-value { font-size: 18px; }
    .stat-card .stat-label { font-size: 12px; }

    table { min-width: 560px; font-size: 12px; }

    .btn {
        padding: 7px 12px;
        font-size: 12px;
    }

    .pagination-info { font-size: 12px; }
    .page-btn {
        min-width: 30px;
        height: 30px;
        font-size: 12px;
    }
}

/* pagination */
.pagination-bar {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 12px 16px;
    gap: 12px;
    flex-wrap: wrap;
}
.pagination-info {
    font-size: 13px;
    color: var(--text-sub);
    white-space: nowrap;
}
.pagination-links {
    display: flex;
    align-items: center;
    gap: 4px;
    flex-wrap: wrap;
}
.page-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 32px;
    height: 32px;
    padding: 0 8px;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    background: var(--surface);
    color: var(--text);
    font-size: 13px;
    cursor: pointer;
    text-decoration: none;
    transition: all .15s;
}
.page-btn:hover:not(.disabled):not(.active) {
    border-color: var(--primary-light);
    background: var(--bg);
}
.page-btn.active {
    background: var(--primary);
    color: #fff;
    border-color: var(--primary);
}
.page-btn.disabled {
    color: var(--text-light);
    cursor: not-allowed;
    background: var(--bg);
}
.page-ellipsis {
    padding: 0 4px;
    color: var(--text-sub);
}
.per-page-select {
    margin-left: 8px;
    height: 32px;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    background: var(--surface);
    font-size: 13px;
    color: var(--text);
    cursor: pointer;
}
