* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

/* Tokens defined in safari-tokens.css when loaded first */
:root {
    --primary-color: #007AFF;
    --secondary-color: #8e8e93;
    --danger-color: #ff3b30;
    --text-color: #000000;
    --bg-color: #f2f2f7;
    --card-bg: #ffffff;
    --border-color: rgba(60, 60, 67, 0.29);
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
    background-color: var(--bg-color);
    color: var(--text-color);
    line-height: 1.6;
    min-height: 100vh;
    display: flex;
    flex-direction: column;
}

.container {
    max-width: 1200px;
    margin: 0 auto;
    padding: 0 20px;
    width: 100%;
}

/* 导航栏 */
.navbar {
    background: var(--chrome-bg, rgba(255, 255, 255, 0.72));
    backdrop-filter: var(--chrome-blur, saturate(180%) blur(20px));
    -webkit-backdrop-filter: var(--chrome-blur, saturate(180%) blur(20px));
    color: var(--color-label, var(--text-color));
    padding: 0.75rem 0;
    padding-top: calc(0.75rem + env(safe-area-inset-top, 0px));
    border-bottom: 0.5px solid var(--color-separator, var(--border-color));
    box-shadow: none;
}

.navbar .container {
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.navbar-brand {
    font-size: 1.5rem;
    margin: 0;
}

.navbar-nav {
    display: flex;
    list-style: none;
    gap: 1.5rem;
}

.navbar-nav a {
    color: var(--color-tint, var(--primary-color));
    text-decoration: none;
    font-weight: 500;
    transition: opacity 0.2s;
}

.navbar-nav a:hover {
    opacity: 0.7;
}

.navbar-brand {
    color: var(--color-label, var(--text-color));
}

/* 主要内容 */
main {
    flex: 1;
    padding: 2rem 0;
}

/* 首页英雄区 */
.hero {
    text-align: center;
    padding: 3rem 0;
}

.hero h1 {
    font-size: 2.5rem;
    margin-bottom: 1rem;
    color: var(--text-color);
}

.hero p {
    font-size: 1.2rem;
    color: #666;
    margin-bottom: 2rem;
}

.actions {
    display: flex;
    gap: 1rem;
    justify-content: center;
    flex-wrap: wrap;
}

/* 特性卡片 */
.features {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(250px, 1fr));
    gap: 1.5rem;
    margin-top: 3rem;
}

.feature-card {
    background: var(--card-bg);
    padding: 1.5rem;
    border-radius: 8px;
    box-shadow: 0 2px 4px rgba(0,0,0,0.1);
    text-align: center;
}

.feature-card h3 {
    font-size: 1.3rem;
    margin-bottom: 0.5rem;
}

.feature-card p {
    color: #666;
}

/* 页面标题 */
.page-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 2rem;
    flex-wrap: wrap;
    gap: 1rem;
}

.page-header h1 {
    font-size: 2rem;
    color: var(--text-color);
}

/* 按钮 */
.btn {
    padding: 0.75rem 1.5rem;
    border: none;
    border-radius: 6px;
    font-size: 1rem;
    cursor: pointer;
    transition: all 0.3s;
    text-decoration: none;
    display: inline-block;
    font-weight: 500;
}

.btn-primary {
    background: var(--color-tint, var(--primary-color));
    color: white;
    border-radius: 10px;
}

.btn-primary:hover {
    background: var(--color-tint-pressed, #0056b3);
}

.btn-secondary {
    background: var(--secondary-color);
    color: white;
}

.btn-secondary:hover {
    background: #1976D2;
}

.btn-danger {
    background: var(--danger-color);
    color: white;
}

.btn-danger:hover {
    background: #da190b;
}

.btn-small {
    padding: 0.4rem 0.8rem;
    font-size: 0.9rem;
}

/* 脚本/任务列表 */
.script-list, .task-list {
    display: flex;
    flex-direction: column;
    gap: 1rem;
}

.script-item, .task-item {
    background: var(--card-bg);
    padding: 1.5rem;
    border-radius: 8px;
    box-shadow: 0 2px 4px rgba(0,0,0,0.1);
}

.script-header, .task-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 1rem;
    flex-wrap: wrap;
    gap: 1rem;
}

.script-header h3, .task-header h3 {
    font-size: 1.3rem;
    color: var(--text-color);
}

.script-actions {
    display: flex;
    gap: 0.5rem;
}

.script-info, .task-info {
    display: flex;
    gap: 1rem;
    align-items: center;
    flex-wrap: wrap;
}

