/* 全域樣式重置 */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

/* 基礎樣式 */
body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Microsoft JhengHei',
        'PingFang TC', 'Noto Sans TC', sans-serif;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    min-height: 100vh;
    padding: 20px;
    line-height: 1.6;
}

/* 主容器 */
.container {
    max-width: 900px;
    margin: 0 auto;
}

/* 頭部區域 */
header {
    text-align: center;
    color: white;
    margin-bottom: 40px;
    animation: fadeInDown 0.6s ease-out;
}

header h1 {
    font-size: 2.5rem;
    font-weight: 700;
    text-shadow: 2px 2px 4px rgba(0, 0, 0, 0.2);
    margin-bottom: 10px;
}

header .subtitle {
    font-size: 1.1rem;
    opacity: 0.95;
}

/* 主要內容區域 */
main {
    background: white;
    border-radius: 16px;
    padding: 40px;
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.3);
    animation: fadeInUp 0.6s ease-out;
}

/* 搜尋框區域 */
.search-box {
    display: flex;
    gap: 12px;
    margin-bottom: 30px;
}

#drugInput {
    flex: 1;
    padding: 14px 20px;
    font-size: 16px;
    border: 2px solid #e0e0e0;
    border-radius: 8px;
    transition: all 0.3s ease;
    font-family: inherit;
}

#drugInput:focus {
    outline: none;
    border-color: #667eea;
    box-shadow: 0 0 0 3px rgba(102, 126, 234, 0.1);
}

#drugInput::placeholder {
    color: #999;
}

#searchBtn {
    padding: 14px 32px;
    font-size: 16px;
    font-weight: 600;
    color: white;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    border: none;
    border-radius: 8px;
    cursor: pointer;
    transition: all 0.2s ease;
    font-family: inherit;
}

#searchBtn:hover {
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(102, 126, 234, 0.4);
}

#searchBtn:active {
    transform: translateY(0);
}

#searchBtn:disabled {
    opacity: 0.6;
    cursor: not-allowed;
    transform: none;
}

/* 載入中狀態 */
.loading {
    text-align: center;
    padding: 40px;
    color: #666;
}

.spinner {
    width: 40px;
    height: 40px;
    margin: 0 auto 16px;
    border: 4px solid #f3f3f3;
    border-top: 4px solid #667eea;
    border-radius: 50%;
    animation: spin 1s linear infinite;
}

@keyframes spin {
    0% {
        transform: rotate(0deg);
    }

    100% {
        transform: rotate(360deg);
    }
}

/* 結果區域 */
.results {
    animation: fadeIn 0.4s ease-out;
}

.results h2 {
    color: #333;
    margin-bottom: 24px;
    font-size: 1.5rem;
}

/* 交互作用項目 */
.interaction-item {
    background: #f8f9fa;
    border-left: 4px solid #667eea;
    border-radius: 8px;
    padding: 20px;
    margin-bottom: 16px;
    transition: all 0.3s ease;
    animation: slideIn 0.4s ease-out;
}

.interaction-item:hover {
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
    transform: translateX(4px);
}

.interaction-header {
    display: flex;
    align-items: center;
    gap: 12px;
    margin-bottom: 12px;
    flex-wrap: wrap;
}

.index {
    background: #667eea;
    color: white;
    padding: 4px 12px;
    border-radius: 12px;
    font-size: 14px;
    font-weight: 600;
    flex-shrink: 0;
}

.drug-name {
    color: #764ba2;
    font-weight: 600;
    font-size: 16px;
}

.interaction-description {
    color: #555;
    line-height: 1.8;
    font-size: 15px;
    white-space: pre-line;
    word-wrap: break-word;
}

/* 無結果訊息 */
.no-results {
    text-align: center;
    padding: 60px 20px;
    color: #999;
    font-size: 18px;
}

/* 錯誤訊息 */
.error {
    background: #fee;
    color: #c33;
    padding: 16px;
    border-radius: 8px;
    border-left: 4px solid #c33;
    margin-bottom: 16px;
}

/* 頁尾 */
footer {
    text-align: center;
    color: white;
    margin-top: 40px;
    opacity: 0.8;
    font-size: 14px;
}

