/* === 基本變數定義 === */

:root {
    --primary-color: #C19A6B;
    --primary-hover: #906E3E;
    --secondary-color: #6BC29B;
    --secondary-hover: #57AE87;
    --danger-color: #dc3545;
    --danger-hover: #bd2130;
    --circle-color: #D0D0D0;
    --circle-hover: #8A8A8A;
    --success-bg: #d4edda;
    --success-border: #c3e6cb;
    --success-text: #155724;
    --error-bg: #f8d7da;
    --error-border: #f5c6cb;
    --error-text: #721c24;
    --warning-bg: #FFF3CD;
    --warning-border: #EBDFB9;
    --warning-text: #856404;
}

/* === 基本元素樣式 === */

body {
    font-family: 'Microsoft JhengHei', Arial, sans-serif;
    line-height: 1.6;
    margin: 0;
    padding: 10px;
    background-color: #f8f9fa;
    color: #333;
}

h1, h2 {
    color: #333;
    margin-bottom: 20px;
    text-align: center;
}

/* === 表單基本元素 === */

form {
    margin-bottom: 30px;
}

label {
    display: block;
    margin-bottom: 5px;
    font-weight: bold;
    color: #555;
}

input, select, textarea, button {
    width: 100%;
    padding: 10px;
    margin-top: 5px;
    border: 1px solid #ddd;
    border-radius: 4px;
    box-sizing: border-box;
    font-size: 14px;
    color: #333;
}

input:focus, select:focus, textarea:focus {
    outline: none;
    border-color: #007bff;
    box-shadow: 0 0 5px rgba(0, 123, 255, 0.5);
}

textarea {
    resize: vertical;
}

/* === 容器樣式 === */

.container {
    max-width: 600px;
    margin: 0 auto;
    padding: 15px;
    background-color: #f8f6f0;
    box-shadow: 0 0 10px rgba(0,0,0,0.1);
    border-radius: 8px;
}

.section {
    margin-bottom: 30px;
    padding: 20px;
    background-color: #f8f6f0;
    border-radius: 5px;
    box-shadow: 0 2px 4px rgba(0,0,0,0.05);
}

/* === 通用按鈕樣式 === */

button {
    color: white;
    padding: 10px 20px;
    border: none;
    cursor: pointer;
    font-weight: bold;
    font-size: 16px;
    text-align: center;
    border-radius: 4px;
    transition: background-color 0.3s;
}

/* 一般按鈕預設使用 primary 顏色 */
button:not(.secondary):not(.danger):not(.circle),
button.primary,
button[type="submit"], 
button[type="button"] {
    background-color: var(--primary-color);
    color: #fff;
    border-radius: 4px;
    border: none;
    cursor: pointer;
}

button:not(.secondary):not(.danger):not(.circle):hover,
button.primary:hover,
button[type="submit"]:hover, 
button[type="button"]:hover {
    background-color: var(--primary-hover);
}

button:disabled {
    background-color: #cccccc !important;
    cursor: not-allowed !important;
    opacity: 0.7;
}

/* Secondary 按鈕樣式 */
button.secondary {
    background-color: var(--secondary-color);
    color: white;
}

button.secondary:hover {
    background-color: var(--secondary-hover);
}

/* Danger 按鈕樣式 */
button.danger {
    background-color: var(--danger-color);
    color: white;
}

button.danger:hover {
    background-color: var(--danger-hover);
}

button[type="submit"], button[type="button"] {
    width: auto;
    padding: 10px 15px;
}

/* === 圓形按鈕樣式 === */

button.circle {
    background-color: var(--circle-color);
    color: white;
    width: 30px;
    height: 30px;
    padding: 0px;
    border-radius: 15px;
    display: flex;
    align-items: center;
    justify-content: center;
}

button.circle:hover {
    background-color: var(--circle-hover);
}

button.circle:disabled {
    background-color: #e0e0e0 !important;
}

/* === 按鈕群組樣式(縮小按鈕、間距) === */

.btn-group {
    display: flex;
    justify-content: center;
    flex-wrap: nowrap;
    white-space: nowarp;
    gap: 10px;
}

.btn {
    display: inline-block;
    padding: 10px;
    border: none;
    text-decoration: none;
    font-size: 16px;
    font-weight: bold;
    cursor: pointer;
    border-radius: 5px;
    transition: background-color 0.3s;
}

.btn-primary {
    background-color: var(--primary-color);
    color: white;
}

.btn-primary:hover {
    background-color: var(--primary-hover);
}

.btn-secondary {
    background-color: var(--secondary-color);
    color: white;
}

.btn-secondary:hover {
    background-color: var(--secondary-hover);
}

/* === 表格樣式 === */

table {
    width: 100%;
    border-collapse: collapse;
    margin-top: 20px;
}

