/* 重置和基础样式 - 增强浏览器兼容性 */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
    -webkit-box-sizing: border-box;
    -moz-box-sizing: border-box;
}

body {
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    line-height: 1.6;
    color: #333;
    background-color: #f5f5f5;
}

.container {
    max-width: 1200px;
    margin: 0 auto;
    padding: 0 15px;
}

/* 头部样式 */
header {
    background: #667eea;
    background: -webkit-linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
    padding: 1rem 0;
    box-shadow: 0 2px 10px rgba(0,0,0,0.1);
    position: relative;
    z-index: 1000;
}

header:after {
    content: "";
    display: table;
    clear: both;
}

header h1 {
    display: inline-block;
    font-size: 1.8rem;
    float: left;
}

.user-info {
    float: right;
    font-size: 0.9rem;
}

.user-info a {
    color: white;
    text-decoration: none;
    margin-left: 10px;
    -webkit-transition: opacity 0.3s;
    transition: opacity 0.3s;
    display: inline-block;
}

.user-info a:hover {
    opacity: 0.8;
}

/* 主内容区域 */
main {
    padding: 2rem 0;
    min-height: calc(100vh - 120px);
}

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

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

.login-form h1 {
    text-align: center;
    margin-bottom: 0.5rem;
    color: #333;
}

.login-form p {
    text-align: center;
    margin-bottom: 1.5rem;
    color: #666;
}

.form-group {
    margin-bottom: 1rem;
    width: 100%;
}

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

.form-group input,
.form-group textarea,
.form-group select {
    width: 100%;
    padding: 0.75rem;
    border: 1px solid #ddd;
    border-radius: 5px;
    font-size: 1rem;
    -webkit-appearance: none;
    -moz-appearance: none;
    appearance: none;
}

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

/* 按钮样式 */
.btn, .login-btn {
    background: #667eea;
    background: -webkit-linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
    border: none;
    padding: 0.75rem 1.5rem;
    border-radius: 5px;
    cursor: pointer;
    font-size: 1rem;
    -webkit-transition: all 0.2s;
    transition: all 0.2s;
    display: inline-block;
    text-decoration: none;
    text-align: center;
}

.btn:hover, .login-btn:hover {
    -webkit-transform: translateY(-2px);
    transform: translateY(-2px);
    box-shadow: 0 5px 15px rgba(0,0,0,0.2);
}

.login-btn {
    width: 100%;
    font-size: 1.1rem;
    padding: 0.9rem;
}

.btn-cancel {
    background: #6c757d !important;
}

.btn-cancel:hover {
    background: #5a6268 !important;
}

/* 错误消息 */
.error-message {
    background: #fee;
    color: #c33;
    padding: 0.75rem;
    border-radius: 5px;
    margin-bottom: 1rem;
    border-left: 4px solid #c33;
}

/* 注册链接 */
.register-link {
    margin-top: 1.5rem;
    padding-top: 1.5rem;
    border-top: 1px solid #eee;
    text-align: center;
}

.register-link a {
    color: #667eea;
    text-decoration: none;
    font-weight: 500;
}

.register-link a:hover {
    text-decoration: underline;
}

/* 登录说明 */
.login-note {
    margin-top: 1.5rem;
    padding-top: 1.5rem;
    border-top: 1px solid #eee;
    font-size: 0.9rem;
    color: #666;
}

.login-note p {
    margin-bottom: 0.5rem;
    text-align: left;
}

/* 仪表板头部 */
.dashboard-header {
    display: -webkit-box;
    display: -ms-flexbox;
    display: flex;
    -webkit-box-pack: justify;
    -ms-flex-pack: justify;
    justify-content: space-between;
    -webkit-box-align: center;
    -ms-flex-align: center;
    align-items: center;
    margin-bottom: 2rem;
    -ms-flex-wrap: wrap;
    flex-wrap: wrap;
    gap: 1rem;
}

.search-box {
    position: relative;
    width: 300px;
}

.search-box input {
    width: 100%;
    padding: 0.75rem 2.5rem 0.75rem 1rem;
    border: 1px solid #ddd;
    border-radius: 25px;
    font-size: 1rem;
}

.search-box i {
    position: absolute;
    right: 1rem;
    top: 50%;
    -webkit-transform: translateY(-50%);
    transform: translateY(-50%);
    color: #666;
}

/* 工具网格布局 - 使用更兼容的Flexbox方法 */
.tools-grid.compact {
    display: -webkit-box;
    display: -ms-flexbox;
    display: flex;
    -ms-flex-wrap: wrap;
    flex-wrap: wrap;
    gap: 1.5rem;
    margin-top: 1.5rem;
    -webkit-box-pack: start;
    -ms-flex-pack: start;
    justify-content: flex-start;
}

