:root {
    --cms-primary: #4f46e5;
    --cms-primary-hover: #4338ca;
    --cms-primary-soft: #eef2ff;
    --cms-sidebar-bg: #0f172a;
    --cms-sidebar-bg-alt: #1e293b;
    --cms-sidebar-text: #cbd5e1;
    --cms-sidebar-text-active: #ffffff;
    --cms-sidebar-accent: #6366f1;
    --cms-surface: #ffffff;
    --cms-surface-muted: #f8fafc;
    --cms-border: #e2e8f0;
    --cms-text: #0f172a;
    --cms-text-muted: #64748b;
    --cms-radius: 0.625rem;
    --cms-radius-sm: 0.375rem;
    --cms-line-height: 1.4;
    --cms-shadow: 0 1px 2px rgba(15, 23, 42, 0.06), 0 8px 24px rgba(15, 23, 42, 0.06);
    --cms-shadow-lg: 0 12px 40px rgba(15, 23, 42, 0.12);
    --bs-primary: var(--cms-primary);
    --bs-primary-rgb: 79, 70, 229;
    --bs-link-color: var(--cms-primary);
    --bs-link-hover-color: var(--cms-primary-hover);
    --bs-border-radius: var(--cms-radius-sm);
    --bs-border-radius-lg: var(--cms-radius);
    --bs-body-line-height: var(--cms-line-height);
}

body.layout-fixed,
body.auth-page {
    font-family: "Noto Sans TC", "Segoe UI", system-ui, -apple-system, sans-serif;
    font-size: 0.875rem;
    line-height: var(--cms-line-height);
    letter-spacing: 0;
}

body.layout-fixed {
    color: var(--cms-text);
    background: var(--cms-surface-muted);
}

.cms-admin p,
.cms-admin .breadcrumb,
.cms-admin .form-text,
.cms-admin .dropdown-item {
    line-height: var(--cms-line-height);
}

.app-header.navbar {
    background: var(--cms-surface) !important;
    border-bottom: 1px solid var(--cms-border);
    box-shadow: 0 1px 0 rgba(15, 23, 42, 0.04);
    min-height: 3rem;
}

.app-header .nav-link {
    color: var(--cms-text);
    font-weight: 500;
    padding-top: 0.375rem;
    padding-bottom: 0.375rem;
}

.app-header .nav-link:hover {
    color: var(--cms-primary);
}

.app-header .navbar-brand-text {
    font-weight: 600;
    color: var(--cms-text);
}

.app-header .navbar-brand-subtitle {
    display: block;
    font-size: 0.6875rem;
    font-weight: 400;
    color: var(--cms-text-muted);
    line-height: 1.15;
    margin-top: 0.0625rem;
}

.app-sidebar {
    background: linear-gradient(180deg, var(--cms-sidebar-bg) 0%, var(--cms-sidebar-bg-alt) 100%) !important;
    border-right: 1px solid rgba(255, 255, 255, 0.06);
}

.app-sidebar .sidebar-brand {
    border-bottom: 1px solid rgba(255, 255, 255, 0.08);
    padding: 0.625rem 0.875rem;
}

.app-sidebar .brand-link {
    color: #fff !important;
    font-weight: 600;
    letter-spacing: 0;
    font-size: 0.9375rem;
    line-height: 1.3;
}

.app-sidebar .brand-text {
    font-weight: 600 !important;
}

.sidebar-user-panel {
    margin: 0.5rem 0.75rem 0.375rem;
    padding: 0.5rem 0.625rem;
    border-radius: var(--cms-radius-sm);
    background: rgba(255, 255, 255, 0.06);
    border: 1px solid rgba(255, 255, 255, 0.08);
}

.sidebar-user-panel .user-name {
    color: #fff;
    font-size: 0.8125rem;
    font-weight: 600;
    margin-bottom: 0;
    line-height: 1.3;
}

.sidebar-user-panel .user-meta {
    color: var(--cms-sidebar-text);
    font-size: 0.6875rem;
    line-height: 1.25;
}

