:root {
    --primary: #3370ff;
    --primary-light: #e8f0fe;
    --sidebar-bg: #f7f8fa;
    --sidebar-width: 220px;
    --border: #e3e6ea;
    --header-bg: #ffffff;
    --text: #1f2329;
    --text-muted: #8f959e;
    --hover: #f0f2f5;
    --selected: #e8f0fe;
    --grid-header-bg: #f5f6f8;
    --grid-border: #e9ebef;
    --grid-odd: #ffffff;
    --grid-even: #fafbfc;
}

* { margin: 0; padding: 0; box-sizing: border-box; }
html, body { height: 100%; font-family: "Microsoft YaHei", "PingFang SC", sans-serif; font-size: 13px; color: var(--text); overflow: hidden; }

#app { display: flex; height: 100vh; }

#sidebar {
    width: var(--sidebar-width);
    background: var(--sidebar-bg);
    border-right: 1px solid var(--border);
    display: flex; flex-direction: column; flex-shrink: 0;
}
.sidebar-header { padding: 16px 16px 12px; border-bottom: 1px solid var(--border); }
.app-title { font-size: 15px; font-weight: 700; }
.app-subtitle { font-size: 11px; color: var(--text-muted); margin-top: 2px; }
#sheet-list { flex: 1; overflow-y: auto; padding: 6px; }
.sheet-item {
    display: flex; align-items: center; padding: 7px 10px; border-radius: 6px;
    cursor: pointer; margin-bottom: 2px; font-size: 13px; gap: 6px;
}
.sheet-item:hover { background: var(--hover); }
.sheet-item.active { background: var(--primary-light); color: var(--primary); font-weight: 600; }
.sheet-icon { width: 16px; text-align: center; color: var(--text-muted); font-size: 12px; }
.sheet-item.active .sheet-icon { color: var(--primary); }
/* 视图子项：挂在表下面，缩进显示 */
.view-item { padding-left: 30px; font-size: 12px; color: var(--text-muted); }
.view-item .view-icon { width: 14px; text-align: center; font-size: 10px; color: var(--text-muted); }
.view-item.active { background: var(--primary-light); color: var(--primary); font-weight: 600; }
.view-item.active .view-icon { color: var(--primary); }
.sheet-count { margin-left: auto; font-size: 11px; color: var(--text-muted); }
.sidebar-footer { padding: 10px; border-top: 1px solid var(--border); display: flex; gap: 6px; }
.sidebar-footer .btn { flex: 1; }

#main { flex: 1; display: flex; flex-direction: column; min-width: 0; }

#toolbar {
    display: flex; align-items: center; padding: 0 12px; height: 46px;
    background: var(--header-bg); border-bottom: 1px solid var(--border); gap: 8px; flex-shrink: 0;
}
#action-buttons { display: flex; gap: 6px; flex: 1; align-items: center; overflow-x: auto; padding-right: 10px; }
.action-btn { white-space: nowrap; }
.view-tab {
    padding: 5px 12px; border-radius: 6px; cursor: pointer; white-space: nowrap;
    color: var(--text-muted); font-size: 13px;
}
.view-tab:hover { background: var(--hover); }
.view-tab.active { background: var(--primary-light); color: var(--primary); font-weight: 600; }
.toolbar-actions { display: flex; gap: 6px; }