.badge {
    display: inline-block;
    padding: 0.25rem 0.75rem;
    background: #e0e0e0;
    border-radius: 12px;
    font-size: 0.85rem;
    color: #666;
}

.status-badge {
    padding: 0.4rem 1rem;
    border-radius: 20px;
    font-size: 0.9rem;
    font-weight: 500;
}

.status-pending {
    background: #fff3cd;
    color: #856404;
}

.status-running {
    background: #d1ecf1;
    color: #0c5460;
}

.status-completed {
    background: #d4edda;
    color: #155724;
}

.status-failed {
    background: #f8d7da;
    color: #721c24;
}

.status-cancelled {
    background: #e2e3e5;
    color: #383d41;
}

.empty {
    text-align: center;
    padding: 3rem;
    color: #999;
    font-size: 1.1rem;
}

/* 模态框 */
.modal {
    display: none;
    position: fixed;
    z-index: 1003;
    left: 0;
    top: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(0,0,0,0.5);
    overflow: auto;
}

.modal-content {
    background-color: var(--card-bg);
    margin: 5% auto;
    padding: 0;
    border-radius: var(--radius-sheet, 12px);
    width: 90%;
    max-width: 600px;
    box-shadow: 0 4px 24px rgba(0, 0, 0, 0.15);
    animation: modalSlideIn 0.3s;
    position: relative;
    z-index: 1004;
}

.modal.modal-sheet {
    display: none;
    align-items: flex-end;
}

.modal.modal-sheet[style*="flex"] {
    display: flex;
}

@keyframes modalSlideIn {
    from {
        transform: translateY(-50px);
        opacity: 0;
    }
    to {
        transform: translateY(0);
        opacity: 1;
    }
}