/* 管理員按鈕 */
.admin-btn {
    padding: 10px 20px;
    background: rgba(255, 255, 255, 0.2);
    color: white;
    border: 2px solid white;
    border-radius: 8px;
    cursor: pointer;
    font-size: 14px;
    font-weight: 600;
    transition: all 0.3s ease;
    backdrop-filter: blur(10px);
}

.admin-btn:hover {
    background: rgba(255, 255, 255, 0.3);
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.2);
}

/* Modal 樣式 */
.modal {
    display: none;
    position: fixed;
    z-index: 1000;
    left: 0;
    top: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(0, 0, 0, 0.5);
    backdrop-filter: blur(5px);
    animation: fadeIn 0.3s ease;
}

.modal-content {
    background-color: white;
    margin: 5% auto;
    padding: 30px;
    border-radius: 12px;
    width: 90%;
    max-width: 600px;
    max-height: 80vh;
    overflow-y: auto;
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.3);
    animation: slideDown 0.3s ease;
}

.admin-modal-content {
    max-width: 95%;
    max-height: 90vh;
    padding: 20px;
}

.modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 20px;
    padding-bottom: 15px;
    border-bottom: 2px solid #e0e0e0;
}

.modal-header h2 {
    margin: 0;
    color: #333;
}

.close-btn {
    background: none;
    border: none;
    font-size: 32px;
    color: #999;
    cursor: pointer;
    padding: 0;
    width: 32px;
    height: 32px;
    line-height: 32px;
    transition: color 0.2s;
}

.close-btn:hover {
    color: #333;
}

.modal-buttons {
    display: flex;
    gap: 12px;
    margin-top: 20px;
    justify-content: flex-end;
}

.modal-buttons button {
    padding: 10px 24px;
    border: none;
    border-radius: 6px;
    cursor: pointer;
    font-size: 14px;
    font-weight: 600;
    transition: all 0.2s;
}

.modal-buttons button.primary {
    background: #667eea;
    color: white;
}

.modal-buttons button.primary:hover {
    background: #5568d3;
}

.modal-buttons button.cancel-btn {
    background: #e0e0e0;
    color: #333;
}

.modal-buttons button.cancel-btn:hover {
    background: #d0d0d0;
}

#passwordInput {
    width: 100%;
    padding: 12px;
    font-size: 16px;
    border: 2px solid #e0e0e0;
    border-radius: 6px;
    margin-top: 10px;
    box-sizing: border-box;
}

#passwordInput:focus {
    outline: none;
    border-color: #667eea;
}

.error-message {
    color: #c33;
    font-size: 14px;
    margin-top: 10px;
}

/* 管理員控制區域 */
.admin-controls {
    display: flex;
    gap: 12px;
    margin-bottom: 20px;
    flex-wrap: wrap;
}

.admin-action-btn {
    padding: 8px 16px;
    background: #667eea;
    color: white;
    border: none;
    border-radius: 6px;
    cursor: pointer;
    font-size: 14px;
    font-weight: 600;
    transition: all 0.2s;
}

.admin-action-btn:hover {
    background: #5568d3;
}

.admin-action-btn.primary {
    background: #28a745;
}

.admin-action-btn.primary:hover {
    background: #218838;
}

/* 管理員表格 */
.admin-table-container {
    max-height: 60vh;
    overflow-y: auto;
    border: 1px solid #e0e0e0;
    border-radius: 8px;
}

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

.admin-table thead {
    background: #f8f9fa;
    position: sticky;
    top: 0;
    z-index: 10;
}

.admin-table th {
    padding: 12px;
    text-align: left;
    font-weight: 600;
    color: #333;
    border-bottom: 2px solid #e0e0e0;
    font-size: 14px;
}

.admin-table td {
    padding: 12px;
    border-bottom: 1px solid #f0f0f0;
    font-size: 14px;
    vertical-align: top;
}

.admin-table tr:hover {
    background: #f8f9fa;
}

.admin-table .description-cell {
    max-width: 300px;
    word-wrap: break-word;
    white-space: pre-wrap;
}

.admin-table .action-cell {
    white-space: nowrap;
}