table th {
    padding: 6px;
    text-align: left;
    border-bottom: 1px solid #ddd;
    background-color: #a8a6a0;
    color: white;
    font-weight: bold;
}

table td {
    padding: 6px;
    text-align: left;
    border-bottom: 1px solid #ddd;
}

table tr:hover {
    background-color: #dad8d2;
}

table tr:nth-child(even) {
    background-color: #eeece6;
}

/* === Modal 樣式 === */

.modal {
    display: none;
    position: fixed;
    z-index: 1000;	/* Ensure it's above other content */
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(0, 0, 0, 0.5);
}

.modal-content {
    position: relative;
    background-color: #fefefe;
    margin: 3% auto;
    padding: 20px;
    border: 1px solid #888;
    width: 80%;
    max-width: 500px;
    border-radius: 8px;
    max-height: 85%; /* 設定最大高度為視窗高度的 85% */
    overflow-y: auto; /* 內容過長時可以捲動 */
}

.modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 10px;
    padding-bottom: 5px;
    border-bottom: 1px solid #ddd;
}

.modal-title {
    margin: 0;
    font-size: 1.5rem;
}

.modal-close {		/* Modal window 右上角 X 關閉按鈕 */
    color: #aaa;
    float: right;
    font-size: 28px;
    font-weight: bold;
    cursor: pointer;
}

.modal-close:hover,
.modal-close:focus {
    color: #777;
    text-decoration: none;
    cursor: pointer;
}

.modal-close .material-symbols-outlined {
    font-size: 28px;
}

.modal-body {
    margin-bottom: 20px;
    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;
}

.modal-body img {		/* 確保圖片不會超出容器 */
    max-width: 100%;
    height: auto;
    display: block;
    margin: 0 auto 15px auto;
}

/* === Logo 樣式 === */

.logo-container {
    text-align: center;
    margin: 20px 0;
}

.logo-container img {
    max-width: 100%;
    height: auto;
}

/* === 訊息提示樣式 === */

.message-modal {
    display: none;
    position: fixed;
    top: 20%;
    right: 20px;
    z-index: 2000;
    animation: slideIn 0.3s ease-out;
}

.message-content {
    background-color: white;
    padding: 15px 20px;
    border-radius: 8px;
    box-shadow: 0 4px 12px rgba(0,0,0,0.15);
    max-width: 300px;
}

.message-body {
		white-space: pre-line;  /* 保留換行符號 */
    word-wrap: break-word;
}

.message-content.success {
    background-color: var(--success-bg);
    border: 1px solid var(--success-border);
    color: var(--success-text);
}

.message-content.error {
    background-color: var(--error-bg);
    border: 1px solid var(--error-border);
    color: var(--error-text);
}

.message-content.warning {
    background-color: var(--warning-bg);
    border: 1px solid var(--warning-border);
    color: var(--warning-text);
}

/* === 返回樣式 === */

.back-button-container {
		position: fixed;
    top: 10px;
    left: 10px;
    z-index: 1000;
}

.back-button {
    display: inline-flex;
    align-items: center;
    padding: 8px 16px;
    background-color: rgba(248, 249, 250, 0.8);  /* 半透明背景 */
    border: 1px solid #dee2e6;
    border-radius: 4px;
    color: #212529;
    text-decoration: none;
    font-weight: bold;
    transition: all 0.2s ease-in-out;
}

.back-button:hover {
    background-color: #e9ecef;
    text-decoration: none;
}

.back-arrow {
    margin-right: 8px;
    font-size: 1.2em;
}

/* === Menu 樣式 === */

.menu-container {
    position: fixed;
    top: 10px;
    right: 10px;
    z-index: 1000;
}

.menu-button {		/* 三 的圖示 */
    background-color: rgba(248, 249, 250, 0.9) !important; /* 白色背景，90%不透明 */
    border: 1px solid #ddd !important;
    padding: 10px 15px !important;
    border-radius: 4px !important;
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 5px;
    color: #212529 !important;
}

.menu-button:hover {
    background-color: #e9ecef !important;
}

.menu-content {
    display: none;
    position: absolute;
    right: 0;
    background-color: rgba(248, 249, 250, 0.9); /* 白色背景，90%不透明 */
    min-width: 180px;
    box-shadow: 0 8px 16px rgba(0,0,0,0.1);
    border-radius: 4px;
    margin-top: 5px;
}

.menu-content a {
    color: #212529;
    padding: 12px 16px;
    text-decoration: none;
    display: block;
    border-bottom: 1px solid #eee;
}

.menu-content a:last-child {
    border-bottom: none;
}

.menu-content a:hover {
    background-color: #e9ecef;
}

.menu-content.show {
    display: block;
}

/* Material Icons styling */
.menu-icon {
    font-size: 24px;
    margin-right: 5px;
}