.modal-header {
    padding: 1.5rem;
    border-bottom: 1px solid var(--border-color);
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.modal-header h2 {
    margin: 0;
    font-size: 1.5rem;
}

.close {
    font-size: 2rem;
    font-weight: bold;
    color: #aaa;
    cursor: pointer;
    border: none;
    background: none;
    line-height: 1;
}

.close:hover {
    color: var(--text-color);
}

.modal-body {
    padding: 1.5rem;
    height:60vh;
    overflow: auto;
}

.modal-footer {
    padding: 1.5rem;
    border-top: 1px solid var(--border-color);
    display: flex;
    justify-content: flex-end;
    gap: 1rem;
}

/* 新建动作模态框特定样式 */
.action-modal-content {
    max-height: 70vh !important;
    display: flex !important;
    flex-direction: column !important;
}

.action-modal-content .modal-body {
    flex: 1;
    overflow-y: auto;
    min-height: 0;
}

.action-modal-content .modal-footer {
    display: flex !important;
    flex-direction: row !important;
    justify-content: flex-end;
    gap: 0.75rem;
    flex-shrink: 0;
}

/* 表单 */
.form-group {
    margin-bottom: 1.5rem;
}

.form-group label {
    display: block;
    margin-bottom: 0.5rem;
    font-weight: 500;
    color: var(--text-color);
}

.form-group input,
.form-group select,
.form-group textarea {
    width: 100%;
    padding: 0.75rem;
    border: 1px solid var(--border-color);
    border-radius: 6px;
    font-size: 1rem;
    font-family: inherit;
}

.form-group input:focus,
.form-group select:focus,
.form-group textarea:focus {
    outline: none;
    border-color: var(--color-tint, var(--primary-color));
    box-shadow: 0 0 0 3px rgba(0, 122, 255, 0.2);
}

/* Safari Settings-style grouped lists */
.settings-group {
    background: var(--color-bg-elevated, var(--card-bg));
    border-radius: 10px;
    overflow: hidden;
    margin-bottom: 1.25rem;
    border: 0.5px solid var(--color-separator, var(--border-color));
}

.settings-group .script-item,
.settings-group .task-item {
    box-shadow: none;
    border-radius: 0;
    margin: 0;
    border-bottom: 0.5px solid var(--color-separator, var(--border-color));
}

.settings-group .script-item:last-child,
.settings-group .task-item:last-child {
    border-bottom: none;
}

.form-group textarea {
    resize: vertical;
    min-height: 100px;
}

.form-group select[multiple] {
    min-height: 200px;
}

/* 页脚 */
.footer {
    background: #333;
    color: white;
    text-align: center;
    padding: 1.5rem 0;
    margin-top: auto;
}

/* 移动端适配 */
@media (max-width: 768px) {
    /* 基础样式 */
    body {
        font-size: 14px;
    }

    .container {
        padding: 0 1rem;
    }

    /* 导航栏 */
    .navbar {
        padding: 0.75rem 0;
    }

    .navbar .container {
        flex-direction: column;
        gap: 0.75rem;
        padding: 0 1rem;
    }

    .navbar-brand {
        font-size: 1.25rem;
    }

    .navbar-nav {
        flex-direction: column;
        gap: 0.5rem;
        text-align: center;
        width: 100%;
    }

    .navbar-nav a {
        padding: 0.5rem;
        display: block;
    }

    /* 主要内容 */
    main {
        padding: 1rem 0;
    }

    /* 首页英雄区 */
    .hero {
        padding: 2rem 0;
    }

    .hero h1 {
        font-size: 1.75rem;
    }

    .hero p {
        font-size: 1rem;
    }

    .actions {
        flex-direction: column;
        gap: 0.75rem;
    }

    .actions .btn {
        width: 100%;
        min-height: 44px;
    }

    /* 特性卡片 */
    .features {
        grid-template-columns: 1fr;
        gap: 1rem;
        margin-top: 2rem;
    }

    .feature-card {
        padding: 1.25rem;
    }

    .feature-card h3 {
        font-size: 1.15rem;
    }

    /* 页面标题 */
    .page-header {
        flex-direction: column;
        align-items: flex-start;
        gap: 0.75rem;
        margin-bottom: 1.5rem;
    }

    .page-header h1 {
        font-size: 1.5rem;
    }

    .page-header .btn {
        width: 100%;
        min-height: 44px;
    }

    /* 按钮 */
    .btn {
        padding: 0.75rem 1.25rem;
        font-size: 0.95rem;
        min-height: 44px;
    }

    .btn-small {
        padding: 0.5rem 0.75rem;
        font-size: 0.85rem;
        min-height: 36px;
    }

    /* 脚本/任务列表 */
    .script-item,
    .task-item {
        padding: 1rem;
    }

    .script-header,
    .task-header {
        flex-direction: column;
        align-items: flex-start;
        gap: 0.75rem;
    }

    .script-header h3,
    .task-header h3 {
        font-size: 1.15rem;
    }

    .script-actions {
        width: 100%;
        flex-wrap: wrap;
    }

    .script-actions .btn {
        flex: 1;
        min-width: calc(50% - 0.25rem);
    }

    .script-info,
    .task-info {
        width: 100%;
        flex-wrap: wrap;
    }

    /* 模态框 — bottom sheet on mobile */
    .modal:not(.tab-switcher-overlay) {
        align-items: flex-end;
    }

    .modal:not(.tab-switcher-overlay) .modal-content {
        width: 100%;
        max-width: 100%;
        margin: 0;
        border-radius: 12px 12px 0 0;
        max-height: 92vh;
        overflow-y: auto;
        animation: sheetSlideUp 0.3s ease;
    }

    .modal:not(.tab-switcher-overlay) .modal-content::before {
        content: '';
        display: block;
        width: 36px;
        height: 5px;
        background: var(--color-fill-secondary, #e5e5ea);
        border-radius: 3px;
        margin: 8px auto 4px;
    }

    @keyframes sheetSlideUp {
        from { transform: translateY(100%); }
        to { transform: translateY(0); }
    }

    .modal-header {
        padding: 1rem;
    }

    .modal-header h2 {
        font-size: 1.25rem;
    }

    .close {
        font-size: 1.75rem;
        width: 32px;
        height: 32px;
    }

    .modal-body {
        padding: 1rem;
    }

    .modal-footer {
        padding: 1rem;
        flex-direction: column;
    }

    .modal-footer .btn {
        width: 100%;
    }

    /* 表单 */
    .form-group {
        margin-bottom: 1rem;
    }

    .form-group label {
        font-size: 0.9rem;
        margin-bottom: 0.4rem;
    }

    .form-group input,
    .form-group select,
    .form-group textarea {
        padding: 0.75rem;
        font-size: 16px; /* 防止iOS自动缩放 */
        min-height: 44px;
    }

    .form-group textarea {
        min-height: 100px;
    }

    /* 徽章 */
    .badge {
        font-size: 0.8rem;
        padding: 0.2rem 0.6rem;
    }

    .status-badge {
        font-size: 0.85rem;
        padding: 0.35rem 0.85rem;
    }

    /* 空状态 */
    .empty {
        padding: 2rem 1rem;
        font-size: 1rem;
    }
}

