:root {
    --primary-color: #0066cc;
    --secondary-color: #004499;
    --success-color: #28a745;
    --danger-color: #dc3545;
    --warning-color: #ffc107;
    --info-color: #17a2b8;
    --light-bg: #f8f9fa;
    --dark-text: #212529;
    --border-color: #dee2e6;
    --shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
}

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

body {
    font-family: "Microsoft JhengHei", Arial, sans-serif;
    font-size: 16px;
    line-height: 1.6;
    color: #212529;
    background: #f8f9fa;
}

a {
    color: var(--primary-color);
    text-decoration: none;
}

a:hover {
    color: var(--secondary-color);
    text-decoration: underline;
}

/* Navbar */
.navbar {
    background: var(--primary-color);
    color: white;
    padding: 0.75rem 1.5rem;
    position: sticky;
    top: 0;
    z-index: 1000;
    display: flex;
    align-items: center;
    justify-content: space-between;
    max-width: 100%;
}

.navbar-brand {
    font-size: 1.25rem;
    font-weight: bold;
    color: white;
    text-decoration: none;
    display: flex;
    align-items: center;
    gap: 0.75rem;
}

/* 機關 logo:白底圓角徽章,讓白底 JPEG 在藍色 navbar 上自然呈現 */
.navbar-logo {
    height: 40px;
    background: #fff;
    padding: 4px 8px;
    border-radius: 6px;
    display: block;
}

.navbar-sys {
    font-size: 1.1rem;
}

.navbar-org {
    font-size: 0.8rem;
    font-weight: normal;
    opacity: 0.85;
}

.navbar-menu {
    display: flex;
    align-items: center;
    gap: 1rem;
    list-style: none;
}

.navbar-menu a {
    color: white;
    text-decoration: none;
    padding: 0.5rem 0.75rem;
    border-radius: 4px;
    transition: background-color 0.2s;
}

.navbar-menu a:hover {
    background: rgba(255, 255, 255, 0.15);
    text-decoration: none;
    color: white;
}

.navbar-user {
    color: rgba(255, 255, 255, 0.85);
    font-size: 0.9rem;
}

/* Sidebar */
.sidebar {
    width: 250px;
    position: fixed;
    top: 60px;
    left: 0;
    bottom: 0;
    background: white;
    border-right: 1px solid var(--border-color);
    overflow-y: auto;
    padding-top: 1.5rem;
    z-index: 999;
    transition: transform 0.3s;
}

.sidebar-item {
    border-bottom: 1px solid var(--border-color);
}

.sidebar-item > a {
    display: block;
    padding: 1rem 1.5rem;
    color: var(--dark-text);
    text-decoration: none;
    transition: background-color 0.3s;
}

.sidebar-item > a:hover {
    background: #e9ecef;
    text-decoration: none;
}

.sidebar-item.active > a {
    background: var(--primary-color);
    color: white;
}

.sidebar-submenu {
    background: #f8f9fa;
    list-style: none;
}

.sidebar-submenu a {
    display: block;
    padding: 0.75rem 1.5rem 0.75rem 3rem;
    color: var(--dark-text);
    text-decoration: none;
    transition: background-color 0.2s;
}

.sidebar-submenu a:hover {
    background: #e9ecef;
    text-decoration: none;
}

.sidebar-submenu a.active {
    color: var(--primary-color);
    font-weight: 500;
}

/* Main Content */
.main-content {
    margin-left: 250px;
    padding: 2rem;
    min-height: calc(100vh - 60px);
}

/* Page Header */
.page-header {
    background: white;
    border-radius: 8px;
    padding: 1.5rem;
    margin-bottom: 2rem;
    box-shadow: var(--shadow);
}

.page-title {
    font-size: 1.75rem;
    font-weight: bold;
    color: var(--primary-color);
    margin-bottom: 0.5rem;
}

/* Breadcrumb */
.breadcrumb {
    list-style: none;
    display: flex;
    gap: 0.5rem;
    font-size: 0.9rem;
    color: #6c757d;
}