/* === 驗證碼樣式 === */

.captcha-container {
    display: flex;
    align-items: center;
    margin-bottom: 15px;
    padding-left: 0;
}

.captcha-container img {
    max-width: 200px;
    border-radius: 0px;
    display: block;
    margin-left: 0;
    padding-left: 0;
}

.captcha-image {
    margin-right: 10px;
    cursor: pointer;
    border: 1px solid #ddd;
}

.captcha-refresh {
    cursor: pointer;
    color: #007bff;
}

/* === 分頁 樣式 === */

/* 分頁控制樣式 */
.pagination-control {
    display: flex;
    justify-content: flex-end;
    align-items: center;
    margin: 20px 0;
    padding: 0 20px;
}

.items-per-page {
    display: flex;
    align-items: center;
    justify-content: right;
    gap: 10px;
}

.items-per-page select {
    padding: 5px;
    border: 1px solid #ddd;
    border-radius: 4px;
    background-color: white;
    max-width: 100px;
}

.items-per-page label {
		margin-top: 0.7rem; /* 修改：label 下方間距 */
}

/* 分頁導航樣式 */
.pagination-nav {
    display: flex;
    justify-content: center;
    align-items: center;
    gap: 15px;
    margin: 20px 0;
    padding: 10px;
}

.page-btn {
    padding: 6px 12px;
    border: 1px solid #ddd;
    border-radius: 4px;
    background-color: white;
    cursor: pointer;
    transition: all 0.3s;
    max-width: 120px;
}

.page-btn:hover {
    background-color: #f0f0f0;
}

.page-btn:disabled {
    background-color: #f5f5f5;
    cursor: not-allowed;
    opacity: 0.6;
}

#pageInfo {
    font-size: 0.9em;
    color: #666;
    min-width: 100px;
    text-align: center;
}

/* === 操作欄位樣式 === */

table td.action-buttons {
    padding: 4px;
    text-align: center;
    white-space: nowrap;
}

.action-action .material-symbols-outlined {
    font-size: 18px; /* 調整圖示大小 */
}

.action-buttons .icon-button {	/* 圖示按鈕基本樣式 */
    background: none;
    border: none;
    cursor: pointer;
    padding: 4px;
    width: auto;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    border-radius: 4px;
    transition: all 0.3s ease;
}

.action-buttons .edit-icon-button {	/* 編輯按鈕樣式 */
    color: #fff !important;
    background-color: var(--primary-color) !important;
}

.action-buttons .edit-icon-button:hover {
    background-color: var(--primary-hover) !important;
}

.action-buttons .delete-icon-button {	/* 刪除按鈕樣式 */
    color: #fff !important;
    background-color: var(--danger-color) !important;
}

.action-buttons .delete-icon-button:hover {
    background-color: var(--danger-hover) !important;
}

.action-buttons .freight-icon-button {	/* 費用按鈕樣式 */
    color: #fff !important;
    background-color: var(--primary-color) !important;
}

.action-buttons .freight-icon-button:hover {
    background-color: var(--primary-hover) !important;
}

.action-buttons .date-icon-button {		/* 日期管理按鈕樣式 */
    color: #fff !important;
    background-color: #95B9C7 !important; /* 藍色 */
}

.action-buttons .date-icon-button:hover {
    background-color: #87AFC7 !important;
}

.action-buttons .active-icon-button {		/* 上架按鈕樣式 */
    color: #fff !important;
    background-color: #28a745 !important; /* 綠色 */
}

.action-buttons .active-icon-button:hover {
    background-color: #218838 !important;
}

.action-buttons .inactive-icon-button {		/* 下架按鈕樣式 */
    color: #fff !important;
    background-color: #6c757d !important; /* 灰色 */
}

.action-buttons .inactive-icon-button:hover {
    background-color: #5a6268 !important;
}

.action-buttons form {	/* 操作按鈕容器 */
    margin: 0;
    padding: 0;
}

/* === 公告 content === */

.announcement-block {
    display: flex;
    align-items: center;
  	justify-content: center;
}

.announcement-content {
    background-color: white;
    border-radius: 8px;
    padding: 20px;
    width: 80%;
    max-width: 500px;
    box-shadow: 0 4px 6px rgba(0,0,0,0.1);
}

.announcement-text {
    line-height: 1.6;
}

.announcement-text h3 {
    margin-bottom: 15px;
}

.announcement-text ul {
    list-style-type: disc;
    padding-left: 20px;
}

.announcement-text li {
    margin-bottom: 10px;
}

/* === form 欄位及其 label 控制樣式 === */

.form-group {
    margin-bottom: 10px;
}

.form-group label {
    display: block;
    margin-bottom: 0.25em;
    font-weight: bold;
    color: #333;
}