/* 正方形卡片样式 - 使用固定宽度和百分比确保多列 */
.tool-card.compact {
    background: white;
    border-radius: 10px;
    padding: 1.5rem 1rem;
    text-decoration: none;
    color: inherit;
    display: -webkit-box;
    display: -ms-flexbox;
    display: flex;
    -webkit-box-orient: vertical;
    -webkit-box-direction: normal;
    -ms-flex-direction: column;
    flex-direction: column;
    -webkit-box-align: center;
    -ms-flex-align: center;
    align-items: center;
    -webkit-box-pack: center;
    -ms-flex-pack: center;
    justify-content: center;
    text-align: center;
    box-shadow: 0 3px 15px rgba(0,0,0,0.1);
    -webkit-transition: all 0.3s ease;
    transition: all 0.3s ease;
    width: calc(25% - 1.5rem); /* 默认4列 */
    min-height: 150px;
    position: relative;
}

.tool-card.compact:hover {
    -webkit-transform: translateY(-5px);
    transform: translateY(-5px);
    box-shadow: 0 8px 25px rgba(0,0,0,0.15);
    color: inherit;
}

.tool-icon {
    font-size: 2rem;
    color: #667eea;
    margin-bottom: 0.75rem;
    display: block;
}

.tool-card.compact h3 {
    font-size: 0.9rem;
    margin-bottom: 0.5rem;
    font-weight: 600;
    line-height: 1.3;
    width: 100%;
}

.tool-badge {
    background: #f0f0f0;
    color: #666;
    padding: 0.25rem 0.5rem;
    border-radius: 12px;
    font-size: 0.7rem;
    margin-top: auto;
}