.breadcrumb li::after {
    content: "/";
    margin-left: 0.5rem;
    color: #6c757d;
}

.breadcrumb li:last-child::after {
    content: "";
}

.breadcrumb a {
    color: var(--primary-color);
}

/* Card */
.card {
    background: white;
    border-radius: 8px;
    box-shadow: var(--shadow);
    padding: 1.5rem;
    margin-bottom: 1.5rem;
}

.card-header {
    font-size: 1.25rem;
    font-weight: bold;
    color: var(--primary-color);
    border-bottom: 2px solid var(--border-color);
    padding-bottom: 0.75rem;
    margin-bottom: 1rem;
}

/* Buttons */
.btn {
    display: inline-block;
    padding: 0.75rem 1.5rem;
    font-size: 14px;
    font-weight: 500;
    border: none;
    border-radius: 4px;
    cursor: pointer;
    transition: all 0.3s;
    text-decoration: none;
    text-align: center;
}

.btn:hover {
    text-decoration: none;
}

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

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

.btn-secondary {
    background: #6c757d;
    color: white;
}

.btn-secondary:hover {
    background: #5a6268;
}

.btn-success {
    background: var(--success-color);
    color: white;
}

.btn-success:hover {
    background: #218838;
}

.btn-danger {
    background: var(--danger-color);
    color: white;
}

.btn-danger:hover {
    background: #c82333;
}

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

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

.btn-sm {
    padding: 0.4rem 0.8rem;
    font-size: 13px;
}

.btn:disabled {
    opacity: 0.6;
    cursor: not-allowed;
}

/* Form */
.form-group {
    margin-bottom: 1.5rem;
}

.form-label {
    display: block;
    font-weight: 500;
    margin-bottom: 0.5rem;
    color: var(--dark-text);
}

.form-label.required::after {
    content: " *";
    color: var(--danger-color);
}

.form-control {
    width: 100%;
    padding: 0.75rem;
    font-size: 14px;
    border: 1px solid var(--border-color);
    border-radius: 4px;
    transition: all 0.3s;
    color: var(--dark-text);
    font-family: inherit;
}

.form-control:focus {
    outline: none;
    border-color: var(--primary-color);
    box-shadow: 0 0 0 3px rgba(0, 102, 204, 0.1);
}

.form-select {
    width: 100%;
    padding: 0.75rem;
    font-size: 14px;
    border: 1px solid var(--border-color);
    border-radius: 4px;
    transition: all 0.3s;
    background: white;
    font-family: inherit;
}

.form-select:focus {
    outline: none;
    border-color: var(--primary-color);
    box-shadow: 0 0 0 3px rgba(0, 102, 204, 0.1);
}

textarea.form-control {
    min-height: 120px;
    resize: vertical;
}

.search-row {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(250px, 1fr));
    gap: 1rem;
}

/* 滿版表單:寬卡片內欄位自動排成多欄,避免單一輸入框拉得過長 */
.form-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
    gap: 0 1.5rem;
}
.form-grid .span-2 { grid-column: 1 / -1; }

/* 後台多卡片並排(填滿可用寬度) */
.card-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(360px, 1fr));
    gap: 1.5rem;
    align-items: start;
}

