/* 基础样式 */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Roboto', 'Helvetica Neue', Arial, sans-serif;
    background-color: #f5f5f5;
    color: #333;
    line-height: 1.6;
}

.page {
    min-height: 100vh;
}

/* 登录页面 */
.login-container {
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    min-height: 100vh;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
}

/* Modal responsiveness and scrollability */
.modal {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.45);
    overflow: auto; /* 允许小屏整体滚动 */
    padding: 16px;  /* 让内容不贴边 */
    z-index: 1000;
}

.modal .modal-content {
    background: #fff;
    margin: 5vh auto; /* 居中且留出顶部空间，便于小屏幕 */
    width: min(900px, 92vw);
    max-height: 90vh;  /* 关键：弹窗内部最高 90% 视高 */
    overflow: hidden;  /* 由内部区域滚动 */
    border-radius: 8px;
    box-shadow: 0 10px 30px rgba(0,0,0,0.2);
    display: flex;
    flex-direction: column;
}

/* 配置管理弹窗：编辑与查看更宽一些 */
#cfgModal .modal-content,
#cfgViewModal .modal-content {
    width: min(1200px, 96vw) !important; /* 提升为更宽，并强制覆盖通用样式 */
    max-width: none !important;
}

.modal .modal-header {
    position: sticky; /* 头部吸顶，方便在长内容中操作关闭 */
    top: 0;
    background: #fff;
    padding: 12px 16px;
    border-bottom: 1px solid #eee;
    z-index: 1;
}

.modal .modal-body {
    overflow-y: auto; /* 关键：内容区滚动 */
    padding: 16px;
}

.modal .form-actions {
    position: sticky; /* 底部操作按钮始终可见 */
    bottom: 0;
    background: #fff;
    padding: 12px 16px;
    border-top: 1px solid #eee;
    display: flex;
    gap: 8px;
    justify-content: flex-end;
}

@media (max-width: 600px) {
    table { min-width: 600px; } /* 小屏保留最小宽度，允许横向滚动查看 */
    .modal .modal-content { width: 96vw; max-height: 92vh; }
    .kv-row { grid-template-columns: 1fr; }
}

.login-container h1 {
    color: white;
    margin-bottom: 2rem;
    font-size: 2.5rem;
    text-shadow: 0 2px 4px rgba(0,0,0,0.3);
}

.login-form {
    background: white;
    padding: 2rem;
    border-radius: 10px;
    box-shadow: 0 10px 25px rgba(0,0,0,0.2);
    width: 100%;
    max-width: 400px;
}

.login-form input {
    width: 100%;
    padding: 12px;
    margin-bottom: 1rem;
    border: 2px solid #e1e1e1;
    border-radius: 6px;
    font-size: 16px;
    transition: border-color 0.3s;
}

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

