/* 基本样式和变量 */
:root {
    /* 亮色主题变量 */
    --bg-primary: #e6e9ef;
    --bg-secondary: #e6e9ef;
    --text-primary: #333333;
    --text-secondary: #666666;
    --border-color: #d1d9e6;
    --accent-color: #4a6cf7;
    --hover-color: #3a5ce5;
    --header-bg: #e6e9ef;
    --table-header-bg: #d1d9e6;
    --table-row-hover: #f0f7ff;
    --shadow-light: rgba(255, 255, 255, 0.8);
    --shadow-dark: rgba(166, 180, 200, 0.7);
    --input-bg: #e6e9ef;
    --gradient-primary: linear-gradient(145deg, #f0f5ff, #d1d9e6);
    --gradient-secondary: linear-gradient(145deg, #d1d9e6, #f0f5ff);
}

/* 深色主题变量 */
[data-theme="dark"] {
    --bg-primary: #1e2026;
    --bg-secondary: #1e2026;
    --text-primary: #e0e0e0;
    --text-secondary: #a0a0a0;
    --border-color: #2d3038;
    --accent-color: #5d7bf9;
    --hover-color: #6e89ff;
    --header-bg: #1e2026;
    --table-header-bg: #2d3038;
    --table-row-hover: #383838;
    --shadow-light: rgba(34, 36, 42, 0.8);
    --shadow-dark: rgba(16, 17, 22, 0.7);
    --input-bg: #1e2026;
    --gradient-primary: linear-gradient(145deg, #21242b, #1a1c21);
    --gradient-secondary: linear-gradient(145deg, #1a1c21, #21242b);
}

/* 全局样式 */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
    transition: background-color 0.3s, color 0.3s, border-color 0.3s, box-shadow 0.3s;
}

body {
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    background-color: var(--bg-primary);
    color: var(--text-primary);
    line-height: 1.6;
    background-image: var(--gradient-primary);
}

.app-container {
    display: flex;
    flex-direction: column;
    height: 100vh;
    max-width: 100%;
    margin: 0 auto;
}

/* 头部样式 */
header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 1rem 2rem;
    background-color: var(--header-bg);
    border-bottom: 1px solid var(--border-color);
    box-shadow: 0 5px 15px rgba(0, 0, 0, 0.05);
    background-image: var(--gradient-primary);
}

.logo {
    font-size: 1.5rem;
    font-weight: bold;
    color: var(--accent-color);
    text-shadow: 1px 1px 2px var(--shadow-light), -1px -1px 2px var(--shadow-dark);
}

.controls {
    display: flex;
    gap: 1rem;
}

/* 按钮样式 - 拟态设计 */
.btn {
    padding: 0.5rem 1rem;
    background-color: var(--accent-color);
    color: white;
    border: none;
    border-radius: 10px;
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 0.5rem;
    font-size: 0.9rem;
    font-weight: 500;
    transition: all 0.3s ease;
    box-shadow: 3px 3px 6px var(--shadow-dark), -3px -3px 6px var(--shadow-light);
    position: relative;
    overflow: hidden;
    z-index: 1;
}

.btn::before {
    content: '';
    position: absolute;
    top: 0;
    left: -100%;
    width: 100%;
    height: 100%;
    background: linear-gradient(90deg, transparent, rgba(255, 255, 255, 0.2), transparent);
    transition: all 0.5s ease;
    z-index: -1;
}

.btn:hover {
    background-color: var(--hover-color);
    transform: translateY(-2px);
    box-shadow: 5px 5px 10px var(--shadow-dark), -5px -5px 10px var(--shadow-light);
}

.btn:hover::before {
    left: 100%;
}

.btn:active {
    transform: translateY(0);
    box-shadow: inset 3px 3px 6px var(--shadow-dark), inset -3px -3px 6px var(--shadow-light);
}

/* 拟态按钮变体 */
.neomorphic-btn {
    background-color: var(--bg-primary);
    color: var(--text-primary);
    border: none;
    border-radius: 10px;
    cursor: pointer;
    transition: all 0.3s ease;
    box-shadow: 3px 3px 6px var(--shadow-dark), -3px -3px 6px var(--shadow-light);
}

.neomorphic-btn:hover {
    box-shadow: 5px 5px 10px var(--shadow-dark), -5px -5px 10px var(--shadow-light);
}

.neomorphic-btn:active {
    box-shadow: inset 3px 3px 6px var(--shadow-dark), inset -3px -3px 6px var(--shadow-light);
}

/* 红色危险按钮 */
.danger-btn {
    padding: 0.5rem 1rem;
    background-color: #ff5252;
    color: white;
    border: none;
    border-radius: 10px;
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 0.5rem;
    font-size: 0.9rem;
    font-weight: 500;
    transition: all 0.3s ease;
    box-shadow: 3px 3px 6px var(--shadow-dark), -3px -3px 6px var(--shadow-light);
    position: relative;
    overflow: hidden;
    z-index: 1;
}

.danger-btn::before {
    content: '';
    position: absolute;
    top: 0;
    left: -100%;
    width: 100%;
    height: 100%;
    background: linear-gradient(90deg, transparent, rgba(255, 255, 255, 0.2), transparent);
    transition: all 0.5s ease;
    z-index: -1;
}

.danger-btn:hover {
    background-color: #ff3b30;
    transform: translateY(-2px);
    box-shadow: 5px 5px 10px var(--shadow-dark), -5px -5px 10px var(--shadow-light);
}

.danger-btn:hover::before {
    left: 100%;
}

.danger-btn:active {
    transform: translateY(0);
    box-shadow: inset 3px 3px 6px var(--shadow-dark), inset -3px -3px 6px var(--shadow-light);
}

/* 深色主题下的红色按钮调整 */
[data-theme="dark"] .danger-btn {
    background-color: #d32f2f;
}

[data-theme="dark"] .danger-btn:hover {
    background-color: #b71c1c;
}

#theme-toggle {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    display: flex;
    justify-content: center;
    align-items: center;
    padding: 0;
    box-shadow: 3px 3px 6px var(--shadow-dark), -3px -3px 6px var(--shadow-light);
    background-color: var(--accent-color);
    color: white;
}

#theme-toggle:hover {
    transform: rotate(15deg);
}

