:root {
    --transition-timing: 0.5s cubic-bezier(0.4, 0, 0.2, 1);
}

body {
    background-color: #f5f5f5;
    font-family: 'Microsoft JhengHei', Arial, sans-serif;
    margin: 0;
    padding: 0;
    color: #333;
    transition: all var(--transition-timing);
}

/* 新增夜間模式相關樣式 */
body.dark-mode {
    background-color: #1a1a1a;
    color: #ffffff;
    transition: all var(--transition-timing);
}

body.dark-mode header {
    background-color: #2d2d2d;
    box-shadow: 0 2px 4px rgba(255,255,255,0.1);
    transition: all var(--transition-timing);
}

body.dark-mode .table-container {
    background-color: #2d2d2d;
    transition: all var(--transition-timing);
}

body.dark-mode th {
    background-color: #404040;
    color: #ffffff;
    transition: all var(--transition-timing);
}

body.dark-mode td {
    border-bottom: 1px solid #404040;
    transition: all var(--transition-timing);
}

body.dark-mode .scanner-container {
    background-color: #2d2d2d;
    transition: all var(--transition-timing);
}

body.dark-mode #deviceTable tr:hover:not(:first-child),
body.dark-mode #historyTable tr:hover:not(:first-child) {
    background-color: #404040;
}

/* 修改模式按鈕樣式 */
.mode-button {
    background: none;
    border: none;
    font-size: 24px;
    cursor: pointer;
    padding: 8px;
    border-radius: 50%;
    width: 40px;
    height: 40px;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all var(--transition-timing);
    transform: rotate(0deg);
    position: relative;
    overflow: hidden;
}

.mode-button:hover {
    background-color: rgba(0,0,0,0.1);
    transform: rotate(15deg);
}

body.dark-mode .mode-button:hover {
    background-color: rgba(255,255,255,0.1);
    transform: rotate(-15deg);
}

.mode-icon {
    position: absolute;
    transition: all var(--transition-timing);
    font-size: 20px; /* 調整圖示大小 */
}

.light-icon {
    transform: translateY(0) rotate(0deg);
    opacity: 1;
}

.dark-icon {
    transform: translateY(100%) rotate(-90deg);
    opacity: 0;
}

body.dark-mode .light-icon {
    transform: translateY(-100%) rotate(90deg);
    opacity: 0;
}

body.dark-mode .dark-icon {
    transform: translateY(0) rotate(0deg);
    opacity: 1;
}

body.dark-mode .category-container {
    background-color: #2d2d2d;
    transition: all var(--transition-timing);
}

body.dark-mode .category-button {
    background-color: #404040;
    border-color: #505050;
    color: #ffffff;
}

body.dark-mode .category-button:hover {
    background-color: #505050;
}

body.dark-mode .category-button.active {
    background-color: #007bff;
    color: white;
}

header {
    background-color: #fff;
    padding: 20px;
    box-shadow: 0 2px 4px rgba(0,0,0,0.1);
    margin-bottom: 20px;
    position: sticky;
    top: 0;
    z-index: 1000;
}

.header-buttons {
    display: flex;
    gap: 10px;
    margin-top: 10px;
    justify-content: flex-start;
    flex-wrap: wrap;
}

.table-container {
    background-color: #fff;
    border-radius: 8px;
    padding: 20px;
    margin: 20px;
    box-shadow: 0 2px 4px rgba(0,0,0,0.1);
    transition: all var(--transition-timing);
}

table {
    width: 100%;
    border-collapse: collapse;
    margin-top: 10px;
}

th, td {
    padding: 12px;
    text-align: left;
    border-bottom: 1px solid #eee;
    transition: background-color 0.5s ease, color 0.5s ease;
}

th {
    background-color: #f8f9fa;
    font-weight: 600;
}

.primary-button {
    background-color: #007bff;
    color: white;
    border: none;
    padding: 10px 20px;
    border-radius: 4px;
    cursor: pointer;
    transition: background-color 0.3s;
}

.secondary-button {
    background-color: #6c757d;
    color: white;
    border: none;
    padding: 10px 20px;
    border-radius: 4px;
    cursor: pointer;
    transition: background-color 0.3s;
}

.warning-button {
    background-color: #dc3545;
    color: white;
    border: none;
    padding: 10px 20px;
    border-radius: 4px;
    cursor: pointer;
    transition: background-color 0.3s;
}

.warning-button:hover {
    background-color: #c82333;
}