.sidebar-menu .nav-header {
    color: rgba(255, 255, 255, 0.45);
    font-size: 0.6875rem;
    font-weight: 700;
    letter-spacing: 0.06em;
    text-transform: uppercase;
    padding: 0.75rem 1.125rem 0.25rem;
    margin-top: 0.25rem;
}

.sidebar-menu .nav-link {
    color: var(--cms-sidebar-text);
    border-radius: var(--cms-radius-sm);
    margin: 0.0625rem 0.5rem;
    padding: 0.4375rem 0.625rem;
    font-size: 0.8125rem;
    line-height: 1.3;
    transition: background-color 0.15s ease, color 0.15s ease;
}

.sidebar-menu .nav-link p {
    margin: 0;
    line-height: 1.3;
}

.sidebar-menu .nav-link:hover {
    background: rgba(255, 255, 255, 0.08);
    color: #fff;
}

.sidebar-menu .nav-link.active {
    background: rgba(99, 102, 241, 0.22);
    color: var(--cms-sidebar-text-active);
    box-shadow: inset 3px 0 0 var(--cms-sidebar-accent);
}

.sidebar-menu .nav-icon {
    opacity: 0.9;
}

.app-main {
    background: var(--cms-surface-muted);
}

.app-content-header {
    background: transparent;
    padding-top: 0.75rem;
    padding-bottom: 0.25rem;
}

.app-content-header h3 {
    font-size: 1.125rem;
    font-weight: 700;
    line-height: 1.3;
    color: var(--cms-text);
}

.app-content {
    padding-top: 0.25rem;
    padding-bottom: 1.25rem;
}

.breadcrumb {
    --bs-breadcrumb-divider: "›";
    --bs-breadcrumb-item-padding-x: 0.375rem;
    font-size: 0.8125rem;
    margin-bottom: 0;
}

.breadcrumb-item + .breadcrumb-item::before {
    padding-top: 0;
}

.breadcrumb-item a {
    color: var(--cms-text-muted);
    text-decoration: none;
}

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

.breadcrumb-item.active {
    color: var(--cms-text);
    font-weight: 500;
}

.card {
    border: 1px solid var(--cms-border);
    border-radius: var(--cms-radius);
    box-shadow: var(--cms-shadow);
}

.card-header {
    background: var(--cms-surface);
    border-bottom: 1px solid var(--cms-border);
    font-weight: 600;
    font-size: 0.875rem;
    line-height: 1.3;
    padding: 0.5rem 0.875rem;
}

.cms-admin .card-body {
    padding: 0.75rem 0.875rem;
}

.card-footer {
    background: var(--cms-surface-muted);
    border-top: 1px solid var(--cms-border);
    padding: 0.5rem 0.875rem;
}

.table {
    --bs-table-striped-bg: rgba(248, 250, 252, 0.8);
}

.table > thead {
    background: var(--cms-sidebar-bg-alt);
    color: #fff;
}

.table > thead th {
    border-bottom: 0;
    font-weight: 600;
    font-size: 0.75rem;
    letter-spacing: 0;
    padding: 0.5rem 0.75rem;
    white-space: nowrap;
    line-height: 1.3;
}

.table > tbody td {
    padding: 0.5rem 0.75rem;
    vertical-align: middle;
    font-size: 0.8125rem;
    line-height: 1.35;
}

.table-hover > tbody > tr:hover > * {
    background-color: var(--cms-primary-soft);
}

.form-label {
    font-weight: 600;
    font-size: 0.8125rem;
    color: var(--cms-text);
    margin-bottom: 0.25rem;
    line-height: 1.3;
}

.form-control,
.form-select {
    border-color: var(--cms-border);
    border-radius: var(--cms-radius-sm);
    padding: 0.375rem 0.625rem;
    font-size: 0.8125rem;
    line-height: 1.35;
}

/* Keep room for Bootstrap's background chevron (theme padding above was too tight). */
.cms-admin .form-select {
    padding-right: 2rem;
    background-position: right 0.5rem center;
}

.cms-admin .admin-per-page-select {
    width: 4.75rem;
    min-width: 4.75rem;
    flex: 0 0 4.75rem;
}

.cms-admin .mb-3 {
    margin-bottom: 0.625rem !important;
}