/* 權限挑選 / 角色管理版面 */
.perm-module-title {
    font-weight: 600;
    color: var(--primary-color);
    margin: 0.85rem 0 0.4rem;
    font-size: 0.95rem;
}
.perm-options {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
    gap: 0.45rem 1.25rem;
}
.perm-options label { display: flex; align-items: center; gap: 0.45rem; font-size: 0.9rem; cursor: pointer; }
.code-hint { color: #9aa0a6; font-size: 0.72rem; font-family: monospace; }
details.panel > summary {
    cursor: pointer;
    font-weight: 500;
    color: var(--primary-color);
    padding: 0.35rem 0;
    user-select: none;
}
.role-summary { display: flex; align-items: center; gap: 0.75rem; flex-wrap: wrap; }
.role-summary .role-name { font-size: 1.1rem; font-weight: bold; }

/* Table */
.table-container {
    overflow-x: auto;
}

.table {
    width: 100%;
    border-collapse: collapse;
}

.table th {
    background: #f8f9fa;
    font-weight: 600;
    text-align: left;
    padding: 0.75rem;
    border-bottom: 2px solid var(--border-color);
    font-size: 16px;
}

.table td {
    padding: 0.75rem;
    border-bottom: 1px solid var(--border-color);
    font-size: 16px;
}

.table tbody tr:hover {
    background: #f8f9fa;
}

/* Badge */
.badge {
    display: inline-block;
    padding: 0.25rem 0.75rem;
    font-size: 0.875rem;
    font-weight: 500;
    border-radius: 12px;
}

.badge-success {
    background: #d4edda;
    color: #155724;
}

.badge-warning {
    background: #fff3cd;
    color: #856404;
}

.badge-danger {
    background: #f8d7da;
    color: #721c24;
}

.badge-info {
    background: #d1ecf1;
    color: #0c5460;
}

.badge-primary {
    background: #cce5ff;
    color: #004085;
}

/* Alert */
.alert {
    padding: 1rem;
    border-radius: 4px;
    margin-bottom: 1rem;
}

.alert-info {
    background: #d1ecf1;
    color: #0c5460;
    border-left: 4px solid var(--info-color);
}

.alert-warning {
    background: #fff3cd;
    color: #856404;
    border-left: 4px solid var(--warning-color);
}

.alert-danger {
    background: #f8d7da;
    color: #721c24;
    border-left: 4px solid var(--danger-color);
}

.alert-success {
    background: #d4edda;
    color: #155724;
    border-left: 4px solid var(--success-color);
}

/* Stats Cards */
.stats-cards {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
    gap: 1rem;
    margin-bottom: 1.5rem;
}

.stat-card {
    background: white;
    border-radius: 8px;
    box-shadow: var(--shadow);
    padding: 1.5rem;
    text-align: center;
}

.stat-card-value {
    font-size: 2rem;
    font-weight: bold;
    color: var(--primary-color);
}

.stat-card.danger .stat-card-value {
    color: var(--danger-color);
}

.stat-card.success .stat-card-value {
    color: var(--success-color);
}

.stat-card.warning .stat-card-value {
    color: #856404;
}

.stat-card-label {
    font-size: 0.875rem;
    color: #6c757d;
    margin-top: 0.25rem;
}

/* File Upload Area */
.file-upload-area {
    border: 2px dashed var(--border-color);
    border-radius: 8px;
    background: #f8f9fa;
    padding: 2rem;
    text-align: center;
    cursor: pointer;
    transition: all 0.3s;
}

.file-upload-area:hover {
    border-color: var(--primary-color);
    background: #e9ecef;
}

.file-upload-area input[type="file"] {
    display: none;
}

.file-upload-area p {
    font-size: 16px;
    color: #6c757d;
    margin-bottom: 0.5rem;
}

/* Pagination */
.pagination {
    list-style: none;
    display: flex;
    gap: 0.5rem;
    justify-content: center;
    margin-top: 1.5rem;
}

.pagination li a,
.pagination li span {
    display: inline-block;
    padding: 0.5rem 0.75rem;
    border: 1px solid var(--border-color);
    border-radius: 4px;
    color: var(--dark-text);
    text-decoration: none;
    transition: all 0.2s;
}

.pagination li.active a,
.pagination li.active span {
    background: var(--primary-color);
    color: white;
    border-color: var(--primary-color);
}

.pagination li a:hover {
    background: #e9ecef;
    text-decoration: none;
}

/* Tab Navigation */
.tab-nav {
    display: flex;
    border-bottom: 2px solid var(--border-color);
    margin-bottom: 1.5rem;
}

.tab-nav-item {
    padding: 0.75rem 1.5rem;
    color: #6c757d;
    cursor: pointer;
    border-bottom: 2px solid transparent;
    margin-bottom: -2px;
    transition: all 0.2s;
}

.tab-nav-item:hover {
    color: var(--primary-color);
}

.tab-nav-item.active {
    color: var(--primary-color);
    border-bottom-color: var(--primary-color);
}

.tab-panel {
    display: none;
}

.tab-panel.active {
    display: block;
}

/* Detail Panel */
.detail-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
    gap: 1rem;
}