.scanner-container {
    text-align: center;
    padding: 20px;
    background-color: #fff;
    border-radius: 8px;
    margin: 20px;
    box-shadow: 0 2px 4px rgba(0,0,0,0.1);
    transition: all var(--transition-timing);
    animation: fadeInScale 0.3s var(--transition-timing);
}

.scanner-container h2 {
    color: #007bff;
    margin-bottom: 15px;
}

#deviceScanStep, #studentScanStep {
    transition: all 0.3s ease;
}

#studentInput {
    width: 80%;
    max-width: 300px;
    padding: 10px;
    margin: 10px 0;
    border: 2px solid #007bff;
    border-radius: 4px;
    font-size: 16px;
}

#manualInputBtn {
    margin-top: 10px;
    background-color: #6c757d;
}

#barcodeInput {
    width: 80%;
    max-width: 300px;
    padding: 10px;
    margin: 10px 0;
    border: 2px solid #007bff;
    border-radius: 4px;
    font-size: 16px;
}

#returnScannerSection {
    margin-bottom: 20px;
}

#returnBarcodeInput {
    width: 80%;
    max-width: 300px;
    padding: 10px;
    margin: 10px 0;
    border: 2px solid #dc3545;
    border-radius: 4px;
    font-size: 16px;
}

button {
    cursor: pointer;
    background-color: #edf3f7;
}

button:hover {
    opacity: 0.9;
}

button:disabled {
    background-color: #cccccc;
    cursor: not-allowed;
}

#loginSection {
    width: 100%;
    display: flex;
    justify-content: center;
    align-items: center;
}

.login-inputs {
    display: flex;
    flex-direction: column;
    gap: 10px;
    margin-bottom: 10px;
}

#loginSection input, #loginSection button {
    width: 200px;
    padding: 8px;
}

.login-container {
    background-color: #f0f0f0;
    padding: 20px;
    border-radius: 8px;
    box-shadow: 0 0 10px rgba(0,0,0,0.1);
    text-align: center;
    width: 300px; /* 設定一個固定寬度 */
}

.login-container h2 {
    margin-bottom: 20px;
}

.login-container input, 
.login-container button {
    display: block;
    width: 100%;
    padding: 10px;
    margin-bottom: 10px;
    box-sizing: border-box;
}

.login-container button {
    background-color: #4CAF50;
    color: white;
    border: none;
    cursor: pointer;
}

.login-container button:hover {
    background-color: #45a049;
}

/* 狀態樣式 */
.status-borrowed {
    color: #dc3545;
    font-weight: bold;
}

.status-available {
    color: #28a745;
    font-weight: bold;
}

/* 按鈕樣式 */
.borrow-button {
    background-color: #28a745;
    color: white;
    border: none;
    padding: 6px 12px;
    border-radius: 4px;
    transition: all 0.3s ease;
}

.return-button {
    background-color: #dc3545;
    color: white;
    border: none;
    padding: 6px 12px;
    border-radius: 4px;
    transition: all 0.3s ease;
}

/* 表格行動畫效果 */
@keyframes fadeIn {
    from { opacity: 0; transform: translateY(-10px); }
    to { opacity: 1; transform: translateY(0); }
}

#deviceTable tr:not(:first-child),
#historyTable tr:not(:first-child) {
    animation: slideIn 0.3s var(--transition-timing);
    animation-fill-mode: both;
}

@keyframes slideIn {
    from {
        opacity: 0;
        transform: translateX(-10px);
    }
    to {
        opacity: 1;
        transform: translateX(0);
    }
}

/* 表格懸停效果 */
#deviceTable tr:hover:not(:first-child),
#historyTable tr:hover:not(:first-child) {
    background-color: #f8f9fa;
    transition: background-color 0.2s ease;
}

.category-container {
    background-color: #fff;
    padding: 15px;
    margin: 20px;
    border-radius: 8px;
    box-shadow: 0 2px 4px rgba(0,0,0,0.1);
    transition: all var(--transition-timing);
    position: sticky;
    top: 100px; /* 調整這個值以確保在header下方適當位置 */
    z-index: 999;
}

.category-buttons {
    display: flex;
    gap: 10px;
    flex-wrap: wrap;
    justify-content: center;
}

.category-button {
    background-color: #f8f9fa;
    border: 1px solid #dee2e6;
    padding: 8px 16px;
    border-radius: 20px;
    cursor: pointer;
    transition: all 0.3s ease;
}

.category-button:hover {
    background-color: #e9ecef;
}