.cms-admin .row {
    --bs-gutter-y: 0.625rem;
}

.form-control:focus,
.form-select:focus {
    border-color: rgba(79, 70, 229, 0.45);
    box-shadow: 0 0 0 0.2rem rgba(79, 70, 229, 0.12);
}

.btn {
    border-radius: var(--cms-radius-sm);
    font-weight: 600;
    font-size: 0.8125rem;
    line-height: 1.3;
    padding: 0.3125rem 0.75rem;
}

.btn-sm {
    font-size: 0.75rem;
    padding: 0.1875rem 0.5rem;
}

.btn-primary {
    --bs-btn-bg: var(--cms-primary);
    --bs-btn-border-color: var(--cms-primary);
    --bs-btn-hover-bg: var(--cms-primary-hover);
    --bs-btn-hover-border-color: var(--cms-primary-hover);
    --bs-btn-active-bg: var(--cms-primary-hover);
    --bs-btn-active-border-color: var(--cms-primary-hover);
}

.btn-outline-primary {
    --bs-btn-color: var(--cms-primary);
    --bs-btn-border-color: rgba(79, 70, 229, 0.35);
    --bs-btn-hover-bg: var(--cms-primary);
    --bs-btn-hover-border-color: var(--cms-primary);
}

.badge {
    font-weight: 600;
    font-size: 0.6875rem;
    border-radius: 999px;
    padding: 0.25em 0.5em;
    line-height: 1.2;
}

.alert {
    border: 0;
    border-radius: var(--cms-radius-sm);
    box-shadow: var(--cms-shadow);
    padding: 0.5rem 0.75rem;
    font-size: 0.8125rem;
    line-height: 1.4;
    margin-bottom: 0.625rem;
}

.small-box .inner {
    padding: 0.625rem 0.875rem;
}

.small-box .inner h3 {
    font-weight: 700;
    font-size: 1.5rem;
    line-height: 1.2;
    margin-bottom: 0.125rem;
}

.small-box .inner p {
    font-size: 0.8125rem;
    margin-bottom: 0;
    line-height: 1.3;
}

.page-toolbar {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 0.625rem;
    margin-bottom: 0.625rem;
}

.page-toolbar .toolbar-description {
    color: var(--cms-text-muted);
    margin: 0;
    font-size: 0.8125rem;
    line-height: 1.35;
}

.filter-panel {
    background: var(--cms-surface);
    border: 1px solid var(--cms-border);
    border-radius: var(--cms-radius);
    box-shadow: var(--cms-shadow);
    padding: 0.625rem 0.75rem;
    margin-bottom: 0.625rem;
}

.filter-panel .row {
    --bs-gutter-y: 0.5rem;
    --bs-gutter-x: 0.5rem;
}

.form-section-title {
    font-size: 0.75rem;
    font-weight: 700;
    color: var(--cms-text-muted);
    text-transform: uppercase;
    letter-spacing: 0.03em;
    margin-bottom: 0.5rem;
    line-height: 1.3;
}

.dropdown-menu {
    border: 1px solid var(--cms-border);
    border-radius: var(--cms-radius-sm);
    box-shadow: var(--cms-shadow-lg);
    font-size: 0.8125rem;
    --bs-dropdown-item-padding-y: 0.3125rem;
    --bs-dropdown-item-padding-x: 0.625rem;
}