#lang-toggle {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    display: flex;
    justify-content: center;
    align-items: center;
    padding: 0;
    box-shadow: 3px 3px 6px var(--shadow-dark), -3px -3px 6px var(--shadow-light);
    background-color: var(--accent-color);
    color: white;
}

#lang-toggle:hover {
    transform: scale(1.1);
}

/* 主要内容区域 */
main {
    display: flex;
    flex-direction: row;
    flex: 1;
    padding: 1rem;
    overflow: hidden;
    gap: 1rem;
}

.sidebar-wrapper {
    position: relative;
    width: 400px;
    min-width: 300px;
    max-width: 80%;
    display: flex;
    flex-direction: column;
    transition: all 0.3s ease-in-out;
    flex-shrink: 0;
}

.sidebar-wrapper.collapsed {
    width: 0;
    min-width: 0;
    overflow: hidden;
}

.sidebar-toggle {
    position: absolute;
    right: -15px;
    top: 50%;
    transform: translateY(-50%);
    z-index: 20;
    width: 30px;
    height: 60px;
    border-radius: 0 10px 10px 0;
    padding: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    background-color: var(--accent-color);
    color: white;
    border: none;
    cursor: pointer;
    transition: transform 0.3s ease-in-out, right 0.3s ease-in-out;
    box-shadow: 3px 3px 6px var(--shadow-dark);
}

.sidebar-toggle i {
    transition: transform 0.3s ease-in-out;
}

.sidebar-toggle.collapsed i {
    transform: rotate(180deg);
}

.sidebar-toggle:hover {
    transform: translateY(-50%) translateX(2px);
}

.json-input-container {
    flex: 1;
    display: flex;
    flex-direction: column;
    padding-right: 0;
}

/* 拟态输入框 */
#json-input {
    width: 100%;
    flex: 1;
    padding: 1rem;
    border: none;
    border-radius: 15px;
    background-color: var(--input-bg);
    color: var(--text-primary);
    resize: none;
    font-family: monospace;
    margin-bottom: 0.5rem;
    min-height: 150px;
    box-shadow: inset 3px 3px 6px var(--shadow-dark), inset -3px -3px 6px var(--shadow-light);
    outline: none;
    background-image: var(--gradient-secondary);
}

#json-input:focus {
    box-shadow: inset 4px 4px 8px var(--shadow-dark), inset -4px -4px 8px var(--shadow-light);
}