.category-button.active {
    background-color: #007bff;
    color: white;
    border-color: #007bff;
}

/* 模態框樣式 */
.modal {
    display: none;
    position: fixed;
    z-index: 1001;
    left: 0;
    top: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(0,0,0,0.5);
    backdrop-filter: blur(5px);
}

.modal-content {
    background-color: #fefefe;
    margin: 5% auto; /* 從 15% 改為 5% */
    padding: 20px;
    border-radius: 8px;
    width: 80%;
    max-width: 700px;
    position: relative;
    animation: modalSlideIn 0.3s ease;
    max-height: 80vh; /* 設定最大高度為視窗高度的 80% */
    overflow-y: auto; /* 允許垂直滾動 */
}

.modal-body {
    overflow-y: auto; /* 確保內容可滾動 */
    max-height: calc(80vh - 100px); /* 減去標題和padding的空間 */
    padding-right: 10px; /* 為滾動條預留空間 */
}

/* 自訂滾動條樣式 */
.modal-content::-webkit-scrollbar {
    width: 8px;
}

.modal-content::-webkit-scrollbar-track {
    background: #f1f1f1;
    border-radius: 4px;
}

.modal-content::-webkit-scrollbar-thumb {
    background: #888;
    border-radius: 4px;
}

.modal-content::-webkit-scrollbar-thumb:hover {
    background: #555;
}

/* 深色模式滾動條樣式 */
body.dark-mode .modal-content::-webkit-scrollbar-track {
    background: #2d2d2d;
}

body.dark-mode .modal-content::-webkit-scrollbar-thumb {
    background: #666;
}

body.dark-mode .modal-content::-webkit-scrollbar-thumb:hover {
    background: #888;
}

.close-button {
    position: absolute;
    right: 20px;
    top: 10px;
    font-size: 28px;
    cursor: pointer;
}

close-button:hover {
    color: #666;
}

.modal-header {
    margin-bottom: 20px;
}

.modal-header h2 {
    text-align: center; /* 新增：標題置中 */
    margin: 0 40px; /* 新增：左右留空間給關閉按鈕 */
}

.item-image {
    text-align: center;
    margin-bottom: 20px;
    min-height: 200px;
    display: flex;
    align-items: center;
    justify-content: center;
    background-color: #f5f5f5;
    border-radius: 4px;
    overflow: hidden; /* 新增 */
}

.item-image img {
    max-width: 100%;
    max-height: 300px;
    width: auto; /* 新增 */
    height: auto; /* 新增 */
    border-radius: 4px;
    object-fit: contain;
    display: block; /* 新增 */
    margin: 0 auto; /* 新增 */
}

.no-image-placeholder {
    padding: 40px;
    background-color: #f0f0f0;
    color: #666;
    border-radius: 4px;
    font-size: 1.2em;
    width: 100%;
    text-align: center;
}

body.dark-mode .no-image-placeholder {
    background-color: #404040;
    color: #999;
}

.item-image img {
    max-width: 100%;
    max-height: 300px;
    border-radius: 4px;
    object-fit: contain;
}

.item-details {
    line-height: 1.4;
    padding: 20px;
}

.item-details p {
    margin: 10px 0;
    background-color: #f8f9fa;
    padding: 15px;
    border-radius: 8px;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
}

.item-details strong {
    color: #007bff;
    display: block;
    margin-bottom: 10px;
    font-size: 1.1em;
}

.item-details span {
    display: block;
    word-wrap: break-word;
}

body.dark-mode .item-details p {
    background-color: #404040;
}

body.dark-mode .item-details strong {
    color: #5aa6ff;
}

@keyframes modalSlideIn {
    from {
        transform: translateY(-100px);
        opacity: 0;
    }
    to {
        transform: translateY(0);
        opacity: 1;
    }
}