.btn {
    padding: 6px 12px; border: 1px solid var(--border); border-radius: 6px;
    background: #fff; cursor: pointer; font-size: 13px; color: var(--text); transition: all .15s;
}
.btn:hover { background: var(--hover); border-color: #c8cdd4; }
.btn-primary { background: var(--primary); color: #fff; border-color: var(--primary); }
.btn-primary:hover { background: #2b5cd9; }
.btn-danger { color: #e5484d; }
.btn-danger:hover { background: #fdecec; border-color: #f5b5b7; }

#grid-container { flex: 1; overflow: auto; position: relative; background: #fff; }
#grid-scroll { min-width: 100%; }
#grid { border-collapse: separate; border-spacing: 0; min-width: 100%; table-layout: auto; }
#grid th, #grid td {
    border-right: 1px solid var(--grid-border); border-bottom: 1px solid var(--grid-border);
    padding: 0; white-space: nowrap; font-size: 13px; text-align: left;
}
#grid thead th {
    position: sticky; top: 0; z-index: 10; background: var(--grid-header-bg);
    font-weight: 600; padding: 8px 10px; min-width: 90px;
    border-bottom: 1px solid #dfe2e6;
}
#grid thead th.row-select-col { width: 36px; min-width: 36px; text-align: center; }
#grid thead th .field-type { display: block; font-weight: 400; font-size: 10px; color: var(--text-muted); }
#grid td.cell { padding: 6px 10px; min-width: 90px; max-width: none; overflow: hidden; text-overflow: ellipsis; vertical-align: middle; cursor: cell; }
/* 列宽拖拽手柄 */
.col-resizer { position: absolute; right: 0; top: 0; bottom: 0; width: 6px; cursor: col-resize; user-select: none; z-index: 12; }
.col-resizer:hover, .col-resizer.dragging { background: rgba(64,150,255,0.45); }
#grid td.cell.row-select-cell { width: 36px; min-width: 36px; text-align: center; cursor: pointer; }
#grid tbody tr:nth-child(even) { background: var(--grid-even); }
#grid tbody tr:hover td { background: var(--hover); }
#grid tbody tr.selected td { background: var(--selected); }
#grid tbody tr.selected td.row-select-cell { background: var(--primary-light); }
#grid td.cell.editing { padding: 0; }
#grid td.cell.editing input, #grid td.cell.editing select, #grid td.cell.editing textarea {
    width: 100%; height: 100%; border: 2px solid var(--primary); outline: none;
    padding: 5px 8px; font-size: 13px; background: #fff;
}
#grid td.cell.cell-number { text-align: right; }
#grid td.cell.cell-button { cursor: pointer; text-align: center; }
.btn-cell {
    display: inline-block; padding: 4px 10px; background: var(--primary-light);
    color: var(--primary); border-radius: 5px; font-size: 12px; border: 1px solid #c6d8ff;
}
.btn-cell:hover { background: #d6e4ff; }
.cell-attachment { color: var(--primary); text-decoration: none; font-size: 12px; }
.cell-attachment:hover { text-decoration: underline; }
.cell-url a { color: var(--primary); text-decoration: none; }
.cell-url a:hover { text-decoration: underline; }
.cell-checkbox { width: 18px; height: 18px; cursor: pointer; }
.cell-image img { max-height: 40px; border-radius: 3px; display: block; }
.cell-empty { color: #c8cdd4; }
.link-item { display: inline-block; margin-right: 4px; font-size: 12px; }

#statusbar {
    display: flex; justify-content: space-between; padding: 5px 14px;
    border-top: 1px solid var(--border); background: var(--sidebar-bg); font-size: 12px; color: var(--text-muted);
}

.context-menu {
    position: fixed; background: #fff; border: 1px solid var(--border); border-radius: 8px;
    box-shadow: 0 4px 16px rgba(0,0,0,.1); z-index: 1000; padding: 4px; min-width: 140px;
}
.context-menu .menu-item { padding: 7px 12px; border-radius: 5px; cursor: pointer; }
.context-menu .menu-item:hover { background: var(--hover); }
.hidden { display: none; }

.modal-overlay {
    position: fixed; inset: 0; background: rgba(0,0,0,.4); display: flex;
    align-items: center; justify-content: center; z-index: 2000;
}
.modal {
    background: #fff; border-radius: 12px; width: 720px; max-width: 92vw; max-height: 88vh;
    display: flex; flex-direction: column; box-shadow: 0 8px 40px rgba(0,0,0,.15);
}
.modal-header { padding: 16px 20px; border-bottom: 1px solid var(--border); display: flex; align-items: center; justify-content: space-between; }
.modal-title { font-size: 16px; font-weight: 700; }
.modal-close { cursor: pointer; font-size: 20px; color: var(--text-muted); padding: 0 4px; }
.modal-body { padding: 16px 20px; overflow-y: auto; flex: 1; }
.modal-footer { padding: 12px 20px; border-top: 1px solid var(--border); display: flex; justify-content: flex-end; gap: 8px; }

.config-table { width: 100%; border-collapse: collapse; }
.config-table th, .config-table td { padding: 8px 10px; border-bottom: 1px solid var(--grid-border); text-align: left; vertical-align: top; }
.config-table th { font-size: 12px; color: var(--text-muted); font-weight: 600; }
.config-table input[type="text"] {
    width: 100%; padding: 6px 8px; border: 1px solid var(--border); border-radius: 5px; font-size: 13px;
}
.config-table input[type="text"]:focus { outline: none; border-color: var(--primary); }
.config-remark { font-size: 11px; color: var(--text-muted); margin-top: 3px; line-height: 1.4; }
.path-key { font-family: Consolas, monospace; font-size: 12px; color: var(--text-muted); }