/* 表格容器 - 拟态卡片 */
.table-container {
    flex: 2;
    overflow: auto;
    border: none;
    border-radius: 15px;
    background-color: var(--bg-secondary);
    min-width: 400px;
    box-shadow: 5px 5px 15px var(--shadow-dark), -5px -5px 15px var(--shadow-light);
    background-image: var(--gradient-secondary);
}

#json-table-wrapper {
    overflow: auto;
    height: 100%;
    border-radius: 15px;
}

/* 表格样式 */
#json-table {
    width: 100%;
    border-collapse: collapse;
    table-layout: fixed;
}

/* 行号列样式 */
#json-table th.row-number-header {
    width: 60px;
    text-align: center;
    background-color: var(--accent-color);
    color: white;
    font-weight: bold;
    z-index: 11;
}

#json-table td.row-number {
    width: 60px;
    text-align: center;
    background-color: var(--bg-tertiary);
    font-weight: 500;
    color: var(--accent-color);
    -webkit-user-select: none;
    user-select: none;
}

#json-table th {
    background-color: var(--table-header-bg);
    padding: 0.75rem;
    text-align: left;
    font-weight: 600;
    color: var(--text-primary);
    border-bottom: 1px solid var(--border-color);
    position: sticky;
    top: 0;
    z-index: 10;
    -webkit-user-select: none;
    user-select: none;
    text-shadow: 1px 1px 1px var(--shadow-light);
}

#json-table th .resize-handle {
    position: absolute;
    right: 0;
    top: 0;
    height: 100%;
    width: 5px;
    background-color: var(--border-color);
    cursor: col-resize;
    opacity: 0;
    transition: opacity 0.2s;
}

#json-table th:hover .resize-handle {
    opacity: 1;
}

#json-table td {
    padding: 0.75rem;
    border-bottom: 1px solid var(--border-color);
    color: var(--text-primary);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    transition: all 0.3s ease;
}

#json-table tr:hover td {
    background-color: var(--table-row-hover);
    transform: scale(1.01);
}

/* 移动端适配 */
@media (max-width: 768px) {
    main {
        flex-direction: column;
        padding: 0.5rem;
        gap: 0.5rem;
    }

    .sidebar-wrapper {
        width: 100%;
        max-width: 100%;
        min-width: unset;
        height: 250px;
        transition: all 0.3s ease-in-out;
    }

    .sidebar-wrapper.collapsed {
        height: 45px;
        width: 100%;
        overflow: hidden;
    }

    .sidebar-wrapper.collapsed #json-input {
        display: none;
    }

    .sidebar-wrapper.collapsed #parse-btn {
        display: none;
    }

    .sidebar-toggle {
        right: unset;
        left: 50%;
        margin-left: -30px;
        bottom: -5px;
        top: unset;
        transform: rotate(90deg);
        width: 60px;
        height: 30px;
        border-radius: 10px 10px 0 0;
        z-index: 25;
    }

    .sidebar-toggle.collapsed i {
        transform: rotate(-90deg);
    }

    .json-input-container {
        padding-right: 0;
        padding-bottom: 5px;
    }

    #json-input {
        resize: vertical;
        border-radius: 10px;
        padding: 0.75rem;
    }

    .table-container {
        flex: 1;
        min-width: unset;
        border-radius: 10px;
    }
    
    #json-table th {
        padding: 0.5rem;
        font-size: 0.8rem;
    }
    
    #json-table td {
        padding: 0.5rem;
        font-size: 0.85rem;
    }
    
    #json-table th.row-number-header,
    #json-table td.row-number {
        width: 40px;
        font-size: 0.75rem;
    }
    
    #json-table td.editing input {
        padding: 0.5rem;
        font-size: 0.85rem;
    }
    
    .modal-content {
        margin: 5% auto;
        width: 95%;
        max-width: 95%;
        border-radius: 15px;
    }
    
    .modal-header {
        padding: 0.75rem 1rem;
    }
    
    .modal-header h2 {
        font-size: 1.2rem;
    }
    
    .modal-body {
        padding: 1rem;
    }
    
    .modal-footer {
        padding: 0.75rem 1rem;
        flex-wrap: wrap;
    }
    
    .modal-footer .btn,
    .modal-footer .danger-btn {
        flex: 1;
        min-width: 45%;
    }
    
    .setting-item {
        flex-direction: column;
        align-items: flex-start;
    }
    
    .setting-item label {
        min-width: unset;
        width: 100%;
        margin-bottom: 0.5rem;
    }
    
    .setting-description {
        font-size: 0.8rem;
    }
}