.detail-item {
    padding: 0.5rem 0;
}

.detail-item-label {
    font-weight: 600;
    color: #495057;
    min-width: 100px;
    display: inline-block;
}

.detail-item-value {
    color: var(--dark-text);
}

/* Loading Spinner */
.loading-spinner {
    display: inline-block;
    width: 2rem;
    height: 2rem;
    border: 3px solid var(--border-color);
    border-top-color: var(--primary-color);
    border-radius: 50%;
    animation: spin 1s ease-in-out infinite;
}

@keyframes spin {
    to { transform: rotate(360deg); }
}

.loading-container {
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 3rem;
}

/* Empty State */
.empty-state {
    text-align: center;
    padding: 3rem;
    color: #6c757d;
}

/* Utility */
.text-center { text-align: center; }
.text-right { text-align: right; }
.text-muted { color: #6c757d; }
.text-danger { color: var(--danger-color); }
.text-success { color: var(--success-color); }
.mt-1 { margin-top: 0.5rem; }
.mt-2 { margin-top: 1rem; }
.mt-3 { margin-top: 1.5rem; }
.mb-1 { margin-bottom: 0.5rem; }
.mb-2 { margin-bottom: 1rem; }
.mb-3 { margin-bottom: 1.5rem; }
.d-flex { display: flex; }
.align-center { align-items: center; }
.justify-between { justify-content: space-between; }
.gap-1 { gap: 0.5rem; }
.gap-2 { gap: 1rem; }

/* Toolbar */
.toolbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 1rem;
    flex-wrap: wrap;
    gap: 0.5rem;
}

/* Login Page Specific */
.login-container {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 100vh;
    background: #f8f9fa;
}

.login-card {
    background: white;
    border-radius: 8px;
    box-shadow: var(--shadow);
    padding: 2.5rem;
    width: 100%;
    max-width: 400px;
}

.login-org {
    font-size: 0.9rem;
    color: #6c757d;
    text-align: center;
    margin-bottom: 0.25rem;
    letter-spacing: 0.05em;
}

.login-logo {
    display: block;
    max-width: 280px;
    width: 100%;
    height: auto;
    margin: 0 auto 1rem;
}

.login-title {
    font-size: 1.5rem;
    font-weight: bold;
    color: var(--primary-color);
    text-align: center;
    margin-bottom: 0.5rem;
}

.login-subtitle {
    font-size: 0.9rem;
    color: #6c757d;
    text-align: center;
    margin-bottom: 2rem;
}

/* Modal — 變更密碼等共用對話框
   _Layout 永遠 include _ChangePasswordModal,沒這條規則時 modal 內容會直接洩漏到頁面 flow */
.modal-overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.5);
    z-index: 2000;
    align-items: center;
    justify-content: center;
}

.modal-overlay.show {
    display: flex;
}

.modal {
    background: #fff;
    border-radius: 6px;
    padding: 1.5rem;
    min-width: 360px;
    max-width: 480px;
    width: 90vw;
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.2);
}

.modal h2 {
    margin-bottom: 1rem;
    color: var(--primary-color);
    font-size: 1.25rem;
}

/* Responsive */
@media (max-width: 768px) {
    .sidebar {
        transform: translateX(-100%);
    }

    .sidebar.open {
        transform: translateX(0);
    }

    .main-content {
        margin-left: 0;
        padding: 1rem;
    }

    .search-row {
        grid-template-columns: 1fr;
    }

    .stats-cards {
        grid-template-columns: 1fr 1fr;
    }
}

/* Print */
@media print {
    .navbar, .sidebar, .breadcrumb, .toolbar, button, .alert,
    .pagination, .file-upload-area, input[type="file"] {
        display: none !important;
    }

    .main-content {
        margin-left: 0 !important;
    }

    .card {
        box-shadow: none;
        border: 1px solid #000;
    }

    body {
        background: white !important;
        font-size: 12pt;
    }
}