/* 響應式設計 */
@media (max-width: 768px) {
    .table-container {
        margin: 10px;
        padding: 10px;
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
    }

    table {
        font-size: 14px;
        min-width: 600px; /* 確保表格內容可以完整顯示 */
    }

    th, td {
        padding: 8px 4px;
        font-size: 13px;
    }

    .header-buttons {
        flex-direction: column;
        gap: 5px;
    }

    .primary-button, .secondary-button, .warning-button {
        width: 100%;
        margin-bottom: 5px;
        padding: 12px;
        font-size: 16px;
    }

    .category-buttons {
        flex-direction: column;
    }
    
    .category-button {
        width: 100%;
        margin-bottom: 5px;
    }

    .category-container {
        top: 140px; /* 在手機版調整固定位置 */
        margin: 10px;
        padding: 10px;
    }

    .category-buttons {
        display: grid;
        grid-template-columns: repeat(2, 1fr);
        gap: 8px;
    }

    .category-button {
        width: 100%;
        padding: 10px;
        font-size: 14px;
        text-align: center;
    }

    .scanner-container {
        margin: 10px;
        padding: 15px;
    }

    .scanner-container h2 {
        font-size: 16px;
    }

    #barcodeInput,
    #studentInput,
    #returnBarcodeInput {
        width: 90%;
        font-size: 16px;
        padding: 12px;
    }

    .status-borrowed,
    .status-available {
        font-size: 13px;
    }

    button {
        min-height: 44px; /* 確保觸控區域足夠大 */
    }

    .table-container::after {
        content: '← 左右滑動查看更多 →';
        display: block;
        text-align: center;
        color: #666;
        font-size: 12px;
        padding: 5px;
    }

    input[type="text"] {
        -webkit-appearance: none;
        border-radius: 4px;
        box-shadow: none;
    }

    header {
        padding: 10px;
    }

    .modal-content {
        margin: 2% auto; /* 手機版更靠上 */
        width: 90%;
        padding: 15px;
    }
    
    .item-image img {
        max-height: 200px;
    }

    .item-details p {
        padding: 12px;
        margin: 10px 0;
    }
    
    .item-details strong {
        font-size: 1em;
    }
}

@media (max-width: 320px) {
    .category-buttons {
        grid-template-columns: 1fr;
    }

    header h1 {
        font-size: 18px;
    }

    .scanner-container h2 {
        font-size: 14px;
    }
}

@media (max-width: 768px) and (orientation: landscape) {
    .category-buttons {
        grid-template-columns: repeat(3, 1fr);
    }

    .header-buttons {
        flex-direction: row;
        flex-wrap: wrap;
    }

    .primary-button, 
    .secondary-button, 
    .warning-button {
        width: auto;
        flex: 1;
    }
}

/* 修改彈出視窗的夜間模式樣式 */
body.dark-mode .modal-content {
    background-color: #2d2d2d;
    color: #ffffff;
    border: 1px solid #404040;
}

body.dark-mode .close-button {
    color: #ffffff;
}

body.dark-mode .close-button:hover {
    color: #aaaaaa;
}

body.dark-mode .item-image {
    background-color: #404040;
    border: 1px solid #505050;
}

body.dark-mode .item-details p {
    background-color: #404040;
    border: 1px solid #505050;
}

body.dark-mode .modal {
    background-color: rgba(0, 0, 0, 0.7);
}

body.dark-mode .modal-header h2 {
    color: #ffffff;
}

body.dark-mode #modalItemStatus.status-available {
    color: #4caf50;
}

body.dark-mode #modalItemStatus.status-borrowed {
    color: #f44336;
}

/* ...existing code... */

.header-right {
    display: flex;
    align-items: center;
    gap: 10px;
}

#loginButton, #logoutButton {
    display: inline-flex;
    align-items: center;
    padding: 8px 16px;
    font-size: 14px;
    border-radius: 20px;
    transition: all 0.3s ease;
}

#loginButton img {
    margin-right: 8px;
}

/* ...existing code... */

/* ...existing styles... */

.admin-button {
    background-color: #6200ea;
    color: white;
    border: none;
    padding: 8px 16px;
    border-radius: 4px;
    cursor: pointer;
    transition: all 0.3s ease;
}

.super-admin-button {
    background-color: #c51162;
    color: white;
    border: none;
    padding: 8px 16px;
    border-radius: 4px;
    cursor: pointer;
    transition: all 0.3s ease;
}

.admin-list {
    margin: 20px 0;
    padding: 10px;
    background-color: #f5f5f5;
    border-radius: 4px;
}

.admin-add {
    display: flex;
    gap: 10px;
    margin-top: 20px;
}

.admin-add input {
    flex: 1;
    padding: 8px;
    border: 1px solid #ddd;
    border-radius: 4px;
}

.remove-admin {
    background-color: #ff1744;
    color: white;
    border: none;
    padding: 4px 8px;
    border-radius: 4px;
    margin-left: 10px;
    cursor: pointer;
}

/* Dark mode styles */
body.dark-mode .admin-list {
    background-color: #333;
}

body.dark-mode .admin-add input {
    background-color: #444;
    color: white;
    border-color: #555;
}

/* ...rest of existing styles... */