/* Auth / Login */
body.auth-page {
    min-height: 100vh;
    margin: 0;
    background:
        radial-gradient(circle at top left, rgba(99, 102, 241, 0.28), transparent 32%),
        radial-gradient(circle at bottom right, rgba(20, 184, 166, 0.22), transparent 28%),
        linear-gradient(145deg, #0f172a 0%, #1e3a5f 48%, #0f766e 100%);
    color: #fff;
}

.auth-shell {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 1.25rem 1rem;
}

.auth-card {
    width: 100%;
    max-width: 26rem;
    background: rgba(255, 255, 255, 0.1);
    backdrop-filter: blur(18px);
    border: 1px solid rgba(255, 255, 255, 0.16);
    border-radius: 1rem;
    box-shadow: var(--cms-shadow-lg);
    padding: 1.5rem;
}

.auth-title {
    text-align: center;
    margin-bottom: 0.25rem;
    font-size: 1.375rem;
    font-weight: 700;
    line-height: 1.25;
}

.auth-subtitle {
    text-align: center;
    color: rgba(255, 255, 255, 0.72);
    margin-bottom: 1.125rem;
    font-size: 0.8125rem;
    line-height: 1.35;
}

.auth-input-group {
    display: flex;
    align-items: stretch;
    background: #fff;
    border-radius: var(--cms-radius-sm);
    overflow: hidden;
    border: 1px solid transparent;
    transition: box-shadow 0.15s ease, border-color 0.15s ease;
}

.auth-input-group:focus-within {
    border-color: rgba(99, 102, 241, 0.45);
    box-shadow: 0 0 0 0.2rem rgba(99, 102, 241, 0.18);
}

.auth-input-icon {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 2.5rem;
    color: var(--cms-text-muted);
    border-right: 1px solid var(--cms-border);
    background: #f8fafc;
}

.auth-input-group .form-control {
    border: 0;
    border-radius: 0;
    box-shadow: none;
    padding: 0.375rem 0.625rem;
    font-size: 0.8125rem;
    line-height: 1.35;
}

.auth-input-group .form-control:focus {
    box-shadow: none;
}

.auth-field {
    margin-bottom: 0.625rem;
}

.auth-captcha-row {
    display: flex;
    align-items: stretch;
    gap: 0.5rem;
    min-width: 0;
}

.auth-captcha-row .auth-input-group {
    flex: 1 1 auto;
    min-width: 0;
}

.auth-captcha-refresh {
    position: relative;
    flex: 0 0 7.75rem;
    width: 7.75rem;
    max-width: 42%;
    min-height: 2.25rem;
    padding: 0;
    margin: 0;
    border: 0;
    background: #fff;
    border-radius: var(--cms-radius-sm);
    overflow: hidden;
    cursor: pointer;
    line-height: 0;
    appearance: none;
    -webkit-appearance: none;
}

.auth-captcha-refresh:focus-visible {
    outline: 0;
    box-shadow: 0 0 0 0.2rem rgba(99, 102, 241, 0.18);
}

.auth-captcha-refresh img {
    position: absolute;
    inset: 0;
    display: block;
    width: 100%;
    height: 100%;
    object-fit: cover;
    object-position: center;
}

.auth-actions {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.625rem;
    margin-top: 0.75rem;
}

.auth-remember {
    color: rgba(255, 255, 255, 0.82);
    font-size: 0.8125rem;
    line-height: 1.3;
}

.auth-remember .form-check-input {
    margin-top: 0.125rem;
}

.auth-submit {
    width: 100%;
    margin-top: 0.625rem;
    padding: 0.5rem 0.875rem;
    font-weight: 700;
    font-size: 0.875rem;
    line-height: 1.3;
    border: 0;
    border-radius: var(--cms-radius-sm);
    background: linear-gradient(135deg, #6366f1 0%, #4f46e5 100%);
    color: #fff;
    transition: transform 0.15s ease, box-shadow 0.15s ease;
}

.auth-submit:hover {
    transform: translateY(-1px);
    box-shadow: 0 10px 24px rgba(79, 70, 229, 0.35);
    color: #fff;
}

.auth-link {
    color: rgba(255, 255, 255, 0.78);
    font-size: 0.8125rem;
    line-height: 1.3;
    text-decoration: none;
}

.auth-link:hover {
    color: #fff;
}

.auth-alert {
    border-radius: var(--cms-radius-sm);
    margin-bottom: 0.625rem;
    font-size: 0.8125rem;
    padding: 0.5rem 0.625rem;
    line-height: 1.35;
}

.small-box {
    border-radius: var(--cms-radius);
    box-shadow: var(--cms-shadow);
    overflow: hidden;
}

@media (max-width: 767.98px) {
    .app-content-header .breadcrumb {
        float: none !important;
        margin-top: 0.5rem;
    }

    .page-toolbar {
        flex-direction: column;
        align-items: stretch;
    }
}