#json-table td.editable {
    cursor: text;
}

#json-table td.editing {
    padding: 0;
}

#json-table td.editing input {
    width: 100%;
    height: 100%;
    padding: 0.75rem;
    border: none;
    background-color: var(--input-bg);
    color: var(--text-primary);
    outline: none;
    box-shadow: inset 2px 2px 5px var(--shadow-dark), inset -2px -2px 5px var(--shadow-light);
}

/* 页脚样式 */
footer {
    padding: 0.75rem 1rem;
    background-color: var(--header-bg);
    border-top: 1px solid var(--border-color);
    box-shadow: 0 -5px 15px rgba(0, 0, 0, 0.05);
    background-image: var(--gradient-primary);
}

.status-bar {
    display: flex;
    justify-content: space-between;
    font-size: 0.85rem;
    color: var(--text-secondary);
}

/* 响应式设计 */
@media (max-width: 768px) {
    header {
        flex-direction: column;
        gap: 0.75rem;
        padding: 0.75rem;
    }
    
    .logo {
        font-size: 1.2rem;
    }
    
    .controls {
        width: 100%;
        display: grid;
        grid-template-columns: repeat(3, 1fr);
        gap: 0.5rem;
    }
    
    .controls .btn {
        padding: 0.4rem 0.5rem;
        font-size: 0.75rem;
        justify-content: center;
        white-space: nowrap;
    }
    
    .controls .btn i {
        font-size: 0.9rem;
    }
    
    #json-input {
        height: 100px;
        font-size: 0.85rem;
    }
    
    footer {
        padding: 0.5rem 0.75rem;
    }
    
    .status-bar {
        font-size: 0.7rem;
        flex-wrap: wrap;
        gap: 0.25rem;
    }
    
    .status-bar span:nth-child(2) {
        display: none;
    }
}

@media (max-width: 480px) {
    .controls {
        grid-template-columns: repeat(2, 1fr);
    }
    
    .controls .btn {
        padding: 0.35rem 0.4rem;
        font-size: 0.7rem;
    }
    
    .logo {
        font-size: 1rem;
    }
    
    .sidebar-wrapper {
        height: 200px;
    }
    
    .sidebar-wrapper.collapsed {
        height: 40px;
    }

    .sidebar-wrapper.collapsed #json-input {
        display: none;
    }

    .sidebar-wrapper.collapsed #parse-btn {
        display: none;
    }
    
    #json-input {
        height: 80px;
        font-size: 0.8rem;
    }
    
    #json-table th {
        padding: 0.4rem;
        font-size: 0.75rem;
    }
    
    #json-table td {
        padding: 0.4rem;
        font-size: 0.8rem;
    }
    
    .modal-content {
        margin: 2% auto;
        width: 98%;
        max-width: 98%;
        border-radius: 12px;
    }
    
    .modal-header h2 {
        font-size: 1rem;
    }
    
    .modal-body {
        padding: 0.75rem;
    }
    
    .setting-description {
        font-size: 0.75rem;
    }
}

/* 横屏模式优化 */
@media (max-width: 768px) and (orientation: landscape) {
    .sidebar-wrapper {
        height: 200px;
    }
    
    .sidebar-wrapper.collapsed {
        height: 40px;
    }

    .sidebar-wrapper.collapsed #json-input {
        display: none;
    }

    .sidebar-wrapper.collapsed #parse-btn {
        display: none;
    }
    
    #json-input {
        height: 80px;
    }
}

/* 模态框样式 */
.modal {
    display: none;
    position: fixed;
    z-index: 100;
    left: 0;
    top: 0;
    width: 100%;
    height: 100%;
    overflow: auto;
    background-color: rgba(0, 0, 0, 0.5);
    animation: fadeIn 0.3s;
    -webkit-backdrop-filter: blur(5px);
    backdrop-filter: blur(5px);
}

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

/* 拟态模态框 */
.modal-content {
    background-color: var(--bg-primary);
    margin: 10% auto;
    padding: 0;
    border-radius: 20px;
    box-shadow: 8px 8px 20px var(--shadow-dark), -8px -8px 20px var(--shadow-light);
    width: 500px;
    max-width: 90%;
    animation: slideDown 0.3s;
    background-image: var(--gradient-primary);
    border: 1px solid var(--border-color);
}

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