/* 置顶工具样式 */
.tool-card.compact.top-tool {
    border: 2px solid #ffd700;
    background: linear-gradient(135deg, #fff9e6 0%, #fff0b3 100%);
}

.top-badge {
    position: absolute;
    top: 5px;
    right: 5px;
    background: #ffd700;
    color: #333;
    padding: 0.2rem 0.5rem;
    border-radius: 10px;
    font-size: 0.6rem;
    font-weight: bold;
}

.top-badge i {
    margin-right: 2px;
}

/* 公共工具和私有工具徽章样式 */
.public-badge {
    background: #28a745 !important;
    color: white !important;
}

.private-badge {
    background: #6c757d !important;
    color: white !important;
}

/* 管理页面卡片样式 */
.tool-card.compact.admin {
    padding-bottom: 3.5rem; /* 为操作按钮留空间 */
}

.tool-actions {
    position: absolute;
    bottom: 1rem;
    left: 0;
    right: 0;
    display: -webkit-box;
    display: -ms-flexbox;
    display: flex;
    -webkit-box-pack: center;
    -ms-flex-pack: center;
    justify-content: center;
    gap: 0.5rem;
}

.tool-btn, .delete-btn, .edit-btn, .top-btn {
    padding: 0.4rem 0.8rem;
    border-radius: 5px;
    text-decoration: none;
    font-size: 0.8rem;
    -webkit-transition: all 0.3s;
    transition: all 0.3s;
    border: none;
    cursor: pointer;
    display: inline-block;
}

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

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

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

.top-btn {
    background: #ffc107 !important;
    color: #333 !important;
}

.tool-btn:hover, .delete-btn:hover, .edit-btn:hover {
    opacity: 0.8;
    color: white;
}

.top-btn:hover {
    background: #e0a800 !important;
    color: #333 !important;
}

/* 复选框样式 */
.checkbox-label {
    display: flex;
    align-items: center;
    cursor: pointer;
    margin-bottom: 0.5rem;
    padding: 0.5rem 0;
}

.checkbox-label input[type="checkbox"] {
    margin-right: 0.5rem;
    width: auto;
    transform: scale(1.2);
}

.checkbox-text {
    font-weight: 500;
    margin-right: 0.5rem;
}

.checkbox-help {
    color: #666;
    font-style: italic;
    font-size: 0.85rem;
}

/* 无工具状态 */
.no-tools {
    text-align: center;
    padding: 3rem;
    color: #666;
}

.no-tools i {
    font-size: 3rem;
    margin-bottom: 1rem;
    opacity: 0.5;
    display: block;
}

/* 管理面板样式 */
.admin-panel {
    background: white;
    padding: 2rem;
    border-radius: 10px;
    box-shadow: 0 3px 15px rgba(0,0,0,0.1);
}

.admin-panel h2 {
    margin-bottom: 1.5rem;
    color: #333;
    border-bottom: 2px solid #f0f0f0;
    padding-bottom: 0.5rem;
}

.add-tool-form, .add-user-form {
    background: #f9f9f9;
    padding: 1.5rem;
    border-radius: 8px;
    margin-bottom: 2rem;
}

.add-tool-form h3, .add-user-form h3 {
    margin-bottom: 1rem;
    color: #555;
}

/* 表格样式 */
.tools-table {
    width: 100%;
    border-collapse: collapse;
    margin-top: 1rem;
    display: table;
}

.tools-table th,
.tools-table td {
    padding: 0.75rem;
    text-align: left;
    border-bottom: 1px solid #eee;
    display: table-cell;
}

.tools-table th {
    background: #f8f9fa;
    font-weight: 600;
    color: #555;
}

.url-cell {
    max-width: 200px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.no-action {
    color: #999;
    font-style: italic;
}

/* 页脚样式 */
footer {
    background: #333;
    color: white;
    text-align: center;
    padding: 1.5rem 0;
    margin-top: 2rem;
    clear: both;
}

footer a {
    color: #ddd;
    text-decoration: none;
}

footer a:hover {
    color: white;
}

.login-footer {
    background: transparent;
    color: white;
    position: absolute;
    bottom: 0;
    width: 100%;
    left: 0;
    right: 0;
}

/* 响应式设计 - 使用更可靠的列数控制 */
/* 大屏幕 - 4列 */
@media (min-width: 1200px) {
    .tool-card.compact {
        width: calc(25% - 1.5rem); /* 4列 */
    }
}

/* 中等屏幕 - 3列 */
@media (max-width: 1199px) and (min-width: 992px) {
    .tool-card.compact {
        width: calc(33.333% - 1.5rem); /* 3列 */
    }
}

/* 小屏幕 - 3列 */
@media (max-width: 991px) and (min-width: 768px) {
    .tool-card.compact {
        width: calc(33.333% - 1.5rem); /* 3列 */
    }
}

/* 平板设备 - 2列 */
@media (max-width: 767px) and (min-width: 576px) {
    .tools-grid.compact {
        gap: 1rem;
    }
    
    .tool-card.compact {
        width: calc(50% - 1rem); /* 2列 */
        min-height: 130px;
        padding: 1rem 0.5rem;
    }
    
    .tool-icon {
        font-size: 1.5rem;
        margin-bottom: 0.5rem;
    }
    
    .tool-card.compact h3 {
        font-size: 0.8rem;
    }
    
    .tool-badge {
        font-size: 0.65rem;
        padding: 0.2rem 0.4rem;
    }
    
    header h1 {
        float: none;
        display: block;
        text-align: center;
        margin-bottom: 0.5rem;
    }
    
    .user-info {
        float: none;
        text-align: center;
        display: block;
    }
}

/* 手机设备 - 2列 */
@media (max-width: 575px) {
    .container {
        padding: 0 10px;
    }
    
    header h1 {
        display: block;
        margin-bottom: 0.5rem;
        font-size: 1.5rem;
        float: none;
        text-align: center;
    }
    
    .user-info {
        float: none;
        display: block;
        font-size: 0.8rem;
        text-align: center;
    }
    
    .dashboard-header {
        -webkit-box-orient: vertical;
        -webkit-box-direction: normal;
        -ms-flex-direction: column;
        flex-direction: column;
        -webkit-box-align: stretch;
        -ms-flex-align: stretch;
        align-items: stretch;
    }
    
    .search-box {
        width: 100%;
    }
    
    .tools-grid.compact {
        gap: 0.8rem;
    }
    
    .tool-card.compact {
        width: calc(50% - 0.8rem); /* 2列 */
        min-height: 110px;
        padding: 0.8rem 0.4rem;
    }
    
    .tool-icon {
        font-size: 1.3rem;
        margin-bottom: 0.4rem;
    }
    
    .tool-card.compact h3 {
        font-size: 0.75rem;
    }
    
    .tool-badge {
        font-size: 0.6rem;
        padding: 0.15rem 0.3rem;
    }
    
    /* 管理页面卡片在移动端的优化 */
    .tool-card.compact.admin {
        padding-bottom: 2.5rem;
    }
    
    .tool-actions {
        bottom: 0.5rem;
    }
    
    .tool-btn, .delete-btn, .edit-btn, .top-btn {
        padding: 0.3rem 0.6rem;
        font-size: 0.7rem;
    }
    
    .admin-panel {
        padding: 1rem;
    }
    
    main {
        padding: 1rem 0;
    }
}

/* 小屏手机 - 保持2列但更紧凑 */
@media (max-width: 400px) {
    .tools-grid.compact {
        gap: 0.6rem;
    }
    
    .tool-card.compact {
        width: calc(50% - 0.6rem); /* 2列 */
        min-height: 100px;
        padding: 0.7rem 0.3rem;
    }
    
    .tool-icon {
        font-size: 1.2rem;
    }
    
    .tool-card.compact h3 {
        font-size: 0.7rem;
    }
    
    .tool-actions {
        gap: 0.3rem;
    }
    
    .tool-btn, .delete-btn, .edit-btn, .top-btn {
        padding: 0.25rem 0.5rem;
        font-size: 0.65rem;
    }
}

/* 极小屏幕 - 保持2列但进一步压缩 */
@media (max-width: 320px) {
    .tools-grid.compact {
        gap: 0.5rem;
    }
    
    .tool-card.compact {
        width: calc(50% - 0.5rem); /* 2列 */
        min-height: 90px;
        padding: 0.6rem 0.2rem;
    }
    
    .tool-icon {
        font-size: 1.1rem;
        margin-bottom: 0.3rem;
    }
    
    .tool-card.compact h3 {
        font-size: 0.65rem;
    }
}

/* 清除浮动辅助类 */
.clearfix:after {
    content: "";
    display: table;
    clear: both;
}

/* 确保所有链接在不同浏览器中显示一致 */
a {
    color: #667eea;
    -webkit-transition: color 0.3s;
    transition: color 0.3s;
}

/* 确保表单元素在 Safari 中显示正常 */
input, textarea, select {
    -webkit-appearance: none;
    -moz-appearance: none;
    appearance: none;
    border-radius: 0;
}
/* 置顶按钮激活状态 */
.top-btn.top-active {
    background: #ffc107 !important;
    color: #333 !important;
    box-shadow: 0 0 5px rgba(255, 193, 7, 0.5);
}

/* 管理员置顶标识 */
.tool-badge small {
    display: block;
    font-size: 0.6rem;
    margin-top: 2px;
    opacity: 0.8;
}
/* 修复 iOS Safari 的按钮样式 */
button, input[type="submit"], input[type="button"] {
    -webkit-appearance: none;
    -moz-appearance: none;
    appearance: none;
}

/* 确保图标正确显示 */
.fas, .fa {
    display: inline-block;
}
/* PWA 相关样式 */
.pwa-prompt {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.5);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 10000;
}

.pwa-prompt-content {
    background: white;
    padding: 2rem;
    border-radius: 10px;
    text-align: center;
    max-width: 400px;
    width: 90%;
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.3);
}

