:root {
    --bg-primary: #1a1a2e;
    --bg-secondary: #16213e;
    --text-primary: #eee;
    --text-secondary: #aaa;
    --accent: #0f3460;
    --border: #333;
    --safe-area-top: env(safe-area-inset-top);
    --safe-area-bottom: env(safe-area-inset-bottom);
}

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    background: var(--bg-primary);
    color: var(--text-primary);
    min-height: 100vh;
    padding-top: var(--safe-area-top);
    padding-bottom: var(--safe-area-bottom);
}

#app {
    display: flex;
    flex-direction: column;
    min-height: 100vh;
}

.nav-bar {
    background: var(--bg-secondary);
    padding: 16px;
    position: sticky;
    top: 0;
}

.nav-title {
    font-size: 18px;
    font-weight: 600;
}

#main-content {
    flex: 1;
    padding: 16px;
}

/* 按钮样式 */
.btn {
    padding: 12px 24px;
    border: none;
    border-radius: 8px;
    font-size: 16px;
    cursor: pointer;
    min-height: 44px; /* iOS 触摸目标 */
}

.btn-primary {
    background: var(--accent);
    color: white;
}

/* 权限审批弹窗 */
.permission-modal {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    background: var(--bg-secondary);
    border-top-left-radius: 16px;
    border-top-right-radius: 16px;
    padding: 20px;
    padding-bottom: calc(20px + var(--safe-area-bottom));
    box-shadow: 0 -4px 20px rgba(0,0,0,0.3);
    z-index: 1000;
    animation: slideUp 0.3s ease;
}

@keyframes slideUp {
    from { transform: translateY(100%); }
    to { transform: translateY(0); }
}

.permission-modal h3 {
    margin-bottom: 12px;
    color: var(--text-primary);
}

.permission-modal .tool-name {
    font-weight: 600;
    color: var(--accent);
    margin-bottom: 8px;
}

.permission-modal pre {
    background: var(--bg-primary);
    padding: 12px;
    border-radius: 8px;
    overflow-x: auto;
    font-size: 12px;
    margin: 12px 0;
    max-height: 200px;
    overflow-y: auto;
}

.permission-actions {
    display: flex;
    gap: 12px;
    margin-top: 16px;
}

.permission-actions .btn {
    flex: 1;
}

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

.permission-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0,0,0,0.5);
    z-index: 999;
}

/* 工具调用展示 */
.tool-call {
    background: var(--bg-secondary);
    border-radius: 8px;
    margin: 8px 0;
    overflow: hidden;
}

.tool-call-header {
    display: flex;
    justify-content: space-between;
    padding: 8px 12px;
    background: var(--accent);
    cursor: pointer;
}

.tool-call-content {
    padding: 12px;
    display: none;
}

.tool-call.expanded .tool-call-content {
    display: block;
}

/* 加载动画 */
.spinner {
    width: 32px;
    height: 32px;
    border: 3px solid var(--border);
    border-top-color: var(--accent);
    border-radius: 50%;
    animation: spin 1s linear infinite;
    margin: 0 auto 12px;
}

@keyframes spin {
    to { transform: rotate(360deg); }
}

/* 消息样式 */
.message {
    margin-bottom: 12px;
    padding: 12px;
    border-radius: 8px;
}

.message.user {
    background: var(--accent);
    margin-left: 20%;
}

.message.assistant {
    background: var(--bg-secondary);
    margin-right: 20%;
}

.message.system {
    background: rgba(255, 193, 7, 0.1);
    border-left: 3px solid #ffc107;
}

.message-header {
    display: flex;
    justify-content: space-between;
    font-size: 12px;
    color: var(--text-secondary);
    margin-bottom: 8px;
}

.message-content {
    word-break: break-word;
}

/* 连接状态 */
.connection-status {
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 12px;
}

.status-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: #666;
}

.connection-status.connected .status-dot {
    background: #28a745;
}

.connection-status.connecting .status-dot,
.connection-status.reconnecting .status-dot {
    background: #ffc107;
    animation: pulse 1s infinite;
}

.connection-status.disconnected .status-dot,
.connection-status.error .status-dot,
.connection-status.failed .status-dot {
    background: #dc3545;
}

@keyframes pulse {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.5; }
}

/* 空状态 */
.empty-state {
    text-align: center;
    padding: 40px 20px;
    color: var(--text-secondary);
}

.empty-state .title {
    font-size: 18px;
    margin-bottom: 8px;
}

.empty-state .hint {
    font-size: 14px;
    opacity: 0.7;
}

/* 卡片和列表 */
.card {
    background: var(--bg-secondary);
    border-radius: 12px;
    padding: 16px;
    margin-bottom: 12px;
}

.card-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 8px;
}

.card-header h3 {
    font-size: 16px;
}

.status-badge {
    padding: 4px 8px;
    border-radius: 4px;
    font-size: 12px;
}

.status-badge.online {
    background: #28a745;
    color: white;
}

.status-badge.offline {
    background: #dc3545;
    color: white;
}

.status-badge.active {
    background: #17a2b8;
    color: white;
}

/* 视图头部 */
.view-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 16px;
}

/* 聊天视图 */
.chat-view {
    display: flex;
    flex-direction: column;
    height: 100%;
}

.chat-header {
    display: flex;
    align-items: center;
    gap: 12px;
    padding-bottom: 12px;
    border-bottom: 1px solid var(--border);
}

.messages-container {
    flex: 1;
    overflow-y: auto;
    padding: 12px 0;
}

.input-area {
    display: flex;
    gap: 8px;
    padding: 12px 0;
    border-top: 1px solid var(--border);
}

.input-area input {
    flex: 1;
    padding: 12px;
    border: 1px solid var(--border);
    border-radius: 8px;
    background: var(--bg-primary);
    color: var(--text-primary);
    font-size: 16px;
}

.btn-back {
    background: transparent;
    color: var(--text-primary);
    padding: 8px 12px;
}

/* 错误消息 */
.error-message {
    text-align: center;
    padding: 20px;
    color: #dc3545;
}

/* 环境卡片 */
.environment-card,
.session-card {
    cursor: pointer;
    transition: transform 0.2s, box-shadow 0.2s;
}

.environment-card:hover,
.session-card:hover {
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(0,0,0,0.2);
}

.label {
    color: var(--text-secondary);
    margin-right: 8px;
}