.modal-header {
    padding: 1rem 1.5rem;
    border-bottom: 1px solid var(--border-color);
    display: flex;
    justify-content: space-between;
    align-items: center;
    border-radius: 20px 20px 0 0;
}

.modal-header h2 {
    margin: 0;
    color: var(--text-primary);
    font-size: 1.5rem;
    text-shadow: 1px 1px 2px var(--shadow-light), -1px -1px 2px var(--shadow-dark);
}

.close {
    color: var(--text-secondary);
    font-size: 1.8rem;
    font-weight: bold;
    cursor: pointer;
    transition: color 0.2s, transform 0.2s;
    width: 30px;
    height: 30px;
    display: flex;
    justify-content: center;
    align-items: center;
    border-radius: 50%;
    box-shadow: 2px 2px 4px var(--shadow-dark), -2px -2px 4px var(--shadow-light);
}

.close:hover {
    color: var(--accent-color);
}

.modal-body {
    padding: 1.5rem;
}

.modal-footer {
    padding: 1rem 1.5rem;
    border-top: 1px solid var(--border-color);
    display: flex;
    justify-content: flex-end;
    border-radius: 0 0 20px 20px;
    gap: 1rem;
}

/* 设置项样式 */
.setting-item {
    margin-bottom: 1.5rem;
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 1rem;
}

.setting-item label {
    font-weight: 500;
    color: var(--text-primary);
    flex: 1;
    min-width: 200px;
}

.setting-description {
    width: 100%;
    margin-top: 0.5rem;
    color: var(--text-secondary);
    font-size: 0.9rem;
}

/* 拟态开关按钮 */
.toggle-switch {
    position: relative;
    display: inline-block;
    width: 60px;
    height: 30px;
    cursor: pointer;
}

.toggle-switch input {
    opacity: 0;
    width: 100%;
    height: 100%;
    position: absolute;
    z-index: 2;
    cursor: pointer;
    left: 0;
    top: 0;
    margin: 0;
    padding: 0;
}

.toggle-slider {
    position: absolute;
    cursor: pointer;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background-color: var(--border-color);
    transition: .4s;
    border-radius: 30px;
    box-shadow: inset 2px 2px 4px var(--shadow-dark), inset -2px -2px 4px var(--shadow-light);
    pointer-events: none;
}

.toggle-slider:before {
    position: absolute;
    content: "";
    height: 22px;
    width: 22px;
    left: 4px;
    bottom: 4px;
    background-color: var(--bg-primary);
    transition: .4s;
    border-radius: 50%;
    pointer-events: none;
    box-shadow: 2px 2px 4px var(--shadow-dark), -2px -2px 4px var(--shadow-light);
}

.toggle-switch input:checked + .toggle-slider {
    background-color: var(--accent-color);
    box-shadow: inset 2px 2px 4px rgba(0, 0, 0, 0.3);
}

.toggle-switch input:checked + .toggle-slider:before {
    transform: translateX(30px);
    box-shadow: 2px 2px 4px var(--shadow-dark), -2px -2px 4px var(--shadow-light);
}

/* 滚动条样式 */
::-webkit-scrollbar {
    width: 12px;
    height: 12px;
}

::-webkit-scrollbar-track {
    background: var(--bg-secondary);
    border-radius: 10px;
    box-shadow: inset 1px 1px 3px var(--shadow-dark), inset -1px -1px 3px var(--shadow-light);
}

::-webkit-scrollbar-thumb {
    background: skyblue;
    border-radius: 10px;
    box-shadow: 2px 2px 5px var(--shadow-dark), -2px -2px 5px var(--shadow-light);
}

::-webkit-scrollbar-thumb:hover {
    background: deepskyblue;
}

/* 移动端滚动条优化 */
@media (max-width: 768px) {
    ::-webkit-scrollbar {
        width: 8px;
        height: 8px;
    }
    
    ::-webkit-scrollbar-thumb {
        background: var(--accent-color);
        opacity: 0.6;
    }
    
    /* 移动端触摸优化 */
    * {
        -webkit-tap-highlight-color: transparent;
        -webkit-touch-callout: none;
    }
    
    .btn, .danger-btn {
        -webkit-user-select: none;
        user-select: none;
    }
}

/* 高亮效果 */
.highlight {
    animation: highlight 0.6s ease-in-out;
}

@keyframes highlight {
    0%, 100% { background-color: transparent; }
    50% { background-color: rgba(74, 108, 247, 0.2); }
}