/* 导航栏 */
.navbar {
    background: white;
    padding: 1rem 2rem;
    box-shadow: 0 2px 4px rgba(0,0,0,0.1);
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.nav-brand h2 {
    color: #333;
    font-weight: 600;
}

.nav-actions {
    display: flex;
    gap: 1rem;
    align-items: center;
}

/* 容器 */
.container {
    max-width: 1600px; /* 增加宽度以容纳更多内容 */
    margin: 0 auto;
    padding: 2rem;
}

/* 操作面板 */
.actions-panel {
    background: white;
    padding: 1.5rem;
    border-radius: 8px;
    box-shadow: 0 2px 4px rgba(0,0,0,0.1);
    margin-bottom: 2rem;
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 1rem;
    flex-wrap: wrap;
}

.actions-left {
    display: flex;
    gap: 1rem;
    flex-wrap: wrap;
}

.actions-right {
    display: flex;
    gap: 1rem;
    flex-wrap: wrap;
}

/* 账号列表区域 */
.accounts-section {
    background: white;
    border-radius: 8px;
    box-shadow: 0 2px 4px rgba(0,0,0,0.1);
    overflow: hidden;
}

.accounts-section h3 {
    padding: 1.5rem;
    margin: 0;
    background: #f8f9fa;
    border-bottom: 1px solid #e1e1e1;
    font-weight: 600;
    color: #333;
}

/* 表格样式 */
.table-container {
    overflow-x: auto;
    border-radius: 8px;
    box-shadow: 0 2px 4px rgba(0,0,0,0.1);
}

table {
    width: 100%;
    border-collapse: collapse;
    table-layout: fixed;
    min-width: 800px; /* 确保表格有最小宽度 */
}

th, td {
    padding: 12px 15px;
    text-align: left;
    border-bottom: 1px solid #e1e1e1;
    vertical-align: middle;
}

th {
    background: #f8f9fa;
    font-weight: 600;
    color: #555;
    position: sticky;
    top: 0;
}

/* 设置各列的宽度 */
/* 账号页表格列宽（保留）
th:nth-child(1), td:nth-child(1) { width: 10%; }
th:nth-child(2), td:nth-child(2) { width: 14%; }
th:nth-child(3), td:nth-child(3) { width: 6%; }
th:nth-child(4), td:nth-child(4) { width: 14%; }
th:nth-child(5), td:nth-child(5) { width: 14%; }
th:nth-child(6), td:nth-child(6) { width: 16%; }
th:nth-child(7), td:nth-child(7) { width: 26%; }
*/

/* 配置管理页表格列宽（更精准，只作用于配置页） */
table.configs-table {
    min-width: 1300px; /* 增加最小宽度，确保按钮不换行 */
}
table.configs-table th:nth-child(1),
table.configs-table td:nth-child(1) { width: 13%; } /* ID */
table.configs-table th:nth-child(2),
table.configs-table td:nth-child(2) { width: 12%; } /* ASIN */
table.configs-table th:nth-child(3),
table.configs-table td:nth-child(3) { width: 25%; } /* 标题 */
table.configs-table th:nth-child(4),
table.configs-table td:nth-child(4) { width: 20%; } /* ACCOUNT */
table.configs-table th:nth-child(5),
table.configs-table td:nth-child(5) { width: 8%; } /* 配置列 */
table.configs-table th:nth-child(6),
table.configs-table td:nth-child(6) { width: 22%; } /* 操作 - 足够宽以容纳所有按钮 */

/* 操作列按钮容器 */
table.configs-table td:nth-child(6) {
    gap: 8px;
}

/* 针对 ID 和 ASIN 列的优化 */
table.configs-table td:nth-child(1),
table.configs-table td:nth-child(2) {
    word-break: break-all;
    font-family: SFMono-Regular, Consolas, "Liberation Mono", Menlo, monospace;
    font-size: 0.85rem;
    color: #555;
    line-height: 1.4; /* 稍微紧凑一点的行高 */
}

/* 标题单元格内文本溢出处理：保持单行省略，配合更宽列更友好 */
table.configs-table td:nth-child(3) span {
    display: block;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

tr:hover {
    background-color: #f8f9fa;
}

/* 表格行交替颜色 */
tr:nth-child(even) {
    background-color: #fafafa;
}

tr:nth-child(even):hover {
    background-color: #f0f0f0;
}

/* 已禁用行的样式 */
tr.disabled-row {
    background-color: #f5f5f5 !important;
    opacity: 0.7;
}

.kv-list {
    display: flex;
    flex-direction: column;
    gap: 8px;
}
.kv-row {
    display: grid;
    grid-template-columns: 1fr 2fr auto;
    gap: 8px;
    align-items: center;
}
.kv-row .kv-key,
.kv-row .kv-value {
    padding: 8px;
}
.kv-row textarea.kv-key,
.kv-row textarea.kv-value {
    resize: both;         /* 支持水平/垂直放大 */
    min-height: 36px;
    font-family: inherit; /* 与页面风格一致 */
}
.btn.btn-xs {
    padding: 4px 8px;
    font-size: 12px;
}
tr.disabled-row:hover {
    background-color: #e9ecef !important;
}

tr.disabled-row:nth-child(even) {
    background-color: #f0f0f0 !important;
}

tr.disabled-row:nth-child(even):hover {
    background-color: #e0e0e0 !important;
}

/* 时间显示样式 */
.time-display {
    font-size: 12px;
    color: #666;
}

/* Token显示样式 */
.token-container {
    display: flex;
    align-items: center;
    gap: 4px;
}

.token-display {
    cursor: pointer;
    padding: 2px 6px;
    border-radius: 3px;
    font-family: monospace;
    font-size: 11px;
    background: #f8f9fa;
    border: 1px solid #e1e1e1;
    flex: 1;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.token-display.has-token {
    background: #e8f5e8;
    border-color: #28a745;
    color: #155724;
}

.token-display.no-token {
    background: #f8d7da;
    border-color: #dc3545;
    color: #721c24;
}

/* 按钮样式 */
.btn {
    padding: 8px 16px;
    border: none;
    border-radius: 6px;
    cursor: pointer;
    font-size: 14px;
    font-weight: 500;
    text-decoration: none;
    display: inline-flex;
    align-items: center;
    gap: 8px;
    transition: all 0.2s;
    position: relative;
}

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

.btn-primary {
    background: #007bff;
    color: white;
}

.btn-primary:hover:not(:disabled) {
    background: #0056b3;
}

.btn-success {
    background: #28a745;
    color: white;
}

.btn-success:hover:not(:disabled) {
    background: #1e7e34;
}

.btn-warning {
    background: #ffc107;
    color: #212529;
}

.btn-warning:hover:not(:disabled) {
    background: #e0a800;
}

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

.btn-danger:hover:not(:disabled) {
    background: #c82333;
}

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

.btn-secondary:hover:not(:disabled) {
    background: #545b62;
}

.btn-info {
    background: #17a2b8;
    color: white;
}

.btn-info:hover:not(:disabled) {
    background: #138496;
}

.btn-outline {
    background: transparent;
    color: #007bff;
    border: 2px solid #007bff;
}

.btn-outline:hover:not(:disabled) {
    background: #007bff;
    color: white;
}

.btn-sm {
    padding: 4px 8px;
    font-size: 12px;
}

/* 状态标签 */
.status {
    padding: 4px 8px;
    border-radius: 4px;
    font-size: 12px;
    font-weight: 500;
    text-transform: uppercase;
    display: inline-block;
    white-space: nowrap;
    margin-bottom: 2px;
}

.status.active {
    background: #d4edda;
    color: #155724;
}

.status.failed {
    background: #f8d7da;
    color: #721c24;
}

.status.pending {
    background: #fff3cd;
    color: #856404;
}

.status.expired {
    background: #e2e3e5;
    color: #383d41;
}

.status.disabled {
    background: #c8c7c7;
    color: #5b5b5b;
    font-size: 11px;
}

/* 状态列容器 */
.status-container {
    display: flex;
    flex-direction: column;
    gap: 2px;
    align-items: flex-start;
}

/* 平台标签 */
.platform-tag {
    padding: 4px 8px;
    border-radius: 4px;
    font-size: 12px;
    font-weight: 500;
    text-transform: uppercase;
}

.platform-tag.sif {
    background: #e3f2fd;
    color: #0d47a1;
}

.platform-tag.sellersprite {
    background: #f3e5f5;
    color: #4a148c;
}

.platform-tag.sorftime {
    background: #e8f5e8;
    color: #1b5e20;
}

.platform-tag.xiyouzhaoci {
    background: #fff3e0;
    color: #e65100;
}

/* 领星ERP 平台标签 */
.platform-tag.lingxing {
    background: #e6f7ff; /* 浅蓝背景 */
    color: #0050b3;     /* 深蓝文字 */
}

/* 模态框 */
.modal {
    display: none;
    position: fixed;
    z-index: 1000;
    left: 0;
    top: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(0,0,0,0.5);
    animation: fadeIn 0.3s;
}

.modal-content {
    background-color: white;
    margin: 5% auto;
    width: 90%;
    max-width: 500px;
    border-radius: 8px;
    box-shadow: 0 4px 20px rgba(0,0,0,0.3);
    animation: slideIn 0.3s;
}

.modal-header {
    padding: 1.5rem;
    border-bottom: 1px solid #e1e1e1;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

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

.close {
    color: #aaa;
    font-size: 28px;
    font-weight: bold;
    cursor: pointer;
    line-height: 1;
}

.close:hover {
    color: #333;
}

.modal-body {
    padding: 1.5rem;
}

/* 表单样式 */
.form-group {
    margin-bottom: 1.5rem;
}

.form-group label {
    display: block;
    margin-bottom: 0.5rem;
    font-weight: 500;
    color: #333;
}

.form-group input,
.form-group select {
    width: 100%;
    padding: 10px;
    border: 2px solid #e1e1e1;
    border-radius: 6px;
    font-size: 14px;
    transition: border-color 0.3s;
}

.form-group input:focus,
.form-group select:focus {
    outline: none;
    border-color: #007bff;
}

.form-actions {
    display: flex;
    gap: 1rem;
    justify-content: flex-end;
    margin-top: 2rem;
}

/* 加载动画 */
.loading-spinner {
    width: 16px;
    height: 16px;
    border: 2px solid #f3f3f3;
    border-top: 2px solid #007bff;
    border-radius: 50%;
    animation: spin 1s linear infinite;
}

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

@keyframes fadeIn {
    from { opacity: 0; }
    to { opacity: 1; }
}

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

/* 消息提示 */
#messageContainer {
    position: fixed;
    top: 20px;
    right: 20px;
    z-index: 1100;
}

.message {
    padding: 12px 20px;
    margin-bottom: 10px;
    border-radius: 6px;
    box-shadow: 0 2px 10px rgba(0,0,0,0.2);
    animation: slideInRight 0.3s;
    max-width: 400px;
}

.message.success {
    background: #d4edda;
    color: #155724;
    border-left: 4px solid #28a745;
}

.message.error {
    background: #f8d7da;
    color: #721c24;
    border-left: 4px solid #dc3545;
}

.message.info {
    background: #d1ecf1;
    color: #0c5460;
    border-left: 4px solid #17a2b8;
}

.message.warning {
    background: #fff3cd;
    color: #856404;
    border-left: 4px solid #ffc107;
}

@keyframes slideInRight {
    from { transform: translateX(100%); opacity: 0; }
    to { transform: translateX(0); opacity: 1; }
}

/* 加载指示器 */
#loadingIndicator {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 10px;
    padding: 2rem;
    color: #666;
}

/* 响应式设计 */
@media (max-width: 768px) {
    .container {
        padding: 1rem;
    }
    
    .navbar {
        padding: 1rem;
        flex-direction: column;
        gap: 1rem;
    }
    
    .nav-actions {
        width: 100%;
        justify-content: center;
    }
    
    .actions-panel {
        flex-direction: column;
        align-items: stretch;
    }
    
    .actions-left,
    .actions-right {
        justify-content: center;
    }
    
    .form-actions {
        flex-direction: column;
    }
    
    .modal-content {
        margin: 10% auto;
        width: 95%;
    }
    
    table {
        font-size: 14px;
    }
    
    th, td {
        padding: 8px 10px;
    }
}

/* Token 显示 */
.token-container {
    display: flex;
    align-items: center;
    gap: 8px;
}

.token-display {
    font-family: monospace;
    font-size: 12px;
    max-width: 200px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    padding: 4px 8px;
    border-radius: 4px;
    cursor: pointer;
    transition: background-color 0.2s;
    border: 1px solid transparent;
}

.token-display:hover {
    opacity: 0.8;
}

.token-display.has-token {
    color: #2d5a2d;
    background: #e8f5e8;
    border-color: #c3e6c3;
}

.token-display.no-token {
    color: #6c757d;
    font-style: italic;
    background: #f8f9fa;
    border-color: #dee2e6;
    cursor: default;
}

.token-full {
    margin-top: 8px;
}

.token-full textarea {
    font-family: monospace;
    font-size: 11px;
    resize: vertical;
    min-height: 60px;
    width: 100%;
}

.btn-xs {
    padding: 2px 6px;
    font-size: 10px;
    line-height: 1.2;
    border-radius: 3px;
}

/* 操作按钮组 */
.action-buttons {
    display: flex;
    gap: 4px;
    flex-wrap: wrap;
    align-items: center;
}

.action-buttons .btn {
    margin-bottom: 2px;
    white-space: nowrap;
}

/* 时间显示 */
.time-display {
    font-size: 12px;
    color: #666;
}

.time-display.recent {
    color: #666;
}

.time-display.old {
    color: #666;
}

/* 用户名列的长文本处理 */
.username-cell {
    display: block;
    width: 100%;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

/* 小屏允许换行避免遮挡 */
@media (max-width: 768px) {
    .username-cell {
        white-space: normal;
        word-break: break-all;
    }
}