.form-group input[type="text"],
.form-group input[type="number"],
.form-group textarea {
    width: 100%;
    padding: 10px;
    border: 1px solid #ddd;
    border-radius: 4px;
    box-sizing: border-box;
    transition: border-color 0.3s;
}

.form-group input[type="file"] {
    padding: 10px 0;
}

.form-group input:focus,
.form-group textarea:focus {
    border-color: var(--primary-color);
    outline: none;
    box-shadow: 0 0 5px rgba(193, 154, 107, 0.2);
}

.form-group input[type="date"] {
    font-family: inherit;
    font-size: 16px;
    color: #333;
}

.form-group input[type="date"]::-webkit-calendar-picker-indicator {
    cursor: pointer;
}

/* modal 上的 button group */
.form-group .btn-group {
		display: flex;
		justify-content: flex-start;
		gap: 20px;
}

/* === Loading 遮罩樣式 === */

.loading-overlay {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(0, 0, 0, 0.5);
    z-index: 9999;
    justify-content: center;
    align-items: center;
}

.loading-spinner {
    background-color: white;
    padding: 20px;
    border-radius: 8px;
    text-align: center;
    box-shadow: 0 2px 10px rgba(0, 0, 0, 0.1);
}

.loading-spinner span {
    display: block;
    margin-bottom: 10px;
}

.loading-spinner .material-symbols-outlined {
    font-size: 36px;
    animation: spin 2s linear infinite;
}

@keyframes spin {
    0% { transform: rotate(0deg); }
    100% { transform: rotate(360deg); }
}

/* === 排序相關樣式 === */

.sortable {
    cursor: pointer;
    text-decoration: none;
    color: inherit;
}

.sortable:hover {
    background-color: #f0f0f0;
}

.sort-icon {
    display: inline-block;
    margin-left: 5px;
}

/* === 回到頁首按鈕樣式 === */

.back-to-top {
    position: fixed;
    bottom: 50px;
    right: 30px;
    width: 50px;
    height: 50px;
    border-radius: 50%;
    background-color: #a67c52;
    color: white;
    box-shadow: 0 3px 10px rgba(0, 0, 0, 0.3);
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    z-index: 1000;
    transform: translateY(100px);
    opacity: 0;
    transition: all 0.3s ease;
}

.back-to-top.show {
    transform: translateY(0);
    opacity: 0.8;
}

.back-to-top:hover {
    background-color: #8a6642;
}

.back-to-top .material-symbols-outlined {
    font-size: 24px;
}


/* === 其他通用樣式 === */

/* label 可加上紅色星號 */
.required {
    color: var(--danger-color);
    margin-left: 4px;
}

/* 倒數計時 */
.countdown-timer {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    background: #ff4444;
    color: white;
    text-align: center;
    padding: 10px;
    z-index: 1000;
}

/* 一般訊息樣式 */
.message {
    padding: 12px;
    margin-bottom: 15px;
    border-radius: 4px;
    animation: fadeOut 0.5s ease-in-out 5s forwards;
}

.message.success {
    background-color: var(--success-bg);
    border: 1px solid var(--success-border);
    color: var(--success-text);
}

.message.error {
    background-color: var(--error-bg);
    border: 1px solid var(--error-border);
    color: var(--error-text);
}

img {
    max-width: 100px;
    border-radius: 4px;
    display: block;
    margin: 0 auto;
}

.loading {
    text-align: center;
    padding: 20px;
}

/* 禁用狀態的輸入框樣式 */
input[type="number"]:disabled {
    background-color: #f5f5f5;
    cursor: not-allowed;
}

@keyframes slideIn {
    from {
        transform: translateX(100%);
        opacity: 0;
    }
    to {
        transform: translateX(0);
        opacity: 1;
    }
}

@keyframes slideOut {
    from {
        transform: translateX(0);
        opacity: 1;
    }
    to {
        transform: translateX(100%);
        opacity: 0;
    }
}

/* 突出顯示行的樣式 */
@keyframes highlight-row {
    0% { background-color: #ffffff; }
    20% { background-color: #ffff6d; }
    80% { background-color: #ffff6d; }
    100% { background-color: #ffffff; }
}

.highlighted-row {
    animation: highlight-row 3s ease;
}

/* 確保手機版也能正確顯示 */
@media (max-width: 768px) {
    .back-button-container {
        top: 10px;
        left: 10px;
    }
    
    .back-button {
        padding: 8px 12px;
        font-size: 0.85rem;
    }

    .modal-content {
        margin: 3% auto; /* 在手機上讓視窗更靠上 */
        width: 90%;
        max-width: 320px;
        max-height: 90vh;
        padding: 15px;
    }
    
    .announcement-content {
    		width: 90%;
        max-width: 320px;
  	}

    .back-to-top {
        bottom: 50px;
        right: 10px;
        width: 40px;
        height: 40px;
    }
}