.pwa-prompt-actions {
    display: flex;
    gap: 1rem;
    justify-content: center;
    margin-top: 1.5rem;
}

.btn-install {
    background: #28a745 !important;
}

.btn-install:hover {
    background: #218838 !important;
}

/* 网络状态提示 */
.network-status {
    position: fixed;
    top: 20px;
    right: 20px;
    padding: 1rem 1.5rem;
    border-radius: 5px;
    color: white;
    z-index: 1000;
    animation: slideIn 0.3s ease;
}

.network-status-success {
    background: #28a745;
}

.network-status-error {
    background: #dc3545;
}

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

/* 独立模式下的特殊样式 */
.pwa-standalone header {
    padding-top: env(safe-area-inset-top);
}

/* 安装按钮样式 */
#pwa-install-btn {
    color: white;
    text-decoration: none;
    margin-left: 10px;
    padding: 0.25rem 0.5rem;
    background: rgba(255, 255, 255, 0.2);
    border-radius: 3px;
    transition: all 0.3s;
}

#pwa-install-btn:hover {
    background: rgba(255, 255, 255, 0.3);
}

/* 离线页面样式 */
.offline-container {
    display: flex;
    justify-content: center;
    align-items: center;
    min-height: 100vh;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    text-align: center;
    color: white;
}

.offline-content {
    background: rgba(255, 255, 255, 0.1);
    padding: 3rem;
    border-radius: 15px;
    backdrop-filter: blur(10px);
    max-width: 500px;
    width: 90%;
}

.offline-icon {
    font-size: 4rem;
    margin-bottom: 1rem;
    opacity: 0.8;
}

/* 移动端优化 */
@media (max-width: 768px) {
    .pwa-prompt-content {
        margin: 1rem;
        padding: 1.5rem;
    }
    
    .pwa-prompt-actions {
        flex-direction: column;
    }
    
    .network-status {
        left: 20px;
        right: 20px;
        top: 10px;
    }
}