.action-btn {
    padding: 6px 12px;
    margin: 0 4px;
    border: none;
    border-radius: 4px;
    cursor: pointer;
    font-size: 12px;
    font-weight: 600;
    transition: all 0.2s;
}

.action-btn.edit {
    background: #667eea;
    color: white;
}

.action-btn.edit:hover {
    background: #5568d3;
}

.action-btn.delete {
    background: #dc3545;
    color: white;
}

.action-btn.delete:hover {
    background: #c82333;
}

/* 表單樣式 */
.form-group {
    margin-bottom: 20px;
}

.form-group label {
    display: block;
    margin-bottom: 8px;
    font-weight: 600;
    color: #333;
    font-size: 14px;
}

.form-group input,
.form-group textarea {
    width: 100%;
    padding: 10px;
    font-size: 14px;
    border: 2px solid #e0e0e0;
    border-radius: 6px;
    font-family: inherit;
    box-sizing: border-box;
}

.form-group input:focus,
.form-group textarea:focus {
    outline: none;
    border-color: #667eea;
}

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

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

/* 動畫效果 */
@keyframes fadeInDown {
    from {
        opacity: 0;
        transform: translateY(-20px);
    }

    to {
        opacity: 1;
        transform: translateY(0);
    }
}

@keyframes fadeInUp {
    from {
        opacity: 0;
        transform: translateY(20px);
    }

    to {
        opacity: 1;
        transform: translateY(0);
    }
}

@keyframes fadeIn {
    from {
        opacity: 0;
    }

    to {
        opacity: 1;
    }
}

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

    to {
        opacity: 1;
        transform: translateX(0);
    }
}

/* 響應式設計 - 平板 */
@media (max-width: 768px) {
    header h1 {
        font-size: 2rem;
    }

    header .subtitle {
        font-size: 1rem;
    }

    main {
        padding: 24px;
    }

    .search-box {
        flex-direction: column;
    }

    #searchBtn {
        width: 100%;
    }

    .interaction-header {
        flex-direction: column;
        align-items: flex-start;
    }
}

/* 響應式設計 - 手機 */
@media (max-width: 480px) {
    body {
        padding: 12px;
    }

    header h1 {
        font-size: 1.6rem;
    }

    header .subtitle {
        font-size: 0.9rem;
    }

    main {
        padding: 20px;
    }

    #drugInput,
    #searchBtn {
        font-size: 14px;
        padding: 12px 16px;
    }

    .results h2 {
        font-size: 1.2rem;
    }

    .interaction-item {
        padding: 16px;
    }

    .interaction-description {
        font-size: 14px;
    }
}

/* 複製控制區域 */
.copy-controls {
    margin: 20px 0;
    padding: 12px;
    background: #f0f0f0;
    border-radius: 8px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-wrap: wrap;
    gap: 12px;
}

.copy-btn {
    padding: 8px 20px;
    background: #667eea;
    color: white;
    border: none;
    border-radius: 6px;
    cursor: pointer;
    font-size: 14px;
    font-weight: 600;
    transition: all 0.2s ease;
    font-family: inherit;
}

.copy-btn:hover {
    background: #5568d3;
    transform: translateY(-1px);
    box-shadow: 0 2px 8px rgba(102, 126, 234, 0.3);
}

.copy-btn:active {
    transform: translateY(0);
}

/* Checkbox 樣式 */
.item-checkbox {
    width: 20px;
    height: 20px;
    margin-top: 4px;
    cursor: pointer;
    flex-shrink: 0;
    accent-color: #667eea;
}

#selectAll,
#selectAllBottom {
    width: 18px;
    height: 18px;
    cursor: pointer;
    accent-color: #667eea;
}

/* 選中的項目高亮 */
.interaction-item:has(.item-checkbox:checked) {
    background: #e8f0fe;
    border-left-color: #4285f4;
}

/* 列印樣式 */
@media print {
    body {
        background: white;
        padding: 0;
    }

    .search-box,
    footer,
    .copy-controls,
    .item-checkbox {
        display: none;
    }

    main {
        box-shadow: none;
        padding: 20px;
    }

    .interaction-item {
        page-break-inside: avoid;
    }
}